use of org.bukkit.util.BlockIterator in project MagicPlugin by elBukkit.
the class MagicMobCommandExecutor method onCommand.
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
if (!api.hasPermission(sender, "Magic.commands.mmob")) {
sendNoPermission(sender);
return true;
}
if (args.length == 0) {
sender.sendMessage(ChatColor.RED + "Usage: mmob [spawn|list] <type> [count]");
return true;
}
if (args[0].equalsIgnoreCase("list")) {
onListMobs(sender);
return true;
}
if (args[0].equalsIgnoreCase("clear")) {
onClearMobs(sender, args);
return true;
}
if (!args[0].equalsIgnoreCase("spawn") || args.length < 2) {
return false;
}
if (!(sender instanceof Player) && !(sender instanceof BlockCommandSender) && args.length < 6) {
sender.sendMessage(ChatColor.RED + "Usage: mmob spawn <type> <x> <y> <z> <world> [count]");
return true;
}
Location targetLocation = null;
World targetWorld = null;
Player player = (sender instanceof Player) ? (Player) sender : null;
BlockCommandSender commandBlock = (sender instanceof BlockCommandSender) ? (BlockCommandSender) sender : null;
if (args.length >= 6) {
targetWorld = Bukkit.getWorld(args[5]);
if (targetWorld == null) {
sender.sendMessage(ChatColor.RED + "Invalid world: " + ChatColor.GRAY + args[5]);
return true;
}
} else if (player != null) {
targetWorld = player.getWorld();
} else if (commandBlock != null) {
Block block = commandBlock.getBlock();
targetWorld = block.getWorld();
targetLocation = block.getLocation();
}
if (args.length >= 5) {
try {
double currentX = 0;
double currentY = 0;
double currentZ = 0;
if (player != null) {
Location currentLocation = player.getLocation();
currentX = currentLocation.getX();
currentY = currentLocation.getY();
currentZ = currentLocation.getZ();
} else if (commandBlock != null) {
Block blockLocation = commandBlock.getBlock();
currentX = blockLocation.getX();
currentY = blockLocation.getY();
currentZ = blockLocation.getZ();
}
targetLocation = new Location(targetWorld, ConfigurationUtils.overrideDouble(args[2], currentX), ConfigurationUtils.overrideDouble(args[3], currentY), ConfigurationUtils.overrideDouble(args[4], currentZ));
} catch (Exception ex) {
sender.sendMessage(ChatColor.RED + "Usage: mmob spawn <type> <x> <y> <z> <world> [count]");
return true;
}
} else if (player != null) {
Location location = player.getEyeLocation();
BlockIterator iterator = new BlockIterator(location.getWorld(), location.toVector(), location.getDirection(), 0, 64);
Block block = location.getBlock();
while (block.getType() == Material.AIR && iterator.hasNext()) {
block = iterator.next();
}
block = block.getRelative(BlockFace.UP);
targetLocation = block.getLocation();
}
if (targetLocation == null || targetLocation.getWorld() == null) {
sender.sendMessage(ChatColor.RED + "Usage: mmob spawn <type> <x> <y> <z> <world> [count]");
return true;
}
String mobKey = args[1];
int count = 1;
String countString = null;
if (args.length == 7) {
countString = args[6];
} else if (args.length == 3) {
countString = args[2];
}
if (countString != null) {
try {
count = Integer.parseInt(countString);
} catch (Exception ex) {
sender.sendMessage(ChatColor.RED + "Invalid count: " + countString);
return true;
}
}
if (count <= 0)
return true;
MageController controller = api.getController();
Entity spawned = null;
for (int i = 0; i < count; i++) {
spawned = controller.spawnMob(mobKey, targetLocation);
}
if (spawned == null) {
sender.sendMessage(ChatColor.RED + "Unknown mob type " + mobKey);
return true;
}
String name = spawned.getName();
if (name == null) {
name = mobKey;
}
sender.sendMessage(ChatColor.AQUA + "Spawned mob: " + ChatColor.LIGHT_PURPLE + name);
return true;
}
use of org.bukkit.util.BlockIterator in project askyblock by tastybento.
the class IslandGuard method onPlayerInteract.
/**
* Handles interaction with objects
*
* @param e - event
*/
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
public void onPlayerInteract(final PlayerInteractEvent e) {
if (DEBUG) {
plugin.getLogger().info(e.getEventName());
}
if (!inWorld(e.getPlayer())) {
return;
}
if (e.getPlayer().isOp() || VaultHelper.checkPerm(e.getPlayer(), Settings.PERMPREFIX + "mod.bypassprotect")) {
return;
}
if ((e.getClickedBlock() != null && plugin.getGrid().locationIsOnIsland(e.getPlayer(), e.getClickedBlock().getLocation()))) {
// You can do anything on your island
return;
}
// is driven by where the player is
if (e.getClickedBlock() == null && (e.getMaterial() != null && plugin.getGrid().playerIsOnIsland(e.getPlayer()))) {
return;
}
// Get island
Island island = plugin.getGrid().getProtectedIslandAt(e.getPlayer().getLocation());
// Check for disallowed clicked blocks
if (e.getClickedBlock() != null) {
if (DEBUG) {
plugin.getLogger().info("DEBUG: clicked block " + e.getClickedBlock());
plugin.getLogger().info("DEBUG: Material " + e.getMaterial());
}
// Look along player's sight line to see if any blocks are fire
try {
BlockIterator iter = new BlockIterator(e.getPlayer(), 10);
Block lastBlock = iter.next();
while (iter.hasNext()) {
lastBlock = iter.next();
if (DEBUG)
plugin.getLogger().info("DEBUG: lastBlock = " + lastBlock.toString());
if (lastBlock.equals(e.getClickedBlock())) {
if (DEBUG)
plugin.getLogger().info("DEBUG: found clicked block");
break;
}
if (lastBlock.getType().equals(Material.SKULL)) {
if (DEBUG)
plugin.getLogger().info("DEBUG: SKULL found");
if (island != null) {
if (!island.getIgsFlag(SettingsFlag.BREAK_BLOCKS)) {
Util.sendMessage(e.getPlayer(), ChatColor.RED + plugin.myLocale(e.getPlayer().getUniqueId()).islandProtected);
if (DEBUG)
plugin.getLogger().info("DEBUG: disallow");
e.setCancelled(true);
lastBlock.getState().update();
return;
}
} else {
if (Settings.defaultWorldSettings.get(SettingsFlag.BREAK_BLOCKS)) {
if (DEBUG)
plugin.getLogger().info("DEBUG: breaking skulls is allowed");
continue;
} else {
if (DEBUG)
plugin.getLogger().info("DEBUG: disallowed");
Util.sendMessage(e.getPlayer(), ChatColor.RED + plugin.myLocale(e.getPlayer().getUniqueId()).islandProtected);
e.setCancelled(true);
lastBlock.getState().update();
return;
}
}
} else if (lastBlock.getType().equals(Material.FIRE)) {
if (DEBUG)
plugin.getLogger().info("DEBUG: fire found");
if (island != null) {
if (!island.getIgsFlag(SettingsFlag.FIRE_EXTINGUISH)) {
Util.sendMessage(e.getPlayer(), ChatColor.RED + plugin.myLocale(e.getPlayer().getUniqueId()).islandProtected);
e.setCancelled(true);
return;
}
} else {
if (Settings.defaultWorldSettings.get(SettingsFlag.FIRE_EXTINGUISH)) {
if (DEBUG)
plugin.getLogger().info("DEBUG: extinguishing is allowed");
continue;
} else {
Util.sendMessage(e.getPlayer(), ChatColor.RED + plugin.myLocale(e.getPlayer().getUniqueId()).islandProtected);
e.setCancelled(true);
return;
}
}
}
}
} catch (Exception ex) {
// To catch at block iterator exceptions that can happen in the void or at the very top of blocks
if (DEBUG) {
plugin.getLogger().info("DEBUG: block iterator error");
ex.printStackTrace();
}
}
// Handle Shulker Boxes
if (e.getClickedBlock().getType().toString().contains("SHULKER_BOX")) {
if (island == null) {
if (!Settings.defaultWorldSettings.get(SettingsFlag.CHEST)) {
Util.sendMessage(e.getPlayer(), ChatColor.RED + plugin.myLocale(e.getPlayer().getUniqueId()).islandProtected);
e.setCancelled(true);
}
} else if (!island.getIgsFlag(SettingsFlag.CHEST)) {
Util.sendMessage(e.getPlayer(), ChatColor.RED + plugin.myLocale(e.getPlayer().getUniqueId()).islandProtected);
e.setCancelled(true);
}
return;
}
// Handle fireworks
if (e.getMaterial() != null && e.getMaterial().equals(Material.FIREWORK)) {
if (island == null) {
if (!Settings.defaultWorldSettings.get(SettingsFlag.PLACE_BLOCKS)) {
Util.sendMessage(e.getPlayer(), ChatColor.RED + plugin.myLocale(e.getPlayer().getUniqueId()).islandProtected);
e.setCancelled(true);
}
} else if (!island.getIgsFlag(SettingsFlag.PLACE_BLOCKS)) {
Util.sendMessage(e.getPlayer(), ChatColor.RED + plugin.myLocale(e.getPlayer().getUniqueId()).islandProtected);
e.setCancelled(true);
}
return;
}
switch(e.getClickedBlock().getType()) {
case WOODEN_DOOR:
case SPRUCE_DOOR:
case ACACIA_DOOR:
case DARK_OAK_DOOR:
case BIRCH_DOOR:
case JUNGLE_DOOR:
case TRAP_DOOR:
if (e.getAction().equals(Action.RIGHT_CLICK_BLOCK)) {
if (island == null) {
if (Settings.defaultWorldSettings.get(SettingsFlag.DOOR)) {
return;
} else {
Util.sendMessage(e.getPlayer(), ChatColor.RED + plugin.myLocale(e.getPlayer().getUniqueId()).islandProtected);
e.setCancelled(true);
return;
}
}
if (!island.getIgsFlag(SettingsFlag.DOOR)) {
Util.sendMessage(e.getPlayer(), ChatColor.RED + plugin.myLocale(e.getPlayer().getUniqueId()).islandProtected);
e.setCancelled(true);
return;
}
}
break;
case FENCE_GATE:
case SPRUCE_FENCE_GATE:
case ACACIA_FENCE_GATE:
case DARK_OAK_FENCE_GATE:
case BIRCH_FENCE_GATE:
case JUNGLE_FENCE_GATE:
if (island == null) {
if (Settings.defaultWorldSettings.get(SettingsFlag.GATE)) {
return;
} else {
Util.sendMessage(e.getPlayer(), ChatColor.RED + plugin.myLocale(e.getPlayer().getUniqueId()).islandProtected);
e.setCancelled(true);
return;
}
}
if (!island.getIgsFlag(SettingsFlag.GATE)) {
Util.sendMessage(e.getPlayer(), ChatColor.RED + plugin.myLocale(e.getPlayer().getUniqueId()).islandProtected);
e.setCancelled(true);
return;
}
break;
case ENDER_CHEST:
break;
case CHEST:
case TRAPPED_CHEST:
case DISPENSER:
case DROPPER:
case HOPPER:
case HOPPER_MINECART:
case STORAGE_MINECART:
if (island == null) {
if (Settings.defaultWorldSettings.get(SettingsFlag.CHEST)) {
return;
} else {
Util.sendMessage(e.getPlayer(), ChatColor.RED + plugin.myLocale(e.getPlayer().getUniqueId()).islandProtected);
e.setCancelled(true);
return;
}
}
if (!island.getIgsFlag(SettingsFlag.CHEST)) {
Util.sendMessage(e.getPlayer(), ChatColor.RED + plugin.myLocale(e.getPlayer().getUniqueId()).islandProtected);
e.setCancelled(true);
return;
}
break;
case SOIL:
// Prevent jumping on crops
if (e.getAction().equals(Action.PHYSICAL)) {
if (island == null) {
if (Settings.defaultWorldSettings.get(SettingsFlag.CROP_TRAMPLE)) {
return;
} else {
Util.sendMessage(e.getPlayer(), ChatColor.RED + plugin.myLocale(e.getPlayer().getUniqueId()).islandProtected);
e.setCancelled(true);
return;
}
}
if (!island.getIgsFlag(SettingsFlag.CROP_TRAMPLE)) {
Util.sendMessage(e.getPlayer(), ChatColor.RED + plugin.myLocale(e.getPlayer().getUniqueId()).islandProtected);
e.setCancelled(true);
return;
}
}
break;
case BREWING_STAND:
case CAULDRON:
if (island == null) {
if (Settings.defaultWorldSettings.get(SettingsFlag.BREWING)) {
return;
} else {
Util.sendMessage(e.getPlayer(), ChatColor.RED + plugin.myLocale(e.getPlayer().getUniqueId()).islandProtected);
e.setCancelled(true);
return;
}
}
if (!island.getIgsFlag(SettingsFlag.BREWING)) {
Util.sendMessage(e.getPlayer(), ChatColor.RED + plugin.myLocale(e.getPlayer().getUniqueId()).islandProtected);
e.setCancelled(true);
return;
}
break;
case DIODE:
case DIODE_BLOCK_OFF:
case DIODE_BLOCK_ON:
case REDSTONE_COMPARATOR_ON:
case REDSTONE_COMPARATOR_OFF:
case DAYLIGHT_DETECTOR:
case DAYLIGHT_DETECTOR_INVERTED:
if (island == null) {
if (Settings.defaultWorldSettings.get(SettingsFlag.REDSTONE)) {
return;
} else {
Util.sendMessage(e.getPlayer(), ChatColor.RED + plugin.myLocale(e.getPlayer().getUniqueId()).islandProtected);
e.setCancelled(true);
return;
}
}
if (!island.getIgsFlag(SettingsFlag.REDSTONE)) {
Util.sendMessage(e.getPlayer(), ChatColor.RED + plugin.myLocale(e.getPlayer().getUniqueId()).islandProtected);
e.setCancelled(true);
return;
}
break;
case ENCHANTMENT_TABLE:
if (island == null) {
if (Settings.defaultWorldSettings.get(SettingsFlag.ENCHANTING)) {
return;
} else {
Util.sendMessage(e.getPlayer(), ChatColor.RED + plugin.myLocale(e.getPlayer().getUniqueId()).islandProtected);
e.setCancelled(true);
return;
}
}
if (!island.getIgsFlag(SettingsFlag.ENCHANTING)) {
Util.sendMessage(e.getPlayer(), ChatColor.RED + plugin.myLocale(e.getPlayer().getUniqueId()).islandProtected);
e.setCancelled(true);
return;
}
break;
case FURNACE:
case BURNING_FURNACE:
if (island == null) {
if (Settings.defaultWorldSettings.get(SettingsFlag.FURNACE)) {
return;
} else {
Util.sendMessage(e.getPlayer(), ChatColor.RED + plugin.myLocale(e.getPlayer().getUniqueId()).islandProtected);
e.setCancelled(true);
return;
}
}
if (!island.getIgsFlag(SettingsFlag.FURNACE)) {
Util.sendMessage(e.getPlayer(), ChatColor.RED + plugin.myLocale(e.getPlayer().getUniqueId()).islandProtected);
e.setCancelled(true);
return;
}
break;
case ICE:
break;
case ITEM_FRAME:
break;
case JUKEBOX:
case NOTE_BLOCK:
if (island == null) {
if (DEBUG)
plugin.getLogger().info("DEBUG: Jukebox island = null");
if (Settings.defaultWorldSettings.get(SettingsFlag.MUSIC)) {
return;
} else {
if (DEBUG)
plugin.getLogger().info("DEBUG: Jukebox not allowed");
Util.sendMessage(e.getPlayer(), ChatColor.RED + plugin.myLocale(e.getPlayer().getUniqueId()).islandProtected);
e.setCancelled(true);
return;
}
}
if (!island.getIgsFlag(SettingsFlag.MUSIC)) {
if (DEBUG)
plugin.getLogger().info("DEBUG: Jukebox not allowed");
Util.sendMessage(e.getPlayer(), ChatColor.RED + plugin.myLocale(e.getPlayer().getUniqueId()).islandProtected);
e.setCancelled(true);
return;
}
break;
case PACKED_ICE:
break;
case STONE_BUTTON:
case WOOD_BUTTON:
case LEVER:
if (island == null) {
if (Settings.defaultWorldSettings.get(SettingsFlag.LEVER_BUTTON)) {
return;
} else {
Util.sendMessage(e.getPlayer(), ChatColor.RED + plugin.myLocale(e.getPlayer().getUniqueId()).islandProtected);
e.setCancelled(true);
return;
}
}
if (!island.getIgsFlag(SettingsFlag.LEVER_BUTTON)) {
Util.sendMessage(e.getPlayer(), ChatColor.RED + plugin.myLocale(e.getPlayer().getUniqueId()).islandProtected);
e.setCancelled(true);
return;
}
break;
case TNT:
break;
case WORKBENCH:
if (island == null) {
if (Settings.defaultWorldSettings.get(SettingsFlag.CRAFTING)) {
return;
} else {
Util.sendMessage(e.getPlayer(), ChatColor.RED + plugin.myLocale(e.getPlayer().getUniqueId()).islandProtected);
e.setCancelled(true);
return;
}
}
if (!island.getIgsFlag(SettingsFlag.CRAFTING)) {
Util.sendMessage(e.getPlayer(), ChatColor.RED + plugin.myLocale(e.getPlayer().getUniqueId()).islandProtected);
e.setCancelled(true);
return;
}
break;
case ANVIL:
if (island == null) {
if (Settings.defaultWorldSettings.get(SettingsFlag.ANVIL)) {
return;
} else {
Util.sendMessage(e.getPlayer(), ChatColor.RED + plugin.myLocale(e.getPlayer().getUniqueId()).islandProtected);
e.setCancelled(true);
return;
}
}
if (!island.getIgsFlag(SettingsFlag.ANVIL)) {
Util.sendMessage(e.getPlayer(), ChatColor.RED + plugin.myLocale(e.getPlayer().getUniqueId()).islandProtected);
e.setCancelled(true);
return;
}
break;
case RAILS:
case POWERED_RAIL:
case DETECTOR_RAIL:
case ACTIVATOR_RAIL:
// If they are not on an island, it's protected
if (island == null) {
if (!Settings.defaultWorldSettings.get(SettingsFlag.PLACE_BLOCKS)) {
Util.sendMessage(e.getPlayer(), ChatColor.RED + plugin.myLocale(e.getPlayer().getUniqueId()).islandProtected);
e.setCancelled(true);
}
return;
}
if (!island.getIgsFlag(SettingsFlag.PLACE_BLOCKS)) {
if (e.getMaterial() == Material.MINECART || e.getMaterial() == Material.STORAGE_MINECART || e.getMaterial() == Material.HOPPER_MINECART || e.getMaterial() == Material.EXPLOSIVE_MINECART || e.getMaterial() == Material.POWERED_MINECART) {
e.setCancelled(true);
Util.sendMessage(e.getPlayer(), ChatColor.RED + plugin.myLocale(e.getPlayer().getUniqueId()).islandProtected);
e.getPlayer().updateInventory();
return;
}
}
break;
case BEACON:
if (island == null) {
if (Settings.defaultWorldSettings.get(SettingsFlag.BEACON)) {
return;
} else {
Util.sendMessage(e.getPlayer(), ChatColor.RED + plugin.myLocale(e.getPlayer().getUniqueId()).islandProtected);
e.setCancelled(true);
return;
}
}
if (!island.getIgsFlag(SettingsFlag.BEACON)) {
Util.sendMessage(e.getPlayer(), ChatColor.RED + plugin.myLocale(e.getPlayer().getUniqueId()).islandProtected);
e.setCancelled(true);
return;
}
break;
case CAKE_BLOCK:
if (island == null) {
if (Settings.defaultWorldSettings.get(SettingsFlag.BREAK_BLOCKS)) {
return;
} else {
Util.sendMessage(e.getPlayer(), ChatColor.RED + plugin.myLocale(e.getPlayer().getUniqueId()).islandProtected);
e.setCancelled(true);
return;
}
}
if (!island.getIgsFlag(SettingsFlag.BREAK_BLOCKS)) {
Util.sendMessage(e.getPlayer(), ChatColor.RED + plugin.myLocale(e.getPlayer().getUniqueId()).islandProtected);
e.setCancelled(true);
return;
}
break;
case DRAGON_EGG:
if (island == null) {
if (Settings.defaultWorldSettings.get(SettingsFlag.BREAK_BLOCKS)) {
return;
} else {
Util.sendMessage(e.getPlayer(), ChatColor.RED + plugin.myLocale(e.getPlayer().getUniqueId()).islandProtected);
e.setCancelled(true);
return;
}
}
if (!island.getIgsFlag(SettingsFlag.BREAK_BLOCKS)) {
Util.sendMessage(e.getPlayer(), ChatColor.RED + plugin.myLocale(e.getPlayer().getUniqueId()).islandProtected);
e.setCancelled(true);
return;
}
break;
case MOB_SPAWNER:
if (island == null) {
if (Settings.defaultWorldSettings.get(SettingsFlag.BREAK_BLOCKS)) {
return;
} else {
Util.sendMessage(e.getPlayer(), ChatColor.RED + plugin.myLocale(e.getPlayer().getUniqueId()).islandProtected);
e.setCancelled(true);
return;
}
}
if (!island.getIgsFlag(SettingsFlag.BREAK_BLOCKS)) {
Util.sendMessage(e.getPlayer(), ChatColor.RED + plugin.myLocale(e.getPlayer().getUniqueId()).islandProtected);
e.setCancelled(true);
return;
}
break;
case BED_BLOCK:
if (e.getPlayer().getWorld().getEnvironment().equals(Environment.NETHER)) {
// Prevent explosions
Util.sendMessage(e.getPlayer(), ChatColor.RED + plugin.myLocale(e.getPlayer().getUniqueId()).islandProtected);
e.setCancelled(true);
return;
}
break;
default:
break;
}
}
// Check for disallowed in-hand items
if (DEBUG) {
plugin.getLogger().info("Material = " + e.getMaterial());
plugin.getLogger().info("in hand = " + Util.getPlayerInHandItems(e.getPlayer()));
}
if (e.getMaterial() != null) {
// and sugar cane
if (e.getMaterial() == Material.WOOD_DOOR || e.getMaterial() == Material.CHEST || e.getMaterial() == Material.TRAPPED_CHEST || e.getMaterial() == Material.IRON_DOOR) {
if ((island == null && Settings.defaultWorldSettings.get(SettingsFlag.PLACE_BLOCKS)) || (island != null && !island.getIgsFlag(SettingsFlag.PLACE_BLOCKS))) {
Util.sendMessage(e.getPlayer(), ChatColor.RED + plugin.myLocale(e.getPlayer().getUniqueId()).islandProtected);
e.setCancelled(true);
e.getPlayer().updateInventory();
return;
}
} else if (e.getMaterial().name().contains("BOAT") && (e.getClickedBlock() != null && !e.getClickedBlock().isLiquid())) {
// Trying to put a boat on non-liquid
if ((island == null && Settings.defaultWorldSettings.get(SettingsFlag.PLACE_BLOCKS)) || (island != null && !island.getIgsFlag(SettingsFlag.PLACE_BLOCKS))) {
Util.sendMessage(e.getPlayer(), ChatColor.RED + plugin.myLocale(e.getPlayer().getUniqueId()).islandProtected);
e.setCancelled(true);
return;
}
} else if (e.getMaterial().equals(Material.ENDER_PEARL)) {
if ((island == null && Settings.defaultWorldSettings.get(SettingsFlag.ENDER_PEARL)) || (island != null && !island.getIgsFlag(SettingsFlag.ENDER_PEARL))) {
Util.sendMessage(e.getPlayer(), ChatColor.RED + plugin.myLocale(e.getPlayer().getUniqueId()).islandProtected);
e.setCancelled(true);
}
return;
} else if (e.getMaterial().equals(Material.FLINT_AND_STEEL)) {
plugin.getLogger().info("DEBUG: flint & steel");
if (e.getClickedBlock() != null) {
if (e.getMaterial().equals(Material.OBSIDIAN)) {
plugin.getLogger().info("DEBUG: flint & steel on obsidian");
// return;
}
if (!actionAllowed(e.getPlayer(), e.getClickedBlock().getLocation(), SettingsFlag.FIRE)) {
Util.sendMessage(e.getPlayer(), ChatColor.RED + plugin.myLocale(e.getPlayer().getUniqueId()).islandProtected);
e.setCancelled(true);
}
}
return;
} else if (e.getMaterial().equals(Material.MONSTER_EGG)) {
if (DEBUG)
plugin.getLogger().info("DEBUG: allowMonsterEggs = " + island.getIgsFlag(SettingsFlag.SPAWN_EGGS));
if (!actionAllowed(e.getPlayer(), e.getClickedBlock().getLocation(), SettingsFlag.SPAWN_EGGS)) {
Util.sendMessage(e.getPlayer(), ChatColor.RED + plugin.myLocale(e.getPlayer().getUniqueId()).islandProtected);
e.setCancelled(true);
}
return;
} else if (e.getMaterial().equals(Material.POTION) && e.getItem().getDurability() != 0) {
// plugin.getLogger().info("DEBUG: potion");
try {
Potion p = Potion.fromItemStack(e.getItem());
if (p.isSplash()) {
// Splash potions are allowed only if PVP is allowed
boolean inNether = false;
if (e.getPlayer().getWorld().equals(ASkyBlock.getNetherWorld())) {
inNether = true;
}
// Check PVP
if (island == null) {
if ((inNether && Settings.defaultWorldSettings.get(SettingsFlag.NETHER_PVP) || (!inNether && Settings.defaultWorldSettings.get(SettingsFlag.PVP)))) {
return;
}
} else {
if ((inNether && island.getIgsFlag(SettingsFlag.NETHER_PVP) || (!inNether && island.getIgsFlag(SettingsFlag.PVP)))) {
return;
}
}
// Not allowed
Util.sendMessage(e.getPlayer(), ChatColor.RED + plugin.myLocale(e.getPlayer().getUniqueId()).islandProtected);
e.setCancelled(true);
}
} catch (Exception ex) {
}
}
// Everything else is okay
}
}
use of org.bukkit.util.BlockIterator in project Glowstone by GlowstoneMC.
the class ItemBucket method clickBucket.
private void clickBucket(GlowPlayer player, ItemStack holding) {
Iterator<Block> itr = new BlockIterator(player, 5);
Block target = null;
// Used to determine the side the block was clicked on:
Block previousTarget = null;
BlockType targetBlockType = null;
boolean validTarget = false;
// blocks
while (itr.hasNext()) {
previousTarget = target;
target = itr.next();
targetBlockType = ItemTable.instance().getBlock(target.getType());
if (targetBlockType instanceof BlockLiquid) {
if (((BlockLiquid) targetBlockType).isCollectible((GlowBlockState) target.getState())) {
validTarget = true;
break;
}
} else if (!target.isEmpty()) {
break;
}
}
if (target != null && validTarget) {
// Get the direction of the bucket fill
BlockFace face;
if (previousTarget != null) {
face = target.getFace(previousTarget);
} else {
face = BlockFace.SELF;
}
Material replaceWith = ((BlockLiquid) targetBlockType).getBucketType();
PlayerBucketFillEvent event = EventFactory.getInstance().callEvent(new PlayerBucketFillEvent(player, target, face, holding.getType(), holding));
if (event.isCancelled()) {
return;
}
if (player.getGameMode() != GameMode.CREATIVE) {
if (holding.getAmount() == 1) {
holding.setType(replaceWith);
} else {
holding.setAmount(holding.getAmount() - 1);
player.getInventory().addItem(new ItemStack(replaceWith));
}
}
target.setType(Material.AIR);
}
}
use of org.bukkit.util.BlockIterator in project Glowstone by GlowstoneMC.
the class GlowLivingEntity method getLineOfSight.
private List<Block> getLineOfSight(Set<Material> transparent, int maxDistance, int maxLength) {
// same limit as CraftBukkit
if (maxDistance > 120) {
maxDistance = 120;
}
LinkedList<Block> blocks = new LinkedList<>();
Iterator<Block> itr = new BlockIterator(this, maxDistance);
while (itr.hasNext()) {
Block block = itr.next();
blocks.add(block);
if (maxLength != 0 && blocks.size() > maxLength) {
blocks.removeFirst();
}
Material material = block.getType();
if (transparent == null) {
if (material != Material.AIR) {
break;
}
} else {
if (!transparent.contains(material)) {
break;
}
}
}
return blocks;
}
use of org.bukkit.util.BlockIterator in project MassiveCore by MassiveCraft.
the class DestinationUtil method getThereLocation.
public static Location getThereLocation(LivingEntity livingEntity) {
BlockIterator iter = createHeadlessIterator(livingEntity);
Block block = nextBeforeSolid(iter);
// Nothing solid in sight
if (block == null)
return null;
Location oldLocation = livingEntity.getLocation();
Location targetLocation = moveLocationToBlock(oldLocation, block);
return targetLocation;
}
Aggregations