Fixed NoSuchMethodError for arrows on MC 1.20/1.20.1

This commit is contained in:
Intelli 2024-05-09 12:25:57 -06:00
parent 86ace6c326
commit 48d2030766

View File

@ -24,6 +24,7 @@ import net.coreprotect.model.BlockGroup;
public class Bukkit_v1_20 extends Bukkit_v1_19 implements BukkitInterface {
private Boolean hasClickedPosition = null;
private Boolean hasBasePotionType = null;
public Bukkit_v1_20() {
BlockGroup.CONTAINERS = new HashSet<>(Arrays.asList(Material.JUKEBOX, Material.DISPENSER, Material.CHEST, Material.FURNACE, Material.BREWING_STAND, Material.TRAPPED_CHEST, Material.HOPPER, Material.DROPPER, Material.ARMOR_STAND, Material.ITEM_FRAME, Material.SHULKER_BOX, Material.BLACK_SHULKER_BOX, Material.BLUE_SHULKER_BOX, Material.BROWN_SHULKER_BOX, Material.CYAN_SHULKER_BOX, Material.GRAY_SHULKER_BOX, Material.GREEN_SHULKER_BOX, Material.LIGHT_BLUE_SHULKER_BOX, Material.LIME_SHULKER_BOX, Material.MAGENTA_SHULKER_BOX, Material.ORANGE_SHULKER_BOX, Material.PINK_SHULKER_BOX, Material.PURPLE_SHULKER_BOX, Material.RED_SHULKER_BOX, Material.LIGHT_GRAY_SHULKER_BOX, Material.WHITE_SHULKER_BOX, Material.YELLOW_SHULKER_BOX, Material.BARREL, Material.BLAST_FURNACE, Material.SMOKER, Material.LECTERN, Material.CHISELED_BOOKSHELF, Material.DECORATED_POT));
@ -260,6 +261,15 @@ public class Bukkit_v1_20 extends Bukkit_v1_19 implements BukkitInterface {
@Override
public ItemStack getArrowMeta(Arrow arrow, ItemStack itemStack) {
try {
if (hasBasePotionType == null) {
hasBasePotionType = true;
Arrow.class.getMethod("getBasePotionType"); // Bukkit 1.20.2+
}
else if (Boolean.FALSE.equals(hasBasePotionType)) {
return super.getArrowMeta(arrow, itemStack);
}
PotionType potionType = arrow.getBasePotionType();
Color color = arrow.getColor();
if (potionType != null || color != null) {
@ -275,5 +285,10 @@ public class Bukkit_v1_20 extends Bukkit_v1_19 implements BukkitInterface {
return itemStack;
}
catch (Exception e) {
hasBasePotionType = false;
return super.getArrowMeta(arrow, itemStack);
}
}
}