Tweak tab completion for 1.13
Needs to be re-imagined at some point, but it partially works
This commit is contained in:
parent
d2636afb48
commit
dce547792a
@ -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
|
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");
|
EntityTypes.getNameToClassMap().remove(name);
|
||||||
Field eField = EntityTypes.class.getDeclaredField("e");
|
EntityTypes.getIdToClassMap().remove((int) entityType.getTypeId());
|
||||||
|
EntityTypes.register(customClass, name, (int) entityType.getTypeId());
|
||||||
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());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void spawnEntity(net.minecraft.server.v1_8_R3.Entity entity, Location location)
|
public static void spawnEntity(net.minecraft.server.v1_8_R3.Entity entity, Location location)
|
||||||
|
@ -11,6 +11,7 @@ import java.util.Set;
|
|||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import java.util.concurrent.atomic.AtomicIntegerFieldUpdater;
|
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.PacketPlayInTabComplete;
|
||||||
import net.minecraft.server.v1_8_R3.PacketPlayOutTabComplete;
|
import net.minecraft.server.v1_8_R3.PacketPlayOutTabComplete;
|
||||||
import net.minecraft.server.v1_8_R3.PlayerConnection;
|
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 org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
|
||||||
import com.google.common.collect.Lists;
|
import com.google.common.collect.Lists;
|
||||||
|
import com.mineplex.ProtocolVersion;
|
||||||
|
|
||||||
import mineplex.core.Managers;
|
import mineplex.core.Managers;
|
||||||
import mineplex.core.account.CoreClientManager;
|
import mineplex.core.account.CoreClientManager;
|
||||||
@ -198,78 +200,88 @@ public class CommandCenter implements Listener, IPacketHandler
|
|||||||
{
|
{
|
||||||
if (packetInfo.getPacket() instanceof PacketPlayInTabComplete)
|
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();
|
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<String> 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");
|
if (ClientManager.Get(packetInfo.getPlayer()).hasPermission(command.getPermission())
|
||||||
return;
|
|| UtilPlayer.isCommandAllowed(packetInfo.getPlayer(), commandName.toLowerCase()))
|
||||||
}
|
|
||||||
|
|
||||||
Set<String> 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())
|
List<String> tmpres = command.onTabComplete(packetInfo.getPlayer(), commandName.toLowerCase(), args);
|
||||||
|| UtilPlayer.isCommandAllowed(packetInfo.getPlayer(), commandName.toLowerCase()))
|
if (tmpres != null)
|
||||||
{
|
{
|
||||||
List<String> tmpres = command.onTabComplete(packetInfo.getPlayer(), commandName.toLowerCase(), args);
|
results.addAll(tmpres);
|
||||||
if (tmpres != null)
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// 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);
|
results.add("/" + alias.toLowerCase());
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// 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());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// 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])));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user