Skip to content

Commit

Permalink
Make FCInputReader::parseMaterial parse materials from NumericID as well
Browse files Browse the repository at this point in the history
  • Loading branch information
EverNife committed Jun 30, 2024
1 parent 9cb4c67 commit ae8097f
Showing 1 changed file with 19 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package br.com.finalcraft.evernifecore.util;

import br.com.finalcraft.evernifecore.reflection.MethodInvoker;
import br.com.finalcraft.evernifecore.version.MCVersion;
import org.bukkit.Material;

Expand Down Expand Up @@ -31,11 +32,29 @@ public static Double parseDouble(String input){
return parseDouble(input, null);
}

private static MethodInvoker<Material> getMaterialByNumericID = null; static {
try {
getMaterialByNumericID = FCReflectionUtil.getMethod(Material.class, "getMaterial", int.class);
}catch (Throwable ignored){

}
}

public static Material parseMaterial(String materialName) {
if (materialName == null || materialName.isEmpty()){
return null;
}

Material material = Material.matchMaterial(materialName);
if (material == null) {
if (MCVersion.isHigherEquals(MCVersion.v1_13)){
material = Material.matchMaterial(materialName, true);
}else if (getMaterialByNumericID != null && Character.isDigit(materialName.charAt(0))) {
//On legacy, check if it's a numeric Material ID
Integer numericID = FCInputReader.parseInt(materialName);
if (numericID != null && numericID >= 0){
material = getMaterialByNumericID.invoke(null, numericID);
}
}
}
return material;
Expand Down

0 comments on commit ae8097f

Please sign in to comment.