1
0
Fork 0
mirror of https://github.com/xHyroM/lighteco.git synced 2024-09-19 21:03:18 +02:00

feat: console support

This commit is contained in:
Jozef Steinhübl 2024-07-16 17:55:19 +02:00
parent c656999576
commit 49dd99b5ef
No known key found for this signature in database
GPG key ID: E6BC90C91973B08F
4 changed files with 23 additions and 16 deletions

View file

@ -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);
}

View file

@ -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<String> {
}
// 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();
}

View file

@ -123,7 +123,7 @@ public class PayCommand extends Command {
public CommandNode<CommandSource> 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.<CommandSource, String>argument("target", StringArgumentType.word())
.suggests(OfflineUserSuggestionProvider.create())
.then(RequiredArgumentBuilder.<CommandSource, Double>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.<CommandSource, String>argument("target", StringArgumentType.word())
.suggests(OfflineUserSuggestionProvider.create())
.then(RequiredArgumentBuilder.<CommandSource, Integer>argument("amount", IntegerArgumentType.integer(1))

View file

@ -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;
}
}