Skip to content

Commit 4a4794f

Browse files
authored
Release 2.7.2 (#233)
* Version 2.7.2 * Use Java 9's takeWhile * Added placeholder %Level_[gamemode]_rank_value Fixes #228 * No save on disable (#231) * Release 2.6.4 * Remove saving to database on disable. #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 * Rosestacker (#232) * Add support for RoseStacker 1.3.0 * Made plugin a Pladdon.
1 parent 389d06d commit 4a4794f

File tree

7 files changed

+102
-150
lines changed

7 files changed

+102
-150
lines changed

pom.xml

Lines changed: 14 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@
6565
<!-- Do not change unless you want different name for local builds. -->
6666
<build.number>-LOCAL</build.number>
6767
<!-- This allows to change between versions. -->
68-
<build.version>2.7.0</build.version>
68+
<build.version>2.7.2</build.version>
6969
<sonar.projectKey>BentoBoxWorld_Level</sonar.projectKey>
7070
<sonar.organization>bentobox-world</sonar.organization>
7171
<sonar.host.url>https://sonarcloud.io</sonar.host.url>
@@ -111,30 +111,6 @@
111111
<build.number></build.number>
112112
</properties>
113113
</profile>
114-
<profile>
115-
<id>sonar</id>
116-
<properties>
117-
<sonar.host.url>https://sonarcloud.io</sonar.host.url>
118-
<sonar.organization>bentobox-world</sonar.organization>
119-
</properties>
120-
<build>
121-
<plugins>
122-
<plugin>
123-
<groupId>org.sonarsource.scanner.maven</groupId>
124-
<artifactId>sonar-maven-plugin</artifactId>
125-
<version>3.6.0.1398</version>
126-
<executions>
127-
<execution>
128-
<phase>verify</phase>
129-
<goals>
130-
<goal>sonar</goal>
131-
</goals>
132-
</execution>
133-
</executions>
134-
</plugin>
135-
</plugins>
136-
</build>
137-
</profile>
138114
</profiles>
139115

140116
<repositories>
@@ -155,6 +131,11 @@
155131
<id>jitpack.io</id>
156132
<url>https://jitpack.io</url>
157133
</repository>
134+
<!-- RoseStacker repo -->
135+
<repository>
136+
<id>rosewood-repo</id>
137+
<url>https://repo.rosewooddev.io/repository/public/</url>
138+
</repository>
158139
</repositories>
159140

160141
<dependencies>
@@ -195,6 +176,7 @@
195176
<groupId>com.github.OmerBenGera</groupId>
196177
<artifactId>WildStackerAPI</artifactId>
197178
<version>b18</version>
179+
<scope>provided</scope>
198180
</dependency>
199181
<!-- Static analysis -->
200182
<!-- We are using Eclipse's annotations. If you're using IDEA, update
@@ -209,6 +191,13 @@
209191
<groupId>com.github.DeadSilenceIV</groupId>
210192
<artifactId>AdvancedChestsAPI</artifactId>
211193
<version>1.8</version>
194+
<scope>provided</scope>
195+
</dependency>
196+
<dependency>
197+
<groupId>dev.rosewood</groupId>
198+
<artifactId>rosestacker</artifactId>
199+
<version>1.3.0</version>
200+
<scope>provided</scope>
212201
</dependency>
213202
</dependencies>
214203

src/main/java/world/bentobox/level/CustomSpliterator.java

Lines changed: 0 additions & 38 deletions
This file was deleted.

src/main/java/world/bentobox/level/Level.java

Lines changed: 34 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
import world.bentobox.level.listeners.IslandActivitiesListeners;
3737
import world.bentobox.level.listeners.JoinLeaveListener;
3838
import world.bentobox.level.objects.LevelsData;
39+
import world.bentobox.level.objects.TopTenData;
3940
import world.bentobox.level.requests.LevelRequestHandler;
4041
import world.bentobox.level.requests.TopTenRequestHandler;
4142

@@ -56,6 +57,7 @@ public class Level extends Addon implements Listener {
5657
private LevelsManager manager;
5758
private boolean stackersEnabled;
5859
private boolean advChestEnabled;
60+
private boolean roseStackersEnabled;
5961
private final List<GameModeAddon> registeredGameModes = new ArrayList<>();
6062

6163
@Override
@@ -105,7 +107,7 @@ public void onEnable() {
105107
// Check if WildStackers is enabled on the server
106108
// I only added support for counting blocks into the island level
107109
// Someone else can PR if they want spawners added to the Leveling system :)
108-
stackersEnabled = Bukkit.getPluginManager().getPlugin("WildStacker") != null;
110+
stackersEnabled = Bukkit.getPluginManager().isPluginEnabled("WildStacker");
109111
if (stackersEnabled) {
110112
log("Hooked into WildStackers.");
111113
}
@@ -121,6 +123,11 @@ public void onEnable() {
121123
advChestEnabled = false;
122124
}
123125
}
126+
// Check if RoseStackers is enabled
127+
roseStackersEnabled = Bukkit.getPluginManager().isPluginEnabled("RoseStacker");
128+
if (roseStackersEnabled) {
129+
log("Hooked into RoseStackers.");
130+
}
124131
}
125132

126133
/**
@@ -206,6 +213,9 @@ private void registerPlaceholders(GameModeAddon gm) {
206213
gm.getDescription().getName().toLowerCase() + "_top_value_" + i, u -> getRankLevel(gm.getOverWorld(), rank));
207214
}
208215

216+
// Personal rank
217+
getPlugin().getPlaceholdersManager().registerPlaceholder(this,
218+
gm.getDescription().getName().toLowerCase() + "_rank_value", u -> getRankValue(gm.getOverWorld(), u));
209219
}
210220

211221
String getRankName(World world, int rank) {
@@ -228,8 +238,23 @@ String getRankLevel(World world, int rank) {
228238
.orElse(null));
229239
}
230240

241+
/**
242+
* Return the rank of the player in a world
243+
* @param world world
244+
* @param user player
245+
* @return rank where 1 is the top rank.
246+
*/
247+
String getRankValue(World world, User user) {
248+
if (user == null) {
249+
return "";
250+
}
251+
// Get the island level for this user
252+
long level = getManager().getIslandLevel(world, user.getUniqueId());
253+
return String.valueOf(getManager().getTopTenLists().getOrDefault(world, new TopTenData(world)).getTopTen().values().stream().filter(l -> l > level).count() + 1);
254+
}
255+
231256
String getVisitedIslandLevel(GameModeAddon gm, User user) {
232-
if (!gm.inWorld(user.getLocation())) return "";
257+
if (user == null || !gm.inWorld(user.getLocation())) return "";
233258
return getIslands().getIslandAt(user.getLocation())
234259
.map(island -> getManager().getIslandLevelString(gm.getOverWorld(), island.getOwner()))
235260
.orElse("0");
@@ -256,11 +281,6 @@ private void registerCommands(GameModeAddon gm) {
256281
public void onDisable() {
257282
// Stop the pipeline
258283
this.getPipeliner().stop();
259-
// Save player data and the top tens
260-
if (manager != null) {
261-
manager.save();
262-
}
263-
264284
}
265285

266286
private void loadBlockSettings() {
@@ -431,4 +451,11 @@ public boolean isRegisteredGameModeWorld(World world) {
431451
return registeredGameModes.stream().map(GameModeAddon::getOverWorld).anyMatch(w -> Util.sameWorld(world, w));
432452
}
433453

454+
/**
455+
* @return the roseStackersEnabled
456+
*/
457+
public boolean isRoseStackersEnabled() {
458+
return roseStackersEnabled;
459+
}
460+
434461
}

src/main/java/world/bentobox/level/LevelsManager.java

Lines changed: 3 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,8 @@
1414
import java.util.UUID;
1515
import java.util.concurrent.CompletableFuture;
1616
import java.util.concurrent.ConcurrentHashMap;
17-
import java.util.function.Predicate;
1817
import java.util.stream.Collectors;
1918
import java.util.stream.Stream;
20-
import java.util.stream.StreamSupport;
2119

2220
import org.bukkit.Bukkit;
2321
import org.bukkit.ChatColor;
@@ -64,8 +62,6 @@ public class LevelsManager {
6462
private final Database<IslandLevels> handler;
6563
// A cache of island levels.
6664
private final Map<String, IslandLevels> levelsCache;
67-
68-
private final Database<TopTenData> topTenHandler;
6965
// Top ten lists
7066
private final Map<World,TopTenData> topTenLists;
7167
// Background
@@ -79,8 +75,6 @@ public LevelsManager(Level addon) {
7975
// Set up the database handler to store and retrieve data
8076
// Note that these are saved by the BentoBox database
8177
handler = new Database<>(addon, IslandLevels.class);
82-
// Top Ten handler
83-
topTenHandler = new Database<>(addon, TopTenData.class);
8478
// Initialize the cache
8579
levelsCache = new HashMap<>();
8680
// Initialize top ten lists
@@ -181,8 +175,6 @@ public CompletableFuture<Results> calculateLevel(UUID targetPlayer, Island islan
181175
}
182176
// Save result
183177
setIslandResults(island.getWorld(), island.getOwner(), r);
184-
// Save top ten
185-
addon.getManager().saveTopTen(island.getWorld());
186178
// Save the island scan details
187179
result.complete(r);
188180
});
@@ -444,18 +436,7 @@ public int getRank(@NonNull World world, UUID uuid) {
444436
.filter(e -> addon.getIslands().isOwner(world, e.getKey()))
445437
.filter(l -> l.getValue() > 0)
446438
.sorted(Collections.reverseOrder(Map.Entry.comparingByValue()));
447-
return takeWhile(stream, x -> !x.getKey().equals(uuid)).map(Map.Entry::getKey).collect(Collectors.toList()).size() + 1;
448-
}
449-
450-
/**
451-
* Java 8's version of Java 9's takeWhile
452-
* @param stream
453-
* @param predicate
454-
* @return stream
455-
*/
456-
public static <T> Stream<T> takeWhile(Stream<T> stream, Predicate<T> predicate) {
457-
CustomSpliterator<T> customSpliterator = new CustomSpliterator<>(stream.spliterator(), predicate);
458-
return StreamSupport.stream(customSpliterator, false);
439+
return stream.takeWhile(x -> !x.getKey().equals(uuid)).map(Map.Entry::getKey).collect(Collectors.toList()).size() + 1;
459440
}
460441

461442
/**
@@ -475,15 +456,14 @@ boolean hasTopTenPerm(@NonNull World world, @NonNull UUID targetPlayer) {
475456
void loadTopTens() {
476457
topTenLists.clear();
477458
Bukkit.getScheduler().runTaskAsynchronously(addon.getPlugin(), () -> {
478-
addon.log("Generating Top Ten Tables");
459+
addon.log("Generating rankings");
479460
handler.loadObjects().forEach(il -> {
480461
if (il.getLevel() > 0) {
481462
addon.getIslands().getIslandById(il.getUniqueId()).ifPresent(i -> this.addToTopTen(i, il.getLevel()));
482463
}
483464
});
484465
topTenLists.keySet().forEach(w -> {
485-
addon.log("Loaded top ten for " + w.getName());
486-
this.saveTopTen(w);
466+
addon.log("Generated rankings for " + w.getName());
487467
});
488468

489469
});
@@ -497,27 +477,10 @@ void loadTopTens() {
497477
public void removeEntry(World world, UUID uuid) {
498478
if (topTenLists.containsKey(world)) {
499479
topTenLists.get(world).getTopTen().remove(uuid);
500-
topTenHandler.saveObjectAsync(topTenLists.get(world));
501480
}
502481

503482
}
504483

505-
/**
506-
* Saves all player data and the top ten
507-
*/
508-
public void save() {
509-
levelsCache.values().forEach(handler::saveObjectAsync);
510-
topTenLists.values().forEach(topTenHandler::saveObjectAsync);
511-
}
512-
513-
/**
514-
* Save the top ten for world
515-
* @param world - world
516-
*/
517-
public void saveTopTen(World world) {
518-
topTenHandler.saveObjectAsync(topTenLists.get(world));
519-
}
520-
521484
/**
522485
* Set an initial island level
523486
* @param island - the island to set. Must have a non-null world

0 commit comments

Comments
 (0)