Tweak tab completion for 1.13

Needs to be re-imagined at some point, but it partially works
This commit is contained in:
Dan Mulloy 2018-07-16 13:10:41 -04:00 committed by Alexander Meech
parent d2636afb48
commit dce547792a
2 changed files with 71 additions and 68 deletions

View File

@ -1075,18 +1075,9 @@ public class UtilEnt
public static void registerEntityType(Class<? extends net.minecraft.server.v1_8_R3.Entity> 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)

View File

@ -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,15 +200,20 @@ 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 = ((CraftPlayer) packetInfo.getPlayer()).getHandle().playerConnection;
PlayerConnection playerConnection = nmsPlayer.playerConnection;
if (chatSpamField.addAndGet(playerConnection, 10) > 500 && !packetInfo.getPlayer().isOp())
{
@ -216,7 +223,7 @@ public class CommandCenter implements Listener, IPacketHandler
Set<String> results = new HashSet<>();
String commandName = message.substring(1);
String commandName = message.startsWith("/") ? message.substring(1) : message;
String[] args = new String[0];
if (commandName.contains(" "))
@ -227,11 +234,11 @@ public class CommandCenter implements Listener, IPacketHandler
System.arraycopy(splits, 1, args, 0, args.length);
}
// System.out.println("Handling tab complete for " + packetInfo.getPlayer().getName() + " " + commandName + " " + Arrays.toString(args) + " " + endsWithSpace);
// System.out.println("Handling tab complete for " + packetInfo.getPlayer().getName() + " " + commandName + " " + Arrays.toString(args));
if (args.length > 0)
{
// System.out.println("Path 1");
// System.out.println("Path 1");
ICommand command = Commands.get(commandName.toLowerCase());
if (command != null)
@ -250,7 +257,7 @@ public class CommandCenter implements Listener, IPacketHandler
// tab complete commands?
else
{
// System.out.println("Path 2");
// System.out.println("Path 2");
for (ICommand command : Commands.values())
{
if (ClientManager.Get(packetInfo.getPlayer()).hasPermission(command.getPermission())
@ -267,9 +274,14 @@ public class CommandCenter implements Listener, IPacketHandler
}
}
// 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])));
}
}
}