From d8244dbd808d711342466d8ad2ffe13ced833779 Mon Sep 17 00:00:00 2001 From: MD <1917406+mdcfe@users.noreply.github.com> Date: Fri, 19 Jul 2024 20:08:38 +0100 Subject: [PATCH] Do not treat Material as an enum --- .../earth2me/essentials/perm/PermissionsDefaults.java | 9 +++++---- .../java/com/earth2me/essentials/utils/LocationUtil.java | 8 ++++---- .../java/com/earth2me/essentials/utils/MaterialUtil.java | 8 ++++++++ 3 files changed, 17 insertions(+), 8 deletions(-) diff --git a/Essentials/src/main/java/com/earth2me/essentials/perm/PermissionsDefaults.java b/Essentials/src/main/java/com/earth2me/essentials/perm/PermissionsDefaults.java index ee854e59b..34551e722 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/perm/PermissionsDefaults.java +++ b/Essentials/src/main/java/com/earth2me/essentials/perm/PermissionsDefaults.java @@ -1,6 +1,7 @@ package com.earth2me.essentials.perm; import com.earth2me.essentials.commands.Commandhat; +import com.earth2me.essentials.utils.MaterialUtil; import com.google.common.collect.ImmutableMap; import org.bukkit.Bukkit; import org.bukkit.Material; @@ -10,16 +11,16 @@ import org.bukkit.permissions.PermissionDefault; import org.bukkit.plugin.PluginManager; public final class PermissionsDefaults { - + private PermissionsDefaults() { } - + public static void registerAllBackDefaults() { for (final World world : Bukkit.getWorlds()) { registerBackDefaultFor(world); } } - + public static void registerBackDefaultFor(final World w) { final String permName = "essentials.back.into." + w.getName(); @@ -41,7 +42,7 @@ public final class PermissionsDefaults { } final ImmutableMap.Builder children = ImmutableMap.builder(); - for (final Material mat : Material.values()) { + for (final Material mat : MaterialUtil.getKnownMaterials()) { final String matPerm = Commandhat.PERM_PREFIX + mat.name().toLowerCase(); children.put(matPerm, true); pluginManager.addPermission(new Permission(matPerm, "Prevent using " + mat + " as a type of hat.", PermissionDefault.FALSE)); diff --git a/Essentials/src/main/java/com/earth2me/essentials/utils/LocationUtil.java b/Essentials/src/main/java/com/earth2me/essentials/utils/LocationUtil.java index ab3a8980f..bfb882165 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/utils/LocationUtil.java +++ b/Essentials/src/main/java/com/earth2me/essentials/utils/LocationUtil.java @@ -14,7 +14,7 @@ import org.bukkit.inventory.ItemStack; import java.util.ArrayList; import java.util.Comparator; -import java.util.EnumSet; +import java.util.HashSet; import java.util.List; import java.util.Set; @@ -37,15 +37,15 @@ public final class LocationUtil { private static final Material FARMLAND = EnumUtil.getMaterial("FARMLAND"); // The player can stand inside these materials - private static final Set HOLLOW_MATERIALS = EnumSet.noneOf(Material.class); - private static final Set TRANSPARENT_MATERIALS = EnumSet.noneOf(Material.class); + private static final Set HOLLOW_MATERIALS = new HashSet<>(); + private static final Set TRANSPARENT_MATERIALS = new HashSet<>(); static { // If the server is running in a test environment, the isTransparent() method will blow up since // it requires the registry to be initialized. This is a workaround to prevent that from happening. if (!Essentials.TESTING) { // Materials from Material.isTransparent() - for (final Material mat : Material.values()) { + for (final Material mat : MaterialUtil.getKnownMaterials()) { if (mat.isTransparent()) { HOLLOW_MATERIALS.add(mat); } diff --git a/Essentials/src/main/java/com/earth2me/essentials/utils/MaterialUtil.java b/Essentials/src/main/java/com/earth2me/essentials/utils/MaterialUtil.java index 2c9023d5d..7292dc082 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/utils/MaterialUtil.java +++ b/Essentials/src/main/java/com/earth2me/essentials/utils/MaterialUtil.java @@ -3,6 +3,7 @@ package com.earth2me.essentials.utils; import org.bukkit.Bukkit; import org.bukkit.DyeColor; import org.bukkit.Material; +import org.bukkit.Registry; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.Damageable; import org.bukkit.material.MaterialData; @@ -246,4 +247,11 @@ public final class MaterialUtil { return DyeColor.WHITE; } + + public static Material[] getKnownMaterials() { + if (VersionUtil.getServerBukkitVersion().isLowerThan(VersionUtil.v1_14_R01)) { + return Material.values(); + } + return Registry.MATERIAL.stream().toArray(Material[]::new); + } }