From fa1de08c0d99c0157f5d27be723f884c800ea22f Mon Sep 17 00:00:00 2001 From: Intelli Date: Tue, 18 Jun 2024 16:04:35 -0600 Subject: [PATCH] Use proper adapter for EntityType.END_CRYSTAL --- .../java/net/coreprotect/bukkit/BukkitAdapter.java | 10 ++++++++++ .../java/net/coreprotect/bukkit/BukkitInterface.java | 2 ++ .../java/net/coreprotect/bukkit/Bukkit_v1_21.java | 11 +++++++++++ .../net/coreprotect/database/rollback/Rollback.java | 9 +-------- 4 files changed, 24 insertions(+), 8 deletions(-) diff --git a/src/main/java/net/coreprotect/bukkit/BukkitAdapter.java b/src/main/java/net/coreprotect/bukkit/BukkitAdapter.java index 59c5878a..db618d5f 100644 --- a/src/main/java/net/coreprotect/bukkit/BukkitAdapter.java +++ b/src/main/java/net/coreprotect/bukkit/BukkitAdapter.java @@ -288,4 +288,14 @@ public ItemStack getArrowMeta(Arrow arrow, ItemStack itemStack) { return itemStack; } + @Override + public EntityType getEntityType(Material material) { + switch (material) { + case END_CRYSTAL: + return EntityType.valueOf("ENDER_CRYSTAL"); + default: + return EntityType.UNKNOWN; + } + } + } diff --git a/src/main/java/net/coreprotect/bukkit/BukkitInterface.java b/src/main/java/net/coreprotect/bukkit/BukkitInterface.java index 48fe07e6..f8dbffab 100644 --- a/src/main/java/net/coreprotect/bukkit/BukkitInterface.java +++ b/src/main/java/net/coreprotect/bukkit/BukkitInterface.java @@ -87,4 +87,6 @@ public interface BukkitInterface { public ItemStack getArrowMeta(Arrow arrow, ItemStack itemStack); + public EntityType getEntityType(Material material); + } diff --git a/src/main/java/net/coreprotect/bukkit/Bukkit_v1_21.java b/src/main/java/net/coreprotect/bukkit/Bukkit_v1_21.java index 4b133b5d..afd53b0c 100644 --- a/src/main/java/net/coreprotect/bukkit/Bukkit_v1_21.java +++ b/src/main/java/net/coreprotect/bukkit/Bukkit_v1_21.java @@ -2,6 +2,7 @@ import org.bukkit.Material; import org.bukkit.Tag; +import org.bukkit.entity.EntityType; import net.coreprotect.model.BlockGroup; @@ -22,4 +23,14 @@ public Bukkit_v1_21() { } } + @Override + public EntityType getEntityType(Material material) { + switch (material) { + case END_CRYSTAL: + return EntityType.valueOf("END_CRYSTAL"); + default: + return EntityType.UNKNOWN; + } + } + } diff --git a/src/main/java/net/coreprotect/database/rollback/Rollback.java b/src/main/java/net/coreprotect/database/rollback/Rollback.java index 7e848722..a15f2397 100644 --- a/src/main/java/net/coreprotect/database/rollback/Rollback.java +++ b/src/main/java/net/coreprotect/database/rollback/Rollback.java @@ -649,14 +649,7 @@ else if ((rowType == Material.END_CRYSTAL)) { } if (!exists) { - EntityType END_CRYSTAL = null; - try { - END_CRYSTAL = EntityType.valueOf("END_CRYSTAL"); // 1.21+ - } - catch (Exception e) { - END_CRYSTAL = EntityType.valueOf("ENDER_CRYSTAL"); // <= 1.20 - } - Entity entity = block.getLocation().getWorld().spawnEntity(location1, END_CRYSTAL); + Entity entity = block.getLocation().getWorld().spawnEntity(location1, BukkitAdapter.ADAPTER.getEntityType(Material.END_CRYSTAL)); EnderCrystal enderCrystal = (EnderCrystal) entity; enderCrystal.setShowingBottom((rowData != 0)); PaperAdapter.ADAPTER.teleportAsync(entity, location1);