matchXMaterial(int id, byte data) {
- if (id < 0 || id > MAX_ID || data < 0) return Optional.empty();
- for (XMaterial materials : VALUES) {
- if (materials.data == data && materials.getId() == id) return Optional.of(materials);
- }
- return Optional.empty();
- }
-
/**
* The main method that parses the given material name and data value as an XMaterial.
* All the values passed to this method will not be null or empty and are formatted correctly.
@@ -1966,7 +1962,6 @@ public enum XMaterial {
* @param data the data value of the material. Is always 0 or {@link #UNKNOWN_DATA_VALUE} when {@link Data#ISFLAT}
* @return an XMaterial (with the same data value if specified)
* @see #matchXMaterial(Material)
- * @see #matchXMaterial(int, byte)
* @see #matchXMaterial(ItemStack)
* @since 3.0.0
*/
@@ -2053,12 +2048,14 @@ public enum XMaterial {
}
/**
+ * This is an internal API. Use {@link com.cryptomorin.xseries.reflection.XReflection#supports(int)} instead.
* Checks if the specified version is the same version or higher than the current server version.
*
* @param version the major version to be checked. "1." is ignored. E.g. 1.12 = 12 | 1.9 = 9
* @return true of the version is equal or higher than the current version.
* @since 2.0.0
*/
+ @ApiStatus.Internal
public static boolean supports(int version) {
return Data.VERSION >= version;
}
@@ -2067,78 +2064,6 @@ public enum XMaterial {
return this.legacy;
}
- /**
- * Checks if the list of given material names matches the given base material.
- * Mostly used for configs.
- *
- * Supports {@link String#contains} {@code CONTAINS:NAME} and Regular Expression {@code REGEX:PATTERN} formats.
- *
- * Example:
- *
- * XMaterial material = {@link #matchXMaterial(ItemStack)};
- * if (material.isOneOf(plugin.getConfig().getStringList("disabled-items")) return;
- *
- *
- * {@code CONTAINS} Examples:
- *
- * {@code "CONTAINS:CHEST" -> CHEST, ENDERCHEST, TRAPPED_CHEST -> true}
- * {@code "cOnTaINS:dYe" -> GREEN_DYE, YELLOW_DYE, BLUE_DYE, INK_SACK -> true}
- *
- *
- * {@code REGEX} Examples
- *
- * {@code "REGEX:^.+_.+_.+$" -> Every Material with 3 underlines or more: SHULKER_SPAWN_EGG, SILVERFISH_SPAWN_EGG, SKELETON_HORSE_SPAWN_EGG}
- * {@code "REGEX:^.{1,3}$" -> Material names that have 3 letters only: BED, MAP, AIR}
- *
- *
- * The reason that there are tags for {@code CONTAINS} and {@code REGEX} is for the performance.
- * Although RegEx patterns are cached in this method,
- * please avoid using the {@code REGEX} tag if you can use the {@code CONTAINS} tag instead.
- * It'll have a huge impact on performance.
- * Please avoid using {@code (capturing groups)} there's no use for them in this case.
- * If you want to use groups, use {@code (?: non-capturing groups)}. It's faster.
- *
- * Want to learn RegEx? You can mess around in RegExr website.
- *
- * @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
- * @deprecated Use XTag.stringMatcher() instead.
- */
- @Deprecated
- public boolean isOneOf(@Nullable Collection materials) {
- if (materials == null || materials.isEmpty()) return false;
- String name = this.name();
-
- for (String comp : materials) {
- String checker = comp.toUpperCase(Locale.ENGLISH);
- if (checker.startsWith("CONTAINS:")) {
- comp = format(checker.substring(9));
- if (name.contains(comp)) return true;
- continue;
- }
- if (checker.startsWith("REGEX:")) {
- comp = comp.substring(6);
- Pattern pattern = CACHED_REGEX.getIfPresent(comp);
- if (pattern == null) {
- try {
- pattern = Pattern.compile(comp);
- CACHED_REGEX.put(comp, pattern);
- } catch (PatternSyntaxException ex) {
- ex.printStackTrace();
- }
- }
- if (pattern != null && pattern.matcher(name).matches()) return true;
- continue;
- }
-
- // Direct Object Equals
- Optional xMat = matchXMaterial(comp);
- if (xMat.isPresent() && xMat.get() == this) return true;
- }
- return false;
- }
-
/**
* Sets the {@link Material} (and data value on older versions) of an item.
* Damageable materials will not have their durability changed.
@@ -2209,7 +2134,6 @@ public enum XMaterial {
* Spigot added material ID support back in 1.16+
*
* @return the ID of the material or -1 if it's not a legacy material or the server doesn't support the material.
- * @see #matchXMaterial(int, byte)
* @since 2.2.0
*/
@SuppressWarnings("deprecation")
@@ -2379,6 +2303,7 @@ public enum XMaterial {
*
* @since 9.0.0
*/
+ @ApiStatus.Internal
private static final class Data {
/**
* The current version of the server in the form of a major version.