Updated to latest BSB API.

This commit is contained in:
Tastybento 2018-01-07 11:25:24 -08:00
parent 5e66722412
commit 87397ac16f
9 changed files with 36 additions and 40 deletions

View File

@ -14,12 +14,12 @@ import bskyblock.addon.level.commands.AdminTop;
import bskyblock.addon.level.commands.IslandLevel;
import bskyblock.addon.level.commands.IslandTop;
import bskyblock.addon.level.config.PluginConfig;
import bskyblock.addon.level.database.object.Levels;
import bskyblock.addon.level.database.object.LevelsData;
import us.tastybento.bskyblock.BSkyBlock;
import us.tastybento.bskyblock.Constants;
import us.tastybento.bskyblock.api.addons.Addon;
import us.tastybento.bskyblock.api.commands.CompositeCommand;
import us.tastybento.bskyblock.api.commands.User;
import us.tastybento.bskyblock.config.Settings;
import us.tastybento.bskyblock.database.BSBDatabase;
import us.tastybento.bskyblock.database.managers.AbstractDatabaseHandler;
@ -38,7 +38,7 @@ public class Level extends Addon {
BukkitTask checker = null;
// Database handler for level data
private AbstractDatabaseHandler<Levels> handler;
private AbstractDatabaseHandler<LevelsData> handler;
// The BSkyBlock database object
private BSBDatabase database;
@ -70,7 +70,7 @@ public class Level extends Addon {
database = BSBDatabase.getDatabase();
// Set up the database handler to store and retrieve Island classes
// Note that these are saved by the BSkyBlock database
handler = (AbstractDatabaseHandler<Levels>) database.getHandler(bSkyBlock, Levels.class);
handler = (AbstractDatabaseHandler<LevelsData>) database.getHandler(LevelsData.class);
// Initialize the cache
levelsCache = new HashMap<>();
// Load all the levels
@ -83,10 +83,10 @@ public class Level extends Addon {
// Local locales
//localeManager = new LocaleManager(this);
// Register commands
CompositeCommand bsbIslandCmd = (CompositeCommand) BSkyBlock.getInstance().getCommandsManager().getCommand(Settings.ISLANDCOMMAND);
CompositeCommand bsbIslandCmd = (CompositeCommand) BSkyBlock.getInstance().getCommandsManager().getCommand(Constants.ISLANDCOMMAND);
new IslandLevel(this, bsbIslandCmd);
new IslandTop(this, bsbIslandCmd);
CompositeCommand bsbAdminCmd = (CompositeCommand) BSkyBlock.getInstance().getCommandsManager().getCommand(Settings.ADMINCOMMAND);
CompositeCommand bsbAdminCmd = (CompositeCommand) BSkyBlock.getInstance().getCommandsManager().getCommand(Constants.ADMINCOMMAND);
new AdminLevel(this, bsbAdminCmd);
new AdminTop(this, bsbAdminCmd);
// Done
@ -102,7 +102,7 @@ public class Level extends Addon {
public void load() {
try {
for (Levels level : handler.loadObjects()) {
for (LevelsData level : handler.loadObjects()) {
levelsCache.put(UUID.fromString(level.getUniqueId()), level.getLevel());
}
} catch (InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException
@ -120,7 +120,7 @@ public class Level extends Addon {
Runnable save = () -> {
try {
for (Entry<UUID, Long> en : levelsCache.entrySet()) {
Levels lv = new Levels();
LevelsData lv = new LevelsData();
lv.setLevel(en.getValue());
lv.setUniqueId(en.getKey().toString());
handler.saveObject(lv);
@ -149,7 +149,7 @@ public class Level extends Addon {
return levelsCache.get(targetPlayer);
}
// Get from database
Levels level;
LevelsData level;
try {
level = handler.loadObject(targetPlayer.toString());
if (level == null) {
@ -178,7 +178,7 @@ public class Level extends Addon {
topTen.addEntry(targetPlayer, level);
}
public AbstractDatabaseHandler<Levels> getHandler() {
public AbstractDatabaseHandler<LevelsData> getHandler() {
return handler;
}

View File

@ -6,8 +6,8 @@ import java.util.UUID;
import org.bukkit.ChatColor;
import us.tastybento.bskyblock.Constants;
import us.tastybento.bskyblock.api.commands.User;
import us.tastybento.bskyblock.config.Settings;
public class LevelPresenter extends LevelPlugin {
@ -46,9 +46,9 @@ public class LevelPresenter extends LevelPlugin {
return false;
}
// Player asking for their own island calc
if (!sender.isPlayer() || sender.getUniqueId().equals(targetPlayer) || sender.isOp() || sender.hasPermission(Settings.PERMPREFIX + "mod.info")) {
if (!sender.isPlayer() || sender.getUniqueId().equals(targetPlayer) || sender.isOp() || sender.hasPermission(Constants.PERMPREFIX + "mod.info")) {
// Newer better system - uses chunks
if (!onLevelWaitTime(sender) || levelWait <= 0 || sender.isOp() || sender.hasPermission(Settings.PERMPREFIX + "mod.info")) {
if (!onLevelWaitTime(sender) || levelWait <= 0 || sender.isOp() || sender.hasPermission(Constants.PERMPREFIX + "mod.info")) {
sender.sendRawMessage(ChatColor.GREEN + "Calculating level, please wait...");
setLevelWaitTime(sender);
new ChunkScanner(plugin, bSkyBlock.getIslands().getIsland(targetPlayer), sender);

View File

@ -41,11 +41,11 @@ import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.SkullMeta;
import bskyblock.addon.level.database.object.Levels;
import bskyblock.addon.level.database.object.TopTenList;
import bskyblock.addon.level.database.object.LevelsData;
import bskyblock.addon.level.database.object.TopTenData;
import bskyblock.addon.level.event.TopTenClick;
import us.tastybento.bskyblock.BSkyBlock;
import us.tastybento.bskyblock.config.Settings;
import us.tastybento.bskyblock.Constants;
import us.tastybento.bskyblock.database.BSBDatabase;
import us.tastybento.bskyblock.database.managers.AbstractDatabaseHandler;
@ -58,14 +58,14 @@ import us.tastybento.bskyblock.database.managers.AbstractDatabaseHandler;
public class TopTen implements Listener {
private Level plugin;
// Top ten list of players
private TopTenList topTenList;
private TopTenData topTenList;
private final int GUISIZE = 27; // Must be a multiple of 9
private final int[] SLOTS = new int[] {4, 12, 14, 19, 20, 21, 22, 23, 24, 25};
private final boolean DEBUG = false;
// Store this as a because it's the same for everyone and saves memory cleanup
private Inventory gui;
private BSBDatabase database;
private AbstractDatabaseHandler<TopTenList> handler;
private AbstractDatabaseHandler<TopTenData> handler;
@SuppressWarnings("unchecked")
public TopTen(Level plugin) {
@ -74,7 +74,7 @@ public class TopTen implements Listener {
database = BSBDatabase.getDatabase();
// 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.getInstance(), TopTenList.class);
handler = (AbstractDatabaseHandler<TopTenData>) database.getHandler(TopTenData.class);
loadTopTen();
}
@ -89,7 +89,7 @@ public class TopTen implements Listener {
Player player = plugin.getServer().getPlayer(ownerUUID);
if (player != null) {
// Online
if (!player.hasPermission(Settings.PERMPREFIX + "intopten")) {
if (!player.hasPermission(Constants.PERMPREFIX + "intopten")) {
topTenList.remove(ownerUUID);
return;
}
@ -105,10 +105,10 @@ public class TopTen implements Listener {
*/
public void create() {
// Obtain all the levels for each known player
AbstractDatabaseHandler<Levels> levelHandler = plugin.getHandler();
AbstractDatabaseHandler<LevelsData> levelHandler = plugin.getHandler();
try {
long index = 0;
for (Levels lv : levelHandler.loadObjects()) {
for (LevelsData lv : levelHandler.loadObjects()) {
if (index++ % 1000 == 0) {
plugin.getLogger().info("Processed " + index + " players for top ten");
}
@ -158,7 +158,7 @@ public class TopTen implements Listener {
Player entry = plugin.getServer().getPlayer(playerUUID);
boolean show = true;
if (entry != null) {
if (!entry.hasPermission(Settings.PERMPREFIX + "intopten")) {
if (!entry.hasPermission(Constants.PERMPREFIX + "intopten")) {
it.remove();
show = false;
}
@ -211,7 +211,7 @@ public class TopTen implements Listener {
return playerSkull;
}
public TopTenList getTopTenList() {
public TopTenData getTopTenList() {
return topTenList;
}
@ -222,7 +222,7 @@ public class TopTen implements Listener {
try {
topTenList = handler.loadObject("topten");
if (topTenList == null) {
topTenList = new TopTenList();
topTenList = new TopTenData();
}
} catch (InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException
| SecurityException | ClassNotFoundException | IntrospectionException | SQLException e) {

View File

@ -4,9 +4,9 @@ import java.util.List;
import java.util.UUID;
import bskyblock.addon.level.Level;
import us.tastybento.bskyblock.Constants;
import us.tastybento.bskyblock.api.commands.CompositeCommand;
import us.tastybento.bskyblock.api.commands.User;
import us.tastybento.bskyblock.config.Settings;
public class AdminLevel extends CompositeCommand {
@ -40,7 +40,7 @@ public class AdminLevel extends CompositeCommand {
@Override
public void setup() {
this.setPermission(Settings.PERMPREFIX + "admin.level");
this.setPermission(Constants.PERMPREFIX + "admin.level");
this.setOnlyPlayer(false);
this.setParameters("admin.level.parameters");
this.setDescription("admin.level.description");

View File

@ -2,15 +2,13 @@ package bskyblock.addon.level.commands;
import java.util.List;
import java.util.Map.Entry;
import bskyblock.addon.level.Level;
import java.util.UUID;
import bskyblock.addon.level.Level;
import us.tastybento.bskyblock.BSkyBlock;
import us.tastybento.bskyblock.Constants;
import us.tastybento.bskyblock.api.commands.CompositeCommand;
import us.tastybento.bskyblock.api.commands.User;
import us.tastybento.bskyblock.config.Settings;
public class AdminTop extends CompositeCommand {
@ -37,7 +35,7 @@ public class AdminTop extends CompositeCommand {
@Override
public void setup() {
this.setPermission(Settings.PERMPREFIX + "admin.top");
this.setPermission(Constants.PERMPREFIX + "admin.top");
this.setOnlyPlayer(false);
this.setDescription("admin.top.description");
}

View File

@ -4,9 +4,9 @@ import java.util.List;
import java.util.UUID;
import bskyblock.addon.level.Level;
import us.tastybento.bskyblock.Constants;
import us.tastybento.bskyblock.api.commands.CompositeCommand;
import us.tastybento.bskyblock.api.commands.User;
import us.tastybento.bskyblock.config.Settings;
public class IslandLevel extends CompositeCommand {
@ -43,7 +43,7 @@ public class IslandLevel extends CompositeCommand {
@Override
public void setup() {
this.setPermission(Settings.PERMPREFIX + "island.level");
this.setPermission(Constants.PERMPREFIX + "island.level");
this.setParameters("island.level.parameters");
this.setDescription("island.level.description");
this.setOnlyPlayer(true);

View File

@ -3,9 +3,9 @@ package bskyblock.addon.level.commands;
import java.util.List;
import bskyblock.addon.level.Level;
import us.tastybento.bskyblock.Constants;
import us.tastybento.bskyblock.api.commands.CompositeCommand;
import us.tastybento.bskyblock.api.commands.User;
import us.tastybento.bskyblock.config.Settings;
public class IslandTop extends CompositeCommand {
@ -24,7 +24,7 @@ public class IslandTop extends CompositeCommand {
@Override
public void setup() {
this.setPermission(Settings.PERMPREFIX + "island.top");
this.setPermission(Constants.PERMPREFIX + "island.top");
this.setDescription("island.top.description");

View File

@ -2,17 +2,15 @@ package bskyblock.addon.level.database.object;
import us.tastybento.bskyblock.database.objects.DataObject;
public class Levels extends DataObject {
public class LevelsData implements DataObject {
private String uniqueId = "";
private long level = 0;
@Override
public String getUniqueId() {
return uniqueId;
}
@Override
public void setUniqueId(String uniqueId) {
this.uniqueId = uniqueId;
}

View File

@ -13,7 +13,7 @@ import us.tastybento.bskyblock.database.objects.DataObject;
* @author ben
*
*/
public class TopTenList extends DataObject {
public class TopTenData implements DataObject {
private String uniqueId = "topten";
private HashMap<UUID, Long> topTen = new HashMap<>();