Search in sources :

Example 6 with Island

use of com.wasteofplastic.acidisland.Island in project acidisland by tastybento.

the class EntityLimits method onCreatureSpawn.

@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
public void onCreatureSpawn(final CreatureSpawnEvent e) {
    if (DEBUG)
        plugin.getLogger().info("DEBUG: entity tracker " + e.getEventName());
    // Check world
    if (!e.getLocation().getWorld().toString().contains(Settings.worldName)) {
        return;
    }
    if (!Settings.entityLimits.containsKey(e.getEntityType())) {
        // Unknown entity limit or unlimited
        return;
    }
    boolean bypass = false;
    if (DEBUG)
        plugin.getLogger().info("DEBUG: spawn reason = " + e.getSpawnReason());
    // Check why it was spawned
    switch(e.getSpawnReason()) {
        // These reasons are due to a player being involved (usually)
        case BREEDING:
        case BUILD_IRONGOLEM:
        case BUILD_SNOWMAN:
        case BUILD_WITHER:
        case CURED:
        case EGG:
        case SPAWNER_EGG:
            // If someone in that area has the bypass permission, allow the spawning
            for (Entity entity : e.getLocation().getWorld().getNearbyEntities(e.getLocation(), 5, 5, 5)) {
                if (entity instanceof Player) {
                    Player player = (Player) entity;
                    if (player.isOp() || VaultHelper.checkPerm(player, Settings.PERMPREFIX + "mod.bypass")) {
                        // plugin.getLogger().info("DEBUG: bypass");
                        bypass = true;
                        break;
                    }
                }
            }
            break;
        default:
            break;
    }
    // Tag the entity with the island spawn location
    Island island = plugin.getGrid().getIslandAt(e.getLocation());
    if (island == null) {
        // Only count island entities
        return;
    }
    // Ignore spawn
    if (island.isSpawn()) {
        return;
    }
    if (DEBUG)
        plugin.getLogger().info("DEBUG: Checking entity limits");
    // Check if the player is at the limit
    if (atLimit(island, bypass, e.getEntity())) {
        e.setCancelled(true);
        if (!e.getSpawnReason().equals(SpawnReason.SPAWNER)) {
            for (Entity ent : e.getLocation().getWorld().getNearbyEntities(e.getLocation(), 5, 5, 5)) {
                if (ent instanceof Player) {
                    Player player = (Player) ent;
                    Util.sendMessage(player, ChatColor.RED + (plugin.myLocale(player.getUniqueId()).entityLimitReached.replace("[entity]", Util.prettifyText(e.getEntityType().toString())).replace("[number]", String.valueOf(Settings.entityLimits.get(e.getEntityType())))));
                }
            }
        }
    }
}
Also used : Entity(org.bukkit.entity.Entity) LivingEntity(org.bukkit.entity.LivingEntity) Player(org.bukkit.entity.Player) Island(com.wasteofplastic.acidisland.Island) EventHandler(org.bukkit.event.EventHandler)

Example 7 with Island

use of com.wasteofplastic.acidisland.Island in project acidisland by tastybento.

the class EntityLimits method onVillagerSpawn.

@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
public void onVillagerSpawn(final CreatureSpawnEvent e) {
    // If not an villager
    if (!(e.getEntity() instanceof Villager)) {
        return;
    }
    if (DEBUG3) {
        plugin.getLogger().info("Villager spawn event! " + e.getEventName());
        plugin.getLogger().info("Reason:" + e.getSpawnReason().toString());
        plugin.getLogger().info("Entity:" + e.getEntityType().toString());
    }
    // Only cover overworld
    if (!e.getEntity().getWorld().equals(ASkyBlock.getIslandWorld())) {
        return;
    }
    // If there's no limit - leave it
    if (Settings.villagerLimit <= 0) {
        return;
    }
    // We only care about villagers breeding, being cured or coming from a spawn egg, etc.
    if (e.getSpawnReason() != SpawnReason.SPAWNER && e.getSpawnReason() != SpawnReason.BREEDING && e.getSpawnReason() != SpawnReason.DISPENSE_EGG && e.getSpawnReason() != SpawnReason.SPAWNER_EGG && e.getSpawnReason() != SpawnReason.CURED) {
        return;
    }
    Island island = plugin.getGrid().getProtectedIslandAt(e.getLocation());
    if (island == null || island.getOwner() == null || island.isSpawn()) {
        // No island, no limit
        return;
    }
    int limit = Settings.villagerLimit * Math.max(1, plugin.getPlayers().getMembers(island.getOwner()).size());
    // plugin.getLogger().info("DEBUG: villager limit = " + limit);
    // long time = System.nanoTime();
    int pop = island.getPopulation();
    // plugin.getLogger().info("DEBUG: time = " + ((System.nanoTime() - time)*0.000000001));
    if (pop >= limit) {
        plugin.getLogger().warning("Island at " + island.getCenter().getBlockX() + "," + island.getCenter().getBlockZ() + " hit the island villager limit of " + limit);
        // plugin.getLogger().info("Stopped villager spawning on island " + island.getCenter());
        // Get all players in the area
        List<Entity> players = e.getEntity().getNearbyEntities(10, 10, 10);
        for (Entity player : players) {
            if (player instanceof Player) {
                Player p = (Player) player;
                Util.sendMessage(p, ChatColor.RED + plugin.myLocale(island.getOwner()).villagerLimitError.replace("[number]", String.valueOf(limit)));
            }
        }
        plugin.getMessages().tellTeam(island.getOwner(), ChatColor.RED + plugin.myLocale(island.getOwner()).villagerLimitError.replace("[number]", String.valueOf(limit)));
        if (e.getSpawnReason().equals(SpawnReason.CURED)) {
            // Easter Egg. Or should I say Easter Apple?
            ItemStack goldenApple = new ItemStack(Material.GOLDEN_APPLE);
            // Nerfed
            // goldenApple.setDurability((short)1);
            e.getLocation().getWorld().dropItemNaturally(e.getLocation(), goldenApple);
        }
        e.setCancelled(true);
    }
}
Also used : Entity(org.bukkit.entity.Entity) LivingEntity(org.bukkit.entity.LivingEntity) Player(org.bukkit.entity.Player) Villager(org.bukkit.entity.Villager) ItemStack(org.bukkit.inventory.ItemStack) Island(com.wasteofplastic.acidisland.Island) EventHandler(org.bukkit.event.EventHandler)

Example 8 with Island

use of com.wasteofplastic.acidisland.Island in project acidisland 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
    }
}
Also used : BlockIterator(org.bukkit.util.BlockIterator) Potion(org.bukkit.potion.Potion) Block(org.bukkit.block.Block) ASkyBlock(com.wasteofplastic.acidisland.ASkyBlock) Island(com.wasteofplastic.acidisland.Island) EventHandler(org.bukkit.event.EventHandler)

Example 9 with Island

use of com.wasteofplastic.acidisland.Island in project acidisland by tastybento.

the class IslandGuard method onBucketFill.

@EventHandler(priority = EventPriority.LOW)
public void onBucketFill(final PlayerBucketFillEvent e) {
    if (DEBUG) {
        plugin.getLogger().info(e.getEventName());
    }
    if (inWorld(e.getPlayer())) {
        // This permission bypasses protection
        if (VaultHelper.checkPerm(e.getPlayer(), Settings.PERMPREFIX + "mod.bypassprotect")) {
            return;
        }
        Island island = plugin.getGrid().getProtectedIslandAt(e.getBlockClicked().getLocation());
        if (island != null) {
            if (island.getMembers().contains(e.getPlayer().getUniqueId())) {
                return;
            }
            if (island.getIgsFlag(SettingsFlag.COLLECT_LAVA) && e.getItemStack().getType().equals(Material.LAVA_BUCKET)) {
                return;
            }
            if (island.getIgsFlag(SettingsFlag.COLLECT_WATER) && e.getItemStack().getType().equals(Material.WATER_BUCKET)) {
                return;
            }
            if (island.getIgsFlag(SettingsFlag.MILKING) && e.getItemStack().getType().equals(Material.MILK_BUCKET)) {
                return;
            }
            if (island.getIgsFlag(SettingsFlag.BUCKET)) {
                return;
            }
        } else {
            // Null
            if (Settings.defaultWorldSettings.get(SettingsFlag.BUCKET)) {
                return;
            }
        }
        // Not allowed
        Util.sendMessage(e.getPlayer(), ChatColor.RED + plugin.myLocale(e.getPlayer().getUniqueId()).islandProtected);
        e.setCancelled(true);
    }
}
Also used : Island(com.wasteofplastic.acidisland.Island) EventHandler(org.bukkit.event.EventHandler)

Example 10 with Island

use of com.wasteofplastic.acidisland.Island in project acidisland by tastybento.

the class IslandGuard method onVehicleMove.

@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
public void onVehicleMove(final VehicleMoveEvent e) {
    if (DEBUG)
        plugin.getLogger().info("DEBUG: vehicle move = " + e.getVehicle());
    if (!inWorld(e.getVehicle())) {
        return;
    }
    Entity passenger = e.getVehicle().getPassenger();
    if (passenger == null || !(passenger instanceof Player)) {
        return;
    }
    Player player = (Player) passenger;
    if (plugin.getGrid() == null) {
        if (DEBUG)
            plugin.getLogger().info("DEBUG: grid = null");
        return;
    }
    Island islandTo = plugin.getGrid().getProtectedIslandAt(e.getTo());
    // Announcement entering
    Island islandFrom = plugin.getGrid().getProtectedIslandAt(e.getFrom());
    // plugin.getLogger().info("islandFrom = " + islandFrom);
    if (islandTo != null && (islandTo.getOwner() != null || islandTo.isSpawn())) {
        // Lock check
        if (islandTo.isLocked() || plugin.getPlayers().isBanned(islandTo.getOwner(), player.getUniqueId())) {
            if (!islandTo.getMembers().contains(player.getUniqueId()) && !player.isOp() && !VaultHelper.checkPerm(player, Settings.PERMPREFIX + "mod.bypassprotect") && !VaultHelper.checkPerm(player, Settings.PERMPREFIX + "mod.bypasslock")) {
                Util.sendMessage(player, ChatColor.RED + plugin.myLocale(player.getUniqueId()).lockIslandLocked);
                // Check if the player is within the border a lot
                int minX = Math.max(islandTo.getMinProtectedX() - e.getTo().getBlockX(), e.getTo().getBlockX() - (islandTo.getMinProtectedX() + islandTo.getProtectionSize()));
                int minZ = Math.max(islandTo.getMinProtectedZ() - e.getTo().getBlockZ(), e.getTo().getBlockZ() - (islandTo.getMinProtectedZ() + islandTo.getProtectionSize()));
                int minMin = Math.max(minX, minZ);
                // plugin.getLogger().info("DEBUG: " + minMin);
                if (minMin < 1) {
                    Vector v = e.getVehicle().getLocation().toVector().subtract(islandTo.getCenter().toVector()).normalize().multiply(new Vector(1.2, 0, 1.2));
                    if (DEBUG)
                        plugin.getLogger().info("DEBUG: direction vector = " + v);
                    e.getVehicle().setVelocity(v);
                }
                if (minMin < -1) {
                    // Teleport player
                    plugin.getGrid().homeTeleport(player);
                }
                return;
            }
        }
    }
    if (islandTo != null && islandFrom == null) {
        // Entering
        if (islandTo.getOwner() != null && (islandTo.isLocked() || plugin.getPlayers().isBanned(islandTo.getOwner(), player.getUniqueId()))) {
            Util.sendMessage(player, ChatColor.RED + plugin.myLocale(player.getUniqueId()).lockIslandLocked);
        }
        if (islandTo.isSpawn()) {
            if (!plugin.myLocale(player.getUniqueId()).lockEnteringSpawn.isEmpty()) {
                if (islandTo.getIgsFlag(SettingsFlag.ENTER_EXIT_MESSAGES)) {
                    Util.sendMessage(player, plugin.myLocale(player.getUniqueId()).lockEnteringSpawn);
                }
            }
        } else {
            if (islandTo.getOwner() != null && !plugin.myLocale(player.getUniqueId()).lockNowEntering.isEmpty()) {
                if (islandTo.getIgsFlag(SettingsFlag.ENTER_EXIT_MESSAGES)) {
                    Util.sendEnterExit(player, plugin.myLocale(player.getUniqueId()).lockNowEntering.replace("[name]", plugin.getGrid().getIslandName(islandTo.getOwner())));
                }
            }
        }
        // Fire entry event
        final IslandEnterEvent event = new IslandEnterEvent(player.getUniqueId(), islandTo, e.getTo());
        plugin.getServer().getPluginManager().callEvent(event);
    } else if (islandTo == null && islandFrom != null) {
        // Leaving
        if (islandFrom.isSpawn()) {
            // Leaving
            if (!plugin.myLocale(player.getUniqueId()).lockLeavingSpawn.isEmpty()) {
                if (islandFrom.getIgsFlag(SettingsFlag.ENTER_EXIT_MESSAGES)) {
                    Util.sendMessage(player, plugin.myLocale(player.getUniqueId()).lockLeavingSpawn);
                }
            }
        } else {
            if (islandFrom.getOwner() != null && !plugin.myLocale(player.getUniqueId()).lockNowLeaving.isEmpty()) {
                if (islandFrom.getIgsFlag(SettingsFlag.ENTER_EXIT_MESSAGES)) {
                    Util.sendEnterExit(player, plugin.myLocale(player.getUniqueId()).lockNowLeaving.replace("[name]", plugin.getGrid().getIslandName(islandFrom.getOwner())));
                }
            }
        }
        // Fire exit event
        final IslandExitEvent event = new IslandExitEvent(player.getUniqueId(), islandFrom, e.getFrom());
        plugin.getServer().getPluginManager().callEvent(event);
    } else if (islandTo != null && islandFrom != null && !islandTo.equals(islandFrom)) {
        // Adjacent islands or overlapping protections
        if (islandFrom.isSpawn()) {
            // Leaving
            if (islandFrom.getIgsFlag(SettingsFlag.ENTER_EXIT_MESSAGES)) {
                Util.sendMessage(player, plugin.myLocale(player.getUniqueId()).lockLeavingSpawn);
            }
        } else if (islandFrom.getOwner() != null) {
            if (islandFrom.getIgsFlag(SettingsFlag.ENTER_EXIT_MESSAGES)) {
                Util.sendEnterExit(player, plugin.myLocale(player.getUniqueId()).lockNowLeaving.replace("[name]", plugin.getGrid().getIslandName(islandFrom.getOwner())));
            }
        }
        if (islandTo.isSpawn()) {
            if (islandTo.getIgsFlag(SettingsFlag.ENTER_EXIT_MESSAGES)) {
                Util.sendMessage(player, plugin.myLocale(player.getUniqueId()).lockEnteringSpawn);
            }
        } else if (islandTo.getOwner() != null) {
            if (islandTo.getIgsFlag(SettingsFlag.ENTER_EXIT_MESSAGES)) {
                Util.sendEnterExit(player, plugin.myLocale(player.getUniqueId()).lockNowEntering.replace("[name]", plugin.getGrid().getIslandName(islandTo.getOwner())));
            }
        }
        // Fire exit event
        final IslandExitEvent event = new IslandExitEvent(player.getUniqueId(), islandFrom, e.getFrom());
        plugin.getServer().getPluginManager().callEvent(event);
        // Fire entry event
        final IslandEnterEvent event2 = new IslandEnterEvent(player.getUniqueId(), islandTo, e.getTo());
        plugin.getServer().getPluginManager().callEvent(event2);
    }
}
Also used : IslandEnterEvent(com.wasteofplastic.acidisland.events.IslandEnterEvent) Entity(org.bukkit.entity.Entity) LivingEntity(org.bukkit.entity.LivingEntity) Player(org.bukkit.entity.Player) IslandExitEvent(com.wasteofplastic.acidisland.events.IslandExitEvent) Island(com.wasteofplastic.acidisland.Island) Vector(org.bukkit.util.Vector) EventHandler(org.bukkit.event.EventHandler)

Aggregations

Island (com.wasteofplastic.acidisland.Island)57 EventHandler (org.bukkit.event.EventHandler)42 Player (org.bukkit.entity.Player)27 UUID (java.util.UUID)13 Location (org.bukkit.Location)12 LivingEntity (org.bukkit.entity.LivingEntity)8 ItemStack (org.bukkit.inventory.ItemStack)8 ArrayList (java.util.ArrayList)7 Entity (org.bukkit.entity.Entity)7 Animals (org.bukkit.entity.Animals)6 ASkyBlock (com.wasteofplastic.acidisland.ASkyBlock)5 IslandEnterEvent (com.wasteofplastic.acidisland.events.IslandEnterEvent)5 Material (org.bukkit.Material)5 Block (org.bukkit.block.Block)5 BukkitRunnable (org.bukkit.scheduler.BukkitRunnable)5 IslandExitEvent (com.wasteofplastic.acidisland.events.IslandExitEvent)4 Inventory (org.bukkit.inventory.Inventory)4 BlockIterator (org.bukkit.util.BlockIterator)4 Vector (org.bukkit.util.Vector)4 SettingsFlag (com.wasteofplastic.acidisland.Island.SettingsFlag)3