Search in sources :

Example 16 with Island

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

the class IslandGuard1_9 method onHitEndCrystal.

/**
 * Handle interaction with end crystals 1.9
 *
 * @param e - event
 */
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
public void onHitEndCrystal(final PlayerInteractAtEntityEvent e) {
    if (!IslandGuard.inWorld(e.getPlayer())) {
        return;
    }
    if (e.getPlayer().isOp()) {
        return;
    }
    // This permission bypasses protection
    if (VaultHelper.checkPerm(e.getPlayer(), Settings.PERMPREFIX + "mod.bypassprotect")) {
        return;
    }
    if (e.getRightClicked() != null && e.getRightClicked().getType().equals(EntityType.ENDER_CRYSTAL)) {
        // Check island
        Island island = plugin.getGrid().getIslandAt(e.getRightClicked().getLocation());
        if (island == null && Settings.defaultWorldSettings.get(SettingsFlag.BREAK_BLOCKS)) {
            return;
        }
        if (island != null) {
            if (island.getMembers().contains(e.getPlayer().getUniqueId()) || island.getIgsFlag(SettingsFlag.BREAK_BLOCKS)) {
                return;
            }
        }
        e.setCancelled(true);
        Util.sendMessage(e.getPlayer(), ChatColor.RED + plugin.myLocale(e.getPlayer().getUniqueId()).islandProtected);
    }
}
Also used : Island(com.wasteofplastic.acidisland.Island) EventHandler(org.bukkit.event.EventHandler)

Example 17 with Island

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

the class IslandGuard1_9 method onRodDamage.

@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
public void onRodDamage(final PlayerFishEvent e) {
    if (e.getPlayer().isOp() || VaultHelper.checkPerm(e.getPlayer(), Settings.PERMPREFIX + "mod.bypassprotect")) {
        return;
    }
    if (!IslandGuard.inWorld(e.getPlayer().getLocation())) {
        return;
    }
    Player p = e.getPlayer();
    if (e.getCaught() != null && (e.getCaught().getType().equals(EntityType.ARMOR_STAND) || e.getCaught().getType().equals(EntityType.ENDER_CRYSTAL))) {
        if (p.isOp() || VaultHelper.checkPerm(p, Settings.PERMPREFIX + "mod.bypassprotect")) {
            return;
        }
        // Check if on island
        if (plugin.getGrid().playerIsOnIsland(p)) {
            return;
        }
        // Check island
        Island island = plugin.getGrid().getIslandAt(e.getCaught().getLocation());
        if (island == null && Settings.defaultWorldSettings.get(SettingsFlag.BREAK_BLOCKS)) {
            return;
        }
        if (island != null && island.getIgsFlag(SettingsFlag.BREAK_BLOCKS)) {
            return;
        }
        Util.sendMessage(p, ChatColor.RED + plugin.myLocale(p.getUniqueId()).islandProtected);
        e.getHook().remove();
        e.setCancelled(true);
    }
}
Also used : Player(org.bukkit.entity.Player) Island(com.wasteofplastic.acidisland.Island) EventHandler(org.bukkit.event.EventHandler)

Example 18 with Island

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

the class IslandGuard1_9 method placeEndCrystalEvent.

// End crystal
@SuppressWarnings("deprecation")
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
void placeEndCrystalEvent(PlayerInteractEvent e) {
    Player p = e.getPlayer();
    if (!IslandGuard.inWorld(p)) {
        return;
    }
    if (p.isOp() || VaultHelper.checkPerm(p, Settings.PERMPREFIX + "mod.bypassprotect")) {
        // You can do anything if you are Op
        return;
    }
    // Check if they are holding armor stand
    for (ItemStack inHand : Util.getPlayerInHandItems(e.getPlayer())) {
        if (inHand.getType().equals(Material.END_CRYSTAL)) {
            // Check island
            Island island = plugin.getGrid().getIslandAt(e.getPlayer().getLocation());
            if (island == null && Settings.defaultWorldSettings.get(SettingsFlag.PLACE_BLOCKS)) {
                return;
            }
            if (island != null && (island.getMembers().contains(p.getUniqueId()) || island.getIgsFlag(SettingsFlag.PLACE_BLOCKS))) {
                // plugin.getLogger().info("1.9 " +"DEBUG: armor stand place check");
                if (Settings.limitedBlocks.containsKey("END_CRYSTAL") && Settings.limitedBlocks.get("END_CRYSTAL") > -1) {
                    // plugin.getLogger().info("1.9 " +"DEBUG: count armor stands");
                    int count = island.getTileEntityCount(Material.END_CRYSTAL, e.getPlayer().getWorld());
                    // plugin.getLogger().info("1.9 " +"DEBUG: count is " + count + " limit is " + Settings.limitedBlocks.get("ARMOR_STAND"));
                    if (Settings.limitedBlocks.get("END_CRYSTAL") <= count) {
                        Util.sendMessage(e.getPlayer(), ChatColor.RED + (plugin.myLocale(e.getPlayer().getUniqueId()).entityLimitReached.replace("[entity]", Util.prettifyText(Material.END_CRYSTAL.toString()))).replace("[number]", String.valueOf(Settings.limitedBlocks.get("END_CRYSTAL"))));
                        e.setCancelled(true);
                        return;
                    }
                }
                return;
            }
            // plugin.getLogger().info("1.9 " +"DEBUG: stand place cancelled");
            e.setCancelled(true);
            Util.sendMessage(e.getPlayer(), ChatColor.RED + plugin.myLocale(e.getPlayer().getUniqueId()).islandProtected);
            e.getPlayer().updateInventory();
        }
    }
}
Also used : Player(org.bukkit.entity.Player) ItemStack(org.bukkit.inventory.ItemStack) Island(com.wasteofplastic.acidisland.Island) EventHandler(org.bukkit.event.EventHandler)

Example 19 with Island

use of com.wasteofplastic.acidisland.Island in project acidisland 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.acidisland.Island)

Example 20 with Island

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

the class IslandGuard1_9 method EndCrystalDamage.

/**
 * Handle end crystal damage by visitors
 * @param e - event
 */
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
public void EndCrystalDamage(EntityDamageByEntityEvent e) {
    if (e.getEntity() == null || !IslandGuard.inWorld(e.getEntity())) {
        return;
    }
    if (!(e.getEntity() instanceof EnderCrystal)) {
        return;
    }
    Player p = null;
    if (e.getDamager() instanceof Player) {
        p = (Player) e.getDamager();
    } else if (e.getDamager() instanceof Projectile) {
        // Get the shooter
        Projectile projectile = (Projectile) e.getDamager();
        ProjectileSource shooter = projectile.getShooter();
        if (shooter instanceof Player) {
            p = (Player) shooter;
        }
    }
    if (p != null) {
        if (p.isOp() || VaultHelper.checkPerm(p, Settings.PERMPREFIX + "mod.bypassprotect")) {
            return;
        }
        // Check if on island
        if (plugin.getGrid().playerIsOnIsland(p)) {
            return;
        }
        // Check island
        Island island = plugin.getGrid().getIslandAt(e.getEntity().getLocation());
        if (island == null && Settings.defaultWorldSettings.get(SettingsFlag.BREAK_BLOCKS)) {
            return;
        }
        if (island != null && island.getIgsFlag(SettingsFlag.BREAK_BLOCKS)) {
            return;
        }
        Util.sendMessage(p, ChatColor.RED + plugin.myLocale(p.getUniqueId()).islandProtected);
        e.setCancelled(true);
    }
}
Also used : Player(org.bukkit.entity.Player) EnderCrystal(org.bukkit.entity.EnderCrystal) ProjectileSource(org.bukkit.projectiles.ProjectileSource) Island(com.wasteofplastic.acidisland.Island) Projectile(org.bukkit.entity.Projectile) 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