本文整理汇总了Java中org.bukkit.event.EventHandler类的典型用法代码示例。如果您正苦于以下问题:Java EventHandler类的具体用法?Java EventHandler怎么用?Java EventHandler使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
EventHandler类属于org.bukkit.event包,在下文中一共展示了EventHandler类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onRegen
import org.bukkit.event.EventHandler; //导入依赖的package包/类
@EventHandler
public void onRegen(EntityRegainHealthEvent event) {
if (event.getEntityType() != EntityType.PLAYER || event.getRegainReason() != EntityRegainHealthEvent.RegainReason.SATIATED) return;
event.setCancelled(true);
Player player = (Player) event.getEntity();
long currentTime = System.currentTimeMillis() / 1000;
if (currentTime - getLastHealTime(player) < 3)
return;
double maxHealth = player.getAttribute(Attribute.GENERIC_MAX_HEALTH).getValue();
if (player.getHealth() < maxHealth) {
player.setHealth(clamp(player.getHealth() + 1, 0.0, maxHealth));
healTimes.put(player.getUniqueId(), currentTime);
}
float exhToApply = (float) 3;
Bukkit.getScheduler().runTaskLater(TGM.get(), () -> {
//This is because bukkit doesn't stop the exhaustion change when cancelling the event
player.setExhaustion(player.getExhaustion() + exhToApply);
//debug("Exhaustion before: " + previousExh + " Now: " + p.getExhaustion() + "Saturation: " + p.getSaturation(), p);
}, 1L);
}
示例2: onSpawn
import org.bukkit.event.EventHandler; //导入依赖的package包/类
@EventHandler
public void onSpawn(CreatureSpawnEvent event) {
if (ConfigOptimize.NoCrowdedEntityenable) {
Chunk chunk = event.getEntity().getLocation().getChunk();
Entity[] entities = chunk.getEntities();
for (Entity e : entities) {
EntityType type = e.getType();
int count = 0;
if (ConfigOptimize.NoCrowdedEntityTypeList.contains("*")
|| ConfigOptimize.NoCrowdedEntityTypeList.contains(type.name())) {
count++;
if (count > ConfigOptimize.NoCrowdedEntityPerChunkLimit && e.getType() != EntityType.PLAYER) {
e.remove();
}
}
}
}
}
示例3: onChat
import org.bukkit.event.EventHandler; //导入依赖的package包/类
@EventHandler
public void onChat(AsyncPlayerChatEvent event){
if(plugin.getConfig().getString("chatformat").equals("true")){
Player player = event.getPlayer();
String message = event.getMessage();
event.setCancelled(true);
String playerNameWithPrefixSuffix = player.getName() + ": ";
try {
playerNameWithPrefixSuffix = ChatColor.translateAlternateColorCodes('&', (!RankManager.getRankPrefix(player).equals(" ")?RankManager.getRankPrefix(player) : "") + RankManager.getRankNameColor(player) +" "+ player.getName() +(!RankManager.getRankSuffix(player).equals(" ")? " "+ RankManager.getRankSuffix(player) : "") + ChatColor.GRAY + ": ");
} catch (SQLException e) {
e.printStackTrace();
}
for(Player p : event.getRecipients()){
p.sendMessage(playerNameWithPrefixSuffix + ChatColor.WHITE + message);
}
}
}
示例4: onMove
import org.bukkit.event.EventHandler; //导入依赖的package包/类
@EventHandler
public void onMove(PlayerMoveEvent evt) {
Player p = evt.getPlayer();
Block b = p.getLocation().getBlock();
if (isImmune(p) // Verify we should get an alert from this player.
|| Utils.isSameBlock(evt.getFrom(), evt.getTo()) // Check they've moved at least to the next block.
|| !checkNearby(b)) // Check if a block is nearby them.
return;
double yDif = evt.getTo().getY() - evt.getFrom().getY();
double ascentMax = 0.8D;
if (p.hasPotionEffect(PotionEffectType.JUMP))
ascentMax += (double) p.getPotionEffect(PotionEffectType.JUMP).getAmplifier() / 10;
detections.detect(new Detection(p),
yDif == 0 && !checkNearby(evt.getFrom(), Material.WATER_LILY, Material.CARPET), // Hover.
yDif > ascentMax, // If they sharply ascend.
yDif == -.125D); // Glide (Unsure if this works.)
}
示例5: onBowShot
import org.bukkit.event.EventHandler; //导入依赖的package包/类
@EventHandler
public void onBowShot(EntityShootBowEvent e) {
if (e.getEntity() instanceof Player &&
e.getProjectile() instanceof Arrow) {
Bukkit.getScheduler().runTaskLater(this, () -> {
if (!e.getProjectile().isDead()) {
EntityTrail t = new EntityTrail(this, e.getProjectile(),
new CircumferenceSupplier(particle, 1.2f, 0.9f, 0.0f, 1)
.rotateY(tick -> tick * (2.0f * (float) Math.PI / 20))
, 1);
trails.put(e.getProjectile(), t);
t.begin();
}
}, 5L);
}
}
示例6: handleWoolCrafting
import org.bukkit.event.EventHandler; //导入依赖的package包/类
@EventHandler
public void handleWoolCrafting(PrepareItemCraftEvent event) {
ItemStack result = event.getRecipe().getResult();
InventoryHolder holder = event.getInventory().getHolder();
if (holder instanceof Player) {
MatchPlayer playerHolder = this.match.getPlayer((Player) holder);
if (playerHolder != null && result != null && result.getType() == Material.WOOL) {
for(MonumentWool wool : this.wools) {
if(wool.getDefinition().isObjectiveWool(result)) {
if(!wool.getDefinition().isCraftable()) {
playerHolder.sendMessage(ChatColor.RED + PGMTranslations.t("match.wool.craftDisabled", playerHolder, BukkitUtils.woolMessage(wool.getDyeColor())));
event.getInventory().setResult(null);
}
}
}
}
}
}
示例7: onEntityDamageByEntity
import org.bukkit.event.EventHandler; //导入依赖的package包/类
@EventHandler(ignoreCancelled = true, priority = EventPriority.HIGH)
public void onEntityDamageByEntity(EntityDamageByEntityEvent event) {
Entity entity = event.getEntity();
if (entity instanceof Player) {
Player attacker = BukkitUtils.getFinalAttacker(event, true);
if (attacker == null)
return;
long remaining;
Player player = (Player) entity;
if ((remaining = getRemaining(player)) > 0L) {
event.setCancelled(true);
attacker.sendMessage(ChatColor.RED + player.getName() + " has their " + getDisplayName() + ChatColor.RED + " timer for another " + ChatColor.BOLD
+ DurationFormatter.getRemaining(remaining, true, false) + ChatColor.RED + '.');
return;
}
if ((remaining = getRemaining(attacker)) > 0L) {
event.setCancelled(true);
attacker.sendMessage(ChatColor.RED + "You cannot attack players whilst your " + getDisplayName() + ChatColor.RED + " timer is active [" + ChatColor.BOLD
+ DurationFormatter.getRemaining(remaining, true, false) + ChatColor.RED + " remaining]. Use '" + ChatColor.GOLD + PVP_COMMAND + ChatColor.RED + "' to allow pvp.");
}
}
}
示例8: onCommand
import org.bukkit.event.EventHandler; //导入依赖的package包/类
@EventHandler (priority = EventPriority.HIGHEST, ignoreCancelled = false)
public void onCommand(PlayerCommandPreprocessEvent event){
if(event.getMessage().isEmpty()){
event.setMessage("/help");
return;
}
Command cmd = commandMap.get(event.getMessage().replaceFirst("/", "").split(" ")[0].toLowerCase());
if(cmd == null){
event.setMessage("/help");
return;
}
if(!cmd.testPermissionSilent(event.getPlayer()))
if(!(cmd instanceof LinkCommand)){
event.setMessage("/help");
}
}
示例9: playerLeave
import org.bukkit.event.EventHandler; //导入依赖的package包/类
@EventHandler
public void playerLeave(PlayerQuitEvent event){
event.setQuitMessage("");
VPPlayer player = getPlayer(event.getPlayer());
player.setMenu(null);
VPPLeaveEvent e = new VPPLeaveEvent(player);
if(getMsgPerm().has(player))
e.setMessage(leave);
e.save(player.save());
player.setOffline();
Bukkit.getServer().getPluginManager().callEvent(e);
//TODO send removed event
if(e.getMessage() != null)
e.getMessage().addSReplacement(PlaceH.SENDER.get(), player).send();
if(e.save())
save(player, false);
}
示例10: onPlayerMove
import org.bukkit.event.EventHandler; //导入依赖的package包/类
@EventHandler
public void onPlayerMove(PlayerMoveEvent event) {
final Player player = event.getPlayer();
final Material from = event.getFrom().getBlock().getRelative(BlockFace.DOWN).getType();
final Behaviour behaviour = Profile.getProfile(player.getUniqueId()).getBehaviour();
final long current = System.currentTimeMillis();
if (player.isSprinting()) {
behaviour.getMotion().setLastSprint(current);
}
if (player.isFlying()) {
behaviour.getMotion().setLastFly(current);
}
if (from.isSolid() || behaviour.getMotion().getLastY() == -1.0 || !behaviour.getMotion().isDescending()) {
behaviour.getMotion().setLastY(player.getLocation().getY());
}
if (!behaviour.isOnGround()) {
behaviour.getMotion().setLastYDiff(event.getTo().getY() - event.getFrom().getY());
}
}
示例11: onConsumeCake
import org.bukkit.event.EventHandler; //导入依赖的package包/类
@EventHandler(priority = EventPriority.HIGHEST)
public void onConsumeCake(PlayerInteractEvent event)
{
if(event.isCancelled()) return;
Player player = event.getPlayer();
if(event.hasBlock() && event.getAction().equals(Action.RIGHT_CLICK_BLOCK))
{
Block cake = event.getClickedBlock();
if(cake.getType().equals(Material.CAKE_BLOCK))
{
if(player.getFoodLevel() < 20 && (player.getGameMode() == GameMode.SURVIVAL || player.getGameMode() == GameMode.ADVENTURE))
{
addStats(player, carbon, 171);
addStats(player, protein, 114);
addStats(player, salts, 3);
}
}
}
}
示例12: onClick
import org.bukkit.event.EventHandler; //导入依赖的package包/类
@SuppressWarnings("deprecation")
@EventHandler
public void onClick(PlayerInteractEvent e) {
if (e.getAction() == Action.PHYSICAL)
return;
if (e.getPlayer().getItemInHand() == null)
return;
if (!e.getPlayer().getItemInHand().getType().equals(Material.COMPASS))
return;
if (!e.getPlayer().getItemInHand().hasItemMeta())
return;
if (!e.getPlayer().getItemInHand().getItemMeta().getDisplayName()
.equalsIgnoreCase(ChatColor.RED + "Selecteer jouw kingdom"))
return;
setKindomMenu(PlayerModule.getInstance().getPlayer(e.getPlayer()));
e.setCancelled(true);
}
示例13: onPlayerMove
import org.bukkit.event.EventHandler; //导入依赖的package包/类
@EventHandler
public void onPlayerMove(PlayerMoveEvent event)
{
if (this.cooldown.contains(event.getPlayer().getUniqueId()))
return;
this.cooldown.add(event.getPlayer().getUniqueId());
this.hub.getServer().getScheduler().runTask(this.hub, () ->
{
this.cooldown.remove(event.getPlayer().getUniqueId());
Parkour parkour = this.hub.getParkourManager().getPlayerParkour(event.getPlayer().getUniqueId());
if (parkour != null && event.getTo().getBlockY() <= parkour.getMinimalHeight())
parkour.failPlayer(event.getPlayer());
});
}
示例14: onWalkieTalkieInteract
import org.bukkit.event.EventHandler; //导入依赖的package包/类
@EventHandler
public void onWalkieTalkieInteract(PlayerInteractEvent e) {
if (e.getPlayer().getInventory().getItemInMainHand().getType() != Material.REDSTONE_COMPARATOR)
return;
if (e.getHand() == EquipmentSlot.OFF_HAND)
return;
WalkieTalkie wt = new WalkieTalkie(main,
main.getPlayerManager().getPlayer(e.getPlayer()).getCurrentWalkieTalkieFrequency());
// Left click to tune frequency.
if (e.getAction() == Action.LEFT_CLICK_AIR || e.getAction() == Action.LEFT_CLICK_BLOCK) {
if (e.getPlayer().isSneaking()) {
wt.decreaseFrequency(e.getPlayer());
} else {
wt.increaseFrequency(e.getPlayer());
}
}
}
示例15: PlayerCommandPreprocessEvent
import org.bukkit.event.EventHandler; //导入依赖的package包/类
@EventHandler
public void PlayerCommandPreprocessEvent(PlayerCommandPreprocessEvent event){
if(!Config.getConfig("jail.eventManager.command.enabled").equals("true"))return;
if(event.getPlayer() == null && !(event.getPlayer() instanceof Player)) return;
Player player = event.getPlayer();
if(isJailPlayer(player)){
String cmd = event.getMessage().split(" ")[0].replace("/", "");
ArrayList<String> list = Config.getList("jail.eventManager.command.whiteList");
if(list !=null){
for(int i=0;i < list.size();){
if(cmd.equalsIgnoreCase(list.get(i)))return;
i++;
}
}
playerTeleportJail(player);
event.setCancelled(true);
}
}