diff --git a/bukkit/src/main/java/dev/xhyrom/lighteco/bukkit/BukkitLightEcoBootstrap.java b/bukkit/src/main/java/dev/xhyrom/lighteco/bukkit/BukkitLightEcoBootstrap.java index eafc476..caddaec 100644 --- a/bukkit/src/main/java/dev/xhyrom/lighteco/bukkit/BukkitLightEcoBootstrap.java +++ b/bukkit/src/main/java/dev/xhyrom/lighteco/bukkit/BukkitLightEcoBootstrap.java @@ -8,6 +8,7 @@ import dev.xhyrom.lighteco.common.plugin.bootstrap.LoaderBootstrap; import dev.xhyrom.lighteco.common.plugin.logger.PluginLogger; import dev.xhyrom.lighteco.common.plugin.scheduler.SchedulerAdapter; import lombok.Getter; +import org.bukkit.OfflinePlayer; import org.bukkit.entity.Entity; import org.bukkit.entity.Player; import org.bukkit.plugin.java.JavaPlugin; @@ -15,6 +16,7 @@ import org.bukkit.plugin.java.JavaPlugin; import java.io.InputStream; import java.nio.file.Path; import java.util.List; +import java.util.Optional; import java.util.UUID; @Getter @@ -59,6 +61,11 @@ public class BukkitLightEcoBootstrap implements LightEcoBootstrap, LoaderBootstr return this.loader.getDataFolder().toPath(); } + @Override + public Optional lookupUniqueId(String username) { + return Optional.ofNullable(this.loader.getServer().getOfflinePlayer(username)).map(OfflinePlayer::getUniqueId); + } + @Override public boolean isPlayerOnline(UUID uniqueId) { Player player = this.loader.getServer().getPlayer(uniqueId); diff --git a/common/src/main/java/dev/xhyrom/lighteco/common/command/abstraction/Command.java b/common/src/main/java/dev/xhyrom/lighteco/common/command/abstraction/Command.java index fb35254..9460863 100644 --- a/common/src/main/java/dev/xhyrom/lighteco/common/command/abstraction/Command.java +++ b/common/src/main/java/dev/xhyrom/lighteco/common/command/abstraction/Command.java @@ -18,9 +18,9 @@ public abstract class Command { @Getter @NonNull - private final List args; + private final List> args; - public Command(@NonNull String name, @Nullable String permission, @NonNull Argument... args) { + public Command(@NonNull String name, @Nullable String permission, @NonNull Argument... args) { this.name = name; this.permission = permission; this.args = List.of(args); diff --git a/common/src/main/java/dev/xhyrom/lighteco/common/command/argument/Argument.java b/common/src/main/java/dev/xhyrom/lighteco/common/command/argument/Argument.java index a04859b..744607c 100644 --- a/common/src/main/java/dev/xhyrom/lighteco/common/command/argument/Argument.java +++ b/common/src/main/java/dev/xhyrom/lighteco/common/command/argument/Argument.java @@ -1,19 +1,20 @@ package dev.xhyrom.lighteco.common.command.argument; +import dev.xhyrom.lighteco.common.plugin.LightEcoPlugin; import lombok.Getter; -import net.kyori.adventure.text.Component; -public class Argument { +public abstract class Argument { @Getter private final String name; - @Getter - private final boolean required; - @Getter - private final Component description; + protected final LightEcoPlugin plugin; - public Argument(String name, boolean required, Component description) { + protected Argument(LightEcoPlugin plugin, String name) { + this.plugin = plugin; this.name = name; - this.required = required; - this.description = description; } + + public abstract Class getPrimitiveType(); + public abstract ArgumentType getArgumentType(); + + public abstract T parse(String input); } diff --git a/common/src/main/java/dev/xhyrom/lighteco/common/command/argument/ArgumentType.java b/common/src/main/java/dev/xhyrom/lighteco/common/command/argument/ArgumentType.java new file mode 100644 index 0000000..ef73afc --- /dev/null +++ b/common/src/main/java/dev/xhyrom/lighteco/common/command/argument/ArgumentType.java @@ -0,0 +1,7 @@ +package dev.xhyrom.lighteco.common.command.argument; + +public enum ArgumentType { + OFFLINE_USER, + INTEGER, + DOUBLE; +} 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 new file mode 100644 index 0000000..1894c3e --- /dev/null +++ b/common/src/main/java/dev/xhyrom/lighteco/common/command/argument/type/OfflineUserArgument.java @@ -0,0 +1,34 @@ +package dev.xhyrom.lighteco.common.command.argument.type; + +import dev.xhyrom.lighteco.common.command.argument.Argument; +import dev.xhyrom.lighteco.common.command.argument.ArgumentType; +import dev.xhyrom.lighteco.common.model.user.User; +import dev.xhyrom.lighteco.common.plugin.LightEcoPlugin; + +import java.util.UUID; + +public class OfflineUserArgument extends Argument { + public OfflineUserArgument(LightEcoPlugin plugin, String name) { + super(plugin, name); + } + + @Override + public Class getPrimitiveType() { + return User.class; + } + + @Override + public ArgumentType getArgumentType() { + return ArgumentType.OFFLINE_USER; + } + + @Override + public User parse(String input) { + UUID uniqueId = this.plugin.getBootstrap().lookupUniqueId(input).orElse(null); + if (uniqueId == null) { + return null; + } + + return this.plugin.getUserManager().loadUser(uniqueId).join(); + } +} diff --git a/common/src/main/java/dev/xhyrom/lighteco/common/plugin/bootstrap/LightEcoBootstrap.java b/common/src/main/java/dev/xhyrom/lighteco/common/plugin/bootstrap/LightEcoBootstrap.java index ac16413..edebb01 100644 --- a/common/src/main/java/dev/xhyrom/lighteco/common/plugin/bootstrap/LightEcoBootstrap.java +++ b/common/src/main/java/dev/xhyrom/lighteco/common/plugin/bootstrap/LightEcoBootstrap.java @@ -6,6 +6,7 @@ import dev.xhyrom.lighteco.common.plugin.scheduler.SchedulerAdapter; import java.io.InputStream; import java.nio.file.Path; import java.util.List; +import java.util.Optional; import java.util.UUID; public interface LightEcoBootstrap { @@ -13,7 +14,10 @@ public interface LightEcoBootstrap { PluginLogger getLogger(); SchedulerAdapter getScheduler(); Path getDataDirectory(); + + Optional lookupUniqueId(String username); boolean isPlayerOnline(UUID uniqueId); List getOnlinePlayers(); + InputStream getResourceStream(String filename); }