mirror of
https://github.com/xHyroM/lighteco.git
synced 2024-11-22 06:51:05 +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();
|
@NonNull Type getType();
|
||||||
|
|
||||||
enum Type {
|
enum Type {
|
||||||
BUKKIT("Bukkit"),
|
PAPER("Paper"),
|
||||||
SPONGE("Sponge"),
|
SPONGE("Sponge"),
|
||||||
VELOCITY("Velocity"),
|
VELOCITY("Velocity"),
|
||||||
BUNGEECORD("BungeeCord");
|
BUNGEECORD("BungeeCord");
|
||||||
|
@ -27,7 +27,7 @@ public interface Platform {
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isLocal() {
|
public boolean isLocal() {
|
||||||
return this == BUKKIT || this == SPONGE;
|
return this == PAPER || this == SPONGE;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isProxy() {
|
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()
|
dev.xhyrom.lighteco.common.model.currency.Currency internal = this.plugin.getCurrencyManager()
|
||||||
.getIfLoaded(currency.getIdentifier());
|
.getIfLoaded(currency.getIdentifier());
|
||||||
|
|
||||||
this.handle.register(internal);
|
this.handle.register(internal, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -6,6 +6,7 @@ import com.mojang.brigadier.exceptions.CommandSyntaxException;
|
||||||
import dev.xhyrom.lighteco.common.command.abstraction.Command;
|
import dev.xhyrom.lighteco.common.command.abstraction.Command;
|
||||||
import dev.xhyrom.lighteco.common.commands.BalanceCommand;
|
import dev.xhyrom.lighteco.common.commands.BalanceCommand;
|
||||||
import dev.xhyrom.lighteco.common.commands.CurrencyParentCommand;
|
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.commands.PayCommand;
|
||||||
import dev.xhyrom.lighteco.common.model.chat.CommandSender;
|
import dev.xhyrom.lighteco.common.model.chat.CommandSender;
|
||||||
import dev.xhyrom.lighteco.common.model.currency.Currency;
|
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.NamedTextColor;
|
||||||
import net.kyori.adventure.text.format.TextDecoration;
|
import net.kyori.adventure.text.format.TextDecoration;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public class CommandManager {
|
public class CommandManager {
|
||||||
protected final LightEcoPlugin plugin;
|
protected final LightEcoPlugin plugin;
|
||||||
@Getter
|
@Getter
|
||||||
|
@ -28,24 +26,22 @@ public class CommandManager {
|
||||||
this.plugin = plugin;
|
this.plugin = plugin;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void register(Currency currency) {
|
// Register built-in commands
|
||||||
register(currency, false);
|
public void register() {
|
||||||
|
register(new InfoCommand());
|
||||||
}
|
}
|
||||||
|
|
||||||
public Command[] register(Currency currency, boolean main) {
|
public void register(Currency currency, boolean main) {
|
||||||
List<Command> commands = new ArrayList<>();
|
register(new CurrencyParentCommand(currency));
|
||||||
commands.add(new CurrencyParentCommand(currency));
|
|
||||||
|
|
||||||
dispatcher.getRoot().addChild(commands.get(0).build());
|
|
||||||
if (main) {
|
if (main) {
|
||||||
commands.add(BalanceCommand.create(currency));
|
register(BalanceCommand.create(currency));
|
||||||
commands.add(PayCommand.create(currency));
|
register(PayCommand.create(currency));
|
||||||
|
|
||||||
dispatcher.getRoot().addChild(commands.get(1).build());
|
|
||||||
dispatcher.getRoot().addChild(commands.get(2).build());
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
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) {
|
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
|
// setup managers
|
||||||
this.setupManagers();
|
this.setupManagers();
|
||||||
|
|
||||||
|
// register built-in commands
|
||||||
|
this.getCommandManager().register();
|
||||||
|
|
||||||
// register platform hooks
|
// register platform hooks
|
||||||
this.registerPlatformHooks();
|
this.registerPlatformHooks();
|
||||||
|
|
||||||
|
|
|
@ -15,6 +15,7 @@ public interface LightEcoBootstrap {
|
||||||
PluginLogger getLogger();
|
PluginLogger getLogger();
|
||||||
SchedulerAdapter getScheduler();
|
SchedulerAdapter getScheduler();
|
||||||
Path getDataDirectory();
|
Path getDataDirectory();
|
||||||
|
String getVersion();
|
||||||
|
|
||||||
Optional<UUID> lookupUniqueId(String username);
|
Optional<UUID> lookupUniqueId(String username);
|
||||||
boolean isPlayerOnline(UUID uniqueId);
|
boolean isPlayerOnline(UUID uniqueId);
|
||||||
|
|
|
@ -60,6 +60,11 @@ public class PaperLightEcoBootstrap implements LightEcoBootstrap, LoaderBootstra
|
||||||
return this.loader.getDataFolder().toPath();
|
return this.loader.getDataFolder().toPath();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getVersion() {
|
||||||
|
return this.loader.getDescription().getVersion();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Optional<UUID> lookupUniqueId(String username) {
|
public Optional<UUID> lookupUniqueId(String username) {
|
||||||
return Optional.of(this.loader.getServer().getOfflinePlayer(username)).map(OfflinePlayer::getUniqueId);
|
return Optional.of(this.loader.getServer().getOfflinePlayer(username)).map(OfflinePlayer::getUniqueId);
|
||||||
|
|
|
@ -70,6 +70,6 @@ public class PaperLightEcoPlugin extends AbstractLightEcoPlugin {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Platform.@NonNull Type getPlatformType() {
|
public Platform.@NonNull Type getPlatformType() {
|
||||||
return Platform.Type.BUKKIT;
|
return Platform.Type.PAPER;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,17 +24,9 @@ public class PaperCommandManager extends CommandManager {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Command[] register(Currency currency, boolean main) {
|
protected void register(Command command) {
|
||||||
Command[] commands = super.register(currency, main);
|
super.register(command);
|
||||||
|
|
||||||
for (Command command : commands) {
|
|
||||||
this.registerToBukkit(command);
|
|
||||||
}
|
|
||||||
|
|
||||||
return commands;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void registerToBukkit(Command command) {
|
|
||||||
CommandExecutor executor = (sender, bukkitCommand, s, args) -> {
|
CommandExecutor executor = (sender, bukkitCommand, s, args) -> {
|
||||||
if (s.startsWith("lighteco:")) {
|
if (s.startsWith("lighteco:")) {
|
||||||
s = s.substring(9);
|
s = s.substring(9);
|
||||||
|
|
|
@ -61,6 +61,11 @@ public class SpongeLightEcoBootstrap implements LightEcoBootstrap, LoaderBootstr
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getVersion() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Optional<UUID> lookupUniqueId(String username) {
|
public Optional<UUID> lookupUniqueId(String username) {
|
||||||
return Optional.empty();
|
return Optional.empty();
|
||||||
|
|
Loading…
Reference in a new issue