mirror of
https://github.com/BentoBoxWorld/Level.git
synced 2024-12-25 10:38:20 +01:00
Moved to addon API.
This commit is contained in:
parent
eb715afcda
commit
b240fce328
@ -4,8 +4,6 @@ version: 0.1
|
||||
|
||||
authors: [tastybento]
|
||||
|
||||
depend: [BSkyBlock]
|
||||
|
||||
permissions:
|
||||
bskyblock.intopten:
|
||||
description: Player is in the top ten.
|
@ -8,7 +8,6 @@ import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
|
||||
import org.bukkit.Chunk;
|
||||
import org.bukkit.ChunkSnapshot;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.World;
|
||||
@ -34,14 +33,14 @@ import us.tastybento.bskyblock.database.objects.Island;
|
||||
public class ChunkScanner {
|
||||
private static final boolean DEBUG = false;
|
||||
protected static final boolean LEVEL_LOGGING = false;
|
||||
private final Level plugin;
|
||||
private final Level addon;
|
||||
private final Set<ChunkSnapshot> finalChunk;
|
||||
private final Results result;
|
||||
private final Optional<User> asker;
|
||||
|
||||
|
||||
public ChunkScanner(Level plugin, Island island) {
|
||||
this.plugin = plugin;
|
||||
this.addon = plugin;
|
||||
// Get the chunks to scan
|
||||
finalChunk = getIslandChunks(island);
|
||||
this.asker = Optional.empty();
|
||||
@ -52,12 +51,12 @@ public class ChunkScanner {
|
||||
|
||||
/**
|
||||
* Calculates the level of an island
|
||||
* @param plugin
|
||||
* @param addon
|
||||
* @param island - island that is being calculated
|
||||
* @param asker - the user who wants the report
|
||||
*/
|
||||
public ChunkScanner(Level plugin, Island island, User asker) {
|
||||
this.plugin = plugin;
|
||||
public ChunkScanner(Level addon, Island island, User asker) {
|
||||
this.addon = addon;
|
||||
// Get the chunks to scan
|
||||
finalChunk = getIslandChunks(island);
|
||||
this.asker = Optional.of(asker);
|
||||
@ -68,7 +67,7 @@ public class ChunkScanner {
|
||||
|
||||
private void runAsyncCount(Island island) {
|
||||
// Run AsyncTask to count blocks in the chunk snapshots
|
||||
plugin.getServer().getScheduler().runTaskAsynchronously(plugin, new Runnable() {
|
||||
addon.getServer().getScheduler().runTaskAsynchronously(addon.getBSkyBlock(), new Runnable() {
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
@Override
|
||||
@ -81,14 +80,14 @@ public class ChunkScanner {
|
||||
// Check if the block coord is inside the protection zone and if not, don't count it
|
||||
if (chunk.getX() * 16 + x < island.getMinProtectedX() || chunk.getX() * 16 + x >= island.getMinProtectedX() + (island.getProtectionRange() * 2)) {
|
||||
if (DEBUG)
|
||||
plugin.getLogger().info("Block is outside protected area - x = " + (chunk.getX() * 16 + x));
|
||||
addon.getLogger().info("Block is outside protected area - x = " + (chunk.getX() * 16 + x));
|
||||
continue;
|
||||
}
|
||||
for (int z = 0; z < 16; z++) {
|
||||
// Check if the block coord is inside the protection zone and if not, don't count it
|
||||
if (chunk.getZ() * 16 + z < island.getMinProtectedZ() || chunk.getZ() * 16 + z >= island.getMinProtectedZ() + (island.getProtectionRange() * 2)) {
|
||||
if (DEBUG)
|
||||
plugin.getLogger().info("Block is outside protected area - z = " + (chunk.getZ() * 16 + z));
|
||||
addon.getLogger().info("Block is outside protected area - z = " + (chunk.getZ() * 16 + z));
|
||||
continue;
|
||||
}
|
||||
|
||||
@ -99,13 +98,13 @@ public class ChunkScanner {
|
||||
MaterialData generic = new MaterialData(type);
|
||||
if (!type.equals(Material.AIR)) { // AIR
|
||||
if (DEBUG)
|
||||
plugin.getLogger().info("Block is inside protected area " + (chunk.getX() * 16) + "," + (chunk.getZ() * 16 + z));
|
||||
addon.getLogger().info("Block is inside protected area " + (chunk.getX() * 16) + "," + (chunk.getZ() * 16 + z));
|
||||
if (DEBUG)
|
||||
plugin.getLogger().info("Block is " + md + "[" + generic +"]");
|
||||
addon.getLogger().info("Block is " + md + "[" + generic +"]");
|
||||
if (limitCount.containsKey(md) && Settings.blockValues.containsKey(md)) {
|
||||
int count = limitCount.get(md);
|
||||
if (DEBUG)
|
||||
plugin.getLogger().info("DEBUG: Count for non-generic " + md + " is " + count);
|
||||
addon.getLogger().info("DEBUG: Count for non-generic " + md + " is " + count);
|
||||
if (count > 0) {
|
||||
limitCount.put(md, --count);
|
||||
if (Settings.seaHeight > 0 && y<=Settings.seaHeight) {
|
||||
@ -121,7 +120,7 @@ public class ChunkScanner {
|
||||
} else if (limitCount.containsKey(generic) && Settings.blockValues.containsKey(generic)) {
|
||||
int count = limitCount.get(generic);
|
||||
if (DEBUG)
|
||||
plugin.getLogger().info("DEBUG: Count for generic " + generic + " is " + count);
|
||||
addon.getLogger().info("DEBUG: Count for generic " + generic + " is " + count);
|
||||
if (count > 0) {
|
||||
limitCount.put(generic, --count);
|
||||
if (Settings.seaHeight > 0 && y<=Settings.seaHeight) {
|
||||
@ -136,7 +135,7 @@ public class ChunkScanner {
|
||||
}
|
||||
} else if (Settings.blockValues.containsKey(md)) {
|
||||
if (DEBUG)
|
||||
plugin.getLogger().info("DEBUG: Adding " + md + " = " + Settings.blockValues.get(md));
|
||||
addon.getLogger().info("DEBUG: Adding " + md + " = " + Settings.blockValues.get(md));
|
||||
if (Settings.seaHeight > 0 && y<=Settings.seaHeight) {
|
||||
result.underWaterBlockCount += Settings.blockValues.get(md);
|
||||
result.uwCount.add(md);
|
||||
@ -146,7 +145,7 @@ public class ChunkScanner {
|
||||
}
|
||||
} else if (Settings.blockValues.containsKey(generic)) {
|
||||
if (DEBUG)
|
||||
plugin.getLogger().info("DEBUG: Adding " + generic + " = " + Settings.blockValues.get(generic));
|
||||
addon.getLogger().info("DEBUG: Adding " + generic + " = " + Settings.blockValues.get(generic));
|
||||
if (Settings.seaHeight > 0 && y<=Settings.seaHeight) {
|
||||
result.underWaterBlockCount += Settings.blockValues.get(generic);
|
||||
result.uwCount.add(md);
|
||||
@ -165,14 +164,14 @@ public class ChunkScanner {
|
||||
|
||||
result.rawBlockCount += (long)((double)result.underWaterBlockCount * Settings.underWaterMultiplier);
|
||||
if (DEBUG)
|
||||
plugin.getLogger().info("DEBUG: block count = "+result.rawBlockCount);
|
||||
addon.getLogger().info("DEBUG: block count = "+result.rawBlockCount);
|
||||
// Set the death penalty
|
||||
result.deathHandicap = BSkyBlock.getPlugin().getPlayers().getDeaths(island.getOwner()) * Settings.deathpenalty;
|
||||
result.deathHandicap = BSkyBlock.getInstance().getPlayers().getDeaths(island.getOwner()) * Settings.deathpenalty;
|
||||
// Set final score
|
||||
result.score = (result.rawBlockCount / Settings.levelCost) - result.deathHandicap;
|
||||
|
||||
// Return to main thread
|
||||
plugin.getServer().getScheduler().runTask(plugin, new Runnable() {
|
||||
addon.getServer().getScheduler().runTask(addon.getBSkyBlock(), new Runnable() {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
@ -302,7 +301,7 @@ public class ChunkScanner {
|
||||
final World world = island.getWorld();
|
||||
// Get the chunks
|
||||
if (DEBUG)
|
||||
plugin.getLogger().info("DEBUG: Getting chunks. Protection range = " + island.getProtectionRange());
|
||||
addon.getLogger().info("DEBUG: Getting chunks. Protection range = " + island.getProtectionRange());
|
||||
//long nano = System.nanoTime();
|
||||
Set<ChunkSnapshot> chunkSnapshot = new HashSet<ChunkSnapshot>();
|
||||
for (int x = island.getMinProtectedX(); x < (island.getMinProtectedX() + (island.getProtectionRange() *2) + 16); x += 16) {
|
||||
@ -315,11 +314,11 @@ public class ChunkScanner {
|
||||
chunkSnapshot.add(world.getBlockAt(x, 0, z).getChunk().getChunkSnapshot());
|
||||
|
||||
if (DEBUG)
|
||||
plugin.getLogger().info("DEBUG: getting chunk at " + x + ", " + z);
|
||||
addon.getLogger().info("DEBUG: getting chunk at " + x + ", " + z);
|
||||
}
|
||||
}
|
||||
if (DEBUG)
|
||||
plugin.getLogger().info("DEBUG: size of chunk snapshot = " + chunkSnapshot.size());
|
||||
addon.getLogger().info("DEBUG: size of chunk snapshot = " + chunkSnapshot.size());
|
||||
return chunkSnapshot;
|
||||
}
|
||||
|
||||
|
@ -7,7 +7,6 @@ import java.util.HashMap;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.bukkit.scheduler.BukkitTask;
|
||||
|
||||
import bskyblock.addin.level.commands.AdminLevel;
|
||||
@ -17,6 +16,7 @@ import bskyblock.addin.level.commands.IslandTop;
|
||||
import bskyblock.addin.level.config.PluginConfig;
|
||||
import bskyblock.addin.level.database.object.Levels;
|
||||
import us.tastybento.bskyblock.BSkyBlock;
|
||||
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;
|
||||
@ -28,7 +28,7 @@ import us.tastybento.bskyblock.database.managers.AbstractDatabaseHandler;
|
||||
* @author tastybento
|
||||
*
|
||||
*/
|
||||
public class Level extends JavaPlugin {
|
||||
public class Level extends AddOn {
|
||||
|
||||
|
||||
// The BSkyBlock plugin instance.
|
||||
@ -60,7 +60,7 @@ public class Level extends JavaPlugin {
|
||||
// Load the plugin's config
|
||||
new PluginConfig(this);
|
||||
// Get the BSkyBlock plugin. This will be available because this plugin depends on it in plugin.yml.
|
||||
bSkyBlock = BSkyBlock.getPlugin();
|
||||
bSkyBlock = BSkyBlock.getInstance();
|
||||
// Check if it is enabled - it might be loaded, but not enabled.
|
||||
if (!bSkyBlock.isEnabled()) {
|
||||
this.setEnabled(false);
|
||||
@ -73,18 +73,20 @@ public class Level extends JavaPlugin {
|
||||
handler = (AbstractDatabaseHandler<Levels>) database.getHandler(bSkyBlock, Levels.class);
|
||||
// Initialize the cache
|
||||
levelsCache = new HashMap<>();
|
||||
// Load all the levels
|
||||
load();
|
||||
// Load the calculator
|
||||
levelCalc = new LevelPresenter(this);
|
||||
// Start the top ten and register it for clicks
|
||||
topTen = new TopTen(this);
|
||||
getServer().getPluginManager().registerEvents(topTen, this);
|
||||
registerListener(topTen);
|
||||
// Local locales
|
||||
//localeManager = new LocaleManager(this);
|
||||
// Register commands
|
||||
CompositeCommand bsbIslandCmd = (CompositeCommand) BSkyBlock.getPlugin().getCommandsManager().getCommand(Settings.ISLANDCOMMAND);
|
||||
CompositeCommand bsbIslandCmd = (CompositeCommand) BSkyBlock.getInstance().getCommandsManager().getCommand(Settings.ISLANDCOMMAND);
|
||||
new IslandLevel(this, bsbIslandCmd);
|
||||
new IslandTop(this, bsbIslandCmd);
|
||||
CompositeCommand bsbAdminCmd = (CompositeCommand) BSkyBlock.getPlugin().getCommandsManager().getCommand(Settings.ADMINCOMMAND);
|
||||
CompositeCommand bsbAdminCmd = (CompositeCommand) BSkyBlock.getInstance().getCommandsManager().getCommand(Settings.ADMINCOMMAND);
|
||||
new AdminLevel(this, bsbAdminCmd);
|
||||
new AdminTop(this, bsbAdminCmd);
|
||||
// Done
|
||||
@ -98,6 +100,18 @@ public class Level extends JavaPlugin {
|
||||
}
|
||||
}
|
||||
|
||||
public void load() {
|
||||
try {
|
||||
for (Levels level : handler.loadObjects()) {
|
||||
levelsCache.put(UUID.fromString(level.getUniqueId()), level.getLevel());
|
||||
}
|
||||
} catch (InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException
|
||||
| SecurityException | ClassNotFoundException | IntrospectionException | SQLException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Save the levels to the database
|
||||
* @param async - if true, saving will be done async
|
||||
@ -118,7 +132,7 @@ public class Level extends JavaPlugin {
|
||||
}
|
||||
};
|
||||
if(async){
|
||||
getServer().getScheduler().runTaskAsynchronously(this, save);
|
||||
getServer().getScheduler().runTaskAsynchronously(getBSkyBlock(), save);
|
||||
} else {
|
||||
save.run();
|
||||
}
|
||||
|
@ -15,7 +15,7 @@ public abstract class LevelPlugin {
|
||||
|
||||
public LevelPlugin(Level plugin) {
|
||||
this.plugin = plugin;
|
||||
this.bSkyBlock = BSkyBlock.getPlugin();
|
||||
this.bSkyBlock = BSkyBlock.getInstance();
|
||||
}
|
||||
|
||||
public final Logger getLogger() {
|
||||
|
@ -45,7 +45,6 @@ import bskyblock.addin.level.database.object.Levels;
|
||||
import bskyblock.addin.level.database.object.TopTenList;
|
||||
import bskyblock.addin.level.event.TopTenClick;
|
||||
import us.tastybento.bskyblock.BSkyBlock;
|
||||
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;
|
||||
@ -75,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.getPlugin(), TopTenList.class);
|
||||
handler = (AbstractDatabaseHandler<TopTenList>) database.getHandler(BSkyBlock.getInstance(), TopTenList.class);
|
||||
loadTopTen();
|
||||
}
|
||||
|
||||
@ -116,7 +115,7 @@ public class TopTen implements Listener {
|
||||
// Convert to UUID
|
||||
UUID playerUUID = UUID.fromString(lv.getUniqueId());
|
||||
// Check if the player is an owner or team leader
|
||||
if (BSkyBlock.getPlugin().getIslands().isOwner(playerUUID)) {
|
||||
if (BSkyBlock.getInstance().getIslands().isOwner(playerUUID)) {
|
||||
topTenList.addLevel(playerUUID, lv.getLevel());
|
||||
}
|
||||
}
|
||||
@ -183,25 +182,25 @@ public class TopTen implements Listener {
|
||||
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);
|
||||
String playerName = BSkyBlock.getInstance().getPlayers().getName(player);
|
||||
if (DEBUG) {
|
||||
plugin.getLogger().info("DEBUG: playername = " + playerName);
|
||||
|
||||
plugin.getLogger().info("DEBUG: second chance = " + BSkyBlock.getPlugin().getPlayers().getName(player));
|
||||
plugin.getLogger().info("DEBUG: second chance = " + BSkyBlock.getInstance().getPlayers().getName(player));
|
||||
}
|
||||
ItemStack playerSkull = new ItemStack(Material.SKULL_ITEM, 1, (short) 3);
|
||||
if (playerName == null) return null;
|
||||
SkullMeta meta = (SkullMeta) playerSkull.getItemMeta();
|
||||
//meta.setOwningPlayer(plugin.getServer().getOfflinePlayer(player));
|
||||
meta.setOwner(playerName);
|
||||
meta.setDisplayName(("topten.guiHeading".replace("[name]", BSkyBlock.getPlugin().getIslands().getIslandName(player))).replace("[rank]", String.valueOf(rank)));
|
||||
meta.setDisplayName(("topten.guiHeading".replace("[name]", BSkyBlock.getInstance().getIslands().getIslandName(player))).replace("[rank]", String.valueOf(rank)));
|
||||
//meta.setDisplayName(ChatColor.YELLOW + "" + ChatColor.BOLD + "<!> " + ChatColor.YELLOW + "Island: " + ChatColor.GOLD + ChatColor.UNDERLINE + plugin.getGrid().getIslandName(player) + ChatColor.GRAY + " (#" + rank + ")");
|
||||
List<String> lore = new ArrayList<String>();
|
||||
lore.add(ChatColor.YELLOW + "topten.islandLevel".replace("[level]", String.valueOf(long1)));
|
||||
if (BSkyBlock.getPlugin().getPlayers().inTeam(player)) {
|
||||
if (BSkyBlock.getInstance().getPlayers().inTeam(player)) {
|
||||
List<String> memberList = new ArrayList<>();
|
||||
for (UUID members : BSkyBlock.getPlugin().getIslands().getMembers(player)) {
|
||||
memberList.add(ChatColor.AQUA + BSkyBlock.getPlugin().getPlayers().getName(members));
|
||||
for (UUID members : BSkyBlock.getInstance().getIslands().getMembers(player)) {
|
||||
memberList.add(ChatColor.AQUA + BSkyBlock.getInstance().getPlayers().getName(members));
|
||||
}
|
||||
lore.addAll(memberList);
|
||||
}
|
||||
|
@ -15,9 +15,6 @@ public class AdminLevel extends CompositeCommand {
|
||||
public AdminLevel(Level levelPlugin, CompositeCommand parent) {
|
||||
super(parent, "level");
|
||||
this.levelPlugin = levelPlugin;
|
||||
this.setPermission(Settings.PERMPREFIX + "admin.level");
|
||||
this.setOnlyPlayer(false);
|
||||
this.setUsage("admin.level.usage");
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -41,4 +38,13 @@ public class AdminLevel extends CompositeCommand {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setup() {
|
||||
this.setPermission(Settings.PERMPREFIX + "admin.level");
|
||||
this.setOnlyPlayer(false);
|
||||
this.setParameters("admin.level.parameters");
|
||||
this.setDescription("admin.level.description");
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -17,9 +17,6 @@ public class AdminTop extends CompositeCommand {
|
||||
public AdminTop(Level levelPlugin, CompositeCommand parent) {
|
||||
super(parent, "top", "topten");
|
||||
this.levelPlugin = levelPlugin;
|
||||
this.setPermission(Settings.PERMPREFIX + "admin.top");
|
||||
this.setOnlyPlayer(false);
|
||||
this.setUsage("admin.top.usage");
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -28,7 +25,7 @@ public class AdminTop extends CompositeCommand {
|
||||
for (Entry<UUID, Long> topTen : levelPlugin.getTopTen().getTopTenList().getTopTen().entrySet()) {
|
||||
UUID player = topTen.getKey();
|
||||
rank++;
|
||||
String item = String.valueOf(rank) + ":" + BSkyBlock.getPlugin().getIslands().getIslandName(player) + " "
|
||||
String item = String.valueOf(rank) + ":" + BSkyBlock.getInstance().getIslands().getIslandName(player) + " "
|
||||
+ "topten.islandLevel" + String.valueOf(topTen.getValue());
|
||||
user.sendLegacyMessage(item);
|
||||
}
|
||||
@ -36,4 +33,11 @@ public class AdminTop extends CompositeCommand {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setup() {
|
||||
this.setPermission(Settings.PERMPREFIX + "admin.top");
|
||||
this.setOnlyPlayer(false);
|
||||
this.setParameters("admin.top.usage");
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -15,9 +15,6 @@ public class IslandLevel extends CompositeCommand {
|
||||
public IslandLevel(Level levelPlugin, CompositeCommand parent) {
|
||||
super(parent, "level");
|
||||
this.levelPlugin = levelPlugin;
|
||||
this.setPermission(Settings.PERMPREFIX + "island.level");
|
||||
this.setUsage("island.level.usage");
|
||||
this.setOnlyPlayer(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -45,4 +42,12 @@ public class IslandLevel extends CompositeCommand {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setup() {
|
||||
this.setPermission(Settings.PERMPREFIX + "island.level");
|
||||
this.setParameters("island.level.parameters");
|
||||
this.setDescription("island.level.description");
|
||||
this.setOnlyPlayer(true);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -14,8 +14,6 @@ public class IslandTop extends CompositeCommand {
|
||||
public IslandTop(Level plugin, CompositeCommand parent) {
|
||||
super(parent, "top", "topten");
|
||||
this.plugin = plugin;
|
||||
this.setPermission(Settings.PERMPREFIX + "island.top");
|
||||
this.setUsage("island.top.usage");
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -24,4 +22,12 @@ public class IslandTop extends CompositeCommand {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setup() {
|
||||
this.setPermission(Settings.PERMPREFIX + "island.top");
|
||||
this.setDescription("island.top.description");
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user