@EventHandler(ignoreCancelled = true, priority = EventPriority.NORMAL) public void onPlayerDeath(PlayerDeathEvent event) { Faction currentEventFac = plugin.getTimerManager().getEventTimer().getEventFaction(); if (currentEventFac instanceof ConquestFaction) { Player player = event.getEntity(); PlayerFaction playerFaction = plugin.getFactionManager().getPlayerFaction(player); if (playerFaction != null && SettingsYML.CONQUEST_POINT_LOSS_PER_DEATH > 0) { int oldPoints = getPoints(playerFaction); if (oldPoints == 0) return; int newPoints = takePoints(playerFaction, SettingsYML.CONQUEST_POINT_LOSS_PER_DEATH); event.setDeathMessage(null); // for some reason if it isn't handled manually, weird colour coding happens Bukkit.broadcastMessage(ChatColor.YELLOW + "[" + currentEventFac.getName() + "] " + ChatColor.GOLD + playerFaction.getName() + " lost " + SettingsYML.CONQUEST_POINT_LOSS_PER_DEATH + " points because " + player.getName() + " died." + ChatColor.AQUA + " (" + newPoints + '/' + SettingsYML.CONQUEST_REQUIRED_WIN_POINTS + ')' + ChatColor.YELLOW + '.'); } } }
@EventHandler(priority = EventPriority.LOW, ignoreCancelled=true) public void onLingeringPotionSplash(final LingeringPotionSplashEvent e) { if (DEBUG) { plugin.getLogger().info("1.9 " + e.getEventName()); plugin.getLogger().info("1.9 entity = " + e.getEntity()); plugin.getLogger().info("1.9 entity type = " + e.getEntityType()); plugin.getLogger().info("1.9 radius = " + e.getAreaEffectCloud().getRadius()); plugin.getLogger().info("1.9 id = " + e.getAreaEffectCloud().getEntityId()); plugin.getLogger().info("1.9 hit entity = " + e.getHitEntity()); } if (!Util.inWorld(e.getEntity().getLocation())) { return; } // Try to get the shooter Projectile projectile = e.getEntity(); plugin.getLogger().info("shooter = " + projectile.getShooter()); if (projectile.getShooter() != null && projectile.getShooter() instanceof Player) { UUID uuid = ((Player)projectile.getShooter()).getUniqueId(); // Store it and remove it when the effect is gone thrownPotions.put(e.getAreaEffectCloud().getEntityId(), uuid); plugin.getServer().getScheduler().runTaskLater(plugin, () -> thrownPotions.remove(e.getAreaEffectCloud().getEntityId()), e.getAreaEffectCloud().getDuration()); } }
@EventHandler(ignoreCancelled = true, priority = EventPriority.MONITOR) public void onInventoryClick(InventoryClickEvent event) { HumanEntity humanEntity = event.getWhoClicked(); if (humanEntity instanceof Player) { Player player = (Player) humanEntity; PearlNameFaker pearlNameFaker = itemNameFakes.get(player.getUniqueId()); if (pearlNameFaker == null) return; // Required to prevent ghost items. int heldSlot = player.getInventory().getHeldItemSlot(); if (event.getSlot() == heldSlot) { pearlNameFaker.setFakeItem(CraftItemStack.asNMSCopy(player.getItemInHand()), heldSlot); } else if (event.getHotbarButton() == heldSlot) { pearlNameFaker.setFakeItem(CraftItemStack.asNMSCopy(event.getCurrentItem()), event.getSlot()); new BukkitRunnable() { @Override public void run() { player.updateInventory(); } }.runTask(plugin); } } }
@EventHandler(ignoreCancelled = true, priority = EventPriority.NORMAL) public void onPearlClip(PlayerTeleportEvent event) { if (event.getCause() == PlayerTeleportEvent.TeleportCause.ENDER_PEARL) { Location to = event.getTo(); if (blockedPearlTypes.contains(to.getBlock().getType())) { Player player = event.getPlayer(); player.sendMessage(ChatColor.RED + "You cannot pearl there."); removeCooldown(player); event.setCancelled(true); return; } to.setX(to.getBlockX() + 0.5D); to.setZ(to.getBlockZ() + 0.5D); event.setTo(to); } }
@EventHandler(ignoreCancelled = true, priority = EventPriority.HIGH) public void onPlayerInteract(PlayerInteractEvent event) { if (event.getAction() != Action.RIGHT_CLICK_BLOCK) return; Player player = event.getPlayer(); if (player.getGameMode() == GameMode.CREATIVE && player.hasPermission(ProtectionListener.PROTECTION_BYPASS_PERMISSION)) { return; } if (plugin.getEotwHandler().isEndOfTheWorld()) { return; } Block block = event.getClickedBlock(); if (!this.isSubclaimable(block)) { return; } if (!this.checkSubclaimIntegrity(player, block)) { event.setCancelled(true); player.sendMessage(ChatColor.RED + "You do not have access to this subclaimed " + block.getType().toString() + '.'); } }
@EventHandler(ignoreCancelled = true, priority = EventPriority.HIGH) public void onPlayerMove(final PlayerMoveEvent event) { final Location from = event.getFrom(); final Location to = event.getTo(); if (from.getBlockX() == to.getBlockX() && from.getBlockZ() == to.getBlockZ()) { return; } if (!isWithinBorder(to) && isWithinBorder(from)) { final Player player = event.getPlayer(); player.sendMessage(ChatColor.RED + "You cannot go past the border."); event.setTo(from); final Entity vehicle = player.getVehicle(); if (vehicle != null) { vehicle.eject(); vehicle.teleport(from); vehicle.setPassenger((Entity)player); } } }
@EventHandler(ignoreCancelled=true, priority=EventPriority.HIGHEST) public void onBlockBreak(BlockBreakEvent event) { Block block = event.getBlock(); if (isEventSign(block)) { BlockState state = block.getState(); Sign sign = (Sign)state; ItemStack stack = new ItemStack(Material.SIGN, 1); ItemMeta meta = stack.getItemMeta(); meta.setDisplayName(EVENT_SIGN_ITEM_NAME); meta.setLore(Arrays.asList(sign.getLines())); stack.setItemMeta(meta); Player player = event.getPlayer(); World world = player.getWorld(); Location blockLocation = block.getLocation(); if ((player.getGameMode() != GameMode.CREATIVE) && (world.isGameRule("doTileDrops"))) { world.dropItemNaturally(blockLocation, stack); } event.setCancelled(true); block.setType(Material.AIR); state.update(); } }
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) public void onPlaceHopper(final BlockPlaceEvent e) { if (!cm.tileLimitEnabled) { return; } if (e.getBlock().getType() == Material.HOPPER) { Player p = e.getPlayer(); if (p.isOp()) { return; } int limit = NeverLagUtils.getMaxPermission(p, "neverlag.limit.hopper."); if (limit <= 0) { limit = cm.tileLimitDefaultHopper; } if (isLimit(e.getBlock().getLocation(), Material.HOPPER, limit)) { e.setCancelled(true); p.sendMessage(i18n.tr("message", limit)); } } }
@EventHandler(priority = EventPriority.NORMAL) public void kill(final MatchPlayerDeathEvent event) { if(!event.isChallengeKill()) return; // Death raindrops are given by the backend, to reduce API usage final int raindrops = calculateRaindrops( event.getKiller(), RaindropConstants.KILL_REWARD, false, 1 ); event.setRaindrops(raindrops); final MatchPlayer killer = event.getOnlineKiller(); if(killer != null) { RaindropUtil.showRaindrops( killer.getBukkit(), raindrops, RaindropUtil.calculateMultiplier(event.getKiller().getPlayerId()), new TranslatableComponent("match.kill.killed", event.getVictim().getComponentName()) ); } }
@EventHandler(ignoreCancelled = true, priority = EventPriority.HIGH) public void onCreatureSpawn(CreatureSpawnEvent event) { if (event.getSpawnReason() == CreatureSpawnEvent.SpawnReason.SLIME_SPLIT) { // allow slimes to always split return; } switch (event.getSpawnReason()) { case NATURAL: if (event.getLocation().getChunk().getEntities().length > MAX_NATURAL_CHUNK_ENTITIES) { event.setCancelled(true); } break; case CHUNK_GEN: if (event.getLocation().getChunk().getEntities().length > MAX_CHUNK_GENERATED_ENTITIES) { event.setCancelled(true); } break; default: break; } }
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) public void onPlace(BlockPlaceEvent e) { if (!cm.isAntiPlaceDoorDupe) { return; } // 判断手里的物品是否为门 if (e.getItemInHand().getType() == Material.WOOD_DOOR || e.getItemInHand().getType() == Material.IRON_DOOR) { // 清理所在区块的甘蔗掉落物 for (Entity entity : e.getPlayer().getLocation().getChunk().getEntities()) { if (entity instanceof Item) { Material itemType = ((Item) entity).getItemStack().getType(); if (itemType == Material.SUGAR_CANE || itemType == Material.CACTUS) { entity.remove(); } } } } }
@EventHandler(ignoreCancelled = true, priority = EventPriority.MONITOR) public void onPlayerDeath(PlayerDeathEvent event) { Player player = event.getEntity(); World world = player.getWorld(); Location location = player.getLocation(); Collection<ItemStack> drops = event.getDrops(); if (!drops.isEmpty()) { Iterator<ItemStack> iterator = drops.iterator(); // Drop the items manually so we can add meta to prevent // PVP Protected players from collecting them. long stamp = System.currentTimeMillis() + +ITEM_PICKUP_DELAY; while (iterator.hasNext()) { itemUUIDPickupDelays.put(world.dropItemNaturally(location, iterator.next()).getUniqueId(), stamp); iterator.remove(); } } clearCooldown(player); }
@EventHandler(ignoreCancelled = true, priority = EventPriority.HIGH) public void onPlayerFish(PlayerFishEvent event) { double amount = event.getExpToDrop(); if (amount > 0) { amount = Math.ceil(amount * SettingsYML.EXP_MULTIPLIER_FISHING); ProjectileSource projectileSource = event.getHook().getShooter(); if (projectileSource instanceof Player) { ItemStack stack = ((Player) projectileSource).getItemInHand(); int enchantmentLevel = stack.getEnchantmentLevel(Enchantment.LUCK); if (enchantmentLevel > 0L) { amount = Math.ceil(amount * (enchantmentLevel * SettingsYML.EXP_MULTIPLIER_LUCK_PER_LEVEL)); } } event.setExpToDrop((int) amount); } }
/** * Add ore to chest on drop * * @param event Item spawn event instance */ @EventHandler(ignoreCancelled = true, priority = EventPriority.LOWEST) public void onItemSpawn(ItemSpawnEvent event) { if (event.getEntityType() != EntityType.DROPPED_ITEM || Meta.hasMeta(event.getEntity().getItemStack()) || event.getEntity().hasMetadata("playerDrop")) return; for (int i = 0; i < MATERIALS.length; i++) { ItemStack stack = event.getEntity().getItemStack(); if (MATERIALS[i] != stack.getType()) continue; ItemStack newStack = stack.clone(); this.inventory.addItem(Meta.addMeta(newStack)); event.getEntity().setItemStack(Meta.addMeta(event.getEntity().getItemStack())); } }
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) public void onPlayerInteract(PlayerInteractEvent e) { if (!cm.isDisableChangeSpawnerType) { return; } if (e.getAction() == Action.RIGHT_CLICK_BLOCK) { if (e.getClickedBlock().getType() == Material.MOB_SPAWNER) { if (e.getItem() == null) { return; } if (e.getPlayer().isOp()) { return; } if (e.getItem().getType() == Material.MONSTER_EGG || e.getItem().getType() == Material.MONSTER_EGGS) { e.setCancelled(true); } } } }
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) public void onPlaceDispenser(final BlockPlaceEvent e) { if (!cm.tileLimitEnabled) { return; } if (e.getBlock().getType() == Material.DISPENSER) { Player p = e.getPlayer(); if (p.isOp()) { return; } int limit = NeverLagUtils.getMaxPermission(p, "neverlag.limit.dispenser."); if (limit <= 0) { limit = cm.tileLimitDefaultDispenser; } if (isLimit(e.getBlock().getLocation(), Material.DISPENSER, limit)) { e.setCancelled(true); p.sendMessage(i18n.tr("message", limit)); } } }
@EventHandler(ignoreCancelled = true, priority = EventPriority.MONITOR) public void onPlayerMove(PlayerMoveEvent event) { Player player = event.getPlayer(); if (!InventoryManager.playerIsLoaded(player)) { return; } PlayerWrapper playerWrapper = InventoryManager.get(player); if (playerWrapper.hasPet() && playerWrapper.getPet().getPassenger() != player) { LivingEntity petEntity = playerWrapper.getPet(); PetType pet = PetManager.getPetFromEntity(petEntity, player); if (pet != null && pet.getRole() != PetType.Role.COMPANION) { EntityUtils.goPetToPlayer(player, petEntity); } } }
@EventHandler(priority = EventPriority.MONITOR) public void hideAbandonedServer(PlayerQuitEvent event) { final Server local = minecraftService.getLocalServer(); if(local.startup_visibility() != ServerDoc.Visibility.PUBLIC && // If server was initially not public and local.visibility() == ServerDoc.Visibility.PUBLIC && // server was made public and event.getPlayer().hasPermission(VISIBILITY_PERMISSION)) { // someone with perms to do that is leaving... // ...check if there is still someone online with that permission for(Player player : event.getPlayer().getServer().getOnlinePlayers()) { // If someone else with perms is online, we're cool if(player != event.getPlayer() && player.hasPermission(VISIBILITY_PERMISSION)) return; } // If nobody with perms is online, make the server non-public again logger.info("Reverting server visibility to " + local.startup_visibility() + " because nobody with permissions is online"); setVisibility(local.startup_visibility()); } }
@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); } } } }
@EventHandler(ignoreCancelled = true, priority = EventPriority.HIGH) public void onEntityChangeBlock(final EntityChangeBlockEvent event) { final Entity entity = event.getEntity(); if (entity instanceof LivingEntity && !attemptBuild(entity, event.getBlock().getLocation(), null)) { event.setCancelled(true); } }
@EventHandler(ignoreCancelled = true, priority = EventPriority.HIGHEST) public void onInventoryCreative(InventoryCreativeEvent event) { HumanEntity humanEntity = event.getWhoClicked(); if (humanEntity instanceof Player && !humanEntity.hasPermission("base.command.gamemode")) { event.setCancelled(true); // humanEntity.sendMessage(ChatColor.RED + "You are not allowed to be in gamemode! Setting you to default gamemode!"); humanEntity.setGameMode(GameMode.SURVIVAL); } }
@EventHandler(ignoreCancelled = true, priority = EventPriority.HIGH) public void onPlayerInteract(PlayerInteractEvent event) { if (!event.hasBlock()) { return; } Block block = event.getClickedBlock(); Action action = event.getAction(); if (action == Action.PHYSICAL) { // Prevent players from trampling on crops or pressure plates, etc. if (!attemptBuild(event.getPlayer(), block.getLocation(), null)) { event.setCancelled(true); } } else if (action == Action.RIGHT_CLICK_BLOCK) { boolean canBuild = !BLOCK_INTERACTABLES.contains(block.getType()); // Special case for cauldron if (canBuild) { Material itemType = event.hasItem() ? event.getItem().getType() : null; if (itemType != null && ITEM_BLOCK_INTERACTABLES.containsKey(itemType) && ITEM_BLOCK_INTERACTABLES.get(itemType).contains(event.getClickedBlock().getType())) { if (block.getType() != Material.WORKBENCH || !event.getPlayer().hasPermission("utilities.openchestsilent") || !plugin.getFactionManager().getFactionAt(block).isSafezone()) { canBuild = false; } } else { MaterialData materialData = block.getState().getData(); if (materialData instanceof Cauldron) { Cauldron cauldron = (Cauldron) materialData; if (!cauldron.isEmpty() && event.hasItem() && event.getItem().getType() == Material.GLASS_BOTTLE) { canBuild = false; } } } } if (!canBuild && !attemptBuild(event.getPlayer(), block.getLocation(), ChatColor.YELLOW + "You cannot do this in the territory of %1$s" + ChatColor.YELLOW + '.', true)) { event.setCancelled(true); } } }
@EventHandler(priority = EventPriority.HIGHEST) public void onThunderChange(ThunderChangeEvent event) { if (plugin.getConfig().getString("toggle.noweather").equals(true)) { boolean storm = event.toThunderState(); if (storm) event.setCancelled(true); } }
@EventHandler(ignoreCancelled = true, priority = EventPriority.HIGH) public void onBucketEmpty(final PlayerBucketEmptyEvent event) { if (!isWithinBorder(event.getBlockClicked().getLocation())) { event.setCancelled(true); event.getPlayer().sendMessage(ChatColor.RED + "You cannot empty buckets past the border."); } }
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true) public void onUnloadChunk(ChunkUnloadEvent e) { if (!cm.hotChunkEnabled || NeverLag.getTpsWatcher().getAverageTPS() < cm.hotChunkTpsThreshold) { return; } ChunkInfo chunkInfo = new ChunkInfo(e.getChunk()); if (hotChunkRecord.contains(chunkInfo)) { e.setCancelled(true); this.addHotChunkUnloadCount(chunkInfo); } }
@EventHandler(ignoreCancelled = true, priority = EventPriority.MONITOR) public void onPlayerMove(PlayerMoveEvent event) { Location from = event.getFrom(); Location to = event.getTo(); // Player didn't move a block. if (from.getBlockX() == to.getBlockX() && from.getBlockY() == to.getBlockY() && from.getBlockZ() == to.getBlockZ()) { return; } cancelTeleport(event.getPlayer(), ChatColor.YELLOW + "You moved a block, therefore cancelling your teleport."); }
@EventHandler(ignoreCancelled = true, priority = EventPriority.MONITOR) public void onCraftItem(CraftItemEvent event) { HumanEntity humanEntity = event.getWhoClicked(); if (humanEntity instanceof Player) { Player player = (Player) humanEntity; if (event.getSlotType() == InventoryType.SlotType.RESULT && isBottledExperience(event.getCurrentItem())) { player.setLevel(0); player.setExp(0); } } }
@EventHandler(ignoreCancelled = true, priority = EventPriority.MONITOR) public void onFactionRenameMonitor(FactionRenameEvent event) { Faction faction = event.getFaction(); if (faction instanceof KothFaction) { ((KothFaction) faction).getCaptureZone().setName(event.getNewName()); } }
@TargetedEventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) public void onDamage(MatchPlayerDamageEvent event) { if(!event.isAttacker(attacker)) return; if(!(event.info() instanceof MeleeInfo)) return; // Absorbed damage is removed from the final value, so we add it back showDamage(event.victim().getBukkit(), event.cause().getFinalDamage() - event.cause().getDamage(EntityDamageEvent.DamageModifier.ABSORPTION)); }
@EventHandler(ignoreCancelled=true, priority=EventPriority.MONITOR) public void onFactionAllyCreate(FactionRelationCreateEvent event) { Set<Player> updates = new HashSet(event.getSenderFaction().getOnlinePlayers()); updates.addAll(event.getTargetFaction().getOnlinePlayers()); for (PlayerBoard board : this.playerBoards.values()) { board.addUpdates(updates); } }
private static void registerEvent(Class<? extends Event> event, EventPriority priority) { PriorityListener listener = listeners[priority.ordinal()]; Set<Class<? extends Event>> events = listener.getEvents(); if (!events.contains(event)) { events.add(event); Bukkit.getPluginManager() .registerEvent(event, listener, priority, executor, SkriptMirror.getInstance()); } }
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) public void onPlayerDamage(EntityDamageEvent event) { MatchPlayer victim = match.getParticipant(event.getEntity()); if(victim == null) return; lastDamageInfos.put(victim, eventResolver.resolveDamage(event)); }
@EventHandler(ignoreCancelled = true, priority = EventPriority.HIGHEST) public void onWitherChangeBlock(EntityChangeBlockEvent event) { Entity entity = event.getEntity(); if (entity instanceof Wither || entity instanceof EnderDragon) { event.setCancelled(true); } }
@EventHandler(priority = EventPriority.HIGHEST) public void onCommand(@Nonnull PlayerCommandPreprocessEvent event) { String label = event.getMessage().split(" ")[0].replace("/", ""); if (!commands.containsKey(label)) { return; } if (commands.get(label).stream().noneMatch(phase -> phase.getGame().isPlaying(event.getPlayer().getUniqueId()))) { event.setCancelled(true); event.getPlayer().sendMessage("Unknown command. Type \"/help\" for help."); } }
@EventHandler(ignoreCancelled = false, priority = EventPriority.HIGH) public void onPlayerInteract(PlayerInteractEvent event) { if (event.hasBlock() && event.getAction() != Action.PHYSICAL) { if (NON_TRANSPARENT_ATTACK_INTERACT_TYPES.contains(event.getClickedBlock().getType())) { cancelAttackingMillis(event.getPlayer().getUniqueId(), THRESHOLD); } } }
@EventHandler(ignoreCancelled = true, priority = EventPriority.MONITOR) public void onPlayerInteract(PlayerInteractEvent event) { if (event.getAction() == Action.RIGHT_CLICK_BLOCK) { Player player = event.getPlayer(); BlockState state = event.getClickedBlock().getState(); if (state instanceof Skull) { Skull skull = (Skull) state; player.sendMessage(ChatColor.YELLOW + "This is " + ChatColor.WHITE + (skull.getSkullType() == SkullType.PLAYER && skull.hasOwner() ? skull.getOwner() : "a " + WordUtils.capitalizeFully(skull.getSkullType().name()) + " skull") + ChatColor.YELLOW + '.'); } } }
@EventHandler(priority = EventPriority.HIGH) public void interactEntity(PlayerInteractEvent event) { if(!event.getPlayer().isOp()) { event.setCancelled(true); event.setUseInteractedBlock(Event.Result.DENY); event.setUseItemInHand(Event.Result.DENY); } }
/** * Prevent using the gun-item to damage blocks (cancels even damaging) * @param event the damage event */ @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) public void preventBlockDamageWithGun(BlockDamageEvent event) { if (event.getItemInHand() == null) return; ItemStack item = event.getItemInHand(); StandardGun gun = findGun(item); if (gun == null) // can't match it return; event.setCancelled(true); }
@EventHandler(ignoreCancelled = true, priority = EventPriority.MONITOR) public void onPlayerQuit(PlayerQuitEvent event) { if (!this.useTaskInstead) return; BukkitTask task = wallBorderTask.remove(event.getPlayer().getUniqueId()); if (task != null) { task.cancel(); } }
@EventHandler(ignoreCancelled = true, priority = EventPriority.HIGH) public void onBlockPlace(BlockPlaceEvent event) { Player player = event.getPlayer(); if (player.getWorld().getEnvironment() == World.Environment.NETHER && event.getBlock().getState() instanceof CreatureSpawner && !player.hasPermission(ProtectionListener.PROTECTION_BYPASS_PERMISSION)) { event.setCancelled(true); player.sendMessage(ChatColor.RED + "You may not place spawners in the nether."); } }