mirror of
https://github.com/BentoBoxWorld/Level.git
synced 2024-11-23 18:45:17 +01:00
Fixes a load of bugs.
https://github.com/BentoBoxWorld/Level/issues/41 https://github.com/BentoBoxWorld/Level/issues/44 https://github.com/BentoBoxWorld/Level/issues/45
This commit is contained in:
parent
bf965277c3
commit
ddbe806af5
2
pom.xml
2
pom.xml
@ -6,7 +6,7 @@
|
||||
|
||||
<groupId>world.bentobox</groupId>
|
||||
<artifactId>level</artifactId>
|
||||
<version>1.2.1-SNAPSHOT</version>
|
||||
<version>1.2.2-SNAPSHOT</version>
|
||||
|
||||
<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>
|
||||
|
@ -147,10 +147,7 @@ public class Level extends Addon {
|
||||
// Register request handlers
|
||||
registerRequestHandler(new LevelRequestHandler(this));
|
||||
|
||||
|
||||
|
||||
// Done
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@ -185,7 +182,7 @@ public class Level extends Addon {
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the initial island level
|
||||
* Zeros the initial island level
|
||||
* @param island - island
|
||||
* @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());
|
||||
return;
|
||||
}
|
||||
setIslandLevel(island.getWorld(), island.getOwner(), level);
|
||||
levelsCache.get(island.getOwner()).setInitialIslandLevel(level);
|
||||
setIslandLevel(island.getWorld(), island.getOwner(), 0L);
|
||||
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() {
|
||||
return handler;
|
||||
}
|
||||
|
@ -14,12 +14,12 @@ import org.bukkit.World;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.Listener;
|
||||
|
||||
import world.bentobox.level.objects.TopTenData;
|
||||
import world.bentobox.bentobox.api.panels.PanelItem;
|
||||
import world.bentobox.bentobox.api.panels.builders.PanelBuilder;
|
||||
import world.bentobox.bentobox.api.panels.builders.PanelItemBuilder;
|
||||
import world.bentobox.bentobox.api.user.User;
|
||||
import world.bentobox.bentobox.database.Database;
|
||||
import world.bentobox.level.objects.TopTenData;
|
||||
|
||||
/**
|
||||
* Handles all Top Ten List functions
|
||||
|
@ -63,6 +63,9 @@ public class CalcIslandLevel {
|
||||
// Results go here
|
||||
result = new Results();
|
||||
|
||||
// Set the initial island handicap
|
||||
result.initialLevel = addon.getInitialIslandLevel(island);
|
||||
|
||||
// Get chunks to scan
|
||||
chunksToScan = getChunksToScan(island);
|
||||
|
||||
@ -229,7 +232,7 @@ public class CalcIslandLevel {
|
||||
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
|
||||
@ -253,6 +256,7 @@ public class CalcIslandLevel {
|
||||
reportLines.add("Total block value count = " + String.format("%,d",result.rawBlockCount));
|
||||
reportLines.add("Level cost = " + addon.getSettings().getLevelCost());
|
||||
reportLines.add("Deaths handicap = " + result.deathHandicap);
|
||||
reportLines.add("Initial island level = " + (0L - result.initialLevel));
|
||||
reportLines.add("Level calculated = " + result.level);
|
||||
reportLines.add(LINE_BREAK);
|
||||
int total = 0;
|
||||
@ -335,6 +339,8 @@ public class CalcIslandLevel {
|
||||
private long level = 0;
|
||||
private int deathHandicap = 0;
|
||||
private long pointsToNextLevel = 0;
|
||||
private long initialLevel = 0;
|
||||
|
||||
/**
|
||||
* @return the deathHandicap
|
||||
*/
|
||||
@ -348,6 +354,13 @@ public class CalcIslandLevel {
|
||||
public List<String> getReport() {
|
||||
return report;
|
||||
}
|
||||
/**
|
||||
* Set level
|
||||
* @param level - level
|
||||
*/
|
||||
public void setLevel(int level) {
|
||||
this.level = level;
|
||||
}
|
||||
/**
|
||||
* @return the level
|
||||
*/
|
||||
@ -361,6 +374,14 @@ public class CalcIslandLevel {
|
||||
return pointsToNextLevel;
|
||||
}
|
||||
|
||||
public long getInitialLevel() {
|
||||
return initialLevel;
|
||||
}
|
||||
|
||||
public void setInitialLevel(long initialLevel) {
|
||||
this.initialLevel = initialLevel;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see java.lang.Object#toString()
|
||||
*/
|
||||
@ -369,7 +390,7 @@ public class CalcIslandLevel {
|
||||
return "Results [report=" + report + ", mdCount=" + mdCount + ", uwCount=" + uwCount + ", ncCount="
|
||||
+ ncCount + ", ofCount=" + ofCount + ", rawBlockCount=" + rawBlockCount + ", underWaterBlockCount="
|
||||
+ underWaterBlockCount + ", level=" + level + ", deathHandicap=" + deathHandicap
|
||||
+ ", pointsToNextLevel=" + pointsToNextLevel + "]";
|
||||
+ ", pointsToNextLevel=" + pointsToNextLevel + ", initialLevel=" + initialLevel + "]";
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -56,6 +56,7 @@ public class PlayerLevel {
|
||||
// Fire post calculation event
|
||||
IslandLevelCalculatedEvent ilce = new IslandLevelCalculatedEvent(targetPlayer, island, calc.getResult());
|
||||
addon.getServer().getPluginManager().callEvent(ilce);
|
||||
// This exposes these values to plugins via the event
|
||||
Map<String, Object> keyValues = new HashMap<>();
|
||||
keyValues.put("eventName", "IslandLevelCalculatedEvent");
|
||||
keyValues.put("targetPlayer", targetPlayer);
|
||||
@ -63,6 +64,7 @@ public class PlayerLevel {
|
||||
keyValues.put("level", calc.getResult().getLevel());
|
||||
keyValues.put("pointsToNextLevel", calc.getResult().getPointsToNextLevel());
|
||||
keyValues.put("deathHandicap", calc.getResult().getDeathHandicap());
|
||||
keyValues.put("initialLevel", calc.getResult().getInitialLevel());
|
||||
addon.getServer().getPluginManager().callEvent(new AddonEvent().builder().addon(addon).keyValues(keyValues).build());
|
||||
Results results = ilce.getResults();
|
||||
// Save the results
|
||||
|
@ -1,12 +1,15 @@
|
||||
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.user.User;
|
||||
import world.bentobox.bentobox.util.Util;
|
||||
import world.bentobox.level.Level;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
public class AdminLevelCommand extends CompositeCommand {
|
||||
|
||||
private final Level levelPlugin;
|
||||
@ -42,4 +45,15 @@ public class AdminLevelCommand extends CompositeCommand {
|
||||
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));
|
||||
}
|
||||
}
|
||||
|
@ -4,8 +4,6 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.bukkit.World;
|
||||
|
||||
import world.bentobox.bentobox.api.commands.CompositeCommand;
|
||||
import world.bentobox.bentobox.api.user.User;
|
||||
import world.bentobox.bentobox.database.objects.Island;
|
||||
@ -29,26 +27,9 @@ public class AdminTopCommand extends CompositeCommand {
|
||||
|
||||
@Override
|
||||
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;
|
||||
for (Map.Entry<UUID, Long> topTen : levelPlugin.getTopTen().getTopTenList(world).getTopTen().entrySet()) {
|
||||
Island island = getPlugin().getIslands().getIsland(world, topTen.getKey());
|
||||
for (Map.Entry<UUID, Long> topTen : levelPlugin.getTopTen().getTopTenList(getWorld()).getTopTen().entrySet()) {
|
||||
Island island = getPlugin().getIslands().getIsland(getWorld(), topTen.getKey());
|
||||
if (island != null) {
|
||||
rank++;
|
||||
user.sendMessage("admin.top.display",
|
||||
|
@ -1,12 +1,12 @@
|
||||
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.user.User;
|
||||
import world.bentobox.level.Level;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
public class IslandLevelCommand extends CompositeCommand {
|
||||
|
||||
private final Level levelPlugin;
|
||||
|
@ -1,11 +1,11 @@
|
||||
package world.bentobox.level.commands.island;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import world.bentobox.bentobox.api.commands.CompositeCommand;
|
||||
import world.bentobox.bentobox.api.user.User;
|
||||
import world.bentobox.level.Level;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class IslandTopCommand extends CompositeCommand {
|
||||
|
||||
private final Level plugin;
|
||||
|
@ -2,9 +2,9 @@ package world.bentobox.level.event;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
import world.bentobox.level.calculators.CalcIslandLevel.Results;
|
||||
import world.bentobox.bentobox.api.events.IslandBaseEvent;
|
||||
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.
|
||||
|
@ -16,11 +16,16 @@ public class LevelsData implements DataObject {
|
||||
@Expose
|
||||
private String uniqueId = "";
|
||||
|
||||
// Map - world name, level
|
||||
/**
|
||||
* Map of world name and island level
|
||||
*/
|
||||
@Expose
|
||||
private Map<String, Long> levels = new HashMap<>();
|
||||
/**
|
||||
* Map of world name to island initial level
|
||||
*/
|
||||
@Expose
|
||||
private long initialIslandLevel = 0;
|
||||
private Map<String, Long> initialLevel = new HashMap<>();
|
||||
|
||||
public LevelsData() {} // For Bean loading
|
||||
|
||||
@ -54,10 +59,10 @@ public class LevelsData implements DataObject {
|
||||
/**
|
||||
* Get the island level for this world
|
||||
* @param world - world
|
||||
* @return island level, less the initialIslandLevel
|
||||
* @return island level
|
||||
*/
|
||||
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() {
|
||||
return initialIslandLevel;
|
||||
public void setInitialLevel(World world, long level) {
|
||||
this.initialLevel.put(world.getName(), level);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param initialIslandLevel the initialIslandLevel to set
|
||||
* @return the initialLevel
|
||||
*/
|
||||
public void setInitialIslandLevel(long initialIslandLevel) {
|
||||
this.initialIslandLevel = initialIslandLevel;
|
||||
public Map<String, Long> getInitialLevel() {
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
@ -1,12 +1,13 @@
|
||||
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.UUID;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
|
||||
import world.bentobox.bentobox.api.addons.request.AddonRequestHandler;
|
||||
import world.bentobox.level.Level;
|
||||
|
||||
public class LevelRequestHandler extends AddonRequestHandler {
|
||||
|
||||
private Level addon;
|
||||
|
@ -15,11 +15,11 @@ import org.powermock.api.mockito.PowerMockito;
|
||||
import org.powermock.core.classloader.annotations.PrepareForTest;
|
||||
import org.powermock.modules.junit4.PowerMockRunner;
|
||||
|
||||
import world.bentobox.level.calculators.PlayerLevel;
|
||||
import world.bentobox.bentobox.BentoBox;
|
||||
import world.bentobox.bentobox.api.user.User;
|
||||
import world.bentobox.bentobox.managers.IslandWorldManager;
|
||||
import world.bentobox.bentobox.managers.IslandsManager;
|
||||
import world.bentobox.level.calculators.PlayerLevel;
|
||||
|
||||
/**
|
||||
* @author tastybento
|
||||
|
Loading…
Reference in New Issue
Block a user