下面列出了org.bukkit.event.player.PlayerBucketEmptyEvent#getPlayer ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
@EventHandler
public void onPlayerBucketEmpty(PlayerBucketEmptyEvent event) {
Block block = event.getBlockClicked().getRelative(event.getBlockFace());
Player player = event.getPlayer();
NovaPlayer nPlayer = PlayerManager.getPlayer(player);
if(nPlayer.getPreferences().getBypass()) {
return;
}
//Fluid protection
NovaRegion fluidProtectRegion = null;
for(NovaRegion region : plugin.getRegionManager().getRegions()) {
if(!region.getWorld().equals(block.getWorld())) {
continue;
}
Location centerLocation = region.getCenter().clone();
Location blockLocation = block.getLocation().clone();
centerLocation.setY(0);
blockLocation.setY(0);
if(blockLocation.distance(centerLocation) <= region.getDiagonal() / 2 + Config.REGION_FLUIDPROTECT.getInt()) {
fluidProtectRegion = region;
break;
}
}
if((fluidProtectRegion != null
&& (!nPlayer.hasGuild()
|| (!fluidProtectRegion.getGuild().isMember(nPlayer)
&& !fluidProtectRegion.getGuild().isAlly(nPlayer.getGuild()))))
|| (RegionManager.get(block) != null
&& (!plugin.getRegionManager().canInteract(player, block)
|| !nPlayer.hasPermission(GuildPermission.BLOCK_PLACE)))) {
event.setCancelled(true);
Message.CHAT_REGION_DENY_INTERACT.send(player);
}
}
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onBucketEmpty(final PlayerBucketEmptyEvent event) {
final PlayerStat stat = PlayerStat.BUCKETS_EMPTIED;
// Get player
final Player player = event.getPlayer();
// Do general check
if (!plugin.doGeneralCheck(player, stat))
return;
PlayerStatSpecification specification = new BucketsEmptiedSpecification(player.getUniqueId(), 1,
player.getWorld().getName());
// Update value to new stat.
plugin.getDataManager().setPlayerInfo(player.getUniqueId(), stat, specification.constructQuery());
}
/**
* Prevents emptying of buckets outside of island space
* @param e - event
*/
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
public void onBucketEmpty(final PlayerBucketEmptyEvent e) {
if (DEBUG) {
plugin.getLogger().info(e.getEventName());
}
if (inWorld(e.getPlayer())) {
Player p = e.getPlayer();
if (e.getBlockClicked() != null) {
// This is where the water or lava actually will be dumped
Block dumpBlock = e.getBlockClicked().getRelative(e.getBlockFace());
if (actionAllowed(p, dumpBlock.getLocation(), SettingsFlag.BUCKET)) {
// Check if biome is Nether and then allow water placement but fizz the water
if (e.getBlockClicked().getBiome().equals(Biome.HELL)) {
if (plugin.getServer().getVersion().contains("(MC: 1.8") || plugin.getServer().getVersion().contains("(MC: 1.7")) {
if (e.getPlayer().getItemInHand().getType().equals(Material.WATER_BUCKET)) {
e.setCancelled(true);
e.getPlayer().getItemInHand().setType(Material.BUCKET);
e.getPlayer().getWorld().playSound(e.getPlayer().getLocation(), Sound.valueOf("FIZZ"), 1F, 2F);
Util.sendMessage(e.getPlayer(), ChatColor.RED + plugin.myLocale(e.getPlayer().getUniqueId()).biomeSet.replace("[biome]", "Nether"));
}
} else {
if (Util.playerIsHolding(e.getPlayer(), Material.WATER_BUCKET)) {
e.setCancelled(true);
if (e.getPlayer().getInventory().getItemInMainHand().getType() == Material.WATER_BUCKET) {
e.getPlayer().getInventory().setItemInMainHand(new ItemStack(Material.BUCKET));
} else if (e.getPlayer().getInventory().getItemInOffHand().getType() == Material.WATER_BUCKET) {
e.getPlayer().getInventory().setItemInOffHand(new ItemStack(Material.BUCKET));
}
e.getPlayer().getWorld().playSound(e.getPlayer().getLocation(), Sound.ENTITY_CREEPER_PRIMED, 1F, 2F);
Util.sendMessage(e.getPlayer(), ChatColor.RED + plugin.myLocale(e.getPlayer().getUniqueId()).biomeSet.replace("[biome]", "Nether"));
}
}
}
return;
}
// Not allowed
Util.sendMessage(p, ChatColor.RED + plugin.myLocale(p.getUniqueId()).islandProtected);
e.setCancelled(true);
}
}
}