Search in sources :

Example 31 with Island

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

the class AdminCmd method countUnowned.

/**
 * Counts unowned islands
 * @param sender
 */
private void countUnowned(final CommandSender sender) {
    unowned = plugin.getGrid().getUnownedIslands();
    if (!unowned.isEmpty()) {
        purgeFlag = true;
        Util.sendMessage(sender, plugin.myLocale().purgeCountingUnowned);
        // Prepare for the async check - make final
        final File playerFolder = plugin.getPlayersFolder();
        // Set the pending flag
        asyncPending = true;
        // Check against player files
        plugin.getServer().getScheduler().runTaskAsynchronously(plugin, new Runnable() {

            @Override
            public void run() {
                // System.out.println("DEBUG: Running async task");
                // Check files against potentialUnowned
                FilenameFilter ymlFilter = new FilenameFilter() {

                    @Override
                    public boolean accept(File dir, String name) {
                        String lowercaseName = name.toLowerCase();
                        if (lowercaseName.endsWith(".yml")) {
                            return true;
                        } else {
                            return false;
                        }
                    }
                };
                for (File file : playerFolder.listFiles(ymlFilter)) {
                    try {
                        Scanner scanner = new Scanner(file);
                        while (scanner.hasNextLine()) {
                            final String lineFromFile = scanner.nextLine();
                            if (lineFromFile.contains("islandLocation:")) {
                                // Check against potentialUnowned list
                                String loc = lineFromFile.substring(lineFromFile.indexOf(' ')).trim();
                                // System.out.println("DEBUG: Location in player file is " + loc);
                                if (unowned.containsKey(loc)) {
                                    // System.out.println("DEBUG: Location found in player file - do not delete");
                                    unowned.remove(loc);
                                }
                                break;
                            }
                        }
                        scanner.close();
                    } catch (FileNotFoundException e) {
                        e.printStackTrace();
                    }
                }
                // System.out.println("DEBUG: scanning done");
                asyncPending = false;
            }
        });
        // Create a repeating task to check if the async task has completed
        new BukkitRunnable() {

            @Override
            public void run() {
                if (asyncPending) {
                    // Still waiting
                    Util.sendMessage(sender, plugin.myLocale().purgeStillChecking);
                } else {
                    // plugin.getLogger().info("DEBUG: unowned size = " + unowned.size());
                    if (unowned.size() > 0) {
                        if (Settings.GAMETYPE.equals(GameType.ASKYBLOCK)) {
                            Util.sendMessage(sender, plugin.myLocale().purgeSkyBlockFound.replace("[number]", String.valueOf(unowned.size())));
                        } else {
                            Util.sendMessage(sender, plugin.myLocale().purgeAcidFound.replace("[number]", String.valueOf(unowned.size())));
                        }
                        if (unowned.size() > Settings.maxPurge) {
                            Util.sendMessage(sender, plugin.myLocale().purgeLimit.replace("[number]", String.valueOf(Settings.maxPurge)));
                            Iterator<Entry<String, Island>> it = unowned.entrySet().iterator();
                            int count = 1;
                            while (it.hasNext()) {
                                it.next();
                                if (count++ > Settings.maxPurge) {
                                    // plugin.getLogger().info("DEBUG: removing record");
                                    it.remove();
                                }
                            }
                        }
                        // plugin.getLogger().info("DEBUG: unowned size after = " + unowned.size());
                        purgeUnownedConfirm = true;
                        purgeFlag = false;
                        plugin.getServer().getScheduler().runTaskLater(plugin, new Runnable() {

                            @Override
                            public void run() {
                                if (purgeUnownedConfirm) {
                                    purgeUnownedConfirm = false;
                                    Util.sendMessage(sender, plugin.myLocale().purgepurgeCancelled);
                                }
                            }
                        }, 400L);
                    } else {
                        Util.sendMessage(sender, plugin.myLocale().purgenoneFound);
                        purgeFlag = false;
                    }
                    this.cancel();
                    plugin.getGrid().saveGrid();
                }
            }
        }.runTaskTimer(plugin, 20L, 20L);
    } else {
        Util.sendMessage(sender, plugin.myLocale().purgenoneFound);
    }
}
Also used : FilenameFilter(java.io.FilenameFilter) Scanner(java.util.Scanner) BukkitRunnable(org.bukkit.scheduler.BukkitRunnable) FileNotFoundException(java.io.FileNotFoundException) BlockIterator(org.bukkit.util.BlockIterator) Iterator(java.util.Iterator) BukkitRunnable(org.bukkit.scheduler.BukkitRunnable) File(java.io.File) Island(com.wasteofplastic.acidisland.Island)

Example 32 with Island

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

the class AdminCmd method adminSetPlayerIsland.

/**
 * Assigns player to an island
 *
 * @param sender
 *            - the player requesting the assignment
 * @param l
 *            - the location of sender
 * @param newOwner
 *            - the assignee
 * @return - true if successful, false if not
 */
public boolean adminSetPlayerIsland(final CommandSender sender, final Location l, final UUID newOwner) {
    // Location island = getClosestIsland(l);
    // Check what the grid thinks
    Island island = plugin.getGrid().getIslandAt(l);
    if (island == null) {
        // Try to find it and create it if it isn't known
        Location closestIsland = plugin.getGrid().getClosestIsland(l);
        // Double check this is not taken already
        island = plugin.getGrid().getIslandAt(closestIsland);
        if (island == null) {
            // Still not known - make an island
            island = plugin.getGrid().addIsland(closestIsland.getBlockX(), closestIsland.getBlockZ());
        }
    }
    if (island.isSpawn()) {
        Util.sendMessage(sender, ChatColor.RED + plugin.myLocale().adminRegisterNotSpawn);
        return false;
    }
    UUID oldOwner = island.getOwner();
    if (oldOwner != null) {
        if (plugin.getPlayers().inTeam(oldOwner)) {
            Util.sendMessage(sender, ChatColor.RED + plugin.myLocale().adminRegisterLeadsTeam.replace("[name]", plugin.getPlayers().getName(oldOwner)));
            return false;
        }
        Util.sendMessage(sender, ChatColor.RED + plugin.myLocale().adminRegisterTaking.replace("[name]", plugin.getPlayers().getName(oldOwner)));
        plugin.getPlayers().setIslandLevel(newOwner, plugin.getPlayers().getIslandLevel(oldOwner));
        plugin.getPlayers().setTeamIslandLocation(oldOwner, null);
        plugin.getPlayers().setHasIsland(oldOwner, false);
        plugin.getPlayers().setIslandLocation(oldOwner, null);
        plugin.getPlayers().setIslandLevel(oldOwner, 0);
        plugin.getPlayers().setTeamIslandLocation(oldOwner, null);
    // plugin.topTenChangeOwner(oldOwner, newOwner);
    }
    // Check if the assigned player already has an island
    Island playersIsland = plugin.getGrid().getIsland(newOwner);
    if (playersIsland != null) {
        Util.sendMessage(sender, ChatColor.RED + (plugin.myLocale().adminRegisterHadIsland.replace("[name]", plugin.getPlayers().getName(playersIsland.getOwner())).replace("[location]", playersIsland.getCenter().getBlockX() + "," + playersIsland.getCenter().getBlockZ())));
        plugin.getGrid().setIslandOwner(playersIsland, null);
    }
    if (sender instanceof Player && Settings.createNether && Settings.newNether && ((Player) sender).getWorld().equals(ASkyBlock.getNetherWorld())) {
        // Island in new nether
        plugin.getPlayers().setHomeLocation(newOwner, island.getCenter().toVector().toLocation(ASkyBlock.getNetherWorld()));
        plugin.getPlayers().setIslandLocation(newOwner, island.getCenter().toVector().toLocation(ASkyBlock.getNetherWorld()));
    } else {
        // Island in overworld
        plugin.getPlayers().setHomeLocation(newOwner, island.getCenter());
        plugin.getPlayers().setIslandLocation(newOwner, island.getCenter());
    }
    plugin.getPlayers().setHasIsland(newOwner, true);
    // Change the grid
    plugin.getGrid().setIslandOwner(island, newOwner);
    return true;
}
Also used : Player(org.bukkit.entity.Player) UUID(java.util.UUID) Island(com.wasteofplastic.acidisland.Island) Location(org.bukkit.Location)

Example 33 with Island

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

the class AdminCmd method purgeUnownedIslands.

/**
 * 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);
}
Also used : Entry(java.util.Map.Entry) BlockIterator(org.bukkit.util.BlockIterator) Iterator(java.util.Iterator) BukkitRunnable(org.bukkit.scheduler.BukkitRunnable) Island(com.wasteofplastic.acidisland.Island)

Example 34 with Island

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

the class IslandCmd method newIsland.

/**
 * Makes an island using schematic. No permission checks are made. They have to be decided
 * before this method is called.
 * @param player
 * @param schematic
 */
public void newIsland(final Player player, final Schematic schematic) {
    // long time = System.nanoTime();
    final UUID playerUUID = player.getUniqueId();
    boolean firstTime = false;
    if (!plugin.getPlayers().hasIsland(playerUUID)) {
        firstTime = true;
    }
    // plugin.getLogger().info("DEBUG: finding island location");
    Location next = getNextIsland(player.getUniqueId());
    // plugin.getLogger().info("DEBUG: found " + next);
    // Set the player's parameters to this island
    plugin.getPlayers().setHasIsland(playerUUID, true);
    // Clear any old home locations (they should be clear, but just in case)
    plugin.getPlayers().clearHomeLocations(playerUUID);
    // Set the player's island location to this new spot
    plugin.getPlayers().setIslandLocation(playerUUID, next);
    // Teleport to the new home
    if (schematic.isPlayerSpawn()) {
        // Set home and teleport
        plugin.getPlayers().setHomeLocation(playerUUID, schematic.getPlayerSpawn(next), 1);
        // Save it for later reference
        plugin.getPlayers().setHomeLocation(playerUUID, schematic.getPlayerSpawn(next), -1);
    }
    // Sets a flag to temporarily disable cleanstone generation
    plugin.setNewIsland(true);
    // Create island based on schematic
    if (schematic != null) {
        // Paste the starting island. If it is a HELL biome, then we start in the Nether
        if (Settings.createNether && schematic.isInNether() && Settings.newNether && ASkyBlock.getNetherWorld() != null) {
            // Paste the overworld if it exists
            if (!schematic.getPartnerName().isEmpty() && schematics.containsKey(schematic.getPartnerName())) {
                // A partner schematic is available
                pastePartner(schematics.get(schematic.getPartnerName()), next, player);
            }
            // Switch home location to the Nether
            next = next.toVector().toLocation(ASkyBlock.getNetherWorld());
            // Set the player's island location to this new spot
            plugin.getPlayers().setIslandLocation(playerUUID, next);
            schematic.pasteSchematic(next, player, true, firstTime ? PasteReason.NEW_ISLAND : PasteReason.RESET);
        } else {
            // Over world start
            // plugin.getLogger().info("DEBUG: pasting");
            // long timer = System.nanoTime();
            // Paste the island and teleport the player home
            schematic.pasteSchematic(next, player, true, firstTime ? PasteReason.NEW_ISLAND : PasteReason.RESET);
            // plugin.getLogger().info("DEBUG: pasted overworld");
            if (Settings.createNether && Settings.newNether && ASkyBlock.getNetherWorld() != null) {
                // Paste the other world schematic
                final Location netherLoc = next.toVector().toLocation(ASkyBlock.getNetherWorld());
                if (schematic.getPartnerName().isEmpty()) {
                    // This will paste the over world schematic again
                    // plugin.getLogger().info("DEBUG: pasting nether");
                    pastePartner(schematic, netherLoc, player);
                // plugin.getLogger().info("DEBUG: pasted nether");
                } else {
                    if (schematics.containsKey(schematic.getPartnerName())) {
                        // plugin.getLogger().info("DEBUG: pasting partner");
                        // A partner schematic is available
                        pastePartner(schematics.get(schematic.getPartnerName()), netherLoc, player);
                    } else {
                        plugin.getLogger().severe("Partner schematic heading '" + schematic.getPartnerName() + "' does not exist");
                    }
                }
            }
        }
        // Record the rating of this schematic - not used for anything right now
        plugin.getPlayers().setStartIslandRating(playerUUID, schematic.getRating());
    }
    // Clear the cleanstone flag so events can happen again
    plugin.setNewIsland(false);
    // Add to the grid
    Island myIsland = plugin.getGrid().addIsland(next.getBlockX(), next.getBlockZ(), playerUUID);
    myIsland.setLevelHandicap(schematic.getLevelHandicap());
    // Save the player so that if the server is reset weird things won't happen
    plugin.getPlayers().save(playerUUID);
    // Start the reset cooldown
    if (!firstTime) {
        setResetWaitTime(player);
    }
    // Set the custom protection range if appropriate
    // Dynamic island range sizes with permissions
    int range = Settings.islandProtectionRange;
    for (PermissionAttachmentInfo perms : player.getEffectivePermissions()) {
        if (perms.getPermission().startsWith(Settings.PERMPREFIX + "island.range.")) {
            if (perms.getPermission().contains(Settings.PERMPREFIX + "island.range.*")) {
                range = Settings.islandProtectionRange;
                break;
            } else {
                String[] spl = perms.getPermission().split(Settings.PERMPREFIX + "island.range.");
                if (spl.length > 1) {
                    if (!NumberUtils.isDigits(spl[1])) {
                        plugin.getLogger().severe("Player " + player.getName() + " has permission: " + perms.getPermission() + " <-- the last part MUST be a number! Ignoring...");
                    } else {
                        range = Math.max(range, Integer.valueOf(spl[1]));
                    }
                }
            }
        }
    }
    // Do some sanity checking
    if (range % 2 != 0) {
        range--;
        plugin.getLogger().warning("Protection range must be even, using " + range + " for " + player.getName());
    }
    if (range > Settings.islandDistance) {
        plugin.getLogger().warning("Player has " + Settings.PERMPREFIX + "island.range." + range);
        range = Settings.islandDistance;
        plugin.getLogger().warning("Island protection range must be " + Settings.islandDistance + " or less. Setting to: " + range);
    }
    myIsland.setProtectionSize(range);
    // Save grid just in case there's a crash
    plugin.getGrid().saveGrid();
    // Done - fire event
    final IslandNewEvent event = new IslandNewEvent(player, schematic, myIsland);
    plugin.getServer().getPluginManager().callEvent(event);
// plugin.getLogger().info("DEBUG: Done! " + (System.nanoTime()- time) * 0.000001);
}
Also used : PermissionAttachmentInfo(org.bukkit.permissions.PermissionAttachmentInfo) UUID(java.util.UUID) IslandNewEvent(com.wasteofplastic.acidisland.events.IslandNewEvent) Island(com.wasteofplastic.acidisland.Island) Location(org.bukkit.Location)

Example 35 with Island

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

the class IslandCmd method addPlayertoTeam.

/**
 * Adds a player to a team. The player and the teamleader MAY be the same
 *
 * @param playerUUID - the player's UUID
 * @param teamLeader
 * @return true if the player is successfully added
 */
public boolean addPlayertoTeam(final UUID playerUUID, final UUID teamLeader) {
    // location
    if (!plugin.getPlayers().setJoinTeam(playerUUID, teamLeader, plugin.getPlayers().getIslandLocation(teamLeader))) {
        return false;
    }
    // if it exists, and if not set to the island location
    if (!playerUUID.equals(teamLeader)) {
        // Clear any old home locations
        plugin.getPlayers().clearHomeLocations(playerUUID);
        // Set homes and spawn point home locations if they exist
        for (Entry<Integer, Location> homes : plugin.getPlayers().getHomeLocations(teamLeader).entrySet()) {
            if (homes.getKey() < 2) {
                plugin.getPlayers().setHomeLocation(playerUUID, homes.getValue(), homes.getKey());
            }
        }
        if (plugin.getPlayers().getHomeLocation(teamLeader, 1) == null) {
            plugin.getPlayers().setHomeLocation(playerUUID, plugin.getPlayers().getIslandLocation(teamLeader));
        // plugin.getLogger().info("DEBUG: Setting player's home to the team island location");
        }
        // If the leader's member list does not contain player then add it
        if (!plugin.getPlayers().getMembers(teamLeader).contains(playerUUID)) {
            plugin.getPlayers().addTeamMember(teamLeader, playerUUID);
        }
        // add it
        if (!plugin.getPlayers().getMembers(teamLeader).contains(teamLeader)) {
            plugin.getPlayers().addTeamMember(teamLeader, teamLeader);
        }
        // Fire event
        final Island island = plugin.getGrid().getIsland(teamLeader);
        final IslandJoinEvent event = new IslandJoinEvent(playerUUID, island);
        plugin.getServer().getPluginManager().callEvent(event);
    }
    return true;
}
Also used : IslandJoinEvent(com.wasteofplastic.acidisland.events.IslandJoinEvent) Island(com.wasteofplastic.acidisland.Island) Location(org.bukkit.Location)

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