Search in sources :

Example 41 with Island

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

the class IslandGuard1_9 method onLingeringPotionDamage.

@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
public void onLingeringPotionDamage(final EntityDamageByEntityEvent e) {
    if (!IslandGuard.inWorld(e.getEntity().getLocation())) {
        return;
    }
    if (e.getEntity() == null || e.getEntity().getUniqueId() == null) {
        return;
    }
    if (e.getCause().equals(DamageCause.ENTITY_ATTACK) && thrownPotions.containsKey(e.getDamager().getEntityId())) {
        UUID attacker = thrownPotions.get(e.getDamager().getEntityId());
        // Self damage
        if (attacker.equals(e.getEntity().getUniqueId())) {
            return;
        }
        Island island = plugin.getGrid().getIslandAt(e.getEntity().getLocation());
        boolean inNether = false;
        if (e.getEntity().getWorld().equals(ASkyBlock.getNetherWorld())) {
            inNether = true;
        }
        // Monsters being hurt
        if (e.getEntity() instanceof Monster || e.getEntity() instanceof Slime || e.getEntity() instanceof Squid) {
            // Normal island check
            if (island != null && island.getMembers().contains(attacker)) {
                // Members always allowed
                return;
            }
            if (actionAllowed(attacker, e.getEntity().getLocation(), SettingsFlag.HURT_MONSTERS)) {
                return;
            }
            // Not allowed
            e.setCancelled(true);
            return;
        }
        // Mobs being hurt
        if (e.getEntity() instanceof Animals || e.getEntity() instanceof IronGolem || e.getEntity() instanceof Snowman || e.getEntity() instanceof Villager) {
            if (island != null && (island.getIgsFlag(SettingsFlag.HURT_MOBS) || island.getMembers().contains(attacker))) {
                return;
            }
            e.setCancelled(true);
            return;
        }
        // Establish whether PVP is allowed or not.
        boolean pvp = false;
        if ((inNether && island != null && island.getIgsFlag(SettingsFlag.NETHER_PVP) || (!inNether && island != null && island.getIgsFlag(SettingsFlag.PVP)))) {
            pvp = true;
        }
        // Players being hurt PvP
        if (e.getEntity() instanceof Player) {
            if (pvp) {
            } else {
                e.setCancelled(true);
            }
        }
    }
}
Also used : Player(org.bukkit.entity.Player) Animals(org.bukkit.entity.Animals) Squid(org.bukkit.entity.Squid) Monster(org.bukkit.entity.Monster) Villager(org.bukkit.entity.Villager) Snowman(org.bukkit.entity.Snowman) IronGolem(org.bukkit.entity.IronGolem) UUID(java.util.UUID) Slime(org.bukkit.entity.Slime) Island(com.wasteofplastic.askyblock.Island) EventHandler(org.bukkit.event.EventHandler)

Example 42 with Island

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

the class IslandGuard1_9 method actionAllowed.

/**
 * Checks if action is allowed for player in location for flag
 * @param uuid
 * @param location
 * @param flag
 * @return true if allowed
 */
private boolean actionAllowed(UUID uuid, Location location, SettingsFlag flag) {
    Player player = plugin.getServer().getPlayer(uuid);
    if (player == null) {
        return actionAllowed(location, flag);
    }
    // This permission bypasses protection
    if (player.isOp() || VaultHelper.checkPerm(player, Settings.PERMPREFIX + "mod.bypassprotect")) {
        return true;
    }
    Island island = plugin.getGrid().getProtectedIslandAt(location);
    if (island != null && (island.getIgsFlag(flag) || island.getMembers().contains(player.getUniqueId()))) {
        return true;
    }
    if (island == null && Settings.defaultWorldSettings.get(flag)) {
        return true;
    }
    return false;
}
Also used : Player(org.bukkit.entity.Player) Island(com.wasteofplastic.askyblock.Island)

Example 43 with Island

use of com.wasteofplastic.askyblock.Island 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");
                        } 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);
                }
            }
        } 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);
            }
        } 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 ignored) {
            }
        }
    // Everything else is okay
    }
}
Also used : BlockIterator(org.bukkit.util.BlockIterator) Potion(org.bukkit.potion.Potion) Block(org.bukkit.block.Block) ASkyBlock(com.wasteofplastic.askyblock.ASkyBlock) Island(com.wasteofplastic.askyblock.Island) EventHandler(org.bukkit.event.EventHandler)

Example 44 with Island

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

the class IslandGuard method onPlateStep.

/**
 * Pressure plates
 * @param e - event
 */
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
public void onPlateStep(PlayerInteractEvent e) {
    if (DEBUG) {
        plugin.getLogger().info("pressure plate = " + e.getEventName());
        plugin.getLogger().info("action = " + e.getAction());
    }
    if (!inWorld(e.getPlayer()) || !e.getAction().equals(Action.PHYSICAL) || e.getPlayer().isOp() || VaultHelper.checkPerm(e.getPlayer(), Settings.PERMPREFIX + "mod.bypassprotect") || plugin.getGrid().playerIsOnIsland(e.getPlayer())) {
        // plugin.getLogger().info("DEBUG: Not in world");
        return;
    }
    // Check island
    Island island = plugin.getGrid().getProtectedIslandAt(e.getPlayer().getLocation());
    if ((island == null && Settings.defaultWorldSettings.get(SettingsFlag.PRESSURE_PLATE))) {
        return;
    }
    if (island != null && island.getIgsFlag(SettingsFlag.PRESSURE_PLATE)) {
        return;
    }
    // Block action
    UUID playerUUID = e.getPlayer().getUniqueId();
    if (!onPlate.containsKey(playerUUID)) {
        Util.sendMessage(e.getPlayer(), ChatColor.RED + plugin.myLocale(playerUUID).islandProtected);
        Vector v = e.getPlayer().getLocation().toVector();
        onPlate.put(playerUUID, new Vector(v.getBlockX(), v.getBlockY(), v.getBlockZ()));
    }
    e.setCancelled(true);
    return;
}
Also used : UUID(java.util.UUID) Island(com.wasteofplastic.askyblock.Island) Vector(org.bukkit.util.Vector) EventHandler(org.bukkit.event.EventHandler)

Example 45 with Island

use of com.wasteofplastic.askyblock.Island in project askyblock 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 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 && !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.askyblock.events.IslandEnterEvent) Entity(org.bukkit.entity.Entity) LivingEntity(org.bukkit.entity.LivingEntity) Player(org.bukkit.entity.Player) IslandExitEvent(com.wasteofplastic.askyblock.events.IslandExitEvent) Island(com.wasteofplastic.askyblock.Island) Vector(org.bukkit.util.Vector) EventHandler(org.bukkit.event.EventHandler)

Aggregations

Island (com.wasteofplastic.askyblock.Island)58 EventHandler (org.bukkit.event.EventHandler)43 Player (org.bukkit.entity.Player)28 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.askyblock.ASkyBlock)5 IslandEnterEvent (com.wasteofplastic.askyblock.events.IslandEnterEvent)5 Material (org.bukkit.Material)5 Block (org.bukkit.block.Block)5 Projectile (org.bukkit.entity.Projectile)5 BukkitRunnable (org.bukkit.scheduler.BukkitRunnable)5 IslandExitEvent (com.wasteofplastic.askyblock.events.IslandExitEvent)4 Monster (org.bukkit.entity.Monster)4 Vector (org.bukkit.util.Vector)4 SettingsFlag (com.wasteofplastic.askyblock.Island.SettingsFlag)3