Search in sources :

Example 56 with Island

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

Example 57 with Island

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

Example 58 with Island

use of com.wasteofplastic.askyblock.Island in project askyblock 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.askyblock.Island) Location(org.bukkit.Location)

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