Skip to content

Commit

Permalink
command script late init
Browse files Browse the repository at this point in the history
  • Loading branch information
mcmonkey4eva committed Jun 15, 2021
1 parent 9712ddd commit eb842f6
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 4 deletions.
Expand Up @@ -139,6 +139,7 @@ public class CommandScriptContainer extends ScriptContainer {

public CommandScriptContainer(YamlConfiguration configurationSection, String scriptContainerName) {
super(configurationSection, scriptContainerName);
CommandScriptHelper.init();
CommandScriptHelper.commandScripts.put(getName(), this);
if (contains("tab complete")) {
hasProcStyleTabComplete = true;
Expand Down
Expand Up @@ -32,12 +32,25 @@ public class CommandScriptHelper implements Listener {
public static Map<String, HelpTopic> helpTopics = null;
public static final Map<String, CommandScriptContainer> commandScripts = new HashMap<>();
public static boolean hasCommandInformation = true;
public static CommandScriptHelper instance;
public static boolean isInitialized = false;

public CommandScriptHelper() {
instance = this;
if (Settings.cache_commandScriptAutoInit) {
init();
}
}

public static void init() {
if (isInitialized) {
return;
}
isInitialized = true;
try {
Server server = Bukkit.getServer();

server.getPluginManager().registerEvents(this, Denizen.getInstance());
server.getPluginManager().registerEvents(instance, Denizen.getInstance());

// Get the CommandMap for the server
Field commandMapField = server.getClass().getDeclaredField("commandMap");
Expand Down Expand Up @@ -136,7 +149,7 @@ public static void syncDenizenCommands() {
* @see #registerDenizenCommand(DenizenCommand)
*/
public static void removeDenizenCommands() {
if (!hasCommandInformation) {
if (!hasCommandInformation || !isInitialized) {
return;
}
for (String command : denizenCommands.keySet()) {
Expand Down Expand Up @@ -188,7 +201,7 @@ public static void registerDenizenCommand(DenizenCommand command) {
* @param command the command.
* @param helpTopic the help topic for the command or command alias.
*/
private static void forceCommand(String name, DenizenCommand command, HelpTopic helpTopic) {
public static void forceCommand(String name, DenizenCommand command, HelpTopic helpTopic) {
// Override any existing non-DenizenCommand commands, but save them just in case
// TODO: use fallback prefixes for overridden commands instead?
if (knownCommands.containsKey(name)) {
Expand Down
Expand Up @@ -90,6 +90,7 @@ public static void refillCache() {
cache_tagTimeoutUnsafe = config.getBoolean("Tags.Timeout when unsafe", false);
cache_warningRate = config.getLong("Tags.Warning rate", 10000);
cache_packetInterception = config.getBoolean("Packets.Interception", true);
cache_commandScriptAutoInit = config.getBoolean("Scripts.Command.Auto init", false);
PlayerFlagHandler.cacheTimeoutSeconds = config.getLong("Saves.Offline player cache timeout", 300);
PlayerFlagHandler.asyncPreload = config.getBoolean("Saves.Load async on login", true);
MapTagBasedFlagTracker.skipAllCleanings = config.getBoolean("Saves.Skip flag cleaning", false);
Expand All @@ -114,7 +115,8 @@ public static void refillCache() {
cache_healthTraitBlockDrops, cache_chatAsynchronous, cache_chatMustSeeNPC, cache_chatMustLookAtNPC,
cache_chatGloballyIfFailedChatTriggers, cache_chatGloballyIfNoChatTriggers,
cache_chatGloballyIfUninteractable, cache_worldScriptChatEventAsynchronous,
cache_tagTimeoutSilent, cache_packetInterception, cache_tagTimeoutUnsafe, cache_createWorldSymbols;
cache_tagTimeoutSilent, cache_packetInterception, cache_tagTimeoutUnsafe, cache_createWorldSymbols,
cache_commandScriptAutoInit;

public static String cache_getAlternateScriptPath, cache_scriptQueueSpeed, cache_healthTraitRespawnDelay,
cache_engageTimeoutInSeconds, cache_chatMultipleTargetsFormat, cache_chatNoTargetFormat,
Expand Down
5 changes: 5 additions & 0 deletions plugin/src/main/resources/config.yml
Expand Up @@ -55,6 +55,11 @@ Scripts:
Alternative folder path: 'plugins/Denizen'
# What character encoding to use. 'default' indicates system default, 'utf8' is suggested as a preferred encoding in most cases.
Encoding: utf8
Command:
# If set to 'true', the command scripts engine will automatically initialize when the server loads.
# If false, it will only initialize once at least one command script is loaded.
# This defaults to false to avoid any possible interference on servers that don't use command scripts.
Auto init: false

# The default options for new Denizen NPCs

Expand Down

0 comments on commit eb842f6

Please sign in to comment.