From 10c884dc649394ec2e42fb7d82d579fdb5d77016 Mon Sep 17 00:00:00 2001 From: Daniil Zao Date: Sun, 14 Jul 2024 18:10:59 +0300 Subject: [PATCH] Don't explode with a bunch of tasks --- .../ownormembased/RestrictCommands.java | 24 +++++++++---------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/src/wgextender/features/regionprotect/ownormembased/RestrictCommands.java b/src/wgextender/features/regionprotect/ownormembased/RestrictCommands.java index 6785494..ae98109 100644 --- a/src/wgextender/features/regionprotect/ownormembased/RestrictCommands.java +++ b/src/wgextender/features/regionprotect/ownormembased/RestrictCommands.java @@ -54,20 +54,18 @@ public RestrictCommands(Config config) { } private void commandRecheckTask(Config config) { - Bukkit.getAsyncScheduler().runAtFixedRate(WGExtender.getInstance(), (task) -> { - if (!config.restrictCommandsInRegionEnabled) { - return; - } - Set 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 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)