Java Code Examples for org.bukkit.event.player.PlayerBucketEmptyEvent#getPlayer()

The following examples show how to use org.bukkit.event.player.PlayerBucketEmptyEvent#getPlayer() . 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: RegionInteractListener.java    From NovaGuilds with GNU General Public License v3.0 5 votes vote down vote up
@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);
	}
}
 
Example 2
Source File: BucketsEmptiedListener.java    From Statz with GNU General Public License v3.0 4 votes vote down vote up
@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());

}
 
Example 3
Source File: IslandGuard.java    From askyblock with GNU General Public License v2.0 4 votes vote down vote up
/**
 * 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);
        }
    }
}