Compare commits
113 Commits
Author | SHA1 | Date |
---|---|---|
tastybento | f2da5ba104 | |
tastybento | c3e03a4f59 | |
tastybento | 7a241f898d | |
tastybento | d37f9ddcdd | |
tastybento | 0bb6eacaf7 | |
tastybento | 5dee0d2426 | |
tastybento | 1369ffb8c8 | |
tastybento | e2cbd18f17 | |
tastybento | 4d16e9c227 | |
tastybento | a4f8d12138 | |
Huynh Tien | 1bd6219f94 | |
add5tar | 2d1f618676 | |
tastybento | 774bbd034c | |
tastybento | 02a19d1bdb | |
tastybento | 952a2a6e81 | |
tastybento | 79f988f460 | |
tastybento | ae030eb548 | |
tastybento | 76e0bad88a | |
tastybento | 2b373f62d9 | |
tastybento | 5f83a81f18 | |
tastybento | 82174649b4 | |
tastybento | cec620162b | |
gitlocalize-app[bot] | cfb35909f0 | |
tastybento | 117d15f3d0 | |
tastybento | 9d1a5c7476 | |
tastybento | 26d4839f6a | |
tastybento | 43c898ecf7 | |
tastybento | 77884f0a11 | |
tastybento | 1a4077be8c | |
tastybento | 3a3c8a320c | |
tastybento | eb71b35c5c | |
tastybento | cdd4366a2a | |
tastybento | 8f567cc328 | |
PapiCapi | 913eed9c77 | |
tastybento | 2b0a6d82ef | |
tastybento | a3537f5b80 | |
tastybento | 1b02f11220 | |
tastybento | 0c42ad866a | |
tastybento | deb09992f1 | |
tastybento | 1b20605791 | |
gitlocalize-app[bot] | 951b0f5549 | |
gitlocalize-app[bot] | 30217ba509 | |
gitlocalize-app[bot] | f8d50a43d6 | |
gitlocalize-app[bot] | dfd30d148b | |
tastybento | 5a66bf162b | |
tastybento | ad3d02c29a | |
tastybento | 34b2b52979 | |
tastybento | 3c79c68e80 | |
BONNe | 78c67b6d2f | |
ceze88 | 9c42a8d007 | |
tastybento | c093796a6e | |
tastybento | 713a409584 | |
tastybento | 0cdb15403b | |
DevSolaris | a493c12f6e | |
tastybento | 42249a8fc9 | |
tastybento | f469e37702 | |
gitlocalize-app[bot] | 29b148052a | |
gitlocalize-app[bot] | f1db2a9284 | |
tastybento | dc9d460e1e | |
evlad | fba73948c6 | |
tastybento | ac6bead52e | |
tastybento | 93869cb34a | |
tastybento | f3ee8a381c | |
tastybento | 3988659dcc | |
tastybento | 51338d280d | |
gitlocalize-app[bot] | 97d9522563 | |
gitlocalize-app[bot] | 32690630d6 | |
BONNe | 2ca4e0a070 | |
BONNe | dae3db6c98 | |
DeadSilenceIV | 90ae98e599 | |
BONNe | 47053fde31 | |
KrazyxWolf | cc90579f51 | |
BONNe | 1914fc11e0 | |
BONNe | 4948689fe8 | |
tastybento | fcf6e76599 | |
tastybento | d9288c7e61 | |
BONNe | eb8c105be5 | |
BONNe | 15ff515078 | |
BONNe | 43fcde5781 | |
BONNe | e16fad882e | |
tastybento | 0a79b7fa58 | |
tastybento | 5d9aa00c13 | |
tastybento | 490fe6c942 | |
tastybento | 336e8d47bf | |
tastybento | a3d06ee41a | |
gitlocalize-app[bot] | 6f174e2b3a | |
gitlocalize-app[bot] | 322ea825ea | |
gitlocalize-app[bot] | 488c6ac9d3 | |
gitlocalize-app[bot] | 840a8c1d79 | |
gitlocalize-app[bot] | 34da24d719 | |
gitlocalize-app[bot] | cbaf14e5f0 | |
tastybento | 7e92a45736 | |
tastybento | 5ce71798a6 | |
Pierre Dedrie | 4a21e4b30c | |
tastybento | 50074ac1df | |
Rubén | cc977d8562 | |
Huynh Tien | 4de5b80ab4 | |
tastybento | 893d8d46a0 | |
tastybento | b1d117d344 | |
tastybento | 11618085ff | |
tastybento | 60f2a268b9 | |
tastybento | 4c59d4d4ae | |
tastybento | 9b8bbdac5f | |
tastybento | d212fcee99 | |
tastybento | 1b29f7f6ac | |
tastybento | b16d458cae | |
tastybento | 7b6f921b10 | |
tastybento | bd6c264f4d | |
tastybento | d55f66f868 | |
tastybento | 76a2688556 | |
tastybento | 4661bcd109 | |
tastybento | 383ede3d59 | |
tastybento | 0ce89dea7f |
27
pom.xml
27
pom.xml
|
@ -59,7 +59,7 @@
|
|||
<powermock.version>2.0.9</powermock.version>
|
||||
<!-- More visible way how to change dependency versions -->
|
||||
<spigot.version>1.20.4-R0.1-SNAPSHOT</spigot.version>
|
||||
<bentobox.version>2.0.0-SNAPSHOT</bentobox.version>
|
||||
<bentobox.version>2.4.0-SNAPSHOT</bentobox.version>
|
||||
<!-- Warps addon version -->
|
||||
<warps.version>1.12.0</warps.version>
|
||||
<!-- Visit addon version -->
|
||||
|
@ -71,7 +71,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.12.0</build.version>
|
||||
<build.version>2.14.0</build.version>
|
||||
<sonar.projectKey>BentoBoxWorld_Level</sonar.projectKey>
|
||||
<sonar.organization>bentobox-world</sonar.organization>
|
||||
<sonar.host.url>https://sonarcloud.io</sonar.host.url>
|
||||
|
@ -129,8 +129,8 @@
|
|||
<repositories>
|
||||
<!--Wild Stacker repo -->
|
||||
<repository>
|
||||
<id>jitpack.io</id>
|
||||
<url>https://jitpack.io</url>
|
||||
<id>bg-repo</id>
|
||||
<url>https://repo.bg-software.com/repository/api/</url>
|
||||
</repository>
|
||||
<!-- RoseStacker repo -->
|
||||
<repository>
|
||||
|
@ -139,8 +139,8 @@
|
|||
</repository>
|
||||
<!-- UltimateStacker repo -->
|
||||
<repository>
|
||||
<id>songoda-public</id>
|
||||
<url>https://repo.songoda.com/repository/public/</url>
|
||||
<id>songoda-plugins</id>
|
||||
<url>https://repo.songoda.com/repository/minecraft-plugins/</url>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>spigot-repo</id>
|
||||
|
@ -154,6 +154,10 @@
|
|||
<id>codemc-public</id>
|
||||
<url>https://repo.codemc.org/repository/maven-public/</url>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>jitpack.io</id>
|
||||
<url>https://jitpack.io</url>
|
||||
</repository>
|
||||
</repositories>
|
||||
|
||||
<dependencies>
|
||||
|
@ -208,9 +212,9 @@
|
|||
</dependency>
|
||||
<!-- Wild Stacker dependency -->
|
||||
<dependency>
|
||||
<groupId>com.github.OmerBenGera</groupId>
|
||||
<groupId>com.bgsoftware</groupId>
|
||||
<artifactId>WildStackerAPI</artifactId>
|
||||
<version>b18</version>
|
||||
<version>2023.3</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<!-- Static analysis -->
|
||||
|
@ -234,10 +238,11 @@
|
|||
<version>1.3.0</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<!-- Ultimate Stacker dependency -->
|
||||
<dependency>
|
||||
<groupId>com.songoda</groupId>
|
||||
<artifactId>UltimateStacker</artifactId>
|
||||
<version>2.4.0</version>
|
||||
<groupId>com.craftaro</groupId>
|
||||
<artifactId>UltimateStacker-API</artifactId>
|
||||
<version>1.0.0-20240329.173606-35</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
|
|
@ -2,6 +2,7 @@ package world.bentobox.level;
|
|||
|
||||
import java.math.BigInteger;
|
||||
import java.text.DecimalFormat;
|
||||
import java.time.Instant;
|
||||
import java.util.AbstractMap;
|
||||
import java.util.Collections;
|
||||
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.LevelsData;
|
||||
import world.bentobox.level.objects.TopTenData;
|
||||
import world.bentobox.level.util.CachedData;
|
||||
|
||||
public class LevelsManager {
|
||||
private static final String INTOPTEN = "intopten";
|
||||
|
@ -52,6 +54,8 @@ public class LevelsManager {
|
|||
private final Map<String, IslandLevels> levelsCache;
|
||||
// Top ten lists
|
||||
private final Map<World, TopTenData> topTenLists;
|
||||
// Cache for top tens
|
||||
private Map<World, CachedData> cache = new HashMap<>();
|
||||
|
||||
public LevelsManager(Level addon) {
|
||||
this.addon = addon;
|
||||
|
@ -325,7 +329,6 @@ public class LevelsManager {
|
|||
|
||||
// Return the unmodifiable map
|
||||
return Collections.unmodifiableMap(weightedTopTen);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -339,7 +342,19 @@ public class LevelsManager {
|
|||
@NonNull
|
||||
public Map<String, Long> getTopTen(@NonNull World world, int size) {
|
||||
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()
|
||||
.filter(l -> l.getValue() > 0).sorted(Collections.reverseOrder(Map.Entry.comparingByValue()))
|
||||
.limit(size)
|
||||
|
@ -399,7 +414,8 @@ public class LevelsManager {
|
|||
addon.log("Generating rankings");
|
||||
handler.loadObjects().forEach(il -> {
|
||||
if (il.getLevel() > 0) {
|
||||
addon.getIslands().getIslandById(il.getUniqueId())
|
||||
// Load islands, but don't cache them
|
||||
addon.getIslands().getIslandById(il.getUniqueId(), false)
|
||||
.ifPresent(i -> this.addToTopTen(i, il.getLevel()));
|
||||
}
|
||||
});
|
||||
|
@ -416,8 +432,9 @@ public class LevelsManager {
|
|||
public void removeEntry(World world, String uuid) {
|
||||
if (topTenLists.containsKey(world)) {
|
||||
topTenLists.get(world).getTopTen().remove(uuid);
|
||||
// Invalidate the cache because of this deletion
|
||||
cache.remove(world);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -40,9 +40,6 @@ import com.bgsoftware.wildstacker.api.objects.StackedBarrel;
|
|||
import com.google.common.collect.Multiset;
|
||||
import com.google.common.collect.Multiset.Entry;
|
||||
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 us.lynuxcraft.deadsilenceiv.advancedchests.AdvancedChestsAPI;
|
||||
|
@ -449,47 +446,33 @@ public class IslandLevelCalculator {
|
|||
// Only count to the highest block in the world for some optimization
|
||||
for (int y = cp.world.getMinHeight(); y < cp.world.getMaxHeight(); y++) {
|
||||
BlockData blockData = cp.chunkSnapshot.getBlockData(x, y, z);
|
||||
Material m = blockData.getMaterial();
|
||||
boolean belowSeaLevel = seaHeight > 0 && y <= seaHeight;
|
||||
// Slabs can be doubled, so check them twice
|
||||
if (Tag.SLABS.isTagged(blockData.getMaterial())) {
|
||||
if (Tag.SLABS.isTagged(m)) {
|
||||
Slab slab = (Slab) blockData;
|
||||
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
|
||||
// chunk
|
||||
if (addon.isStackersEnabled() && (blockData.getMaterial().equals(Material.CAULDRON)
|
||||
|| blockData.getMaterial().equals(Material.SPAWNER))) {
|
||||
if (addon.isStackersEnabled() && (m.equals(Material.CAULDRON) || m.equals(Material.SPAWNER))) {
|
||||
stackedBlocks.add(new Location(cp.world, (double) x + cp.chunkSnapshot.getX() * 16, y,
|
||||
(double) z + cp.chunkSnapshot.getZ() * 16));
|
||||
}
|
||||
|
||||
Block block = cp.chunk.getBlock(x, y, z);
|
||||
|
||||
if (addon.isUltimateStackerEnabled()) {
|
||||
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());
|
||||
}
|
||||
}
|
||||
}
|
||||
if (addon.isUltimateStackerEnabled() && !m.isAir()) {
|
||||
Location l = new Location(cp.chunk.getWorld(), x, y, z);
|
||||
UltimateStackerCalc.addStackers(m, l, results, belowSeaLevel, limitCount(m));
|
||||
}
|
||||
|
||||
// Scan chests
|
||||
if (addon.getSettings().isIncludeChests() && CHESTS.contains(blockData.getMaterial())) {
|
||||
if (addon.getSettings().isIncludeChests() && CHESTS.contains(m)) {
|
||||
chestBlocks.add(cp.chunk);
|
||||
}
|
||||
// Add the value of the block's material
|
||||
checkBlock(blockData.getMaterial(), belowSeaLevel);
|
||||
checkBlock(m, belowSeaLevel);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -625,41 +608,32 @@ public class IslandLevelCalculator {
|
|||
// Done
|
||||
pipeliner.getInProcessQueue().remove(this);
|
||||
// Chunk finished
|
||||
// This was the last chunk
|
||||
handleStackedBlocks();
|
||||
handleChests();
|
||||
long checkTime = System.currentTimeMillis();
|
||||
finishTask = Bukkit.getScheduler().runTaskTimer(addon.getPlugin(), () -> {
|
||||
// Check every half second if all the chests and stacks have been cleared
|
||||
if ((chestBlocks.isEmpty() && stackedBlocks.isEmpty())
|
||||
|| System.currentTimeMillis() - checkTime > MAX_AMOUNT) {
|
||||
// This was the last chunk. Handle stacked blocks, then chests and exit
|
||||
handleStackedBlocks().thenCompose(v -> handleChests()).thenRun(() -> {
|
||||
this.tidyUp();
|
||||
this.getR().complete(getResults());
|
||||
finishTask.cancel();
|
||||
}
|
||||
}, 0, 10L);
|
||||
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void handleChests() {
|
||||
Iterator<Chunk> it = chestBlocks.iterator();
|
||||
while (it.hasNext()) {
|
||||
Chunk v = it.next();
|
||||
Util.getChunkAtAsync(v.getWorld(), v.getX(), v.getZ()).thenAccept(c -> {
|
||||
private CompletableFuture<Void> handleChests() {
|
||||
List<CompletableFuture<Void>> futures = new ArrayList<>();
|
||||
for (Chunk v : chestBlocks) {
|
||||
CompletableFuture<Void> future = Util.getChunkAtAsync(v.getWorld(), v.getX(), v.getZ()).thenAccept(c -> {
|
||||
scanChests(c);
|
||||
it.remove();
|
||||
});
|
||||
futures.add(future);
|
||||
}
|
||||
// Return a CompletableFuture that completes when all futures are done
|
||||
return CompletableFuture.allOf(futures.toArray(new CompletableFuture[0]));
|
||||
}
|
||||
|
||||
private void handleStackedBlocks() {
|
||||
private CompletableFuture<Void> handleStackedBlocks() {
|
||||
// Deal with any stacked blocks
|
||||
Iterator<Location> it = stackedBlocks.iterator();
|
||||
while (it.hasNext()) {
|
||||
Location v = it.next();
|
||||
Util.getChunkAtAsync(v).thenAccept(c -> {
|
||||
List<CompletableFuture<Void>> futures = new ArrayList<>();
|
||||
for (Location v : stackedBlocks) {
|
||||
CompletableFuture<Void> future = Util.getChunkAtAsync(v).thenAccept(c -> {
|
||||
Block stackedBlock = v.getBlock();
|
||||
boolean belowSeaLevel = seaHeight > 0 && v.getBlockY() <= seaHeight;
|
||||
if (WildStackerAPI.getWildStacker().getSystemManager().isStackedBarrel(stackedBlock)) {
|
||||
|
@ -674,8 +648,12 @@ public class IslandLevelCalculator {
|
|||
checkBlock(stackedBlock.getType(), belowSeaLevel);
|
||||
}
|
||||
}
|
||||
it.remove();
|
||||
});
|
||||
futures.add(future);
|
||||
}
|
||||
// Return a CompletableFuture that completes when all futures are done
|
||||
return CompletableFuture.allOf(futures.toArray(new CompletableFuture[0]));
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -111,7 +111,11 @@ public class IslandLevelCommand extends CompositeCommand {
|
|||
}
|
||||
// Send player how many points are required to reach next island level
|
||||
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
|
||||
if (results.getLevel() != oldLevel) {
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
|
@ -2,7 +2,7 @@ name: Level
|
|||
main: world.bentobox.level.Level
|
||||
version: ${version}${build.number}
|
||||
icon: DIAMOND
|
||||
api-version: 1.16.5
|
||||
api-version: 2.4.0
|
||||
|
||||
authors: tastybento
|
||||
|
||||
|
|
|
@ -42,8 +42,8 @@ island:
|
|||
estimated-wait: "&a Estimated wait: [number] seconds"
|
||||
in-queue: "&a You are number [number] in the queue"
|
||||
island-level-is: "&a Island level is &b[level]"
|
||||
required-points-to-next-level: "&a [points] points required until the next level"
|
||||
deaths: "&c([number] deaths)"
|
||||
required-points-to-next-level: "&a Level progress: &6 [progress]&b /&e [levelcost] &a points"
|
||||
deaths: "&c ([number] deaths)"
|
||||
cooldown: "&c You must wait &b[time] &c seconds until you can do that again"
|
||||
in-progress: "&6 Island level calculation is in progress..."
|
||||
time-out: "&c The level calculation took too long. Please try again later."
|
||||
|
|
|
@ -121,7 +121,7 @@ detail_panel:
|
|||
# TIPPED_ARROW:INSTANT_DAMAGE:2::LINGER:2
|
||||
# TIPPED_ARROW:JUMP:2:NOTEXTENDED:NOSPLASH:1
|
||||
# TIPPED_ARROW:WEAKNESS::::1 - any weakness enchantment
|
||||
icon: TIPPED_ARROW:INSTANT_HEAL::::1
|
||||
icon: tipped_arrow{CustomPotionColor:11546150}
|
||||
title: level.gui.buttons.previous.name
|
||||
description: level.gui.buttons.previous.description
|
||||
data:
|
||||
|
@ -139,7 +139,7 @@ detail_panel:
|
|||
7: material_button
|
||||
8: material_button
|
||||
9:
|
||||
icon: TIPPED_ARROW:JUMP::::1
|
||||
icon: tipped_arrow{CustomPotionColor:8439583}
|
||||
title: level.gui.buttons.next.name
|
||||
description: level.gui.buttons.next.description
|
||||
data:
|
||||
|
|
|
@ -64,7 +64,7 @@ value_panel:
|
|||
8: material_button
|
||||
3:
|
||||
1:
|
||||
icon: TIPPED_ARROW:INSTANT_HEAL::::1
|
||||
icon: tipped_arrow{CustomPotionColor:11546150}
|
||||
title: level.gui.buttons.previous.name
|
||||
description: level.gui.buttons.previous.description
|
||||
data:
|
||||
|
@ -82,7 +82,7 @@ value_panel:
|
|||
7: material_button
|
||||
8: material_button
|
||||
9:
|
||||
icon: TIPPED_ARROW:JUMP::::1
|
||||
icon: tipped_arrow{CustomPotionColor:8439583}
|
||||
title: level.gui.buttons.next.name
|
||||
description: level.gui.buttons.next.description
|
||||
data:
|
||||
|
|
|
@ -2,7 +2,9 @@ package world.bentobox.level;
|
|||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.anyString;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.Mockito.doNothing;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.times;
|
||||
import static org.mockito.Mockito.verify;
|
||||
|
@ -19,6 +21,7 @@ import java.util.Collections;
|
|||
import java.util.Comparator;
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.jar.JarEntry;
|
||||
import java.util.jar.JarOutputStream;
|
||||
import java.util.logging.Logger;
|
||||
|
@ -30,7 +33,9 @@ import org.bukkit.World;
|
|||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemFactory;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.bukkit.plugin.PluginManager;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.bukkit.scheduler.BukkitScheduler;
|
||||
import org.eclipse.jdt.annotation.NonNull;
|
||||
import org.junit.After;
|
||||
|
@ -47,6 +52,8 @@ import org.powermock.core.classloader.annotations.PrepareForTest;
|
|||
import org.powermock.modules.junit4.PowerMockRunner;
|
||||
import org.powermock.reflect.Whitebox;
|
||||
|
||||
import com.github.puregero.multilib.MultiLib;
|
||||
|
||||
import world.bentobox.bentobox.BentoBox;
|
||||
import world.bentobox.bentobox.Settings;
|
||||
import world.bentobox.bentobox.api.addons.AddonDescription;
|
||||
|
@ -72,7 +79,7 @@ import world.bentobox.level.listeners.JoinLeaveListener;
|
|||
*/
|
||||
@SuppressWarnings("deprecation")
|
||||
@RunWith(PowerMockRunner.class)
|
||||
@PrepareForTest({ Bukkit.class, BentoBox.class, User.class })
|
||||
@PrepareForTest({ Bukkit.class, BentoBox.class, User.class, MultiLib.class })
|
||||
public class LevelTest {
|
||||
|
||||
private static File jFile;
|
||||
|
@ -144,8 +151,15 @@ public class LevelTest {
|
|||
/**
|
||||
* @throws java.lang.Exception
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
// Mock MultiLib
|
||||
PowerMockito.mockStatic(MultiLib.class);
|
||||
// Mock the behavior of the onString method
|
||||
PowerMockito.doNothing().when(MultiLib.class);
|
||||
MultiLib.onString(any(Plugin.class), anyString(), (Consumer<String>) any(Consumer.class));
|
||||
|
||||
// Set up plugin
|
||||
Whitebox.setInternalState(BentoBox.class, "instance", plugin);
|
||||
when(plugin.getLogger()).thenReturn(Logger.getAnonymousLogger());
|
||||
|
|
|
@ -4,6 +4,7 @@ import static org.junit.Assert.assertEquals;
|
|||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.anyBoolean;
|
||||
import static org.mockito.ArgumentMatchers.anyInt;
|
||||
import static org.mockito.ArgumentMatchers.anyString;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
|
@ -165,6 +166,7 @@ public class LevelsManagerTest {
|
|||
when(im.hasIsland(eq(world), any(UUID.class))).thenReturn(true);
|
||||
when(im.getIsland(world, uuid)).thenReturn(island);
|
||||
when(im.getIslandById(anyString())).thenReturn(Optional.of(island));
|
||||
when(im.getIslandById(anyString(), eq(false))).thenReturn(Optional.of(island));
|
||||
|
||||
// Player
|
||||
when(player.getUniqueId()).thenReturn(uuid);
|
||||
|
@ -395,8 +397,8 @@ public class LevelsManagerTest {
|
|||
lm.loadTopTens();
|
||||
PowerMockito.verifyStatic(Bukkit.class); // 1
|
||||
Bukkit.getScheduler();
|
||||
verify(scheduler).runTaskAsynchronously(eq(plugin), task.capture());
|
||||
task.getValue().run();
|
||||
verify(scheduler).runTaskAsynchronously(eq(plugin), task.capture()); // Capture the task in the scheduler
|
||||
task.getValue().run(); // run it
|
||||
verify(addon).log("Generating rankings");
|
||||
verify(addon).log("Generated rankings for bskyblock-world");
|
||||
|
||||
|
|
|
@ -9,9 +9,9 @@ import static org.mockito.Mockito.mock;
|
|||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
|
@ -138,7 +138,7 @@ public class PlaceholderManagerTest {
|
|||
when(im.getIsland(any(World.class), any(User.class))).thenReturn(island);
|
||||
when(im.getIslandAt(any(Location.class))).thenReturn(Optional.of(island));
|
||||
when(im.getIslandById(anyString())).thenAnswer((Answer<Optional<Island>>) invocation -> Optional.of(islands.get(invocation.getArgument(0, String.class))));
|
||||
when(im.getIslands(any(), any(UUID.class))).thenReturn(new HashSet<>(islands.values()));
|
||||
when(im.getIslands(any(), any(UUID.class))).thenReturn(new ArrayList<>(islands.values()));
|
||||
when(addon.getIslands()).thenReturn(im);
|
||||
|
||||
// Levels Manager
|
||||
|
|
|
@ -10,7 +10,7 @@ import static org.mockito.Mockito.verify;
|
|||
import static org.mockito.Mockito.when;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.Set;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
|
@ -120,8 +120,8 @@ public class AdminTopRemoveCommandTest {
|
|||
when(island.getOwner()).thenReturn(uuid);
|
||||
// Island Manager
|
||||
when(plugin.getIslands()).thenReturn(im);
|
||||
when(im.getIslands(any(), any(User.class))).thenReturn(Set.of(island));
|
||||
when(im.getIslands(any(), any(UUID.class))).thenReturn(Set.of(island));
|
||||
when(im.getIslands(any(), any(User.class))).thenReturn(List.of(island));
|
||||
when(im.getIslands(any(), any(UUID.class))).thenReturn(List.of(island));
|
||||
|
||||
// Bukkit
|
||||
PowerMockito.mockStatic(Bukkit.class);
|
||||
|
|
Loading…
Reference in New Issue