From 284f18c68088b34fd72faa0207a477aa07946424 Mon Sep 17 00:00:00 2001 From: tastybento Date: Fri, 21 Aug 2020 16:21:02 -0700 Subject: [PATCH] Fixes bugs with tests. Support old Biomes addons. --- src/main/java/world/bentobox/level/Level.java | 17 +++++++++++++++++ .../world/bentobox/level/LevelsManager.java | 6 ++++++ .../world/bentobox/level/LevelsManagerTest.java | 1 + 3 files changed, 24 insertions(+) diff --git a/src/main/java/world/bentobox/level/Level.java b/src/main/java/world/bentobox/level/Level.java index b381993..e424914 100644 --- a/src/main/java/world/bentobox/level/Level.java +++ b/src/main/java/world/bentobox/level/Level.java @@ -31,6 +31,7 @@ import world.bentobox.level.config.BlockConfig; import world.bentobox.level.config.ConfigSettings; import world.bentobox.level.listeners.IslandActivitiesListeners; import world.bentobox.level.listeners.JoinLeaveListener; +import world.bentobox.level.objects.LevelsData; import world.bentobox.level.requests.LevelRequestHandler; import world.bentobox.level.requests.TopTenRequestHandler; @@ -325,4 +326,20 @@ public class Level extends Addon implements Listener { if (island != null) getManager().calculateLevel(playerUUID, island); } + /** + * Provide the levels data for the target player + * @param targetPlayer - UUID of target player + * @return LevelsData object or null if not found. Only island levels are set! + * @deprecated Do not use this anymore. Use {@link #getIslandLevel(World, UUID)} + */ + @Deprecated + public LevelsData getLevelsData(UUID targetPlayer) { + LevelsData ld = new LevelsData(targetPlayer); + getPlugin().getAddonsManager().getGameModeAddons().stream() + .filter(gm -> !settings.getGameModes().contains(gm.getDescription().getName())) + .forEach(gm -> { + ld.setLevel(gm.getOverWorld(), this.getIslandLevel(gm.getOverWorld(), targetPlayer)); + }); + return ld; + } } diff --git a/src/main/java/world/bentobox/level/LevelsManager.java b/src/main/java/world/bentobox/level/LevelsManager.java index a56103f..91d18d1 100644 --- a/src/main/java/world/bentobox/level/LevelsManager.java +++ b/src/main/java/world/bentobox/level/LevelsManager.java @@ -158,6 +158,8 @@ public class LevelsManager { addon.getPipeliner().addIsland(island).thenAccept(r -> { // Results are irrelevant because the island is unowned or deleted, or IslandLevelCalcEvent is cancelled if (r == null || fireIslandLevelCalcEvent(targetPlayer, island, r)) { + System.out.println("results are null or event canceled"); + result.complete(null); } // Save result @@ -498,6 +500,8 @@ public class LevelsManager { // Remove the initial level if (addon.getSettings().isZeroNewIslandLevels()) { il.setLevel(lv - il.getInitialLevel()); + } else { + il.setLevel(lv); } handler.saveObjectAsync(levelsCache.get(id)); // Update TopTen @@ -520,6 +524,8 @@ public class LevelsManager { // Remove the initial level if (addon.getSettings().isZeroNewIslandLevels()) { ld.setLevel(r.getLevel() - ld.getInitialLevel()); + } else { + ld.setLevel(r.getLevel()); } ld.setUwCount(Maps.asMap(r.getUwCount().elementSet(), elem -> r.getUwCount().count(elem))); ld.setMdCount(Maps.asMap(r.getMdCount().elementSet(), elem -> r.getMdCount().count(elem))); diff --git a/src/test/java/world/bentobox/level/LevelsManagerTest.java b/src/test/java/world/bentobox/level/LevelsManagerTest.java index fc3aa9c..f87c464 100644 --- a/src/test/java/world/bentobox/level/LevelsManagerTest.java +++ b/src/test/java/world/bentobox/level/LevelsManagerTest.java @@ -256,6 +256,7 @@ public class LevelsManagerTest { results.setLevel(10000); results.setInitialLevel(3); lm.calculateLevel(uuid, island); + // Complete the pipelined completable future cf.complete(results); assertEquals(10000L, lm.getLevelsData(island).getLevel());