org.bukkit.event.EventHandler Java Examples
The following examples show how to use
org.bukkit.event.EventHandler.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: WarpPowderListener.java From BedWars with GNU Lesser General Public License v3.0 | 6 votes |
@EventHandler public void onMove(PlayerMoveEvent event) { Player player = event.getPlayer(); if (event.isCancelled() || !Main.isPlayerInGame(player)) { return; } if (event.getFrom().getBlock().equals(event.getTo().getBlock())) { return; } GamePlayer gPlayer = Main.getPlayerGameProfile(player); Game game = gPlayer.getGame(); if (gPlayer.isSpectator) { return; } WarpPowder warpPowder = (WarpPowder) game.getFirstActivedSpecialItemOfPlayer(player, WarpPowder.class); if (warpPowder != null) { warpPowder.cancelTeleport(true, true); } }
Example #2
Source File: PlayerInteractListener.java From IridiumSkyblock with GNU General Public License v2.0 | 6 votes |
@EventHandler public void onPlayerInteractEntity(PlayerInteractEntityEvent event) { try { final Player player = event.getPlayer(); final User user = User.getUser(player); final Entity rightClicked = event.getRightClicked(); final Location location = rightClicked.getLocation(); final IslandManager islandManager = IridiumSkyblock.getIslandManager(); final Island island = islandManager.getIslandViaLocation(location); if (island == null) return; if (island.getPermissions(user).interact) return; event.setCancelled(true); } catch (Exception e) { IridiumSkyblock.getInstance().sendErrorMessage(e); } }
Example #3
Source File: EventFilterMatchModule.java From PGM with GNU Affero General Public License v3.0 | 6 votes |
@EventHandler(priority = EventPriority.HIGHEST) public void onInteract(final PlayerInteractEvent event) { if (cancelUnlessInteracting(event, event.getPlayer())) { // Allow the how-to book to be read if (event.getMaterial() == Material.WRITTEN_BOOK) { event.setUseItemInHand(Event.Result.ALLOW); } MatchPlayer player = match.getPlayer(event.getPlayer()); if (player == null) return; ClickType clickType = convertClick(event.getAction(), event.getPlayer()); if (clickType == null) return; match.callEvent( new ObserverInteractEvent( player, clickType, event.getClickedBlock(), null, event.getItem())); } }
Example #4
Source File: WorldListener.java From BedWars with GNU Lesser General Public License v3.0 | 6 votes |
@EventHandler public void onCreatureSpawn(CreatureSpawnEvent event) { if (event.isCancelled() || event.getSpawnReason() == SpawnReason.CUSTOM) { return; } for (String gameName : Main.getGameNames()) { Game game = Main.getGame(gameName); if (game.getStatus() != GameStatus.DISABLED) // prevent creature spawn everytime, not just in game if (/*(game.getStatus() == GameStatus.RUNNING || game.getStatus() == GameStatus.GAME_END_CELEBRATING) &&*/ game.getOriginalOrInheritedPreventSpawningMobs()) { if (GameCreator.isInArea(event.getLocation(), game.getPos1(), game.getPos2())) { event.setCancelled(true); return; //} } else /*if (game.getStatus() == GameStatus.WAITING) {*/ if (game.getLobbyWorld() == event.getLocation().getWorld()) { if (event.getLocation().distanceSquared(game.getLobbySpawn()) <= Math .pow(Main.getConfigurator().config.getInt("prevent-lobby-spawn-mobs-in-radius"), 2)) { event.setCancelled(true); return; } } } } }
Example #5
Source File: TeamChestListener.java From BedWars with GNU Lesser General Public License v3.0 | 6 votes |
@EventHandler public void onTeamChestBuilt(BedwarsPlayerBuildBlock event) { if (event.isCancelled()) { return; } Block block = event.getBlock(); RunningTeam team = event.getTeam(); if (block.getType() != Material.ENDER_CHEST) { return; } String unhidden = APIUtils.unhashFromInvisibleStringStartsWith(event.getItemInHand(), TEAM_CHEST_PREFIX); if (unhidden != null || Main.getConfigurator().config.getBoolean("specials.teamchest.turn-all-enderchests-to-teamchests")) { team.addTeamChest(block); String message = i18n("team_chest_placed"); for (Player pl : team.getConnectedPlayers()) { pl.sendMessage(message); } } }
Example #6
Source File: GolemListener.java From BedWars with GNU Lesser General Public License v3.0 | 6 votes |
@EventHandler public void onGolemDeath(EntityDeathEvent event) { if (!(event.getEntity() instanceof IronGolem)) { return; } IronGolem ironGolem = (IronGolem) event.getEntity(); for (String name : Main.getGameNames()) { Game game = Main.getGame(name); if ((game.getStatus() == GameStatus.RUNNING || game.getStatus() == GameStatus.GAME_END_CELEBRATING) && ironGolem.getWorld().equals(game.getGameWorld())) { List<SpecialItem> golems = game.getActivedSpecialItems(Golem.class); for (SpecialItem item : golems) { if (item instanceof Golem) { Golem golem = (Golem) item; if (golem.getEntity().equals(ironGolem)) { event.getDrops().clear(); } } } } } }
Example #7
Source File: EntityDamageByEntityListener.java From IridiumSkyblock with GNU General Public License v2.0 | 6 votes |
@EventHandler public void onEntityDamageEvent(EntityDamageEvent event) { final Entity damagee = event.getEntity(); if (!(damagee instanceof Player)) return; final Player player = (Player) damagee; final User user = User.getUser(player); final Location damageeLocation = damagee.getLocation(); final IslandManager islandManager = IridiumSkyblock.getIslandManager(); final Island island = islandManager.getIslandViaLocation(damageeLocation); if (island == null) return; //The user is visiting this island, so disable damage if (user.islandID != island.getId() && IridiumSkyblock.getConfiguration().disablePvPOnIslands) { event.setCancelled(true); } }
Example #8
Source File: FallTracker.java From PGM with GNU Affero General Public License v3.0 | 6 votes |
@EventHandler(priority = EventPriority.MONITOR) public void onPlayerSpleef(final PlayerSpleefEvent event) { MatchPlayer victim = event.getVictim(); FallState fall = this.falls.get(victim); if (fall == null || !fall.isStarted) { if (fall != null) { // End the existing fall and replace it with the spleef endFall(fall); } fall = new FallState(victim, FallInfo.From.GROUND, event.getSpleefInfo()); fall.isStarted = true; Location loc = victim.getBukkit().getLocation(); fall.isClimbing = Materials.isClimbable(loc); fall.isSwimming = Materials.isWater(loc); fall.isInLava = Materials.isLava(loc); this.falls.put(victim, fall); logger.fine("Spleefed " + fall); } }
Example #9
Source File: CommandEventHandler.java From GriefDefender with MIT License | 6 votes |
@EventHandler(priority = EventPriority.MONITOR) public void onPlayerChatPost(AsyncPlayerChatEvent event) { final Player player = event.getPlayer(); final Iterator<Player> iterator = event.getRecipients().iterator(); while (iterator.hasNext()) { final Player receiver = iterator.next(); if (receiver == player) { continue; } final GDPlayerData receiverData = GriefDefenderPlugin.getInstance().dataStore.getOrCreatePlayerData(receiver.getWorld(), receiver.getUniqueId()); if (receiverData.isRecordingChat()) { iterator.remove(); final String s = String.format(event.getFormat(), event.getPlayer().getDisplayName(), event.getMessage()); final Component message = LegacyComponentSerializer.legacy().deserialize(s, '&'); final Component component = TextComponent.builder() .append(TextComponent.builder() .append(message) .hoverEvent(HoverEvent.showText(TextComponent.of(formatter.format(Instant.now())))) .build()) .build(); receiverData.chatLines.add(component); } } }
Example #10
Source File: CoreMatchModule.java From PGM with GNU Affero General Public License v3.0 | 6 votes |
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) public void leakCheck(final BlockTransformEvent event) { if (event.getWorld() != this.match.getWorld()) return; if (event.getNewState().getType() == Material.STATIONARY_LAVA) { Vector blockVector = BlockVectors.center(event.getNewState()).toVector(); for (Core core : this.cores) { if (!core.hasLeaked() && core.getLeakRegion().contains(blockVector)) { // core has leaked core.markLeaked(); this.match.callEvent(new CoreLeakEvent(this.match, core, event.getNewState())); this.match.callEvent( new GoalCompleteEvent( this.match, core, core.getOwner(), false, core.getContributions())); } } } }
Example #11
Source File: DestroyableMatchModule.java From PGM with GNU Affero General Public License v3.0 | 6 votes |
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) public void processBlockDamage(BlockDamageEvent event) { if (this.match.getWorld() != event.getBlock().getWorld()) return; Block block = event.getBlock(); MaterialData material = block.getState().getData(); MatchPlayer player = this.match.getPlayer(event.getPlayer()); for (Destroyable destroyable : this.destroyables) { if (player != null && player.getParty() == destroyable.getOwner() && !destroyable.isDestroyed() && destroyable.getBlockRegion().contains(block) && destroyable.hasMaterial(material)) { event.setCancelled(true); // TODO: translate this player.sendWarning(TextComponent.of("You may not damage your own objective.")); } } }
Example #12
Source File: PlayerListener.java From BedWars with GNU Lesser General Public License v3.0 | 6 votes |
@EventHandler public void onLaunchProjectile(ProjectileLaunchEvent event) { if (event.isCancelled()) { return; } Projectile projectile = event.getEntity(); if (projectile.getShooter() instanceof Player) { Player damager = (Player) projectile.getShooter(); if (Main.isPlayerInGame(damager)) { if (Main.getPlayerGameProfile(damager).isSpectator) { event.setCancelled(true); } } } }
Example #13
Source File: DoubleJumpMatchModule.java From PGM with GNU Affero General Public License v3.0 | 6 votes |
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) public void onPlayerToggleFlight(final PlayerToggleFlightEvent event) { Player player = event.getPlayer(); Jumper jumper = this.jumpers.get(player); if (jumper == null) return; if (event.isFlying()) { event.setCancelled(true); this.setCharge(jumper, 0f); this.refreshJump(player); // calculate jump Vector impulse = player.getLocation().getDirection(); impulse.setY(0.75 + Math.abs(impulse.getY()) * 0.5); impulse.multiply(jumper.kit.power / 3f); event.getPlayer().setVelocity(impulse); player.getWorld().playSound(player.getLocation(), Sound.ZOMBIE_INFECT, 0.5f, 1.8f); } }
Example #14
Source File: TrapListener.java From BedWars with GNU Lesser General Public License v3.0 | 6 votes |
@EventHandler public void onTrapBuild(BedwarsPlayerBuildBlock event) { if (event.isCancelled()) { return; } ItemStack trapItem = event.getItemInHand(); String unhidden = APIUtils.unhashFromInvisibleStringStartsWith(trapItem, TRAP_PREFIX); if (unhidden != null) { int classID = Integer.parseInt(unhidden.split(":")[2]); for (SpecialItem special : event.getGame().getActivedSpecialItems(Trap.class)) { Trap trap = (Trap) special; if (System.identityHashCode(trap) == classID) { trap.place(event.getBlock().getLocation()); event.getPlayer().sendMessage(i18n("trap_built")); return; } } } }
Example #15
Source File: TeamSelectorInventory.java From BedWars with GNU Lesser General Public License v3.0 | 6 votes |
@EventHandler public void onPostAction(PostActionEvent event) { if (event.getFormat() != simpleGuiFormat) { return; } Player player = event.getPlayer(); MapReader reader = event.getItem().getReader(); if (reader.containsKey("team")) { Team team = (Team) reader.get("team"); game.selectTeam(Main.getPlayerGameProfile(player), team.getName()); player.closeInventory(); repaint(); openedForPlayers.remove(player); } }
Example #16
Source File: AntiGriefListener.java From PGM with GNU Affero General Public License v3.0 | 6 votes |
@EventHandler(priority = EventPriority.HIGHEST) public void checkDefuse(final PlayerInteractEvent event) { ItemStack hand = event.getPlayer().getItemInHand(); if (hand == null || hand.getType() != DEFUSE_ITEM) return; MatchPlayer clicker = this.mm.getPlayer(event.getPlayer()); if (clicker != null && clicker.isObserving() && clicker.getBukkit().hasPermission(Permissions.DEFUSE)) { if (event.getAction() == Action.RIGHT_CLICK_AIR) { this.obsTntDefuse(clicker, event.getPlayer().getLocation()); } else if (event.getAction() == Action.RIGHT_CLICK_BLOCK) { this.obsTntDefuse(clicker, event.getClickedBlock().getLocation()); } } }
Example #17
Source File: KitMatchModule.java From PGM with GNU Affero General Public License v3.0 | 6 votes |
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) public void onGrenadeLaunch(final ProjectileLaunchEvent event) { if (event.getEntity().getShooter() instanceof Player) { Player player = (Player) event.getEntity().getShooter(); ItemStack stack = player.getItemInHand(); if (stack != null) { // special case for grenade arrows if (stack.getType() == Material.BOW) { int arrows = player.getInventory().first(Material.ARROW); if (arrows == -1) return; stack = player.getInventory().getItem(arrows); } Grenade grenade = Grenade.ITEM_TAG.get(stack); if (grenade != null) { grenade.set(PGM.get(), event.getEntity()); } } } }
Example #18
Source File: BlockEventHandler.java From GriefDefender with MIT License | 6 votes |
@EventHandler(priority = EventPriority.LOWEST) public void onBlockDispense(BlockDispenseEvent event) { final Block block = event.getBlock(); final World world = event.getBlock().getWorld(); if (!GriefDefenderPlugin.getInstance().claimsEnabledForWorld(world.getUID())) { return; } final Location location = block.getLocation(); final GDClaimManager claimWorldManager = GriefDefenderPlugin.getInstance().dataStore.getClaimWorldManager(world.getUID()); final GDChunk gpChunk = claimWorldManager.getChunk(block.getChunk()); final GDPermissionUser user = gpChunk.getBlockOwner(location); if (user != null) { final BlockFace face = NMSUtil.getInstance().getFacing(block); final Location faceLocation = BlockUtil.getInstance().getBlockRelative(location, face); final GDClaim targetClaim = this.storage.getClaimAt(faceLocation); final ItemStack activeItem = user != null && user.getOnlinePlayer() != null ? NMSUtil.getInstance().getActiveItem(user.getOnlinePlayer()) : null; final Tristate result = GDPermissionManager.getInstance().getFinalPermission(event, location, targetClaim, Flags.INTERACT_BLOCK_SECONDARY, activeItem, event.getBlock(), user, TrustTypes.BUILDER, true); if (result == Tristate.FALSE) { event.setCancelled(true); } else { GDCauseStackManager.getInstance().pushCause(user); } } }
Example #19
Source File: ArrowBlockerListener.java From BedWars with GNU Lesser General Public License v3.0 | 6 votes |
@EventHandler(priority = EventPriority.HIGH) public void onDamage(EntityDamageEvent event) { Entity entity = event.getEntity(); if (!(entity instanceof Player)) { return; } Player player = ((Player) entity).getPlayer(); if (!Main.isPlayerInGame(player)) { return; } GamePlayer gPlayer = Main.getPlayerGameProfile(player); Game game = gPlayer.getGame(); if (gPlayer.isSpectator) { return; } ArrowBlocker arrowBlocker = (ArrowBlocker) game.getFirstActivedSpecialItemOfPlayer(player, ArrowBlocker.class); if (arrowBlocker != null && event.getCause() == EntityDamageEvent.DamageCause.PROJECTILE) { event.setCancelled(true); } }
Example #20
Source File: WorldEventHandler.java From GriefDefender with MIT License | 6 votes |
@EventHandler(priority = EventPriority.LOWEST) public void onWorldSave(WorldSaveEvent event) { if (!GriefDefenderPlugin.getInstance().claimsEnabledForWorld(event.getWorld().getUID())) { return; } GDTimings.WORLD_SAVE_EVENT.startTiming(); GDClaimManager claimWorldManager = GriefDefenderPlugin.getInstance().dataStore.getClaimWorldManager(event.getWorld().getUID()); if (claimWorldManager == null) { GDTimings.WORLD_SAVE_EVENT.stopTiming(); return; } claimWorldManager.save(); GDTimings.WORLD_SAVE_EVENT.stopTiming(); }
Example #21
Source File: FreezeMatchModule.java From PGM with GNU Affero General Public License v3.0 | 5 votes |
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true) public void onPlayerMove(final PlayerMoveEvent event) { if (freeze.isFrozen(event.getPlayer())) { Location old = event.getFrom(); old.setPitch(event.getTo().getPitch()); old.setYaw(event.getTo().getYaw()); event.setTo(old); } }
Example #22
Source File: MatchManagerImpl.java From PGM with GNU Affero General Public License v3.0 | 5 votes |
@EventHandler public void onMatchLoad(MatchLoadEvent event) { final Match match = event.getMatch(); matchById.put(checkNotNull(match).getId(), match); matchByWorld.put(checkNotNull(match.getWorld()).getName(), match); logger.info("Loaded match-" + match.getId() + " (" + match.getMap().getId() + ")"); if (unloadNonMatches) { for (World world : PGM.get().getServer().getWorlds()) { onNonMatchUnload(world); } } }
Example #23
Source File: ItemCraftListener.java From IridiumSkyblock with GNU General Public License v2.0 | 5 votes |
@EventHandler public void onItemCraft(PrepareItemCraftEvent event) { try { final CraftingInventory inventory = event.getInventory(); if (inventory.getResult() == null) return; for (ItemStack itemStack : inventory.getContents()) { if (Utils.getCrystals(itemStack) == 0) continue; inventory.setResult(null); return; } } catch (Exception e) { IridiumSkyblock.getInstance().sendErrorMessage(e); } }
Example #24
Source File: PickerMatchModule.java From PGM with GNU Affero General Public License v3.0 | 5 votes |
@EventHandler(priority = EventPriority.HIGHEST) public void rightClickIcon(final ObserverInteractEvent event) { final boolean right = event.getClickType() == ClickType.RIGHT; final boolean left = event.getClickType() == ClickType.LEFT; if ((!right && !left) || InventoryUtils.isNothing(event.getClickedItem())) return; final ItemStack hand = event.getClickedItem(); String displayName = hand.getItemMeta().getDisplayName(); if (displayName == null) return; final MatchPlayer player = event.getPlayer(); if (!canUse(player)) return; boolean handled = false; final JoinMatchModule jmm = match.needModule(JoinMatchModule.class); if (hand.getType() == Button.JOIN.material) { handled = true; if (right && canOpenWindow(player) && settingEnabled(player, true)) { showWindow(player); } else { // If there is nothing to pick or setting is disabled, just join immediately jmm.join(player, null); } } else if (hand.getType() == Button.LEAVE.material && left) { jmm.leave(player); } if (handled) { event.setCancelled(true); // Unfortunately, not opening the window seems to cause the player to put the helmet // on their head, no matter what we do server-side. So, we have to force an inventory // update to resync them. player.getBukkit().updateInventory(); } }
Example #25
Source File: PlayerListener.java From BedWars with GNU Lesser General Public License v3.0 | 5 votes |
@EventHandler public void onEntityInteract(PlayerInteractEntityEvent event) { if (event.isCancelled()) { return; } Player player = event.getPlayer(); if (Main.isPlayerInGame(player)) { GamePlayer gPlayer = Main.getPlayerGameProfile(player); Game game = gPlayer.getGame(); if (game.getStatus() == GameStatus.WAITING || gPlayer.isSpectator) { event.setCancelled(true); } } }
Example #26
Source File: TNTSheepListener.java From BedWars with GNU Lesser General Public License v3.0 | 5 votes |
@EventHandler public void onTNTSheepUsed(PlayerInteractEvent event) { Player player = event.getPlayer(); if (!Main.isPlayerInGame(player)) { return; } GamePlayer gamePlayer = Main.getPlayerGameProfile(player); Game game = gamePlayer.getGame(); if (event.getAction() == Action.RIGHT_CLICK_AIR || event.getAction() == Action.RIGHT_CLICK_BLOCK) { if (game.getStatus() == GameStatus.RUNNING && !gamePlayer.isSpectator && event.getItem() != null) { ItemStack stack = event.getItem(); String unhidden = APIUtils.unhashFromInvisibleStringStartsWith(stack, TNT_SHEEP_PREFIX); if (unhidden != null) { event.setCancelled(true); double speed = Double.parseDouble(unhidden.split(":")[2]); double follow = Double.parseDouble(unhidden.split(":")[3]); double maxTargetDistance = Double.parseDouble(unhidden.split(":")[4]); int explosionTime = Integer.parseInt(unhidden.split(":")[5]); Location startLocation; if (event.getClickedBlock() == null) { startLocation = player.getLocation(); } else { startLocation = event.getClickedBlock().getRelative(BlockFace.UP).getLocation(); } TNTSheep sheep = new TNTSheep(game, player, game.getTeamOfPlayer(player), startLocation, stack, speed, follow, maxTargetDistance, explosionTime); sheep.spawn(); } } } }
Example #27
Source File: WorldListener.java From BedWars with GNU Lesser General Public License v3.0 | 5 votes |
@EventHandler public void onChunkUnload(ChunkUnloadEvent unload) { if (unload instanceof Cancellable) { Chunk chunk = unload.getChunk(); for (String name : Main.getGameNames()) { Game game = Main.getGame(name); if (game.getStatus() != GameStatus.DISABLED && game.getStatus() != GameStatus.WAITING && GameCreator.isChunkInArea(chunk, game.getPos1(), game.getPos2())) { ((Cancellable) unload).setCancelled(false); return; } } } }
Example #28
Source File: ProtectionWallListener.java From BedWars with GNU Lesser General Public License v3.0 | 5 votes |
@EventHandler public void onBlockBreak(BedwarsPlayerBreakBlock event) { final Game game = event.getGame(); final Block block = event.getBlock(); for (ProtectionWall checkedWall : getCreatedWalls(game)) { if (checkedWall != null) { for (Block wallBlock : checkedWall.getWallBlocks()) { if (wallBlock.equals(block) && !checkedWall.canBreak()) { event.setCancelled(true); } } } } }
Example #29
Source File: ListenerMenuOpenCommands.java From TrMenu with MIT License | 5 votes |
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) public void onCommand(PlayerCommandPreprocessEvent e) { Player p = e.getPlayer(); String[] cmd = e.getMessage().substring(1).split(" "); if (cmd.length > 0) { for (int i = 0; i < cmd.length; i++) { String[] read = read(cmd, i); String command = read[0]; String[] args = ArrayUtils.remove(read, 0); Menu menu = TrMenuAPI.getMenuByCommand(command); if (menu != null) { if (menu.isTransferArgs()) { if (args.length < menu.getForceTransferArgsAmount()) { TLocale.sendTo(p, "MENU.NOT-ENOUGH-ARGS", menu.getForceTransferArgsAmount()); e.setCancelled(true); return; } } else if (args.length > 0) { return; } menu.open(p, args); e.setCancelled(true); break; } } } }
Example #30
Source File: PickerMatchModule.java From PGM with GNU Affero General Public License v3.0 | 5 votes |
@EventHandler public void teamSwitch(final PlayerPartyChangeEvent event) { refreshCountsAll(); refreshKit(event.getPlayer()); if (event.getNewParty() == null) { picking.remove(event.getPlayer()); } }