From a6c46d02708540788e569d73274290e58013d41c Mon Sep 17 00:00:00 2001 From: YoyoNow Date: Fri, 4 Apr 2025 11:21:54 +0200 Subject: [PATCH 1/2] Use combinedIds to hide in TechHider.iBlockDataHidden --- .../src/de/steamwar/techhider/TechHider.java | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/SpigotCore/SpigotCore_Main/src/de/steamwar/techhider/TechHider.java b/SpigotCore/SpigotCore_Main/src/de/steamwar/techhider/TechHider.java index 03063eb8..3c9e3677 100644 --- a/SpigotCore/SpigotCore_Main/src/de/steamwar/techhider/TechHider.java +++ b/SpigotCore/SpigotCore_Main/src/de/steamwar/techhider/TechHider.java @@ -49,10 +49,9 @@ public class TechHider { public static final Class craftMagicNumbers = Reflection.getClass("org.bukkit.craftbukkit.util.CraftMagicNumbers"); private static final Reflection.Method getBlockByMaterial = Reflection.getTypedMethod(craftMagicNumbers, "getBlock", block, Material.class); - private static final Reflection.Method getBlockByBlockData = Reflection.getTypedMethod(iBlockData, null, block); - private static final Reflection.Method getMaterialByBlock = Reflection.getTypedMethod(craftMagicNumbers, "getMaterial", Material.class, block); + private static final Reflection.Method getCombinedIdByIBlockData = Reflection.getTypedMethod(block, null, int.class, iBlockData); public boolean iBlockDataHidden(Object iBlockData) { - return obfuscate.contains((Material) getMaterialByBlock.invoke(null, getBlockByBlockData.invoke(iBlockData))); + return obfuscateIds.contains(getCombinedIdByIBlockData.invoke(null, iBlockData)); } public static final Object AIR = getBlockDataByBlock.invoke(getBlockByMaterial.invoke(null, Material.AIR)); @@ -66,15 +65,12 @@ public class TechHider { @Getter private final int obfuscationTargetId; @Getter - private final Set obfuscate; - @Getter private final Set obfuscateIds; @Getter private final Set hiddenBlockEntities; public TechHider(LocationEvaluator locationEvaluator, Material obfuscationTarget, Set obfuscate, Set hiddenBlockEntities) { this.locationEvaluator = locationEvaluator; - this.obfuscate = obfuscate; this.obfuscateIds = obfuscate.stream().flatMap(m -> BlockIds.impl.materialToAllIds(m).stream()).collect(Collectors.toSet()); this.hiddenBlockEntities = hiddenBlockEntities; this.obfuscationTarget = getBlockDataByBlock.invoke(getBlockByMaterial.invoke(null, obfuscationTarget)); From 812e78d277f78d086a13787eb57801b6cbcb2859 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Sat, 5 Apr 2025 18:02:48 +0200 Subject: [PATCH 2/2] Make it 1.8 compatible --- .../SpigotCore_14/src/de/steamwar/techhider/BlockIds14.java | 4 ++-- .../SpigotCore_8/src/de/steamwar/techhider/BlockIds8.java | 6 ++++++ .../SpigotCore_Main/src/de/steamwar/techhider/BlockIds.java | 4 ++++ .../src/de/steamwar/techhider/TechHider.java | 3 +-- 4 files changed, 13 insertions(+), 4 deletions(-) diff --git a/SpigotCore/SpigotCore_14/src/de/steamwar/techhider/BlockIds14.java b/SpigotCore/SpigotCore_14/src/de/steamwar/techhider/BlockIds14.java index ebf5e952..6e2c0397 100644 --- a/SpigotCore/SpigotCore_14/src/de/steamwar/techhider/BlockIds14.java +++ b/SpigotCore/SpigotCore_14/src/de/steamwar/techhider/BlockIds14.java @@ -66,8 +66,8 @@ public class BlockIds14 implements BlockIds { return getBlock.invoke(null, material); } - private static final Reflection.Method getCombinedId = Reflection.getTypedMethod(TechHider.block, null, int.class, TechHider.iBlockData); - private int getCombinedId(Object blockData) { + @Override + public int getCombinedId(Object blockData) { return (int) getCombinedId.invoke(null, blockData); } } diff --git a/SpigotCore/SpigotCore_8/src/de/steamwar/techhider/BlockIds8.java b/SpigotCore/SpigotCore_8/src/de/steamwar/techhider/BlockIds8.java index 538e8dbd..64ac6c41 100644 --- a/SpigotCore/SpigotCore_8/src/de/steamwar/techhider/BlockIds8.java +++ b/SpigotCore/SpigotCore_8/src/de/steamwar/techhider/BlockIds8.java @@ -25,6 +25,12 @@ import java.util.Collections; import java.util.Set; public class BlockIds8 implements BlockIds { + @Override + public int getCombinedId(Object iBlockData) { + int id = (int) getCombinedId.invoke(null, iBlockData); // blockState << 12 | blockId + return (id & 4095) | (id >> 12); + } + @Override @SuppressWarnings("deprecation") public int materialToId(Material material) { diff --git a/SpigotCore/SpigotCore_Main/src/de/steamwar/techhider/BlockIds.java b/SpigotCore/SpigotCore_Main/src/de/steamwar/techhider/BlockIds.java index 8e129a1d..fa2f7f6e 100644 --- a/SpigotCore/SpigotCore_Main/src/de/steamwar/techhider/BlockIds.java +++ b/SpigotCore/SpigotCore_Main/src/de/steamwar/techhider/BlockIds.java @@ -19,6 +19,7 @@ package de.steamwar.techhider; +import de.steamwar.Reflection; import de.steamwar.core.Core; import de.steamwar.core.VersionDependent; import org.bukkit.Material; @@ -28,6 +29,9 @@ import java.util.Set; public interface BlockIds { BlockIds impl = VersionDependent.getVersionImpl(Core.getInstance()); + Reflection.Method getCombinedId = Reflection.getTypedMethod(TechHider.block, null, int.class, TechHider.iBlockData); + + int getCombinedId(Object iBlockData); int materialToId(Material material); Set materialToAllIds(Material material); } diff --git a/SpigotCore/SpigotCore_Main/src/de/steamwar/techhider/TechHider.java b/SpigotCore/SpigotCore_Main/src/de/steamwar/techhider/TechHider.java index 3c9e3677..021d2fe4 100644 --- a/SpigotCore/SpigotCore_Main/src/de/steamwar/techhider/TechHider.java +++ b/SpigotCore/SpigotCore_Main/src/de/steamwar/techhider/TechHider.java @@ -49,9 +49,8 @@ public class TechHider { public static final Class craftMagicNumbers = Reflection.getClass("org.bukkit.craftbukkit.util.CraftMagicNumbers"); private static final Reflection.Method getBlockByMaterial = Reflection.getTypedMethod(craftMagicNumbers, "getBlock", block, Material.class); - private static final Reflection.Method getCombinedIdByIBlockData = Reflection.getTypedMethod(block, null, int.class, iBlockData); public boolean iBlockDataHidden(Object iBlockData) { - return obfuscateIds.contains(getCombinedIdByIBlockData.invoke(null, iBlockData)); + return obfuscateIds.contains(BlockIds.impl.getCombinedId(iBlockData)); } public static final Object AIR = getBlockDataByBlock.invoke(getBlockByMaterial.invoke(null, Material.AIR));