Plugin-side changes to fix tab complete

This commit is contained in:
Dan Mulloy 2018-07-25 13:19:54 -04:00 committed by Alexander Meech
parent c999e31fdd
commit 72a81ad362
2 changed files with 85 additions and 60 deletions

View File

@ -13,19 +13,23 @@ 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.PacketPlayOutDeclareCommands;
import net.minecraft.server.v1_8_R3.PacketPlayOutTabComplete;
import net.minecraft.server.v1_8_R3.PlayerConnection;
import org.bukkit.craftbukkit.v1_8_R3.entity.CraftPlayer;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.plugin.java.JavaPlugin;
import com.google.common.collect.Lists;
import com.mineplex.ProtocolVersion;
import mineplex.core.Managers;
import mineplex.core.account.CoreClient;
import mineplex.core.account.CoreClientManager;
import mineplex.core.account.permissions.Permission;
import mineplex.core.account.permissions.PermissionGroup;
@ -195,6 +199,32 @@ public class CommandCenter implements Listener, IPacketHandler
return Commands;
}
private List<String> getCommands(Player player)
{
CoreClient client = ClientManager.Get(player);
List<String> commands = new ArrayList<>();
for (Map.Entry<String, ICommand> entry : Commands.entrySet())
{
if (client.hasPermission(entry.getValue().getPermission()))
{
commands.add(entry.getKey());
}
}
return commands;
}
@EventHandler
public void onPlayerJoin(PlayerJoinEvent event)
{
int protocol = UtilPlayer.getProtocol(event.getPlayer());
if (protocol >= ProtocolVersion.v1_13)
{
List<String> commands = getCommands(event.getPlayer());
UtilPlayer.sendPacket(event.getPlayer(), new PacketPlayOutDeclareCommands(commands));
}
}
@Override
public void handle(PacketInfo packetInfo)
{
@ -203,18 +233,17 @@ public class CommandCenter implements Listener, IPacketHandler
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())
{
playerConnection.disconnect("disconnect.spam");
@ -223,7 +252,7 @@ public class CommandCenter implements Listener, IPacketHandler
Set<String> results = new HashSet<>();
String commandName = message.startsWith("/") ? message.substring(1) : message;
String commandName = message.substring(1);
String[] args = new String[0];
if (commandName.contains(" "))
@ -234,11 +263,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));
// System.out.println("Handling tab complete for " + packetInfo.getPlayer().getName() + " " + commandName + " " + Arrays.toString(args) + " " + endsWithSpace);
if (args.length > 0)
{
// System.out.println("Path 1");
// System.out.println("Path 1");
ICommand command = Commands.get(commandName.toLowerCase());
if (command != null)
@ -246,7 +275,8 @@ public class CommandCenter implements Listener, IPacketHandler
if (ClientManager.Get(packetInfo.getPlayer()).hasPermission(command.getPermission())
|| UtilPlayer.isCommandAllowed(packetInfo.getPlayer(), commandName.toLowerCase()))
{
List<String> tmpres = command.onTabComplete(packetInfo.getPlayer(), commandName.toLowerCase(), args);
List<String> tmpres = command
.onTabComplete(packetInfo.getPlayer(), commandName.toLowerCase(), args);
if (tmpres != null)
{
results.addAll(tmpres);
@ -257,7 +287,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())
@ -274,14 +304,9 @@ public class CommandCenter implements Listener, IPacketHandler
}
}
// System.out.println("Final results: " + results);
// System.out.println("Final results: " + results);
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])));
}
}
}

View File

@ -596,7 +596,7 @@ public abstract class Challenge implements Listener
{
if (block != Blocks.AIR)
{
chunksection = chunk.getSections()[y >> 4] = new ChunkSection(y >> 4 << 4, !nmsWorld.worldProvider.o());
chunksection = chunk.getSections()[y >> 4] = new ChunkSection(y >> 4 << 4, chunk, !nmsWorld.worldProvider.o());
}
}
chunksection.setType(i, j & 15, k, ibd);