Compare commits

..

No commits in common. "develop" and "2.11.0" have entirely different histories.

40 changed files with 2283 additions and 3205 deletions

View File

@ -11,22 +11,21 @@ jobs:
name: Build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v2
with:
fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis
- name: Set up JDK 17
uses: actions/setup-java@v3
uses: actions/setup-java@v1
with:
distribution: 'adopt'
java-version: 17
- name: Cache SonarCloud packages
uses: actions/cache@v3
uses: actions/cache@v1
with:
path: ~/.sonar/cache
key: ${{ runner.os }}-sonar
restore-keys: ${{ runner.os }}-sonar
- name: Cache Maven packages
uses: actions/cache@v3
uses: actions/cache@v1
with:
path: ~/.m2
key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }}

37
pom.xml
View File

@ -58,12 +58,12 @@
<!-- Non-minecraft related dependencies -->
<powermock.version>2.0.9</powermock.version>
<!-- More visible way how to change dependency versions -->
<spigot.version>1.20.4-R0.1-SNAPSHOT</spigot.version>
<bentobox.version>2.5.1-SNAPSHOT</bentobox.version>
<spigot.version>1.19.4-R0.1-SNAPSHOT</spigot.version>
<bentobox.version>1.23.0</bentobox.version>
<!-- Warps addon version -->
<warps.version>1.12.0</warps.version>
<!-- Visit addon version -->
<visit.version>1.6.0</visit.version>
<visit.version>1.4.0</visit.version>
<!-- Panel Utils version -->
<panelutils.version>1.1.0</panelutils.version>
<!-- Revision variable removes warning about dynamic version -->
@ -71,7 +71,7 @@
<!-- Do not change unless you want different name for local builds. -->
<build.number>-LOCAL</build.number>
<!-- This allows to change between versions. -->
<build.version>2.16.2</build.version>
<build.version>2.11.0</build.version>
<sonar.projectKey>BentoBoxWorld_Level</sonar.projectKey>
<sonar.organization>bentobox-world</sonar.organization>
<sonar.host.url>https://sonarcloud.io</sonar.host.url>
@ -129,8 +129,8 @@
<repositories>
<!--Wild Stacker repo -->
<repository>
<id>bg-repo</id>
<url>https://repo.bg-software.com/repository/api/</url>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
<!-- RoseStacker repo -->
<repository>
@ -139,8 +139,8 @@
</repository>
<!-- UltimateStacker repo -->
<repository>
<id>songoda-plugins</id>
<url>https://repo.songoda.com/repository/minecraft-plugins/</url>
<id>songoda-public</id>
<url>https://repo.songoda.com/repository/public/</url>
</repository>
<repository>
<id>spigot-repo</id>
@ -154,10 +154,6 @@
<id>codemc-public</id>
<url>https://repo.codemc.org/repository/maven-public/</url>
</repository>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
</repositories>
<dependencies>
@ -212,9 +208,9 @@
</dependency>
<!-- Wild Stacker dependency -->
<dependency>
<groupId>com.bgsoftware</groupId>
<groupId>com.github.OmerBenGera</groupId>
<artifactId>WildStackerAPI</artifactId>
<version>2023.3</version>
<version>b18</version>
<scope>provided</scope>
</dependency>
<!-- Static analysis -->
@ -235,14 +231,13 @@
<dependency>
<groupId>dev.rosewood</groupId>
<artifactId>rosestacker</artifactId>
<version>1.5.27</version>
<version>1.3.0</version>
<scope>provided</scope>
</dependency>
<!-- Ultimate Stacker dependency -->
<dependency>
<groupId>com.craftaro</groupId>
<artifactId>UltimateStacker-API</artifactId>
<version>1.0.0-20240329.173606-35</version>
<groupId>com.songoda</groupId>
<artifactId>UltimateStacker</artifactId>
<version>2.3.3</version>
<scope>provided</scope>
</dependency>
</dependencies>
@ -408,15 +403,13 @@
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.10</version>
<version>0.8.7</version>
<configuration>
<append>true</append>
<excludes>
<!-- This is required to prevent Jacoco from adding
synthetic fields to a JavaBean class (causes errors in testing) -->
<exclude>**/*Names*</exclude>
<!-- Prevents the Material is too large to mock error -->
<exclude>org/bukkit/Material*</exclude>
</excludes>
</configuration>
<executions>

View File

@ -24,7 +24,6 @@ import world.bentobox.level.calculators.Pipeliner;
import world.bentobox.level.commands.AdminLevelCommand;
import world.bentobox.level.commands.AdminLevelStatusCommand;
import world.bentobox.level.commands.AdminSetInitialLevelCommand;
import world.bentobox.level.commands.AdminStatsCommand;
import world.bentobox.level.commands.AdminTopCommand;
import world.bentobox.level.commands.IslandLevelCommand;
import world.bentobox.level.commands.IslandTopCommand;
@ -40,6 +39,7 @@ import world.bentobox.level.requests.TopTenRequestHandler;
import world.bentobox.visit.VisitAddon;
import world.bentobox.warps.Warp;
/**
* @author tastybento
*
@ -71,6 +71,7 @@ public class Level extends Addon {
*/
private VisitAddon visitHook;
@Override
public void onLoad() {
// Save the default config from config.yml
@ -111,7 +112,8 @@ public class Level extends Addon {
// Register commands for GameModes
registeredGameModes.clear();
getPlugin().getAddonsManager().getGameModeAddons().stream()
.filter(gm -> !settings.getGameModes().contains(gm.getDescription().getName())).forEach(gm -> {
.filter(gm -> !settings.getGameModes().contains(gm.getDescription().getName()))
.forEach(gm -> {
log("Level hooking into " + gm.getDescription().getName());
registerCommands(gm);
new PlaceholderManager(this).registerPlaceholders(gm);
@ -124,15 +126,11 @@ public class Level extends Addon {
// Check if WildStackers is enabled on the server
// I only added support for counting blocks into the island level
// Someone else can PR if they want spawners added to the Leveling system :)
if (!settings.getDisabledPluginHooks().contains("WildStacker")) {
stackersEnabled = Bukkit.getPluginManager().isPluginEnabled("WildStacker");
if (stackersEnabled) {
log("Hooked into WildStackers.");
}
}
// Check if AdvancedChests is enabled on the server
if (!settings.getDisabledPluginHooks().contains("AdvancedChests")) {
Plugin advChest = Bukkit.getPluginManager().getPlugin("AdvancedChests");
advChestEnabled = advChest != null;
if (advChestEnabled) {
@ -140,59 +138,58 @@ public class Level extends Addon {
if (compareVersions(advChest.getDescription().getVersion(), "23.0") > 0) {
log("Hooked into AdvancedChests.");
} else {
logError("Could not hook into AdvancedChests " + advChest.getDescription().getVersion()
+ " - requires version 23.0 or later");
logError("Could not hook into AdvancedChests " + advChest.getDescription().getVersion() + " - requires version 23.0 or later");
advChestEnabled = false;
}
}
}
// Check if RoseStackers is enabled
if (!settings.getDisabledPluginHooks().contains("RoseStacker")) {
roseStackersEnabled = Bukkit.getPluginManager().isPluginEnabled("RoseStacker");
if (roseStackersEnabled) {
log("Hooked into RoseStackers.");
}
}
// Check if UltimateStacker is enabled
if (!settings.getDisabledPluginHooks().contains("UltimateStacker")) {
ultimateStackerEnabled = Bukkit.getPluginManager().isPluginEnabled("UltimateStacker");
if (ultimateStackerEnabled) {
log("Hooked into UltimateStacker.");
}
}
}
@Override
public void allLoaded() {
public void allLoaded()
{
super.allLoaded();
if (this.isEnabled()) {
if (this.isEnabled())
{
this.hookExtensions();
}
}
/**
* This method tries to hook into addons and plugins
*/
private void hookExtensions() {
private void hookExtensions()
{
// Try to find Visit addon and if it does not exist, display a warning
this.getAddonByName("Visit").ifPresentOrElse(addon -> {
this.getAddonByName("Visit").ifPresentOrElse(addon ->
{
this.visitHook = (VisitAddon) addon;
this.log("Level Addon hooked into Visit addon.");
}, () -> this.visitHook = null);
// Try to find Warps addon and if it does not exist, display a warning
this.getAddonByName("Warps").ifPresentOrElse(addon -> {
this.getAddonByName("Warps").ifPresentOrElse(addon ->
{
this.warpHook = (Warp) addon;
this.log("Level Addon hooked into Warps addon.");
}, () -> this.warpHook = null);
}
/**
* Compares versions
*
* @param version1 version 1
* @param version2 version 2
* @return {@code <0 if version 1 is older than version 2, =0 if the same, >0 if version 1 is newer than version 2}
@ -224,7 +221,6 @@ public class Level extends Addon {
if (getSettings().isZeroNewIslandLevels()) {
new AdminSetInitialLevelCommand(this, adminCommand);
}
new AdminStatsCommand(this, adminCommand);
});
gm.getPlayerCommand().ifPresent(playerCmd -> {
new IslandLevelCommand(this, playerCmd);
@ -257,6 +253,7 @@ public class Level extends Addon {
}
/**
* @return the blockConfig
*/
@ -287,7 +284,6 @@ public class Level extends Addon {
/**
* Set the config settings - used for tests only
*
* @param configSettings - config settings
*/
void setSettings(ConfigSettings configSettings) {
@ -311,7 +307,6 @@ public class Level extends Addon {
/**
* Get level from cache for a player.
*
* @param targetPlayer - target player UUID
* @return Level of player or zero if player is unknown or UUID is null
*/
@ -321,7 +316,6 @@ public class Level extends Addon {
/**
* Sets the player's level to a value
*
* @param world - world
* @param targetPlayer - target player
* @param level - level
@ -332,7 +326,6 @@ public class Level extends Addon {
/**
* Zeros the initial island level
*
* @param island - island
* @param level - initial calculated island level
*/
@ -342,7 +335,6 @@ public class Level extends Addon {
/**
* Get the initial island level
*
* @param island - island
* @return level or 0 by default
*/
@ -352,23 +344,19 @@ public class Level extends Addon {
/**
* Calculates a user's island
*
* @param world - the world where this island is
* @param user - not used! See depecration message
* @param playerUUID - the target island member's UUID
* @deprecated Do not use this anymore. Use
* getManager().calculateLevel(playerUUID, island)
* @deprecated Do not use this anymore. Use getManager().calculateLevel(playerUUID, island)
*/
@Deprecated(since="2.3.0", forRemoval=true)
public void calculateIslandLevel(World world, @Nullable User user, @NonNull UUID playerUUID) {
Island island = getIslands().getIsland(world, playerUUID);
if (island != null)
getManager().calculateLevel(playerUUID, island);
if (island != null) getManager().calculateLevel(playerUUID, island);
}
/**
* Provide the levels data for the target player
*
* @param targetPlayer - UUID of target player
* @return LevelsData object or null if not found. Only island levels are set!
* @deprecated Do not use this anymore. Use {@link #getIslandLevel(World, UUID)}
@ -377,7 +365,8 @@ public class Level extends Addon {
public LevelsData getLevelsData(UUID targetPlayer) {
LevelsData ld = new LevelsData(targetPlayer);
getPlugin().getAddonsManager().getGameModeAddons().stream()
.filter(gm -> !settings.getGameModes().contains(gm.getDescription().getName())).forEach(gm -> {
.filter(gm -> !settings.getGameModes().contains(gm.getDescription().getName()))
.forEach(gm -> {
if (getSettings().isZeroNewIslandLevels()) {
Island island = getIslands().getIsland(gm.getOverWorld(), targetPlayer);
if (island != null) {
@ -398,7 +387,6 @@ public class Level extends Addon {
/**
* Check if Level addon is active in game mode
*
* @param gm Game Mode Addon
* @return true if active, false if not
*/
@ -408,7 +396,6 @@ public class Level extends Addon {
/**
* Checks if Level addon is active in world
*
* @param world world
* @return true if active, false if not
*/
@ -435,7 +422,8 @@ public class Level extends Addon {
*
* @return {@code Visit} of this object, {@code null} otherwise.
*/
public VisitAddon getVisitHook() {
public VisitAddon getVisitHook()
{
return this.visitHook;
}
@ -444,8 +432,8 @@ public class Level extends Addon {
*
* @return {@code Warp} of this object, {@code null} otherwise.
*/
public Warp getWarpHook() {
public Warp getWarpHook()
{
return this.warpHook;
}
}

View File

@ -9,14 +9,8 @@ import world.bentobox.bentobox.api.addons.Pladdon;
*
*/
public class LevelPladdon extends Pladdon {
private Addon addon;
@Override
public Addon getAddon() {
if (addon == null) {
addon = new Level();
}
return addon;
return new Level();
}
}

View File

@ -2,8 +2,6 @@ package world.bentobox.level;
import java.math.BigInteger;
import java.text.DecimalFormat;
import java.time.Instant;
import java.util.AbstractMap;
import java.util.Collections;
import java.util.HashMap;
import java.util.LinkedHashMap;
@ -32,12 +30,20 @@ import world.bentobox.level.events.IslandPreLevelEvent;
import world.bentobox.level.objects.IslandLevels;
import world.bentobox.level.objects.LevelsData;
import world.bentobox.level.objects.TopTenData;
import world.bentobox.level.util.CachedData;
public class LevelsManager {
private static final String INTOPTEN = "intopten";
private static final TreeMap<BigInteger, String> LEVELS = new TreeMap<>();
private static final TreeMap<BigInteger, String> LEVELS;
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;
// Database handler for level data
@ -46,8 +52,7 @@ public class LevelsManager {
private final Map<String, IslandLevels> levelsCache;
// Top ten lists
private final Map<World,TopTenData> topTenLists;
// Cache for top tens
private Map<World, CachedData> cache = new HashMap<>();
public LevelsManager(Level addon) {
this.addon = addon;
@ -59,12 +64,6 @@ public class LevelsManager {
levelsCache = new HashMap<>();
// Initialize top ten lists
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() {
@ -77,7 +76,8 @@ public class LevelsManager {
// World
.map(Bukkit::getWorld).filter(Objects::nonNull)
// 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
World w = i.getWorld();
IslandLevels il = new IslandLevels(i.getUniqueId());
@ -99,27 +99,43 @@ public class LevelsManager {
});
}
/**
* Add a score to the top players list
* @param world - world
* @param targetPlayer - target player
* @param lv - island level
*/
private void addToTopTen(@NonNull World world, @NonNull UUID targetPlayer, long lv) {
// Get top ten
Map<UUID, Long> topTen = topTenLists.computeIfAbsent(world, k -> new TopTenData(world)).getTopTen();
// Remove this player from the top list no matter what (we'll put them back later if required)
topTen.remove(targetPlayer);
// Get the island
Island island = addon.getIslands().getIsland(world, targetPlayer);
if (island != null && island.getOwner() != null && hasTopTenPerm(world, island.getOwner())) {
// Insert the owner into the top ten
topTen.put(island.getOwner(), lv);
}
}
/**
* Add an island to a top ten
*
* @param island - island to add
* @param lv - level
* @return true if successful, false if not added
*/
private boolean addToTopTen(Island island, long lv) {
if (island != null && island.getOwner() != null && island.getWorld() != null
&& hasTopTenPerm(island.getWorld(), island.getOwner())) {
topTenLists.computeIfAbsent(island.getWorld(), k -> new TopTenData(island.getWorld())).getTopTen()
.put(island.getUniqueId(), lv);
if (island != null && island.getOwner() != null && hasTopTenPerm(island.getWorld(), island.getOwner())) {
topTenLists.computeIfAbsent(island.getWorld(), k -> new TopTenData(island.getWorld()))
.getTopTen().put(island.getOwner(), lv);
return true;
}
return false;
}
/**
* Calculate the island level, set all island member's levels to the result and
* try to add the owner to the top ten
*
* Calculate the island level, set all island member's levels to the result and try to add the owner to the top ten
* @param targetPlayer - uuid of targeted player - owner or team member
* @param island - island to calculate
* @return completable future with the results of the calculation
@ -134,13 +150,12 @@ public class LevelsManager {
}
// Add island to the pipeline
addon.getPipeliner().addIsland(island).thenAccept(r -> {
// Results are irrelevant because the island is unowned or deleted, or
// IslandLevelCalcEvent is cancelled
// Results are irrelevant because the island is unowned or deleted, or IslandLevelCalcEvent is cancelled
if (r == null || fireIslandLevelCalcEvent(targetPlayer, island, r)) {
result.complete(null);
}
// Save result
setIslandResults(island, r);
setIslandResults(island.getWorld(), island.getOwner(), r);
// Save the island scan details
result.complete(r);
});
@ -149,7 +164,6 @@ public class LevelsManager {
/**
* Fires the IslandLevelCalculatedEvent and returns true if it is canceled
*
* @param targetPlayer - target player
* @param island - island
* @param results - results set
@ -159,28 +173,23 @@ public class LevelsManager {
// Fire post calculation event
IslandLevelCalculatedEvent ilce = new IslandLevelCalculatedEvent(targetPlayer, island, results);
Bukkit.getPluginManager().callEvent(ilce);
if (ilce.isCancelled())
return true;
if (ilce.isCancelled()) return true;
// Set the values if they were altered
results.setLevel((Long)ilce.getKeyValues().getOrDefault("level", results.getLevel()));
results.setInitialLevel((Long)ilce.getKeyValues().getOrDefault("initialLevel", results.getInitialLevel()));
results.setDeathHandicap((int)ilce.getKeyValues().getOrDefault("deathHandicap", results.getDeathHandicap()));
results.setPointsToNextLevel(
(Long) ilce.getKeyValues().getOrDefault("pointsToNextLevel", results.getPointsToNextLevel()));
results.setPointsToNextLevel((Long)ilce.getKeyValues().getOrDefault("pointsToNextLevel", results.getPointsToNextLevel()));
results.setTotalPoints((Long)ilce.getKeyValues().getOrDefault("totalPoints", results.getTotalPoints()));
return ((Boolean)ilce.getKeyValues().getOrDefault("isCancelled", false));
}
/**
* Get the string representation of the level. May be converted to shorthand
* notation, e.g., 104556 = 10.5k
*
* Get the string representation of the level. May be converted to shorthand notation, e.g., 104556 = 10.5k
* @param lvl - long value to represent
* @return string of the level.
*/
public String formatLevel(@Nullable Long lvl) {
if (lvl == null)
return "";
if (lvl == null) return "";
String level = String.valueOf(lvl);
// Asking for the level of another player
if(addon.getSettings().isShorthand()) {
@ -193,8 +202,7 @@ public class LevelsManager {
// 1 527 314 -> 1.5M
// 3 874 130 021 -> 3.8G
// 4 002 317 889 -> 4.0T
level = new DecimalFormat("#.#").format(
levelValue.divide(stage.getKey().divide(THOUSAND)).doubleValue() / 1000.0) + stage.getValue();
level = new DecimalFormat("#.#").format(levelValue.divide(stage.getKey().divide(THOUSAND)).doubleValue()/1000.0) + stage.getValue();
}
}
return level;
@ -202,7 +210,6 @@ public class LevelsManager {
/**
* Get the initial level of the island. Used to zero island levels
*
* @param island - island
* @return initial level of island
*/
@ -212,48 +219,25 @@ public class LevelsManager {
/**
* Get level of island from cache for a player.
*
* @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
* @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) {
return getIslandLevel(world, targetPlayer, false);
}
/**
* Get level of island from cache for a player.
*
* @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;
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();
return island == null ? 0L : getLevelsData(island).getLevel();
}
/**
* Get the maximum level ever given to this island
*
* @param world - world where the island is
* @param targetPlayer - target player UUID
* @return Max level of the player's island or zero if player is unknown or UUID
* is null
* @return Max level of the player's island or zero if player is unknown or UUID is null
*/
public long getIslandMaxLevel(@NonNull World world, @Nullable UUID targetPlayer) {
if (targetPlayer == null)
return 0L;
if (targetPlayer == null) return 0L;
// Get the island
Island island = addon.getIslands().getIsland(world, targetPlayer);
return island == null ? 0L : getLevelsData(island).getMaxLevel();
@ -261,11 +245,9 @@ public class LevelsManager {
/**
* Returns a formatted string of the target player's island level
*
* @param world - world where the island is
* @param targetPlayer - target player's UUID
* @return Formatted level of player or zero if player is unknown or UUID is
* null
* @return Formatted level of player or zero if player is unknown or UUID is null
*/
public String getIslandLevelString(@NonNull World world, @Nullable UUID targetPlayer) {
return formatLevel(getIslandLevel(world, targetPlayer));
@ -273,7 +255,6 @@ public class LevelsManager {
/**
* Load a level data for the island from the cache or database.
*
* @param island - UUID of island
* @return IslandLevels object
*/
@ -300,125 +281,72 @@ public class LevelsManager {
}
/**
* Get the number of points required until the next level since the last level
* calc
*
* Get the number of points required until the next level since the last level calc
* @param world - world where the island is
* @param targetPlayer - target player UUID
* @return string with the number required or blank if the player is unknown
*/
public String getPointsToNextString(@NonNull World world, @Nullable UUID targetPlayer) {
if (targetPlayer == null)
return "";
if (targetPlayer == null) return "";
Island island = addon.getIslands().getIsland(world, targetPlayer);
return island == null ? "" : String.valueOf(getLevelsData(island).getPointsToNextLevel());
}
/**
* Get the weighted top ten for this world. Weighting is based on number of
* players per team.
*
* Get the top ten for this world. Returns offline players or players with the intopten permission.
* @param world - world requested
* @param size - size of the top ten
* @return sorted top ten map. The key is the island unique ID
* @return sorted top ten map
*/
@NonNull
public Map<Island, Long> getWeightedTopTen(@NonNull World world, int size) {
public Map<UUID, Long> getTopTen(@NonNull World world, int size) {
createAndCleanRankings(world);
Map<Island, Long> weightedTopTen = topTenLists.get(world).getTopTen().entrySet().stream()
.map(en -> addon.getIslands().getIslandById(en.getKey()).map(island -> {
long value = (long) (en.getValue() / (double) Math.max(1, island.getMemberSet().size())); // Calculate
// weighted
// value
return new AbstractMap.SimpleEntry<>(island, value);
}).orElse(null)) // Handle islands that do not exist according to this ID - old deleted ones
.filter(Objects::nonNull) // Filter out null entries
.filter(en -> en.getValue() > 0) // Filter out entries with non-positive values
.sorted(Collections.reverseOrder(Map.Entry.comparingByValue())) // Sort in descending order of values
.limit(size) // Limit to the top 'size' entries
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue, (e1, e2) -> e1, // In case of key
// collision, choose
// the first one
LinkedHashMap::new // Preserves the order of entries
));
// Return the unmodifiable map
return Collections.unmodifiableMap(weightedTopTen);
}
/**
* Get the top ten for this world. Returns offline players or players with the
* intopten permission.
*
* @param world - world requested
* @param size - size of the top ten
* @return sorted top ten map. The key is the island unique ID
*/
@NonNull
public Map<String, Long> getTopTen(@NonNull World world, int size) {
createAndCleanRankings(world);
CachedData cachedData = cache.get(world);
Instant now = Instant.now();
if (cachedData != null && cachedData.getLastUpdated().plusSeconds(1).isAfter(now)) {
return cachedData.getCachedMap();
} else {
Map<String, Long> newTopTen = calculateTopTen(world, size);
cache.put(world, new CachedData(newTopTen, now));
return newTopTen;
}
}
private Map<String, Long> calculateTopTen(@NonNull World world, int size) {
// Return the sorted map
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)));
.filter(e -> addon.getIslands().isOwner(world, e.getKey()))
.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) {
topTenLists.computeIfAbsent(world, TopTenData::new);
// Remove player from top ten if they are online and do not have the perm
topTenLists.get(world).getTopTen().keySet().removeIf(u -> addon.getIslands().getIslandById(u)
.filter(i -> i.getOwner() == null || !hasTopTenPerm(world, i.getOwner())).isPresent());
topTenLists.get(world).getTopTen().keySet().removeIf(u -> !hasTopTenPerm(world, u));
}
/**
* @return the topTenLists
*/
public Map<World, TopTenData> getTopTenLists() {
protected Map<World, TopTenData> getTopTenLists() {
return topTenLists;
}
/**
* Get the rank of the player in the rankings
*
* @param world - world
* @param uuid - player UUID
* @return rank placing - note - placing of 1 means top ranked
*/
public int getRank(@NonNull World world, UUID uuid) {
createAndCleanRankings(world);
Stream<Entry<String, Long>> stream = topTenLists.get(world).getTopTen().entrySet().stream()
.filter(l -> l.getValue() > 0).sorted(Collections.reverseOrder(Map.Entry.comparingByValue()));
// Get player's current island
Island island = addon.getIslands().getIsland(world, uuid);
String id = island == null ? null : island.getUniqueId();
return (int) (stream.takeWhile(x -> !x.getKey().equals(id)).map(Map.Entry::getKey).count() + 1);
Stream<Entry<UUID, Long>> stream = topTenLists.get(world).getTopTen().entrySet().stream()
.filter(e -> addon.getIslands().isOwner(world, e.getKey()))
.filter(l -> l.getValue() > 0)
.sorted(Collections.reverseOrder(Map.Entry.comparingByValue()));
return (int) (stream.takeWhile(x -> !x.getKey().equals(uuid)).map(Map.Entry::getKey).count() + 1);
}
/**
* Checks if player has the correct top ten perm to have their level saved
*
* @param world
* @param targetPlayer
* @return true if player has the perm or the player is offline
*/
boolean hasTopTenPerm(@NonNull World world, @NonNull UUID targetPlayer) {
String permPrefix = addon.getPlugin().getIWM().getPermissionPrefix(world);
return Bukkit.getPlayer(targetPlayer) == null
|| Bukkit.getPlayer(targetPlayer).hasPermission(permPrefix + INTOPTEN);
return Bukkit.getPlayer(targetPlayer) == null || Bukkit.getPlayer(targetPlayer).hasPermission(permPrefix + INTOPTEN);
}
/**
@ -430,9 +358,7 @@ public class LevelsManager {
addon.log("Generating rankings");
handler.loadObjects().forEach(il -> {
if (il.getLevel() > 0) {
// Load islands, but don't cache them
addon.getIslands().getIslandById(il.getUniqueId(), false)
.ifPresent(i -> this.addToTopTen(i, il.getLevel()));
addon.getIslands().getIslandById(il.getUniqueId()).ifPresent(i -> this.addToTopTen(i, il.getLevel()));
}
});
topTenLists.keySet().forEach(w -> addon.log("Generated rankings for " + w.getName()));
@ -440,38 +366,32 @@ public class LevelsManager {
}
/**
* Removes an island from a world's top ten
*
* Removes a player from a world's top ten and removes world from player's level data
* @param world - world
* @param uuid - the island's uuid
* @param uuid - the player's uuid
*/
public void removeEntry(World world, String uuid) {
public void removeEntry(World world, UUID uuid) {
if (topTenLists.containsKey(world)) {
topTenLists.get(world).getTopTen().remove(uuid);
// Invalidate the cache because of this deletion
cache.remove(world);
}
}
/**
* Set an initial island level
*
* @param island - the island to set. Must have a non-null world
* @param lv - initial island level
*/
public void setInitialIslandLevel(@NonNull Island island, long lv) {
if (island.getWorld() == null)
return;
if (island.getWorld() == null) return;
levelsCache.computeIfAbsent(island.getUniqueId(), IslandLevels::new).setInitialLevel(lv);
handler.saveObjectAsync(levelsCache.get(island.getUniqueId()));
}
/**
* Set the island level for the owner of the island that targetPlayer is a
* member
*
* Set the island level for the owner of the island that targetPlayer is a member
* @param world - world
* @param island - island
* @param targetPlayer - player, may be a team member
* @param lv - level
*/
public void setIslandLevel(@NonNull World world, @NonNull UUID targetPlayer, long lv) {
@ -488,21 +408,21 @@ public class LevelsManager {
}
handler.saveObjectAsync(levelsCache.get(id));
// Update TopTen
addToTopTen(island, levelsCache.get(id).getLevel());
addToTopTen(world, targetPlayer, levelsCache.get(id).getLevel());
}
}
/**
* Set the island level for the owner of the island that targetPlayer is a
* member
*
* Set the island level for the owner of the island that targetPlayer is a member
* @param world - world
* @param owner - owner of the island
* @param r - results of the calculation
*/
private void setIslandResults(Island island, Results r) {
if (island == null)
return;
private void setIslandResults(World world, @NonNull UUID owner, Results r) {
// Get the island
Island island = addon.getIslands().getIsland(world, owner);
if (island == null) return;
IslandLevels ld = levelsCache.computeIfAbsent(island.getUniqueId(), IslandLevels::new);
ld.setLevel(r.getLevel());
ld.setUwCount(Maps.asMap(r.getUwCount().elementSet(), elem -> r.getUwCount().count(elem)));
@ -512,12 +432,11 @@ public class LevelsManager {
levelsCache.put(island.getUniqueId(), ld);
handler.saveObjectAsync(ld);
// Update TopTen
addToTopTen(island, ld.getLevel());
addToTopTen(world, owner, ld.getLevel());
}
/**
* Removes island from cache when it is deleted
*
* @param uniqueId - id of island
*/
public void deleteIsland(String uniqueId) {

View File

@ -2,12 +2,10 @@ package world.bentobox.level;
import java.util.Collections;
import java.util.Map;
import java.util.Optional;
import java.util.UUID;
import java.util.stream.Collectors;
import org.bukkit.World;
import org.eclipse.jdt.annotation.Nullable;
import world.bentobox.bentobox.BentoBox;
import world.bentobox.bentobox.api.addons.GameModeAddon;
@ -20,7 +18,6 @@ import world.bentobox.level.objects.TopTenData;
/**
* Handles Level placeholders
*
* @author tastybento
*
*/
@ -35,164 +32,127 @@ public class PlaceholderManager {
}
protected void registerPlaceholders(GameModeAddon gm) {
if (plugin.getPlaceholdersManager() == null)
return;
if (plugin.getPlaceholdersManager() == null) return;
PlaceholdersManager bpm = plugin.getPlaceholdersManager();
// 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()));
// Island Level owner only
bpm.registerPlaceholder(addon, gm.getDescription().getName().toLowerCase() + "_island_level_owner",
user -> String.valueOf(addon.getManager().getIslandLevel(gm.getOverWorld(), user.getUniqueId(), true)));
// Unformatted island level
bpm.registerPlaceholder(addon, gm.getDescription().getName().toLowerCase() + "_island_level_raw",
bpm.registerPlaceholder(addon,
gm.getDescription().getName().toLowerCase() + "_island_level_raw",
user -> String.valueOf(addon.getManager().getIslandLevel(gm.getOverWorld(), user.getUniqueId())));
// Total number of points counted before applying level formula
bpm.registerPlaceholder(addon, gm.getDescription().getName().toLowerCase() + "_island_total_points", user -> {
bpm.registerPlaceholder(addon,
gm.getDescription().getName().toLowerCase() + "_island_total_points",
user -> {
IslandLevels data = addon.getManager().getLevelsData(addon.getIslands().getIsland(gm.getOverWorld(), user));
return data.getTotalPoints()+"";
});
// Points to the next level for player
bpm.registerPlaceholder(addon, gm.getDescription().getName().toLowerCase() + "_points_to_next_level",
bpm.registerPlaceholder(addon,
gm.getDescription().getName().toLowerCase() + "_points_to_next_level",
user -> addon.getManager().getPointsToNextString(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",
bpm.registerPlaceholder(addon,
gm.getDescription().getName().toLowerCase() + "_island_level_max",
user -> String.valueOf(addon.getManager().getIslandMaxLevel(gm.getOverWorld(), user.getUniqueId())));
// Visited Island Level
bpm.registerPlaceholder(addon, gm.getDescription().getName().toLowerCase() + "_visited_island_level",
user -> getVisitedIslandLevel(gm, user));
bpm.registerPlaceholder(addon,
gm.getDescription().getName().toLowerCase() + "_visited_island_level", user -> getVisitedIslandLevel(gm, user));
// Register Top Ten Placeholders
for (int i = 1; i < 11; i++) {
final int rank = i;
// Name
bpm.registerPlaceholder(addon, gm.getDescription().getName().toLowerCase() + "_top_name_" + i,
u -> getRankName(gm.getOverWorld(), rank, false));
// Island Name
bpm.registerPlaceholder(addon, gm.getDescription().getName().toLowerCase() + "_top_island_name_" + i,
u -> getRankIslandName(gm.getOverWorld(), rank, false));
// Members
bpm.registerPlaceholder(addon, gm.getDescription().getName().toLowerCase() + "_top_members_" + i,
u -> getRankMembers(gm.getOverWorld(), rank, false));
// Level
bpm.registerPlaceholder(addon, gm.getDescription().getName().toLowerCase() + "_top_value_" + i,
u -> getRankLevel(gm.getOverWorld(), rank, false));
// Weighted Level Name (Level / number of members)
bpm.registerPlaceholder(addon, gm.getDescription().getName().toLowerCase() + "_top_weighted_name_" + i,
u -> getRankName(gm.getOverWorld(), rank, true));
// Weighted Island Name
bpm.registerPlaceholder(addon,
gm.getDescription().getName().toLowerCase() + "_top_weighted_island_name_" + i,
u -> getRankIslandName(gm.getOverWorld(), rank, true));
// Weighted Members
bpm.registerPlaceholder(addon, gm.getDescription().getName().toLowerCase() + "_top_weighted_members_" + i,
u -> getRankMembers(gm.getOverWorld(), rank, true));
// Weighted Level (Level / number of members)
bpm.registerPlaceholder(addon, gm.getDescription().getName().toLowerCase() + "_top_weighted_value_" + i,
u -> getRankLevel(gm.getOverWorld(), rank, true));
gm.getDescription().getName().toLowerCase() + "_top_name_" + i, u -> getRankName(gm.getOverWorld(), rank));
// Island Name
bpm.registerPlaceholder(addon,
gm.getDescription().getName().toLowerCase() + "_top_island_name_" + i, u -> getRankIslandName(gm.getOverWorld(), rank));
// Members
bpm.registerPlaceholder(addon,
gm.getDescription().getName().toLowerCase() + "_top_members_" + i, u -> getRankMembers(gm.getOverWorld(), rank));
// Level
bpm.registerPlaceholder(addon,
gm.getDescription().getName().toLowerCase() + "_top_value_" + i, u -> getRankLevel(gm.getOverWorld(), rank));
}
// Personal rank
bpm.registerPlaceholder(addon, gm.getDescription().getName().toLowerCase() + "_rank_value",
u -> getRankValue(gm.getOverWorld(), u));
bpm.registerPlaceholder(addon,
gm.getDescription().getName().toLowerCase() + "_rank_value", u -> getRankValue(gm.getOverWorld(), u));
}
/**
* Get the name of the owner of the island who holds the rank in this world.
*
* Get the name of the player who holds the rank in this world
* @param world world
* @param rank rank 1 to 10
* @param weighted if true, then the weighted rank name is returned
* @return rank name
*/
String getRankName(World world, int rank, boolean weighted) {
// Ensure rank is within bounds
rank = Math.max(1, Math.min(rank, Level.TEN));
if (weighted) {
return addon.getManager().getWeightedTopTen(world, Level.TEN).keySet().stream().skip(rank - 1L).limit(1L)
.findFirst().map(Island::getOwner).map(addon.getPlayers()::getName).orElse("");
}
@Nullable
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);
return addon.getPlayers().getName(owner);
String getRankName(World world, int rank) {
if (rank < 1) rank = 1;
if (rank > Level.TEN) rank = Level.TEN;
return addon.getPlayers().getName(addon.getManager().getTopTen(world, Level.TEN).keySet().stream().skip(rank - 1L).limit(1L).findFirst().orElse(null));
}
/**
* Get the island name for this rank
*
* @param world world
* @param rank rank 1 to 10
* @param weighted if true, then the weighted rank name is returned
* @return name of island or nothing if there isn't one
*/
String getRankIslandName(World world, int rank, boolean weighted) {
// Ensure rank is within bounds
rank = Math.max(1, Math.min(rank, Level.TEN));
if (weighted) {
return addon.getManager().getWeightedTopTen(world, Level.TEN).keySet().stream().skip(rank - 1L).limit(1L)
.findFirst().map(Island::getName).orElse("");
String getRankIslandName(World world, int rank) {
if (rank < 1) rank = 1;
if (rank > Level.TEN) rank = Level.TEN;
UUID owner = addon.getManager().getTopTen(world, Level.TEN).keySet().stream().skip(rank - 1L).limit(1L).findFirst().orElse(null);
if (owner != null) {
Island island = addon.getIslands().getIsland(world, owner);
if (island != null) {
return island.getName() == null ? "" : island.getName();
}
return addon.getManager().getTopTen(world, Level.TEN).keySet().stream().skip(rank - 1L).limit(1L).findFirst()
.flatMap(addon.getIslands()::getIslandById).map(Island::getName).orElse("");
}
/**
* Gets a comma separated string of island member names
*
* @param world world
* @param rank rank to request
* @param weighted if true, then the weighted rank name is returned
* @return comma separated string of island member names
*/
String getRankMembers(World world, int rank, boolean weighted) {
// Ensure rank is within bounds
rank = Math.max(1, Math.min(rank, Level.TEN));
if (weighted) {
return addon.getManager().getWeightedTopTen(world, Level.TEN).keySet().stream().skip(rank - 1L).limit(1L)
.findFirst()
.map(is -> is.getMembers().entrySet().stream().filter(e -> e.getValue() >= RanksManager.MEMBER_RANK)
.sorted(Collections.reverseOrder(Map.Entry.comparingByValue())).map(Map.Entry::getKey)
.map(addon.getPlayers()::getName).collect(Collectors.joining(",")))
.orElse("");
}
Optional<Island> island = addon.getManager().getTopTen(world, Level.TEN).keySet().stream().skip(rank - 1L)
.limit(1L).findFirst().flatMap(addon.getIslands()::getIslandById);
if (island.isPresent()) {
// Sort members by rank
return island.get().getMembers().entrySet().stream().filter(e -> e.getValue() >= RanksManager.MEMBER_RANK)
.sorted(Collections.reverseOrder(Map.Entry.comparingByValue())).map(Map.Entry::getKey)
.map(addon.getPlayers()::getName).collect(Collectors.joining(","));
}
return "";
}
/**
* Get the level for the rank requested
*
* Gets a comma separated string of island member names
* @param world world
* @param rank rank wanted
* @param weighted true if weighted (level/number of team members)
* @return level for the rank requested
* @param rank rank to request
* @return comma separated string of island member names
*/
String getRankLevel(World world, int rank, boolean weighted) {
// Ensure rank is within bounds
rank = Math.max(1, Math.min(rank, Level.TEN));
if (weighted) {
return addon.getManager().formatLevel(addon.getManager().getWeightedTopTen(world, Level.TEN).values()
.stream().skip(rank - 1L).limit(1L).findFirst().orElse(null));
String getRankMembers(World world, int rank) {
if (rank < 1) rank = 1;
if (rank > Level.TEN) rank = Level.TEN;
UUID owner = addon.getManager().getTopTen(world, Level.TEN).keySet().stream().skip(rank - 1L).limit(1L).findFirst().orElse(null);
if (owner != null) {
Island island = addon.getIslands().getIsland(world, owner);
if (island != null) {
// Sort members by rank
return island.getMembers().entrySet().stream()
.filter(e -> e.getValue() >= RanksManager.MEMBER_RANK)
.sorted(Collections.reverseOrder(Map.Entry.comparingByValue()))
.map(Map.Entry::getKey)
.map(addon.getPlayers()::getName)
.collect(Collectors.joining(","));
}
return addon.getManager().formatLevel(addon.getManager().getTopTen(world, Level.TEN).values().stream()
.skip(rank - 1L).limit(1L).findFirst().orElse(null));
}
return "";
}
String getRankLevel(World world, int rank) {
if (rank < 1) rank = 1;
if (rank > Level.TEN) rank = Level.TEN;
return addon.getManager()
.formatLevel(addon.getManager()
.getTopTen(world, Level.TEN)
.values()
.stream()
.skip(rank - 1L)
.limit(1L)
.findFirst()
.orElse(null));
}
/**
* Return the rank of the player in a world
*
* @param world world
* @param user player
* @return rank where 1 is the top rank.
@ -203,13 +163,11 @@ public class PlaceholderManager {
}
// Get the island level for this user
long level = addon.getManager().getIslandLevel(world, user.getUniqueId());
return String.valueOf(addon.getManager().getTopTenLists().getOrDefault(world, new TopTenData(world)).getTopTen()
.values().stream().filter(l -> l > level).count() + 1);
return String.valueOf(addon.getManager().getTopTenLists().getOrDefault(world, new TopTenData(world)).getTopTen().values().stream().filter(l -> l > level).count() + 1);
}
String getVisitedIslandLevel(GameModeAddon gm, User user) {
if (user == null || !gm.inWorld(user.getWorld()))
return "";
if (user == null || !gm.inWorld(user.getWorld())) return "";
return addon.getIslands().getIslandAt(user.getLocation())
.map(island -> addon.getManager().getIslandLevelString(gm.getOverWorld(), island.getOwner()))
.orElse("0");

View File

@ -1,121 +0,0 @@
package world.bentobox.level.calculators;
import java.text.ParseException;
/**
* Utility class to evaluate equations
*/
public class EquationEvaluator {
private static class Parser {
private final String input;
private int pos = -1;
private int currentChar;
@SuppressWarnings("unused")
private Parser() {
throw new IllegalStateException("Utility class");
}
public Parser(String input) {
this.input = input;
moveToNextChar();
}
private void moveToNextChar() {
currentChar = (++pos < input.length()) ? input.charAt(pos) : -1;
}
private boolean tryToEat(int charToEat) {
while (currentChar == ' ') {
moveToNextChar();
}
if (currentChar == charToEat) {
moveToNextChar();
return true;
}
return false;
}
public double evaluate() throws ParseException {
double result = parseExpression();
if (pos < input.length()) {
throw new ParseException("Unexpected character: " + (char) currentChar, pos);
}
return result;
}
private double parseExpression() throws ParseException {
double result = parseTerm();
while (true) {
if (tryToEat('+')) {
result += parseTerm();
} else if (tryToEat('-')) {
result -= parseTerm();
} else {
return result;
}
}
}
private double parseFactor() throws ParseException {
if (tryToEat('+')) {
return parseFactor(); // unary plus
}
if (tryToEat('-')) {
return -parseFactor(); // unary minus
}
double x;
int startPos = this.pos;
if (tryToEat('(')) { // parentheses
x = parseExpression();
tryToEat(')');
} else if ((currentChar >= '0' && currentChar <= '9') || currentChar == '.') { // numbers
while ((currentChar >= '0' && currentChar <= '9') || currentChar == '.') {
moveToNextChar();
}
x = Double.parseDouble(input.substring(startPos, this.pos));
} else if (currentChar >= 'a' && currentChar <= 'z') { // functions
while (currentChar >= 'a' && currentChar <= 'z') {
moveToNextChar();
}
String func = input.substring(startPos, this.pos);
x = parseFactor();
x = switch (func) {
case "sqrt" -> Math.sqrt(x);
case "sin" -> Math.sin(Math.toRadians(x));
case "cos" -> Math.cos(Math.toRadians(x));
case "tan" -> Math.tan(Math.toRadians(x));
case "log" -> Math.log(x);
default -> throw new ParseException("Unknown function: " + func, startPos);
};
} else {
throw new ParseException("Unexpected: " + (char) currentChar, startPos);
}
if (tryToEat('^')) {
x = Math.pow(x, parseFactor()); // exponentiation
}
return x;
}
private double parseTerm() throws ParseException {
double x = parseFactor();
for (;;) {
if (tryToEat('*'))
x *= parseFactor(); // multiplication
else if (tryToEat('/'))
x /= parseFactor(); // division
else
return x;
}
}
}
public static double eval(final String equation) throws ParseException {
return new Parser(equation).evaluate();
}
}

View File

@ -1,6 +1,6 @@
package world.bentobox.level.calculators;
import java.text.ParseException;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
@ -16,6 +16,9 @@ import java.util.UUID;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ConcurrentLinkedQueue;
import com.songoda.ultimatestacker.UltimateStacker;
import com.songoda.ultimatestacker.core.compatibility.CompatibleMaterial;
import com.songoda.ultimatestacker.stackable.block.BlockStack;
import org.bukkit.Bukkit;
import org.bukkit.Chunk;
import org.bukkit.ChunkSnapshot;
@ -24,11 +27,7 @@ import org.bukkit.Material;
import org.bukkit.Tag;
import org.bukkit.World;
import org.bukkit.World.Environment;
import org.bukkit.block.Block;
import org.bukkit.block.BlockState;
import org.bukkit.block.Container;
import org.bukkit.block.CreatureSpawner;
import org.bukkit.block.ShulkerBox;
import org.bukkit.block.*;
import org.bukkit.block.data.BlockData;
import org.bukkit.block.data.type.Slab;
import org.bukkit.inventory.ItemStack;
@ -55,21 +54,121 @@ import world.bentobox.level.calculators.Results.Result;
public class IslandLevelCalculator {
private static final String LINE_BREAK = "==================================";
public static final long MAX_AMOUNT = 10000000;
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.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.LIME_SHULKER_BOX, Material.MAGENTA_SHULKER_BOX, Material.ORANGE_SHULKER_BOX,
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.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.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.WHITE_SHULKER_BOX, Material.YELLOW_SHULKER_BOX, Material.COMPOSTER, Material.BARREL,
Material.DISPENSER, Material.DROPPER, Material.SMOKER, Material.BLAST_FURNACE);
Material.WHITE_SHULKER_BOX, Material.YELLOW_SHULKER_BOX, Material.COMPOSTER, Material.BARREL, Material.DISPENSER,
Material.DROPPER, Material.SMOKER, Material.BLAST_FURNACE);
private static final int CHUNKS_TO_SCAN = 100;
/**
* Method to evaluate a mathematical equation
* @param str - equation to evaluate
* @return value of equation
*/
private static double eval(final String str) throws IOException {
return new Object() {
int pos = -1;
int ch;
boolean eat(int charToEat) {
while (ch == ' ') nextChar();
if (ch == charToEat) {
nextChar();
return true;
}
return false;
}
void nextChar() {
ch = (++pos < str.length()) ? str.charAt(pos) : -1;
}
double parse() throws IOException {
nextChar();
double x = parseExpression();
if (pos < str.length()) throw new IOException("Unexpected: " + (char)ch);
return x;
}
// Grammar:
// expression = term | expression `+` term | expression `-` term
// term = factor | term `*` factor | term `/` factor
// factor = `+` factor | `-` factor | `(` expression `)`
// | number | functionName factor | factor `^` factor
double parseExpression() throws IOException {
double x = parseTerm();
for (;;) {
if (eat('+')) x += parseTerm(); // addition
else if (eat('-')) x -= parseTerm(); // subtraction
else return x;
}
}
double parseFactor() throws IOException {
if (eat('+')) return parseFactor(); // unary plus
if (eat('-')) return -parseFactor(); // unary minus
double x;
int startPos = this.pos;
if (eat('(')) { // parentheses
x = parseExpression();
eat(')');
} else if ((ch >= '0' && ch <= '9') || ch == '.') { // numbers
while ((ch >= '0' && ch <= '9') || ch == '.') nextChar();
x = Double.parseDouble(str.substring(startPos, this.pos));
} else if (ch >= 'a' && ch <= 'z') { // functions
while (ch >= 'a' && ch <= 'z') nextChar();
String func = str.substring(startPos, this.pos);
x = parseFactor();
switch (func) {
case "sqrt":
x = Math.sqrt(x);
break;
case "sin":
x = Math.sin(Math.toRadians(x));
break;
case "cos":
x = Math.cos(Math.toRadians(x));
break;
case "tan":
x = Math.tan(Math.toRadians(x));
break;
case "log":
x = Math.log(x);
break;
default:
throw new IOException("Unknown function: " + func);
}
} else {
throw new IOException("Unexpected: " + (char)ch);
}
if (eat('^')) x = Math.pow(x, parseFactor()); // exponentiation
return x;
}
double parseTerm() throws IOException {
double x = parseFactor();
for (;;) {
if (eat('*')) x *= parseFactor(); // multiplication
else if (eat('/')) x /= parseFactor(); // division
else return x;
}
}
}.parse();
}
private final Level addon;
private final Queue<Pair<Integer, Integer>> chunksToCheck;
private final Island island;
private final Map<Material, Integer> limitCount;
private final CompletableFuture<Results> r;
private final Results results;
private long duration;
private final boolean zeroIsland;
@ -79,13 +178,12 @@ public class IslandLevelCalculator {
private final Set<Chunk> chestBlocks = new HashSet<>();
private BukkitTask finishTask;
/**
* Constructor to get the level for an island
*
* @param addon - Level addon
* @param island - the island to scan
* @param r - completable result that will be completed when the
* calculation is complete
* @param r - completable result that will be completed when the calculation is complete
* @param zeroIsland - true if the calculation is due to an island zeroing
*/
public IslandLevelCalculator(Level addon, Island island, CompletableFuture<Results> r, boolean zeroIsland) {
@ -121,29 +219,25 @@ public class IslandLevelCalculator {
/**
* Calculate the level based on the raw points
*
* @param blockAndDeathPoints - raw points counted on island
* @return level of island
*/
private long calculateLevel(long blockAndDeathPoints) {
String calcString = addon.getSettings().getLevelCalc();
String withValues = calcString.replace("blocks", String.valueOf(blockAndDeathPoints)).replace("level_cost",
String.valueOf(this.addon.getSettings().getLevelCost()));
String withValues = calcString.replace("blocks", String.valueOf(blockAndDeathPoints)).replace("level_cost", String.valueOf(this.addon.getSettings().getLevelCost()));
long evalWithValues;
try {
evalWithValues = (long) EquationEvaluator.eval(withValues);
evalWithValues = (long)eval(withValues);
return evalWithValues - (addon.getSettings().isZeroNewIslandLevels() ? results.initialLevel.get() : 0);
} catch (ParseException e) {
} catch (IOException e) {
addon.getPlugin().logStacktrace(e);
return 0L;
}
}
/**
* Adds value to the results based on the material and whether the block is
* below sea level or not
*
* Adds value to the results based on the material and whether the block is below sea level or not
* @param mat - material of the block
* @param belowSeaLevel - true if below sea level
*/
@ -160,22 +254,20 @@ public class IslandLevelCalculator {
/**
* Get a set of all the chunks in island
*
* @param island - island
* @return - set of pairs of x,z coordinates to check
*/
private Queue<Pair<Integer, Integer>> getChunksToScan(Island island) {
Queue<Pair<Integer, Integer>> chunkQueue = new ConcurrentLinkedQueue<>();
for (int x = island.getMinProtectedX(); x < (island.getMinProtectedX() + island.getProtectionRange() * 2
+ 16); x += 16) {
for (int z = island.getMinProtectedZ(); z < (island.getMinProtectedZ() + island.getProtectionRange() * 2
+ 16); z += 16) {
for (int x = island.getMinProtectedX(); x < (island.getMinProtectedX() + island.getProtectionRange() * 2 + 16); x += 16) {
for (int z = island.getMinProtectedZ(); z < (island.getMinProtectedZ() + island.getProtectionRange() * 2 + 16); z += 16) {
chunkQueue.add(new Pair<>(x >> 4, z >> 4));
}
}
return chunkQueue;
}
/**
* @return the island
*/
@ -185,7 +277,6 @@ public class IslandLevelCalculator {
/**
* Get the completable result for this calculation
*
* @return the r
*/
public CompletableFuture<Results> getR() {
@ -194,14 +285,12 @@ public class IslandLevelCalculator {
/**
* Get the full analysis report
*
* @return a list of lines
*/
private List<String> getReport() {
List<String> reportLines = new ArrayList<>();
// provide counts
reportLines.add("Level Log for island in " + addon.getPlugin().getIWM().getFriendlyName(island.getWorld())
+ " at " + Util.xyz(island.getCenter().toVector()));
reportLines.add("Level Log for island in " + addon.getPlugin().getIWM().getFriendlyName(island.getWorld()) + " at " + Util.xyz(island.getCenter().toVector()));
reportLines.add("Island owner UUID = " + island.getOwner());
reportLines.add("Total block value count = " + String.format("%,d",results.rawBlockCount.get()));
reportLines.add("Formula to calculate island level: " + addon.getSettings().getLevelCalc());
@ -215,8 +304,7 @@ public class IslandLevelCalculator {
reportLines.add(LINE_BREAK);
int total = 0;
if (!results.uwCount.isEmpty()) {
reportLines.add("Underwater block count (Multiplier = x" + addon.getSettings().getUnderWaterMultiplier()
+ ") value");
reportLines.add("Underwater block count (Multiplier = x" + addon.getSettings().getUnderWaterMultiplier() + ") value");
reportLines.add("Total number of underwater blocks = " + String.format("%,d",results.uwCount.size()));
reportLines.addAll(sortedReport(total, results.uwCount));
}
@ -224,8 +312,7 @@ public class IslandLevelCalculator {
reportLines.add("Total number of blocks = " + String.format("%,d",results.mdCount.size()));
reportLines.addAll(sortedReport(total, results.mdCount));
reportLines.add(
"Blocks not counted because they exceeded limits: " + String.format("%,d", results.ofCount.size()));
reportLines.add("Blocks not counted because they exceeded limits: " + String.format("%,d",results.ofCount.size()));
Iterable<Multiset.Entry<Material>> entriesSortedByCount = results.ofCount.entrySet();
Iterator<Entry<Material>> it = entriesSortedByCount.iterator();
while (it.hasNext()) {
@ -237,8 +324,7 @@ public class IslandLevelCalculator {
limit = addon.getBlockConfig().getBlockLimits().get(generic);
explain = " - All types)";
}
reportLines.add(type.getElement().toString() + ": " + String.format("%,d", type.getCount())
+ " blocks (max " + limit + explain);
reportLines.add(type.getElement().toString() + ": " + String.format("%,d",type.getCount()) + " blocks (max " + limit + explain);
}
reportLines.add(LINE_BREAK);
reportLines.add("Blocks on island that are not in config.yml");
@ -260,10 +346,9 @@ public class IslandLevelCalculator {
public Results getResults() {
return results;
}
/**
* Get value of a material World blocks trump regular block values
*
* Get value of a material
* World blocks trump regular block values
* @param md - Material to check
* @return value of a material
*/
@ -279,11 +364,9 @@ public class IslandLevelCalculator {
/**
* Get a chunk async
*
* @param env - the environment
* @param pairList - chunk coordinate
* @return a future chunk or future null if there is no chunk to load, e.g.,
* there is no island nether
* @return a future chunk or future null if there is no chunk to load, e.g., there is no island nether
*/
private CompletableFuture<List<Chunk>> getWorldChunk(Environment env, Queue<Pair<Integer, Integer>> pairList) {
if (worlds.containsKey(env)) {
@ -327,9 +410,7 @@ public class IslandLevelCalculator {
}
/**
* Checks if a block has been limited or not and whether a block has any value
* or not
*
* Checks if a block has been limited or not and whether a block has any value or not
* @param md Material
* @return value of the block if can be counted
*/
@ -347,9 +428,9 @@ public class IslandLevelCalculator {
return getValue(md);
}
/**
* Scan all containers in a chunk and count their blocks
*
* @param chunk - the chunk to scan
*/
private void scanChests(Chunk chunk) {
@ -374,8 +455,7 @@ public class IslandLevelCalculator {
}
private void countItemStack(ItemStack i) {
if (i == null || !i.getType().isBlock())
return;
if (i == null || !i.getType().isBlock()) return;
for (int c = 0; c < i.getAmount(); c++) {
if (addon.getSettings().isIncludeShulkersInChest()
@ -389,13 +469,10 @@ public class IslandLevelCalculator {
}
/**
* Scan the chunk chests and count the blocks. Note that the chunks are a list
* of all the island chunks in a particular world, so the memory usage is high,
* but I think most servers can handle it.
*
* Scan the chunk chests and count the blocks. Note that the chunks are a list of all the island chunks
* in a particular world, so the memory usage is high, but I think most servers can handle it.
* @param chunks - a list of chunks to scan
* @return future that completes when the scan is done and supplies a boolean
* that will be true if the scan was successful, false if not
* @return future that completes when the scan is done and supplies a boolean that will be true if the scan was successful, false if not
*/
private CompletableFuture<Boolean> scanChunk(List<Chunk> chunks) {
// If the chunk hasn't been generated, return
@ -405,13 +482,11 @@ public class IslandLevelCalculator {
// Count blocks in chunk
CompletableFuture<Boolean> result = new CompletableFuture<>();
/*
* 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
* not sure how much lag this will cause, but as all the chunks are loaded,
* maybe not that much.
* 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 not sure how much lag this will cause, but as all the chunks are loaded, maybe not that much.
*/
List<ChunkPair> preLoad = chunks.stream().map(c -> new ChunkPair(c.getWorld(), c, c.getChunkSnapshot()))
.toList();
List<ChunkPair> preLoad = chunks.stream().map(c -> new ChunkPair(c.getWorld(), c, c.getChunkSnapshot())).toList();
Bukkit.getScheduler().runTaskAsynchronously(BentoBox.getInstance(), () -> {
preLoad.forEach(this::scanAsync);
// Once they are all done, return to the main thread.
@ -420,59 +495,63 @@ public class IslandLevelCalculator {
return result;
}
record ChunkPair(World world, Chunk chunk, ChunkSnapshot chunkSnapshot) {
}
record ChunkPair(World world, Chunk chunk, ChunkSnapshot chunkSnapshot) {}
/**
* Count the blocks on the island
*
* @param cp chunk to scan
*/
private void scanAsync(ChunkPair cp) {
for (int x = 0; x< 16; x++) {
// Check if the block coordinate is inside the protection zone and if not, don't
// count it
if (cp.chunkSnapshot.getX() * 16 + x < island.getMinProtectedX() || cp.chunkSnapshot.getX() * 16
+ x >= island.getMinProtectedX() + island.getProtectionRange() * 2) {
// Check if the block coordinate is inside the protection zone and if not, don't count it
if (cp.chunkSnapshot.getX() * 16 + x < island.getMinProtectedX() || cp.chunkSnapshot.getX() * 16 + x >= island.getMinProtectedX() + island.getProtectionRange() * 2) {
continue;
}
for (int z = 0; z < 16; z++) {
// Check if the block coordinate is inside the protection zone and if not, don't
// count it
if (cp.chunkSnapshot.getZ() * 16 + z < island.getMinProtectedZ() || cp.chunkSnapshot.getZ() * 16
+ z >= island.getMinProtectedZ() + island.getProtectionRange() * 2) {
// Check if the block coordinate is inside the protection zone and if not, don't count it
if (cp.chunkSnapshot.getZ() * 16 + z < island.getMinProtectedZ() || cp.chunkSnapshot.getZ() * 16 + z >= island.getMinProtectedZ() + island.getProtectionRange() * 2) {
continue;
}
// Only count to the highest block in the world for some optimization
for (int y = cp.world.getMinHeight(); y < cp.world.getMaxHeight(); y++) {
BlockData blockData = cp.chunkSnapshot.getBlockData(x, y, z);
Material m = blockData.getMaterial();
boolean belowSeaLevel = seaHeight > 0 && y <= seaHeight;
// Slabs can be doubled, so check them twice
if (Tag.SLABS.isTagged(m)) {
if (Tag.SLABS.isTagged(blockData.getMaterial())) {
Slab slab = (Slab)blockData;
if (slab.getType().equals(Slab.Type.DOUBLE)) {
checkBlock(m, belowSeaLevel);
checkBlock(blockData.getMaterial(), belowSeaLevel);
}
}
// Hook for Wild Stackers (Blocks and Spawners Only) - this has to use the real
// chunk
if (addon.isStackersEnabled() && (m.equals(Material.CAULDRON) || m.equals(Material.SPAWNER))) {
stackedBlocks.add(new Location(cp.world, (double) x + cp.chunkSnapshot.getX() * 16, y,
(double) z + cp.chunkSnapshot.getZ() * 16));
// Hook for Wild Stackers (Blocks and Spawners Only) - this has to use the real chunk
if (addon.isStackersEnabled() && (blockData.getMaterial().equals(Material.CAULDRON) || blockData.getMaterial().equals(Material.SPAWNER))) {
stackedBlocks.add(new Location(cp.world, (double)x + cp.chunkSnapshot.getX() * 16, y, (double)z + cp.chunkSnapshot.getZ() * 16));
}
if (addon.isUltimateStackerEnabled() && !m.isAir()) {
Location l = new Location(cp.chunk.getWorld(), x, y, z);
UltimateStackerCalc.addStackers(m, l, results, belowSeaLevel, limitCount(m));
Block block = cp.chunk.getBlock(x, y, z);
if (addon.isUltimateStackerEnabled()) {
if (!blockData.getMaterial().equals(Material.AIR)) {
BlockStack stack = UltimateStacker.getInstance().getBlockStackManager().getBlock(block, CompatibleMaterial.getMaterial(block));
if (stack != null) {
int value = limitCount(blockData.getMaterial());
if (belowSeaLevel) {
results.underWaterBlockCount.addAndGet((long) stack.getAmount() * value);
results.uwCount.add(blockData.getMaterial());
} else {
results.rawBlockCount.addAndGet((long) stack.getAmount() * value);
results.mdCount.add(blockData.getMaterial());
}
}
}
}
// Scan chests
if (addon.getSettings().isIncludeChests() && CHESTS.contains(m)) {
if (addon.getSettings().isIncludeChests() && CHESTS.contains(blockData.getMaterial())) {
chestBlocks.add(cp.chunk);
}
// Add the value of the block's material
checkBlock(m, belowSeaLevel);
checkBlock(blockData.getMaterial(), belowSeaLevel);
}
}
}
@ -480,9 +559,7 @@ public class IslandLevelCalculator {
/**
* Scan the next chunk on the island
*
* @return completable boolean future that will be true if more chunks are left
* to be scanned, and false if not
* @return completable boolean future that will be true if more chunks are left to be scanned, and false if not
*/
public CompletableFuture<Boolean> scanNextChunk() {
if (chunksToCheck.isEmpty()) {
@ -502,28 +579,31 @@ public class IslandLevelCalculator {
CompletableFuture<Boolean> result = new CompletableFuture<>();
// Get chunks and scan
// Get chunks and scan
getWorldChunk(Environment.THE_END, endPairList).thenAccept(
endChunks -> scanChunk(endChunks).thenAccept(b -> getWorldChunk(Environment.NETHER, netherPairList)
.thenAccept(netherChunks -> scanChunk(netherChunks)
.thenAccept(b2 -> getWorldChunk(Environment.NORMAL, pairList)
.thenAccept(normalChunks -> scanChunk(normalChunks).thenAccept(b3 ->
getWorldChunk(Environment.THE_END, endPairList).thenAccept(endChunks ->
scanChunk(endChunks).thenAccept(b ->
getWorldChunk(Environment.NETHER, netherPairList).thenAccept(netherChunks ->
scanChunk(netherChunks).thenAccept(b2 ->
getWorldChunk(Environment.NORMAL, pairList).thenAccept(normalChunks ->
scanChunk(normalChunks).thenAccept(b3 ->
// Complete the result now that all chunks have been scanned
result.complete(!chunksToCheck.isEmpty())))))));
result.complete(!chunksToCheck.isEmpty()))))
)
)
);
return result;
}
private Collection<String> sortedReport(int total, Multiset<Material> materialCount) {
Collection<String> result = new ArrayList<>();
Iterable<Multiset.Entry<Material>> entriesSortedByCount = Multisets.copyHighestCountFirst(materialCount)
.entrySet();
Iterable<Multiset.Entry<Material>> entriesSortedByCount = Multisets.copyHighestCountFirst(materialCount).entrySet();
for (Entry<Material> en : entriesSortedByCount) {
Material type = en.getElement();
int value = getValue(type);
result.add(type.toString() + ":" + String.format("%,d", en.getCount()) + " blocks x " + value + " = "
+ (value * en.getCount()));
result.add(type.toString() + ":"
+ String.format("%,d", en.getCount()) + " blocks x " + value + " = " + (value * en.getCount()));
total += (value * en.getCount());
}
@ -532,29 +612,34 @@ public class IslandLevelCalculator {
return result;
}
/**
* Finalizes the calculations and makes the report
*/
public void tidyUp() {
// Finalize calculations
results.rawBlockCount
.addAndGet((long) (results.underWaterBlockCount.get() * addon.getSettings().getUnderWaterMultiplier()));
results.rawBlockCount.addAndGet((long)(results.underWaterBlockCount.get() * addon.getSettings().getUnderWaterMultiplier()));
// Set the death penalty
if (this.addon.getSettings().isSumTeamDeaths()) {
for (UUID uuid : this.island.getMemberSet()) {
if (this.addon.getSettings().isSumTeamDeaths())
{
for (UUID uuid : this.island.getMemberSet())
{
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.
this.results.deathHandicap.set(this.island.getOwner() == null ? 0
: this.addon.getPlayers().getDeaths(island.getWorld(), this.island.getOwner()));
this.results.deathHandicap.set(this.island.getOwner() == null ? 0 :
this.addon.getPlayers().getDeaths(island.getWorld(), this.island.getOwner()));
}
long blockAndDeathPoints = this.results.rawBlockCount.get();
this.results.totalPoints.set(blockAndDeathPoints);
if (this.addon.getSettings().getDeathPenalty() > 0) {
if (this.addon.getSettings().getDeathPenalty() > 0)
{
// Proper death penalty calculation.
blockAndDeathPoints -= this.results.deathHandicap.get() * this.addon.getSettings().getDeathPenalty();
}
@ -589,13 +674,11 @@ public class IslandLevelCalculator {
addon.getPlugin().logError("scanChunk not on Primary Thread!");
}
// Timeout check
if (System.currentTimeMillis()
- pipeliner.getInProcessQueue().get(this) > addon.getSettings().getCalculationTimeout() * 60000) {
if (System.currentTimeMillis() - pipeliner.getInProcessQueue().get(this) > addon.getSettings().getCalculationTimeout() * 60000) {
// Done
pipeliner.getInProcessQueue().remove(this);
getR().complete(new Results(Result.TIMEOUT));
addon.logError("Level calculation timed out after " + addon.getSettings().getCalculationTimeout()
+ "m for island: " + getIsland());
addon.logError("Level calculation timed out after " + addon.getSettings().getCalculationTimeout() + "m for island: " + getIsland());
if (!isNotZeroIsland()) {
addon.logError("Island level was being zeroed.");
}
@ -608,32 +691,40 @@ public class IslandLevelCalculator {
// Done
pipeliner.getInProcessQueue().remove(this);
// Chunk finished
// This was the last chunk. Handle stacked blocks, then chests and exit
handleStackedBlocks().thenCompose(v -> handleChests()).thenRun(() -> {
// This was the last chunk
handleStackedBlocks();
handleChests();
long checkTime = System.currentTimeMillis();
finishTask = Bukkit.getScheduler().runTaskTimer(addon.getPlugin(), () -> {
// Check every half second if all the chests and stacks have been cleared
if ((chestBlocks.isEmpty() && stackedBlocks.isEmpty()) || System.currentTimeMillis() - checkTime > MAX_AMOUNT) {
this.tidyUp();
this.getR().complete(getResults());
});
finishTask.cancel();
}
}, 0, 10L);
}
});
}
private CompletableFuture<Void> handleChests() {
List<CompletableFuture<Void>> futures = new ArrayList<>();
for (Chunk v : chestBlocks) {
CompletableFuture<Void> future = Util.getChunkAtAsync(v.getWorld(), v.getX(), v.getZ()).thenAccept(c -> {
private void handleChests() {
Iterator<Chunk> it = chestBlocks.iterator();
while(it.hasNext()) {
Chunk v = it.next();
Util.getChunkAtAsync(v.getWorld(), v.getX(), v.getZ()).thenAccept(c -> {
scanChests(c);
it.remove();
});
futures.add(future);
}
// Return a CompletableFuture that completes when all futures are done
return CompletableFuture.allOf(futures.toArray(new CompletableFuture[0]));
}
private CompletableFuture<Void> handleStackedBlocks() {
private void handleStackedBlocks() {
// Deal with any stacked blocks
List<CompletableFuture<Void>> futures = new ArrayList<>();
for (Location v : stackedBlocks) {
CompletableFuture<Void> future = Util.getChunkAtAsync(v).thenAccept(c -> {
Iterator<Location> it = stackedBlocks.iterator();
while (it.hasNext()) {
Location v = it.next();
Util.getChunkAtAsync(v).thenAccept(c -> {
Block stackedBlock = v.getBlock();
boolean belowSeaLevel = seaHeight > 0 && v.getBlockY() <= seaHeight;
if (WildStackerAPI.getWildStacker().getSystemManager().isStackedBarrel(stackedBlock)) {
@ -648,12 +739,8 @@ public class IslandLevelCalculator {
checkBlock(stackedBlock.getType(), belowSeaLevel);
}
}
it.remove();
});
futures.add(future);
}
// Return a CompletableFuture that completes when all futures are done
return CompletableFuture.allOf(futures.toArray(new CompletableFuture[0]));
}
}

View File

@ -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);
}
}
}
}

View File

@ -46,20 +46,10 @@ public class AdminSetInitialLevelCommand extends CompositeCommand {
@Override
public boolean execute(User user, String label, List<String> args) {
long initialLevel = addon.getManager().getInitialLevel(island);
long lv = 0;
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));
}
String initialLevel = String.valueOf(addon.getManager().getInitialLevel(island));
long lv = Long.parseLong(args.get(1));
addon.getManager().setInitialIslandLevel(island, lv);
user.sendMessage("admin.level.sethandicap.changed", TextVariables.NUMBER, String.valueOf(initialLevel),
"[new_number]", String.valueOf(lv));
user.sendMessage("admin.level.sethandicap.changed", TextVariables.NUMBER, initialLevel, "[new_number]", String.valueOf(lv));
return true;
}
@ -74,21 +64,11 @@ public class AdminSetInitialLevelCommand extends CompositeCommand {
user.sendMessage("general.errors.unknown-player", TextVariables.NAME, args.get(0));
return false;
}
// Check if this is a add or remove
if (args.get(1).startsWith("+") || args.get(1).startsWith("-")) {
String change = args.get(1).substring(1);
if (!Util.isInteger(change, true)) {
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
island = getAddon().getIslands().getIsland(getWorld(), targetUUID);
if (island == null) {

View File

@ -1,98 +0,0 @@
package world.bentobox.level.commands;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.TreeMap;
import java.util.stream.Collectors;
import org.bukkit.World;
import world.bentobox.bentobox.api.commands.CompositeCommand;
import world.bentobox.bentobox.api.localization.TextVariables;
import world.bentobox.bentobox.api.user.User;
import world.bentobox.level.Level;
import world.bentobox.level.objects.TopTenData;
public class AdminStatsCommand extends CompositeCommand {
private final Level level;
public AdminStatsCommand(Level addon, CompositeCommand parent) {
super(parent, "stats");
this.level = addon;
new AdminTopRemoveCommand(addon, this);
}
@Override
public void setup() {
this.setPermission("admin.stats");
this.setOnlyPlayer(false);
this.setDescription("admin.stats.description");
}
@Override
public boolean execute(User user, String label, List<String> args) {
user.sendMessage("admin.stats.title");
Map<World, TopTenData> topTenLists = level.getManager().getTopTenLists();
if (topTenLists.isEmpty()) {
user.sendMessage("admin.stats.no-data");
return false;
}
for (Entry<World, TopTenData> en : topTenLists.entrySet()) {
user.sendMessage("admin.stats.world", TextVariables.NAME,
level.getPlugin().getIWM().getWorldName(en.getKey()));
Map<String, Long> topTen = en.getValue().getTopTen();
if (topTen.isEmpty()) {
user.sendMessage("admin.stats.no-data");
return false;
}
// Calculating basic statistics
long sum = 0, max = Long.MIN_VALUE, min = Long.MAX_VALUE;
Map<Long, Integer> levelFrequency = new HashMap<>();
for (Long level : topTen.values()) {
sum += level;
max = Math.max(max, level);
min = Math.min(min, level);
levelFrequency.merge(level, 1, Integer::sum);
}
double average = sum / (double) topTen.size();
List<Long> sortedLevels = topTen.values().stream().sorted().collect(Collectors.toList());
long median = sortedLevels.get(sortedLevels.size() / 2);
Long mode = Collections.max(levelFrequency.entrySet(), Map.Entry.comparingByValue()).getKey();
// Logging basic statistics
user.sendMessage("admin.stats.average-level", TextVariables.NUMBER, String.valueOf(average));
user.sendMessage("admin.stats.median-level", TextVariables.NUMBER, String.valueOf(median));
user.sendMessage("admin.stats.mode-level", TextVariables.NUMBER, String.valueOf(mode));
user.sendMessage("admin.stats.highest-level", TextVariables.NUMBER, String.valueOf(max));
user.sendMessage("admin.stats.lowest-level", TextVariables.NUMBER, String.valueOf(min));
// Grouping data for distribution analysis
Map<String, Integer> rangeMap = new TreeMap<>();
for (Long level : topTen.values()) {
String range = getRange(level);
rangeMap.merge(range, 1, Integer::sum);
}
// Logging distribution
user.sendMessage("admin.stats.distribution");
for (Map.Entry<String, Integer> entry : rangeMap.entrySet()) {
user.sendMessage(
entry.getKey() + ": " + entry.getValue() + " " + user.getTranslation("admin.stats.islands"));
}
}
return true;
}
private static String getRange(long level) {
long rangeStart = level / 100 * 100;
long rangeEnd = rangeStart + 99;
return rangeStart + "-" + rangeEnd;
}
}

View File

@ -2,7 +2,7 @@ package world.bentobox.level.commands;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.UUID;
import world.bentobox.bentobox.api.commands.CompositeCommand;
import world.bentobox.bentobox.api.user.User;
@ -30,16 +30,20 @@ public class AdminTopCommand extends CompositeCommand {
public boolean execute(User user, String label, List<String> args) {
user.sendMessage("island.top.gui-title");
int rank = 0;
for (Map.Entry<String, Long> topTen : levelPlugin.getManager().getTopTen(getWorld(), Level.TEN).entrySet()) {
Optional<Island> is = getPlugin().getIslands().getIslandById(topTen.getKey());
if (is.isPresent()) {
Island island = is.get();
for (Map.Entry<UUID, Long> topTen : levelPlugin.getManager().getTopTen(getWorld(), Level.TEN).entrySet()) {
Island island = getPlugin().getIslands().getIsland(getWorld(), topTen.getKey());
if (island != null) {
rank++;
user.sendMessage("admin.top.display", "[rank]", String.valueOf(rank), "[name]",
this.getPlugin().getPlayers().getUser(island.getOwner()).getName(), "[level]",
user.sendMessage("admin.top.display",
"[rank]",
String.valueOf(rank),
"[name]",
this.getPlugin().getPlayers().getUser(island.getOwner()).getName(),
"[level]",
String.valueOf(topTen.getValue()));
}
}
return true;
}
}

View File

@ -6,12 +6,10 @@ import java.util.Optional;
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.database.objects.Island;
import world.bentobox.level.Level;
/**
* Removes a player from the top ten
*
* @author tastybento
*
*/
@ -33,11 +31,8 @@ public class AdminTopRemoveCommand extends CompositeCommand {
this.setDescription("admin.top.remove.description");
}
/*
* (non-Javadoc)
*
* @see world.bentobox.bentobox.api.commands.BentoBoxCommand#canExecute(world.
* bentobox.bentobox.api.user.User, java.lang.String, java.util.List)
/* (non-Javadoc)
* @see world.bentobox.bentobox.api.commands.BentoBoxCommand#canExecute(world.bentobox.bentobox.api.user.User, java.lang.String, java.util.List)
*/
@Override
public boolean canExecute(User user, String label, List<String> args) {
@ -56,18 +51,14 @@ public class AdminTopRemoveCommand extends CompositeCommand {
@Override
public boolean execute(User user, String label, List<String> args) {
// Removes islands that this target is an owner of
getIslands().getIslands(getWorld(), target.getUniqueId()).stream()
.filter(is -> target.getUniqueId().equals(is.getOwner()))
.forEach(island -> addon.getManager().removeEntry(getWorld(), island.getUniqueId()));
addon.getManager().removeEntry(getWorld(), target.getUniqueId());
user.sendMessage("general.success");
return true;
}
@Override
public Optional<List<String>> tabComplete(User user, String alias, List<String> args) {
return Optional.of(addon.getManager().getTopTen(getWorld(), Level.TEN).keySet().stream()
.map(getIslands()::getIslandById).flatMap(Optional::stream).map(Island::getOwner)
.map(addon.getPlayers()::getName).filter(n -> !n.isEmpty()).toList());
return Optional.of(addon.getManager().getTopTen(getWorld(), Level.TEN).keySet().stream().map(addon.getPlayers()::getName)
.filter(n -> !n.isEmpty()).toList());
}
}

View File

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

View File

@ -8,14 +8,11 @@ import java.util.Optional;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.inventory.PlayerInventory;
import org.eclipse.jdt.annotation.NonNull;
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.util.Util;
import world.bentobox.level.Level;
import world.bentobox.level.objects.IslandLevels;
import world.bentobox.level.panels.ValuePanel;
import world.bentobox.level.util.Utils;
@ -115,19 +112,6 @@ public class IslandValueCommand extends CompositeCommand
"[value]", (underWater * value) + ""),
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
{

View File

@ -2,12 +2,9 @@ package world.bentobox.level.config;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.EnumMap;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Objects;
@ -29,7 +26,6 @@ public class BlockConfig {
private Map<Material, Integer> blockLimits = 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 List<Material> hiddenBlocks;
private Level addon;
/**
@ -53,16 +49,6 @@ public class BlockConfig {
if (blockValues.isConfigurationSection("worlds")) {
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
blockValues.save(file);
}
@ -74,16 +60,10 @@ public class BlockConfig {
if (bWorld != null) {
ConfigurationSection worldValues = worlds.getConfigurationSection(world);
for (String material : Objects.requireNonNull(worldValues).getKeys(false)) {
try {
Material mat = Material.valueOf(material);
Map<Material, Integer> values = worldBlockValues.getOrDefault(bWorld,
new EnumMap<>(Material.class));
Map<Material, Integer> values = worldBlockValues.getOrDefault(bWorld, new EnumMap<>(Material.class));
values.put(mat, worldValues.getInt(material));
worldBlockValues.put(bWorld, values);
} catch (Exception e) {
addon.logError(
"Unknown material (" + material + ") in blockconfig.yml worlds section. Skipping...");
}
}
} else {
addon.logWarning("Level Addon: No such world in blockconfig.yml : " + world);
@ -117,7 +97,7 @@ public class BlockConfig {
Material mat = Material.valueOf(material);
bl.put(mat, limits.getInt(material, 0));
} catch (Exception e) {
addon.logError("Unknown material (" + material + ") in blockconfig.yml Limits section. Skipping...");
addon.logWarning("Unknown material (" + material + ") in blockconfig.yml Limits section. Skipping...");
}
}
return bl;
@ -173,22 +153,5 @@ public class BlockConfig {
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);
}
}

View File

@ -1,9 +1,7 @@
package world.bentobox.level.config;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Objects;
import world.bentobox.bentobox.BentoBox;
import world.bentobox.bentobox.api.configuration.ConfigComment;
@ -121,17 +119,6 @@ public class ConfigSettings implements ConfigObject {
@ConfigComment("Shows large level values rounded down, e.g., 10,345 -> 10k")
@ConfigEntry(path = "shorthand")
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("Include Shulker Box content in chests in level calculations.")
@ConfigComment("Will count blocks in Shulker Boxes inside of chests.")
@ -139,12 +126,6 @@ public class ConfigSettings implements ConfigObject {
@ConfigEntry(path = "include-shulkers-in-chest")
private boolean includeShulkersInChest = false;
@ConfigComment("")
@ConfigComment("Disables hooking with other plugins.")
@ConfigComment("Example: disabled-plugin-hooks: [UltimateStacker, RoseStacker]")
@ConfigEntry(path = "disabled-plugin-hooks")
private List<String> disabledPluginHooks = new ArrayList<>();
/**
* @return the gameModes
@ -423,68 +404,4 @@ public class ConfigSettings implements ConfigObject {
public void setIncludeShulkersInChest(boolean includeShulkersInChest) {
this.includeShulkersInChest = includeShulkersInChest;
}
public List<String> getDisabledPluginHooks() {
return disabledPluginHooks;
}
public void setDisabledPluginHooks(List<String> 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;
}
}

View File

@ -1,5 +1,7 @@
package world.bentobox.level.listeners;
import java.util.UUID;
import org.bukkit.World;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
@ -19,9 +21,7 @@ import world.bentobox.bentobox.database.objects.Island;
import world.bentobox.level.Level;
/**
* Listens for new islands or ownership changes and sets the level to zero
* automatically
*
* Listens for new islands or ownership changes and sets the level to zero automatically
* @author tastybento
*
*/
@ -54,14 +54,18 @@ public class IslandActivitiesListeners implements Listener {
private void zeroIsland(final Island island) {
// Clear the island setting
if (island.getOwner() != null && island.getWorld() != null) {
addon.getPipeliner().zeroIsland(island)
.thenAccept(results -> addon.getManager().setInitialIslandLevel(island, results.getLevel()));
addon.getPipeliner().zeroIsland(island).thenAccept(results ->
addon.getManager().setInitialIslandLevel(island, results.getLevel()));
}
}
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onIslandDelete(IslandPreclearEvent e) {
remove(e.getIsland().getWorld(), e.getIsland().getUniqueId());
// Remove player from the top ten and level
UUID uuid = e.getIsland().getOwner();
World world = e.getIsland().getWorld();
remove(world, uuid);
}
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
@ -70,7 +74,7 @@ public class IslandActivitiesListeners implements Listener {
addon.getManager().deleteIsland(e.getIsland().getUniqueId());
}
private void remove(World world, String uuid) {
private void remove(World world, UUID uuid) {
if (uuid != null && world != null) {
addon.getManager().removeEntry(world, uuid);
}
@ -79,43 +83,43 @@ public class IslandActivitiesListeners implements Listener {
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
public void onNewIslandOwner(TeamSetownerEvent e) {
// Remove island from the top ten and level
remove(e.getIsland().getWorld(), e.getIsland().getUniqueId());
// Remove player from the top ten and level
remove(e.getIsland().getWorld(), e.getIsland().getOwner());
}
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
public void onIsland(TeamJoinedEvent e) {
// TODO: anything to do here?
// Remove player from the top ten and level
// remove(e.getIsland().getWorld(), e.getPlayerUUID());
remove(e.getIsland().getWorld(), e.getPlayerUUID());
}
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
public void onIsland(IslandUnregisteredEvent e) {
// Remove island from the top ten
remove(e.getIsland().getWorld(), e.getIsland().getUniqueId());
// Remove player from the top ten
remove(e.getIsland().getWorld(), e.getPlayerUUID());
}
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
public void onIsland(IslandRegisteredEvent e) {
// TODO: anything to do here?
// Remove player from the top ten
// remove(e.getIsland().getWorld(), e.getPlayerUUID());
remove(e.getIsland().getWorld(), e.getPlayerUUID());
}
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
public void onIsland(TeamLeaveEvent e) {
// TODO: anything to do here?
// Remove player from the top ten and level
// remove(e.getIsland().getWorld(), e.getPlayerUUID());
remove(e.getIsland().getWorld(), e.getPlayerUUID());
}
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
public void onIsland(TeamKickEvent e) {
//// TODO: anything to do here?
// Remove player from the top ten and level
// remove(e.getIsland().getWorld(), e.getPlayerUUID());
remove(e.getIsland().getWorld(), e.getPlayerUUID());
}
}

View File

@ -62,7 +62,7 @@ public class IslandLevels implements DataObject {
private Map<Material, Integer> uwCount;
/**
* MaterialData count - count of all blocks excluding under water
* MaterialData count - count of all blocks
*/
@Expose
private Map<Material, Integer> mdCount;
@ -162,7 +162,6 @@ public class IslandLevels implements DataObject {
}
/**
* The count of underwater blocks
* @return the uwCount
*/
public Map<Material, Integer> getUwCount() {
@ -170,7 +169,6 @@ public class IslandLevels implements DataObject {
}
/**
* Underwater blocks
* @param uwCount the uwCount to set
*/
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
*/
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
*/
public void setMdCount(Map<Material, Integer> mdCount) {

View File

@ -3,41 +3,56 @@ package world.bentobox.level.objects;
import java.util.LinkedHashMap;
import java.util.Locale;
import java.util.Map;
import java.util.UUID;
import org.bukkit.World;
import com.google.gson.annotations.Expose;
import world.bentobox.bentobox.database.objects.DataObject;
import world.bentobox.bentobox.database.objects.Table;
/**
* This class stores the top ten.
*
* @author tastybento
*
*/
public class TopTenData {
@Table(name = "TopTenData")
public class TopTenData implements DataObject {
// UniqueId is the world name
@Expose
private String uniqueId = "";
@Expose
private Map<String, Long> topTen = new LinkedHashMap<>();
private Map<UUID, Long> topTen = new LinkedHashMap<>();
public TopTenData(World k) {
uniqueId = k.getName().toLowerCase(Locale.ENGLISH);
}
@Override
public String getUniqueId() {
// This is the world name
return uniqueId;
}
@Override
public void setUniqueId(String uniqueId) {
// This is the world name - make it always lowercase
this.uniqueId = uniqueId.toLowerCase(Locale.ENGLISH);
}
/**
* @return the topTen
*/
public Map<String, Long> getTopTen() {
public Map<UUID, Long> getTopTen() {
return topTen;
}
/**
* @param topTen the topTen to set
*/
public void setTopTen(Map<String, Long> topTen) {
public void setTopTen(Map<UUID, Long> topTen) {
this.topTen = topTen;
}
}

View File

@ -1,5 +1,6 @@
package world.bentobox.level.panels;
import java.io.File;
import java.util.ArrayList;
import java.util.Comparator;
@ -29,54 +30,66 @@ import world.bentobox.level.Level;
import world.bentobox.level.objects.IslandLevels;
import world.bentobox.level.util.Utils;
/**
* This class opens GUI that shows generator view for user.
*/
public class DetailsPanel {
public class DetailsPanel
{
// ---------------------------------------------------------------------
// Section: Internal Constructor
// ---------------------------------------------------------------------
/**
* This is internal constructor. It is used internally in current class to avoid
* creating objects everywhere.
* This is internal constructor. It is used internally in current class to avoid creating objects everywhere.
*
* @param addon Level object
* @param world World where user is operating
* @param user User who opens panel
*/
private DetailsPanel(Level addon, World world, User user) {
private DetailsPanel(Level addon,
World world,
User user)
{
this.addon = addon;
this.world = world;
this.user = user;
this.island = this.addon.getIslands().getIsland(world, user);
if (this.island != null) {
if (this.island != null)
{
this.levelsData = this.addon.getManager().getLevelsData(this.island);
} else {
}
else
{
this.levelsData = null;
}
// By default no-filters are active.
this.activeTab = Tab.VALUE_BLOCKS;
this.activeTab = Tab.ALL_BLOCKS;
this.activeFilter = Filter.NAME;
this.materialCountList = new ArrayList<>(Material.values().length);
this.updateFilters();
}
/**
* This method builds this GUI.
*/
private void build() {
if (this.island == null || this.levelsData == null) {
private void build()
{
if (this.island == null || this.levelsData == null)
{
// Nothing to see.
Utils.sendMessage(this.user, this.user.getTranslation("general.errors.no-island"));
return;
}
if (this.levelsData.getMdCount().isEmpty() && this.levelsData.getUwCount().isEmpty()) {
if (this.levelsData.getMdCount().isEmpty() && this.levelsData.getUwCount().isEmpty())
{
// Nothing to see.
Utils.sendMessage(this.user, this.user.getTranslation("level.conversations.no-data"));
return;
@ -104,38 +117,16 @@ public class DetailsPanel {
panelBuilder.build();
}
/**
* This method updates filter of elements based on tabs.
*/
private void updateFilters() {
private void updateFilters()
{
this.materialCountList.clear();
switch (this.activeTab) {
case VALUE_BLOCKS -> {
Map<Material, Integer> materialCountMap = new EnumMap<>(Material.class);
materialCountMap.putAll(this.levelsData.getMdCount());
// Add underwater blocks.
this.levelsData.getUwCount().forEach((material, count) -> materialCountMap.put(material,
materialCountMap.computeIfAbsent(material, key -> 0) + count));
// Remove zero value blocks
materialCountMap.entrySet().removeIf(en -> {
Integer value = this.addon.getBlockConfig().getValue(world, en.getKey());
return value == null || value == 0;
});
// Remove any hidden blocks
materialCountMap.keySet().removeIf(this.addon.getBlockConfig()::isHiddenBlock);
materialCountMap.entrySet().stream().sorted((Map.Entry.comparingByKey())).forEachOrdered(entry -> {
if (entry.getValue() > 0) {
this.materialCountList.add(new Pair<>(entry.getKey(), entry.getValue()));
}
});
}
switch (this.activeTab)
{
case ALL_BLOCKS -> {
Map<Material, Integer> materialCountMap = new EnumMap<>(Material.class);
@ -145,24 +136,17 @@ public class DetailsPanel {
this.levelsData.getUwCount().forEach((material, count) -> materialCountMap.put(material,
materialCountMap.computeIfAbsent(material, key -> 0) + count));
// Remove any hidden blocks
materialCountMap.keySet().removeIf(this.addon.getBlockConfig()::isHiddenBlock);
materialCountMap.entrySet().stream().sorted((Map.Entry.comparingByKey()))
.forEachOrdered(entry -> this.materialCountList.add(new Pair<>(entry.getKey(), entry.getValue())));
materialCountMap.entrySet().stream().sorted((Map.Entry.comparingByKey())).
forEachOrdered(entry ->
this.materialCountList.add(new Pair<>(entry.getKey(), entry.getValue())));
}
case ABOVE_SEA_LEVEL -> this.levelsData.getMdCount().entrySet().stream()
.filter(en -> this.addon.getBlockConfig().isNotHiddenBlock(en.getKey()))
.sorted((Map.Entry.comparingByKey()))
case ABOVE_SEA_LEVEL -> this.levelsData.getMdCount().entrySet().stream().sorted((Map.Entry.comparingByKey()))
.forEachOrdered(entry -> this.materialCountList.add(new Pair<>(entry.getKey(), entry.getValue())));
case UNDERWATER -> this.levelsData.getUwCount().entrySet().stream()
.filter(en -> this.addon.getBlockConfig().isNotHiddenBlock(en.getKey()))
.sorted((Map.Entry.comparingByKey()))
case UNDERWATER -> this.levelsData.getUwCount().entrySet().stream().sorted((Map.Entry.comparingByKey()))
.forEachOrdered(entry -> this.materialCountList.add(new Pair<>(entry.getKey(), entry.getValue())));
case SPAWNER -> {
if (this.addon.getBlockConfig().isNotHiddenBlock(Material.SPAWNER)) {
int aboveWater = this.levelsData.getMdCount().getOrDefault(Material.SPAWNER, 0);
int underWater = this.levelsData.getUwCount().getOrDefault(Material.SPAWNER, 0);
@ -170,48 +154,60 @@ public class DetailsPanel {
this.materialCountList.add(new Pair<>(Material.SPAWNER, underWater + aboveWater));
}
}
}
Comparator<Pair<Material, Integer>> sorter;
switch (this.activeFilter) {
case COUNT -> {
sorter = (o1, o2) -> {
if (o1.getValue().equals(o2.getValue())) {
switch (this.activeFilter)
{
case COUNT ->
{
sorter = (o1, o2) ->
{
if (o1.getValue().equals(o2.getValue()))
{
String o1Name = Utils.prettifyObject(o1.getKey(), this.user);
String o2Name = Utils.prettifyObject(o2.getKey(), this.user);
return String.CASE_INSENSITIVE_ORDER.compare(o1Name, o2Name);
} else {
}
else
{
return Integer.compare(o2.getValue(), o1.getValue());
}
};
}
case VALUE -> {
sorter = (o1, o2) -> {
case VALUE ->
{
sorter = (o1, o2) ->
{
int blockLimit = this.addon.getBlockConfig().getBlockLimits().getOrDefault(o1.getKey(), 0);
int o1Count = blockLimit > 0 ? Math.min(o1.getValue(), blockLimit) : o1.getValue();
blockLimit = this.addon.getBlockConfig().getBlockLimits().getOrDefault(o2.getKey(), 0);
int o2Count = blockLimit > 0 ? Math.min(o2.getValue(), blockLimit) : o2.getValue();
long o1Value = (long) o1Count
* this.addon.getBlockConfig().getBlockValues().getOrDefault(o1.getKey(), 0);
long o2Value = (long) o2Count
* this.addon.getBlockConfig().getBlockValues().getOrDefault(o2.getKey(), 0);
long o1Value = (long) o1Count *
this.addon.getBlockConfig().getBlockValues().getOrDefault(o1.getKey(), 0);
long o2Value = (long) o2Count *
this.addon.getBlockConfig().getBlockValues().getOrDefault(o2.getKey(), 0);
if (o1Value == o2Value) {
if (o1Value == o2Value)
{
String o1Name = Utils.prettifyObject(o1.getKey(), this.user);
String o2Name = Utils.prettifyObject(o2.getKey(), this.user);
return String.CASE_INSENSITIVE_ORDER.compare(o1Name, o2Name);
} else {
}
else
{
return Long.compare(o2Value, o1Value);
}
};
}
default -> {
sorter = (o1, o2) -> {
default ->
{
sorter = (o1, o2) ->
{
String o1Name = Utils.prettifyObject(o1.getKey(), this.user);
String o2Name = Utils.prettifyObject(o2.getKey(), this.user);
@ -225,10 +221,12 @@ public class DetailsPanel {
this.pageIndex = 0;
}
// ---------------------------------------------------------------------
// Section: Tab Button Type
// ---------------------------------------------------------------------
/**
* Create tab button panel item.
*
@ -236,36 +234,44 @@ public class DetailsPanel {
* @param slot the slot
* @return the panel item
*/
private PanelItem createTabButton(ItemTemplateRecord template, TemplatedPanel.ItemSlot slot) {
private PanelItem createTabButton(ItemTemplateRecord template, TemplatedPanel.ItemSlot slot)
{
PanelItemBuilder builder = new PanelItemBuilder();
if (template.icon() != null) {
if (template.icon() != null)
{
// Set icon
builder.icon(template.icon().clone());
}
if (template.title() != null) {
if (template.title() != null)
{
// Set title
builder.name(this.user.getTranslation(this.world, template.title()));
}
if (template.description() != null) {
if (template.description() != null)
{
// Set description
builder.description(this.user.getTranslation(this.world, template.description()));
}
Tab tab = Enums.getIfPresent(Tab.class, String.valueOf(template.dataMap().get("tab"))).or(Tab.VALUE_BLOCKS);
Tab tab = Enums.getIfPresent(Tab.class, String.valueOf(template.dataMap().get("tab"))).or(Tab.ALL_BLOCKS);
// Get only possible actions, by removing all inactive ones.
List<ItemTemplateRecord.ActionRecords> activeActions = new ArrayList<>(template.actions());
activeActions.removeIf(action -> "VIEW".equalsIgnoreCase(action.actionType()) && this.activeTab == tab);
activeActions.removeIf(action ->
"VIEW".equalsIgnoreCase(action.actionType()) && this.activeTab == tab);
// Add Click handler
builder.clickHandler((panel, user, clickType, i) -> {
for (ItemTemplateRecord.ActionRecords action : activeActions) {
builder.clickHandler((panel, user, clickType, i) ->
{
for (ItemTemplateRecord.ActionRecords action : activeActions)
{
if ((clickType == action.clickType() || ClickType.UNKNOWN.equals(action.clickType()))
&& "VIEW".equalsIgnoreCase(action.actionType())) {
&& "VIEW".equalsIgnoreCase(action.actionType()))
{
this.activeTab = tab;
// Update filters.
@ -278,12 +284,15 @@ public class DetailsPanel {
});
// Collect tooltips.
List<String> tooltips = activeActions.stream().filter(action -> action.tooltip() != null)
.map(action -> this.user.getTranslation(this.world, action.tooltip())).filter(text -> !text.isBlank())
.collect(Collectors.toCollection(() -> new ArrayList<>(template.actions().size())));
List<String> tooltips = activeActions.stream().
filter(action -> action.tooltip() != null).
map(action -> this.user.getTranslation(this.world, action.tooltip())).
filter(text -> !text.isBlank()).
collect(Collectors.toCollection(() -> new ArrayList<>(template.actions().size())));
// Add tooltips.
if (!tooltips.isEmpty()) {
if (!tooltips.isEmpty())
{
// Empty line and tooltips.
builder.description("");
builder.description(tooltips);
@ -294,6 +303,7 @@ public class DetailsPanel {
return builder.build();
}
/**
* Create next button panel item.
*
@ -301,61 +311,77 @@ public class DetailsPanel {
* @param slot the slot
* @return the panel item
*/
private PanelItem createFilterButton(ItemTemplateRecord template, TemplatedPanel.ItemSlot slot) {
private PanelItem createFilterButton(ItemTemplateRecord template, TemplatedPanel.ItemSlot slot)
{
PanelItemBuilder builder = new PanelItemBuilder();
if (template.icon() != null) {
if (template.icon() != null)
{
// Set icon
builder.icon(template.icon().clone());
}
Filter filter;
if (slot.amountMap().getOrDefault("FILTER", 0) > 1) {
if (slot.amountMap().getOrDefault("FILTER", 0) > 1)
{
filter = Enums.getIfPresent(Filter.class, String.valueOf(template.dataMap().get("filter"))).or(Filter.NAME);
} else {
}
else
{
filter = this.activeFilter;
}
final String reference = "level.gui.buttons.filters.";
if (template.title() != null) {
if (template.title() != null)
{
// Set title
builder.name(this.user.getTranslation(this.world,
template.title().replace("[filter]", filter.name().toLowerCase())));
} else {
builder.name(this.user.getTranslation(this.world, template.title().replace("[filter]", filter.name().toLowerCase())));
}
else
{
builder.name(this.user.getTranslation(this.world, reference + filter.name().toLowerCase() + ".name"));
}
if (template.description() != null) {
if (template.description() != null)
{
// Set description
builder.description(this.user.getTranslation(this.world,
template.description().replace("[filter]", filter.name().toLowerCase())));
} else {
builder.name(
this.user.getTranslation(this.world, reference + filter.name().toLowerCase() + ".description"));
builder.description(this.user.getTranslation(this.world, template.description().replace("[filter]", filter.name().toLowerCase())));
}
else
{
builder.name(this.user.getTranslation(this.world, reference + filter.name().toLowerCase() + ".description"));
}
// Get only possible actions, by removing all inactive ones.
List<ItemTemplateRecord.ActionRecords> activeActions = new ArrayList<>(template.actions());
// Add Click handler
builder.clickHandler((panel, user, clickType, i) -> {
for (ItemTemplateRecord.ActionRecords action : activeActions) {
if (clickType == action.clickType() || ClickType.UNKNOWN.equals(action.clickType())) {
if ("UP".equalsIgnoreCase(action.actionType())) {
builder.clickHandler((panel, user, clickType, i) ->
{
for (ItemTemplateRecord.ActionRecords action : activeActions)
{
if (clickType == action.clickType() || ClickType.UNKNOWN.equals(action.clickType()))
{
if ("UP".equalsIgnoreCase(action.actionType()))
{
this.activeFilter = Utils.getNextValue(Filter.values(), filter);
// Update filters.
this.updateFilters();
this.build();
} else if ("DOWN".equalsIgnoreCase(action.actionType())) {
}
else if ("DOWN".equalsIgnoreCase(action.actionType()))
{
this.activeFilter = Utils.getPreviousValue(Filter.values(), filter);
// Update filters.
this.updateFilters();
this.build();
} else if ("SELECT".equalsIgnoreCase(action.actionType())) {
}
else if ("SELECT".equalsIgnoreCase(action.actionType()))
{
this.activeFilter = filter;
// Update filters.
@ -369,12 +395,15 @@ public class DetailsPanel {
});
// Collect tooltips.
List<String> tooltips = activeActions.stream().filter(action -> action.tooltip() != null)
.map(action -> this.user.getTranslation(this.world, action.tooltip())).filter(text -> !text.isBlank())
.collect(Collectors.toCollection(() -> new ArrayList<>(template.actions().size())));
List<String> tooltips = activeActions.stream().
filter(action -> action.tooltip() != null).
map(action -> this.user.getTranslation(this.world, action.tooltip())).
filter(text -> !text.isBlank()).
collect(Collectors.toCollection(() -> new ArrayList<>(template.actions().size())));
// Add tooltips.
if (!tooltips.isEmpty()) {
if (!tooltips.isEmpty())
{
// Empty line and tooltips.
builder.description("");
builder.description(tooltips);
@ -385,10 +414,12 @@ public class DetailsPanel {
return builder.build();
}
// ---------------------------------------------------------------------
// Section: Create common buttons
// ---------------------------------------------------------------------
/**
* Create next button panel item.
*
@ -396,11 +427,13 @@ public class DetailsPanel {
* @param slot the slot
* @return the panel item
*/
private PanelItem createNextButton(ItemTemplateRecord template, TemplatedPanel.ItemSlot slot) {
private PanelItem createNextButton(ItemTemplateRecord template, TemplatedPanel.ItemSlot slot)
{
long size = this.materialCountList.size();
if (size <= slot.amountMap().getOrDefault("BLOCK", 1)
|| 1.0 * size / slot.amountMap().getOrDefault("BLOCK", 1) <= this.pageIndex + 1) {
if (size <= slot.amountMap().getOrDefault("BLOCK", 1) ||
1.0 * size / slot.amountMap().getOrDefault("BLOCK", 1) <= this.pageIndex + 1)
{
// There are no next elements
return null;
}
@ -409,30 +442,37 @@ public class DetailsPanel {
PanelItemBuilder builder = new PanelItemBuilder();
if (template.icon() != null) {
if (template.icon() != null)
{
ItemStack clone = template.icon().clone();
if (Boolean.TRUE.equals(template.dataMap().getOrDefault("indexing", false))) {
if (Boolean.TRUE.equals(template.dataMap().getOrDefault("indexing", false)))
{
clone.setAmount(nextPageIndex);
}
builder.icon(clone);
}
if (template.title() != null) {
if (template.title() != null)
{
builder.name(this.user.getTranslation(this.world, template.title()));
}
if (template.description() != null) {
builder.description(this.user.getTranslation(this.world, template.description(), TextVariables.NUMBER,
String.valueOf(nextPageIndex)));
if (template.description() != null)
{
builder.description(this.user.getTranslation(this.world, template.description(),
TextVariables.NUMBER, String.valueOf(nextPageIndex)));
}
// Add ClickHandler
builder.clickHandler((panel, user, clickType, i) -> {
for (ItemTemplateRecord.ActionRecords action : template.actions()) {
if ((clickType == action.clickType() || ClickType.UNKNOWN.equals(action.clickType()))
&& "NEXT".equalsIgnoreCase(action.actionType())) {
builder.clickHandler((panel, user, clickType, i) ->
{
for (ItemTemplateRecord.ActionRecords action : template.actions())
{
if ((clickType == action.clickType() || ClickType.UNKNOWN.equals(action.clickType())) &&
"NEXT".equalsIgnoreCase(action.actionType()))
{
this.pageIndex++;
this.build();
}
@ -443,12 +483,15 @@ public class DetailsPanel {
});
// Collect tooltips.
List<String> tooltips = template.actions().stream().filter(action -> action.tooltip() != null)
.map(action -> this.user.getTranslation(this.world, action.tooltip())).filter(text -> !text.isBlank())
.collect(Collectors.toCollection(() -> new ArrayList<>(template.actions().size())));
List<String> tooltips = template.actions().stream().
filter(action -> action.tooltip() != null).
map(action -> this.user.getTranslation(this.world, action.tooltip())).
filter(text -> !text.isBlank()).
collect(Collectors.toCollection(() -> new ArrayList<>(template.actions().size())));
// Add tooltips.
if (!tooltips.isEmpty()) {
if (!tooltips.isEmpty())
{
// Empty line and tooltips.
builder.description("");
builder.description(tooltips);
@ -457,6 +500,7 @@ public class DetailsPanel {
return builder.build();
}
/**
* Create previous button panel item.
*
@ -464,8 +508,10 @@ public class DetailsPanel {
* @param slot the slot
* @return the panel item
*/
private PanelItem createPreviousButton(ItemTemplateRecord template, TemplatedPanel.ItemSlot slot) {
if (this.pageIndex == 0) {
private PanelItem createPreviousButton(ItemTemplateRecord template, TemplatedPanel.ItemSlot slot)
{
if (this.pageIndex == 0)
{
// There are no next elements
return null;
}
@ -474,30 +520,37 @@ public class DetailsPanel {
PanelItemBuilder builder = new PanelItemBuilder();
if (template.icon() != null) {
if (template.icon() != null)
{
ItemStack clone = template.icon().clone();
if (Boolean.TRUE.equals(template.dataMap().getOrDefault("indexing", false))) {
if (Boolean.TRUE.equals(template.dataMap().getOrDefault("indexing", false)))
{
clone.setAmount(previousPageIndex);
}
builder.icon(clone);
}
if (template.title() != null) {
if (template.title() != null)
{
builder.name(this.user.getTranslation(this.world, template.title()));
}
if (template.description() != null) {
builder.description(this.user.getTranslation(this.world, template.description(), TextVariables.NUMBER,
String.valueOf(previousPageIndex)));
if (template.description() != null)
{
builder.description(this.user.getTranslation(this.world, template.description(),
TextVariables.NUMBER, String.valueOf(previousPageIndex)));
}
// Add ClickHandler
builder.clickHandler((panel, user, clickType, i) -> {
for (ItemTemplateRecord.ActionRecords action : template.actions()) {
builder.clickHandler((panel, user, clickType, i) ->
{
for (ItemTemplateRecord.ActionRecords action : template.actions())
{
if ((clickType == action.clickType() || ClickType.UNKNOWN.equals(action.clickType()))
&& "PREVIOUS".equalsIgnoreCase(action.actionType())) {
&& "PREVIOUS".equalsIgnoreCase(action.actionType()))
{
this.pageIndex--;
this.build();
}
@ -508,12 +561,15 @@ public class DetailsPanel {
});
// Collect tooltips.
List<String> tooltips = template.actions().stream().filter(action -> action.tooltip() != null)
.map(action -> this.user.getTranslation(this.world, action.tooltip())).filter(text -> !text.isBlank())
.collect(Collectors.toCollection(() -> new ArrayList<>(template.actions().size())));
List<String> tooltips = template.actions().stream().
filter(action -> action.tooltip() != null).
map(action -> this.user.getTranslation(this.world, action.tooltip())).
filter(text -> !text.isBlank()).
collect(Collectors.toCollection(() -> new ArrayList<>(template.actions().size())));
// Add tooltips.
if (!tooltips.isEmpty()) {
if (!tooltips.isEmpty())
{
// Empty line and tooltips.
builder.description("");
builder.description(tooltips);
@ -522,10 +578,12 @@ public class DetailsPanel {
return builder.build();
}
// ---------------------------------------------------------------------
// Section: Create Material Button
// ---------------------------------------------------------------------
/**
* Create material button panel item.
*
@ -533,15 +591,18 @@ public class DetailsPanel {
* @param slot the slot
* @return the panel item
*/
private PanelItem createMaterialButton(ItemTemplateRecord template, TemplatedPanel.ItemSlot slot) {
if (this.materialCountList.isEmpty()) {
private PanelItem createMaterialButton(ItemTemplateRecord template, TemplatedPanel.ItemSlot slot)
{
if (this.materialCountList.isEmpty())
{
// Does not contain any generators.
return null;
}
int index = this.pageIndex * slot.amountMap().getOrDefault("BLOCK", 1) + slot.slot();
if (index >= this.materialCountList.size()) {
if (index >= this.materialCountList.size())
{
// Out of index.
return null;
}
@ -549,6 +610,7 @@ public class DetailsPanel {
return this.createMaterialButton(template, this.materialCountList.get(index));
}
/**
* This method creates button for material.
*
@ -556,92 +618,106 @@ public class DetailsPanel {
* @param materialCount materialCount which button must be created.
* @return PanelItem for generator tier.
*/
private PanelItem createMaterialButton(ItemTemplateRecord template, Pair<Material, Integer> materialCount) {
private PanelItem createMaterialButton(ItemTemplateRecord template,
Pair<Material, Integer> materialCount)
{
PanelItemBuilder builder = new PanelItemBuilder();
if (template.icon() != null) {
if (template.icon() != null)
{
builder.icon(template.icon().clone());
} else {
}
else
{
builder.icon(PanelUtils.getMaterialItem(materialCount.getKey()));
}
if (materialCount.getValue() < 64) {
if (materialCount.getValue() < 64)
{
builder.amount(materialCount.getValue());
}
if (template.title() != null) {
builder.name(this.user.getTranslation(this.world, template.title(), TextVariables.NUMBER,
String.valueOf(materialCount.getValue()), "[material]",
Utils.prettifyObject(materialCount.getKey(), this.user)));
if (template.title() != null)
{
builder.name(this.user.getTranslation(this.world, template.title(),
TextVariables.NUMBER, String.valueOf(materialCount.getValue()),
"[material]", Utils.prettifyObject(materialCount.getKey(), this.user)));
}
String description = Utils.prettifyDescription(materialCount.getKey(), this.user);
final String reference = "level.gui.buttons.material.";
String blockId = this.user.getTranslationOrNothing(reference + "id", "[id]", materialCount.getKey().name());
String blockId = this.user.getTranslationOrNothing(reference + "id",
"[id]", materialCount.getKey().name());
int blockValue = this.addon.getBlockConfig().getBlockValues().getOrDefault(materialCount.getKey(), 0);
String value = blockValue > 0
? this.user.getTranslationOrNothing(reference + "value", TextVariables.NUMBER,
String.valueOf(blockValue))
: "";
String value = blockValue > 0 ? this.user.getTranslationOrNothing(reference + "value",
TextVariables.NUMBER, String.valueOf(blockValue)) : "";
int blockLimit = this.addon.getBlockConfig().getBlockLimits().getOrDefault(materialCount.getKey(), 0);
String limit = blockLimit > 0
? this.user.getTranslationOrNothing(reference + "limit", TextVariables.NUMBER,
String.valueOf(blockLimit))
: "";
String limit = blockLimit > 0 ? this.user.getTranslationOrNothing(reference + "limit",
TextVariables.NUMBER, String.valueOf(blockLimit)) : "";
String count = this.user.getTranslationOrNothing(reference + "count", TextVariables.NUMBER,
String.valueOf(materialCount.getValue()));
String count = this.user.getTranslationOrNothing(reference + "count",
TextVariables.NUMBER, String.valueOf(materialCount.getValue()));
long calculatedValue = (long) Math.min(blockLimit > 0 ? blockLimit : Integer.MAX_VALUE,
materialCount.getValue()) * blockValue;
long calculatedValue = (long) Math.min(blockLimit > 0 ? blockLimit : Integer.MAX_VALUE, materialCount.getValue()) * blockValue;
String valueText = calculatedValue > 0 ? this.user.getTranslationOrNothing(reference + "calculated",
TextVariables.NUMBER, String.valueOf(calculatedValue)) : "";
if (template.description() != null) {
builder.description(this.user
.getTranslation(this.world, template.description(), "[description]", description, "[id]", blockId,
"[value]", value, "[calculated]", valueText, "[limit]", limit, "[count]", count)
.replaceAll("(?m)^[ \\t]*\\r?\\n", "").replaceAll("(?<!\\\\)\\|", "\n").replace("\\\\\\|", "|"));
if (template.description() != null)
{
builder.description(this.user.getTranslation(this.world, template.description(),
"[description]", description,
"[id]", blockId,
"[value]", value,
"[calculated]", valueText,
"[limit]", limit,
"[count]", count).
replaceAll("(?m)^[ \\t]*\\r?\\n", "").
replaceAll("(?<!\\\\)\\|", "\n").
replace("\\\\\\|", "|"));
}
return builder.build();
}
// ---------------------------------------------------------------------
// Section: Other Methods
// ---------------------------------------------------------------------
/**
* This method is used to open UserPanel outside this class. It will be much
* easier to open panel with single method call then initializing new object.
* This method is used to open UserPanel outside this class. It will be much easier to open panel with single method
* call then initializing new object.
*
* @param addon Level object
* @param world World where user is operating
* @param user User who opens panel
*/
public static void openPanel(Level addon, World world, User user) {
public static void openPanel(Level addon,
World world,
User user)
{
new DetailsPanel(addon, world, user).build();
}
// ---------------------------------------------------------------------
// Section: Enums
// ---------------------------------------------------------------------
/**
* This enum holds possible tabs for current gui.
*/
private enum Tab {
private enum Tab
{
/**
* All block Tab
*/
ALL_BLOCKS,
/**
* Blocks that have value
*/
VALUE_BLOCKS,
/**
* Above Sea level Tab.
*/
@ -656,10 +732,12 @@ public class DetailsPanel {
SPAWNER
}
/**
* Sorting order of blocks.
*/
private enum Filter {
private enum Filter
{
/**
* By name
*/
@ -674,6 +752,7 @@ public class DetailsPanel {
COUNT
}
// ---------------------------------------------------------------------
// Section: Variables
// ---------------------------------------------------------------------

View File

@ -5,11 +5,10 @@
package world.bentobox.level.panels;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.UUID;
import java.util.stream.Collectors;
@ -30,44 +29,50 @@ import world.bentobox.bentobox.managers.RanksManager;
import world.bentobox.level.Level;
import world.bentobox.level.util.Utils;
/**
* This panel opens top likes panel
*/
public class TopLevelPanel {
public class TopLevelPanel
{
// ---------------------------------------------------------------------
// Section: Internal Constructor
// ---------------------------------------------------------------------
/**
* This is internal constructor. It is used internally in current class to avoid
* creating objects everywhere.
* This is internal constructor. It is used internally in current class to avoid creating objects everywhere.
*
* @param addon Level object.
* @param user User who opens Panel.
* @param world World where gui is opened
* @param permissionPrefix Permission Prefix
*/
private TopLevelPanel(Level addon, User user, World world, String permissionPrefix) {
private TopLevelPanel(Level addon, User user, World world, String permissionPrefix)
{
this.addon = addon;
this.user = user;
this.world = world;
this.iconPermission = permissionPrefix + "level.icon";
topIslands = new ArrayList<>();
for (Map.Entry<String, Long> en : addon.getManager().getTopTen(this.world, Level.TEN).entrySet()) {
Optional<Island> is = addon.getIslands().getIslandById(en.getKey());
if (is.isPresent()) {
topIslands.add(new IslandTopRecord(is.get(), en.getValue()));
}
}
this.topIslands = this.addon.getManager().getTopTen(this.world, 10).entrySet().stream().
map(entry -> {
Island island = this.addon.getIslandsManager().getIsland(this.world, entry.getKey());
return new IslandTopRecord(island, entry.getValue());
}).
collect(Collectors.toList());
}
/**
* Build method manages current panel opening. It uses BentoBox PanelAPI that is
* easy to use and users can get nice panels.
* Build method manages current panel opening. It uses BentoBox PanelAPI that is easy to use and users can get nice
* panels.
*/
public void build() {
public void build()
{
TemplatedPanelBuilder panelBuilder = new TemplatedPanelBuilder();
panelBuilder.user(this.user);
@ -82,38 +87,47 @@ public class TopLevelPanel {
panelBuilder.build();
}
// ---------------------------------------------------------------------
// Section: Methods
// ---------------------------------------------------------------------
/**
* Creates fallback based on template.
*
* @param template Template record for fallback button.
* @param index Place of the fallback.
* @return Fallback panel item.
*/
private PanelItem createFallback(ItemTemplateRecord template, long index) {
if (template == null) {
private PanelItem createFallback(ItemTemplateRecord template, long index)
{
if (template == null)
{
return null;
}
PanelItemBuilder builder = new PanelItemBuilder();
if (template.icon() != null) {
if (template.icon() != null)
{
builder.icon(template.icon().clone());
}
if (template.title() != null) {
builder.name(
this.user.getTranslation(this.world, template.title(), TextVariables.NAME, String.valueOf(index)));
} else {
builder.name(this.user.getTranslation(this.world, REFERENCE, TextVariables.NAME, String.valueOf(index)));
if (template.title() != null)
{
builder.name(this.user.getTranslation(this.world, template.title(),
TextVariables.NAME, String.valueOf(index)));
}
else
{
builder.name(this.user.getTranslation(this.world, REFERENCE,
TextVariables.NAME, String.valueOf(index)));
}
if (template.description() != null) {
builder.description(this.user.getTranslation(this.world, template.description(), TextVariables.NUMBER,
String.valueOf(index)));
if (template.description() != null)
{
builder.description(this.user.getTranslation(this.world, template.description(),
TextVariables.NUMBER, String.valueOf(index)));
}
builder.amount(index != 0 ? (int) index : 1);
@ -121,40 +135,46 @@ public class TopLevelPanel {
return builder.build();
}
/**
* This method creates player icon with warp functionality.
*
* @return PanelItem for PanelBuilder.
*/
private PanelItem createPlayerButton(ItemTemplateRecord template, TemplatedPanel.ItemSlot itemSlot) {
private PanelItem createPlayerButton(ItemTemplateRecord template, TemplatedPanel.ItemSlot itemSlot)
{
int index = (int) template.dataMap().getOrDefault("index", 0);
if (index < 1) {
if (index < 1)
{
return this.createFallback(template.fallback(), index);
}
IslandTopRecord islandTopRecord = this.topIslands.size() < index ? null : this.topIslands.get(index - 1);
if (islandTopRecord == null) {
if (islandTopRecord == null)
{
return this.createFallback(template.fallback(), index);
}
return this.createIslandIcon(template, islandTopRecord, index);
}
/**
* This method creates button from template for given island top record.
*
* @param template Icon Template.
* @param islandTopRecord Island Top Record.
* @param index Place Index.
* @return PanelItem for PanelBuilder.
*/
private PanelItem createIslandIcon(ItemTemplateRecord template, IslandTopRecord islandTopRecord, int index) {
private PanelItem createIslandIcon(ItemTemplateRecord template, IslandTopRecord islandTopRecord, int index)
{
// Get player island.
Island island = islandTopRecord.island();
if (island == null) {
if (island == null)
{
return this.createFallback(template.fallback(), index);
}
@ -169,19 +189,23 @@ public class TopLevelPanel {
// Get only possible actions, by removing all inactive ones.
List<ItemTemplateRecord.ActionRecords> activeActions = new ArrayList<>(template.actions());
activeActions.removeIf(action -> {
switch (action.actionType().toUpperCase()) {
activeActions.removeIf(action ->
{
switch (action.actionType().toUpperCase())
{
case "WARP" -> {
return island.getOwner() == null || this.addon.getWarpHook() == null
|| !this.addon.getWarpHook().getWarpSignsManager().hasWarp(this.world, island.getOwner());
return island.getOwner() == null ||
this.addon.getWarpHook() == null ||
!this.addon.getWarpHook().getWarpSignsManager().hasWarp(this.world, island.getOwner());
}
case "VISIT" -> {
return island.getOwner() == null || this.addon.getVisitHook() == null
|| !this.addon.getVisitHook().getAddonManager().preprocessTeleportation(this.user, island, true);
return island.getOwner() == null ||
this.addon.getVisitHook() == null ||
!this.addon.getVisitHook().getAddonManager().preprocessTeleportation(this.user, island);
}
case "VIEW" -> {
return island.getOwner() == null
|| !island.getMemberSet(RanksManager.MEMBER_RANK).contains(this.user.getUniqueId());
return island.getOwner() == null ||
!island.getMemberSet(RanksManager.MEMBER_RANK).contains(this.user.getUniqueId());
}
default -> {
return false;
@ -190,30 +214,33 @@ public class TopLevelPanel {
});
// Add Click handler
builder.clickHandler((panel, user, clickType, i) -> {
for (ItemTemplateRecord.ActionRecords action : activeActions) {
if (clickType == action.clickType() || action.clickType() == ClickType.UNKNOWN) {
switch (action.actionType().toUpperCase()) {
builder.clickHandler((panel, user, clickType, i) ->
{
for (ItemTemplateRecord.ActionRecords action : activeActions)
{
if (clickType == action.clickType() || action.clickType() == ClickType.UNKNOWN)
{
switch (action.actionType().toUpperCase())
{
case "WARP" -> {
this.user.closeInventory();
this.addon.getWarpHook().getWarpSignsManager().warpPlayer(this.world, this.user,
island.getOwner());
this.addon.getWarpHook().getWarpSignsManager().warpPlayer(this.world, this.user, island.getOwner());
}
case "VISIT" ->
// The command call implementation solves necessity to check for all visits
// options,
// like cool down, confirmation and preprocess in single go. Would it be better
// to write
// The command call implementation solves necessity to check for all visits options,
// like cool down, confirmation and preprocess in single go. Would it be better to write
// all logic here?
this.addon.getPlugin().getIWM().getAddon(this.world).flatMap(GameModeAddon::getPlayerCommand)
.ifPresent(command -> {
String mainCommand = this.addon.getVisitHook().getSettings().getPlayerMainCommand();
this.addon.getPlugin().getIWM().getAddon(this.world).
flatMap(GameModeAddon::getPlayerCommand).ifPresent(command ->
{
String mainCommand =
this.addon.getVisitHook().getSettings().getPlayerMainCommand();
if (!mainCommand.isBlank()) {
if (!mainCommand.isBlank())
{
this.user.closeInventory();
this.user.performCommand(
command.getTopLabel() + " " + mainCommand + " " + island.getOwner());
this.user.performCommand(command.getTopLabel() + " " + mainCommand + " " + island.getOwner());
}
});
@ -235,12 +262,15 @@ public class TopLevelPanel {
});
// Collect tooltips.
List<String> tooltips = activeActions.stream().filter(action -> action.tooltip() != null)
.map(action -> this.user.getTranslation(this.world, action.tooltip())).filter(text -> !text.isBlank())
.collect(Collectors.toCollection(() -> new ArrayList<>(template.actions().size())));
List<String> tooltips = activeActions.stream().
filter(action -> action.tooltip() != null).
map(action -> this.user.getTranslation(this.world, action.tooltip())).
filter(text -> !text.isBlank()).
collect(Collectors.toCollection(() -> new ArrayList<>(template.actions().size())));
// Add tooltips.
if (!tooltips.isEmpty()) {
if (!tooltips.isEmpty())
{
// Empty line and tooltips.
builder.description("");
builder.description(tooltips);
@ -249,75 +279,104 @@ public class TopLevelPanel {
return builder.build();
}
/**
* Populate given panel item builder name with values from template and island
* objects.
* Populate given panel item builder name with values from template and island objects.
*
* @param builder the builder
* @param template the template
* @param island the island
*/
private void populateIslandTitle(PanelItemBuilder builder, ItemTemplateRecord template, Island island) {
private void populateIslandTitle(PanelItemBuilder builder,
ItemTemplateRecord template,
Island island)
{
// Get Island Name
String nameText;
if (island.getName() == null || island.getName().isEmpty()) {
nameText = this.user.getTranslation(REFERENCE + "owners-island", PLAYER,
island.getOwner() == null ? this.user.getTranslation(REFERENCE + "unknown")
: this.addon.getPlayers().getName(island.getOwner()));
} else {
if (island.getName() == null || island.getName().isEmpty())
{
nameText = this.user.getTranslation(REFERENCE + "owners-island",
PLAYER,
island.getOwner() == null ?
this.user.getTranslation(REFERENCE + "unknown") :
this.addon.getPlayers().getName(island.getOwner()));
}
else
{
nameText = island.getName();
}
// Template specific title is always more important than custom one.
if (template.title() != null && !template.title().isBlank()) {
builder.name(this.user.getTranslation(this.world, template.title(), TextVariables.NAME, nameText));
} else {
if (template.title() != null && !template.title().isBlank())
{
builder.name(this.user.getTranslation(this.world, template.title(),
TextVariables.NAME, nameText));
}
else
{
builder.name(this.user.getTranslation(REFERENCE + "name", TextVariables.NAME, nameText));
}
}
/**
* Populate given panel item builder icon with values from template and island
* objects.
* Populate given panel item builder icon with values from template and island objects.
*
* @param builder the builder
* @param template the template
* @param island the island
*/
private void populateIslandIcon(PanelItemBuilder builder, ItemTemplateRecord template, Island island) {
private void populateIslandIcon(PanelItemBuilder builder,
ItemTemplateRecord template,
Island island)
{
User owner = island.getOwner() == null ? null : User.getInstance(island.getOwner());
// Get permission or island icon
String permissionIcon = owner == null ? null : Utils.getPermissionValue(owner, this.iconPermission, null);
String permissionIcon = owner == null ? null :
Utils.getPermissionValue(owner, this.iconPermission, null);
Material material;
if (permissionIcon != null && !permissionIcon.equals("*")) {
if (permissionIcon != null && !permissionIcon.equals("*"))
{
material = Material.matchMaterial(permissionIcon);
} else {
}
else
{
material = null;
}
if (material != null) {
if (!material.equals(Material.PLAYER_HEAD)) {
if (material != null)
{
if (!material.equals(Material.PLAYER_HEAD))
{
builder.icon(material);
} else {
}
else
{
builder.icon(owner.getName());
}
} else if (template.icon() != null) {
}
else if (template.icon() != null)
{
builder.icon(template.icon().clone());
} else if (owner != null) {
}
else if (owner != null)
{
builder.icon(owner.getName());
} else {
}
else
{
builder.icon(Material.PLAYER_HEAD);
}
}
/**
* Populate given panel item builder description with values from template and
* island objects.
* Populate given panel item builder description with values from template and island objects.
*
* @param builder the builder
* @param template the template
@ -325,72 +384,94 @@ public class TopLevelPanel {
* @param islandTopRecord the top record object
* @param index place index.
*/
private void populateIslandDescription(PanelItemBuilder builder, ItemTemplateRecord template, Island island,
IslandTopRecord islandTopRecord, int index) {
private void populateIslandDescription(PanelItemBuilder builder,
ItemTemplateRecord template,
Island island,
IslandTopRecord islandTopRecord,
int index)
{
// Get Owner Name
String ownerText = this.user.getTranslation(REFERENCE + "owner", PLAYER,
island.getOwner() == null ? this.user.getTranslation(REFERENCE + "unknown")
: this.addon.getPlayers().getName(island.getOwner()));
String ownerText = this.user.getTranslation(REFERENCE + "owner",
PLAYER,
island.getOwner() == null ?
this.user.getTranslation(REFERENCE + "unknown") :
this.addon.getPlayers().getName(island.getOwner()));
// Get Members Text
String memberText;
if (island.getMemberSet().size() > 1) {
if (island.getMemberSet().size() > 1)
{
StringBuilder memberBuilder = new StringBuilder(
this.user.getTranslationOrNothing(REFERENCE + "members-title"));
for (UUID uuid : island.getMemberSet()) {
for (UUID uuid : island.getMemberSet())
{
User member = User.getInstance(uuid);
if (memberBuilder.length() > 0) {
if (memberBuilder.length() > 0)
{
memberBuilder.append("\n");
}
memberBuilder.append(this.user.getTranslationOrNothing(REFERENCE + "member", PLAYER, member.getName()));
memberBuilder.append(
this.user.getTranslationOrNothing(REFERENCE + "member",
PLAYER, member.getName()));
}
memberText = memberBuilder.toString();
} else {
}
else
{
memberText = "";
}
String placeText = this.user.getTranslation(REFERENCE + "place", TextVariables.NUMBER, String.valueOf(index));
String placeText = this.user.getTranslation(REFERENCE + "place",
TextVariables.NUMBER, String.valueOf(index));
String levelText = this.user.getTranslation(REFERENCE + "level", TextVariables.NUMBER,
this.addon.getManager().formatLevel(islandTopRecord.level()));
String levelText = this.user.getTranslation(REFERENCE + "level",
TextVariables.NUMBER, this.addon.getManager().formatLevel(islandTopRecord.level()));
// Template specific description is always more important than custom one.
if (template.description() != null && !template.description().isBlank()) {
builder.description(this.user
.getTranslation(this.world, template.description(), "[owner]", ownerText, "[members]", memberText,
"[level]", levelText, "[place]", placeText)
.replaceAll("(?m)^[ \\t]*\\r?\\n", "").replaceAll("(?<!\\\\)\\|", "\n").replace("\\\\\\|", "|")); // Not
// a
// regex
// -
// replace
// is
// more
// efficient
} else {
if (template.description() != null && !template.description().isBlank())
{
builder.description(this.user.getTranslation(this.world, template.description(),
"[owner]", ownerText,
"[members]", memberText,
"[level]", levelText,
"[place]", placeText).
replaceAll("(?m)^[ \\t]*\\r?\\n", "").
replaceAll("(?<!\\\\)\\|", "\n").
replace("\\\\\\|", "|")); // Not a regex - replace is more efficient
}
else
{
// Now combine everything.
String descriptionText = this.user.getTranslation(REFERENCE + "description", "[owner]", ownerText,
"[members]", memberText, "[level]", levelText, "[place]", placeText);
String descriptionText = this.user.getTranslation(REFERENCE + "description",
"[owner]", ownerText,
"[members]", memberText,
"[level]", levelText,
"[place]", placeText);
builder.description(descriptionText.replaceAll("(?m)^[ \\t]*\\r?\\n", "").replaceAll("(?<!\\\\)\\|", "\n")
.replace("\\\\\\|", "|")); // Not a regex - replace is more efficient
builder.description(descriptionText.
replaceAll("(?m)^[ \\t]*\\r?\\n", "").
replaceAll("(?<!\\\\)\\|", "\n").
replace("\\\\\\|", "|")); // Not a regex - replace is more efficient
}
}
/**
* Create viewer button panel item.
*
* @return PanelItem for PanelBuilder.
*/
private PanelItem createViewerButton(ItemTemplateRecord template, TemplatedPanel.ItemSlot itemSlot) {
private PanelItem createViewerButton(ItemTemplateRecord template, TemplatedPanel.ItemSlot itemSlot)
{
Island island = this.addon.getIslands().getIsland(this.world, this.user);
if (island == null || island.getOwner() == null) {
if (island == null || island.getOwner() == null)
{
// Player do not have an island.
return null;
}
@ -403,16 +484,18 @@ public class TopLevelPanel {
return this.createIslandIcon(template, topRecord, place);
}
/**
* This method is used to open UserPanel outside this class. It will be much
* easier to open panel with single method call then initializing new object.
* This method is used to open UserPanel outside this class. It will be much easier to open panel with single method
* call then initializing new object.
*
* @param addon Level Addon object
* @param user User who opens panel
* @param world World where gui is opened
* @param permissionPrefix Permission Prefix
*/
public static void openPanel(Level addon, User user, World world, String permissionPrefix) {
public static void openPanel(Level addon, User user, World world, String permissionPrefix)
{
new TopLevelPanel(addon, user, world, permissionPrefix).build();
}
@ -429,12 +512,9 @@ public class TopLevelPanel {
/**
* This record is used internally. It converts user -> level to island -> level.
*
* @param island island
* @param level level
*/
private record IslandTopRecord(Island island, Long level) {
}
private record IslandTopRecord(Island island, Long level) {}
// ---------------------------------------------------------------------
// Section: Variables

View File

@ -58,9 +58,7 @@ public class ValuePanel
this.activeFilter = Filter.NAME_ASC;
this.materialRecordList = Arrays.stream(Material.values()).
filter(Material::isBlock).
filter(Material::isItem). // Remove things like PITCHER_CROP
filter(m -> !m.name().startsWith("LEGACY_")).
filter(this.addon.getBlockConfig()::isNotHiddenBlock).
map(material ->
{
Integer value = this.addon.getBlockConfig().getValue(this.world, material);
@ -585,7 +583,6 @@ public class ValuePanel
return null;
}
@SuppressWarnings("deprecation")
int index = this.pageIndex * slot.amountMap().getOrDefault(BLOCK, 1) + slot.slot();
if (index >= this.elementList.size())

View File

@ -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;
}
}

View File

@ -2,7 +2,7 @@ name: Level
main: world.bentobox.level.Level
version: ${version}${build.number}
icon: DIAMOND
api-version: 2.5.1
api-version: 1.16.5
authors: tastybento

View File

@ -10,10 +10,6 @@
limits:
COBBLESTONE: 10000
NETHERRACK: 1000
# These blocks will never be shown in the GUI even if they have value
hidden-blocks:
- BEDROCK
- AIR
blocks:
ACACIA_BUTTON: 1
ACACIA_DOOR: 2
@ -291,7 +287,7 @@ blocks:
GRANITE_SLAB: 1
GRANITE_STAIRS: 1
GRANITE_WALL: 1
SHORT_GRASS: 4
GRASS: 4
GRASS_BLOCK: 4
GRAVEL: 1
GRAY_BANNER: 2

View File

@ -19,7 +19,7 @@ calculation-timeout: 5
#
# 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 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.
zero-new-island-levels: true
#
@ -72,18 +72,3 @@ sumteamdeaths: false
# Shorthand island level
# Shows large level values rounded down, e.g., 10,345 -> 10k
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: []

View File

@ -8,12 +8,8 @@ admin:
parameters: "<player>"
description: "calculate the island level for player"
sethandicap:
parameters: <player> [+/-]<handicap>
description: |
set or change the island *handicap*
e.g. +10 will remove 10 levels,
30 will set handicap to 30,
-20 will add 20 levels
parameters: <player> <handicap>
description: "set the island handicap, usually the level of the starter island"
changed: "&a Initial island handicap changed from [number] to [new_number]."
invalid-level: "&c Invalid handicap. Use an integer."
levelstatus:
@ -26,18 +22,8 @@ admin:
remove:
description: "remove player from Top Ten"
parameters: "<player>"
stats:
description: "show stats on islands on this server"
title: "Server Island Stats"
world: "&a [name]"
no-data: "&c No data to process."
average-level: "Average Island Level: [number]"
median-level: "Median Island Level: [number]"
mode-level: "Mode Island Level: [number]"
highest-level: "Highest Island Level: [number]"
lowest-level: "Lowest Island Level: [number]"
distribution: "Island Level Distribution:"
islands: "islands"
island:
level:
parameters: "[player]"
@ -46,7 +32,7 @@ island:
estimated-wait: "&a Estimated wait: [number] seconds"
in-queue: "&a You are number [number] in the queue"
island-level-is: "&a Island level is &b[level]"
required-points-to-next-level: "&a 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)"
cooldown: "&c You must wait &b[time] &c seconds until you can do that again"
in-progress: "&6 Island level calculation is in progress..."
@ -116,11 +102,6 @@ level:
limit: "&7 Block limit: &e [number]"
count: "&7 Number of blocks: &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:
name: "&f&l All Blocks"
description: |-
@ -220,7 +201,3 @@ level:
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.
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"

View File

@ -1,184 +0,0 @@
---
admin:
level:
parameters: "<player>"
description: розрахувати рівень острова для гравця
sethandicap:
parameters: "<player> <handicap>"
description: встановити гандикап острова, як правило, рівень острова стартера
changed: "&a Початковий гандикап острова змінено з [number] на [new_number]."
invalid-level: "&c Недійсний гандикап. Використовуйте ціле число."
levelstatus:
description: показати, скільки островів у черзі на сканування
islands-in-queue: "&a Острови в черзі: [number]"
top:
description: показати першу десятку списку
unknown-world: "&c Невідомий світ!"
display: "&f[rank]. &a[name] &7- &b[level]"
remove:
description: видалити гравця з першої десятки
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:
level:
parameters: "[player]"
description: обчисліть свій рівень острова або покажіть рівень [player]
calculating: "&a Розрахунок рівня..."
estimated-wait: "&a Приблизне очікування: [number] секунд"
in-queue: "&a Ви номер [number] у черзі"
island-level-is: "&a Рівень острова &b[level]"
required-points-to-next-level: "&a [points] потрібні бали до наступного рівня"
deaths: "&c([number] смерті)"
cooldown: "&c Ви повинні зачекати &b[time] &c секунд, поки ви зможете зробити
це знову"
in-progress: "&6 Розрахунок рівня острова триває..."
time-out: "&c Розрахунок рівня тривав занадто довго. Будь-ласка спробуйте пізніше."
top:
description: показати першу десятку
gui-title: "& Десятка Кращих"
gui-heading: "&6[name]: &B[rank]"
island-level: "&b Рівень [level]"
warp-to: "&A Варп на острів [name]."
level-details:
above-sea-level-blocks: Блоки над рівнем моря
spawners: Спавера
underwater-blocks: Підводні блоки
all-blocks: Всі блоки
no-island: "&c Немає острова!"
names-island: острів [name].
syntax: "[name] x [number]"
hint: "&c Запустіть рівень, щоб переглянути звіт про блокування"
level:
commands:
value:
parameters: "[hand|<material>]"
description: показує значення блоків. Додайте 'hand' в кінці, щоб відобразити
значення предмета в руках.
gui:
titles:
top: "&0&l Топ островів"
detail-panel: "&0&l острів [name]."
value-panel: "&0&l Значення блоку"
buttons:
island:
empty: "&f&l [name]. місце"
name: "&f&l [name]"
description: |-
[owner]
[members]
[place]
[level]
owners-island: Острів [player].
owner: "&7&l Власник: &r&b [player]"
members-title: "&7&l Члени:"
member: "&b - [player]"
unknown: невідомий
place: "&7&o [number]. &r&7 місце"
level: "&7 Рівень: &o [number]"
material:
name: "&f&l [number] x [material]"
description: |-
[description]
[count]
[value]
[calculated]
[limit]
[id]
id: "&7 Ідентифікатор блоку: &e [id]"
value: "&7 Значення блоку: &e [number]"
limit: "&7 Обмеження блоку: &e [number]"
count: "&7 Кількість блоків: &e [number]"
calculated: "&7 Розраховане значення: &e [number]"
all_blocks:
name: "&f&l Усі блоки"
description: |-
&7 Показати всі блоки
&7 на острові.
above_sea_level:
name: "&f&l Блоки над рівнем моря"
description: |-
&7 Показувати лише блоки
&7, які знаходяться над морем
&7 рівень.
underwater:
name: "&f&l Блоки під рівнем моря"
description: |-
&7 Показувати лише блоки
&7, які знаходяться нижче моря
&7 рівень.
spawner:
name: "&f&l Спанера"
description: "&7 Відображати лише спавнери."
filters:
name:
name: "&f&l Сортувати за назвою"
description: "&7 Сортувати всі блоки за назвою."
value:
name: "&f&l Сортувати за значенням"
description: "&7 Сортувати всі блоки за їх значенням."
count:
name: "&f&l Сортувати за кількістю"
description: "&7 Відсортуйте всі блоки за їх кількістю."
value:
name: "&f&l [material]"
description: |-
[description]
[value]
[underwater]
[limit]
[id]
id: "&7 Ідентифікатор блоку: &e [id]"
value: "&7 Значення блоку: &e [number]"
underwater: "&7 Нижче рівня моря: &e [number]"
limit: "&7 Обмеження блоку: &e [number]"
previous:
name: "&f&l Попередня сторінка"
description: "&7 Перейти на сторінку [number]."
next:
name: "&f&l Наступна сторінка"
description: "&7 Перейти на сторінку [number]."
search:
name: "&f&l Пошук"
description: |-
&7 Пошук конкретного
&7 значення.
search: "&b Значення: [value]"
tips:
click-to-view: "&e Натисніть &7, щоб переглянути."
click-to-previous: "&e Натисніть &7, щоб переглянути попередню сторінку."
click-to-next: "&e Натисніть &7, щоб переглянути наступну сторінку."
click-to-select: "&e Натисніть &7, щоб вибрати."
left-click-to-cycle-up: "&e Клацніть лівою кнопкою миші &7, щоб перейти вгору."
right-click-to-cycle-down: "&e Клацніть правою кнопкою миші &7, щоб перейти
вниз."
left-click-to-change: "&e Клацніть лівою кнопкою миші &7 для редагування."
right-click-to-clear: "&e Клацніть правою кнопкою миші &7, щоб очистити."
click-to-asc: "&e Клацніть &7, щоб відсортувати в порядку збільшення."
click-to-desc: "&e Клацніть &7, щоб відсортувати в порядку зменшення."
click-to-warp: "&e Натисніть &7, щоб деформувати."
click-to-visit: "&e Натисніть &7, щоб відвідати."
right-click-to-visit: "&e Клацніть правою кнопкою миші &7, щоб відвідати."
conversations:
prefix: "&l&6 [BentoBox]: &r"
no-data: "&c Запустіть рівень, щоб переглянути звіт про блокування."
cancel-string: cancel
exit-string: cancel, exit, quit
write-search: "&e Введіть пошукове значення. (Напишіть 'cancel', щоб вийти)"
search-updated: "&a Значення пошуку оновлено."
cancelled: "&c Розмова скасована!"
no-value: "&c Цей предмет не має цінності."
unknown-item: "&c '[material]' не існує в грі."
value: "&7 Значення '[material]' таке: &e[value]"
value-underwater: "&7 Значення '[material]' нижче рівня моря: &e[value]"
empty-hand: "&c У вашій руці немає блоків"

210
src/main/resources/locales/zh-CN.yml Normal file → Executable file
View File

@ -1,93 +1,79 @@
---
admin:
level:
parameters: <player>
parameters: "<player>"
description: 计算指定玩家的岛屿等级
sethandicap:
parameters: <player> <handicap>
description: 设置偏差值, 通常用于抵消初始岛屿等级, 来保证岛屿等级从零开始. 实际岛屿等级 - <handicap> = 最终的岛屿等级
changed: '&a岛屿的偏差值从[number]更改为[new_number]'
invalid-level: '&c偏差值无效, 请使用整数'
parameters: "<player> <handicap>"
description: 设置偏差值,通常用于抵消初始岛屿等级,来保证岛屿等级从零开始。实际岛屿等级 - <handicap> = 最终的岛屿等级
changed: "&a 岛屿的偏差值从 [number] 更改为 [new_number]"
invalid-level: "&c 偏差值无效,请使用整数"
levelstatus:
description: 显示等级计算队列中的岛屿
islands-in-queue: '&a列队中的岛屿: [number]'
islands-in-queue: "&a 列队中的岛屿:[number]"
top:
description: 显示前十名
unknown-world: '&c未知的世界!'
display: '&f[rank]. &a[name] &7- &b[level]'
unknown-world: "&c 未知的世界!"
display: "&f[rank]. &a[name] &7- &b[level]"
remove:
description: 将玩家移出前十名
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: 个岛屿
parameters: "<player>"
island:
level:
parameters: '[player]'
parameters: "[player]"
description: 计算你或指定玩家 [player] 的岛屿等级
calculating: '&a等级计算中...'
estimated-wait: '&a预计等待时间: [number]秒'
in-queue: '&a你处于队列中第[number]个'
island-level-is: '&a岛屿等级为: &b[level]'
required-points-to-next-level: '&a还需[points]点数才能到达下一级'
deaths: '&c([number]次死亡)'
cooldown: '&c还需等待&b[time]&c秒才能再次使用该指令'
in-progress: '&6岛屿等级正在计算中...'
time-out: '&c等级计算超时, 请稍后再试'
calculating: "&a 等级计算中..."
estimated-wait: "&a 预计等待时间:[number] 秒"
in-queue: "&a 你处于队列中第 [number] 个"
island-level-is: "&a 岛屿等级为 &b[level]"
required-points-to-next-level: "&a 还需 [points] 点数才能到达下一级"
deaths: "&c([number] 次死亡)"
cooldown: "&c 还需等待 &b[time] &c秒才能再次使用该指令"
in-progress: "&6 岛级等级正在计算中..."
time-out: "&c 等级计算超时。请稍后再试"
top:
description: 显示前十名
gui-title: '&a前十'
gui-heading: '&6[name]: &B[rank]'
island-level: '&b等级: [level]'
warp-to: '&a正在传送到[name]的岛屿'
gui-title: "&a 前十"
gui-heading: "&6[name]: &B[rank]"
island-level: "&b 等级 [level]"
warp-to: "&a 正在传送到 [name] 的岛屿"
level-details:
above-sea-level-blocks: 海平面以上的方块
spawners: 刷怪笼
underwater-blocks: 水下的方块
all-blocks: 所有方块
no-island: '&c没有岛屿!'
names-island: '[name]的岛屿'
syntax: '[name] x [number]'
hint: '&c运行level指令查看方块报告'
no-island: "&c 没有岛屿!"
names-island: "[name] 的岛屿"
syntax: "[name] x [number]"
hint: "&c 运行level指令查看方块报告"
level:
commands:
value:
parameters: '[hand|<material>]'
description: 显示方块的价值. 在末尾添加'hand'可显示手中方块的价值
parameters: "[hand|<material>]"
description: 显示方块的价值。在末尾添加 'hand' 可显示手中方块的价值
gui:
titles:
top: '&0&l岛屿排行榜'
detail-panel: '&0&l[name]的岛屿'
value-panel: '&0&l方块价值'
top: "&0&l 岛屿排行榜"
detail-panel: "&0&l [name] 的岛屿"
value-panel: "&0&l 方块价值"
buttons:
island:
empty: '&f&l第[name]名'
name: '&f&l[name]'
empty: "&f&l 第 [name] 名"
name: "&f&l [name]"
description: |-
[owner]
[members]
[place]
[level]
owners-island: '[player]的岛屿'
owner: '&7&l岛主: &r&b[player]'
members-title: '&7&l成员: '
member: '&b- [player]'
owners-island: "[player] 的岛屿"
owner: "&7&l 岛主:&r&b [player]"
members-title: "&7&l 成员:"
member: "&b - [player]"
unknown: 未知
place: '&7第&7&o[number]&r&7名'
level: '&7等级: &o[number]'
place: "&7第 &7&o[number] &r&7名"
level: "&7 等级: &o [number]"
material:
name: '&f&l [number] x [material]'
name: "&f&l [number] x [material]"
description: |-
[description]
[count]
@ -95,79 +81,83 @@ level:
[calculated]
[limit]
[id]
id: '&7方块ID: &e[id]'
value: '&7方块价值: &e[number]'
limit: '&7方块限制: &e[number]'
count: '&7方块数量: &e[number]'
calculated: '&7计算值: &e[number]'
id: "&7 方块ID&e [id]"
value: "&7 方块价值:&e [number]"
limit: "&7 方块限制:&e [number]"
count: "&7 方块数量:&e [number]"
calculated: "&7 计算值:&e [number]"
all_blocks:
name: '&f&l所有方块'
description: '&7显示岛屿上所有的方块'
name: "&f&l 所有方块"
description: "&7 显示岛屿上所有的方块"
above_sea_level:
name: '&f&l海平面以上的方块'
description: '&7只显示所有海平面以上的方块'
name: "&f&l 海平面以上的方块"
description: |-
&7 只显示所有
&7 海平面以上的方块
underwater:
name: '&f&l海平面以下的方块'
description: 只显示所有海平面以下的方块
name: "&f&l 海平面以下的方块"
description: |-
&7 只显示所有
&7 海平面以下的方块
spawner:
name: '&f&l刷怪笼'
description: '&7只显示刷怪笼'
name: "&f&l 刷怪笼"
description: "&7 只显示刷怪笼"
filters:
name:
name: '&f&l按名称排序'
description: '&7通过名称排序所有的方块'
name: "&f&l 按名称排序"
description: "&7 通过名称排序所有的方块"
value:
name: '&f&l按价值排序'
description: '&7通过价值排序所有的方块'
name: "&f&l 按价值排序"
description: "&7 通过价值排序所有的方块"
count:
name: '&f&l按数量排序'
description: '&7通过数量排序所有方块'
name: "&f&l 按数量排序"
description: "&7 通过数量排序所有方块"
value:
name: '&f&l[material]'
name: "&f&l [material]"
description: |-
[description]
[value]
[underwater]
[limit]
[id]
id: '&7方块ID: &e[id]'
value: '&7方块价值: &e[number]'
underwater: '&7海平面以下方块的价值: &e[number]'
limit: '&7方块限制: &e[number]'
id: "&7 方块ID&e [id]"
value: "&7 方块价值:&e [number]"
underwater: "&7 海平面以下方块的价值:&e [number]"
limit: "&7 方块限制:&e [number]"
previous:
name: '&f&l上一页'
description: '&7切换到第[number]页'
name: "&f&l 上一页"
description: "&7 切换到第 [number] 页"
next:
name: '&f&l下一页'
description: '&7切换到第[number]页'
name: "&f&l 下一页"
description: "&7 切换到第 [number] 页"
search:
name: '&f&l搜索'
description: '&7搜索特定的内容'
search: '&b搜索值: [value]'
name: "&f&l 搜索"
description: "&7 搜索特定的内容"
search: "&b 搜索值:[value]"
tips:
click-to-view: '&e点击 &7查看'
click-to-previous: '&e点击 &7查看上一页'
click-to-next: '&e点击 &7查看下一页'
click-to-select: '&e点击 &7选择'
left-click-to-cycle-up: '&e左键 &7向上循环'
right-click-to-cycle-down: '&e右键 &7向下循环'
left-click-to-change: '&e左键 &7编辑'
right-click-to-clear: '&e右键 &7清除'
click-to-asc: '&e点击 &7以升序排序'
click-to-desc: '&e点击 &7以降序排序'
click-to-warp: '&e点击 &7去岛屿传送点'
click-to-visit: '&e点击 &7参观'
right-click-to-visit: '&e右键 &7查看'
click-to-view: "&e 点击 &7 查看"
click-to-previous: "&e 点击 &7 查看上一页"
click-to-next: "&e 点击 &7 查看下一页"
click-to-select: "&e 点击 &7 选择"
left-click-to-cycle-up: "&e 左键点击 &7 向上循环"
right-click-to-cycle-down: "&e 右键点击 &7 向下循环"
left-click-to-change: "&e 左键点击 &7 编辑"
right-click-to-clear: "&e 右键点击 &7 清除"
click-to-asc: "&e 点击 &7 以升序排序"
click-to-desc: "&e 点击 &7 以降序排序"
click-to-warp: "&e 点击 &7 去岛屿传送点"
click-to-visit: "&e 点击 &7 参观"
right-click-to-visit: "&e 右键点击 &7 查看"
conversations:
prefix: '&l&6[BentoBox]: &r'
no-data: '&c运行level指令查看方块报告'
prefix: "&l&6 [BentoBox]: &r"
no-data: "&c 运行level指令查看方块报告"
cancel-string: cancel
exit-string: cancel, exit, quit
write-search: '&e请输入要搜索的值. (输入''cancel''退出)'
search-updated: '&a搜索值已更新'
cancelled: '&c对话已取消'
no-value: '&c这件物品一文不值'
unknown-item: '&c物品''[material]''在游戏中不存在'
value: '&7物品''[material]''的价值: &e[value]'
value-underwater: '&7物品''[material]''在海平面以下的价值: &e[value]'
empty-hand: '&c你的手中没有拿着方块'
write-search: "&e 请输入要搜索的值. (输入 'cancel' 退出)"
search-updated: "&a 搜索值已更新"
cancelled: "&c 对话已取消!"
no-value: "&c 这件物品一文不值"
unknown-item: "&c 物品 '[material]' 在游戏中不存在"
value: "&7 物品 '[material]' 的价值:&e[value]"
value-underwater: "&7 物品 '[material]' 在海平面以下的价值:&e[value]"
empty-hand: "&c 你的手中没有拿着方块"

View File

@ -1,73 +1,27 @@
# Name of panel used for indentification in the code
detail_panel:
# Title of the panel shown to the user. This is a reference and the reference will be translatable in the locale file
title: level.gui.titles.detail-panel
# The type of panel to show. Options are INVENTORY, HOPPER, DROPPER. INVENTORY is that standard chest inventory and
# the others refer to the inventories shown for those items.
type: INVENTORY
# The background of the panel. These items will be shown if other items are not there. STAINED_GLASS_PANEs give a good effect.
background:
icon: BLACK_STAINED_GLASS_PANE
# Each item may have text applied to it, but usually for background items, nothing is shown.
title: "&b&r" # Empty text. This is using the Bukkit chat color coding with &'s.
title: "&b&r" # Empty text
border:
# The border of each panel may be shown as a different item.
# It can be used to provide a contrast to items in the panel.
icon: BLACK_STAINED_GLASS_PANE
title: "&b&r" # Empty text
# This tag indicates which rows in the panel must be shown. The panel will be sized vertically accordingly. This does not include the borders.
# This can be a list and rows must be between 1 and 6, if used.
force-shown: []
# The content section contains details of each item/button in the panel. The numbers indicate the rows and then then columns of each item.
content:
# Row number
1:
# Column number
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: STONE
# 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.all_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.all_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: ALL_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
4:
3:
icon: GRASS_BLOCK
title: level.gui.buttons.above_sea_level.name
description: level.gui.buttons.above_sea_level.description
@ -78,7 +32,7 @@ detail_panel:
view:
click-type: unknown
tooltip: level.gui.tips.click-to-view
5:
4:
icon: WATER_BUCKET
title: level.gui.buttons.underwater.name
description: level.gui.buttons.underwater.description
@ -89,7 +43,7 @@ detail_panel:
view:
click-type: unknown
tooltip: level.gui.tips.click-to-view
6:
5:
icon: SPAWNER
title: level.gui.buttons.spawner.name
description: level.gui.buttons.spawner.description
@ -103,12 +57,12 @@ detail_panel:
9:
# You can create multiple buttons. By default it is one.
icon: IRON_TRAPDOOR
# [filter] is a placeholder for different filter types. It will be replaced with name, value, count.
# [filter] is placeholder for different filter types. It will be replaced with name, value, count.
title: level.gui.buttons.filters.[filter].name
description: level.gui.buttons.filters.[filter].description
data:
type: FILTER
# the value of filter button. Suggestion is to leave first value to name if you use single button.
# the value of filter button. Suggestion is to leave fist value to name if you use single button.
filter: NAME
actions:
up:
@ -122,7 +76,6 @@ detail_panel:
# click-type: unknown
# tooltip: level.gui.tips.click-to-select
2:
# If a button is used repeatedly then it can be mentioned by name and then defined in the 'reusable' section
2: material_button
3: material_button
4: material_button
@ -132,11 +85,7 @@ detail_panel:
8: material_button
3:
1:
# In this case, the icon is defined as a TIPPED_ARROW with a color.
# CustomPotionColor uses the Decimal description of a Color, just as leather armor does.
# All you need to do is take a hex code of a color (like #ff00aa) which represents red,
# green, blue as 2 hex digits each and convert that number into a decimal, using a hex to decimal calculator.
icon: tipped_arrow{CustomPotionColor:11546150}
icon: TIPPED_ARROW:INSTANT_HEAL::::1
title: level.gui.buttons.previous.name
description: level.gui.buttons.previous.description
data:
@ -154,7 +103,7 @@ detail_panel:
7: material_button
8: material_button
9:
icon: tipped_arrow{CustomPotionColor:8439583}
icon: TIPPED_ARROW:JUMP::::1
title: level.gui.buttons.next.name
description: level.gui.buttons.next.description
data:
@ -172,12 +121,8 @@ detail_panel:
6: material_button
7: material_button
8: material_button
# This is where reuable buttons are defined.
reusable:
# This is the name of the button that is referenced
material_button:
# If the icon for a button is not defined, it defaults to AIR and so effectively will not be shown.
# icons are usually not defined if the icon is going to be dynamically set in the panel, e.g. in this case the material will vary
#icon: STONE
title: level.gui.buttons.material.name
description: level.gui.buttons.material.description

View File

@ -1,28 +1,15 @@
# Name of panel used for indentification in the code
top_panel:
# Title of the panel shown to the user. This is a reference and the reference will be translatable in the locale file
title: level.gui.titles.top
# The type of panel to show. Options are INVENTORY, HOPPER, DROPPER. INVENTORY is that standard chest inventory and
# the others refer to the inventories shown for those items.
type: INVENTORY
# The background of the panel. These items will be shown if other items are not there. STAINED_GLASS_PANEs give a good effect.
background:
icon: BLACK_STAINED_GLASS_PANE
# Each item may have text applied to it, but usually for background items, nothing is shown.
title: "&b&r" # Empty text
border:
# The border of each panel may be shown as a different item.
# It can be used to provide a contrast to items in the panel.
icon: BLACK_STAINED_GLASS_PANE
title: "&b&r" # Empty text
# This tag indicates which rows in the panel must be shown. The panel will be sized vertically accordingly. This does not include the borders.
# This can be a list and rows must be between 1 and 6, if used.
force-shown: [2,3,4,5]
# The content section contains details of each item/button in the panel. The numbers indicate the rows and then then columns of each item.
content:
# Row number
2:
# Column number
5:
#icon: PLAYER_HEAD
title: level.gui.buttons.island.name

View File

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

View File

@ -61,7 +61,6 @@ import world.bentobox.bentobox.managers.FlagsManager;
import world.bentobox.bentobox.managers.IslandWorldManager;
import world.bentobox.bentobox.managers.IslandsManager;
import world.bentobox.bentobox.managers.PlaceholdersManager;
import world.bentobox.bentobox.util.Util;
import world.bentobox.level.config.BlockConfig;
import world.bentobox.level.config.ConfigSettings;
import world.bentobox.level.listeners.IslandActivitiesListeners;
@ -73,7 +72,7 @@ import world.bentobox.level.listeners.JoinLeaveListener;
*/
@SuppressWarnings("deprecation")
@RunWith(PowerMockRunner.class)
@PrepareForTest({ Bukkit.class, BentoBox.class, User.class, Util.class })
@PrepareForTest({Bukkit.class, BentoBox.class, User.class})
public class LevelTest {
private static File jFile;
@ -175,14 +174,15 @@ public class LevelTest {
IslandWorldManager iwm = mock(IslandWorldManager.class);
when(plugin.getIWM()).thenReturn(iwm);
// Player has island to begin with
when(im.getIsland(Mockito.any(), Mockito.any(UUID.class))).thenReturn(island);
when(plugin.getIslands()).thenReturn(im);
// Locales
// Return the reference (USE THIS IN THE FUTURE)
when(user.getTranslation(Mockito.anyString()))
.thenAnswer((Answer<String>) invocation -> invocation.getArgument(0, String.class));
when(user.getTranslation(Mockito.anyString())).thenAnswer((Answer<String>) invocation -> invocation.getArgument(0, String.class));
// Server
PowerMockito.mockStatic(Bukkit.class);
@ -190,27 +190,20 @@ public class LevelTest {
when(Bukkit.getServer()).thenReturn(server);
when(Bukkit.getLogger()).thenReturn(Logger.getAnonymousLogger());
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 = new Level();
File dataFolder = new File("addons/Level");
addon.setDataFolder(dataFolder);
addon.setFile(jFile);
AddonDescription desc = new AddonDescription.Builder("bentobox", "Level", "1.3").description("test")
.authors("tastybento").build();
AddonDescription desc = new AddonDescription.Builder("bentobox", "Level", "1.3").description("test").authors("tastybento").build();
addon.setDescription(desc);
addon.setSettings(new ConfigSettings());
// Addons manager
when(plugin.getAddonsManager()).thenReturn(am);
// One game mode
when(am.getGameModeAddons()).thenReturn(Collections.singletonList(gameMode));
AddonDescription desc2 = new AddonDescription.Builder("bentobox", "BSkyBlock", "1.3").description("test")
.authors("tasty").build();
AddonDescription desc2 = new AddonDescription.Builder("bentobox", "BSkyBlock", "1.3").description("test").authors("tasty").build();
when(gameMode.getDescription()).thenReturn(desc2);
when(gameMode.getOverWorld()).thenReturn(world);
@ -226,7 +219,9 @@ public class LevelTest {
when(plugin.getFlagsManager()).thenReturn(fm);
when(fm.getFlags()).thenReturn(Collections.emptyList());
// Bukkit
PowerMockito.mockStatic(Bukkit.class);
when(Bukkit.getScheduler()).thenReturn(scheduler);
ItemMeta meta = mock(ItemMeta.class);
ItemFactory itemFactory = mock(ItemFactory.class);
@ -265,7 +260,10 @@ public class LevelTest {
private static void deleteAll(File file) throws IOException {
if (file.exists()) {
Files.walk(file.toPath()).sorted(Comparator.reverseOrder()).map(Path::toFile).forEach(File::delete);
Files.walk(file.toPath())
.sorted(Comparator.reverseOrder())
.map(Path::toFile)
.forEach(File::delete);
}
}
@ -278,7 +276,7 @@ public class LevelTest {
verify(plugin).logWarning("[Level] Level Addon: No such world in blockconfig.yml : acidisland_world");
verify(plugin).log("[Level] Level hooking into BSkyBlock");
verify(cmd, times(3)).getAddon(); // 3 commands
verify(adminCmd, times(5)).getAddon(); // Five commands
verify(adminCmd, times(4)).getAddon(); // Four commands
// Placeholders
verify(phm).registerPlaceholder(eq(addon), eq("bskyblock_island_level"), any());
verify(phm).registerPlaceholder(eq(addon), eq("bskyblock_visited_island_level"), any());

View File

@ -82,6 +82,7 @@ public class LevelsManagerTest {
@Mock
private Settings pluginSettings;
// Class under test
private LevelsManager lm;
@Mock
@ -94,7 +95,7 @@ public class LevelsManagerTest {
private World world;
@Mock
private Player player;
@Mock
private ConfigSettings settings;
@Mock
private User user;
@ -113,11 +114,12 @@ public class LevelsManagerTest {
@Mock
private BukkitScheduler scheduler;
@SuppressWarnings("unchecked")
@BeforeClass
public static void beforeClass() {
// This has to be done beforeClass otherwise the tests will interfere with each
// other
// This has to be done beforeClass otherwise the tests will interfere with each other
handler = mock(AbstractDatabaseHandler.class);
// Database
PowerMockito.mockStatic(DatabaseSetup.class);
@ -160,12 +162,12 @@ public class LevelsManagerTest {
when(island.getMemberSet()).thenReturn(iset);
when(island.getOwner()).thenReturn(uuid);
when(island.getWorld()).thenReturn(world);
when(island.getUniqueId()).thenReturn(uuid.toString());
when(island.getUniqueId()).thenReturn(UUID.randomUUID().toString());
// Default to uuid's being island owners
when(im.hasIsland(eq(world), any(UUID.class))).thenReturn(true);
when(im.isOwner(eq(world), any())).thenReturn(true);
when(im.getOwner(any(), any(UUID.class))).thenAnswer(in -> in.getArgument(1, UUID.class));
when(im.getIsland(world, uuid)).thenReturn(island);
when(im.getIslandById(anyString())).thenReturn(Optional.of(island));
when(im.getIslandById(anyString(), eq(false))).thenReturn(Optional.of(island));
// Player
when(player.getUniqueId()).thenReturn(uuid);
@ -175,7 +177,6 @@ public class LevelsManagerTest {
when(world.getName()).thenReturn("bskyblock-world");
// Settings
settings = new ConfigSettings();
when(addon.getSettings()).thenReturn(settings);
// User
@ -246,13 +247,15 @@ public class LevelsManagerTest {
private static void deleteAll(File file) throws IOException {
if (file.exists()) {
Files.walk(file.toPath()).sorted(Comparator.reverseOrder()).map(Path::toFile).forEach(File::delete);
Files.walk(file.toPath())
.sorted(Comparator.reverseOrder())
.map(Path::toFile)
.forEach(File::delete);
}
}
/**
* Test method for
* {@link world.bentobox.level.LevelsManager#calculateLevel(UUID, world.bentobox.bentobox.database.objects.Island)}.
* Test method for {@link world.bentobox.level.LevelsManager#calculateLevel(UUID, world.bentobox.bentobox.database.objects.Island)}.
*/
@Test
public void testCalculateLevel() {
@ -280,8 +283,7 @@ public class LevelsManagerTest {
}
/**
* Test method for
* {@link world.bentobox.level.LevelsManager#getInitialLevel(world.bentobox.bentobox.database.objects.Island)}.
* Test method for {@link world.bentobox.level.LevelsManager#getInitialLevel(world.bentobox.bentobox.database.objects.Island)}.
*/
@Test
public void testGetInitialLevel() {
@ -289,8 +291,7 @@ public class LevelsManagerTest {
}
/**
* Test method for
* {@link world.bentobox.level.LevelsManager#getIslandLevel(org.bukkit.World, java.util.UUID)}.
* Test method for {@link world.bentobox.level.LevelsManager#getIslandLevel(org.bukkit.World, java.util.UUID)}.
*/
@Test
public void testGetIslandLevel() {
@ -298,8 +299,7 @@ public class LevelsManagerTest {
}
/**
* Test method for
* {@link world.bentobox.level.LevelsManager#getPointsToNextString(org.bukkit.World, java.util.UUID)}.
* Test method for {@link world.bentobox.level.LevelsManager#getPointsToNextString(org.bukkit.World, java.util.UUID)}.
*/
@Test
public void testGetPointsToNextString() {
@ -310,8 +310,7 @@ public class LevelsManagerTest {
}
/**
* Test method for
* {@link world.bentobox.level.LevelsManager#getIslandLevelString(org.bukkit.World, java.util.UUID)}.
* Test method for {@link world.bentobox.level.LevelsManager#getIslandLevelString(org.bukkit.World, java.util.UUID)}.
*/
@Test
public void testGetIslandLevelString() {
@ -319,8 +318,7 @@ public class LevelsManagerTest {
}
/**
* Test method for
* {@link world.bentobox.level.LevelsManager#getLevelsData(java.util.UUID)}.
* Test method for {@link world.bentobox.level.LevelsManager#getLevelsData(java.util.UUID)}.
*/
@Test
public void testGetLevelsData() {
@ -334,7 +332,7 @@ public class LevelsManagerTest {
@Test
public void testFormatLevel() {
assertEquals("123456789", lm.formatLevel(123456789L));
settings.setShorthand(true);
when(settings.isShorthand()).thenReturn(true);
assertEquals("123.5M", lm.formatLevel(123456789L));
assertEquals("1.2k", lm.formatLevel(1234L));
assertEquals("123.5G", lm.formatLevel(123456789352L));
@ -344,44 +342,39 @@ public class LevelsManagerTest {
}
/**
* Test method for
* {@link world.bentobox.level.LevelsManager#getTopTen(org.bukkit.World, int)}.
* Test method for {@link world.bentobox.level.LevelsManager#getTopTen(org.bukkit.World, int)}.
*/
@Test
public void testGetTopTenEmpty() {
Map<String, Long> tt = lm.getTopTen(world, Level.TEN);
Map<UUID, Long> tt = lm.getTopTen(world, Level.TEN);
assertTrue(tt.isEmpty());
}
/**
* Test method for
* {@link world.bentobox.level.LevelsManager#getTopTen(org.bukkit.World, int)}.
* Test method for {@link world.bentobox.level.LevelsManager#getTopTen(org.bukkit.World, int)}.
*/
@Test
public void testGetTopTen() {
testLoadTopTens();
Map<String, Long> tt = lm.getTopTen(world, Level.TEN);
Map<UUID, Long> tt = lm.getTopTen(world, Level.TEN);
assertFalse(tt.isEmpty());
assertEquals(1, tt.size());
assertEquals(1, lm.getTopTen(world, 1).size());
}
/**
* Test method for
* {@link world.bentobox.level.LevelsManager#getWeightedTopTen(org.bukkit.World, int)}.
* Test method for {@link world.bentobox.level.LevelsManager#getTopTen(org.bukkit.World, int)}.
*/
@Test
public void testGetWeightedTopTen() {
public void testGetTopTenNoOwners() {
when(im.isOwner(eq(world), any())).thenReturn(false);
testLoadTopTens();
Map<Island, Long> tt = lm.getWeightedTopTen(world, Level.TEN);
assertFalse(tt.isEmpty());
assertEquals(1, tt.size());
assertEquals(1, lm.getTopTen(world, 1).size());
Map<UUID, Long> tt = lm.getTopTen(world, Level.TEN);
assertTrue(tt.isEmpty());
}
/**
* Test method for
* {@link world.bentobox.level.LevelsManager#hasTopTenPerm(org.bukkit.World, java.util.UUID)}.
* Test method for {@link world.bentobox.level.LevelsManager#hasTopTenPerm(org.bukkit.World, java.util.UUID)}.
*/
@Test
public void testHasTopTenPerm() {
@ -397,30 +390,28 @@ public class LevelsManagerTest {
lm.loadTopTens();
PowerMockito.verifyStatic(Bukkit.class); // 1
Bukkit.getScheduler();
verify(scheduler).runTaskAsynchronously(eq(plugin), task.capture()); // Capture the task in the scheduler
task.getValue().run(); // run it
verify(scheduler).runTaskAsynchronously(eq(plugin), task.capture());
task.getValue().run();
verify(addon).log("Generating rankings");
verify(addon).log("Generated rankings for bskyblock-world");
}
/**
* Test method for
* {@link world.bentobox.level.LevelsManager#removeEntry(org.bukkit.World, java.util.UUID)}.
* Test method for {@link world.bentobox.level.LevelsManager#removeEntry(org.bukkit.World, java.util.UUID)}.
*/
@Test
public void testRemoveEntry() {
testLoadTopTens();
Map<String, Long> tt = lm.getTopTen(world, Level.TEN);
assertTrue(tt.containsKey(uuid.toString()));
lm.removeEntry(world, uuid.toString());
Map<UUID, Long> tt = lm.getTopTen(world, Level.TEN);
assertTrue(tt.containsKey(uuid));
lm.removeEntry(world, uuid);
tt = lm.getTopTen(world, Level.TEN);
assertFalse(tt.containsKey(uuid.toString()));
assertFalse(tt.containsKey(uuid));
}
/**
* Test method for
* {@link world.bentobox.level.LevelsManager#setInitialIslandLevel(world.bentobox.bentobox.database.objects.Island, long)}.
* Test method for {@link world.bentobox.level.LevelsManager#setInitialIslandLevel(world.bentobox.bentobox.database.objects.Island, long)}.
*/
@Test
public void testSetInitialIslandLevel() {
@ -429,8 +420,7 @@ public class LevelsManagerTest {
}
/**
* Test method for
* {@link world.bentobox.level.LevelsManager#setIslandLevel(org.bukkit.World, java.util.UUID, long)}.
* Test method for {@link world.bentobox.level.LevelsManager#setIslandLevel(org.bukkit.World, java.util.UUID, long)}.
*/
@Test
public void testSetIslandLevel() {
@ -439,23 +429,23 @@ public class LevelsManagerTest {
}
/**
* Test method for
* {@link world.bentobox.level.LevelsManager#getRank(World, UUID)}
* Test method for {@link world.bentobox.level.LevelsManager#getRank(World, UUID)}
*/
@Test
public void testGetRank() {
lm.createAndCleanRankings(world);
Map<World, TopTenData> ttl = lm.getTopTenLists();
Map<String, Long> tt = ttl.get(world).getTopTen();
Map<UUID, Long> tt = ttl.get(world).getTopTen();
for (long i = 100; i < 150; i++) {
tt.put(UUID.randomUUID().toString(), i);
tt.put(UUID.randomUUID(), i);
}
// Put island as lowest rank
tt.put(uuid.toString(), 10L);
// Put player as lowest rank
tt.put(uuid, 10L);
assertEquals(51, lm.getRank(world, uuid));
// Put island as highest rank
tt.put(uuid.toString(), 1000L);
// Put player as highest rank
tt.put(uuid, 1000L);
assertEquals(1, lm.getRank(world, uuid));
// Unknown UUID - lowest rank + 1
assertEquals(52, lm.getRank(world, UUID.randomUUID()));

View File

@ -3,18 +3,16 @@ package world.bentobox.level;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Optional;
import java.util.UUID;
import java.util.stream.Collectors;
@ -56,7 +54,7 @@ public class PlaceholderManagerTest {
@Mock
private BentoBox plugin;
private PlaceholderManager phm;
private PlaceholderManager pm;
@Mock
private PlaceholdersManager bpm;
@Mock
@ -69,25 +67,13 @@ public class PlaceholderManagerTest {
private Island island;
@Mock
private User user;
private static final Map<UUID, String> names = new LinkedHashMap<>();
static {
names.put(UUID.randomUUID(), "tasty");
names.put(UUID.randomUUID(), "bento");
names.put(UUID.randomUUID(), "fred");
names.put(UUID.randomUUID(), "bonne");
names.put(UUID.randomUUID(), "cyprien");
names.put(UUID.randomUUID(), "mael");
names.put(UUID.randomUUID(), "joe");
names.put(UUID.randomUUID(), "horacio");
names.put(UUID.randomUUID(), "steph");
names.put(UUID.randomUUID(), "vicky");
}
private Map<String, Island> islands = new HashMap<>();
private Map<String, Long> map = new LinkedHashMap<>();
private Map<Island, Long> map2 = new LinkedHashMap<>();
private Map<UUID, String> names = new HashMap<>();
private static final List<String> NAMES = List.of("tasty", "bento", "fred", "bonne", "cyprien", "mael", "joe", "horacio", "steph", "vicky");
private Map<UUID, Island> islands = new HashMap<>();
private Map<UUID, Long> map = new HashMap<>();
private @NonNull IslandLevels data;
@Mock
private PlayersManager pm;
private PlayersManager players;
/**
* @throws java.lang.Exception
@ -97,32 +83,29 @@ public class PlaceholderManagerTest {
when(addon.getPlugin()).thenReturn(plugin);
// Users
when(addon.getPlayers()).thenReturn(pm);
when(addon.getPlayers()).thenReturn(players);
// Users
when(user.getWorld()).thenReturn(world);
when(user.getLocation()).thenReturn(mock(Location.class));
int i = 0;
for (Entry<UUID, String> n : names.entrySet()) {
UUID uuid = UUID.randomUUID(); // Random island ID
Long value = (long)(100 - i++);
map.put(uuid.toString(), value); // level
for (int i = 0; i < Level.TEN; i++) {
UUID uuid = UUID.randomUUID();
names.put(uuid, NAMES.get(i));
map.put(uuid, (long)(100 - i));
Island is = new Island();
is.setUniqueId(uuid.toString());
is.setOwner(n.getKey());
is.setName(n.getValue() + "'s island");
islands.put(uuid.toString(), is);
map2.put(is, value);
is.setOwner(uuid);
is.setName(NAMES.get(i) + "'s island");
islands.put(uuid, is);
}
// Sort
map = map.entrySet().stream()
.sorted(Collections.reverseOrder(Map.Entry.comparingByValue()))
.collect(Collectors.toMap( Map.Entry::getKey, Map.Entry::getValue, (e1, e2) -> e1, LinkedHashMap::new));
when(pm.getName(any())).thenAnswer((Answer<String>) invocation -> names.getOrDefault(invocation.getArgument(0, UUID.class), "unknown"));
when(players.getName(any())).thenAnswer((Answer<String>) invocation -> names.getOrDefault(invocation.getArgument(0, UUID.class), "unknown"));
Map<UUID, Integer> members = new HashMap<>();
names.forEach((uuid, l) -> members.put(uuid, RanksManager.MEMBER_RANK));
islands.values().forEach(is -> is.setMembers(members));
map.forEach((uuid, l) -> members.put(uuid, RanksManager.MEMBER_RANK));
islands.values().forEach(i -> i.setMembers(members));
// Placeholders manager for plugin
@ -137,8 +120,7 @@ public class PlaceholderManagerTest {
// Islands
when(im.getIsland(any(World.class), any(User.class))).thenReturn(island);
when(im.getIslandAt(any(Location.class))).thenReturn(Optional.of(island));
when(im.getIslandById(anyString())).thenAnswer((Answer<Optional<Island>>) invocation -> Optional.of(islands.get(invocation.getArgument(0, String.class))));
when(im.getIslands(any(), any(UUID.class))).thenReturn(new ArrayList<>(islands.values()));
when(im.getIsland(any(World.class), any(UUID.class))).thenAnswer((Answer<Island>) invocation -> islands.get(invocation.getArgument(1, UUID.class)));
when(addon.getIslands()).thenReturn(im);
// Levels Manager
@ -147,7 +129,6 @@ public class PlaceholderManagerTest {
when(lm.getPointsToNextString(any(), any())).thenReturn("1234567");
when(lm.getIslandMaxLevel(any(), any())).thenReturn(987654L);
when(lm.getTopTen(world, Level.TEN)).thenReturn(map);
when(lm.getWeightedTopTen(world, Level.TEN)).thenReturn(map2);
when(lm.formatLevel(any())).thenAnswer((Answer<String>) invocation -> invocation.getArgument(0, Long.class).toString());
data = new IslandLevels("uniqueId");
@ -155,12 +136,11 @@ public class PlaceholderManagerTest {
when(lm.getLevelsData(island)).thenReturn(data);
when(addon.getManager()).thenReturn(lm);
phm = new PlaceholderManager(addon);
pm = new PlaceholderManager(addon);
}
/**
* Test method for
* {@link world.bentobox.level.PlaceholderManager#PlaceholderManager(world.bentobox.level.Level)}.
* Test method for {@link world.bentobox.level.PlaceholderManager#PlaceholderManager(world.bentobox.level.Level)}.
*/
@Test
public void testPlaceholderManager() {
@ -168,12 +148,11 @@ public class PlaceholderManagerTest {
}
/**
* Test method for
* {@link world.bentobox.level.PlaceholderManager#registerPlaceholders(world.bentobox.bentobox.api.addons.GameModeAddon)}.
* Test method for {@link world.bentobox.level.PlaceholderManager#registerPlaceholders(world.bentobox.bentobox.api.addons.GameModeAddon)}.
*/
@Test
public void testRegisterPlaceholders() {
phm.registerPlaceholders(gm);
pm.registerPlaceholders(gm);
// Island Level
verify(bpm).registerPlaceholder(eq(addon), eq("aoneblock_island_level"), any());
verify(bpm).registerPlaceholder(eq(addon), eq("aoneblock_island_level_raw"), any());
@ -203,99 +182,78 @@ public class PlaceholderManagerTest {
}
/**
* Test method for
* {@link world.bentobox.level.PlaceholderManager#getRankName(org.bukkit.World, int)}.
* Test method for {@link world.bentobox.level.PlaceholderManager#getRankName(org.bukkit.World, int)}.
*/
@Test
public void testGetRankName() {
// Test extremes
assertEquals("tasty", phm.getRankName(world, 0, false));
assertEquals("vicky", phm.getRankName(world, 100, false));
assertEquals("tasty", pm.getRankName(world, 0));
assertEquals("vicky", pm.getRankName(world, 100));
// Test the ranks
int rank = 1;
for (String name : names.values()) {
assertEquals(name, phm.getRankName(world, rank++, false));
for (String name : NAMES) {
assertEquals(name, pm.getRankName(world, rank++));
}
}
/**
* Test method for
* {@link world.bentobox.level.PlaceholderManager#getRankIslandName(org.bukkit.World, int)}.
* Test method for {@link world.bentobox.level.PlaceholderManager#getRankIslandName(org.bukkit.World, int)}.
*/
@Test
public void testGetRankIslandName() {
// Test extremes
assertEquals("tasty's island", phm.getRankIslandName(world, 0, false));
assertEquals("vicky's island", phm.getRankIslandName(world, 100, false));
assertEquals("tasty's island", pm.getRankIslandName(world, 0));
assertEquals("vicky's island", pm.getRankIslandName(world, 100));
// Test the ranks
int rank = 1;
for (String name : names.values()) {
assertEquals(name + "'s island", phm.getRankIslandName(world, rank++, false));
for (String name : NAMES) {
assertEquals(name + "'s island", pm.getRankIslandName(world, rank++));
}
}
/**
* Test method for
* {@link world.bentobox.level.PlaceholderManager#getRankMembers(org.bukkit.World, int)}.
* Test method for {@link world.bentobox.level.PlaceholderManager#getRankMembers(org.bukkit.World, int)}.
*/
@Test
public void testGetRankMembers() {
// Test extremes
check(1, phm.getRankMembers(world, 0, false));
check(2, phm.getRankMembers(world, 100, false));
check(1, pm.getRankMembers(world, 0));
check(2, pm.getRankMembers(world, 100));
// Test the ranks
for (int rank = 1; rank < 11; rank++) {
check(3, phm.getRankMembers(world, rank, false));
check(3, pm.getRankMembers(world, rank));
}
}
void check(int indicator, String list) {
for (String n : names.values()) {
assertTrue(n + " is missing for test " + indicator, list.contains(n));
for (String n : NAMES) {
assertTrue(n + " is missing for twst " + indicator, list.contains(n));
}
}
/**
* Test method for
* {@link world.bentobox.level.PlaceholderManager#getRankLevel(org.bukkit.World, int)}.
* Test method for {@link world.bentobox.level.PlaceholderManager#getRankLevel(org.bukkit.World, int)}.
*/
@Test
public void testGetRankLevel() {
// Test extremes
assertEquals("100", phm.getRankLevel(world, 0, false));
assertEquals("91", phm.getRankLevel(world, 100, false));
assertEquals("100", pm.getRankLevel(world, 0));
assertEquals("91", pm.getRankLevel(world, 100));
// Test the ranks
for (int rank = 1; rank < 11; rank++) {
assertEquals(String.valueOf(101 - rank), phm.getRankLevel(world, rank, false));
assertEquals(String.valueOf(101 - rank), pm.getRankLevel(world, rank));
}
}
/**
* Test method for
* {@link world.bentobox.level.PlaceholderManager#getRankLevel(org.bukkit.World, int)}.
*/
@Test
public void testGetWeightedRankLevel() {
// Test extremes
assertEquals("100", phm.getRankLevel(world, 0, true));
assertEquals("91", phm.getRankLevel(world, 100, true));
// Test the ranks
for (int rank = 1; rank < 11; rank++) {
assertEquals(String.valueOf(101 - rank), phm.getRankLevel(world, rank, true));
}
}
/**
* Test method for
* {@link world.bentobox.level.PlaceholderManager#getVisitedIslandLevel(world.bentobox.bentobox.api.addons.GameModeAddon, world.bentobox.bentobox.api.user.User)}.
* Test method for {@link world.bentobox.level.PlaceholderManager#getVisitedIslandLevel(world.bentobox.bentobox.api.addons.GameModeAddon, world.bentobox.bentobox.api.user.User)}.
*/
@Test
public void testGetVisitedIslandLevelNullUser() {
assertEquals("", phm.getVisitedIslandLevel(gm, null));
assertEquals("", pm.getVisitedIslandLevel(gm, null));
}
@ -306,17 +264,16 @@ public class PlaceholderManagerTest {
public void testGetVisitedIslandLevelUserNotInWorld() {
// Another world
when(user.getWorld()).thenReturn(mock(World.class));
assertEquals("", phm.getVisitedIslandLevel(gm, user));
assertEquals("", pm.getVisitedIslandLevel(gm, user));
}
/**
* Test method for
* {@link world.bentobox.level.PlaceholderManager#getVisitedIslandLevel(world.bentobox.bentobox.api.addons.GameModeAddon, world.bentobox.bentobox.api.user.User)}.
* Test method for {@link world.bentobox.level.PlaceholderManager#getVisitedIslandLevel(world.bentobox.bentobox.api.addons.GameModeAddon, world.bentobox.bentobox.api.user.User)}.
*/
@Test
public void testGetVisitedIslandLevel() {
assertEquals("1234567", phm.getVisitedIslandLevel(gm, user));
assertEquals("1234567", pm.getVisitedIslandLevel(gm, user));
}
@ -326,7 +283,7 @@ public class PlaceholderManagerTest {
@Test
public void testGetVisitedIslandLevelNoIsland() {
when(im.getIslandAt(any(Location.class))).thenReturn(Optional.empty());
assertEquals("0", phm.getVisitedIslandLevel(gm, user));
assertEquals("0", pm.getVisitedIslandLevel(gm, user));
}

View File

@ -1,37 +0,0 @@
package world.bentobox.level.calculators;
import static org.junit.Assert.assertEquals;
import java.text.ParseException;
import org.junit.Test;
/**
* Test the equation evaluation
*/
public class EquationEvaluatorTest {
/**
* Test method for {@link world.bentobox.level.calculators.EquationEvaluator#eval(java.lang.String)}.
* @throws ParseException
*/
@Test
public void testEval() throws ParseException {
assertEquals(4D, EquationEvaluator.eval("2+2"), 0D);
assertEquals(0D, EquationEvaluator.eval("2-2"), 0D);
assertEquals(1D, EquationEvaluator.eval("2/2"), 0D);
assertEquals(4D, EquationEvaluator.eval("2*2"), 0D);
assertEquals(8D, EquationEvaluator.eval("2+2+2+2"), 0D);
assertEquals(5D, EquationEvaluator.eval("2.5+2.5"), 0D);
assertEquals(1.414, EquationEvaluator.eval("sqrt(2)"), 0.001D);
assertEquals(3.414, EquationEvaluator.eval("2 + sqrt(2)"), 0.001D);
assertEquals(0D, EquationEvaluator.eval("sin(0)"), 0.1D);
assertEquals(1D, EquationEvaluator.eval("cos(0)"), 0.1D);
assertEquals(0D, EquationEvaluator.eval("tan(0)"), 0.1D);
assertEquals(0D, EquationEvaluator.eval("log(1)"), 0.1D);
assertEquals(27D, EquationEvaluator.eval("3^3"), 0.D);
assertEquals(84.70332D, EquationEvaluator.eval("3^3 + 2 + 2.65 * (3 / 4) - sin(45) * log(10) + 55.344"),
0.0001D);
}
}

View File

@ -1,183 +0,0 @@
package world.bentobox.level.commands;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Random;
import java.util.UUID;
import org.bukkit.Bukkit;
import org.bukkit.Server;
import org.bukkit.World;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemFactory;
import org.bukkit.inventory.meta.ItemMeta;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.powermock.api.mockito.PowerMockito;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;
import org.powermock.reflect.Whitebox;
import world.bentobox.bentobox.BentoBox;
import world.bentobox.bentobox.api.addons.GameModeAddon;
import world.bentobox.bentobox.api.commands.CompositeCommand;
import world.bentobox.bentobox.api.user.User;
import world.bentobox.bentobox.database.objects.Island;
import world.bentobox.bentobox.managers.IslandWorldManager;
import world.bentobox.bentobox.managers.IslandsManager;
import world.bentobox.bentobox.managers.LocalesManager;
import world.bentobox.bentobox.managers.PlayersManager;
import world.bentobox.level.Level;
import world.bentobox.level.LevelsManager;
import world.bentobox.level.objects.TopTenData;
/**
* @author tastybento
*/
@RunWith(PowerMockRunner.class)
@PrepareForTest({ Bukkit.class, BentoBox.class })
public class AdminStatsCommandTest {
@Mock
private CompositeCommand ic;
private UUID uuid;
@Mock
private User user;
@Mock
private IslandsManager im;
@Mock
private Island island;
@Mock
private Level addon;
@Mock
private World world;
@Mock
private IslandWorldManager iwm;
@Mock
private GameModeAddon gameModeAddon;
@Mock
private Player p;
@Mock
private LocalesManager lm;
@Mock
private PlayersManager pm;
private AdminStatsCommand asc;
private TopTenData ttd;
@Mock
private LevelsManager manager;
@Mock
private Server server;
@Before
public void setUp() {
// Set up plugin
BentoBox plugin = mock(BentoBox.class);
Whitebox.setInternalState(BentoBox.class, "instance", plugin);
User.setPlugin(plugin);
when(addon.getPlugin()).thenReturn(plugin);
// Addon
when(ic.getAddon()).thenReturn(addon);
when(ic.getPermissionPrefix()).thenReturn("bskyblock.");
when(ic.getLabel()).thenReturn("island");
when(ic.getTopLabel()).thenReturn("island");
when(ic.getWorld()).thenReturn(world);
when(ic.getTopLabel()).thenReturn("bsb");
// IWM friendly name
when(plugin.getIWM()).thenReturn(iwm);
when(iwm.getFriendlyName(any())).thenReturn("BSkyBlock");
// World
when(world.toString()).thenReturn("world");
when(world.getName()).thenReturn("BSkyBlock_world");
// Player manager
when(plugin.getPlayers()).thenReturn(pm);
when(pm.getUser(anyString())).thenReturn(user);
// topTen
when(addon.getManager()).thenReturn(manager);
// User
uuid = UUID.randomUUID();
when(user.getUniqueId()).thenReturn(uuid);
when(user.getTranslation(any())).thenAnswer(invocation -> invocation.getArgument(0, String.class));
// Bukkit
PowerMockito.mockStatic(Bukkit.class);
when(Bukkit.getServer()).thenReturn(server);
// Mock item factory (for itemstacks)
ItemFactory itemFactory = mock(ItemFactory.class);
ItemMeta itemMeta = mock(ItemMeta.class);
when(itemFactory.getItemMeta(any())).thenReturn(itemMeta);
when(server.getItemFactory()).thenReturn(itemFactory);
when(Bukkit.getItemFactory()).thenReturn(itemFactory);
// Top ten
ttd = new TopTenData(world);
Map<String, Long> topten = new HashMap<>();
Random r = new Random();
for (int i = 0; i < 1000; i++) {
topten.put(UUID.randomUUID().toString(), r.nextLong(20000));
}
ttd.setTopTen(topten);
asc = new AdminStatsCommand(addon, ic);
}
@After
public void tearDown() {
User.clearUsers();
}
/**
* Test method for
* {@link world.bentobox.level.commands.AdminStatsCommand#setup()}.
*/
@Test
public void testSetup() {
assertEquals("bskyblock.admin.stats", asc.getPermission());
assertFalse(asc.isOnlyPlayer());
assertEquals("admin.stats.description", asc.getDescription());
}
/**
* Test method for
* {@link world.bentobox.level.commands.AdminStatsCommand#execute(world.bentobox.bentobox.api.user.User, java.lang.String, java.util.List)}.
*/
@Test
public void testExecuteUserStringListOfString() {
assertFalse(asc.execute(user, "", List.of()));
verify(user).sendMessage("admin.stats.title");
verify(user).sendMessage("admin.stats.no-data");
}
/**
* Test method for
* {@link world.bentobox.level.commands.AdminStatsCommand#execute(world.bentobox.bentobox.api.user.User, java.lang.String, java.util.List)}.
*/
@Test
public void testExecuteUserStringListOfStringLevels() {
Map<World, TopTenData> map = new HashMap<>();
map.put(world, ttd);
when(manager.getTopTenLists()).thenReturn(map);
assertTrue(asc.execute(user, "", List.of()));
verify(user).sendMessage("admin.stats.title");
verify(user, never()).sendMessage("admin.stats.no-data");
}
}

View File

@ -1,208 +0,0 @@
package world.bentobox.level.commands;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import java.util.Collections;
import java.util.List;
import java.util.UUID;
import org.bukkit.Bukkit;
import org.bukkit.Server;
import org.bukkit.World;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemFactory;
import org.bukkit.inventory.meta.ItemMeta;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.powermock.api.mockito.PowerMockito;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;
import org.powermock.reflect.Whitebox;
import world.bentobox.bentobox.BentoBox;
import world.bentobox.bentobox.api.addons.GameModeAddon;
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.database.objects.Island;
import world.bentobox.bentobox.managers.IslandWorldManager;
import world.bentobox.bentobox.managers.IslandsManager;
import world.bentobox.bentobox.managers.LocalesManager;
import world.bentobox.bentobox.managers.PlayersManager;
import world.bentobox.level.Level;
import world.bentobox.level.LevelsManager;
import world.bentobox.level.objects.TopTenData;
/**
* @author tastybento
*
*/
@RunWith(PowerMockRunner.class)
@PrepareForTest({ Bukkit.class, BentoBox.class })
public class AdminTopRemoveCommandTest {
@Mock
private CompositeCommand ic;
private UUID uuid;
@Mock
private User user;
@Mock
private IslandsManager im;
@Mock
private Island island;
@Mock
private Level addon;
@Mock
private World world;
@Mock
private IslandWorldManager iwm;
@Mock
private GameModeAddon gameModeAddon;
@Mock
private Player p;
@Mock
private LocalesManager lm;
@Mock
private PlayersManager pm;
private AdminTopRemoveCommand atrc;
@Mock
private TopTenData ttd;
@Mock
private LevelsManager manager;
@Mock
private Server server;
@Before
public void setUp() {
// Set up plugin
BentoBox plugin = mock(BentoBox.class);
Whitebox.setInternalState(BentoBox.class, "instance", plugin);
User.setPlugin(plugin);
// Addon
when(ic.getAddon()).thenReturn(addon);
when(ic.getPermissionPrefix()).thenReturn("bskyblock.");
when(ic.getLabel()).thenReturn("island");
when(ic.getTopLabel()).thenReturn("island");
when(ic.getWorld()).thenReturn(world);
when(ic.getTopLabel()).thenReturn("bsb");
// IWM friendly name
when(plugin.getIWM()).thenReturn(iwm);
when(iwm.getFriendlyName(any())).thenReturn("BSkyBlock");
// World
when(world.toString()).thenReturn("world");
when(world.getName()).thenReturn("BSkyBlock_world");
// Player manager
when(plugin.getPlayers()).thenReturn(pm);
when(pm.getUser(anyString())).thenReturn(user);
// topTen
when(addon.getManager()).thenReturn(manager);
// User
uuid = UUID.randomUUID();
when(user.getUniqueId()).thenReturn(uuid);
when(user.getTranslation(any())).thenAnswer(invocation -> invocation.getArgument(0, String.class));
// Island
when(island.getUniqueId()).thenReturn(uuid.toString());
when(island.getOwner()).thenReturn(uuid);
// Island Manager
when(plugin.getIslands()).thenReturn(im);
when(im.getIslands(any(), any(User.class))).thenReturn(List.of(island));
when(im.getIslands(any(), any(UUID.class))).thenReturn(List.of(island));
// Bukkit
PowerMockito.mockStatic(Bukkit.class);
when(Bukkit.getServer()).thenReturn(server);
// Mock item factory (for itemstacks)
ItemFactory itemFactory = mock(ItemFactory.class);
ItemMeta itemMeta = mock(ItemMeta.class);
when(itemFactory.getItemMeta(any())).thenReturn(itemMeta);
when(server.getItemFactory()).thenReturn(itemFactory);
when(Bukkit.getItemFactory()).thenReturn(itemFactory);
atrc = new AdminTopRemoveCommand(addon, ic);
}
@After
public void tearDown() {
User.clearUsers();
}
/**
* Test method for
* {@link world.bentobox.level.commands.admin.AdminTopRemoveCommand#AdminTopRemoveCommand(world.bentobox.level.Level, world.bentobox.bentobox.api.commands.CompositeCommand)}.
*/
@Test
public void testAdminTopRemoveCommand() {
assertEquals("remove", atrc.getLabel());
assertEquals("delete", atrc.getAliases().get(0));
}
/**
* Test method for
* {@link world.bentobox.level.commands.admin.AdminTopRemoveCommand#setup()}.
*/
@Test
public void testSetup() {
assertEquals("bskyblock.admin.top.remove", atrc.getPermission());
assertEquals("admin.top.remove.parameters", atrc.getParameters());
assertEquals("admin.top.remove.description", atrc.getDescription());
assertFalse(atrc.isOnlyPlayer());
}
/**
* Test method for
* {@link world.bentobox.level.commands.admin.AdminTopRemoveCommand#canExecute(world.bentobox.bentobox.api.user.User, java.lang.String, java.util.List)}.
*/
@Test
public void testCanExecuteWrongArgs() {
assertFalse(atrc.canExecute(user, "delete", Collections.emptyList()));
verify(user).sendMessage("commands.help.header", TextVariables.LABEL, "BSkyBlock");
}
/**
* Test method for {@link world.bentobox.level.commands.admin.AdminTopRemoveCommand#canExecute(world.bentobox.bentobox.api.user.User, java.lang.String, java.util.List)}.
*/
@Test
public void testCanExecuteUnknown() {
when(pm.getUser(anyString())).thenReturn(null);
assertFalse(atrc.canExecute(user, "delete", Collections.singletonList("tastybento")));
verify(user).sendMessage("general.errors.unknown-player", TextVariables.NAME, "tastybento");
}
/**
* Test method for
* {@link world.bentobox.level.commands.admin.AdminTopRemoveCommand#canExecute(world.bentobox.bentobox.api.user.User, java.lang.String, java.util.List)}.
*/
@Test
public void testCanExecuteKnown() {
assertTrue(atrc.canExecute(user, "delete", Collections.singletonList("tastybento")));
}
/**
* Test method for
* {@link world.bentobox.level.commands.admin.AdminTopRemoveCommand#execute(world.bentobox.bentobox.api.user.User, java.lang.String, java.util.List)}.
*/
@Test
public void testExecuteUserStringListOfString() {
testCanExecuteKnown();
assertTrue(atrc.execute(user, "delete", Collections.singletonList("tastybento")));
verify(manager).removeEntry(world, uuid.toString());
verify(user).sendMessage("general.success");
}
}

View File

@ -0,0 +1,199 @@
package world.bentobox.level.commands.admin;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import java.util.Collections;
import java.util.UUID;
import org.bukkit.Bukkit;
import org.bukkit.Server;
import org.bukkit.World;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemFactory;
import org.bukkit.inventory.meta.ItemMeta;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.powermock.api.mockito.PowerMockito;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;
import org.powermock.reflect.Whitebox;
import world.bentobox.bentobox.BentoBox;
import world.bentobox.bentobox.api.addons.GameModeAddon;
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.database.objects.Island;
import world.bentobox.bentobox.managers.IslandWorldManager;
import world.bentobox.bentobox.managers.IslandsManager;
import world.bentobox.bentobox.managers.LocalesManager;
import world.bentobox.bentobox.managers.PlayersManager;
import world.bentobox.level.Level;
import world.bentobox.level.LevelsManager;
import world.bentobox.level.commands.AdminTopRemoveCommand;
import world.bentobox.level.objects.TopTenData;
/**
* @author tastybento
*
*/
@RunWith(PowerMockRunner.class)
@PrepareForTest({Bukkit.class, BentoBox.class})
public class AdminTopRemoveCommandTest {
@Mock
private CompositeCommand ic;
private UUID uuid;
@Mock
private User user;
@Mock
private IslandsManager im;
@Mock
private Island island;
@Mock
private Level addon;
@Mock
private World world;
@Mock
private IslandWorldManager iwm;
@Mock
private GameModeAddon gameModeAddon;
@Mock
private Player p;
@Mock
private LocalesManager lm;
@Mock
private PlayersManager pm;
private AdminTopRemoveCommand atrc;
@Mock
private TopTenData ttd;
@Mock
private LevelsManager manager;
@Mock
private Server server;
@Before
public void setUp() {
// Set up plugin
BentoBox plugin = mock(BentoBox.class);
Whitebox.setInternalState(BentoBox.class, "instance", plugin);
User.setPlugin(plugin);
// Addon
when(ic.getAddon()).thenReturn(addon);
when(ic.getPermissionPrefix()).thenReturn("bskyblock.");
when(ic.getLabel()).thenReturn("island");
when(ic.getTopLabel()).thenReturn("island");
when(ic.getWorld()).thenReturn(world);
when(ic.getTopLabel()).thenReturn("bsb");
// IWM friendly name
when(plugin.getIWM()).thenReturn(iwm);
when(iwm.getFriendlyName(any())).thenReturn("BSkyBlock");
// World
when(world.toString()).thenReturn("world");
when(world.getName()).thenReturn("BSkyBlock_world");
// Player manager
when(plugin.getPlayers()).thenReturn(pm);
when(pm.getUser(anyString())).thenReturn(user);
// topTen
when(addon.getManager()).thenReturn(manager);
// User
uuid = UUID.randomUUID();
when(user.getUniqueId()).thenReturn(uuid);
when(user.getTranslation(any())).thenAnswer(invocation -> invocation.getArgument(0, String.class));
// Bukkit
PowerMockito.mockStatic(Bukkit.class);
when(Bukkit.getServer()).thenReturn(server);
// Mock item factory (for itemstacks)
ItemFactory itemFactory = mock(ItemFactory.class);
ItemMeta itemMeta = mock(ItemMeta.class);
when(itemFactory.getItemMeta(any())).thenReturn(itemMeta);
when(server.getItemFactory()).thenReturn(itemFactory);
when(Bukkit.getItemFactory()).thenReturn(itemFactory);
atrc = new AdminTopRemoveCommand(addon, ic);
}
@After
public void tearDown() {
User.clearUsers();
}
/**
* Test method for {@link world.bentobox.level.commands.admin.AdminTopRemoveCommand#AdminTopRemoveCommand(world.bentobox.level.Level, world.bentobox.bentobox.api.commands.CompositeCommand)}.
*/
@Test
public void testAdminTopRemoveCommand() {
assertEquals("remove", atrc.getLabel());
assertEquals("delete", atrc.getAliases().get(0));
}
/**
* Test method for {@link world.bentobox.level.commands.admin.AdminTopRemoveCommand#setup()}.
*/
@Test
public void testSetup() {
assertEquals("bskyblock.admin.top.remove", atrc.getPermission());
assertEquals("admin.top.remove.parameters", atrc.getParameters());
assertEquals("admin.top.remove.description", atrc.getDescription());
assertFalse(atrc.isOnlyPlayer());
}
/**
* Test method for {@link world.bentobox.level.commands.admin.AdminTopRemoveCommand#canExecute(world.bentobox.bentobox.api.user.User, java.lang.String, java.util.List)}.
*/
@Test
public void testCanExecuteWrongArgs() {
assertFalse(atrc.canExecute(user, "delete", Collections.emptyList()));
verify(user).sendMessage("commands.help.header", TextVariables.LABEL, "BSkyBlock");
}
/**
* Test method for {@link world.bentobox.level.commands.admin.AdminTopRemoveCommand#canExecute(world.bentobox.bentobox.api.user.User, java.lang.String, java.util.List)}.
*/
@Test
public void testCanExecuteUnknown() {
when(pm.getUser(anyString())).thenReturn(null);
assertFalse(atrc.canExecute(user, "delete", Collections.singletonList("tastybento")));
verify(user).sendMessage("general.errors.unknown-player", TextVariables.NAME, "tastybento");
}
/**
* Test method for {@link world.bentobox.level.commands.admin.AdminTopRemoveCommand#canExecute(world.bentobox.bentobox.api.user.User, java.lang.String, java.util.List)}.
*/
@Test
public void testCanExecuteKnown() {
assertTrue(atrc.canExecute(user, "delete", Collections.singletonList("tastybento")));
}
/**
* Test method for {@link world.bentobox.level.commands.admin.AdminTopRemoveCommand#execute(world.bentobox.bentobox.api.user.User, java.lang.String, java.util.List)}.
*/
@Test
public void testExecuteUserStringListOfString() {
testCanExecuteKnown();
assertTrue(atrc.execute(user, "delete", Collections.singletonList("tastybento")));
verify(manager).removeEntry(any(World.class), eq(uuid));
verify(user).sendMessage("general.success");
}
}