Skip to content

Commit

Permalink
Fix Command Syncing CME (#6763)
Browse files Browse the repository at this point in the history
  • Loading branch information
APickledWalrus authored Jun 6, 2024
1 parent b9a7ab8 commit 23cc26b
Showing 1 changed file with 17 additions and 6 deletions.
23 changes: 17 additions & 6 deletions src/main/java/ch/njol/skript/structures/StructCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,9 @@
@Since("1.0")
public class StructCommand extends Structure {

// Paper versions with the new command system need a delay before syncing commands or a CME will occur.
private static final boolean DELAY_COMMAND_SYNCING = Skript.classExists("io.papermc.paper.command.brigadier.Commands");

public static final Priority PRIORITY = new Priority(500);

private static final Pattern COMMAND_PATTERN = Pattern.compile("(?i)^command\\s+/?(\\S+)\\s*(\\s+(.+))?$");
Expand Down Expand Up @@ -315,7 +318,7 @@ public boolean load() {

@Override
public boolean postLoad() {
attemptCommandSync();
scheduleCommandSync();
return true;
}

Expand All @@ -328,20 +331,28 @@ public void unload() {

@Override
public void postUnload() {
attemptCommandSync();
scheduleCommandSync();
}

private void attemptCommandSync() {
private void scheduleCommandSync() {
if (SYNC_COMMANDS.get()) {
SYNC_COMMANDS.set(false);
if (CommandReloader.syncCommands(Bukkit.getServer())) {
Skript.debug("Commands synced to clients");
if (DELAY_COMMAND_SYNCING) {
Bukkit.getScheduler().runTask(Skript.getInstance(), this::forceCommandSync);
} else {
Skript.debug("Commands changed but not synced to clients (normal on 1.12 and older)");
forceCommandSync();
}
}
}

private void forceCommandSync() {
if (CommandReloader.syncCommands(Bukkit.getServer())) {
Skript.debug("Commands synced to clients");
} else {
Skript.debug("Commands changed but not synced to clients (normal on 1.12 and older)");
}
}

@Override
public Priority getPriority() {
return PRIORITY;
Expand Down

0 comments on commit 23cc26b

Please sign in to comment.