From dce547792a90def85b4cc829caeab8afc476a7f7 Mon Sep 17 00:00:00 2001 From: Dan Mulloy Date: Mon, 16 Jul 2018 13:10:41 -0400 Subject: [PATCH] Tweak tab completion for 1.13 Needs to be re-imagined at some point, but it partially works --- .../mineplex/core/common/util/UtilEnt.java | 15 +-- .../mineplex/core/command/CommandCenter.java | 124 ++++++++++-------- 2 files changed, 71 insertions(+), 68 deletions(-) diff --git a/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilEnt.java b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilEnt.java index 9712875a0..d6f7269a5 100644 --- a/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilEnt.java +++ b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilEnt.java @@ -1075,18 +1075,9 @@ public class UtilEnt public static void registerEntityType(Class customClass, EntityType entityType, String name) throws NoSuchMethodException, InvocationTargetException, IllegalAccessException, NoSuchFieldException { - Field cField = EntityTypes.class.getDeclaredField("c"); - Field eField = EntityTypes.class.getDeclaredField("e"); - - cField.setAccessible(true); - eField.setAccessible(true); - - ((Map) cField.get(null)).remove(name); - ((Map) eField.get(null)).remove((int) entityType.getTypeId()); - - Method method = EntityTypes.class.getDeclaredMethod("a", Class.class, String.class, int.class); - method.setAccessible(true); - method.invoke(null, customClass, name, entityType.getTypeId()); + EntityTypes.getNameToClassMap().remove(name); + EntityTypes.getIdToClassMap().remove((int) entityType.getTypeId()); + EntityTypes.register(customClass, name, (int) entityType.getTypeId()); } public static void spawnEntity(net.minecraft.server.v1_8_R3.Entity entity, Location location) diff --git a/Plugins/Mineplex.Core/src/mineplex/core/command/CommandCenter.java b/Plugins/Mineplex.Core/src/mineplex/core/command/CommandCenter.java index a6d494381..96b2449c2 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/command/CommandCenter.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/command/CommandCenter.java @@ -11,6 +11,7 @@ import java.util.Set; import java.util.UUID; import java.util.concurrent.atomic.AtomicIntegerFieldUpdater; +import net.minecraft.server.v1_8_R3.EntityPlayer; import net.minecraft.server.v1_8_R3.PacketPlayInTabComplete; import net.minecraft.server.v1_8_R3.PacketPlayOutTabComplete; import net.minecraft.server.v1_8_R3.PlayerConnection; @@ -22,6 +23,7 @@ import org.bukkit.event.player.PlayerCommandPreprocessEvent; import org.bukkit.plugin.java.JavaPlugin; import com.google.common.collect.Lists; +import com.mineplex.ProtocolVersion; import mineplex.core.Managers; import mineplex.core.account.CoreClientManager; @@ -198,78 +200,88 @@ public class CommandCenter implements Listener, IPacketHandler { if (packetInfo.getPacket() instanceof PacketPlayInTabComplete) { - PacketPlayInTabComplete packet = (PacketPlayInTabComplete) packetInfo.getPacket(); + EntityPlayer nmsPlayer = ((CraftPlayer) packetInfo.getPlayer()).getHandle(); + if (nmsPlayer.getProtocol() >= ProtocolVersion.v1_13) + { + // TODO this logic needs to be re-tooled for the new system + return; + } + // System.out.println("[Plugin] Handling tab complete packet"); + PacketPlayInTabComplete packet = (PacketPlayInTabComplete) packetInfo.getPacket(); String message = packet.a(); - if (message.startsWith("/")) + packetInfo.setCancelled(true); + + PlayerConnection playerConnection = nmsPlayer.playerConnection; + + if (chatSpamField.addAndGet(playerConnection, 10) > 500 && !packetInfo.getPlayer().isOp()) { - packetInfo.setCancelled(true); + playerConnection.disconnect("disconnect.spam"); + return; + } - PlayerConnection playerConnection = ((CraftPlayer) packetInfo.getPlayer()).getHandle().playerConnection; + Set results = new HashSet<>(); - if (chatSpamField.addAndGet(playerConnection, 10) > 500 && !packetInfo.getPlayer().isOp()) + String commandName = message.startsWith("/") ? message.substring(1) : message; + String[] args = new String[0]; + + if (commandName.contains(" ")) + { + String[] splits = commandName.split(" ", -1); + commandName = splits[0]; + args = new String[splits.length - 1]; + System.arraycopy(splits, 1, args, 0, args.length); + } + + // System.out.println("Handling tab complete for " + packetInfo.getPlayer().getName() + " " + commandName + " " + Arrays.toString(args)); + + if (args.length > 0) + { + // System.out.println("Path 1"); + ICommand command = Commands.get(commandName.toLowerCase()); + + if (command != null) { - playerConnection.disconnect("disconnect.spam"); - return; - } - - Set results = new HashSet<>(); - - String commandName = message.substring(1); - String[] args = new String[0]; - - if (commandName.contains(" ")) - { - String[] splits = commandName.split(" ", -1); - commandName = splits[0]; - args = new String[splits.length - 1]; - System.arraycopy(splits, 1, args, 0, args.length); - } - -// System.out.println("Handling tab complete for " + packetInfo.getPlayer().getName() + " " + commandName + " " + Arrays.toString(args) + " " + endsWithSpace); - - if (args.length > 0) - { -// System.out.println("Path 1"); - ICommand command = Commands.get(commandName.toLowerCase()); - - if (command != null) + if (ClientManager.Get(packetInfo.getPlayer()).hasPermission(command.getPermission()) + || UtilPlayer.isCommandAllowed(packetInfo.getPlayer(), commandName.toLowerCase())) { - if (ClientManager.Get(packetInfo.getPlayer()).hasPermission(command.getPermission()) - || UtilPlayer.isCommandAllowed(packetInfo.getPlayer(), commandName.toLowerCase())) + List tmpres = command.onTabComplete(packetInfo.getPlayer(), commandName.toLowerCase(), args); + if (tmpres != null) { - List tmpres = command.onTabComplete(packetInfo.getPlayer(), commandName.toLowerCase(), args); - if (tmpres != null) + results.addAll(tmpres); + } + } + } + } + // tab complete commands? + else + { + // System.out.println("Path 2"); + for (ICommand command : Commands.values()) + { + if (ClientManager.Get(packetInfo.getPlayer()).hasPermission(command.getPermission()) + || UtilPlayer.isCommandAllowed(packetInfo.getPlayer(), commandName.toLowerCase())) + { + for (String alias : command.Aliases()) + { + if (alias.startsWith(commandName)) { - results.addAll(tmpres); - } - } - } - } - // tab complete commands? - else - { -// System.out.println("Path 2"); - for (ICommand command : Commands.values()) - { - if (ClientManager.Get(packetInfo.getPlayer()).hasPermission(command.getPermission()) - || UtilPlayer.isCommandAllowed(packetInfo.getPlayer(), commandName.toLowerCase())) - { - for (String alias : command.Aliases()) - { - if (alias.startsWith(commandName)) - { - results.add("/" + alias.toLowerCase()); - } + results.add("/" + alias.toLowerCase()); } } } } + } -// System.out.println("Final results: " + results); + // System.out.println("Final results: " + results); - playerConnection.sendPacket(new PacketPlayOutTabComplete(results.toArray(new String[results.size()]))); + if (nmsPlayer.getProtocol() < ProtocolVersion.v1_13) + { + playerConnection.sendPacket(new PacketPlayOutTabComplete(results.toArray(new String[0]))); + } else + { + playerConnection.sendPacket(new PacketPlayOutTabComplete(packet.c(), packet.a(), results.toArray(new String[0]))); } } }