Fixes bug where top ten was cleared after reloading.

https://github.com/BentoBoxWorld/Level/issues/163
This commit is contained in:
tastybento 2020-07-04 15:46:36 -07:00
parent 66b098ec73
commit 39e294eaf6
2 changed files with 12 additions and 3 deletions

View File

@ -8,12 +8,15 @@ import org.bukkit.Bukkit;
import org.bukkit.World;
import org.bukkit.configuration.InvalidConfigurationException;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.eclipse.jdt.annotation.NonNull;
import org.eclipse.jdt.annotation.Nullable;
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.events.BentoBoxReadyEvent;
import world.bentobox.bentobox.api.user.User;
import world.bentobox.bentobox.database.objects.Island;
import world.bentobox.level.calculators.Pipeliner;
@ -35,7 +38,7 @@ import world.bentobox.level.requests.TopTenRequestHandler;
* @author tastybento
*
*/
public class Level extends Addon {
public class Level extends Addon implements Listener {
// Settings
private ConfigSettings settings;
@ -71,10 +74,10 @@ public class Level extends Addon {
pipeliner = new Pipeliner(this);
// Start Manager
manager = new LevelsManager(this);
manager.loadTopTens();
// Register listeners
this.registerListener(new IslandActivitiesListeners(this));
this.registerListener(new JoinLeaveListener(this));
this.registerListener(this);
// Register commands for GameModes
getPlugin().getAddonsManager().getGameModeAddons().stream()
.filter(gm -> !settings.getGameModes().contains(gm.getDescription().getName()))
@ -94,6 +97,11 @@ public class Level extends Addon {
}
@EventHandler
public void onBentoBoxReady(BentoBoxReadyEvent e) {
manager.loadTopTens();
}
private void registerPlaceholders(GameModeAddon gm) {
if (getPlugin().getPlaceholdersManager() == null) return;
// Island Level

View File

@ -355,7 +355,7 @@ public class LevelsManager {
World world = Bukkit.getWorld(tt.getUniqueId());
if (world != null) {
topTenLists.put(world, tt);
addon.log("Loaded TopTen for " + world.getName());
addon.log("Loaded top ten for " + world.getName());
// Update based on user data
// Remove any non island owners
tt.getTopTen().keySet().removeIf(u -> !addon.getIslands().isOwner(world, u));
@ -434,6 +434,7 @@ public class LevelsManager {
return ld.getLevel(world);
}
}
addon.getPlugin().logDebug("Returning 0L");
return 0L;
}