From 7d3a9ff36dbb04fb25985f9f804ddcfae79e021d Mon Sep 17 00:00:00 2001 From: Pierre Maurice Schwang Date: Tue, 10 Aug 2021 10:31:37 +0200 Subject: [PATCH] Fixed Unit Tests (BlockVector3.isLongPackable) (#1168) * Fixed Unit Tests (BlockVector3.isLongPackable) * Re-enable tests for ci * Address gh action dependency complaints * Fix "invalid usage of tag &" for MinecraftVersion.java * Simple StubServer for BukkitWorldTest.java * Add parallelgzip to test runtime, fixed javadoc encoding, make gradlew executable and patch StubServer for latest spigot / paper release * Move Javadoc UTF-8 to PlatformConfig.kt * Revert "make gradlew executable" Was required for act to run, but not required for GH actions - Weird behavior * Mark upstream changes, move class + apply editorconfig Co-authored-by: NotMyFault Co-authored-by: Matt <4009945+MattBDev@users.noreply.github.com> --- .github/workflows/build.yml | 2 +- buildSrc/src/main/kotlin/PlatformConfig.kt | 1 + .../bukkit/util/MinecraftVersion.java | 2 +- .../fastasyncworldedit/util/StubServer.java | 922 ++++++++++++++++++ .../worldedit/bukkit/BukkitWorldTest.java | 5 + worldedit-core/build.gradle.kts | 1 + 6 files changed, 931 insertions(+), 2 deletions(-) create mode 100644 worldedit-bukkit/src/test/java/com/fastasyncworldedit/util/StubServer.java diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 3af56089c..6865877ef 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -23,7 +23,7 @@ jobs: distribution: "temurin" java-version: "16" - name: "Clean Build" - run: "./gradlew clean build -x test" + run: "./gradlew clean build" - name: Archive Artifacts uses: actions/upload-artifact@v2 with: diff --git a/buildSrc/src/main/kotlin/PlatformConfig.kt b/buildSrc/src/main/kotlin/PlatformConfig.kt index 8ba0c9d75..70413fcd8 100644 --- a/buildSrc/src/main/kotlin/PlatformConfig.kt +++ b/buildSrc/src/main/kotlin/PlatformConfig.kt @@ -72,6 +72,7 @@ fun Project.applyPlatformAndCoreConfiguration() { "implSpec:a:Implementation Requirements:", "implNote:a:Implementation Note:" ) + options.encoding = "UTF-8" } } diff --git a/worldedit-bukkit/src/main/java/com/fastasyncworldedit/bukkit/util/MinecraftVersion.java b/worldedit-bukkit/src/main/java/com/fastasyncworldedit/bukkit/util/MinecraftVersion.java index cf1a9a207..bf2119024 100644 --- a/worldedit-bukkit/src/main/java/com/fastasyncworldedit/bukkit/util/MinecraftVersion.java +++ b/worldedit-bukkit/src/main/java/com/fastasyncworldedit/bukkit/util/MinecraftVersion.java @@ -20,7 +20,7 @@ public class MinecraftVersion implements Comparable { * Construct a new version with major, minor and release version. * * @param major Major part of the version, only {@code 1} would make sense. - * @param minor Minor part, full updates, e.g. Nether & Caves & Cliffs + * @param minor Minor part, full updates, e.g. Nether & Caves & Cliffs * @param release Release, changes for the server software during a minor update. */ public MinecraftVersion(int major, int minor, int release) { diff --git a/worldedit-bukkit/src/test/java/com/fastasyncworldedit/util/StubServer.java b/worldedit-bukkit/src/test/java/com/fastasyncworldedit/util/StubServer.java new file mode 100644 index 000000000..6bdac4edf --- /dev/null +++ b/worldedit-bukkit/src/test/java/com/fastasyncworldedit/util/StubServer.java @@ -0,0 +1,922 @@ +package com.fastasyncworldedit.util; + +import com.destroystokyo.paper.entity.ai.MobGoals; +import com.destroystokyo.paper.profile.PlayerProfile; +import io.papermc.paper.datapack.DatapackManager; +import net.kyori.adventure.audience.Audience; +import net.kyori.adventure.text.Component; +import org.bukkit.BanList; +import org.bukkit.GameMode; +import org.bukkit.Keyed; +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.NamespacedKey; +import org.bukkit.OfflinePlayer; +import org.bukkit.Server; +import org.bukkit.StructureType; +import org.bukkit.Tag; +import org.bukkit.UnsafeValues; +import org.bukkit.Warning; +import org.bukkit.World; +import org.bukkit.WorldCreator; +import org.bukkit.advancement.Advancement; +import org.bukkit.block.data.BlockData; +import org.bukkit.boss.BarColor; +import org.bukkit.boss.BarFlag; +import org.bukkit.boss.BarStyle; +import org.bukkit.boss.BossBar; +import org.bukkit.boss.KeyedBossBar; +import org.bukkit.command.CommandException; +import org.bukkit.command.CommandMap; +import org.bukkit.command.CommandSender; +import org.bukkit.command.ConsoleCommandSender; +import org.bukkit.command.PluginCommand; +import org.bukkit.entity.Entity; +import org.bukkit.entity.Player; +import org.bukkit.event.inventory.InventoryType; +import org.bukkit.generator.ChunkGenerator; +import org.bukkit.help.HelpMap; +import org.bukkit.inventory.Inventory; +import org.bukkit.inventory.InventoryHolder; +import org.bukkit.inventory.ItemFactory; +import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.Merchant; +import org.bukkit.inventory.Recipe; +import org.bukkit.loot.LootTable; +import org.bukkit.map.MapView; +import org.bukkit.plugin.Plugin; +import org.bukkit.plugin.PluginManager; +import org.bukkit.plugin.ServicesManager; +import org.bukkit.plugin.messaging.Messenger; +import org.bukkit.scheduler.BukkitScheduler; +import org.bukkit.scoreboard.ScoreboardManager; +import org.bukkit.util.CachedServerIcon; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import java.awt.image.BufferedImage; +import java.io.File; +import java.util.Collection; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.UUID; +import java.util.function.Consumer; +import java.util.logging.Logger; + +public class StubServer implements Server { + + @Override + public @NotNull String getName() { + return null; + } + + @Override + public @NotNull String getVersion() { + return "STUB"; + } + + @Override + public @NotNull String getBukkitVersion() { + return null; + } + + @Override + public @NotNull String getMinecraftVersion() { + return null; + } + + @Override + public @NotNull Collection getOnlinePlayers() { + return null; + } + + @Override + public int getMaxPlayers() { + return 0; + } + + @Override + public void setMaxPlayers(int i) { + + } + + @Override + public int getPort() { + return 0; + } + + @Override + public int getViewDistance() { + return 0; + } + + @Override + public @NotNull String getIp() { + return null; + } + + @Override + public @NotNull String getWorldType() { + return null; + } + + @Override + public boolean getGenerateStructures() { + return false; + } + + @Override + public int getMaxWorldSize() { + return 0; + } + + @Override + public boolean getAllowEnd() { + return false; + } + + @Override + public boolean getAllowNether() { + return false; + } + + @Override + public boolean hasWhitelist() { + return false; + } + + @Override + public void setWhitelist(boolean b) { + + } + + @Override + public boolean isWhitelistEnforced() { + return false; + } + + @Override + public void setWhitelistEnforced(final boolean b) { + + } + + @Override + public @NotNull Set getWhitelistedPlayers() { + return null; + } + + @Override + public void reloadWhitelist() { + + } + + /** + * @param s + * @deprecated + */ + @Override + public int broadcastMessage(@NotNull String s) { + return 0; + } + + @Override + public @NotNull String getUpdateFolder() { + return null; + } + + @Override + public @NotNull File getUpdateFolderFile() { + return null; + } + + @Override + public long getConnectionThrottle() { + return 0; + } + + @Override + public int getTicksPerAnimalSpawns() { + return 0; + } + + @Override + public int getTicksPerMonsterSpawns() { + return 0; + } + + @Override + public int getTicksPerWaterSpawns() { + return 0; + } + + @Override + public int getTicksPerWaterAmbientSpawns() { + return 0; + } + + @Override + public int getTicksPerAmbientSpawns() { + return 0; + } + + @Override + public @Nullable Player getPlayer(@NotNull String s) { + return null; + } + + @Override + public @Nullable Player getPlayerExact(@NotNull String s) { + return null; + } + + @Override + public @NotNull List matchPlayer(@NotNull String s) { + return null; + } + + @Override + public @Nullable Player getPlayer(@NotNull UUID uuid) { + return null; + } + + @Override + public @Nullable UUID getPlayerUniqueId(@NotNull String s) { + return null; + } + + @Override + public @NotNull PluginManager getPluginManager() { + return null; + } + + @Override + public @NotNull BukkitScheduler getScheduler() { + return null; + } + + @Override + public @NotNull ServicesManager getServicesManager() { + return null; + } + + @Override + public @NotNull List getWorlds() { + return null; + } + + @Override + public @Nullable World createWorld(@NotNull WorldCreator worldCreator) { + return null; + } + + @Override + public boolean unloadWorld(@NotNull String s, boolean b) { + return false; + } + + @Override + public boolean unloadWorld(@NotNull World world, boolean b) { + return false; + } + + @Override + public @Nullable World getWorld(@NotNull String s) { + return null; + } + + @Override + public @Nullable World getWorld(@NotNull UUID uuid) { + return null; + } + + @Override + public @Nullable World getWorld(@NotNull NamespacedKey namespacedKey) { + return null; + } + + /** + * @param i + * @deprecated + */ + @Override + public @Nullable MapView getMap(int i) { + return null; + } + + @Override + public @NotNull MapView createMap(@NotNull World world) { + return null; + } + + @Override + public @NotNull ItemStack createExplorerMap( + @NotNull World world, + @NotNull Location location, + @NotNull StructureType structureType + ) { + return null; + } + + @Override + public @NotNull ItemStack createExplorerMap( + @NotNull World world, + @NotNull Location location, + @NotNull StructureType structureType, + int i, + boolean b + ) { + return null; + } + + @Override + public void reload() { + + } + + @Override + public void reloadData() { + + } + + @Override + public @NotNull Logger getLogger() { + return Logger.getLogger("StubServer"); + } + + @Override + public @Nullable PluginCommand getPluginCommand(@NotNull String s) { + return null; + } + + @Override + public void savePlayers() { + + } + + @Override + public boolean dispatchCommand(@NotNull CommandSender commandSender, @NotNull String s) throws CommandException { + return false; + } + + @Override + public boolean addRecipe(@Nullable Recipe recipe) { + return false; + } + + @Override + public @NotNull List getRecipesFor(@NotNull ItemStack itemStack) { + return null; + } + + @Override + public @Nullable Recipe getRecipe(@NotNull NamespacedKey namespacedKey) { + return null; + } + + @Override + public @Nullable Recipe getCraftingRecipe(final @NotNull ItemStack[] itemStacks, @NotNull final World world) { + return null; + } + + @Override + public @NotNull ItemStack craftItem( + final @NotNull ItemStack[] itemStacks, + @NotNull final World world, + @NotNull final Player player + ) { + return null; + } + + @Override + public @NotNull Iterator recipeIterator() { + return null; + } + + @Override + public void clearRecipes() { + + } + + @Override + public void resetRecipes() { + + } + + @Override + public boolean removeRecipe(@NotNull NamespacedKey namespacedKey) { + return false; + } + + @Override + public @NotNull Map getCommandAliases() { + return null; + } + + @Override + public int getSpawnRadius() { + return 0; + } + + @Override + public void setSpawnRadius(int i) { + + } + + @Override + public boolean getOnlineMode() { + return false; + } + + @Override + public boolean getAllowFlight() { + return false; + } + + @Override + public boolean isHardcore() { + return false; + } + + @Override + public void shutdown() { + + } + + /** + * @param s + * @param s1 + * @deprecated + */ + @Override + public int broadcast(@NotNull String s, @NotNull String s1) { + return 0; + } + + @Override + public int broadcast(@NotNull final Component component) { + return 0; + } + + @Override + public int broadcast(@NotNull Component component, @NotNull String s) { + return 0; + } + + /** + * @param s + * @deprecated + */ + @Override + public @NotNull OfflinePlayer getOfflinePlayer(@NotNull String s) { + return null; + } + + @Override + public @Nullable OfflinePlayer getOfflinePlayerIfCached(@NotNull String s) { + return null; + } + + @Override + public @NotNull OfflinePlayer getOfflinePlayer(@NotNull UUID uuid) { + return null; + } + + @Override + public @NotNull Set getIPBans() { + return null; + } + + @Override + public void banIP(@NotNull String s) { + + } + + @Override + public void unbanIP(@NotNull String s) { + + } + + @Override + public @NotNull Set getBannedPlayers() { + return null; + } + + @Override + public @NotNull BanList getBanList(BanList.@NotNull Type type) { + return null; + } + + @Override + public @NotNull Set getOperators() { + return null; + } + + @Override + public @NotNull GameMode getDefaultGameMode() { + return null; + } + + @Override + public void setDefaultGameMode(@NotNull GameMode gameMode) { + + } + + @Override + public @NotNull ConsoleCommandSender getConsoleSender() { + return null; + } + + @Override + public @NotNull File getWorldContainer() { + return null; + } + + @Override + public @NotNull OfflinePlayer[] getOfflinePlayers() { + return new OfflinePlayer[0]; + } + + @Override + public @NotNull Messenger getMessenger() { + return null; + } + + @Override + public @NotNull HelpMap getHelpMap() { + return null; + } + + @Override + public @NotNull Inventory createInventory(@Nullable InventoryHolder inventoryHolder, @NotNull InventoryType inventoryType) { + return null; + } + + @Override + public @NotNull Inventory createInventory( + @Nullable InventoryHolder inventoryHolder, + @NotNull InventoryType inventoryType, + @NotNull Component component + ) { + return null; + } + + /** + * @param inventoryHolder + * @param inventoryType + * @param s + * @deprecated + */ + @Override + public @NotNull Inventory createInventory( + @Nullable InventoryHolder inventoryHolder, + @NotNull InventoryType inventoryType, + @NotNull String s + ) { + return null; + } + + @Override + public @NotNull Inventory createInventory(@Nullable InventoryHolder inventoryHolder, int i) throws IllegalArgumentException { + return null; + } + + @Override + public @NotNull Inventory createInventory( + @Nullable InventoryHolder inventoryHolder, + int i, + @NotNull Component component + ) throws IllegalArgumentException { + return null; + } + + /** + * @param inventoryHolder + * @param i + * @param s + * @deprecated + */ + @Override + public @NotNull Inventory createInventory(@Nullable InventoryHolder inventoryHolder, int i, @NotNull String s) throws + IllegalArgumentException { + return null; + } + + @Override + public @NotNull Merchant createMerchant(@Nullable Component component) { + return null; + } + + /** + * @param s + * @deprecated + */ + @Override + public @NotNull Merchant createMerchant(@Nullable String s) { + return null; + } + + @Override + public int getMonsterSpawnLimit() { + return 0; + } + + @Override + public int getAnimalSpawnLimit() { + return 0; + } + + @Override + public int getWaterAnimalSpawnLimit() { + return 0; + } + + @Override + public int getWaterAmbientSpawnLimit() { + return 0; + } + + @Override + public int getAmbientSpawnLimit() { + return 0; + } + + @Override + public boolean isPrimaryThread() { + return false; + } + + @Override + public @NotNull Component motd() { + return null; + } + + /** + * @deprecated + */ + @Override + public @NotNull String getMotd() { + return null; + } + + @Override + public @Nullable Component shutdownMessage() { + return null; + } + + /** + * @deprecated + */ + @Override + public @Nullable String getShutdownMessage() { + return null; + } + + @Override + public Warning.@NotNull WarningState getWarningState() { + return null; + } + + @Override + public @NotNull ItemFactory getItemFactory() { + return null; + } + + @Override + public @NotNull ScoreboardManager getScoreboardManager() { + return null; + } + + @Override + public @Nullable CachedServerIcon getServerIcon() { + return null; + } + + @Override + public @NotNull CachedServerIcon loadServerIcon(@NotNull File file) throws IllegalArgumentException, Exception { + return null; + } + + @Override + public @NotNull CachedServerIcon loadServerIcon(@NotNull BufferedImage bufferedImage) throws IllegalArgumentException, + Exception { + return null; + } + + @Override + public void setIdleTimeout(int i) { + + } + + @Override + public int getIdleTimeout() { + return 0; + } + + @Override + public ChunkGenerator.@NotNull ChunkData createChunkData(@NotNull World world) { + return null; + } + + @Override + public ChunkGenerator.@NotNull ChunkData createVanillaChunkData(@NotNull World world, int i, int i1) { + return null; + } + + @Override + public @NotNull BossBar createBossBar( + @Nullable String s, + @NotNull BarColor barColor, + @NotNull BarStyle barStyle, + @NotNull BarFlag... barFlags + ) { + return null; + } + + @Override + public @NotNull KeyedBossBar createBossBar( + @NotNull NamespacedKey namespacedKey, + @Nullable String s, + @NotNull BarColor barColor, + @NotNull BarStyle barStyle, + @NotNull BarFlag... barFlags + ) { + return null; + } + + @Override + public @NotNull Iterator getBossBars() { + return null; + } + + @Override + public @Nullable KeyedBossBar getBossBar(@NotNull NamespacedKey namespacedKey) { + return null; + } + + @Override + public boolean removeBossBar(@NotNull NamespacedKey namespacedKey) { + return false; + } + + @Override + public @Nullable Entity getEntity(@NotNull UUID uuid) { + return null; + } + + @Override + public @NotNull double[] getTPS() { + return new double[0]; + } + + @Override + public @NotNull long[] getTickTimes() { + return new long[0]; + } + + @Override + public double getAverageTickTime() { + return 0; + } + + @Override + public @NotNull CommandMap getCommandMap() { + return null; + } + + @Override + public @Nullable Advancement getAdvancement(@NotNull NamespacedKey namespacedKey) { + return null; + } + + @Override + public @NotNull Iterator advancementIterator() { + return null; + } + + @Override + public @NotNull BlockData createBlockData(@NotNull Material material) { + return null; + } + + @Override + public @NotNull BlockData createBlockData(@NotNull Material material, @Nullable Consumer consumer) { + return null; + } + + @Override + public @NotNull BlockData createBlockData(@NotNull String s) throws IllegalArgumentException { + return null; + } + + @Override + public @NotNull BlockData createBlockData(@Nullable Material material, @Nullable String s) throws IllegalArgumentException { + return null; + } + + @Override + public Tag getTag(@NotNull String s, @NotNull NamespacedKey namespacedKey, @NotNull Class aClass) { + return null; + } + + @Override + public @NotNull Iterable> getTags(@NotNull String s, @NotNull Class aClass) { + return null; + } + + @Override + public @Nullable LootTable getLootTable(@NotNull NamespacedKey namespacedKey) { + return null; + } + + @Override + public @NotNull List selectEntities(@NotNull CommandSender commandSender, @NotNull String s) throws + IllegalArgumentException { + return null; + } + + /** + * @deprecated + */ + @Override + public @NotNull UnsafeValues getUnsafe() { + return null; + } + + @Override + public @NotNull Spigot spigot() { + return null; + } + + @Override + public void reloadPermissions() { + + } + + @Override + public boolean reloadCommandAliases() { + return false; + } + + @Override + public boolean suggestPlayerNamesWhenNullTabCompletions() { + return false; + } + + @Override + public @NotNull String getPermissionMessage() { + return null; + } + + @Override + public @NotNull PlayerProfile createProfile(@NotNull UUID uuid) { + return null; + } + + @Override + public @NotNull PlayerProfile createProfile(@NotNull String s) { + return null; + } + + @Override + public @NotNull PlayerProfile createProfile(@Nullable UUID uuid, @Nullable String s) { + return null; + } + + @Override + public int getCurrentTick() { + return 0; + } + + @Override + public boolean isStopping() { + return false; + } + + @Override + public @NotNull MobGoals getMobGoals() { + return null; + } + + @Override + public @NotNull DatapackManager getDatapackManager() { + return null; + } + + @Override + public @NotNull Iterable audiences() { + return null; + } + + @Override + public void sendPluginMessage(@NotNull Plugin plugin, @NotNull String s, @NotNull byte[] bytes) { + + } + + @Override + public @NotNull Set getListeningPluginChannels() { + return null; + } + +} diff --git a/worldedit-bukkit/src/test/java/com/sk89q/worldedit/bukkit/BukkitWorldTest.java b/worldedit-bukkit/src/test/java/com/sk89q/worldedit/bukkit/BukkitWorldTest.java index 447f2ec9a..dc593f765 100644 --- a/worldedit-bukkit/src/test/java/com/sk89q/worldedit/bukkit/BukkitWorldTest.java +++ b/worldedit-bukkit/src/test/java/com/sk89q/worldedit/bukkit/BukkitWorldTest.java @@ -19,7 +19,9 @@ package com.sk89q.worldedit.bukkit; +import com.fastasyncworldedit.util.StubServer; import com.sk89q.worldedit.util.TreeGenerator; +import org.bukkit.Bukkit; import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.assertNotNull; @@ -28,6 +30,9 @@ public class BukkitWorldTest { @Test public void testTreeTypeMapping() { + // FAWE start - server implementation required because of LOGGER#warn in BukkitWorld.java + Bukkit.setServer(new StubServer()); + // FAWE end for (TreeGenerator.TreeType type : TreeGenerator.TreeType.values()) { assertNotNull(BukkitWorld.toBukkitTreeType(type), "No mapping for: " + type); } diff --git a/worldedit-core/build.gradle.kts b/worldedit-core/build.gradle.kts index 354b1c694..7795cba77 100644 --- a/worldedit-core/build.gradle.kts +++ b/worldedit-core/build.gradle.kts @@ -65,6 +65,7 @@ dependencies { // Tests testRuntimeOnly(libs.log4jCore) testImplementation(libs.adventureNbt) + testImplementation(libs.parallelgzip) } tasks.named("test") {