mirror of
https://github.com/BentoBoxWorld/Level.git
synced 2024-09-27 21:32:39 +02:00
Compare commits
2 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
6ddc0471cf | ||
|
1321bcf9d6 |
26
pom.xml
26
pom.xml
@ -65,7 +65,7 @@
|
||||
<!-- Do not change unless you want different name for local builds. -->
|
||||
<build.number>-LOCAL</build.number>
|
||||
<!-- This allows to change between versions. -->
|
||||
<build.version>2.6.3</build.version>
|
||||
<build.version>2.6.4</build.version>
|
||||
</properties>
|
||||
|
||||
<!-- Profiles will allow to automatically change build version. -->
|
||||
@ -108,30 +108,6 @@
|
||||
<build.number></build.number>
|
||||
</properties>
|
||||
</profile>
|
||||
<profile>
|
||||
<id>sonar</id>
|
||||
<properties>
|
||||
<sonar.host.url>https://sonarcloud.io</sonar.host.url>
|
||||
<sonar.organization>bentobox-world</sonar.organization>
|
||||
</properties>
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.sonarsource.scanner.maven</groupId>
|
||||
<artifactId>sonar-maven-plugin</artifactId>
|
||||
<version>3.6.0.1398</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<phase>verify</phase>
|
||||
<goals>
|
||||
<goal>sonar</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</profile>
|
||||
</profiles>
|
||||
|
||||
<repositories>
|
||||
|
@ -247,11 +247,6 @@ public class Level extends Addon implements Listener {
|
||||
public void onDisable() {
|
||||
// Stop the pipeline
|
||||
this.getPipeliner().stop();
|
||||
// Save player data and the top tens
|
||||
if (manager != null) {
|
||||
manager.save();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void loadBlockSettings() {
|
||||
|
@ -64,8 +64,6 @@ public class LevelsManager {
|
||||
private final Database<IslandLevels> handler;
|
||||
// A cache of island levels.
|
||||
private final Map<String, IslandLevels> levelsCache;
|
||||
|
||||
private final Database<TopTenData> topTenHandler;
|
||||
// Top ten lists
|
||||
private final Map<World,TopTenData> topTenLists;
|
||||
// Background
|
||||
@ -79,8 +77,6 @@ public class LevelsManager {
|
||||
// Set up the database handler to store and retrieve data
|
||||
// Note that these are saved by the BentoBox database
|
||||
handler = new Database<>(addon, IslandLevels.class);
|
||||
// Top Ten handler
|
||||
topTenHandler = new Database<>(addon, TopTenData.class);
|
||||
// Initialize the cache
|
||||
levelsCache = new HashMap<>();
|
||||
// Initialize top ten lists
|
||||
@ -181,8 +177,6 @@ public class LevelsManager {
|
||||
}
|
||||
// Save result
|
||||
setIslandResults(island.getWorld(), island.getOwner(), r);
|
||||
// Save top ten
|
||||
addon.getManager().saveTopTen(island.getWorld());
|
||||
// Save the island scan details
|
||||
result.complete(r);
|
||||
});
|
||||
@ -418,11 +412,11 @@ public class LevelsManager {
|
||||
.collect(Collectors.toMap(
|
||||
Map.Entry::getKey, Map.Entry::getValue, (e1, e2) -> e1, LinkedHashMap::new)));
|
||||
}
|
||||
|
||||
|
||||
void createAndCleanRankings(@NonNull World world) {
|
||||
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));
|
||||
topTenLists.get(world).getTopTen().keySet().removeIf(u -> !hasTopTenPerm(world, u));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -441,12 +435,12 @@ public class LevelsManager {
|
||||
public int getRank(@NonNull World world, UUID uuid) {
|
||||
createAndCleanRankings(world);
|
||||
Stream<Entry<UUID, Long>> stream = topTenLists.get(world).getTopTen().entrySet().stream()
|
||||
.filter(e -> addon.getIslands().isOwner(world, e.getKey()))
|
||||
.filter(l -> l.getValue() > 0)
|
||||
.sorted(Collections.reverseOrder(Map.Entry.comparingByValue()));
|
||||
.filter(e -> addon.getIslands().isOwner(world, e.getKey()))
|
||||
.filter(l -> l.getValue() > 0)
|
||||
.sorted(Collections.reverseOrder(Map.Entry.comparingByValue()));
|
||||
return takeWhile(stream, x -> !x.getKey().equals(uuid)).map(Map.Entry::getKey).collect(Collectors.toList()).size() + 1;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Java 8's version of Java 9's takeWhile
|
||||
* @param stream
|
||||
@ -457,7 +451,7 @@ public class LevelsManager {
|
||||
CustomSpliterator<T> customSpliterator = new CustomSpliterator<>(stream.spliterator(), predicate);
|
||||
return StreamSupport.stream(customSpliterator, false);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Checks if player has the correct top ten perm to have their level saved
|
||||
* @param world
|
||||
@ -475,15 +469,14 @@ public class LevelsManager {
|
||||
void loadTopTens() {
|
||||
topTenLists.clear();
|
||||
Bukkit.getScheduler().runTaskAsynchronously(addon.getPlugin(), () -> {
|
||||
addon.log("Generating Top Ten Tables");
|
||||
addon.log("Generating rankings");
|
||||
handler.loadObjects().forEach(il -> {
|
||||
if (il.getLevel() > 0) {
|
||||
addon.getIslands().getIslandById(il.getUniqueId()).ifPresent(i -> this.addToTopTen(i, il.getLevel()));
|
||||
}
|
||||
});
|
||||
topTenLists.keySet().forEach(w -> {
|
||||
addon.log("Loaded top ten for " + w.getName());
|
||||
this.saveTopTen(w);
|
||||
addon.log("Generated rankings for " + w.getName());
|
||||
});
|
||||
|
||||
});
|
||||
@ -497,27 +490,10 @@ public class LevelsManager {
|
||||
public void removeEntry(World world, UUID uuid) {
|
||||
if (topTenLists.containsKey(world)) {
|
||||
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
|
||||
* @param island - the island to set. Must have a non-null world
|
||||
|
@ -401,14 +401,6 @@ public class LevelsManagerTest {
|
||||
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)}.
|
||||
*/
|
||||
@ -443,7 +435,7 @@ public class LevelsManagerTest {
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Test method for {@link world.bentobox.level.LevelsManager#getRank(World, UUID)}
|
||||
*/
|
||||
@ -453,7 +445,7 @@ public class LevelsManagerTest {
|
||||
Map<World, TopTenData> ttl = lm.getTopTenLists();
|
||||
Map<UUID, Long> tt = ttl.get(world).getTopTen();
|
||||
for (long i = 100; i < 150; i++) {
|
||||
tt.put(UUID.randomUUID(), i);
|
||||
tt.put(UUID.randomUUID(), i);
|
||||
}
|
||||
// Put player as lowest rank
|
||||
tt.put(uuid, 10L);
|
||||
|
Loading…
Reference in New Issue
Block a user