From 17fb99f3aae987eabf7bfe3798094de7e8eea541 Mon Sep 17 00:00:00 2001 From: crashdemons Date: Wed, 14 Feb 2024 19:03:12 -0600 Subject: [PATCH] add temporary workaround for console spam errors when checking old custom heads without a valid profile. --- .../playerheads/SkullConverter.java | 24 +++++++++++++++++++ .../playerheads/PlayerHeadsListener.java | 6 ++--- 2 files changed, 27 insertions(+), 3 deletions(-) diff --git a/PlayerHeads-core/src/main/java/com/github/crashdemons/playerheads/SkullConverter.java b/PlayerHeads-core/src/main/java/com/github/crashdemons/playerheads/SkullConverter.java index 9dad36be..8e49bdfb 100644 --- a/PlayerHeads-core/src/main/java/com/github/crashdemons/playerheads/SkullConverter.java +++ b/PlayerHeads-core/src/main/java/com/github/crashdemons/playerheads/SkullConverter.java @@ -14,6 +14,8 @@ import org.bukkit.entity.EntityType; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.SkullMeta; +import org.bukkit.plugin.PluginLogger; +import org.shininet.bukkit.playerheads.PlayerHeads; /** * Abstract class defining methods for converting between entities, custom skullState type, and legacy username-skulls, etc. @@ -92,6 +94,28 @@ public static TexturedSkullType skullTypeFromItemStack(ItemStack stack, boolean return determineSkullType(op,skullState,filterCustomPlayerHeads,filterBlockedHeads); } + + @Deprecated + public static TexturedSkullType skullTypeFromItemStack_NoException(ItemStack stack, boolean filterCustomPlayerHeads, boolean filterBlockedHeads){ + TexturedSkullType skullType = null; + try{ //FIXME: Temporary workaround! + skullType = SkullConverter.skullTypeFromItemStack(stack,filterCustomPlayerHeads,filterBlockedHeads); + }catch (IllegalArgumentException e){ + PlayerHeads.instance.getLogger().warning("Ignoring unsupported legacy head profile from custom head: "+e.getMessage()); + } + return skullType; + } + + @Deprecated + public static TexturedSkullType skullTypeFromBlockState_NoException(BlockState state, boolean filterCustomPlayerHeads, boolean filterBlockedHeads){ + TexturedSkullType skullType = null; + try{ //FIXME: Temporary workaround! + skullType = SkullConverter.skullTypeFromBlockState(state,filterCustomPlayerHeads,filterBlockedHeads); + }catch (IllegalArgumentException e){ + PlayerHeads.instance.getLogger().warning("Ignoring unsupported legacy head profile from custom head: "+e.getMessage()); + } + return skullType; + } diff --git a/PlayerHeads-core/src/main/java/org/shininet/bukkit/playerheads/PlayerHeadsListener.java b/PlayerHeads-core/src/main/java/org/shininet/bukkit/playerheads/PlayerHeadsListener.java index 5d2c6fc7..db511dc4 100644 --- a/PlayerHeads-core/src/main/java/org/shininet/bukkit/playerheads/PlayerHeadsListener.java +++ b/PlayerHeads-core/src/main/java/org/shininet/bukkit/playerheads/PlayerHeadsListener.java @@ -689,7 +689,7 @@ public void onItemSpawnEvent(ItemSpawnEvent event) { if (!fixDroppedHeads) { return; } - TexturedSkullType skullType = SkullConverter.skullTypeFromItemStack(stack,true,true); + TexturedSkullType skullType = SkullConverter.skullTypeFromItemStack_NoException(stack,true,true); if (skullType == null) { return; } @@ -753,7 +753,7 @@ private ItemStack createConvertedMobhead(TexturedSkullType skullType, boolean is //NOTE: the blockbreak handler expects this to unconditionally drop the item unless the new event is cancelled. private BlockDropResult blockDrop(BlockEvent event, Block block, BlockState state, CompatibleProfile oldProfile) { if(CompatiblePlugins.heads.getExternalHeadHandling(state)==HeadModificationHandling.NO_INTERACTION) return BlockDropResult.FAILED_BLOCKED_HEAD;//TODO: redundant code - SkullConverter checks custom & external heads now - TexturedSkullType skullType = SkullConverter.skullTypeFromBlockState(state,true,true); + TexturedSkullType skullType = SkullConverter.skullTypeFromBlockState_NoException(state,true,true); if(skullType==null) return BlockDropResult.FAILED_BLOCKED_HEAD; Location location = block.getLocation(); ItemStack item = null; @@ -807,7 +807,7 @@ public void onBlockBreak(BlockBreakEvent event) { if(CompatiblePlugins.heads.getExternalHeadHandling(block.getState())==HeadModificationHandling.NO_INTERACTION) return;//TODO: redundant code - SkullConverter checks custom & external heads now if (player.getGameMode() != GameMode.CREATIVE) { BlockState state = block.getState(); - TexturedSkullType skullType = SkullConverter.skullTypeFromBlockState(state,true,true); + TexturedSkullType skullType = SkullConverter.skullTypeFromBlockState_NoException(state,true,true); if (skullType != null) { boolean canBreak = true;