diff --git a/Level/src/bskyblock/addin/level/Level.java b/Level/src/bskyblock/addin/level/Level.java index b0d77e7..6cf4fcc 100644 --- a/Level/src/bskyblock/addin/level/Level.java +++ b/Level/src/bskyblock/addin/level/Level.java @@ -11,6 +11,7 @@ import org.bukkit.command.CommandSender; import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.scheduler.BukkitTask; +import bskyblock.addin.level.commands.Commands; import bskyblock.addin.level.config.LocaleManager; import bskyblock.addin.level.config.PluginConfig; import bskyblock.addin.level.database.object.Levels; @@ -150,7 +151,7 @@ public class Level extends JavaPlugin { //getLogger().info("DEBUG: set island level to " + level + " for " + bSkyBlock.getPlayers().getName(targetPlayer)); // Add to cache levelsCache.put(targetPlayer, level); - topTen.topTenAddEntry(targetPlayer, level); + topTen.addEntry(targetPlayer, level); } /** diff --git a/Level/src/bskyblock/addin/level/TopTen.java b/Level/src/bskyblock/addin/level/TopTen.java index 1255e89..d465904 100644 --- a/Level/src/bskyblock/addin/level/TopTen.java +++ b/Level/src/bskyblock/addin/level/TopTen.java @@ -30,7 +30,6 @@ import java.util.UUID; import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.Material; -import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; @@ -75,7 +74,7 @@ public class TopTen implements Listener { // Set up the database handler to store and retrieve the TopTenList class // Note that these are saved in the BSkyBlock database handler = (AbstractDatabaseHandler) database.getHandler(BSkyBlock.getPlugin(), TopTenList.class); - topTenLoad(); + loadTopTen(); } /** @@ -84,7 +83,7 @@ public class TopTen implements Listener { * @param ownerUUID * @param l */ - public void topTenAddEntry(UUID ownerUUID, long l) { + public void addEntry(UUID ownerUUID, long l) { // Try and see if the player is online Player player = plugin.getServer().getPlayer(ownerUUID); if (player != null) { @@ -95,33 +94,15 @@ public class TopTen implements Listener { } } topTenList.addLevel(ownerUUID, l); - topTenSave(); - } - - /** - * Removes ownerUUID from the top ten list - * - * @param ownerUUID - */ - public void topTenRemoveEntry(UUID ownerUUID) { - topTenList.remove(ownerUUID); - } - - /** - * Generates a sorted map of islands for the Top Ten list from all player - * files - */ - public void topTenCreate() { - topTenCreate(null); + saveTopTen(); } /** * Creates the top ten list from scratch. Does not get the level of each island. Just * takes the level from the player's file. * Runs asynchronously from the main thread. - * @param sender */ - public void topTenCreate(final CommandSender sender) { + public void create() { // Obtain all the levels for each known player AbstractDatabaseHandler levelHandler = plugin.getHandler(); try { @@ -142,37 +123,7 @@ public class TopTen implements Listener { // TODO Auto-generated catch block e.printStackTrace(); } - topTenSave(); - } - - public void topTenSave() { - //plugin.getLogger().info("Saving top ten list"); - if (topTenList == null) { - //plugin.getLogger().info("DEBUG: toptenlist = null!"); - return; - } - try { - handler.saveObject(topTenList); - } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException | SecurityException - | InstantiationException | NoSuchMethodException | IntrospectionException | SQLException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - } - - /** - * Loads the top ten from the database - */ - public void topTenLoad() { - try { - topTenList = handler.loadObject("topten"); - if (topTenList == null) { - topTenList = new TopTenList(); - } - } catch (InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException - | SecurityException | ClassNotFoundException | IntrospectionException | SQLException e) { - e.printStackTrace(); - } + saveTopTen(); } /** @@ -182,12 +133,11 @@ public class TopTen implements Listener { * - the requesting player * @return - true if successful, false if no Top Ten list exists */ - public boolean topTenShow(final Player player) { - + public boolean getGUI(final Player player) { if (DEBUG) - plugin.getLogger().info("DEBUG: new GUI display"); + plugin.getLogger().info("DEBUG: GUI display"); // New GUI display (shown by default) - if (topTenList == null) topTenCreate(); + if (topTenList == null) create(); // Create the top ten GUI if it does not exist if (gui == null) { gui = Bukkit.createInventory(null, GUISIZE, plugin.getLocale(player.getUniqueId()).get("topten.guiTitle")); @@ -227,7 +177,7 @@ public class TopTen implements Listener { return true; } - ItemStack getSkull(int rank, Long long1, UUID player){ + private ItemStack getSkull(int rank, Long long1, UUID player){ if (DEBUG) plugin.getLogger().info("DEBUG: Getting the skull"); String playerName = BSkyBlock.getPlugin().getPlayers().getName(player); @@ -258,8 +208,23 @@ public class TopTen implements Listener { return playerSkull; } - void remove(UUID owner) { - topTenList.remove(owner); + public TopTenList getTopTenList() { + return topTenList; + } + + /** + * Loads the top ten from the database + */ + public void loadTopTen() { + try { + topTenList = handler.loadObject("topten"); + if (topTenList == null) { + topTenList = new TopTenList(); + } + } catch (InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException + | SecurityException | ClassNotFoundException | IntrospectionException | SQLException e) { + e.printStackTrace(); + } } @SuppressWarnings("deprecation") @@ -292,4 +257,28 @@ public class TopTen implements Listener { } } + /** + * Removes ownerUUID from the top ten list + * + * @param ownerUUID + */ + public void removeEntry(UUID ownerUUID) { + topTenList.remove(ownerUUID); + } + + public void saveTopTen() { + //plugin.getLogger().info("Saving top ten list"); + if (topTenList == null) { + //plugin.getLogger().info("DEBUG: toptenlist = null!"); + return; + } + try { + handler.saveObject(topTenList); + } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException | SecurityException + | InstantiationException | NoSuchMethodException | IntrospectionException | SQLException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + } diff --git a/Level/src/bskyblock/addin/level/Commands.java b/Level/src/bskyblock/addin/level/commands/Commands.java similarity index 76% rename from Level/src/bskyblock/addin/level/Commands.java rename to Level/src/bskyblock/addin/level/commands/Commands.java index 2945371..43a7b02 100644 --- a/Level/src/bskyblock/addin/level/Commands.java +++ b/Level/src/bskyblock/addin/level/commands/Commands.java @@ -1,5 +1,6 @@ -package bskyblock.addin.level; +package bskyblock.addin.level.commands; +import java.util.Map.Entry; import java.util.Set; import java.util.UUID; @@ -7,6 +8,8 @@ import org.bukkit.ChatColor; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; +import bskyblock.addin.level.CalculateLevel; +import bskyblock.addin.level.Level; import us.tastybento.bskyblock.BSkyBlock; import us.tastybento.bskyblock.api.commands.ArgumentHandler; import us.tastybento.bskyblock.api.commands.CanUseResp; @@ -22,7 +25,7 @@ public class Commands extends CalculateLevel { } private void setupCommands() { - // level command + // island level command bSkyBlock.addSubCommand(new ArgumentHandler("island") { @Override @@ -76,7 +79,7 @@ public class Commands extends CalculateLevel { } }.alias("level")); - // top command + // island top command bSkyBlock.addSubCommand(new ArgumentHandler("island") { @Override @@ -90,7 +93,7 @@ public class Commands extends CalculateLevel { @Override public void execute(CommandSender sender, String[] args) { - plugin.getTopTen().topTenShow((Player)sender); + plugin.getTopTen().getGUI((Player)sender); return; } @@ -145,6 +148,42 @@ public class Commands extends CalculateLevel { return new String[]{"[player]", "Calculate a player's island's level"}; } }.alias("level")); + + // admin top command + bSkyBlock.addSubCommand(new ArgumentHandler("bsadmin") { + + @Override + public CanUseResp canUse(CommandSender sender) { + if (sender instanceof Player) { + VaultHelper.hasPerm((Player)sender, Settings.PERMPREFIX + "admin.topten"); + return new CanUseResp(true); + } + return new CanUseResp(true); + } + + @Override + public void execute(CommandSender sender, String[] args) { + int rank = 0; + for (Entry topTen : plugin.getTopTen().getTopTenList().getTopTen().entrySet()) { + UUID player = topTen.getKey(); + rank++; + String item = String.valueOf(rank) + ":" + BSkyBlock.getPlugin().getIslands().getIslandName(player) + " " + + plugin.getLocale(sender).get("topten.islandLevel").replace("[level]", String.valueOf(topTen.getValue())); + Util.sendMessage(sender, item); + } + return; + } + + @Override + public Set tabComplete(CommandSender sender, String[] args) { + return null; + } + + @Override + public String[] usage(CommandSender sender) { + return new String[]{"", "List top ten"}; + } + }.alias("top")); }