tastybento 2019-02-21 19:56:44 -08:00
parent bf965277c3
commit ddbe806af5
13 changed files with 103 additions and 55 deletions

View File

@ -6,7 +6,7 @@
<groupId>world.bentobox</groupId> <groupId>world.bentobox</groupId>
<artifactId>level</artifactId> <artifactId>level</artifactId>
<version>1.2.1-SNAPSHOT</version> <version>1.2.2-SNAPSHOT</version>
<name>Level</name> <name>Level</name>
<description>Level is an add-on for BentoBox, an expandable Minecraft Bukkit plugin for island-type games like SkyBlock or AcidIsland.</description> <description>Level is an add-on for BentoBox, an expandable Minecraft Bukkit plugin for island-type games like SkyBlock or AcidIsland.</description>

View File

@ -147,10 +147,7 @@ public class Level extends Addon {
// Register request handlers // Register request handlers
registerRequestHandler(new LevelRequestHandler(this)); registerRequestHandler(new LevelRequestHandler(this));
// Done // Done
} }
/** /**
@ -185,7 +182,7 @@ public class Level extends Addon {
} }
/** /**
* Sets the initial island level * Zeros the initial island level
* @param island - island * @param island - island
* @param level - initial calculated island level * @param level - initial calculated island level
*/ */
@ -194,10 +191,19 @@ public class Level extends Addon {
this.logError("Level: request to store a null (initial) " + island.getWorld() + " " + island.getOwner()); this.logError("Level: request to store a null (initial) " + island.getWorld() + " " + island.getOwner());
return; return;
} }
setIslandLevel(island.getWorld(), island.getOwner(), level); setIslandLevel(island.getWorld(), island.getOwner(), 0L);
levelsCache.get(island.getOwner()).setInitialIslandLevel(level); levelsCache.get(island.getOwner()).setInitialLevel(island.getWorld(), level);
} }
/**
* Get the initial island level
* @param island - island
* @return level or 0 by default
*/
public long getInitialIslandLevel(Island island) {
return levelsCache.containsKey(island.getOwner()) ? levelsCache.get(island.getOwner()).getInitialLevel(island.getWorld()) : 0L;
}
public Database<LevelsData> getHandler() { public Database<LevelsData> getHandler() {
return handler; return handler;
} }

View File

@ -14,12 +14,12 @@ import org.bukkit.World;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
import world.bentobox.level.objects.TopTenData;
import world.bentobox.bentobox.api.panels.PanelItem; import world.bentobox.bentobox.api.panels.PanelItem;
import world.bentobox.bentobox.api.panels.builders.PanelBuilder; import world.bentobox.bentobox.api.panels.builders.PanelBuilder;
import world.bentobox.bentobox.api.panels.builders.PanelItemBuilder; import world.bentobox.bentobox.api.panels.builders.PanelItemBuilder;
import world.bentobox.bentobox.api.user.User; import world.bentobox.bentobox.api.user.User;
import world.bentobox.bentobox.database.Database; import world.bentobox.bentobox.database.Database;
import world.bentobox.level.objects.TopTenData;
/** /**
* Handles all Top Ten List functions * Handles all Top Ten List functions

View File

@ -63,6 +63,9 @@ public class CalcIslandLevel {
// Results go here // Results go here
result = new Results(); result = new Results();
// Set the initial island handicap
result.initialLevel = addon.getInitialIslandLevel(island);
// Get chunks to scan // Get chunks to scan
chunksToScan = getChunksToScan(island); chunksToScan = getChunksToScan(island);
@ -229,7 +232,7 @@ public class CalcIslandLevel {
blockAndDeathPoints -= this.result.deathHandicap * this.addon.getSettings().getDeathPenalty(); blockAndDeathPoints -= this.result.deathHandicap * this.addon.getSettings().getDeathPenalty();
} }
this.result.level = blockAndDeathPoints / this.addon.getSettings().getLevelCost() - this.island.getLevelHandicap(); this.result.level = blockAndDeathPoints / this.addon.getSettings().getLevelCost() - this.island.getLevelHandicap() - result.initialLevel;
// Calculate how many points are required to get to the next level // Calculate how many points are required to get to the next level
@ -253,6 +256,7 @@ public class CalcIslandLevel {
reportLines.add("Total block value count = " + String.format("%,d",result.rawBlockCount)); reportLines.add("Total block value count = " + String.format("%,d",result.rawBlockCount));
reportLines.add("Level cost = " + addon.getSettings().getLevelCost()); reportLines.add("Level cost = " + addon.getSettings().getLevelCost());
reportLines.add("Deaths handicap = " + result.deathHandicap); reportLines.add("Deaths handicap = " + result.deathHandicap);
reportLines.add("Initial island level = " + (0L - result.initialLevel));
reportLines.add("Level calculated = " + result.level); reportLines.add("Level calculated = " + result.level);
reportLines.add(LINE_BREAK); reportLines.add(LINE_BREAK);
int total = 0; int total = 0;
@ -335,6 +339,8 @@ public class CalcIslandLevel {
private long level = 0; private long level = 0;
private int deathHandicap = 0; private int deathHandicap = 0;
private long pointsToNextLevel = 0; private long pointsToNextLevel = 0;
private long initialLevel = 0;
/** /**
* @return the deathHandicap * @return the deathHandicap
*/ */
@ -348,6 +354,13 @@ public class CalcIslandLevel {
public List<String> getReport() { public List<String> getReport() {
return report; return report;
} }
/**
* Set level
* @param level - level
*/
public void setLevel(int level) {
this.level = level;
}
/** /**
* @return the level * @return the level
*/ */
@ -361,6 +374,14 @@ public class CalcIslandLevel {
return pointsToNextLevel; return pointsToNextLevel;
} }
public long getInitialLevel() {
return initialLevel;
}
public void setInitialLevel(long initialLevel) {
this.initialLevel = initialLevel;
}
/* (non-Javadoc) /* (non-Javadoc)
* @see java.lang.Object#toString() * @see java.lang.Object#toString()
*/ */
@ -369,7 +390,7 @@ public class CalcIslandLevel {
return "Results [report=" + report + ", mdCount=" + mdCount + ", uwCount=" + uwCount + ", ncCount=" return "Results [report=" + report + ", mdCount=" + mdCount + ", uwCount=" + uwCount + ", ncCount="
+ ncCount + ", ofCount=" + ofCount + ", rawBlockCount=" + rawBlockCount + ", underWaterBlockCount=" + ncCount + ", ofCount=" + ofCount + ", rawBlockCount=" + rawBlockCount + ", underWaterBlockCount="
+ underWaterBlockCount + ", level=" + level + ", deathHandicap=" + deathHandicap + underWaterBlockCount + ", level=" + level + ", deathHandicap=" + deathHandicap
+ ", pointsToNextLevel=" + pointsToNextLevel + "]"; + ", pointsToNextLevel=" + pointsToNextLevel + ", initialLevel=" + initialLevel + "]";
} }
} }

View File

@ -56,6 +56,7 @@ public class PlayerLevel {
// Fire post calculation event // Fire post calculation event
IslandLevelCalculatedEvent ilce = new IslandLevelCalculatedEvent(targetPlayer, island, calc.getResult()); IslandLevelCalculatedEvent ilce = new IslandLevelCalculatedEvent(targetPlayer, island, calc.getResult());
addon.getServer().getPluginManager().callEvent(ilce); addon.getServer().getPluginManager().callEvent(ilce);
// This exposes these values to plugins via the event
Map<String, Object> keyValues = new HashMap<>(); Map<String, Object> keyValues = new HashMap<>();
keyValues.put("eventName", "IslandLevelCalculatedEvent"); keyValues.put("eventName", "IslandLevelCalculatedEvent");
keyValues.put("targetPlayer", targetPlayer); keyValues.put("targetPlayer", targetPlayer);
@ -63,6 +64,7 @@ public class PlayerLevel {
keyValues.put("level", calc.getResult().getLevel()); keyValues.put("level", calc.getResult().getLevel());
keyValues.put("pointsToNextLevel", calc.getResult().getPointsToNextLevel()); keyValues.put("pointsToNextLevel", calc.getResult().getPointsToNextLevel());
keyValues.put("deathHandicap", calc.getResult().getDeathHandicap()); keyValues.put("deathHandicap", calc.getResult().getDeathHandicap());
keyValues.put("initialLevel", calc.getResult().getInitialLevel());
addon.getServer().getPluginManager().callEvent(new AddonEvent().builder().addon(addon).keyValues(keyValues).build()); addon.getServer().getPluginManager().callEvent(new AddonEvent().builder().addon(addon).keyValues(keyValues).build());
Results results = ilce.getResults(); Results results = ilce.getResults();
// Save the results // Save the results

View File

@ -1,12 +1,15 @@
package world.bentobox.level.commands.admin; package world.bentobox.level.commands.admin;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import java.util.UUID;
import world.bentobox.bentobox.api.commands.CompositeCommand; import world.bentobox.bentobox.api.commands.CompositeCommand;
import world.bentobox.bentobox.api.user.User; import world.bentobox.bentobox.api.user.User;
import world.bentobox.bentobox.util.Util;
import world.bentobox.level.Level; import world.bentobox.level.Level;
import java.util.List;
import java.util.UUID;
public class AdminLevelCommand extends CompositeCommand { public class AdminLevelCommand extends CompositeCommand {
private final Level levelPlugin; private final Level levelPlugin;
@ -42,4 +45,15 @@ public class AdminLevelCommand extends CompositeCommand {
return false; return false;
} }
} }
@Override
public Optional<List<String>> tabComplete(User user, String alias, List<String> args) {
String lastArg = !args.isEmpty() ? args.get(args.size()-1) : "";
if (args.isEmpty()) {
// Don't show every player on the server. Require at least the first letter
return Optional.empty();
}
List<String> options = new ArrayList<>(Util.getOnlinePlayerList(user));
return Optional.of(Util.tabLimit(options, lastArg));
}
} }

View File

@ -4,8 +4,6 @@ import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.UUID; import java.util.UUID;
import org.bukkit.World;
import world.bentobox.bentobox.api.commands.CompositeCommand; import world.bentobox.bentobox.api.commands.CompositeCommand;
import world.bentobox.bentobox.api.user.User; import world.bentobox.bentobox.api.user.User;
import world.bentobox.bentobox.database.objects.Island; import world.bentobox.bentobox.database.objects.Island;
@ -29,26 +27,9 @@ public class AdminTopCommand extends CompositeCommand {
@Override @Override
public boolean execute(User user, String label, List<String> args) { public boolean execute(User user, String label, List<String> args) {
// Get world
World world;
if (args.isEmpty()) {
if (getPlugin().getIWM().getOverWorlds().size() == 1) {
world = getPlugin().getIWM().getOverWorlds().get(0);
} else {
showHelp(this, user);
return false;
}
} else {
world = getPlugin().getIWM().getIslandWorld(args.get(0));
if (world == null) {
user.sendMessage("commands.admin.top.unknown-world");
return false;
}
}
int rank = 0; int rank = 0;
for (Map.Entry<UUID, Long> topTen : levelPlugin.getTopTen().getTopTenList(world).getTopTen().entrySet()) { for (Map.Entry<UUID, Long> topTen : levelPlugin.getTopTen().getTopTenList(getWorld()).getTopTen().entrySet()) {
Island island = getPlugin().getIslands().getIsland(world, topTen.getKey()); Island island = getPlugin().getIslands().getIsland(getWorld(), topTen.getKey());
if (island != null) { if (island != null) {
rank++; rank++;
user.sendMessage("admin.top.display", user.sendMessage("admin.top.display",

View File

@ -1,12 +1,12 @@
package world.bentobox.level.commands.island; package world.bentobox.level.commands.island;
import java.util.List;
import java.util.UUID;
import world.bentobox.bentobox.api.commands.CompositeCommand; import world.bentobox.bentobox.api.commands.CompositeCommand;
import world.bentobox.bentobox.api.user.User; import world.bentobox.bentobox.api.user.User;
import world.bentobox.level.Level; import world.bentobox.level.Level;
import java.util.List;
import java.util.UUID;
public class IslandLevelCommand extends CompositeCommand { public class IslandLevelCommand extends CompositeCommand {
private final Level levelPlugin; private final Level levelPlugin;

View File

@ -1,11 +1,11 @@
package world.bentobox.level.commands.island; package world.bentobox.level.commands.island;
import java.util.List;
import world.bentobox.bentobox.api.commands.CompositeCommand; import world.bentobox.bentobox.api.commands.CompositeCommand;
import world.bentobox.bentobox.api.user.User; import world.bentobox.bentobox.api.user.User;
import world.bentobox.level.Level; import world.bentobox.level.Level;
import java.util.List;
public class IslandTopCommand extends CompositeCommand { public class IslandTopCommand extends CompositeCommand {
private final Level plugin; private final Level plugin;

View File

@ -2,9 +2,9 @@ package world.bentobox.level.event;
import java.util.UUID; import java.util.UUID;
import world.bentobox.level.calculators.CalcIslandLevel.Results;
import world.bentobox.bentobox.api.events.IslandBaseEvent; import world.bentobox.bentobox.api.events.IslandBaseEvent;
import world.bentobox.bentobox.database.objects.Island; import world.bentobox.bentobox.database.objects.Island;
import world.bentobox.level.calculators.CalcIslandLevel.Results;
/** /**
* This event is fired after the island level is calculated and before the results are saved. * This event is fired after the island level is calculated and before the results are saved.

View File

@ -16,11 +16,16 @@ public class LevelsData implements DataObject {
@Expose @Expose
private String uniqueId = ""; private String uniqueId = "";
// Map - world name, level /**
* Map of world name and island level
*/
@Expose @Expose
private Map<String, Long> levels = new HashMap<>(); private Map<String, Long> levels = new HashMap<>();
/**
* Map of world name to island initial level
*/
@Expose @Expose
private long initialIslandLevel = 0; private Map<String, Long> initialLevel = new HashMap<>();
public LevelsData() {} // For Bean loading public LevelsData() {} // For Bean loading
@ -54,10 +59,10 @@ public class LevelsData implements DataObject {
/** /**
* Get the island level for this world * Get the island level for this world
* @param world - world * @param world - world
* @return island level, less the initialIslandLevel * @return island level
*/ */
public Long getLevel(World world) { public Long getLevel(World world) {
return world == null ? -initialIslandLevel : levels.getOrDefault(world.getName(), 0L) - initialIslandLevel; return world == null ? 0L : levels.getOrDefault(world.getName(), 0L);
} }
/** /**
@ -79,16 +84,34 @@ public class LevelsData implements DataObject {
} }
/** /**
* @return the initialIslandLevel * Set the initial level of the island for this world
* @param world - world
* @param level - level
*/ */
public long getInitialIslandLevel() { public void setInitialLevel(World world, long level) {
return initialIslandLevel; this.initialLevel.put(world.getName(), level);
} }
/** /**
* @param initialIslandLevel the initialIslandLevel to set * @return the initialLevel
*/ */
public void setInitialIslandLevel(long initialIslandLevel) { public Map<String, Long> getInitialLevel() {
this.initialIslandLevel = initialIslandLevel; return initialLevel;
}
/**
* @param initialLevel the initialLevel to set
*/
public void setInitialLevel(Map<String, Long> initialLevel) {
this.initialLevel = initialLevel;
}
/**
* Get the initial island level for this world
* @param world - world
* @return initial island level or 0 by default
*/
public long getInitialLevel(World world) {
return initialLevel.getOrDefault(world.getName(), 0L);
} }
} }

View File

@ -1,12 +1,13 @@
package world.bentobox.level.requests; package world.bentobox.level.requests;
import org.bukkit.Bukkit;
import world.bentobox.bentobox.api.addons.request.AddonRequestHandler;
import world.bentobox.level.Level;
import java.util.Map; import java.util.Map;
import java.util.UUID; import java.util.UUID;
import org.bukkit.Bukkit;
import world.bentobox.bentobox.api.addons.request.AddonRequestHandler;
import world.bentobox.level.Level;
public class LevelRequestHandler extends AddonRequestHandler { public class LevelRequestHandler extends AddonRequestHandler {
private Level addon; private Level addon;

View File

@ -15,11 +15,11 @@ import org.powermock.api.mockito.PowerMockito;
import org.powermock.core.classloader.annotations.PrepareForTest; import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner; import org.powermock.modules.junit4.PowerMockRunner;
import world.bentobox.level.calculators.PlayerLevel;
import world.bentobox.bentobox.BentoBox; import world.bentobox.bentobox.BentoBox;
import world.bentobox.bentobox.api.user.User; import world.bentobox.bentobox.api.user.User;
import world.bentobox.bentobox.managers.IslandWorldManager; import world.bentobox.bentobox.managers.IslandWorldManager;
import world.bentobox.bentobox.managers.IslandsManager; import world.bentobox.bentobox.managers.IslandsManager;
import world.bentobox.level.calculators.PlayerLevel;
/** /**
* @author tastybento * @author tastybento