mirror of
https://github.com/BentoBoxWorld/Level.git
synced 2024-11-05 18:33:10 +01:00
Added admin command to list top ten
This commit is contained in:
parent
dc416e9176
commit
61bf5ac921
@ -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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -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<TopTenList>) 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<Levels> 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();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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<UUID, Long> 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<String> tabComplete(CommandSender sender, String[] args) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] usage(CommandSender sender) {
|
||||
return new String[]{"", "List top ten"};
|
||||
}
|
||||
}.alias("top"));
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user