diff --git a/pom.xml b/pom.xml index b532606..f7c6aed 100644 --- a/pom.xml +++ b/pom.xml @@ -45,7 +45,11 @@ de.tr7zw.changeme.nbtapi - nl.sbdeveloper.themeparkplus.nbtapi + nl.sbdeveloper.themeparkplus.libs.nbtapi + + + org.codemc.worldguardwrapper + nl.sbdeveloper.themeparkplus.libs.worldguardwrapper @@ -93,17 +97,13 @@ spigot-repo https://hub.spigotmc.org/nexus/content/repositories/snapshots/ - - codemc-repo - https://repo.codemc.org/repository/maven-public/ - jitpack.io https://jitpack.io - CodeMC - https://repo.codemc.org/repository/maven-public + codemc-repo + https://repo.codemc.org/repository/maven-public/ sk89q-repo @@ -120,27 +120,15 @@ org.spigotmc spigot-api - 1.15.2-R0.1-SNAPSHOT + 1.16.1-R0.1-SNAPSHOT provided me.paradoxpixel themepark - 1.4.4 + 2.1.1 system - ${pom.basedir}/src/lib/themepark-1.4.4.jar - - - com.sk89q.worldedit - worldedit-bukkit - 6.1.4-SNAPSHOT - provided - - - com.sk89q.worldguard - worldguard-legacy - 6.2 - provided + ${pom.basedir}/src/lib/themepark-2.1.1.jar org.projectlombok @@ -180,5 +168,10 @@ 1.7 compile + + org.codemc.worldguardwrapper + worldguardwrapper + 1.1.9-SNAPSHOT + diff --git a/src/lib/themepark-1.4.4.jar b/src/lib/themepark-1.4.4.jar deleted file mode 100644 index dcc345c..0000000 Binary files a/src/lib/themepark-1.4.4.jar and /dev/null differ diff --git a/src/lib/themepark-2.1.1.jar b/src/lib/themepark-2.1.1.jar new file mode 100644 index 0000000..6e230ad Binary files /dev/null and b/src/lib/themepark-2.1.1.jar differ diff --git a/src/main/lombok/nl/sbdeveloper/themeparkplus/api/PlusAPI.java b/src/main/lombok/nl/sbdeveloper/themeparkplus/api/PlusAPI.java index f43bb3e..22f44ed 100644 --- a/src/main/lombok/nl/sbdeveloper/themeparkplus/api/PlusAPI.java +++ b/src/main/lombok/nl/sbdeveloper/themeparkplus/api/PlusAPI.java @@ -1,25 +1,21 @@ package nl.sbdeveloper.themeparkplus.api; -import com.sk89q.worldguard.protection.ApplicableRegionSet; -import com.sk89q.worldguard.protection.regions.ProtectedRegion; import de.tr7zw.changeme.nbtapi.NBTItem; -import me.paradoxpixel.themepark.api.attraction.Attraction; +import nl.iobyte.themepark.api.attraction.Attraction; import nl.sbdeveloper.themeparkplus.ThemeParkPlus; import nl.sbdeveloper.themeparkplus.api.objects.Gate; import nl.sbdeveloper.themeparkplus.api.objects.WaitingRow; import nl.sbdeveloper.themeparkplus.util.ConfigUtil; import nl.sbdeveloper.themeparkplus.util.XMaterial; -import nl.sbdeveloper.themeparkplus.util.WorldGuardLegacyManager; import org.bukkit.Location; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.ItemMeta; +import org.codemc.worldguardwrapper.WorldGuardWrapper; +import org.codemc.worldguardwrapper.region.IWrappedRegion; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import java.util.Collections; -import java.util.HashMap; -import java.util.List; -import java.util.Optional; +import java.util.*; public class PlusAPI { private static HashMap gates = new HashMap<>(); @@ -119,9 +115,9 @@ public class PlusAPI { @Nullable public static WaitingRow getRow(Location loc) { if (loc == null) return null; - ApplicableRegionSet set = WorldGuardLegacyManager.getInstance().getApplicableRegionSet(loc); + Set set = WorldGuardWrapper.getInstance().getRegions(loc); for (WaitingRow row : rows.values()) { - if (set.getRegions().stream().anyMatch(region -> region.getId().equalsIgnoreCase(row.getRegionID()))) { + if (set.stream().anyMatch(region -> region.getId().equalsIgnoreCase(row.getRegionID()))) { return row; } } diff --git a/src/main/lombok/nl/sbdeveloper/themeparkplus/api/objects/MalfunctionReport.java b/src/main/lombok/nl/sbdeveloper/themeparkplus/api/objects/MalfunctionReport.java index ac67429..9c17f7b 100644 --- a/src/main/lombok/nl/sbdeveloper/themeparkplus/api/objects/MalfunctionReport.java +++ b/src/main/lombok/nl/sbdeveloper/themeparkplus/api/objects/MalfunctionReport.java @@ -8,7 +8,7 @@ import lombok.Setter; import java.time.LocalDateTime; import java.util.UUID; -/** @deprecated Please don't use! It's not implemented yet. */ +/** Please don't use! It's not implemented yet. */ @Getter @Setter @NoArgsConstructor @AllArgsConstructor public class MalfunctionReport { private String rideID; diff --git a/src/main/lombok/nl/sbdeveloper/themeparkplus/api/objects/SignLocation.java b/src/main/lombok/nl/sbdeveloper/themeparkplus/api/objects/SignLocation.java deleted file mode 100644 index d54f1bd..0000000 --- a/src/main/lombok/nl/sbdeveloper/themeparkplus/api/objects/SignLocation.java +++ /dev/null @@ -1,29 +0,0 @@ -package nl.sbdeveloper.themeparkplus.api.objects; - -import lombok.AllArgsConstructor; -import lombok.Getter; -import lombok.NoArgsConstructor; -import lombok.Setter; -import org.bukkit.Bukkit; -import org.bukkit.Location; -import org.bukkit.block.Block; -import org.jetbrains.annotations.NotNull; - -import java.util.Objects; - -@Getter @Setter @NoArgsConstructor @AllArgsConstructor -public class SignLocation { - private String worldName; - private int x; - private int y; - private int z; - - @NotNull - public static SignLocation getFromLocation(@NotNull Location in) { - return new SignLocation(Objects.requireNonNull(in.getWorld()).getName(), in.getBlockX(), in.getBlockY(), in.getBlockZ()); - } - - public Block getBlock() { - return Bukkit.getWorld(worldName).getBlockAt(x, y, z); - } -} diff --git a/src/main/lombok/nl/sbdeveloper/themeparkplus/api/objects/WaitingRow.java b/src/main/lombok/nl/sbdeveloper/themeparkplus/api/objects/WaitingRow.java index 63cb94c..2234adb 100644 --- a/src/main/lombok/nl/sbdeveloper/themeparkplus/api/objects/WaitingRow.java +++ b/src/main/lombok/nl/sbdeveloper/themeparkplus/api/objects/WaitingRow.java @@ -4,6 +4,7 @@ import lombok.AllArgsConstructor; import lombok.Getter; import lombok.NoArgsConstructor; import lombok.Setter; +import org.bukkit.Location; import java.util.ArrayList; @@ -13,22 +14,22 @@ public class WaitingRow { @Getter @Setter private String regionID; @Getter @Setter private transient int waitingPlayers = 0; @Getter private transient double waitingTimeMinutes = 0; - private ArrayList signLocations = new ArrayList<>(); + private ArrayList signLocations = new ArrayList<>(); public WaitingRow(String rideID, String regionID) { this.rideID = rideID; this.regionID = regionID; } - public ArrayList getSignLocations() { + public ArrayList getSignLocations() { return signLocations; } - public void addSignLocation(SignLocation loc) { + public void addSignLocation(Location loc) { this.signLocations.add(loc); } - public void removeSignLocation(SignLocation loc) { + public void removeSignLocation(Location loc) { this.signLocations.remove(loc); } diff --git a/src/main/lombok/nl/sbdeveloper/themeparkplus/commands/TPPCMD.java b/src/main/lombok/nl/sbdeveloper/themeparkplus/commands/TPPCMD.java index 8ddb12f..775cb4c 100644 --- a/src/main/lombok/nl/sbdeveloper/themeparkplus/commands/TPPCMD.java +++ b/src/main/lombok/nl/sbdeveloper/themeparkplus/commands/TPPCMD.java @@ -1,7 +1,7 @@ package nl.sbdeveloper.themeparkplus.commands; -import me.paradoxpixel.themepark.api.API; -import me.paradoxpixel.themepark.api.attraction.Attraction; +import nl.iobyte.themepark.api.API; +import nl.iobyte.themepark.api.attraction.Attraction; import nl.sbdeveloper.themeparkplus.ThemeParkPlus; import nl.sbdeveloper.themeparkplus.api.PlusAPI; import nl.sbdeveloper.themeparkplus.api.enums.WalkingDirection; diff --git a/src/main/lombok/nl/sbdeveloper/themeparkplus/listeners/FastpassListeners.java b/src/main/lombok/nl/sbdeveloper/themeparkplus/listeners/FastpassListeners.java index c9b523d..6dfcd30 100644 --- a/src/main/lombok/nl/sbdeveloper/themeparkplus/listeners/FastpassListeners.java +++ b/src/main/lombok/nl/sbdeveloper/themeparkplus/listeners/FastpassListeners.java @@ -1,9 +1,9 @@ package nl.sbdeveloper.themeparkplus.listeners; import de.tr7zw.changeme.nbtapi.NBTItem; -import me.paradoxpixel.themepark.api.API; -import me.paradoxpixel.themepark.api.attraction.Attraction; -import me.paradoxpixel.themepark.api.attraction.component.Status; +import nl.iobyte.themepark.api.API; +import nl.iobyte.themepark.api.attraction.Attraction; +import nl.iobyte.themepark.api.attraction.component.Status; import nl.sbdeveloper.themeparkplus.ThemeParkPlus; import nl.sbdeveloper.themeparkplus.api.PlusAPI; import nl.sbdeveloper.themeparkplus.util.ConfigUtil; diff --git a/src/main/lombok/nl/sbdeveloper/themeparkplus/listeners/SignListeners.java b/src/main/lombok/nl/sbdeveloper/themeparkplus/listeners/SignListeners.java index de571fe..d2a62e9 100644 --- a/src/main/lombok/nl/sbdeveloper/themeparkplus/listeners/SignListeners.java +++ b/src/main/lombok/nl/sbdeveloper/themeparkplus/listeners/SignListeners.java @@ -1,9 +1,8 @@ package nl.sbdeveloper.themeparkplus.listeners; -import me.paradoxpixel.themepark.api.API; +import nl.iobyte.themepark.api.API; import nl.sbdeveloper.themeparkplus.ThemeParkPlus; import nl.sbdeveloper.themeparkplus.api.PlusAPI; -import nl.sbdeveloper.themeparkplus.api.objects.SignLocation; import nl.sbdeveloper.themeparkplus.api.objects.WaitingRow; import nl.sbdeveloper.themeparkplus.util.ConfigUtil; import org.bukkit.block.BlockState; @@ -66,7 +65,7 @@ public class SignListeners implements Listener { foundRow = new WaitingRow(lines[2], lines[3]); PlusAPI.addRow(foundRow); } - foundRow.addSignLocation(SignLocation.getFromLocation(e.getBlock().getLocation())); + foundRow.addSignLocation(e.getBlock().getLocation()); ThemeParkPlus.getData().save(); e.setLine(0, wrLineOne); @@ -91,7 +90,7 @@ public class SignListeners implements Listener { if (row.getSignLocations().size() == 1) { PlusAPI.removeRow(row); } else { - row.removeSignLocation(SignLocation.getFromLocation(e.getBlock().getLocation())); + row.removeSignLocation(e.getBlock().getLocation()); } ThemeParkPlus.getData().save(); } diff --git a/src/main/lombok/nl/sbdeveloper/themeparkplus/listeners/StatusChangeListener.java b/src/main/lombok/nl/sbdeveloper/themeparkplus/listeners/StatusChangeListener.java index 845d851..ca4bfb4 100644 --- a/src/main/lombok/nl/sbdeveloper/themeparkplus/listeners/StatusChangeListener.java +++ b/src/main/lombok/nl/sbdeveloper/themeparkplus/listeners/StatusChangeListener.java @@ -2,9 +2,9 @@ package nl.sbdeveloper.themeparkplus.listeners; import club.minnced.discord.webhook.send.WebhookEmbed; import club.minnced.discord.webhook.send.WebhookEmbedBuilder; -import me.paradoxpixel.themepark.api.attraction.component.Status; -import me.paradoxpixel.themepark.api.event.attraction.StatusChangeEvent; -import me.paradoxpixel.themepark.attraction.status.StatusManager; +import nl.iobyte.themepark.api.attraction.component.Status; +import nl.iobyte.themepark.api.attraction.manager.StatusManager; +import nl.iobyte.themepark.api.events.attraction.ChangeStatusEvent; import nl.sbdeveloper.themeparkplus.ThemeParkPlus; import nl.sbdeveloper.themeparkplus.util.ConfigUtil; import org.bukkit.ChatColor; @@ -17,18 +17,18 @@ import org.jetbrains.annotations.NotNull; */ public class StatusChangeListener implements Listener { @EventHandler - public void onStatusChange(@NotNull StatusChangeEvent e) { - if (e.getStatusAfter() != Status.GLOBAL) { + public void onStatusChange(@NotNull ChangeStatusEvent e) { + if (e.getAfter() != Status.GLOBAL) { String title = ThemeParkPlus.getSConfig().getFile().getString("DiscordWebhook.Embed.Title"); if (title == null) return; String rideName = ChatColor.stripColor(ConfigUtil.makecolored(e.getAttraction().getName())); - String statusAfter = ChatColor.stripColor(ConfigUtil.makecolored(StatusManager.getName(e.getStatusAfter()))); + String statusAfter = ChatColor.stripColor(ConfigUtil.makecolored(StatusManager.getName(e.getAfter()))); title = title.replaceAll("%RideName%", rideName); String copy = ThemeParkPlus.getSConfig().getFile().getString("DiscordWebhook.Embed.Copyright"); String copyimg = ThemeParkPlus.getSConfig().getFile().getString("DiscordWebhook.Embed.CopyrightImage"); - Integer color = ThemeParkPlus.getSConfig().getFile().getInt("DiscordWebhook.Embed.Colors." + e.getStatusAfter().toString()); + Integer color = ThemeParkPlus.getSConfig().getFile().getInt("DiscordWebhook.Embed.Colors." + e.getAfter().toString()); if (copy == null || copyimg == null) return; WebhookEmbed embed = new WebhookEmbedBuilder() diff --git a/src/main/lombok/nl/sbdeveloper/themeparkplus/listeners/WaitingTimeListener.java b/src/main/lombok/nl/sbdeveloper/themeparkplus/listeners/WaitingTimeListener.java index 8fd6528..4047f90 100644 --- a/src/main/lombok/nl/sbdeveloper/themeparkplus/listeners/WaitingTimeListener.java +++ b/src/main/lombok/nl/sbdeveloper/themeparkplus/listeners/WaitingTimeListener.java @@ -2,7 +2,6 @@ package nl.sbdeveloper.themeparkplus.listeners; import nl.sbdeveloper.themeparkplus.ThemeParkPlus; import nl.sbdeveloper.themeparkplus.api.PlusAPI; -import nl.sbdeveloper.themeparkplus.api.objects.SignLocation; import nl.sbdeveloper.themeparkplus.api.objects.WaitingRow; import nl.sbdeveloper.themeparkplus.util.ConfigUtil; import org.bukkit.Bukkit; @@ -77,7 +76,7 @@ public class WaitingTimeListener implements Listener { usedRow.setWaitingPlayers(waitingNew); usedRow.setWaitingTimeMinutes(waitingTimeNew); - for (SignLocation signLocation : usedRow.getSignLocations()) { + for (Location signLocation : usedRow.getSignLocations()) { BlockState signblocks = signLocation.getBlock().getState(); if (signblocks instanceof Sign) { Sign signs = (Sign) signblocks; diff --git a/src/main/lombok/nl/sbdeveloper/themeparkplus/managers/DBManager.java b/src/main/lombok/nl/sbdeveloper/themeparkplus/managers/DBManager.java index 1079909..64aa1a7 100644 --- a/src/main/lombok/nl/sbdeveloper/themeparkplus/managers/DBManager.java +++ b/src/main/lombok/nl/sbdeveloper/themeparkplus/managers/DBManager.java @@ -1,12 +1,15 @@ package nl.sbdeveloper.themeparkplus.managers; import com.google.gson.Gson; +import com.google.gson.GsonBuilder; import nl.sbdeveloper.themeparkplus.api.PlusAPI; import nl.sbdeveloper.themeparkplus.api.objects.Gate; import nl.sbdeveloper.themeparkplus.api.objects.WaitingRow; import nl.sbdeveloper.themeparkplus.sbutils.LocationSerializer; import nl.sbdeveloper.themeparkplus.sbutils.SQLiteDB; +import nl.sbdeveloper.themeparkplus.util.LocationGsonAdapter; import org.bukkit.Location; +import org.jetbrains.annotations.NotNull; import java.sql.Connection; import java.sql.PreparedStatement; @@ -37,6 +40,11 @@ public class DBManager { } } + @NotNull + private Gson getGson() { + return new GsonBuilder().registerTypeAdapter(Location.class, new LocationGsonAdapter()).create(); + } + public void load() throws SQLException { /* Load gates */ String query = "SELECT * FROM gates"; @@ -47,7 +55,7 @@ public class DBManager { byte[] blob = gateSet.getBytes("gateData"); String json = new String(blob); - Gson gson = new Gson(); + Gson gson = getGson(); Gate gate = gson.fromJson(json, Gate.class); PlusAPI.addGate(gate); } @@ -61,7 +69,7 @@ public class DBManager { byte[] blob = rowSet.getBytes("rowData"); String json = new String(blob); - Gson gson = new Gson(); + Gson gson = getGson(); WaitingRow row = gson.fromJson(json, WaitingRow.class); PlusAPI.addRow(row); } @@ -69,7 +77,7 @@ public class DBManager { public void save() { for (Map.Entry entry : PlusAPI.getGates().entrySet()) { - Gson gson = new Gson(); + Gson gson = getGson(); byte[] blob = gson.toJson(entry.getValue()).getBytes(); try { @@ -93,7 +101,7 @@ public class DBManager { for (Map.Entry entry : PlusAPI.getRows().entrySet()) { - Gson gson = new Gson(); + Gson gson = getGson(); byte[] blob = gson.toJson(entry.getValue()).getBytes(); try { diff --git a/src/main/lombok/nl/sbdeveloper/themeparkplus/sbutils/LocationSerializer.java b/src/main/lombok/nl/sbdeveloper/themeparkplus/sbutils/LocationSerializer.java index 350767b..4faed2e 100644 --- a/src/main/lombok/nl/sbdeveloper/themeparkplus/sbutils/LocationSerializer.java +++ b/src/main/lombok/nl/sbdeveloper/themeparkplus/sbutils/LocationSerializer.java @@ -2,9 +2,8 @@ package nl.sbdeveloper.themeparkplus.sbutils; import org.bukkit.Bukkit; import org.bukkit.Location; - -import javax.annotation.Nonnull; -import javax.annotation.Nullable; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; public class LocationSerializer { @@ -16,7 +15,7 @@ public class LocationSerializer { * @return The location or null if error */ @Nullable - public static Location deserialize(@Nonnull String string) { + public static Location deserialize(@NotNull String string) { String[] split = string.split("_"); if (split.length < 4) return null; @@ -37,8 +36,8 @@ public class LocationSerializer { * * @return The location or null if error */ - @Nonnull - public static Location deserializePY(@Nonnull String string) { + @NotNull + public static Location deserializePY(@NotNull String string) { String[] split = string.split("_"); //world_x_y_z @@ -60,7 +59,7 @@ public class LocationSerializer { * @return The serialized string */ @Nullable - public static String serialize(@Nonnull Location loc) { + public static String serialize(@NotNull Location loc) { if (loc.getWorld() == null) return null; return loc.getWorld().getName() + "_" + loc.getX() + "_" + loc.getY() + "_" + loc.getZ(); } @@ -73,7 +72,7 @@ public class LocationSerializer { * @return The serialized string */ @Nullable - public static String serializePY(@Nonnull Location loc) { + public static String serializePY(@NotNull Location loc) { if (loc.getWorld() == null) return null; return loc.getWorld().getName() + "_" + loc.getX() + "_" + loc.getY() + "_" + loc.getZ() + "_" + loc.getYaw() + "_" + loc.getPitch(); } diff --git a/src/main/lombok/nl/sbdeveloper/themeparkplus/util/LocationGsonAdapter.java b/src/main/lombok/nl/sbdeveloper/themeparkplus/util/LocationGsonAdapter.java new file mode 100644 index 0000000..0d4dd4d --- /dev/null +++ b/src/main/lombok/nl/sbdeveloper/themeparkplus/util/LocationGsonAdapter.java @@ -0,0 +1,65 @@ +package nl.sbdeveloper.themeparkplus.util; + +import com.google.gson.Gson; +import com.google.gson.TypeAdapter; +import com.google.gson.reflect.TypeToken; +import com.google.gson.stream.JsonReader; +import com.google.gson.stream.JsonToken; +import com.google.gson.stream.JsonWriter; +import org.bukkit.Bukkit; +import org.bukkit.Location; +import org.bukkit.World; + +import java.io.IOException; +import java.lang.reflect.Type; +import java.util.HashMap; +import java.util.Map; + +public class LocationGsonAdapter extends TypeAdapter { + private static Gson g = new Gson(); + + private static Type seriType = new TypeToken>(){}.getType(); + + private static String UUID = "uuid"; + private static String X = "x"; + private static String Y = "y"; + private static String Z = "z"; + private static String YAW = "yaw"; + private static String PITCH = "pitch"; + + @Override + public void write(JsonWriter jsonWriter, Location location) throws IOException { + if(location == null) { + jsonWriter.nullValue(); + return; + } + jsonWriter.value(getRaw(location)); + } + + @Override + public Location read(JsonReader jsonReader) throws IOException { + if(jsonReader.peek() == JsonToken.NULL) { + jsonReader.nextNull(); + return null; + } + return fromRaw(jsonReader.nextString()); + } + + private String getRaw (Location location) { + Map serial = new HashMap<>(); + serial.put(UUID, location.getWorld().getUID().toString()); + serial.put(X, Double.toString(location.getX())); + serial.put(Y, Double.toString(location.getY())); + serial.put(Z, Double.toString(location.getZ())); + serial.put(YAW, Float.toString(location.getYaw())); + serial.put(PITCH, Float.toString(location.getPitch())); + return g.toJson(serial); + } + + private Location fromRaw (String raw) { + Map keys = g.fromJson(raw, seriType); + World w = Bukkit.getWorld(java.util.UUID.fromString((String) keys.get(UUID))); + return new Location(w, Double.parseDouble((String) keys.get(X)), Double.parseDouble((String) keys.get(Y)), Double.parseDouble((String) keys.get(Z)), + Float.parseFloat((String) keys.get(YAW)), Float.parseFloat((String) keys.get(PITCH))); + } +} diff --git a/src/main/lombok/nl/sbdeveloper/themeparkplus/util/Reflection.java b/src/main/lombok/nl/sbdeveloper/themeparkplus/util/Reflection.java deleted file mode 100644 index fa9112d..0000000 --- a/src/main/lombok/nl/sbdeveloper/themeparkplus/util/Reflection.java +++ /dev/null @@ -1,38 +0,0 @@ -package nl.sbdeveloper.themeparkplus.util; - -import org.bukkit.Bukkit; -import org.jetbrains.annotations.Nullable; - -public class Reflection { - private static String version = Bukkit.getServer().getClass().getPackage().getName().split("\\.")[3]; - - @Nullable - public static Class getCraftBukkitClass(String name) { - try { - return Class.forName("org.bukkit.craftbukkit." + version + "." + name); - } catch (ClassNotFoundException var2) { - var2.printStackTrace(); - return null; - } - } - - @Nullable - public static Class getNMSClass(String name) { - try { - return Class.forName("net.minecraft.server." + version + "." + name); - } catch (ClassNotFoundException var2) { - var2.printStackTrace(); - return null; - } - } - - @Nullable - public static Class getClass(String name) { - try { - return Class.forName(name); - } catch (ClassNotFoundException var2) { - var2.printStackTrace(); - return null; - } - } -} \ No newline at end of file diff --git a/src/main/lombok/nl/sbdeveloper/themeparkplus/util/WorldGuardLegacyManager.java b/src/main/lombok/nl/sbdeveloper/themeparkplus/util/WorldGuardLegacyManager.java deleted file mode 100644 index e023806..0000000 --- a/src/main/lombok/nl/sbdeveloper/themeparkplus/util/WorldGuardLegacyManager.java +++ /dev/null @@ -1,195 +0,0 @@ -package nl.sbdeveloper.themeparkplus.util; - -import java.lang.reflect.Method; -import java.util.*; - -import org.bukkit.Bukkit; -import org.bukkit.Location; -import org.bukkit.World; -import org.bukkit.plugin.Plugin; - -import com.sk89q.worldedit.Vector; -import com.sk89q.worldedit.bukkit.BukkitWorld; -import com.sk89q.worldedit.bukkit.WorldEditPlugin; -import com.sk89q.worldguard.bukkit.WorldGuardPlugin; -import com.sk89q.worldguard.protection.ApplicableRegionSet; -import com.sk89q.worldguard.protection.flags.registry.FlagRegistry; -import com.sk89q.worldguard.protection.managers.RegionManager; -import com.sk89q.worldguard.protection.regions.ProtectedCuboidRegion; -import com.sk89q.worldguard.protection.regions.ProtectedRegion; -import org.jetbrains.annotations.NotNull; - -public class WorldGuardLegacyManager { - - private static String wgVerStr = null; - private static WorldGuardLegacyManager instance = null; - - public static WorldGuardLegacyManager getInstance() { - if (instance == null) { - instance = new WorldGuardLegacyManager(); - } - return instance; - } - - public WorldGuardPlugin getWorldGuard() { - Plugin plugin = Bukkit.getServer().getPluginManager().getPlugin("WorldGuard"); - if (!(plugin instanceof WorldGuardPlugin)) { - return null; - } - return (WorldGuardPlugin) plugin; - } - - public WorldEditPlugin getWorldEdit() { - Plugin plugin = Bukkit.getServer().getPluginManager().getPlugin("WorldEdit"); - if (!(plugin instanceof WorldEditPlugin)) { - return null; - } - return (WorldEditPlugin) plugin; - } - - public ProtectedRegion getLowerCasePlot(World w, String regionname) { - for (ProtectedRegion pr : getRegionManager(w).getRegions().values()) { - if (pr.getId().toLowerCase().equalsIgnoreCase(regionname)) { - return pr; - } - } - return null; - } - - public RegionManager getRegionManager(World w) { - if (getWgVer().contains("7.")) { - try { - Class wgClass = Reflection.getClass("com.sk89q.worldguard.WorldGuard"); - - Object instance = wgClass.getDeclaredMethod("getInstance").invoke(null); - Class wgInstanceClass = instance.getClass(); - - Object platform = wgInstanceClass.getDeclaredMethod("getPlatform").invoke(instance); - Class wgPlatformClass = platform.getClass(); - - Object regionContainer = wgPlatformClass.getDeclaredMethod("getRegionContainer").invoke(platform); - Class wgRegionContainer = regionContainer.getClass(); - - return (RegionManager) wgRegionContainer.getSuperclass() - .getMethod("get", com.sk89q.worldedit.world.World.class) - .invoke(regionContainer, new BukkitWorld(w)); - } catch (Exception ex) { - ex.printStackTrace(); - } - } else { - return getWorldGuard().getRegionManager(w); - } - return null; - } - - @SuppressWarnings("unchecked") - public List getRegions(Location loc) { - ArrayList regions = new ArrayList<>(); - if (getWgVer().contains("7.")) { - try { - RegionManager mngr = getRegionManager(loc.getWorld()); - - Class blockVector3 = Reflection.getClass("com.sk89q.worldedit.math.BlockVector3"); - - Method applicableRegions = mngr.getClass().getDeclaredMethod("getApplicableRegions", blockVector3); - - Method blockVectorAt = blockVector3.getDeclaredMethod("at", double.class, double.class, double.class); - Object blockVector = blockVectorAt.invoke(null, loc.getX(), loc.getY(), loc.getZ()); - - Object regionSet = applicableRegions.invoke(mngr, blockVector); - - Method getregions = regionSet.getClass().getMethod("getRegions"); - - regions = new ArrayList<>(((HashSet) getregions.invoke(regionSet))); - - } catch (Exception ex) { - ex.printStackTrace(); - } - } else { - regions = new ArrayList<>(getRegionManager(loc.getWorld()) - .getApplicableRegions(new Vector(loc.getX(), loc.getY(), loc.getZ())).getRegions()); - } - - regions.sort(Comparator.comparing(ProtectedRegion::getPriority)); - return regions; - } - - public ProtectedCuboidRegion getProtectedCubiodRegion(String regionname, Location loc1, Location loc2) { - if (getWgVer().contains("7.")) { - try { - - Object bvloc1 = getBlockVectorV3(loc1); - Object bvloc2 = getBlockVectorV3(loc2); - - Class prCbRg = Reflection.getClass("com.sk89q.worldguard.protection.regions.ProtectedCuboidRegion"); - - return (ProtectedCuboidRegion) prCbRg.getConstructor(String.class, bvloc1.getClass(), bvloc2.getClass()) - .newInstance(regionname, bvloc1, bvloc2); - } catch (Exception ex) { - ex.printStackTrace(); - } - } else { - return new ProtectedCuboidRegion(regionname, - new com.sk89q.worldedit.BlockVector(loc1.getX(), loc1.getY(), loc1.getZ()), - new com.sk89q.worldedit.BlockVector(loc2.getX(), loc2.getY(), loc2.getZ())); - } - return null; - } - - public Object getBlockVectorV3(@NotNull Location loc) throws Exception { - Class blockVector3 = Reflection.getClass("com.sk89q.worldedit.math.BlockVector3"); - - Method blockVectorAt = blockVector3.getDeclaredMethod("at", double.class, double.class, double.class); - return blockVectorAt.invoke(null, loc.getX(), loc.getY(), loc.getZ()); - } - - public FlagRegistry getFlagRegistry() { - if (getWgVer().contains("7.")) { - try { - Class wgClass = Reflection.getClass("com.sk89q.worldguard.WorldGuard"); - - Object instance = wgClass.getDeclaredMethod("getInstance").invoke(null); - Class wgInstanceClass = instance.getClass(); - Method declaredMethod = wgInstanceClass.getDeclaredMethod("getFlagRegistry"); - return (FlagRegistry) declaredMethod.invoke(instance); - } catch (Exception ex) { - ex.printStackTrace(); - return null; - } - } else { - return getWorldGuard().getFlagRegistry(); - } - } - - public ApplicableRegionSet getApplicableRegionSet(Location loc) { - if (getWgVer().contains("7.")) { - try { - RegionManager mngr = getRegionManager(loc.getWorld()); - - Class blockVector3 = Reflection.getClass("com.sk89q.worldedit.math.BlockVector3"); - - Method applicableRegions = mngr.getClass().getDeclaredMethod("getApplicableRegions", blockVector3); - - Method blockVectorAt = blockVector3.getDeclaredMethod("at", double.class, double.class, double.class); - Object blockVector = blockVectorAt.invoke(null, loc.getX(), loc.getY(), loc.getZ()); - - Object regionSet = applicableRegions.invoke(mngr, blockVector); - - return (ApplicableRegionSet) regionSet; - } catch (Exception ex) { - ex.printStackTrace(); - return null; - } - } else { - return getRegionManager(loc.getWorld()).getApplicableRegions(new Vector(loc.getX(), loc.getY(), loc.getZ())); - } - } - - - public String getWgVer() { - if (wgVerStr == null) { - wgVerStr = Bukkit.getPluginManager().getPlugin("WorldGuard").getDescription().getVersion(); - } - return wgVerStr; - } -} \ No newline at end of file diff --git a/src/main/lombok/nl/sbdeveloper/themeparkplus/util/XMaterial.java b/src/main/lombok/nl/sbdeveloper/themeparkplus/util/XMaterial.java index 6911ff1..dc858b5 100644 --- a/src/main/lombok/nl/sbdeveloper/themeparkplus/util/XMaterial.java +++ b/src/main/lombok/nl/sbdeveloper/themeparkplus/util/XMaterial.java @@ -25,30 +25,28 @@ package nl.sbdeveloper.themeparkplus.util; import com.google.common.base.Enums; import com.google.common.cache.Cache; import com.google.common.cache.CacheBuilder; -import com.google.common.collect.ImmutableMap; -import com.google.common.collect.ImmutableSet; -import com.google.common.collect.Maps; +import com.google.common.cache.CacheLoader; +import com.google.common.cache.LoadingCache; import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.Validate; import org.apache.commons.lang.WordUtils; import org.bukkit.Bukkit; import org.bukkit.Material; import org.bukkit.inventory.ItemStack; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; -import javax.annotation.Nonnull; -import javax.annotation.Nullable; import java.util.*; import java.util.concurrent.TimeUnit; import java.util.regex.Pattern; +import java.util.regex.PatternSyntaxException; /** * XMaterial - Data Values/Pre-flattening
- * Supports 1.8-1.15
* 1.13 and above as priority. *

- * This class is mainly designed to support ItemStacks. - * If you want to use it on blocks you'll have to - * use XBlock + * This class is mainly designed to support ItemStacks. If you want to use it on blocks, you'll have to use + * XBlock *

* Pre-flattening: https://minecraft.gamepedia.com/Java_Edition_data_values/Pre-flattening * Materials: https://hub.spigotmc.org/javadocs/spigot/org/bukkit/Material.html @@ -56,16 +54,20 @@ import java.util.regex.Pattern; * Material IDs: https://minecraft-ids.grahamedgecombe.com/ * Material Source Code: https://hub.spigotmc.org/stash/projects/SPIGOT/repos/bukkit/browse/src/main/java/org/bukkit/Material.java * XMaterial v1: https://www.spigotmc.org/threads/329630/ + *

+ * This class will throw a "unsupported material" error if someone tries to use an item with an invalid data value which can only happen in 1.12 servers and below. + * To get an invalid item, (aka Missing Texture Block) you can use the command + * /give @p minecraft:dirt 1 10 where 1 is the item amount, and 10 is the data value. The material {@link #DIRT} with a data value of {@code 10} doesn't exist. * * @author Crypto Morin - * @version 4.0.0 + * @version 6.0.1 * @see Material * @see ItemStack */ public enum XMaterial { ACACIA_BOAT("BOAT_ACACIA"), ACACIA_BUTTON("WOOD_BUTTON"), - ACACIA_DOOR("ACACIA_DOOR_ITEM"), + ACACIA_DOOR("ACACIA_DOOR_ITEM", "ACACIA_DOOR"), ACACIA_FENCE, ACACIA_FENCE_GATE, ACACIA_LEAVES("LEAVES_2"), @@ -73,11 +75,11 @@ public enum XMaterial { ACACIA_PLANKS(4, "WOOD"), ACACIA_PRESSURE_PLATE("WOOD_PLATE"), ACACIA_SAPLING(4, "SAPLING"), - ACACIA_SIGN("SIGN"), + ACACIA_SIGN("SIGN_POST", "SIGN"), ACACIA_SLAB(4, "WOOD_STEP", "WOODEN_SLAB", "WOOD_DOUBLE_STEP"), ACACIA_STAIRS, ACACIA_TRAPDOOR("TRAP_DOOR"), - ACACIA_WALL_SIGN("SIGN_POST", "WALL_SIGN"), + ACACIA_WALL_SIGN("WALL_SIGN"), ACACIA_WOOD("LOG_2"), ACTIVATOR_RAIL, /** @@ -89,6 +91,7 @@ public enum XMaterial { */ AIR, ALLIUM(2, "RED_ROSE"), + ANCIENT_DEBRIS("1.16"), ANDESITE(5, "STONE"), ANDESITE_SLAB, ANDESITE_STAIRS, @@ -105,6 +108,7 @@ public enum XMaterial { BAMBOO_SAPLING("1.14"), BARREL("1.14", "CHEST", ""), BARRIER, + BASALT("1.16"), BAT_SPAWN_EGG(65, "MONSTER_EGG"), BEACON, BEDROCK, @@ -123,7 +127,7 @@ public enum XMaterial { BELL("1.14"), BIRCH_BOAT("BOAT_BIRCH"), BIRCH_BUTTON("WOOD_BUTTON"), - BIRCH_DOOR("BIRCH_DOOR_ITEM"), + BIRCH_DOOR("BIRCH_DOOR_ITEM", "BIRCH_DOOR"), BIRCH_FENCE, BIRCH_FENCE_GATE, BIRCH_LEAVES(2, "LEAVES"), @@ -131,18 +135,22 @@ public enum XMaterial { BIRCH_PLANKS(2, "WOOD"), BIRCH_PRESSURE_PLATE("WOOD_PLATE"), BIRCH_SAPLING(2, "SAPLING"), - BIRCH_SIGN("SIGN"), + BIRCH_SIGN("SIGN_POST", "SIGN"), BIRCH_SLAB(2, "WOOD_STEP", "WOODEN_SLAB", "WOOD_DOUBLE_STEP"), BIRCH_STAIRS("BIRCH_WOOD_STAIRS"), BIRCH_TRAPDOOR("TRAP_DOOR"), - BIRCH_WALL_SIGN("SIGN_POST", "WALL_SIGN"), + BIRCH_WALL_SIGN("WALL_SIGN"), BIRCH_WOOD(2, "LOG"), + BLACKSTONE("1.16"), + BLACKSTONE_SLAB("1.16"), + BLACKSTONE_STAIRS("1.16"), + BLACKSTONE_WALL("1.16"), BLACK_BANNER("BANNER", "STANDING_BANNER"), - BLACK_BED(15, "BED", "BED_BLOCK"), + BLACK_BED(15, "BED_BLOCK", "BED"), BLACK_CARPET(15, "CARPET"), BLACK_CONCRETE(15, "CONCRETE"), BLACK_CONCRETE_POWDER(15, "CONCRETE_POWDER"), - BLACK_DYE("1.14", "INK_SACK"), + BLACK_DYE("1.14", "INK_SACK", "INK_SAC"), BLACK_GLAZED_TERRACOTTA(15, "1.12", "HARD_CLAY", "STAINED_CLAY", "BLACK_TERRACOTTA"), BLACK_SHULKER_BOX, BLACK_STAINED_GLASS(15, "STAINED_GLASS"), @@ -154,8 +162,8 @@ public enum XMaterial { BLAZE_POWDER, BLAZE_ROD, BLAZE_SPAWN_EGG(61, "MONSTER_EGG"), - BLUE_BANNER(11, "BANNER", "STANDING_BANNER"), - BLUE_BED(4, "BED", "BED_BLOCK"), + BLUE_BANNER(4, "BANNER", "STANDING_BANNER"), + BLUE_BED(11, "BED_BLOCK", "BED"), BLUE_CARPET(11, "CARPET"), BLUE_CONCRETE(11, "CONCRETE"), BLUE_CONCRETE_POWDER(11, "CONCRETE_POWDER"), @@ -166,8 +174,8 @@ public enum XMaterial { BLUE_SHULKER_BOX, BLUE_STAINED_GLASS(11, "STAINED_GLASS"), BLUE_STAINED_GLASS_PANE(11, "THIN_GLASS", "STAINED_GLASS_PANE"), - BLUE_TERRACOTTA(11, "STAINED_CLAY"), - BLUE_WALL_BANNER(11, "WALL_BANNER"), + BLUE_TERRACOTTA(11, "HARD_CLAY", "STAINED_CLAY"), + BLUE_WALL_BANNER(4, "WALL_BANNER"), BLUE_WOOL(11, "WOOL"), BONE, BONE_BLOCK, @@ -188,7 +196,7 @@ public enum XMaterial { BRICK_STAIRS, BRICK_WALL, BROWN_BANNER(3, "BANNER", "STANDING_BANNER"), - BROWN_BED(12, "BED", "BED_BLOCK"), + BROWN_BED(12, "BED_BLOCK", "BED"), BROWN_CARPET(12, "CARPET"), BROWN_CONCRETE(12, "CONCRETE"), BROWN_CONCRETE_POWDER(12, "CONCRETE_POWDER"), @@ -225,6 +233,7 @@ public enum XMaterial { */ CAVE_AIR("AIR"), CAVE_SPIDER_SPAWN_EGG(59, "MONSTER_EGG"), + CHAIN("1.16"), CHAINMAIL_BOOTS, CHAINMAIL_CHESTPLATE, CHAINMAIL_HELMET, @@ -236,6 +245,8 @@ public enum XMaterial { CHICKEN("RAW_CHICKEN"), CHICKEN_SPAWN_EGG(93, "MONSTER_EGG"), CHIPPED_ANVIL(1, "ANVIL"), + CHISELED_NETHER_BRICKS(1, "NETHER_BRICKS"), + CHISELED_POLISHED_BLACKSTONE("1.16", "POLISHED_BLACKSTONE"), CHISELED_QUARTZ_BLOCK(1, "QUARTZ_BLOCK"), CHISELED_RED_SANDSTONE(1, "RED_SANDSTONE"), CHISELED_SANDSTONE(1, "SANDSTONE"), @@ -262,7 +273,14 @@ public enum XMaterial { COD_SPAWN_EGG("1.13", "MONSTER_EGG", ""), COMMAND_BLOCK("COMMAND"), COMMAND_BLOCK_MINECART("COMMAND_MINECART"), - COMPARATOR("REDSTONE_COMPARATOR", "REDSTONE_COMPARATOR_ON", "REDSTONE_COMPARATOR_OFF"), + /** + * Unlike redstone torch and redstone lamp... neither REDTONE_COMPARATOR_OFF nor REDSTONE_COMPARATOR_ON + * are items. REDSTONE_COMPARATOR is. + * + * @see #REDSTONE_TORCH + * @see #REDSTONE_LAMP + */ + COMPARATOR("REDSTONE_COMPARATOR_OFF", "REDSTONE_COMPARATOR_ON", "REDSTONE_COMPARATOR"), COMPASS, COMPOSTER("1.14", "CAULDRON", ""), CONDUIT("1.13", "BEACON"), @@ -276,19 +294,38 @@ public enum XMaterial { COOKIE, CORNFLOWER(4, "1.14", "BLUE_DYE", ""), COW_SPAWN_EGG(92, "MONSTER_EGG"), + CRACKED_NETHER_BRICKS(2, "NETHER_BRICKS"), + CRACKED_POLISHED_BLACKSTONE_BRICKS("1.16", "POLISHED_BLACKSTONE_BRICKS"), CRACKED_STONE_BRICKS(2, "SMOOTH_BRICK"), CRAFTING_TABLE("WORKBENCH"), CREEPER_BANNER_PATTERN, CREEPER_HEAD(4, "SKULL", "SKULL_ITEM"), CREEPER_SPAWN_EGG(50, "MONSTER_EGG"), CREEPER_WALL_HEAD(4, "SKULL", "SKULL_ITEM"), + CRIMSON_BUTTON("1.16"), + CRIMSON_DOOR("1.16"), + CRIMSON_FENCE("1.16"), + CRIMSON_FENCE_GATE("1.16"), + CRIMSON_FUNGUS("1.16"), + CRIMSON_HYPHAE("1.16"), + CRIMSON_NYLIUM("1.16"), + CRIMSON_PLANKS("1.16"), + CRIMSON_PRESSURE_PLATE("1.16"), + CRIMSON_ROOTS("1.16"), + CRIMSON_SIGN("1.16", "SIGN_POST"), + CRIMSON_SLAB("1.16"), + CRIMSON_STAIRS("1.16"), + CRIMSON_STEM("1.16"), + CRIMSON_TRAPDOOR("1.16"), + CRIMSON_WALL_SIGN("1.16", "WALL_SIGN"), CROSSBOW, + CRYING_OBSIDIAN("1.16"), CUT_RED_SANDSTONE("1.13"), CUT_RED_SANDSTONE_SLAB("STONE_SLAB2"), CUT_SANDSTONE("1.13"), CUT_SANDSTONE_SLAB("STEP"), CYAN_BANNER(6, "BANNER", "STANDING_BANNER"), - CYAN_BED(9, "BED", "BED_BLOCK"), + CYAN_BED(9, "BED_BLOCK", "BED"), CYAN_CARPET(9, "CARPET"), CYAN_CONCRETE(9, "CONCRETE"), CYAN_CONCRETE_POWDER(9, "CONCRETE_POWDER"), @@ -304,19 +341,19 @@ public enum XMaterial { DANDELION("YELLOW_FLOWER"), DARK_OAK_BOAT("BOAT_DARK_OAK"), DARK_OAK_BUTTON("WOOD_BUTTON"), - DARK_OAK_DOOR("DARK_OAK_DOOR_ITEM"), + DARK_OAK_DOOR("DARK_OAK_DOOR_ITEM", "DARK_OAK_DOOR"), DARK_OAK_FENCE, DARK_OAK_FENCE_GATE, - DARK_OAK_LEAVES(1, "LEAVES", "LEAVES_2"), + DARK_OAK_LEAVES(4, "LEAVES", "LEAVES_2"), DARK_OAK_LOG(1, "LOG", "LOG_2"), DARK_OAK_PLANKS(5, "WOOD"), DARK_OAK_PRESSURE_PLATE("WOOD_PLATE"), DARK_OAK_SAPLING(5, "SAPLING"), - DARK_OAK_SIGN("SIGN"), - DARK_OAK_SLAB("WOOD_STEP", "WOODEN_SLAB", "WOOD_DOUBLE_STEP"), + DARK_OAK_SIGN("SIGN_POST", "SIGN"), + DARK_OAK_SLAB(5, "WOOD_STEP", "WOODEN_SLAB", "WOOD_DOUBLE_STEP"), DARK_OAK_STAIRS, DARK_OAK_TRAPDOOR("TRAP_DOOR"), - DARK_OAK_WALL_SIGN("SIGN_POST", "WALL_SIGN"), + DARK_OAK_WALL_SIGN("WALL_SIGN"), DARK_OAK_WOOD(1, "LOG", "LOG_2"), DARK_PRISMARINE(1, "PRISMARINE"), DARK_PRISMARINE_SLAB("1.13"), @@ -395,7 +432,7 @@ public enum XMaterial { END_ROD("1.9", "BLAZE_ROD", ""), END_STONE("ENDER_STONE"), END_STONE_BRICKS("END_BRICKS"), - END_STONE_BRICK_SLAB(4, "STEP"), + END_STONE_BRICK_SLAB(6, "STEP"), END_STONE_BRICK_STAIRS("SMOOTH_STAIRS"), END_STONE_BRICK_WALL, EVOKER_SPAWN_EGG(34, "MONSTER_EGG"), @@ -404,6 +441,11 @@ public enum XMaterial { FEATHER, FERMENTED_SPIDER_EYE, FERN(2, "LONG_GRASS"), + /** + * For some reasons filled map items are really special. + * Their data value starts from 0 and every time a player + * creates a new map that maps data value increases. + */ FILLED_MAP("MAP"), FIRE, FIREWORK_ROCKET("FIREWORK"), @@ -428,6 +470,7 @@ public enum XMaterial { FURNACE_MINECART("POWERED_MINECART"), GHAST_SPAWN_EGG(56, "MONSTER_EGG"), GHAST_TEAR, + GILDED_BLACKSTONE("1.16"), GLASS, GLASS_BOTTLE, GLASS_PANE("THIN_GLASS"), @@ -455,12 +498,12 @@ public enum XMaterial { GRANITE_SLAB, GRANITE_STAIRS, GRANITE_WALL, - GRASS, + GRASS(1, "LONG_GRASS"), GRASS_BLOCK("GRASS"), GRASS_PATH, GRAVEL, GRAY_BANNER(8, "BANNER", "STANDING_BANNER"), - GRAY_BED(7, "BED", "BED_BLOCK"), + GRAY_BED(7, "BED_BLOCK", "BED"), GRAY_CARPET(7, "CARPET"), GRAY_CONCRETE(7, "CONCRETE"), GRAY_CONCRETE_POWDER(7, "CONCRETE_POWDER"), @@ -473,7 +516,7 @@ public enum XMaterial { GRAY_WALL_BANNER(8, "WALL_BANNER"), GRAY_WOOL(7, "WOOL"), GREEN_BANNER(2, "BANNER", "STANDING_BANNER"), - GREEN_BED(13, "BED", "BED_BLOCK"), + GREEN_BED(13, "BED_BLOCK", "BED"), GREEN_CARPET(13, "CARPET"), GREEN_CONCRETE(13, "CONCRETE"), GREEN_CONCRETE_POWDER(13, "CONCRETE_POWDER"), @@ -491,6 +534,7 @@ public enum XMaterial { HAY_BLOCK, HEART_OF_THE_SEA("1.13"), HEAVY_WEIGHTED_PRESSURE_PLATE("IRON_PLATE"), + HOGLIN_SPAWN_EGG("1.16", "MONSTER_EGG"), HONEYCOMB("1.15"), HONEYCOMB_BLOCK("1.15"), HONEY_BLOCK("1.15", "SLIME_BLOCK", ""), @@ -510,6 +554,11 @@ public enum XMaterial { INFESTED_MOSSY_STONE_BRICKS(3, "MONSTER_EGGS"), INFESTED_STONE("MONSTER_EGGS"), INFESTED_STONE_BRICKS(2, "MONSTER_EGGS", "SMOOTH_BRICK"), + /** + * We will only add "INK_SAC" for {@link #BLACK_DYE} since it's + * the only material (linked with this material) that is added + * after 1.13, which means it can use both INK_SACK and INK_SAC. + */ INK_SAC("INK_SACK"), IRON_AXE, IRON_BARS("IRON_FENCE"), @@ -534,7 +583,7 @@ public enum XMaterial { JUKEBOX, JUNGLE_BOAT("BOAT_JUNGLE"), JUNGLE_BUTTON("WOOD_BUTTON"), - JUNGLE_DOOR("JUNGLE_DOOR_ITEM"), + JUNGLE_DOOR("JUNGLE_DOOR_ITEM", "JUNGLE_DOOR"), JUNGLE_FENCE, JUNGLE_FENCE_GATE, JUNGLE_LEAVES(3, "LEAVES"), @@ -542,11 +591,11 @@ public enum XMaterial { JUNGLE_PLANKS(3, "WOOD"), JUNGLE_PRESSURE_PLATE("WOOD_PLATE"), JUNGLE_SAPLING(3, "SAPLING"), - JUNGLE_SIGN("SIGN"), + JUNGLE_SIGN("SIGN_POST", "SIGN"), JUNGLE_SLAB(3, "WOOD_STEP", "WOODEN_SLAB", "WOOD_DOUBLE_STEP"), JUNGLE_STAIRS("JUNGLE_WOOD_STAIRS"), JUNGLE_TRAPDOOR("TRAP_DOOR"), - JUNGLE_WALL_SIGN("SIGN_POST", "WALL_SIGN"), + JUNGLE_WALL_SIGN("WALL_SIGN"), JUNGLE_WOOD(3, "LOG"), KELP("1.13"), KELP_PLANT("1.13"), @@ -568,8 +617,8 @@ public enum XMaterial { LEATHER_LEGGINGS, LECTERN("1.14", "BOOKSHELF", ""), LEVER, - LIGHT_BLUE_BANNER(3, "BANNER", "STANDING_BANNER"), - LIGHT_BLUE_BED(3, "BED", "BED_BLOCK"), + LIGHT_BLUE_BANNER(12, "BANNER", "STANDING_BANNER"), + LIGHT_BLUE_BED(3, "BED_BLOCK", "BED"), LIGHT_BLUE_CARPET(3, "CARPET"), LIGHT_BLUE_CONCRETE(3, "CONCRETE"), LIGHT_BLUE_CONCRETE_POWDER(3, "CONCRETE_POWDER"), @@ -582,16 +631,16 @@ public enum XMaterial { LIGHT_BLUE_WALL_BANNER(12, "WALL_BANNER", "BANNER", "STANDING_BANNER"), LIGHT_BLUE_WOOL(3, "WOOL"), LIGHT_GRAY_BANNER(7, "BANNER", "STANDING_BANNER"), - LIGHT_GRAY_BED(8, "BED", "BED_BLOCK"), + LIGHT_GRAY_BED(8, "BED_BLOCK", "BED"), LIGHT_GRAY_CARPET(8, "CARPET"), LIGHT_GRAY_CONCRETE(8, "CONCRETE"), LIGHT_GRAY_CONCRETE_POWDER(8, "CONCRETE_POWDER"), LIGHT_GRAY_DYE(7, "INK_SACK"), /** - * Renamed to SILVER_GLAZED_TERRACOTTA in 1.13 + * Renamed to SILVER_GLAZED_TERRACOTTA in 1.12 * Renamed to LIGHT_GRAY_GLAZED_TERRACOTTA in 1.14 */ - LIGHT_GRAY_GLAZED_TERRACOTTA(8, "1.12", "HARD_CLAY", "STAINED_CLAY", "LIGHT_GRAY_TERRACOTTA", "SILVER_GLAZED_TERRACOTTA"), + LIGHT_GRAY_GLAZED_TERRACOTTA("1.12", "HARD_CLAY", "STAINED_CLAY", "LIGHT_GRAY_TERRACOTTA", "SILVER_GLAZED_TERRACOTTA"), LIGHT_GRAY_SHULKER_BOX("SILVER_SHULKER_BOX"), LIGHT_GRAY_STAINED_GLASS(8, "STAINED_GLASS"), LIGHT_GRAY_STAINED_GLASS_PANE(8, "THIN_GLASS", "STAINED_GLASS_PANE"), @@ -603,7 +652,7 @@ public enum XMaterial { LILY_OF_THE_VALLEY(15, "1.14", "WHITE_DYE", ""), LILY_PAD("WATER_LILY"), LIME_BANNER(10, "BANNER", "STANDING_BANNER"), - LIME_BED(5, "BED", "BED_BLOCK"), + LIME_BED(5, "BED_BLOCK", "BED"), LIME_CARPET(5, "CARPET"), LIME_CONCRETE(5, "CONCRETE"), LIME_CONCRETE_POWDER(5, "CONCRETE_POWDER"), @@ -617,9 +666,10 @@ public enum XMaterial { LIME_WOOL(5, "WOOL"), LINGERING_POTION, LLAMA_SPAWN_EGG(103, "MONSTER_EGG"), + LODESTONE("1.16"), LOOM("1.14"), MAGENTA_BANNER(13, "BANNER", "STANDING_BANNER"), - MAGENTA_BED(2, "BED", "BED_BLOCK"), + MAGENTA_BED(2, "BED_BLOCK", "BED"), MAGENTA_CARPET(2, "CARPET"), MAGENTA_CONCRETE(2, "CONCRETE"), MAGENTA_CONCRETE_POWDER(2, "CONCRETE_POWDER"), @@ -634,6 +684,13 @@ public enum XMaterial { MAGMA_BLOCK("1.10", "MAGMA"), MAGMA_CREAM, MAGMA_CUBE_SPAWN_EGG(62, "MONSTER_EGG"), + /** + * Adding this to the duplicated list will give you a filled map + * for 1.13+ versions and removing it from duplicated list will + * still give you a filled map in -1.12 versions. + * Since higher versions are our priority I'll keep 1.13+ support + * until I can come up with something to fix it. + */ MAP("EMPTY_MAP"), MELON("MELON_BLOCK"), MELON_SEEDS, @@ -648,7 +705,7 @@ public enum XMaterial { MOSSY_COBBLESTONE_STAIRS, MOSSY_COBBLESTONE_WALL(1, "COBBLE_WALL", "COBBLESTONE_WALL"), MOSSY_STONE_BRICKS(1, "SMOOTH_BRICK"), - MOSSY_STONE_BRICK_SLAB(4, "STEP"), + MOSSY_STONE_BRICK_SLAB(5, "STEP"), MOSSY_STONE_BRICK_STAIRS("SMOOTH_STAIRS"), MOSSY_STONE_BRICK_WALL, MOVING_PISTON("PISTON_BASE", "PISTON_MOVING_PIECE"), @@ -663,6 +720,7 @@ public enum XMaterial { MUSIC_DISC_FAR("RECORD_6"), MUSIC_DISC_MALL("RECORD_7"), MUSIC_DISC_MELLOHI("RECORD_8"), + MUSIC_DISC_PIGSTEP("1.16"), MUSIC_DISC_STAL("RECORD_9"), MUSIC_DISC_STRAD("RECORD_10"), MUSIC_DISC_WAIT("RECORD_11"), @@ -671,15 +729,29 @@ public enum XMaterial { MYCELIUM("MYCEL"), NAME_TAG, NAUTILUS_SHELL("1.13"), + NETHERITE_AXE("1.16"), + NETHERITE_BLOCK("1.16"), + NETHERITE_BOOTS("1.16"), + NETHERITE_CHESTPLATE("1.16"), + NETHERITE_HELMET("1.16"), + NETHERITE_HOE("1.16"), + NETHERITE_INGOT("1.16"), + NETHERITE_LEGGINGS("1.16"), + NETHERITE_PICKAXE("1.16"), + NETHERITE_SCRAP("1.16"), + NETHERITE_SHOVEL("1.16"), + NETHERITE_SWORD("1.16"), NETHERRACK, NETHER_BRICK("NETHER_BRICK_ITEM"), NETHER_BRICKS("NETHER_BRICK"), NETHER_BRICK_FENCE("NETHER_FENCE"), - NETHER_BRICK_SLAB(4, "STEP"), + NETHER_BRICK_SLAB(6, "STEP"), NETHER_BRICK_STAIRS, NETHER_BRICK_WALL, + NETHER_GOLD_ORE("1.16"), NETHER_PORTAL("PORTAL"), NETHER_QUARTZ_ORE("QUARTZ_ORE"), + NETHER_SPROUTS("1.16"), NETHER_STAR, /** * Just like mentioned in https://minecraft.gamepedia.com/Nether_Wart @@ -699,17 +771,17 @@ public enum XMaterial { OAK_PLANKS("WOOD"), OAK_PRESSURE_PLATE("WOOD_PLATE"), OAK_SAPLING("SAPLING"), - OAK_SIGN("SIGN"), + OAK_SIGN("SIGN_POST", "SIGN"), OAK_SLAB("WOOD_STEP", "WOODEN_SLAB", "WOOD_DOUBLE_STEP"), OAK_STAIRS("WOOD_STAIRS"), OAK_TRAPDOOR("TRAP_DOOR"), - OAK_WALL_SIGN("SIGN_POST", "WALL_SIGN"), + OAK_WALL_SIGN("WALL_SIGN"), OAK_WOOD("LOG"), OBSERVER, OBSIDIAN, OCELOT_SPAWN_EGG(98, "MONSTER_EGG"), ORANGE_BANNER(14, "BANNER", "STANDING_BANNER"), - ORANGE_BED(1, "BED", "BED_BLOCK"), + ORANGE_BED(1, "BED_BLOCK", "BED"), ORANGE_CARPET(1, "CARPET"), ORANGE_CONCRETE(1, "CONCRETE"), ORANGE_CONCRETE_POWDER(1, "CONCRETE_POWDER"), @@ -732,10 +804,12 @@ public enum XMaterial { PETRIFIED_OAK_SLAB("WOOD_STEP"), PHANTOM_MEMBRANE("1.13"), PHANTOM_SPAWN_EGG("1.13", "MONSTER_EGG", ""), + PIGLIN_BANNER_PATTERN("1.16"), + PIGLIN_SPAWN_EGG(57, "MONSTER_EGG"), PIG_SPAWN_EGG(90, "MONSTER_EGG"), PILLAGER_SPAWN_EGG("1.14"), PINK_BANNER(9, "BANNER", "STANDING_BANNER"), - PINK_BED(6, "BED", "BED_BLOCK"), + PINK_BED(6, "BED_BLOCK", "BED"), PINK_CARPET(6, "CARPET"), PINK_CONCRETE(6, "CONCRETE"), PINK_CONCRETE_POWDER(6, "CONCRETE_POWDER"), @@ -746,7 +820,7 @@ public enum XMaterial { PINK_STAINED_GLASS_PANE(6, "THIN_GLASS", "STAINED_GLASS_PANE"), PINK_TERRACOTTA(6, "HARD_CLAY", "STAINED_CLAY"), PINK_TULIP(7, "RED_ROSE"), - PINK_WALL_BANNER(14, "WALL_BANNER"), + PINK_WALL_BANNER(9, "WALL_BANNER"), PINK_WOOL(6, "WOOL"), PISTON("PISTON_BASE"), PISTON_HEAD("PISTON_EXTENSION"), @@ -758,6 +832,17 @@ public enum XMaterial { POLISHED_ANDESITE(6, "STONE"), POLISHED_ANDESITE_SLAB, POLISHED_ANDESITE_STAIRS, + POLISHED_BASALT("1.16"), + POLISHED_BLACKSTONE("1.16"), + POLISHED_BLACKSTONE_BRICKS("1.16"), + POLISHED_BLACKSTONE_BRICK_SLAB("1.16"), + POLISHED_BLACKSTONE_BRICK_STAIRS("1.16"), + POLISHED_BLACKSTONE_BRICK_WALL("1.16"), + POLISHED_BLACKSTONE_BUTTON("1.16"), + POLISHED_BLACKSTONE_PRESSURE_PLATE("1.16"), + POLISHED_BLACKSTONE_SLAB("1.16"), + POLISHED_BLACKSTONE_STAIRS("1.16"), + POLISHED_BLACKSTONE_WALL("1.16"), POLISHED_DIORITE(4, "STONE"), POLISHED_DIORITE_SLAB, POLISHED_DIORITE_STAIRS, @@ -779,6 +864,8 @@ public enum XMaterial { POTTED_BROWN_MUSHROOM("FLOWER_POT"), POTTED_CACTUS("FLOWER_POT"), POTTED_CORNFLOWER, + POTTED_CRIMSON_FUNGUS("1.16"), + POTTED_CRIMSON_ROOTS("1.16"), POTTED_DANDELION("YELLOW_FLOWER", "FLOWER_POT"), POTTED_DARK_OAK_SAPLING(5, "SAPLING", "FLOWER_POT"), POTTED_DEAD_BUSH("FLOWER_POT"), @@ -793,6 +880,8 @@ public enum XMaterial { POTTED_RED_MUSHROOM("FLOWER_POT"), POTTED_RED_TULIP(4, "RED_ROSE", "FLOWER_POT"), POTTED_SPRUCE_SAPLING(1, "SAPLING", "FLOWER_POT"), + POTTED_WARPED_FUNGUS("1.16"), + POTTED_WARPED_ROOTS("1.16"), POTTED_WHITE_TULIP(6, "RED_ROSE", "FLOWER_POT"), POTTED_WITHER_ROSE, POWERED_RAIL, @@ -813,7 +902,7 @@ public enum XMaterial { PUMPKIN_SEEDS, PUMPKIN_STEM, PURPLE_BANNER(5, "BANNER", "STANDING_BANNER"), - PURPLE_BED(10, "BED", "BED_BLOCK"), + PURPLE_BED(10, "BED_BLOCK", "BED"), PURPLE_CARPET(10, "CARPET"), PURPLE_CONCRETE(10, "CONCRETE"), PURPLE_CONCRETE_POWDER(10, "CONCRETE_POWDER"), @@ -831,6 +920,7 @@ public enum XMaterial { PURPUR_STAIRS, QUARTZ, QUARTZ_BLOCK, + QUARTZ_BRICKS("1.16"), QUARTZ_PILLAR(2, "QUARTZ_BLOCK"), QUARTZ_SLAB(7, "STEP"), QUARTZ_STAIRS, @@ -843,17 +933,31 @@ public enum XMaterial { RAVAGER_SPAWN_EGG("1.14"), REDSTONE, REDSTONE_BLOCK, - REDSTONE_LAMP("REDSTONE_LAMP_OFF", "REDSTONE_LAMP_ON"), + /** + * Unlike redstone torch, REDSTONE_LAMP_ON isn't an item. + * The name is just here on the list for matching. + * + * @see #REDSTONE_TORCH + */ + REDSTONE_LAMP("REDSTONE_LAMP_ON", "REDSTONE_LAMP_OFF"), REDSTONE_ORE("GLOWING_REDSTONE_ORE"), - REDSTONE_TORCH("REDSTONE_TORCH_ON", "REDSTONE_TORCH_OFF"), - REDSTONE_WALL_TORCH(1, "REDSTONE_TORCH_ON", "REDSTONE_TORCH_OFF"), + /** + * REDSTONE_TORCH_OFF isn't an item, but a block. + * But REDSTONE_TORCH_ON is the item. + * The name is just here on the list for matching. + */ + REDSTONE_TORCH("REDSTONE_TORCH_OFF", "REDSTONE_TORCH_ON"), + REDSTONE_WALL_TORCH, REDSTONE_WIRE, RED_BANNER(1, "BANNER", "STANDING_BANNER"), - RED_BED(14, "BED", "BED_BLOCK"), + /** + * Data value 14 or 0 + */ + RED_BED(0, "BED_BLOCK", "BED"), RED_CARPET(14, "CARPET"), RED_CONCRETE(14, "CONCRETE"), RED_CONCRETE_POWDER(14, "CONCRETE_POWDER"), - RED_DYE(1, "ROSE_RED"), + RED_DYE(1, "INK_SACK", "ROSE_RED"), RED_GLAZED_TERRACOTTA(14, "1.12", "HARD_CLAY", "STAINED_CLAY", "RED_TERRACOTTA"), RED_MUSHROOM, RED_MUSHROOM_BLOCK("RED_MUSHROOM", "HUGE_MUSHROOM_2"), @@ -873,8 +977,9 @@ public enum XMaterial { RED_TULIP(4, "RED_ROSE"), RED_WALL_BANNER(1, "WALL_BANNER"), RED_WOOL(14, "WOOL"), - REPEATER("DIODE", "DIODE_BLOCK_ON", "DIODE_BLOCK_OFF"), + REPEATER("DIODE_BLOCK_ON", "DIODE_BLOCK_OFF", "DIODE"), REPEATING_COMMAND_BLOCK("COMMAND", "COMMAND_REPEATING"), + RESPAWN_ANCHOR("1.16"), ROSE_BUSH(4, "DOUBLE_PLANT"), ROTTEN_FLESH, SADDLE, @@ -894,6 +999,7 @@ public enum XMaterial { SHEARS, SHEEP_SPAWN_EGG(91, "MONSTER_EGG"), SHIELD, + SHROOMLIGHT("1.16"), SHULKER_BOX("PURPLE_SHULKER_BOX"), SHULKER_SHELL, SHULKER_SPAWN_EGG(69, "MONSTER_EGG"), @@ -922,7 +1028,13 @@ public enum XMaterial { SNOW, SNOWBALL("SNOW_BALL"), SNOW_BLOCK, + SOUL_CAMPFIRE("1.16"), + SOUL_FIRE("1.16"), + SOUL_LANTERN("1.16"), SOUL_SAND, + SOUL_SOIL("1.16"), + SOUL_TORCH("1.16"), + SOUL_WALL_TORCH("1.16"), SPAWNER("MOB_SPAWNER"), SPECTRAL_ARROW("1.9", "ARROW", ""), SPIDER_EYE, @@ -931,19 +1043,19 @@ public enum XMaterial { SPONGE, SPRUCE_BOAT("BOAT_SPRUCE"), SPRUCE_BUTTON("WOOD_BUTTON"), - SPRUCE_DOOR("SPRUCE_DOOR_ITEM"), + SPRUCE_DOOR("SPRUCE_DOOR_ITEM", "SPRUCE_DOOR"), SPRUCE_FENCE, SPRUCE_FENCE_GATE, - SPRUCE_LEAVES(1, "LEAVES"), + SPRUCE_LEAVES(1, "LEAVES", "LEAVES_2"), SPRUCE_LOG(1, "LOG"), SPRUCE_PLANKS(1, "WOOD"), SPRUCE_PRESSURE_PLATE("WOOD_PLATE"), SPRUCE_SAPLING(1, "SAPLING"), - SPRUCE_SIGN("SIGN"), + SPRUCE_SIGN("SIGN_POST", "SIGN"), SPRUCE_SLAB(1, "WOOD_STEP", "WOODEN_SLAB", "WOOD_DOUBLE_STEP"), SPRUCE_STAIRS("SPRUCE_WOOD_STAIRS"), SPRUCE_TRAPDOOR("TRAP_DOOR"), - SPRUCE_WALL_SIGN("SIGN_POST", "WALL_SIGN"), + SPRUCE_WALL_SIGN("WALL_SIGN"), SPRUCE_WOOD(1, "LOG"), SQUID_SPAWN_EGG(94, "MONSTER_EGG"), STICK, @@ -964,11 +1076,14 @@ public enum XMaterial { STONE_STAIRS, STONE_SWORD, STRAY_SPAWN_EGG(6, "MONSTER_EGG"), + STRIDER_SPAWN_EGG("1.16"), STRING, STRIPPED_ACACIA_LOG("LOG_2"), STRIPPED_ACACIA_WOOD("LOG_2"), STRIPPED_BIRCH_LOG(2, "LOG"), STRIPPED_BIRCH_WOOD(2, "LOG"), + STRIPPED_CRIMSON_HYPHAE("1.16"), + STRIPPED_CRIMSON_STEM("1.16"), STRIPPED_DARK_OAK_LOG("LOG"), STRIPPED_DARK_OAK_WOOD("LOG"), STRIPPED_JUNGLE_LOG(3, "LOG"), @@ -977,6 +1092,8 @@ public enum XMaterial { STRIPPED_OAK_WOOD("LOG"), STRIPPED_SPRUCE_LOG(1, "LOG"), STRIPPED_SPRUCE_WOOD(1, "LOG"), + STRIPPED_WARPED_HYPHAE("1.16"), + STRIPPED_WARPED_STEM("1.16"), STRUCTURE_BLOCK, /** * Originally developers used barrier blocks for its purpose. @@ -995,6 +1112,7 @@ public enum XMaterial { SWEET_BERRY_BUSH("1.14", "GRASS", ""), TALL_GRASS(2, "DOUBLE_PLANT"), TALL_SEAGRASS(2, "1.13", "TALL_GRASS", ""), + TARGET("1.16"), TERRACOTTA("HARD_CLAY"), TIPPED_ARROW("1.9", "ARROW", ""), TNT, @@ -1016,6 +1134,8 @@ public enum XMaterial { TURTLE_EGG("1.13", "EGG", ""), TURTLE_HELMET("1.13", "IRON_HELMET", ""), TURTLE_SPAWN_EGG("1.13", "CHICKEN_SPAWN_EGG", ""), + TWISTING_VINES("1.16"), + TWISTING_VINES_PLANT("1.16"), VEX_SPAWN_EGG(35, "MONSTER_EGG"), VILLAGER_SPAWN_EGG(120, "MONSTER_EGG"), VINDICATOR_SPAWN_EGG(36, "MONSTER_EGG"), @@ -1028,6 +1148,24 @@ public enum XMaterial { VOID_AIR("AIR"), WALL_TORCH("TORCH"), WANDERING_TRADER_SPAWN_EGG("1.14", "VILLAGER_SPAWN_EGG", ""), + WARPED_BUTTON("1.16"), + WARPED_DOOR("1.16"), + WARPED_FENCE("1.16"), + WARPED_FENCE_GATE("1.16"), + WARPED_FUNGUS("1.16"), + WARPED_FUNGUS_ON_A_STICK("1.16"), + WARPED_HYPHAE("1.16"), + WARPED_NYLIUM("1.16"), + WARPED_PLANKS("1.16"), + WARPED_PRESSURE_PLATE("1.16"), + WARPED_ROOTS("1.16"), + WARPED_SIGN("1.16", "SIGN_POST"), + WARPED_SLAB("1.16"), + WARPED_STAIRS("1.16"), + WARPED_STEM("1.16"), + WARPED_TRAPDOOR("1.16"), + WARPED_WALL_SIGN("1.16", "WALL_SIGN"), + WARPED_WART_BLOCK("1.16"), /** * This is used for blocks only. * In 1.13- WATER will turn into STATIONARY_WATER after it finished spreading. @@ -1037,6 +1175,8 @@ public enum XMaterial { */ WATER("STATIONARY_WATER"), WATER_BUCKET, + WEEPING_VINES("1.16"), + WEEPING_VINES_PLANT("1.16"), WET_SPONGE(1, "SPONGE"), /** * Wheat is a known material in pre-1.13 @@ -1045,16 +1185,16 @@ public enum XMaterial { WHEAT("CROPS"), WHEAT_SEEDS("SEEDS"), WHITE_BANNER(15, "BANNER", "STANDING_BANNER"), - WHITE_BED("BED", "BED_BLOCK"), + WHITE_BED("BED_BLOCK", "BED"), WHITE_CARPET("CARPET"), WHITE_CONCRETE("CONCRETE"), WHITE_CONCRETE_POWDER("CONCRETE_POWDER"), WHITE_DYE(15, "1.14", "INK_SACK", "BONE_MEAL"), - WHITE_GLAZED_TERRACOTTA("1.12", "HARD_CLAY", "STAINED_CLAY", "WHITE_TERRACOTTA"), + WHITE_GLAZED_TERRACOTTA("1.12", "HARD_CLAY", "STAINED_CLAY"), WHITE_SHULKER_BOX, WHITE_STAINED_GLASS("STAINED_GLASS"), WHITE_STAINED_GLASS_PANE("THIN_GLASS", "STAINED_GLASS_PANE"), - WHITE_TERRACOTTA("HARD_CLAY", "TERRACOTTA"), + WHITE_TERRACOTTA("HARD_CLAY", "STAINED_CLAY", "TERRACOTTA"), WHITE_TULIP(6, "RED_ROSE"), WHITE_WALL_BANNER(15, "WALL_BANNER"), WHITE_WOOL("WOOL"), @@ -1072,7 +1212,7 @@ public enum XMaterial { WRITABLE_BOOK("BOOK_AND_QUILL"), WRITTEN_BOOK, YELLOW_BANNER(11, "BANNER", "STANDING_BANNER"), - YELLOW_BED(4, "BED", "BED_BLOCK"), + YELLOW_BED(4, "BED_BLOCK", "BED"), YELLOW_CARPET(4, "CARPET"), YELLOW_CONCRETE(4, "CONCRETE"), YELLOW_CONCRETE_POWDER(4, "CONCRETE_POWDER"), @@ -1084,21 +1224,31 @@ public enum XMaterial { YELLOW_TERRACOTTA(4, "HARD_CLAY", "STAINED_CLAY"), YELLOW_WALL_BANNER(11, "WALL_BANNER"), YELLOW_WOOL(4, "WOOL"), + ZOGLIN_SPAWN_EGG("1.16"), ZOMBIE_HEAD(2, "SKULL", "SKULL_ITEM"), ZOMBIE_HORSE_SPAWN_EGG(29, "MONSTER_EGG"), - ZOMBIE_PIGMAN_SPAWN_EGG(57, "MONSTER_EGG"), ZOMBIE_SPAWN_EGG(54, "MONSTER_EGG"), ZOMBIE_VILLAGER_SPAWN_EGG(27, "MONSTER_EGG"), - ZOMBIE_WALL_HEAD(2, "SKULL", "SKULL_ITEM"); + ZOMBIE_WALL_HEAD(2, "SKULL", "SKULL_ITEM"), + ZOMBIFIED_PIGLIN_SPAWN_EGG(57, "MONSTER_EGG", "ZOMBIE_PIGMAN_SPAWN_EGG"); /** - * An immutable cached set of {@link XMaterial#values()} to avoid allocating memory for + * Cached set of {@link XMaterial#values()} to avoid allocating memory for * calling the method every time. + * This set is mutable for performance, but do not change the elements. * * @since 2.0.0 */ public static final EnumSet VALUES = EnumSet.allOf(XMaterial.class); + + /** + * We don't want to use {@link Enums#getIfPresent(Class, String)} to avoid a few checks. + * + * @since 5.1.0 + */ + private static final Map NAMES = new HashMap<>(); + /** * A set of material names that can be damaged. *

@@ -1107,13 +1257,13 @@ public enum XMaterial { * * @since 1.0.0 */ - private static final ImmutableSet DAMAGEABLE = ImmutableSet.of( + private static final Set DAMAGEABLE = new HashSet<>(Arrays.asList( "HELMET", "CHESTPLATE", "LEGGINGS", "BOOTS", "SWORD", "AXE", "PICKAXE", "SHOVEL", "HOE", "ELYTRA", "TRIDENT", "HORSE_ARMOR", "BARDING", "SHEARS", "FLINT_AND_STEEL", "BOW", "FISHING_ROD", "CARROT_ON_A_STICK", "CARROT_STICK", "SPADE", "SHIELD" - ); + )); /** * XMaterial Paradox (Duplication Check) *

@@ -1124,19 +1274,39 @@ public enum XMaterial { * * @since 3.0.0 */ - @SuppressWarnings("UnstableApiUsage") - private static final ImmutableMap DUPLICATED = Maps.immutableEnumMap(ImmutableMap.builder() - .put(MELON, MELON_SLICE) - .put(CARROT, CARROTS) - .put(POTATO, POTATOES) - .put(BEETROOT, BEETROOTS) - .put(BROWN_MUSHROOM, BROWN_MUSHROOM_BLOCK) - .put(BRICK, BRICKS) - .put(RED_MUSHROOM, RED_MUSHROOM_BLOCK) - .put(MAP, FILLED_MAP) - .put(NETHER_BRICK, NETHER_BRICKS) - .build() - ); + private static final EnumMap DUPLICATED = new EnumMap(XMaterial.class) {{ + put(MELON, MELON_SLICE); + put(CARROT, CARROTS); + put(POTATO, POTATOES); + put(BEETROOT, BEETROOTS); + put(BROWN_MUSHROOM, BROWN_MUSHROOM_BLOCK); + put(BRICK, BRICKS); + put(NETHER_BRICK, NETHER_BRICKS); + + // Illegal Elements + // Since both 1.12 and 1.13 have _DOOR XMaterial will use it + // for 1.12 to parse the material, but it needs _DOOR_ITEM. + // We'll trick XMaterial into thinking this needs to be parsed + // using the old methods. + // Some of these materials have their enum name added to the legacy list as well. + put(DARK_OAK_DOOR, DARK_OAK_DOOR); + put(ACACIA_DOOR, ACACIA_DOOR); + put(BIRCH_DOOR, BIRCH_DOOR); + put(JUNGLE_DOOR, JUNGLE_DOOR); + put(SPRUCE_DOOR, SPRUCE_DOOR); + put(CAULDRON, CAULDRON); + put(BREWING_STAND, BREWING_STAND); + }}; + + /** + * Guava (Google Core Libraries for Java)'s cache for performance and timed caches. + * For strings that match a certain XMaterial. Mostly cached for configs. + * + * @since 1.0.0 + */ + private static final Cache NAME_CACHE = CacheBuilder.newBuilder() + .expireAfterAccess(15, TimeUnit.MINUTES) + .build(); /* * A set of all the legacy names without duplicates. *

@@ -1151,17 +1321,6 @@ public enum XMaterial { .filter(m -> m.charAt(1) == '.') .collect(Collectors.collectingAndThen(Collectors.toSet(), ImmutableSet::copyOf)); */ - - /** - * Guava (Google Core Libraries for Java)'s cache for performance and timed caches. - * For strings that match a certain XMaterial. Mostly cached for configs. - * - * @since 1.0.0 - */ - private static final Cache NAME_CACHE = CacheBuilder.newBuilder() - .softValues() - .expireAfterAccess(15, TimeUnit.MINUTES) - .build(); /** * Guava (Google Core Libraries for Java)'s cache for performance and timed caches. * For XMaterials that are already parsed once. @@ -1169,18 +1328,26 @@ public enum XMaterial { * @since 3.0.0 */ private static final Cache> PARSED_CACHE = CacheBuilder.newBuilder() - .softValues() .expireAfterAccess(10, TimeUnit.MINUTES) - .concurrencyLevel(Runtime.getRuntime().availableProcessors()) .build(); - /** - * Pre-compiled RegEx pattern. - * Include both replacements to avoid recreating string multiple times with multiple RegEx checks. + * This is used for {@link #isOneOf(Collection)} * - * @since 3.0.0 + * @since 3.4.0 */ - private static final Pattern FORMAT_PATTERN = Pattern.compile("\\W+"); + private static final LoadingCache CACHED_REGEX = CacheBuilder.newBuilder() + .expireAfterAccess(1, TimeUnit.HOURS) + .build(new CacheLoader() { + @Override + public Pattern load(@NotNull String str) { + try { + return Pattern.compile(str); + } catch (PatternSyntaxException ex) { + ex.printStackTrace(); + return null; + } + } + }); /** * The current version of the server in the a form of a major version. * @@ -1194,6 +1361,11 @@ public enum XMaterial { * @since 3.0.0 */ private static final boolean ISFLAT = supports(13); + + static { + for (XMaterial material : VALUES) NAMES.put(material.name(), material); + } + /** * The data value of this material https://minecraft.gamepedia.com/Java_Edition_data_values/Pre-flattening * @@ -1246,7 +1418,7 @@ public enum XMaterial { * An invocation of this method yields exactly the same result as the expression: *

*

- * {@link #getVersion()} == 1.8 + * !{@link #supports(int)} 9 *
* * @since 2.0.0 @@ -1255,6 +1427,18 @@ public enum XMaterial { return !supports(9); } + /** + * Gets the {@link XMaterial} with this name without throwing an exception. + * + * @param name the name of the material. + * @return an optional that can be empty. + * @since 5.1.0 + */ + @NotNull + private static Optional getIfPresent(@NotNull String name) { + return Optional.ofNullable(NAMES.get(name)); + } + /** * The current version of the server. * @@ -1274,15 +1458,16 @@ public enum XMaterial { * @since 1.0.0 */ @Nullable - private static XMaterial requestOldXMaterial(@Nonnull String name, byte data) { + private static XMaterial requestOldXMaterial(@NotNull String name, byte data) { String holder = name + data; - XMaterial material = NAME_CACHE.getIfPresent(holder); - if (material != null) return material; + XMaterial cache = NAME_CACHE.getIfPresent(holder); + if (cache != null) return cache; - for (XMaterial materials : VALUES) { - if ((data == -1 || data == materials.data) && materials.anyMatchLegacy(name)) { - NAME_CACHE.put(holder, materials); - return materials; + for (XMaterial material : VALUES) { + // Not using material.name().equals(name) check is intended. + if ((data == -1 || data == material.data) && material.anyMatchLegacy(name)) { + NAME_CACHE.put(holder, material); + return material; } } @@ -1301,60 +1486,39 @@ public enum XMaterial { * @return true if XMaterial enum has this material. * @since 1.0.0 */ - public static boolean contains(@Nonnull String name) { + public static boolean contains(@NotNull String name) { Validate.notEmpty(name, "Cannot check for null or empty material name"); name = format(name); - for (XMaterial materials : VALUES) + for (XMaterial materials : VALUES) { if (materials.name().equals(name)) return true; + } return false; } /** * Parses the given material name as an XMaterial with unspecified data value. * - * @see #matchXMaterial(String, byte) + * @see #matchXMaterialWithData(String) * @since 2.0.0 */ - @Nonnull - public static Optional matchXMaterial(@Nonnull String name) { - return matchXMaterial(name, (byte) -1); - } - - /** - * Parses the given material name as an XMaterial. - * Can also be used like: MATERIAL:DATA - *

- * Examples - *

-     *     {@code INK_SACK:1 -> RED_DYE}
-     *     {@code WOOL, 14  -> RED_WOOL}
-     * 
- * - * @see #matchDefinedXMaterial(String, byte) - * @see #matchXMaterial(ItemStack) - * @since 2.0.0 - */ - @Nonnull - public static Optional matchXMaterial(@Nonnull String name, byte data) { + @NotNull + public static Optional matchXMaterial(@NotNull String name) { Validate.notEmpty(name, "Cannot match a material with null or empty material name"); Optional oldMatch = matchXMaterialWithData(name); if (oldMatch.isPresent()) return oldMatch; - - // -1 Determines whether the item's data value is unknown and only the name is given. - // Checking if the item is damageable won't do anything as the data is not going to be checked in requestOldMaterial anyway. - return matchDefinedXMaterial(format(name), data); + return matchDefinedXMaterial(format(name), (byte) -1); } /** * Parses material name and data value from the specified string. - * The seperators are: , or : + * The separator for the material name and its data value is {@code :} * Spaces are allowed. Mostly used when getting materials from config for old school minecrafters. *

* Examples *

      *     {@code INK_SACK:1 -> RED_DYE}
-     *     {@code WOOL, 14  -> RED_WOOL}
+     *     {@code WOOL: 14  -> RED_WOOL}
      * 
* * @param name the material string that consists of the material name, data and separator character. @@ -1362,14 +1526,17 @@ public enum XMaterial { * @see #matchXMaterial(String) * @since 3.0.0 */ + @NotNull private static Optional matchXMaterialWithData(String name) { - for (char separator : new char[]{',', ':'}) { - int index = name.indexOf(separator); - if (index == -1) continue; - + int index = name.indexOf(':'); + if (index != -1) { String mat = format(name.substring(0, index)); - byte data = Byte.parseByte(StringUtils.deleteWhitespace(name.substring(index + 1))); - return matchDefinedXMaterial(mat, data); + + try { + byte data = (byte) Integer.parseInt(StringUtils.deleteWhitespace(name.substring(index + 1))); + return matchDefinedXMaterial(mat, data); + } catch (NumberFormatException ignored) { + } } return Optional.empty(); @@ -1383,11 +1550,11 @@ public enum XMaterial { * @see #matchXMaterial(ItemStack) * @since 2.0.0 */ - @Nonnull - public static XMaterial matchXMaterial(@Nonnull Material material) { + @NotNull + public static XMaterial matchXMaterial(@NotNull Material material) { Objects.requireNonNull(material, "Cannot match null material"); return matchDefinedXMaterial(material.name(), (byte) -1) - .orElseThrow(() -> new IllegalArgumentException("Unsupported Material: " + material)); + .orElseThrow(() -> new IllegalArgumentException("Unsupported material with no data value: " + material.name())); } /** @@ -1399,14 +1566,15 @@ public enum XMaterial { * @see #matchDefinedXMaterial(String, byte) * @since 2.0.0 */ - @Nonnull + @NotNull @SuppressWarnings("deprecation") - public static XMaterial matchXMaterial(@Nonnull ItemStack item) { + public static XMaterial matchXMaterial(@NotNull ItemStack item) { Objects.requireNonNull(item, "Cannot match null ItemStack"); String material = item.getType().name(); - return matchDefinedXMaterial(material, - isDamageable(material) ? (byte) 0 : (byte) item.getDurability()) - .orElseThrow(() -> new IllegalArgumentException("Unsupported Material: " + material)); + byte data = (byte) (ISFLAT || isDamageable(material) ? 0 : item.getDurability()); + + return matchDefinedXMaterial(material, data) + .orElseThrow(() -> new IllegalArgumentException("Unsupported material: " + material + " (" + data + ')')); } /** @@ -1416,32 +1584,45 @@ public enum XMaterial { * @param name the formatted name of the material. * @param data the data value of the material. * @return an XMaterial (with the same data value if specified) - * @see #matchXMaterial(String, byte) * @see #matchXMaterial(Material) * @see #matchXMaterial(int, byte) * @see #matchXMaterial(ItemStack) * @since 3.0.0 */ - @Nonnull - private static Optional matchDefinedXMaterial(@Nonnull String name, byte data) { + @SuppressWarnings("OptionalAssignedToNull") + @NotNull + private static Optional matchDefinedXMaterial(@NotNull String name, byte data) { boolean duplicated = isDuplicated(name); // Do basic number and boolean checks before accessing more complex enum stuff. // Maybe we can simplify (ISFLAT || !duplicated) with the (!ISFLAT && duplicated) under it to save a few nanoseconds? // if (!Boolean.valueOf(Boolean.getBoolean(Boolean.TRUE.toString())).equals(Boolean.FALSE.booleanValue())) return null; + Optional xMaterial = null; if (data <= 0 && (ISFLAT || !duplicated)) { // Apparently the transform method is more efficient than toJavaUtil() // toJavaUtil isn't even supported in older versions. - Optional xMat = Enums.getIfPresent(XMaterial.class, name).transform(Optional::of).or(Optional.empty()); - if (xMat.isPresent()) return xMat; + xMaterial = getIfPresent(name); + if (xMaterial.isPresent()) return xMaterial; } // XMaterial Paradox (Duplication Check) // I've concluded that this is just an infinite loop that keeps // going around the Singular Form and the Plural Form materials. A waste of brain cells and a waste of time. // This solution works just fine anyway. - if (!ISFLAT && duplicated) return Optional.ofNullable(requestDuplicatedXMaterial(name, data)); - return Optional.ofNullable(requestOldXMaterial(name, data)); + XMaterial xMat = requestOldXMaterial(name, data); + if (xMat == null) { + // Special case. Refer to FILLED_MAP for more info. + if (data > 0 && name.endsWith("MAP")) return Optional.of(FILLED_MAP); + return Optional.empty(); + } + + if (!ISFLAT && duplicated && xMat.name().charAt(xMat.name().length() - 1) == 'S') { + // A solution for XMaterial Paradox. + // Manually parses the duplicated materials to find the exact material based on the server version. + // If ends with "S" -> Plural Form Material + return xMaterial == null ? getIfPresent(name) : xMaterial; + } + return Optional.ofNullable(xMat); } /** @@ -1456,13 +1637,12 @@ public enum XMaterial { * @see #isDuplicated() * @since 2.0.0 */ - public static boolean isDuplicated(@Nonnull String name) { - Validate.notEmpty(name, "Cannot check duplication for null or empty material name"); - name = format(name); - + private static boolean isDuplicated(@NotNull String name) { // Don't use matchXMaterial() since this method is being called from matchXMaterial() itself and will cause a StackOverflowError. - for (Map.Entry duplicated : DUPLICATED.entrySet()) - if (duplicated.getKey().name().equals(name) || duplicated.getKey().anyMatchLegacy(name)) return true; + for (Map.Entry duplicated : DUPLICATED.entrySet()) { + XMaterial material = duplicated.getKey(); + if (material.name().equals(name) || material.anyMatchLegacy(name)) return true; + } return false; } @@ -1476,7 +1656,7 @@ public enum XMaterial { * @see #matchXMaterial(ItemStack) * @since 2.0.0 */ - @Nonnull + @NotNull public static Optional matchXMaterial(int id, byte data) { if (id < 0 || data < 0) return Optional.empty(); @@ -1486,72 +1666,43 @@ public enum XMaterial { return Optional.empty(); } - /** - * A solution for XMaterial Paradox. - * Manually parses the duplicated materials to find the exact material based on the server version. - * - * @param name the name of the material. - * @return the duplicated XMaterial based on the version. - * @throws IllegalArgumentException may be thrown. If thrown, it's a bug. - * @since 2.0.0 - */ - @Nullable - private static XMaterial requestDuplicatedXMaterial(@Nonnull String name, byte data) { - XMaterial mat = requestOldXMaterial(name, data); - // If ends with "S" -> Plural Form Material - return mat.name().charAt(mat.name().length() - 1) == 'S' ? Enums.getIfPresent(XMaterial.class, name).orNull() : mat; - } - - /** - * Always returns the value with the given duplicated material key name. - * - * @param name the name of the material. - * @return the new XMaterial of this duplicated material. - * @see #getXMaterialIfDuplicated(String) - * @since 2.0.0 - */ - @Nonnull - public static Optional getNewXMaterialIfDuplicated(@Nonnull String name) { - Validate.notEmpty(name, "Cannot get new duplicated material for null or empty material name"); - name = format(name); - - for (Map.Entry duplicated : DUPLICATED.entrySet()) - if (duplicated.getKey().name().equals(name)) return Optional.of(duplicated.getKey()); - return Optional.empty(); - } - - /** - * Checks if the item is duplicated for a different purpose in new versions from {@link #DUPLICATED}. - * - * @param name the name of the material. - * @return the other XMaterial (key or value) of the XMaterial (key or value). - * @see #matchXMaterial(String, byte) - * @since 2.0.0 - */ - @Nullable - public static XMaterial getXMaterialIfDuplicated(@Nonnull String name) { - Validate.notEmpty(name, "Cannot get duplicated material for null or empty material name"); - name = format(name); - - for (Map.Entry duplicated : DUPLICATED.entrySet()) - if (duplicated.getKey().name().equals(name)) return duplicated.getValue(); - else if (duplicated.getValue().name().equals(name)) return duplicated.getKey(); - - return null; - } - /** * Attempts to build the string like an enum name. - * Removes all the spaces, numbers and extra non-English characters. Also removes some config/in-game based strings. + * Removes all the spaces, and extra non-English characters. Also removes some config/in-game based strings. + * While this method is hard to maintain, it's extremely efficient. It's approximately more than x5 times faster than + * the normal RegEx + String Methods approach for both formatted and unformatted material names. * * @param name the material name to modify. * @return a Material enum name. * @since 2.0.0 */ - @Nonnull - private static String format(@Nonnull String name) { - return FORMAT_PATTERN.matcher( - name.trim().replace('-', '_').replace(' ', '_')).replaceAll("").toUpperCase(Locale.ENGLISH); + @NotNull + protected static String format(@NotNull String name) { + int len = name.length(); + char[] chs = new char[len]; + int count = 0; + boolean appendUnderline = false; + + for (int i = 0; i < len; ++i) { + char ch = name.charAt(i); + + if (!appendUnderline && count != 0 && (ch == '-' || ch == ' ' || ch == '_') && chs[count] != '_') appendUnderline = true; + else { + boolean number = false; + // Old materials have numbers in them. + if ((ch >= 'A' && ch <= 'Z') || (ch >= 'a' && ch <= 'z') || (number = (ch >= '0' && ch <= '9'))) { + if (appendUnderline) { + chs[count++] = '_'; + appendUnderline = false; + } + + if (number) chs[count++] = ch; + else chs[count++] = (char) (ch & 0x5f); + } + } + } + + return new String(chs, 0, count); } /** @@ -1572,8 +1723,8 @@ public enum XMaterial { * @see #toWord(String) * @since 2.1.0 */ - @Nonnull - public static String toWord(@Nonnull Material material) { + @NotNull + public static String toWord(@NotNull Material material) { Objects.requireNonNull(material, "Cannot translate a null material to a word"); return toWord(material.name()); } @@ -1593,8 +1744,8 @@ public enum XMaterial { * @return a cleaned more readable enum name. * @since 2.1.0 */ - @Nonnull - private static String toWord(@Nonnull String name) { + @NotNull + private static String toWord(@NotNull String name) { return WordUtils.capitalize(name.replace('_', ' ').toLowerCase(Locale.ENGLISH)); } @@ -1605,8 +1756,8 @@ public enum XMaterial { * @return the exact major version. * @since 2.0.0 */ - @Nonnull - public static String getMajorVersion(@Nonnull String version) { + @NotNull + public static String getMajorVersion(@NotNull String version) { Validate.notEmpty(version, "Cannot get major Minecraft version from null or empty string"); // getVersion() @@ -1635,10 +1786,11 @@ public enum XMaterial { * @see #isDamageable() * @since 1.0.0 */ - public static boolean isDamageable(@Nonnull String name) { + public static boolean isDamageable(@NotNull String name) { Objects.requireNonNull(name, "Material name cannot be null"); - for (String damageable : DAMAGEABLE) + for (String damageable : DAMAGEABLE) { if (name.contains(damageable)) return true; + } return false; } @@ -1678,32 +1830,31 @@ public enum XMaterial { *

* Want to learn RegEx? You can mess around in RegExr website. * - * @param material the base material to match other materials with. * @param materials the material names to check base material on. * @return true if one of the given material names is similar to the base material. * @since 3.1.1 */ - public static boolean isOneOf(@Nonnull Material material, @Nullable List materials) { + public boolean isOneOf(@Nullable Collection materials) { if (materials == null || materials.isEmpty()) return false; - Objects.requireNonNull(material, "Cannot match materials with a null material"); - String name = material.name(); + String name = this.name(); for (String comp : materials) { - comp = comp.toUpperCase(); - if (comp.startsWith("CONTAINS:")) { - comp = format(comp.substring(9)); + String checker = comp.toUpperCase(Locale.ENGLISH); + if (checker.startsWith("CONTAINS:")) { + comp = format(checker.substring(9)); if (name.contains(comp)) return true; continue; } - if (comp.startsWith("REGEX:")) { + if (checker.startsWith("REGEX:")) { comp = comp.substring(6); - if (name.matches(comp)) return true; + Pattern pattern = CACHED_REGEX.getUnchecked(comp); + if (pattern != null && pattern.matcher(name).matches()) return true; continue; } // Direct Object Equals - Optional mat = matchXMaterial(comp); - if (mat.isPresent() && mat.get().parseMaterial() == material) return true; + Optional xMat = matchXMaterial(comp); + if (xMat.isPresent() && xMat.get() == this) return true; } return false; } @@ -1733,31 +1884,18 @@ public enum XMaterial { * @see #parseItem() * @since 3.0.0 */ - @Nonnull + @NotNull @SuppressWarnings("deprecation") - public ItemStack setType(@Nonnull ItemStack item) { + public ItemStack setType(@NotNull ItemStack item) { Objects.requireNonNull(item, "Cannot set material for null ItemStack"); + Material material = this.parseMaterial(); + Validate.isTrue(material != null, "Unsupported material: " + this.name()); - item.setType(this.parseMaterial()); + item.setType(material); if (!ISFLAT && !this.isDamageable()) item.setDurability(this.data); return item; } - /** - * Checks if the list of given material names matches the given base material. - * Mostly used for configs. - * - * @param materials the material names to check base material on. - * @return true if one of the given material names is similar to the base material. - * @see #isOneOf(Material, List) - * @since 3.0.0 - */ - public boolean isOneOf(@Nullable List materials) { - Material material = this.parseMaterial(); - if (material == null) return false; - return isOneOf(material, materials); - } - /** * Checks if the given string matches any of this material's legacy material names. * All the values passed to this method will not be null or empty and are formatted correctly. @@ -1766,7 +1904,7 @@ public enum XMaterial { * @return true if it's one of the legacy names. * @since 2.0.0 */ - private boolean anyMatchLegacy(@Nonnull String name) { + private boolean anyMatchLegacy(@NotNull String name) { for (String legacy : this.legacy) { if (legacy.isEmpty()) break; // Left-side suggestion list if (name.equals(legacy)) return true; @@ -1798,14 +1936,13 @@ public enum XMaterial { public int getId() { if (this.data != 0 || (this.legacy.length != 0 && Integer.parseInt(this.legacy[0].substring(2)) >= 13)) return -1; Material material = this.parseMaterial(); - return material == null ? -1 : material.getId(); + return material.getId(); } /** * Checks if the material has any duplicates. * * @return true if there is a duplicated name for this material, otherwise false. - * @see #getXMaterialIfDuplicated() * @see #isDuplicated(String) * @since 2.0.0 */ @@ -1813,19 +1950,6 @@ public enum XMaterial { return DUPLICATED.containsKey(this); } - /** - * Checks if the item is duplicated for a different purpose in new versions. - * - * @return true if the item's name is duplicated, otherwise false. - * @see #isDuplicated() - * @see #getNewXMaterialIfDuplicated(String) - * @since 2.0.0 - */ - @Nullable - public XMaterial getXMaterialIfDuplicated() { - return DUPLICATED.get(this); - } - /** * Checks if the material can be damaged by using it. * Names going through this method are not formatted. @@ -1860,7 +1984,7 @@ public enum XMaterial { * @return a list of legacy material names and the first element as the version the material was added in if new. * @since 1.0.0 */ - @Nonnull + @NotNull public String[] getLegacy() { return legacy; } @@ -1913,7 +2037,6 @@ public enum XMaterial { * * @param suggest use a suggested material (from older materials) if the material is added in a later version of Minecraft. * @return the material related to this XMaterial based on the server version. - * @see #matchXMaterial(String, byte) * @since 2.0.0 */ @SuppressWarnings("OptionalAssignedToNull") @@ -1929,7 +2052,8 @@ public enum XMaterial { if (mat == null) mat = requestOldMaterial(suggest); } - if (mat != null) PARSED_CACHE.put(this, Optional.ofNullable(mat)); + Optional opt = Optional.ofNullable(mat); + PARSED_CACHE.put(this, opt); return mat; } @@ -1973,7 +2097,7 @@ public enum XMaterial { * @since 1.0.0 */ @SuppressWarnings("deprecation") - public boolean isSimilar(@Nonnull ItemStack item) { + public boolean isSimilar(@NotNull ItemStack item) { Objects.requireNonNull(item, "Cannot compare with null ItemStack"); if (item.getType() != this.parseMaterial()) return false; return ISFLAT || this.isDamageable() || item.getDurability() == this.data; @@ -1987,7 +2111,7 @@ public enum XMaterial { * @see #parseMaterial(boolean) * @since 2.0.0 */ - @Nonnull + @NotNull public List getSuggestions() { if (this.legacy.length == 0 || this.legacy[0].charAt(1) != '.') return new ArrayList<>(); List suggestions = new ArrayList<>();