Release 2.13.0 (#310)

* Update tipped arrows in GUI Panel

* Version 2.13.0

* Add more string replacements for /is level output (#303)

* Update hooks and fix UltimateStacker API (#305)

* Isolate UltimateStacker imports so no errors if US is not installed (#307) Fixes #306

* Implement a cache for top tens (#309)
This commit is contained in:
tastybento 2024-05-05 13:40:14 -07:00 committed by GitHub
parent 3061e80097
commit 3983764353
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
9 changed files with 577 additions and 510 deletions

25
pom.xml
View File

@ -71,7 +71,7 @@
<!-- Do not change unless you want different name for local builds. --> <!-- Do not change unless you want different name for local builds. -->
<build.number>-LOCAL</build.number> <build.number>-LOCAL</build.number>
<!-- This allows to change between versions. --> <!-- This allows to change between versions. -->
<build.version>2.12.0</build.version> <build.version>2.13.0</build.version>
<sonar.projectKey>BentoBoxWorld_Level</sonar.projectKey> <sonar.projectKey>BentoBoxWorld_Level</sonar.projectKey>
<sonar.organization>bentobox-world</sonar.organization> <sonar.organization>bentobox-world</sonar.organization>
<sonar.host.url>https://sonarcloud.io</sonar.host.url> <sonar.host.url>https://sonarcloud.io</sonar.host.url>
@ -129,8 +129,8 @@
<repositories> <repositories>
<!--Wild Stacker repo --> <!--Wild Stacker repo -->
<repository> <repository>
<id>jitpack.io</id> <id>bg-repo</id>
<url>https://jitpack.io</url> <url>https://repo.bg-software.com/repository/api/</url>
</repository> </repository>
<!-- RoseStacker repo --> <!-- RoseStacker repo -->
<repository> <repository>
@ -139,8 +139,8 @@
</repository> </repository>
<!-- UltimateStacker repo --> <!-- UltimateStacker repo -->
<repository> <repository>
<id>songoda-public</id> <id>songoda-plugins</id>
<url>https://repo.songoda.com/repository/public/</url> <url>https://repo.songoda.com/repository/minecraft-plugins/</url>
</repository> </repository>
<repository> <repository>
<id>spigot-repo</id> <id>spigot-repo</id>
@ -154,6 +154,10 @@
<id>codemc-public</id> <id>codemc-public</id>
<url>https://repo.codemc.org/repository/maven-public/</url> <url>https://repo.codemc.org/repository/maven-public/</url>
</repository> </repository>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
</repositories> </repositories>
<dependencies> <dependencies>
@ -208,9 +212,9 @@
</dependency> </dependency>
<!-- Wild Stacker dependency --> <!-- Wild Stacker dependency -->
<dependency> <dependency>
<groupId>com.github.OmerBenGera</groupId> <groupId>com.bgsoftware</groupId>
<artifactId>WildStackerAPI</artifactId> <artifactId>WildStackerAPI</artifactId>
<version>b18</version> <version>2023.3</version>
<scope>provided</scope> <scope>provided</scope>
</dependency> </dependency>
<!-- Static analysis --> <!-- Static analysis -->
@ -234,10 +238,11 @@
<version>1.3.0</version> <version>1.3.0</version>
<scope>provided</scope> <scope>provided</scope>
</dependency> </dependency>
<!-- Ultimate Stacker dependency -->
<dependency> <dependency>
<groupId>com.songoda</groupId> <groupId>com.craftaro</groupId>
<artifactId>UltimateStacker</artifactId> <artifactId>UltimateStacker-API</artifactId>
<version>2.4.0</version> <version>1.0.0-20240329.173606-35</version>
<scope>provided</scope> <scope>provided</scope>
</dependency> </dependency>
</dependencies> </dependencies>

View File

@ -2,6 +2,7 @@ package world.bentobox.level;
import java.math.BigInteger; import java.math.BigInteger;
import java.text.DecimalFormat; import java.text.DecimalFormat;
import java.time.Instant;
import java.util.AbstractMap; import java.util.AbstractMap;
import java.util.Collections; import java.util.Collections;
import java.util.HashMap; import java.util.HashMap;
@ -31,6 +32,7 @@ import world.bentobox.level.events.IslandPreLevelEvent;
import world.bentobox.level.objects.IslandLevels; import world.bentobox.level.objects.IslandLevels;
import world.bentobox.level.objects.LevelsData; import world.bentobox.level.objects.LevelsData;
import world.bentobox.level.objects.TopTenData; import world.bentobox.level.objects.TopTenData;
import world.bentobox.level.util.CachedData;
public class LevelsManager { public class LevelsManager {
private static final String INTOPTEN = "intopten"; private static final String INTOPTEN = "intopten";
@ -52,6 +54,8 @@ public class LevelsManager {
private final Map<String, IslandLevels> levelsCache; private final Map<String, IslandLevels> levelsCache;
// Top ten lists // Top ten lists
private final Map<World, TopTenData> topTenLists; private final Map<World, TopTenData> topTenLists;
// Cache for top tens
private Map<World, CachedData> cache = new HashMap<>();
public LevelsManager(Level addon) { public LevelsManager(Level addon) {
this.addon = addon; this.addon = addon;
@ -325,7 +329,6 @@ public class LevelsManager {
// Return the unmodifiable map // Return the unmodifiable map
return Collections.unmodifiableMap(weightedTopTen); return Collections.unmodifiableMap(weightedTopTen);
} }
/** /**
@ -339,7 +342,19 @@ public class LevelsManager {
@NonNull @NonNull
public Map<String, Long> getTopTen(@NonNull World world, int size) { public Map<String, Long> getTopTen(@NonNull World world, int size) {
createAndCleanRankings(world); createAndCleanRankings(world);
// Return the sorted map CachedData cachedData = cache.get(world);
Instant now = Instant.now();
if (cachedData != null && cachedData.getLastUpdated().plusSeconds(1).isAfter(now)) {
return cachedData.getCachedMap();
} else {
Map<String, Long> newTopTen = calculateTopTen(world, size);
cache.put(world, new CachedData(newTopTen, now));
return newTopTen;
}
}
private Map<String, Long> calculateTopTen(@NonNull World world, int size) {
return Collections.unmodifiableMap(topTenLists.get(world).getTopTen().entrySet().stream() return Collections.unmodifiableMap(topTenLists.get(world).getTopTen().entrySet().stream()
.filter(l -> l.getValue() > 0).sorted(Collections.reverseOrder(Map.Entry.comparingByValue())) .filter(l -> l.getValue() > 0).sorted(Collections.reverseOrder(Map.Entry.comparingByValue()))
.limit(size) .limit(size)
@ -416,8 +431,9 @@ public class LevelsManager {
public void removeEntry(World world, String uuid) { public void removeEntry(World world, String uuid) {
if (topTenLists.containsKey(world)) { if (topTenLists.containsKey(world)) {
topTenLists.get(world).getTopTen().remove(uuid); topTenLists.get(world).getTopTen().remove(uuid);
// Invalidate the cache because of this deletion
cache.remove(world);
} }
} }
/** /**

View File

@ -40,9 +40,6 @@ import com.bgsoftware.wildstacker.api.objects.StackedBarrel;
import com.google.common.collect.Multiset; import com.google.common.collect.Multiset;
import com.google.common.collect.Multiset.Entry; import com.google.common.collect.Multiset.Entry;
import com.google.common.collect.Multisets; import com.google.common.collect.Multisets;
import com.songoda.ultimatestacker.UltimateStacker;
import com.songoda.ultimatestacker.core.compatibility.CompatibleMaterial;
import com.songoda.ultimatestacker.stackable.block.BlockStack;
import dev.rosewood.rosestacker.api.RoseStackerAPI; import dev.rosewood.rosestacker.api.RoseStackerAPI;
import us.lynuxcraft.deadsilenceiv.advancedchests.AdvancedChestsAPI; import us.lynuxcraft.deadsilenceiv.advancedchests.AdvancedChestsAPI;
@ -449,47 +446,33 @@ public class IslandLevelCalculator {
// Only count to the highest block in the world for some optimization // Only count to the highest block in the world for some optimization
for (int y = cp.world.getMinHeight(); y < cp.world.getMaxHeight(); y++) { for (int y = cp.world.getMinHeight(); y < cp.world.getMaxHeight(); y++) {
BlockData blockData = cp.chunkSnapshot.getBlockData(x, y, z); BlockData blockData = cp.chunkSnapshot.getBlockData(x, y, z);
Material m = blockData.getMaterial();
boolean belowSeaLevel = seaHeight > 0 && y <= seaHeight; boolean belowSeaLevel = seaHeight > 0 && y <= seaHeight;
// Slabs can be doubled, so check them twice // Slabs can be doubled, so check them twice
if (Tag.SLABS.isTagged(blockData.getMaterial())) { if (Tag.SLABS.isTagged(m)) {
Slab slab = (Slab) blockData; Slab slab = (Slab) blockData;
if (slab.getType().equals(Slab.Type.DOUBLE)) { if (slab.getType().equals(Slab.Type.DOUBLE)) {
checkBlock(blockData.getMaterial(), belowSeaLevel); checkBlock(m, belowSeaLevel);
} }
} }
// Hook for Wild Stackers (Blocks and Spawners Only) - this has to use the real // Hook for Wild Stackers (Blocks and Spawners Only) - this has to use the real
// chunk // chunk
if (addon.isStackersEnabled() && (blockData.getMaterial().equals(Material.CAULDRON) if (addon.isStackersEnabled() && (m.equals(Material.CAULDRON) || m.equals(Material.SPAWNER))) {
|| blockData.getMaterial().equals(Material.SPAWNER))) {
stackedBlocks.add(new Location(cp.world, (double) x + cp.chunkSnapshot.getX() * 16, y, stackedBlocks.add(new Location(cp.world, (double) x + cp.chunkSnapshot.getX() * 16, y,
(double) z + cp.chunkSnapshot.getZ() * 16)); (double) z + cp.chunkSnapshot.getZ() * 16));
} }
Block block = cp.chunk.getBlock(x, y, z); if (addon.isUltimateStackerEnabled() && !m.isAir()) {
Location l = new Location(cp.chunk.getWorld(), x, y, z);
if (addon.isUltimateStackerEnabled()) { UltimateStackerCalc.addStackers(m, l, results, belowSeaLevel, limitCount(m));
if (!blockData.getMaterial().equals(Material.AIR)) {
BlockStack stack = UltimateStacker.getInstance().getBlockStackManager().getBlock(block,
CompatibleMaterial.getMaterial(block));
if (stack != null) {
int value = limitCount(blockData.getMaterial());
if (belowSeaLevel) {
results.underWaterBlockCount.addAndGet((long) stack.getAmount() * value);
results.uwCount.add(blockData.getMaterial());
} else {
results.rawBlockCount.addAndGet((long) stack.getAmount() * value);
results.mdCount.add(blockData.getMaterial());
}
}
}
} }
// Scan chests // Scan chests
if (addon.getSettings().isIncludeChests() && CHESTS.contains(blockData.getMaterial())) { if (addon.getSettings().isIncludeChests() && CHESTS.contains(m)) {
chestBlocks.add(cp.chunk); chestBlocks.add(cp.chunk);
} }
// Add the value of the block's material // Add the value of the block's material
checkBlock(blockData.getMaterial(), belowSeaLevel); checkBlock(m, belowSeaLevel);
} }
} }
} }

View File

@ -0,0 +1,29 @@
package world.bentobox.level.calculators;
import org.bukkit.Location;
import org.bukkit.Material;
import com.craftaro.ultimatestacker.api.UltimateStackerApi;
import com.craftaro.ultimatestacker.api.utils.Stackable;
import world.bentobox.bentobox.BentoBox;
/**
* Isolates UltimateStacker imports so that they are only loaded if the plugin exists
*/
public class UltimateStackerCalc {
public static void addStackers(Material material, Location location, Results results, boolean belowSeaLevel,
int value) {
Stackable stack = UltimateStackerApi.getBlockStackManager().getBlock(location);
if (stack != null) {
if (belowSeaLevel) {
results.underWaterBlockCount.addAndGet((long) stack.getAmount() * value);
results.uwCount.add(material);
} else {
results.rawBlockCount.addAndGet((long) stack.getAmount() * value);
results.mdCount.add(material);
}
}
}
}

View File

@ -111,7 +111,11 @@ public class IslandLevelCommand extends CompositeCommand {
} }
// Send player how many points are required to reach next island level // Send player how many points are required to reach next island level
if (results.getPointsToNextLevel() >= 0) { if (results.getPointsToNextLevel() >= 0) {
user.sendMessage("island.level.required-points-to-next-level", "[points]", String.valueOf(results.getPointsToNextLevel())); user.sendMessage("island.level.required-points-to-next-level",
"[points]", String.valueOf(results.getPointsToNextLevel()),
"[progress]", String.valueOf(this.addon.getSettings().getLevelCost()-results.getPointsToNextLevel()),
"[levelcost]", String.valueOf(this.addon.getSettings().getLevelCost())
);
} }
// Tell other team members // Tell other team members
if (results.getLevel() != oldLevel) { if (results.getLevel() != oldLevel) {

View File

@ -0,0 +1,30 @@
package world.bentobox.level.util;
import java.time.Instant;
import java.util.Map;
/**
* Cache for top tens
*/
public class CachedData {
private Map<String, Long> cachedMap;
private Instant lastUpdated;
public CachedData(Map<String, Long> cachedMap, Instant lastUpdated) {
this.cachedMap = cachedMap;
this.lastUpdated = lastUpdated;
}
public Map<String, Long> getCachedMap() {
return cachedMap;
}
public Instant getLastUpdated() {
return lastUpdated;
}
public void updateCache(Map<String, Long> newMap, Instant newUpdateTime) {
this.cachedMap = newMap;
this.lastUpdated = newUpdateTime;
}
}

View File

@ -42,7 +42,7 @@ island:
estimated-wait: "&a Estimated wait: [number] seconds" estimated-wait: "&a Estimated wait: [number] seconds"
in-queue: "&a You are number [number] in the queue" in-queue: "&a You are number [number] in the queue"
island-level-is: "&a Island level is &b[level]" island-level-is: "&a Island level is &b[level]"
required-points-to-next-level: "&a [points] points required until the next level" required-points-to-next-level: "&a Level progress: &6 [progress]&b /&e [levelcost] &a points"
deaths: "&c ([number] deaths)" deaths: "&c ([number] deaths)"
cooldown: "&c You must wait &b[time] &c seconds until you can do that again" cooldown: "&c You must wait &b[time] &c seconds until you can do that again"
in-progress: "&6 Island level calculation is in progress..." in-progress: "&6 Island level calculation is in progress..."

View File

@ -121,7 +121,7 @@ detail_panel:
# TIPPED_ARROW:INSTANT_DAMAGE:2::LINGER:2 # TIPPED_ARROW:INSTANT_DAMAGE:2::LINGER:2
# TIPPED_ARROW:JUMP:2:NOTEXTENDED:NOSPLASH:1 # TIPPED_ARROW:JUMP:2:NOTEXTENDED:NOSPLASH:1
# TIPPED_ARROW:WEAKNESS::::1 - any weakness enchantment # TIPPED_ARROW:WEAKNESS::::1 - any weakness enchantment
icon: TIPPED_ARROW:INSTANT_HEAL::::1 icon: tipped_arrow{CustomPotionColor:11546150}
title: level.gui.buttons.previous.name title: level.gui.buttons.previous.name
description: level.gui.buttons.previous.description description: level.gui.buttons.previous.description
data: data:
@ -139,7 +139,7 @@ detail_panel:
7: material_button 7: material_button
8: material_button 8: material_button
9: 9:
icon: TIPPED_ARROW:JUMP::::1 icon: tipped_arrow{CustomPotionColor:8439583}
title: level.gui.buttons.next.name title: level.gui.buttons.next.name
description: level.gui.buttons.next.description description: level.gui.buttons.next.description
data: data:

View File

@ -64,7 +64,7 @@ value_panel:
8: material_button 8: material_button
3: 3:
1: 1:
icon: TIPPED_ARROW:INSTANT_HEAL::::1 icon: tipped_arrow{CustomPotionColor:11546150}
title: level.gui.buttons.previous.name title: level.gui.buttons.previous.name
description: level.gui.buttons.previous.description description: level.gui.buttons.previous.description
data: data:
@ -82,7 +82,7 @@ value_panel:
7: material_button 7: material_button
8: material_button 8: material_button
9: 9:
icon: TIPPED_ARROW:JUMP::::1 icon: tipped_arrow{CustomPotionColor:8439583}
title: level.gui.buttons.next.name title: level.gui.buttons.next.name
description: level.gui.buttons.next.description description: level.gui.buttons.next.description
data: data: