Sonar Cloud code smell clean up (#278)
This commit is contained in:
parent
a493c12f6e
commit
0cdb15403b
|
@ -36,8 +36,8 @@ import world.bentobox.level.config.BlockConfig;
|
||||||
import world.bentobox.level.config.ConfigSettings;
|
import world.bentobox.level.config.ConfigSettings;
|
||||||
import world.bentobox.level.listeners.IslandActivitiesListeners;
|
import world.bentobox.level.listeners.IslandActivitiesListeners;
|
||||||
import world.bentobox.level.listeners.JoinLeaveListener;
|
import world.bentobox.level.listeners.JoinLeaveListener;
|
||||||
import world.bentobox.level.objects.IslandLevels;
|
|
||||||
import world.bentobox.level.listeners.MigrationListener;
|
import world.bentobox.level.listeners.MigrationListener;
|
||||||
|
import world.bentobox.level.objects.IslandLevels;
|
||||||
import world.bentobox.level.objects.LevelsData;
|
import world.bentobox.level.objects.LevelsData;
|
||||||
import world.bentobox.level.objects.TopTenData;
|
import world.bentobox.level.objects.TopTenData;
|
||||||
import world.bentobox.level.requests.LevelRequestHandler;
|
import world.bentobox.level.requests.LevelRequestHandler;
|
||||||
|
@ -176,20 +176,14 @@ public class Level extends Addon {
|
||||||
{
|
{
|
||||||
this.visitHook = (VisitAddon) addon;
|
this.visitHook = (VisitAddon) addon;
|
||||||
this.log("Level Addon hooked into Visit addon.");
|
this.log("Level Addon hooked into Visit addon.");
|
||||||
}, () ->
|
}, () -> this.visitHook = null);
|
||||||
{
|
|
||||||
this.visitHook = null;
|
|
||||||
});
|
|
||||||
|
|
||||||
// Try to find Warps addon and if it does not exist, display a warning
|
// 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.warpHook = (Warp) addon;
|
||||||
this.log("Level Addon hooked into Warps addon.");
|
this.log("Level Addon hooked into Warps addon.");
|
||||||
}, () ->
|
}, () -> this.warpHook = null);
|
||||||
{
|
|
||||||
this.warpHook = null;
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -230,9 +224,9 @@ public class Level extends Addon {
|
||||||
getPlugin().getPlaceholdersManager().registerPlaceholder(this,
|
getPlugin().getPlaceholdersManager().registerPlaceholder(this,
|
||||||
gm.getDescription().getName().toLowerCase() + "_island_total_points",
|
gm.getDescription().getName().toLowerCase() + "_island_total_points",
|
||||||
user -> {
|
user -> {
|
||||||
IslandLevels data = getManager().getLevelsData(this.getIslands().getIsland(gm.getOverWorld(), user));
|
IslandLevels data = getManager().getLevelsData(this.getIslands().getIsland(gm.getOverWorld(), user));
|
||||||
return data.getTotalPoints()+"";
|
return data.getTotalPoints()+"";
|
||||||
});
|
});
|
||||||
|
|
||||||
getPlugin().getPlaceholdersManager().registerPlaceholder(this,
|
getPlugin().getPlaceholdersManager().registerPlaceholder(this,
|
||||||
gm.getDescription().getName().toLowerCase() + "_points_to_next_level",
|
gm.getDescription().getName().toLowerCase() + "_points_to_next_level",
|
||||||
|
@ -478,7 +472,7 @@ public class Level extends Addon {
|
||||||
* @param playerUUID - the target island member's UUID
|
* @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
|
@Deprecated(since="2.3.0", forRemoval=true)
|
||||||
public void calculateIslandLevel(World world, @Nullable User user, @NonNull UUID playerUUID) {
|
public void calculateIslandLevel(World world, @Nullable User user, @NonNull UUID playerUUID) {
|
||||||
Island island = getIslands().getIsland(world, playerUUID);
|
Island island = getIslands().getIsland(world, playerUUID);
|
||||||
if (island != null) getManager().calculateLevel(playerUUID, island);
|
if (island != null) getManager().calculateLevel(playerUUID, island);
|
||||||
|
@ -490,7 +484,7 @@ public class Level extends Addon {
|
||||||
* @return LevelsData object or null if not found. Only island levels are set!
|
* @return LevelsData object or null if not found. Only island levels are set!
|
||||||
* @deprecated Do not use this anymore. Use {@link #getIslandLevel(World, UUID)}
|
* @deprecated Do not use this anymore. Use {@link #getIslandLevel(World, UUID)}
|
||||||
*/
|
*/
|
||||||
@Deprecated
|
@Deprecated(since="2.3.0", forRemoval=true)
|
||||||
public LevelsData getLevelsData(UUID targetPlayer) {
|
public LevelsData getLevelsData(UUID targetPlayer) {
|
||||||
LevelsData ld = new LevelsData(targetPlayer);
|
LevelsData ld = new LevelsData(targetPlayer);
|
||||||
getPlugin().getAddonsManager().getGameModeAddons().stream()
|
getPlugin().getAddonsManager().getGameModeAddons().stream()
|
||||||
|
|
|
@ -152,8 +152,6 @@ public class LevelsManager {
|
||||||
addon.getPipeliner().addIsland(island).thenAccept(r -> {
|
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)) {
|
if (r == null || fireIslandLevelCalcEvent(targetPlayer, island, r)) {
|
||||||
System.out.println("results are null or event canceled");
|
|
||||||
|
|
||||||
result.complete(null);
|
result.complete(null);
|
||||||
}
|
}
|
||||||
// Save result
|
// Save result
|
||||||
|
@ -337,7 +335,7 @@ public class LevelsManager {
|
||||||
.filter(e -> addon.getIslands().isOwner(world, e.getKey()))
|
.filter(e -> addon.getIslands().isOwner(world, e.getKey()))
|
||||||
.filter(l -> l.getValue() > 0)
|
.filter(l -> l.getValue() > 0)
|
||||||
.sorted(Collections.reverseOrder(Map.Entry.comparingByValue()));
|
.sorted(Collections.reverseOrder(Map.Entry.comparingByValue()));
|
||||||
return stream.takeWhile(x -> !x.getKey().equals(uuid)).map(Map.Entry::getKey).collect(Collectors.toList()).size() + 1;
|
return (int) (stream.takeWhile(x -> !x.getKey().equals(uuid)).map(Map.Entry::getKey).count() + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -363,10 +361,7 @@ public class LevelsManager {
|
||||||
addon.getIslands().getIslandById(il.getUniqueId()).ifPresent(i -> this.addToTopTen(i, il.getLevel()));
|
addon.getIslands().getIslandById(il.getUniqueId()).ifPresent(i -> this.addToTopTen(i, il.getLevel()));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
topTenLists.keySet().forEach(w -> {
|
topTenLists.keySet().forEach(w -> addon.log("Generated rankings for " + w.getName()));
|
||||||
addon.log("Generated rankings for " + w.getName());
|
|
||||||
});
|
|
||||||
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
package world.bentobox.level.calculators;
|
package world.bentobox.level.calculators;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.EnumMap;
|
import java.util.EnumMap;
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
@ -65,9 +65,10 @@ public class IslandLevelCalculator {
|
||||||
* @param str - equation to evaluate
|
* @param str - equation to evaluate
|
||||||
* @return value of equation
|
* @return value of equation
|
||||||
*/
|
*/
|
||||||
private static double eval(final String str) {
|
private static double eval(final String str) throws IOException {
|
||||||
return new Object() {
|
return new Object() {
|
||||||
int pos = -1, ch;
|
int pos = -1;
|
||||||
|
int ch;
|
||||||
|
|
||||||
boolean eat(int charToEat) {
|
boolean eat(int charToEat) {
|
||||||
while (ch == ' ') nextChar();
|
while (ch == ' ') nextChar();
|
||||||
|
@ -82,10 +83,10 @@ public class IslandLevelCalculator {
|
||||||
ch = (++pos < str.length()) ? str.charAt(pos) : -1;
|
ch = (++pos < str.length()) ? str.charAt(pos) : -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
double parse() {
|
double parse() throws IOException {
|
||||||
nextChar();
|
nextChar();
|
||||||
double x = parseExpression();
|
double x = parseExpression();
|
||||||
if (pos < str.length()) throw new RuntimeException("Unexpected: " + (char)ch);
|
if (pos < str.length()) throw new IOException("Unexpected: " + (char)ch);
|
||||||
return x;
|
return x;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -95,7 +96,7 @@ public class IslandLevelCalculator {
|
||||||
// factor = `+` factor | `-` factor | `(` expression `)`
|
// factor = `+` factor | `-` factor | `(` expression `)`
|
||||||
// | number | functionName factor | factor `^` factor
|
// | number | functionName factor | factor `^` factor
|
||||||
|
|
||||||
double parseExpression() {
|
double parseExpression() throws IOException {
|
||||||
double x = parseTerm();
|
double x = parseTerm();
|
||||||
for (;;) {
|
for (;;) {
|
||||||
if (eat('+')) x += parseTerm(); // addition
|
if (eat('+')) x += parseTerm(); // addition
|
||||||
|
@ -104,7 +105,7 @@ public class IslandLevelCalculator {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
double parseFactor() {
|
double parseFactor() throws IOException {
|
||||||
if (eat('+')) return parseFactor(); // unary plus
|
if (eat('+')) return parseFactor(); // unary plus
|
||||||
if (eat('-')) return -parseFactor(); // unary minus
|
if (eat('-')) return -parseFactor(); // unary minus
|
||||||
|
|
||||||
|
@ -137,10 +138,10 @@ public class IslandLevelCalculator {
|
||||||
x = Math.log(x);
|
x = Math.log(x);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
throw new RuntimeException("Unknown function: " + func);
|
throw new IOException("Unknown function: " + func);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
throw new RuntimeException("Unexpected: " + (char)ch);
|
throw new IOException("Unexpected: " + (char)ch);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (eat('^')) x = Math.pow(x, parseFactor()); // exponentiation
|
if (eat('^')) x = Math.pow(x, parseFactor()); // exponentiation
|
||||||
|
@ -148,7 +149,7 @@ public class IslandLevelCalculator {
|
||||||
return x;
|
return x;
|
||||||
}
|
}
|
||||||
|
|
||||||
double parseTerm() {
|
double parseTerm() throws IOException {
|
||||||
double x = parseFactor();
|
double x = parseFactor();
|
||||||
for (;;) {
|
for (;;) {
|
||||||
if (eat('*')) x *= parseFactor(); // multiplication
|
if (eat('*')) x *= parseFactor(); // multiplication
|
||||||
|
@ -161,7 +162,7 @@ public class IslandLevelCalculator {
|
||||||
private final Level addon;
|
private final Level addon;
|
||||||
private final Queue<Pair<Integer, Integer>> chunksToCheck;
|
private final Queue<Pair<Integer, Integer>> chunksToCheck;
|
||||||
private final Island island;
|
private final Island island;
|
||||||
private final HashMap<Material, Integer> limitCount;
|
private final Map<Material, Integer> limitCount;
|
||||||
private final CompletableFuture<Results> r;
|
private final CompletableFuture<Results> r;
|
||||||
|
|
||||||
|
|
||||||
|
@ -190,7 +191,7 @@ public class IslandLevelCalculator {
|
||||||
results = new Results();
|
results = new Results();
|
||||||
duration = System.currentTimeMillis();
|
duration = System.currentTimeMillis();
|
||||||
chunksToCheck = getChunksToScan(island);
|
chunksToCheck = getChunksToScan(island);
|
||||||
this.limitCount = new HashMap<>(addon.getBlockConfig().getBlockLimits());
|
this.limitCount = new EnumMap<>(addon.getBlockConfig().getBlockLimits());
|
||||||
// Get the initial island level
|
// Get the initial island level
|
||||||
results.initialLevel.set(addon.getInitialIslandLevel(island));
|
results.initialLevel.set(addon.getInitialIslandLevel(island));
|
||||||
// Set up the worlds
|
// Set up the worlds
|
||||||
|
@ -221,7 +222,15 @@ public class IslandLevelCalculator {
|
||||||
private long calculateLevel(long blockAndDeathPoints) {
|
private long calculateLevel(long blockAndDeathPoints) {
|
||||||
String calcString = addon.getSettings().getLevelCalc();
|
String calcString = addon.getSettings().getLevelCalc();
|
||||||
String withValues = calcString.replace("blocks", String.valueOf(blockAndDeathPoints)).replace("level_cost", String.valueOf(this.addon.getSettings().getLevelCost()));
|
String withValues = calcString.replace("blocks", String.valueOf(blockAndDeathPoints)).replace("level_cost", String.valueOf(this.addon.getSettings().getLevelCost()));
|
||||||
return (long)eval(withValues) - (addon.getSettings().isZeroNewIslandLevels() ? results.initialLevel.get() : 0);
|
long evalWithValues;
|
||||||
|
try {
|
||||||
|
evalWithValues = (long)eval(withValues);
|
||||||
|
return evalWithValues - (addon.getSettings().isZeroNewIslandLevels() ? results.initialLevel.get() : 0);
|
||||||
|
|
||||||
|
} catch (IOException e) {
|
||||||
|
addon.getPlugin().logStacktrace(e);
|
||||||
|
return 0L;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -424,7 +433,7 @@ public class IslandLevelCalculator {
|
||||||
private void scanChests(Chunk chunk) {
|
private void scanChests(Chunk chunk) {
|
||||||
// Count blocks in chests
|
// Count blocks in chests
|
||||||
for (BlockState bs : chunk.getTileEntities()) {
|
for (BlockState bs : chunk.getTileEntities()) {
|
||||||
if (bs instanceof Container) {
|
if (bs instanceof Container container) {
|
||||||
if (addon.isAdvChestEnabled()) {
|
if (addon.isAdvChestEnabled()) {
|
||||||
AdvancedChest<?,?> aChest = AdvancedChestsAPI.getChestManager().getAdvancedChest(bs.getLocation());
|
AdvancedChest<?,?> aChest = AdvancedChestsAPI.getChestManager().getAdvancedChest(bs.getLocation());
|
||||||
if (aChest != null && aChest.getChestType().getName().equals("NORMAL")) {
|
if (aChest != null && aChest.getChestType().getName().equals("NORMAL")) {
|
||||||
|
@ -437,7 +446,7 @@ public class IslandLevelCalculator {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Regular chest
|
// Regular chest
|
||||||
((Container)bs).getSnapshotInventory().forEach(this::countItemStack);
|
container.getSnapshotInventory().forEach(this::countItemStack);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -513,7 +522,7 @@ public class IslandLevelCalculator {
|
||||||
}
|
}
|
||||||
// Hook for Wild Stackers (Blocks and Spawners Only) - this has to use the real chunk
|
// Hook for Wild Stackers (Blocks and Spawners Only) - this has to use the real chunk
|
||||||
if (addon.isStackersEnabled() && (blockData.getMaterial().equals(Material.CAULDRON) || blockData.getMaterial().equals(Material.SPAWNER))) {
|
if (addon.isStackersEnabled() && (blockData.getMaterial().equals(Material.CAULDRON) || blockData.getMaterial().equals(Material.SPAWNER))) {
|
||||||
stackedBlocks.add(new Location(cp.world, x + cp.chunkSnapshot.getX() * 16,y,z + cp.chunkSnapshot.getZ() * 16));
|
stackedBlocks.add(new Location(cp.world, (double)x + cp.chunkSnapshot.getX() * 16, y, (double)z + cp.chunkSnapshot.getZ() * 16));
|
||||||
}
|
}
|
||||||
// Scan chests
|
// Scan chests
|
||||||
if (addon.getSettings().isIncludeChests() && CHESTS.contains(blockData.getMaterial())) {
|
if (addon.getSettings().isIncludeChests() && CHESTS.contains(blockData.getMaterial())) {
|
||||||
|
@ -564,21 +573,21 @@ public class IslandLevelCalculator {
|
||||||
}
|
}
|
||||||
|
|
||||||
private Collection<String> sortedReport(int total, Multiset<Material> materialCount) {
|
private Collection<String> sortedReport(int total, Multiset<Material> materialCount) {
|
||||||
Collection<String> r = new ArrayList<>();
|
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) {
|
for (Entry<Material> en : entriesSortedByCount) {
|
||||||
Material type = en.getElement();
|
Material type = en.getElement();
|
||||||
|
|
||||||
int value = getValue(type);
|
int value = getValue(type);
|
||||||
|
|
||||||
r.add(type.toString() + ":"
|
result.add(type.toString() + ":"
|
||||||
+ String.format("%,d", en.getCount()) + " blocks x " + value + " = " + (value * en.getCount()));
|
+ String.format("%,d", en.getCount()) + " blocks x " + value + " = " + (value * en.getCount()));
|
||||||
total += (value * en.getCount());
|
total += (value * en.getCount());
|
||||||
|
|
||||||
}
|
}
|
||||||
r.add("Subtotal = " + total);
|
result.add("Subtotal = " + total);
|
||||||
r.add(LINE_BREAK);
|
result.add(LINE_BREAK);
|
||||||
return r;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -638,7 +647,7 @@ public class IslandLevelCalculator {
|
||||||
|
|
||||||
public void scanIsland(Pipeliner pipeliner) {
|
public void scanIsland(Pipeliner pipeliner) {
|
||||||
// Scan the next chunk
|
// Scan the next chunk
|
||||||
scanNextChunk().thenAccept(r -> {
|
scanNextChunk().thenAccept(result -> {
|
||||||
if (!Bukkit.isPrimaryThread()) {
|
if (!Bukkit.isPrimaryThread()) {
|
||||||
addon.getPlugin().logError("scanChunk not on Primary Thread!");
|
addon.getPlugin().logError("scanChunk not on Primary Thread!");
|
||||||
}
|
}
|
||||||
|
@ -653,7 +662,7 @@ public class IslandLevelCalculator {
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (Boolean.TRUE.equals(r) && !pipeliner.getTask().isCancelled()) {
|
if (Boolean.TRUE.equals(result) && !pipeliner.getTask().isCancelled()) {
|
||||||
// scanNextChunk returns true if there are more chunks to scan
|
// scanNextChunk returns true if there are more chunks to scan
|
||||||
scanIsland(pipeliner);
|
scanIsland(pipeliner);
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -2,7 +2,6 @@ package world.bentobox.level.commands;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.stream.Collectors;
|
|
||||||
|
|
||||||
import world.bentobox.bentobox.api.commands.CompositeCommand;
|
import world.bentobox.bentobox.api.commands.CompositeCommand;
|
||||||
import world.bentobox.bentobox.api.localization.TextVariables;
|
import world.bentobox.bentobox.api.localization.TextVariables;
|
||||||
|
@ -60,6 +59,6 @@ public class AdminTopRemoveCommand extends CompositeCommand {
|
||||||
@Override
|
@Override
|
||||||
public Optional<List<String>> tabComplete(User user, String alias, List<String> args) {
|
public Optional<List<String>> tabComplete(User user, String alias, List<String> args) {
|
||||||
return Optional.of(addon.getManager().getTopTen(getWorld(), Level.TEN).keySet().stream().map(addon.getPlayers()::getName)
|
return Optional.of(addon.getManager().getTopTen(getWorld(), Level.TEN).keySet().stream().map(addon.getPlayers()::getName)
|
||||||
.filter(n -> !n.isEmpty()).collect(Collectors.toList()));
|
.filter(n -> !n.isEmpty()).toList());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,6 +19,7 @@ import world.bentobox.level.util.Utils;
|
||||||
|
|
||||||
public class IslandValueCommand extends CompositeCommand
|
public class IslandValueCommand extends CompositeCommand
|
||||||
{
|
{
|
||||||
|
private static final String MATERIAL = "[material]";
|
||||||
private final Level addon;
|
private final Level addon;
|
||||||
|
|
||||||
|
|
||||||
|
@ -45,7 +46,7 @@ public class IslandValueCommand extends CompositeCommand
|
||||||
if (args.size() > 1)
|
if (args.size() > 1)
|
||||||
{
|
{
|
||||||
this.showHelp(this, user);
|
this.showHelp(this, user);
|
||||||
return true;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (args.isEmpty())
|
if (args.isEmpty())
|
||||||
|
@ -73,8 +74,8 @@ public class IslandValueCommand extends CompositeCommand
|
||||||
if (material == null)
|
if (material == null)
|
||||||
{
|
{
|
||||||
Utils.sendMessage(user,
|
Utils.sendMessage(user,
|
||||||
user.getTranslation(this.getWorld(), "level.conversations.unknown-item",
|
user.getTranslation(this.getWorld(), "level.conversations.unknown-item",
|
||||||
"[material]", args.get(0)));
|
MATERIAL, args.get(0)));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -98,24 +99,24 @@ public class IslandValueCommand extends CompositeCommand
|
||||||
if (value != null)
|
if (value != null)
|
||||||
{
|
{
|
||||||
Utils.sendMessage(user,
|
Utils.sendMessage(user,
|
||||||
user.getTranslation(this.getWorld(), "level.conversations.value",
|
user.getTranslation(this.getWorld(), "level.conversations.value",
|
||||||
"[value]", String.valueOf(value),
|
"[value]", String.valueOf(value),
|
||||||
"[material]", Utils.prettifyObject(material, user)));
|
MATERIAL, Utils.prettifyObject(material, user)));
|
||||||
|
|
||||||
double underWater = this.addon.getSettings().getUnderWaterMultiplier();
|
double underWater = this.addon.getSettings().getUnderWaterMultiplier();
|
||||||
|
|
||||||
if (underWater > 1.0)
|
if (underWater > 1.0)
|
||||||
{
|
{
|
||||||
Utils.sendMessage(user,
|
Utils.sendMessage(user,
|
||||||
user.getTranslation(this.getWorld(),"level.conversations.success-underwater",
|
user.getTranslation(this.getWorld(),"level.conversations.success-underwater",
|
||||||
"[value]", (underWater * value) + ""),
|
"[value]", (underWater * value) + ""),
|
||||||
"[material]", Utils.prettifyObject(material, user));
|
MATERIAL, Utils.prettifyObject(material, user));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Utils.sendMessage(user,
|
Utils.sendMessage(user,
|
||||||
user.getTranslation(this.getWorld(),"level.conversations.no-value"));
|
user.getTranslation(this.getWorld(),"level.conversations.no-value"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -132,8 +133,8 @@ public class IslandValueCommand extends CompositeCommand
|
||||||
}
|
}
|
||||||
|
|
||||||
List<String> options = new ArrayList<>(Arrays.stream(Material.values()).
|
List<String> options = new ArrayList<>(Arrays.stream(Material.values()).
|
||||||
filter(Material::isBlock).
|
filter(Material::isBlock).
|
||||||
map(Material::name).toList());
|
map(Material::name).toList());
|
||||||
|
|
||||||
options.add("HAND");
|
options.add("HAND");
|
||||||
|
|
||||||
|
|
|
@ -1,16 +1,23 @@
|
||||||
package world.bentobox.level.panels;
|
package world.bentobox.level.panels;
|
||||||
|
|
||||||
|
|
||||||
import com.google.common.base.Enums;
|
import java.io.File;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Comparator;
|
||||||
|
import java.util.EnumMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
import org.bukkit.event.inventory.ClickType;
|
import org.bukkit.event.inventory.ClickType;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
import java.io.File;
|
|
||||||
import java.util.*;
|
import com.google.common.base.Enums;
|
||||||
import java.util.stream.Collectors;
|
|
||||||
|
|
||||||
import lv.id.bonne.panelutils.PanelUtils;
|
import lv.id.bonne.panelutils.PanelUtils;
|
||||||
|
import world.bentobox.bentobox.api.localization.TextVariables;
|
||||||
import world.bentobox.bentobox.api.panels.PanelItem;
|
import world.bentobox.bentobox.api.panels.PanelItem;
|
||||||
import world.bentobox.bentobox.api.panels.TemplatedPanel;
|
import world.bentobox.bentobox.api.panels.TemplatedPanel;
|
||||||
import world.bentobox.bentobox.api.panels.builders.PanelItemBuilder;
|
import world.bentobox.bentobox.api.panels.builders.PanelItemBuilder;
|
||||||
|
@ -18,7 +25,6 @@ import world.bentobox.bentobox.api.panels.builders.TemplatedPanelBuilder;
|
||||||
import world.bentobox.bentobox.api.panels.reader.ItemTemplateRecord;
|
import world.bentobox.bentobox.api.panels.reader.ItemTemplateRecord;
|
||||||
import world.bentobox.bentobox.api.user.User;
|
import world.bentobox.bentobox.api.user.User;
|
||||||
import world.bentobox.bentobox.database.objects.Island;
|
import world.bentobox.bentobox.database.objects.Island;
|
||||||
import world.bentobox.bentobox.hooks.LangUtilsHook;
|
|
||||||
import world.bentobox.bentobox.util.Pair;
|
import world.bentobox.bentobox.util.Pair;
|
||||||
import world.bentobox.level.Level;
|
import world.bentobox.level.Level;
|
||||||
import world.bentobox.level.objects.IslandLevels;
|
import world.bentobox.level.objects.IslandLevels;
|
||||||
|
@ -43,8 +49,8 @@ public class DetailsPanel
|
||||||
* @param user User who opens panel
|
* @param user User who opens panel
|
||||||
*/
|
*/
|
||||||
private DetailsPanel(Level addon,
|
private DetailsPanel(Level addon,
|
||||||
World world,
|
World world,
|
||||||
User user)
|
User user)
|
||||||
{
|
{
|
||||||
this.addon = addon;
|
this.addon = addon;
|
||||||
this.world = world;
|
this.world = world;
|
||||||
|
@ -121,99 +127,93 @@ public class DetailsPanel
|
||||||
|
|
||||||
switch (this.activeTab)
|
switch (this.activeTab)
|
||||||
{
|
{
|
||||||
case ALL_BLOCKS -> {
|
case ALL_BLOCKS -> {
|
||||||
Map<Material, Integer> materialCountMap = new EnumMap<>(Material.class);
|
Map<Material, Integer> materialCountMap = new EnumMap<>(Material.class);
|
||||||
|
|
||||||
materialCountMap.putAll(this.levelsData.getMdCount());
|
materialCountMap.putAll(this.levelsData.getMdCount());
|
||||||
|
|
||||||
// Add underwater blocks.
|
// Add underwater blocks.
|
||||||
this.levelsData.getUwCount().forEach((material, count) -> {
|
this.levelsData.getUwCount().forEach((material, count) -> materialCountMap.put(material,
|
||||||
materialCountMap.put(material,
|
materialCountMap.computeIfAbsent(material, key -> 0) + count));
|
||||||
materialCountMap.computeIfAbsent(material, key -> 0) + count);
|
|
||||||
});
|
|
||||||
|
|
||||||
materialCountMap.entrySet().stream().sorted((Map.Entry.comparingByKey())).
|
materialCountMap.entrySet().stream().sorted((Map.Entry.comparingByKey())).
|
||||||
forEachOrdered(entry ->
|
forEachOrdered(entry ->
|
||||||
this.materialCountList.add(new Pair<>(entry.getKey(), entry.getValue())));
|
this.materialCountList.add(new Pair<>(entry.getKey(), entry.getValue())));
|
||||||
}
|
}
|
||||||
case ABOVE_SEA_LEVEL -> {
|
case ABOVE_SEA_LEVEL -> this.levelsData.getMdCount().entrySet().stream().sorted((Map.Entry.comparingByKey()))
|
||||||
this.levelsData.getMdCount().entrySet().stream().sorted((Map.Entry.comparingByKey())).
|
.forEachOrdered(entry -> this.materialCountList.add(new Pair<>(entry.getKey(), entry.getValue())));
|
||||||
forEachOrdered(entry ->
|
|
||||||
this.materialCountList.add(new Pair<>(entry.getKey(), entry.getValue())));
|
|
||||||
}
|
|
||||||
case UNDERWATER -> {
|
|
||||||
this.levelsData.getUwCount().entrySet().stream().sorted((Map.Entry.comparingByKey())).
|
|
||||||
forEachOrdered(entry ->
|
|
||||||
this.materialCountList.add(new Pair<>(entry.getKey(), entry.getValue())));
|
|
||||||
}
|
|
||||||
case SPAWNER -> {
|
|
||||||
int aboveWater = this.levelsData.getMdCount().getOrDefault(Material.SPAWNER, 0);
|
|
||||||
int underWater = this.levelsData.getUwCount().getOrDefault(Material.SPAWNER, 0);
|
|
||||||
|
|
||||||
// TODO: spawners need some touch...
|
case UNDERWATER -> this.levelsData.getUwCount().entrySet().stream().sorted((Map.Entry.comparingByKey()))
|
||||||
this.materialCountList.add(new Pair<>(Material.SPAWNER, underWater + aboveWater));
|
.forEachOrdered(entry -> this.materialCountList.add(new Pair<>(entry.getKey(), entry.getValue())));
|
||||||
}
|
|
||||||
|
case SPAWNER -> {
|
||||||
|
int aboveWater = this.levelsData.getMdCount().getOrDefault(Material.SPAWNER, 0);
|
||||||
|
int underWater = this.levelsData.getUwCount().getOrDefault(Material.SPAWNER, 0);
|
||||||
|
|
||||||
|
// TODO: spawners need some touch...
|
||||||
|
this.materialCountList.add(new Pair<>(Material.SPAWNER, underWater + aboveWater));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Comparator<Pair<Material, Integer>> sorter;
|
Comparator<Pair<Material, Integer>> sorter;
|
||||||
|
|
||||||
switch (this.activeFilter)
|
switch (this.activeFilter)
|
||||||
{
|
{
|
||||||
case COUNT ->
|
case COUNT ->
|
||||||
|
{
|
||||||
|
sorter = (o1, o2) ->
|
||||||
{
|
{
|
||||||
sorter = (o1, o2) ->
|
if (o1.getValue().equals(o2.getValue()))
|
||||||
{
|
|
||||||
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
|
|
||||||
{
|
|
||||||
return Integer.compare(o2.getValue(), o1.getValue());
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
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);
|
|
||||||
|
|
||||||
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
|
|
||||||
{
|
|
||||||
return Long.compare(o2Value, o1Value);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
default ->
|
|
||||||
{
|
|
||||||
sorter = (o1, o2) ->
|
|
||||||
{
|
{
|
||||||
String o1Name = Utils.prettifyObject(o1.getKey(), this.user);
|
String o1Name = Utils.prettifyObject(o1.getKey(), this.user);
|
||||||
String o2Name = Utils.prettifyObject(o2.getKey(), this.user);
|
String o2Name = Utils.prettifyObject(o2.getKey(), this.user);
|
||||||
|
|
||||||
return String.CASE_INSENSITIVE_ORDER.compare(o1Name, o2Name);
|
return String.CASE_INSENSITIVE_ORDER.compare(o1Name, o2Name);
|
||||||
};
|
}
|
||||||
}
|
else
|
||||||
|
{
|
||||||
|
return Integer.compare(o2.getValue(), o1.getValue());
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
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);
|
||||||
|
|
||||||
|
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
|
||||||
|
{
|
||||||
|
return Long.compare(o2Value, o1Value);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
default ->
|
||||||
|
{
|
||||||
|
sorter = (o1, o2) ->
|
||||||
|
{
|
||||||
|
String o1Name = Utils.prettifyObject(o1.getKey(), this.user);
|
||||||
|
String o2Name = Utils.prettifyObject(o2.getKey(), this.user);
|
||||||
|
|
||||||
|
return String.CASE_INSENSITIVE_ORDER.compare(o1Name, o2Name);
|
||||||
|
};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
this.materialCountList.sort(sorter);
|
this.materialCountList.sort(sorter);
|
||||||
|
@ -222,9 +222,9 @@ public class DetailsPanel
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// ---------------------------------------------------------------------
|
// ---------------------------------------------------------------------
|
||||||
// Section: Tab Button Type
|
// Section: Tab Button Type
|
||||||
// ---------------------------------------------------------------------
|
// ---------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -262,23 +262,21 @@ public class DetailsPanel
|
||||||
List<ItemTemplateRecord.ActionRecords> activeActions = new ArrayList<>(template.actions());
|
List<ItemTemplateRecord.ActionRecords> activeActions = new ArrayList<>(template.actions());
|
||||||
|
|
||||||
activeActions.removeIf(action ->
|
activeActions.removeIf(action ->
|
||||||
"VIEW".equalsIgnoreCase(action.actionType()) && this.activeTab == tab);
|
"VIEW".equalsIgnoreCase(action.actionType()) && this.activeTab == tab);
|
||||||
|
|
||||||
// Add Click handler
|
// Add Click handler
|
||||||
builder.clickHandler((panel, user, clickType, i) ->
|
builder.clickHandler((panel, user, clickType, i) ->
|
||||||
{
|
{
|
||||||
for (ItemTemplateRecord.ActionRecords action : activeActions)
|
for (ItemTemplateRecord.ActionRecords action : activeActions)
|
||||||
{
|
{
|
||||||
if (clickType == action.clickType() || ClickType.UNKNOWN.equals(action.clickType()))
|
if ((clickType == action.clickType() || ClickType.UNKNOWN.equals(action.clickType()))
|
||||||
|
&& "VIEW".equalsIgnoreCase(action.actionType()))
|
||||||
{
|
{
|
||||||
if ("VIEW".equalsIgnoreCase(action.actionType()))
|
this.activeTab = tab;
|
||||||
{
|
|
||||||
this.activeTab = tab;
|
|
||||||
|
|
||||||
// Update filters.
|
// Update filters.
|
||||||
this.updateFilters();
|
this.updateFilters();
|
||||||
this.build();
|
this.build();
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -287,10 +285,10 @@ public class DetailsPanel
|
||||||
|
|
||||||
// Collect tooltips.
|
// Collect tooltips.
|
||||||
List<String> tooltips = activeActions.stream().
|
List<String> tooltips = activeActions.stream().
|
||||||
filter(action -> action.tooltip() != null).
|
filter(action -> action.tooltip() != null).
|
||||||
map(action -> this.user.getTranslation(this.world, action.tooltip())).
|
map(action -> this.user.getTranslation(this.world, action.tooltip())).
|
||||||
filter(text -> !text.isBlank()).
|
filter(text -> !text.isBlank()).
|
||||||
collect(Collectors.toCollection(() -> new ArrayList<>(template.actions().size())));
|
collect(Collectors.toCollection(() -> new ArrayList<>(template.actions().size())));
|
||||||
|
|
||||||
// Add tooltips.
|
// Add tooltips.
|
||||||
if (!tooltips.isEmpty())
|
if (!tooltips.isEmpty())
|
||||||
|
@ -398,10 +396,10 @@ public class DetailsPanel
|
||||||
|
|
||||||
// Collect tooltips.
|
// Collect tooltips.
|
||||||
List<String> tooltips = activeActions.stream().
|
List<String> tooltips = activeActions.stream().
|
||||||
filter(action -> action.tooltip() != null).
|
filter(action -> action.tooltip() != null).
|
||||||
map(action -> this.user.getTranslation(this.world, action.tooltip())).
|
map(action -> this.user.getTranslation(this.world, action.tooltip())).
|
||||||
filter(text -> !text.isBlank()).
|
filter(text -> !text.isBlank()).
|
||||||
collect(Collectors.toCollection(() -> new ArrayList<>(template.actions().size())));
|
collect(Collectors.toCollection(() -> new ArrayList<>(template.actions().size())));
|
||||||
|
|
||||||
// Add tooltips.
|
// Add tooltips.
|
||||||
if (!tooltips.isEmpty())
|
if (!tooltips.isEmpty())
|
||||||
|
@ -417,9 +415,9 @@ public class DetailsPanel
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// ---------------------------------------------------------------------
|
// ---------------------------------------------------------------------
|
||||||
// Section: Create common buttons
|
// Section: Create common buttons
|
||||||
// ---------------------------------------------------------------------
|
// ---------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -434,7 +432,7 @@ public class DetailsPanel
|
||||||
long size = this.materialCountList.size();
|
long size = this.materialCountList.size();
|
||||||
|
|
||||||
if (size <= slot.amountMap().getOrDefault("BLOCK", 1) ||
|
if (size <= slot.amountMap().getOrDefault("BLOCK", 1) ||
|
||||||
1.0 * size / slot.amountMap().getOrDefault("BLOCK", 1) <= this.pageIndex + 1)
|
1.0 * size / slot.amountMap().getOrDefault("BLOCK", 1) <= this.pageIndex + 1)
|
||||||
{
|
{
|
||||||
// There are no next elements
|
// There are no next elements
|
||||||
return null;
|
return null;
|
||||||
|
@ -448,7 +446,7 @@ public class DetailsPanel
|
||||||
{
|
{
|
||||||
ItemStack clone = template.icon().clone();
|
ItemStack clone = template.icon().clone();
|
||||||
|
|
||||||
if ((Boolean) template.dataMap().getOrDefault("indexing", false))
|
if (Boolean.TRUE.equals(template.dataMap().getOrDefault("indexing", false)))
|
||||||
{
|
{
|
||||||
clone.setAmount(nextPageIndex);
|
clone.setAmount(nextPageIndex);
|
||||||
}
|
}
|
||||||
|
@ -464,7 +462,7 @@ public class DetailsPanel
|
||||||
if (template.description() != null)
|
if (template.description() != null)
|
||||||
{
|
{
|
||||||
builder.description(this.user.getTranslation(this.world, template.description(),
|
builder.description(this.user.getTranslation(this.world, template.description(),
|
||||||
"[number]", String.valueOf(nextPageIndex)));
|
TextVariables.NUMBER, String.valueOf(nextPageIndex)));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add ClickHandler
|
// Add ClickHandler
|
||||||
|
@ -472,13 +470,11 @@ public class DetailsPanel
|
||||||
{
|
{
|
||||||
for (ItemTemplateRecord.ActionRecords action : template.actions())
|
for (ItemTemplateRecord.ActionRecords action : template.actions())
|
||||||
{
|
{
|
||||||
if (clickType == action.clickType() || ClickType.UNKNOWN.equals(action.clickType()))
|
if ((clickType == action.clickType() || ClickType.UNKNOWN.equals(action.clickType())) &&
|
||||||
|
"NEXT".equalsIgnoreCase(action.actionType()))
|
||||||
{
|
{
|
||||||
if ("NEXT".equalsIgnoreCase(action.actionType()))
|
this.pageIndex++;
|
||||||
{
|
this.build();
|
||||||
this.pageIndex++;
|
|
||||||
this.build();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -488,10 +484,10 @@ public class DetailsPanel
|
||||||
|
|
||||||
// Collect tooltips.
|
// Collect tooltips.
|
||||||
List<String> tooltips = template.actions().stream().
|
List<String> tooltips = template.actions().stream().
|
||||||
filter(action -> action.tooltip() != null).
|
filter(action -> action.tooltip() != null).
|
||||||
map(action -> this.user.getTranslation(this.world, action.tooltip())).
|
map(action -> this.user.getTranslation(this.world, action.tooltip())).
|
||||||
filter(text -> !text.isBlank()).
|
filter(text -> !text.isBlank()).
|
||||||
collect(Collectors.toCollection(() -> new ArrayList<>(template.actions().size())));
|
collect(Collectors.toCollection(() -> new ArrayList<>(template.actions().size())));
|
||||||
|
|
||||||
// Add tooltips.
|
// Add tooltips.
|
||||||
if (!tooltips.isEmpty())
|
if (!tooltips.isEmpty())
|
||||||
|
@ -528,7 +524,7 @@ public class DetailsPanel
|
||||||
{
|
{
|
||||||
ItemStack clone = template.icon().clone();
|
ItemStack clone = template.icon().clone();
|
||||||
|
|
||||||
if ((Boolean) template.dataMap().getOrDefault("indexing", false))
|
if (Boolean.TRUE.equals(template.dataMap().getOrDefault("indexing", false)))
|
||||||
{
|
{
|
||||||
clone.setAmount(previousPageIndex);
|
clone.setAmount(previousPageIndex);
|
||||||
}
|
}
|
||||||
|
@ -544,7 +540,7 @@ public class DetailsPanel
|
||||||
if (template.description() != null)
|
if (template.description() != null)
|
||||||
{
|
{
|
||||||
builder.description(this.user.getTranslation(this.world, template.description(),
|
builder.description(this.user.getTranslation(this.world, template.description(),
|
||||||
"[number]", String.valueOf(previousPageIndex)));
|
TextVariables.NUMBER, String.valueOf(previousPageIndex)));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add ClickHandler
|
// Add ClickHandler
|
||||||
|
@ -552,13 +548,11 @@ public class DetailsPanel
|
||||||
{
|
{
|
||||||
for (ItemTemplateRecord.ActionRecords action : template.actions())
|
for (ItemTemplateRecord.ActionRecords action : template.actions())
|
||||||
{
|
{
|
||||||
if (clickType == action.clickType() || ClickType.UNKNOWN.equals(action.clickType()))
|
if ((clickType == action.clickType() || ClickType.UNKNOWN.equals(action.clickType()))
|
||||||
|
&& "PREVIOUS".equalsIgnoreCase(action.actionType()))
|
||||||
{
|
{
|
||||||
if ("PREVIOUS".equalsIgnoreCase(action.actionType()))
|
this.pageIndex--;
|
||||||
{
|
this.build();
|
||||||
this.pageIndex--;
|
|
||||||
this.build();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -568,10 +562,10 @@ public class DetailsPanel
|
||||||
|
|
||||||
// Collect tooltips.
|
// Collect tooltips.
|
||||||
List<String> tooltips = template.actions().stream().
|
List<String> tooltips = template.actions().stream().
|
||||||
filter(action -> action.tooltip() != null).
|
filter(action -> action.tooltip() != null).
|
||||||
map(action -> this.user.getTranslation(this.world, action.tooltip())).
|
map(action -> this.user.getTranslation(this.world, action.tooltip())).
|
||||||
filter(text -> !text.isBlank()).
|
filter(text -> !text.isBlank()).
|
||||||
collect(Collectors.toCollection(() -> new ArrayList<>(template.actions().size())));
|
collect(Collectors.toCollection(() -> new ArrayList<>(template.actions().size())));
|
||||||
|
|
||||||
// Add tooltips.
|
// Add tooltips.
|
||||||
if (!tooltips.isEmpty())
|
if (!tooltips.isEmpty())
|
||||||
|
@ -585,9 +579,9 @@ public class DetailsPanel
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// ---------------------------------------------------------------------
|
// ---------------------------------------------------------------------
|
||||||
// Section: Create Material Button
|
// Section: Create Material Button
|
||||||
// ---------------------------------------------------------------------
|
// ---------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -625,7 +619,7 @@ public class DetailsPanel
|
||||||
* @return PanelItem for generator tier.
|
* @return PanelItem for generator tier.
|
||||||
*/
|
*/
|
||||||
private PanelItem createMaterialButton(ItemTemplateRecord template,
|
private PanelItem createMaterialButton(ItemTemplateRecord template,
|
||||||
Pair<Material, Integer> materialCount)
|
Pair<Material, Integer> materialCount)
|
||||||
{
|
{
|
||||||
PanelItemBuilder builder = new PanelItemBuilder();
|
PanelItemBuilder builder = new PanelItemBuilder();
|
||||||
|
|
||||||
|
@ -646,30 +640,30 @@ public class DetailsPanel
|
||||||
if (template.title() != null)
|
if (template.title() != null)
|
||||||
{
|
{
|
||||||
builder.name(this.user.getTranslation(this.world, template.title(),
|
builder.name(this.user.getTranslation(this.world, template.title(),
|
||||||
"[number]", String.valueOf(materialCount.getValue()),
|
TextVariables.NUMBER, String.valueOf(materialCount.getValue()),
|
||||||
"[material]", Utils.prettifyObject(materialCount.getKey(), this.user)));
|
"[material]", Utils.prettifyObject(materialCount.getKey(), this.user)));
|
||||||
}
|
}
|
||||||
|
|
||||||
String description = Utils.prettifyDescription(materialCount.getKey(), this.user);
|
String description = Utils.prettifyDescription(materialCount.getKey(), this.user);
|
||||||
|
|
||||||
final String reference = "level.gui.buttons.material.";
|
final String reference = "level.gui.buttons.material.";
|
||||||
String blockId = this.user.getTranslationOrNothing(reference + "id",
|
String blockId = this.user.getTranslationOrNothing(reference + "id",
|
||||||
"[id]", materialCount.getKey().name());
|
"[id]", materialCount.getKey().name());
|
||||||
|
|
||||||
int blockValue = this.addon.getBlockConfig().getBlockValues().getOrDefault(materialCount.getKey(), 0);
|
int blockValue = this.addon.getBlockConfig().getBlockValues().getOrDefault(materialCount.getKey(), 0);
|
||||||
String value = blockValue > 0 ? this.user.getTranslationOrNothing(reference + "value",
|
String value = blockValue > 0 ? this.user.getTranslationOrNothing(reference + "value",
|
||||||
"[number]", String.valueOf(blockValue)) : "";
|
TextVariables.NUMBER, String.valueOf(blockValue)) : "";
|
||||||
|
|
||||||
int blockLimit = this.addon.getBlockConfig().getBlockLimits().getOrDefault(materialCount.getKey(), 0);
|
int blockLimit = this.addon.getBlockConfig().getBlockLimits().getOrDefault(materialCount.getKey(), 0);
|
||||||
String limit = blockLimit > 0 ? this.user.getTranslationOrNothing(reference + "limit",
|
String limit = blockLimit > 0 ? this.user.getTranslationOrNothing(reference + "limit",
|
||||||
"[number]", String.valueOf(blockLimit)) : "";
|
TextVariables.NUMBER, String.valueOf(blockLimit)) : "";
|
||||||
|
|
||||||
String count = this.user.getTranslationOrNothing(reference + "count",
|
String count = this.user.getTranslationOrNothing(reference + "count",
|
||||||
"[number]", String.valueOf(materialCount.getValue()));
|
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",
|
String valueText = calculatedValue > 0 ? this.user.getTranslationOrNothing(reference + "calculated",
|
||||||
"[number]", String.valueOf(calculatedValue)) : "";
|
TextVariables.NUMBER, String.valueOf(calculatedValue)) : "";
|
||||||
|
|
||||||
if (template.description() != null)
|
if (template.description() != null)
|
||||||
{
|
{
|
||||||
|
@ -680,18 +674,18 @@ public class DetailsPanel
|
||||||
"[calculated]", valueText,
|
"[calculated]", valueText,
|
||||||
"[limit]", limit,
|
"[limit]", limit,
|
||||||
"[count]", count).
|
"[count]", count).
|
||||||
replaceAll("(?m)^[ \\t]*\\r?\\n", "").
|
replaceAll("(?m)^[ \\t]*\\r?\\n", "").
|
||||||
replaceAll("(?<!\\\\)\\|", "\n").
|
replaceAll("(?<!\\\\)\\|", "\n").
|
||||||
replaceAll("\\\\\\|", "|"));
|
replace("\\\\\\|", "|"));
|
||||||
}
|
}
|
||||||
|
|
||||||
return builder.build();
|
return builder.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// ---------------------------------------------------------------------
|
// ---------------------------------------------------------------------
|
||||||
// Section: Other Methods
|
// Section: Other Methods
|
||||||
// ---------------------------------------------------------------------
|
// ---------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -703,16 +697,16 @@ public class DetailsPanel
|
||||||
* @param user User who opens panel
|
* @param user User who opens panel
|
||||||
*/
|
*/
|
||||||
public static void openPanel(Level addon,
|
public static void openPanel(Level addon,
|
||||||
World world,
|
World world,
|
||||||
User user)
|
User user)
|
||||||
{
|
{
|
||||||
new DetailsPanel(addon, world, user).build();
|
new DetailsPanel(addon, world, user).build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// ---------------------------------------------------------------------
|
// ---------------------------------------------------------------------
|
||||||
// Section: Enums
|
// Section: Enums
|
||||||
// ---------------------------------------------------------------------
|
// ---------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -759,9 +753,9 @@ public class DetailsPanel
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// ---------------------------------------------------------------------
|
// ---------------------------------------------------------------------
|
||||||
// Section: Variables
|
// Section: Variables
|
||||||
// ---------------------------------------------------------------------
|
// ---------------------------------------------------------------------
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This variable holds targeted island.
|
* This variable holds targeted island.
|
||||||
|
|
|
@ -6,14 +6,18 @@
|
||||||
package world.bentobox.level.panels;
|
package world.bentobox.level.panels;
|
||||||
|
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.UUID;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
import org.bukkit.event.inventory.ClickType;
|
import org.bukkit.event.inventory.ClickType;
|
||||||
import java.io.File;
|
|
||||||
import java.util.*;
|
|
||||||
import java.util.stream.Collectors;
|
|
||||||
|
|
||||||
import world.bentobox.bentobox.api.addons.GameModeAddon;
|
import world.bentobox.bentobox.api.addons.GameModeAddon;
|
||||||
|
import world.bentobox.bentobox.api.localization.TextVariables;
|
||||||
import world.bentobox.bentobox.api.panels.PanelItem;
|
import world.bentobox.bentobox.api.panels.PanelItem;
|
||||||
import world.bentobox.bentobox.api.panels.TemplatedPanel;
|
import world.bentobox.bentobox.api.panels.TemplatedPanel;
|
||||||
import world.bentobox.bentobox.api.panels.builders.PanelItemBuilder;
|
import world.bentobox.bentobox.api.panels.builders.PanelItemBuilder;
|
||||||
|
@ -31,9 +35,11 @@ import world.bentobox.level.util.Utils;
|
||||||
*/
|
*/
|
||||||
public class TopLevelPanel
|
public class TopLevelPanel
|
||||||
{
|
{
|
||||||
// ---------------------------------------------------------------------
|
|
||||||
// Section: Internal Constructor
|
|
||||||
// ---------------------------------------------------------------------
|
// ---------------------------------------------------------------------
|
||||||
|
// Section: Internal Constructor
|
||||||
|
// ---------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -53,11 +59,11 @@ public class TopLevelPanel
|
||||||
this.iconPermission = permissionPrefix + "level.icon";
|
this.iconPermission = permissionPrefix + "level.icon";
|
||||||
|
|
||||||
this.topIslands = this.addon.getManager().getTopTen(this.world, 10).entrySet().stream().
|
this.topIslands = this.addon.getManager().getTopTen(this.world, 10).entrySet().stream().
|
||||||
map(entry -> {
|
map(entry -> {
|
||||||
Island island = this.addon.getIslandsManager().getIsland(this.world, entry.getKey());
|
Island island = this.addon.getIslandsManager().getIsland(this.world, entry.getKey());
|
||||||
return new IslandTopRecord(island, entry.getValue());
|
return new IslandTopRecord(island, entry.getValue());
|
||||||
}).
|
}).
|
||||||
collect(Collectors.toList());
|
collect(Collectors.toList());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -82,9 +88,9 @@ public class TopLevelPanel
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// ---------------------------------------------------------------------
|
// ---------------------------------------------------------------------
|
||||||
// Section: Methods
|
// Section: Methods
|
||||||
// ---------------------------------------------------------------------
|
// ---------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -100,8 +106,6 @@ public class TopLevelPanel
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
final String reference = "level.gui.buttons.island.";
|
|
||||||
|
|
||||||
PanelItemBuilder builder = new PanelItemBuilder();
|
PanelItemBuilder builder = new PanelItemBuilder();
|
||||||
|
|
||||||
if (template.icon() != null)
|
if (template.icon() != null)
|
||||||
|
@ -112,18 +116,18 @@ public class TopLevelPanel
|
||||||
if (template.title() != null)
|
if (template.title() != null)
|
||||||
{
|
{
|
||||||
builder.name(this.user.getTranslation(this.world, template.title(),
|
builder.name(this.user.getTranslation(this.world, template.title(),
|
||||||
"[name]", String.valueOf(index)));
|
TextVariables.NAME, String.valueOf(index)));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
builder.name(this.user.getTranslation(this.world, reference,
|
builder.name(this.user.getTranslation(this.world, REFERENCE,
|
||||||
"[name]", String.valueOf(index)));
|
TextVariables.NAME, String.valueOf(index)));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (template.description() != null)
|
if (template.description() != null)
|
||||||
{
|
{
|
||||||
builder.description(this.user.getTranslation(this.world, template.description(),
|
builder.description(this.user.getTranslation(this.world, template.description(),
|
||||||
"[number]", String.valueOf(index)));
|
TextVariables.NUMBER, String.valueOf(index)));
|
||||||
}
|
}
|
||||||
|
|
||||||
builder.amount(index != 0 ? (int) index : 1);
|
builder.amount(index != 0 ? (int) index : 1);
|
||||||
|
@ -189,23 +193,23 @@ public class TopLevelPanel
|
||||||
{
|
{
|
||||||
switch (action.actionType().toUpperCase())
|
switch (action.actionType().toUpperCase())
|
||||||
{
|
{
|
||||||
case "WARP" -> {
|
case "WARP" -> {
|
||||||
return island.getOwner() == null ||
|
return island.getOwner() == null ||
|
||||||
this.addon.getWarpHook() == null ||
|
this.addon.getWarpHook() == null ||
|
||||||
!this.addon.getWarpHook().getWarpSignsManager().hasWarp(this.world, island.getOwner());
|
!this.addon.getWarpHook().getWarpSignsManager().hasWarp(this.world, island.getOwner());
|
||||||
}
|
}
|
||||||
case "VISIT" -> {
|
case "VISIT" -> {
|
||||||
return island.getOwner() == null ||
|
return island.getOwner() == null ||
|
||||||
this.addon.getVisitHook() == null ||
|
this.addon.getVisitHook() == null ||
|
||||||
!this.addon.getVisitHook().getAddonManager().preprocessTeleportation(this.user, island);
|
!this.addon.getVisitHook().getAddonManager().preprocessTeleportation(this.user, island);
|
||||||
}
|
}
|
||||||
case "VIEW" -> {
|
case "VIEW" -> {
|
||||||
return island.getOwner() == null ||
|
return island.getOwner() == null ||
|
||||||
!island.getMemberSet(RanksManager.MEMBER_RANK).contains(this.user.getUniqueId());
|
!island.getMemberSet(RanksManager.MEMBER_RANK).contains(this.user.getUniqueId());
|
||||||
}
|
}
|
||||||
default -> {
|
default -> {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -218,33 +222,38 @@ public class TopLevelPanel
|
||||||
{
|
{
|
||||||
switch (action.actionType().toUpperCase())
|
switch (action.actionType().toUpperCase())
|
||||||
{
|
{
|
||||||
case "WARP" -> {
|
case "WARP" -> {
|
||||||
this.user.closeInventory();
|
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" -> {
|
case "VISIT" ->
|
||||||
// The command call implementation solves necessity to check for all visits options,
|
// 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
|
// like cool down, confirmation and preprocess in single go. Would it be better to write
|
||||||
// all logic here?
|
// all logic here?
|
||||||
|
|
||||||
this.addon.getPlugin().getIWM().getAddon(this.world).
|
this.addon.getPlugin().getIWM().getAddon(this.world).
|
||||||
flatMap(GameModeAddon::getPlayerCommand).ifPresent(command ->
|
flatMap(GameModeAddon::getPlayerCommand).ifPresent(command ->
|
||||||
{
|
{
|
||||||
String mainCommand =
|
String mainCommand =
|
||||||
this.addon.getVisitHook().getSettings().getPlayerMainCommand();
|
this.addon.getVisitHook().getSettings().getPlayerMainCommand();
|
||||||
|
|
||||||
if (!mainCommand.isBlank())
|
if (!mainCommand.isBlank())
|
||||||
{
|
{
|
||||||
this.user.closeInventory();
|
|
||||||
this.user.performCommand(command.getTopLabel() + " " + mainCommand + " " + island.getOwner());
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
case "VIEW" -> {
|
|
||||||
this.user.closeInventory();
|
this.user.closeInventory();
|
||||||
// Open Detailed GUI.
|
this.user.performCommand(command.getTopLabel() + " " + mainCommand + " " + island.getOwner());
|
||||||
DetailsPanel.openPanel(this.addon, this.world, this.user);
|
|
||||||
}
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
case "VIEW" -> {
|
||||||
|
this.user.closeInventory();
|
||||||
|
// Open Detailed GUI.
|
||||||
|
DetailsPanel.openPanel(this.addon, this.world, this.user);
|
||||||
|
}
|
||||||
|
// Catch default
|
||||||
|
default -> {
|
||||||
|
this.user.closeInventory();
|
||||||
|
addon.logError("Unknown action type " + action.actionType().toUpperCase());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -254,10 +263,10 @@ public class TopLevelPanel
|
||||||
|
|
||||||
// Collect tooltips.
|
// Collect tooltips.
|
||||||
List<String> tooltips = activeActions.stream().
|
List<String> tooltips = activeActions.stream().
|
||||||
filter(action -> action.tooltip() != null).
|
filter(action -> action.tooltip() != null).
|
||||||
map(action -> this.user.getTranslation(this.world, action.tooltip())).
|
map(action -> this.user.getTranslation(this.world, action.tooltip())).
|
||||||
filter(text -> !text.isBlank()).
|
filter(text -> !text.isBlank()).
|
||||||
collect(Collectors.toCollection(() -> new ArrayList<>(template.actions().size())));
|
collect(Collectors.toCollection(() -> new ArrayList<>(template.actions().size())));
|
||||||
|
|
||||||
// Add tooltips.
|
// Add tooltips.
|
||||||
if (!tooltips.isEmpty())
|
if (!tooltips.isEmpty())
|
||||||
|
@ -278,22 +287,21 @@ public class TopLevelPanel
|
||||||
* @param template the template
|
* @param template the template
|
||||||
* @param island the island
|
* @param island the island
|
||||||
*/
|
*/
|
||||||
private void populateIslandTitle(PanelItemBuilder builder,
|
private void populateIslandTitle(PanelItemBuilder builder,
|
||||||
ItemTemplateRecord template,
|
ItemTemplateRecord template,
|
||||||
Island island)
|
Island island)
|
||||||
{
|
{
|
||||||
final String reference = "level.gui.buttons.island.";
|
|
||||||
|
|
||||||
// Get Island Name
|
// Get Island Name
|
||||||
String nameText;
|
String nameText;
|
||||||
|
|
||||||
if (island.getName() == null || island.getName().isEmpty())
|
if (island.getName() == null || island.getName().isEmpty())
|
||||||
{
|
{
|
||||||
nameText = this.user.getTranslation(reference + "owners-island",
|
nameText = this.user.getTranslation(REFERENCE + "owners-island",
|
||||||
"[player]",
|
PLAYER,
|
||||||
island.getOwner() == null ?
|
island.getOwner() == null ?
|
||||||
this.user.getTranslation(reference + "unknown") :
|
this.user.getTranslation(REFERENCE + "unknown") :
|
||||||
this.addon.getPlayers().getName(island.getOwner()));
|
this.addon.getPlayers().getName(island.getOwner()));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -304,11 +312,11 @@ public class TopLevelPanel
|
||||||
if (template.title() != null && !template.title().isBlank())
|
if (template.title() != null && !template.title().isBlank())
|
||||||
{
|
{
|
||||||
builder.name(this.user.getTranslation(this.world, template.title(),
|
builder.name(this.user.getTranslation(this.world, template.title(),
|
||||||
"[name]", nameText));
|
TextVariables.NAME, nameText));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
builder.name(this.user.getTranslation(reference + "name", "[name]", nameText));
|
builder.name(this.user.getTranslation(REFERENCE + "name", TextVariables.NAME, nameText));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -321,11 +329,11 @@ public class TopLevelPanel
|
||||||
* @param island the island
|
* @param island the island
|
||||||
*/
|
*/
|
||||||
private void populateIslandIcon(PanelItemBuilder builder,
|
private void populateIslandIcon(PanelItemBuilder builder,
|
||||||
ItemTemplateRecord template,
|
ItemTemplateRecord template,
|
||||||
Island island)
|
Island island)
|
||||||
{
|
{
|
||||||
User owner = island.getOwner() == null ? null : User.getInstance(island.getOwner());
|
User owner = island.getOwner() == null ? null : User.getInstance(island.getOwner());
|
||||||
|
|
||||||
// Get permission or island icon
|
// Get permission or island icon
|
||||||
String permissionIcon = owner == null ? null :
|
String permissionIcon = owner == null ? null :
|
||||||
Utils.getPermissionValue(owner, this.iconPermission, null);
|
Utils.getPermissionValue(owner, this.iconPermission, null);
|
||||||
|
@ -376,20 +384,18 @@ public class TopLevelPanel
|
||||||
* @param islandTopRecord the top record object
|
* @param islandTopRecord the top record object
|
||||||
* @param index place index.
|
* @param index place index.
|
||||||
*/
|
*/
|
||||||
private void populateIslandDescription(PanelItemBuilder builder,
|
private void populateIslandDescription(PanelItemBuilder builder,
|
||||||
ItemTemplateRecord template,
|
ItemTemplateRecord template,
|
||||||
Island island,
|
Island island,
|
||||||
IslandTopRecord islandTopRecord,
|
IslandTopRecord islandTopRecord,
|
||||||
int index)
|
int index)
|
||||||
{
|
{
|
||||||
final String reference = "level.gui.buttons.island.";
|
|
||||||
|
|
||||||
// Get Owner Name
|
// Get Owner Name
|
||||||
String ownerText = this.user.getTranslation(reference + "owner",
|
String ownerText = this.user.getTranslation(REFERENCE + "owner",
|
||||||
"[player]",
|
PLAYER,
|
||||||
island.getOwner() == null ?
|
island.getOwner() == null ?
|
||||||
this.user.getTranslation(reference + "unknown") :
|
this.user.getTranslation(REFERENCE + "unknown") :
|
||||||
this.addon.getPlayers().getName(island.getOwner()));
|
this.addon.getPlayers().getName(island.getOwner()));
|
||||||
|
|
||||||
// Get Members Text
|
// Get Members Text
|
||||||
String memberText;
|
String memberText;
|
||||||
|
@ -397,11 +403,11 @@ public class TopLevelPanel
|
||||||
if (island.getMemberSet().size() > 1)
|
if (island.getMemberSet().size() > 1)
|
||||||
{
|
{
|
||||||
StringBuilder memberBuilder = new StringBuilder(
|
StringBuilder memberBuilder = new StringBuilder(
|
||||||
this.user.getTranslationOrNothing(reference + "members-title"));
|
this.user.getTranslationOrNothing(REFERENCE + "members-title"));
|
||||||
|
|
||||||
for (UUID uuid : island.getMemberSet())
|
for (UUID uuid : island.getMemberSet())
|
||||||
{
|
{
|
||||||
User user = User.getInstance(uuid);
|
User member = User.getInstance(uuid);
|
||||||
|
|
||||||
if (memberBuilder.length() > 0)
|
if (memberBuilder.length() > 0)
|
||||||
{
|
{
|
||||||
|
@ -409,8 +415,8 @@ public class TopLevelPanel
|
||||||
}
|
}
|
||||||
|
|
||||||
memberBuilder.append(
|
memberBuilder.append(
|
||||||
this.user.getTranslationOrNothing(reference + "member",
|
this.user.getTranslationOrNothing(REFERENCE + "member",
|
||||||
"[player]", user.getName()));
|
PLAYER, member.getName()));
|
||||||
}
|
}
|
||||||
|
|
||||||
memberText = memberBuilder.toString();
|
memberText = memberBuilder.toString();
|
||||||
|
@ -420,11 +426,11 @@ public class TopLevelPanel
|
||||||
memberText = "";
|
memberText = "";
|
||||||
}
|
}
|
||||||
|
|
||||||
String placeText = this.user.getTranslation(reference + "place",
|
String placeText = this.user.getTranslation(REFERENCE + "place",
|
||||||
"[number]", String.valueOf(index));
|
TextVariables.NUMBER, String.valueOf(index));
|
||||||
|
|
||||||
String levelText = this.user.getTranslation(reference + "level",
|
String levelText = this.user.getTranslation(REFERENCE + "level",
|
||||||
"[number]", this.addon.getManager().formatLevel(islandTopRecord.level()));
|
TextVariables.NUMBER, this.addon.getManager().formatLevel(islandTopRecord.level()));
|
||||||
|
|
||||||
// Template specific description is always more important than custom one.
|
// Template specific description is always more important than custom one.
|
||||||
if (template.description() != null && !template.description().isBlank())
|
if (template.description() != null && !template.description().isBlank())
|
||||||
|
@ -434,26 +440,26 @@ public class TopLevelPanel
|
||||||
"[members]", memberText,
|
"[members]", memberText,
|
||||||
"[level]", levelText,
|
"[level]", levelText,
|
||||||
"[place]", placeText).
|
"[place]", placeText).
|
||||||
replaceAll("(?m)^[ \\t]*\\r?\\n", "").
|
replaceAll("(?m)^[ \\t]*\\r?\\n", "").
|
||||||
replaceAll("(?<!\\\\)\\|", "\n").
|
replaceAll("(?<!\\\\)\\|", "\n").
|
||||||
replaceAll("\\\\\\|", "|"));
|
replace("\\\\\\|", "|")); // Not a regex - replace is more efficient
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// Now combine everything.
|
// Now combine everything.
|
||||||
String descriptionText = this.user.getTranslation(reference + "description",
|
String descriptionText = this.user.getTranslation(REFERENCE + "description",
|
||||||
"[owner]", ownerText,
|
"[owner]", ownerText,
|
||||||
"[members]", memberText,
|
"[members]", memberText,
|
||||||
"[level]", levelText,
|
"[level]", levelText,
|
||||||
"[place]", placeText);
|
"[place]", placeText);
|
||||||
|
|
||||||
builder.description(descriptionText.
|
builder.description(descriptionText.
|
||||||
replaceAll("(?m)^[ \\t]*\\r?\\n", "").
|
replaceAll("(?m)^[ \\t]*\\r?\\n", "").
|
||||||
replaceAll("(?<!\\\\)\\|", "\n").
|
replaceAll("(?<!\\\\)\\|", "\n").
|
||||||
replaceAll("\\\\\\|", "|"));
|
replace("\\\\\\|", "|")); // Not a regex - replace is more efficient
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create viewer button panel item.
|
* Create viewer button panel item.
|
||||||
|
@ -473,11 +479,11 @@ public class TopLevelPanel
|
||||||
int place = this.addon.getManager().getRank(this.world, this.user.getUniqueId());
|
int place = this.addon.getManager().getRank(this.world, this.user.getUniqueId());
|
||||||
long level = this.addon.getIslandLevel(this.world, island.getOwner());
|
long level = this.addon.getIslandLevel(this.world, island.getOwner());
|
||||||
|
|
||||||
IslandTopRecord record = new IslandTopRecord(island, level);
|
IslandTopRecord topRecord = new IslandTopRecord(island, level);
|
||||||
|
|
||||||
return this.createIslandIcon(template, record, place);
|
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
|
* This method is used to open UserPanel outside this class. It will be much easier to open panel with single method
|
||||||
|
@ -493,11 +499,16 @@ public class TopLevelPanel
|
||||||
new TopLevelPanel(addon, user, world, permissionPrefix).build();
|
new TopLevelPanel(addon, user, world, permissionPrefix).build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ---------------------------------------------------------------------
|
||||||
|
// Section: Constants
|
||||||
|
// ---------------------------------------------------------------------
|
||||||
|
|
||||||
// ---------------------------------------------------------------------
|
private static final String REFERENCE = "level.gui.buttons.island.";
|
||||||
// Section: Record
|
private static final String PLAYER = "[player]";
|
||||||
// ---------------------------------------------------------------------
|
|
||||||
|
|
||||||
|
// ---------------------------------------------------------------------
|
||||||
|
// Section: Record
|
||||||
|
// ---------------------------------------------------------------------
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This record is used internally. It converts user -> level to island -> level.
|
* This record is used internally. It converts user -> level to island -> level.
|
||||||
|
@ -505,9 +516,9 @@ public class TopLevelPanel
|
||||||
private record IslandTopRecord(Island island, Long level) {}
|
private record IslandTopRecord(Island island, Long level) {}
|
||||||
|
|
||||||
|
|
||||||
// ---------------------------------------------------------------------
|
// ---------------------------------------------------------------------
|
||||||
// Section: Variables
|
// Section: Variables
|
||||||
// ---------------------------------------------------------------------
|
// ---------------------------------------------------------------------
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This variable allows to access addon object.
|
* This variable allows to access addon object.
|
||||||
|
|
|
@ -1,25 +1,29 @@
|
||||||
package world.bentobox.level.panels;
|
package world.bentobox.level.panels;
|
||||||
|
|
||||||
|
|
||||||
import com.google.common.base.Enums;
|
import java.io.File;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.Comparator;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.function.Consumer;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
import org.bukkit.event.inventory.ClickType;
|
import org.bukkit.event.inventory.ClickType;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
import java.io.File;
|
|
||||||
import java.util.*;
|
import com.google.common.base.Enums;
|
||||||
import java.util.function.Consumer;
|
|
||||||
import java.util.stream.Collectors;
|
|
||||||
|
|
||||||
import lv.id.bonne.panelutils.PanelUtils;
|
import lv.id.bonne.panelutils.PanelUtils;
|
||||||
|
import world.bentobox.bentobox.api.localization.TextVariables;
|
||||||
import world.bentobox.bentobox.api.panels.PanelItem;
|
import world.bentobox.bentobox.api.panels.PanelItem;
|
||||||
import world.bentobox.bentobox.api.panels.TemplatedPanel;
|
import world.bentobox.bentobox.api.panels.TemplatedPanel;
|
||||||
import world.bentobox.bentobox.api.panels.builders.PanelItemBuilder;
|
import world.bentobox.bentobox.api.panels.builders.PanelItemBuilder;
|
||||||
import world.bentobox.bentobox.api.panels.builders.TemplatedPanelBuilder;
|
import world.bentobox.bentobox.api.panels.builders.TemplatedPanelBuilder;
|
||||||
import world.bentobox.bentobox.api.panels.reader.ItemTemplateRecord;
|
import world.bentobox.bentobox.api.panels.reader.ItemTemplateRecord;
|
||||||
import world.bentobox.bentobox.api.user.User;
|
import world.bentobox.bentobox.api.user.User;
|
||||||
import world.bentobox.bentobox.hooks.LangUtilsHook;
|
|
||||||
import world.bentobox.bentobox.util.Pair;
|
|
||||||
import world.bentobox.level.Level;
|
import world.bentobox.level.Level;
|
||||||
import world.bentobox.level.util.ConversationUtils;
|
import world.bentobox.level.util.ConversationUtils;
|
||||||
import world.bentobox.level.util.Utils;
|
import world.bentobox.level.util.Utils;
|
||||||
|
@ -30,6 +34,7 @@ import world.bentobox.level.util.Utils;
|
||||||
*/
|
*/
|
||||||
public class ValuePanel
|
public class ValuePanel
|
||||||
{
|
{
|
||||||
|
|
||||||
// ---------------------------------------------------------------------
|
// ---------------------------------------------------------------------
|
||||||
// Section: Internal Constructor
|
// Section: Internal Constructor
|
||||||
// ---------------------------------------------------------------------
|
// ---------------------------------------------------------------------
|
||||||
|
@ -43,8 +48,8 @@ public class ValuePanel
|
||||||
* @param user User who opens panel
|
* @param user User who opens panel
|
||||||
*/
|
*/
|
||||||
private ValuePanel(Level addon,
|
private ValuePanel(Level addon,
|
||||||
World world,
|
World world,
|
||||||
User user)
|
User user)
|
||||||
{
|
{
|
||||||
this.addon = addon;
|
this.addon = addon;
|
||||||
this.world = world;
|
this.world = world;
|
||||||
|
@ -52,18 +57,18 @@ public class ValuePanel
|
||||||
|
|
||||||
this.activeFilter = Filter.NAME_ASC;
|
this.activeFilter = Filter.NAME_ASC;
|
||||||
this.materialRecordList = Arrays.stream(Material.values()).
|
this.materialRecordList = Arrays.stream(Material.values()).
|
||||||
filter(Material::isBlock).
|
filter(Material::isBlock).
|
||||||
filter(m -> !m.name().startsWith("LEGACY_")).
|
filter(m -> !m.name().startsWith("LEGACY_")).
|
||||||
map(material ->
|
map(material ->
|
||||||
{
|
{
|
||||||
Integer value = this.addon.getBlockConfig().getValue(this.world, material);
|
Integer value = this.addon.getBlockConfig().getValue(this.world, material);
|
||||||
Integer limit = this.addon.getBlockConfig().getBlockLimits().get(material);
|
Integer limit = this.addon.getBlockConfig().getBlockLimits().get(material);
|
||||||
|
|
||||||
return new MaterialRecord(material,
|
return new MaterialRecord(material,
|
||||||
value != null ? value : 0,
|
value != null ? value : 0,
|
||||||
limit != null ? limit : 0);
|
limit != null ? limit : 0);
|
||||||
}).
|
}).
|
||||||
collect(Collectors.toList());
|
collect(Collectors.toList());
|
||||||
|
|
||||||
this.elementList = new ArrayList<>(Material.values().length);
|
this.elementList = new ArrayList<>(Material.values().length);
|
||||||
this.searchText = "";
|
this.searchText = "";
|
||||||
|
@ -86,7 +91,7 @@ public class ValuePanel
|
||||||
|
|
||||||
panelBuilder.registerTypeBuilder("NEXT", this::createNextButton);
|
panelBuilder.registerTypeBuilder("NEXT", this::createNextButton);
|
||||||
panelBuilder.registerTypeBuilder("PREVIOUS", this::createPreviousButton);
|
panelBuilder.registerTypeBuilder("PREVIOUS", this::createPreviousButton);
|
||||||
panelBuilder.registerTypeBuilder("BLOCK", this::createMaterialButton);
|
panelBuilder.registerTypeBuilder(BLOCK, this::createMaterialButton);
|
||||||
|
|
||||||
panelBuilder.registerTypeBuilder("FILTER", this::createFilterButton);
|
panelBuilder.registerTypeBuilder("FILTER", this::createFilterButton);
|
||||||
panelBuilder.registerTypeBuilder("SEARCH", this::createSearchButton);
|
panelBuilder.registerTypeBuilder("SEARCH", this::createSearchButton);
|
||||||
|
@ -105,60 +110,60 @@ public class ValuePanel
|
||||||
|
|
||||||
switch (this.activeFilter)
|
switch (this.activeFilter)
|
||||||
{
|
{
|
||||||
case VALUE_ASC ->
|
case VALUE_ASC ->
|
||||||
{
|
|
||||||
sorter = (o1, o2) ->
|
|
||||||
{
|
|
||||||
if (o1.value().equals(o2.value()))
|
|
||||||
{
|
|
||||||
String o1Name = Utils.prettifyObject(o1.material(), this.user);
|
|
||||||
String o2Name = Utils.prettifyObject(o2.material(), this.user);
|
|
||||||
|
|
||||||
return String.CASE_INSENSITIVE_ORDER.compare(o1Name, o2Name);
|
sorter = (o1, o2) ->
|
||||||
}
|
{
|
||||||
else
|
if (o1.value().equals(o2.value()))
|
||||||
{
|
|
||||||
return Integer.compare(o1.value(), o2.value());
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
case VALUE_DESC ->
|
|
||||||
{
|
{
|
||||||
sorter = (o1, o2) ->
|
String o1Name = Utils.prettifyObject(o1.material(), this.user);
|
||||||
{
|
String o2Name = Utils.prettifyObject(o2.material(), this.user);
|
||||||
if (o1.value().equals(o2.value()))
|
|
||||||
{
|
|
||||||
String o1Name = Utils.prettifyObject(o1.material(), this.user);
|
|
||||||
String o2Name = Utils.prettifyObject(o2.material(), this.user);
|
|
||||||
|
|
||||||
return String.CASE_INSENSITIVE_ORDER.compare(o1Name, o2Name);
|
return String.CASE_INSENSITIVE_ORDER.compare(o1Name, o2Name);
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return Integer.compare(o2.value(), o1.value());
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
case NAME_DESC ->
|
else
|
||||||
{
|
{
|
||||||
sorter = (o1, o2) ->
|
return Integer.compare(o1.value(), o2.value());
|
||||||
{
|
|
||||||
String o1Name = Utils.prettifyObject(o1.material(), this.user);
|
|
||||||
String o2Name = Utils.prettifyObject(o2.material(), this.user);
|
|
||||||
|
|
||||||
return String.CASE_INSENSITIVE_ORDER.compare(o2Name, o1Name);
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
default ->
|
};
|
||||||
|
|
||||||
|
case VALUE_DESC ->
|
||||||
|
|
||||||
|
sorter = (o1, o2) ->
|
||||||
|
{
|
||||||
|
if (o1.value().equals(o2.value()))
|
||||||
{
|
{
|
||||||
sorter = (o1, o2) ->
|
String o1Name = Utils.prettifyObject(o1.material(), this.user);
|
||||||
{
|
String o2Name = Utils.prettifyObject(o2.material(), this.user);
|
||||||
String o1Name = Utils.prettifyObject(o1.material(), this.user);
|
|
||||||
String o2Name = Utils.prettifyObject(o2.material(), this.user);
|
|
||||||
|
|
||||||
return String.CASE_INSENSITIVE_ORDER.compare(o1Name, o2Name);
|
return String.CASE_INSENSITIVE_ORDER.compare(o1Name, o2Name);
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return Integer.compare(o2.value(), o1.value());
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
case NAME_DESC ->
|
||||||
|
|
||||||
|
sorter = (o1, o2) ->
|
||||||
|
{
|
||||||
|
String o1Name = Utils.prettifyObject(o1.material(), this.user);
|
||||||
|
String o2Name = Utils.prettifyObject(o2.material(), this.user);
|
||||||
|
|
||||||
|
return String.CASE_INSENSITIVE_ORDER.compare(o2Name, o1Name);
|
||||||
|
};
|
||||||
|
|
||||||
|
default ->
|
||||||
|
|
||||||
|
sorter = (o1, o2) ->
|
||||||
|
{
|
||||||
|
String o1Name = Utils.prettifyObject(o1.material(), this.user);
|
||||||
|
String o2Name = Utils.prettifyObject(o2.material(), this.user);
|
||||||
|
|
||||||
|
return String.CASE_INSENSITIVE_ORDER.compare(o1Name, o2Name);
|
||||||
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
this.materialRecordList.sort(sorter);
|
this.materialRecordList.sort(sorter);
|
||||||
|
@ -168,12 +173,12 @@ public class ValuePanel
|
||||||
this.elementList = new ArrayList<>(this.materialRecordList.size());
|
this.elementList = new ArrayList<>(this.materialRecordList.size());
|
||||||
final String text = this.searchText.toLowerCase();
|
final String text = this.searchText.toLowerCase();
|
||||||
|
|
||||||
this.materialRecordList.forEach(record ->
|
this.materialRecordList.forEach(rec ->
|
||||||
{
|
{
|
||||||
if (record.material.name().toLowerCase().contains(text) ||
|
if (rec.material.name().toLowerCase().contains(text) ||
|
||||||
Utils.prettifyObject(record.material(), this.user).toLowerCase().contains(text))
|
Utils.prettifyObject(rec.material(), this.user).toLowerCase().contains(text))
|
||||||
{
|
{
|
||||||
this.elementList.add(record);
|
this.elementList.add(rec);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -186,9 +191,9 @@ public class ValuePanel
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// ---------------------------------------------------------------------
|
// ---------------------------------------------------------------------
|
||||||
// Section: Tab Button Type
|
// Section: Tab Button Type
|
||||||
// ---------------------------------------------------------------------
|
// ---------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -224,7 +229,7 @@ public class ValuePanel
|
||||||
List<ItemTemplateRecord.ActionRecords> activeActions = new ArrayList<>(template.actions());
|
List<ItemTemplateRecord.ActionRecords> activeActions = new ArrayList<>(template.actions());
|
||||||
|
|
||||||
activeActions.removeIf(action ->
|
activeActions.removeIf(action ->
|
||||||
"CLEAR".equalsIgnoreCase(action.actionType()) && this.searchText.isBlank());
|
"CLEAR".equalsIgnoreCase(action.actionType()) && this.searchText.isBlank());
|
||||||
|
|
||||||
// Add Click handler
|
// Add Click handler
|
||||||
builder.clickHandler((panel, user, clickType, i) ->
|
builder.clickHandler((panel, user, clickType, i) ->
|
||||||
|
@ -257,9 +262,9 @@ public class ValuePanel
|
||||||
|
|
||||||
// start conversation
|
// start conversation
|
||||||
ConversationUtils.createStringInput(consumer,
|
ConversationUtils.createStringInput(consumer,
|
||||||
user,
|
user,
|
||||||
user.getTranslation("level.conversations.write-search"),
|
user.getTranslation("level.conversations.write-search"),
|
||||||
user.getTranslation("level.conversations.search-updated"));
|
user.getTranslation("level.conversations.search-updated"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -269,10 +274,10 @@ public class ValuePanel
|
||||||
|
|
||||||
// Collect tooltips.
|
// Collect tooltips.
|
||||||
List<String> tooltips = activeActions.stream().
|
List<String> tooltips = activeActions.stream().
|
||||||
filter(action -> action.tooltip() != null).
|
filter(action -> action.tooltip() != null).
|
||||||
map(action -> this.user.getTranslation(this.world, action.tooltip())).
|
map(action -> this.user.getTranslation(this.world, action.tooltip())).
|
||||||
filter(text -> !text.isBlank()).
|
filter(text -> !text.isBlank()).
|
||||||
collect(Collectors.toCollection(() -> new ArrayList<>(template.actions().size())));
|
collect(Collectors.toCollection(() -> new ArrayList<>(template.actions().size())));
|
||||||
|
|
||||||
// Add tooltips.
|
// Add tooltips.
|
||||||
if (!tooltips.isEmpty())
|
if (!tooltips.isEmpty())
|
||||||
|
@ -336,7 +341,7 @@ public class ValuePanel
|
||||||
if (this.activeFilter.name().startsWith(filterName))
|
if (this.activeFilter.name().startsWith(filterName))
|
||||||
{
|
{
|
||||||
return this.activeFilter.name().endsWith("ASC") && "ASC".equalsIgnoreCase(action.actionType()) ||
|
return this.activeFilter.name().endsWith("ASC") && "ASC".equalsIgnoreCase(action.actionType()) ||
|
||||||
this.activeFilter.name().endsWith("DESC") && "DESC".equalsIgnoreCase(action.actionType());
|
this.activeFilter.name().endsWith("DESC") && "DESC".equalsIgnoreCase(action.actionType());
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -375,10 +380,10 @@ public class ValuePanel
|
||||||
|
|
||||||
// Collect tooltips.
|
// Collect tooltips.
|
||||||
List<String> tooltips = activeActions.stream().
|
List<String> tooltips = activeActions.stream().
|
||||||
filter(action -> action.tooltip() != null).
|
filter(action -> action.tooltip() != null).
|
||||||
map(action -> this.user.getTranslation(this.world, action.tooltip())).
|
map(action -> this.user.getTranslation(this.world, action.tooltip())).
|
||||||
filter(text -> !text.isBlank()).
|
filter(text -> !text.isBlank()).
|
||||||
collect(Collectors.toCollection(() -> new ArrayList<>(template.actions().size())));
|
collect(Collectors.toCollection(() -> new ArrayList<>(template.actions().size())));
|
||||||
|
|
||||||
// Add tooltips.
|
// Add tooltips.
|
||||||
if (!tooltips.isEmpty())
|
if (!tooltips.isEmpty())
|
||||||
|
@ -394,9 +399,9 @@ public class ValuePanel
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// ---------------------------------------------------------------------
|
// ---------------------------------------------------------------------
|
||||||
// Section: Create common buttons
|
// Section: Create common buttons
|
||||||
// ---------------------------------------------------------------------
|
// ---------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -410,8 +415,8 @@ public class ValuePanel
|
||||||
{
|
{
|
||||||
long size = this.elementList.size();
|
long size = this.elementList.size();
|
||||||
|
|
||||||
if (size <= slot.amountMap().getOrDefault("BLOCK", 1) ||
|
if (size <= slot.amountMap().getOrDefault(BLOCK, 1) ||
|
||||||
1.0 * size / slot.amountMap().getOrDefault("BLOCK", 1) <= this.pageIndex + 1)
|
1.0 * size / slot.amountMap().getOrDefault(BLOCK, 1) <= this.pageIndex + 1)
|
||||||
{
|
{
|
||||||
// There are no next elements
|
// There are no next elements
|
||||||
return null;
|
return null;
|
||||||
|
@ -425,7 +430,7 @@ public class ValuePanel
|
||||||
{
|
{
|
||||||
ItemStack clone = template.icon().clone();
|
ItemStack clone = template.icon().clone();
|
||||||
|
|
||||||
if ((Boolean) template.dataMap().getOrDefault("indexing", false))
|
if (Boolean.TRUE.equals(template.dataMap().getOrDefault("indexing", false)))
|
||||||
{
|
{
|
||||||
clone.setAmount(nextPageIndex);
|
clone.setAmount(nextPageIndex);
|
||||||
}
|
}
|
||||||
|
@ -441,7 +446,7 @@ public class ValuePanel
|
||||||
if (template.description() != null)
|
if (template.description() != null)
|
||||||
{
|
{
|
||||||
builder.description(this.user.getTranslation(this.world, template.description(),
|
builder.description(this.user.getTranslation(this.world, template.description(),
|
||||||
"[number]", String.valueOf(nextPageIndex)));
|
TextVariables.NUMBER, String.valueOf(nextPageIndex)));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add ClickHandler
|
// Add ClickHandler
|
||||||
|
@ -449,13 +454,11 @@ public class ValuePanel
|
||||||
{
|
{
|
||||||
for (ItemTemplateRecord.ActionRecords action : template.actions())
|
for (ItemTemplateRecord.ActionRecords action : template.actions())
|
||||||
{
|
{
|
||||||
if (clickType == action.clickType() || ClickType.UNKNOWN.equals(action.clickType()))
|
if ((clickType == action.clickType() || ClickType.UNKNOWN.equals(action.clickType()))
|
||||||
|
&& "NEXT".equalsIgnoreCase(action.actionType()))
|
||||||
{
|
{
|
||||||
if ("NEXT".equalsIgnoreCase(action.actionType()))
|
this.pageIndex++;
|
||||||
{
|
this.build();
|
||||||
this.pageIndex++;
|
|
||||||
this.build();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -465,10 +468,10 @@ public class ValuePanel
|
||||||
|
|
||||||
// Collect tooltips.
|
// Collect tooltips.
|
||||||
List<String> tooltips = template.actions().stream().
|
List<String> tooltips = template.actions().stream().
|
||||||
filter(action -> action.tooltip() != null).
|
filter(action -> action.tooltip() != null).
|
||||||
map(action -> this.user.getTranslation(this.world, action.tooltip())).
|
map(action -> this.user.getTranslation(this.world, action.tooltip())).
|
||||||
filter(text -> !text.isBlank()).
|
filter(text -> !text.isBlank()).
|
||||||
collect(Collectors.toCollection(() -> new ArrayList<>(template.actions().size())));
|
collect(Collectors.toCollection(() -> new ArrayList<>(template.actions().size())));
|
||||||
|
|
||||||
// Add tooltips.
|
// Add tooltips.
|
||||||
if (!tooltips.isEmpty())
|
if (!tooltips.isEmpty())
|
||||||
|
@ -505,7 +508,7 @@ public class ValuePanel
|
||||||
{
|
{
|
||||||
ItemStack clone = template.icon().clone();
|
ItemStack clone = template.icon().clone();
|
||||||
|
|
||||||
if ((Boolean) template.dataMap().getOrDefault("indexing", false))
|
if (Boolean.TRUE.equals(template.dataMap().getOrDefault("indexing", false)))
|
||||||
{
|
{
|
||||||
clone.setAmount(previousPageIndex);
|
clone.setAmount(previousPageIndex);
|
||||||
}
|
}
|
||||||
|
@ -521,7 +524,7 @@ public class ValuePanel
|
||||||
if (template.description() != null)
|
if (template.description() != null)
|
||||||
{
|
{
|
||||||
builder.description(this.user.getTranslation(this.world, template.description(),
|
builder.description(this.user.getTranslation(this.world, template.description(),
|
||||||
"[number]", String.valueOf(previousPageIndex)));
|
TextVariables.NUMBER, String.valueOf(previousPageIndex)));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add ClickHandler
|
// Add ClickHandler
|
||||||
|
@ -529,13 +532,11 @@ public class ValuePanel
|
||||||
{
|
{
|
||||||
for (ItemTemplateRecord.ActionRecords action : template.actions())
|
for (ItemTemplateRecord.ActionRecords action : template.actions())
|
||||||
{
|
{
|
||||||
if (clickType == action.clickType() || ClickType.UNKNOWN.equals(action.clickType()))
|
if ((clickType == action.clickType() || ClickType.UNKNOWN.equals(action.clickType()))
|
||||||
|
&& "PREVIOUS".equalsIgnoreCase(action.actionType()))
|
||||||
{
|
{
|
||||||
if ("PREVIOUS".equalsIgnoreCase(action.actionType()))
|
this.pageIndex--;
|
||||||
{
|
this.build();
|
||||||
this.pageIndex--;
|
|
||||||
this.build();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -545,10 +546,10 @@ public class ValuePanel
|
||||||
|
|
||||||
// Collect tooltips.
|
// Collect tooltips.
|
||||||
List<String> tooltips = template.actions().stream().
|
List<String> tooltips = template.actions().stream().
|
||||||
filter(action -> action.tooltip() != null).
|
filter(action -> action.tooltip() != null).
|
||||||
map(action -> this.user.getTranslation(this.world, action.tooltip())).
|
map(action -> this.user.getTranslation(this.world, action.tooltip())).
|
||||||
filter(text -> !text.isBlank()).
|
filter(text -> !text.isBlank()).
|
||||||
collect(Collectors.toCollection(() -> new ArrayList<>(template.actions().size())));
|
collect(Collectors.toCollection(() -> new ArrayList<>(template.actions().size())));
|
||||||
|
|
||||||
// Add tooltips.
|
// Add tooltips.
|
||||||
if (!tooltips.isEmpty())
|
if (!tooltips.isEmpty())
|
||||||
|
@ -562,9 +563,9 @@ public class ValuePanel
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// ---------------------------------------------------------------------
|
// ---------------------------------------------------------------------
|
||||||
// Section: Create Material Button
|
// Section: Create Material Button
|
||||||
// ---------------------------------------------------------------------
|
// ---------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -582,7 +583,7 @@ public class ValuePanel
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
int index = this.pageIndex * slot.amountMap().getOrDefault("BLOCK", 1) + slot.slot();
|
int index = this.pageIndex * slot.amountMap().getOrDefault(BLOCK, 1) + slot.slot();
|
||||||
|
|
||||||
if (index >= this.elementList.size())
|
if (index >= this.elementList.size())
|
||||||
{
|
{
|
||||||
|
@ -602,7 +603,7 @@ public class ValuePanel
|
||||||
* @return PanelItem for generator tier.
|
* @return PanelItem for generator tier.
|
||||||
*/
|
*/
|
||||||
private PanelItem createMaterialButton(ItemTemplateRecord template,
|
private PanelItem createMaterialButton(ItemTemplateRecord template,
|
||||||
MaterialRecord materialRecord)
|
MaterialRecord materialRecord)
|
||||||
{
|
{
|
||||||
PanelItemBuilder builder = new PanelItemBuilder();
|
PanelItemBuilder builder = new PanelItemBuilder();
|
||||||
|
|
||||||
|
@ -623,24 +624,24 @@ public class ValuePanel
|
||||||
if (template.title() != null)
|
if (template.title() != null)
|
||||||
{
|
{
|
||||||
builder.name(this.user.getTranslation(this.world, template.title(),
|
builder.name(this.user.getTranslation(this.world, template.title(),
|
||||||
"[material]", Utils.prettifyObject(materialRecord.material(), this.user)));
|
"[material]", Utils.prettifyObject(materialRecord.material(), this.user)));
|
||||||
}
|
}
|
||||||
|
|
||||||
String description = Utils.prettifyDescription(materialRecord.material(), this.user);
|
String description = Utils.prettifyDescription(materialRecord.material(), this.user);
|
||||||
|
|
||||||
final String reference = "level.gui.buttons.material.";
|
final String reference = "level.gui.buttons.material.";
|
||||||
String blockId = this.user.getTranslationOrNothing(reference + "id",
|
String blockId = this.user.getTranslationOrNothing(reference + "id",
|
||||||
"[id]", materialRecord.material().name());
|
"[id]", materialRecord.material().name());
|
||||||
|
|
||||||
String value = this.user.getTranslationOrNothing(reference + "value",
|
String value = this.user.getTranslationOrNothing(reference + "value",
|
||||||
"[number]", String.valueOf(materialRecord.value()));
|
TextVariables.NUMBER, String.valueOf(materialRecord.value()));
|
||||||
|
|
||||||
String underWater;
|
String underWater;
|
||||||
|
|
||||||
if (this.addon.getSettings().getUnderWaterMultiplier() > 1.0)
|
if (this.addon.getSettings().getUnderWaterMultiplier() > 1.0)
|
||||||
{
|
{
|
||||||
underWater = this.user.getTranslationOrNothing(reference + "underwater",
|
underWater = this.user.getTranslationOrNothing(reference + "underwater",
|
||||||
"[number]", String.valueOf(materialRecord.value() * this.addon.getSettings().getUnderWaterMultiplier()));
|
TextVariables.NUMBER, String.valueOf(materialRecord.value() * this.addon.getSettings().getUnderWaterMultiplier()));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -648,7 +649,7 @@ public class ValuePanel
|
||||||
}
|
}
|
||||||
|
|
||||||
String limit = materialRecord.limit() > 0 ? this.user.getTranslationOrNothing(reference + "limit",
|
String limit = materialRecord.limit() > 0 ? this.user.getTranslationOrNothing(reference + "limit",
|
||||||
"[number]", String.valueOf(materialRecord.limit())) : "";
|
TextVariables.NUMBER, String.valueOf(materialRecord.limit())) : "";
|
||||||
|
|
||||||
if (template.description() != null)
|
if (template.description() != null)
|
||||||
{
|
{
|
||||||
|
@ -658,13 +659,13 @@ public class ValuePanel
|
||||||
"[value]", value,
|
"[value]", value,
|
||||||
"[underwater]", underWater,
|
"[underwater]", underWater,
|
||||||
"[limit]", limit).
|
"[limit]", limit).
|
||||||
replaceAll("(?m)^[ \\t]*\\r?\\n", "").
|
replaceAll("(?m)^[ \\t]*\\r?\\n", "").
|
||||||
replaceAll("(?<!\\\\)\\|", "\n").
|
replaceAll("(?<!\\\\)\\|", "\n").
|
||||||
replaceAll("\\\\\\|", "|"));
|
replace("\\\\\\|", "|")); // Non regex
|
||||||
}
|
}
|
||||||
|
|
||||||
builder.clickHandler((panel, user1, clickType, i) -> {
|
builder.clickHandler((panel, user1, clickType, i) -> {
|
||||||
System.out.println("Material: " + materialRecord.material());
|
addon.log("Material: " + materialRecord.material());
|
||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -672,9 +673,9 @@ public class ValuePanel
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// ---------------------------------------------------------------------
|
// ---------------------------------------------------------------------
|
||||||
// Section: Other Methods
|
// Section: Other Methods
|
||||||
// ---------------------------------------------------------------------
|
// ---------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -686,16 +687,16 @@ public class ValuePanel
|
||||||
* @param user User who opens panel
|
* @param user User who opens panel
|
||||||
*/
|
*/
|
||||||
public static void openPanel(Level addon,
|
public static void openPanel(Level addon,
|
||||||
World world,
|
World world,
|
||||||
User user)
|
User user)
|
||||||
{
|
{
|
||||||
new ValuePanel(addon, world, user).build();
|
new ValuePanel(addon, world, user).build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// ---------------------------------------------------------------------
|
// ---------------------------------------------------------------------
|
||||||
// Section: Enums
|
// Section: Enums
|
||||||
// ---------------------------------------------------------------------
|
// ---------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -726,10 +727,15 @@ public class ValuePanel
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ---------------------------------------------------------------------
|
||||||
|
// Section: Constants
|
||||||
|
// ---------------------------------------------------------------------
|
||||||
|
|
||||||
// ---------------------------------------------------------------------
|
private static final String BLOCK = "BLOCK";
|
||||||
// Section: Variables
|
|
||||||
// ---------------------------------------------------------------------
|
// ---------------------------------------------------------------------
|
||||||
|
// Section: Variables
|
||||||
|
// ---------------------------------------------------------------------
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This variable allows to access addon object.
|
* This variable allows to access addon object.
|
||||||
|
|
|
@ -7,10 +7,16 @@
|
||||||
package world.bentobox.level.util;
|
package world.bentobox.level.util;
|
||||||
|
|
||||||
|
|
||||||
import org.bukkit.conversations.*;
|
import java.util.function.Consumer;
|
||||||
|
|
||||||
|
import org.bukkit.conversations.ConversationAbandonedListener;
|
||||||
|
import org.bukkit.conversations.ConversationContext;
|
||||||
|
import org.bukkit.conversations.ConversationFactory;
|
||||||
|
import org.bukkit.conversations.MessagePrompt;
|
||||||
|
import org.bukkit.conversations.Prompt;
|
||||||
|
import org.bukkit.conversations.StringPrompt;
|
||||||
import org.eclipse.jdt.annotation.NonNull;
|
import org.eclipse.jdt.annotation.NonNull;
|
||||||
import org.eclipse.jdt.annotation.Nullable;
|
import org.eclipse.jdt.annotation.Nullable;
|
||||||
import java.util.function.Consumer;
|
|
||||||
|
|
||||||
import world.bentobox.bentobox.BentoBox;
|
import world.bentobox.bentobox.BentoBox;
|
||||||
import world.bentobox.bentobox.api.user.User;
|
import world.bentobox.bentobox.api.user.User;
|
||||||
|
@ -18,10 +24,11 @@ import world.bentobox.bentobox.api.user.User;
|
||||||
|
|
||||||
public class ConversationUtils
|
public class ConversationUtils
|
||||||
{
|
{
|
||||||
// ---------------------------------------------------------------------
|
// ---------------------------------------------------------------------
|
||||||
// Section: Conversation API implementation
|
// Section: Conversation API implementation
|
||||||
// ---------------------------------------------------------------------
|
// ---------------------------------------------------------------------
|
||||||
|
|
||||||
|
private ConversationUtils() {} // Private constructor as this is a utility class only with static methods
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This method will close opened gui and writes question in chat. After players answers on question in chat, message
|
* This method will close opened gui and writes question in chat. After players answers on question in chat, message
|
||||||
|
@ -32,9 +39,9 @@ public class ConversationUtils
|
||||||
* @param user User who is targeted with current confirmation.
|
* @param user User who is targeted with current confirmation.
|
||||||
*/
|
*/
|
||||||
public static void createStringInput(Consumer<String> consumer,
|
public static void createStringInput(Consumer<String> consumer,
|
||||||
User user,
|
User user,
|
||||||
@NonNull String question,
|
@NonNull String question,
|
||||||
@Nullable String successMessage)
|
@Nullable String successMessage)
|
||||||
{
|
{
|
||||||
// Text input message.
|
// Text input message.
|
||||||
StringPrompt stringPrompt = new StringPrompt()
|
StringPrompt stringPrompt = new StringPrompt()
|
||||||
|
@ -56,16 +63,16 @@ public class ConversationUtils
|
||||||
};
|
};
|
||||||
|
|
||||||
new ConversationFactory(BentoBox.getInstance()).
|
new ConversationFactory(BentoBox.getInstance()).
|
||||||
withPrefix(context -> user.getTranslation("level.conversations.prefix")).
|
withPrefix(context -> user.getTranslation("level.conversations.prefix")).
|
||||||
withFirstPrompt(stringPrompt).
|
withFirstPrompt(stringPrompt).
|
||||||
// On cancel conversation will be closed.
|
// On cancel conversation will be closed.
|
||||||
withLocalEcho(false).
|
withLocalEcho(false).
|
||||||
withTimeout(90).
|
withTimeout(90).
|
||||||
withEscapeSequence(user.getTranslation("level.conversations.cancel-string")).
|
withEscapeSequence(user.getTranslation("level.conversations.cancel-string")).
|
||||||
// Use null value in consumer to detect if user has abandoned conversation.
|
// Use null value in consumer to detect if user has abandoned conversation.
|
||||||
addConversationAbandonedListener(ConversationUtils.getAbandonListener(consumer, user)).
|
addConversationAbandonedListener(ConversationUtils.getAbandonListener(consumer, user)).
|
||||||
buildConversation(user.getPlayer()).
|
buildConversation(user.getPlayer()).
|
||||||
begin();
|
begin();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -111,7 +118,7 @@ public class ConversationUtils
|
||||||
consumer.accept(null);
|
consumer.accept(null);
|
||||||
// send cancell message
|
// send cancell message
|
||||||
abandonedEvent.getContext().getForWhom().sendRawMessage(
|
abandonedEvent.getContext().getForWhom().sendRawMessage(
|
||||||
user.getTranslation("level.conversations.prefix") +
|
user.getTranslation("level.conversations.prefix") +
|
||||||
user.getTranslation("level.conversations.cancelled"));
|
user.getTranslation("level.conversations.cancelled"));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -7,10 +7,10 @@
|
||||||
package world.bentobox.level.util;
|
package world.bentobox.level.util;
|
||||||
|
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.permissions.PermissionAttachmentInfo;
|
import org.bukkit.permissions.PermissionAttachmentInfo;
|
||||||
import java.util.List;
|
|
||||||
import java.util.stream.Collectors;
|
|
||||||
|
|
||||||
import world.bentobox.bentobox.api.user.User;
|
import world.bentobox.bentobox.api.user.User;
|
||||||
import world.bentobox.bentobox.hooks.LangUtilsHook;
|
import world.bentobox.bentobox.hooks.LangUtilsHook;
|
||||||
|
@ -18,6 +18,10 @@ import world.bentobox.bentobox.hooks.LangUtilsHook;
|
||||||
|
|
||||||
public class Utils
|
public class Utils
|
||||||
{
|
{
|
||||||
|
private static final String LEVEL_MATERIALS = "level.materials.";
|
||||||
|
|
||||||
|
private Utils() {} // Private constructor as this is a utility class only with static methods
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This method sends a message to the user with appended "prefix" text before message.
|
* This method sends a message to the user with appended "prefix" text before message.
|
||||||
* @param user User who receives message.
|
* @param user User who receives message.
|
||||||
|
@ -27,7 +31,7 @@ public class Utils
|
||||||
public static void sendMessage(User user, String translationText, String... parameters)
|
public static void sendMessage(User user, String translationText, String... parameters)
|
||||||
{
|
{
|
||||||
user.sendMessage(user.getTranslation( "level.conversations.prefix") +
|
user.sendMessage(user.getTranslation( "level.conversations.prefix") +
|
||||||
user.getTranslation( translationText, parameters));
|
user.getTranslation( translationText, parameters));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -52,9 +56,9 @@ public class Utils
|
||||||
String permPrefix = permissionPrefix + ".";
|
String permPrefix = permissionPrefix + ".";
|
||||||
|
|
||||||
List<String> permissions = user.getEffectivePermissions().stream().
|
List<String> permissions = user.getEffectivePermissions().stream().
|
||||||
map(PermissionAttachmentInfo::getPermission).
|
map(PermissionAttachmentInfo::getPermission).
|
||||||
filter(permission -> permission.startsWith(permPrefix)).
|
filter(permission -> permission.startsWith(permPrefix)).
|
||||||
collect(Collectors.toList());
|
toList();
|
||||||
|
|
||||||
for (String permission : permissions)
|
for (String permission : permissions)
|
||||||
{
|
{
|
||||||
|
@ -154,7 +158,7 @@ public class Utils
|
||||||
// materials:
|
// materials:
|
||||||
// [material]:
|
// [material]:
|
||||||
// name: [name]
|
// name: [name]
|
||||||
String translation = user.getTranslationOrNothing("level.materials." + object.name().toLowerCase() + ".name");
|
String translation = user.getTranslationOrNothing(LEVEL_MATERIALS + object.name().toLowerCase() + ".name");
|
||||||
|
|
||||||
if (!translation.isEmpty())
|
if (!translation.isEmpty())
|
||||||
{
|
{
|
||||||
|
@ -167,7 +171,7 @@ public class Utils
|
||||||
// materials:
|
// materials:
|
||||||
// [material]: [name]
|
// [material]: [name]
|
||||||
|
|
||||||
translation = user.getTranslationOrNothing("level.materials." + object.name().toLowerCase());
|
translation = user.getTranslationOrNothing(LEVEL_MATERIALS + object.name().toLowerCase());
|
||||||
|
|
||||||
if (!translation.isEmpty())
|
if (!translation.isEmpty())
|
||||||
{
|
{
|
||||||
|
@ -211,7 +215,7 @@ public class Utils
|
||||||
// materials:
|
// materials:
|
||||||
// [material]:
|
// [material]:
|
||||||
// description: [text]
|
// description: [text]
|
||||||
String translation = user.getTranslationOrNothing("level.materials." + object.name().toLowerCase() + ".description");
|
String translation = user.getTranslationOrNothing(LEVEL_MATERIALS + object.name().toLowerCase() + ".description");
|
||||||
|
|
||||||
if (!translation.isEmpty())
|
if (!translation.isEmpty())
|
||||||
{
|
{
|
||||||
|
|
|
@ -166,7 +166,7 @@ public class LevelsManagerTest {
|
||||||
// Default to uuid's being island owners
|
// Default to uuid's being island owners
|
||||||
when(im.isOwner(eq(world), any())).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.getOwner(any(), any(UUID.class))).thenAnswer(in -> in.getArgument(1, UUID.class));
|
||||||
when(im.getIsland(eq(world), eq(uuid))).thenReturn(island);
|
when(im.getIsland(world, uuid)).thenReturn(island);
|
||||||
when(im.getIslandById(anyString())).thenReturn(Optional.of(island));
|
when(im.getIslandById(anyString())).thenReturn(Optional.of(island));
|
||||||
|
|
||||||
// Player
|
// Player
|
||||||
|
@ -392,8 +392,8 @@ public class LevelsManagerTest {
|
||||||
Bukkit.getScheduler();
|
Bukkit.getScheduler();
|
||||||
verify(scheduler).runTaskAsynchronously(eq(plugin), task.capture());
|
verify(scheduler).runTaskAsynchronously(eq(plugin), task.capture());
|
||||||
task.getValue().run();
|
task.getValue().run();
|
||||||
verify(addon).log(eq("Generating rankings"));
|
verify(addon).log("Generating rankings");
|
||||||
verify(addon).log(eq("Generated rankings for bskyblock-world"));
|
verify(addon).log("Generated rankings for bskyblock-world");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -164,7 +164,7 @@ public class AdminTopRemoveCommandTest {
|
||||||
@Test
|
@Test
|
||||||
public void testCanExecuteWrongArgs() {
|
public void testCanExecuteWrongArgs() {
|
||||||
assertFalse(atrc.canExecute(user, "delete", Collections.emptyList()));
|
assertFalse(atrc.canExecute(user, "delete", Collections.emptyList()));
|
||||||
verify(user).sendMessage(eq("commands.help.header"), eq(TextVariables.LABEL), eq("BSkyBlock"));
|
verify(user).sendMessage("commands.help.header", TextVariables.LABEL, "BSkyBlock");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -174,7 +174,7 @@ public class AdminTopRemoveCommandTest {
|
||||||
public void testCanExecuteUnknown() {
|
public void testCanExecuteUnknown() {
|
||||||
when(pm.getUser(anyString())).thenReturn(null);
|
when(pm.getUser(anyString())).thenReturn(null);
|
||||||
assertFalse(atrc.canExecute(user, "delete", Collections.singletonList("tastybento")));
|
assertFalse(atrc.canExecute(user, "delete", Collections.singletonList("tastybento")));
|
||||||
verify(user).sendMessage(eq("general.errors.unknown-player"), eq(TextVariables.NAME), eq("tastybento"));
|
verify(user).sendMessage("general.errors.unknown-player", TextVariables.NAME, "tastybento");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -193,7 +193,7 @@ public class AdminTopRemoveCommandTest {
|
||||||
testCanExecuteKnown();
|
testCanExecuteKnown();
|
||||||
assertTrue(atrc.execute(user, "delete", Collections.singletonList("tastybento")));
|
assertTrue(atrc.execute(user, "delete", Collections.singletonList("tastybento")));
|
||||||
verify(manager).removeEntry(any(World.class), eq(uuid));
|
verify(manager).removeEntry(any(World.class), eq(uuid));
|
||||||
verify(user).sendMessage(eq("general.success"));
|
verify(user).sendMessage("general.success");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue