From 8ebad6c18e05c66719af48f7e37c702417f946bf Mon Sep 17 00:00:00 2001 From: yoyosource Date: Tue, 12 Oct 2021 20:30:36 +0200 Subject: [PATCH 01/12] First TinyProtocol Signed-off-by: yoyosource --- .../features/other/NoClipCommand.java | 88 ++++++----- .../steamwar/bausystem/utils/ProtocolAPI.java | 140 ++++++++++++++++++ 2 files changed, 190 insertions(+), 38 deletions(-) create mode 100644 BauSystem_Main/src/de/steamwar/bausystem/utils/ProtocolAPI.java diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/other/NoClipCommand.java b/BauSystem_Main/src/de/steamwar/bausystem/features/other/NoClipCommand.java index 4d8d5f1f..75fd8e72 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/other/NoClipCommand.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/other/NoClipCommand.java @@ -19,23 +19,20 @@ package de.steamwar.bausystem.features.other; -import com.comphenix.protocol.PacketType; -import com.comphenix.protocol.ProtocolLibrary; -import com.comphenix.protocol.events.PacketAdapter; -import com.comphenix.protocol.events.PacketContainer; -import com.comphenix.protocol.events.PacketEvent; import com.comphenix.protocol.wrappers.EnumWrappers; import com.comphenix.protocol.wrappers.PlayerInfoData; import com.comphenix.protocol.wrappers.WrappedChatComponent; import com.comphenix.protocol.wrappers.WrappedGameProfile; +import com.comphenix.tinyprotocol.Reflection; import de.steamwar.bausystem.BauSystem; import de.steamwar.bausystem.features.tpslimit.TPSUtils; import de.steamwar.bausystem.linkage.LinkageType; import de.steamwar.bausystem.linkage.Linked; +import de.steamwar.bausystem.utils.ProtocolAPI; import de.steamwar.command.SWCommand; import de.steamwar.core.VersionedRunnable; import lombok.Getter; -import org.bukkit.Bukkit; +import net.minecraft.server.v1_15_R1.PacketPlayOutPlayerInfo; import org.bukkit.GameMode; import org.bukkit.craftbukkit.v1_15_R1.entity.CraftPlayer; import org.bukkit.entity.Player; @@ -46,42 +43,59 @@ import org.bukkit.event.player.PlayerGameModeChangeEvent; import org.bukkit.event.player.PlayerTeleportEvent; import org.bukkit.event.player.PlayerToggleFlightEvent; -import java.lang.reflect.InvocationTargetException; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; -import java.util.logging.Level; +import java.util.function.BiFunction; @Linked(LinkageType.COMMAND) @Linked(LinkageType.LISTENER) public class NoClipCommand extends SWCommand implements Listener { + public static final Class playerInfo = Reflection.getClass("{nms}.PacketPlayOutPlayerInfo"); + private static final Reflection.FieldAccessor playerInfoAction = Reflection.getField(playerInfo, PacketPlayOutPlayerInfo.EnumPlayerInfoAction.class, 0); + private static final Reflection.FieldAccessor playerInfoDataList = Reflection.getField(playerInfo, "b", List.class); + + public static final Class gameStateChange = Reflection.getClass("{nms}.PacketPlayOutGameStateChange"); + private static final Reflection.FieldAccessor integerFieldAccessor = Reflection.getField(gameStateChange, int.class, 0); + private static final Reflection.FieldAccessor floatFieldAccessor = Reflection.getField(gameStateChange, float.class, 0); + + public static final Class position = Reflection.getClass("{nms}.PacketPlayInFlying$PacketPlayInPosition"); + public static final Class positionLook = Reflection.getClass("{nms}.PacketPlayInFlying$PacketPlayInPositionLook"); + public static final Class useItem = Reflection.getClass("{nms}.PacketPlayInUseItem"); + public static final Class blockDig = Reflection.getClass("{nms}.PacketPlayInBlockDig"); + public static final Class windowClick = Reflection.getClass("{nms}.PacketPlayInWindowClick"); + @Getter private static final List NOCLIPS = new ArrayList<>(); private static final Map LAST_TICKS = new HashMap<>(); protected NoClipCommand() { super("noclip", "nc"); - ProtocolLibrary.getProtocolManager().addPacketListener(new PacketAdapter(BauSystem.getInstance(), PacketType.Play.Client.POSITION, PacketType.Play.Client.POSITION_LOOK) { - @Override - public void onPacketReceiving(PacketEvent event) { - if (NOCLIPS.contains(event.getPlayer())) { - if (LAST_TICKS.getOrDefault(event.getPlayer(), -1L).equals(TPSUtils.currentTick.get())) return; - VersionedRunnable.call(new VersionedRunnable(() -> NoClipCommand_15.setGameModeInternal(event.getPlayer(), GameMode.SPECTATOR), 15)); - LAST_TICKS.put(event.getPlayer(), TPSUtils.currentTick.get()); - } + + BiFunction first = (player, o) -> { + if (NOCLIPS.contains(player)) { + if (LAST_TICKS.getOrDefault(player, -1L).equals(TPSUtils.currentTick.get())) return o; + VersionedRunnable.call(new VersionedRunnable(() -> NoClipCommand_15.setGameModeInternal(player, GameMode.SPECTATOR), 15)); + LAST_TICKS.put(player, TPSUtils.currentTick.get()); } - }); - ProtocolLibrary.getProtocolManager().addPacketListener(new PacketAdapter(BauSystem.getInstance(), PacketType.Play.Client.USE_ITEM, PacketType.Play.Client.BLOCK_DIG, PacketType.Play.Client.WINDOW_CLICK) { - @Override - public void onPacketReceiving(PacketEvent event) { - if (NOCLIPS.contains(event.getPlayer())) { - VersionedRunnable.call(new VersionedRunnable(() -> NoClipCommand_15.setGameModeInternal(event.getPlayer(), GameMode.CREATIVE), 15)); - LAST_TICKS.put(event.getPlayer(), TPSUtils.currentTick.get()); - } + return o; + }; + ProtocolAPI.setIncomingHandler(position, first); + ProtocolAPI.setIncomingHandler(positionLook, first); + + BiFunction second = (player, o) -> { + if (NOCLIPS.contains(player)) { + if (LAST_TICKS.getOrDefault(player, -1L).equals(TPSUtils.currentTick.get())) return o; + VersionedRunnable.call(new VersionedRunnable(() -> NoClipCommand_15.setGameModeInternal(player, GameMode.SPECTATOR), 15)); + LAST_TICKS.put(player, TPSUtils.currentTick.get()); } - }); + return o; + }; + ProtocolAPI.setIncomingHandler(useItem, second); + ProtocolAPI.setIncomingHandler(blockDig, second); + ProtocolAPI.setIncomingHandler(windowClick, second); } @Register(help = true) @@ -93,23 +107,21 @@ public class NoClipCommand extends SWCommand implements Listener { player.setGameMode(GameMode.SPECTATOR); ((CraftPlayer) player).getHandle().abilities.mayBuild = true; ((CraftPlayer) player).getHandle().abilities.canInstantlyBuild = true; - PacketContainer gm3packet = ProtocolLibrary.getProtocolManager().createPacket(PacketType.Play.Server.PLAYER_INFO); - gm3packet.getPlayerInfoAction().write(0, EnumWrappers.PlayerInfoAction.UPDATE_GAME_MODE); + + Object playerInfoObject = Reflection.newInstance(playerInfo); + playerInfoAction.set(playerInfoObject, PacketPlayOutPlayerInfo.EnumPlayerInfoAction.UPDATE_GAME_MODE); List playerInfoActions = new ArrayList<>(); playerInfoActions.add(new PlayerInfoData(WrappedGameProfile.fromPlayer(player), 1, EnumWrappers.NativeGameMode.SPECTATOR, WrappedChatComponent.fromText(player.getDisplayName()))); - gm3packet.getPlayerInfoDataLists().write(0, playerInfoActions); - PacketContainer gm1packet = ProtocolLibrary.getProtocolManager().createPacket(PacketType.Play.Server.GAME_STATE_CHANGE); - gm1packet.getIntegers().write(0, 3); - gm1packet.getFloat().write(0, 1F); + playerInfoDataList.set(playerInfoObject, playerInfoActions); + + Object gameStateChangeObject = Reflection.newInstance(gameStateChange); + integerFieldAccessor.set(gameStateChangeObject, 3); + floatFieldAccessor.set(gameStateChangeObject, 1F); + NOCLIPS.add(player); BauSystem.MESSAGE.send("OTHER_NOCLIP_SLOT_INFO", player); - try { - ProtocolLibrary.getProtocolManager().sendServerPacket(player, gm1packet); - ProtocolLibrary.getProtocolManager().sendServerPacket(player, gm3packet); - } catch (InvocationTargetException e) { - Bukkit.getLogger().log(Level.SEVERE, "Invocation target exception", e); - player.performCommand("noclip"); - } + ProtocolAPI.tinyProtocol.sendPacket(player, gameStateChangeObject); + ProtocolAPI.tinyProtocol.sendPacket(player, playerInfoObject); } } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/utils/ProtocolAPI.java b/BauSystem_Main/src/de/steamwar/bausystem/utils/ProtocolAPI.java new file mode 100644 index 00000000..eab08b08 --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/utils/ProtocolAPI.java @@ -0,0 +1,140 @@ +/* + * This file is a part of the SteamWar software. + * + * Copyright (C) 2021 SteamWar.de-Serverteam + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +package de.steamwar.bausystem.utils; + +import com.comphenix.tinyprotocol.TinyProtocol; +import de.steamwar.bausystem.BauSystem; +import io.netty.channel.Channel; +import lombok.experimental.UtilityClass; +import org.bukkit.Bukkit; +import org.bukkit.entity.Player; + +import java.lang.reflect.Array; +import java.lang.reflect.Field; +import java.lang.reflect.Modifier; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.function.BiConsumer; +import java.util.function.BiFunction; +import java.util.function.UnaryOperator; + +@UtilityClass +public class ProtocolAPI { + + private static final Map, BiFunction> outgoingHandler = new HashMap<>(); + private static final Map, BiFunction> incomingHandler = new HashMap<>(); + + public static final TinyProtocol tinyProtocol = new TinyProtocol(BauSystem.getInstance()) { + @Override + public Object onPacketOutAsync(Player receiver, Channel channel, Object packet) { + BiFunction handler = outgoingHandler.get(packet.getClass()); + if (handler == null) + return packet; + return handler.apply(receiver, packet); + } + + @Override + public Object onPacketInAsync(Player sender, Channel channel, Object packet) { + BiFunction handler = incomingHandler.get(packet.getClass()); + if (handler == null) + return packet; + return handler.apply(sender, packet); + } + }; + + public static void setOutgoingHandler(Class packetClass, BiFunction handler) { + outgoingHandler.put(packetClass, handler); + } + + public static void removeOutgoingHandler(Class packetClass) { + outgoingHandler.remove(packetClass); + } + + public static void setIncomingHandler(Class packetClass, BiFunction handler) { + incomingHandler.put(packetClass, handler); + } + + public static void removeIncomingHandler(Class packetClass) { + incomingHandler.remove(packetClass); + } + + public static void broadcastPacket(Object packet) { + Bukkit.getOnlinePlayers().stream().map(tinyProtocol::getChannel).filter(tinyProtocol::hasInjected).forEach(channel -> tinyProtocol.sendPacket(channel, packet)); + } + + public static BiFunction, Object> arrayCloneGenerator(Class elementClass) { + return (array, worker) -> { + int length = Array.getLength(array); + Object result = Array.newInstance(elementClass, length); + + for (int i = 0; i < length; i++) + Array.set(result, i, worker.apply(Array.get(array, i))); + + return result; + }; + } + + public static UnaryOperator shallowCloneGenerator(Class clazz) { + BiConsumer filler = shallowFill(clazz); + + return source -> { + Object clone; + try { + clone = clazz.newInstance(); + } catch (InstantiationException | IllegalAccessException e) { + throw new IllegalStateException("Could not clone " + clazz.getName(), e); + } + filler.accept(source, clone); + return clone; + }; + } + + private static BiConsumer shallowFill(Class clazz) { + if (clazz == null) + return (source, clone) -> { + }; + + BiConsumer superFiller = shallowFill(clazz.getSuperclass()); + + Field[] fds = clazz.getDeclaredFields(); + List fields = new ArrayList<>(); + for (Field field : fds) { + if (Modifier.isStatic(field.getModifiers())) + continue; + + field.setAccessible(true); + fields.add(field); + } + + return (source, clone) -> { + superFiller.accept(source, clone); + try { + for (Field field : fields) { + field.set(clone, field.get(source)); + } + } catch (IllegalAccessException e) { + throw new IllegalStateException("Could not set field", e); + } + + }; + } +} From e71931e7574f281c4647ddd4d6eb55875ee64fd3 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Tue, 12 Oct 2021 20:36:42 +0200 Subject: [PATCH 02/12] Add tinyprotocol for NoClipCommand Signed-off-by: yoyosource --- .../de/steamwar/bausystem/features/other/NoClipCommand.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/other/NoClipCommand.java b/BauSystem_Main/src/de/steamwar/bausystem/features/other/NoClipCommand.java index 75fd8e72..5ae234d5 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/other/NoClipCommand.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/other/NoClipCommand.java @@ -87,8 +87,7 @@ public class NoClipCommand extends SWCommand implements Listener { BiFunction second = (player, o) -> { if (NOCLIPS.contains(player)) { - if (LAST_TICKS.getOrDefault(player, -1L).equals(TPSUtils.currentTick.get())) return o; - VersionedRunnable.call(new VersionedRunnable(() -> NoClipCommand_15.setGameModeInternal(player, GameMode.SPECTATOR), 15)); + VersionedRunnable.call(new VersionedRunnable(() -> NoClipCommand_15.setGameModeInternal(player, GameMode.CREATIVE), 15)); LAST_TICKS.put(player, TPSUtils.currentTick.get()); } return o; From 81d1b4a914f40b2e835401bd88f46d6012eeb298 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Tue, 12 Oct 2021 20:50:31 +0200 Subject: [PATCH 03/12] Add tinyprotocol for SignEdit Signed-off-by: yoyosource --- .../bausystem/features/world/SignEdit.java | 70 +++++++++---------- 1 file changed, 32 insertions(+), 38 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/world/SignEdit.java b/BauSystem_Main/src/de/steamwar/bausystem/features/world/SignEdit.java index dc15ef2a..5d525f0c 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/world/SignEdit.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/world/SignEdit.java @@ -19,17 +19,15 @@ package de.steamwar.bausystem.features.world; -import com.comphenix.protocol.PacketType; -import com.comphenix.protocol.ProtocolLibrary; -import com.comphenix.protocol.events.PacketAdapter; -import com.comphenix.protocol.events.PacketContainer; -import com.comphenix.protocol.events.PacketEvent; -import com.comphenix.protocol.wrappers.BlockPosition; +import com.comphenix.tinyprotocol.Reflection; import de.steamwar.bausystem.BauSystem; import de.steamwar.bausystem.linkage.LinkageType; import de.steamwar.bausystem.linkage.Linked; +import de.steamwar.bausystem.utils.ProtocolAPI; +import net.minecraft.server.v1_15_R1.BlockPosition; import org.bukkit.Bukkit; import org.bukkit.ChatColor; +import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.block.Block; import org.bukkit.block.Sign; @@ -38,13 +36,18 @@ import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; import org.bukkit.event.block.Action; import org.bukkit.event.player.PlayerInteractEvent; - -import java.lang.reflect.InvocationTargetException; -import java.util.logging.Level; +import org.bukkit.util.Vector; @Linked(LinkageType.LISTENER) public class SignEdit implements Listener { + public static final Class openSign = Reflection.getClass("{nms}.PacketPlayOutOpenSignEditor"); + private static final Reflection.FieldAccessor blockPositionFieldAccessor = Reflection.getField(openSign, net.minecraft.server.v1_15_R1.BlockPosition.class, 0); + + public static final Class updateSign = Reflection.getClass("{nms}.PacketPlayInUpdateSign"); + private static final Reflection.FieldAccessor getBlockPositionFieldAccessor = Reflection.getField(updateSign, BlockPosition.class, 0); + private static final Reflection.FieldAccessor stringFieldAccessor = Reflection.getField(updateSign, String[].class, 0); + @EventHandler public void editSign(PlayerInteractEvent event) { if (event.getAction() != Action.RIGHT_CLICK_BLOCK || @@ -62,38 +65,29 @@ public class SignEdit implements Listener { } sign.update(); - PacketContainer signOpen = ProtocolLibrary.getProtocolManager().createPacket(PacketType.Play.Server.OPEN_SIGN_EDITOR); - signOpen.getBlockPositionModifier().write(0, new BlockPosition(event.getClickedBlock().getLocation().toVector())); - try { - ProtocolLibrary.getProtocolManager().sendServerPacket(player, signOpen); - } catch (InvocationTargetException e) { - Bukkit.getLogger().log(Level.SEVERE, "Invocation target exception", e); - } + Object openSignObject = Reflection.newInstance(openSign); + Vector vector = event.getClickedBlock().getLocation().toVector(); + blockPositionFieldAccessor.set(openSignObject, new BlockPosition(vector.getBlockX(), vector.getBlockY(), vector.getBlockZ())); + ProtocolAPI.tinyProtocol.sendPacket(player, openSignObject); + } - ProtocolLibrary.getProtocolManager().addPacketListener(new PacketAdapter(BauSystem.getInstance(), PacketType.Play.Client.UPDATE_SIGN) { - @Override - public void onPacketReceiving(PacketEvent event) { - if (!event.getPlayer().equals(player)) + { + ProtocolAPI.setIncomingHandler(updateSign, (player, o) -> { + Bukkit.getScheduler().runTask(BauSystem.getInstance(), () -> { + BlockPosition position = getBlockPositionFieldAccessor.get(o); + String[] lines = stringFieldAccessor.get(o); + + Block signLoc = new Location(player.getWorld(), position.getX(), position.getY(), position.getZ()).getBlock(); + if (!signLoc.getType().name().contains("SIGN")) return; - event.setCancelled(true); - Bukkit.getScheduler().runTask(BauSystem.getInstance(), () -> { - PacketContainer packetContainer = event.getPacket(); - BlockPosition position = packetContainer.getBlockPositionModifier().read(0); - String[] lines = packetContainer.getStringArrays().read(0); - Block signLoc = position.toLocation(player.getWorld()).getBlock(); - if (!signLoc.getType().name().contains("SIGN")) - return; - - org.bukkit.block.Sign sign = ((Sign) signLoc.getState()); - for (int i = 0; i < lines.length; i++) { - sign.setLine(i, ChatColor.translateAlternateColorCodes('&', lines[i])); - } - sign.update(); - - ProtocolLibrary.getProtocolManager().removePacketListener(this); - }); - } + org.bukkit.block.Sign sign = ((Sign) signLoc.getState()); + for (int i = 0; i < lines.length; i++) { + sign.setLine(i, ChatColor.translateAlternateColorCodes('&', lines[i])); + } + sign.update(); + }); + return o; }); } } From 229db35fe31498112dd1b9d24490668ee241a575 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Tue, 12 Oct 2021 21:14:11 +0200 Subject: [PATCH 04/12] Add tinyprotocol Signed-off-by: yoyosource --- BauSystem_Main/build.gradle | 1 - .../features/detonator/DetonatorListener.java | 46 +++++++++---------- .../features/other/NoClipCommand.java | 15 +++--- .../steamwar/bausystem/utils/ProtocolAPI.java | 27 ----------- 4 files changed, 29 insertions(+), 60 deletions(-) diff --git a/BauSystem_Main/build.gradle b/BauSystem_Main/build.gradle index 9629d086..32d7760b 100644 --- a/BauSystem_Main/build.gradle +++ b/BauSystem_Main/build.gradle @@ -61,6 +61,5 @@ dependencies { compileOnly files("${projectDir}/../lib/Spigot-1.15.jar") compileOnly files("${projectDir}/../lib/WorldEdit-1.15.jar") - compileOnly files("${projectDir}/../lib/ProtocolLib.jar") compileOnly files("${projectDir}/../lib/SpigotCore.jar") } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/detonator/DetonatorListener.java b/BauSystem_Main/src/de/steamwar/bausystem/features/detonator/DetonatorListener.java index c699211e..4a7ae09b 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/detonator/DetonatorListener.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/detonator/DetonatorListener.java @@ -19,17 +19,14 @@ package de.steamwar.bausystem.features.detonator; -import com.comphenix.protocol.PacketType; -import com.comphenix.protocol.ProtocolLibrary; -import com.comphenix.protocol.events.PacketAdapter; -import com.comphenix.protocol.events.PacketContainer; -import com.comphenix.protocol.events.PacketEvent; +import com.comphenix.tinyprotocol.Reflection; import de.steamwar.bausystem.BauSystem; import de.steamwar.bausystem.SWUtils; import de.steamwar.bausystem.features.detonator.storage.DetonatorStorage; import de.steamwar.bausystem.features.detonator.storage.ItemStorage; import de.steamwar.bausystem.linkage.LinkageType; import de.steamwar.bausystem.linkage.Linked; +import de.steamwar.bausystem.utils.ProtocolAPI; import org.bukkit.Location; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; @@ -49,30 +46,29 @@ import java.util.Set; @Linked(LinkageType.LISTENER) public class DetonatorListener implements Listener { + public static final Class useEntity = Reflection.getClass("{nms}.PacketPlayInUseEntity"); + private static final Reflection.FieldAccessor entityIdFieldAccessor = Reflection.getField(useEntity, int.class, 0); + private static final Set HAS_UPDATED = new HashSet<>(); public DetonatorListener() { - ProtocolLibrary.getProtocolManager().addPacketListener(new PacketAdapter(BauSystem.getInstance(), PacketType.Play.Client.USE_ENTITY) { - @Override - public void onPacketReceiving(PacketEvent event) { - List entities = new ArrayList<>(Detonator.getDetoEntities(event.getPlayer())); - if (entities.isEmpty()) { - return; - } - - PacketContainer container = event.getPacket(); - int entityId = container.getIntegers().read(0); - entities.removeIf(abstractDetonatorEntity -> abstractDetonatorEntity.getId() != entityId); - - if (entities.isEmpty()) { - return; - } - AbstractDetonatorEntity entity = entities.get(0); - Location location = entity.getBukkitEntity().getLocation().getBlock().getLocation(); - addLocationToDetonator(location, event.getPlayer()); - HAS_UPDATED.add(event.getPlayer()); - event.setCancelled(true); + ProtocolAPI.setIncomingHandler(useEntity, (player, o) -> { + List entities = new ArrayList<>(Detonator.getDetoEntities(player)); + if (entities.isEmpty()) { + return o; } + + int entityId = entityIdFieldAccessor.get(o); + entities.removeIf(abstractDetonatorEntity -> abstractDetonatorEntity.getId() != entityId); + + if (entities.isEmpty()) { + return o; + } + AbstractDetonatorEntity entity = entities.get(0); + Location location = entity.getBukkitEntity().getLocation().getBlock().getLocation(); + addLocationToDetonator(location, player); + HAS_UPDATED.add(player); + return null; }); } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/other/NoClipCommand.java b/BauSystem_Main/src/de/steamwar/bausystem/features/other/NoClipCommand.java index 5ae234d5..ef0bbad8 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/other/NoClipCommand.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/other/NoClipCommand.java @@ -19,11 +19,8 @@ package de.steamwar.bausystem.features.other; -import com.comphenix.protocol.wrappers.EnumWrappers; -import com.comphenix.protocol.wrappers.PlayerInfoData; -import com.comphenix.protocol.wrappers.WrappedChatComponent; -import com.comphenix.protocol.wrappers.WrappedGameProfile; import com.comphenix.tinyprotocol.Reflection; +import com.mojang.authlib.GameProfile; import de.steamwar.bausystem.BauSystem; import de.steamwar.bausystem.features.tpslimit.TPSUtils; import de.steamwar.bausystem.linkage.LinkageType; @@ -32,6 +29,8 @@ import de.steamwar.bausystem.utils.ProtocolAPI; import de.steamwar.command.SWCommand; import de.steamwar.core.VersionedRunnable; import lombok.Getter; +import net.minecraft.server.v1_15_R1.EnumGamemode; +import net.minecraft.server.v1_15_R1.IChatBaseComponent; import net.minecraft.server.v1_15_R1.PacketPlayOutPlayerInfo; import org.bukkit.GameMode; import org.bukkit.craftbukkit.v1_15_R1.entity.CraftPlayer; @@ -109,9 +108,11 @@ public class NoClipCommand extends SWCommand implements Listener { Object playerInfoObject = Reflection.newInstance(playerInfo); playerInfoAction.set(playerInfoObject, PacketPlayOutPlayerInfo.EnumPlayerInfoAction.UPDATE_GAME_MODE); - List playerInfoActions = new ArrayList<>(); - playerInfoActions.add(new PlayerInfoData(WrappedGameProfile.fromPlayer(player), 1, EnumWrappers.NativeGameMode.SPECTATOR, WrappedChatComponent.fromText(player.getDisplayName()))); - playerInfoDataList.set(playerInfoObject, playerInfoActions); + PacketPlayOutPlayerInfo packetPlayOutPlayerInfo = (PacketPlayOutPlayerInfo) playerInfoObject; + + List playerInfoData = new ArrayList<>(); + playerInfoData.add(packetPlayOutPlayerInfo.new PlayerInfoData(new GameProfile(player.getUniqueId(), player.getName()), 1, EnumGamemode.SPECTATOR, IChatBaseComponent.ChatSerializer.b(player.getDisplayName()))); + playerInfoDataList.set(playerInfoObject, playerInfoData); Object gameStateChangeObject = Reflection.newInstance(gameStateChange); integerFieldAccessor.set(gameStateChangeObject, 3); diff --git a/BauSystem_Main/src/de/steamwar/bausystem/utils/ProtocolAPI.java b/BauSystem_Main/src/de/steamwar/bausystem/utils/ProtocolAPI.java index eab08b08..e88e7c94 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/utils/ProtocolAPI.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/utils/ProtocolAPI.java @@ -81,33 +81,6 @@ public class ProtocolAPI { Bukkit.getOnlinePlayers().stream().map(tinyProtocol::getChannel).filter(tinyProtocol::hasInjected).forEach(channel -> tinyProtocol.sendPacket(channel, packet)); } - public static BiFunction, Object> arrayCloneGenerator(Class elementClass) { - return (array, worker) -> { - int length = Array.getLength(array); - Object result = Array.newInstance(elementClass, length); - - for (int i = 0; i < length; i++) - Array.set(result, i, worker.apply(Array.get(array, i))); - - return result; - }; - } - - public static UnaryOperator shallowCloneGenerator(Class clazz) { - BiConsumer filler = shallowFill(clazz); - - return source -> { - Object clone; - try { - clone = clazz.newInstance(); - } catch (InstantiationException | IllegalAccessException e) { - throw new IllegalStateException("Could not clone " + clazz.getName(), e); - } - filler.accept(source, clone); - return clone; - }; - } - private static BiConsumer shallowFill(Class clazz) { if (clazz == null) return (source, clone) -> { From d82af9c07490129726e110f089661bdbc57029c0 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Tue, 12 Oct 2021 21:21:27 +0200 Subject: [PATCH 05/12] Add tinyprotocol Signed-off-by: yoyosource --- .../features/other/NoClipCommand.java | 48 +++++++++++-------- 1 file changed, 29 insertions(+), 19 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/other/NoClipCommand.java b/BauSystem_Main/src/de/steamwar/bausystem/features/other/NoClipCommand.java index ef0bbad8..a4b635d3 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/other/NoClipCommand.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/other/NoClipCommand.java @@ -27,11 +27,9 @@ import de.steamwar.bausystem.linkage.LinkageType; import de.steamwar.bausystem.linkage.Linked; import de.steamwar.bausystem.utils.ProtocolAPI; import de.steamwar.command.SWCommand; +import de.steamwar.core.Core; import de.steamwar.core.VersionedRunnable; import lombok.Getter; -import net.minecraft.server.v1_15_R1.EnumGamemode; -import net.minecraft.server.v1_15_R1.IChatBaseComponent; -import net.minecraft.server.v1_15_R1.PacketPlayOutPlayerInfo; import org.bukkit.GameMode; import org.bukkit.craftbukkit.v1_15_R1.entity.CraftPlayer; import org.bukkit.entity.Player; @@ -42,19 +40,28 @@ import org.bukkit.event.player.PlayerGameModeChangeEvent; import org.bukkit.event.player.PlayerTeleportEvent; import org.bukkit.event.player.PlayerToggleFlightEvent; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; +import java.util.*; import java.util.function.BiFunction; @Linked(LinkageType.COMMAND) @Linked(LinkageType.LISTENER) public class NoClipCommand extends SWCommand implements Listener { - public static final Class playerInfo = Reflection.getClass("{nms}.PacketPlayOutPlayerInfo"); - private static final Reflection.FieldAccessor playerInfoAction = Reflection.getField(playerInfo, PacketPlayOutPlayerInfo.EnumPlayerInfoAction.class, 0); - private static final Reflection.FieldAccessor playerInfoDataList = Reflection.getField(playerInfo, "b", List.class); + private static final Class playerInfoPacket = Reflection.getClass("{nms}.PacketPlayOutPlayerInfo"); + private static final Reflection.ConstructorInvoker playerInfoConstructor = Reflection.getConstructor(playerInfoPacket); + private static final Class playerInfoActionClass = Reflection.getClass("{nms}.PacketPlayOutPlayerInfo$EnumPlayerInfoAction"); + public static final Object addPlayer = playerInfoActionClass.getEnumConstants()[0]; + private static final Reflection.FieldAccessor playerInfoAction = Reflection.getField(playerInfoPacket, playerInfoActionClass, 0); + private static final Object updateGamemode = playerInfoActionClass.getEnumConstants()[1]; + public static final Object removePlayer = playerInfoActionClass.getEnumConstants()[4]; + private static final Reflection.FieldAccessor playerInfoData = Reflection.getField(playerInfoPacket, List.class, 0); + private static final Class playerInfoDataClass = Reflection.getClass("{nms}.PacketPlayOutPlayerInfo$PlayerInfoData"); + private static final Class enumGamemode = Reflection.getClass(Core.getVersion() > 9 ? "{nms}.EnumGamemode" : "{nms}.WorldSettings$EnumGamemode"); + public static final Object creative = enumGamemode.getEnumConstants()[2]; + private static final Object spectator = enumGamemode.getEnumConstants()[4]; + private static final Class iChatBaseComponent = Reflection.getClass("{nms}.IChatBaseComponent"); + + private static final Reflection.ConstructorInvoker playerInfoDataConstructor = Reflection.getConstructor(playerInfoDataClass, playerInfoPacket, GameProfile.class, int.class, enumGamemode, iChatBaseComponent); public static final Class gameStateChange = Reflection.getClass("{nms}.PacketPlayOutGameStateChange"); private static final Reflection.FieldAccessor integerFieldAccessor = Reflection.getField(gameStateChange, int.class, 0); @@ -106,14 +113,6 @@ public class NoClipCommand extends SWCommand implements Listener { ((CraftPlayer) player).getHandle().abilities.mayBuild = true; ((CraftPlayer) player).getHandle().abilities.canInstantlyBuild = true; - Object playerInfoObject = Reflection.newInstance(playerInfo); - playerInfoAction.set(playerInfoObject, PacketPlayOutPlayerInfo.EnumPlayerInfoAction.UPDATE_GAME_MODE); - PacketPlayOutPlayerInfo packetPlayOutPlayerInfo = (PacketPlayOutPlayerInfo) playerInfoObject; - - List playerInfoData = new ArrayList<>(); - playerInfoData.add(packetPlayOutPlayerInfo.new PlayerInfoData(new GameProfile(player.getUniqueId(), player.getName()), 1, EnumGamemode.SPECTATOR, IChatBaseComponent.ChatSerializer.b(player.getDisplayName()))); - playerInfoDataList.set(playerInfoObject, playerInfoData); - Object gameStateChangeObject = Reflection.newInstance(gameStateChange); integerFieldAccessor.set(gameStateChangeObject, 3); floatFieldAccessor.set(gameStateChangeObject, 1F); @@ -121,7 +120,7 @@ public class NoClipCommand extends SWCommand implements Listener { NOCLIPS.add(player); BauSystem.MESSAGE.send("OTHER_NOCLIP_SLOT_INFO", player); ProtocolAPI.tinyProtocol.sendPacket(player, gameStateChangeObject); - ProtocolAPI.tinyProtocol.sendPacket(player, playerInfoObject); + pseudoSpectator(player, false); } } @@ -157,4 +156,15 @@ public class NoClipCommand extends SWCommand implements Listener { event.setCancelled(true); } } + + public static void pseudoSpectator(Player player, boolean enable) { + ProtocolAPI.tinyProtocol.sendPacket(player, playerInfoPacket(updateGamemode, new GameProfile(player.getUniqueId(), player.getName()), enable ? creative : spectator)); + } + + public static Object playerInfoPacket(Object action, GameProfile profile, Object mode) { + Object packet = playerInfoConstructor.invoke(); + playerInfoAction.set(packet, action); + playerInfoData.set(packet, Collections.singletonList(playerInfoDataConstructor.invoke(packet, profile, 0, mode, null))); + return packet; + } } \ No newline at end of file From 2e171bd657146e39b77f61e34b6a70af2d3cc606 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Tue, 12 Oct 2021 21:22:01 +0200 Subject: [PATCH 06/12] Add tinyprotocol Signed-off-by: yoyosource --- BauSystem_Main/src/plugin.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/BauSystem_Main/src/plugin.yml b/BauSystem_Main/src/plugin.yml index 36a8d970..a75ce068 100644 --- a/BauSystem_Main/src/plugin.yml +++ b/BauSystem_Main/src/plugin.yml @@ -1,7 +1,7 @@ name: BauSystem authors: [Lixfel, YoyoNow, Chaoscaot, Zeanon] version: "2.0" -depend: [WorldEdit, SpigotCore, ProtocolLib] +depend: [WorldEdit, SpigotCore] load: POSTWORLD main: de.steamwar.bausystem.BauSystem api-version: "1.13" From 83e26406adc1e1eebf861cbddef297b9e2358833 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Tue, 12 Oct 2021 21:22:32 +0200 Subject: [PATCH 07/12] Add tinyprotocol Signed-off-by: yoyosource --- .../src/de/steamwar/bausystem/features/other/NoClipCommand.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/other/NoClipCommand.java b/BauSystem_Main/src/de/steamwar/bausystem/features/other/NoClipCommand.java index a4b635d3..9cb262c9 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/other/NoClipCommand.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/other/NoClipCommand.java @@ -50,10 +50,8 @@ public class NoClipCommand extends SWCommand implements Listener { private static final Class playerInfoPacket = Reflection.getClass("{nms}.PacketPlayOutPlayerInfo"); private static final Reflection.ConstructorInvoker playerInfoConstructor = Reflection.getConstructor(playerInfoPacket); private static final Class playerInfoActionClass = Reflection.getClass("{nms}.PacketPlayOutPlayerInfo$EnumPlayerInfoAction"); - public static final Object addPlayer = playerInfoActionClass.getEnumConstants()[0]; private static final Reflection.FieldAccessor playerInfoAction = Reflection.getField(playerInfoPacket, playerInfoActionClass, 0); private static final Object updateGamemode = playerInfoActionClass.getEnumConstants()[1]; - public static final Object removePlayer = playerInfoActionClass.getEnumConstants()[4]; private static final Reflection.FieldAccessor playerInfoData = Reflection.getField(playerInfoPacket, List.class, 0); private static final Class playerInfoDataClass = Reflection.getClass("{nms}.PacketPlayOutPlayerInfo$PlayerInfoData"); private static final Class enumGamemode = Reflection.getClass(Core.getVersion() > 9 ? "{nms}.EnumGamemode" : "{nms}.WorldSettings$EnumGamemode"); From fb0e4dbd230b2a5647f3ebeda865bbd8b04d6001 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Tue, 12 Oct 2021 21:24:37 +0200 Subject: [PATCH 08/12] Add tinyprotocol Signed-off-by: yoyosource --- .../steamwar/bausystem/utils/ProtocolAPI.java | 30 ------------------- 1 file changed, 30 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/utils/ProtocolAPI.java b/BauSystem_Main/src/de/steamwar/bausystem/utils/ProtocolAPI.java index e88e7c94..e3ba3aea 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/utils/ProtocolAPI.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/utils/ProtocolAPI.java @@ -80,34 +80,4 @@ public class ProtocolAPI { public static void broadcastPacket(Object packet) { Bukkit.getOnlinePlayers().stream().map(tinyProtocol::getChannel).filter(tinyProtocol::hasInjected).forEach(channel -> tinyProtocol.sendPacket(channel, packet)); } - - private static BiConsumer shallowFill(Class clazz) { - if (clazz == null) - return (source, clone) -> { - }; - - BiConsumer superFiller = shallowFill(clazz.getSuperclass()); - - Field[] fds = clazz.getDeclaredFields(); - List fields = new ArrayList<>(); - for (Field field : fds) { - if (Modifier.isStatic(field.getModifiers())) - continue; - - field.setAccessible(true); - fields.add(field); - } - - return (source, clone) -> { - superFiller.accept(source, clone); - try { - for (Field field : fields) { - field.set(clone, field.get(source)); - } - } catch (IllegalAccessException e) { - throw new IllegalStateException("Could not set field", e); - } - - }; - } } From 1786f6c311ee139dd736e99628c6b14d3835d178 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Tue, 12 Oct 2021 21:26:54 +0200 Subject: [PATCH 09/12] Add tinyprotocol Signed-off-by: yoyosource --- .../src/de/steamwar/bausystem/utils/ProtocolAPI.java | 7 ------- 1 file changed, 7 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/utils/ProtocolAPI.java b/BauSystem_Main/src/de/steamwar/bausystem/utils/ProtocolAPI.java index e3ba3aea..351a27fb 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/utils/ProtocolAPI.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/utils/ProtocolAPI.java @@ -26,16 +26,9 @@ import lombok.experimental.UtilityClass; import org.bukkit.Bukkit; import org.bukkit.entity.Player; -import java.lang.reflect.Array; -import java.lang.reflect.Field; -import java.lang.reflect.Modifier; -import java.util.ArrayList; import java.util.HashMap; -import java.util.List; import java.util.Map; -import java.util.function.BiConsumer; import java.util.function.BiFunction; -import java.util.function.UnaryOperator; @UtilityClass public class ProtocolAPI { From 94be6998d2d27b1caecb4870090a15bc7893d3c2 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Tue, 12 Oct 2021 21:28:05 +0200 Subject: [PATCH 10/12] Add tinyprotocol Signed-off-by: yoyosource --- .../bausystem/features/detonator/DetonatorListener.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/detonator/DetonatorListener.java b/BauSystem_Main/src/de/steamwar/bausystem/features/detonator/DetonatorListener.java index 4a7ae09b..53a77ce0 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/detonator/DetonatorListener.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/detonator/DetonatorListener.java @@ -53,18 +53,18 @@ public class DetonatorListener implements Listener { public DetonatorListener() { ProtocolAPI.setIncomingHandler(useEntity, (player, o) -> { - List entities = new ArrayList<>(Detonator.getDetoEntities(player)); + List entities = Detonator.getDetoEntities(player); if (entities.isEmpty()) { return o; } int entityId = entityIdFieldAccessor.get(o); - entities.removeIf(abstractDetonatorEntity -> abstractDetonatorEntity.getId() != entityId); + AbstractDetonatorEntity entity = entities.stream().filter(abstractDetonatorEntity -> abstractDetonatorEntity.getId() == entityId).findFirst().orElse(null); - if (entities.isEmpty()) { + if (entity == null) { return o; } - AbstractDetonatorEntity entity = entities.get(0); + Location location = entity.getBukkitEntity().getLocation().getBlock().getLocation(); addLocationToDetonator(location, player); HAS_UPDATED.add(player); From a70da25e1c4b29b4608a8e2677fbb9db676d956b Mon Sep 17 00:00:00 2001 From: yoyosource Date: Tue, 12 Oct 2021 21:28:54 +0200 Subject: [PATCH 11/12] Add tinyprotocol Signed-off-by: yoyosource --- .../steamwar/bausystem/features/detonator/DetonatorListener.java | 1 - 1 file changed, 1 deletion(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/detonator/DetonatorListener.java b/BauSystem_Main/src/de/steamwar/bausystem/features/detonator/DetonatorListener.java index 53a77ce0..8b6b91da 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/detonator/DetonatorListener.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/detonator/DetonatorListener.java @@ -38,7 +38,6 @@ import org.bukkit.event.player.PlayerItemHeldEvent; import org.bukkit.event.player.PlayerMoveEvent; import org.bukkit.event.player.PlayerSwapHandItemsEvent; -import java.util.ArrayList; import java.util.HashSet; import java.util.List; import java.util.Set; From e635f76c9d3dae597660b76422db8e0dbf55df50 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Tue, 12 Oct 2021 21:34:41 +0200 Subject: [PATCH 12/12] Add tinyprotocol Signed-off-by: yoyosource --- .../features/other/NoClipCommand.java | 23 +++++++++---------- 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/other/NoClipCommand.java b/BauSystem_Main/src/de/steamwar/bausystem/features/other/NoClipCommand.java index 9cb262c9..ae2034b7 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/other/NoClipCommand.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/other/NoClipCommand.java @@ -54,22 +54,21 @@ public class NoClipCommand extends SWCommand implements Listener { private static final Object updateGamemode = playerInfoActionClass.getEnumConstants()[1]; private static final Reflection.FieldAccessor playerInfoData = Reflection.getField(playerInfoPacket, List.class, 0); private static final Class playerInfoDataClass = Reflection.getClass("{nms}.PacketPlayOutPlayerInfo$PlayerInfoData"); - private static final Class enumGamemode = Reflection.getClass(Core.getVersion() > 9 ? "{nms}.EnumGamemode" : "{nms}.WorldSettings$EnumGamemode"); - public static final Object creative = enumGamemode.getEnumConstants()[2]; + private static final Class enumGamemode = Reflection.getClass("{nms}.EnumGamemode"); private static final Object spectator = enumGamemode.getEnumConstants()[4]; private static final Class iChatBaseComponent = Reflection.getClass("{nms}.IChatBaseComponent"); private static final Reflection.ConstructorInvoker playerInfoDataConstructor = Reflection.getConstructor(playerInfoDataClass, playerInfoPacket, GameProfile.class, int.class, enumGamemode, iChatBaseComponent); - public static final Class gameStateChange = Reflection.getClass("{nms}.PacketPlayOutGameStateChange"); + private static final Class gameStateChange = Reflection.getClass("{nms}.PacketPlayOutGameStateChange"); private static final Reflection.FieldAccessor integerFieldAccessor = Reflection.getField(gameStateChange, int.class, 0); private static final Reflection.FieldAccessor floatFieldAccessor = Reflection.getField(gameStateChange, float.class, 0); - public static final Class position = Reflection.getClass("{nms}.PacketPlayInFlying$PacketPlayInPosition"); - public static final Class positionLook = Reflection.getClass("{nms}.PacketPlayInFlying$PacketPlayInPositionLook"); - public static final Class useItem = Reflection.getClass("{nms}.PacketPlayInUseItem"); - public static final Class blockDig = Reflection.getClass("{nms}.PacketPlayInBlockDig"); - public static final Class windowClick = Reflection.getClass("{nms}.PacketPlayInWindowClick"); + private static final Class position = Reflection.getClass("{nms}.PacketPlayInFlying$PacketPlayInPosition"); + private static final Class positionLook = Reflection.getClass("{nms}.PacketPlayInFlying$PacketPlayInPositionLook"); + private static final Class useItem = Reflection.getClass("{nms}.PacketPlayInUseItem"); + private static final Class blockDig = Reflection.getClass("{nms}.PacketPlayInBlockDig"); + private static final Class windowClick = Reflection.getClass("{nms}.PacketPlayInWindowClick"); @Getter private static final List NOCLIPS = new ArrayList<>(); @@ -118,7 +117,7 @@ public class NoClipCommand extends SWCommand implements Listener { NOCLIPS.add(player); BauSystem.MESSAGE.send("OTHER_NOCLIP_SLOT_INFO", player); ProtocolAPI.tinyProtocol.sendPacket(player, gameStateChangeObject); - pseudoSpectator(player, false); + pseudoSpectator(player); } } @@ -155,11 +154,11 @@ public class NoClipCommand extends SWCommand implements Listener { } } - public static void pseudoSpectator(Player player, boolean enable) { - ProtocolAPI.tinyProtocol.sendPacket(player, playerInfoPacket(updateGamemode, new GameProfile(player.getUniqueId(), player.getName()), enable ? creative : spectator)); + private static void pseudoSpectator(Player player) { + ProtocolAPI.tinyProtocol.sendPacket(player, playerInfoPacket(updateGamemode, new GameProfile(player.getUniqueId(), player.getName()), spectator)); } - public static Object playerInfoPacket(Object action, GameProfile profile, Object mode) { + private static Object playerInfoPacket(Object action, GameProfile profile, Object mode) { Object packet = playerInfoConstructor.invoke(); playerInfoAction.set(packet, action); playerInfoData.set(packet, Collections.singletonList(playerInfoDataConstructor.invoke(packet, profile, 0, mode, null)));