From 9547d40a3bf2aa5b17dec6bc474a6470f22e77c1 Mon Sep 17 00:00:00 2001 From: Oliver Date: Mon, 31 May 2021 18:37:24 -0600 Subject: [PATCH] Some tests, clean up, and mobs config value --- .gitignore | 2 - .../ohowe12/spectatormode/SpectatorMode.java | 18 +- .../context/SpectatorContextCalculator.java | 17 +- .../listener/OnCommandPreprocessListener.java | 9 +- .../listener/OnMoveListener.java | 7 +- .../me/ohowe12/spectatormode/state/State.java | 43 ++-- .../spectatormode/state/StateHolder.java | 19 +- .../spectatormode/util/ConfigManager.java | 10 +- .../ohowe12/spectatormode/util/Messenger.java | 9 +- .../spectatormode/util/UpdateChecker.java | 15 +- src/main/java/org/bstats/bukkit/Metrics.java | 206 +++++++++--------- src/main/resources/config.yml | 4 +- src/main/resources/plugin.yml | 10 +- .../spectatormode/SpectatorManagerTest.java | 9 +- .../SpectatorContextCalculatorTest.java | 48 ++++ .../OnCommandPreprocessListenerTest.java | 19 +- .../listener/OnMoveListenerTest.java | 38 +++- .../spectatormode/utils/TestUtils.java | 3 +- .../utils/mocks/ContextConsumerMock.java | 10 + src/test/resources/configs/badhealth.yml | 49 +---- src/test/resources/configs/badworld.yml | 46 ---- src/test/resources/configs/badylevel.yml | 2 + .../resources/configs/disabledcommands.yml | 50 +---- .../resources/configs/disabledeffects.yml | 50 +---- 24 files changed, 313 insertions(+), 380 deletions(-) create mode 100644 src/test/java/me/ohowe12/spectatormode/context/SpectatorContextCalculatorTest.java create mode 100644 src/test/java/me/ohowe12/spectatormode/utils/mocks/ContextConsumerMock.java create mode 100644 src/test/resources/configs/badylevel.yml diff --git a/.gitignore b/.gitignore index e9e224c..eb73b87 100644 --- a/.gitignore +++ b/.gitignore @@ -48,7 +48,6 @@ out/ ## Eclipse ############################## .settings/ -bin/ tmp/ .metadata .classpath @@ -65,7 +64,6 @@ local.properties ## NetBeans ############################## nbproject/private/ -build/ nbbuild/ dist/ nbdist/ diff --git a/src/main/java/me/ohowe12/spectatormode/SpectatorMode.java b/src/main/java/me/ohowe12/spectatormode/SpectatorMode.java index 6815f4a..8c94422 100644 --- a/src/main/java/me/ohowe12/spectatormode/SpectatorMode.java +++ b/src/main/java/me/ohowe12/spectatormode/SpectatorMode.java @@ -28,11 +28,14 @@ import dev.jorel.commandapi.arguments.IntegerArgument; import dev.jorel.commandapi.arguments.PlayerArgument; import me.ohowe12.spectatormode.context.SpectatorContextCalculator; -import me.ohowe12.spectatormode.listener.*; -import me.ohowe12.spectatormode.util.*; +import me.ohowe12.spectatormode.listener.OnCommandPreprocessListener; +import me.ohowe12.spectatormode.listener.OnLogOnListener; +import me.ohowe12.spectatormode.listener.OnMoveListener; +import me.ohowe12.spectatormode.util.ConfigManager; +import me.ohowe12.spectatormode.util.Logger; +import me.ohowe12.spectatormode.util.Messenger; +import me.ohowe12.spectatormode.util.UpdateChecker; import org.bstats.bukkit.Metrics; -import org.bukkit.Bukkit; -import org.bukkit.ChatColor; import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.entity.Player; import org.bukkit.plugin.PluginDescriptionFile; @@ -104,7 +107,7 @@ private void initializeLuckPermsContext() { pluginLogger.debugLog("LuckPerms not enabled"); return; } - SpectatorContextCalculator.initalizeSpectatorContext(this); + SpectatorContextCalculator.initializeSpectatorContext(this); } private void addMetrics() { @@ -170,8 +173,9 @@ public void registerCommands() { spectatorManager.togglePlayer((Player) args[0], true); }); - CommandAPICommand mainCommand = new CommandAPICommand("s").withAliases("smps").withPermission("smpspectator.use").executesPlayer((player, - args) -> { + CommandAPICommand mainCommand = new CommandAPICommand("s").withAliases("smps").withPermission("smpspectator" + + ".use").executesPlayer((player, + args) -> { spectatorManager.togglePlayer(player); }).withSubcommand(enableCommand).withSubcommand(disableCommand).withSubcommand(reloadCommand).withSubcommand(effectCommand).withSubcommand(forceCommand); diff --git a/src/main/java/me/ohowe12/spectatormode/context/SpectatorContextCalculator.java b/src/main/java/me/ohowe12/spectatormode/context/SpectatorContextCalculator.java index 3278550..17b464a 100644 --- a/src/main/java/me/ohowe12/spectatormode/context/SpectatorContextCalculator.java +++ b/src/main/java/me/ohowe12/spectatormode/context/SpectatorContextCalculator.java @@ -23,22 +23,25 @@ package me.ohowe12.spectatormode.context; -import org.bukkit.Bukkit; -import org.bukkit.entity.Player; -import org.bukkit.plugin.RegisteredServiceProvider; - import me.ohowe12.spectatormode.SpectatorMode; import net.luckperms.api.LuckPerms; import net.luckperms.api.context.ContextCalculator; import net.luckperms.api.context.ContextConsumer; import net.luckperms.api.context.ContextSet; import net.luckperms.api.context.ImmutableContextSet; +import org.bukkit.Bukkit; +import org.bukkit.entity.Player; +import org.bukkit.plugin.RegisteredServiceProvider; public class SpectatorContextCalculator implements ContextCalculator { private final SpectatorMode plugin; - public static void initalizeSpectatorContext(SpectatorMode plugin) { + public SpectatorContextCalculator(SpectatorMode plugin) { + this.plugin = plugin; + } + + public static void initializeSpectatorContext(SpectatorMode plugin) { RegisteredServiceProvider provider = Bukkit.getServicesManager().getRegistration(LuckPerms.class); if (provider != null) { LuckPerms api = provider.getProvider(); @@ -46,10 +49,6 @@ public static void initalizeSpectatorContext(SpectatorMode plugin) { } } - public SpectatorContextCalculator(SpectatorMode plugin) { - this.plugin = plugin; - } - @Override public void calculate(Player target, ContextConsumer contextConsumer) { contextConsumer.accept("SMP Spectator", diff --git a/src/main/java/me/ohowe12/spectatormode/listener/OnCommandPreprocessListener.java b/src/main/java/me/ohowe12/spectatormode/listener/OnCommandPreprocessListener.java index 8d0b0b1..8d2389b 100644 --- a/src/main/java/me/ohowe12/spectatormode/listener/OnCommandPreprocessListener.java +++ b/src/main/java/me/ohowe12/spectatormode/listener/OnCommandPreprocessListener.java @@ -23,8 +23,8 @@ package me.ohowe12.spectatormode.listener; -import me.ohowe12.spectatormode.util.Messenger; import me.ohowe12.spectatormode.SpectatorMode; +import me.ohowe12.spectatormode.util.Messenger; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; @@ -50,13 +50,14 @@ public void onCommandEvent(final PlayerCommandPreprocessEvent e) { return; } - String rawCommand = e.getMessage().substring(1).split(" ")[0]; // /back -> back || /essentials:back -> essentials:back + String rawCommand = e.getMessage().substring(1).split(" ")[0]; // /back -> back || /essentials:back -> + // essentials:back String[] splited = rawCommand.split(":"); rawCommand = splited[splited.length - 1]; if (plugin.getConfigManager().getList("bad-commands") - .contains(rawCommand)) { - Messenger.send(player,"bad-command-message"); + .contains(rawCommand)) { + Messenger.send(player, "bad-command-message"); e.setCancelled(true); } } diff --git a/src/main/java/me/ohowe12/spectatormode/listener/OnMoveListener.java b/src/main/java/me/ohowe12/spectatormode/listener/OnMoveListener.java index 6da6f97..6035fed 100644 --- a/src/main/java/me/ohowe12/spectatormode/listener/OnMoveListener.java +++ b/src/main/java/me/ohowe12/spectatormode/listener/OnMoveListener.java @@ -25,9 +25,7 @@ import me.ohowe12.spectatormode.SpectatorMode; import me.ohowe12.spectatormode.util.Messenger; -import org.bukkit.GameMode; -import org.bukkit.Location; -import org.bukkit.Material; +import org.bukkit.*; import org.bukkit.block.Block; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; @@ -76,6 +74,9 @@ private boolean shouldCancelMoveEvent(PlayerMoveEvent e) { private boolean outsideWorldBorder(PlayerMoveEvent e) { Location location = e.getTo(); + if (plugin.isUnitTest()) { + return false; + } return !location.getWorld().getWorldBorder().isInside(location); } diff --git a/src/main/java/me/ohowe12/spectatormode/state/State.java b/src/main/java/me/ohowe12/spectatormode/state/State.java index 61801b3..3d7f1df 100644 --- a/src/main/java/me/ohowe12/spectatormode/state/State.java +++ b/src/main/java/me/ohowe12/spectatormode/state/State.java @@ -24,6 +24,7 @@ package me.ohowe12.spectatormode.state; import me.ohowe12.spectatormode.SpectatorMode; +import me.ohowe12.spectatormode.util.Logger; import org.bukkit.Bukkit; import org.bukkit.Chunk; import org.bukkit.Location; @@ -43,8 +44,8 @@ @SuppressWarnings("unchecked") public class State { - private Player player; private final SpectatorMode plugin; + private Player player; private Location playerLocation; private int fireTicks; private ArrayList potionEffects; @@ -59,8 +60,8 @@ public State(@NotNull Player player, @NotNull SpectatorMode plugin) { fireTicks = player.getFireTicks(); potionEffects = new ArrayList<>(player.getActivePotionEffects()); waterBubbles = player.getRemainingAir(); - if (!plugin.isUnitTest()) - prepareMobs(); + + prepareMobs(); } public State(@NotNull Map serialized, @NotNull SpectatorMode plugin) { @@ -91,27 +92,33 @@ public Map getMobIds() { public Player getPlayer() { return player; } - public UUID getPlayerUUID() { - return player.getUniqueId(); - } public void resetPlayer(Player player) { player.teleport(getPlayerLocation()); - player.setFireTicks(getFireTicks()); + player.setFireTicks(getFireTicks()); player.addPotionEffects(getPotionEffects()); player.setRemainingAir(getWaterBubbles()); } private void deserialize(@NotNull Map serialized) { - playerLocation = (Location) serialized.get("Location"); - fireTicks = (int) serialized.get("Fire ticks"); - potionEffects = (ArrayList) serialized.get("Potions"); - waterBubbles = (int) serialized.get("Water bubbles"); - mobIds = (Map) serialized.get("Mobs"); - + try { + playerLocation = (Location) serialized.get("Location"); + fireTicks = (int) serialized.get("Fire ticks"); + potionEffects = (ArrayList) serialized.get("Potions"); + waterBubbles = (int) serialized.get("Water bubbles"); + mobIds = (Map) serialized.get("Mobs"); + } catch (ClassCastException exception) { + plugin.getPluginLogger().log(Logger.ANSI_RED + "There has been an error with your data.yml file!\nYou can" + + " either fix this your self my removing the file and letting it regenerate itself, manually " + + "fixing everything inside of it, or join the discord server for help. Please provide this error message with it:"); + throw exception; + } } private void prepareMobs() { + if (!plugin.getConfigManager().getBoolean("mobs") || plugin.isUnitTest()) { + return; + } World world = player.getWorld(); Chunk defaultChunk = world.getChunkAt(getPlayerLocation()); for (int x = 0; x <= 4; x++) { @@ -127,11 +134,11 @@ private void processMobChunk(Chunk chunk) { } } - private void checkAndAddEntity(Entity e) { - if (e instanceof LivingEntity) { + private void checkAndAddEntity(Entity entity) { + if (entity instanceof LivingEntity) { @NotNull - LivingEntity living = (LivingEntity) e; - if (e instanceof Player) { + LivingEntity living = (LivingEntity) entity; + if (entity instanceof Player) { return; } if (living.getRemoveWhenFarAway()) { @@ -154,7 +161,7 @@ private void addLivingEntity(LivingEntity living) { } public void unPrepareMobs() { - if (plugin.isUnitTest()) { + if (plugin.getConfigManager().getBoolean("mobs") || plugin.isUnitTest()) { return; } @NotNull diff --git a/src/main/java/me/ohowe12/spectatormode/state/StateHolder.java b/src/main/java/me/ohowe12/spectatormode/state/StateHolder.java index 716fbd6..62c2c24 100644 --- a/src/main/java/me/ohowe12/spectatormode/state/StateHolder.java +++ b/src/main/java/me/ohowe12/spectatormode/state/StateHolder.java @@ -78,6 +78,7 @@ public void removePlayer(Player player) { public Set allPlayersInState() { return stateMap.keySet(); } + public Collection allStates() { return stateMap.values(); } @@ -90,8 +91,7 @@ public void save() { } }); } - for (@NotNull - final Map.Entry entry : stateMap.entrySet()) { + for (@NotNull final Map.Entry entry : stateMap.entrySet()) { dataFile.set("data." + entry.getKey(), entry.getValue().serialize()); } try { @@ -109,8 +109,8 @@ public void load() { Objects.requireNonNull(dataFile.getConfigurationSection("data")).getKeys(false).forEach(key -> { final Map value = new HashMap<>(); - @SuppressWarnings("unchecked") - final ArrayList potions = (ArrayList) dataFile + @SuppressWarnings("unchecked") final ArrayList potions = + (ArrayList) dataFile .getList("data." + key + ".Potions"); value.put("Potions", potions); @@ -118,8 +118,9 @@ public void load() { value.put("Water bubbles", waterBubbles); final Map mobs = new HashMap<>(); - Objects.requireNonNull(dataFile.getConfigurationSection("data." + key + ".Mobs")).getKeys(false) - .forEach(mobKey -> mobs.put(mobKey, dataFile.getBoolean("data." + key + ".Mobs" + mobKey))); + for (String mobKey : dataFile.getConfigurationSection("data." + key + ".Mobs").getKeys(false)) { + mobs.put(mobKey, dataFile.getBoolean("data." + key + ".Mobs" + mobKey)); + } value.put("Mobs", mobs); final int fireTicks = dataFile.getInt("data." + key + ".Fire ticks"); @@ -128,12 +129,6 @@ public void load() { final Location location = dataFile.getLocation("data." + key + ".Location"); value.put("Location", location); - String placeHolder = dataFile.getString("data." + key + ".PlaceholderUUID"); - value.put("PlaceholderUUID", placeHolder); - - boolean needsMob = dataFile.getBoolean("data." + key + "NeedsMob"); - value.put("NeedsMob", needsMob); - stateMap.put(key, new State(value, plugin)); }); } catch (final NullPointerException ignored) { diff --git a/src/main/java/me/ohowe12/spectatormode/util/ConfigManager.java b/src/main/java/me/ohowe12/spectatormode/util/ConfigManager.java index 8fcc2b4..36e2e3c 100644 --- a/src/main/java/me/ohowe12/spectatormode/util/ConfigManager.java +++ b/src/main/java/me/ohowe12/spectatormode/util/ConfigManager.java @@ -23,17 +23,17 @@ package me.ohowe12.spectatormode.util; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Objects; - import me.ohowe12.spectatormode.SpectatorMode; import org.bukkit.ChatColor; import org.bukkit.configuration.Configuration; import org.bukkit.configuration.file.FileConfiguration; import org.jetbrains.annotations.NotNull; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Objects; + public class ConfigManager { private final FileConfiguration config; diff --git a/src/main/java/me/ohowe12/spectatormode/util/Messenger.java b/src/main/java/me/ohowe12/spectatormode/util/Messenger.java index 121521c..c09302d 100644 --- a/src/main/java/me/ohowe12/spectatormode/util/Messenger.java +++ b/src/main/java/me/ohowe12/spectatormode/util/Messenger.java @@ -34,12 +34,12 @@ public abstract class Messenger { + private static SpectatorMode plugin; + private Messenger() { } - private static SpectatorMode plugin; - public static void init(@NotNull SpectatorMode plugin) { Messenger.plugin = plugin; } @@ -56,7 +56,8 @@ public static void send(@NotNull CommandSender sender, @NotNull String msgkey, @ send(sender, sender, msgkey, extra); } - public static void send(@NotNull CommandSender sender, @NotNull CommandSender target, @NotNull String msgkey, @NotNull String extra) { + public static void send(@NotNull CommandSender sender, @NotNull CommandSender target, @NotNull String msgkey, + @NotNull String extra) { String cfgmsg = Objects.requireNonNull(plugin.getConfigManager(), "Messenger not initialized") .getColorizedString(msgkey) .replace("/target/", target.getName()); @@ -66,6 +67,6 @@ public static void send(@NotNull CommandSender sender, @NotNull CommandSender ta if (!(sender instanceof Player)) sender.sendMessage(cfgmsg); else - ((Player)sender).spigot().sendMessage(type, new TextComponent(cfgmsg)); + ((Player) sender).spigot().sendMessage(type, new TextComponent(cfgmsg)); } } diff --git a/src/main/java/me/ohowe12/spectatormode/util/UpdateChecker.java b/src/main/java/me/ohowe12/spectatormode/util/UpdateChecker.java index cd43517..ba2b46e 100644 --- a/src/main/java/me/ohowe12/spectatormode/util/UpdateChecker.java +++ b/src/main/java/me/ohowe12/spectatormode/util/UpdateChecker.java @@ -23,27 +23,28 @@ package me.ohowe12.spectatormode.util; -import java.io.IOException; -import java.io.InputStream; -import java.net.URL; -import java.util.Scanner; import org.bukkit.Bukkit; import org.bukkit.plugin.Plugin; import org.bukkit.util.Consumer; import org.jetbrains.annotations.NotNull; +import java.io.IOException; +import java.io.InputStream; +import java.net.URL; +import java.util.Scanner; + public class UpdateChecker { private UpdateChecker() { - + } public static void getVersion(final @NotNull Consumer consumer, Plugin plugin) { Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> { try (InputStream inputStream = new URL( - "https://api.spigotmc.org/legacy/update.php?resource=77267") - .openStream(); Scanner scanner = new Scanner(inputStream)) { + "https://api.spigotmc.org/legacy/update.php?resource=77267") + .openStream(); Scanner scanner = new Scanner(inputStream)) { if (scanner.hasNext()) { consumer.accept(scanner.next()); } diff --git a/src/main/java/org/bstats/bukkit/Metrics.java b/src/main/java/org/bstats/bukkit/Metrics.java index 89a2580..270c92d 100644 --- a/src/main/java/org/bstats/bukkit/Metrics.java +++ b/src/main/java/org/bstats/bukkit/Metrics.java @@ -1,21 +1,17 @@ package org.bstats.bukkit; -import java.io.BufferedReader; -import java.io.ByteArrayOutputStream; -import java.io.DataOutputStream; -import java.io.File; -import java.io.IOException; -import java.io.InputStreamReader; +import org.bukkit.Bukkit; +import org.bukkit.configuration.file.YamlConfiguration; +import org.bukkit.entity.Player; +import org.bukkit.plugin.Plugin; +import org.bukkit.plugin.java.JavaPlugin; + +import javax.net.ssl.HttpsURLConnection; +import java.io.*; import java.lang.reflect.Method; import java.net.URL; import java.nio.charset.StandardCharsets; -import java.util.Arrays; -import java.util.Collection; -import java.util.HashSet; -import java.util.Map; -import java.util.Objects; -import java.util.Set; -import java.util.UUID; +import java.util.*; import java.util.concurrent.Callable; import java.util.concurrent.Executors; import java.util.concurrent.ScheduledExecutorService; @@ -26,12 +22,6 @@ import java.util.logging.Level; import java.util.stream.Collectors; import java.util.zip.GZIPOutputStream; -import javax.net.ssl.HttpsURLConnection; -import org.bukkit.Bukkit; -import org.bukkit.configuration.file.YamlConfiguration; -import org.bukkit.entity.Player; -import org.bukkit.plugin.Plugin; -import org.bukkit.plugin.java.JavaPlugin; @SuppressWarnings("all") public class Metrics { @@ -43,9 +33,9 @@ public class Metrics { /** * Creates a new Metrics instance. * - * @param plugin Your plugin instance. + * @param plugin Your plugin instance. * @param serviceId The id of the service. It can be found at What is my plugin id? + * href="https://bstats.org/what-is-my-plugin-id">What is my plugin id? */ public Metrics(JavaPlugin plugin, int serviceId) { this.plugin = plugin; @@ -64,9 +54,12 @@ public Metrics(JavaPlugin plugin, int serviceId) { .options() .header( "bStats (https://bStats.org) collects some basic information for plugin authors, like how\n" - + "many people use their plugin and their total player count. It's recommended to keep bStats\n" - + "enabled, but if you're not comfortable with this, you can turn this setting off. There is no\n" - + "performance penalty associated with having metrics enabled, and data sent to bStats is fully\n" + + "many people use their plugin and their total player count. It's recommended to" + + " keep bStats\n" + + "enabled, but if you're not comfortable with this, you can turn this setting " + + "off. There is no\n" + + "performance penalty associated with having metrics enabled, and data sent to " + + "bStats is fully\n" + "anonymous.") .copyDefaults(true); try { @@ -139,7 +132,9 @@ private int getPlayerAmount() { public static class MetricsBase { - /** The version of the Metrics class. */ + /** + * The version of the Metrics class. + */ public static final String METRICS_VERSION = "2.2.1"; private static final ScheduledExecutorService scheduler = @@ -178,23 +173,24 @@ public static class MetricsBase { /** * Creates a new MetricsBase class instance. * - * @param platform The platform of the service. - * @param serviceId The id of the service. - * @param serverUuid The server uuid. - * @param enabled Whether or not data sending is enabled. - * @param appendPlatformDataConsumer A consumer that receives a {@code JsonObjectBuilder} and - * appends all platform-specific data. - * @param appendServiceDataConsumer A consumer that receives a {@code JsonObjectBuilder} and - * appends all service-specific data. - * @param submitTaskConsumer A consumer that takes a runnable with the submit task. This can be - * used to delegate the data collection to a another thread to prevent errors caused by - * concurrency. Can be {@code null}. + * @param platform The platform of the service. + * @param serviceId The id of the service. + * @param serverUuid The server uuid. + * @param enabled Whether or not data sending is enabled. + * @param appendPlatformDataConsumer A consumer that receives a {@code JsonObjectBuilder} and + * appends all platform-specific data. + * @param appendServiceDataConsumer A consumer that receives a {@code JsonObjectBuilder} and + * appends all service-specific data. + * @param submitTaskConsumer A consumer that takes a runnable with the submit task. This can be + * used to delegate the data collection to a another thread to prevent + * errors caused by + * concurrency. Can be {@code null}. * @param checkServiceEnabledSupplier A supplier to check if the service is still enabled. - * @param errorLogger A consumer that accepts log message and an error. - * @param infoLogger A consumer that accepts info log messages. - * @param logErrors Whether or not errors should be logged. - * @param logSentData Whether or not the sent data should be logged. - * @param logResponseStatusText Whether or not the response status text should be logged. + * @param errorLogger A consumer that accepts log message and an error. + * @param infoLogger A consumer that accepts info log messages. + * @param logErrors Whether or not errors should be logged. + * @param logSentData Whether or not the sent data should be logged. + * @param logResponseStatusText Whether or not the response status text should be logged. */ public MetricsBase( String platform, @@ -229,6 +225,23 @@ public MetricsBase( } } + /** + * Gzips the given string. + * + * @param str The string to gzip. + * @return The gzipped string. + */ + private static byte[] compress(final String str) throws IOException { + if (str == null) { + return null; + } + ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); + try (GZIPOutputStream gzip = new GZIPOutputStream(outputStream)) { + gzip.write(str.getBytes(StandardCharsets.UTF_8)); + } + return outputStream.toByteArray(); + } + public void addCustomChart(CustomChart chart) { this.customCharts.add(chart); } @@ -323,7 +336,9 @@ private void sendData(JsonObjectBuilder.JsonObject data) throws Exception { } } - /** Checks that the class was properly relocated. */ + /** + * Checks that the class was properly relocated. + */ private void checkRelocation() { // You can use the property to disable the check in your test environment if (System.getProperty("bstats.relocatecheck") == null @@ -331,9 +346,9 @@ private void checkRelocation() { // Maven's Relocate is clever and changes strings, too. So we have to use this little // "trick" ... :D final String defaultPackage = - new String(new byte[] {'o', 'r', 'g', '.', 'b', 's', 't', 'a', 't', 's'}); + new String(new byte[]{'o', 'r', 'g', '.', 'b', 's', 't', 'a', 't', 's'}); final String examplePackage = - new String(new byte[] {'y', 'o', 'u', 'r', '.', 'p', 'a', 'c', 'k', 'a', 'g', 'e'}); + new String(new byte[]{'y', 'o', 'u', 'r', '.', 'p', 'a', 'c', 'k', 'a', 'g', 'e'}); // We want to make sure no one just copy & pastes the example and uses the wrong package // names if (MetricsBase.class.getPackage().getName().startsWith(defaultPackage) @@ -342,23 +357,6 @@ private void checkRelocation() { } } } - - /** - * Gzips the given string. - * - * @param str The string to gzip. - * @return The gzipped string. - */ - private static byte[] compress(final String str) throws IOException { - if (str == null) { - return null; - } - ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); - try (GZIPOutputStream gzip = new GZIPOutputStream(outputStream)) { - gzip.write(str.getBytes(StandardCharsets.UTF_8)); - } - return outputStream.toByteArray(); - } } public static class AdvancedBarChart extends CustomChart { @@ -368,7 +366,7 @@ public static class AdvancedBarChart extends CustomChart { /** * Class constructor. * - * @param chartId The id of the chart. + * @param chartId The id of the chart. * @param callable The callable which is used to request the chart data. */ public AdvancedBarChart(String chartId, Callable> callable) { @@ -408,7 +406,7 @@ public static class SimpleBarChart extends CustomChart { /** * Class constructor. * - * @param chartId The id of the chart. + * @param chartId The id of the chart. * @param callable The callable which is used to request the chart data. */ public SimpleBarChart(String chartId, Callable> callable) { @@ -425,7 +423,7 @@ protected JsonObjectBuilder.JsonObject getChartData() throws Exception { return null; } for (Map.Entry entry : map.entrySet()) { - valuesBuilder.appendField(entry.getKey(), new int[] {entry.getValue()}); + valuesBuilder.appendField(entry.getKey(), new int[]{entry.getValue()}); } return new JsonObjectBuilder().appendField("values", valuesBuilder.build()).build(); } @@ -438,7 +436,7 @@ public static class MultiLineChart extends CustomChart { /** * Class constructor. * - * @param chartId The id of the chart. + * @param chartId The id of the chart. * @param callable The callable which is used to request the chart data. */ public MultiLineChart(String chartId, Callable> callable) { @@ -478,7 +476,7 @@ public static class AdvancedPie extends CustomChart { /** * Class constructor. * - * @param chartId The id of the chart. + * @param chartId The id of the chart. * @param callable The callable which is used to request the chart data. */ public AdvancedPie(String chartId, Callable> callable) { @@ -552,7 +550,7 @@ public static class SingleLineChart extends CustomChart { /** * Class constructor. * - * @param chartId The id of the chart. + * @param chartId The id of the chart. * @param callable The callable which is used to request the chart data. */ public SingleLineChart(String chartId, Callable callable) { @@ -578,7 +576,7 @@ public static class SimplePie extends CustomChart { /** * Class constructor. * - * @param chartId The id of the chart. + * @param chartId The id of the chart. * @param callable The callable which is used to request the chart data. */ public SimplePie(String chartId, Callable callable) { @@ -604,7 +602,7 @@ public static class DrilldownPie extends CustomChart { /** * Class constructor. * - * @param chartId The id of the chart. + * @param chartId The id of the chart. * @param callable The callable which is used to request the chart data. */ public DrilldownPie(String chartId, Callable>> callable) { @@ -657,6 +655,34 @@ public JsonObjectBuilder() { builder.append("{"); } + /** + * Escapes the given string like stated in https://www.ietf.org/rfc/rfc4627.txt. + * + *

This method escapes only the necessary characters '"', '\'. and '\u0000' - '\u001F'. + * Compact escapes are not used (e.g., '\n' is escaped as "\u000a" and not as "\n"). + * + * @param value The value to escape. + * @return The escaped value. + */ + private static String escape(String value) { + final StringBuilder builder = new StringBuilder(); + for (int i = 0; i < value.length(); i++) { + char c = value.charAt(i); + if (c == '"') { + builder.append("\\\""); + } else if (c == '\\') { + builder.append("\\\\"); + } else if (c <= '\u000F') { + builder.append("\\u000").append(Integer.toHexString(c)); + } else if (c <= '\u001F') { + builder.append("\\u00").append(Integer.toHexString(c)); + } else { + builder.append(c); + } + } + return builder.toString(); + } + /** * Appends a null field to the JSON. * @@ -671,7 +697,7 @@ public JsonObjectBuilder appendNull(String key) { /** * Appends a string field to the JSON. * - * @param key The key of the field. + * @param key The key of the field. * @param value The value of the field. * @return A reference to this object. */ @@ -686,7 +712,7 @@ public JsonObjectBuilder appendField(String key, String value) { /** * Appends an integer field to the JSON. * - * @param key The key of the field. + * @param key The key of the field. * @param value The value of the field. * @return A reference to this object. */ @@ -698,7 +724,7 @@ public JsonObjectBuilder appendField(String key, int value) { /** * Appends an object to the JSON. * - * @param key The key of the field. + * @param key The key of the field. * @param object The object. * @return A reference to this object. */ @@ -713,7 +739,7 @@ public JsonObjectBuilder appendField(String key, JsonObject object) { /** * Appends a string array to the JSON. * - * @param key The key of the field. + * @param key The key of the field. * @param values The string array. * @return A reference to this object. */ @@ -732,7 +758,7 @@ public JsonObjectBuilder appendField(String key, String[] values) { /** * Appends an integer array to the JSON. * - * @param key The key of the field. + * @param key The key of the field. * @param values The integer array. * @return A reference to this object. */ @@ -749,7 +775,7 @@ public JsonObjectBuilder appendField(String key, int[] values) { /** * Appends an object array to the JSON. * - * @param key The key of the field. + * @param key The key of the field. * @param values The integer array. * @return A reference to this object. */ @@ -766,7 +792,7 @@ public JsonObjectBuilder appendField(String key, JsonObject[] values) { /** * Appends a field to the object. * - * @param key The key of the field. + * @param key The key of the field. * @param escapedValue The escaped value of the field. */ private void appendFieldUnescaped(String key, String escapedValue) { @@ -797,34 +823,6 @@ public JsonObject build() { return object; } - /** - * Escapes the given string like stated in https://www.ietf.org/rfc/rfc4627.txt. - * - *

This method escapes only the necessary characters '"', '\'. and '\u0000' - '\u001F'. - * Compact escapes are not used (e.g., '\n' is escaped as "\u000a" and not as "\n"). - * - * @param value The value to escape. - * @return The escaped value. - */ - private static String escape(String value) { - final StringBuilder builder = new StringBuilder(); - for (int i = 0; i < value.length(); i++) { - char c = value.charAt(i); - if (c == '"') { - builder.append("\\\""); - } else if (c == '\\') { - builder.append("\\\\"); - } else if (c <= '\u000F') { - builder.append("\\u000").append(Integer.toHexString(c)); - } else if (c <= '\u001F') { - builder.append("\\u00").append(Integer.toHexString(c)); - } else { - builder.append(c); - } - } - return builder.toString(); - } - /** * A super simple representation of a JSON object. * diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index 0b282b5..d31cd7a 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -87,8 +87,8 @@ closest-hostile: 0 # This will detach leads when a player enters spectator mode with /s detach-leads: true -# Save mobs. If your server is having lag issues it is advised to turn this on -save-mobs: true +# Save mobs. If your server is having lag issues it is advised to turn this off +mobs: true ### Message section ### #Adding /actionbar/ in front of a message, will make it appear in the actionbar instead of the chat diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index b36f7b2..1e52970 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -2,7 +2,9 @@ name: SpectatorMode version: ${project.version} main: me.ohowe12.spectatormode.SpectatorMode api-version: 1.16 -softdepend: [Multiverse-Core, LuckPerms] +softdepend: [ Multiverse-Core, LuckPerms ] +loadbefore: + - Essentials permissions: spectator.*: @@ -34,4 +36,8 @@ permissions: default: op smpspectator.reload: description: Be able to reload the config - default: op \ No newline at end of file + default: op + +commands: + s: + description: The command for SMP Spectator Mode \ No newline at end of file diff --git a/src/test/java/me/ohowe12/spectatormode/SpectatorManagerTest.java b/src/test/java/me/ohowe12/spectatormode/SpectatorManagerTest.java index eb8c9dc..8c132c9 100644 --- a/src/test/java/me/ohowe12/spectatormode/SpectatorManagerTest.java +++ b/src/test/java/me/ohowe12/spectatormode/SpectatorManagerTest.java @@ -33,9 +33,10 @@ import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -import static org.junit.jupiter.api.Assertions.*; import static me.ohowe12.spectatormode.utils.TestUtils.assertEqualsColored; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; class SpectatorManagerTest { @@ -113,10 +114,12 @@ void testToggleEffectsCommand() { private void assertDoesNotHaveAnyEffects() { assertEquals(0, playerMock.getActivePotionEffects().size()); } + private void assertHasSpectatorEffects() { assertTrue(playerMock.getActivePotionEffects().stream().anyMatch(e -> e.getType() == PotionEffectType.NIGHT_VISION)); assertTrue(playerMock.getActivePotionEffects().stream().anyMatch(e -> e.getType() == PotionEffectType.CONDUIT_POWER)); } + @Test void testTogglePlayerMessageSent() { spectatorManager.togglePlayer(playerMock); @@ -156,7 +159,8 @@ void testTogglePlayerWithBadHealth() { spectatorManager.togglePlayer(playerMock); - assertEqualsColored("&cYou are below the minimum required health to preform this command!", playerMock.nextMessage()); + assertEqualsColored("&cYou are below the minimum required health to preform this command!", + playerMock.nextMessage()); playerMock.assertGameMode(GameMode.SURVIVAL); } @@ -171,5 +175,4 @@ void testTogglePlayerWithBadWorld() { } - } \ No newline at end of file diff --git a/src/test/java/me/ohowe12/spectatormode/context/SpectatorContextCalculatorTest.java b/src/test/java/me/ohowe12/spectatormode/context/SpectatorContextCalculatorTest.java new file mode 100644 index 0000000..ba5ce9c --- /dev/null +++ b/src/test/java/me/ohowe12/spectatormode/context/SpectatorContextCalculatorTest.java @@ -0,0 +1,48 @@ +package me.ohowe12.spectatormode.context; + +import me.ohowe12.spectatormode.SpectatorManager; +import me.ohowe12.spectatormode.SpectatorMode; +import me.ohowe12.spectatormode.state.StateHolder; +import me.ohowe12.spectatormode.utils.mocks.ContextConsumerMock; +import net.luckperms.api.context.ContextConsumer; +import org.bukkit.entity.Player; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.ValueSource; + +import static org.mockito.Mockito.*; + +class SpectatorContextCalculatorTest { + + private static SpectatorContextCalculator spectatorContextCalculator; + + private static SpectatorMode pluginMock; + private static SpectatorManager spectatorManagerMock; + private static StateHolder stateHolderMock; + private static Player playerMock; + private static ContextConsumer contextConsumerMock; + + @BeforeAll + public static void setUp() { + pluginMock = mock(SpectatorMode.class); + spectatorManagerMock = mock(SpectatorManager.class); + stateHolderMock = mock(StateHolder.class); + playerMock = mock(Player.class); + contextConsumerMock = mock(ContextConsumerMock.class); + + + when(pluginMock.getSpectatorManager()).thenReturn(spectatorManagerMock); + when(spectatorManagerMock.getStateHolder()).thenReturn(stateHolderMock); + + spectatorContextCalculator = new SpectatorContextCalculator(pluginMock); + } + + @ParameterizedTest + @ValueSource(booleans = {true, false}) + void testCalculate(boolean inState) { + when(stateHolderMock.hasPlayer(playerMock)).thenReturn(inState); + + spectatorContextCalculator.calculate(playerMock, contextConsumerMock); + verify(contextConsumerMock, times(1)).accept("SMP Spectator", String.valueOf(inState)); + } +} \ No newline at end of file diff --git a/src/test/java/me/ohowe12/spectatormode/listener/OnCommandPreprocessListenerTest.java b/src/test/java/me/ohowe12/spectatormode/listener/OnCommandPreprocessListenerTest.java index dd82e9d..e28176e 100644 --- a/src/test/java/me/ohowe12/spectatormode/listener/OnCommandPreprocessListenerTest.java +++ b/src/test/java/me/ohowe12/spectatormode/listener/OnCommandPreprocessListenerTest.java @@ -11,9 +11,10 @@ import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -import static org.junit.jupiter.api.Assertions.*; import static me.ohowe12.spectatormode.utils.TestUtils.assertEqualsColored; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; class OnCommandPreprocessListenerTest { ServerMock serverMock; @@ -74,13 +75,27 @@ void testDisabledCommandWithOverridePermission() { @Test void testCommandWithSemiColon() { assert playerMock != null; - PlayerCommandPreprocessEvent otherEvent = new PlayerCommandPreprocessEvent(playerMock, "/exampleplugin:testcommand"); + PlayerCommandPreprocessEvent otherEvent = new PlayerCommandPreprocessEvent(playerMock, "/exampleplugin" + + ":testcommand"); new OnCommandPreprocessListener(plugin).onCommandEvent(otherEvent); assertEqualsColored("&cYou can not execute that command while in spectator mode", playerMock.nextMessage()); assertTrue(otherEvent.isCancelled()); } + @Test + void testWhenNotInState() { + assert playerMock != null; + // Put into survival + spectatorManager.togglePlayer(playerMock); + playerMock.nextMessage(); + + new OnCommandPreprocessListener(plugin).onCommandEvent(event); + + playerMock.assertNoMoreSaid(); + assertFalse(event.isCancelled()); + } + @Test void testJustSlash() { // here to just make sure we dont get index out of bounds or something like that diff --git a/src/test/java/me/ohowe12/spectatormode/listener/OnMoveListenerTest.java b/src/test/java/me/ohowe12/spectatormode/listener/OnMoveListenerTest.java index 569269d..8893ce6 100644 --- a/src/test/java/me/ohowe12/spectatormode/listener/OnMoveListenerTest.java +++ b/src/test/java/me/ohowe12/spectatormode/listener/OnMoveListenerTest.java @@ -2,13 +2,18 @@ import be.seeseemelk.mockbukkit.MockBukkit; import be.seeseemelk.mockbukkit.ServerMock; +import be.seeseemelk.mockbukkit.WorldMock; import be.seeseemelk.mockbukkit.entity.PlayerMock; -import me.ohowe12.spectatormode.SpectatorManager; import me.ohowe12.spectatormode.SpectatorMode; +import me.ohowe12.spectatormode.utils.TestUtils; import org.bukkit.GameMode; +import org.bukkit.Location; +import org.bukkit.event.player.PlayerMoveEvent; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.ValueSource; import static org.junit.jupiter.api.Assertions.*; @@ -17,8 +22,8 @@ class OnMoveListenerTest { ServerMock serverMock; SpectatorMode plugin; + // Default player location is 0, 5, 0 PlayerMock playerMock; - SpectatorManager spectatorManager; @BeforeEach void setUp() { @@ -31,7 +36,7 @@ void setUp() { plugin.reloadConfig(); - spectatorManager = plugin.getSpectatorManager(); + plugin.getSpectatorManager().togglePlayer(playerMock); } @AfterEach @@ -39,5 +44,32 @@ void tearDown() { MockBukkit.unmock(); } + @ParameterizedTest + @ValueSource(ints = {-3, -5, -6}) + void testEnabledAndBadYLevel(int shift) { + TestUtils.setConfigFileOfPlugin(plugin, "badylevel.yml"); + + playerMock.simulatePlayerMove(playerMock.getLocation().add(0, shift, 0)); + + assertMoveEventCanceled(); + } + + @ParameterizedTest + @ValueSource(ints = {-2, 1}) + void testEnabledAndGoodYLevel(int shift) { + TestUtils.setConfigFileOfPlugin(plugin, "badylevel.yml"); + + playerMock.simulatePlayerMove(playerMock.getLocation().add(0, -shift, 0)); + + assertMoveEventNotCanceled(); + } + + private void assertMoveEventCanceled() { + assertEquals(playerMock.getWorld().getSpawnLocation(), playerMock.getLocation()); + } + private void assertMoveEventNotCanceled() { + assertNotEquals(playerMock.getWorld().getSpawnLocation(), playerMock.getLocation()); + } + } \ No newline at end of file diff --git a/src/test/java/me/ohowe12/spectatormode/utils/TestUtils.java b/src/test/java/me/ohowe12/spectatormode/utils/TestUtils.java index e781909..4ae3ba9 100644 --- a/src/test/java/me/ohowe12/spectatormode/utils/TestUtils.java +++ b/src/test/java/me/ohowe12/spectatormode/utils/TestUtils.java @@ -38,7 +38,8 @@ public static void assertEqualsColored(String expected, String actual) { } public static void setConfigFileOfPlugin(SpectatorMode plugin, String configName) { - FileConfiguration configuration = YamlConfiguration.loadConfiguration(new File("src/test/resources/configs/" + configName)); + FileConfiguration configuration = + YamlConfiguration.loadConfiguration(new File("src/test/resources/configs/" + configName)); configuration.setDefaults(plugin.getConfig()); plugin.setConfigManagerConfigFile(configuration); } diff --git a/src/test/java/me/ohowe12/spectatormode/utils/mocks/ContextConsumerMock.java b/src/test/java/me/ohowe12/spectatormode/utils/mocks/ContextConsumerMock.java new file mode 100644 index 0000000..c931651 --- /dev/null +++ b/src/test/java/me/ohowe12/spectatormode/utils/mocks/ContextConsumerMock.java @@ -0,0 +1,10 @@ +package me.ohowe12.spectatormode.utils.mocks; + +import net.luckperms.api.context.ContextConsumer; + +public class ContextConsumerMock implements ContextConsumer { + @Override + public void accept(String s, String s1) { + // here to be mocked + } +} diff --git a/src/test/resources/configs/badhealth.yml b/src/test/resources/configs/badhealth.yml index 2298187..07a7f32 100644 --- a/src/test/resources/configs/badhealth.yml +++ b/src/test/resources/configs/badhealth.yml @@ -1,51 +1,4 @@ # config file for SpectatorManagerTest#testTogglePlayerWithBadHealth -enabled: true -speed: true -night-vision: true -conduit: true -max-speed: 5 -teleport-back: false -seffect: true -enforce-worlds: false -worlds-allowed: [ world, world_nether, world_the_end ] -enforce-y: false -y-level: 0 -disallow-non-transparent-blocks: false -disallow-all-blocks: false -disallowed-blocks: [ ] -bubble-size: 35 -enforce-distance: false -distance: 64 # Changes health -minimum-health: 5 -prevent-teleport: false -bad-commands: [ ] -enforce-world-border: true -disable-switching-message: false -silence-survival-mode-message-on-join: true -placeholder-mob: false -update-checker: true -closest-hostile: 0 -detach-leads: true -spectator-mode-message: '&9Setting gamemode to &b&lSPECTATOR MODE' -survival-mode-message: '&9Setting gamemode to &b&lSURVIVAL MODE' -falling-message: '&cHey you &lcan not &r&cdo that while falling!' -world-message: '&cHey you&l can not &r&cdo that in that world!' -health-message: '&cYou are below the minimum required health to preform this command!' -permission-message: '&cYou do not have permission to do that!' -disabled-message: '&cSpectator Mode is &lnot &r&cenabled by the server!' -console-message: '&cYou are &lnot &ca player!' -disable-message: '&dSpectator mode has been &ldisabled' -enable-message: '&dSpectator mode has been &lenabled' -reload-message: '&bThe config file has been reloaded!' -speed-message: '&bSpeed has been set to ' -invalid-speed-message: '&cThat is not a valid speed' -invalid-player-message: '&cThat is not a valid player' -force-success: '&bSuccessfully forced /target/ into ' -force-fail: '&cFailed to force /target/ into ' -no-spectator-message: '&cYou did not preform the /s command' -bad-command-message: '&cYou can not execute that command while in spectator mode' -not-in-state-message: '&cYou did not use this command to get into spectator mode!' -mob-to-close-message: '&cYou are to close to a hostile mob to enter spectator mode' -debug: false \ No newline at end of file +minimum-health: 5 \ No newline at end of file diff --git a/src/test/resources/configs/badworld.yml b/src/test/resources/configs/badworld.yml index d81f75b..c609c1b 100644 --- a/src/test/resources/configs/badworld.yml +++ b/src/test/resources/configs/badworld.yml @@ -1,51 +1,5 @@ # config file for SpectatorManagerTest#testTogglePlayerWithBadWorld -enabled: true -speed: true -night-vision: true -conduit: true -max-speed: 5 -teleport-back: false -seffect: true # Changed worlds and worlds-allowed enforce-worlds: true worlds-allowed: [ aworldyouarenotin ] -enforce-y: false -y-level: 0 -disallow-non-transparent-blocks: false -disallow-all-blocks: false -disallowed-blocks: [ ] -bubble-size: 35 -enforce-distance: false -distance: 64 -minimum-health: 0 -prevent-teleport: false -bad-commands: [ ] -enforce-world-border: true -disable-switching-message: false -silence-survival-mode-message-on-join: true -placeholder-mob: false -update-checker: true -closest-hostile: 0 -detach-leads: true -spectator-mode-message: '&9Setting gamemode to &b&lSPECTATOR MODE' -survival-mode-message: '&9Setting gamemode to &b&lSURVIVAL MODE' -falling-message: '&cHey you &lcan not &r&cdo that while falling!' -world-message: '&cHey you&l can not &r&cdo that in that world!' -health-message: '&cYou are below the minimum required health to preform this command!' -permission-message: '&cYou do not have permission to do that!' -disabled-message: '&cSpectator Mode is &lnot &r&cenabled by the server!' -console-message: '&cYou are &lnot &ca player!' -disable-message: '&dSpectator mode has been &ldisabled' -enable-message: '&dSpectator mode has been &lenabled' -reload-message: '&bThe config file has been reloaded!' -speed-message: '&bSpeed has been set to ' -invalid-speed-message: '&cThat is not a valid speed' -invalid-player-message: '&cThat is not a valid player' -force-success: '&bSuccessfully forced /target/ into ' -force-fail: '&cFailed to force /target/ into ' -no-spectator-message: '&cYou did not preform the /s command' -bad-command-message: '&cYou can not execute that command while in spectator mode' -not-in-state-message: '&cYou did not use this command to get into spectator mode!' -mob-to-close-message: '&cYou are to close to a hostile mob to enter spectator mode' -debug: false \ No newline at end of file diff --git a/src/test/resources/configs/badylevel.yml b/src/test/resources/configs/badylevel.yml new file mode 100644 index 0000000..641f63d --- /dev/null +++ b/src/test/resources/configs/badylevel.yml @@ -0,0 +1,2 @@ +enforce-y: true +y-level: 2 \ No newline at end of file diff --git a/src/test/resources/configs/disabledcommands.yml b/src/test/resources/configs/disabledcommands.yml index e41a4c0..4f6f3b2 100644 --- a/src/test/resources/configs/disabledcommands.yml +++ b/src/test/resources/configs/disabledcommands.yml @@ -1,50 +1,2 @@ # config file for OnCommandPreprocessListenerTest - -enabled: true -speed: true -night-vision: true -conduit: true -max-speed: 5 -teleport-back: false -seffect: true -enforce-worlds: false -worlds-allowed: [ world, world_nether, world_the_end ] -enforce-y: false -y-level: 0 -disallow-non-transparent-blocks: false -disallow-all-blocks: false -disallowed-blocks: [ ] -bubble-size: 35 -enforce-distance: false -distance: 64 -minimum-health: 0 -prevent-teleport: false -bad-commands: [ 'testcommand' ] -enforce-world-border: true -disable-switching-message: false -silence-survival-mode-message-on-join: true -placeholder-mob: false -update-checker: true -closest-hostile: 0 -detach-leads: true -spectator-mode-message: '&9Setting gamemode to &b&lSPECTATOR MODE' -survival-mode-message: '&9Setting gamemode to &b&lSURVIVAL MODE' -falling-message: '&cHey you &lcan not &r&cdo that while falling!' -world-message: '&cHey you&l can not &r&cdo that in that world!' -health-message: '&cYou are below the minimum required health to preform this command!' -permission-message: '&cYou do not have permission to do that!' -disabled-message: '&cSpectator Mode is &lnot &r&cenabled by the server!' -console-message: '&cYou are &lnot &ca player!' -disable-message: '&dSpectator mode has been &ldisabled' -enable-message: '&dSpectator mode has been &lenabled' -reload-message: '&bThe config file has been reloaded!' -speed-message: '&bSpeed has been set to ' -invalid-speed-message: '&cThat is not a valid speed' -invalid-player-message: '&cThat is not a valid player' -force-success: '&bSuccessfully forced /target/ into ' -force-fail: '&cFailed to force /target/ into ' -no-spectator-message: '&cYou did not preform the /s command' -bad-command-message: '&cYou can not execute that command while in spectator mode' -not-in-state-message: '&cYou did not use this command to get into spectator mode!' -mob-to-close-message: '&cYou are to close to a hostile mob to enter spectator mode' -debug: false \ No newline at end of file +bad-commands: [ 'testcommand' ] \ No newline at end of file diff --git a/src/test/resources/configs/disabledeffects.yml b/src/test/resources/configs/disabledeffects.yml index c8b9365..be6b2a9 100644 --- a/src/test/resources/configs/disabledeffects.yml +++ b/src/test/resources/configs/disabledeffects.yml @@ -1,51 +1,3 @@ # config file for SpectatorManagerTest#testNotGivenEffectsWhenDisabled - -enabled: true -speed: true -# Changes here night-vision: false -conduit: false -max-speed: 5 -teleport-back: false -seffect: true -enforce-worlds: false -worlds-allowed: [ world, world_nether, world_the_end ] -enforce-y: false -y-level: 0 -disallow-non-transparent-blocks: false -disallow-all-blocks: false -disallowed-blocks: [ ] -bubble-size: 35 -enforce-distance: false -distance: 64 -minimum-health: 0 -prevent-teleport: false -bad-commands: [ ] -enforce-world-border: true -disable-switching-message: false -silence-survival-mode-message-on-join: true -placeholder-mob: false -update-checker: true -closest-hostile: 0 -detach-leads: true -spectator-mode-message: '&9Setting gamemode to &b&lSPECTATOR MODE' -survival-mode-message: '&9Setting gamemode to &b&lSURVIVAL MODE' -falling-message: '&cHey you &lcan not &r&cdo that while falling!' -world-message: '&cHey you&l can not &r&cdo that in that world!' -health-message: '&cYou are below the minimum required health to preform this command!' -permission-message: '&cYou do not have permission to do that!' -disabled-message: '&cSpectator Mode is &lnot &r&cenabled by the server!' -console-message: '&cYou are &lnot &ca player!' -disable-message: '&dSpectator mode has been &ldisabled' -enable-message: '&dSpectator mode has been &lenabled' -reload-message: '&bThe config file has been reloaded!' -speed-message: '&bSpeed has been set to ' -invalid-speed-message: '&cThat is not a valid speed' -invalid-player-message: '&cThat is not a valid player' -force-success: '&bSuccessfully forced /target/ into ' -force-fail: '&cFailed to force /target/ into ' -no-spectator-message: '&cYou did not preform the /s command' -bad-command-message: '&cYou can not execute that command while in spectator mode' -not-in-state-message: '&cYou did not use this command to get into spectator mode!' -mob-to-close-message: '&cYou are to close to a hostile mob to enter spectator mode' -debug: false \ No newline at end of file +conduit: false \ No newline at end of file