3 Commits

Author SHA1 Message Date
eefe17e5f7 Merge pull request 'Use combinedIds to hide in TechHider.iBlockDataHidden' (#35) from hotfix/TechHider into main
All checks were successful
SteamWarCI Build successful
Reviewed-on: #35
Reviewed-by: Chaoscaot <max@chaoscaot.de>
2025-04-05 18:12:54 +02:00
812e78d277 Make it 1.8 compatible
All checks were successful
SteamWarCI Build successful
2025-04-05 18:02:48 +02:00
a6c46d0270 Use combinedIds to hide in TechHider.iBlockDataHidden
All checks were successful
SteamWarCI Build successful
2025-04-04 11:21:54 +02:00
4 changed files with 13 additions and 8 deletions

View File

@ -66,8 +66,8 @@ public class BlockIds14 implements BlockIds {
return getBlock.invoke(null, material); return getBlock.invoke(null, material);
} }
private static final Reflection.Method getCombinedId = Reflection.getTypedMethod(TechHider.block, null, int.class, TechHider.iBlockData); @Override
private int getCombinedId(Object blockData) { public int getCombinedId(Object blockData) {
return (int) getCombinedId.invoke(null, blockData); return (int) getCombinedId.invoke(null, blockData);
} }
} }

View File

@ -25,6 +25,12 @@ import java.util.Collections;
import java.util.Set; import java.util.Set;
public class BlockIds8 implements BlockIds { 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 @Override
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
public int materialToId(Material material) { public int materialToId(Material material) {

View File

@ -19,6 +19,7 @@
package de.steamwar.techhider; package de.steamwar.techhider;
import de.steamwar.Reflection;
import de.steamwar.core.Core; import de.steamwar.core.Core;
import de.steamwar.core.VersionDependent; import de.steamwar.core.VersionDependent;
import org.bukkit.Material; import org.bukkit.Material;
@ -28,6 +29,9 @@ import java.util.Set;
public interface BlockIds { public interface BlockIds {
BlockIds impl = VersionDependent.getVersionImpl(Core.getInstance()); 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); int materialToId(Material material);
Set<Integer> materialToAllIds(Material material); Set<Integer> materialToAllIds(Material material);
} }

View File

@ -49,10 +49,8 @@ public class TechHider {
public static final Class<?> craftMagicNumbers = Reflection.getClass("org.bukkit.craftbukkit.util.CraftMagicNumbers"); 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 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);
public boolean iBlockDataHidden(Object iBlockData) { public boolean iBlockDataHidden(Object iBlockData) {
return obfuscate.contains((Material) getMaterialByBlock.invoke(null, getBlockByBlockData.invoke(iBlockData))); return obfuscateIds.contains(BlockIds.impl.getCombinedId(iBlockData));
} }
public static final Object AIR = getBlockDataByBlock.invoke(getBlockByMaterial.invoke(null, Material.AIR)); public static final Object AIR = getBlockDataByBlock.invoke(getBlockByMaterial.invoke(null, Material.AIR));
@ -66,15 +64,12 @@ public class TechHider {
@Getter @Getter
private final int obfuscationTargetId; private final int obfuscationTargetId;
@Getter @Getter
private final Set<Material> obfuscate;
@Getter
private final Set<Integer> obfuscateIds; private final Set<Integer> obfuscateIds;
@Getter @Getter
private final Set<String> hiddenBlockEntities; private final Set<String> hiddenBlockEntities;
public TechHider(LocationEvaluator locationEvaluator, Material obfuscationTarget, Set<Material> obfuscate, Set<String> hiddenBlockEntities) { public TechHider(LocationEvaluator locationEvaluator, Material obfuscationTarget, Set<Material> obfuscate, Set<String> hiddenBlockEntities) {
this.locationEvaluator = locationEvaluator; this.locationEvaluator = locationEvaluator;
this.obfuscate = obfuscate;
this.obfuscateIds = obfuscate.stream().flatMap(m -> BlockIds.impl.materialToAllIds(m).stream()).collect(Collectors.toSet()); this.obfuscateIds = obfuscate.stream().flatMap(m -> BlockIds.impl.materialToAllIds(m).stream()).collect(Collectors.toSet());
this.hiddenBlockEntities = hiddenBlockEntities; this.hiddenBlockEntities = hiddenBlockEntities;
this.obfuscationTarget = getBlockDataByBlock.invoke(getBlockByMaterial.invoke(null, obfuscationTarget)); this.obfuscationTarget = getBlockDataByBlock.invoke(getBlockByMaterial.invoke(null, obfuscationTarget));