From 81020af843bad2cba496e2316ada3b1c0a9bf6d9 Mon Sep 17 00:00:00 2001 From: ayunami2000 Date: Sun, 27 Aug 2023 09:59:07 -0400 Subject: [PATCH] Fix fake op permission level on world change. --- src/main/java/dev/plex/FalseOp.java | 10 +++++++- .../dev/plex/listener/PlayerListener.java | 24 +++++++++++++------ 2 files changed, 26 insertions(+), 8 deletions(-) diff --git a/src/main/java/dev/plex/FalseOp.java b/src/main/java/dev/plex/FalseOp.java index 9f463e0..4784611 100644 --- a/src/main/java/dev/plex/FalseOp.java +++ b/src/main/java/dev/plex/FalseOp.java @@ -7,6 +7,8 @@ import org.bukkit.Bukkit; public class FalseOp extends PlexModule { + private PlayerListener playerListener; + @Override public void enable() { @@ -15,11 +17,17 @@ public class FalseOp extends PlexModule PlexLog.error("The Plex-FalseOp module requires the ProtocolLib plugin to work."); return; } - registerListener(new PlayerListener()); + playerListener = new PlayerListener(); + registerListener(playerListener); } @Override public void disable() { + if (playerListener != null) + { + playerListener.cleanUp(); + playerListener = null; + } } } \ No newline at end of file diff --git a/src/main/java/dev/plex/listener/PlayerListener.java b/src/main/java/dev/plex/listener/PlayerListener.java index 287fdcb..224832c 100644 --- a/src/main/java/dev/plex/listener/PlayerListener.java +++ b/src/main/java/dev/plex/listener/PlayerListener.java @@ -19,7 +19,6 @@ import org.bukkit.event.block.Action; import org.bukkit.event.block.BlockBreakEvent; import org.bukkit.event.block.BlockPlaceEvent; import org.bukkit.event.player.PlayerInteractEvent; -import org.bukkit.event.player.PlayerJoinEvent; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.ItemMeta; import org.bukkit.util.Vector; @@ -27,19 +26,30 @@ import org.bukkit.util.Vector; public class PlayerListener extends PlexListener { private final ProtocolManager protocolManager; + private final PacketListener packetListener; public PlayerListener() { protocolManager = ProtocolLibrary.getProtocolManager(); + packetListener = new PacketAdapter(plugin, ListenerPriority.NORMAL, PacketType.Play.Server.ENTITY_STATUS) + { + @Override + public void onPacketSending(PacketEvent event) + { + PacketContainer packet = event.getPacket(); + byte b; + if (packet.getIntegers().getValues().get(0) == event.getPlayer().getEntityId() && (b = packet.getBytes().getValues().get(0)) >= (byte) 24 && b <= (byte) 27) + { + packet.getBytes().write(0, (byte) 28); + } + } + }; + protocolManager.addPacketListener(packetListener); } - @EventHandler - public void onJoin(PlayerJoinEvent event) + public void cleanUp() { - PacketContainer packet = new PacketContainer(PacketType.Play.Server.ENTITY_STATUS); - packet.getIntegers().write(0, event.getPlayer().getEntityId()); - packet.getBytes().write(0, (byte) 28); - protocolManager.sendServerPacket(event.getPlayer(), packet); + protocolManager.removePacketListener(packetListener); } @EventHandler