mirror of
https://github.com/xHyroM/lighteco.git
synced 2024-11-10 01:18:07 +01:00
feat: console support
This commit is contained in:
parent
c656999576
commit
49dd99b5ef
4 changed files with 23 additions and 16 deletions
|
@ -60,7 +60,7 @@ public class CommandManager {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void execute(CommandSender sender, String name, String[] args) {
|
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(
|
sender.sendMessage(MiniMessage.miniMessage().deserialize(
|
||||||
this.plugin.getConfig().messages.wait
|
this.plugin.getConfig().messages.wait
|
||||||
));
|
));
|
||||||
|
@ -73,6 +73,7 @@ public class CommandManager {
|
||||||
source
|
source
|
||||||
);
|
);
|
||||||
|
|
||||||
|
if (!sender.isConsole())
|
||||||
locks.add(sender.getUniqueId());
|
locks.add(sender.getUniqueId());
|
||||||
|
|
||||||
CompletableFuture.runAsync(() -> {
|
CompletableFuture.runAsync(() -> {
|
||||||
|
@ -81,6 +82,7 @@ public class CommandManager {
|
||||||
} catch (CommandSyntaxException e) {
|
} catch (CommandSyntaxException e) {
|
||||||
this.sendError(sender, name, e);
|
this.sendError(sender, name, e);
|
||||||
} finally {
|
} finally {
|
||||||
|
if (!source.sender().isConsole()) {
|
||||||
this.plugin.getBootstrap().getLogger().debug("Removing lock for " + sender.getUsername());
|
this.plugin.getBootstrap().getLogger().debug("Removing lock for " + sender.getUsername());
|
||||||
|
|
||||||
UUID target = locksMappings.get(sender.getUniqueId());
|
UUID target = locksMappings.get(sender.getUniqueId());
|
||||||
|
@ -93,6 +95,7 @@ public class CommandManager {
|
||||||
|
|
||||||
locks.remove(sender.getUniqueId());
|
locks.remove(sender.getUniqueId());
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}, executor);
|
}, executor);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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.chat.CommandSender;
|
||||||
import dev.xhyrom.lighteco.common.model.user.User;
|
import dev.xhyrom.lighteco.common.model.user.User;
|
||||||
import dev.xhyrom.lighteco.common.plugin.LightEcoPlugin;
|
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;
|
import java.util.UUID;
|
||||||
|
|
||||||
|
@ -32,6 +30,7 @@ public class OfflineUserArgument implements ArgumentType<String> {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Lock the user to prevent race conditions
|
// Lock the user to prevent race conditions
|
||||||
|
if (!sender.isConsole())
|
||||||
plugin.getCommandManager().lockBySender(context.getSource().sender(), uniqueId);
|
plugin.getCommandManager().lockBySender(context.getSource().sender(), uniqueId);
|
||||||
|
|
||||||
return plugin.getUserManager().loadUser(uniqueId).join();
|
return plugin.getUserManager().loadUser(uniqueId).join();
|
||||||
|
|
|
@ -123,7 +123,7 @@ public class PayCommand extends Command {
|
||||||
public CommandNode<CommandSource> build() {
|
public CommandNode<CommandSource> build() {
|
||||||
if (currency.fractionalDigits() > 0) {
|
if (currency.fractionalDigits() > 0) {
|
||||||
return builder()
|
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())
|
.then(RequiredArgumentBuilder.<CommandSource, String>argument("target", StringArgumentType.word())
|
||||||
.suggests(OfflineUserSuggestionProvider.create())
|
.suggests(OfflineUserSuggestionProvider.create())
|
||||||
.then(RequiredArgumentBuilder.<CommandSource, Double>argument("amount", DoubleArgumentType.doubleArg(1))
|
.then(RequiredArgumentBuilder.<CommandSource, Double>argument("amount", DoubleArgumentType.doubleArg(1))
|
||||||
|
@ -136,7 +136,7 @@ public class PayCommand extends Command {
|
||||||
}
|
}
|
||||||
|
|
||||||
return builder()
|
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())
|
.then(RequiredArgumentBuilder.<CommandSource, String>argument("target", StringArgumentType.word())
|
||||||
.suggests(OfflineUserSuggestionProvider.create())
|
.suggests(OfflineUserSuggestionProvider.create())
|
||||||
.then(RequiredArgumentBuilder.<CommandSource, Integer>argument("amount", IntegerArgumentType.integer(1))
|
.then(RequiredArgumentBuilder.<CommandSource, Integer>argument("amount", IntegerArgumentType.integer(1))
|
||||||
|
|
|
@ -1,13 +1,18 @@
|
||||||
package dev.xhyrom.lighteco.common.model.chat;
|
package dev.xhyrom.lighteco.common.model.chat;
|
||||||
|
|
||||||
import net.kyori.adventure.text.Component;
|
import net.kyori.adventure.text.Component;
|
||||||
|
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||||
|
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
public interface CommandSender {
|
public interface CommandSender {
|
||||||
String getUsername();
|
String getUsername();
|
||||||
UUID getUniqueId();
|
@Nullable UUID getUniqueId();
|
||||||
|
|
||||||
boolean eligible(String permission);
|
boolean eligible(String permission);
|
||||||
void sendMessage(Component message);
|
void sendMessage(Component message);
|
||||||
|
|
||||||
|
default boolean isConsole() {
|
||||||
|
return getUniqueId() == null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue