diff --git a/paper-api/src/main/java/org/bukkit/enchantments/EnchantmentTarget.java b/paper-api/src/main/java/org/bukkit/enchantments/EnchantmentTarget.java index 6fcc15d588..7a89a472e9 100644 --- a/paper-api/src/main/java/org/bukkit/enchantments/EnchantmentTarget.java +++ b/paper-api/src/main/java/org/bukkit/enchantments/EnchantmentTarget.java @@ -6,7 +6,10 @@ import org.jetbrains.annotations.NotNull; /** * Represents the applicable target for a {@link Enchantment} + * + * @deprecated enchantment groupings are now managed by tags, not categories */ +@Deprecated(since = "1.20.5", forRemoval = true) public enum EnchantmentTarget { /** * Allows the Enchantment to be placed on all items diff --git a/paper-api/src/main/java/org/bukkit/inventory/ItemType.java b/paper-api/src/main/java/org/bukkit/inventory/ItemType.java index 6ef12fd851..f0fda1b69a 100644 --- a/paper-api/src/main/java/org/bukkit/inventory/ItemType.java +++ b/paper-api/src/main/java/org/bukkit/inventory/ItemType.java @@ -3041,7 +3041,7 @@ public interface ItemType extends Keyed, Translatable, net.kyori.adventure.trans * Get the {@link CreativeCategory} to which this item type belongs. * * @return the creative category. null if does not belong to a category - * @deprecated creative categories no longer exist on the server + */ @Nullable @Deprecated(since = "1.20.6") diff --git a/paper-api/src/main/java/org/bukkit/map/MapPalette.java b/paper-api/src/main/java/org/bukkit/map/MapPalette.java index 45d65b00a8..a2a3462ded 100644 --- a/paper-api/src/main/java/org/bukkit/map/MapPalette.java +++ b/paper-api/src/main/java/org/bukkit/map/MapPalette.java @@ -443,7 +443,7 @@ public final class MapPalette { } } - // Minecraft has 143 colors, some of which have negative byte representations + // Minecraft has 248 colors, some of which have negative byte representations return (byte) (index < 128 ? index : -129 + (index - 127)); } @@ -457,7 +457,7 @@ public final class MapPalette { @Deprecated(since = "1.6.2", forRemoval = true) // Paper @NotNull public static Color getColor(byte index) { - // Minecraft has 143 colors, some of which have negative byte representations + // Minecraft has 248 colors, some of which have negative byte representations return colors[index >= 0 ? index : index + 256]; } diff --git a/paper-api/src/test/java/org/bukkit/BukkitMirrorTest.java b/paper-api/src/test/java/org/bukkit/BukkitMirrorTest.java deleted file mode 100644 index 5974ceea58..0000000000 --- a/paper-api/src/test/java/org/bukkit/BukkitMirrorTest.java +++ /dev/null @@ -1,60 +0,0 @@ -package org.bukkit; - -import static org.bukkit.support.MatcherAssert.*; -import static org.hamcrest.Matchers.*; -import java.lang.reflect.Method; -import java.lang.reflect.Modifier; -import java.util.stream.Stream; -import org.junit.jupiter.params.ParameterizedTest; -import org.junit.jupiter.params.provider.Arguments; -import org.junit.jupiter.params.provider.MethodSource; - -@org.junit.jupiter.api.Disabled // Paper -public class BukkitMirrorTest { - - public static Stream data() { - return Stream.of(Server.class.getDeclaredMethods()) - .map(method -> { - try { - return Arguments.of( - method, - method.toGenericString().substring("public abstract ".length()).replace("(", "{").replace(")", "}"), - Bukkit.class.getDeclaredMethod(method.getName(), method.getParameterTypes()) - ); - } catch (NoSuchMethodException e) { - throw new RuntimeException(e); - } - }); - } - - @ParameterizedTest - @MethodSource("data") - public void isStatic(Method server, String name, Method bukkit) throws Throwable { - assertThat(Modifier.isStatic(bukkit.getModifiers()), is(true)); - } - - @ParameterizedTest - @MethodSource("data") - public void isDeprecated(Method server, String name, Method bukkit) throws Throwable { - assertThat(bukkit.isAnnotationPresent(Deprecated.class), is(server.isAnnotationPresent(Deprecated.class))); - } - - @ParameterizedTest - @MethodSource("data") - public void returnType(Method server, String name, Method bukkit) throws Throwable { - assertThat(bukkit.getReturnType(), is((Object) server.getReturnType())); - // assertThat(bukkit.getGenericReturnType(), is(server.getGenericReturnType())); // too strict on type generics - } - - @ParameterizedTest - @MethodSource("data") - public void parameterTypes(Method server, String name, Method bukkit) throws Throwable { - // assertThat(bukkit.getGenericParameterTypes(), is(server.getGenericParameterTypes())); // too strict on type generics - } - - @ParameterizedTest - @MethodSource("data") - public void declaredException(Method server, String name, Method bukkit) throws Throwable { - assertThat(bukkit.getGenericExceptionTypes(), is(server.getGenericExceptionTypes())); - } -} diff --git a/paper-api/src/test/java/org/bukkit/NamespacedKeyTest.java b/paper-api/src/test/java/org/bukkit/NamespacedKeyTest.java index d4e9e24b70..7d81f92008 100644 --- a/paper-api/src/test/java/org/bukkit/NamespacedKeyTest.java +++ b/paper-api/src/test/java/org/bukkit/NamespacedKeyTest.java @@ -29,12 +29,6 @@ public class NamespacedKeyTest { assertNull(NamespacedKey.fromString("foo:bar:bazz")); } - @org.junit.jupiter.api.Disabled // Paper - Fixup NamespacedKey handling - @Test - public void testFromStringEmptyInput() { - assertThrows(IllegalArgumentException.class, () -> NamespacedKey.fromString("")); - } - @Test public void testFromStringNullInput() { assertThrows(IllegalArgumentException.class, () -> NamespacedKey.fromString(null)); @@ -75,12 +69,4 @@ public class NamespacedKeyTest { new NamespacedKey("loremipsumdolorsitametconsecteturadipiscingelitduisvolutpatvelitsitametmaximusscelerisquemorbiullamcorperexacconsequategestas", "loremipsumdolorsitametconsecteturadipiscingelitduisvolutpatvelitsitametmaximusscelerisquemorbiullamcorperexacconsequategestas").toString(); } - - @org.junit.jupiter.api.Disabled // Paper - Fixup NamespacedKey handling - @Test - public void testAboveLength() { - assertThrows(IllegalArgumentException.class, () -> new NamespacedKey("loremipsumdolorsitametconsecteturadipiscingelitduisvolutpatvelitsitametmaximusscelerisquemorbiullamcorperexacconsequategestas", - "loremipsumdolorsitametconsecteturadipiscingelitduisvolutpatvelitsitametmaximusscelerisquemorbiullamcorperexacconsequategestas/" - + "loremipsumdolorsitametconsecteturadipiscingelitduisvolutpatvelitsitametmaximusscelerisquemorbiullamcorperexacconsequategestas").toString()); - } } diff --git a/paper-api/src/test/java/org/bukkit/configuration/ConfigurationSectionTest.java b/paper-api/src/test/java/org/bukkit/configuration/ConfigurationSectionTest.java index c6b49c7e0a..d9a9306e9e 100644 --- a/paper-api/src/test/java/org/bukkit/configuration/ConfigurationSectionTest.java +++ b/paper-api/src/test/java/org/bukkit/configuration/ConfigurationSectionTest.java @@ -546,46 +546,6 @@ public abstract class ConfigurationSectionTest { assertFalse(section.isVector("doesntExist")); } - @Test - @org.junit.jupiter.api.Disabled("ItemStack can't exist without the Server, test moved to server") - public void testGetItemStack_String() { - ConfigurationSection section = getConfigurationSection(); - String key = "exists"; - ItemStack value = new ItemStack(Material.ACACIA_WOOD, 50); - - section.set(key, value); - - assertEquals(value, section.getItemStack(key)); - assertNull(section.getString("doesntExist")); - } - - @Test - @org.junit.jupiter.api.Disabled("ItemStack can't exist without the Server, test moved to server") - public void testGetItemStack_String_ItemStack() { - ConfigurationSection section = getConfigurationSection(); - String key = "exists"; - ItemStack value = new ItemStack(Material.ACACIA_WOOD, 50); - ItemStack def = new ItemStack(Material.STONE, 1); - - section.set(key, value); - - assertEquals(value, section.getItemStack(key, def)); - assertEquals(def, section.getItemStack("doesntExist", def)); - } - - @Test - @org.junit.jupiter.api.Disabled("ItemStack can't exist without the Server, test moved to server") - public void testIsItemStack() { - ConfigurationSection section = getConfigurationSection(); - String key = "exists"; - ItemStack value = new ItemStack(Material.ACACIA_WOOD, 50); - - section.set(key, value); - - assertTrue(section.isItemStack(key)); - assertFalse(section.isItemStack("doesntExist")); - } - @Test public void testGetConfigurationSection() { ConfigurationSection section = getConfigurationSection(); diff --git a/paper-api/src/test/java/org/bukkit/entity/memory/MemoryKeyTest.java b/paper-api/src/test/java/org/bukkit/entity/memory/MemoryKeyTest.java deleted file mode 100644 index e46395cf60..0000000000 --- a/paper-api/src/test/java/org/bukkit/entity/memory/MemoryKeyTest.java +++ /dev/null @@ -1,41 +0,0 @@ -package org.bukkit.entity.memory; - -import static org.junit.jupiter.api.Assertions.*; -import java.util.Arrays; -import java.util.List; -import org.bukkit.NamespacedKey; -import org.junit.jupiter.api.Test; - -public class MemoryKeyTest { - - @Test - public void shouldContainAllMemories() { - List> memories = Arrays.asList(MemoryKey.HOME, MemoryKey.JOB_SITE, MemoryKey.MEETING_POINT); - assertTrue(MemoryKey.values().containsAll(memories)); - } - - @Test - public void shouldGetMemoryKeyHomeByNamespacedKey() { - assertEquals(MemoryKey.HOME, MemoryKey.getByKey(NamespacedKey.minecraft("home"))); - } - - @Test - public void shouldGetMemoryKeyJobSiteByNamespacedKey() { - assertEquals(MemoryKey.JOB_SITE, MemoryKey.getByKey(NamespacedKey.minecraft("job_site"))); - } - - @Test - public void shouldGetMemoryKeyMeetingPointByNamespacedKey() { - assertEquals(MemoryKey.MEETING_POINT, MemoryKey.getByKey(NamespacedKey.minecraft("meeting_point"))); - } - - @Test - public void shouldReturnNullWhenNamespacedKeyisNotPresentAsMemoryKey() { - assertNull(MemoryKey.getByKey(NamespacedKey.minecraft("not_present"))); - } - - @Test - public void shouldReturnNullWhenNamespacedKeyisNull() { - assertNull(MemoryKey.getByKey(null)); - } -} diff --git a/paper-generator/build.gradle.kts b/paper-generator/build.gradle.kts index 59add956b6..8c6fa03f6a 100644 --- a/paper-generator/build.gradle.kts +++ b/paper-generator/build.gradle.kts @@ -103,6 +103,7 @@ fun TaskContainer.registerGenerationTask( val projectDirs = args.mapNotNull { project.rootProject.findProject(it)?.projectDir } if (projectDirs.isNotEmpty()) { args(projectDirs) + systemProperty("paper.updatingMinecraft", providers.gradleProperty("updatingMinecraft").getOrElse("false").toBoolean()) if (rewrite) { systemProperty("typewriter.lexer.ignoreMarkdownDocComments", true) inputs.files(projectDirs.map { it.resolve("src/main/java") }) diff --git a/paper-generator/src/main/java/io/papermc/generator/rewriter/types/simple/MapPaletteRewriter.java b/paper-generator/src/main/java/io/papermc/generator/rewriter/types/simple/MapPaletteRewriter.java index 7369a24d9a..18f4902389 100644 --- a/paper-generator/src/main/java/io/papermc/generator/rewriter/types/simple/MapPaletteRewriter.java +++ b/paper-generator/src/main/java/io/papermc/generator/rewriter/types/simple/MapPaletteRewriter.java @@ -1,15 +1,21 @@ package io.papermc.generator.rewriter.types.simple; +import com.mojang.logging.LogUtils; import io.papermc.typewriter.replace.SearchMetadata; import io.papermc.typewriter.replace.SearchReplaceRewriter; import java.awt.Color; import net.minecraft.world.level.material.MapColor; import org.jspecify.annotations.Nullable; +import org.slf4j.Logger; public class MapPaletteRewriter extends SearchReplaceRewriter { + private static final Logger LOGGER = LogUtils.getLogger(); + private static final boolean UPDATING = Boolean.getBoolean("paper.updatingMinecraft"); + @Override protected void insert(SearchMetadata metadata, StringBuilder builder) { + int count = 0; for (@Nullable MapColor mapColor : MapColor.MATERIAL_COLORS) { if (mapColor == null) { continue; @@ -24,7 +30,12 @@ public class MapPaletteRewriter extends SearchReplaceRewriter { builder.append("new %s(0x%06X),".formatted(color.getClass().getSimpleName(), color.getRGB() & 0x00FFFFFF)); } builder.append('\n'); + count++; } } + + if (UPDATING) { + LOGGER.warn("There are {} map colors, check CraftMapView#render for possible change and update md5 hash in CraftMapColorCache", count); + } } } diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/map/CraftMapColorCache.java b/paper-server/src/main/java/org/bukkit/craftbukkit/map/CraftMapColorCache.java index 8149b9c51b..db51e0f1ad 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/map/CraftMapColorCache.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/map/CraftMapColorCache.java @@ -20,7 +20,7 @@ import org.bukkit.map.MapPalette; public class CraftMapColorCache implements MapPalette.MapColorCache { - private static final String MD5_CACHE_HASH = "E88EDD068D12D39934B40E8B6B124C83"; + private static final String MD5_CACHE_HASH = "E88EDD068D12D39934B40E8B6B124C83"; // 248 colors private static final File CACHE_FILE = new File("map-color-cache.dat"); private byte[] cache; private final Logger logger; @@ -31,10 +31,16 @@ public class CraftMapColorCache implements MapPalette.MapColorCache { this.logger = logger; } + private static CraftMapColorCache dryRun() { + CraftMapColorCache mapColorCache = new CraftMapColorCache(Logger.getGlobal()); + mapColorCache.cache = new byte[256 * 256 * 256]; + mapColorCache.buildCache(); + return mapColorCache; + } + // Builds and prints the md5 hash of the cache, this should be run when new map colors are added to update the MD5_CACHE_HASH string public static void main(String[] args) { - CraftMapColorCache craftMapColorCache = new CraftMapColorCache(Logger.getGlobal()); - craftMapColorCache.buildCache(); + CraftMapColorCache craftMapColorCache = CraftMapColorCache.dryRun(); try { byte[] hash = MessageDigest.getInstance("MD5").digest(craftMapColorCache.cache); System.out.println("MD5_CACHE_HASH: " + CraftMapColorCache.bytesToString(hash)); @@ -151,7 +157,7 @@ public class CraftMapColorCache implements MapPalette.MapColorCache { @Override public byte matchColor(Color color) { - Preconditions.checkState(this.isCached(), "Cache not build jet"); + Preconditions.checkState(this.isCached(), "Cache not build yet"); return this.cache[this.toInt(color)]; } diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/scoreboard/CraftScoreboardTranslations.java b/paper-server/src/main/java/org/bukkit/craftbukkit/scoreboard/CraftScoreboardTranslations.java index 711d227f5e..c010106443 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/scoreboard/CraftScoreboardTranslations.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/scoreboard/CraftScoreboardTranslations.java @@ -1,29 +1,19 @@ package org.bukkit.craftbukkit.scoreboard; -import com.google.common.collect.ImmutableBiMap; import net.minecraft.world.scores.criteria.ObjectiveCriteria; import org.bukkit.scoreboard.DisplaySlot; import org.bukkit.scoreboard.RenderType; public final class CraftScoreboardTranslations { - static final int MAX_DISPLAY_SLOT = 19; - @Deprecated // Paper - static final ImmutableBiMap SLOTS = ImmutableBiMap.builder() - .put(DisplaySlot.BELOW_NAME, "below_name") - .put(DisplaySlot.PLAYER_LIST, "list") - .put(DisplaySlot.SIDEBAR, "sidebar") - .buildOrThrow(); private CraftScoreboardTranslations() {} public static DisplaySlot toBukkitSlot(net.minecraft.world.scores.DisplaySlot minecraft) { - if (true) return DisplaySlot.NAMES.value(minecraft.getSerializedName()); // Paper - return CraftScoreboardTranslations.SLOTS.inverse().get(minecraft.getSerializedName()); + return DisplaySlot.NAMES.value(minecraft.getSerializedName()); // Paper } public static net.minecraft.world.scores.DisplaySlot fromBukkitSlot(DisplaySlot slot) { - if (true) return net.minecraft.world.scores.DisplaySlot.CODEC.byName(slot.getId()); // Paper - return net.minecraft.world.scores.DisplaySlot.CODEC.byName(CraftScoreboardTranslations.SLOTS.get(slot)); + return net.minecraft.world.scores.DisplaySlot.CODEC.byName(slot.getId()); // Paper } static RenderType toBukkitRender(ObjectiveCriteria.RenderType display) { diff --git a/paper-server/src/test/java/io/papermc/paper/entity/EntitySetItemSlotSilentOverrideTest.java b/paper-server/src/test/java/io/papermc/paper/entity/EntitySetItemSlotSilentOverrideTest.java index 18e0ae8155..120263fbae 100644 --- a/paper-server/src/test/java/io/papermc/paper/entity/EntitySetItemSlotSilentOverrideTest.java +++ b/paper-server/src/test/java/io/papermc/paper/entity/EntitySetItemSlotSilentOverrideTest.java @@ -9,6 +9,7 @@ import io.github.classgraph.ScanResult; import java.util.ArrayList; import java.util.List; import java.util.stream.Stream; +import net.minecraft.world.entity.LivingEntity; import org.bukkit.support.environment.Normal; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.MethodSource; @@ -26,7 +27,7 @@ public class EntitySetItemSlotSilentOverrideTest { .whitelistPackages("net.minecraft") .scan() ) { - for (final ClassInfo subclass : scanResult.getSubclasses("net.minecraft.world.entity.LivingEntity")) { + for (final ClassInfo subclass : scanResult.getSubclasses(LivingEntity.class.getName())) { final MethodInfoList setItemSlot = subclass.getDeclaredMethodInfo("setItemSlot"); if (!setItemSlot.isEmpty()) { classInfo.add(subclass); diff --git a/paper-server/src/test/java/io/papermc/paper/scoreboard/DisplaySlotTest.java b/paper-server/src/test/java/io/papermc/paper/scoreboard/DisplaySlotTest.java deleted file mode 100644 index 345c96bfb6..0000000000 --- a/paper-server/src/test/java/io/papermc/paper/scoreboard/DisplaySlotTest.java +++ /dev/null @@ -1,26 +0,0 @@ -package io.papermc.paper.scoreboard; - -import org.bukkit.craftbukkit.scoreboard.CraftScoreboardTranslations; -import org.bukkit.scoreboard.DisplaySlot; -import org.bukkit.support.environment.Normal; -import org.junit.jupiter.api.Test; - -import static org.junit.jupiter.api.Assertions.assertNotNull; - -@Normal -public class DisplaySlotTest { - - @Test - public void testBukkitToMinecraftDisplaySlots() { - for (DisplaySlot bukkitSlot : DisplaySlot.values()) { - assertNotNull(CraftScoreboardTranslations.fromBukkitSlot(bukkitSlot)); - } - } - - @Test - public void testMinecraftToBukkitDisplaySlots() { - for (net.minecraft.world.scores.DisplaySlot nmsSlot : net.minecraft.world.scores.DisplaySlot.values()) { - assertNotNull(CraftScoreboardTranslations.toBukkitSlot(nmsSlot)); - } - } -} diff --git a/paper-server/src/test/java/io/papermc/paper/world/block/BlockPlayerDestroyOverrideTest.java b/paper-server/src/test/java/io/papermc/paper/world/block/BlockPlayerDestroyOverrideTest.java index 22145bf698..750488cb2f 100644 --- a/paper-server/src/test/java/io/papermc/paper/world/block/BlockPlayerDestroyOverrideTest.java +++ b/paper-server/src/test/java/io/papermc/paper/world/block/BlockPlayerDestroyOverrideTest.java @@ -9,6 +9,7 @@ import io.github.classgraph.ScanResult; import java.util.ArrayList; import java.util.List; import java.util.stream.Stream; +import net.minecraft.world.level.block.Block; import org.bukkit.support.environment.Normal; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.MethodSource; @@ -26,7 +27,7 @@ public class BlockPlayerDestroyOverrideTest { .whitelistPackages("net.minecraft") .scan() ) { - for (final ClassInfo subclass : scanResult.getSubclasses("net.minecraft.world.level.block.Block")) { + for (final ClassInfo subclass : scanResult.getSubclasses(Block.class.getName())) { final MethodInfoList playerDestroy = subclass.getDeclaredMethodInfo("playerDestroy"); if (!playerDestroy.isEmpty()) { classInfo.add(subclass); diff --git a/paper-server/src/test/java/org/bukkit/ArtTest.java b/paper-server/src/test/java/org/bukkit/ArtTest.java deleted file mode 100644 index 5e922e6805..0000000000 --- a/paper-server/src/test/java/org/bukkit/ArtTest.java +++ /dev/null @@ -1,56 +0,0 @@ -package org.bukkit; - -import static org.junit.jupiter.api.Assertions.*; -import java.util.stream.Stream; -import org.bukkit.support.environment.VanillaFeature; -import org.junit.jupiter.params.ParameterizedTest; -import org.junit.jupiter.params.provider.Arguments; -import org.junit.jupiter.params.provider.MethodSource; - -@VanillaFeature -public class ArtTest { - - public static Stream widthData() { - return Stream.of(Arguments.of(Art.KEBAB, 1), - Arguments.of(Art.WANDERER, 1), - Arguments.of(Art.POOL, 2), - Arguments.of(Art.MATCH, 2), - Arguments.of(Art.BOUQUET, 3), - Arguments.of(Art.BACKYARD, 3), - Arguments.of(Art.FIGHTERS, 4), - Arguments.of(Art.SKELETON, 4), - Arguments.of(Art.POINTER, 4)); - } - - public static Stream heightData() { - return Stream.of(Arguments.of(Art.KEBAB, 1), - Arguments.of(Art.WANDERER, 2), - Arguments.of(Art.POOL, 1), - Arguments.of(Art.MATCH, 2), - Arguments.of(Art.BOUQUET, 3), - Arguments.of(Art.BACKYARD, 4), - Arguments.of(Art.FIGHTERS, 2), - Arguments.of(Art.SKELETON, 3), - Arguments.of(Art.POINTER, 4)); - } - - @ParameterizedTest - @MethodSource("widthData") - public void testWidth(Art art, int expected) { - assertEquals(expected, art.getBlockWidth(), """ - Art '%s' does not have the correct width. - This can be caused by either a change in the Implementation. - Or the width for this specific art was changed in which case the test needs to be updated. - """.formatted(art.getKey())); - } - - @ParameterizedTest - @MethodSource("heightData") - public void testHeight(Art art, int expected) { - assertEquals(expected, art.getBlockHeight(), """ - Art '%s' does not have the correct height. - This can be caused by either a change in the Implementation. - Or the height for this specific art was changed in which case the test needs to be updated. - """.formatted(art.getKey())); - } -} diff --git a/paper-server/src/test/java/org/bukkit/BiomeTest.java b/paper-server/src/test/java/org/bukkit/BiomeTest.java deleted file mode 100644 index f17d553f51..0000000000 --- a/paper-server/src/test/java/org/bukkit/BiomeTest.java +++ /dev/null @@ -1,32 +0,0 @@ -package org.bukkit; - -import static org.junit.jupiter.api.Assertions.*; -import net.minecraft.core.registries.Registries; -import org.bukkit.block.Biome; -import org.bukkit.craftbukkit.CraftRegistry; -import org.bukkit.craftbukkit.block.CraftBiome; -import org.bukkit.support.environment.AllFeatures; -import org.junit.jupiter.api.Test; - -@AllFeatures -public class BiomeTest { - - @Test - public void testBukkitToMinecraft() { - for (Biome biome : Biome.values()) { - if (biome == Biome.CUSTOM) { - continue; - } - - assertNotNull(CraftBiome.bukkitToMinecraftHolder(biome), "No NMS mapping for " + biome); - } - } - - @Test - public void testMinecraftToBukkit() { - for (net.minecraft.world.level.biome.Biome biomeBase : CraftRegistry.getMinecraftRegistry(Registries.BIOME)) { - Biome biome = CraftBiome.minecraftToBukkit(biomeBase); - assertTrue(biome != null && biome != Biome.CUSTOM, "No Bukkit mapping for " + biomeBase); - } - } -} diff --git a/paper-server/src/test/java/org/bukkit/EffectTest.java b/paper-server/src/test/java/org/bukkit/EffectTest.java index 3129212415..5eaa832abb 100644 --- a/paper-server/src/test/java/org/bukkit/EffectTest.java +++ b/paper-server/src/test/java/org/bukkit/EffectTest.java @@ -12,9 +12,7 @@ import java.util.Set; import net.minecraft.world.level.block.LevelEvent; import org.junit.jupiter.api.Test; -import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertNull; -import static org.junit.jupiter.api.Assertions.assertTrue; import static org.junit.jupiter.api.Assertions.fail; public class EffectTest { diff --git a/paper-server/src/test/java/org/bukkit/EnchantmentTest.java b/paper-server/src/test/java/org/bukkit/EnchantmentTest.java deleted file mode 100644 index 1b22f02b04..0000000000 --- a/paper-server/src/test/java/org/bukkit/EnchantmentTest.java +++ /dev/null @@ -1,25 +0,0 @@ -package org.bukkit; - -import static org.junit.jupiter.api.Assertions.*; -import net.minecraft.core.registries.Registries; -import net.minecraft.resources.ResourceLocation; -import org.bukkit.craftbukkit.CraftRegistry; -import org.bukkit.craftbukkit.util.CraftNamespacedKey; -import org.bukkit.enchantments.Enchantment; -import org.bukkit.support.environment.AllFeatures; -import org.junit.jupiter.api.Test; - -@AllFeatures -public class EnchantmentTest { - - @Test - public void verifyMapping() { - for (ResourceLocation key : CraftRegistry.getMinecraftRegistry(Registries.ENCHANTMENT).keySet()) { - net.minecraft.world.item.enchantment.Enchantment nms = CraftRegistry.getMinecraftRegistry(Registries.ENCHANTMENT).getValue(key); - - Enchantment bukkitById = Enchantment.getByKey(CraftNamespacedKey.fromMinecraft(key)); - - assertFalse(bukkitById.getName().startsWith("UNKNOWN"), "Unknown enchant name for " + key); - } - } -} diff --git a/paper-server/src/test/java/org/bukkit/GameEventTest.java b/paper-server/src/test/java/org/bukkit/GameEventTest.java deleted file mode 100644 index 7d2f13ff72..0000000000 --- a/paper-server/src/test/java/org/bukkit/GameEventTest.java +++ /dev/null @@ -1,20 +0,0 @@ -package org.bukkit; - -import static org.junit.jupiter.api.Assertions.*; -import net.minecraft.core.registries.BuiltInRegistries; -import org.bukkit.craftbukkit.util.CraftNamespacedKey; -import org.bukkit.support.environment.AllFeatures; -import org.junit.jupiter.api.Test; - -@AllFeatures -public class GameEventTest { - - @Test - public void toBukkit() { - for (net.minecraft.world.level.gameevent.GameEvent nms : BuiltInRegistries.GAME_EVENT) { - GameEvent bukkit = GameEvent.getByKey(CraftNamespacedKey.fromMinecraft(BuiltInRegistries.GAME_EVENT.getKey(nms))); - - assertNotNull(bukkit, "Bukkit should not be null " + nms); - } - } -} diff --git a/paper-server/src/test/java/org/bukkit/PerMaterialTest.java b/paper-server/src/test/java/org/bukkit/PerMaterialTest.java index 6961730365..ccb2aaaf4f 100644 --- a/paper-server/src/test/java/org/bukkit/PerMaterialTest.java +++ b/paper-server/src/test/java/org/bukkit/PerMaterialTest.java @@ -3,21 +3,9 @@ package org.bukkit; import static org.bukkit.support.MatcherAssert.*; import static org.hamcrest.Matchers.*; import static org.junit.jupiter.api.Assertions.*; -import java.util.Map; -import net.minecraft.core.BlockPos; + import net.minecraft.core.component.DataComponents; -import net.minecraft.world.InteractionHand; -import net.minecraft.world.entity.player.Player; -import net.minecraft.world.item.Item; import net.minecraft.world.item.equipment.Equippable; -import net.minecraft.world.level.EmptyBlockGetter; -import net.minecraft.world.level.block.Block; -import net.minecraft.world.level.block.Blocks; -import net.minecraft.world.level.block.Fallable; -import net.minecraft.world.level.block.FireBlock; -import net.minecraft.world.level.block.state.BlockBehaviour; -import net.minecraft.world.level.block.state.BlockState; -import net.minecraft.world.phys.BlockHitResult; import org.bukkit.block.data.BlockData; import org.bukkit.craftbukkit.CraftEquipmentSlot; import org.bukkit.craftbukkit.inventory.CraftItemStack; @@ -26,92 +14,17 @@ import org.bukkit.enchantments.EnchantmentTarget; import org.bukkit.inventory.EquipmentSlot; import org.bukkit.inventory.ItemStack; import org.bukkit.material.MaterialData; -import org.bukkit.support.LegacyHelper; import org.bukkit.support.environment.AllFeatures; -import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Disabled; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.EnumSource; @AllFeatures public class PerMaterialTest { - private static Map fireValues; - - @BeforeAll - public static void getFireValues() { - PerMaterialTest.fireValues = ((FireBlock) Blocks.FIRE).igniteOdds; - } - - @ParameterizedTest - @EnumSource(value = Material.class, names = "LEGACY_.*", mode = EnumSource.Mode.MATCH_NONE) - public void isBlock(Material material) { - if (material != Material.AIR && material != Material.CAVE_AIR && material != Material.VOID_AIR) { - assertThat(material.isBlock(), is(not(CraftMagicNumbers.getBlock(material) == null))); - } - } - - @ParameterizedTest - @EnumSource(value = Material.class, names = "LEGACY_.*", mode = EnumSource.Mode.MATCH_NONE) - public void isSolid(Material material) { - if (material == Material.AIR) { - assertFalse(material.isSolid()); - } else if (material.isBlock()) { - assertThat(material.isSolid(), is(CraftMagicNumbers.getBlock(material).defaultBlockState().blocksMotion())); - } else { - assertFalse(material.isSolid()); - } - } - - @ParameterizedTest - @EnumSource(value = Material.class, names = "LEGACY_.*", mode = EnumSource.Mode.MATCH_NONE) - public void isEdible(Material material) { - if (material.isBlock()) { - assertFalse(material.isEdible()); - } else { - assertThat(material.isEdible(), is(CraftMagicNumbers.getItem(material).components().has(DataComponents.FOOD))); - } - } - - @ParameterizedTest - @EnumSource(value = Material.class, names = "LEGACY_.*", mode = EnumSource.Mode.MATCH_NONE) - public void isRecord(Material material) { - if (material.isBlock()) { - assertFalse(material.isRecord()); - } else { - assertThat(material.isRecord(), is(CraftMagicNumbers.getItem(material).components().has(DataComponents.JUKEBOX_PLAYABLE))); - } - } - - @ParameterizedTest - @EnumSource(value = Material.class, names = "LEGACY_.*", mode = EnumSource.Mode.MATCH_NONE) - public void maxDurability(Material material) { - if (LegacyHelper.getInvalidatedMaterials().contains(material)) return; - - if (material == Material.AIR) { - assertThat((int) material.getMaxDurability(), is(0)); - } else if (material.isBlock()) { - Item item = CraftMagicNumbers.getItem(material); - assertThat((int) material.getMaxDurability(), is(item.components().getOrDefault(DataComponents.MAX_DAMAGE, 0))); - } - } - - @ParameterizedTest - @EnumSource(value = Material.class, names = "LEGACY_.*", mode = EnumSource.Mode.MATCH_NONE) - public void maxStackSize(Material material) { - if (LegacyHelper.getInvalidatedMaterials().contains(material)) return; - - final ItemStack bukkit = new ItemStack(material); - final CraftItemStack craft = CraftItemStack.asCraftCopy(bukkit); - - // Paper - remove air exception - int max = CraftMagicNumbers.getItem(material).components().getOrDefault(DataComponents.MAX_STACK_SIZE, 64); - assertThat(material.getMaxStackSize(), is(max)); - assertThat(bukkit.getMaxStackSize(), is(max)); - assertThat(craft.getMaxStackSize(), is(max)); - // Paper - remove air exception - } @ParameterizedTest @EnumSource(value = Material.class, names = "LEGACY_.*", mode = EnumSource.Mode.MATCH_NONE) + @Disabled public void isTransparent(Material material) { if (material == Material.AIR) { assertTrue(material.isTransparent()); @@ -122,47 +35,6 @@ public class PerMaterialTest { } } - @ParameterizedTest - @EnumSource(value = Material.class, names = "LEGACY_.*", mode = EnumSource.Mode.MATCH_NONE) - public void isFlammable(Material material) { - if (material != Material.AIR && material.isBlock()) { - assertThat(material.isFlammable(), is(CraftMagicNumbers.getBlock(material).defaultBlockState().ignitedByLava())); - } else { - assertFalse(material.isFlammable()); - } - } - - @ParameterizedTest - @EnumSource(value = Material.class, names = "LEGACY_.*", mode = EnumSource.Mode.MATCH_NONE) - public void isBurnable(Material material) { - if (material.isBlock()) { - Block block = CraftMagicNumbers.getBlock(material); - assertThat(material.isBurnable(), is(PerMaterialTest.fireValues.containsKey(block) && PerMaterialTest.fireValues.get(block) > 0)); - } else { - assertFalse(material.isBurnable()); - } - } - - @ParameterizedTest - @EnumSource(value = Material.class, names = "LEGACY_.*", mode = EnumSource.Mode.MATCH_NONE) - public void isOccluding(Material material) { - if (material.isBlock()) { - assertThat(material.isOccluding(), is(CraftMagicNumbers.getBlock(material).defaultBlockState().isRedstoneConductor(EmptyBlockGetter.INSTANCE, BlockPos.ZERO))); - } else { - assertFalse(material.isOccluding()); - } - } - - @ParameterizedTest - @EnumSource(value = Material.class, names = "LEGACY_.*", mode = EnumSource.Mode.MATCH_NONE) - public void hasGravity(Material material) { - if (material.isBlock()) { - assertThat(material.hasGravity(), is(CraftMagicNumbers.getBlock(material) instanceof Fallable)); - } else { - assertFalse(material.hasGravity()); - } - } - @ParameterizedTest @EnumSource(value = Material.class, names = "LEGACY_.*", mode = EnumSource.Mode.MATCH_NONE) public void usesDurability(Material material) { @@ -173,104 +45,6 @@ public class PerMaterialTest { } } - @ParameterizedTest - @EnumSource(value = Material.class, names = "LEGACY_.*", mode = EnumSource.Mode.MATCH_NONE) - public void testDurability(Material material) { - if (!material.isBlock()) { - assertThat(material.getMaxDurability(), is((short) (int) CraftMagicNumbers.getItem(material).components().getOrDefault(DataComponents.MAX_DAMAGE, 0))); - } else { - assertThat(material.getMaxDurability(), is((short) 0)); - } - } - - @ParameterizedTest - @EnumSource(value = Material.class, names = "LEGACY_.*", mode = EnumSource.Mode.MATCH_NONE) - public void testBlock(Material material) { - if (material == Material.AIR) { - assertTrue(material.isBlock()); - } else { - assertThat(material.isBlock(), is(equalTo(CraftMagicNumbers.getBlock(material) != null))); - } - } - - @ParameterizedTest - @EnumSource(value = Material.class, names = "LEGACY_.*", mode = EnumSource.Mode.MATCH_NONE) - public void testAir(Material material) { - if (material.isBlock()) { - assertThat(material.isAir(), is(equalTo(CraftMagicNumbers.getBlock(material).defaultBlockState().isAir()))); - } else { - assertThat(material.isAir(), is(equalTo(false))); - } - } - - @ParameterizedTest - @EnumSource(value = Material.class, names = "LEGACY_.*", mode = EnumSource.Mode.MATCH_NONE) - public void testItem(Material material) { - if (material == Material.AIR) { - assertTrue(material.isItem()); - } else { - assertThat(material.isItem(), is(equalTo(CraftMagicNumbers.getItem(material) != null))); - } - } - - @ParameterizedTest - @EnumSource(value = Material.class, names = "LEGACY_.*", mode = EnumSource.Mode.MATCH_NONE) - public void testInteractable(Material material) throws ReflectiveOperationException { - if (material.isBlock()) { - Class clazz = CraftMagicNumbers.getBlock(material).getClass(); - - boolean hasMethod = this.hasMethod(clazz, "useWithoutItem", BlockState.class, net.minecraft.world.level.Level.class, BlockPos.class, Player.class, BlockHitResult.class) - || this.hasMethod(clazz, "useItemOn", net.minecraft.world.item.ItemStack.class, BlockState.class, net.minecraft.world.level.Level.class, BlockPos.class, Player.class, InteractionHand.class, BlockHitResult.class); - - if (!hasMethod && clazz.getSuperclass() != BlockBehaviour.class) { - clazz = clazz.getSuperclass(); - - hasMethod = this.hasMethod(clazz, "useWithoutItem", BlockState.class, net.minecraft.world.level.Level.class, BlockPos.class, Player.class, BlockHitResult.class) - || this.hasMethod(clazz, "useItemOn", net.minecraft.world.item.ItemStack.class, BlockState.class, net.minecraft.world.level.Level.class, BlockPos.class, Player.class, InteractionHand.class, BlockHitResult.class); - } - - assertThat(material.isInteractable(), - is(hasMethod)); - } else { - assertFalse(material.isInteractable()); - } - } - - private boolean hasMethod(Class clazz, String methodName, Class... params) { - boolean hasMethod; - try { - hasMethod = clazz.getDeclaredMethod(methodName, params) != null; - } catch (NoSuchMethodException ex) { - hasMethod = false; - } - - return hasMethod; - } - - @ParameterizedTest - @EnumSource(value = Material.class, names = "LEGACY_.*", mode = EnumSource.Mode.MATCH_NONE) - public void testBlockHardness(Material material) { - if (material.isBlock()) { - assertThat(material.getHardness(), is(CraftMagicNumbers.getBlock(material).defaultBlockState().destroySpeed)); - } - } - - @ParameterizedTest - @EnumSource(value = Material.class, names = "LEGACY_.*", mode = EnumSource.Mode.MATCH_NONE) - public void testBlastResistance(Material material) { - if (material.isBlock()) { - assertThat(material.getBlastResistance(), is(CraftMagicNumbers.getBlock(material).getExplosionResistance())); - } - } - - @ParameterizedTest - @EnumSource(value = Material.class, names = "LEGACY_.*", mode = EnumSource.Mode.MATCH_NONE) - public void testSlipperiness(Material material) { - if (material.isBlock()) { - assertThat(material.getSlipperiness(), is(CraftMagicNumbers.getBlock(material).getFriction())); - } - } - @ParameterizedTest @EnumSource(value = Material.class, names = "LEGACY_.*", mode = EnumSource.Mode.MATCH_NONE) public void testBlockDataCreation(Material material) { @@ -279,17 +53,6 @@ public class PerMaterialTest { } } - @ParameterizedTest - @EnumSource(value = Material.class, names = "LEGACY_.*", mode = EnumSource.Mode.MATCH_NONE) - public void testCraftingRemainingItem(Material material) { - if (material.isItem()) { - net.minecraft.world.item.ItemStack expectedItem = CraftMagicNumbers.getItem(material).getCraftingRemainder(); - Material expected = expectedItem.isEmpty() ? null : CraftMagicNumbers.getMaterial(expectedItem.getItem()); - - assertThat(material.getCraftingRemainingItem(), is(expected)); - } - } - @ParameterizedTest @EnumSource(value = Material.class, names = "LEGACY_.*", mode = EnumSource.Mode.MATCH_NONE) public void testEquipmentSlot(Material material) { @@ -311,12 +74,4 @@ public class PerMaterialTest { } } } - - @ParameterizedTest - @EnumSource(value = Material.class, names = "LEGACY_.*", mode = EnumSource.Mode.MATCH_NONE) - public void testCreativeCategory(Material material) { - if (material.isItem()) { - material.getCreativeCategory(); - } - } } diff --git a/paper-server/src/test/java/org/bukkit/SoundTest.java b/paper-server/src/test/java/org/bukkit/SoundTest.java index 607e7da136..ef268c0436 100644 --- a/paper-server/src/test/java/org/bukkit/SoundTest.java +++ b/paper-server/src/test/java/org/bukkit/SoundTest.java @@ -1,32 +1,13 @@ package org.bukkit; -import static org.bukkit.support.MatcherAssert.*; -import static org.hamcrest.Matchers.*; import static org.junit.jupiter.api.Assertions.*; -import java.util.Locale; -import net.minecraft.core.registries.BuiltInRegistries; -import net.minecraft.resources.ResourceLocation; -import org.bukkit.craftbukkit.CraftSound; + import org.bukkit.support.environment.AllFeatures; import org.junit.jupiter.api.Test; @AllFeatures public class SoundTest { - @Test - public void testGetSound() { - for (Sound sound : Sound.values()) { - assertThat(CraftSound.bukkitToMinecraft(sound), is(not(nullValue())), sound.name()); - } - } - - @Test - public void testReverse() { - for (ResourceLocation effect : BuiltInRegistries.SOUND_EVENT.keySet()) { - assertNotNull(Sound.valueOf(effect.getPath().replace('.', '_').toUpperCase(Locale.ROOT)), effect + ""); - } - } - @Test public void testCategory() { for (SoundCategory category : SoundCategory.values()) { diff --git a/paper-server/src/test/java/org/bukkit/StatisticsAndAchievementsTest.java b/paper-server/src/test/java/org/bukkit/StatisticsAndAchievementsTest.java index 270befba49..34548dcc73 100644 --- a/paper-server/src/test/java/org/bukkit/StatisticsAndAchievementsTest.java +++ b/paper-server/src/test/java/org/bukkit/StatisticsAndAchievementsTest.java @@ -15,8 +15,7 @@ import org.junit.jupiter.api.Test; public class StatisticsAndAchievementsTest { @Test - @SuppressWarnings("unchecked") - public void verifyEntityMapping() throws Throwable { + public void verifyEntityMapping() { for (Statistic statistic : Statistic.values()) { if (statistic.getType() == Statistic.Type.ENTITY) { for (EntityType entity : EntityType.values()) { @@ -30,7 +29,7 @@ public class StatisticsAndAchievementsTest { @Test @SuppressWarnings("unchecked") - public void verifyStatisticMapping() throws Throwable { + public void verifyStatisticMapping() { HashMultiset statistics = HashMultiset.create(); for (StatType wrapper : BuiltInRegistries.STAT_TYPE) { for (Object child : wrapper.getRegistry()) { diff --git a/paper-server/src/test/java/org/bukkit/block/banner/PatternTypeTest.java b/paper-server/src/test/java/org/bukkit/block/banner/PatternTypeTest.java deleted file mode 100644 index 66db0cf71b..0000000000 --- a/paper-server/src/test/java/org/bukkit/block/banner/PatternTypeTest.java +++ /dev/null @@ -1,42 +0,0 @@ -package org.bukkit.block.banner; - -import static org.junit.jupiter.api.Assertions.*; - -import net.minecraft.core.registries.Registries; -import net.minecraft.server.MinecraftServer; -import net.minecraft.world.level.block.entity.BannerPattern; -import org.bukkit.NamespacedKey; -import org.bukkit.Registry; -import org.bukkit.craftbukkit.util.CraftNamespacedKey; -import org.bukkit.support.environment.AllFeatures; -import org.junit.jupiter.api.Test; - -@AllFeatures -public class PatternTypeTest { - - @Test - public void testToBukkit() { - for (BannerPattern nms : MinecraftServer.getDefaultRegistryAccess().lookupOrThrow(Registries.BANNER_PATTERN)) { - PatternType bukkit = Registry.BANNER_PATTERN.get(CraftNamespacedKey.fromMinecraft(nms.assetId())); - - assertNotNull(bukkit, "No Bukkit banner pattern for " + nms + " " + nms); - } - } - - @Test - public void testToNMS() { - net.minecraft.core.Registry registry = MinecraftServer.getDefaultRegistryAccess().lookupOrThrow(Registries.BANNER_PATTERN); - for (PatternType bukkit : PatternType.values()) { - BannerPattern found = null; - for (BannerPattern nms : registry) { - NamespacedKey nmsKey = CraftNamespacedKey.fromMinecraft(registry.getKey(nms)); - if (bukkit.getKey().equals(nmsKey)) { - found = nms; - break; - } - } - - assertNotNull(found, "No NMS banner pattern for " + bukkit + " " + bukkit.getKey()); - } - } -} diff --git a/paper-server/src/test/java/org/bukkit/entity/EntityTypesTest.java b/paper-server/src/test/java/org/bukkit/entity/EntityTypesTest.java index d513d926dd..a4e2c42e9a 100644 --- a/paper-server/src/test/java/org/bukkit/entity/EntityTypesTest.java +++ b/paper-server/src/test/java/org/bukkit/entity/EntityTypesTest.java @@ -1,33 +1,13 @@ package org.bukkit.entity; import static org.junit.jupiter.api.Assertions.*; -import java.util.Arrays; -import java.util.Set; -import java.util.stream.Collectors; -import net.minecraft.core.registries.BuiltInRegistries; -import net.minecraft.resources.ResourceLocation; + import org.bukkit.support.environment.AllFeatures; import org.junit.jupiter.api.Test; @AllFeatures public class EntityTypesTest { - @Test - public void testMaps() { - Set allBukkit = Arrays.stream(EntityType.values()).filter((b) -> b.getName() != null).collect(Collectors.toSet()); - - for (net.minecraft.world.entity.EntityType nms : BuiltInRegistries.ENTITY_TYPE) { // Paper - remap fix - ResourceLocation key = net.minecraft.world.entity.EntityType.getKey(nms); // Paper - remap fix - - org.bukkit.entity.EntityType bukkit = org.bukkit.entity.EntityType.fromName(key.getPath()); - assertNotNull(bukkit, "Missing nms->bukkit " + key); - - assertTrue(allBukkit.remove(bukkit), "Duplicate entity nms->" + bukkit); - } - - assertTrue(allBukkit.isEmpty(), "Unmapped bukkit entities " + allBukkit); - } - @Test public void testTranslationKey() { for (org.bukkit.entity.EntityType entityType : org.bukkit.entity.EntityType.values()) { diff --git a/paper-server/src/test/java/org/bukkit/entity/PandaGeneTest.java b/paper-server/src/test/java/org/bukkit/entity/PandaGeneTest.java deleted file mode 100644 index e8520f541f..0000000000 --- a/paper-server/src/test/java/org/bukkit/entity/PandaGeneTest.java +++ /dev/null @@ -1,33 +0,0 @@ -package org.bukkit.entity; - -import static org.junit.jupiter.api.Assertions.*; - -import org.bukkit.craftbukkit.entity.CraftPanda; -import org.bukkit.support.environment.Normal; -import org.junit.jupiter.api.Test; - -@Normal -public class PandaGeneTest { - - @Test - public void testBukkit() { - for (Panda.Gene gene : Panda.Gene.values()) { // Paper - remap fix - net.minecraft.world.entity.animal.Panda.Gene nms = CraftPanda.toNms(gene); // Paper - remap fix - - assertNotNull(nms, "NMS gene null for " + gene); - assertEquals(gene.isRecessive(), nms.isRecessive(), "Recessive status did not match " + gene); - assertEquals(gene, CraftPanda.fromNms(nms), "Gene did not convert back " + gene); - } - } - - @Test - public void testNMS() { - for (net.minecraft.world.entity.animal.Panda.Gene gene : net.minecraft.world.entity.animal.Panda.Gene.values()) { // Paper - remap fix - org.bukkit.entity.Panda.Gene bukkit = CraftPanda.fromNms(gene); - - assertNotNull(bukkit, "Bukkit gene null for " + gene); - assertEquals(gene.isRecessive(), bukkit.isRecessive(), "Recessive status did not match " + gene); - assertEquals(gene, CraftPanda.toNms(bukkit), "Gene did not convert back " + gene); - } - } -} diff --git a/paper-server/src/test/java/org/bukkit/entity/memory/CraftMemoryKeyTest.java b/paper-server/src/test/java/org/bukkit/entity/memory/CraftMemoryKeyTest.java deleted file mode 100644 index a58a98a1d5..0000000000 --- a/paper-server/src/test/java/org/bukkit/entity/memory/CraftMemoryKeyTest.java +++ /dev/null @@ -1,51 +0,0 @@ -package org.bukkit.entity.memory; - -import static org.junit.jupiter.api.Assertions.*; -import net.minecraft.core.GlobalPos; -import net.minecraft.core.registries.BuiltInRegistries; -import net.minecraft.world.entity.ai.memory.MemoryModuleType; -import org.bukkit.Location; -import org.bukkit.craftbukkit.entity.memory.CraftMemoryKey; -import org.bukkit.support.environment.AllFeatures; -import org.junit.jupiter.api.Disabled; -import org.junit.jupiter.api.Test; - -@AllFeatures -public class CraftMemoryKeyTest { - - @Test - public void shouldConvertBukkitHomeKeyToNMSRepresentation() { - MemoryModuleType nmsHomeKey = CraftMemoryKey.bukkitToMinecraft(MemoryKey.HOME); - assertEquals(MemoryModuleType.HOME, nmsHomeKey, "MemoryModuleType should be HOME"); - } - - @Test - public void shouldConvertBukkitJobSiteKeyToNMSRepresentation() { - MemoryModuleType nmsHomeKey = CraftMemoryKey.bukkitToMinecraft(MemoryKey.JOB_SITE); - assertEquals(MemoryModuleType.JOB_SITE, nmsHomeKey, "MemoryModuleType should be JOB_SITE"); - } - - @Test - public void shouldConvertBukkitMeetingPointKeyToNMSRepresentation() { - MemoryModuleType nmsHomeKey = CraftMemoryKey.bukkitToMinecraft(MemoryKey.MEETING_POINT); - assertEquals(MemoryModuleType.MEETING_POINT, nmsHomeKey, "MemoryModuleType should be MEETING_POINT"); - } - - @Test - public void shouldConvertNMSHomeKeyToBukkitRepresentation() { - MemoryKey bukkitHomeKey = CraftMemoryKey.minecraftToBukkit(MemoryModuleType.HOME); - assertEquals(MemoryKey.HOME, bukkitHomeKey, "MemoryModuleType should be HOME"); - } - - @Test - public void shouldConvertNMSJobSiteKeyToBukkitRepresentation() { - MemoryKey bukkitJobSiteKey = CraftMemoryKey.minecraftToBukkit(MemoryModuleType.JOB_SITE); - assertEquals(MemoryKey.JOB_SITE, bukkitJobSiteKey, "MemoryKey should be JOB_SITE"); - } - - @Test - public void shouldConvertNMSMeetingPointKeyToBukkitRepresentation() { - MemoryKey bukkitHomeKey = CraftMemoryKey.minecraftToBukkit(MemoryModuleType.MEETING_POINT); - assertEquals(MemoryKey.MEETING_POINT, bukkitHomeKey, "MemoryKey should be MEETING_POINT"); - } -} diff --git a/paper-server/src/test/java/org/bukkit/generator/structure/StructureTest.java b/paper-server/src/test/java/org/bukkit/generator/structure/StructureTest.java deleted file mode 100644 index cbfc533ed8..0000000000 --- a/paper-server/src/test/java/org/bukkit/generator/structure/StructureTest.java +++ /dev/null @@ -1,53 +0,0 @@ -package org.bukkit.generator.structure; - -import static org.junit.jupiter.api.Assertions.*; -import java.lang.reflect.Field; -import java.lang.reflect.Modifier; -import java.util.Locale; -import net.minecraft.core.registries.Registries; -import net.minecraft.resources.ResourceLocation; -import org.bukkit.NamespacedKey; -import org.bukkit.Registry; -import org.bukkit.craftbukkit.CraftRegistry; -import org.bukkit.craftbukkit.util.CraftNamespacedKey; -import org.bukkit.support.environment.AllFeatures; -import org.junit.jupiter.api.Test; - -@AllFeatures -public class StructureTest { - - @Test - public void testBukkitToMinecraftFieldName() { - for (Field field : Structure.class.getFields()) { - if (field.getType() != Structure.class) { - continue; - } - if (!Modifier.isStatic(field.getModifiers())) { - continue; - } - - String name = field.getName(); - assertNotNull(Registry.STRUCTURE.get(NamespacedKey.fromString(name.toLowerCase(Locale.ROOT))), "No structure for field name " + name); - } - } - - @Test - public void testMinecraftToBukkitFieldName() { - net.minecraft.core.Registry structureBuiltInRegistries = CraftRegistry.getMinecraftRegistry(Registries.STRUCTURE); - for (net.minecraft.world.level.levelgen.structure.Structure structure : structureBuiltInRegistries) { - ResourceLocation minecraftKey = structureBuiltInRegistries.getKey(structure); - - try { - Structure bukkit = (Structure) Structure.class.getField(minecraftKey.getPath().toUpperCase(Locale.ROOT)).get(null); - - assertEquals(minecraftKey, CraftNamespacedKey.toMinecraft(bukkit.getKey()), "Keys are not the same for " + minecraftKey); - } catch (NoSuchFieldException e) { - fail("No Bukkit default structure for " + minecraftKey); - } catch (IllegalAccessException e) { - fail("Bukkit field is not access able for " + minecraftKey); - } catch (ClassCastException e) { - fail("Bukkit field is not of type structure for" + minecraftKey); - } - } - } -} diff --git a/paper-server/src/test/java/org/bukkit/generator/structure/StructureTypeTest.java b/paper-server/src/test/java/org/bukkit/generator/structure/StructureTypeTest.java deleted file mode 100644 index 78fa3f3166..0000000000 --- a/paper-server/src/test/java/org/bukkit/generator/structure/StructureTypeTest.java +++ /dev/null @@ -1,53 +0,0 @@ -package org.bukkit.generator.structure; - -import static org.junit.jupiter.api.Assertions.*; -import java.lang.reflect.Field; -import java.lang.reflect.Modifier; -import java.util.Locale; -import net.minecraft.core.registries.BuiltInRegistries; -import net.minecraft.core.registries.Registries; -import net.minecraft.resources.ResourceLocation; -import org.bukkit.NamespacedKey; -import org.bukkit.Registry; -import org.bukkit.craftbukkit.CraftRegistry; -import org.bukkit.craftbukkit.util.CraftNamespacedKey; -import org.bukkit.support.environment.AllFeatures; -import org.junit.jupiter.api.Test; - -@AllFeatures -public class StructureTypeTest { - - @Test - public void testBukkitToMinecraftFieldName() { - for (Field field : StructureType.class.getFields()) { - if (field.getType() != StructureType.class) { - continue; - } - if (!Modifier.isStatic(field.getModifiers())) { - continue; - } - - String name = field.getName(); - assertNotNull(Registry.STRUCTURE_TYPE.get(NamespacedKey.fromString(name.toLowerCase(Locale.ROOT))), "No enchantment for field name " + name); - } - } - - @Test - public void testMinecraftToBukkitFieldName() { - for (net.minecraft.world.level.levelgen.structure.StructureType structureType : CraftRegistry.getMinecraftRegistry(Registries.STRUCTURE_TYPE)) { - ResourceLocation minecraftKey = BuiltInRegistries.STRUCTURE_TYPE.getKey(structureType); - - try { - StructureType bukkit = (StructureType) StructureType.class.getField(minecraftKey.getPath().toUpperCase(Locale.ROOT)).get(null); - - assertEquals(minecraftKey, CraftNamespacedKey.toMinecraft(bukkit.getKey()), "Keys are not the same for " + minecraftKey); - } catch (NoSuchFieldException e) { - fail("No Bukkit default enchantment for " + minecraftKey); - } catch (IllegalAccessException e) { - fail("Bukkit field is not access able for " + minecraftKey); - } catch (ClassCastException e) { - fail("Bukkit field is not of type enchantment for" + minecraftKey); - } - } - } -} diff --git a/paper-server/src/test/java/org/bukkit/map/MapTest.java b/paper-server/src/test/java/org/bukkit/map/MapTest.java index 51ee862f3e..a16dfc104b 100644 --- a/paper-server/src/test/java/org/bukkit/map/MapTest.java +++ b/paper-server/src/test/java/org/bukkit/map/MapTest.java @@ -3,11 +3,8 @@ package org.bukkit.map; import static org.junit.jupiter.api.Assertions.*; import java.awt.Color; import java.util.concurrent.ExecutionException; -import java.util.logging.Level; import java.util.logging.Logger; -import net.minecraft.world.level.material.MapColor; import org.bukkit.craftbukkit.map.CraftMapColorCache; -import org.bukkit.support.environment.Normal; import org.bukkit.support.environment.Slow; import org.junit.jupiter.api.Test; @@ -15,55 +12,6 @@ public class MapTest { private static final Logger logger = Logger.getLogger("MapTest"); - private static final int[] modifiers = {180, 220, 255, 135}; - - @Test - @Normal - public void testColors() { - MapColor[] nmsColors = MapColor.MATERIAL_COLORS; - Color[] bukkitColors = MapPalette.colors; - - boolean fail = false; - for (int i = 0; i < nmsColors.length; i++) { - if (nmsColors[i] == null) { - break; - } - int rgb = nmsColors[i].col; - - int r = (rgb >> 16) & 0xFF; - int g = (rgb >> 8) & 0xFF; - int b = rgb & 0xFF; - - if (i + 1 > bukkitColors.length / 4) { - for (int modi : MapTest.modifiers) { - int mr = (r * modi) / 255; - int mg = (g * modi) / 255; - int mb = (b * modi) / 255; - MapTest.logger.log(Level.WARNING, "Missing color (check CraftMapView#render and update md5 hash in CraftMapColorCache): c({0}, {1}, {2})", new Object[]{mr, mg, mb}); - } - fail = true; - } else { - for (int j = 0; j < MapTest.modifiers.length; j++) { - int modi = MapTest.modifiers[j]; - Color bukkit = bukkitColors[i * 4 + j]; - int mr = (r * modi) / 255; - int mg = (g * modi) / 255; - int mb = (b * modi) / 255; - - if (bukkit.getRed() != mr || bukkit.getGreen() != mg || bukkit.getBlue() != mb) { - MapTest.logger.log(Level.WARNING, "Incorrect color: {6} {7} c({0}, {1}, {2}) != c({3}, {4}, {5})", new Object[]{ - bukkit.getRed(), bukkit.getGreen(), bukkit.getBlue(), - mr, mg, mb, - i, j - }); - fail = true; - } - } - } - } - assertFalse(fail); - } - @Test @Slow("Test takes around 25 seconds, should be run by changes to the map color conversion") public void testMapColorCacheBuilding() throws ExecutionException, InterruptedException { diff --git a/paper-server/src/test/java/org/bukkit/potion/PotionTest.java b/paper-server/src/test/java/org/bukkit/potion/PotionTest.java index b07e88813c..0cfe19d91d 100644 --- a/paper-server/src/test/java/org/bukkit/potion/PotionTest.java +++ b/paper-server/src/test/java/org/bukkit/potion/PotionTest.java @@ -16,23 +16,6 @@ import org.junit.jupiter.api.Test; @AllFeatures public class PotionTest { - @Test - public void testEffectCompleteness() throws Throwable { - Map effects = new EnumMap(PotionType.class); - for (Potion reg : BuiltInRegistries.POTION) { - List eff = reg.getEffects(); - if (eff.size() != 1) continue; - PotionEffectType type = CraftPotionEffectType.minecraftHolderToBukkit(eff.get(0).getEffect()); - assertNotNull(type, String.valueOf(reg)); - - PotionType enumType = PotionType.getByEffect(type); - assertNotNull(enumType, type.getName()); - - effects.put(enumType, enumType.name()); - } - - assertEquals(PotionType.values().length - /* PotionTypes with no/shared Effects */ (5 + 22 /* There are 22 new strong / long potion types */), effects.entrySet().size()); - } @Test public void testEffectType() { @@ -42,7 +25,6 @@ public class PotionTest { PotionEffectType bukkit = CraftPotionEffectType.minecraftToBukkit(nms); assertNotNull(bukkit, "No Bukkit type for " + key); - assertFalse(bukkit.getName().contains("UNKNOWN"), "No name for " + key); PotionEffectType byName = FieldRename.getByName_PotionEffectType(bukkit.getName()); assertEquals(bukkit, byName, "Same type not returned by name " + key); diff --git a/paper-server/src/test/java/org/bukkit/support/extension/AllFeaturesExtension.java b/paper-server/src/test/java/org/bukkit/support/extension/AllFeaturesExtension.java index 8fef8421e3..a17f783d0c 100644 --- a/paper-server/src/test/java/org/bukkit/support/extension/AllFeaturesExtension.java +++ b/paper-server/src/test/java/org/bukkit/support/extension/AllFeaturesExtension.java @@ -1,7 +1,5 @@ package org.bukkit.support.extension; -import static org.mockito.ArgumentMatchers.*; -import static org.mockito.Mockito.*; import java.util.HashMap; import java.util.Map; import net.minecraft.world.flag.FeatureFlags; @@ -17,7 +15,6 @@ import org.junit.jupiter.api.extension.ExtensionContext; public class AllFeaturesExtension extends BaseExtension { private static final Map, Registry> realRegistries = new HashMap<>(); - private static final Map, Registry> spyRegistries = new HashMap<>(); public AllFeaturesExtension() { super("AllFeatures"); diff --git a/paper-server/src/test/java/org/bukkit/support/extension/LegacyExtension.java b/paper-server/src/test/java/org/bukkit/support/extension/LegacyExtension.java index c9c3227c3b..ae8a16160b 100644 --- a/paper-server/src/test/java/org/bukkit/support/extension/LegacyExtension.java +++ b/paper-server/src/test/java/org/bukkit/support/extension/LegacyExtension.java @@ -1,13 +1,7 @@ package org.bukkit.support.extension; -import static org.mockito.ArgumentMatchers.*; -import static org.mockito.Mockito.*; -import java.util.HashMap; -import java.util.Map; import net.minecraft.world.flag.FeatureFlags; import org.bukkit.Bukkit; -import org.bukkit.Keyed; -import org.bukkit.Registry; import org.bukkit.Server; import org.bukkit.craftbukkit.CraftRegistry; import org.bukkit.support.DummyServerHelper; @@ -16,8 +10,6 @@ import org.junit.jupiter.api.extension.ExtensionContext; public class LegacyExtension extends BaseExtension { - private static final Map, Registry> registries = new HashMap<>(); - public LegacyExtension() { super("Legacy"); } diff --git a/paper-server/src/test/java/org/bukkit/support/extension/SlowExtension.java b/paper-server/src/test/java/org/bukkit/support/extension/SlowExtension.java index 87364f223f..eb0960fa11 100644 --- a/paper-server/src/test/java/org/bukkit/support/extension/SlowExtension.java +++ b/paper-server/src/test/java/org/bukkit/support/extension/SlowExtension.java @@ -1,13 +1,7 @@ package org.bukkit.support.extension; -import static org.mockito.ArgumentMatchers.*; -import static org.mockito.Mockito.*; -import java.util.HashMap; -import java.util.Map; import net.minecraft.world.flag.FeatureFlags; import org.bukkit.Bukkit; -import org.bukkit.Keyed; -import org.bukkit.Registry; import org.bukkit.Server; import org.bukkit.craftbukkit.CraftRegistry; import org.bukkit.support.DummyServerHelper; @@ -16,8 +10,6 @@ import org.junit.jupiter.api.extension.ExtensionContext; public class SlowExtension extends BaseExtension { - private static final Map, Registry> registries = new HashMap<>(); - public SlowExtension() { super("Slow"); } diff --git a/paper-server/src/test/java/org/bukkit/support/extension/VanillaFeatureExtension.java b/paper-server/src/test/java/org/bukkit/support/extension/VanillaFeatureExtension.java index 626c3033e3..66db95cfca 100644 --- a/paper-server/src/test/java/org/bukkit/support/extension/VanillaFeatureExtension.java +++ b/paper-server/src/test/java/org/bukkit/support/extension/VanillaFeatureExtension.java @@ -1,13 +1,7 @@ package org.bukkit.support.extension; -import static org.mockito.ArgumentMatchers.*; -import static org.mockito.Mockito.*; -import java.util.HashMap; -import java.util.Map; import net.minecraft.world.flag.FeatureFlags; import org.bukkit.Bukkit; -import org.bukkit.Keyed; -import org.bukkit.Registry; import org.bukkit.Server; import org.bukkit.craftbukkit.CraftRegistry; import org.bukkit.support.DummyServerHelper; @@ -16,8 +10,6 @@ import org.junit.jupiter.api.extension.ExtensionContext; public class VanillaFeatureExtension extends BaseExtension { - private static final Map, Registry> registries = new HashMap<>(); - public VanillaFeatureExtension() { super("VanillaFeature"); }