mirror of
https://github.com/xHyroM/lighteco.git
synced 2024-11-21 22:41:06 +01:00
feat: add built-in info command
This commit is contained in:
parent
a71a2b6454
commit
571e1a82f7
10 changed files with 67 additions and 29 deletions
|
@ -11,7 +11,7 @@ public interface Platform {
|
|||
@NonNull Type getType();
|
||||
|
||||
enum Type {
|
||||
BUKKIT("Bukkit"),
|
||||
PAPER("Paper"),
|
||||
SPONGE("Sponge"),
|
||||
VELOCITY("Velocity"),
|
||||
BUNGEECORD("BungeeCord");
|
||||
|
@ -27,7 +27,7 @@ public interface Platform {
|
|||
}
|
||||
|
||||
public boolean isLocal() {
|
||||
return this == BUKKIT || this == SPONGE;
|
||||
return this == PAPER || this == SPONGE;
|
||||
}
|
||||
|
||||
public boolean isProxy() {
|
||||
|
|
|
@ -15,7 +15,7 @@ public class ApiCommandManager extends ApiAbstractManager<dev.xhyrom.lighteco.co
|
|||
dev.xhyrom.lighteco.common.model.currency.Currency internal = this.plugin.getCurrencyManager()
|
||||
.getIfLoaded(currency.getIdentifier());
|
||||
|
||||
this.handle.register(internal);
|
||||
this.handle.register(internal, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -6,6 +6,7 @@ import com.mojang.brigadier.exceptions.CommandSyntaxException;
|
|||
import dev.xhyrom.lighteco.common.command.abstraction.Command;
|
||||
import dev.xhyrom.lighteco.common.commands.BalanceCommand;
|
||||
import dev.xhyrom.lighteco.common.commands.CurrencyParentCommand;
|
||||
import dev.xhyrom.lighteco.common.commands.InfoCommand;
|
||||
import dev.xhyrom.lighteco.common.commands.PayCommand;
|
||||
import dev.xhyrom.lighteco.common.model.chat.CommandSender;
|
||||
import dev.xhyrom.lighteco.common.model.currency.Currency;
|
||||
|
@ -16,9 +17,6 @@ import net.kyori.adventure.text.event.ClickEvent;
|
|||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
import net.kyori.adventure.text.format.TextDecoration;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class CommandManager {
|
||||
protected final LightEcoPlugin plugin;
|
||||
@Getter
|
||||
|
@ -28,24 +26,22 @@ public class CommandManager {
|
|||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
public void register(Currency currency) {
|
||||
register(currency, false);
|
||||
// Register built-in commands
|
||||
public void register() {
|
||||
register(new InfoCommand());
|
||||
}
|
||||
|
||||
public Command[] register(Currency currency, boolean main) {
|
||||
List<Command> commands = new ArrayList<>();
|
||||
commands.add(new CurrencyParentCommand(currency));
|
||||
public void register(Currency currency, boolean main) {
|
||||
register(new CurrencyParentCommand(currency));
|
||||
|
||||
dispatcher.getRoot().addChild(commands.get(0).build());
|
||||
if (main) {
|
||||
commands.add(BalanceCommand.create(currency));
|
||||
commands.add(PayCommand.create(currency));
|
||||
|
||||
dispatcher.getRoot().addChild(commands.get(1).build());
|
||||
dispatcher.getRoot().addChild(commands.get(2).build());
|
||||
register(BalanceCommand.create(currency));
|
||||
register(PayCommand.create(currency));
|
||||
}
|
||||
}
|
||||
|
||||
return commands.toArray(new Command[0]);
|
||||
protected void register(Command command) {
|
||||
dispatcher.getRoot().addChild(command.build());
|
||||
}
|
||||
|
||||
public void execute(CommandSender sender, String name, String[] args) {
|
||||
|
|
|
@ -0,0 +1,36 @@
|
|||
package dev.xhyrom.lighteco.common.commands;
|
||||
|
||||
import com.mojang.brigadier.tree.CommandNode;
|
||||
import dev.xhyrom.lighteco.common.command.CommandSource;
|
||||
import dev.xhyrom.lighteco.common.command.abstraction.Command;
|
||||
import dev.xhyrom.lighteco.common.model.chat.CommandSender;
|
||||
import dev.xhyrom.lighteco.common.plugin.LightEcoPlugin;
|
||||
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
|
||||
|
||||
import static com.mojang.brigadier.Command.SINGLE_SUCCESS;
|
||||
|
||||
public class InfoCommand extends Command {
|
||||
public InfoCommand() {
|
||||
super("lighteco", "LightEco information");
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommandNode<CommandSource> build() {
|
||||
return builder()
|
||||
.requires(source -> source.sender().eligible("lighteco.command.info"))
|
||||
.executes(context -> {
|
||||
LightEcoPlugin plugin = context.getSource().plugin();
|
||||
CommandSender sender = context.getSource().sender();
|
||||
|
||||
sender.sendMessage(MiniMessage.miniMessage().deserialize(
|
||||
"<#fa5246><bold>LightEco</bold></#fa5246> <dark_gray>(<#d6766f>v<version><dark_gray>) <white>on <#d6766f><platform>",
|
||||
Placeholder.parsed("version", plugin.getBootstrap().getVersion()),
|
||||
Placeholder.parsed("platform", plugin.getPlatformType().getName())
|
||||
));
|
||||
|
||||
return SINGLE_SUCCESS;
|
||||
})
|
||||
.build();
|
||||
}
|
||||
}
|
|
@ -65,6 +65,9 @@ public abstract class AbstractLightEcoPlugin implements LightEcoPlugin {
|
|||
// setup managers
|
||||
this.setupManagers();
|
||||
|
||||
// register built-in commands
|
||||
this.getCommandManager().register();
|
||||
|
||||
// register platform hooks
|
||||
this.registerPlatformHooks();
|
||||
|
||||
|
|
|
@ -15,6 +15,7 @@ public interface LightEcoBootstrap {
|
|||
PluginLogger getLogger();
|
||||
SchedulerAdapter getScheduler();
|
||||
Path getDataDirectory();
|
||||
String getVersion();
|
||||
|
||||
Optional<UUID> lookupUniqueId(String username);
|
||||
boolean isPlayerOnline(UUID uniqueId);
|
||||
|
|
|
@ -60,6 +60,11 @@ public class PaperLightEcoBootstrap implements LightEcoBootstrap, LoaderBootstra
|
|||
return this.loader.getDataFolder().toPath();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getVersion() {
|
||||
return this.loader.getDescription().getVersion();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<UUID> lookupUniqueId(String username) {
|
||||
return Optional.of(this.loader.getServer().getOfflinePlayer(username)).map(OfflinePlayer::getUniqueId);
|
||||
|
|
|
@ -70,6 +70,6 @@ public class PaperLightEcoPlugin extends AbstractLightEcoPlugin {
|
|||
|
||||
@Override
|
||||
public Platform.@NonNull Type getPlatformType() {
|
||||
return Platform.Type.BUKKIT;
|
||||
return Platform.Type.PAPER;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -24,17 +24,9 @@ public class PaperCommandManager extends CommandManager {
|
|||
}
|
||||
|
||||
@Override
|
||||
public Command[] register(Currency currency, boolean main) {
|
||||
Command[] commands = super.register(currency, main);
|
||||
protected void register(Command command) {
|
||||
super.register(command);
|
||||
|
||||
for (Command command : commands) {
|
||||
this.registerToBukkit(command);
|
||||
}
|
||||
|
||||
return commands;
|
||||
}
|
||||
|
||||
private void registerToBukkit(Command command) {
|
||||
CommandExecutor executor = (sender, bukkitCommand, s, args) -> {
|
||||
if (s.startsWith("lighteco:")) {
|
||||
s = s.substring(9);
|
||||
|
|
|
@ -61,6 +61,11 @@ public class SpongeLightEcoBootstrap implements LightEcoBootstrap, LoaderBootstr
|
|||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getVersion() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<UUID> lookupUniqueId(String username) {
|
||||
return Optional.empty();
|
||||
|
|
Loading…
Reference in a new issue