Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
tastybento committed Aug 16, 2019
2 parents 8e83785 + 0bd5bd4 commit cc93175
Show file tree
Hide file tree
Showing 25 changed files with 978 additions and 199 deletions.
142 changes: 105 additions & 37 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,24 @@

<groupId>world.bentobox</groupId>
<artifactId>level</artifactId>
<version>1.5.0</version>
<version>${revision}</version>

<name>Level</name>
<description>Level is an add-on for BentoBox, an expandable Minecraft Bukkit plugin for island-type games like SkyBlock or AcidIsland.</description>
<url>https://github.com/BentoBoxWorld/Level</url>
<inceptionYear>2017</inceptionYear>

<developers>
<developer>
<id>tastybento</id>
<email>[email protected]</email>
<timezone>-8</timezone>
<roles>
<role>Lead Developer</role>
</roles>
</developer>
</developers>

<scm>
<connection>scm:git:https://github.com/BentoBoxWorld/Level.git</connection>
<developerConnection>scm:git:[email protected]:BentoBoxWorld/Level.git</developerConnection>
Expand Down Expand Up @@ -41,12 +52,59 @@
</distributionManagement>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
<powermock.version>1.7.4</powermock.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
<!-- Non-minecraft related dependencies -->
<powermock.version>2.0.2</powermock.version>
<!-- More visible way how to change dependency versions -->
<spigot.version>1.13.2-R0.1-SNAPSHOT</spigot.version>
<bentobox.version>1.6.0-SNAPSHOT</bentobox.version>
<!-- Revision variable removes warning about dynamic version -->
<revision>${build.version}-SNAPSHOT</revision>
<!-- Do not change unless you want different name for local builds. -->
<build.number>-LOCAL</build.number>
<!-- This allows to change between versions. -->
<build.version>1.6.0</build.version>
</properties>

<!-- Profiles will allow to automatically change build version. -->
<profiles>
<profile>
<!-- ci profile is activated if exist environment variable BUILD_NUMBER. -->
<!-- It replaces ${build.number} that is currently '-LOCAL' with correct build number from JENKINS machine. -->
<id>ci</id>
<activation>
<property>
<name>env.BUILD_NUMBER</name>
</property>
</activation>
<properties>
<!-- Override only if necessary -->
<build.number>-b${env.BUILD_NUMBER}</build.number>
</properties>
</profile>
<profile>
<!-- Master profile is activated if exist environment variable GIT_BRANCH and its value is origin/master. -->
<!-- It will replace 'revision' with '${build.version}' so it removes '-SNAPSHOT' string at the end. -->
<!-- Also, as this is release build, build number can be set to empty string. -->
<!-- This profile will be used only if exist environment variable GIT_BRANCH with value origin/master. -->
<id>master</id>
<activation>
<property>
<name>env.GIT_BRANCH</name>
<value>origin/master</value>
</property>
</activation>
<properties>
<!-- Override only if necessary -->
<revision>${build.version}</revision>
<!-- Empties build number variable.-->
<build.number></build.number>
</properties>
</profile>
</profiles>

<repositories>
<repository>
<id>spigot-repo</id>
Expand All @@ -62,40 +120,50 @@
</repository>
</repositories>

<dependencies>
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId>
<version>1.14.1-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-all</artifactId>
<version>1.10.19</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-module-junit4</artifactId>
<version>${powermock.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-api-mockito</artifactId>
<version>${powermock.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>world.bentobox</groupId>
<artifactId>bentobox</artifactId>
<version>1.5.0</version>
<scope>provided</scope>
</dependency>
</dependencies>
<dependencies>
<!-- Spigot API -->
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId>
<version>${spigot.version}</version>
<scope>provided</scope>
</dependency>
<!-- Mockito (Unit testing) -->
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>3.0.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-module-junit4</artifactId>
<version>${powermock.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-api-mockito2</artifactId>
<version>${powermock.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>world.bentobox</groupId>
<artifactId>bentobox</artifactId>
<version>${bentobox.version}</version>
<scope>provided</scope>
</dependency>
</dependencies>

<build>
<!-- By default ${revision} is ${build.version}-SNAPSHOT -->
<!-- If GIT_BRANCH variable is set to origin/master, then it will be only ${build.version}. -->

<!-- By default ${build.number} is -LOCAL. -->
<!-- If the BUILD_NUMBER variable is set, then it will be -b[number]. -->
<!-- If GIT_BRANCH variable is set to origin/master, then it will be the empty string. -->
<finalName>${project.name}-${revision}${build.number}</finalName>

<defaultGoal>clean package</defaultGoal>
<resources>
<resource>
Expand Down
20 changes: 14 additions & 6 deletions src/main/java/world/bentobox/level/Level.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import java.util.UUID;

import org.bukkit.World;
import org.eclipse.jdt.annotation.Nullable;

import world.bentobox.bentobox.api.addons.Addon;
import world.bentobox.bentobox.api.user.User;
Expand Down Expand Up @@ -46,16 +47,16 @@ public class Level extends Addon {
private TopTen topTen;

// Level calculator
private LevelPresenter levelCalc;
private LevelPresenter levelPresenter;

/**
* Calculates a user's island
* @param world - the world where this island is
* @param user - the user who is asking, or null if none
* @param playerUUID - the target island member's UUID
*/
public void calculateIslandLevel(World world, User user, UUID playerUUID) {
levelCalc.calculateIslandLevel(world, user, playerUUID);
public void calculateIslandLevel(World world, @Nullable User user, UUID playerUUID) {
levelPresenter.calculateIslandLevel(world, user, playerUUID);
}

/**
Expand Down Expand Up @@ -85,14 +86,21 @@ public LevelsData getLevelsData(UUID targetPlayer) {
/**
* @return the settings
*/
public final Settings getSettings() {
public Settings getSettings() {
return settings;
}

public TopTen getTopTen() {
return topTen;
}

/**
* @return the levelPresenter
*/
public LevelPresenter getLevelPresenter() {
return levelPresenter;
}

@Override
public void onDisable(){
// Save the cache
Expand All @@ -115,7 +123,7 @@ public void onEnable() {
// Initialize the cache
levelsCache = new HashMap<>();
// Load the calculator
levelCalc = new LevelPresenter(this, this.getPlugin());
levelPresenter = new LevelPresenter(this, this.getPlugin());
// Start the top ten and register it for clicks
topTen = new TopTen(this);
registerListener(topTen);
Expand Down Expand Up @@ -208,7 +216,7 @@ public void setInitialIslandLevel(Island island, long level) {
public long getInitialIslandLevel(Island island) {
return levelsCache.containsKey(island.getOwner()) ? levelsCache.get(island.getOwner()).getInitialLevel(island.getWorld()) : 0L;
}

public Database<LevelsData> getHandler() {
return handler;
}
Expand Down
58 changes: 50 additions & 8 deletions src/main/java/world/bentobox/level/LevelPresenter.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
package world.bentobox.level;

import java.math.BigInteger;
import java.text.DecimalFormat;
import java.util.Calendar;
import java.util.HashMap;
import java.util.Map;
import java.util.TreeMap;
import java.util.UUID;

import org.bukkit.World;
Expand All @@ -10,7 +14,18 @@
import world.bentobox.bentobox.api.user.User;
import world.bentobox.level.calculators.PlayerLevel;

class LevelPresenter {
public class LevelPresenter {

private static final BigInteger THOUSAND = BigInteger.valueOf(1000);
private static final TreeMap<BigInteger, String> LEVELS;
static {
LEVELS = new TreeMap<>();

LEVELS.put(THOUSAND, "k");
LEVELS.put(THOUSAND.pow(2), "M");
LEVELS.put(THOUSAND.pow(3), "G");
LEVELS.put(THOUSAND.pow(4), "T");
}

private int levelWait;
private final Level addon;
Expand Down Expand Up @@ -41,26 +56,53 @@ public void calculateIslandLevel(World world, final User sender, UUID targetPlay
targetPlayer = plugin.getIslands().getOwner(world, targetPlayer);
inTeam = true;
} else {
sender.sendMessage("general.errors.player-has-no-island");
if (sender != null) sender.sendMessage("general.errors.player-has-no-island");
return;
}
}
// Player asking for their own island calc
if (inTeam || !sender.isPlayer() || sender.getUniqueId().equals(targetPlayer) || sender.isOp() || sender.hasPermission(permPrefix + "mod.info")) {
if (sender == null || inTeam || !sender.isPlayer() || sender.getUniqueId().equals(targetPlayer) || sender.isOp() || sender.hasPermission(permPrefix + "mod.info")) {
// Newer better system - uses chunks
if (!onLevelWaitTime(sender) || levelWait <= 0 || sender.isOp() || sender.hasPermission(permPrefix + "mod.info")) {
sender.sendMessage("island.level.calculating");
setLevelWaitTime(sender);
if (sender == null || !onLevelWaitTime(sender) || levelWait <= 0 || sender.isOp() || sender.hasPermission(permPrefix + "mod.info")) {
if (sender != null) {
sender.sendMessage("island.level.calculating");
setLevelWaitTime(sender);
}
new PlayerLevel(addon, plugin.getIslands().getIsland(world, targetPlayer), targetPlayer, sender);
} else {
// Cooldown
sender.sendMessage("island.level.cooldown", "[time]", String.valueOf(getLevelWaitTime(sender)));
}

} else {
// Asking for the level of another player
sender.sendMessage("island.level.island-level-is","[level]", String.valueOf(addon.getIslandLevel(world, targetPlayer)));
long lvl = addon.getIslandLevel(world, targetPlayer);

sender.sendMessage("island.level.island-level-is","[level]", getLevelString(lvl));
}
}

/**
* Get the string representation of the level. May be converted to shorthand notation, e.g., 104556 -> 10.5k
* @param lvl - long value to represent
* @return string of the level.
*/
public String getLevelString(long lvl) {
String level = String.valueOf(lvl);
// Asking for the level of another player
if(addon.getSettings().isShortHand()) {
BigInteger levelValue = BigInteger.valueOf(lvl);

Map.Entry<BigInteger, String> stage = LEVELS.floorEntry(levelValue);

if (stage != null) { // level > 1000
// 1 052 -> 1.0k
// 1 527 314 -> 1.5M
// 3 874 130 021 -> 3.8G
// 4 002 317 889 -> 4.0T
level = new DecimalFormat("#.#").format(levelValue.divide(stage.getKey().divide(THOUSAND)).doubleValue()/1000.0) + stage.getValue();
}
}
return level;
}

/**
Expand Down
Loading

0 comments on commit cc93175

Please sign in to comment.