Plugin-side changes to fix tab complete
This commit is contained in:
parent
c999e31fdd
commit
72a81ad362
@ -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.EntityPlayer;
|
||||||
import net.minecraft.server.v1_8_R3.PacketPlayInTabComplete;
|
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.PacketPlayOutTabComplete;
|
||||||
import net.minecraft.server.v1_8_R3.PlayerConnection;
|
import net.minecraft.server.v1_8_R3.PlayerConnection;
|
||||||
|
|
||||||
import org.bukkit.craftbukkit.v1_8_R3.entity.CraftPlayer;
|
import org.bukkit.craftbukkit.v1_8_R3.entity.CraftPlayer;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
import org.bukkit.event.Listener;
|
import org.bukkit.event.Listener;
|
||||||
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
|
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
|
||||||
|
import org.bukkit.event.player.PlayerJoinEvent;
|
||||||
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 com.mineplex.ProtocolVersion;
|
||||||
|
|
||||||
import mineplex.core.Managers;
|
import mineplex.core.Managers;
|
||||||
|
import mineplex.core.account.CoreClient;
|
||||||
import mineplex.core.account.CoreClientManager;
|
import mineplex.core.account.CoreClientManager;
|
||||||
import mineplex.core.account.permissions.Permission;
|
import mineplex.core.account.permissions.Permission;
|
||||||
import mineplex.core.account.permissions.PermissionGroup;
|
import mineplex.core.account.permissions.PermissionGroup;
|
||||||
@ -195,6 +199,32 @@ public class CommandCenter implements Listener, IPacketHandler
|
|||||||
return Commands;
|
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
|
@Override
|
||||||
public void handle(PacketInfo packetInfo)
|
public void handle(PacketInfo packetInfo)
|
||||||
{
|
{
|
||||||
@ -203,85 +233,80 @@ public class CommandCenter implements Listener, IPacketHandler
|
|||||||
EntityPlayer nmsPlayer = ((CraftPlayer) packetInfo.getPlayer()).getHandle();
|
EntityPlayer nmsPlayer = ((CraftPlayer) packetInfo.getPlayer()).getHandle();
|
||||||
if (nmsPlayer.getProtocol() >= ProtocolVersion.v1_13)
|
if (nmsPlayer.getProtocol() >= ProtocolVersion.v1_13)
|
||||||
{
|
{
|
||||||
// TODO this logic needs to be re-tooled for the new system
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// System.out.println("[Plugin] Handling tab complete packet");
|
|
||||||
PacketPlayInTabComplete packet = (PacketPlayInTabComplete) packetInfo.getPacket();
|
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");
|
packetInfo.setCancelled(true);
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
Set<String> results = new HashSet<>();
|
PlayerConnection playerConnection = nmsPlayer.playerConnection;
|
||||||
|
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)
|
|
||||||
{
|
{
|
||||||
if (ClientManager.Get(packetInfo.getPlayer()).hasPermission(command.getPermission())
|
playerConnection.disconnect("disconnect.spam");
|
||||||
|| UtilPlayer.isCommandAllowed(packetInfo.getPlayer(), commandName.toLowerCase()))
|
return;
|
||||||
{
|
|
||||||
List<String> tmpres = command.onTabComplete(packetInfo.getPlayer(), commandName.toLowerCase(), args);
|
|
||||||
if (tmpres != null)
|
|
||||||
{
|
|
||||||
results.addAll(tmpres);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
// tab complete commands?
|
Set<String> results = new HashSet<>();
|
||||||
else
|
|
||||||
{
|
String commandName = message.substring(1);
|
||||||
// System.out.println("Path 2");
|
String[] args = new String[0];
|
||||||
for (ICommand command : Commands.values())
|
|
||||||
|
if (commandName.contains(" "))
|
||||||
{
|
{
|
||||||
if (ClientManager.Get(packetInfo.getPlayer()).hasPermission(command.getPermission())
|
String[] splits = commandName.split(" ", -1);
|
||||||
|| UtilPlayer.isCommandAllowed(packetInfo.getPlayer(), commandName.toLowerCase()))
|
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)
|
||||||
{
|
{
|
||||||
for (String alias : command.Aliases())
|
if (ClientManager.Get(packetInfo.getPlayer()).hasPermission(command.getPermission())
|
||||||
|
|| UtilPlayer.isCommandAllowed(packetInfo.getPlayer(), commandName.toLowerCase()))
|
||||||
{
|
{
|
||||||
if (alias.startsWith(commandName))
|
List<String> tmpres = command
|
||||||
|
.onTabComplete(packetInfo.getPlayer(), commandName.toLowerCase(), args);
|
||||||
|
if (tmpres != null)
|
||||||
{
|
{
|
||||||
results.add("/" + alias.toLowerCase());
|
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());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// 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])));
|
playerConnection.sendPacket(new PacketPlayOutTabComplete(results.toArray(new String[0])));
|
||||||
} else
|
|
||||||
{
|
|
||||||
playerConnection.sendPacket(new PacketPlayOutTabComplete(packet.c(), packet.a(), results.toArray(new String[0])));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -596,7 +596,7 @@ public abstract class Challenge implements Listener
|
|||||||
{
|
{
|
||||||
if (block != Blocks.AIR)
|
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);
|
chunksection.setType(i, j & 15, k, ibd);
|
||||||
|
Loading…
Reference in New Issue
Block a user