Skip to content

Commit

Permalink
Update list of commands for players and commandblocks upon register_c…
Browse files Browse the repository at this point in the history
…ommand()
  • Loading branch information
PseudoKnight committed Aug 23, 2018
1 parent a42c09c commit 36ee133
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 4 deletions.
Expand Up @@ -6,6 +6,10 @@
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import com.laytonsmith.commandhelper.CommandHelperPlugin;
import org.bukkit.Bukkit;
import org.bukkit.Server;
import org.bukkit.command.Command;
import org.bukkit.command.SimpleCommandMap;

Expand Down Expand Up @@ -52,12 +56,22 @@ public List<MCCommand> getCommands() {

@Override
public boolean register(String fallback, MCCommand cmd) {
return scm.register(fallback, ((BukkitMCCommand) cmd).cmd);
boolean success = scm.register(fallback, ((BukkitMCCommand) cmd).cmd);
if(!CommandHelperPlugin.self.isFirstLoad()) {
Server s = Bukkit.getServer();
ReflectionUtils.invokeMethod(s.getClass(), s, "syncCommands");
}
return success;
}

@Override
public boolean register(String label, String fallback, MCCommand cmd) {
return scm.register(label, fallback, ((BukkitMCCommand) cmd).cmd);
boolean success = scm.register(label, fallback, ((BukkitMCCommand) cmd).cmd);
if(!CommandHelperPlugin.self.isFirstLoad()) {
Server s = Bukkit.getServer();
ReflectionUtils.invokeMethod(s.getClass(), s, "syncCommands");
}
return success;
}

@SuppressWarnings("unchecked")
Expand Down
Expand Up @@ -110,7 +110,7 @@ public class CommandHelperPlugin extends JavaPlugin {
public final ExecutionQueue executionQueue = new MethodScriptExecutionQueue("CommandHelperExecutionQueue", "default");
public PersistenceNetwork persistenceNetwork;
public Profiles profiles;
//public boolean firstLoad = true;
private boolean firstLoad = true;
public long interpreterUnlockedUntil = 0;
private Thread loadingThread;
/**
Expand Down Expand Up @@ -364,7 +364,7 @@ public Integer call() throws Exception {
CommandHelperFileLocations.getDefault().getLocalPackagesDirectory(),
CommandHelperFileLocations.getDefault().getPreferencesFile(),
new File(CommandHelperFileLocations.getDefault().getConfigDirectory(), mainFile), this);
ac.reload(null, null, true);
ac.reload(null, null, this.firstLoad);

//Clear out our hostname cache
hostnameLookupCache = new ConcurrentHashMap<>();
Expand Down Expand Up @@ -396,9 +396,15 @@ public Thread newThread(Runnable r) {
playerListener.loadGlobalAliases();
interpreterListener.reload();

firstLoad = false;

Static.getLogger().log(Level.INFO, "[CommandHelper] CommandHelper {0} enabled", getDescription().getVersion());
}

public boolean isFirstLoad() {
return this.firstLoad;
}

public static AliasCore getCore() {
return ac;
}
Expand Down

0 comments on commit 36ee133

Please sign in to comment.