From c71ea517a279b3b1b5c2a561b8ba631e7a0c3d7c Mon Sep 17 00:00:00 2001 From: MrGazdag <44264503+MrGazdag@users.noreply.github.com> Date: Thu, 12 Aug 2021 03:53:49 +0200 Subject: [PATCH] add refreshCommands() --- .../net/minestom/server/entity/Player.java | 22 +++++++++++-------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/src/main/java/net/minestom/server/entity/Player.java b/src/main/java/net/minestom/server/entity/Player.java index 24f27b385..52b9e5672 100644 --- a/src/main/java/net/minestom/server/entity/Player.java +++ b/src/main/java/net/minestom/server/entity/Player.java @@ -246,15 +246,8 @@ public class Player extends LivingEntity implements CommandSender, Localizable, this.playerConnection.sendPacket(player.getAddPlayerToList()); } - // Commands start - { - CommandManager commandManager = MinecraftServer.getCommandManager(); - DeclareCommandsPacket declareCommandsPacket = commandManager.createDeclareCommandsPacket(this); - - playerConnection.sendPacket(declareCommandsPacket); - } - // Commands end - + // Commands + refreshCommands(); // Recipes start { @@ -431,6 +424,17 @@ public class Player extends LivingEntity implements CommandSender, Localizable, // Runnable called when teleportation is successful (after loading and sending necessary chunk) teleport(respawnEvent.getRespawnPosition()).thenRun(this::refreshAfterTeleport); } + + /** + * Refreshes the command list for this player. This checks the + * {@link net.minestom.server.command.builder.condition.CommandCondition}s + * again, and any changes will be visible to the player. + */ + public void refreshCommands() { + CommandManager commandManager = MinecraftServer.getCommandManager(); + DeclareCommandsPacket declareCommandsPacket = commandManager.createDeclareCommandsPacket(this); + playerConnection.sendPacket(declareCommandsPacket); + } @Override public boolean isOnGround() {