Improve testing and change playtime permissions
This commit is contained in:
+13
-4
@@ -1,7 +1,7 @@
|
||||
plugins {
|
||||
id 'java'
|
||||
id 'com.github.johnrengelman.shadow' version '6.1.0'
|
||||
id "io.freefair.lombok" version "5.1.0"
|
||||
id "io.freefair.lombok" version "6.0.0-m2"
|
||||
}
|
||||
|
||||
group 'sh.okx'
|
||||
@@ -29,13 +29,14 @@ repositories {
|
||||
}
|
||||
|
||||
dependencies {
|
||||
testImplementation group: 'junit', name: 'junit', version: '4.12'
|
||||
testImplementation 'com.github.seeseemelk:MockBukkit-v1.16:1.0.0'
|
||||
testImplementation("org.junit.platform:junit-platform-launcher:1.7.2")
|
||||
testImplementation("org.junit.jupiter:junit-jupiter-engine:5.7.2")
|
||||
testImplementation 'com.github.MockBukkit:MockBukkit:04889261630cd6f5aaebd86a576bbcd12c442ea7'
|
||||
testImplementation group: 'org.slf4j', name: 'slf4j-nop', version: '1.7.30'
|
||||
testImplementation group: 'org.slf4j', name: 'slf4j-api', version: '1.7.30'
|
||||
|
||||
compileOnly 'org.jetbrains:annotations:16.0.2'
|
||||
compileOnly 'org.spigotmc:spigot-api:1.17-R0.1-SNAPSHOT'
|
||||
compileOnly 'org.spigotmc:spigot-api:1.16.5-R0.1-SNAPSHOT'
|
||||
compileOnly('com.github.Realizedd:TokenManager:3.2.4') {
|
||||
transitive = false
|
||||
}
|
||||
@@ -72,6 +73,7 @@ shadowJar {
|
||||
processResources {
|
||||
// do this again whenever version changes
|
||||
inputs.property 'version', project.version
|
||||
duplicatesStrategy = 'include'
|
||||
|
||||
// copy plugin.yml and replace version
|
||||
from(sourceSets.main.resources.srcDirs) {
|
||||
@@ -91,3 +93,10 @@ task spigot(type: com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar) {
|
||||
archiveFileName = "Rankup.jar"
|
||||
}
|
||||
|
||||
test {
|
||||
useJUnitPlatform()
|
||||
testLogging {
|
||||
events "passed", "skipped", "failed"
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Vendored
BIN
Binary file not shown.
+1
-1
@@ -1,5 +1,5 @@
|
||||
distributionBase=GRADLE_USER_HOME
|
||||
distributionPath=wrapper/dists
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-6.8.3-bin.zip
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-7.1-bin.zip
|
||||
zipStoreBase=GRADLE_USER_HOME
|
||||
zipStorePath=wrapper/dists
|
||||
|
||||
@@ -82,6 +82,7 @@ esac
|
||||
|
||||
CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
|
||||
|
||||
|
||||
# Determine the Java command to use to start the JVM.
|
||||
if [ -n "$JAVA_HOME" ] ; then
|
||||
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
|
||||
@@ -129,6 +130,7 @@ fi
|
||||
if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then
|
||||
APP_HOME=`cygpath --path --mixed "$APP_HOME"`
|
||||
CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
|
||||
|
||||
JAVACMD=`cygpath --unix "$JAVACMD"`
|
||||
|
||||
# We build the pattern for arguments to be converted via cygpath
|
||||
|
||||
Vendored
+4
-18
@@ -40,7 +40,7 @@ if defined JAVA_HOME goto findJavaFromJavaHome
|
||||
|
||||
set JAVA_EXE=java.exe
|
||||
%JAVA_EXE% -version >NUL 2>&1
|
||||
if "%ERRORLEVEL%" == "0" goto init
|
||||
if "%ERRORLEVEL%" == "0" goto execute
|
||||
|
||||
echo.
|
||||
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
|
||||
@@ -54,7 +54,7 @@ goto fail
|
||||
set JAVA_HOME=%JAVA_HOME:"=%
|
||||
set JAVA_EXE=%JAVA_HOME%/bin/java.exe
|
||||
|
||||
if exist "%JAVA_EXE%" goto init
|
||||
if exist "%JAVA_EXE%" goto execute
|
||||
|
||||
echo.
|
||||
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
|
||||
@@ -64,28 +64,14 @@ echo location of your Java installation.
|
||||
|
||||
goto fail
|
||||
|
||||
:init
|
||||
@rem Get command-line arguments, handling Windows variants
|
||||
|
||||
if not "%OS%" == "Windows_NT" goto win9xME_args
|
||||
|
||||
:win9xME_args
|
||||
@rem Slurp the command line arguments.
|
||||
set CMD_LINE_ARGS=
|
||||
set _SKIP=2
|
||||
|
||||
:win9xME_args_slurp
|
||||
if "x%~1" == "x" goto execute
|
||||
|
||||
set CMD_LINE_ARGS=%*
|
||||
|
||||
:execute
|
||||
@rem Setup the command line
|
||||
|
||||
set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
|
||||
|
||||
|
||||
@rem Execute Gradle
|
||||
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
|
||||
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %*
|
||||
|
||||
:end
|
||||
@rem End local scope for the variables with windows NT shell
|
||||
|
||||
@@ -201,7 +201,7 @@ public class InfoCommand implements TabExecutor {
|
||||
element = next;
|
||||
}
|
||||
return true;
|
||||
} else if (args[0].equalsIgnoreCase("playtime") && (sender.hasPermission("rankup.playtime.get") || sender.hasPermission("rankup.playtime.set"))) {
|
||||
} else if (args[0].equalsIgnoreCase("playtime") && (sender.hasPermission("rankup.playtime.get") || sender.hasPermission("rankup.playtime"))) {
|
||||
Statistic playOneTick;
|
||||
try {
|
||||
playOneTick = Statistic.valueOf("PLAY_ONE_MINUTE");
|
||||
@@ -241,7 +241,7 @@ public class InfoCommand implements TabExecutor {
|
||||
}
|
||||
player.sendMessage(ChatColor.LIGHT_PURPLE + who + " played for " + minutes + " minutes.");
|
||||
return true;
|
||||
} else if (args[1].equalsIgnoreCase("set") && sender.hasPermission("rankup.playtime.set")) {
|
||||
} else if (args[1].equalsIgnoreCase("set") && sender.hasPermission("rankup.playtime")) {
|
||||
if (args.length < 4) {
|
||||
sender.sendMessage(ChatColor.GREEN + "/" + label + " " + args[0] + " set <player> <minutes>" + ChatColor.YELLOW + " Update the playtime statistic for a player");
|
||||
return true;
|
||||
@@ -264,7 +264,7 @@ public class InfoCommand implements TabExecutor {
|
||||
player.setStatistic(playOneTick, minutes * 20 * 60);
|
||||
player.sendMessage(ChatColor.LIGHT_PURPLE + "Updated playtime for " + player.getName() + " to " + minutes + " minutes");
|
||||
return true;
|
||||
} else if (args[1].equalsIgnoreCase("add") && sender.hasPermission("rankup.playtime.set")) {
|
||||
} else if (args[1].equalsIgnoreCase("add") && sender.hasPermission("rankup.playtime")) {
|
||||
if (args.length < 4) {
|
||||
sender.sendMessage(ChatColor.GREEN + "/" + label + " " + args[0] + " add <player> <minutes>" + ChatColor.YELLOW + " Increase the playtime statistic for a player");
|
||||
return true;
|
||||
@@ -304,7 +304,7 @@ public class InfoCommand implements TabExecutor {
|
||||
ChatColor.GREEN + "/" + label + " " + args[0] + " get [player] " + ChatColor.YELLOW
|
||||
+ " Get amount of minutes played");
|
||||
}
|
||||
if (sender.hasPermission("rankup.playtime.set")) {
|
||||
if (sender.hasPermission("rankup.playtime")) {
|
||||
sender.sendMessage(
|
||||
ChatColor.GREEN + "/" + label + " " + args[0] + " set <player> <minutes>"
|
||||
+ ChatColor.YELLOW + " Update the playtime statistic for a player");
|
||||
@@ -356,7 +356,7 @@ public class InfoCommand implements TabExecutor {
|
||||
list.add("forceprestige");
|
||||
list.add("rankdown");
|
||||
}
|
||||
if (sender.hasPermission("rankup.playtime.get") || sender.hasPermission("rankup.playtime.set")) {
|
||||
if (sender.hasPermission("rankup.playtime.get") || sender.hasPermission("rankup.playtime")) {
|
||||
list.add("playtime");
|
||||
}
|
||||
return StringUtil.copyPartialMatches(args[0], list, new ArrayList<>());
|
||||
@@ -372,7 +372,7 @@ public class InfoCommand implements TabExecutor {
|
||||
if (sender.hasPermission("rankup.playtime.get")) {
|
||||
options.add("get");
|
||||
}
|
||||
if (sender.hasPermission("rankup.playtime.set")) {
|
||||
if (sender.hasPermission("rankup.playtime")) {
|
||||
options.add("set");
|
||||
options.add("add");
|
||||
}
|
||||
|
||||
@@ -33,14 +33,13 @@ public class PebbleMessageBuilder implements MessageBuilder {
|
||||
}
|
||||
|
||||
private void replaceInitial() {
|
||||
Function<Player, Object> lastMinute = player -> {
|
||||
lastMinuteContext.put("ranks", player -> {
|
||||
List<RankContext> ranks = new ArrayList<>();
|
||||
for (Rank rank : plugin.getRankups().getTree()) {
|
||||
ranks.add(new RankContext(plugin, player, rank));
|
||||
}
|
||||
return ranks;
|
||||
};
|
||||
lastMinuteContext.put("ranks", lastMinute);
|
||||
});
|
||||
lastMinuteContext.put("player", HumanEntity::getName);
|
||||
}
|
||||
|
||||
|
||||
@@ -61,7 +61,10 @@ permissions:
|
||||
rankup.maxrankup:
|
||||
default: true
|
||||
rankup.playtime:
|
||||
description: Use all /rankup3 playtime subcommands for anyone.
|
||||
children:
|
||||
rankup.playtime.get: true
|
||||
rankup.playtime.set: true
|
||||
default: op
|
||||
rankup.playtime.get:
|
||||
description: Use /rankup3 playtime get for anyone.
|
||||
default: op
|
||||
@@ -1,10 +1,11 @@
|
||||
package sh.okx.rankup;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
import be.seeseemelk.mockbukkit.entity.PlayerMock;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import sh.okx.rankup.messages.Message;
|
||||
import sh.okx.rankup.ranks.Rank;
|
||||
import sh.okx.rankup.ranks.RankElement;
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
package sh.okx.rankup;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
import be.seeseemelk.mockbukkit.entity.PlayerMock;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
public class RankupCommandTest extends RankupTest {
|
||||
@Test
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
package sh.okx.rankup;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
import be.seeseemelk.mockbukkit.entity.PlayerMock;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import sh.okx.rankup.placeholders.RankupExpansion;
|
||||
|
||||
public class RankupPlaceholderTest extends RankupTest {
|
||||
|
||||
@@ -10,12 +10,11 @@ import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.SimpleFileVisitor;
|
||||
import java.nio.file.attribute.BasicFileAttributes;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import sh.okx.rankup.economy.TestEconomyProvider;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import sh.okx.rankup.providers.TestEconomyProvider;
|
||||
import sh.okx.rankup.hook.GroupProvider;
|
||||
import sh.okx.rankup.hook.TestGroupProvider;
|
||||
import sh.okx.rankup.hook.TestPermissionManager;
|
||||
import sh.okx.rankup.providers.TestGroupProvider;
|
||||
import sh.okx.rankup.providers.TestPermissionManager;
|
||||
|
||||
public abstract class RankupTest {
|
||||
private final File testResourceFolder;
|
||||
@@ -37,7 +36,7 @@ public abstract class RankupTest {
|
||||
protected ServerMock server;
|
||||
protected RankupPlugin plugin;
|
||||
|
||||
@Before
|
||||
@BeforeEach
|
||||
public void setup() {
|
||||
System.setProperty("RANKUP_TEST", "true");
|
||||
|
||||
@@ -77,7 +76,7 @@ public abstract class RankupTest {
|
||||
}
|
||||
}
|
||||
|
||||
@After
|
||||
@BeforeEach
|
||||
public void tearDown() {
|
||||
MockBukkit.unmock();
|
||||
System.clearProperty("RANKUP_TEST");
|
||||
|
||||
@@ -0,0 +1,56 @@
|
||||
package sh.okx.rankup.commands;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
import be.seeseemelk.mockbukkit.entity.PlayerMock;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Statistic;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import sh.okx.rankup.RankupTest;
|
||||
|
||||
public class ComandPlaytimeTest extends RankupTest {
|
||||
@Test
|
||||
public void testAdd() {
|
||||
PlayerMock player = server.addPlayer();
|
||||
|
||||
player.setStatistic(Statistic.PLAY_ONE_MINUTE, ticks(10));
|
||||
|
||||
player.addAttachment(plugin, "rankup.playtime", true);
|
||||
player.performCommand("pru playtime add " + player.getName() + " 20");
|
||||
|
||||
assertEquals(ticks(30), player.getStatistic(Statistic.PLAY_ONE_MINUTE));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSet() {
|
||||
PlayerMock player = server.addPlayer();
|
||||
|
||||
player.setStatistic(Statistic.PLAY_ONE_MINUTE, ticks(20));
|
||||
|
||||
player.addAttachment(plugin, "rankup.playtime", true);
|
||||
player.performCommand("pru playtime set " + player.getName() + " 25");
|
||||
|
||||
assertEquals(ticks(25), player.getStatistic(Statistic.PLAY_ONE_MINUTE));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetSelf() {
|
||||
PlayerMock player = server.addPlayer();
|
||||
|
||||
player.setStatistic(Statistic.PLAY_ONE_MINUTE, ticks(5));
|
||||
|
||||
player.addAttachment(plugin, "rankup.playtime.get", true);
|
||||
player.performCommand("pru playtime get " + player.getName());
|
||||
|
||||
player.assertSaid(ChatColor.LIGHT_PURPLE + "You have played for 5 minutes.");
|
||||
player.assertNoMoreSaid();
|
||||
}
|
||||
|
||||
private int ticks(int minutes) {
|
||||
return minutes * 20 * 60;
|
||||
}
|
||||
|
||||
private int minutes(int ticks) {
|
||||
return ticks / 20 / 60;
|
||||
}
|
||||
}
|
||||
@@ -2,7 +2,7 @@ package sh.okx.rankup.legacy;
|
||||
|
||||
import be.seeseemelk.mockbukkit.entity.PlayerMock;
|
||||
import java.text.DecimalFormat;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import sh.okx.rankup.RankupTest;
|
||||
|
||||
public class LegacyPlaceholderTest extends RankupTest {
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
package sh.okx.rankup.messages;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.instanceOf;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
public class MessageBuilderTest {
|
||||
@Test
|
||||
public void testFailIfEmpty() {
|
||||
assertThat(new StringMessageBuilder("").failIfEmpty(), instanceOf(NullMessageBuilder.class));
|
||||
assertTrue(new StringMessageBuilder("").failIfEmpty() instanceof NullMessageBuilder);
|
||||
}
|
||||
}
|
||||
@@ -1,10 +1,10 @@
|
||||
package sh.okx.rankup.messages;
|
||||
|
||||
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
|
||||
import be.seeseemelk.mockbukkit.entity.PlayerMock;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import sh.okx.rankup.RankupTest;
|
||||
|
||||
public class RankupPlaceholderTest extends RankupTest {
|
||||
|
||||
@@ -1,12 +1,13 @@
|
||||
package sh.okx.rankup.pebble;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import sh.okx.rankup.text.pebble.PebbleTextProcessor;
|
||||
|
||||
public class PebbleTest {
|
||||
|
||||
+2
-1
@@ -1,10 +1,11 @@
|
||||
package sh.okx.rankup.economy;
|
||||
package sh.okx.rankup.providers;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
import sh.okx.rankup.economy.Economy;
|
||||
|
||||
public class TestEconomy implements Economy {
|
||||
private final Map<UUID, Double> balances = new HashMap<>();
|
||||
+4
-1
@@ -1,4 +1,7 @@
|
||||
package sh.okx.rankup.economy;
|
||||
package sh.okx.rankup.providers;
|
||||
|
||||
import sh.okx.rankup.economy.Economy;
|
||||
import sh.okx.rankup.economy.EconomyProvider;
|
||||
|
||||
public class TestEconomyProvider implements EconomyProvider {
|
||||
@Override
|
||||
+2
-1
@@ -1,9 +1,10 @@
|
||||
package sh.okx.rankup.hook;
|
||||
package sh.okx.rankup.providers;
|
||||
|
||||
import com.google.common.collect.ArrayListMultimap;
|
||||
import com.google.common.collect.Multimap;
|
||||
|
||||
import java.util.UUID;
|
||||
import sh.okx.rankup.hook.GroupProvider;
|
||||
|
||||
public class TestGroupProvider implements GroupProvider {
|
||||
private Multimap<UUID, String> groups = ArrayListMultimap.create();
|
||||
+4
-1
@@ -1,4 +1,7 @@
|
||||
package sh.okx.rankup.hook;
|
||||
package sh.okx.rankup.providers;
|
||||
|
||||
import sh.okx.rankup.hook.GroupProvider;
|
||||
import sh.okx.rankup.hook.PermissionManager;
|
||||
|
||||
public class TestPermissionManager implements PermissionManager {
|
||||
private final GroupProvider groupProvider;
|
||||
Reference in New Issue
Block a user