/** * Gets the cancellation state of this event. Set to true if you want to * prevent buckets from placing water and so forth * * @return boolean cancellation state */ public boolean isCancelled() { return useInteractedBlock() == Result.DENY; }
/** * Sets the cancellation state of this event. A canceled event will not be * executed in the server, but will still pass to other plugins * <p> * Canceling this event will prevent use of food (player won't lose the * food item), prevent bows/snowballs/eggs from firing, etc. (player won't * lose the ammo) * * @param cancel true if you wish to cancel this event */ public void setCancelled(boolean cancel) { setUseInteractedBlock(cancel ? Result.DENY : useInteractedBlock() == Result.DENY ? Result.DEFAULT : useInteractedBlock()); setUseItemInHand(cancel ? Result.DENY : useItemInHand() == Result.DENY ? Result.DEFAULT : useItemInHand()); }
/** * Sets the new result of the login, as an enum * * @param result New result to set * @deprecated This method uses a deprecated enum from {@link * PlayerPreLoginEvent} * @see #setLoginResult(Result) */ @Deprecated public void setResult(final PlayerPreLoginEvent.Result result) { this.result = result == null ? null : Result.valueOf(result.name()); }
@EventHandler(ignoreCancelled = true) public void onPlayerCommandPreprocess(PlayerCommandPreprocessEvent event) { if (commandRegistration.dispatch(event.getPlayer(), event.getMessage().substring(1))) { event.setCancelled(true); } }
@Override public void incrementStatistic(Statistic statistic, int amount) { int initialAmount = stats.get(statistic); PlayerStatisticIncrementEvent event = EventFactory.getInstance().callEvent( new PlayerStatisticIncrementEvent(this, statistic, initialAmount, initialAmount + amount)); if (!event.isCancelled()) { stats.add(statistic, amount); } }
/** * Convenience method. Returns the material of the item represented by * this event * * @return Material the material of the item used */ public Material getMaterial() { if (!hasItem()) { return Material.AIR; } return item.getType(); }
@Override public void setSprinting(boolean sprinting) { if (EventFactory.getInstance() .callEvent(new PlayerToggleSprintEvent(this, sprinting)).isCancelled()) { return; } metadata.setBit(MetadataIndex.STATUS, StatusFlags.SPRINTING, sprinting); }
@Override public void setSneaking(boolean sneak) { if (EventFactory.getInstance() .callEvent(new PlayerToggleSneakEvent(this, sneak)).isCancelled()) { return; } metadata.setBit(MetadataIndex.STATUS, StatusFlags.SNEAKING, sneak); }
@Override public void giveExp(int xp) { PlayerExpChangeEvent event = EventFactory.getInstance() .callEvent(new PlayerExpChangeEvent(this, xp)); xp = event.getAmount(); totalExperience += xp; // gradually award levels based on xp points float value = 1.0f / getExpToLevel(); for (int i = 0; i < xp; ++i) { exp += value; if (exp >= 1) { exp -= 1; setLevel(level + 1); value = 1.0f / getExpToLevel(level); } } sendExperience(); }
public PlayerQuitEvent onPlayerQuit(Player player) { return callEvent(new PlayerQuitEvent(player, GlowstoneMessages.Player.LEFT.get(ChatColor.YELLOW, player.getName()))); }
public PlayerJoinEvent onPlayerJoin(Player player) { return callEvent(new PlayerJoinEvent(player, GlowstoneMessages.Player.JOINED.get(ChatColor.YELLOW, player.getName()))); }
public PlayerKickEvent onPlayerKick(Player player, String reason) { return callEvent(new PlayerKickEvent(player, reason, null)); }
/** * Remove a listening channel from this player. * * @param channel The channel to remove. */ public void removeChannel(String channel) { if (listeningChannels.remove(channel)) { EventFactory.getInstance().callEvent(new PlayerUnregisterChannelEvent(this, channel)); } }
/** * Add a listening channel to this player. * * @param channel The channel to add. */ public void addChannel(String channel) { checkArgument(listeningChannels.size() < 128, "Cannot add more than 127 channels!"); if (listeningChannels.add(channel)) { EventFactory.getInstance().callEvent(new PlayerRegisterChannelEvent(this, channel)); } }
@Override public void setLevel(int level) { int newLevel = Math.max(level, 0); if (newLevel != this.level) { EventFactory.getInstance().callEvent( new PlayerLevelChangeEvent(this, this.level, newLevel)); this.level = newLevel; sendExperience(); } }
@Override public void incrementStatistic(Statistic statistic, Material material, int amount) { int initialAmount = stats.get(statistic); PlayerStatisticIncrementEvent event = EventFactory.getInstance().callEvent( new PlayerStatisticIncrementEvent(this, statistic, initialAmount, initialAmount + amount, material)); if (!event.isCancelled()) { stats.add(statistic, material, amount); } }
/** * Convenience method to inform the user whether this was a block * placement event. * * @return boolean true if the item in hand was a block */ public boolean isBlockInHand() { if (!hasItem()) { return false; } return item.getType().isBlock(); }
/** * Disallows the player from logging in, with the given reason * * @param result New result for disallowing the player * @param message Kick message to display to the user * @deprecated This method uses a deprecated enum from {@link * PlayerPreLoginEvent} * @see #disallow(Result, String) */ @Deprecated public void disallow(final PlayerPreLoginEvent.Result result, final String message) { this.result = result == null ? null : Result.valueOf(result.name()); this.message = message; }
@Override public void incrementStatistic(Statistic statistic, EntityType entityType, int amount) throws IllegalArgumentException { int initialAmount = stats.get(statistic); PlayerStatisticIncrementEvent event = EventFactory.getInstance().callEvent( new PlayerStatisticIncrementEvent(this, statistic, initialAmount, initialAmount + amount, entityType)); if (!event.isCancelled()) { stats.add(statistic, entityType, amount); } }