diff --git a/common/src/main/java/dev/xhyrom/lighteco/common/command/CommandManager.java b/common/src/main/java/dev/xhyrom/lighteco/common/command/CommandManager.java index a4729dc..f04c600 100644 --- a/common/src/main/java/dev/xhyrom/lighteco/common/command/CommandManager.java +++ b/common/src/main/java/dev/xhyrom/lighteco/common/command/CommandManager.java @@ -60,7 +60,7 @@ public class CommandManager { } public void execute(CommandSender sender, String name, String[] args) { - if (locks.contains(sender.getUniqueId())) { + if (!sender.isConsole() && locks.contains(sender.getUniqueId())) { sender.sendMessage(MiniMessage.miniMessage().deserialize( this.plugin.getConfig().messages.wait )); @@ -73,7 +73,8 @@ public class CommandManager { source ); - locks.add(sender.getUniqueId()); + if (!sender.isConsole()) + locks.add(sender.getUniqueId()); CompletableFuture.runAsync(() -> { try { @@ -81,17 +82,19 @@ public class CommandManager { } catch (CommandSyntaxException e) { this.sendError(sender, name, e); } finally { - this.plugin.getBootstrap().getLogger().debug("Removing lock for " + sender.getUsername()); + if (!source.sender().isConsole()) { + this.plugin.getBootstrap().getLogger().debug("Removing lock for " + sender.getUsername()); - UUID target = locksMappings.get(sender.getUniqueId()); - if (target != null) { - locks.remove(target); - locksMappings.remove(sender.getUniqueId()); + UUID target = locksMappings.get(sender.getUniqueId()); + if (target != null) { + locks.remove(target); + locksMappings.remove(sender.getUniqueId()); - this.plugin.getBootstrap().getLogger().debug("Removing lock caused by " + sender.getUsername() + " for " + target); + this.plugin.getBootstrap().getLogger().debug("Removing lock caused by " + sender.getUsername() + " for " + target); + } + + locks.remove(sender.getUniqueId()); } - - locks.remove(sender.getUniqueId()); } }, executor); } diff --git a/common/src/main/java/dev/xhyrom/lighteco/common/command/argument/type/OfflineUserArgument.java b/common/src/main/java/dev/xhyrom/lighteco/common/command/argument/type/OfflineUserArgument.java index ff80db7..9416568 100644 --- a/common/src/main/java/dev/xhyrom/lighteco/common/command/argument/type/OfflineUserArgument.java +++ b/common/src/main/java/dev/xhyrom/lighteco/common/command/argument/type/OfflineUserArgument.java @@ -9,8 +9,6 @@ import dev.xhyrom.lighteco.common.command.exception.LockedUserException; import dev.xhyrom.lighteco.common.model.chat.CommandSender; import dev.xhyrom.lighteco.common.model.user.User; import dev.xhyrom.lighteco.common.plugin.LightEcoPlugin; -import net.kyori.adventure.text.minimessage.MiniMessage; -import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder; import java.util.UUID; @@ -32,7 +30,8 @@ public class OfflineUserArgument implements ArgumentType { } // Lock the user to prevent race conditions - plugin.getCommandManager().lockBySender(context.getSource().sender(), uniqueId); + if (!sender.isConsole()) + plugin.getCommandManager().lockBySender(context.getSource().sender(), uniqueId); return plugin.getUserManager().loadUser(uniqueId).join(); } diff --git a/common/src/main/java/dev/xhyrom/lighteco/common/commands/PayCommand.java b/common/src/main/java/dev/xhyrom/lighteco/common/commands/PayCommand.java index 692212a..94db38c 100644 --- a/common/src/main/java/dev/xhyrom/lighteco/common/commands/PayCommand.java +++ b/common/src/main/java/dev/xhyrom/lighteco/common/commands/PayCommand.java @@ -123,7 +123,7 @@ public class PayCommand extends Command { public CommandNode build() { if (currency.fractionalDigits() > 0) { return builder() - .requires((source) -> source.sender().eligible("lighteco.currency." + currency.getIdentifier() + ".command.pay")) + .requires((source) -> !source.sender().isConsole() && source.sender().eligible("lighteco.currency." + currency.getIdentifier() + ".command.pay")) .then(RequiredArgumentBuilder.argument("target", StringArgumentType.word()) .suggests(OfflineUserSuggestionProvider.create()) .then(RequiredArgumentBuilder.argument("amount", DoubleArgumentType.doubleArg(1)) @@ -136,7 +136,7 @@ public class PayCommand extends Command { } return builder() - .requires((source) -> source.sender().eligible("lighteco.currency." + currency.getIdentifier() + ".command.pay")) + .requires((source) -> !source.sender().isConsole() && source.sender().eligible("lighteco.currency." + currency.getIdentifier() + ".command.pay")) .then(RequiredArgumentBuilder.argument("target", StringArgumentType.word()) .suggests(OfflineUserSuggestionProvider.create()) .then(RequiredArgumentBuilder.argument("amount", IntegerArgumentType.integer(1)) diff --git a/common/src/main/java/dev/xhyrom/lighteco/common/model/chat/CommandSender.java b/common/src/main/java/dev/xhyrom/lighteco/common/model/chat/CommandSender.java index fba33f8..63b197a 100644 --- a/common/src/main/java/dev/xhyrom/lighteco/common/model/chat/CommandSender.java +++ b/common/src/main/java/dev/xhyrom/lighteco/common/model/chat/CommandSender.java @@ -1,13 +1,18 @@ package dev.xhyrom.lighteco.common.model.chat; import net.kyori.adventure.text.Component; +import org.checkerframework.checker.nullness.qual.Nullable; import java.util.UUID; public interface CommandSender { String getUsername(); - UUID getUniqueId(); + @Nullable UUID getUniqueId(); boolean eligible(String permission); void sendMessage(Component message); + + default boolean isConsole() { + return getUniqueId() == null; + } }