From 26ccf98d44b8d35d937a8b4203408ee281d3c774 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Mon, 24 May 2021 15:23:35 +0200 Subject: [PATCH] WIP Signed-off-by: Lixfel --- .../fightsystem/commands/RemoveCommand.java | 2 +- .../fightsystem/record/PacketProcessor.java | 72 ++-- .../steamwar/fightsystem/record/REntity.java | 347 ++++++++++++++++++ .../fightsystem/record/RecordSystem.java | 2 +- .../steamwar/fightsystem/utils/TechHider.java | 32 +- 5 files changed, 403 insertions(+), 52 deletions(-) create mode 100644 FightSystem_Main/src/de/steamwar/fightsystem/record/REntity.java diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/commands/RemoveCommand.java b/FightSystem_Main/src/de/steamwar/fightsystem/commands/RemoveCommand.java index 29ba6d2..b538532 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/commands/RemoveCommand.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/commands/RemoveCommand.java @@ -30,7 +30,7 @@ import org.bukkit.entity.Player; public class RemoveCommand implements CommandExecutor { public RemoveCommand() { - new StateDependentCommand(ArenaMode.VariableTeams, FightState.Setup, "remove", this); + new StateDependentCommand(ArenaMode.VariableTeams, FightState.Setup, "die", this); } @Override diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/record/PacketProcessor.java b/FightSystem_Main/src/de/steamwar/fightsystem/record/PacketProcessor.java index c7fdf23..50685e4 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/record/PacketProcessor.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/record/PacketProcessor.java @@ -19,36 +19,37 @@ package de.steamwar.fightsystem.record; -import com.sk89q.worldedit.EditSession; import de.steamwar.fightsystem.Config; import de.steamwar.fightsystem.FightSystem; -import de.steamwar.fightsystem.utils.ColorConverter; -import de.steamwar.sql.NoClipboardException; +import de.steamwar.fightsystem.fight.Fight; +import de.steamwar.fightsystem.fight.FightTeam; +import de.steamwar.fightsystem.utils.TechHider; import de.steamwar.sql.Schematic; import de.steamwar.sql.SteamwarUser; import net.md_5.bungee.api.ChatMessageType; import net.md_5.bungee.api.chat.BaseComponent; import net.md_5.bungee.api.chat.TextComponent; import org.bukkit.*; +import org.bukkit.entity.EntityType; import org.bukkit.entity.Player; import org.bukkit.scheduler.BukkitTask; import java.io.EOFException; import java.io.IOException; -import java.util.HashMap; import java.util.LinkedList; -import java.util.Map; import java.util.Objects; +import java.util.Set; import java.util.logging.Level; class PacketProcessor { private static final World world = Bukkit.getWorlds().get(0); - private final Map packetCounter = new HashMap<>(); private final PacketSource source; private final BukkitTask task; private final LinkedList syncList = new LinkedList<>(); + private final Set hiddenBlockIds = TechHider.getHiddenBlockIds(); + private final int obfuscateWith = TechHider.getObfuscateWith(); public PacketProcessor(PacketSource source){ @@ -103,13 +104,13 @@ class PacketProcessor { float yaw = source.rFloat(); byte headYaw = source.rByte(); - execSync(() -> REntity.getEntity(entityId).move(locX, locY, locZ, yaw, pitch, headYaw)); + execSync(() -> REntity.getEntity(entityId).move(locX, locY, locZ, pitch, yaw, headYaw)); } private void entityDespawns() throws IOException { int entityId = source.rInt(); - execSync(() -> REntity.getEntity(entityId).remove()); + execSync(() -> REntity.getEntity(entityId).die()); } private void entitySneak() throws IOException { @@ -129,7 +130,7 @@ class PacketProcessor { private void tntSpawn() throws IOException { int entityId = source.rInt(); - execSync(() -> new RTnT(entityId)); + execSync(() -> new REntity(entityId, EntityType.PRIMED_TNT)); } private void entityVelocity() throws IOException { @@ -142,7 +143,7 @@ class PacketProcessor { execSync(() -> { REntity entity = REntity.getEntity(entityId); if(entity != null) - entity.setMotion(dX, dY, dZ); + entity.setVelocity(dX, dY, dZ); }); } @@ -152,19 +153,19 @@ class PacketProcessor { boolean enchanted = source.rBoolean(); String slot = source.rString(); - execSync(() -> ((RPlayer)REntity.getEntity(entityId)).setItem(item, enchanted, slot)); + execSync(() -> REntity.getEntity(entityId).setItem(item, enchanted, slot)); } private void arrowSpawn() throws IOException { int entityId = source.rInt(); - execSync(() -> new RArrow(entityId)); + execSync(() -> new REntity(entityId, EntityType.ARROW)); } private void fireballSpawn() throws IOException { int entityId = source.rInt(); - execSync(() -> new RFireball(entityId)); + execSync(() -> new REntity(entityId, EntityType.FIREBALL)); } private void send(ChatMessageType type) throws IOException { @@ -196,8 +197,8 @@ class PacketProcessor { if(!Config.ArenaRegion.in2dRegion(x, z)) return; //Outside of the arena - if (!InspectCommand.inspecting && Config.TechhiderActive && Config.HiddenBlocks.contains(blockState)) { - blockState = Config.ObfuscateWith; + if (TechHider.ENABLED && hiddenBlockIds.contains(blockState)) { + blockState = obfuscateWith; } IBlockData blockData = Objects.requireNonNull(Block.REGISTRY_ID.fromId(blockState)); execSync(() -> { @@ -251,19 +252,10 @@ class PacketProcessor { }); } - private void pasteSchem(int pasteX, int cornerY, int pasteZ, int cornerX, int cornerZ, boolean rotate, String prefix) throws IOException { + private void pasteSchem(FightTeam team) throws IOException { int schemId = source.rInt(); - Schematic schem = Schematic.getSchemFromDB(schemId); - DyeColor c = ColorConverter.chat2dye(ChatColor.getByChar(ChatColor.getLastColors(prefix).replace("§", ""))); - execSync(() -> { - try { - EditSession e = Paster.pasteSchematic(schem, pasteX, cornerY, pasteZ, rotate); - Paster.replaceTeamColor(e, c, cornerX, cornerY, cornerZ); - } catch (NoClipboardException | IOException e) { - throw new SecurityException("Could not load Clipboard", e); - } - }); + execSync(() -> team.pasteSchem(Schematic.getSchemFromDB(schemId))); } private void teams() throws IOException { @@ -287,18 +279,17 @@ class PacketProcessor { } private void endSpectating(){ + REntity.dieAll(); WorldLoader.reloadWorld(); SpectateSystem.getScoreboard().setTitle("§eKein Kampf"); - - for(Map.Entry entry : packetCounter.entrySet()){ - System.out.println(Integer.toHexString(entry.getKey()) + " " + entry.getValue()); - } - - packetCounter.clear(); } - private void bow() { - //TODO implement Bow + private void bow() throws IOException { + int entityId = source.rInt(); + boolean drawn = source.rBoolean(); + boolean offHand = source.rBoolean(); + + execSync(() -> REntity.getEntity(entityId).setBowDrawn(drawn, offHand)); } private void damage() throws IOException { @@ -309,8 +300,9 @@ class PacketProcessor { private void fireTick() throws IOException { int entityId = source.rInt(); + boolean perma = source.rBoolean(); - execSync(() -> REntity.getEntity(entityId).setOnFire()); + execSync(() -> REntity.getEntity(entityId).setOnFire(perma)); } private void process(){ @@ -319,7 +311,6 @@ class PacketProcessor { boolean tickFinished = false; while(!source.isClosed() && !tickFinished){ byte packetType = source.rByte(); - packetCounter.compute(packetType, (key, value) -> value != null ? value + 1 : 1); switch(packetType){ case 0x00: playerJoins(); @@ -352,10 +343,14 @@ class PacketProcessor { fireballSpawn(); break; case 0x0A: + bow(); + break; case 0x0B: damage(); + break; case 0x0C: fireTick(); + break; case 0x30: block(); break; @@ -381,10 +376,10 @@ class PacketProcessor { send(ChatMessageType.SYSTEM); break; case (byte) 0xB0: - pasteSchem(Config.TeamBluePasteX, Config.TeamBlueCornerY, Config.TeamBluePasteZ, Config.TeamBlueCornerX, Config.TeamBlueCornerZ, Config.TeamBlueRotate, Config.TeamBluePrefix); + pasteSchem(Fight.getBlueTeam()); break; case (byte) 0xB1: - pasteSchem(Config.TeamRedPasteX, Config.TeamRedCornerY, Config.TeamRedPasteZ, Config.TeamRedCornerX, Config.TeamRedCornerZ, Config.TeamRedRotate, Config.TeamRedPrefix); + pasteSchem(Fight.getRedTeam()); break; case (byte) 0xB2: teams(); @@ -401,6 +396,7 @@ class PacketProcessor { break; case (byte) 0xFF: //Tick + execSync(REntity::tickFire); if(!source.async()) tickFinished = true; break; diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/record/REntity.java b/FightSystem_Main/src/de/steamwar/fightsystem/record/REntity.java new file mode 100644 index 0000000..9b8df3d --- /dev/null +++ b/FightSystem_Main/src/de/steamwar/fightsystem/record/REntity.java @@ -0,0 +1,347 @@ +package de.steamwar.fightsystem.record; + +import com.comphenix.protocol.PacketType; +import com.comphenix.protocol.ProtocolLibrary; +import com.comphenix.protocol.events.PacketContainer; +import com.comphenix.protocol.reflect.StructureModifier; +import com.comphenix.protocol.wrappers.*; +import de.steamwar.core.Core; +import de.steamwar.sql.SteamwarUser; +import net.royawesome.jlibnoise.MathHelper; +import org.bukkit.Bukkit; +import org.bukkit.Material; +import org.bukkit.OfflinePlayer; +import org.bukkit.enchantments.Enchantment; +import org.bukkit.entity.EntityType; +import org.bukkit.entity.Player; +import org.bukkit.inventory.ItemStack; +import org.bukkit.scoreboard.NameTagVisibility; +import org.bukkit.scoreboard.Team; + +import java.util.*; + +public class REntity { + + private static final Map entities = new HashMap<>(); + + public static REntity getEntity(int internalId){ + return entities.get(internalId); + } + + public static void tickFire() { + entities.forEach((integer, entity) -> { + if(entity.fireTick > 0) { + entity.fireTick--; + if(entity.fireTick == 0) { + //TODO + /*DataWatcher dataWatcher = new DataWatcher(null); + + DataWatcherObject dataWatcherObject = new DataWatcherObject<>(0, DataWatcherRegistry.a); + dataWatcher.register(dataWatcherObject, (byte) 0); + dataWatcher.markDirty(dataWatcherObject); + entity.sendDataWatcher(dataWatcher);*/ + } + } + }); + } + + public static void playerJoins(Player player){ + /*for(REntity entity : entities.values()){ + entity.sendToPlayer(player); + entity.sendLocation(player); + if(entity.fireTick != 0) { + DataWatcher dataWatcher = new DataWatcher(null); + + DataWatcherObject dataWatcherObject = new DataWatcherObject<>(0, DataWatcherRegistry.a); + dataWatcher.register(dataWatcherObject, (byte) 1); + dataWatcher.markDirty(dataWatcherObject); + entity.sendDataWatcher(dataWatcher); + } + if(entity.sneaks) { + DataWatcher dataWatcher = new DataWatcher(null); + + DataWatcherObject dataWatcherObject = new DataWatcherObject<>(6, DataWatcherRegistry.s); + dataWatcher.register(dataWatcherObject, EntityPose.CROUCHING); + dataWatcher.markDirty(dataWatcherObject); + entity.sendDataWatcher(dataWatcher); + } + }*/ + } + + public static void dieAll(){ + entities.forEach((id, entity) -> entity.broadcastDeath()); + entities.clear(); + } + + private static final Team team; + + static { + if(Bukkit.getScoreboardManager().getMainScoreboard().getTeam("Replay") == null) + team = Bukkit.getScoreboardManager().getMainScoreboard().registerNewTeam("Replay"); + else + team = Bukkit.getScoreboardManager().getMainScoreboard().getTeam("Replay"); + team.setNameTagVisibility(NameTagVisibility.NEVER); + } + + private static int entityCount = Integer.MAX_VALUE; + private static final Random random = new Random(); + + private final int internalId, entityId; + private final UUID uuid; + private final EntityType entityType; + private final PlayerInfoData playerInfoData; + private final Map itemSlots = new HashMap<>(); + + private double locX, locY, locZ; + private byte yaw, pitch, headYaw; + private int fireTick; + private boolean sneaks; + + public REntity(int internalId, int userId){ + this.internalId = internalId; + this.entityType = EntityType.PLAYER; + this.entityId = entityCount--; + + SteamwarUser user = SteamwarUser.get(userId); + this.uuid = user.getUUID(); + this.playerInfoData = new PlayerInfoData(WrappedGameProfile.fromOfflinePlayer(Bukkit.getOfflinePlayer(uuid)), 0, EnumWrappers.NativeGameMode.SURVIVAL, WrappedChatComponent.fromText(user.getUserName())); + entities.put(internalId, this); + + //TODO: Spawn him! + } + + public REntity(int internalId, EntityType entityType){ + this.internalId = internalId; + this.entityType = entityType; + this.entityId = entityCount--; + this.playerInfoData = null; + this.uuid = new UUID(random.nextLong() & -61441L | 16384L, random.nextLong() & 4611686018427387903L | -9223372036854775808L); + entities.put(internalId, this); + + ProtocolLibrary.getProtocolManager().broadcastServerPacket(getSpawnEntityPacket()); + } + + public void move(double locX, double locY, double locZ, float pitch, float yaw, byte headYaw){ + this.locX = locX; + this.locY = locY; + this.locZ = locZ; + this.yaw = (byte)((int)(yaw * 256.0F / 360.0F)); + this.pitch = (byte)((int)(pitch * 256.0F / 360.0F)); + this.headYaw = headYaw; + ProtocolLibrary.getProtocolManager().broadcastServerPacket(getTeleportPacket()); + ProtocolLibrary.getProtocolManager().broadcastServerPacket(getHeadRotationPacket()); + } + + public void animation(byte animation) { + PacketContainer animationPacket = ProtocolLibrary.getProtocolManager().createPacket(PacketType.Play.Server.ANIMATION); + StructureModifier ints = animationPacket.getIntegers(); + ints.write(0, entityId); + ints.write(1, (int) animation); + ProtocolLibrary.getProtocolManager().broadcastServerPacket(animationPacket); + } + + public void setVelocity(double dX, double dY, double dZ) { + PacketContainer velocityPacket = ProtocolLibrary.getProtocolManager().createPacket(PacketType.Play.Server.ENTITY_VELOCITY); + StructureModifier ints = velocityPacket.getIntegers(); + ints.write(0, entityId); + ints.write(1, calcVelocity(dX)); + ints.write(2, calcVelocity(dY)); + ints.write(3, calcVelocity(dZ)); + ProtocolLibrary.getProtocolManager().broadcastServerPacket(velocityPacket); + } + + public void damage() { + PacketContainer statusPacket = ProtocolLibrary.getProtocolManager().createPacket(PacketType.Play.Server.ENTITY_STATUS); + statusPacket.getIntegers().write(0, entityId); + statusPacket.getBytes().write(0, (byte) 2); + ProtocolLibrary.getProtocolManager().broadcastServerPacket(statusPacket); + } + + public void sneak(boolean sneaking) { + sneaks = sneaking; + /* + DataWatcher dataWatcher = new DataWatcher(null); + + DataWatcherObject dataWatcherObject = new DataWatcherObject<>(6, DataWatcherRegistry.s); + dataWatcher.register(dataWatcherObject, sneaking?EntityPose.CROUCHING:EntityPose.STANDING); + dataWatcher.markDirty(dataWatcherObject); + + sendDataWatcher(dataWatcher);*/ + } + + public void setOnFire(boolean perma) { + if(!perma) { + fireTick = 21; + } else { + fireTick = -1; + } + + /*DataWatcher dataWatcher = new DataWatcher(null); + + DataWatcherObject dataWatcherObject = new DataWatcherObject<>(0, DataWatcherRegistry.a); + dataWatcher.register(dataWatcherObject, (byte) 1); + dataWatcher.markDirty(dataWatcherObject); + + sendDataWatcher(dataWatcher);*/ + } + + public void setBowDrawn(boolean drawn, boolean offHand) { + /*DataWatcher dataWatcher = new DataWatcher(null); + + DataWatcherObject dataWatcherObject = new DataWatcherObject<>(7, DataWatcherRegistry.a); + dataWatcher.register(dataWatcherObject, (byte) ((drawn ? 1 : 0) + (offHand ? 2 : 0))); + dataWatcher.markDirty(dataWatcherObject); + + sendDataWatcher(dataWatcher); + + private void sendDataWatcher(DataWatcher dataWatcher) { + PacketPlayOutEntityMetadata packet = new PacketPlayOutEntityMetadata(entity.getId(), dataWatcher, false); + + for(Player player : Bukkit.getOnlinePlayers()){ + ((CraftPlayer) player).getHandle().playerConnection.sendPacket(packet); + } + } + */ + } + + public void setItem(String item, boolean enchanted, String slot) { + ItemStack stack = new ItemStack(Material.valueOf(item.replace("minecraft:", "").toUpperCase()), 1); + if(enchanted) + stack.addEnchantment(Enchantment.DURABILITY, 1); + itemSlots.put(slot, stack); + + ProtocolLibrary.getProtocolManager().broadcastServerPacket(getEquipmentPacket(slot, stack)); + } + + public void die(){ + broadcastDeath(); + entities.remove(internalId); + } + + private void broadcastDeath(){ + if(entityType == EntityType.PLAYER){ + PacketContainer infoPacket = ProtocolLibrary.getProtocolManager().createPacket(PacketType.Play.Server.PLAYER_INFO); + infoPacket.getPlayerInfoAction().write(0, EnumWrappers.PlayerInfoAction.REMOVE_PLAYER); + infoPacket.getPlayerInfoDataLists().write(0, Collections.singletonList(new PlayerInfoData())); + ProtocolLibrary.getProtocolManager().broadcastServerPacket(infoPacket); + team.removeEntry(name); + } + + PacketContainer destroyPacket = ProtocolLibrary.getProtocolManager().createPacket(PacketType.Play.Server.ENTITY_DESTROY); + destroyPacket.getIntegerArrays().write(0, new int[]{entityId}); + ProtocolLibrary.getProtocolManager().broadcastServerPacket(destroyPacket); + } + + private int entityTypeToId(){ + //TODO + return 0; + } + + private int calcVelocity(double value) { + return (int)(Math.max(-3.9, Math.min(value, 3.9)) * 8000); + } + + private void fillPositioningPacket(PacketContainer packet, StructureModifier ints){ + ints.write(0, entityId); + if(Core.getVersion() > 8){ + StructureModifier doubles = packet.getDoubles(); + doubles.write(0, locX); + doubles.write(1, locY); + doubles.write(2, locZ); + }else{ + ints.write(1, MathHelper.floor(locX * 32)); + ints.write(2, MathHelper.floor(locY * 32)); + ints.write(3, MathHelper.floor(locZ * 32)); + } + } + + private void fillByteRotation(PacketContainer packet){ + StructureModifier bytes = packet.getBytes(); + bytes.write(0, yaw); + bytes.write(1, pitch); + } + + private PacketContainer getTeleportPacket(){ + PacketContainer teleportPacket = ProtocolLibrary.getProtocolManager().createPacket(PacketType.Play.Server.ENTITY_TELEPORT); + fillPositioningPacket(teleportPacket, teleportPacket.getIntegers()); + fillByteRotation(teleportPacket); + return teleportPacket; + } + + private PacketContainer getHeadRotationPacket(){ + PacketContainer headRotation = ProtocolLibrary.getProtocolManager().createPacket(PacketType.Play.Server.ENTITY_HEAD_ROTATION); + headRotation.getIntegers().write(0, entityId); + headRotation.getBytes().write(1, headYaw); + return headRotation; + } + + private PacketContainer getSpawnEntityPacket(){ + PacketContainer spawnPacket = ProtocolLibrary.getProtocolManager().createPacket(PacketType.Play.Server.SPAWN_ENTITY); + StructureModifier ints = spawnPacket.getIntegers(); + fillPositioningPacket(spawnPacket, ints); + spawnPacket.getUUIDs().write(0, uuid); + if(Core.getVersion() > 8){ + spawnPacket.getUUIDs().write(0, uuid); + ints.write(1, 0); // dX + ints.write(2, 0); // dY + ints.write(3, 0); // dZ + } + ints.write(4, (int)pitch); + ints.write(5, (int)yaw); + if(Core.getVersion() > 12){ + spawnPacket.getEntityTypeModifier().write(0, entityType); + }else{ + ints.write(6, entityTypeToId()); + } + return spawnPacket; + } + + private PacketContainer getEquipmentPacket(String slot, ItemStack stack){ + PacketContainer equipmentPacket = ProtocolLibrary.getProtocolManager().createPacket(PacketType.Play.Server.ENTITY_EQUIPMENT); + StructureModifier ints = equipmentPacket.getIntegers(); + ints.write(0, entityId); + if(Core.getVersion() > 8){ + switch(slot){ + case "MAINHAND": + case "OFFHAND": + ints.write(1, 0); + break; + case "HEAD": + ints.write(1, 4); + break; + case "CHEST": + ints.write(1, 3); + break; + case "LEGS": + ints.write(1, 2); + break; + case "FEET": + default: + ints.write(1, 1); + } + }else{ + equipmentPacket.getItemSlots().write(0, EnumWrappers.ItemSlot.valueOf(slot)); + } + equipmentPacket.getItemModifier().write(0, stack); + return equipmentPacket; + } + + private PacketContainer getPlayerInfoPacket(){ + PacketContainer infoPacket = ProtocolLibrary.getProtocolManager().createPacket(PacketType.Play.Server.PLAYER_INFO); + infoPacket.getPlayerInfoAction().write(0, EnumWrappers.PlayerInfoAction.ADD_PLAYER); + infoPacket.getPlayerInfoDataLists().write(0, Collections.singletonList(playerInfoData)); + return infoPacket; + } + + private PacketContainer getNamedSpawnPacket(){ + PacketContainer namedSpawnPacket = ProtocolLibrary.getProtocolManager().createPacket(PacketType.Play.Server.NAMED_ENTITY_SPAWN); + StructureModifier ints = namedSpawnPacket.getIntegers(); + fillPositioningPacket(namedSpawnPacket, ints); + namedSpawnPacket.getUUIDs().write(0, uuid); + fillByteRotation(namedSpawnPacket); + if(Core.getVersion() < 13){ + namedSpawnPacket.getDataWatcherModifier().write(0, new WrappedDataWatcher()); + } + return namedSpawnPacket; + } +} diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/record/RecordSystem.java b/FightSystem_Main/src/de/steamwar/fightsystem/record/RecordSystem.java index 52e31ba..f60741e 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/record/RecordSystem.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/record/RecordSystem.java @@ -157,7 +157,7 @@ public class RecordSystem { public static synchronized void item(Player p, ItemStack item, String slot){ Recorder.rByte(0x07); Recorder.rInt(p.getEntityId()); - Recorder.rString(item.getType().getKey().toString()); + Recorder.rString("minecraft:" + item.getType().name().toLowerCase()); Recorder.rBoolean(!item.getEnchantments().isEmpty()); Recorder.rString(slot); Recorder.flush(); diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/utils/TechHider.java b/FightSystem_Main/src/de/steamwar/fightsystem/utils/TechHider.java index 3a3308e..58aa1d1 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/utils/TechHider.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/utils/TechHider.java @@ -50,7 +50,7 @@ import static de.steamwar.fightsystem.utils.ITechHider.bypass; public class TechHider extends StateDependent { - private static final boolean enabled = !Config.OnlyPublicSchematics && !Config.test() && Config.TechhiderActive; + public static final boolean ENABLED = !Config.OnlyPublicSchematics && !Config.test() && Config.TechhiderActive; private final ProtocolManager protocolManager = ProtocolLibrary.getProtocolManager(); private final Map packetCache = new HashMap<>(); @@ -59,16 +59,10 @@ public class TechHider extends StateDependent { private final int threadMultiplier; public TechHider(){ - super(enabled, FightState.Schem); + super(ENABLED, FightState.Schem); - Set hiddenBlockIds = VersionedCallable.call( - new VersionedCallable<>(TechHider_8::getHiddenBlockIds, 8), - new VersionedCallable<>(TechHider_14::getHiddenBlockIds, 14), - new VersionedCallable<>(TechHider_15::getHiddenBlockIds, 15)); - int obfuscateWith = VersionedCallable.call( - new VersionedCallable<>(TechHider_8::getObfuscateWith, 8), - new VersionedCallable<>(TechHider_14::getObfuscateWith, 14), - new VersionedCallable<>(TechHider_15::getObfuscateWith, 15)); + Set hiddenBlockIds = getHiddenBlockIds(); + int obfuscateWith = getObfuscateWith(); obfuscateMaterial = Material.getMaterial(Config.ObfuscateWith.toUpperCase()); chunkHider = VersionedCallable.call(new VersionedCallable<>(() -> null, 8), @@ -263,8 +257,22 @@ public class TechHider extends StateDependent { } }; + public static Set getHiddenBlockIds(){ + return VersionedCallable.call( + new VersionedCallable<>(TechHider_8::getHiddenBlockIds, 8), + new VersionedCallable<>(TechHider_14::getHiddenBlockIds, 14), + new VersionedCallable<>(TechHider_15::getHiddenBlockIds, 15)); + } + + public static int getObfuscateWith(){ + return VersionedCallable.call( + new VersionedCallable<>(TechHider_8::getObfuscateWith, 8), + new VersionedCallable<>(TechHider_14::getObfuscateWith, 14), + new VersionedCallable<>(TechHider_15::getObfuscateWith, 15)); + } + public static List prepareChunkReload(Player p, boolean hide){ - if(!enabled) + if(!ENABLED) return Collections.emptyList(); List chunksToReload = new ArrayList<>(); Config.ArenaRegion.forEachChunk((x, z) -> { @@ -275,7 +283,7 @@ public class TechHider extends StateDependent { } public static void reloadChunks(Player p, List chunksToReload, boolean hide){ - if(!enabled) + if(!ENABLED) return; Bukkit.getScheduler().runTaskLater(FightSystem.getPlugin(), () -> { for(ChunkPos chunk : chunksToReload){