com.wasteofplastic.askyblock.Island Java Examples

The following examples show how to use com.wasteofplastic.askyblock.Island. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: FlyingMobEvents.java    From askyblock with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Track where the mob was created. This will determine its allowable movement zone.
 * @param e - event
 */
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
public void mobSpawn(CreatureSpawnEvent e) {
    // Only cover withers in the island world
    if (!IslandGuard.inWorld(e.getEntity())) {
        return;
    }
    if (!e.getEntityType().equals(EntityType.WITHER) && !e.getEntityType().equals(EntityType.BLAZE) && !e.getEntityType().equals(EntityType.GHAST)) {
        return;
    }
    if (DEBUG) {
        plugin.getLogger().info("Flying mobs " + e.getEventName());
    }
    // Store where this mob originated
    Island island = plugin.getGrid().getIslandAt(e.getLocation());
    if (island != null) {
        if (DEBUG) {
            plugin.getLogger().info("DEBUG: Mob spawned on known island - id = " + e.getEntity().getUniqueId());
        }
        mobSpawnInfo.put(e.getEntity(),island);
    } // Else do nothing - maybe an Op spawned it? If so, on their head be it!
}
 
Example #2
Source File: IslandGuard.java    From askyblock with GNU General Public License v2.0 6 votes vote down vote up
@EventHandler(priority = EventPriority.LOW)
public void onPistonExtend(BlockPistonExtendEvent e) {
    if (DEBUG) {
        plugin.getLogger().info(e.getEventName());
    }
    Location pistonLoc = e.getBlock().getLocation();
    if (Settings.allowPistonPush || !inWorld(pistonLoc)) {
        //plugin.getLogger().info("DEBUG: Not in world");
        return;
    }
    Island island = plugin.getGrid().getProtectedIslandAt(pistonLoc);
    if (island == null || !island.onIsland(pistonLoc)) {
        //plugin.getLogger().info("DEBUG: Not on is island protection zone");
        return;
    }
    // We need to check where the blocks are going to go, not where they are
    for (Block b : e.getBlocks()) {
        if (!island.onIsland(b.getRelative(e.getDirection()).getLocation())) {
            //plugin.getLogger().info("DEBUG: Block is outside protected area");
            e.setCancelled(true);
            return;
        }
    }
}
 
Example #3
Source File: IslandGuard.java    From askyblock with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Handle visitor chicken egg throwing
 * @param e - event
 */
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
public void onEggThrow(PlayerEggThrowEvent e) {
    if (DEBUG) {
        plugin.getLogger().info("egg throwing = " + e.getEventName());
    }
    if (!inWorld(e.getPlayer()) || e.getPlayer().isOp() || VaultHelper.checkPerm(e.getPlayer(), Settings.PERMPREFIX + "mod.bypassprotect")
            || plugin.getGrid().playerIsOnIsland(e.getPlayer()) || plugin.getGrid().isAtSpawn(e.getPlayer().getLocation())) {
        return;
    }
    // Check island
    Island island = plugin.getGrid().getProtectedIslandAt(e.getPlayer().getLocation());
    if (island == null) {
        return;
    }
    if (!island.getIgsFlag(SettingsFlag.EGGS)) {
        e.setHatching(false);
        Util.sendMessage(e.getPlayer(), ChatColor.RED + plugin.myLocale(e.getPlayer().getUniqueId()).islandProtected);
        //e.getPlayer().updateInventory();
    }

    return;
}
 
Example #4
Source File: IslandGuard.java    From askyblock with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Stop redstone if team members are offline and disableOfflineRedstone is TRUE.
 * @param e - event
 */
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
public void onBlockRedstone(final BlockRedstoneEvent e){
    if(Settings.disableOfflineRedstone) {
        // Check world
        if (!inWorld(e.getBlock())) {
            return;
        }
        // Check if this is on an island
        Island island = plugin.getGrid().getIslandAt(e.getBlock().getLocation());
        if (island == null || island.isSpawn()) {
            return;
        }
        for(UUID member : island.getMembers()){
            if(plugin.getServer().getPlayer(member) != null) return;
        }
        e.setNewCurrent(0);
    }
}
 
Example #5
Source File: EntityLimits.java    From askyblock with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Prevents trees from growing outside of the protected area.
 *
 * @param e - event
 */
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
public void onTreeGrow(final StructureGrowEvent e) {
    if (DEBUG) {
        plugin.getLogger().info(e.getEventName());
    }
    // Check world
    if (!IslandGuard.inWorld(e.getLocation())) {
        return;
    }
    // Check if this is on an island
    Island island = plugin.getGrid().getIslandAt(e.getLocation());
    if (island == null || island.isSpawn()) {
        return;
    }
    Iterator<BlockState> it = e.getBlocks().iterator();
    while (it.hasNext()) {
        BlockState b = it.next();
        if (b.getType() == Material.LOG || b.getType() == Material.LOG_2
                || b.getType() == Material.LEAVES || b.getType() == Material.LEAVES_2) {
            if (!island.onIsland(b.getLocation())) {
                it.remove();
            }
        }
    }
}
 
Example #6
Source File: IslandGuard1_9.java    From askyblock with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 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;
}
 
Example #7
Source File: SafeSpotTeleport.java    From askyblock with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Gets a set of chunk coords that will be scanned.
 * @param entity
 * @param location
 * @return
 */
private List<Pair<Integer, Integer>> getChunksToScan() {
    List<Pair<Integer, Integer>> result = new ArrayList<>();
    // Get island if available
    Island island = plugin.getGrid().getIslandAt(location);
    int maxRadius = island == null ? Settings.islandProtectionRange/2 : island.getProtectionSize()/2;
    maxRadius = maxRadius > MAX_RADIUS ? MAX_RADIUS : maxRadius;

    int x = location.getBlockX();
    int z = location.getBlockZ();
    // Create ever increasing squares around the target location
    int radius = 0;
    do {
        for (int i = x - radius; i <= x + radius; i+=16) {
            for (int j = z - radius; j <= z + radius; j+=16) {
                addChunk(result, island, new Pair<>(i,j), new Pair<>(i/16, j/16));
            }
        }
        radius++;
    } while (radius < maxRadius);
    return result;
}
 
Example #8
Source File: PlayerEvents.java    From askyblock with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Places player back on their island if the setting is true
 * @param e - event
 */
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onPlayerRespawn(final PlayerRespawnEvent e) {
    if (DEBUG) {
        plugin.getLogger().info(e.getEventName());
    }
    if (!Settings.respawnOnIsland) {
        return;
    }
    if (respawn.contains(e.getPlayer().getUniqueId())) {
        respawn.remove(e.getPlayer().getUniqueId());
        Location respawnLocation = plugin.getGrid().getSafeHomeLocation(e.getPlayer().getUniqueId(), 1);
        if (respawnLocation != null) {
            //plugin.getLogger().info("DEBUG: Setting respawn location to " + respawnLocation);
            e.setRespawnLocation(respawnLocation);
            // Get island
            Island island = plugin.getGrid().getIslandAt(respawnLocation);
            if (island != null) {
                // Run perms etc.
                processPerms(e.getPlayer(), island);
            }
        }
    }
}
 
Example #9
Source File: PlayerEvents.java    From askyblock with GNU General Public License v2.0 6 votes vote down vote up
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
public void onVisitorDrop(final PlayerDropItemEvent e) {
    if (DEBUG) {
        plugin.getLogger().info(e.getEventName());
    }
    if (!IslandGuard.inWorld(e.getPlayer())) {
        return;
    }
    Island island = plugin.getGrid().getIslandAt(e.getItemDrop().getLocation());
    if ((island != null && island.getIgsFlag(SettingsFlag.VISITOR_ITEM_DROP))
            || e.getPlayer().isOp() || VaultHelper.checkPerm(e.getPlayer(), Settings.PERMPREFIX + "mod.bypassprotect")
            || plugin.getGrid().locationIsOnIsland(e.getPlayer(), e.getItemDrop().getLocation())) {
        return;
    }
    Util.sendMessage(e.getPlayer(), ChatColor.RED + plugin.myLocale(e.getPlayer().getUniqueId()).islandProtected);
    e.setCancelled(true);
}
 
Example #10
Source File: PlayerEvents3.java    From askyblock with GNU General Public License v2.0 6 votes vote down vote up
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
public void onVisitorPickup(final EntityPickupItemEvent e) {
    if (DEBUG) {
        plugin.getLogger().info(e.getEventName());
    }
    if (e.getEntity() instanceof Player) {
        Player player = (Player)e.getEntity();
        if (!IslandGuard.inWorld(player)) {
            return;
        }
        Island island = plugin.getGrid().getIslandAt(e.getItem().getLocation());
        if ((island != null && island.getIgsFlag(SettingsFlag.VISITOR_ITEM_PICKUP)) 
                || player.isOp() || VaultHelper.checkPerm(player, Settings.PERMPREFIX + "mod.bypassprotect")
                || plugin.getGrid().locationIsOnIsland(player, e.getItem().getLocation())) {
            return;
        }
        e.setCancelled(true);
    }
}
 
Example #11
Source File: PlayerEvents2.java    From askyblock with GNU General Public License v2.0 6 votes vote down vote up
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
public void onVisitorPickup(final PlayerPickupItemEvent e) {
    if (DEBUG) {
        plugin.getLogger().info(e.getEventName());
    }
    if (!IslandGuard.inWorld(e.getPlayer())) {
        return;
    }
    Island island = plugin.getGrid().getIslandAt(e.getItem().getLocation());
    if ((island != null && island.getIgsFlag(SettingsFlag.VISITOR_ITEM_PICKUP)) 
            || e.getPlayer().isOp() || VaultHelper.checkPerm(e.getPlayer(), Settings.PERMPREFIX + "mod.bypassprotect")
            || plugin.getGrid().locationIsOnIsland(e.getPlayer(), e.getItem().getLocation())) {
        return;
    }
    e.setCancelled(true);
}
 
Example #12
Source File: IslandGuard1_9.java    From askyblock with GNU General Public License v2.0 5 votes vote down vote up
@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);
    }
}
 
Example #13
Source File: IslandGuard1_9.java    From askyblock with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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);
    }
}
 
Example #14
Source File: IslandGuard1_9.java    From askyblock with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Action allowed in this location
 * @param location
 * @param flag
 * @return true if allowed
 */
private boolean actionAllowed(Location location, SettingsFlag flag) {
    Island island = plugin.getGrid().getProtectedIslandAt(location);
    if (island != null && island.getIgsFlag(flag)){
        return true;
    }
    return island == null && Settings.defaultWorldSettings.get(flag);
}
 
Example #15
Source File: AdminCmd.java    From askyblock with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Purges the unowned islands upon direction from sender
 * @param sender
 */

private void purgeUnownedIslands(final CommandSender sender) {
    purgeFlag = true;
    final int total = unowned.size();
    new BukkitRunnable() {
        @Override
        public void run() {
            if (unowned.isEmpty()) {
                purgeFlag = false;
                Util.sendMessage(sender, ChatColor.YELLOW + plugin.myLocale().purgefinished);
                this.cancel();
                plugin.getGrid().saveGrid();
            }
            if (unowned.size() > 0) {
                Iterator<Entry<String, Island>> it = unowned.entrySet().iterator();
                Entry<String,Island> entry = it.next();
                if (entry.getValue().getOwner() == null) {
                    Util.sendMessage(sender, ChatColor.YELLOW + "[" + (total - unowned.size() + 1) + "/" + total + "] " + plugin.myLocale().purgeRemovingAt.replace("[location]",
                            entry.getValue().getCenter().getWorld().getName() + " " + entry.getValue().getCenter().getBlockX()
                            + "," + entry.getValue().getCenter().getBlockZ()));
                    deleteIslands(entry.getValue(),sender);
                }
                // Remove from the list
                it.remove();
            }
            Util.sendMessage(sender, plugin.myLocale().purgeNowWaiting);
        }
    }.runTaskTimer(plugin, 0L, 20L);
}
 
Example #16
Source File: HookASkyBlock.java    From CombatLogX with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean doesTeamMatch(Player player1, Player player2) {
    if(player1 == null || player2 == null) return false;

    UUID uuid1 = player1.getUniqueId();
    UUID uuid2 = player2.getUniqueId();
    if(uuid1.equals(uuid2)) return true;

    Island island = getIslandFor(player1);
    if(island == null) return false;

    List<UUID> memberList = island.getMembers();
    return memberList.contains(uuid2);
}
 
Example #17
Source File: IslandGuard.java    From askyblock with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Action allowed in this location
 * @param location
 * @param flag
 * @return true if allowed
 */
private boolean actionAllowed(Location location, SettingsFlag flag) {
    Island island = plugin.getGrid().getProtectedIslandAt(location);
    if (island != null && island.getIgsFlag(flag)){
        return true;
    }
    return island == null && Settings.defaultWorldSettings.get(flag);
}
 
Example #18
Source File: IslandGuard.java    From askyblock with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Checks if action is allowed for player in location for flag
 * @param player
 * @param location
 * @param flag
 * @return true if allowed
 */
private boolean actionAllowed(Player player, Location location, SettingsFlag flag) {
    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;
    }
    return island == null && Settings.defaultWorldSettings.get(flag);
}
 
Example #19
Source File: ASkyBlockListener.java    From ShopChest with MIT License 5 votes vote down vote up
private boolean handleForLocation(Player player, Location loc, Cancellable e) {
    Island island = ASkyBlockAPI.getInstance().getIslandAt(loc);
    if (island == null) 
        return false;

    if (!player.getUniqueId().equals(island.getOwner()) && !island.getMembers().contains(player.getUniqueId())) {
        e.setCancelled(true);
        plugin.debug("Cancel Reason: ASkyBlock");
        return true;
    }

    return false;
}
 
Example #20
Source File: IslandGuard.java    From askyblock with GNU General Public License v2.0 5 votes vote down vote up
@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);
    }
}
 
Example #21
Source File: IslandGuard.java    From askyblock with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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;
}
 
Example #22
Source File: EntityLimits.java    From askyblock with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Action allowed in this location
 * @param location
 * @param flag
 * @return true if allowed
 */
private boolean actionAllowed(Location location, SettingsFlag flag) {
    Island island = plugin.getGrid().getProtectedIslandAt(location);
    if (island != null && island.getIgsFlag(flag)){
        return true;
    }
    return island == null && Settings.defaultWorldSettings.get(flag);
}
 
Example #23
Source File: EntityLimits.java    From askyblock with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Checks if action is allowed for player in location for flag
 * @param player
 * @param location
 * @param flag
 * @return true if allowed
 */
private boolean actionAllowed(Player player, Location location, SettingsFlag flag) {
    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;
    }
    return island == null && Settings.defaultWorldSettings.get(flag);
}
 
Example #24
Source File: PlayerEvents.java    From askyblock with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Adds perms or fly for player on island
 * @param player
 * @param island
 */
private void processPerms(final Player player, final Island island) {
    if (island != null && island.getMembers().contains(player.getUniqueId())) {
        if (DEBUG)
            plugin.getLogger().info("DEBUG: player on island " + player.getName());
        if(VaultHelper.checkPerm(player, Settings.PERMPREFIX + "islandfly", island.getCenter().getWorld())) {
            if (DEBUG)
                plugin.getLogger().info("DEBUG: player has fly");
            plugin.getServer().getScheduler().runTask(plugin, () -> {
                player.setAllowFlight(true);
                player.setFlying(true);

            });

        }
        if (DEBUG)
            plugin.getLogger().info("DEBUG: adding temp perms");
        for(String perm : Settings.temporaryPermissions) {
            if(!VaultHelper.checkPerm(player, perm, island.getCenter().getWorld())){
                VaultHelper.addPerm(player, perm, ASkyBlock.getIslandWorld());
                if (Settings.createNether && Settings.newNether && ASkyBlock.getNetherWorld() != null) {
                    VaultHelper.addPerm(player, perm, ASkyBlock.getNetherWorld());
                }
                List<String> perms = new ArrayList<>();
                if(temporaryPerms.containsKey(player.getUniqueId())) perms = temporaryPerms.get(player.getUniqueId());
                perms.add(perm);
                temporaryPerms.put(player.getUniqueId(), perms);
                if (DEBUG)
                    plugin.getLogger().info("DEBUG: adding perm " + perm);
            } else {
                if (DEBUG)
                    plugin.getLogger().info("DEBUG: player already has perm " + perm);
            }
        }
    }
}
 
Example #25
Source File: PlayerEvents.java    From askyblock with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Handle player joining
 * @param event
 */
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
public void onPlayerJoin(final PlayerJoinEvent event) {
    final Island island = plugin.getGrid().getProtectedIslandAt(event.getPlayer().getLocation());
    if (island != null) {
        processPerms(event.getPlayer(), island);
        // Fire entry event
        final IslandEnterEvent e = new IslandEnterEvent(event.getPlayer().getUniqueId(), island, event.getPlayer().getLocation());
        plugin.getServer().getPluginManager().callEvent(e);
    }
}
 
Example #26
Source File: PlayerEvents.java    From askyblock with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Removes temporary perms when the player log out
 * @param event
 */
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
public void onPlayerLeave(PlayerQuitEvent event){
    if (DEBUG)
        plugin.getLogger().info("DEBUG: Removing fly and all temp perms");
    Player player = event.getPlayer();

    if(temporaryPerms.containsKey(player.getUniqueId())){
        for(String perm : temporaryPerms.get(player.getUniqueId())){
            VaultHelper.removePerm(player, perm, ASkyBlock.getIslandWorld());
            if (Settings.createNether && Settings.newNether && ASkyBlock.getNetherWorld() != null) {
                VaultHelper.removePerm(player, perm, ASkyBlock.getNetherWorld());
            }
        }
        temporaryPerms.remove(player.getUniqueId());
    }
    if(VaultHelper.checkPerm(player, Settings.PERMPREFIX + "islandfly")) {
        if (player.getGameMode().equals(GameMode.SURVIVAL)) {
            player.setAllowFlight(false);
            player.setFlying(false);
        }
    }
    final Island island = plugin.getGrid().getProtectedIslandAt(event.getPlayer().getLocation());
    if (island != null) {
        // Fire exit event
        final IslandExitEvent e = new IslandExitEvent(event.getPlayer().getUniqueId(), island, event.getPlayer().getLocation());
        plugin.getServer().getPluginManager().callEvent(e);
    }
}
 
Example #27
Source File: PlayerEvents.java    From askyblock with GNU General Public License v2.0 5 votes vote down vote up
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
public void onVistorDeath(final PlayerDeathEvent e) {
    if (DEBUG) {
        plugin.getLogger().info(e.getEventName());
    }
    if (!IslandGuard.inWorld(e.getEntity())) {
        return;
    }
    // Mute death messages
    if (Settings.muteDeathMessages) {
        e.setDeathMessage(null);
    }
    // If visitors will keep items and their level on death
    // This will override any global settings
    if (Settings.allowVisitorKeepInvOnDeath) {
        // If the player is not a visitor then they die and lose everything -
        // sorry :-(
        Island island = plugin.getGrid().getProtectedIslandAt(e.getEntity().getLocation());
        if (island != null && !island.getMembers().contains(e.getEntity().getUniqueId())) {
            // They are a visitor
            InventorySave.getInstance().savePlayerInventory(e.getEntity());
            e.getDrops().clear();
            e.setKeepLevel(true);
            e.setDroppedExp(0);
        }
    }
}
 
Example #28
Source File: IslandGuard1_8.java    From askyblock with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Checks if action is allowed for player in location for flag
 * @param player
 * @param location
 * @param flag
 * @return true if allowed
 */
private boolean actionAllowed(Player player, Location location, SettingsFlag 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;
    }
    return island == null && Settings.defaultWorldSettings.get(flag);
}
 
Example #29
Source File: IslandGuard1_8.java    From askyblock with GNU General Public License v2.0 5 votes vote down vote up
@EventHandler(priority = EventPriority.LOW, ignoreCancelled=true)
public void ArmorStandDestroy(EntityDamageByEntityEvent e) {
    if (DEBUG) {
        plugin.getLogger().info("1.8 " + "IslandGuard New " + e.getEventName());
    }
    if (!(e.getEntity() instanceof LivingEntity)) {
        return;
    }
    if (!IslandGuard.inWorld(e.getEntity())) {
        return;
    }
    final LivingEntity livingEntity = (LivingEntity) e.getEntity();
    if (!livingEntity.getType().equals(EntityType.ARMOR_STAND)) {
        return;
    }
    if (e.getDamager() instanceof Player) {
        Player p = (Player) e.getDamager();
        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);
    }
}
 
Example #30
Source File: FlyingMobEvents.java    From askyblock with GNU General Public License v2.0 5 votes vote down vote up
/**
 * @param plugin - ASkyBlock plugin object
 */
public FlyingMobEvents(ASkyBlock plugin) {
    this.plugin = plugin;
    this.mobSpawnInfo = new WeakHashMap<>();
    new BukkitRunnable() {

        public void run() {
            //Bukkit.getLogger().info("DEBUG: checking - mobspawn size = " + mobSpawnInfo.size());
            Iterator<Entry<Entity, Island>> it = mobSpawnInfo.entrySet().iterator();
            while (it.hasNext()) {
                Entry<Entity, Island> entry = it.next();
                if (entry.getKey() == null) {
                    //Bukkit.getLogger().info("DEBUG: removing null entity");
                    it.remove();
                } else {
                    if (entry.getKey() instanceof LivingEntity) {
                        if (!entry.getValue().inIslandSpace(entry.getKey().getLocation())) {
                            //Bukkit.getLogger().info("DEBUG: removing entity outside of island");
                            it.remove();
                            // Kill mob
                            LivingEntity mob = (LivingEntity)entry.getKey();
                            mob.setHealth(0);
                            entry.getKey().remove();
                        } else {
                            //Bukkit.getLogger().info("DEBUG: entity " + entry.getKey().getName() + " is in island space");
                        }
                    } else {
                        // Not living entity
                        it.remove();
                    }
                }
            }               
        }

    }.runTaskTimer(plugin, 20L, 20L);
}