mirror of
https://github.com/BentoBoxWorld/Level.git
synced 2024-09-28 21:57:28 +02:00
Compare commits
No commits in common. "develop" and "2.12.0" have entirely different histories.
29
pom.xml
29
pom.xml
@ -59,7 +59,7 @@
|
|||||||
<powermock.version>2.0.9</powermock.version>
|
<powermock.version>2.0.9</powermock.version>
|
||||||
<!-- More visible way how to change dependency versions -->
|
<!-- More visible way how to change dependency versions -->
|
||||||
<spigot.version>1.20.4-R0.1-SNAPSHOT</spigot.version>
|
<spigot.version>1.20.4-R0.1-SNAPSHOT</spigot.version>
|
||||||
<bentobox.version>2.5.1-SNAPSHOT</bentobox.version>
|
<bentobox.version>2.0.0-SNAPSHOT</bentobox.version>
|
||||||
<!-- Warps addon version -->
|
<!-- Warps addon version -->
|
||||||
<warps.version>1.12.0</warps.version>
|
<warps.version>1.12.0</warps.version>
|
||||||
<!-- Visit addon version -->
|
<!-- Visit addon version -->
|
||||||
@ -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.16.2</build.version>
|
<build.version>2.12.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>bg-repo</id>
|
<id>jitpack.io</id>
|
||||||
<url>https://repo.bg-software.com/repository/api/</url>
|
<url>https://jitpack.io</url>
|
||||||
</repository>
|
</repository>
|
||||||
<!-- RoseStacker repo -->
|
<!-- RoseStacker repo -->
|
||||||
<repository>
|
<repository>
|
||||||
@ -139,8 +139,8 @@
|
|||||||
</repository>
|
</repository>
|
||||||
<!-- UltimateStacker repo -->
|
<!-- UltimateStacker repo -->
|
||||||
<repository>
|
<repository>
|
||||||
<id>songoda-plugins</id>
|
<id>songoda-public</id>
|
||||||
<url>https://repo.songoda.com/repository/minecraft-plugins/</url>
|
<url>https://repo.songoda.com/repository/public/</url>
|
||||||
</repository>
|
</repository>
|
||||||
<repository>
|
<repository>
|
||||||
<id>spigot-repo</id>
|
<id>spigot-repo</id>
|
||||||
@ -154,10 +154,6 @@
|
|||||||
<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>
|
||||||
@ -212,9 +208,9 @@
|
|||||||
</dependency>
|
</dependency>
|
||||||
<!-- Wild Stacker dependency -->
|
<!-- Wild Stacker dependency -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.bgsoftware</groupId>
|
<groupId>com.github.OmerBenGera</groupId>
|
||||||
<artifactId>WildStackerAPI</artifactId>
|
<artifactId>WildStackerAPI</artifactId>
|
||||||
<version>2023.3</version>
|
<version>b18</version>
|
||||||
<scope>provided</scope>
|
<scope>provided</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<!-- Static analysis -->
|
<!-- Static analysis -->
|
||||||
@ -235,14 +231,13 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>dev.rosewood</groupId>
|
<groupId>dev.rosewood</groupId>
|
||||||
<artifactId>rosestacker</artifactId>
|
<artifactId>rosestacker</artifactId>
|
||||||
<version>1.5.27</version>
|
<version>1.3.0</version>
|
||||||
<scope>provided</scope>
|
<scope>provided</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<!-- Ultimate Stacker dependency -->
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.craftaro</groupId>
|
<groupId>com.songoda</groupId>
|
||||||
<artifactId>UltimateStacker-API</artifactId>
|
<artifactId>UltimateStacker</artifactId>
|
||||||
<version>1.0.0-20240329.173606-35</version>
|
<version>2.4.0</version>
|
||||||
<scope>provided</scope>
|
<scope>provided</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
@ -9,14 +9,8 @@ import world.bentobox.bentobox.api.addons.Pladdon;
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class LevelPladdon extends Pladdon {
|
public class LevelPladdon extends Pladdon {
|
||||||
|
|
||||||
private Addon addon;
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Addon getAddon() {
|
public Addon getAddon() {
|
||||||
if (addon == null) {
|
return new Level();
|
||||||
addon = new Level();
|
|
||||||
}
|
|
||||||
return addon;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,7 +2,6 @@ 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;
|
||||||
@ -32,12 +31,19 @@ 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";
|
||||||
private static final TreeMap<BigInteger, String> LEVELS = new TreeMap<>();
|
private static final TreeMap<BigInteger, String> LEVELS;
|
||||||
private static final BigInteger THOUSAND = BigInteger.valueOf(1000);
|
private static final BigInteger THOUSAND = BigInteger.valueOf(1000);
|
||||||
|
static {
|
||||||
|
LEVELS = new TreeMap<>();
|
||||||
|
|
||||||
|
LEVELS.put(THOUSAND, "k");
|
||||||
|
LEVELS.put(THOUSAND.pow(2), "M");
|
||||||
|
LEVELS.put(THOUSAND.pow(3), "G");
|
||||||
|
LEVELS.put(THOUSAND.pow(4), "T");
|
||||||
|
}
|
||||||
private final Level addon;
|
private final Level addon;
|
||||||
|
|
||||||
// Database handler for level data
|
// Database handler for level data
|
||||||
@ -46,57 +52,49 @@ 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;
|
||||||
// Get the BentoBox database
|
// Get the BentoBox database
|
||||||
// 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);
|
||||||
// Initialize the cache
|
// Initialize the cache
|
||||||
levelsCache = new HashMap<>();
|
levelsCache = new HashMap<>();
|
||||||
// Initialize top ten lists
|
// Initialize top ten lists
|
||||||
topTenLists = new ConcurrentHashMap<>();
|
topTenLists = new ConcurrentHashMap<>();
|
||||||
// Units
|
|
||||||
LEVELS.put(THOUSAND, addon.getSettings().getKilo());
|
|
||||||
LEVELS.put(THOUSAND.pow(2), addon.getSettings().getMega());
|
|
||||||
LEVELS.put(THOUSAND.pow(3), addon.getSettings().getGiga());
|
|
||||||
LEVELS.put(THOUSAND.pow(4), addon.getSettings().getTera());
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void migrate() {
|
public void migrate() {
|
||||||
Database<LevelsData> oldDb = new Database<>(addon, LevelsData.class);
|
Database<LevelsData> oldDb = new Database<>(addon, LevelsData.class);
|
||||||
oldDb.loadObjects().forEach(ld -> {
|
oldDb.loadObjects().forEach(ld -> {
|
||||||
try {
|
try {
|
||||||
UUID owner = UUID.fromString(ld.getUniqueId());
|
UUID owner = UUID.fromString(ld.getUniqueId());
|
||||||
// Step through each world
|
// Step through each world
|
||||||
ld.getLevels().keySet().stream()
|
ld.getLevels().keySet().stream()
|
||||||
// World
|
// World
|
||||||
.map(Bukkit::getWorld).filter(Objects::nonNull)
|
.map(Bukkit::getWorld).filter(Objects::nonNull)
|
||||||
// Island
|
// Island
|
||||||
.map(w -> addon.getIslands().getIsland(w, owner)).filter(Objects::nonNull).forEach(i -> {
|
.map(w -> addon.getIslands().getIsland(w, owner)).filter(Objects::nonNull).forEach(i -> {
|
||||||
// Make new database entry
|
// Make new database entry
|
||||||
World w = i.getWorld();
|
World w = i.getWorld();
|
||||||
IslandLevels il = new IslandLevels(i.getUniqueId());
|
IslandLevels il = new IslandLevels(i.getUniqueId());
|
||||||
il.setInitialLevel(ld.getInitialLevel(w));
|
il.setInitialLevel(ld.getInitialLevel(w));
|
||||||
il.setLevel(ld.getLevel(w));
|
il.setLevel(ld.getLevel(w));
|
||||||
il.setMdCount(ld.getMdCount(w));
|
il.setMdCount(ld.getMdCount(w));
|
||||||
il.setPointsToNextLevel(ld.getPointsToNextLevel(w));
|
il.setPointsToNextLevel(ld.getPointsToNextLevel(w));
|
||||||
il.setUwCount(ld.getUwCount(w));
|
il.setUwCount(ld.getUwCount(w));
|
||||||
// Save it
|
// Save it
|
||||||
handler.saveObjectAsync(il);
|
handler.saveObjectAsync(il);
|
||||||
});
|
});
|
||||||
// Now delete the old database entry
|
// Now delete the old database entry
|
||||||
oldDb.deleteID(ld.getUniqueId());
|
oldDb.deleteID(ld.getUniqueId());
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
addon.logError("Could not migrate level data database! " + e.getMessage());
|
addon.logError("Could not migrate level data database! " + e.getMessage());
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -107,13 +105,12 @@ public class LevelsManager {
|
|||||||
* @return true if successful, false if not added
|
* @return true if successful, false if not added
|
||||||
*/
|
*/
|
||||||
private boolean addToTopTen(Island island, long lv) {
|
private boolean addToTopTen(Island island, long lv) {
|
||||||
if (island != null && island.getOwner() != null && island.getWorld() != null
|
if (island != null && island.getOwner() != null && hasTopTenPerm(island.getWorld(), island.getOwner())) {
|
||||||
&& hasTopTenPerm(island.getWorld(), island.getOwner())) {
|
topTenLists.computeIfAbsent(island.getWorld(), k -> new TopTenData(island.getWorld())).getTopTen()
|
||||||
topTenLists.computeIfAbsent(island.getWorld(), k -> new TopTenData(island.getWorld())).getTopTen()
|
.put(island.getUniqueId(), lv);
|
||||||
.put(island.getUniqueId(), lv);
|
return true;
|
||||||
return true;
|
}
|
||||||
}
|
return false;
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -125,26 +122,26 @@ public class LevelsManager {
|
|||||||
* @return completable future with the results of the calculation
|
* @return completable future with the results of the calculation
|
||||||
*/
|
*/
|
||||||
public CompletableFuture<Results> calculateLevel(UUID targetPlayer, Island island) {
|
public CompletableFuture<Results> calculateLevel(UUID targetPlayer, Island island) {
|
||||||
CompletableFuture<Results> result = new CompletableFuture<>();
|
CompletableFuture<Results> result = new CompletableFuture<>();
|
||||||
// Fire pre-level calc event
|
// Fire pre-level calc event
|
||||||
IslandPreLevelEvent e = new IslandPreLevelEvent(targetPlayer, island);
|
IslandPreLevelEvent e = new IslandPreLevelEvent(targetPlayer, island);
|
||||||
Bukkit.getPluginManager().callEvent(e);
|
Bukkit.getPluginManager().callEvent(e);
|
||||||
if (e.isCancelled()) {
|
if (e.isCancelled()) {
|
||||||
return CompletableFuture.completedFuture(null);
|
return CompletableFuture.completedFuture(null);
|
||||||
}
|
}
|
||||||
// Add island to the pipeline
|
// Add island to the pipeline
|
||||||
addon.getPipeliner().addIsland(island).thenAccept(r -> {
|
addon.getPipeliner().addIsland(island).thenAccept(r -> {
|
||||||
// Results are irrelevant because the island is unowned or deleted, or
|
// Results are irrelevant because the island is unowned or deleted, or
|
||||||
// IslandLevelCalcEvent is cancelled
|
// IslandLevelCalcEvent is cancelled
|
||||||
if (r == null || fireIslandLevelCalcEvent(targetPlayer, island, r)) {
|
if (r == null || fireIslandLevelCalcEvent(targetPlayer, island, r)) {
|
||||||
result.complete(null);
|
result.complete(null);
|
||||||
}
|
}
|
||||||
// Save result
|
// Save result
|
||||||
setIslandResults(island, r);
|
setIslandResults(island, r);
|
||||||
// Save the island scan details
|
// Save the island scan details
|
||||||
result.complete(r);
|
result.complete(r);
|
||||||
});
|
});
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -156,19 +153,19 @@ public class LevelsManager {
|
|||||||
* @return true if canceled
|
* @return true if canceled
|
||||||
*/
|
*/
|
||||||
private boolean fireIslandLevelCalcEvent(UUID targetPlayer, Island island, Results results) {
|
private boolean fireIslandLevelCalcEvent(UUID targetPlayer, Island island, Results results) {
|
||||||
// Fire post calculation event
|
// Fire post calculation event
|
||||||
IslandLevelCalculatedEvent ilce = new IslandLevelCalculatedEvent(targetPlayer, island, results);
|
IslandLevelCalculatedEvent ilce = new IslandLevelCalculatedEvent(targetPlayer, island, results);
|
||||||
Bukkit.getPluginManager().callEvent(ilce);
|
Bukkit.getPluginManager().callEvent(ilce);
|
||||||
if (ilce.isCancelled())
|
if (ilce.isCancelled())
|
||||||
return true;
|
return true;
|
||||||
// Set the values if they were altered
|
// Set the values if they were altered
|
||||||
results.setLevel((Long) ilce.getKeyValues().getOrDefault("level", results.getLevel()));
|
results.setLevel((Long) ilce.getKeyValues().getOrDefault("level", results.getLevel()));
|
||||||
results.setInitialLevel((Long) ilce.getKeyValues().getOrDefault("initialLevel", results.getInitialLevel()));
|
results.setInitialLevel((Long) ilce.getKeyValues().getOrDefault("initialLevel", results.getInitialLevel()));
|
||||||
results.setDeathHandicap((int) ilce.getKeyValues().getOrDefault("deathHandicap", results.getDeathHandicap()));
|
results.setDeathHandicap((int) ilce.getKeyValues().getOrDefault("deathHandicap", results.getDeathHandicap()));
|
||||||
results.setPointsToNextLevel(
|
results.setPointsToNextLevel(
|
||||||
(Long) ilce.getKeyValues().getOrDefault("pointsToNextLevel", results.getPointsToNextLevel()));
|
(Long) ilce.getKeyValues().getOrDefault("pointsToNextLevel", results.getPointsToNextLevel()));
|
||||||
results.setTotalPoints((Long) ilce.getKeyValues().getOrDefault("totalPoints", results.getTotalPoints()));
|
results.setTotalPoints((Long) ilce.getKeyValues().getOrDefault("totalPoints", results.getTotalPoints()));
|
||||||
return ((Boolean) ilce.getKeyValues().getOrDefault("isCancelled", false));
|
return ((Boolean) ilce.getKeyValues().getOrDefault("isCancelled", false));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -179,25 +176,25 @@ public class LevelsManager {
|
|||||||
* @return string of the level.
|
* @return string of the level.
|
||||||
*/
|
*/
|
||||||
public String formatLevel(@Nullable Long lvl) {
|
public String formatLevel(@Nullable Long lvl) {
|
||||||
if (lvl == null)
|
if (lvl == null)
|
||||||
return "";
|
return "";
|
||||||
String level = String.valueOf(lvl);
|
String level = String.valueOf(lvl);
|
||||||
// Asking for the level of another player
|
// Asking for the level of another player
|
||||||
if (addon.getSettings().isShorthand()) {
|
if (addon.getSettings().isShorthand()) {
|
||||||
BigInteger levelValue = BigInteger.valueOf(lvl);
|
BigInteger levelValue = BigInteger.valueOf(lvl);
|
||||||
|
|
||||||
Map.Entry<BigInteger, String> stage = LEVELS.floorEntry(levelValue);
|
Map.Entry<BigInteger, String> stage = LEVELS.floorEntry(levelValue);
|
||||||
|
|
||||||
if (stage != null) { // level > 1000
|
if (stage != null) { // level > 1000
|
||||||
// 1 052 -> 1.0k
|
// 1 052 -> 1.0k
|
||||||
// 1 527 314 -> 1.5M
|
// 1 527 314 -> 1.5M
|
||||||
// 3 874 130 021 -> 3.8G
|
// 3 874 130 021 -> 3.8G
|
||||||
// 4 002 317 889 -> 4.0T
|
// 4 002 317 889 -> 4.0T
|
||||||
level = new DecimalFormat("#.#").format(
|
level = new DecimalFormat("#.#").format(
|
||||||
levelValue.divide(stage.getKey().divide(THOUSAND)).doubleValue() / 1000.0) + stage.getValue();
|
levelValue.divide(stage.getKey().divide(THOUSAND)).doubleValue() / 1000.0) + stage.getValue();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return level;
|
return level;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -207,7 +204,7 @@ public class LevelsManager {
|
|||||||
* @return initial level of island
|
* @return initial level of island
|
||||||
*/
|
*/
|
||||||
public long getInitialLevel(Island island) {
|
public long getInitialLevel(Island island) {
|
||||||
return getLevelsData(island).getInitialLevel();
|
return getLevelsData(island).getInitialLevel();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -215,32 +212,15 @@ public class LevelsManager {
|
|||||||
*
|
*
|
||||||
* @param world - world where the island is
|
* @param world - world where the island is
|
||||||
* @param targetPlayer - target player UUID
|
* @param targetPlayer - target player UUID
|
||||||
* @param ownerOnly - return level only if the target player is the owner
|
|
||||||
* @return Level of the player's island or zero if player is unknown or UUID is
|
* @return Level of the player's island or zero if player is unknown or UUID is
|
||||||
* null
|
* null
|
||||||
*/
|
*/
|
||||||
public long getIslandLevel(@NonNull World world, @Nullable UUID targetPlayer) {
|
public long getIslandLevel(@NonNull World world, @Nullable UUID targetPlayer) {
|
||||||
return getIslandLevel(world, targetPlayer, false);
|
if (targetPlayer == null)
|
||||||
}
|
return 0L;
|
||||||
|
// Get the island
|
||||||
/**
|
Island island = addon.getIslands().getIsland(world, targetPlayer);
|
||||||
* Get level of island from cache for a player.
|
return island == null ? 0L : getLevelsData(island).getLevel();
|
||||||
*
|
|
||||||
* @param world - world where the island is
|
|
||||||
* @param targetPlayer - target player UUID
|
|
||||||
* @param ownerOnly - return level only if the target player is the owner
|
|
||||||
* @return Level of the player's island or zero if player is unknown or UUID is
|
|
||||||
* null
|
|
||||||
*/
|
|
||||||
public long getIslandLevel(@NonNull World world, @Nullable UUID targetPlayer, boolean ownerOnly) {
|
|
||||||
if (targetPlayer == null)
|
|
||||||
return 0L;
|
|
||||||
// Get the island
|
|
||||||
Island island = addon.getIslands().getIsland(world, targetPlayer);
|
|
||||||
if (island == null || island.getOwner() == null || (ownerOnly && !island.getOwner().equals(targetPlayer))) {
|
|
||||||
return 0L;
|
|
||||||
}
|
|
||||||
return getLevelsData(island).getLevel();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -252,11 +232,11 @@ public class LevelsManager {
|
|||||||
* is null
|
* is null
|
||||||
*/
|
*/
|
||||||
public long getIslandMaxLevel(@NonNull World world, @Nullable UUID targetPlayer) {
|
public long getIslandMaxLevel(@NonNull World world, @Nullable UUID targetPlayer) {
|
||||||
if (targetPlayer == null)
|
if (targetPlayer == null)
|
||||||
return 0L;
|
return 0L;
|
||||||
// Get the island
|
// Get the island
|
||||||
Island island = addon.getIslands().getIsland(world, targetPlayer);
|
Island island = addon.getIslands().getIsland(world, targetPlayer);
|
||||||
return island == null ? 0L : getLevelsData(island).getMaxLevel();
|
return island == null ? 0L : getLevelsData(island).getMaxLevel();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -268,7 +248,7 @@ public class LevelsManager {
|
|||||||
* null
|
* null
|
||||||
*/
|
*/
|
||||||
public String getIslandLevelString(@NonNull World world, @Nullable UUID targetPlayer) {
|
public String getIslandLevelString(@NonNull World world, @Nullable UUID targetPlayer) {
|
||||||
return formatLevel(getIslandLevel(world, targetPlayer));
|
return formatLevel(getIslandLevel(world, targetPlayer));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -279,24 +259,24 @@ public class LevelsManager {
|
|||||||
*/
|
*/
|
||||||
@NonNull
|
@NonNull
|
||||||
public IslandLevels getLevelsData(@NonNull Island island) {
|
public IslandLevels getLevelsData(@NonNull Island island) {
|
||||||
String id = island.getUniqueId();
|
String id = island.getUniqueId();
|
||||||
if (levelsCache.containsKey(id)) {
|
if (levelsCache.containsKey(id)) {
|
||||||
return levelsCache.get(id);
|
return levelsCache.get(id);
|
||||||
}
|
}
|
||||||
// Get from database if not in cache
|
// Get from database if not in cache
|
||||||
if (handler.objectExists(id)) {
|
if (handler.objectExists(id)) {
|
||||||
IslandLevels ld = handler.loadObject(id);
|
IslandLevels ld = handler.loadObject(id);
|
||||||
if (ld != null) {
|
if (ld != null) {
|
||||||
levelsCache.put(id, ld);
|
levelsCache.put(id, ld);
|
||||||
} else {
|
} else {
|
||||||
handler.deleteID(id);
|
handler.deleteID(id);
|
||||||
levelsCache.put(id, new IslandLevels(id));
|
levelsCache.put(id, new IslandLevels(id));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
levelsCache.put(id, new IslandLevels(id));
|
levelsCache.put(id, new IslandLevels(id));
|
||||||
}
|
}
|
||||||
// Return cached value
|
// Return cached value
|
||||||
return levelsCache.get(id);
|
return levelsCache.get(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -308,10 +288,10 @@ public class LevelsManager {
|
|||||||
* @return string with the number required or blank if the player is unknown
|
* @return string with the number required or blank if the player is unknown
|
||||||
*/
|
*/
|
||||||
public String getPointsToNextString(@NonNull World world, @Nullable UUID targetPlayer) {
|
public String getPointsToNextString(@NonNull World world, @Nullable UUID targetPlayer) {
|
||||||
if (targetPlayer == null)
|
if (targetPlayer == null)
|
||||||
return "";
|
return "";
|
||||||
Island island = addon.getIslands().getIsland(world, targetPlayer);
|
Island island = addon.getIslands().getIsland(world, targetPlayer);
|
||||||
return island == null ? "" : String.valueOf(getLevelsData(island).getPointsToNextLevel());
|
return island == null ? "" : String.valueOf(getLevelsData(island).getPointsToNextLevel());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -324,27 +304,28 @@ public class LevelsManager {
|
|||||||
*/
|
*/
|
||||||
@NonNull
|
@NonNull
|
||||||
public Map<Island, Long> getWeightedTopTen(@NonNull World world, int size) {
|
public Map<Island, Long> getWeightedTopTen(@NonNull World world, int size) {
|
||||||
createAndCleanRankings(world);
|
createAndCleanRankings(world);
|
||||||
Map<Island, Long> weightedTopTen = topTenLists.get(world).getTopTen().entrySet().stream()
|
Map<Island, Long> weightedTopTen = topTenLists.get(world).getTopTen().entrySet().stream()
|
||||||
.map(en -> addon.getIslands().getIslandById(en.getKey()).map(island -> {
|
.map(en -> addon.getIslands().getIslandById(en.getKey()).map(island -> {
|
||||||
|
|
||||||
long value = (long) (en.getValue() / (double) Math.max(1, island.getMemberSet().size())); // Calculate
|
long value = (long) (en.getValue() / (double) Math.max(1, island.getMemberSet().size())); // Calculate
|
||||||
// weighted
|
// weighted
|
||||||
// value
|
// value
|
||||||
return new AbstractMap.SimpleEntry<>(island, value);
|
return new AbstractMap.SimpleEntry<>(island, value);
|
||||||
}).orElse(null)) // Handle islands that do not exist according to this ID - old deleted ones
|
}).orElse(null)) // Handle islands that do not exist according to this ID - old deleted ones
|
||||||
.filter(Objects::nonNull) // Filter out null entries
|
.filter(Objects::nonNull) // Filter out null entries
|
||||||
.filter(en -> en.getValue() > 0) // Filter out entries with non-positive values
|
.filter(en -> en.getValue() > 0) // Filter out entries with non-positive values
|
||||||
.sorted(Collections.reverseOrder(Map.Entry.comparingByValue())) // Sort in descending order of values
|
.sorted(Collections.reverseOrder(Map.Entry.comparingByValue())) // Sort in descending order of values
|
||||||
.limit(size) // Limit to the top 'size' entries
|
.limit(size) // Limit to the top 'size' entries
|
||||||
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue, (e1, e2) -> e1, // In case of key
|
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue, (e1, e2) -> e1, // In case of key
|
||||||
// collision, choose
|
// collision, choose
|
||||||
// the first one
|
// the first one
|
||||||
LinkedHashMap::new // Preserves the order of entries
|
LinkedHashMap::new // Preserves the order of entries
|
||||||
));
|
));
|
||||||
|
|
||||||
|
// Return the unmodifiable map
|
||||||
|
return Collections.unmodifiableMap(weightedTopTen);
|
||||||
|
|
||||||
// Return the unmodifiable map
|
|
||||||
return Collections.unmodifiableMap(weightedTopTen);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -357,38 +338,26 @@ 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);
|
||||||
CachedData cachedData = cache.get(world);
|
// Return the sorted map
|
||||||
Instant now = Instant.now();
|
return Collections.unmodifiableMap(topTenLists.get(world).getTopTen().entrySet().stream()
|
||||||
|
.filter(l -> l.getValue() > 0).sorted(Collections.reverseOrder(Map.Entry.comparingByValue()))
|
||||||
if (cachedData != null && cachedData.getLastUpdated().plusSeconds(1).isAfter(now)) {
|
.limit(size)
|
||||||
return cachedData.getCachedMap();
|
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue, (e1, e2) -> e1, LinkedHashMap::new)));
|
||||||
} 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)
|
|
||||||
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue, (e1, e2) -> e1, LinkedHashMap::new)));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void createAndCleanRankings(@NonNull World world) {
|
void createAndCleanRankings(@NonNull World world) {
|
||||||
topTenLists.computeIfAbsent(world, TopTenData::new);
|
topTenLists.computeIfAbsent(world, TopTenData::new);
|
||||||
// Remove player from top ten if they are online and do not have the perm
|
// Remove player from top ten if they are online and do not have the perm
|
||||||
topTenLists.get(world).getTopTen().keySet().removeIf(u -> addon.getIslands().getIslandById(u)
|
topTenLists.get(world).getTopTen().keySet().removeIf(u -> addon.getIslands().getIslandById(u)
|
||||||
.filter(i -> i.getOwner() == null || !hasTopTenPerm(world, i.getOwner())).isPresent());
|
.filter(i -> i.getOwner() == null || !hasTopTenPerm(world, i.getOwner())).isPresent());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return the topTenLists
|
* @return the topTenLists
|
||||||
*/
|
*/
|
||||||
public Map<World, TopTenData> getTopTenLists() {
|
public Map<World, TopTenData> getTopTenLists() {
|
||||||
return topTenLists;
|
return topTenLists;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -399,13 +368,13 @@ public class LevelsManager {
|
|||||||
* @return rank placing - note - placing of 1 means top ranked
|
* @return rank placing - note - placing of 1 means top ranked
|
||||||
*/
|
*/
|
||||||
public int getRank(@NonNull World world, UUID uuid) {
|
public int getRank(@NonNull World world, UUID uuid) {
|
||||||
createAndCleanRankings(world);
|
createAndCleanRankings(world);
|
||||||
Stream<Entry<String, Long>> stream = topTenLists.get(world).getTopTen().entrySet().stream()
|
Stream<Entry<String, Long>> stream = 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()));
|
||||||
// Get player's current island
|
// Get player's current island
|
||||||
Island island = addon.getIslands().getIsland(world, uuid);
|
Island island = addon.getIslands().getIsland(world, uuid);
|
||||||
String id = island == null ? null : island.getUniqueId();
|
String id = island == null ? null : island.getUniqueId();
|
||||||
return (int) (stream.takeWhile(x -> !x.getKey().equals(id)).map(Map.Entry::getKey).count() + 1);
|
return (int) (stream.takeWhile(x -> !x.getKey().equals(id)).map(Map.Entry::getKey).count() + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -416,27 +385,26 @@ public class LevelsManager {
|
|||||||
* @return true if player has the perm or the player is offline
|
* @return true if player has the perm or the player is offline
|
||||||
*/
|
*/
|
||||||
boolean hasTopTenPerm(@NonNull World world, @NonNull UUID targetPlayer) {
|
boolean hasTopTenPerm(@NonNull World world, @NonNull UUID targetPlayer) {
|
||||||
String permPrefix = addon.getPlugin().getIWM().getPermissionPrefix(world);
|
String permPrefix = addon.getPlugin().getIWM().getPermissionPrefix(world);
|
||||||
return Bukkit.getPlayer(targetPlayer) == null
|
return Bukkit.getPlayer(targetPlayer) == null
|
||||||
|| Bukkit.getPlayer(targetPlayer).hasPermission(permPrefix + INTOPTEN);
|
|| Bukkit.getPlayer(targetPlayer).hasPermission(permPrefix + INTOPTEN);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Loads all the top tens from the database
|
* Loads all the top tens from the database
|
||||||
*/
|
*/
|
||||||
public void loadTopTens() {
|
public void loadTopTens() {
|
||||||
topTenLists.clear();
|
topTenLists.clear();
|
||||||
Bukkit.getScheduler().runTaskAsynchronously(addon.getPlugin(), () -> {
|
Bukkit.getScheduler().runTaskAsynchronously(addon.getPlugin(), () -> {
|
||||||
addon.log("Generating rankings");
|
addon.log("Generating rankings");
|
||||||
handler.loadObjects().forEach(il -> {
|
handler.loadObjects().forEach(il -> {
|
||||||
if (il.getLevel() > 0) {
|
if (il.getLevel() > 0) {
|
||||||
// Load islands, but don't cache them
|
addon.getIslands().getIslandById(il.getUniqueId())
|
||||||
addon.getIslands().getIslandById(il.getUniqueId(), false)
|
.ifPresent(i -> this.addToTopTen(i, il.getLevel()));
|
||||||
.ifPresent(i -> this.addToTopTen(i, il.getLevel()));
|
}
|
||||||
}
|
});
|
||||||
});
|
topTenLists.keySet().forEach(w -> addon.log("Generated rankings for " + w.getName()));
|
||||||
topTenLists.keySet().forEach(w -> addon.log("Generated rankings for " + w.getName()));
|
});
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -446,11 +414,10 @@ public class LevelsManager {
|
|||||||
* @param uuid - the island's uuid
|
* @param uuid - the island's uuid
|
||||||
*/
|
*/
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -460,10 +427,10 @@ public class LevelsManager {
|
|||||||
* @param lv - initial island level
|
* @param lv - initial island level
|
||||||
*/
|
*/
|
||||||
public void setInitialIslandLevel(@NonNull Island island, long lv) {
|
public void setInitialIslandLevel(@NonNull Island island, long lv) {
|
||||||
if (island.getWorld() == null)
|
if (island.getWorld() == null)
|
||||||
return;
|
return;
|
||||||
levelsCache.computeIfAbsent(island.getUniqueId(), IslandLevels::new).setInitialLevel(lv);
|
levelsCache.computeIfAbsent(island.getUniqueId(), IslandLevels::new).setInitialLevel(lv);
|
||||||
handler.saveObjectAsync(levelsCache.get(island.getUniqueId()));
|
handler.saveObjectAsync(levelsCache.get(island.getUniqueId()));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -475,21 +442,21 @@ public class LevelsManager {
|
|||||||
* @param lv - level
|
* @param lv - level
|
||||||
*/
|
*/
|
||||||
public void setIslandLevel(@NonNull World world, @NonNull UUID targetPlayer, long lv) {
|
public void setIslandLevel(@NonNull World world, @NonNull UUID targetPlayer, long lv) {
|
||||||
// Get the island
|
// Get the island
|
||||||
Island island = addon.getIslands().getIsland(world, targetPlayer);
|
Island island = addon.getIslands().getIsland(world, targetPlayer);
|
||||||
if (island != null) {
|
if (island != null) {
|
||||||
String id = island.getUniqueId();
|
String id = island.getUniqueId();
|
||||||
IslandLevels il = levelsCache.computeIfAbsent(id, IslandLevels::new);
|
IslandLevels il = levelsCache.computeIfAbsent(id, IslandLevels::new);
|
||||||
// Remove the initial level
|
// Remove the initial level
|
||||||
if (addon.getSettings().isZeroNewIslandLevels()) {
|
if (addon.getSettings().isZeroNewIslandLevels()) {
|
||||||
il.setLevel(lv - il.getInitialLevel());
|
il.setLevel(lv - il.getInitialLevel());
|
||||||
} else {
|
} else {
|
||||||
il.setLevel(lv);
|
il.setLevel(lv);
|
||||||
}
|
}
|
||||||
handler.saveObjectAsync(levelsCache.get(id));
|
handler.saveObjectAsync(levelsCache.get(id));
|
||||||
// Update TopTen
|
// Update TopTen
|
||||||
addToTopTen(island, levelsCache.get(id).getLevel());
|
addToTopTen(island, levelsCache.get(id).getLevel());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -501,18 +468,18 @@ public class LevelsManager {
|
|||||||
* @param r - results of the calculation
|
* @param r - results of the calculation
|
||||||
*/
|
*/
|
||||||
private void setIslandResults(Island island, Results r) {
|
private void setIslandResults(Island island, Results r) {
|
||||||
if (island == null)
|
if (island == null)
|
||||||
return;
|
return;
|
||||||
IslandLevels ld = levelsCache.computeIfAbsent(island.getUniqueId(), IslandLevels::new);
|
IslandLevels ld = levelsCache.computeIfAbsent(island.getUniqueId(), IslandLevels::new);
|
||||||
ld.setLevel(r.getLevel());
|
ld.setLevel(r.getLevel());
|
||||||
ld.setUwCount(Maps.asMap(r.getUwCount().elementSet(), elem -> r.getUwCount().count(elem)));
|
ld.setUwCount(Maps.asMap(r.getUwCount().elementSet(), elem -> r.getUwCount().count(elem)));
|
||||||
ld.setMdCount(Maps.asMap(r.getMdCount().elementSet(), elem -> r.getMdCount().count(elem)));
|
ld.setMdCount(Maps.asMap(r.getMdCount().elementSet(), elem -> r.getMdCount().count(elem)));
|
||||||
ld.setPointsToNextLevel(r.getPointsToNextLevel());
|
ld.setPointsToNextLevel(r.getPointsToNextLevel());
|
||||||
ld.setTotalPoints(r.getTotalPoints());
|
ld.setTotalPoints(r.getTotalPoints());
|
||||||
levelsCache.put(island.getUniqueId(), ld);
|
levelsCache.put(island.getUniqueId(), ld);
|
||||||
handler.saveObjectAsync(ld);
|
handler.saveObjectAsync(ld);
|
||||||
// Update TopTen
|
// Update TopTen
|
||||||
addToTopTen(island, ld.getLevel());
|
addToTopTen(island, ld.getLevel());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -521,8 +488,8 @@ public class LevelsManager {
|
|||||||
* @param uniqueId - id of island
|
* @param uniqueId - id of island
|
||||||
*/
|
*/
|
||||||
public void deleteIsland(String uniqueId) {
|
public void deleteIsland(String uniqueId) {
|
||||||
levelsCache.remove(uniqueId);
|
levelsCache.remove(uniqueId);
|
||||||
handler.deleteID(uniqueId);
|
handler.deleteID(uniqueId);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -30,72 +30,69 @@ public class PlaceholderManager {
|
|||||||
private final BentoBox plugin;
|
private final BentoBox plugin;
|
||||||
|
|
||||||
public PlaceholderManager(Level addon) {
|
public PlaceholderManager(Level addon) {
|
||||||
this.addon = addon;
|
this.addon = addon;
|
||||||
this.plugin = addon.getPlugin();
|
this.plugin = addon.getPlugin();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void registerPlaceholders(GameModeAddon gm) {
|
protected void registerPlaceholders(GameModeAddon gm) {
|
||||||
if (plugin.getPlaceholdersManager() == null)
|
if (plugin.getPlaceholdersManager() == null)
|
||||||
return;
|
return;
|
||||||
PlaceholdersManager bpm = plugin.getPlaceholdersManager();
|
PlaceholdersManager bpm = plugin.getPlaceholdersManager();
|
||||||
// Island Level
|
// Island Level
|
||||||
bpm.registerPlaceholder(addon, gm.getDescription().getName().toLowerCase() + "_island_level",
|
bpm.registerPlaceholder(addon, gm.getDescription().getName().toLowerCase() + "_island_level",
|
||||||
user -> addon.getManager().getIslandLevelString(gm.getOverWorld(), user.getUniqueId()));
|
user -> addon.getManager().getIslandLevelString(gm.getOverWorld(), user.getUniqueId()));
|
||||||
// Island Level owner only
|
// Unformatted island level
|
||||||
bpm.registerPlaceholder(addon, gm.getDescription().getName().toLowerCase() + "_island_level_owner",
|
bpm.registerPlaceholder(addon, gm.getDescription().getName().toLowerCase() + "_island_level_raw",
|
||||||
user -> String.valueOf(addon.getManager().getIslandLevel(gm.getOverWorld(), user.getUniqueId(), true)));
|
user -> String.valueOf(addon.getManager().getIslandLevel(gm.getOverWorld(), user.getUniqueId())));
|
||||||
// Unformatted island level
|
// Total number of points counted before applying level formula
|
||||||
bpm.registerPlaceholder(addon, gm.getDescription().getName().toLowerCase() + "_island_level_raw",
|
bpm.registerPlaceholder(addon, gm.getDescription().getName().toLowerCase() + "_island_total_points", user -> {
|
||||||
user -> String.valueOf(addon.getManager().getIslandLevel(gm.getOverWorld(), user.getUniqueId())));
|
IslandLevels data = addon.getManager().getLevelsData(addon.getIslands().getIsland(gm.getOverWorld(), user));
|
||||||
// Total number of points counted before applying level formula
|
return data.getTotalPoints() + "";
|
||||||
bpm.registerPlaceholder(addon, gm.getDescription().getName().toLowerCase() + "_island_total_points", user -> {
|
});
|
||||||
IslandLevels data = addon.getManager().getLevelsData(addon.getIslands().getIsland(gm.getOverWorld(), user));
|
// Points to the next level for player
|
||||||
return data.getTotalPoints() + "";
|
bpm.registerPlaceholder(addon, gm.getDescription().getName().toLowerCase() + "_points_to_next_level",
|
||||||
});
|
user -> addon.getManager().getPointsToNextString(gm.getOverWorld(), user.getUniqueId()));
|
||||||
// Points to the next level for player
|
// Maximum level this island has ever been. Current level maybe lower.
|
||||||
bpm.registerPlaceholder(addon, gm.getDescription().getName().toLowerCase() + "_points_to_next_level",
|
bpm.registerPlaceholder(addon, gm.getDescription().getName().toLowerCase() + "_island_level_max",
|
||||||
user -> addon.getManager().getPointsToNextString(gm.getOverWorld(), user.getUniqueId()));
|
user -> String.valueOf(addon.getManager().getIslandMaxLevel(gm.getOverWorld(), user.getUniqueId())));
|
||||||
// Maximum level this island has ever been. Current level maybe lower.
|
|
||||||
bpm.registerPlaceholder(addon, gm.getDescription().getName().toLowerCase() + "_island_level_max",
|
|
||||||
user -> String.valueOf(addon.getManager().getIslandMaxLevel(gm.getOverWorld(), user.getUniqueId())));
|
|
||||||
|
|
||||||
// Visited Island Level
|
// Visited Island Level
|
||||||
bpm.registerPlaceholder(addon, gm.getDescription().getName().toLowerCase() + "_visited_island_level",
|
bpm.registerPlaceholder(addon, gm.getDescription().getName().toLowerCase() + "_visited_island_level",
|
||||||
user -> getVisitedIslandLevel(gm, user));
|
user -> getVisitedIslandLevel(gm, user));
|
||||||
|
|
||||||
// Register Top Ten Placeholders
|
// Register Top Ten Placeholders
|
||||||
for (int i = 1; i < 11; i++) {
|
for (int i = 1; i < 11; i++) {
|
||||||
final int rank = i;
|
final int rank = i;
|
||||||
// Name
|
// Name
|
||||||
bpm.registerPlaceholder(addon, gm.getDescription().getName().toLowerCase() + "_top_name_" + i,
|
bpm.registerPlaceholder(addon, gm.getDescription().getName().toLowerCase() + "_top_name_" + i,
|
||||||
u -> getRankName(gm.getOverWorld(), rank, false));
|
u -> getRankName(gm.getOverWorld(), rank, false));
|
||||||
// Island Name
|
// Island Name
|
||||||
bpm.registerPlaceholder(addon, gm.getDescription().getName().toLowerCase() + "_top_island_name_" + i,
|
bpm.registerPlaceholder(addon, gm.getDescription().getName().toLowerCase() + "_top_island_name_" + i,
|
||||||
u -> getRankIslandName(gm.getOverWorld(), rank, false));
|
u -> getRankIslandName(gm.getOverWorld(), rank, false));
|
||||||
// Members
|
// Members
|
||||||
bpm.registerPlaceholder(addon, gm.getDescription().getName().toLowerCase() + "_top_members_" + i,
|
bpm.registerPlaceholder(addon, gm.getDescription().getName().toLowerCase() + "_top_members_" + i,
|
||||||
u -> getRankMembers(gm.getOverWorld(), rank, false));
|
u -> getRankMembers(gm.getOverWorld(), rank, false));
|
||||||
// Level
|
// Level
|
||||||
bpm.registerPlaceholder(addon, gm.getDescription().getName().toLowerCase() + "_top_value_" + i,
|
bpm.registerPlaceholder(addon, gm.getDescription().getName().toLowerCase() + "_top_value_" + i,
|
||||||
u -> getRankLevel(gm.getOverWorld(), rank, false));
|
u -> getRankLevel(gm.getOverWorld(), rank, false));
|
||||||
// Weighted Level Name (Level / number of members)
|
// Weighted Level Name (Level / number of members)
|
||||||
bpm.registerPlaceholder(addon, gm.getDescription().getName().toLowerCase() + "_top_weighted_name_" + i,
|
bpm.registerPlaceholder(addon, gm.getDescription().getName().toLowerCase() + "_top_weighted_name_" + i,
|
||||||
u -> getRankName(gm.getOverWorld(), rank, true));
|
u -> getRankName(gm.getOverWorld(), rank, true));
|
||||||
// Weighted Island Name
|
// Weighted Island Name
|
||||||
bpm.registerPlaceholder(addon,
|
bpm.registerPlaceholder(addon,
|
||||||
gm.getDescription().getName().toLowerCase() + "_top_weighted_island_name_" + i,
|
gm.getDescription().getName().toLowerCase() + "_top_weighted_island_name_" + i,
|
||||||
u -> getRankIslandName(gm.getOverWorld(), rank, true));
|
u -> getRankIslandName(gm.getOverWorld(), rank, true));
|
||||||
// Weighted Members
|
// Weighted Members
|
||||||
bpm.registerPlaceholder(addon, gm.getDescription().getName().toLowerCase() + "_top_weighted_members_" + i,
|
bpm.registerPlaceholder(addon, gm.getDescription().getName().toLowerCase() + "_top_weighted_members_" + i,
|
||||||
u -> getRankMembers(gm.getOverWorld(), rank, true));
|
u -> getRankMembers(gm.getOverWorld(), rank, true));
|
||||||
// Weighted Level (Level / number of members)
|
// Weighted Level (Level / number of members)
|
||||||
bpm.registerPlaceholder(addon, gm.getDescription().getName().toLowerCase() + "_top_weighted_value_" + i,
|
bpm.registerPlaceholder(addon, gm.getDescription().getName().toLowerCase() + "_top_weighted_value_" + i,
|
||||||
u -> getRankLevel(gm.getOverWorld(), rank, true));
|
u -> getRankLevel(gm.getOverWorld(), rank, true));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Personal rank
|
// Personal rank
|
||||||
bpm.registerPlaceholder(addon, gm.getDescription().getName().toLowerCase() + "_rank_value",
|
bpm.registerPlaceholder(addon, gm.getDescription().getName().toLowerCase() + "_rank_value",
|
||||||
u -> getRankValue(gm.getOverWorld(), u));
|
u -> getRankValue(gm.getOverWorld(), u));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -107,17 +104,17 @@ public class PlaceholderManager {
|
|||||||
* @return rank name
|
* @return rank name
|
||||||
*/
|
*/
|
||||||
String getRankName(World world, int rank, boolean weighted) {
|
String getRankName(World world, int rank, boolean weighted) {
|
||||||
// Ensure rank is within bounds
|
// Ensure rank is within bounds
|
||||||
rank = Math.max(1, Math.min(rank, Level.TEN));
|
rank = Math.max(1, Math.min(rank, Level.TEN));
|
||||||
if (weighted) {
|
if (weighted) {
|
||||||
return addon.getManager().getWeightedTopTen(world, Level.TEN).keySet().stream().skip(rank - 1L).limit(1L)
|
return addon.getManager().getWeightedTopTen(world, Level.TEN).keySet().stream().skip(rank - 1L).limit(1L)
|
||||||
.findFirst().map(Island::getOwner).map(addon.getPlayers()::getName).orElse("");
|
.findFirst().map(Island::getOwner).map(addon.getPlayers()::getName).orElse("");
|
||||||
}
|
}
|
||||||
@Nullable
|
@Nullable
|
||||||
UUID owner = addon.getManager().getTopTen(world, Level.TEN).keySet().stream().skip(rank - 1L).limit(1L)
|
UUID owner = addon.getManager().getTopTen(world, Level.TEN).keySet().stream().skip(rank - 1L).limit(1L)
|
||||||
.findFirst().flatMap(addon.getIslands()::getIslandById).map(Island::getOwner).orElse(null);
|
.findFirst().flatMap(addon.getIslands()::getIslandById).map(Island::getOwner).orElse(null);
|
||||||
|
|
||||||
return addon.getPlayers().getName(owner);
|
return addon.getPlayers().getName(owner);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -129,14 +126,14 @@ public class PlaceholderManager {
|
|||||||
* @return name of island or nothing if there isn't one
|
* @return name of island or nothing if there isn't one
|
||||||
*/
|
*/
|
||||||
String getRankIslandName(World world, int rank, boolean weighted) {
|
String getRankIslandName(World world, int rank, boolean weighted) {
|
||||||
// Ensure rank is within bounds
|
// Ensure rank is within bounds
|
||||||
rank = Math.max(1, Math.min(rank, Level.TEN));
|
rank = Math.max(1, Math.min(rank, Level.TEN));
|
||||||
if (weighted) {
|
if (weighted) {
|
||||||
return addon.getManager().getWeightedTopTen(world, Level.TEN).keySet().stream().skip(rank - 1L).limit(1L)
|
return addon.getManager().getWeightedTopTen(world, Level.TEN).keySet().stream().skip(rank - 1L).limit(1L)
|
||||||
.findFirst().map(Island::getName).orElse("");
|
.findFirst().map(Island::getName).orElse("");
|
||||||
}
|
}
|
||||||
return addon.getManager().getTopTen(world, Level.TEN).keySet().stream().skip(rank - 1L).limit(1L).findFirst()
|
return addon.getManager().getTopTen(world, Level.TEN).keySet().stream().skip(rank - 1L).limit(1L).findFirst()
|
||||||
.flatMap(addon.getIslands()::getIslandById).map(Island::getName).orElse("");
|
.flatMap(addon.getIslands()::getIslandById).map(Island::getName).orElse("");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -148,27 +145,27 @@ public class PlaceholderManager {
|
|||||||
* @return comma separated string of island member names
|
* @return comma separated string of island member names
|
||||||
*/
|
*/
|
||||||
String getRankMembers(World world, int rank, boolean weighted) {
|
String getRankMembers(World world, int rank, boolean weighted) {
|
||||||
// Ensure rank is within bounds
|
// Ensure rank is within bounds
|
||||||
rank = Math.max(1, Math.min(rank, Level.TEN));
|
rank = Math.max(1, Math.min(rank, Level.TEN));
|
||||||
if (weighted) {
|
if (weighted) {
|
||||||
return addon.getManager().getWeightedTopTen(world, Level.TEN).keySet().stream().skip(rank - 1L).limit(1L)
|
return addon.getManager().getWeightedTopTen(world, Level.TEN).keySet().stream().skip(rank - 1L).limit(1L)
|
||||||
.findFirst()
|
.findFirst()
|
||||||
.map(is -> is.getMembers().entrySet().stream().filter(e -> e.getValue() >= RanksManager.MEMBER_RANK)
|
.map(is -> is.getMembers().entrySet().stream().filter(e -> e.getValue() >= RanksManager.MEMBER_RANK)
|
||||||
.sorted(Collections.reverseOrder(Map.Entry.comparingByValue())).map(Map.Entry::getKey)
|
.sorted(Collections.reverseOrder(Map.Entry.comparingByValue())).map(Map.Entry::getKey)
|
||||||
.map(addon.getPlayers()::getName).collect(Collectors.joining(",")))
|
.map(addon.getPlayers()::getName).collect(Collectors.joining(",")))
|
||||||
.orElse("");
|
.orElse("");
|
||||||
}
|
}
|
||||||
|
|
||||||
Optional<Island> island = addon.getManager().getTopTen(world, Level.TEN).keySet().stream().skip(rank - 1L)
|
Optional<Island> island = addon.getManager().getTopTen(world, Level.TEN).keySet().stream().skip(rank - 1L)
|
||||||
.limit(1L).findFirst().flatMap(addon.getIslands()::getIslandById);
|
.limit(1L).findFirst().flatMap(addon.getIslands()::getIslandById);
|
||||||
|
|
||||||
if (island.isPresent()) {
|
if (island.isPresent()) {
|
||||||
// Sort members by rank
|
// Sort members by rank
|
||||||
return island.get().getMembers().entrySet().stream().filter(e -> e.getValue() >= RanksManager.MEMBER_RANK)
|
return island.get().getMembers().entrySet().stream().filter(e -> e.getValue() >= RanksManager.MEMBER_RANK)
|
||||||
.sorted(Collections.reverseOrder(Map.Entry.comparingByValue())).map(Map.Entry::getKey)
|
.sorted(Collections.reverseOrder(Map.Entry.comparingByValue())).map(Map.Entry::getKey)
|
||||||
.map(addon.getPlayers()::getName).collect(Collectors.joining(","));
|
.map(addon.getPlayers()::getName).collect(Collectors.joining(","));
|
||||||
}
|
}
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -180,14 +177,14 @@ public class PlaceholderManager {
|
|||||||
* @return level for the rank requested
|
* @return level for the rank requested
|
||||||
*/
|
*/
|
||||||
String getRankLevel(World world, int rank, boolean weighted) {
|
String getRankLevel(World world, int rank, boolean weighted) {
|
||||||
// Ensure rank is within bounds
|
// Ensure rank is within bounds
|
||||||
rank = Math.max(1, Math.min(rank, Level.TEN));
|
rank = Math.max(1, Math.min(rank, Level.TEN));
|
||||||
if (weighted) {
|
if (weighted) {
|
||||||
return addon.getManager().formatLevel(addon.getManager().getWeightedTopTen(world, Level.TEN).values()
|
return addon.getManager().formatLevel(addon.getManager().getWeightedTopTen(world, Level.TEN).values()
|
||||||
.stream().skip(rank - 1L).limit(1L).findFirst().orElse(null));
|
.stream().skip(rank - 1L).limit(1L).findFirst().orElse(null));
|
||||||
}
|
}
|
||||||
return addon.getManager().formatLevel(addon.getManager().getTopTen(world, Level.TEN).values().stream()
|
return addon.getManager().formatLevel(addon.getManager().getTopTen(world, Level.TEN).values().stream()
|
||||||
.skip(rank - 1L).limit(1L).findFirst().orElse(null));
|
.skip(rank - 1L).limit(1L).findFirst().orElse(null));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -198,21 +195,21 @@ public class PlaceholderManager {
|
|||||||
* @return rank where 1 is the top rank.
|
* @return rank where 1 is the top rank.
|
||||||
*/
|
*/
|
||||||
private String getRankValue(World world, User user) {
|
private String getRankValue(World world, User user) {
|
||||||
if (user == null) {
|
if (user == null) {
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
// Get the island level for this user
|
// Get the island level for this user
|
||||||
long level = addon.getManager().getIslandLevel(world, user.getUniqueId());
|
long level = addon.getManager().getIslandLevel(world, user.getUniqueId());
|
||||||
return String.valueOf(addon.getManager().getTopTenLists().getOrDefault(world, new TopTenData(world)).getTopTen()
|
return String.valueOf(addon.getManager().getTopTenLists().getOrDefault(world, new TopTenData(world)).getTopTen()
|
||||||
.values().stream().filter(l -> l > level).count() + 1);
|
.values().stream().filter(l -> l > level).count() + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
String getVisitedIslandLevel(GameModeAddon gm, User user) {
|
String getVisitedIslandLevel(GameModeAddon gm, User user) {
|
||||||
if (user == null || !gm.inWorld(user.getWorld()))
|
if (user == null || !gm.inWorld(user.getWorld()))
|
||||||
return "";
|
return "";
|
||||||
return addon.getIslands().getIslandAt(user.getLocation())
|
return addon.getIslands().getIslandAt(user.getLocation())
|
||||||
.map(island -> addon.getManager().getIslandLevelString(gm.getOverWorld(), island.getOwner()))
|
.map(island -> addon.getManager().getIslandLevelString(gm.getOverWorld(), island.getOwner()))
|
||||||
.orElse("0");
|
.orElse("0");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -40,6 +40,9 @@ 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;
|
||||||
@ -56,13 +59,13 @@ public class IslandLevelCalculator {
|
|||||||
private static final String LINE_BREAK = "==================================";
|
private static final String LINE_BREAK = "==================================";
|
||||||
public static final long MAX_AMOUNT = 10000000;
|
public static final long MAX_AMOUNT = 10000000;
|
||||||
private static final List<Material> CHESTS = Arrays.asList(Material.CHEST, Material.CHEST_MINECART,
|
private static final List<Material> CHESTS = Arrays.asList(Material.CHEST, Material.CHEST_MINECART,
|
||||||
Material.TRAPPED_CHEST, Material.SHULKER_BOX, Material.BLACK_SHULKER_BOX, Material.BLUE_SHULKER_BOX,
|
Material.TRAPPED_CHEST, Material.SHULKER_BOX, Material.BLACK_SHULKER_BOX, Material.BLUE_SHULKER_BOX,
|
||||||
Material.BROWN_SHULKER_BOX, Material.CYAN_SHULKER_BOX, Material.GRAY_SHULKER_BOX,
|
Material.BROWN_SHULKER_BOX, Material.CYAN_SHULKER_BOX, Material.GRAY_SHULKER_BOX,
|
||||||
Material.GREEN_SHULKER_BOX, Material.LIGHT_BLUE_SHULKER_BOX, Material.LIGHT_GRAY_SHULKER_BOX,
|
Material.GREEN_SHULKER_BOX, Material.LIGHT_BLUE_SHULKER_BOX, Material.LIGHT_GRAY_SHULKER_BOX,
|
||||||
Material.LIME_SHULKER_BOX, Material.MAGENTA_SHULKER_BOX, Material.ORANGE_SHULKER_BOX,
|
Material.LIME_SHULKER_BOX, Material.MAGENTA_SHULKER_BOX, Material.ORANGE_SHULKER_BOX,
|
||||||
Material.PINK_SHULKER_BOX, Material.PURPLE_SHULKER_BOX, Material.RED_SHULKER_BOX, Material.RED_SHULKER_BOX,
|
Material.PINK_SHULKER_BOX, Material.PURPLE_SHULKER_BOX, Material.RED_SHULKER_BOX, Material.RED_SHULKER_BOX,
|
||||||
Material.WHITE_SHULKER_BOX, Material.YELLOW_SHULKER_BOX, Material.COMPOSTER, Material.BARREL,
|
Material.WHITE_SHULKER_BOX, Material.YELLOW_SHULKER_BOX, Material.COMPOSTER, Material.BARREL,
|
||||||
Material.DISPENSER, Material.DROPPER, Material.SMOKER, Material.BLAST_FURNACE);
|
Material.DISPENSER, Material.DROPPER, Material.SMOKER, Material.BLAST_FURNACE);
|
||||||
private static final int CHUNKS_TO_SCAN = 100;
|
private static final int CHUNKS_TO_SCAN = 100;
|
||||||
private final Level addon;
|
private final Level addon;
|
||||||
private final Queue<Pair<Integer, Integer>> chunksToCheck;
|
private final Queue<Pair<Integer, Integer>> chunksToCheck;
|
||||||
@ -89,34 +92,34 @@ public class IslandLevelCalculator {
|
|||||||
* @param zeroIsland - true if the calculation is due to an island zeroing
|
* @param zeroIsland - true if the calculation is due to an island zeroing
|
||||||
*/
|
*/
|
||||||
public IslandLevelCalculator(Level addon, Island island, CompletableFuture<Results> r, boolean zeroIsland) {
|
public IslandLevelCalculator(Level addon, Island island, CompletableFuture<Results> r, boolean zeroIsland) {
|
||||||
this.addon = addon;
|
this.addon = addon;
|
||||||
this.island = island;
|
this.island = island;
|
||||||
this.r = r;
|
this.r = r;
|
||||||
this.zeroIsland = zeroIsland;
|
this.zeroIsland = zeroIsland;
|
||||||
results = new Results();
|
results = new Results();
|
||||||
duration = System.currentTimeMillis();
|
duration = System.currentTimeMillis();
|
||||||
chunksToCheck = getChunksToScan(island);
|
chunksToCheck = getChunksToScan(island);
|
||||||
this.limitCount = new EnumMap<>(addon.getBlockConfig().getBlockLimits());
|
this.limitCount = new EnumMap<>(addon.getBlockConfig().getBlockLimits());
|
||||||
// Get the initial island level
|
// Get the initial island level
|
||||||
results.initialLevel.set(addon.getInitialIslandLevel(island));
|
results.initialLevel.set(addon.getInitialIslandLevel(island));
|
||||||
// Set up the worlds
|
// Set up the worlds
|
||||||
worlds.put(Environment.NORMAL, Util.getWorld(island.getWorld()));
|
worlds.put(Environment.NORMAL, Util.getWorld(island.getWorld()));
|
||||||
// Nether
|
// Nether
|
||||||
if (addon.getSettings().isNether()) {
|
if (addon.getSettings().isNether()) {
|
||||||
World nether = addon.getPlugin().getIWM().getNetherWorld(island.getWorld());
|
World nether = addon.getPlugin().getIWM().getNetherWorld(island.getWorld());
|
||||||
if (nether != null) {
|
if (nether != null) {
|
||||||
worlds.put(Environment.NETHER, nether);
|
worlds.put(Environment.NETHER, nether);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// End
|
// End
|
||||||
if (addon.getSettings().isEnd()) {
|
if (addon.getSettings().isEnd()) {
|
||||||
World end = addon.getPlugin().getIWM().getEndWorld(island.getWorld());
|
World end = addon.getPlugin().getIWM().getEndWorld(island.getWorld());
|
||||||
if (end != null) {
|
if (end != null) {
|
||||||
worlds.put(Environment.THE_END, end);
|
worlds.put(Environment.THE_END, end);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Sea Height
|
// Sea Height
|
||||||
seaHeight = addon.getPlugin().getIWM().getSeaHeight(island.getWorld());
|
seaHeight = addon.getPlugin().getIWM().getSeaHeight(island.getWorld());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -126,18 +129,18 @@ public class IslandLevelCalculator {
|
|||||||
* @return level of island
|
* @return level of island
|
||||||
*/
|
*/
|
||||||
private long calculateLevel(long blockAndDeathPoints) {
|
private long calculateLevel(long blockAndDeathPoints) {
|
||||||
String calcString = addon.getSettings().getLevelCalc();
|
String calcString = addon.getSettings().getLevelCalc();
|
||||||
String withValues = calcString.replace("blocks", String.valueOf(blockAndDeathPoints)).replace("level_cost",
|
String withValues = calcString.replace("blocks", String.valueOf(blockAndDeathPoints)).replace("level_cost",
|
||||||
String.valueOf(this.addon.getSettings().getLevelCost()));
|
String.valueOf(this.addon.getSettings().getLevelCost()));
|
||||||
long evalWithValues;
|
long evalWithValues;
|
||||||
try {
|
try {
|
||||||
evalWithValues = (long) EquationEvaluator.eval(withValues);
|
evalWithValues = (long) EquationEvaluator.eval(withValues);
|
||||||
return evalWithValues - (addon.getSettings().isZeroNewIslandLevels() ? results.initialLevel.get() : 0);
|
return evalWithValues - (addon.getSettings().isZeroNewIslandLevels() ? results.initialLevel.get() : 0);
|
||||||
|
|
||||||
} catch (ParseException e) {
|
} catch (ParseException e) {
|
||||||
addon.getPlugin().logStacktrace(e);
|
addon.getPlugin().logStacktrace(e);
|
||||||
return 0L;
|
return 0L;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -148,14 +151,14 @@ public class IslandLevelCalculator {
|
|||||||
* @param belowSeaLevel - true if below sea level
|
* @param belowSeaLevel - true if below sea level
|
||||||
*/
|
*/
|
||||||
private void checkBlock(Material mat, boolean belowSeaLevel) {
|
private void checkBlock(Material mat, boolean belowSeaLevel) {
|
||||||
int count = limitCount(mat);
|
int count = limitCount(mat);
|
||||||
if (belowSeaLevel) {
|
if (belowSeaLevel) {
|
||||||
results.underWaterBlockCount.addAndGet(count);
|
results.underWaterBlockCount.addAndGet(count);
|
||||||
results.uwCount.add(mat);
|
results.uwCount.add(mat);
|
||||||
} else {
|
} else {
|
||||||
results.rawBlockCount.addAndGet(count);
|
results.rawBlockCount.addAndGet(count);
|
||||||
results.mdCount.add(mat);
|
results.mdCount.add(mat);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -165,22 +168,22 @@ public class IslandLevelCalculator {
|
|||||||
* @return - set of pairs of x,z coordinates to check
|
* @return - set of pairs of x,z coordinates to check
|
||||||
*/
|
*/
|
||||||
private Queue<Pair<Integer, Integer>> getChunksToScan(Island island) {
|
private Queue<Pair<Integer, Integer>> getChunksToScan(Island island) {
|
||||||
Queue<Pair<Integer, Integer>> chunkQueue = new ConcurrentLinkedQueue<>();
|
Queue<Pair<Integer, Integer>> chunkQueue = new ConcurrentLinkedQueue<>();
|
||||||
for (int x = island.getMinProtectedX(); x < (island.getMinProtectedX() + island.getProtectionRange() * 2
|
for (int x = island.getMinProtectedX(); x < (island.getMinProtectedX() + island.getProtectionRange() * 2
|
||||||
+ 16); x += 16) {
|
+ 16); x += 16) {
|
||||||
for (int z = island.getMinProtectedZ(); z < (island.getMinProtectedZ() + island.getProtectionRange() * 2
|
for (int z = island.getMinProtectedZ(); z < (island.getMinProtectedZ() + island.getProtectionRange() * 2
|
||||||
+ 16); z += 16) {
|
+ 16); z += 16) {
|
||||||
chunkQueue.add(new Pair<>(x >> 4, z >> 4));
|
chunkQueue.add(new Pair<>(x >> 4, z >> 4));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return chunkQueue;
|
return chunkQueue;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return the island
|
* @return the island
|
||||||
*/
|
*/
|
||||||
public Island getIsland() {
|
public Island getIsland() {
|
||||||
return island;
|
return island;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -189,7 +192,7 @@ public class IslandLevelCalculator {
|
|||||||
* @return the r
|
* @return the r
|
||||||
*/
|
*/
|
||||||
public CompletableFuture<Results> getR() {
|
public CompletableFuture<Results> getR() {
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -198,67 +201,67 @@ public class IslandLevelCalculator {
|
|||||||
* @return a list of lines
|
* @return a list of lines
|
||||||
*/
|
*/
|
||||||
private List<String> getReport() {
|
private List<String> getReport() {
|
||||||
List<String> reportLines = new ArrayList<>();
|
List<String> reportLines = new ArrayList<>();
|
||||||
// provide counts
|
// provide counts
|
||||||
reportLines.add("Level Log for island in " + addon.getPlugin().getIWM().getFriendlyName(island.getWorld())
|
reportLines.add("Level Log for island in " + addon.getPlugin().getIWM().getFriendlyName(island.getWorld())
|
||||||
+ " at " + Util.xyz(island.getCenter().toVector()));
|
+ " at " + Util.xyz(island.getCenter().toVector()));
|
||||||
reportLines.add("Island owner UUID = " + island.getOwner());
|
reportLines.add("Island owner UUID = " + island.getOwner());
|
||||||
reportLines.add("Total block value count = " + String.format("%,d", results.rawBlockCount.get()));
|
reportLines.add("Total block value count = " + String.format("%,d", results.rawBlockCount.get()));
|
||||||
reportLines.add("Formula to calculate island level: " + addon.getSettings().getLevelCalc());
|
reportLines.add("Formula to calculate island level: " + addon.getSettings().getLevelCalc());
|
||||||
reportLines.add("Level cost = " + addon.getSettings().getLevelCost());
|
reportLines.add("Level cost = " + addon.getSettings().getLevelCost());
|
||||||
reportLines.add("Deaths handicap = " + results.deathHandicap.get());
|
reportLines.add("Deaths handicap = " + results.deathHandicap.get());
|
||||||
if (addon.getSettings().isZeroNewIslandLevels()) {
|
if (addon.getSettings().isZeroNewIslandLevels()) {
|
||||||
reportLines.add("Initial island level = " + (0L - addon.getManager().getInitialLevel(island)));
|
reportLines.add("Initial island level = " + (0L - addon.getManager().getInitialLevel(island)));
|
||||||
}
|
}
|
||||||
reportLines.add("Previous level = " + addon.getManager().getIslandLevel(island.getWorld(), island.getOwner()));
|
reportLines.add("Previous level = " + addon.getManager().getIslandLevel(island.getWorld(), island.getOwner()));
|
||||||
reportLines.add("New level = " + results.getLevel());
|
reportLines.add("New level = " + results.getLevel());
|
||||||
reportLines.add(LINE_BREAK);
|
reportLines.add(LINE_BREAK);
|
||||||
int total = 0;
|
int total = 0;
|
||||||
if (!results.uwCount.isEmpty()) {
|
if (!results.uwCount.isEmpty()) {
|
||||||
reportLines.add("Underwater block count (Multiplier = x" + addon.getSettings().getUnderWaterMultiplier()
|
reportLines.add("Underwater block count (Multiplier = x" + addon.getSettings().getUnderWaterMultiplier()
|
||||||
+ ") value");
|
+ ") value");
|
||||||
reportLines.add("Total number of underwater blocks = " + String.format("%,d", results.uwCount.size()));
|
reportLines.add("Total number of underwater blocks = " + String.format("%,d", results.uwCount.size()));
|
||||||
reportLines.addAll(sortedReport(total, results.uwCount));
|
reportLines.addAll(sortedReport(total, results.uwCount));
|
||||||
}
|
}
|
||||||
reportLines.add("Regular block count");
|
reportLines.add("Regular block count");
|
||||||
reportLines.add("Total number of blocks = " + String.format("%,d", results.mdCount.size()));
|
reportLines.add("Total number of blocks = " + String.format("%,d", results.mdCount.size()));
|
||||||
reportLines.addAll(sortedReport(total, results.mdCount));
|
reportLines.addAll(sortedReport(total, results.mdCount));
|
||||||
|
|
||||||
reportLines.add(
|
reportLines.add(
|
||||||
"Blocks not counted because they exceeded limits: " + String.format("%,d", results.ofCount.size()));
|
"Blocks not counted because they exceeded limits: " + String.format("%,d", results.ofCount.size()));
|
||||||
Iterable<Multiset.Entry<Material>> entriesSortedByCount = results.ofCount.entrySet();
|
Iterable<Multiset.Entry<Material>> entriesSortedByCount = results.ofCount.entrySet();
|
||||||
Iterator<Entry<Material>> it = entriesSortedByCount.iterator();
|
Iterator<Entry<Material>> it = entriesSortedByCount.iterator();
|
||||||
while (it.hasNext()) {
|
while (it.hasNext()) {
|
||||||
Entry<Material> type = it.next();
|
Entry<Material> type = it.next();
|
||||||
Integer limit = addon.getBlockConfig().getBlockLimits().get(type.getElement());
|
Integer limit = addon.getBlockConfig().getBlockLimits().get(type.getElement());
|
||||||
String explain = ")";
|
String explain = ")";
|
||||||
if (limit == null) {
|
if (limit == null) {
|
||||||
Material generic = type.getElement();
|
Material generic = type.getElement();
|
||||||
limit = addon.getBlockConfig().getBlockLimits().get(generic);
|
limit = addon.getBlockConfig().getBlockLimits().get(generic);
|
||||||
explain = " - All types)";
|
explain = " - All types)";
|
||||||
}
|
}
|
||||||
reportLines.add(type.getElement().toString() + ": " + String.format("%,d", type.getCount())
|
reportLines.add(type.getElement().toString() + ": " + String.format("%,d", type.getCount())
|
||||||
+ " blocks (max " + limit + explain);
|
+ " blocks (max " + limit + explain);
|
||||||
}
|
}
|
||||||
reportLines.add(LINE_BREAK);
|
reportLines.add(LINE_BREAK);
|
||||||
reportLines.add("Blocks on island that are not in config.yml");
|
reportLines.add("Blocks on island that are not in config.yml");
|
||||||
reportLines.add("Total number = " + String.format("%,d", results.ncCount.size()));
|
reportLines.add("Total number = " + String.format("%,d", results.ncCount.size()));
|
||||||
entriesSortedByCount = results.ncCount.entrySet();
|
entriesSortedByCount = results.ncCount.entrySet();
|
||||||
it = entriesSortedByCount.iterator();
|
it = entriesSortedByCount.iterator();
|
||||||
while (it.hasNext()) {
|
while (it.hasNext()) {
|
||||||
Entry<Material> type = it.next();
|
Entry<Material> type = it.next();
|
||||||
reportLines.add(type.getElement().toString() + ": " + String.format("%,d", type.getCount()) + " blocks");
|
reportLines.add(type.getElement().toString() + ": " + String.format("%,d", type.getCount()) + " blocks");
|
||||||
}
|
}
|
||||||
reportLines.add(LINE_BREAK);
|
reportLines.add(LINE_BREAK);
|
||||||
|
|
||||||
return reportLines;
|
return reportLines;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return the results
|
* @return the results
|
||||||
*/
|
*/
|
||||||
public Results getResults() {
|
public Results getResults() {
|
||||||
return results;
|
return results;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -268,13 +271,13 @@ public class IslandLevelCalculator {
|
|||||||
* @return value of a material
|
* @return value of a material
|
||||||
*/
|
*/
|
||||||
private int getValue(Material md) {
|
private int getValue(Material md) {
|
||||||
Integer value = addon.getBlockConfig().getValue(island.getWorld(), md);
|
Integer value = addon.getBlockConfig().getValue(island.getWorld(), md);
|
||||||
if (value == null) {
|
if (value == null) {
|
||||||
// Not in config
|
// Not in config
|
||||||
results.ncCount.add(md);
|
results.ncCount.add(md);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -286,44 +289,44 @@ public class IslandLevelCalculator {
|
|||||||
* there is no island nether
|
* there is no island nether
|
||||||
*/
|
*/
|
||||||
private CompletableFuture<List<Chunk>> getWorldChunk(Environment env, Queue<Pair<Integer, Integer>> pairList) {
|
private CompletableFuture<List<Chunk>> getWorldChunk(Environment env, Queue<Pair<Integer, Integer>> pairList) {
|
||||||
if (worlds.containsKey(env)) {
|
if (worlds.containsKey(env)) {
|
||||||
CompletableFuture<List<Chunk>> r2 = new CompletableFuture<>();
|
CompletableFuture<List<Chunk>> r2 = new CompletableFuture<>();
|
||||||
List<Chunk> chunkList = new ArrayList<>();
|
List<Chunk> chunkList = new ArrayList<>();
|
||||||
World world = worlds.get(env);
|
World world = worlds.get(env);
|
||||||
// Get the chunk, and then coincidentally check the RoseStacker
|
// Get the chunk, and then coincidentally check the RoseStacker
|
||||||
loadChunks(r2, world, pairList, chunkList);
|
loadChunks(r2, world, pairList, chunkList);
|
||||||
return r2;
|
return r2;
|
||||||
}
|
}
|
||||||
return CompletableFuture.completedFuture(Collections.emptyList());
|
return CompletableFuture.completedFuture(Collections.emptyList());
|
||||||
}
|
}
|
||||||
|
|
||||||
private void loadChunks(CompletableFuture<List<Chunk>> r2, World world, Queue<Pair<Integer, Integer>> pairList,
|
private void loadChunks(CompletableFuture<List<Chunk>> r2, World world, Queue<Pair<Integer, Integer>> pairList,
|
||||||
List<Chunk> chunkList) {
|
List<Chunk> chunkList) {
|
||||||
if (pairList.isEmpty()) {
|
if (pairList.isEmpty()) {
|
||||||
r2.complete(chunkList);
|
r2.complete(chunkList);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Pair<Integer, Integer> p = pairList.poll();
|
Pair<Integer, Integer> p = pairList.poll();
|
||||||
Util.getChunkAtAsync(world, p.x, p.z, world.getEnvironment().equals(Environment.NETHER)).thenAccept(chunk -> {
|
Util.getChunkAtAsync(world, p.x, p.z, world.getEnvironment().equals(Environment.NETHER)).thenAccept(chunk -> {
|
||||||
if (chunk != null) {
|
if (chunk != null) {
|
||||||
chunkList.add(chunk);
|
chunkList.add(chunk);
|
||||||
roseStackerCheck(chunk);
|
roseStackerCheck(chunk);
|
||||||
}
|
}
|
||||||
loadChunks(r2, world, pairList, chunkList); // Iteration
|
loadChunks(r2, world, pairList, chunkList); // Iteration
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private void roseStackerCheck(Chunk chunk) {
|
private void roseStackerCheck(Chunk chunk) {
|
||||||
if (addon.isRoseStackersEnabled()) {
|
if (addon.isRoseStackersEnabled()) {
|
||||||
RoseStackerAPI.getInstance().getStackedBlocks(Collections.singletonList(chunk)).forEach(e -> {
|
RoseStackerAPI.getInstance().getStackedBlocks(Collections.singletonList(chunk)).forEach(e -> {
|
||||||
// Blocks below sea level can be scored differently
|
// Blocks below sea level can be scored differently
|
||||||
boolean belowSeaLevel = seaHeight > 0 && e.getLocation().getY() <= seaHeight;
|
boolean belowSeaLevel = seaHeight > 0 && e.getLocation().getY() <= seaHeight;
|
||||||
// Check block once because the base block will be counted in the chunk snapshot
|
// Check block once because the base block will be counted in the chunk snapshot
|
||||||
for (int _x = 0; _x < e.getStackSize() - 1; _x++) {
|
for (int _x = 0; _x < e.getStackSize() - 1; _x++) {
|
||||||
checkBlock(e.getBlock().getType(), belowSeaLevel);
|
checkBlock(e.getBlock().getType(), belowSeaLevel);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -334,17 +337,17 @@ public class IslandLevelCalculator {
|
|||||||
* @return value of the block if can be counted
|
* @return value of the block if can be counted
|
||||||
*/
|
*/
|
||||||
private int limitCount(Material md) {
|
private int limitCount(Material md) {
|
||||||
if (limitCount.containsKey(md)) {
|
if (limitCount.containsKey(md)) {
|
||||||
int count = limitCount.get(md);
|
int count = limitCount.get(md);
|
||||||
if (count > 0) {
|
if (count > 0) {
|
||||||
limitCount.put(md, --count);
|
limitCount.put(md, --count);
|
||||||
return getValue(md);
|
return getValue(md);
|
||||||
} else {
|
} else {
|
||||||
results.ofCount.add(md);
|
results.ofCount.add(md);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return getValue(md);
|
return getValue(md);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -353,39 +356,39 @@ public class IslandLevelCalculator {
|
|||||||
* @param chunk - the chunk to scan
|
* @param chunk - the chunk to scan
|
||||||
*/
|
*/
|
||||||
private void scanChests(Chunk chunk) {
|
private void scanChests(Chunk chunk) {
|
||||||
// Count blocks in chests
|
// Count blocks in chests
|
||||||
for (BlockState bs : chunk.getTileEntities()) {
|
for (BlockState bs : chunk.getTileEntities()) {
|
||||||
if (bs instanceof Container container) {
|
if (bs instanceof Container container) {
|
||||||
if (addon.isAdvChestEnabled()) {
|
if (addon.isAdvChestEnabled()) {
|
||||||
AdvancedChest<?, ?> aChest = AdvancedChestsAPI.getChestManager().getAdvancedChest(bs.getLocation());
|
AdvancedChest<?, ?> aChest = AdvancedChestsAPI.getChestManager().getAdvancedChest(bs.getLocation());
|
||||||
if (aChest != null && aChest.getChestType().getName().equals("NORMAL")) {
|
if (aChest != null && aChest.getChestType().getName().equals("NORMAL")) {
|
||||||
aChest.getPages().stream().map(ChestPage::getItems).forEach(c -> {
|
aChest.getPages().stream().map(ChestPage::getItems).forEach(c -> {
|
||||||
for (Object i : c) {
|
for (Object i : c) {
|
||||||
countItemStack((ItemStack) i);
|
countItemStack((ItemStack) i);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Regular chest
|
// Regular chest
|
||||||
container.getSnapshotInventory().forEach(this::countItemStack);
|
container.getSnapshotInventory().forEach(this::countItemStack);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void countItemStack(ItemStack i) {
|
private void countItemStack(ItemStack i) {
|
||||||
if (i == null || !i.getType().isBlock())
|
if (i == null || !i.getType().isBlock())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
for (int c = 0; c < i.getAmount(); c++) {
|
for (int c = 0; c < i.getAmount(); c++) {
|
||||||
if (addon.getSettings().isIncludeShulkersInChest()
|
if (addon.getSettings().isIncludeShulkersInChest()
|
||||||
&& i.getItemMeta() instanceof BlockStateMeta blockStateMeta
|
&& i.getItemMeta() instanceof BlockStateMeta blockStateMeta
|
||||||
&& blockStateMeta.getBlockState() instanceof ShulkerBox shulkerBox) {
|
&& blockStateMeta.getBlockState() instanceof ShulkerBox shulkerBox) {
|
||||||
shulkerBox.getSnapshotInventory().forEach(this::countItemStack);
|
shulkerBox.getSnapshotInventory().forEach(this::countItemStack);
|
||||||
}
|
}
|
||||||
|
|
||||||
checkBlock(i.getType(), false);
|
checkBlock(i.getType(), false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -398,26 +401,26 @@ public class IslandLevelCalculator {
|
|||||||
* that will be true if the scan was successful, false if not
|
* that will be true if the scan was successful, false if not
|
||||||
*/
|
*/
|
||||||
private CompletableFuture<Boolean> scanChunk(List<Chunk> chunks) {
|
private CompletableFuture<Boolean> scanChunk(List<Chunk> chunks) {
|
||||||
// If the chunk hasn't been generated, return
|
// If the chunk hasn't been generated, return
|
||||||
if (chunks == null || chunks.isEmpty()) {
|
if (chunks == null || chunks.isEmpty()) {
|
||||||
return CompletableFuture.completedFuture(false);
|
return CompletableFuture.completedFuture(false);
|
||||||
}
|
}
|
||||||
// Count blocks in chunk
|
// Count blocks in chunk
|
||||||
CompletableFuture<Boolean> result = new CompletableFuture<>();
|
CompletableFuture<Boolean> result = new CompletableFuture<>();
|
||||||
/*
|
/*
|
||||||
* At this point, we need to grab a snapshot of each chunk and then scan it
|
* At this point, we need to grab a snapshot of each chunk and then scan it
|
||||||
* async. At the end, we make the CompletableFuture true to show it is done. I'm
|
* async. At the end, we make the CompletableFuture true to show it is done. I'm
|
||||||
* not sure how much lag this will cause, but as all the chunks are loaded,
|
* not sure how much lag this will cause, but as all the chunks are loaded,
|
||||||
* maybe not that much.
|
* maybe not that much.
|
||||||
*/
|
*/
|
||||||
List<ChunkPair> preLoad = chunks.stream().map(c -> new ChunkPair(c.getWorld(), c, c.getChunkSnapshot()))
|
List<ChunkPair> preLoad = chunks.stream().map(c -> new ChunkPair(c.getWorld(), c, c.getChunkSnapshot()))
|
||||||
.toList();
|
.toList();
|
||||||
Bukkit.getScheduler().runTaskAsynchronously(BentoBox.getInstance(), () -> {
|
Bukkit.getScheduler().runTaskAsynchronously(BentoBox.getInstance(), () -> {
|
||||||
preLoad.forEach(this::scanAsync);
|
preLoad.forEach(this::scanAsync);
|
||||||
// Once they are all done, return to the main thread.
|
// Once they are all done, return to the main thread.
|
||||||
Bukkit.getScheduler().runTask(addon.getPlugin(), () -> result.complete(true));
|
Bukkit.getScheduler().runTask(addon.getPlugin(), () -> result.complete(true));
|
||||||
});
|
});
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
record ChunkPair(World world, Chunk chunk, ChunkSnapshot chunkSnapshot) {
|
record ChunkPair(World world, Chunk chunk, ChunkSnapshot chunkSnapshot) {
|
||||||
@ -429,53 +432,67 @@ public class IslandLevelCalculator {
|
|||||||
* @param cp chunk to scan
|
* @param cp chunk to scan
|
||||||
*/
|
*/
|
||||||
private void scanAsync(ChunkPair cp) {
|
private void scanAsync(ChunkPair cp) {
|
||||||
for (int x = 0; x < 16; x++) {
|
for (int x = 0; x < 16; x++) {
|
||||||
// Check if the block coordinate is inside the protection zone and if not, don't
|
// Check if the block coordinate is inside the protection zone and if not, don't
|
||||||
// count it
|
// count it
|
||||||
if (cp.chunkSnapshot.getX() * 16 + x < island.getMinProtectedX() || cp.chunkSnapshot.getX() * 16
|
if (cp.chunkSnapshot.getX() * 16 + x < island.getMinProtectedX() || cp.chunkSnapshot.getX() * 16
|
||||||
+ x >= island.getMinProtectedX() + island.getProtectionRange() * 2) {
|
+ x >= island.getMinProtectedX() + island.getProtectionRange() * 2) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
for (int z = 0; z < 16; z++) {
|
for (int z = 0; z < 16; z++) {
|
||||||
// Check if the block coordinate is inside the protection zone and if not, don't
|
// Check if the block coordinate is inside the protection zone and if not, don't
|
||||||
// count it
|
// count it
|
||||||
if (cp.chunkSnapshot.getZ() * 16 + z < island.getMinProtectedZ() || cp.chunkSnapshot.getZ() * 16
|
if (cp.chunkSnapshot.getZ() * 16 + z < island.getMinProtectedZ() || cp.chunkSnapshot.getZ() * 16
|
||||||
+ z >= island.getMinProtectedZ() + island.getProtectionRange() * 2) {
|
+ z >= island.getMinProtectedZ() + island.getProtectionRange() * 2) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
// 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));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (addon.isUltimateStackerEnabled() && !m.isAir()) {
|
Block block = cp.chunk.getBlock(x, y, z);
|
||||||
Location l = new Location(cp.chunk.getWorld(), x, y, z);
|
|
||||||
UltimateStackerCalc.addStackers(m, l, results, belowSeaLevel, limitCount(m));
|
|
||||||
}
|
|
||||||
|
|
||||||
// Scan chests
|
if (addon.isUltimateStackerEnabled()) {
|
||||||
if (addon.getSettings().isIncludeChests() && CHESTS.contains(m)) {
|
if (!blockData.getMaterial().equals(Material.AIR)) {
|
||||||
chestBlocks.add(cp.chunk);
|
BlockStack stack = UltimateStacker.getInstance().getBlockStackManager().getBlock(block,
|
||||||
}
|
CompatibleMaterial.getMaterial(block));
|
||||||
// Add the value of the block's material
|
if (stack != null) {
|
||||||
checkBlock(m, belowSeaLevel);
|
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
|
||||||
|
if (addon.getSettings().isIncludeChests() && CHESTS.contains(blockData.getMaterial())) {
|
||||||
|
chestBlocks.add(cp.chunk);
|
||||||
|
}
|
||||||
|
// Add the value of the block's material
|
||||||
|
checkBlock(blockData.getMaterial(), belowSeaLevel);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -485,175 +502,180 @@ public class IslandLevelCalculator {
|
|||||||
* to be scanned, and false if not
|
* to be scanned, and false if not
|
||||||
*/
|
*/
|
||||||
public CompletableFuture<Boolean> scanNextChunk() {
|
public CompletableFuture<Boolean> scanNextChunk() {
|
||||||
if (chunksToCheck.isEmpty()) {
|
if (chunksToCheck.isEmpty()) {
|
||||||
addon.logError("Unexpected: no chunks to scan!");
|
addon.logError("Unexpected: no chunks to scan!");
|
||||||
// This should not be needed, but just in case
|
// This should not be needed, but just in case
|
||||||
return CompletableFuture.completedFuture(false);
|
return CompletableFuture.completedFuture(false);
|
||||||
}
|
}
|
||||||
// Retrieve and remove from the queue
|
// Retrieve and remove from the queue
|
||||||
Queue<Pair<Integer, Integer>> pairList = new ConcurrentLinkedQueue<>();
|
Queue<Pair<Integer, Integer>> pairList = new ConcurrentLinkedQueue<>();
|
||||||
int i = 0;
|
int i = 0;
|
||||||
while (!chunksToCheck.isEmpty() && i++ < CHUNKS_TO_SCAN) {
|
while (!chunksToCheck.isEmpty() && i++ < CHUNKS_TO_SCAN) {
|
||||||
pairList.add(chunksToCheck.poll());
|
pairList.add(chunksToCheck.poll());
|
||||||
}
|
}
|
||||||
Queue<Pair<Integer, Integer>> endPairList = new ConcurrentLinkedQueue<>(pairList);
|
Queue<Pair<Integer, Integer>> endPairList = new ConcurrentLinkedQueue<>(pairList);
|
||||||
Queue<Pair<Integer, Integer>> netherPairList = new ConcurrentLinkedQueue<>(pairList);
|
Queue<Pair<Integer, Integer>> netherPairList = new ConcurrentLinkedQueue<>(pairList);
|
||||||
// Set up the result
|
// Set up the result
|
||||||
CompletableFuture<Boolean> result = new CompletableFuture<>();
|
CompletableFuture<Boolean> result = new CompletableFuture<>();
|
||||||
// Get chunks and scan
|
// Get chunks and scan
|
||||||
// Get chunks and scan
|
// Get chunks and scan
|
||||||
getWorldChunk(Environment.THE_END, endPairList).thenAccept(
|
getWorldChunk(Environment.THE_END, endPairList).thenAccept(
|
||||||
endChunks -> scanChunk(endChunks).thenAccept(b -> getWorldChunk(Environment.NETHER, netherPairList)
|
endChunks -> scanChunk(endChunks).thenAccept(b -> getWorldChunk(Environment.NETHER, netherPairList)
|
||||||
.thenAccept(netherChunks -> scanChunk(netherChunks)
|
.thenAccept(netherChunks -> scanChunk(netherChunks)
|
||||||
.thenAccept(b2 -> getWorldChunk(Environment.NORMAL, pairList)
|
.thenAccept(b2 -> getWorldChunk(Environment.NORMAL, pairList)
|
||||||
.thenAccept(normalChunks -> scanChunk(normalChunks).thenAccept(b3 ->
|
.thenAccept(normalChunks -> scanChunk(normalChunks).thenAccept(b3 ->
|
||||||
// Complete the result now that all chunks have been scanned
|
// Complete the result now that all chunks have been scanned
|
||||||
result.complete(!chunksToCheck.isEmpty())))))));
|
result.complete(!chunksToCheck.isEmpty())))))));
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
private Collection<String> sortedReport(int total, Multiset<Material> materialCount) {
|
private Collection<String> sortedReport(int total, Multiset<Material> materialCount) {
|
||||||
Collection<String> result = new ArrayList<>();
|
Collection<String> result = new ArrayList<>();
|
||||||
Iterable<Multiset.Entry<Material>> entriesSortedByCount = Multisets.copyHighestCountFirst(materialCount)
|
Iterable<Multiset.Entry<Material>> entriesSortedByCount = Multisets.copyHighestCountFirst(materialCount)
|
||||||
.entrySet();
|
.entrySet();
|
||||||
for (Entry<Material> en : entriesSortedByCount) {
|
for (Entry<Material> en : entriesSortedByCount) {
|
||||||
Material type = en.getElement();
|
Material type = en.getElement();
|
||||||
|
|
||||||
int value = getValue(type);
|
int value = getValue(type);
|
||||||
|
|
||||||
result.add(type.toString() + ":" + String.format("%,d", en.getCount()) + " blocks x " + value + " = "
|
result.add(type.toString() + ":" + String.format("%,d", en.getCount()) + " blocks x " + value + " = "
|
||||||
+ (value * en.getCount()));
|
+ (value * en.getCount()));
|
||||||
total += (value * en.getCount());
|
total += (value * en.getCount());
|
||||||
|
|
||||||
}
|
}
|
||||||
result.add("Subtotal = " + total);
|
result.add("Subtotal = " + total);
|
||||||
result.add(LINE_BREAK);
|
result.add(LINE_BREAK);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Finalizes the calculations and makes the report
|
* Finalizes the calculations and makes the report
|
||||||
*/
|
*/
|
||||||
public void tidyUp() {
|
public void tidyUp() {
|
||||||
// Finalize calculations
|
// Finalize calculations
|
||||||
results.rawBlockCount
|
results.rawBlockCount
|
||||||
.addAndGet((long) (results.underWaterBlockCount.get() * addon.getSettings().getUnderWaterMultiplier()));
|
.addAndGet((long) (results.underWaterBlockCount.get() * addon.getSettings().getUnderWaterMultiplier()));
|
||||||
|
|
||||||
// Set the death penalty
|
// Set the death penalty
|
||||||
if (this.addon.getSettings().isSumTeamDeaths()) {
|
if (this.addon.getSettings().isSumTeamDeaths()) {
|
||||||
for (UUID uuid : this.island.getMemberSet()) {
|
for (UUID uuid : this.island.getMemberSet()) {
|
||||||
this.results.deathHandicap.addAndGet(this.addon.getPlayers().getDeaths(island.getWorld(), uuid));
|
this.results.deathHandicap.addAndGet(this.addon.getPlayers().getDeaths(island.getWorld(), uuid));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// At this point, it may be that the island has become unowned.
|
// At this point, it may be that the island has become unowned.
|
||||||
this.results.deathHandicap.set(this.island.getOwner() == null ? 0
|
this.results.deathHandicap.set(this.island.getOwner() == null ? 0
|
||||||
: this.addon.getPlayers().getDeaths(island.getWorld(), this.island.getOwner()));
|
: this.addon.getPlayers().getDeaths(island.getWorld(), this.island.getOwner()));
|
||||||
}
|
}
|
||||||
|
|
||||||
long blockAndDeathPoints = this.results.rawBlockCount.get();
|
long blockAndDeathPoints = this.results.rawBlockCount.get();
|
||||||
this.results.totalPoints.set(blockAndDeathPoints);
|
this.results.totalPoints.set(blockAndDeathPoints);
|
||||||
|
|
||||||
if (this.addon.getSettings().getDeathPenalty() > 0) {
|
if (this.addon.getSettings().getDeathPenalty() > 0) {
|
||||||
// Proper death penalty calculation.
|
// Proper death penalty calculation.
|
||||||
blockAndDeathPoints -= this.results.deathHandicap.get() * this.addon.getSettings().getDeathPenalty();
|
blockAndDeathPoints -= this.results.deathHandicap.get() * this.addon.getSettings().getDeathPenalty();
|
||||||
}
|
}
|
||||||
this.results.level.set(calculateLevel(blockAndDeathPoints));
|
this.results.level.set(calculateLevel(blockAndDeathPoints));
|
||||||
|
|
||||||
// Calculate how many points are required to get to the next level
|
// Calculate how many points are required to get to the next level
|
||||||
long nextLevel = this.results.level.get();
|
long nextLevel = this.results.level.get();
|
||||||
long blocks = blockAndDeathPoints;
|
long blocks = blockAndDeathPoints;
|
||||||
while (nextLevel < this.results.level.get() + 1 && blocks - blockAndDeathPoints < MAX_AMOUNT) {
|
while (nextLevel < this.results.level.get() + 1 && blocks - blockAndDeathPoints < MAX_AMOUNT) {
|
||||||
nextLevel = calculateLevel(++blocks);
|
nextLevel = calculateLevel(++blocks);
|
||||||
}
|
}
|
||||||
this.results.pointsToNextLevel.set(blocks - blockAndDeathPoints);
|
this.results.pointsToNextLevel.set(blocks - blockAndDeathPoints);
|
||||||
|
|
||||||
// Report
|
// Report
|
||||||
results.report = getReport();
|
results.report = getReport();
|
||||||
// Set the duration
|
// Set the duration
|
||||||
addon.getPipeliner().setTime(System.currentTimeMillis() - duration);
|
addon.getPipeliner().setTime(System.currentTimeMillis() - duration);
|
||||||
// All done.
|
// All done.
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return the zeroIsland
|
* @return the zeroIsland
|
||||||
*/
|
*/
|
||||||
boolean isNotZeroIsland() {
|
boolean isNotZeroIsland() {
|
||||||
return !zeroIsland;
|
return !zeroIsland;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void scanIsland(Pipeliner pipeliner) {
|
public void scanIsland(Pipeliner pipeliner) {
|
||||||
// Scan the next chunk
|
// Scan the next chunk
|
||||||
scanNextChunk().thenAccept(result -> {
|
scanNextChunk().thenAccept(result -> {
|
||||||
if (!Bukkit.isPrimaryThread()) {
|
if (!Bukkit.isPrimaryThread()) {
|
||||||
addon.getPlugin().logError("scanChunk not on Primary Thread!");
|
addon.getPlugin().logError("scanChunk not on Primary Thread!");
|
||||||
}
|
}
|
||||||
// Timeout check
|
// Timeout check
|
||||||
if (System.currentTimeMillis()
|
if (System.currentTimeMillis()
|
||||||
- pipeliner.getInProcessQueue().get(this) > addon.getSettings().getCalculationTimeout() * 60000) {
|
- pipeliner.getInProcessQueue().get(this) > addon.getSettings().getCalculationTimeout() * 60000) {
|
||||||
// Done
|
// Done
|
||||||
pipeliner.getInProcessQueue().remove(this);
|
pipeliner.getInProcessQueue().remove(this);
|
||||||
getR().complete(new Results(Result.TIMEOUT));
|
getR().complete(new Results(Result.TIMEOUT));
|
||||||
addon.logError("Level calculation timed out after " + addon.getSettings().getCalculationTimeout()
|
addon.logError("Level calculation timed out after " + addon.getSettings().getCalculationTimeout()
|
||||||
+ "m for island: " + getIsland());
|
+ "m for island: " + getIsland());
|
||||||
if (!isNotZeroIsland()) {
|
if (!isNotZeroIsland()) {
|
||||||
addon.logError("Island level was being zeroed.");
|
addon.logError("Island level was being zeroed.");
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (Boolean.TRUE.equals(result) && !pipeliner.getTask().isCancelled()) {
|
if (Boolean.TRUE.equals(result) && !pipeliner.getTask().isCancelled()) {
|
||||||
// scanNextChunk returns true if there are more chunks to scan
|
// scanNextChunk returns true if there are more chunks to scan
|
||||||
scanIsland(pipeliner);
|
scanIsland(pipeliner);
|
||||||
} else {
|
} else {
|
||||||
// Done
|
// Done
|
||||||
pipeliner.getInProcessQueue().remove(this);
|
pipeliner.getInProcessQueue().remove(this);
|
||||||
// Chunk finished
|
// Chunk finished
|
||||||
// This was the last chunk. Handle stacked blocks, then chests and exit
|
// This was the last chunk
|
||||||
handleStackedBlocks().thenCompose(v -> handleChests()).thenRun(() -> {
|
handleStackedBlocks();
|
||||||
this.tidyUp();
|
handleChests();
|
||||||
this.getR().complete(getResults());
|
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.tidyUp();
|
||||||
|
this.getR().complete(getResults());
|
||||||
|
finishTask.cancel();
|
||||||
|
}
|
||||||
|
}, 0, 10L);
|
||||||
|
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private CompletableFuture<Void> handleChests() {
|
private void handleChests() {
|
||||||
List<CompletableFuture<Void>> futures = new ArrayList<>();
|
Iterator<Chunk> it = chestBlocks.iterator();
|
||||||
for (Chunk v : chestBlocks) {
|
while (it.hasNext()) {
|
||||||
CompletableFuture<Void> future = Util.getChunkAtAsync(v.getWorld(), v.getX(), v.getZ()).thenAccept(c -> {
|
Chunk v = it.next();
|
||||||
scanChests(c);
|
Util.getChunkAtAsync(v.getWorld(), v.getX(), v.getZ()).thenAccept(c -> {
|
||||||
});
|
scanChests(c);
|
||||||
futures.add(future);
|
it.remove();
|
||||||
}
|
});
|
||||||
// Return a CompletableFuture that completes when all futures are done
|
}
|
||||||
return CompletableFuture.allOf(futures.toArray(new CompletableFuture[0]));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private CompletableFuture<Void> handleStackedBlocks() {
|
private void handleStackedBlocks() {
|
||||||
// Deal with any stacked blocks
|
// Deal with any stacked blocks
|
||||||
List<CompletableFuture<Void>> futures = new ArrayList<>();
|
Iterator<Location> it = stackedBlocks.iterator();
|
||||||
for (Location v : stackedBlocks) {
|
while (it.hasNext()) {
|
||||||
CompletableFuture<Void> future = Util.getChunkAtAsync(v).thenAccept(c -> {
|
Location v = it.next();
|
||||||
Block stackedBlock = v.getBlock();
|
Util.getChunkAtAsync(v).thenAccept(c -> {
|
||||||
boolean belowSeaLevel = seaHeight > 0 && v.getBlockY() <= seaHeight;
|
Block stackedBlock = v.getBlock();
|
||||||
if (WildStackerAPI.getWildStacker().getSystemManager().isStackedBarrel(stackedBlock)) {
|
boolean belowSeaLevel = seaHeight > 0 && v.getBlockY() <= seaHeight;
|
||||||
StackedBarrel barrel = WildStackerAPI.getStackedBarrel(stackedBlock);
|
if (WildStackerAPI.getWildStacker().getSystemManager().isStackedBarrel(stackedBlock)) {
|
||||||
int barrelAmt = WildStackerAPI.getBarrelAmount(stackedBlock);
|
StackedBarrel barrel = WildStackerAPI.getStackedBarrel(stackedBlock);
|
||||||
for (int _x = 0; _x < barrelAmt; _x++) {
|
int barrelAmt = WildStackerAPI.getBarrelAmount(stackedBlock);
|
||||||
checkBlock(barrel.getType(), belowSeaLevel);
|
for (int _x = 0; _x < barrelAmt; _x++) {
|
||||||
}
|
checkBlock(barrel.getType(), belowSeaLevel);
|
||||||
} else if (WildStackerAPI.getWildStacker().getSystemManager().isStackedSpawner(stackedBlock)) {
|
}
|
||||||
int spawnerAmt = WildStackerAPI.getSpawnersAmount((CreatureSpawner) stackedBlock.getState());
|
} else if (WildStackerAPI.getWildStacker().getSystemManager().isStackedSpawner(stackedBlock)) {
|
||||||
for (int _x = 0; _x < spawnerAmt; _x++) {
|
int spawnerAmt = WildStackerAPI.getSpawnersAmount((CreatureSpawner) stackedBlock.getState());
|
||||||
checkBlock(stackedBlock.getType(), belowSeaLevel);
|
for (int _x = 0; _x < spawnerAmt; _x++) {
|
||||||
}
|
checkBlock(stackedBlock.getType(), belowSeaLevel);
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
futures.add(future);
|
it.remove();
|
||||||
}
|
});
|
||||||
// Return a CompletableFuture that completes when all futures are done
|
}
|
||||||
return CompletableFuture.allOf(futures.toArray(new CompletableFuture[0]));
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,29 +0,0 @@
|
|||||||
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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -46,20 +46,10 @@ public class AdminSetInitialLevelCommand extends CompositeCommand {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean execute(User user, String label, List<String> args) {
|
public boolean execute(User user, String label, List<String> args) {
|
||||||
long initialLevel = addon.getManager().getInitialLevel(island);
|
String initialLevel = String.valueOf(addon.getManager().getInitialLevel(island));
|
||||||
long lv = 0;
|
long lv = Long.parseLong(args.get(1));
|
||||||
if (args.get(1).startsWith("+")) {
|
|
||||||
String change = args.get(1).substring(1);
|
|
||||||
lv = initialLevel + Long.parseLong(change);
|
|
||||||
} else if (args.get(1).startsWith("-")) {
|
|
||||||
String change = args.get(1).substring(1);
|
|
||||||
lv = initialLevel - Long.parseLong(change);
|
|
||||||
} else {
|
|
||||||
lv = Long.parseLong(args.get(1));
|
|
||||||
}
|
|
||||||
addon.getManager().setInitialIslandLevel(island, lv);
|
addon.getManager().setInitialIslandLevel(island, lv);
|
||||||
user.sendMessage("admin.level.sethandicap.changed", TextVariables.NUMBER, String.valueOf(initialLevel),
|
user.sendMessage("admin.level.sethandicap.changed", TextVariables.NUMBER, initialLevel, "[new_number]", String.valueOf(lv));
|
||||||
"[new_number]", String.valueOf(lv));
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -74,20 +64,10 @@ public class AdminSetInitialLevelCommand extends CompositeCommand {
|
|||||||
user.sendMessage("general.errors.unknown-player", TextVariables.NAME, args.get(0));
|
user.sendMessage("general.errors.unknown-player", TextVariables.NAME, args.get(0));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
// Check if this is a add or remove
|
// Check value
|
||||||
if (args.get(1).startsWith("+") || args.get(1).startsWith("-")) {
|
if (!Util.isInteger(args.get(1), true)) {
|
||||||
String change = args.get(1).substring(1);
|
user.sendMessage("admin.level.sethandicap.invalid-level");
|
||||||
if (!Util.isInteger(change, true)) {
|
return false;
|
||||||
user.sendMessage("admin.level.sethandicap.invalid-level");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
// Value is okay
|
|
||||||
} else {
|
|
||||||
// Check value
|
|
||||||
if (!Util.isInteger(args.get(1), true)) {
|
|
||||||
user.sendMessage("admin.level.sethandicap.invalid-level");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
// Check island
|
// Check island
|
||||||
island = getAddon().getIslands().getIsland(getWorld(), targetUUID);
|
island = getAddon().getIslands().getIsland(getWorld(), targetUUID);
|
||||||
|
@ -111,11 +111,7 @@ 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",
|
user.sendMessage("island.level.required-points-to-next-level", "[points]", String.valueOf(results.getPointsToNextLevel()));
|
||||||
"[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) {
|
||||||
|
@ -8,14 +8,11 @@ import java.util.Optional;
|
|||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.inventory.PlayerInventory;
|
import org.bukkit.inventory.PlayerInventory;
|
||||||
import org.eclipse.jdt.annotation.NonNull;
|
|
||||||
|
|
||||||
import world.bentobox.bentobox.api.commands.CompositeCommand;
|
import world.bentobox.bentobox.api.commands.CompositeCommand;
|
||||||
import world.bentobox.bentobox.api.localization.TextVariables;
|
|
||||||
import world.bentobox.bentobox.api.user.User;
|
import world.bentobox.bentobox.api.user.User;
|
||||||
import world.bentobox.bentobox.util.Util;
|
import world.bentobox.bentobox.util.Util;
|
||||||
import world.bentobox.level.Level;
|
import world.bentobox.level.Level;
|
||||||
import world.bentobox.level.objects.IslandLevels;
|
|
||||||
import world.bentobox.level.panels.ValuePanel;
|
import world.bentobox.level.panels.ValuePanel;
|
||||||
import world.bentobox.level.util.Utils;
|
import world.bentobox.level.util.Utils;
|
||||||
|
|
||||||
@ -115,19 +112,6 @@ public class IslandValueCommand extends CompositeCommand
|
|||||||
"[value]", (underWater * value) + ""),
|
"[value]", (underWater * value) + ""),
|
||||||
MATERIAL, Utils.prettifyObject(material, user));
|
MATERIAL, Utils.prettifyObject(material, user));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Show how many have been placed and how many are allowed
|
|
||||||
@NonNull
|
|
||||||
IslandLevels lvData = this.addon.getManager()
|
|
||||||
.getLevelsData(getIslands().getPrimaryIsland(getWorld(), user.getUniqueId()));
|
|
||||||
int count = lvData.getMdCount().getOrDefault(material, 0) + lvData.getUwCount().getOrDefault(material, 0);
|
|
||||||
user.sendMessage("level.conversations.you-have", TextVariables.NUMBER,
|
|
||||||
String.valueOf(count));
|
|
||||||
int limit = this.addon.getBlockConfig().getBlockLimits().getOrDefault(material, -1);
|
|
||||||
if (limit > 0) {
|
|
||||||
user.sendMessage("level.conversations.you-can-place", TextVariables.NUMBER,
|
|
||||||
String.valueOf(limit));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -2,12 +2,9 @@ package world.bentobox.level.config;
|
|||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.EnumMap;
|
import java.util.EnumMap;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
|
||||||
import java.util.Locale;
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
|
||||||
@ -29,7 +26,6 @@ public class BlockConfig {
|
|||||||
private Map<Material, Integer> blockLimits = new EnumMap<>(Material.class);
|
private Map<Material, Integer> blockLimits = new EnumMap<>(Material.class);
|
||||||
private Map<Material, Integer> blockValues = new EnumMap<>(Material.class);
|
private Map<Material, Integer> blockValues = new EnumMap<>(Material.class);
|
||||||
private final Map<World, Map<Material, Integer>> worldBlockValues = new HashMap<>();
|
private final Map<World, Map<Material, Integer>> worldBlockValues = new HashMap<>();
|
||||||
private final List<Material> hiddenBlocks;
|
|
||||||
private Level addon;
|
private Level addon;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -53,16 +49,6 @@ public class BlockConfig {
|
|||||||
if (blockValues.isConfigurationSection("worlds")) {
|
if (blockValues.isConfigurationSection("worlds")) {
|
||||||
loadWorlds(blockValues);
|
loadWorlds(blockValues);
|
||||||
}
|
}
|
||||||
// Hidden
|
|
||||||
hiddenBlocks = blockValues.getStringList("hidden-blocks").stream().map(name -> {
|
|
||||||
try {
|
|
||||||
return Material.valueOf(name.toUpperCase(Locale.ENGLISH));
|
|
||||||
|
|
||||||
} catch (Exception e) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}).filter(Objects::nonNull).toList();
|
|
||||||
|
|
||||||
// All done
|
// All done
|
||||||
blockValues.save(file);
|
blockValues.save(file);
|
||||||
}
|
}
|
||||||
@ -173,22 +159,5 @@ public class BlockConfig {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Return true if the block should be hidden
|
|
||||||
* @param m block material
|
|
||||||
* @return true if hidden
|
|
||||||
*/
|
|
||||||
public boolean isHiddenBlock(Material m) {
|
|
||||||
return hiddenBlocks.contains(m);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Return true if the block should not be hidden
|
|
||||||
* @param m block material
|
|
||||||
* @return false if hidden
|
|
||||||
*/
|
|
||||||
public boolean isNotHiddenBlock(Material m) {
|
|
||||||
return !hiddenBlocks.contains(m);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -3,7 +3,6 @@ package world.bentobox.level.config;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Objects;
|
|
||||||
|
|
||||||
import world.bentobox.bentobox.BentoBox;
|
import world.bentobox.bentobox.BentoBox;
|
||||||
import world.bentobox.bentobox.api.configuration.ConfigComment;
|
import world.bentobox.bentobox.api.configuration.ConfigComment;
|
||||||
@ -121,17 +120,6 @@ public class ConfigSettings implements ConfigObject {
|
|||||||
@ConfigComment("Shows large level values rounded down, e.g., 10,345 -> 10k")
|
@ConfigComment("Shows large level values rounded down, e.g., 10,345 -> 10k")
|
||||||
@ConfigEntry(path = "shorthand")
|
@ConfigEntry(path = "shorthand")
|
||||||
private boolean shorthand = false;
|
private boolean shorthand = false;
|
||||||
|
|
||||||
@ConfigComment("Shorthand units")
|
|
||||||
@ConfigEntry(path = "units.kilo")
|
|
||||||
private String kilo = "k";
|
|
||||||
@ConfigEntry(path = "units.mega")
|
|
||||||
private String mega = "M";
|
|
||||||
@ConfigEntry(path = "units.giga")
|
|
||||||
private String giga = "G";
|
|
||||||
@ConfigEntry(path = "units.tera")
|
|
||||||
private String tera = "T";
|
|
||||||
|
|
||||||
@ConfigComment("")
|
@ConfigComment("")
|
||||||
@ConfigComment("Include Shulker Box content in chests in level calculations.")
|
@ConfigComment("Include Shulker Box content in chests in level calculations.")
|
||||||
@ConfigComment("Will count blocks in Shulker Boxes inside of chests.")
|
@ConfigComment("Will count blocks in Shulker Boxes inside of chests.")
|
||||||
@ -431,60 +419,4 @@ public class ConfigSettings implements ConfigObject {
|
|||||||
public void setDisabledPluginHooks(List<String> disabledPluginHooks) {
|
public void setDisabledPluginHooks(List<String> disabledPluginHooks) {
|
||||||
this.disabledPluginHooks = disabledPluginHooks;
|
this.disabledPluginHooks = disabledPluginHooks;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @return the kilo
|
|
||||||
*/
|
|
||||||
public String getKilo() {
|
|
||||||
return Objects.requireNonNullElse(kilo, "k");
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param kilo the kilo to set
|
|
||||||
*/
|
|
||||||
public void setKilo(String kilo) {
|
|
||||||
this.kilo = kilo;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return the mega
|
|
||||||
*/
|
|
||||||
public String getMega() {
|
|
||||||
return Objects.requireNonNullElse(mega, "M");
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param mega the mega to set
|
|
||||||
*/
|
|
||||||
public void setMega(String mega) {
|
|
||||||
this.mega = mega;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return the giga
|
|
||||||
*/
|
|
||||||
public String getGiga() {
|
|
||||||
return Objects.requireNonNullElse(giga, "G");
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param giga the giga to set
|
|
||||||
*/
|
|
||||||
public void setGiga(String giga) {
|
|
||||||
this.giga = giga;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return the tera
|
|
||||||
*/
|
|
||||||
public String getTera() {
|
|
||||||
return Objects.requireNonNullElse(tera, "T");
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param tera the tera to set
|
|
||||||
*/
|
|
||||||
public void setTera(String tera) {
|
|
||||||
this.tera = tera;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -62,7 +62,7 @@ public class IslandLevels implements DataObject {
|
|||||||
private Map<Material, Integer> uwCount;
|
private Map<Material, Integer> uwCount;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* MaterialData count - count of all blocks excluding under water
|
* MaterialData count - count of all blocks
|
||||||
*/
|
*/
|
||||||
@Expose
|
@Expose
|
||||||
private Map<Material, Integer> mdCount;
|
private Map<Material, Integer> mdCount;
|
||||||
@ -162,7 +162,6 @@ public class IslandLevels implements DataObject {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The count of underwater blocks
|
|
||||||
* @return the uwCount
|
* @return the uwCount
|
||||||
*/
|
*/
|
||||||
public Map<Material, Integer> getUwCount() {
|
public Map<Material, Integer> getUwCount() {
|
||||||
@ -170,7 +169,6 @@ public class IslandLevels implements DataObject {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Underwater blocks
|
|
||||||
* @param uwCount the uwCount to set
|
* @param uwCount the uwCount to set
|
||||||
*/
|
*/
|
||||||
public void setUwCount(Map<Material, Integer> uwCount) {
|
public void setUwCount(Map<Material, Integer> uwCount) {
|
||||||
@ -178,7 +176,6 @@ public class IslandLevels implements DataObject {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* All blocks count except for underwater blocks
|
|
||||||
* @return the mdCount
|
* @return the mdCount
|
||||||
*/
|
*/
|
||||||
public Map<Material, Integer> getMdCount() {
|
public Map<Material, Integer> getMdCount() {
|
||||||
@ -186,7 +183,6 @@ public class IslandLevels implements DataObject {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* All blocks except for underwater blocks
|
|
||||||
* @param mdCount the mdCount to set
|
* @param mdCount the mdCount to set
|
||||||
*/
|
*/
|
||||||
public void setMdCount(Map<Material, Integer> mdCount) {
|
public void setMdCount(Map<Material, Integer> mdCount) {
|
||||||
|
File diff suppressed because it is too large
Load Diff
@ -58,9 +58,7 @@ public class ValuePanel
|
|||||||
this.activeFilter = Filter.NAME_ASC;
|
this.activeFilter = Filter.NAME_ASC;
|
||||||
this.materialRecordList = Arrays.stream(Material.values()).
|
this.materialRecordList = Arrays.stream(Material.values()).
|
||||||
filter(Material::isBlock).
|
filter(Material::isBlock).
|
||||||
filter(Material::isItem). // Remove things like PITCHER_CROP
|
|
||||||
filter(m -> !m.name().startsWith("LEGACY_")).
|
filter(m -> !m.name().startsWith("LEGACY_")).
|
||||||
filter(this.addon.getBlockConfig()::isNotHiddenBlock).
|
|
||||||
map(material ->
|
map(material ->
|
||||||
{
|
{
|
||||||
Integer value = this.addon.getBlockConfig().getValue(this.world, material);
|
Integer value = this.addon.getBlockConfig().getValue(this.world, material);
|
||||||
@ -585,7 +583,6 @@ public class ValuePanel
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("deprecation")
|
|
||||||
int index = this.pageIndex * slot.amountMap().getOrDefault(BLOCK, 1) + slot.slot();
|
int index = this.pageIndex * slot.amountMap().getOrDefault(BLOCK, 1) + slot.slot();
|
||||||
|
|
||||||
if (index >= this.elementList.size())
|
if (index >= this.elementList.size())
|
||||||
|
@ -1,30 +0,0 @@
|
|||||||
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
|
main: world.bentobox.level.Level
|
||||||
version: ${version}${build.number}
|
version: ${version}${build.number}
|
||||||
icon: DIAMOND
|
icon: DIAMOND
|
||||||
api-version: 2.5.1
|
api-version: 1.16.5
|
||||||
|
|
||||||
authors: tastybento
|
authors: tastybento
|
||||||
|
|
||||||
|
@ -10,10 +10,6 @@
|
|||||||
limits:
|
limits:
|
||||||
COBBLESTONE: 10000
|
COBBLESTONE: 10000
|
||||||
NETHERRACK: 1000
|
NETHERRACK: 1000
|
||||||
# These blocks will never be shown in the GUI even if they have value
|
|
||||||
hidden-blocks:
|
|
||||||
- BEDROCK
|
|
||||||
- AIR
|
|
||||||
blocks:
|
blocks:
|
||||||
ACACIA_BUTTON: 1
|
ACACIA_BUTTON: 1
|
||||||
ACACIA_DOOR: 2
|
ACACIA_DOOR: 2
|
||||||
|
@ -4,22 +4,22 @@
|
|||||||
# Disabled Game Mode Addons
|
# Disabled Game Mode Addons
|
||||||
# Level will NOT hook into these game mode addons.
|
# Level will NOT hook into these game mode addons.
|
||||||
disabled-game-modes: []
|
disabled-game-modes: []
|
||||||
#
|
#
|
||||||
# When executing level command from console, should a report be shown?
|
# When executing level command from console, should a report be shown?
|
||||||
log-report-to-console: true
|
log-report-to-console: true
|
||||||
#
|
#
|
||||||
# Number of concurrent island calculations
|
# Number of concurrent island calculations
|
||||||
# If your CPU can handle it, you can run parallel island calcs if there are more than one in the queue
|
# If your CPU can handle it, you can run parallel island calcs if there are more than one in the queue
|
||||||
concurrent-island-calcs: 1
|
concurrent-island-calcs: 1
|
||||||
#
|
#
|
||||||
# Island level calculation timeout in minutes.
|
# Island level calculation timeout in minutes.
|
||||||
# If an island takes longer that this time to calculate, then the calculation will abort.
|
# If an island takes longer that this time to calculate, then the calculation will abort.
|
||||||
# Generally, calculation should only take a few seconds, so if this ever triggers then something is not right.
|
# Generally, calculation should only take a few seconds, so if this ever triggers then something is not right.
|
||||||
calculation-timeout: 5
|
calculation-timeout: 5
|
||||||
#
|
#
|
||||||
# Zero island levels on new island or island reset
|
# Zero island levels on new island or island reset
|
||||||
# If true, Level will calculate the starter island's level and remove it from any future level calculations.
|
# If true, Level will calculate the starter island's level and remove it from any future level calculations.
|
||||||
# If false, the player's starter island blocks will count towards their level.
|
# If this is false, the player's starter island blocks will count towards their level.
|
||||||
# This will reduce CPU if false.
|
# This will reduce CPU if false.
|
||||||
zero-new-island-levels: true
|
zero-new-island-levels: true
|
||||||
#
|
#
|
||||||
@ -72,18 +72,3 @@ sumteamdeaths: false
|
|||||||
# Shorthand island level
|
# Shorthand island level
|
||||||
# Shows large level values rounded down, e.g., 10,345 -> 10k
|
# Shows large level values rounded down, e.g., 10,345 -> 10k
|
||||||
shorthand: false
|
shorthand: false
|
||||||
units:
|
|
||||||
# Shorthand units
|
|
||||||
kilo: k
|
|
||||||
mega: M
|
|
||||||
giga: G
|
|
||||||
tera: T
|
|
||||||
#
|
|
||||||
# Include Shulker Box content in chests in level calculations.
|
|
||||||
# Will count blocks in Shulker Boxes inside of chests.
|
|
||||||
# NOTE: include-chests needs to be enabled for this to work!.
|
|
||||||
include-shulkers-in-chest: false
|
|
||||||
#
|
|
||||||
# Disables hooking with other plugins.
|
|
||||||
# Example: disabled-plugin-hooks: [UltimateStacker, RoseStacker]
|
|
||||||
disabled-plugin-hooks: []
|
|
@ -8,12 +8,8 @@ admin:
|
|||||||
parameters: "<player>"
|
parameters: "<player>"
|
||||||
description: "calculate the island level for player"
|
description: "calculate the island level for player"
|
||||||
sethandicap:
|
sethandicap:
|
||||||
parameters: <player> [+/-]<handicap>
|
parameters: <player> <handicap>
|
||||||
description: |
|
description: "set the island handicap, usually the level of the starter island"
|
||||||
set or change the island *handicap*
|
|
||||||
e.g. +10 will remove 10 levels,
|
|
||||||
30 will set handicap to 30,
|
|
||||||
-20 will add 20 levels
|
|
||||||
changed: "&a Initial island handicap changed from [number] to [new_number]."
|
changed: "&a Initial island handicap changed from [number] to [new_number]."
|
||||||
invalid-level: "&c Invalid handicap. Use an integer."
|
invalid-level: "&c Invalid handicap. Use an integer."
|
||||||
levelstatus:
|
levelstatus:
|
||||||
@ -46,8 +42,8 @@ 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 Level progress: &6 [progress]&b /&e [levelcost] &a points"
|
required-points-to-next-level: "&a [points] points required until the next level"
|
||||||
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..."
|
||||||
time-out: "&c The level calculation took too long. Please try again later."
|
time-out: "&c The level calculation took too long. Please try again later."
|
||||||
@ -116,11 +112,6 @@ level:
|
|||||||
limit: "&7 Block limit: &e [number]"
|
limit: "&7 Block limit: &e [number]"
|
||||||
count: "&7 Number of blocks: &e [number]"
|
count: "&7 Number of blocks: &e [number]"
|
||||||
calculated: "&7 Calculated value: &e [number]"
|
calculated: "&7 Calculated value: &e [number]"
|
||||||
value_blocks:
|
|
||||||
name: "&f&l All Blocks With Value"
|
|
||||||
description: |-
|
|
||||||
&7 Display all blocks
|
|
||||||
&7 with value on island.
|
|
||||||
all_blocks:
|
all_blocks:
|
||||||
name: "&f&l All Blocks"
|
name: "&f&l All Blocks"
|
||||||
description: |-
|
description: |-
|
||||||
@ -220,7 +211,3 @@ level:
|
|||||||
value-underwater: "&7 The value of '[material]' below sea-level: &e[value]"
|
value-underwater: "&7 The value of '[material]' below sea-level: &e[value]"
|
||||||
# Message that is sent to user when he does not hold any items in hand.
|
# Message that is sent to user when he does not hold any items in hand.
|
||||||
empty-hand: "&c There are no blocks in your hand"
|
empty-hand: "&c There are no blocks in your hand"
|
||||||
# Message when showing how many have been placed of a block
|
|
||||||
you-have: "&7 You have [number] at last count."
|
|
||||||
# Message about the limit
|
|
||||||
you-can-place: "&7 You can place up to [number] and have them count"
|
|
||||||
|
212
src/main/resources/locales/zh-CN.yml
Normal file → Executable file
212
src/main/resources/locales/zh-CN.yml
Normal file → Executable file
@ -1,93 +1,79 @@
|
|||||||
|
---
|
||||||
admin:
|
admin:
|
||||||
level:
|
level:
|
||||||
parameters: <player>
|
parameters: "<player>"
|
||||||
description: 计算指定玩家的岛屿等级
|
description: 计算指定玩家的岛屿等级
|
||||||
sethandicap:
|
sethandicap:
|
||||||
parameters: <player> <handicap>
|
parameters: "<player> <handicap>"
|
||||||
description: 设置偏差值, 通常用于抵消初始岛屿等级, 来保证岛屿等级从零开始. 实际岛屿等级 - <handicap> = 最终的岛屿等级
|
description: 设置偏差值,通常用于抵消初始岛屿等级,来保证岛屿等级从零开始。实际岛屿等级 - <handicap> = 最终的岛屿等级
|
||||||
changed: '&a岛屿的偏差值从[number]更改为[new_number]'
|
changed: "&a 岛屿的偏差值从 [number] 更改为 [new_number]"
|
||||||
invalid-level: '&c偏差值无效, 请使用整数'
|
invalid-level: "&c 偏差值无效,请使用整数"
|
||||||
levelstatus:
|
levelstatus:
|
||||||
description: 显示等级计算队列中的岛屿
|
description: 显示等级计算队列中的岛屿
|
||||||
islands-in-queue: '&a列队中的岛屿: [number]'
|
islands-in-queue: "&a 列队中的岛屿:[number]"
|
||||||
top:
|
top:
|
||||||
description: 显示前十名
|
description: 显示前十名
|
||||||
unknown-world: '&c未知的世界!'
|
unknown-world: "&c 未知的世界!"
|
||||||
display: '&f[rank]. &a[name] &7- &b[level]'
|
display: "&f[rank]. &a[name] &7- &b[level]"
|
||||||
remove:
|
remove:
|
||||||
description: 将玩家移出前十名
|
description: 将玩家移出前十名
|
||||||
parameters: <player>
|
parameters: "<player>"
|
||||||
stats:
|
|
||||||
description: 显示该服务器上岛屿的统计数据
|
|
||||||
title: 服务器岛屿数据
|
|
||||||
world: '&a[name]'
|
|
||||||
no-data: '&c没有数据.'
|
|
||||||
average-level: '平均岛屿等级: [number]'
|
|
||||||
median-level: '中位数岛屿等级: [number]'
|
|
||||||
mode-level: '众数岛屿等级: [number]'
|
|
||||||
highest-level: '最高岛屿等级: [number]'
|
|
||||||
lowest-level: '最低岛屿等级: [number]'
|
|
||||||
distribution: '岛屿等级分布:'
|
|
||||||
islands: 个岛屿
|
|
||||||
island:
|
island:
|
||||||
level:
|
level:
|
||||||
parameters: '[player]'
|
parameters: "[player]"
|
||||||
description: 计算你或指定玩家[player]的岛屿等级
|
description: 计算你或指定玩家 [player] 的岛屿等级
|
||||||
calculating: '&a等级计算中...'
|
calculating: "&a 等级计算中..."
|
||||||
estimated-wait: '&a预计等待时间: [number]秒'
|
estimated-wait: "&a 预计等待时间:[number] 秒"
|
||||||
in-queue: '&a你处于队列中第[number]个'
|
in-queue: "&a 你处于队列中第 [number] 个"
|
||||||
island-level-is: '&a岛屿等级为: &b[level]'
|
island-level-is: "&a 岛屿等级为 &b[level]"
|
||||||
required-points-to-next-level: '&a还需[points]点数才能到达下一级'
|
required-points-to-next-level: "&a 还需 [points] 点数才能到达下一级"
|
||||||
deaths: '&c([number]次死亡)'
|
deaths: "&c([number] 次死亡)"
|
||||||
cooldown: '&c还需等待&b[time]&c秒才能再次使用该指令'
|
cooldown: "&c 还需等待 &b[time] &c秒才能再次使用该指令"
|
||||||
in-progress: '&6岛屿等级正在计算中...'
|
in-progress: "&6 岛级等级正在计算中..."
|
||||||
time-out: '&c等级计算超时, 请稍后再试'
|
time-out: "&c 等级计算超时。请稍后再试"
|
||||||
|
|
||||||
top:
|
top:
|
||||||
description: 显示前十名
|
description: 显示前十名
|
||||||
gui-title: '&a前十'
|
gui-title: "&a 前十"
|
||||||
gui-heading: '&6[name]: &B[rank]'
|
gui-heading: "&6[name]: &B[rank]"
|
||||||
island-level: '&b等级: [level]'
|
island-level: "&b 等级 [level]"
|
||||||
warp-to: '&a正在传送到[name]的岛屿'
|
warp-to: "&a 正在传送到 [name] 的岛屿"
|
||||||
|
|
||||||
level-details:
|
level-details:
|
||||||
above-sea-level-blocks: 海平面以上的方块
|
above-sea-level-blocks: 海平面以上的方块
|
||||||
spawners: 刷怪笼
|
spawners: 刷怪笼
|
||||||
underwater-blocks: 水下的方块
|
underwater-blocks: 水下的方块
|
||||||
all-blocks: 所有方块
|
all-blocks: 所有方块
|
||||||
no-island: '&c没有岛屿!'
|
no-island: "&c 没有岛屿!"
|
||||||
names-island: '[name]的岛屿'
|
names-island: "[name] 的岛屿"
|
||||||
syntax: '[name] x [number]'
|
syntax: "[name] x [number]"
|
||||||
hint: '&c运行level指令查看方块报告'
|
hint: "&c 运行level指令查看方块报告"
|
||||||
|
|
||||||
level:
|
level:
|
||||||
commands:
|
commands:
|
||||||
value:
|
value:
|
||||||
parameters: '[hand|<material>]'
|
parameters: "[hand|<material>]"
|
||||||
description: 显示方块的价值. 在末尾添加'hand'可显示手中方块的价值
|
description: 显示方块的价值。在末尾添加 'hand' 可显示手中方块的价值
|
||||||
gui:
|
gui:
|
||||||
titles:
|
titles:
|
||||||
top: '&0&l岛屿排行榜'
|
top: "&0&l 岛屿排行榜"
|
||||||
detail-panel: '&0&l[name]的岛屿'
|
detail-panel: "&0&l [name] 的岛屿"
|
||||||
value-panel: '&0&l方块价值'
|
value-panel: "&0&l 方块价值"
|
||||||
buttons:
|
buttons:
|
||||||
island:
|
island:
|
||||||
empty: '&f&l第[name]名'
|
empty: "&f&l 第 [name] 名"
|
||||||
name: '&f&l[name]'
|
name: "&f&l [name]"
|
||||||
description: |-
|
description: |-
|
||||||
[owner]
|
[owner]
|
||||||
[members]
|
[members]
|
||||||
[place]
|
[place]
|
||||||
[level]
|
[level]
|
||||||
owners-island: '[player]的岛屿'
|
owners-island: "[player] 的岛屿"
|
||||||
owner: '&7&l岛主: &r&b[player]'
|
owner: "&7&l 岛主:&r&b [player]"
|
||||||
members-title: '&7&l成员: '
|
members-title: "&7&l 成员:"
|
||||||
member: '&b- [player]'
|
member: "&b - [player]"
|
||||||
unknown: 未知
|
unknown: 未知
|
||||||
place: '&7第&7&o[number]&r&7名'
|
place: "&7第 &7&o[number] &r&7名"
|
||||||
level: '&7等级: &o[number]'
|
level: "&7 等级: &o [number]"
|
||||||
material:
|
material:
|
||||||
name: '&f&l [number] x [material]'
|
name: "&f&l [number] x [material]"
|
||||||
description: |-
|
description: |-
|
||||||
[description]
|
[description]
|
||||||
[count]
|
[count]
|
||||||
@ -95,79 +81,83 @@ level:
|
|||||||
[calculated]
|
[calculated]
|
||||||
[limit]
|
[limit]
|
||||||
[id]
|
[id]
|
||||||
id: '&7方块ID: &e[id]'
|
id: "&7 方块ID:&e [id]"
|
||||||
value: '&7方块价值: &e[number]'
|
value: "&7 方块价值:&e [number]"
|
||||||
limit: '&7方块限制: &e[number]'
|
limit: "&7 方块限制:&e [number]"
|
||||||
count: '&7方块数量: &e[number]'
|
count: "&7 方块数量:&e [number]"
|
||||||
calculated: '&7计算值: &e[number]'
|
calculated: "&7 计算值:&e [number]"
|
||||||
all_blocks:
|
all_blocks:
|
||||||
name: '&f&l所有方块'
|
name: "&f&l 所有方块"
|
||||||
description: '&7显示岛屿上所有的方块'
|
description: "&7 显示岛屿上所有的方块"
|
||||||
above_sea_level:
|
above_sea_level:
|
||||||
name: '&f&l海平面以上的方块'
|
name: "&f&l 海平面以上的方块"
|
||||||
description: '&7只显示所有海平面以上的方块'
|
description: |-
|
||||||
|
&7 只显示所有
|
||||||
|
&7 海平面以上的方块
|
||||||
underwater:
|
underwater:
|
||||||
name: '&f&l海平面以下的方块'
|
name: "&f&l 海平面以下的方块"
|
||||||
description: 只显示所有海平面以下的方块
|
description: |-
|
||||||
|
&7 只显示所有
|
||||||
|
&7 海平面以下的方块
|
||||||
spawner:
|
spawner:
|
||||||
name: '&f&l刷怪笼'
|
name: "&f&l 刷怪笼"
|
||||||
description: '&7只显示刷怪笼'
|
description: "&7 只显示刷怪笼"
|
||||||
filters:
|
filters:
|
||||||
name:
|
name:
|
||||||
name: '&f&l按名称排序'
|
name: "&f&l 按名称排序"
|
||||||
description: '&7通过名称排序所有的方块'
|
description: "&7 通过名称排序所有的方块"
|
||||||
value:
|
value:
|
||||||
name: '&f&l按价值排序'
|
name: "&f&l 按价值排序"
|
||||||
description: '&7通过价值排序所有的方块'
|
description: "&7 通过价值排序所有的方块"
|
||||||
count:
|
count:
|
||||||
name: '&f&l按数量排序'
|
name: "&f&l 按数量排序"
|
||||||
description: '&7通过数量排序所有方块'
|
description: "&7 通过数量排序所有方块"
|
||||||
value:
|
value:
|
||||||
name: '&f&l[material]'
|
name: "&f&l [material]"
|
||||||
description: |-
|
description: |-
|
||||||
[description]
|
[description]
|
||||||
[value]
|
[value]
|
||||||
[underwater]
|
[underwater]
|
||||||
[limit]
|
[limit]
|
||||||
[id]
|
[id]
|
||||||
id: '&7方块ID: &e[id]'
|
id: "&7 方块ID:&e [id]"
|
||||||
value: '&7方块价值: &e[number]'
|
value: "&7 方块价值:&e [number]"
|
||||||
underwater: '&7海平面以下方块的价值: &e[number]'
|
underwater: "&7 海平面以下方块的价值:&e [number]"
|
||||||
limit: '&7方块限制: &e[number]'
|
limit: "&7 方块限制:&e [number]"
|
||||||
previous:
|
previous:
|
||||||
name: '&f&l上一页'
|
name: "&f&l 上一页"
|
||||||
description: '&7切换到第[number]页'
|
description: "&7 切换到第 [number] 页"
|
||||||
next:
|
next:
|
||||||
name: '&f&l下一页'
|
name: "&f&l 下一页"
|
||||||
description: '&7切换到第[number]页'
|
description: "&7 切换到第 [number] 页"
|
||||||
search:
|
search:
|
||||||
name: '&f&l搜索'
|
name: "&f&l 搜索"
|
||||||
description: '&7搜索特定的内容'
|
description: "&7 搜索特定的内容"
|
||||||
search: '&b搜索值: [value]'
|
search: "&b 搜索值:[value]"
|
||||||
tips:
|
tips:
|
||||||
click-to-view: '&e点击 &7查看'
|
click-to-view: "&e 点击 &7 查看"
|
||||||
click-to-previous: '&e点击 &7查看上一页'
|
click-to-previous: "&e 点击 &7 查看上一页"
|
||||||
click-to-next: '&e点击 &7查看下一页'
|
click-to-next: "&e 点击 &7 查看下一页"
|
||||||
click-to-select: '&e点击 &7选择'
|
click-to-select: "&e 点击 &7 选择"
|
||||||
left-click-to-cycle-up: '&e左键 &7向上循环'
|
left-click-to-cycle-up: "&e 左键点击 &7 向上循环"
|
||||||
right-click-to-cycle-down: '&e右键 &7向下循环'
|
right-click-to-cycle-down: "&e 右键点击 &7 向下循环"
|
||||||
left-click-to-change: '&e左键 &7编辑'
|
left-click-to-change: "&e 左键点击 &7 编辑"
|
||||||
right-click-to-clear: '&e右键 &7清除'
|
right-click-to-clear: "&e 右键点击 &7 清除"
|
||||||
click-to-asc: '&e点击 &7以升序排序'
|
click-to-asc: "&e 点击 &7 以升序排序"
|
||||||
click-to-desc: '&e点击 &7以降序排序'
|
click-to-desc: "&e 点击 &7 以降序排序"
|
||||||
click-to-warp: '&e点击 &7去岛屿传送点'
|
click-to-warp: "&e 点击 &7 去岛屿传送点"
|
||||||
click-to-visit: '&e点击 &7参观'
|
click-to-visit: "&e 点击 &7 参观"
|
||||||
right-click-to-visit: '&e右键 &7查看'
|
right-click-to-visit: "&e 右键点击 &7 查看"
|
||||||
conversations:
|
conversations:
|
||||||
prefix: '&l&6[BentoBox]: &r'
|
prefix: "&l&6 [BentoBox]: &r"
|
||||||
no-data: '&c运行level指令查看方块报告'
|
no-data: "&c 运行level指令查看方块报告"
|
||||||
cancel-string: cancel
|
cancel-string: cancel
|
||||||
exit-string: cancel, exit, quit
|
exit-string: cancel, exit, quit
|
||||||
write-search: '&e请输入要搜索的值. (输入''cancel''退出)'
|
write-search: "&e 请输入要搜索的值. (输入 'cancel' 退出)"
|
||||||
search-updated: '&a搜索值已更新'
|
search-updated: "&a 搜索值已更新"
|
||||||
cancelled: '&c对话已取消'
|
cancelled: "&c 对话已取消!"
|
||||||
no-value: '&c这件物品一文不值'
|
no-value: "&c 这件物品一文不值"
|
||||||
unknown-item: '&c物品''[material]''在游戏中不存在'
|
unknown-item: "&c 物品 '[material]' 在游戏中不存在"
|
||||||
value: '&7物品''[material]''的价值: &e[value]'
|
value: "&7 物品 '[material]' 的价值:&e[value]"
|
||||||
value-underwater: '&7物品''[material]''在海平面以下的价值: &e[value]'
|
value-underwater: "&7 物品 '[material]' 在海平面以下的价值:&e[value]"
|
||||||
empty-hand: '&c你的手中没有拿着方块'
|
empty-hand: "&c 你的手中没有拿着方块"
|
||||||
|
@ -24,28 +24,6 @@ detail_panel:
|
|||||||
1:
|
1:
|
||||||
# Column number
|
# Column number
|
||||||
2:
|
2:
|
||||||
# Icon is a Bukkit Material.
|
|
||||||
icon: ICE
|
|
||||||
# Title of the button shown to the user. This is a reference and the reference will be translatable in the locale file
|
|
||||||
title: level.gui.buttons.value_blocks.name
|
|
||||||
# Description of the button shown to the user in the lore. This is a reference and the reference will be translatable in the locale file
|
|
||||||
description: level.gui.buttons.value_blocks.description
|
|
||||||
# The data section is a key-value list of data relavent for this button. It is interpreted by the code implemented the panel.
|
|
||||||
# The convention is to specify the type and the panel tab that will open if pressed. These are Enums in the code.
|
|
||||||
data:
|
|
||||||
# Type button will go to the ALL_BLOCKS tab when clicked.
|
|
||||||
type: TAB
|
|
||||||
tab: VALUE_BLOCKS
|
|
||||||
# Actions cover what happens if the button is clicked or the mouse is moved over it. There can be multiple actions possible for different
|
|
||||||
# click-types.
|
|
||||||
actions:
|
|
||||||
# Each action has an arbitrary descriptive name to define it.
|
|
||||||
view:
|
|
||||||
# The click-type is the same as the bukkit {@link org.bukkit.event.inventory.ClickType}. UNKNOWN is the default.
|
|
||||||
click-type: unknown
|
|
||||||
# tooltip is a locale reference that will be translated for the user and shown when they hover over the button.
|
|
||||||
tooltip: level.gui.tips.click-to-view
|
|
||||||
3:
|
|
||||||
# Icon is a Bukkit Material.
|
# Icon is a Bukkit Material.
|
||||||
icon: STONE
|
icon: STONE
|
||||||
# Title of the button shown to the user. This is a reference and the reference will be translatable in the locale file
|
# Title of the button shown to the user. This is a reference and the reference will be translatable in the locale file
|
||||||
@ -67,7 +45,7 @@ detail_panel:
|
|||||||
click-type: unknown
|
click-type: unknown
|
||||||
# tooltip is a locale reference that will be translated for the user and shown when they hover over the button.
|
# tooltip is a locale reference that will be translated for the user and shown when they hover over the button.
|
||||||
tooltip: level.gui.tips.click-to-view
|
tooltip: level.gui.tips.click-to-view
|
||||||
4:
|
3:
|
||||||
icon: GRASS_BLOCK
|
icon: GRASS_BLOCK
|
||||||
title: level.gui.buttons.above_sea_level.name
|
title: level.gui.buttons.above_sea_level.name
|
||||||
description: level.gui.buttons.above_sea_level.description
|
description: level.gui.buttons.above_sea_level.description
|
||||||
@ -78,7 +56,7 @@ detail_panel:
|
|||||||
view:
|
view:
|
||||||
click-type: unknown
|
click-type: unknown
|
||||||
tooltip: level.gui.tips.click-to-view
|
tooltip: level.gui.tips.click-to-view
|
||||||
5:
|
4:
|
||||||
icon: WATER_BUCKET
|
icon: WATER_BUCKET
|
||||||
title: level.gui.buttons.underwater.name
|
title: level.gui.buttons.underwater.name
|
||||||
description: level.gui.buttons.underwater.description
|
description: level.gui.buttons.underwater.description
|
||||||
@ -89,7 +67,7 @@ detail_panel:
|
|||||||
view:
|
view:
|
||||||
click-type: unknown
|
click-type: unknown
|
||||||
tooltip: level.gui.tips.click-to-view
|
tooltip: level.gui.tips.click-to-view
|
||||||
6:
|
5:
|
||||||
icon: SPAWNER
|
icon: SPAWNER
|
||||||
title: level.gui.buttons.spawner.name
|
title: level.gui.buttons.spawner.name
|
||||||
description: level.gui.buttons.spawner.description
|
description: level.gui.buttons.spawner.description
|
||||||
@ -132,11 +110,18 @@ detail_panel:
|
|||||||
8: material_button
|
8: material_button
|
||||||
3:
|
3:
|
||||||
1:
|
1:
|
||||||
# In this case, the icon is defined as a TIPPED_ARROW with a color.
|
# In this case, the icon is defined as a TIPPED_ARROW with and enchantment applied. The format for the enchantment is
|
||||||
# CustomPotionColor uses the Decimal description of a Color, just as leather armor does.
|
# define in {@link world.bentobox.bentobox.util.ItemParser} and available for POTIONS or TIPPED_ARROWs.
|
||||||
# All you need to do is take a hex code of a color (like #ff00aa) which represents red,
|
# Format TIPPED_ARROW:NAME:<LEVEL>:<EXTENDED>:<SPLASH/LINGER>:QTY
|
||||||
# green, blue as 2 hex digits each and convert that number into a decimal, using a hex to decimal calculator.
|
# LEVEL, EXTENDED, SPLASH, LINGER are optional.
|
||||||
icon: tipped_arrow{CustomPotionColor:11546150}
|
# LEVEL is a number, 1 or 2
|
||||||
|
# LINGER is for V1.9 servers and later
|
||||||
|
# Examples:
|
||||||
|
# TIPPED_ARROW:STRENGTH:1:EXTENDED:SPLASH:1
|
||||||
|
# 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
|
||||||
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:
|
||||||
@ -154,7 +139,7 @@ detail_panel:
|
|||||||
7: material_button
|
7: material_button
|
||||||
8: material_button
|
8: material_button
|
||||||
9:
|
9:
|
||||||
icon: tipped_arrow{CustomPotionColor:8439583}
|
icon: TIPPED_ARROW:JUMP::::1
|
||||||
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:
|
||||||
|
@ -64,7 +64,7 @@ value_panel:
|
|||||||
8: material_button
|
8: material_button
|
||||||
3:
|
3:
|
||||||
1:
|
1:
|
||||||
icon: tipped_arrow{CustomPotionColor:11546150}
|
icon: TIPPED_ARROW:INSTANT_HEAL::::1
|
||||||
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{CustomPotionColor:8439583}
|
icon: TIPPED_ARROW:JUMP::::1
|
||||||
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:
|
||||||
|
@ -61,7 +61,6 @@ import world.bentobox.bentobox.managers.FlagsManager;
|
|||||||
import world.bentobox.bentobox.managers.IslandWorldManager;
|
import world.bentobox.bentobox.managers.IslandWorldManager;
|
||||||
import world.bentobox.bentobox.managers.IslandsManager;
|
import world.bentobox.bentobox.managers.IslandsManager;
|
||||||
import world.bentobox.bentobox.managers.PlaceholdersManager;
|
import world.bentobox.bentobox.managers.PlaceholdersManager;
|
||||||
import world.bentobox.bentobox.util.Util;
|
|
||||||
import world.bentobox.level.config.BlockConfig;
|
import world.bentobox.level.config.BlockConfig;
|
||||||
import world.bentobox.level.config.ConfigSettings;
|
import world.bentobox.level.config.ConfigSettings;
|
||||||
import world.bentobox.level.listeners.IslandActivitiesListeners;
|
import world.bentobox.level.listeners.IslandActivitiesListeners;
|
||||||
@ -73,7 +72,7 @@ import world.bentobox.level.listeners.JoinLeaveListener;
|
|||||||
*/
|
*/
|
||||||
@SuppressWarnings("deprecation")
|
@SuppressWarnings("deprecation")
|
||||||
@RunWith(PowerMockRunner.class)
|
@RunWith(PowerMockRunner.class)
|
||||||
@PrepareForTest({ Bukkit.class, BentoBox.class, User.class, Util.class })
|
@PrepareForTest({ Bukkit.class, BentoBox.class, User.class })
|
||||||
public class LevelTest {
|
public class LevelTest {
|
||||||
|
|
||||||
private static File jFile;
|
private static File jFile;
|
||||||
@ -145,7 +144,7 @@ public class LevelTest {
|
|||||||
/**
|
/**
|
||||||
* @throws java.lang.Exception
|
* @throws java.lang.Exception
|
||||||
*/
|
*/
|
||||||
@Before
|
@Before
|
||||||
public void setUp() throws Exception {
|
public void setUp() throws Exception {
|
||||||
// Set up plugin
|
// Set up plugin
|
||||||
Whitebox.setInternalState(BentoBox.class, "instance", plugin);
|
Whitebox.setInternalState(BentoBox.class, "instance", plugin);
|
||||||
@ -190,11 +189,6 @@ public class LevelTest {
|
|||||||
when(Bukkit.getServer()).thenReturn(server);
|
when(Bukkit.getServer()).thenReturn(server);
|
||||||
when(Bukkit.getLogger()).thenReturn(Logger.getAnonymousLogger());
|
when(Bukkit.getLogger()).thenReturn(Logger.getAnonymousLogger());
|
||||||
when(Bukkit.getPluginManager()).thenReturn(mock(PluginManager.class));
|
when(Bukkit.getPluginManager()).thenReturn(mock(PluginManager.class));
|
||||||
when(Bukkit.getBukkitVersion()).thenReturn("");
|
|
||||||
|
|
||||||
// Util
|
|
||||||
PowerMockito.mockStatic(Util.class, Mockito.RETURNS_MOCKS);
|
|
||||||
when(Util.inTest()).thenReturn(true);
|
|
||||||
|
|
||||||
// Addon
|
// Addon
|
||||||
addon = new Level();
|
addon = new Level();
|
||||||
@ -227,6 +221,7 @@ public class LevelTest {
|
|||||||
when(fm.getFlags()).thenReturn(Collections.emptyList());
|
when(fm.getFlags()).thenReturn(Collections.emptyList());
|
||||||
|
|
||||||
// Bukkit
|
// Bukkit
|
||||||
|
PowerMockito.mockStatic(Bukkit.class);
|
||||||
when(Bukkit.getScheduler()).thenReturn(scheduler);
|
when(Bukkit.getScheduler()).thenReturn(scheduler);
|
||||||
ItemMeta meta = mock(ItemMeta.class);
|
ItemMeta meta = mock(ItemMeta.class);
|
||||||
ItemFactory itemFactory = mock(ItemFactory.class);
|
ItemFactory itemFactory = mock(ItemFactory.class);
|
||||||
|
@ -94,7 +94,7 @@ public class LevelsManagerTest {
|
|||||||
private World world;
|
private World world;
|
||||||
@Mock
|
@Mock
|
||||||
private Player player;
|
private Player player;
|
||||||
|
@Mock
|
||||||
private ConfigSettings settings;
|
private ConfigSettings settings;
|
||||||
@Mock
|
@Mock
|
||||||
private User user;
|
private User user;
|
||||||
@ -165,7 +165,6 @@ public class LevelsManagerTest {
|
|||||||
when(im.hasIsland(eq(world), any(UUID.class))).thenReturn(true);
|
when(im.hasIsland(eq(world), any(UUID.class))).thenReturn(true);
|
||||||
when(im.getIsland(world, uuid)).thenReturn(island);
|
when(im.getIsland(world, uuid)).thenReturn(island);
|
||||||
when(im.getIslandById(anyString())).thenReturn(Optional.of(island));
|
when(im.getIslandById(anyString())).thenReturn(Optional.of(island));
|
||||||
when(im.getIslandById(anyString(), eq(false))).thenReturn(Optional.of(island));
|
|
||||||
|
|
||||||
// Player
|
// Player
|
||||||
when(player.getUniqueId()).thenReturn(uuid);
|
when(player.getUniqueId()).thenReturn(uuid);
|
||||||
@ -175,7 +174,6 @@ public class LevelsManagerTest {
|
|||||||
when(world.getName()).thenReturn("bskyblock-world");
|
when(world.getName()).thenReturn("bskyblock-world");
|
||||||
|
|
||||||
// Settings
|
// Settings
|
||||||
settings = new ConfigSettings();
|
|
||||||
when(addon.getSettings()).thenReturn(settings);
|
when(addon.getSettings()).thenReturn(settings);
|
||||||
|
|
||||||
// User
|
// User
|
||||||
@ -334,7 +332,7 @@ public class LevelsManagerTest {
|
|||||||
@Test
|
@Test
|
||||||
public void testFormatLevel() {
|
public void testFormatLevel() {
|
||||||
assertEquals("123456789", lm.formatLevel(123456789L));
|
assertEquals("123456789", lm.formatLevel(123456789L));
|
||||||
settings.setShorthand(true);
|
when(settings.isShorthand()).thenReturn(true);
|
||||||
assertEquals("123.5M", lm.formatLevel(123456789L));
|
assertEquals("123.5M", lm.formatLevel(123456789L));
|
||||||
assertEquals("1.2k", lm.formatLevel(1234L));
|
assertEquals("1.2k", lm.formatLevel(1234L));
|
||||||
assertEquals("123.5G", lm.formatLevel(123456789352L));
|
assertEquals("123.5G", lm.formatLevel(123456789352L));
|
||||||
@ -397,8 +395,8 @@ public class LevelsManagerTest {
|
|||||||
lm.loadTopTens();
|
lm.loadTopTens();
|
||||||
PowerMockito.verifyStatic(Bukkit.class); // 1
|
PowerMockito.verifyStatic(Bukkit.class); // 1
|
||||||
Bukkit.getScheduler();
|
Bukkit.getScheduler();
|
||||||
verify(scheduler).runTaskAsynchronously(eq(plugin), task.capture()); // Capture the task in the scheduler
|
verify(scheduler).runTaskAsynchronously(eq(plugin), task.capture());
|
||||||
task.getValue().run(); // run it
|
task.getValue().run();
|
||||||
verify(addon).log("Generating rankings");
|
verify(addon).log("Generating rankings");
|
||||||
verify(addon).log("Generated rankings for bskyblock-world");
|
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.verify;
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
import java.util.HashSet;
|
||||||
import java.util.LinkedHashMap;
|
import java.util.LinkedHashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Map.Entry;
|
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.getIsland(any(World.class), any(User.class))).thenReturn(island);
|
||||||
when(im.getIslandAt(any(Location.class))).thenReturn(Optional.of(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.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 ArrayList<>(islands.values()));
|
when(im.getIslands(any(), any(UUID.class))).thenReturn(new HashSet<>(islands.values()));
|
||||||
when(addon.getIslands()).thenReturn(im);
|
when(addon.getIslands()).thenReturn(im);
|
||||||
|
|
||||||
// Levels Manager
|
// Levels Manager
|
||||||
|
@ -10,7 +10,7 @@ import static org.mockito.Mockito.verify;
|
|||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.Set;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
@ -120,8 +120,8 @@ public class AdminTopRemoveCommandTest {
|
|||||||
when(island.getOwner()).thenReturn(uuid);
|
when(island.getOwner()).thenReturn(uuid);
|
||||||
// Island Manager
|
// Island Manager
|
||||||
when(plugin.getIslands()).thenReturn(im);
|
when(plugin.getIslands()).thenReturn(im);
|
||||||
when(im.getIslands(any(), any(User.class))).thenReturn(List.of(island));
|
when(im.getIslands(any(), any(User.class))).thenReturn(Set.of(island));
|
||||||
when(im.getIslands(any(), any(UUID.class))).thenReturn(List.of(island));
|
when(im.getIslands(any(), any(UUID.class))).thenReturn(Set.of(island));
|
||||||
|
|
||||||
// Bukkit
|
// Bukkit
|
||||||
PowerMockito.mockStatic(Bukkit.class);
|
PowerMockito.mockStatic(Bukkit.class);
|
||||||
|
Loading…
Reference in New Issue
Block a user