diff --git a/Plugins/Mineplex.Core/src/mineplex/core/command/CommandCenter.java b/Plugins/Mineplex.Core/src/mineplex/core/command/CommandCenter.java index 96b2449c2..3588b7c79 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/command/CommandCenter.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/command/CommandCenter.java @@ -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 getCommands(Player player) + { + CoreClient client = ClientManager.Get(player); + List commands = new ArrayList<>(); + for (Map.Entry 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 commands = getCommands(event.getPlayer()); + UtilPlayer.sendPacket(event.getPlayer(), new PacketPlayOutDeclareCommands(commands)); + } + } + @Override public void handle(PacketInfo packetInfo) { @@ -203,85 +233,80 @@ 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(); - - packetInfo.setCancelled(true); - - PlayerConnection playerConnection = nmsPlayer.playerConnection; - - if (chatSpamField.addAndGet(playerConnection, 10) > 500 && !packetInfo.getPlayer().isOp()) + if (message.startsWith("/")) { - playerConnection.disconnect("disconnect.spam"); - return; - } + packetInfo.setCancelled(true); - Set results = new HashSet<>(); - - 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 playerConnection = nmsPlayer.playerConnection; + if (chatSpamField.addAndGet(playerConnection, 10) > 500 && !packetInfo.getPlayer().isOp()) { - 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) - { - results.addAll(tmpres); - } - } + playerConnection.disconnect("disconnect.spam"); + return; } - } - // tab complete commands? - else - { - // System.out.println("Path 2"); - for (ICommand command : Commands.values()) + + Set results = new HashSet<>(); + + String commandName = message.substring(1); + String[] args = new String[0]; + + if (commandName.contains(" ")) { - if (ClientManager.Get(packetInfo.getPlayer()).hasPermission(command.getPermission()) - || UtilPlayer.isCommandAllowed(packetInfo.getPlayer(), commandName.toLowerCase())) + 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) { - for (String alias : command.Aliases()) + if (ClientManager.Get(packetInfo.getPlayer()).hasPermission(command.getPermission()) + || UtilPlayer.isCommandAllowed(packetInfo.getPlayer(), commandName.toLowerCase())) { - if (alias.startsWith(commandName)) + List 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]))); - } else - { - playerConnection.sendPacket(new PacketPlayOutTabComplete(packet.c(), packet.a(), results.toArray(new String[0]))); } } } diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/mineware/challenge/Challenge.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/mineware/challenge/Challenge.java index 93ab39880..3bb693d75 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/mineware/challenge/Challenge.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/mineware/challenge/Challenge.java @@ -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);