mirror of
https://github.com/BentoBoxWorld/Level.git
synced 2024-11-30 14:03:27 +01:00
No save on disable (#231)
* Release 2.6.4 * Remove saving to database on disable. https://github.com/BentoBoxWorld/Level/issues/229 First, the top ten tables are never actually used or loaded. They are created in memory by loading the island levels. So there is no reason to keep saving them. Second, the island level data is saved every time it is changed, so there is no need to save all of the cache on exit. * Fixes tests
This commit is contained in:
parent
76a2688556
commit
d55f66f868
@ -275,11 +275,6 @@ public class Level extends Addon implements Listener {
|
|||||||
public void onDisable() {
|
public void onDisable() {
|
||||||
// Stop the pipeline
|
// Stop the pipeline
|
||||||
this.getPipeliner().stop();
|
this.getPipeliner().stop();
|
||||||
// Save player data and the top tens
|
|
||||||
if (manager != null) {
|
|
||||||
manager.save();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void loadBlockSettings() {
|
private void loadBlockSettings() {
|
||||||
|
@ -62,8 +62,6 @@ public class LevelsManager {
|
|||||||
private final Database<IslandLevels> handler;
|
private final Database<IslandLevels> handler;
|
||||||
// A cache of island levels.
|
// A cache of island levels.
|
||||||
private final Map<String, IslandLevels> levelsCache;
|
private final Map<String, IslandLevels> levelsCache;
|
||||||
|
|
||||||
private final Database<TopTenData> topTenHandler;
|
|
||||||
// Top ten lists
|
// Top ten lists
|
||||||
private final Map<World,TopTenData> topTenLists;
|
private final Map<World,TopTenData> topTenLists;
|
||||||
// Background
|
// Background
|
||||||
@ -77,8 +75,6 @@ public class LevelsManager {
|
|||||||
// Set up the database handler to store and retrieve data
|
// Set up the database handler to store and retrieve data
|
||||||
// Note that these are saved by the BentoBox database
|
// Note that these are saved by the BentoBox database
|
||||||
handler = new Database<>(addon, IslandLevels.class);
|
handler = new Database<>(addon, IslandLevels.class);
|
||||||
// Top Ten handler
|
|
||||||
topTenHandler = new Database<>(addon, TopTenData.class);
|
|
||||||
// Initialize the cache
|
// Initialize the cache
|
||||||
levelsCache = new HashMap<>();
|
levelsCache = new HashMap<>();
|
||||||
// Initialize top ten lists
|
// Initialize top ten lists
|
||||||
@ -179,8 +175,6 @@ public class LevelsManager {
|
|||||||
}
|
}
|
||||||
// Save result
|
// Save result
|
||||||
setIslandResults(island.getWorld(), island.getOwner(), r);
|
setIslandResults(island.getWorld(), island.getOwner(), r);
|
||||||
// Save top ten
|
|
||||||
addon.getManager().saveTopTen(island.getWorld());
|
|
||||||
// Save the island scan details
|
// Save the island scan details
|
||||||
result.complete(r);
|
result.complete(r);
|
||||||
});
|
});
|
||||||
@ -462,15 +456,14 @@ public class LevelsManager {
|
|||||||
void loadTopTens() {
|
void loadTopTens() {
|
||||||
topTenLists.clear();
|
topTenLists.clear();
|
||||||
Bukkit.getScheduler().runTaskAsynchronously(addon.getPlugin(), () -> {
|
Bukkit.getScheduler().runTaskAsynchronously(addon.getPlugin(), () -> {
|
||||||
addon.log("Generating Top Ten Tables");
|
addon.log("Generating rankings");
|
||||||
handler.loadObjects().forEach(il -> {
|
handler.loadObjects().forEach(il -> {
|
||||||
if (il.getLevel() > 0) {
|
if (il.getLevel() > 0) {
|
||||||
addon.getIslands().getIslandById(il.getUniqueId()).ifPresent(i -> this.addToTopTen(i, il.getLevel()));
|
addon.getIslands().getIslandById(il.getUniqueId()).ifPresent(i -> this.addToTopTen(i, il.getLevel()));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
topTenLists.keySet().forEach(w -> {
|
topTenLists.keySet().forEach(w -> {
|
||||||
addon.log("Loaded top ten for " + w.getName());
|
addon.log("Generated rankings for " + w.getName());
|
||||||
this.saveTopTen(w);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
@ -484,27 +477,10 @@ public class LevelsManager {
|
|||||||
public void removeEntry(World world, UUID uuid) {
|
public void removeEntry(World world, UUID uuid) {
|
||||||
if (topTenLists.containsKey(world)) {
|
if (topTenLists.containsKey(world)) {
|
||||||
topTenLists.get(world).getTopTen().remove(uuid);
|
topTenLists.get(world).getTopTen().remove(uuid);
|
||||||
topTenHandler.saveObjectAsync(topTenLists.get(world));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Saves all player data and the top ten
|
|
||||||
*/
|
|
||||||
public void save() {
|
|
||||||
levelsCache.values().forEach(handler::saveObjectAsync);
|
|
||||||
topTenLists.values().forEach(topTenHandler::saveObjectAsync);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Save the top ten for world
|
|
||||||
* @param world - world
|
|
||||||
*/
|
|
||||||
public void saveTopTen(World world) {
|
|
||||||
topTenHandler.saveObjectAsync(topTenLists.get(world));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set an initial island level
|
* Set an initial island level
|
||||||
* @param island - the island to set. Must have a non-null world
|
* @param island - the island to set. Must have a non-null world
|
||||||
|
@ -383,8 +383,8 @@ public class LevelsManagerTest {
|
|||||||
Bukkit.getScheduler();
|
Bukkit.getScheduler();
|
||||||
verify(scheduler).runTaskAsynchronously(eq(plugin), task.capture());
|
verify(scheduler).runTaskAsynchronously(eq(plugin), task.capture());
|
||||||
task.getValue().run();
|
task.getValue().run();
|
||||||
verify(addon).log(eq("Generating Top Ten Tables"));
|
verify(addon).log(eq("Generating rankings"));
|
||||||
verify(addon).log(eq("Loaded top ten for bskyblock-world"));
|
verify(addon).log(eq("Generated rankings for bskyblock-world"));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -401,14 +401,6 @@ public class LevelsManagerTest {
|
|||||||
assertFalse(tt.containsKey(uuid));
|
assertFalse(tt.containsKey(uuid));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Test method for {@link world.bentobox.level.LevelsManager#save()}.
|
|
||||||
*/
|
|
||||||
@Test
|
|
||||||
public void testSave() {
|
|
||||||
lm.save();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test method for {@link world.bentobox.level.LevelsManager#setInitialIslandLevel(world.bentobox.bentobox.database.objects.Island, long)}.
|
* Test method for {@link world.bentobox.level.LevelsManager#setInitialIslandLevel(world.bentobox.bentobox.database.objects.Island, long)}.
|
||||||
*/
|
*/
|
||||||
|
Loading…
Reference in New Issue
Block a user