Skip to content

Commit

Permalink
Don't explode with a bunch of tasks
Browse files Browse the repository at this point in the history
  • Loading branch information
imDaniX committed Jul 14, 2024
1 parent 20b81f7 commit 10c884d
Showing 1 changed file with 11 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,20 +54,18 @@ public RestrictCommands(Config config) {
}

private void commandRecheckTask(Config config) {
Bukkit.getAsyncScheduler().runAtFixedRate(WGExtender.getInstance(), (task) -> {
if (!config.restrictCommandsInRegionEnabled) {
return;
}
Set<String> computedRestrictedCommands = new HashSet<>();
for (String restrictedCommand : config.restrictedCommandsInRegion) {
String[] split = SPACE_PATTERN.split(restrictedCommand, 2);
String toAdd = split.length > 1 ? split[1] : "";
for (String alias : CommandUtils.getCommandAliases(split[0].toLowerCase(Locale.ROOT))) {
computedRestrictedCommands.add(alias + toAdd);
}
if (!config.restrictCommandsInRegionEnabled) {
return;
}
Set<String> computedRestrictedCommands = new HashSet<>();
for (String restrictedCommand : config.restrictedCommandsInRegion) {
String[] split = SPACE_PATTERN.split(restrictedCommand, 2);
String toAdd = split.length > 1 ? split[1] : "";
for (String alias : CommandUtils.getCommandAliases(split[0].toLowerCase(Locale.ROOT))) {
computedRestrictedCommands.add(alias + toAdd);
}
restrictedCommands = computedRestrictedCommands;
}, TICK, TICK * 100, TimeUnit.MILLISECONDS);
}
restrictedCommands = computedRestrictedCommands;
}

@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
Expand Down

0 comments on commit 10c884d

Please sign in to comment.