diff --git a/.gitignore b/.gitignore index 44ea237797a..5df22e6732b 100644 --- a/.gitignore +++ b/.gitignore @@ -25,6 +25,8 @@ out/ build/ target/ *.class +build-logic/.kotlin/ +build-logic/bin/ # Run directory /run/ diff --git a/Essentials/build.gradle b/Essentials/build.gradle index 2cf2c028e74..4e04f09320a 100644 --- a/Essentials/build.gradle +++ b/Essentials/build.gradle @@ -14,21 +14,25 @@ dependencies { implementation 'org.checkerframework:checker-qual:3.49.0' implementation 'nu.studer:java-ordered-properties:1.0.4' - implementation 'net.kyori:adventure-api:4.21.0' - implementation 'net.kyori:adventure-text-minimessage:4.21.0' + implementation 'net.kyori:adventure-api:4.23.0' + implementation 'net.kyori:adventure-text-minimessage:4.23.0' implementation 'net.kyori:adventure-platform-bukkit:4.4.0' // Providers - api project(':providers:BaseProviders') - api project(path: ':providers:PaperProvider', configuration: 'shadow') + api(project(':providers:BaseProviders')) { + exclude(module: 'spigot-api') + } + api(project(path: ':providers:PaperProvider', configuration: 'shadow')){ + exclude(module: 'paper-api') + } api(project(':providers:NMSReflectionProvider')) { - exclude group: "org.bukkit", module: "bukkit" + exclude(module: 'bukkit') } api(project(':providers:1_8Provider')) { - exclude group: "org.spigotmc", module: "spigot" + exclude(module: 'spigot-api') } api(project(':providers:1_12Provider')) { - exclude group: "org.bukkit", module: "bukkit" + exclude(module: 'bukkit') } } diff --git a/Essentials/src/main/java/com/earth2me/essentials/Essentials.java b/Essentials/src/main/java/com/earth2me/essentials/Essentials.java index 39c7a596612..fe58510a17c 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/Essentials.java +++ b/Essentials/src/main/java/com/earth2me/essentials/Essentials.java @@ -66,7 +66,6 @@ import net.ess3.provider.ServerStateProvider; import net.ess3.provider.providers.BaseBannerDataProvider; import net.ess3.provider.providers.BaseInventoryViewProvider; -import net.ess3.provider.providers.BaseLoggerProvider; import net.ess3.provider.providers.BlockMetaSpawnerItemProvider; import net.ess3.provider.providers.BukkitMaterialTagProvider; import net.ess3.provider.providers.BukkitSpawnerBlockProvider; @@ -120,18 +119,13 @@ import org.bukkit.event.player.PlayerJoinEvent; import org.bukkit.event.world.WorldLoadEvent; import org.bukkit.inventory.InventoryView; -import org.bukkit.plugin.InvalidDescriptionException; import org.bukkit.plugin.Plugin; -import org.bukkit.plugin.PluginDescriptionFile; import org.bukkit.plugin.PluginManager; import org.bukkit.plugin.ServicePriority; import org.bukkit.plugin.java.JavaPlugin; -import org.bukkit.plugin.java.JavaPluginLoader; import org.bukkit.scheduler.BukkitScheduler; import org.bukkit.scheduler.BukkitTask; -import java.io.File; -import java.io.IOException; import java.util.ArrayList; import java.util.Collection; import java.util.Collections; @@ -187,52 +181,11 @@ public class Essentials extends JavaPlugin implements net.ess3.api.IEssentials { EconomyLayers.init(); } - public Essentials() { - } - - protected Essentials(final JavaPluginLoader loader, final PluginDescriptionFile description, final File dataFolder, final File file) { - super(loader, description, dataFolder, file); - } - - public Essentials(final Server server) { - super(new JavaPluginLoader(server), new PluginDescriptionFile("Essentials", "", "com.earth2me.essentials.Essentials"), null, null); - } - @Override public ISettings getSettings() { return settings; } - public void setupForTesting(final Server server) throws IOException, InvalidDescriptionException { - TESTING = true; - LOGGER = new BaseLoggerProvider(this, BUKKIT_LOGGER); - final File dataFolder = File.createTempFile("essentialstest", ""); - if (!dataFolder.delete()) { - throw new IOException(); - } - if (!dataFolder.mkdir()) { - throw new IOException(); - } - i18n = new I18n(this); - i18n.onEnable(); - i18n.updateLocale("en"); - Console.setInstance(this); - - LOGGER.log(Level.INFO, AdventureUtil.miniToLegacy(tlLiteral("usingTempFolderForTesting"))); - LOGGER.log(Level.INFO, dataFolder.toString()); - settings = new Settings(this); - mail = new MailServiceImpl(this); - userMap = new ModernUserMap(this); - balanceTop = new BalanceTopImpl(this); - permissionsHandler = new PermissionsHandler(this, false); - Economy.setEss(this); - confList = new ArrayList<>(); - jails = new Jails(this); - registerListeners(server.getPluginManager()); - kits = new Kits(this); - bukkitAudience = BukkitAudiences.create(this); - } - @Override public void onLoad() { try { @@ -426,7 +379,9 @@ public void onEnable() { // Tick Count Provider providerFactory.registerProvider(PaperTickCountProvider.class); - providerFactory.finalizeRegistration(); + if (!TESTING) { + providerFactory.finalizeRegistration(); + } // Event Providers if (PaperLib.isPaper()) { @@ -464,15 +419,17 @@ public void onEnable() { PermissionsDefaults.registerAllBackDefaults(); PermissionsDefaults.registerAllHatDefaults(); - updateChecker = new UpdateChecker(this); - runTaskAsynchronously(() -> { - getLogger().log(Level.INFO, AdventureUtil.miniToLegacy(tlLiteral("versionFetching"))); - for (final Component component : updateChecker.getVersionMessages(false, true, new CommandSource(this, Bukkit.getConsoleSender()))) { - getLogger().log(getSettings().isUpdateCheckEnabled() ? Level.WARNING : Level.INFO, AdventureUtil.adventureToLegacy(component)); - } - }); + if (!TESTING) { + updateChecker = new UpdateChecker(this); + runTaskAsynchronously(() -> { + getLogger().log(Level.INFO, AdventureUtil.miniToLegacy(tlLiteral("versionFetching"))); + for (final Component component : updateChecker.getVersionMessages(false, true, new CommandSource(this, Bukkit.getConsoleSender()))) { + getLogger().log(getSettings().isUpdateCheckEnabled() ? Level.WARNING : Level.INFO, AdventureUtil.adventureToLegacy(component)); + } + }); - metrics = new MetricsWrapper(this, 858, true); + metrics = new MetricsWrapper(this, 858, true); + } execTimer.mark("Init(External)"); @@ -486,7 +443,9 @@ public void onEnable() { handleCrash(ex); throw ex; } - getBackup().setPendingShutdown(false); + if (!TESTING) { + getBackup().setPendingShutdown(false); + } } // Returns our provider logger if available @@ -554,11 +513,19 @@ public ProviderFactory getProviders() { @Override public void onDisable() { - final boolean stopping = provider(ServerStateProvider.class).isStopping(); + if (bukkitAudience != null) { + bukkitAudience.close(); + } + + final boolean stopping = TESTING || provider(ServerStateProvider.class).isStopping(); if (!stopping) { LOGGER.log(Level.SEVERE, AdventureUtil.miniToLegacy(tlLiteral("serverReloading"))); } - getBackup().setPendingShutdown(true); + + if (!TESTING) { + getBackup().setPendingShutdown(true); + } + for (final User user : getOnlineUsers()) { if (user.isVanished()) { user.setVanished(false); @@ -575,7 +542,7 @@ public void onDisable() { } } cleanupOpenInventories(); - if (getBackup().getTaskLock() != null && !getBackup().getTaskLock().isDone()) { + if (!TESTING && getBackup().getTaskLock() != null && !getBackup().getTaskLock().isDone()) { LOGGER.log(Level.SEVERE, AdventureUtil.miniToLegacy(tlLiteral("backupInProgress"))); getBackup().getTaskLock().join(); } @@ -586,9 +553,12 @@ public void onDisable() { backup.stopTask(); } - this.getPermissionsHandler().unregisterContexts(); + if (!TESTING) { + this.getPermissionsHandler().unregisterContexts(); + } Economy.setEss(null); + AdventureUtil.setEss(null); Trade.closeLog(); getUsers().shutdown(); diff --git a/Essentials/src/main/java/com/earth2me/essentials/Mob.java b/Essentials/src/main/java/com/earth2me/essentials/Mob.java index b9085b84b5d..9ddb0c0d2f4 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/Mob.java +++ b/Essentials/src/main/java/com/earth2me/essentials/Mob.java @@ -124,7 +124,8 @@ public enum Mob { ARMADILLO("Armadillo", Enemies.FRIENDLY, "ARMADILLO"), BREEZE("Breeze", Enemies.ENEMY, "BREEZE"), BOGGED("Bogged", Enemies.ENEMY, "BOGGED"), - CREAKING("Creaking", Enemies.ENEMY, "CREAKING") + CREAKING("Creaking", Enemies.ENEMY, "CREAKING"), + HAPPY_GHAST("HappyGhast", Enemies.FRIENDLY, "HAPPY_GHAST") ; private static final Map hashMap = new HashMap<>(); diff --git a/Essentials/src/main/java/com/earth2me/essentials/User.java b/Essentials/src/main/java/com/earth2me/essentials/User.java index 72f6feaad6c..d529a96d101 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/User.java +++ b/Essentials/src/main/java/com/earth2me/essentials/User.java @@ -136,6 +136,10 @@ public boolean isAuthorized(final IEssentialsCommand cmd, final String permissio @Override public boolean isAuthorized(final String node) { + if (Essentials.TESTING) { + return false; + } + final boolean result = isAuthorizedCheck(node); if (ess.getSettings().isDebug()) { ess.getLogger().log(Level.INFO, "checking if " + base.getName() + " has " + node + " - " + result); @@ -145,6 +149,10 @@ public boolean isAuthorized(final String node) { @Override public boolean isPermissionSet(final String node) { + if (Essentials.TESTING) { + return false; + } + final boolean result = isPermSetCheck(node); if (ess.getSettings().isDebug()) { ess.getLogger().log(Level.INFO, "checking if " + base.getName() + " has " + node + " (set-explicit) - " + result); diff --git a/Essentials/src/main/java/com/earth2me/essentials/utils/VersionUtil.java b/Essentials/src/main/java/com/earth2me/essentials/utils/VersionUtil.java index 790ddc349c9..b7a3684820a 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/utils/VersionUtil.java +++ b/Essentials/src/main/java/com/earth2me/essentials/utils/VersionUtil.java @@ -42,8 +42,9 @@ public final class VersionUtil { public static final BukkitVersion v1_21_R01 = BukkitVersion.fromString("1.21-R0.1-SNAPSHOT"); public static final BukkitVersion v1_21_3_R01 = BukkitVersion.fromString("1.21.3-R0.1-SNAPSHOT"); public static final BukkitVersion v1_21_5_R01 = BukkitVersion.fromString("1.21.5-R0.1-SNAPSHOT"); + public static final BukkitVersion v1_21_6_R01 = BukkitVersion.fromString("1.21.6-R0.1-SNAPSHOT"); - private static final Set supportedVersions = ImmutableSet.of(v1_8_8_R01, v1_9_4_R01, v1_10_2_R01, v1_11_2_R01, v1_12_2_R01, v1_13_2_R01, v1_14_4_R01, v1_15_2_R01, v1_16_5_R01, v1_17_1_R01, v1_18_2_R01, v1_19_4_R01, v1_20_6_R01, v1_21_5_R01); + private static final Set supportedVersions = ImmutableSet.of(v1_8_8_R01, v1_9_4_R01, v1_10_2_R01, v1_11_2_R01, v1_12_2_R01, v1_13_2_R01, v1_14_4_R01, v1_15_2_R01, v1_16_5_R01, v1_17_1_R01, v1_18_2_R01, v1_19_4_R01, v1_20_6_R01, v1_21_6_R01); public static final boolean PRE_FLATTENING = VersionUtil.getServerBukkitVersion().isLowerThan(VersionUtil.v1_13_0_R01); diff --git a/Essentials/src/main/resources/items.json b/Essentials/src/main/resources/items.json index 8efb97205cb..73564a64293 100644 --- a/Essentials/src/main/resources/items.json +++ b/Essentials/src/main/resources/items.json @@ -1774,6 +1774,13 @@ "blagtcotta": "black_glazed_terracotta", "blagterra": "black_glazed_terracotta", "minecraft:black_glazed_terracotta": "black_glazed_terracotta", + "black_harness": { + "material": "BLACK_HARNESS" + }, + "bkharness": "black_harness", + "blackharness": "black_harness", + "blaharness": "black_harness", + "minecraft:black_harness": "black_harness", "black_shulker_box": { "material": "BLACK_SHULKER_BOX" }, @@ -2024,6 +2031,12 @@ "blugtcotta": "blue_glazed_terracotta", "blugterra": "blue_glazed_terracotta", "minecraft:blue_glazed_terracotta": "blue_glazed_terracotta", + "blue_harness": { + "material": "BLUE_HARNESS" + }, + "blueharness": "blue_harness", + "bluharness": "blue_harness", + "minecraft:blue_harness": "blue_harness", "blue_ice": { "material": "BLUE_ICE" }, @@ -2354,6 +2367,13 @@ "browngtcotta": "brown_glazed_terracotta", "browngterra": "brown_glazed_terracotta", "minecraft:brown_glazed_terracotta": "brown_glazed_terracotta", + "brown_harness": { + "material": "BROWN_HARNESS" + }, + "brharness": "brown_harness", + "broharness": "brown_harness", + "brownharness": "brown_harness", + "minecraft:brown_harness": "brown_harness", "brown_mushroom": { "material": "BROWN_MUSHROOM" }, @@ -5151,6 +5171,12 @@ "cyangtcotta": "cyan_glazed_terracotta", "cyangterra": "cyan_glazed_terracotta", "minecraft:cyan_glazed_terracotta": "cyan_glazed_terracotta", + "cyan_harness": { + "material": "CYAN_HARNESS" + }, + "charness": "cyan_harness", + "cyanharness": "cyan_harness", + "minecraft:cyan_harness": "cyan_harness", "cyan_shulker_box": { "material": "CYAN_SHULKER_BOX" }, @@ -6448,6 +6474,15 @@ }, "dragonhead": "dragon_head", "minecraft:dragon_head": "dragon_head", + "dried_ghast": { + "material": "DRIED_GHAST" + }, + "driedg": "dried_ghast", + "driedghast": "dried_ghast", + "dryghast": "dried_ghast", + "ghastb": "dried_ghast", + "ghastblock": "dried_ghast", + "minecraft:dried_ghast": "dried_ghast", "dried_kelp": { "material": "DRIED_KELP" }, @@ -8374,6 +8409,19 @@ "greygtcotta": "gray_glazed_terracotta", "greygterra": "gray_glazed_terracotta", "minecraft:gray_glazed_terracotta": "gray_glazed_terracotta", + "gray_harness": { + "material": "GRAY_HARNESS" + }, + "darkgraharness": "gray_harness", + "darkgrayharness": "gray_harness", + "darkgreyharness": "gray_harness", + "dgraharness": "gray_harness", + "dgrayharness": "gray_harness", + "dgreyharness": "gray_harness", + "graharness": "gray_harness", + "grayharness": "gray_harness", + "greyharness": "gray_harness", + "minecraft:gray_harness": "gray_harness", "gray_shulker_box": { "material": "GRAY_SHULKER_BOX" }, @@ -8718,6 +8766,16 @@ "gregtcotta": "green_glazed_terracotta", "gregterra": "green_glazed_terracotta", "minecraft:green_glazed_terracotta": "green_glazed_terracotta", + "green_harness": { + "material": "GREEN_HARNESS" + }, + "darkgreenharness": "green_harness", + "darkgreharness": "green_harness", + "dgreenharness": "green_harness", + "dgreharness": "green_harness", + "greenharness": "green_harness", + "greharness": "green_harness", + "minecraft:green_harness": "green_harness", "green_shulker_box": { "material": "GREEN_SHULKER_BOX" }, @@ -8923,6 +8981,94 @@ "hangroots": "hanging_roots", "hroots": "hanging_roots", "minecraft:hanging_roots": "hanging_roots", + "happy_ghast_spawn_egg": { + "material": "HAPPY_GHAST_SPAWN_EGG" + }, + "eggghastling": "happy_ghast_spawn_egg", + "egghappy_ghast": "happy_ghast_spawn_egg", + "egghappyg": "happy_ghast_spawn_egg", + "egghappyghast": "happy_ghast_spawn_egg", + "egghghast": "happy_ghast_spawn_egg", + "ghastlingegg": "happy_ghast_spawn_egg", + "ghastlingsegg": "happy_ghast_spawn_egg", + "ghastlingspawn": "happy_ghast_spawn_egg", + "ghastlingspawnegg": "happy_ghast_spawn_egg", + "happy_ghastegg": "happy_ghast_spawn_egg", + "happy_ghastsegg": "happy_ghast_spawn_egg", + "happy_ghastspawn": "happy_ghast_spawn_egg", + "happy_ghastspawnegg": "happy_ghast_spawn_egg", + "happygegg": "happy_ghast_spawn_egg", + "happyghastegg": "happy_ghast_spawn_egg", + "happyghastsegg": "happy_ghast_spawn_egg", + "happyghastspawn": "happy_ghast_spawn_egg", + "happyghastspawnegg": "happy_ghast_spawn_egg", + "happygsegg": "happy_ghast_spawn_egg", + "happygspawn": "happy_ghast_spawn_egg", + "happygspawnegg": "happy_ghast_spawn_egg", + "hghastegg": "happy_ghast_spawn_egg", + "hghastsegg": "happy_ghast_spawn_egg", + "hghastspawn": "happy_ghast_spawn_egg", + "hghastspawnegg": "happy_ghast_spawn_egg", + "minecraft:happy_ghast_spawn_egg": "happy_ghast_spawn_egg", + "seggghastling": "happy_ghast_spawn_egg", + "segghappy_ghast": "happy_ghast_spawn_egg", + "segghappyg": "happy_ghast_spawn_egg", + "segghappyghast": "happy_ghast_spawn_egg", + "segghghast": "happy_ghast_spawn_egg", + "spawneggghastling": "happy_ghast_spawn_egg", + "spawnegghappy_ghast": "happy_ghast_spawn_egg", + "spawnegghappyg": "happy_ghast_spawn_egg", + "spawnegghappyghast": "happy_ghast_spawn_egg", + "spawnegghghast": "happy_ghast_spawn_egg", + "spawnghastling": "happy_ghast_spawn_egg", + "spawnhappy_ghast": "happy_ghast_spawn_egg", + "spawnhappyg": "happy_ghast_spawn_egg", + "spawnhappyghast": "happy_ghast_spawn_egg", + "spawnhghast": "happy_ghast_spawn_egg", + "happy_ghast_spawner": { + "entity": "HAPPY_GHAST", + "material": "SPAWNER" + }, + "ghastlingcage": "happy_ghast_spawner", + "ghastlingmcage": "happy_ghast_spawner", + "ghastlingmobcage": "happy_ghast_spawner", + "ghastlingmobspawner": "happy_ghast_spawner", + "ghastlingmonstercage": "happy_ghast_spawner", + "ghastlingmonsterspawner": "happy_ghast_spawner", + "ghastlingmspawner": "happy_ghast_spawner", + "ghastlingspawner": "happy_ghast_spawner", + "happy_ghastcage": "happy_ghast_spawner", + "happy_ghastmcage": "happy_ghast_spawner", + "happy_ghastmobcage": "happy_ghast_spawner", + "happy_ghastmobspawner": "happy_ghast_spawner", + "happy_ghastmonstercage": "happy_ghast_spawner", + "happy_ghastmonsterspawner": "happy_ghast_spawner", + "happy_ghastmspawner": "happy_ghast_spawner", + "happy_ghastspawner": "happy_ghast_spawner", + "happygcage": "happy_ghast_spawner", + "happyghastcage": "happy_ghast_spawner", + "happyghastmcage": "happy_ghast_spawner", + "happyghastmobcage": "happy_ghast_spawner", + "happyghastmobspawner": "happy_ghast_spawner", + "happyghastmonstercage": "happy_ghast_spawner", + "happyghastmonsterspawner": "happy_ghast_spawner", + "happyghastmspawner": "happy_ghast_spawner", + "happyghastspawner": "happy_ghast_spawner", + "happygmcage": "happy_ghast_spawner", + "happygmobcage": "happy_ghast_spawner", + "happygmobspawner": "happy_ghast_spawner", + "happygmonstercage": "happy_ghast_spawner", + "happygmonsterspawner": "happy_ghast_spawner", + "happygmspawner": "happy_ghast_spawner", + "happygspawner": "happy_ghast_spawner", + "hghastcage": "happy_ghast_spawner", + "hghastmcage": "happy_ghast_spawner", + "hghastmobcage": "happy_ghast_spawner", + "hghastmobspawner": "happy_ghast_spawner", + "hghastmonstercage": "happy_ghast_spawner", + "hghastmonsterspawner": "happy_ghast_spawner", + "hghastmspawner": "happy_ghast_spawner", + "hghastspawner": "happy_ghast_spawner", "harming_lingering_potion": { "potionData": { "type": "HARMING", @@ -11811,6 +11957,16 @@ "lightblugtcotta": "light_blue_glazed_terracotta", "lightblugterra": "light_blue_glazed_terracotta", "minecraft:light_blue_glazed_terracotta": "light_blue_glazed_terracotta", + "light_blue_harness": { + "material": "LIGHT_BLUE_HARNESS" + }, + "lbharness": "light_blue_harness", + "lblueharness": "light_blue_harness", + "lbluharness": "light_blue_harness", + "light_blueharness": "light_blue_harness", + "lightblueharness": "light_blue_harness", + "lightbluharness": "light_blue_harness", + "minecraft:light_blue_harness": "light_blue_harness", "light_blue_shulker_box": { "material": "LIGHT_BLUE_SHULKER_BOX" }, @@ -12190,6 +12346,21 @@ "silverglazedterracotta": "light_gray_glazed_terracotta", "silvergtcotta": "light_gray_glazed_terracotta", "silvergterra": "light_gray_glazed_terracotta", + "light_gray_harness": { + "material": "LIGHT_GRAY_HARNESS" + }, + "lgharness": "light_gray_harness", + "lgraharness": "light_gray_harness", + "lgrayharness": "light_gray_harness", + "lgreyharness": "light_gray_harness", + "light_grayharness": "light_gray_harness", + "lightgraharness": "light_gray_harness", + "lightgrayharness": "light_gray_harness", + "lightgreyharness": "light_gray_harness", + "minecraft:light_gray_harness": "light_gray_harness", + "siaharness": "light_gray_harness", + "siharness": "light_gray_harness", + "silverharness": "light_gray_harness", "light_gray_shulker_box": { "material": "LIGHT_GRAY_SHULKER_BOX" }, @@ -12597,6 +12768,16 @@ "limegtcotta": "lime_glazed_terracotta", "limegterra": "lime_glazed_terracotta", "minecraft:lime_glazed_terracotta": "lime_glazed_terracotta", + "lime_harness": { + "material": "LIME_HARNESS" + }, + "lgreenharness": "lime_harness", + "lgreharness": "lime_harness", + "lharness": "lime_harness", + "lightgreenharness": "lime_harness", + "lightgreharness": "lime_harness", + "limeharness": "lime_harness", + "minecraft:lime_harness": "lime_harness", "lime_shulker_box": { "material": "LIME_SHULKER_BOX" }, @@ -19919,6 +20100,12 @@ "mgtcotta": "magenta_glazed_terracotta", "mgterra": "magenta_glazed_terracotta", "minecraft:magenta_glazed_terracotta": "magenta_glazed_terracotta", + "magenta_harness": { + "material": "MAGENTA_HARNESS" + }, + "magentaharness": "magenta_harness", + "mharness": "magenta_harness", + "minecraft:magenta_harness": "magenta_harness", "magenta_shulker_box": { "material": "MAGENTA_SHULKER_BOX" }, @@ -21966,6 +22153,42 @@ "whmusicdisk": "music_disc_strad", "whmusicrecord": "music_disc_strad", "whrecord": "music_disc_strad", + "music_disc_tears": { + "material": "MUSIC_DISC_TEARS" + }, + "cdghast": "music_disc_tears", + "cdtears": "music_disc_tears", + "discghast": "music_disc_tears", + "disctears": "music_disc_tears", + "diskghast": "music_disc_tears", + "disktears": "music_disc_tears", + "ghastcd": "music_disc_tears", + "ghastdisc": "music_disc_tears", + "ghastdisk": "music_disc_tears", + "ghastmdisc": "music_disc_tears", + "ghastmusicdisc": "music_disc_tears", + "ghastmusicdisk": "music_disc_tears", + "ghastmusicrecord": "music_disc_tears", + "ghastrecord": "music_disc_tears", + "mdiscghast": "music_disc_tears", + "mdisctears": "music_disc_tears", + "minecraft:music_disc_tears": "music_disc_tears", + "musicdiscghast": "music_disc_tears", + "musicdisctears": "music_disc_tears", + "musicdiskghast": "music_disc_tears", + "musicdisktears": "music_disc_tears", + "musicrecordghast": "music_disc_tears", + "musicrecordtears": "music_disc_tears", + "recordghast": "music_disc_tears", + "recordtears": "music_disc_tears", + "tearscd": "music_disc_tears", + "tearsdisc": "music_disc_tears", + "tearsdisk": "music_disc_tears", + "tearsmdisc": "music_disc_tears", + "tearsmusicdisc": "music_disc_tears", + "tearsmusicdisk": "music_disc_tears", + "tearsmusicrecord": "music_disc_tears", + "tearsrecord": "music_disc_tears", "music_disc_wait": { "material": "MUSIC_DISC_WAIT" }, @@ -23277,6 +23500,12 @@ "orangeglazedterracotta": "orange_glazed_terracotta", "orangegtcotta": "orange_glazed_terracotta", "orangegterra": "orange_glazed_terracotta", + "orange_harness": { + "material": "ORANGE_HARNESS" + }, + "minecraft:orange_harness": "orange_harness", + "oharness": "orange_harness", + "orangeharness": "orange_harness", "orange_shulker_box": { "material": "ORANGE_SHULKER_BOX" }, @@ -24805,6 +25034,12 @@ "pinkglazedterracotta": "pink_glazed_terracotta", "pinkgtcotta": "pink_glazed_terracotta", "pinkgterra": "pink_glazed_terracotta", + "pink_harness": { + "material": "PINK_HARNESS" + }, + "minecraft:pink_harness": "pink_harness", + "piharness": "pink_harness", + "pinkharness": "pink_harness", "pink_petals": { "material": "PINK_PETALS" }, @@ -26057,6 +26292,12 @@ "purpleglazedterracotta": "purple_glazed_terracotta", "purplegtcotta": "purple_glazed_terracotta", "purplegterra": "purple_glazed_terracotta", + "purple_harness": { + "material": "PURPLE_HARNESS" + }, + "minecraft:purple_harness": "purple_harness", + "puharness": "purple_harness", + "purpleharness": "purple_harness", "purple_shulker_box": { "material": "PURPLE_SHULKER_BOX" }, @@ -26509,6 +26750,12 @@ "rglazedterracotta": "red_glazed_terracotta", "rgtcotta": "red_glazed_terracotta", "rgterra": "red_glazed_terracotta", + "red_harness": { + "material": "RED_HARNESS" + }, + "minecraft:red_harness": "red_harness", + "redharness": "red_harness", + "rharness": "red_harness", "red_mushroom": { "material": "RED_MUSHROOM" }, @@ -46804,6 +47051,12 @@ "whiteglazedterracotta": "white_glazed_terracotta", "whitegtcotta": "white_glazed_terracotta", "whitegterra": "white_glazed_terracotta", + "white_harness": { + "material": "WHITE_HARNESS" + }, + "minecraft:white_harness": "white_harness", + "wharness": "white_harness", + "whiteharness": "white_harness", "white_shulker_box": { "material": "WHITE_SHULKER_BOX" }, @@ -47351,6 +47604,12 @@ "yglazedterracotta": "yellow_glazed_terracotta", "ygtcotta": "yellow_glazed_terracotta", "ygterra": "yellow_glazed_terracotta", + "yellow_harness": { + "material": "YELLOW_HARNESS" + }, + "minecraft:yellow_harness": "yellow_harness", + "yellowharness": "yellow_harness", + "yharness": "yellow_harness", "yellow_shulker_box": { "material": "YELLOW_SHULKER_BOX" }, diff --git a/Essentials/src/test/java/com/earth2me/essentials/EconomyTest.java b/Essentials/src/test/java/com/earth2me/essentials/EconomyTest.java index eaa37156863..cfc5729cd03 100644 --- a/Essentials/src/test/java/com/earth2me/essentials/EconomyTest.java +++ b/Essentials/src/test/java/com/earth2me/essentials/EconomyTest.java @@ -8,92 +8,102 @@ import net.ess3.api.Economy; import net.ess3.api.MaxMoneyException; import org.bukkit.command.CommandSender; -import org.bukkit.plugin.InvalidDescriptionException; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.mockbukkit.mockbukkit.MockBukkit; +import org.mockbukkit.mockbukkit.ServerMock; -import java.io.IOException; +import java.io.File; public class EconomyTest { private static final String NPCNAME = "npc1"; private static final String PLAYERNAME = "testPlayer1"; private static final String PLAYERNAME2 = "testPlayer2"; - private final transient Essentials ess; - private final FakeServer server; - - public EconomyTest() { - this.server = FakeServer.getServer(); - ess = new Essentials(server); - try { - ess.setupForTesting(server); - } catch (final InvalidDescriptionException ex) { - Assert.fail("InvalidDescriptionException"); - } catch (final IOException ex) { - Assert.fail("IOException"); + private Essentials ess; + private ServerMock server; + + @BeforeEach + void setUp() { + server = MockBukkit.mock(); + Essentials.TESTING = true; + ess = MockBukkit.load(Essentials.class); + + // Proactively create the userdata folder to prevent async task failures + final File userdataFolder = new File(ess.getDataFolder(), "userdata"); + if (!userdataFolder.exists()) { + userdataFolder.mkdirs(); } - server.addPlayer(new OfflinePlayerStub(PLAYERNAME, ess.getServer())); - server.addPlayer(new OfflinePlayerStub(PLAYERNAME2, ess.getServer())); + + server.addPlayer(PLAYERNAME); + server.addPlayer(PLAYERNAME2); + } + + @AfterEach + void tearDown() { + MockBukkit.unmock(); } // only one big test, since we use static instances @Test public void testEconomy() { // test NPC - Assert.assertFalse("NPC does not exists", Economy.playerExists(NPCNAME)); - Assert.assertTrue("Create NPC", Economy.createNPC(NPCNAME)); - Assert.assertTrue("NPC exists", Economy.playerExists(NPCNAME)); - Assert.assertNotNull("NPC can be accessed", ess.getOfflineUser(NPCNAME)); + Assertions.assertFalse(Economy.playerExists(NPCNAME), "NPC does not exists"); + Assertions.assertTrue(Economy.createNPC(NPCNAME), "Create NPC"); + Assertions.assertTrue(Economy.playerExists(NPCNAME), "NPC exists"); + Assertions.assertNotNull(ess.getOfflineUser(NPCNAME), "NPC can be accessed"); try { Economy.removeNPC(NPCNAME); } catch (final UserDoesNotExistException ex) { - Assert.fail(ex.getMessage()); + Assertions.fail(ex.getMessage()); } - Assert.assertFalse("NPC can be removed", Economy.playerExists(NPCNAME)); + Assertions.assertFalse(Economy.playerExists(NPCNAME), "NPC can be removed"); //test Math try { - Assert.assertTrue("Player exists", Economy.playerExists(PLAYERNAME)); + Assertions.assertTrue(Economy.playerExists(PLAYERNAME), "Player exists"); Economy.resetBalance(PLAYERNAME); - Assert.assertEquals("Player has no money", 0.0, Economy.getMoney(PLAYERNAME), 0); + Assertions.assertEquals(0.0, Economy.getMoney(PLAYERNAME), 0, "Player has no money"); Economy.add(PLAYERNAME, 10.0); - Assert.assertEquals("Add money", 10.0, Economy.getMoney(PLAYERNAME), 0); + Assertions.assertEquals(10.0, Economy.getMoney(PLAYERNAME), 0, "Add money"); Economy.subtract(PLAYERNAME, 5.0); - Assert.assertEquals("Subtract money", 5.0, Economy.getMoney(PLAYERNAME), 0); + Assertions.assertEquals(5.0, Economy.getMoney(PLAYERNAME), 0, "Subtract money"); Economy.multiply(PLAYERNAME, 2.0); - Assert.assertEquals("Multiply money", 10.0, Economy.getMoney(PLAYERNAME), 0); + Assertions.assertEquals(10.0, Economy.getMoney(PLAYERNAME), 0, "Multiply money"); Economy.divide(PLAYERNAME, 2.0); - Assert.assertEquals("Divide money", 5.0, Economy.getMoney(PLAYERNAME), 0); + Assertions.assertEquals(5.0, Economy.getMoney(PLAYERNAME), 0, "Divide money"); Economy.setMoney(PLAYERNAME, 10.0); - Assert.assertEquals("Set money", 10.0, Economy.getMoney(PLAYERNAME), 0); + Assertions.assertEquals(10.0, Economy.getMoney(PLAYERNAME), 0, "Set money"); } catch (final NoLoanPermittedException | UserDoesNotExistException | MaxMoneyException ex) { - Assert.fail(ex.getMessage()); + Assertions.fail(ex.getMessage()); } //test Format - Assert.assertEquals("Format $1,000", "$1,000", Economy.format(1000.0)); - Assert.assertEquals("Format $10", "$10", Economy.format(10.0)); - Assert.assertEquals("Format $10.10", "$10.10", Economy.format(10.10)); - Assert.assertEquals("Format $10.10", "$10.10", Economy.format(10.1000001)); - Assert.assertEquals("Format $10.10", "$10.10", Economy.format(10.1099999)); + Assertions.assertEquals("$1,000", Economy.format(1000.0), "Format $1,000"); + Assertions.assertEquals("$10", Economy.format(10.0), "Format $10"); + Assertions.assertEquals("$10.10", Economy.format(10.10), "Format $10.10"); + Assertions.assertEquals("$10.10", Economy.format(10.1000001), "Format $10.10"); + Assertions.assertEquals("$10.10", Economy.format(10.1099999), "Format $10.10"); //test Exceptions try { - Assert.assertTrue("Player exists", Economy.playerExists(PLAYERNAME)); + Assertions.assertTrue(Economy.playerExists(PLAYERNAME), "Player exists"); Economy.resetBalance(PLAYERNAME); - Assert.assertEquals("Reset balance", 0.0, Economy.getMoney(PLAYERNAME), 0); + Assertions.assertEquals(0.0, Economy.getMoney(PLAYERNAME), 0, "Reset balance"); Economy.subtract(PLAYERNAME, 5.0); - Assert.fail("Did not throw exception"); + Assertions.fail("Did not throw exception"); } catch (final NoLoanPermittedException | MaxMoneyException ignored) { } catch (final UserDoesNotExistException ex) { - Assert.fail(ex.getMessage()); + Assertions.fail(ex.getMessage()); } try { Economy.resetBalance("UnknownPlayer"); - Assert.fail("Did not throw exception"); + Assertions.fail("Did not throw exception"); } catch (final NoLoanPermittedException | MaxMoneyException ex) { - Assert.fail(ex.getMessage()); + Assertions.fail(ex.getMessage()); } catch (final UserDoesNotExistException ignored) { } } @@ -139,7 +149,7 @@ public void testNegativePayCommand() { try { runCommand("pay", user1, PLAYERNAME2 + " -123"); } catch (final Exception e) { - Assert.assertEquals(AdventureUtil.miniToLegacy(I18n.tlLiteral("payMustBePositive")), e.getMessage()); + Assertions.assertEquals(AdventureUtil.miniToLegacy(I18n.tlLiteral("payMustBePositive")), e.getMessage()); } } } diff --git a/Essentials/src/test/java/com/earth2me/essentials/MessagingTest.java b/Essentials/src/test/java/com/earth2me/essentials/MessagingTest.java index 73254d0a734..6b2542371e0 100644 --- a/Essentials/src/test/java/com/earth2me/essentials/MessagingTest.java +++ b/Essentials/src/test/java/com/earth2me/essentials/MessagingTest.java @@ -3,36 +3,37 @@ import com.earth2me.essentials.commands.IEssentialsCommand; import com.earth2me.essentials.commands.NoChargeException; import org.bukkit.command.CommandSender; -import org.bukkit.plugin.InvalidDescriptionException; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.mockbukkit.mockbukkit.MockBukkit; +import org.mockbukkit.mockbukkit.ServerMock; +import org.mockbukkit.mockbukkit.entity.PlayerMock; -import java.io.IOException; - -import static org.junit.Assert.fail; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertThrows; public class MessagingTest { - private final OfflinePlayerStub base1; - private final Essentials ess; - private final FakeServer server; + private PlayerMock base1; + private Essentials ess; + private ServerMock server; - public MessagingTest() { - server = FakeServer.getServer(); - ess = new Essentials(server); - try { - ess.setupForTesting(server); - } catch (final InvalidDescriptionException ex) { - fail("InvalidDescriptionException"); - } catch (final IOException ex) { - fail("IOException"); - } - base1 = server.createPlayer("testPlayer1"); - server.addPlayer(base1); + @BeforeEach + void setUp() { + this.server = MockBukkit.mock(); + Essentials.TESTING = true; + ess = MockBukkit.load(Essentials.class); + base1 = server.addPlayer("testPlayer1"); ess.getUser(base1); } + @AfterEach + void tearDown() { + MockBukkit.unmock(); + } + private void runCommand(final String command, final User user, final String args) throws Exception { runCommand(command, user, args.split("\\s+")); } @@ -68,27 +69,29 @@ private void runConsoleCommand(final String command, final String[] args) throws } } - @Test(expected = Exception.class) // I really don't like this, but see note below about console reply - public void testNullLastMessageReplyRecipient() throws Exception { - final User user1 = ess.getUser(base1); - final Console console = Console.getInstance(); - if (ess.getSettings().isLastMessageReplyRecipient()) { - assertNull(console.getReplyRecipient()); // console never messaged or received messages from anyone. - + @Test + public void testNullLastMessageReplyRecipient() { + assertThrows(Exception.class, () -> { + final User user1 = ess.getUser(base1); + final Console console = Console.getInstance(); if (ess.getSettings().isLastMessageReplyRecipient()) { - runCommand("r", user1, "This is me sending you a message using /r without you replying!"); - } + assertNull(console.getReplyRecipient()); // console never messaged or received messages from anyone. - // Not really much of a strict test, but just "testing" console output. - user1.setAfk(true); + if (ess.getSettings().isLastMessageReplyRecipient()) { + runCommand("r", user1, "This is me sending you a message using /r without you replying!"); + } - // Console replies using "/r Hey, son!" - // - // This throws Exception because the console hasnt messaged anyone. - runConsoleCommand("r", "Hey, son!"); - } else { - throw new Exception(); // Needed to prevent build failures. - } + // Not really much of a strict test, but just "testing" console output. + user1.setAfk(true); + + // Console replies using "/r Hey, son!" + // + // This throws Exception because the console hasnt messaged anyone. + runConsoleCommand("r", "Hey, son!"); + } else { + throw new Exception(); // Needed to prevent build failures. + } + }); } @Test diff --git a/Essentials/src/test/java/com/earth2me/essentials/StorageTest.java b/Essentials/src/test/java/com/earth2me/essentials/StorageTest.java index fda8d82bb4c..378adaba8bd 100644 --- a/Essentials/src/test/java/com/earth2me/essentials/StorageTest.java +++ b/Essentials/src/test/java/com/earth2me/essentials/StorageTest.java @@ -2,36 +2,36 @@ import org.bukkit.Location; import org.bukkit.World; -import org.bukkit.plugin.InvalidDescriptionException; -import org.junit.Assert; -import org.junit.Test; - -import java.io.IOException; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.mockbukkit.mockbukkit.MockBukkit; +import org.mockbukkit.mockbukkit.ServerMock; +import org.mockbukkit.mockbukkit.entity.PlayerMock; public class StorageTest { - private final Essentials ess; - private final FakeServer server; - private final World world; + private Essentials ess; + private ServerMock server; + private World world; - public StorageTest() { - server = FakeServer.getServer(); - world = server.getWorld("testWorld"); - ess = new Essentials(server); - try { - ess.setupForTesting(server); - } catch (final InvalidDescriptionException ex) { - Assert.fail("InvalidDescriptionException"); - } catch (final IOException ex) { - Assert.fail("IOException"); - } + @BeforeEach + public void setUp() { + this.server = MockBukkit.mock(); + world = server.addSimpleWorld("testWorld"); + Essentials.TESTING = true; + ess = MockBukkit.load(Essentials.class); + } + + @AfterEach + public void tearDown() { + MockBukkit.unmock(); } @Test public void testOldUserdata() { final ExecuteTimer ext = new ExecuteTimer(); ext.start(); - final OfflinePlayerStub base1 = server.createPlayer("testPlayer1"); - server.addPlayer(base1); + final PlayerMock base1 = server.addPlayer("testPlayer1"); ext.mark("fake user created"); final UserData user = ess.getUser(base1); ext.mark("load empty user"); diff --git a/Essentials/src/test/java/com/earth2me/essentials/ToggleTest.java b/Essentials/src/test/java/com/earth2me/essentials/ToggleTest.java index 4652c3b5123..fd109b9a505 100644 --- a/Essentials/src/test/java/com/earth2me/essentials/ToggleTest.java +++ b/Essentials/src/test/java/com/earth2me/essentials/ToggleTest.java @@ -2,33 +2,36 @@ import com.earth2me.essentials.commands.IEssentialsCommand; import com.earth2me.essentials.commands.NoChargeException; -import junit.framework.TestCase; import org.bukkit.command.CommandSender; -import org.bukkit.plugin.InvalidDescriptionException; - -import java.io.IOException; - -public class ToggleTest extends TestCase { - private final OfflinePlayerStub base1; - private final Essentials ess; - private final FakeServer server; - - public ToggleTest(final String testName) { - super(testName); - server = FakeServer.getServer(); - ess = new Essentials(server); - try { - ess.setupForTesting(server); - } catch (final InvalidDescriptionException ex) { - fail("InvalidDescriptionException"); - } catch (final IOException ex) { - fail("IOException"); - } - base1 = server.createPlayer("testPlayer1"); - server.addPlayer(base1); +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.mockbukkit.mockbukkit.MockBukkit; +import org.mockbukkit.mockbukkit.ServerMock; +import org.mockbukkit.mockbukkit.entity.PlayerMock; + +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; + +public class ToggleTest { + private PlayerMock base1; + private Essentials ess; + private ServerMock server; + + @BeforeEach + public void setUp() { + this.server = MockBukkit.mock(); + Essentials.TESTING = true; + ess = MockBukkit.load(Essentials.class); + base1 = server.addPlayer("testPlayer1"); ess.getUser(base1); } + @AfterEach + public void tearDown() { + MockBukkit.unmock(); + } + private void runCommand(final String command, final User user, final String[] args) throws Exception { final IEssentialsCommand cmd; @@ -55,6 +58,7 @@ private void runConsoleCommand(final String command, final String[] args) throws } + @Test public void testFlyToggle() throws Exception { final User user = ess.getUser(base1); @@ -79,6 +83,7 @@ public void testFlyToggle() throws Exception { assertFalse(user.getBase().getAllowFlight()); } + @Test public void testFlyDisOnToggle() throws Exception { final User user = ess.getUser(base1); @@ -90,6 +95,7 @@ public void testFlyDisOnToggle() throws Exception { assertFalse(user.getBase().isFlying()); } + @Test public void testGodToggle() throws Exception { final User user = ess.getUser(base1); @@ -114,6 +120,7 @@ public void testGodToggle() throws Exception { assertFalse(user.isGodModeEnabled()); } + @Test public void testConsoleToggle() throws Exception { final User user = ess.getUser(base1); @@ -138,6 +145,7 @@ public void testConsoleToggle() throws Exception { assertFalse(user.getBase().getAllowFlight()); } + @Test public void testAliasesToggle() throws Exception { final User user = ess.getUser(base1); diff --git a/Essentials/src/test/java/com/earth2me/essentials/UserTest.java b/Essentials/src/test/java/com/earth2me/essentials/UserTest.java index 0c3715545b7..7136aa4233f 100644 --- a/Essentials/src/test/java/com/earth2me/essentials/UserTest.java +++ b/Essentials/src/test/java/com/earth2me/essentials/UserTest.java @@ -1,49 +1,57 @@ package com.earth2me.essentials; -import junit.framework.TestCase; import net.ess3.api.MaxMoneyException; import org.bukkit.Location; -import org.bukkit.plugin.InvalidDescriptionException; +import org.bukkit.entity.Player; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.mockbukkit.mockbukkit.MockBukkit; +import org.mockbukkit.mockbukkit.ServerMock; +import org.mockbukkit.mockbukkit.entity.PlayerMock; -import java.io.IOException; import java.math.BigDecimal; -public class UserTest extends TestCase { - private final OfflinePlayerStub base1; - private final Essentials ess; - private final FakeServer server; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.fail; - public UserTest(final String testName) { - super(testName); - server = FakeServer.getServer(); - ess = new Essentials(server); - try { - ess.setupForTesting(server); - } catch (final InvalidDescriptionException ex) { - fail("InvalidDescriptionException"); - } catch (final IOException ex) { - fail("IOException"); - } - base1 = server.createPlayer("testPlayer1"); - server.addPlayer(base1); +public class UserTest { + private PlayerMock base1; + private Essentials ess; + private ServerMock server; + + @BeforeEach + public void setUp() { + this.server = MockBukkit.mock(); + Essentials.TESTING = true; + ess = MockBukkit.load(Essentials.class); + base1 = server.addPlayer("testPlayer1"); ess.getUser(base1); } + @AfterEach + public void tearEach() { + MockBukkit.unmock(); + } + private void should(final String what) { - System.out.println(getName() + " should " + what); + System.out.println("UserTest should " + what); } + @Test public void testUpdate() { - final OfflinePlayerStub base1alt = server.createPlayer(base1.getName()); + final Player base1alt = server.getPlayer(base1.getName()); assertEquals(base1alt, ess.getUser(base1alt).getBase()); } + @Test public void testHome() { final User user = ess.getUser(base1); final Location loc = base1.getLocation(); loc.setWorld(server.getWorlds().get(0)); user.setHome("home", loc); - final OfflinePlayerStub base2 = server.createPlayer(base1.getName()); + final Player base2 = server.getPlayer(base1.getName()); final User user2 = ess.getUser(base2); final Location home = user2.getHome(loc); @@ -56,6 +64,7 @@ public void testHome() { assertEquals(loc.getPitch(), home.getPitch()); } + @Test public void testMoney() { should("properly set, take, give, and get money"); final User user = ess.getUser(base1); diff --git a/Essentials/src/test/java/com/earth2me/essentials/UtilTest.java b/Essentials/src/test/java/com/earth2me/essentials/UtilTest.java index 350a41d2f4f..3652a74da0e 100644 --- a/Essentials/src/test/java/com/earth2me/essentials/UtilTest.java +++ b/Essentials/src/test/java/com/earth2me/essentials/UtilTest.java @@ -3,29 +3,36 @@ import com.earth2me.essentials.utils.DateUtil; import com.earth2me.essentials.utils.LocationUtil; import com.earth2me.essentials.utils.VersionUtil; -import junit.framework.TestCase; -import org.bukkit.plugin.InvalidDescriptionException; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.mockbukkit.mockbukkit.MockBukkit; -import java.io.IOException; import java.util.Calendar; import java.util.GregorianCalendar; import java.util.HashSet; import java.util.Set; -public class UtilTest extends TestCase { +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; - public UtilTest() { - final FakeServer server = FakeServer.getServer(); - final Essentials ess = new Essentials(server); - try { - ess.setupForTesting(server); - } catch (final InvalidDescriptionException ex) { - fail("InvalidDescriptionException"); - } catch (final IOException ex) { - fail("IOException"); - } +public class UtilTest { + + private Essentials ess; + + @BeforeEach + public void setUp() { + MockBukkit.mock(); + Essentials.TESTING = true; + ess = MockBukkit.load(Essentials.class); + } + + @AfterEach + public void afterEach() { + MockBukkit.unmock(); } + @Test public void testSafeLocation() { final Set testSet = new HashSet<>(); int count = 0; @@ -55,12 +62,14 @@ public void testSafeLocation() { assertEquals(diameter * diameter * diameter, count); } + @Test public void testFDDnow() { final Calendar c = new GregorianCalendar(); final String resp = DateUtil.formatDateDiff(c, c); assertEquals(resp, "now"); } + @Test public void testFDDfuture() { Calendar a, b; a = new GregorianCalendar(2010, Calendar.FEBRUARY, 1, 10, 0, 0); @@ -128,6 +137,7 @@ public void testFDDfuture() { assertEquals("5 minutes", DateUtil.formatDateDiff(a, b)); } + @Test public void testFDDpast() { Calendar a, b; a = new GregorianCalendar(2010, Calendar.FEBRUARY, 1, 10, 0, 0); @@ -192,6 +202,7 @@ public void testFDDpast() { assertEquals("10 years 6 months 10 days", DateUtil.formatDateDiff(a, b)); } + @Test public void testVer() { VersionUtil.BukkitVersion v; v = VersionUtil.BukkitVersion.fromString("1.13.2-R0.1"); diff --git a/Essentials/src/test/java/com/earth2me/essentials/utils/FormatUtilTest.java b/Essentials/src/test/java/com/earth2me/essentials/utils/FormatUtilTest.java index 7983bdb7121..c56940dc98c 100644 --- a/Essentials/src/test/java/com/earth2me/essentials/utils/FormatUtilTest.java +++ b/Essentials/src/test/java/com/earth2me/essentials/utils/FormatUtilTest.java @@ -1,9 +1,9 @@ package com.earth2me.essentials.utils; import net.ess3.api.IUser; -import org.junit.Test; +import org.junit.jupiter.api.Test; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; diff --git a/Essentials/src/test/java/com/earth2me/essentials/utils/NumberUtilTest.java b/Essentials/src/test/java/com/earth2me/essentials/utils/NumberUtilTest.java index 22f33aa5784..31ea05b3881 100644 --- a/Essentials/src/test/java/com/earth2me/essentials/utils/NumberUtilTest.java +++ b/Essentials/src/test/java/com/earth2me/essentials/utils/NumberUtilTest.java @@ -1,15 +1,15 @@ package com.earth2me.essentials.utils; import com.earth2me.essentials.commands.InvalidModifierException; -import org.junit.Test; +import org.junit.jupiter.api.Test; import java.math.BigDecimal; import java.text.ParseException; import java.util.Locale; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotEquals; -import static org.junit.Assert.assertThrows; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; public class NumberUtilTest { diff --git a/Essentials/src/test/java/com/earth2me/essentials/utils/StringUtilTest.java b/Essentials/src/test/java/com/earth2me/essentials/utils/StringUtilTest.java index e4b0cde74dc..4a2c6d162ef 100644 --- a/Essentials/src/test/java/com/earth2me/essentials/utils/StringUtilTest.java +++ b/Essentials/src/test/java/com/earth2me/essentials/utils/StringUtilTest.java @@ -1,6 +1,6 @@ package com.earth2me.essentials.utils; -import org.junit.Test; +import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; diff --git a/README.md b/README.md index 8afe788463e..cece66cb2ea 100644 --- a/README.md +++ b/README.md @@ -26,7 +26,7 @@ however, have some new requirements: * **EssentialsX requires CraftBukkit, Spigot or Paper to run.** Other server software may work, but these are not tested by the team and we may not be able to help with any issues that occur. * **EssentialsX currently supports Minecraft versions 1.8.8, 1.9.4, 1.10.2, 1.11.2, 1.12.2, 1.13.2, 1.14.4, 1.15.2, - 1.16.5, 1.17.1, 1.18.2, 1.19.4, 1.20.6, and 1.21.5.** + 1.16.5, 1.17.1, 1.18.2, 1.19.4, 1.20.6, and 1.21.6.** * **EssentialsX currently requires Java 8 or higher.** We recommend using the latest Java version supported by your server software. * **EssentialsX requires [Vault](http://dev.bukkit.org/bukkit-plugins/vault/) to enable using chat prefix/suffixes and diff --git a/build-logic/src/main/kotlin/FileCopyTask.kt b/build-logic/src/main/kotlin/FileCopyTask.kt index a270901056b..e73c80224e4 100644 --- a/build-logic/src/main/kotlin/FileCopyTask.kt +++ b/build-logic/src/main/kotlin/FileCopyTask.kt @@ -11,7 +11,7 @@ abstract class FileCopyTask : DefaultTask() { val destination = project.objects.fileProperty() @TaskAction - private fun copyFile() { + fun copyFile() { destination.get().asFile.parentFile.mkdirs() fileToCopy.get().asFile.copyTo(destination.get().asFile, overwrite = true) } diff --git a/build-logic/src/main/kotlin/constants.kt b/build-logic/src/main/kotlin/constants.kt index ef2b779f283..afcf9197af8 100644 --- a/build-logic/src/main/kotlin/constants.kt +++ b/build-logic/src/main/kotlin/constants.kt @@ -1 +1 @@ -const val RUN_PAPER_MINECRAFT_VERSION = "1.21.5" +const val RUN_PAPER_MINECRAFT_VERSION = "1.21.6" diff --git a/build-logic/src/main/kotlin/essentials.base-conventions.gradle.kts b/build-logic/src/main/kotlin/essentials.base-conventions.gradle.kts index 765db527c53..67d022f40fb 100644 --- a/build-logic/src/main/kotlin/essentials.base-conventions.gradle.kts +++ b/build-logic/src/main/kotlin/essentials.base-conventions.gradle.kts @@ -10,14 +10,20 @@ plugins { val baseExtension = extensions.create("essentials", project) val checkstyleVersion = "8.36.2" -val spigotVersion = "1.21.5-R0.1-SNAPSHOT" -val junit5Version = "5.10.2" -val mockitoVersion = "3.12.4" +val paperVersion = "1.21.6-R0.1-SNAPSHOT" +val paperTestVersion = "1.21.5-R0.1-SNAPSHOT" +val junit5Version = "5.12.2" +val junitPlatformVersion = "1.12.2" +val mockitoVersion = "5.18.0" dependencies { testImplementation("org.junit.jupiter", "junit-jupiter", junit5Version) - testImplementation("org.junit.vintage", "junit-vintage-engine", junit5Version) + testImplementation("org.junit.platform", "junit-platform-launcher", junitPlatformVersion) testImplementation("org.mockito", "mockito-core", mockitoVersion) + testImplementation("org.mockbukkit.mockbukkit:mockbukkit-v1.21:4.50.0") { + exclude(module = "paper-api") + exclude(module = "spigot-api") + } constraints { implementation("org.yaml:snakeyaml:1.28") { @@ -27,6 +33,7 @@ dependencies { } tasks.test { + useJUnitPlatform() testLogging { events("PASSED", "SKIPPED", "FAILED") } @@ -35,7 +42,31 @@ tasks.test { afterEvaluate { if (baseExtension.injectBukkitApi.get()) { dependencies { - api("org.spigotmc", "spigot-api", spigotVersion) + api("io.papermc.paper", "paper-api", paperVersion) + testImplementation("io.papermc.paper", "paper-api", paperTestVersion) + } + + configurations { + testCompileClasspath { + resolutionStrategy { + dependencySubstitution { + substitute( module("io.papermc.paper:paper-api")) + .using(module("io.papermc.paper:paper-api:$paperTestVersion")) + } + } + } + testRuntimeClasspath { + resolutionStrategy { + dependencySubstitution { + substitute( module("io.papermc.paper:paper-api")) + .using(module("io.papermc.paper:paper-api:$paperTestVersion")) + } + } + } + } + + java { + disableAutoTargetJvm() } } if (baseExtension.injectBstats.get()) { diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index df97d72b8b9..ff23a68d70f 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-8.10.2-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.14.2-bin.zip networkTimeout=10000 validateDistributionUrl=true zipStoreBase=GRADLE_USER_HOME diff --git a/providers/1_12Provider/build.gradle b/providers/1_12Provider/build.gradle index 438afeea59e..1f707015ab9 100644 --- a/providers/1_12Provider/build.gradle +++ b/providers/1_12Provider/build.gradle @@ -4,7 +4,7 @@ plugins { dependencies { implementation(project(':providers:BaseProviders')) { - exclude group: "org.spigotmc", module: "spigot-api" + exclude(module: 'spigot-api') } api project(':providers:NMSReflectionProvider') } diff --git a/providers/1_8Provider/build.gradle b/providers/1_8Provider/build.gradle index 9313505930d..64195893ab9 100644 --- a/providers/1_8Provider/build.gradle +++ b/providers/1_8Provider/build.gradle @@ -4,7 +4,7 @@ plugins { dependencies { implementation(project(':providers:BaseProviders')) { - exclude group: "org.spigotmc", module: "spigot-api" + exclude(module: 'spigot-api') } implementation 'org.spigotmc:spigot-api:1.8.8-R0.1-SNAPSHOT' } diff --git a/providers/BaseProviders/build.gradle b/providers/BaseProviders/build.gradle index 99176e2221f..53c5cc60d0a 100644 --- a/providers/BaseProviders/build.gradle +++ b/providers/BaseProviders/build.gradle @@ -3,5 +3,10 @@ plugins { } essentials { + injectBukkitApi.set(false) injectBstats.set(false) } + +dependencies { + api 'org.spigotmc:spigot-api:1.21.5-R0.1-SNAPSHOT' +} diff --git a/providers/NMSReflectionProvider/build.gradle b/providers/NMSReflectionProvider/build.gradle index c064338a9e0..3a6ac00d58b 100644 --- a/providers/NMSReflectionProvider/build.gradle +++ b/providers/NMSReflectionProvider/build.gradle @@ -3,7 +3,9 @@ plugins { } dependencies { - implementation project(':providers:BaseProviders') + implementation(project(':providers:BaseProviders')) { + exclude(module: 'spigot-api') + } api 'org.bukkit:bukkit:1.12.2-R0.1-SNAPSHOT' } diff --git a/providers/NMSReflectionProvider/src/main/java/net/ess3/nms/refl/ReflUtil.java b/providers/NMSReflectionProvider/src/main/java/net/ess3/nms/refl/ReflUtil.java index e358cb29efe..07d8123e643 100644 --- a/providers/NMSReflectionProvider/src/main/java/net/ess3/nms/refl/ReflUtil.java +++ b/providers/NMSReflectionProvider/src/main/java/net/ess3/nms/refl/ReflUtil.java @@ -51,6 +51,9 @@ public static String getNMSVersion() { public static NMSVersion getNmsVersionObject() { if (nmsVersionObject == null) { try { + if (getNMSVersion().equals("ServerMock")) { + return nmsVersionObject = new NMSVersion(99, 99, 99); + } nmsVersionObject = NMSVersion.fromString(getNMSVersion()); } catch (final IllegalArgumentException e) { try { diff --git a/settings.gradle.kts b/settings.gradle.kts index b8d7d4419c4..595b6d0bccf 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -1,12 +1,12 @@ dependencyResolutionManagement { repositories { + maven("https://repo.papermc.io/repository/maven-public/") maven("https://hub.spigotmc.org/nexus/content/groups/public/") { content { includeGroup("org.spigotmc") includeGroup("net.md_5") } } - maven("https://repo.papermc.io/repository/maven-public/") maven("https://jitpack.io") { content { includeGroup("com.github.milkbowl") } content { includeGroup("com.github.MinnDevelopment") }