Do not treat Material as an enum

This commit is contained in:
MD 2024-07-19 20:08:38 +01:00
parent 33e086ff05
commit d8244dbd80
3 changed files with 17 additions and 8 deletions

View File

@ -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;
@ -41,7 +42,7 @@ public final class PermissionsDefaults {
}
final ImmutableMap.Builder<String, Boolean> 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));

View File

@ -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<Material> HOLLOW_MATERIALS = EnumSet.noneOf(Material.class);
private static final Set<Material> TRANSPARENT_MATERIALS = EnumSet.noneOf(Material.class);
private static final Set<Material> HOLLOW_MATERIALS = new HashSet<>();
private static final Set<Material> 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);
}

View File

@ -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);
}
}