Merge branch 'develop'

This commit is contained in:
tastybento 2020-02-01 19:50:57 -08:00
commit dad302a5fe
16 changed files with 653 additions and 91 deletions

19
pom.xml
View File

@ -59,13 +59,13 @@
<powermock.version>2.0.2</powermock.version> <powermock.version>2.0.2</powermock.version>
<!-- More visible way how to change dependency versions --> <!-- More visible way how to change dependency versions -->
<spigot.version>1.14.4-R0.1-SNAPSHOT</spigot.version> <spigot.version>1.14.4-R0.1-SNAPSHOT</spigot.version>
<bentobox.version>1.9.0-SNAPSHOT</bentobox.version> <bentobox.version>1.9.0</bentobox.version>
<!-- Revision variable removes warning about dynamic version --> <!-- Revision variable removes warning about dynamic version -->
<revision>${build.version}-SNAPSHOT</revision> <revision>${build.version}-SNAPSHOT</revision>
<!-- Do not change unless you want different name for local builds. --> <!-- Do not change unless you want different name for local builds. -->
<build.number>-LOCAL</build.number> <build.number>-LOCAL</build.number>
<!-- This allows to change between versions. --> <!-- This allows to change between versions. -->
<build.version>1.9.0</build.version> <build.version>1.9.3</build.version>
</properties> </properties>
<!-- Profiles will allow to automatically change build version. --> <!-- Profiles will allow to automatically change build version. -->
@ -147,6 +147,11 @@
<id>codemc-public</id> <id>codemc-public</id>
<url>https://repo.codemc.org/repository/maven-public/</url> <url>https://repo.codemc.org/repository/maven-public/</url>
</repository> </repository>
<!--Wild Stacker repo-->
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
</repositories> </repositories>
<dependencies> <dependencies>
@ -182,6 +187,12 @@
<version>${bentobox.version}</version> <version>${bentobox.version}</version>
<scope>provided</scope> <scope>provided</scope>
</dependency> </dependency>
<!-- Wild Stacker dependency-->
<dependency>
<groupId>com.github.OmerBenGera</groupId>
<artifactId>WildStackerAPI</artifactId>
<version>b17</version>
</dependency>
</dependencies> </dependencies>
<build> <build>
@ -242,9 +253,11 @@
<artifactId>maven-javadoc-plugin</artifactId> <artifactId>maven-javadoc-plugin</artifactId>
<version>3.0.1</version> <version>3.0.1</version>
<configuration> <configuration>
<show>public</show> <show>private</show>
<failOnError>false</failOnError> <failOnError>false</failOnError>
<additionalJOption>-Xdoclint:none</additionalJOption> <additionalJOption>-Xdoclint:none</additionalJOption>
<javadocExecutable>${java.home}/bin/javadoc</javadocExecutable>
<source>8</source>
</configuration> </configuration>
<executions> <executions>
<execution> <execution>

View File

@ -6,12 +6,14 @@ import java.util.Map;
import java.util.UUID; import java.util.UUID;
import org.bukkit.World; import org.bukkit.World;
import org.eclipse.jdt.annotation.NonNull;
import org.eclipse.jdt.annotation.Nullable; import org.eclipse.jdt.annotation.Nullable;
import world.bentobox.bentobox.api.addons.Addon; import world.bentobox.bentobox.api.addons.Addon;
import world.bentobox.bentobox.api.user.User; import world.bentobox.bentobox.api.user.User;
import world.bentobox.bentobox.database.Database; import world.bentobox.bentobox.database.Database;
import world.bentobox.bentobox.database.objects.Island; import world.bentobox.bentobox.database.objects.Island;
import world.bentobox.level.calculators.CalcIslandLevel;
import world.bentobox.level.commands.admin.AdminLevelCommand; import world.bentobox.level.commands.admin.AdminLevelCommand;
import world.bentobox.level.commands.admin.AdminTopCommand; import world.bentobox.level.commands.admin.AdminTopCommand;
import world.bentobox.level.commands.island.IslandLevelCommand; import world.bentobox.level.commands.island.IslandLevelCommand;
@ -55,16 +57,17 @@ public class Level extends Addon {
* @param user - the user who is asking, or null if none * @param user - the user who is asking, or null if none
* @param playerUUID - the target island member's UUID * @param playerUUID - the target island member's UUID
*/ */
public void calculateIslandLevel(World world, @Nullable User user, UUID playerUUID) { public void calculateIslandLevel(World world, @Nullable User user, @NonNull UUID playerUUID) {
levelPresenter.calculateIslandLevel(world, user, playerUUID); levelPresenter.calculateIslandLevel(world, user, playerUUID);
} }
/** /**
* Get level from cache for a player * Get level from cache for a player.
* @param targetPlayer - target player * @param targetPlayer - target player UUID
* @return Level of player * @return Level of player or zero if player is unknown or UUID is null
*/ */
public long getIslandLevel(World world, UUID targetPlayer) { public long getIslandLevel(World world, @Nullable UUID targetPlayer) {
if (targetPlayer == null) return 0L;
LevelsData ld = getLevelsData(targetPlayer); LevelsData ld = getLevelsData(targetPlayer);
return ld == null ? 0L : ld.getLevel(world); return ld == null ? 0L : ld.getLevel(world);
} }
@ -74,7 +77,7 @@ public class Level extends Addon {
* @param targetPlayer - UUID of target player * @param targetPlayer - UUID of target player
* @return LevelsData object or null if not found * @return LevelsData object or null if not found
*/ */
public LevelsData getLevelsData(UUID targetPlayer) { public LevelsData getLevelsData(@NonNull UUID targetPlayer) {
// Get from database if not in cache // Get from database if not in cache
if (!levelsCache.containsKey(targetPlayer) && handler.objectExists(targetPlayer.toString())) { if (!levelsCache.containsKey(targetPlayer) && handler.objectExists(targetPlayer.toString())) {
levelsCache.put(targetPlayer, handler.loadObject(targetPlayer.toString())); levelsCache.put(targetPlayer, handler.loadObject(targetPlayer.toString()));
@ -163,9 +166,9 @@ public class Level extends Addon {
getPlugin().getPlaceholdersManager().registerPlaceholder(this, getPlugin().getPlaceholdersManager().registerPlaceholder(this,
gm.getDescription().getName().toLowerCase() + "_visited_island_level", gm.getDescription().getName().toLowerCase() + "_visited_island_level",
user -> getPlugin().getIslands().getIslandAt(user.getLocation()) user -> getPlugin().getIslands().getIslandAt(user.getLocation())
.map(island -> getIslandLevel(gm.getOverWorld(), island.getOwner())) .map(island -> getIslandLevel(gm.getOverWorld(), island.getOwner()))
.map(level -> getLevelPresenter().getLevelString(level)) .map(level -> getLevelPresenter().getLevelString(level))
.orElse("0")); .orElse("0"));
// Top Ten // Top Ten
for (int i = 1; i <= 10; i++) { for (int i = 1; i <= 10; i++) {
@ -175,7 +178,7 @@ public class Level extends Addon {
gm.getDescription().getName().toLowerCase() + "_top_value_" + rank, gm.getDescription().getName().toLowerCase() + "_top_value_" + rank,
user -> { user -> {
Collection<Long> values = getTopTen().getTopTenList(gm.getOverWorld()).getTopTen().values(); Collection<Long> values = getTopTen().getTopTenList(gm.getOverWorld()).getTopTen().values();
return values.size() < rank ? "" : values.stream().skip(rank).findFirst().map(String::valueOf).orElse(""); return values.size() < rank ? "" : values.stream().skip(rank - 1).findFirst().map(String::valueOf).orElse("");
}); });
// Name // Name
@ -183,7 +186,7 @@ public class Level extends Addon {
gm.getDescription().getName().toLowerCase() + "_top_name_" + rank, gm.getDescription().getName().toLowerCase() + "_top_name_" + rank,
user -> { user -> {
Collection<UUID> values = getTopTen().getTopTenList(gm.getOverWorld()).getTopTen().keySet(); Collection<UUID> values = getTopTen().getTopTenList(gm.getOverWorld()).getTopTen().keySet();
return values.size() < rank ? "" : getPlayers().getName(values.stream().skip(rank).findFirst().orElse(null)); return values.size() < rank ? "" : getPlayers().getName(values.stream().skip(rank - 1).findFirst().orElse(null));
}); });
} }
} }
@ -197,6 +200,13 @@ public class Level extends Addon {
registerRequestHandler(new LevelRequestHandler(this)); registerRequestHandler(new LevelRequestHandler(this));
registerRequestHandler(new TopTenRequestHandler(this)); registerRequestHandler(new TopTenRequestHandler(this));
// Check if WildStackers is enabled on the server
if (getPlugin().getServer().getPluginManager().getPlugin("WildStacker") != null) {
// I only added support for counting blocks into the island level
// Someone else can PR if they want spawners added to the Leveling system :)
CalcIslandLevel.stackersEnabled = true;
} else CalcIslandLevel.stackersEnabled = false;
// Done // Done
} }
@ -236,7 +246,7 @@ public class Level extends Addon {
* @param island - island * @param island - island
* @param level - initial calculated island level * @param level - initial calculated island level
*/ */
public void setInitialIslandLevel(Island island, long level) { public void setInitialIslandLevel(@NonNull Island island, long level) {
if (island.getWorld() == null || island.getOwner() == null) { if (island.getWorld() == null || island.getOwner() == null) {
this.logError("Level: request to store a null (initial) " + island.getWorld() + " " + island.getOwner()); this.logError("Level: request to store a null (initial) " + island.getWorld() + " " + island.getOwner());
return; return;
@ -250,15 +260,19 @@ public class Level extends Addon {
* @param island - island * @param island - island
* @return level or 0 by default * @return level or 0 by default
*/ */
public long getInitialIslandLevel(Island island) { public long getInitialIslandLevel(@NonNull Island island) {
return levelsCache.containsKey(island.getOwner()) ? levelsCache.get(island.getOwner()).getInitialLevel(island.getWorld()) : 0L; return levelsCache.containsKey(island.getOwner()) ? levelsCache.get(island.getOwner()).getInitialLevel(island.getWorld()) : 0L;
} }
/**
* @return database handler
*/
@Nullable
public Database<LevelsData> getHandler() { public Database<LevelsData> getHandler() {
return handler; return handler;
} }
public void uncachePlayer(UUID uniqueId) { public void uncachePlayer(@Nullable UUID uniqueId) {
if (levelsCache.containsKey(uniqueId) && levelsCache.get(uniqueId) != null) { if (levelsCache.containsKey(uniqueId) && levelsCache.get(uniqueId) != null) {
handler.saveObject(levelsCache.get(uniqueId)); handler.saveObject(levelsCache.get(uniqueId));
} }

View File

@ -82,7 +82,7 @@ public class LevelPresenter {
} }
/** /**
* Get the string representation of the level. May be converted to shorthand notation, e.g., 104556 -> 10.5k * Get the string representation of the level. May be converted to shorthand notation, e.g., 104556 = 10.5k
* @param lvl - long value to represent * @param lvl - long value to represent
* @return string of the level. * @return string of the level.
*/ */

View File

@ -1,15 +1,27 @@
package world.bentobox.level.calculators; package world.bentobox.level.calculators;
import java.util.*; import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Queue;
import java.util.Set;
import java.util.UUID;
import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicLong; import java.util.concurrent.atomic.AtomicLong;
import com.bgsoftware.wildstacker.api.WildStackerAPI;
import com.bgsoftware.wildstacker.api.objects.StackedBarrel;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.Chunk; import org.bukkit.Chunk;
import org.bukkit.ChunkSnapshot; import org.bukkit.ChunkSnapshot;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.Tag; import org.bukkit.Tag;
import org.bukkit.World; import org.bukkit.World;
import org.bukkit.block.Block;
import org.bukkit.block.data.BlockData; import org.bukkit.block.data.BlockData;
import org.bukkit.block.data.type.Slab; import org.bukkit.block.data.type.Slab;
@ -28,7 +40,8 @@ public class CalcIslandLevel {
private static final String LINE_BREAK = "=================================="; private static final String LINE_BREAK = "==================================";
public static final long MAX_AMOUNT = 10000; public static final long MAX_AMOUNT = 10000;
public static Boolean stackersEnabled;
private final Level addon; private final Level addon;
@ -92,17 +105,15 @@ public class CalcIslandLevel {
total += chunksToScan.size(); total += chunksToScan.size();
} }
} }
queueid = Bukkit.getScheduler().scheduleSyncRepeatingTask(addon.getPlugin(), new Runnable() { queueid = Bukkit.getScheduler().scheduleSyncRepeatingTask(addon.getPlugin(), () -> {
public void run() { for (int i = 0; i < addon.getSettings().getChunks(); i++) {
for (int i = 0; i < 10; i++) { if (q.size() == 0) {
if (q.size() == 0) { return;
return;
}
Chunk c = q.remove();
getChunk(c);
} }
Chunk c = q.remove();
getChunk(c);
} }
}, 1L, 1L); }, addon.getSettings().getTickDelay(), addon.getSettings().getTickDelay());
chunksToScan.forEach(c -> worlds.forEach(w -> Util.getChunkAtAsync(w, c.x, c.z).thenAccept(this::addChunkQueue))); chunksToScan.forEach(c -> worlds.forEach(w -> Util.getChunkAtAsync(w, c.x, c.z).thenAccept(this::addChunkQueue)));
} }
@ -115,7 +126,7 @@ public class CalcIslandLevel {
ChunkSnapshot snapShot = ch.getChunkSnapshot(); ChunkSnapshot snapShot = ch.getChunkSnapshot();
Bukkit.getScheduler().runTaskAsynchronously(addon.getPlugin(), () -> { Bukkit.getScheduler().runTaskAsynchronously(addon.getPlugin(), () -> {
this.scanChunk(snapShot); this.scanChunk(snapShot, ch);
count.getAndIncrement(); count.getAndIncrement();
if (count.get() == total) { if (count.get() == total) {
Bukkit.getScheduler().cancelTask(queueid); Bukkit.getScheduler().cancelTask(queueid);
@ -124,7 +135,7 @@ public class CalcIslandLevel {
}); });
} }
private void scanChunk(ChunkSnapshot chunk) { private void scanChunk(ChunkSnapshot chunk, Chunk physicalChunk) {
World chunkWorld = Bukkit.getWorld(chunk.getWorldName()); World chunkWorld = Bukkit.getWorld(chunk.getWorldName());
if (chunkWorld == null) return; if (chunkWorld == null) return;
int maxHeight = chunkWorld.getMaxHeight(); int maxHeight = chunkWorld.getMaxHeight();
@ -148,23 +159,37 @@ public class CalcIslandLevel {
if (Tag.SLABS.isTagged(blockData.getMaterial())) { if (Tag.SLABS.isTagged(blockData.getMaterial())) {
Slab slab = (Slab)blockData; Slab slab = (Slab)blockData;
if (slab.getType().equals(Slab.Type.DOUBLE)) { if (slab.getType().equals(Slab.Type.DOUBLE)) {
checkBlock(blockData, belowSeaLevel); checkBlock(blockData.getMaterial(), belowSeaLevel);
} }
} }
checkBlock(blockData, belowSeaLevel);
// Hook for Wild Stackers (Blocks Only)
if (stackersEnabled && blockData.getMaterial() == Material.CAULDRON) {
Block cauldronBlock = physicalChunk.getBlock(x, y, z);
if (WildStackerAPI.getWildStacker().getSystemManager().isStackedBarrel(cauldronBlock)) {
StackedBarrel barrel = WildStackerAPI.getStackedBarrel(cauldronBlock);
int barrelAmt = WildStackerAPI.getBarrelAmount(cauldronBlock);
for (int _x = 0; _x < barrelAmt; _x++) {
checkBlock(barrel.getType(), belowSeaLevel);
}
}
}
checkBlock(blockData.getMaterial(), belowSeaLevel);
} }
} }
} }
} }
private void checkBlock(BlockData bd, boolean belowSeaLevel) { // Didnt see a reason to pass BlockData when all that's used was the material
int count = limitCount(bd.getMaterial()); private void checkBlock(Material mat, boolean belowSeaLevel) {
int count = limitCount(mat);
if (belowSeaLevel) { if (belowSeaLevel) {
result.underWaterBlockCount.addAndGet(count); result.underWaterBlockCount.addAndGet(count);
result.uwCount.add(bd.getMaterial()); result.uwCount.add(mat);
} else { } else {
result.rawBlockCount.addAndGet(count); result.rawBlockCount.addAndGet(count);
result.mdCount.add(bd.getMaterial()); result.mdCount.add(mat);
} }
} }
@ -383,7 +408,7 @@ public class CalcIslandLevel {
* Set level * Set level
* @param level - level * @param level - level
*/ */
public void setLevel(int level) { public void setLevel(long level) {
this.level.set(level); this.level.set(level);
} }
/** /**

View File

@ -66,7 +66,7 @@ public class PlayerLevel {
keyValues.put("pointsToNextLevel", calc.getResult().getPointsToNextLevel()); keyValues.put("pointsToNextLevel", calc.getResult().getPointsToNextLevel());
keyValues.put("deathHandicap", calc.getResult().getDeathHandicap()); keyValues.put("deathHandicap", calc.getResult().getDeathHandicap());
keyValues.put("initialLevel", calc.getResult().getInitialLevel()); keyValues.put("initialLevel", calc.getResult().getInitialLevel());
addon.getServer().getPluginManager().callEvent(new AddonEvent().builder().addon(addon).keyValues(keyValues).build()); new AddonEvent().builder().addon(addon).keyValues(keyValues).build();
Results results = ilce.getResults(); Results results = ilce.getResults();
// Save the results // Save the results
island.getMemberSet().forEach(m -> addon.setIslandLevel(world, m, results.getLevel())); island.getMemberSet().forEach(m -> addon.setIslandLevel(world, m, results.getLevel()));

View File

@ -23,6 +23,8 @@ public class Settings {
private int deathpenalty; private int deathpenalty;
private long levelCost; private long levelCost;
private int levelWait; private int levelWait;
private int chunks;
private long taskDelay;
private List<String> gameModes; private List<String> gameModes;
@ -33,9 +35,22 @@ public class Settings {
// GameModes // GameModes
gameModes = level.getConfig().getStringList("game-modes"); gameModes = level.getConfig().getStringList("game-modes");
// Performance
setTickDelay(level.getConfig().getLong("task-delay",1));
if (taskDelay < 1L) {
level.logError("task-delay must be at least 1");
setTickDelay(1L);
}
setChunks(level.getConfig().getInt("chunks", 10));
if (chunks < 1) {
level.logError("chunks must be at least 1");
setChunks(1);
}
setLevelWait(level.getConfig().getInt("levelwait", 60)); setLevelWait(level.getConfig().getInt("levelwait", 60));
if (getLevelWait() < 0) { if (getLevelWait() < 0) {
level.logError("levelwait must be at least 0");
setLevelWait(0); setLevelWait(0);
} }
setDeathpenalty(level.getConfig().getInt("deathpenalty", 0)); setDeathpenalty(level.getConfig().getInt("deathpenalty", 0));
@ -215,7 +230,7 @@ public class Settings {
} }
/** /**
* @return true if levels should be shown in shorthand notation, e.g., 10,234 -> 10k * @return true if levels should be shown in shorthand notation, e.g., 10,234 = 10k
*/ */
public boolean isShortHand() { public boolean isShortHand() {
return level.getConfig().getBoolean("shorthand"); return level.getConfig().getBoolean("shorthand");
@ -228,4 +243,32 @@ public class Settings {
return level.getConfig().getString("level-calc", "blocks / level_cost"); return level.getConfig().getString("level-calc", "blocks / level_cost");
} }
/**
* @return the chunks
*/
public int getChunks() {
return chunks;
}
/**
* @param chunks the chunks to set
*/
public void setChunks(int chunks) {
this.chunks = chunks;
}
/**
* @return the tickDelay
*/
public long getTickDelay() {
return taskDelay;
}
/**
* @param tickDelay the tickDelay to set
*/
public void setTickDelay(long tickDelay) {
this.taskDelay = tickDelay;
}
} }

View File

@ -1,5 +1,6 @@
package world.bentobox.level.event; package world.bentobox.level.event;
import java.util.List;
import java.util.UUID; import java.util.UUID;
import world.bentobox.bentobox.api.events.IslandBaseEvent; import world.bentobox.bentobox.api.events.IslandBaseEvent;
@ -29,11 +30,58 @@ public class IslandLevelCalculatedEvent extends IslandBaseEvent {
} }
/** /**
* Do NOT get this result if you are not a BentoBox addon!
* @return the results * @return the results
*/ */
public Results getResults() { public Results getResults() {
return results; return results;
} }
/**
* @return death handicap value
*/
public int getDeathHandicap() {
return results.getDeathHandicap();
}
/**
* Get the island's initial level. It may be zero if it was never calculated
* or if a player was registered to the island after it was made.
* @return initial level of island as calculated when the island was created.
*/
public long getInitialLevel() {
return results.getInitialLevel();
}
/**
* @return the level calculated
*/
public long getLevel() {
return results.getLevel();
}
/**
* Overwrite the level. This level will be used instead of the calculated level.
* @param level - the level to set
*/
public void setLevel(long level) {
results.setLevel(level);
}
/**
* @return number of points required to next level
*/
public long getPointsToNextLevel() {
return results.getPointsToNextLevel();
}
/**
* @return a human readable report explaining how the calculation was made
*/
public List<String> getReport() {
return results.getReport();
}
/** /**
* @return the targetPlayer * @return the targetPlayer
@ -42,6 +90,7 @@ public class IslandLevelCalculatedEvent extends IslandBaseEvent {
return targetPlayer; return targetPlayer;
} }
/** /**
* Do not use this if you are not a BentoBox addon
* @param results the results to set * @param results the results to set
*/ */
public void setResults(Results results) { public void setResults(Results results) {
@ -55,5 +104,4 @@ public class IslandLevelCalculatedEvent extends IslandBaseEvent {
this.targetPlayer = targetPlayer; this.targetPlayer = targetPlayer;
} }
} }

View File

@ -31,9 +31,6 @@ public class LevelPlaceholder implements PlaceholderReplacer {
*/ */
@Override @Override
public String onReplace(User user) { public String onReplace(User user) {
addon.logWarning("You are using a deprecated placeholder.");
addon.log("Please replace any occurrence of 'Level_" + gm.getDescription().getName().toLowerCase() + "-island-level'");
addon.log("by 'Level_" + gm.getDescription().getName().toLowerCase() + "_island_level'");
return addon.getLevelPresenter().getLevelString(addon.getIslandLevel(gm.getOverWorld(), user.getUniqueId())); return addon.getLevelPresenter().getLevelString(addon.getIslandLevel(gm.getOverWorld(), user.getUniqueId()));
} }

View File

@ -30,9 +30,6 @@ public class TopTenNamePlaceholder implements PlaceholderReplacer {
*/ */
@Override @Override
public String onReplace(User user) { public String onReplace(User user) {
level.logWarning("You are using a deprecated placeholder.");
level.log("Please replace any occurrence of 'Level_" + gm.getDescription().getName().toLowerCase() + "-island-level-top-name-#'");
level.log("by 'Level_" + gm.getDescription().getName().toLowerCase() + "_top_name_#'");
Collection<UUID> values = level.getTopTen().getTopTenList(gm.getOverWorld()).getTopTen().keySet(); Collection<UUID> values = level.getTopTen().getTopTenList(gm.getOverWorld()).getTopTen().keySet();
return values.size() < i ? "" : level.getPlayers().getName(values.stream().skip(i).findFirst().orElse(null)); return values.size() < i ? "" : level.getPlayers().getName(values.stream().skip(i).findFirst().orElse(null));
} }

View File

@ -30,9 +30,6 @@ public class TopTenPlaceholder implements PlaceholderReplacer {
*/ */
@Override @Override
public String onReplace(User user) { public String onReplace(User user) {
level.logWarning("You are using a deprecated placeholder.");
level.log("Please replace any occurrence of 'Level_" + gm.getDescription().getName().toLowerCase() + "-island-level-top-value-#'");
level.log("by 'Level_" + gm.getDescription().getName().toLowerCase() + "_top_value_#'");
Collection<Long> values = level.getTopTen().getTopTenList(gm.getOverWorld()).getTopTen().values(); Collection<Long> values = level.getTopTen().getTopTenList(gm.getOverWorld()).getTopTen().values();
return values.size() < i ? "" : values.stream().skip(i).findFirst().map(String::valueOf).orElse(""); return values.size() < i ? "" : values.stream().skip(i).findFirst().map(String::valueOf).orElse("");
} }

View File

@ -7,7 +7,6 @@ import org.bukkit.Bukkit;
import world.bentobox.bentobox.api.addons.request.AddonRequestHandler; import world.bentobox.bentobox.api.addons.request.AddonRequestHandler;
import world.bentobox.level.Level; import world.bentobox.level.Level;
import world.bentobox.level.objects.TopTenData;
/** /**
@ -54,8 +53,7 @@ public class TopTenRequestHandler extends AddonRequestHandler {
return Collections.emptyMap(); return Collections.emptyMap();
} }
// Null-point check. // No null check required
TopTenData data = addon.getTopTen().getTopTenList(Bukkit.getWorld((String) map.get(WORLD_NAME))); return addon.getTopTen().getTopTenList(Bukkit.getWorld((String) map.get(WORLD_NAME))).getTopTen();
return data != null ? data.getTopTen() : Collections.emptyMap();
} }
} }

View File

@ -9,6 +9,15 @@ game-modes:
- CaveBlock - CaveBlock
#- SkyGrid #- SkyGrid
# Performance settings
# Level is very processor-intensive, so these settings may need to be tweaked to optimize for your server
# Delay between each task that loads chunks for calculating levels
# Increasing this will slow down level calculations but reduce average load
task-delay: 1
# Number of chunks that will be processed per task
chunks: 10
# This file lists the values for various blocks that are used to calculate the # This file lists the values for various blocks that are used to calculate the
# island level. Level = total of all blocks in island boundary / 100. # island level. Level = total of all blocks in island boundary / 100.
# Players with the permission askyblock.island.multiplier.# will have their blocks # Players with the permission askyblock.island.multiplier.# will have their blocks

View File

@ -0,0 +1,42 @@
###########################################################################################
# This is a YML file. Be careful when editing. Check your edits in a YAML checker like #
# the one at http://yaml-online-parser.appspot.com #
# #
# Translation by: CZghost #
###########################################################################################
admin:
level:
parameters: "<player>"
description: "vypočítat úroveň ostrova hráče"
top:
description: "ukázat seznam TOP 10"
unknown-world: "&cNeznámý svět!"
display: "&f[rank]. &a[name] &7- &b[level]"
remove:
description: "odstranit hráče z TOP 10"
parameters: "<player>"
island:
level:
parameters: "[player]"
description: "spočítat úroveň tvého ostrova nebo ostrova hráče [player]"
calculating: "&aPočítám úroveň..."
island-level-is: "&aÚroveň ostrova je &b[level]"
required-points-to-next-level: "&a[points] vyžadováno do další úrovně"
deaths: "&c([number] smrtí)"
cooldown: "&cMusíš čekat &b[time] &csekund, než můžeš příkaz znovu použít"
top:
description: "ukázat TOP 10"
gui-title: "&aTOP 10"
gui-heading: "&6[name]: &B[rank]"
island-level: "&BÚroveň [level]"
warp-to: "&AWarp na ostrov [name]"
value:
description: "ukáže hodnotu jakéhokoliv bloku"
success: "&7Hodnota tohoto bloku je: &e[value]"
success-underwater: "&7Hodnota tohoto bloku pod úrovní moře: &e[value]"
empty-hand: "&cNemáš v ruce žádný blok"
no-value: "&cTento předmět nemá žádnou hodnotu."

View File

@ -1,37 +1,35 @@
########################################################################################### ---
# This is a YML file. Be careful when editing. Check your edits in a YAML checker like #
# the one at http://yaml-online-parser.appspot.com #
###########################################################################################
admin: admin:
level: level:
description: aprēķina spēlētāja salas līmeni
parameters: "<spēlētājs>" parameters: "<spēlētājs>"
description: "aprēķina spēlētāja salas līmeni"
top: top:
description: "rādīt labākās 10 salas" description: rādīt labākās 10 salas
unknown-world: "&cNezināma pasaule!"
display: "&f[rank]. &a[name] &7- &b[level]" display: "&f[rank]. &a[name] &7- &b[level]"
unknown-world: "&cNezināma pasaule!"
remove:
description: noņemt spēlētāju no labāko desmit saraksta
parameters: "<spēlētājs>"
island: island:
level: level:
parameters: "[player]" calculating: "&aAprēķina līmeni..."
description: "aprēķina tavas salas līmeni, vai parāda spēlētāja [player] līmeni" cooldown: "&cTev ir jāuzgaida &b[time]&c sekundes, lai vēlreiz aprēķinātu salas
calculating: "&aAprēķina līmeni..." līmeni!"
island-level-is: "&aSalas līmenis ir &b[level]"
required-points-to-next-level: "&aNepieciešami [points] punkti, lai sasniegtu nākošo līmeni"
deaths: "&c([number] nāves)" deaths: "&c([number] nāves)"
cooldown: "&cTev ir jāuzgaida &b[time]&c sekundes, lai vēlreiz aprēķinātu salas līmeni!" description: aprēķina tavas salas līmeni, vai parāda spēlētāja [player] līmeni
island-level-is: "&aSalas līmenis ir &b[level]"
parameters: "[player]"
required-points-to-next-level: "&aNepieciešami [points] punkti, lai sasniegtu
nākošo līmeni"
top: top:
description: "rādīt labākos 10" description: rādīt labākos 10
gui-title: "&aLabākie 10"
gui-heading: "&6[name]: &B[rank]" gui-heading: "&6[name]: &B[rank]"
gui-title: "&aLabākie 10"
island-level: "&BLīmenis [level]" island-level: "&BLīmenis [level]"
warp-to: "&APārvietoties uz [name] salu." warp-to: "&APārvietoties uz [name] salu."
value: value:
description: "rādīt vērtību jebkuram blokam" description: rādīt vērtību jebkuram blokam
success: "&7Vērtība šim blokam ir: &e[value]"
success-underwater: "&7Vērtība šim blokam zem jūras līmeņa: &e[value]"
empty-hand: "&cTev nav bloks rokās." empty-hand: "&cTev nav bloks rokās."
no-value: "&cŠim blokam/priekšmetam nav vērtības." no-value: "&cŠim blokam/priekšmetam nav vērtības."
success: "&7Vērtība šim blokam ir: &e[value]"
success-underwater: "&7Vērtība šim blokam zem jūras līmeņa: &e[value]"

View File

@ -6,25 +6,35 @@
admin: admin:
level: level:
parameters: "<player>" parameters: "<player>"
description: "计算玩家的岛屿等级" description: "计算玩家的岛屿等级"
top: top:
description: "显示排名前十榜单" description: "显示前十名"
unknown-world: "&c未知世界" unknown-world: "&c未知世界!"
display: "&f[rank]. &a[name] &7- &b[level]"
remove:
description: "将玩家移出前十"
parameters: "<player>"
island: island:
level: level:
parameters: "[player]" parameters: "[player]"
description: "计算您的岛屿等级或显示 [player] 的岛屿等级" description: "计算你或玩家 [player] 的岛屿等级"
calculating: "&a正在计算等级……" calculating: "&a计算等级中..."
island-level-is: "&a岛屿等级 &b[level]" island-level-is: "&a岛屿等级 &b[level]"
required-points-to-next-level: "&a距离下一级还需要 [points] 点" required-points-to-next-level: "&a还需 [points] 才能升到下一级"
deaths: "&c[number] 次死亡)" deaths: "&c([number] 次死亡)"
cooldown: "&c在您可以次做这件事之前必须 &b[time] &c秒" cooldown: "&c再等 &b[time] &c秒才能再次使用"
top: top:
description: "显示排名前十榜单" description: "显示前十名"
gui-title: "&a前十" gui-title: "&a前十"
gui-heading: "&6[name]: &B[rank]" gui-heading: "&6[name]: &B[rank]"
island-level: "&B等级 [level]" island-level: "&B等级 [level]"
warp-to: "&A正在传送到 [name] 的岛屿" warp-to: "&A正传送到 [name] 的岛屿"
value:
description: "查看某方块的价值"
success: "&7本方块的价值: &e[value]"
success-underwater: "&7本方块的水下价值: &e[value]"
empty-hand: "&c你手里没有方块"
no-value: "&c这个东西一文不值."

View File

@ -0,0 +1,371 @@
package world.bentobox.level;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Collections;
import java.util.Comparator;
import java.util.Optional;
import java.util.UUID;
import java.util.jar.JarEntry;
import java.util.jar.JarOutputStream;
import java.util.logging.Logger;
import org.bukkit.Bukkit;
import org.bukkit.Server;
import org.bukkit.UnsafeValues;
import org.bukkit.World;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemFactory;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.plugin.PluginManager;
import org.bukkit.scheduler.BukkitScheduler;
import org.eclipse.jdt.annotation.NonNull;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.stubbing.Answer;
import org.powermock.api.mockito.PowerMockito;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;
import org.powermock.reflect.Whitebox;
import world.bentobox.bentobox.BentoBox;
import world.bentobox.bentobox.Settings;
import world.bentobox.bentobox.api.addons.AddonDescription;
import world.bentobox.bentobox.api.addons.GameModeAddon;
import world.bentobox.bentobox.api.commands.CompositeCommand;
import world.bentobox.bentobox.api.user.User;
import world.bentobox.bentobox.database.DatabaseSetup.DatabaseType;
import world.bentobox.bentobox.database.objects.Island;
import world.bentobox.bentobox.managers.AddonsManager;
import world.bentobox.bentobox.managers.CommandsManager;
import world.bentobox.bentobox.managers.FlagsManager;
import world.bentobox.bentobox.managers.IslandWorldManager;
import world.bentobox.bentobox.managers.IslandsManager;
import world.bentobox.bentobox.managers.PlaceholdersManager;
import world.bentobox.level.listeners.IslandTeamListeners;
import world.bentobox.level.listeners.JoinLeaveListener;
/**
* @author tastybento
*
*/
@SuppressWarnings("deprecation")
@RunWith(PowerMockRunner.class)
@PrepareForTest({Bukkit.class, BentoBox.class, User.class})
public class LevelTest {
private static File jFile;
@Mock
private User user;
@Mock
private IslandsManager im;
@Mock
private Island island;
@Mock
private BentoBox plugin;
@Mock
private FlagsManager fm;
@Mock
private GameModeAddon gameMode;
@Mock
private AddonsManager am;
@Mock
private BukkitScheduler scheduler;
@Mock
private Settings settings;
private Level addon;
@Mock
private Logger logger;
@Mock
private PlaceholdersManager phm;
@Mock
private CompositeCommand cmd;
@Mock
private CompositeCommand adminCmd;
@Mock
private World world;
private UUID uuid;
@BeforeClass
public static void beforeClass() throws IOException {
jFile = new File("addon.jar");
// Copy over config file from src folder
Path fromPath = Paths.get("src/main/resources/config.yml");
Path path = Paths.get("config.yml");
Files.copy(fromPath, path);
try (JarOutputStream tempJarOutputStream = new JarOutputStream(new FileOutputStream(jFile))) {
//Added the new files to the jar.
try (FileInputStream fis = new FileInputStream(path.toFile())) {
byte[] buffer = new byte[1024];
int bytesRead = 0;
JarEntry entry = new JarEntry(path.toString());
tempJarOutputStream.putNextEntry(entry);
while((bytesRead = fis.read(buffer)) != -1) {
tempJarOutputStream.write(buffer, 0, bytesRead);
}
}
}
}
/**
* @throws java.lang.Exception
*/
@SuppressWarnings("deprecation")
@Before
public void setUp() throws Exception {
// Set up plugin
Whitebox.setInternalState(BentoBox.class, "instance", plugin);
when(plugin.getLogger()).thenReturn(Logger.getAnonymousLogger());
//when(plugin.isEnabled()).thenReturn(true);
// Command manager
CommandsManager cm = mock(CommandsManager.class);
when(plugin.getCommandsManager()).thenReturn(cm);
// Player
Player p = mock(Player.class);
// Sometimes use Mockito.withSettings().verboseLogging()
when(user.isOp()).thenReturn(false);
uuid = UUID.randomUUID();
when(user.getUniqueId()).thenReturn(uuid);
when(user.getPlayer()).thenReturn(p);
when(user.getName()).thenReturn("tastybento");
User.setPlugin(plugin);
// Island World Manager
IslandWorldManager iwm = mock(IslandWorldManager.class);
when(plugin.getIWM()).thenReturn(iwm);
// Player has island to begin with
when(im.getIsland(Mockito.any(), Mockito.any(UUID.class))).thenReturn(island);
when(plugin.getIslands()).thenReturn(im);
// Locales
// Return the reference (USE THIS IN THE FUTURE)
when(user.getTranslation(Mockito.anyString())).thenAnswer((Answer<String>) invocation -> invocation.getArgument(0, String.class));
// Server
PowerMockito.mockStatic(Bukkit.class);
Server server = mock(Server.class);
when(Bukkit.getServer()).thenReturn(server);
when(Bukkit.getLogger()).thenReturn(Logger.getAnonymousLogger());
when(Bukkit.getPluginManager()).thenReturn(mock(PluginManager.class));
// Addon
addon = new Level();
File dataFolder = new File("addons/Level");
addon.setDataFolder(dataFolder);
addon.setFile(jFile);
AddonDescription desc = new AddonDescription.Builder("bentobox", "Level", "1.3").description("test").authors("tastybento").build();
addon.setDescription(desc);
// Addons manager
when(plugin.getAddonsManager()).thenReturn(am);
// One game mode
when(am.getGameModeAddons()).thenReturn(Collections.singletonList(gameMode));
AddonDescription desc2 = new AddonDescription.Builder("bentobox", "BSkyBlock", "1.3").description("test").authors("tasty").build();
when(gameMode.getDescription()).thenReturn(desc2);
// Player command
@NonNull
Optional<CompositeCommand> opCmd = Optional.of(cmd);
when(gameMode.getPlayerCommand()).thenReturn(opCmd);
// Admin command
Optional<CompositeCommand> opAdminCmd = Optional.of(adminCmd);
when(gameMode.getAdminCommand()).thenReturn(opAdminCmd);
// Flags manager
when(plugin.getFlagsManager()).thenReturn(fm);
when(fm.getFlags()).thenReturn(Collections.emptyList());
// The database type has to be created one line before the thenReturn() to work!
when(plugin.getSettings()).thenReturn(settings);
DatabaseType value = DatabaseType.JSON;
when(settings.getDatabaseType()).thenReturn(value);
// Bukkit
PowerMockito.mockStatic(Bukkit.class);
when(Bukkit.getScheduler()).thenReturn(scheduler);
ItemMeta meta = mock(ItemMeta.class);
ItemFactory itemFactory = mock(ItemFactory.class);
when(itemFactory.getItemMeta(any())).thenReturn(meta);
when(Bukkit.getItemFactory()).thenReturn(itemFactory);
UnsafeValues unsafe = mock(UnsafeValues.class);
when(unsafe.getDataVersion()).thenReturn(777);
when(Bukkit.getUnsafe()).thenReturn(unsafe);
// placeholders
when(plugin.getPlaceholdersManager()).thenReturn(phm);
// World
when(world.getName()).thenReturn("bskyblock-world");
// Island
when(island.getWorld()).thenReturn(world);
when(island.getOwner()).thenReturn(uuid);
}
/**
* @throws java.lang.Exception
*/
@After
public void tearDown() throws Exception {
deleteAll(new File("database"));
}
@AfterClass
public static void cleanUp() throws Exception {
new File("addon.jar").delete();
new File("config.yml").delete();
deleteAll(new File("addons"));
}
private static void deleteAll(File file) throws IOException {
if (file.exists()) {
Files.walk(file.toPath())
.sorted(Comparator.reverseOrder())
.map(Path::toFile)
.forEach(File::delete);
}
}
/**
* Test method for {@link world.bentobox.level.Level#onEnable()}.
*/
@Test
public void testOnEnable() {
addon.onEnable();
verify(plugin).logWarning("[Level] Level Addon: No such world in config.yml : acidisland_world");
verify(plugin).log("[Level] Level hooking into BSkyBlock");
verify(cmd, times(3)).getAddon(); // Three commands
verify(adminCmd, times(2)).getAddon(); // Two commands
// Placeholders
verify(phm).registerPlaceholder(eq(addon), eq("bskyblock-island-level"), any());
for (int i = 1; i < 11; i++) {
verify(phm).registerPlaceholder(eq(addon), eq("bskyblock-island-level-top-name-" + i), any());
verify(phm).registerPlaceholder(eq(addon), eq("bskyblock-island-level-top-value-" + i), any());
}
verify(phm).registerPlaceholder(eq(addon), eq("bskyblock_island_level"), any());
verify(phm).registerPlaceholder(eq(addon), eq("bskyblock_visited_island_level"), any());
for (int i = 1; i < 11; i++) {
verify(phm).registerPlaceholder(eq(addon), eq("bskyblock_top_name_" + i), any());
verify(phm).registerPlaceholder(eq(addon), eq("bskyblock_top_value_" + i), any());
}
// Commands
verify(am).registerListener(eq(addon), any(IslandTeamListeners.class));
verify(am).registerListener(eq(addon), any(JoinLeaveListener.class));
}
/**
* Test method for {@link world.bentobox.level.Level#getIslandLevel(org.bukkit.World, java.util.UUID)}.
*/
@Test
public void testGetIslandLevelUnknown() {
addon.onEnable();
assertEquals(0L, addon.getIslandLevel(world, UUID.randomUUID()));
}
/**
* Test method for {@link world.bentobox.level.Level#getIslandLevel(org.bukkit.World, java.util.UUID)}.
*/
@Test
public void testGetIslandLevelNullTarget() {
addon.onEnable();
assertEquals(0L, addon.getIslandLevel(world, UUID.randomUUID()));
}
/**
* Test method for {@link world.bentobox.level.Level#getLevelsData(java.util.UUID)}.
*/
@Test
public void testGetLevelsDataUnknown() {
addon.onEnable();
assertNull(addon.getLevelsData(UUID.randomUUID()));
}
/**
* Test method for {@link world.bentobox.level.Level#getSettings()}.
*/
@Test
public void testGetSettings() {
addon.onEnable();
world.bentobox.level.config.Settings s = addon.getSettings();
assertEquals(100, s.getDeathPenalty());
}
/**
* Test method for {@link world.bentobox.level.Level#getTopTen()}.
*/
@Test
public void testGetTopTen() {
addon.onEnable();
assertNotNull(addon.getTopTen());
}
/**
* Test method for {@link world.bentobox.level.Level#getLevelPresenter()}.
*/
@Test
public void testGetLevelPresenter() {
addon.onEnable();
assertNotNull(addon.getLevelPresenter());
}
/**
* Test method for {@link world.bentobox.level.Level#setIslandLevel(org.bukkit.World, java.util.UUID, long)}.
*/
@Test
public void testSetIslandLevel() {
addon.onEnable();
addon.setIslandLevel(world, uuid, 345L);
assertEquals(345L, addon.getIslandLevel(world, uuid));
verify(plugin, never()).logError(anyString());
}
/**
* Test method for {@link world.bentobox.level.Level#getInitialIslandLevel(world.bentobox.bentobox.database.objects.Island)}.
*/
@Test
public void testGetInitialIslandLevel() {
addon.onEnable();
addon.setInitialIslandLevel(island, 40);
verify(plugin, never()).logError(anyString());
assertEquals(40, addon.getInitialIslandLevel(island));
}
/**
* Test method for {@link world.bentobox.level.Level#getHandler()}.
*/
@Test
public void testGetHandler() {
addon.onEnable();
assertNotNull(addon.getHandler());
}
}