Bug fixes from sonar cloud.
This commit is contained in:
parent
08b7c99c3f
commit
d5c4e3a53c
|
@ -12,7 +12,6 @@ import world.bentobox.bentobox.api.addons.Addon;
|
|||
import world.bentobox.bentobox.api.addons.GameModeAddon;
|
||||
import world.bentobox.bentobox.api.configuration.Config;
|
||||
import world.bentobox.bentobox.api.user.User;
|
||||
import world.bentobox.level.calculators.IslandLevelCalculator;
|
||||
import world.bentobox.level.calculators.Pipeliner;
|
||||
import world.bentobox.level.commands.AdminLevelCommand;
|
||||
import world.bentobox.level.commands.AdminLevelStatusCommand;
|
||||
|
@ -39,6 +38,7 @@ public class Level extends Addon {
|
|||
private BlockConfig blockConfig;
|
||||
private Pipeliner pipeliner;
|
||||
private LevelsManager manager;
|
||||
private boolean stackersEnabled;
|
||||
|
||||
@Override
|
||||
public void onLoad() {
|
||||
|
@ -85,7 +85,7 @@ public class Level extends Addon {
|
|||
// Check if WildStackers is enabled on the server
|
||||
// I only added support for counting blocks into the island level
|
||||
// Someone else can PR if they want spawners added to the Leveling system :)
|
||||
IslandLevelCalculator.stackersEnabled = Bukkit.getPluginManager().getPlugin("WildStacker") != null;
|
||||
stackersEnabled = Bukkit.getPluginManager().getPlugin("WildStacker") != null;
|
||||
|
||||
}
|
||||
|
||||
|
@ -119,13 +119,13 @@ public class Level extends Addon {
|
|||
private String getRankName(World world, int rank) {
|
||||
if (rank < 1) rank = 1;
|
||||
if (rank > 10) rank = 10;
|
||||
return getPlayers().getName(getManager().getTopTen(world, 10).keySet().stream().skip(rank - 1).limit(1).findFirst().orElse(null));
|
||||
return getPlayers().getName(getManager().getTopTen(world, 10).keySet().stream().skip(rank - 1L).limit(1L).findFirst().orElse(null));
|
||||
}
|
||||
|
||||
private String getRankLevel(World world, int rank) {
|
||||
if (rank < 1) rank = 1;
|
||||
if (rank > 10) rank = 10;
|
||||
return getManager().formatLevel(getManager().getTopTen(world, 10).values().stream().skip(rank - 1).limit(1).findFirst().orElse(null));
|
||||
return getManager().formatLevel(getManager().getTopTen(world, 10).values().stream().skip(rank - 1L).limit(1L).findFirst().orElse(null));
|
||||
}
|
||||
|
||||
private String getVisitedIslandLevel(GameModeAddon gm, User user) {
|
||||
|
@ -214,4 +214,11 @@ public class Level extends Addon {
|
|||
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the stackersEnabled
|
||||
*/
|
||||
public boolean isStackersEnabled() {
|
||||
return stackersEnabled;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -36,6 +36,7 @@ import world.bentobox.level.objects.TopTenData;
|
|||
public class LevelsManager {
|
||||
private static final String INTOPTEN = "intopten";
|
||||
private static final TreeMap<BigInteger, String> LEVELS;
|
||||
private static final int[] SLOTS = new int[] {4, 12, 14, 19, 20, 21, 22, 23, 24, 25};
|
||||
private static final BigInteger THOUSAND = BigInteger.valueOf(1000);
|
||||
static {
|
||||
LEVELS = new TreeMap<>();
|
||||
|
@ -53,7 +54,6 @@ public class LevelsManager {
|
|||
// A cache of island levels.
|
||||
private final Map<UUID, LevelsData> levelsCache;
|
||||
|
||||
private final int[] SLOTS = new int[] {4, 12, 14, 19, 20, 21, 22, 23, 24, 25};
|
||||
private final Database<TopTenData> topTenHandler;
|
||||
// Top ten lists
|
||||
private Map<World,TopTenData> topTenLists;
|
||||
|
@ -125,7 +125,6 @@ public class LevelsManager {
|
|||
keyValues.put("deathHandicap", results.getDeathHandicap());
|
||||
keyValues.put("initialLevel", results.getInitialLevel());
|
||||
new AddonEvent().builder().addon(addon).keyValues(keyValues).build();
|
||||
results = ilce.getResults();
|
||||
return ilce.isCancelled();
|
||||
}
|
||||
|
||||
|
@ -272,7 +271,7 @@ public class LevelsManager {
|
|||
* @return sorted top ten map
|
||||
*/
|
||||
public Map<UUID, Long> getTopTen(World world, int size) {
|
||||
topTenLists.computeIfAbsent(world, k -> new TopTenData(k));
|
||||
topTenLists.computeIfAbsent(world, TopTenData::new);
|
||||
// Remove player from top ten if they are online and do not have the perm
|
||||
topTenLists.get(world).getTopTen().keySet().removeIf(u -> !hasTopTenPerm(world, u));
|
||||
// Return the sorted map
|
||||
|
@ -291,8 +290,7 @@ public class LevelsManager {
|
|||
*/
|
||||
boolean hasTopTenPerm(@NonNull World world, @NonNull UUID targetPlayer) {
|
||||
String permPrefix = addon.getPlugin().getIWM().getPermissionPrefix(world);
|
||||
boolean hasPerm = Bukkit.getPlayer(targetPlayer) != null && Bukkit.getPlayer(targetPlayer).hasPermission(permPrefix + INTOPTEN);
|
||||
return hasPerm;
|
||||
return Bukkit.getPlayer(targetPlayer) != null && Bukkit.getPlayer(targetPlayer).hasPermission(permPrefix + INTOPTEN);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -348,12 +346,12 @@ public class LevelsManager {
|
|||
*/
|
||||
public void setInitialIslandLevel(@NonNull Island island, long lv) {
|
||||
if (island.getOwner() == null || island.getWorld() == null) return;
|
||||
levelsCache.computeIfAbsent(island.getOwner(), k -> new LevelsData(k)).setInitialLevel(island.getWorld(), lv);
|
||||
levelsCache.computeIfAbsent(island.getOwner(), LevelsData::new).setInitialLevel(island.getWorld(), lv);
|
||||
handler.saveObjectAsync(levelsCache.get(island.getOwner()));
|
||||
}
|
||||
|
||||
public void setIslandLevel(@NonNull World world, @NonNull UUID targetPlayer, long lv) {
|
||||
levelsCache.computeIfAbsent(targetPlayer, k -> new LevelsData(targetPlayer)).setLevel(world, lv);
|
||||
levelsCache.computeIfAbsent(targetPlayer, LevelsData::new).setLevel(world, lv);
|
||||
handler.saveObjectAsync(levelsCache.get(targetPlayer));
|
||||
// Add to Top Ten
|
||||
addToTopTen(world, targetPlayer, lv);
|
||||
|
|
|
@ -41,7 +41,6 @@ import world.bentobox.level.Level;
|
|||
public class IslandLevelCalculator {
|
||||
private static final String LINE_BREAK = "==================================";
|
||||
public static final long MAX_AMOUNT = 10000;
|
||||
public static Boolean stackersEnabled;
|
||||
|
||||
/**
|
||||
* Method to evaluate a mathematical equation
|
||||
|
@ -381,7 +380,7 @@ public class IslandLevelCalculator {
|
|||
}
|
||||
}
|
||||
// Hook for Wild Stackers (Blocks Only) - this has to use the real chunk
|
||||
if (stackersEnabled && blockData.getMaterial() == Material.CAULDRON) {
|
||||
if (addon.isStackersEnabled() && blockData.getMaterial() == Material.CAULDRON) {
|
||||
Block cauldronBlock = chunk.getBlock(x, y, z);
|
||||
if (WildStackerAPI.getWildStacker().getSystemManager().isStackedBarrel(cauldronBlock)) {
|
||||
StackedBarrel barrel = WildStackerAPI.getStackedBarrel(cauldronBlock);
|
||||
|
@ -431,9 +430,6 @@ public class IslandLevelCalculator {
|
|||
* @return future that completes when the scan is done and supplies a boolean that will be true if the scan was successful, false if not
|
||||
*/
|
||||
private CompletableFuture<Boolean> scanChunk(@NonNull Chunk chunk) {
|
||||
if (chunk == null) {
|
||||
return CompletableFuture.completedFuture(false);
|
||||
}
|
||||
// Scan chests
|
||||
if (addon.getSettings().isIncludeChests()) {
|
||||
scanChests(chunk);
|
||||
|
|
|
@ -72,7 +72,7 @@ public class Pipeliner {
|
|||
if (!Bukkit.isPrimaryThread()) {
|
||||
addon.getPlugin().logError("scanChunk not on Primary Thread!");
|
||||
}
|
||||
if (r) {
|
||||
if (Boolean.TRUE.equals(r)) {
|
||||
// scanNextChunk returns true if there are more chunks to scan
|
||||
scanChunk(iD);
|
||||
} else {
|
||||
|
|
|
@ -9,9 +9,12 @@ import world.bentobox.bentobox.api.localization.TextVariables;
|
|||
import world.bentobox.bentobox.api.user.User;
|
||||
import world.bentobox.bentobox.database.objects.Island;
|
||||
import world.bentobox.level.Level;
|
||||
import world.bentobox.level.calculators.Results;
|
||||
|
||||
public class IslandLevelCommand extends CompositeCommand {
|
||||
|
||||
private static final String ISLAND_LEVEL_IS = "island.level.island-level-is";
|
||||
private static final String LEVEL = "[level]";
|
||||
private final Level addon;
|
||||
|
||||
public IslandLevelCommand(Level addon, CompositeCommand parent) {
|
||||
|
@ -43,7 +46,7 @@ public class IslandLevelCommand extends CompositeCommand {
|
|||
}
|
||||
// Request for another player's island level
|
||||
if (!user.getUniqueId().equals(playerUUID) ) {
|
||||
user.sendMessage("island.level.island-level-is", "[level]", addon.getManager().getIslandLevelString(getWorld(), playerUUID));
|
||||
user.sendMessage(ISLAND_LEVEL_IS, LEVEL, addon.getManager().getIslandLevelString(getWorld(), playerUUID));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -66,7 +69,11 @@ public class IslandLevelCommand extends CompositeCommand {
|
|||
|
||||
private boolean scanIsland(User user, UUID playerUUID) {
|
||||
Island island = getIslands().getIsland(getWorld(), playerUUID);
|
||||
if (island != null) {
|
||||
if (island == null) {
|
||||
user.sendMessage("general.errors.player-has-no-island");
|
||||
return false;
|
||||
|
||||
}
|
||||
user.sendMessage("island.level.calculating");
|
||||
int inQueue = addon.getPipeliner().getIslandsInQueue();
|
||||
if (inQueue > 1) {
|
||||
|
@ -76,8 +83,15 @@ public class IslandLevelCommand extends CompositeCommand {
|
|||
long oldLevel = addon.getManager().getIslandLevel(getWorld(), playerUUID);
|
||||
addon.getManager().calculateLevel(playerUUID, island).thenAccept(results -> {
|
||||
if (results == null) return; // island was deleted or become unowned
|
||||
showResult(user, playerUUID, island, oldLevel, results);
|
||||
});
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
private void showResult(User user, UUID playerUUID, Island island, long oldLevel, Results results) {
|
||||
if (user.isPlayer()) {
|
||||
user.sendMessage("island.level.island-level-is", "[level]", addon.getManager().getIslandLevelString(getWorld(), playerUUID));
|
||||
user.sendMessage(ISLAND_LEVEL_IS, LEVEL, addon.getManager().getIslandLevelString(getWorld(), playerUUID));
|
||||
// Player
|
||||
if (addon.getSettings().getDeathPenalty() != 0) {
|
||||
user.sendMessage("island.level.deaths", "[number]", String.valueOf(results.getDeathHandicap()));
|
||||
|
@ -90,17 +104,11 @@ public class IslandLevelCommand extends CompositeCommand {
|
|||
if (results.getLevel() != oldLevel) {
|
||||
island.getMemberSet().stream()
|
||||
.filter(u -> !u.equals(user.getUniqueId()))
|
||||
.forEach(m -> User.getInstance(m).sendMessage("island.level.island-level-is", "[level]", addon.getManager().getIslandLevelString(getWorld(), playerUUID)));
|
||||
.forEach(m -> User.getInstance(m).sendMessage(ISLAND_LEVEL_IS, LEVEL, addon.getManager().getIslandLevelString(getWorld(), playerUUID)));
|
||||
}
|
||||
} else {
|
||||
results.getReport().forEach(BentoBox.getInstance()::log);
|
||||
}
|
||||
});
|
||||
return true;
|
||||
} else {
|
||||
user.sendMessage("general.errors.player-has-no-island");
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -49,9 +49,8 @@ public class IslandActivitiesListeners implements Listener {
|
|||
private void zeroIsland(final Island island) {
|
||||
// Clear the island setting
|
||||
if (island.getOwner() != null && island.getWorld() != null) {
|
||||
addon.getPipeliner().addIsland(island).thenAccept(results -> {
|
||||
addon.getManager().setInitialIslandLevel(island, results.getLevel());
|
||||
});
|
||||
addon.getPipeliner().addIsland(island).thenAccept(results ->
|
||||
addon.getManager().setInitialIslandLevel(island, results.getLevel()));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -246,7 +246,7 @@ public class LevelsManagerTest {
|
|||
lm.calculateLevel(uuid, island);
|
||||
cf.complete(results);
|
||||
|
||||
assertTrue(lm.getLevelsData(uuid).getLevel(world) == 10000);
|
||||
assertEquals(Long.valueOf(10000), lm.getLevelsData(uuid).getLevel(world));
|
||||
//Map<UUID, Long> tt = lm.getTopTen(world, 10);
|
||||
//assertEquals(1, tt.size());
|
||||
//assertTrue(tt.get(uuid) == 10000);
|
||||
|
|
Loading…
Reference in New Issue