From d0ec585cde5445806e1ae9a5974d110464db614d Mon Sep 17 00:00:00 2001
From: Manere <133597204+Manered@users.noreply.github.com>
Date: Tue, 19 Dec 2023 20:19:08 +0100
Subject: [PATCH] v3.2.0
Honestly don't even ask me why I wasted a week on working on a library :sob:
---
.gitignore | 3 +-
pom.xml | 29 +-
.../dev/manere/utils/cachable/Cachable.java | 171 +++++++
.../utils/cachable/CachableSnapshot.java | 45 ++
.../utils/cachable/impl/CachableImpl.java | 147 ++++++
.../cachable/impl/CachableSnapshotImpl.java | 69 +++
...ommandSettings.java => CommandConfig.java} | 42 +-
.../dev/manere/utils/command/CommandType.java | 22 -
.../manere/utils/command/CommandTypes.java | 77 ++++
.../dev/manere/utils/command/Commander.java | 18 +-
.../command/annotation/AutoRegister.java | 4 +-
.../annotation/AutoRegisterHandler.java | 15 +-
.../manere/utils/command/args/Argument.java | 4 +-
.../command/args/custom/CustomArgument.java | 3 +-
.../args/custom/CustomListArgument.java | 11 +-
.../entity/CachedOfflinePlayerArgument.java | 2 +-
.../args/entity/EntityTypeArgument.java | 2 +-
.../args/entity/OfflinePlayerArgument.java | 2 +-
.../command/args/entity/PlayerArgument.java | 2 +-
.../args/exception/ArgumentExType.java | 10 +-
.../exception/ArgumentParseException.java | 2 +-
.../command/args/misc/GamemodeArgument.java | 2 +-
.../args/primitive/BooleanArgument.java | 2 +-
.../args/primitive/DoubleArgument.java | 2 +-
.../command/args/primitive/FloatArgument.java | 2 +-
.../args/primitive/IntegerArgument.java | 31 +-
.../command/args/primitive/LongArgument.java | 2 +-
.../command/args/text/ComponentArgument.java | 2 +-
.../args/text/ComponentListArgument.java | 44 ++
.../command/args/text/StringArgument.java | 2 +-
.../command/args/text/StringListArgument.java | 4 +-
.../utils/command/args/text/TextArgument.java | 2 +-
.../command/args/text/TextListArgument.java | 43 ++
.../utils/command/builder/CommandBuilder.java | 237 ----------
.../utils/command/impl/CommandInfo.java | 86 ++++
.../manere/utils/command/impl/Commands.java | 422 ++++++++++++++++++
.../CommandsRegistrar.java} | 15 +-
.../alias/CommandAliasBuilder.java | 38 +-
.../dispatcher/CommandContext.java | 80 +++-
.../dispatcher/CommandDispatcher.java | 3 +-
.../dispatcher/SuggestionDispatcher.java | 3 +-
.../permission/CommandPermission.java | 3 +-
.../permission/CommandPermissionBuilder.java | 26 +-
.../java/dev/manere/utils/config/Config.java | 1 -
.../utils/config/section/ConfigSection.java | 2 +-
.../utils/config/section/ConfigSelection.java | 9 +-
.../config/setter/ConfigSectionSetter.java | 1 -
.../utils/config/setter/ConfigSetter.java | 1 -
.../manere/utils/config/val/ConfigList.java | 1 -
.../manere/utils/config/val/ConfigVal.java | 10 +-
.../manere/utils/consumers/PairConsumer.java | 18 +
.../utils/consumers/TripleConsumer.java | 20 +
.../dev/manere/utils/context/Context.java | 36 ++
src/main/java/dev/manere/utils/elo/ELO.java | 1 -
.../java/dev/manere/utils/elo/Ratings.java | 2 +-
.../java/dev/manere/utils/elo/Winner.java | 11 +-
.../utils/event/builder/EventBuilder.java | 17 +-
.../utils/event/builder/EventCallback.java | 12 +-
.../utils/event/builder/EventHandler.java | 29 +-
.../event/crystal/PlayerAnchorDeathEvent.java | 125 ++++++
...vent.java => PlayerCrystalDeathEvent.java} | 21 +-
.../impl/SpigotAnchorEventListener.java | 75 ++++
.../SpigotCrystalEventListener.java} | 28 +-
.../dev/manere/utils/item/ItemBuilder.java | 143 +++++-
.../dev/manere/utils/item/PotionBuilder.java | 12 +-
.../java/dev/manere/utils/library/Utils.java | 12 +-
.../utils/library/event/PluginEvents.java | 98 ++++
.../utils/library/wrapper/PluginWrapper.java | 250 +++++++++++
.../manere/utils/location/LocationUtils.java | 1 -
.../manere/utils/logger/AdventureLogger.java | 1 -
.../java/dev/manere/utils/logger/Loggers.java | 14 +-
.../java/dev/manere/utils/menu/MenuBase.java | 3 +-
.../java/dev/manere/utils/menu/MenuUtils.java | 1 -
.../menu/{ => listener}/CloseListener.java | 4 +-
.../menu/{ => listener}/DragListener.java | 4 +-
.../menu/{ => listener}/MenuListener.java | 26 +-
.../dev/manere/utils/menu/normal/Menu.java | 78 ++--
.../utils/menu/paginated/PaginatedMenu.java | 121 ++---
.../utils/menu/paginated/PaginatedSlot.java | 4 +
.../utils/message/ActionBarMessager.java | 4 +-
.../dev/manere/utils/message/Messagers.java | 1 -
.../java/dev/manere/utils/misc/Buildable.java | 12 +
.../dev/manere/utils/misc/FluentBuilder.java | 16 +
.../dev/manere/utils/misc/ObjectUtils.java | 156 +++++++
.../java/dev/manere/utils/misc/Storable.java | 23 +
.../utils/model/{Duo.java => Tuple.java} | 12 +-
.../utils/papi/PlaceholderAPIBuilder.java | 9 +-
.../dev/manere/utils/pdc/UUIDDataType.java | 79 ++++
.../manere/utils/player/cache/CacheInfo.java | 27 --
.../manere/utils/player/cache/CacheKey.java | 39 --
.../manere/utils/player/cache/CacheVal.java | 102 -----
.../utils/player/cache/PlayerCache.java | 142 ------
.../manere/utils/prettify/ListPrettify.java | 1 -
.../utils/reflection/ReflectionUtils.java | 5 +-
.../manere/utils/registration/Registrar.java | 25 +-
.../utils/resource/ResourceBuilder.java | 127 ++++++
.../manere/utils/resource/ResourceFile.java | 212 +++++++++
.../utils/resource/ResourceOptions.java | 115 +++++
.../utils/resource/format/ResourceFormat.java | 47 ++
.../resource/format/ResourceFormats.java | 24 +
.../utils/resource/path/ResourcePath.java | 42 ++
.../utils/resource/path/ResourcePaths.java | 40 ++
.../resource/yaml/ResourceConfiguration.java | 336 ++++++++++++++
.../utils/returnable/PairReturnable.java | 15 +
.../manere/utils/returnable/Returnable.java | 13 +
.../utils/returnable/TripleReturnable.java | 17 +
.../utils/scheduler/AsyncScheduler.java | 75 ----
.../manere/utils/scheduler/SchedulerBase.java | 118 +++++
.../manere/utils/scheduler/Schedulers.java | 85 +++-
.../manere/utils/scheduler/SyncScheduler.java | 75 ----
.../dev/manere/utils/scheduler/TickTimes.java | 4 +-
.../utils/scheduler/async/AsyncScheduler.java | 77 ++++
.../scheduler/builder/SchedulerBuilder.java | 245 +++++-----
.../scheduler/builder/SchedulerConfig.java | 103 +++++
.../builder/SchedulerThreadType.java | 16 +
.../utils/scheduler/builder/TaskType.java | 22 -
.../scheduler/builder/task/SchedulerTask.java | 99 ++++
.../scheduler/stacker/SchedulerStacker.java | 167 ++-----
.../utils/scheduler/sync/SyncScheduler.java | 71 +++
.../dev/manere/utils/scoreboard/Sidebar.java | 11 +-
.../utils/scoreboard/SidebarHandler.java | 46 +-
.../utils/serializers/Base64Serializer.java | 1 -
.../utils/serializers/ByteSerializer.java | 105 +++++
.../manere/utils/serializers/Serializers.java | 14 +-
.../dev/manere/utils/server/ServerUtils.java | 1 -
.../utils/sql/connection/SQLConnector.java | 1 -
.../dev/manere/utils/tablist/Tablist.java | 116 +++++
src/main/java/dev/manere/utils/text/Text.java | 19 +-
.../manere/utils/text/color/TextStyle.java | 34 +-
.../dev/manere/utils/text/font/SmallFont.java | 1 -
.../utils/tierlist/data/PlayerInfo.java | 1 -
.../manere/utils/tierlist/data/TierList.java | 1 -
.../java/dev/manere/utils/update/Updater.java | 1 -
.../java/dev/manere/utils/world/Worlds.java | 55 ++-
.../utils/worldedit/AsyncWorldEditor.java | 1 -
.../utils/worldedit/SyncWorldEditor.java | 1 -
.../manere/utils/worldedit/WorldEditor.java | 1 -
137 files changed, 4753 insertions(+), 1378 deletions(-)
create mode 100644 src/main/java/dev/manere/utils/cachable/Cachable.java
create mode 100644 src/main/java/dev/manere/utils/cachable/CachableSnapshot.java
create mode 100644 src/main/java/dev/manere/utils/cachable/impl/CachableImpl.java
create mode 100644 src/main/java/dev/manere/utils/cachable/impl/CachableSnapshotImpl.java
rename src/main/java/dev/manere/utils/command/{CommandSettings.java => CommandConfig.java} (65%)
delete mode 100644 src/main/java/dev/manere/utils/command/CommandType.java
create mode 100644 src/main/java/dev/manere/utils/command/CommandTypes.java
create mode 100644 src/main/java/dev/manere/utils/command/args/text/ComponentListArgument.java
create mode 100644 src/main/java/dev/manere/utils/command/args/text/TextListArgument.java
delete mode 100644 src/main/java/dev/manere/utils/command/builder/CommandBuilder.java
create mode 100644 src/main/java/dev/manere/utils/command/impl/CommandInfo.java
create mode 100644 src/main/java/dev/manere/utils/command/impl/Commands.java
rename src/main/java/dev/manere/utils/command/{builder/CommandBuilderHandler.java => impl/CommandsRegistrar.java} (88%)
rename src/main/java/dev/manere/utils/command/{builder => impl}/alias/CommandAliasBuilder.java (66%)
rename src/main/java/dev/manere/utils/command/{builder => impl}/dispatcher/CommandContext.java (72%)
rename src/main/java/dev/manere/utils/command/{builder => impl}/dispatcher/CommandDispatcher.java (89%)
rename src/main/java/dev/manere/utils/command/{builder => impl}/dispatcher/SuggestionDispatcher.java (91%)
rename src/main/java/dev/manere/utils/command/{builder => impl}/permission/CommandPermission.java (78%)
rename src/main/java/dev/manere/utils/command/{builder => impl}/permission/CommandPermissionBuilder.java (80%)
create mode 100644 src/main/java/dev/manere/utils/consumers/PairConsumer.java
create mode 100644 src/main/java/dev/manere/utils/consumers/TripleConsumer.java
create mode 100644 src/main/java/dev/manere/utils/context/Context.java
create mode 100644 src/main/java/dev/manere/utils/event/crystal/PlayerAnchorDeathEvent.java
rename src/main/java/dev/manere/utils/event/crystal/{PlayerDeathByPlayerWithCrystalEvent.java => PlayerCrystalDeathEvent.java} (92%)
create mode 100644 src/main/java/dev/manere/utils/event/crystal/impl/SpigotAnchorEventListener.java
rename src/main/java/dev/manere/utils/event/crystal/{SpigotEventListener.java => impl/SpigotCrystalEventListener.java} (66%)
create mode 100644 src/main/java/dev/manere/utils/library/event/PluginEvents.java
create mode 100644 src/main/java/dev/manere/utils/library/wrapper/PluginWrapper.java
rename src/main/java/dev/manere/utils/menu/{ => listener}/CloseListener.java (90%)
rename src/main/java/dev/manere/utils/menu/{ => listener}/DragListener.java (90%)
rename src/main/java/dev/manere/utils/menu/{ => listener}/MenuListener.java (87%)
create mode 100644 src/main/java/dev/manere/utils/misc/Buildable.java
create mode 100644 src/main/java/dev/manere/utils/misc/FluentBuilder.java
create mode 100644 src/main/java/dev/manere/utils/misc/ObjectUtils.java
create mode 100644 src/main/java/dev/manere/utils/misc/Storable.java
rename src/main/java/dev/manere/utils/model/{Duo.java => Tuple.java} (84%)
create mode 100644 src/main/java/dev/manere/utils/pdc/UUIDDataType.java
delete mode 100644 src/main/java/dev/manere/utils/player/cache/CacheInfo.java
delete mode 100644 src/main/java/dev/manere/utils/player/cache/CacheKey.java
delete mode 100644 src/main/java/dev/manere/utils/player/cache/CacheVal.java
delete mode 100644 src/main/java/dev/manere/utils/player/cache/PlayerCache.java
create mode 100644 src/main/java/dev/manere/utils/resource/ResourceBuilder.java
create mode 100644 src/main/java/dev/manere/utils/resource/ResourceFile.java
create mode 100644 src/main/java/dev/manere/utils/resource/ResourceOptions.java
create mode 100644 src/main/java/dev/manere/utils/resource/format/ResourceFormat.java
create mode 100644 src/main/java/dev/manere/utils/resource/format/ResourceFormats.java
create mode 100644 src/main/java/dev/manere/utils/resource/path/ResourcePath.java
create mode 100644 src/main/java/dev/manere/utils/resource/path/ResourcePaths.java
create mode 100644 src/main/java/dev/manere/utils/resource/yaml/ResourceConfiguration.java
create mode 100644 src/main/java/dev/manere/utils/returnable/PairReturnable.java
create mode 100644 src/main/java/dev/manere/utils/returnable/Returnable.java
create mode 100644 src/main/java/dev/manere/utils/returnable/TripleReturnable.java
delete mode 100644 src/main/java/dev/manere/utils/scheduler/AsyncScheduler.java
create mode 100644 src/main/java/dev/manere/utils/scheduler/SchedulerBase.java
delete mode 100644 src/main/java/dev/manere/utils/scheduler/SyncScheduler.java
create mode 100644 src/main/java/dev/manere/utils/scheduler/async/AsyncScheduler.java
create mode 100644 src/main/java/dev/manere/utils/scheduler/builder/SchedulerConfig.java
create mode 100644 src/main/java/dev/manere/utils/scheduler/builder/SchedulerThreadType.java
delete mode 100644 src/main/java/dev/manere/utils/scheduler/builder/TaskType.java
create mode 100644 src/main/java/dev/manere/utils/scheduler/builder/task/SchedulerTask.java
create mode 100644 src/main/java/dev/manere/utils/scheduler/sync/SyncScheduler.java
create mode 100644 src/main/java/dev/manere/utils/serializers/ByteSerializer.java
create mode 100644 src/main/java/dev/manere/utils/tablist/Tablist.java
diff --git a/.gitignore b/.gitignore
index 1c12ecd..85ec936 100644
--- a/.gitignore
+++ b/.gitignore
@@ -34,4 +34,5 @@ replay_pid*
/target/
target/
target
-/target
\ No newline at end of file
+/target
+dependency-reduced-pom.xml
\ No newline at end of file
diff --git a/pom.xml b/pom.xml
index 4d1a73e..503e789 100644
--- a/pom.xml
+++ b/pom.xml
@@ -6,7 +6,7 @@
dev.manereutils
- 3.1.0
+ 3.2.0jarUtils
@@ -27,6 +27,27 @@
17
+
+ org.apache.maven.plugins
+ maven-shade-plugin
+ 3.5.0
+
+
+
+ com.jeff_media.customblockdata
+ dev.manere.utils.customblockdata
+
+
+
+
+
+ package
+
+ shade
+
+
+
+
@@ -86,6 +107,12 @@
+
+ com.jeff-media
+ custom-block-data
+ 2.2.2
+ compile
+
diff --git a/src/main/java/dev/manere/utils/cachable/Cachable.java b/src/main/java/dev/manere/utils/cachable/Cachable.java
new file mode 100644
index 0000000..8907459
--- /dev/null
+++ b/src/main/java/dev/manere/utils/cachable/Cachable.java
@@ -0,0 +1,171 @@
+package dev.manere.utils.cachable;
+
+import dev.manere.utils.cachable.impl.CachableImpl;
+import dev.manere.utils.consumers.PairConsumer;
+import dev.manere.utils.model.Tuple;
+
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Map;
+
+/**
+ * The {@code Cachable} interface defines methods for a caching mechanism that associates keys with values.
+ *
+ * @param The type of keys in the cache.
+ * @param The type of values in the cache.
+ */
+public interface Cachable {
+ /**
+ * Creates and returns a Cachable instance.
+ *
+ * @param The key type
+ * @param The value type
+ * @return A new Cachable instance
+ */
+ static CachableImpl of() {
+ return new CachableImpl<>();
+ }
+
+ /**
+ * Creates and returns a Cachable instance initialized with the given entries.
+ *
+ * @param The key type
+ * @param The value type
+ * @param entries The initial entries to cache
+ * @return A Cachable instance with the given initial entries
+ */
+ static CachableImpl of(Collection> entries) {
+ CachableImpl cachable = new CachableImpl<>();
+ cachable.cacheAll(entries);
+
+ return cachable;
+ }
+
+ /**
+ * Creates and returns a Cachable instance initialized with the given entries.
+ *
+ * @param The key type
+ * @param The value type
+ * @param entries The initial entries to cache
+ * @return A Cachable instance with the given initial entries
+ */
+ static CachableImpl of(Map entries) {
+ CachableImpl cachable = new CachableImpl<>();
+ cachable.cacheAll(entries);
+
+ return cachable;
+ }
+
+ /**
+ * Creates and returns a Cachable instance initialized with the given entries.
+ *
+ * @param The key type
+ * @param The value type
+ * @param entries The initial entries to cache
+ * @return A Cachable instance with the given initial entries
+ */
+ @SafeVarargs
+ static CachableImpl of(Tuple... entries) {
+ return Cachable.of(Arrays.asList(entries));
+ }
+
+ /**
+ * Retrieves the value associated with the given key.
+ *
+ * @param key The key whose associated value is to be returned.
+ * @return The value associated with the given key, or null if the key is not present in the cache.
+ */
+ V val(K key);
+
+ /**
+ * Retrieves the key associated with the given value.
+ *
+ * @param val The value whose associated key is to be returned.
+ * @return The key associated with the given value, or null if the value is not present in the cache.
+ */
+ K key(V val);
+
+ /**
+ * Returns true if the cachable contains a key
+ * @param key The key to check for
+ * @return true if exists, false otherwise
+ */
+ boolean hasKey(K key);
+
+ /**
+ * Returns true if the cachable contains a value
+ * @param val The val to check for
+ * @return true if exists, false otherwise
+ */
+ boolean hasVal(V val);
+
+ /**
+ * Caches the specified key-value pair.
+ *
+ * @param key The key to be cached.
+ * @param val The value to be cached.
+ */
+ void cache(K key, V val);
+
+ /**
+ * Removes the specified key-value pair from the cache.
+ *
+ * @param key The key to be removed.
+ * @param val The value to be removed.
+ */
+ void del(K key, V val);
+
+ /**
+ * Removes the entry associated with the specified key from the cache.
+ *
+ * @param key The key to be removed.
+ */
+ void del(K key);
+
+ /**
+ * Caches multiple key-value pairs.
+ *
+ * @param entries A collection of key-value pairs to be cached.
+ */
+ void cacheAll(Collection> entries);
+
+ /**
+ * Caches a key-value map.
+ *
+ * @param entries A key-value map to be cached.
+ */
+ void cacheAll(Map entries);
+
+ /**
+ * Removes multiple entries from the cache based on the specified keys.
+ *
+ * @param keys A collection of keys to be removed.
+ */
+ void delAll(Collection keys);
+
+ /**
+ * Performs the given action for each entry in the cache.
+ *
+ * @param forEach The action to be performed for each entry.
+ */
+ void forEach(PairConsumer forEach);
+
+ /**
+ * Returns the number of entries currently cached.
+ *
+ * @return The number of entries in the cache.
+ */
+ int cached();
+
+ /**
+ * Clears all entries from the cache.
+ */
+ void clear();
+
+ /**
+ * Creates and returns a snapshot of the current state of the cache.
+ *
+ * @return A snapshot of the cache.
+ */
+ CachableSnapshot snapshot();
+}
diff --git a/src/main/java/dev/manere/utils/cachable/CachableSnapshot.java b/src/main/java/dev/manere/utils/cachable/CachableSnapshot.java
new file mode 100644
index 0000000..a5b4a71
--- /dev/null
+++ b/src/main/java/dev/manere/utils/cachable/CachableSnapshot.java
@@ -0,0 +1,45 @@
+package dev.manere.utils.cachable;
+
+import dev.manere.utils.model.Tuple;
+
+import java.util.Collection;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * The {@code CachableSnapshot} interface represents a snapshot or view of a cache's current state.
+ * It provides methods to access the cached entries as a map, list, or collection of key-value pairs.
+ *
+ * WARNING: THIS DOES NOT UPDATE! ONCE CREATED YOUR VALUES WILL BE OLD VALUES IF UPDATED AFTER YOU MADE A SNAPSHOT
+ * @param The type of keys in the cache.
+ * @param The type of values in the cache.
+ */
+public interface CachableSnapshot {
+ /**
+ * Returns the cached entries as an unmodifiable map.
+ *
+ * @return An unmodifiable map view of the cached entries
+ */
+ Map asMap();
+
+ /**
+ * Returns the cached entries as an unmodifiable list.
+ *
+ * @return An unmodifiable list view of the cached entries
+ */
+ List> asList();
+
+ /**
+ * Returns the cached entries as an unmodifiable collection.
+ *
+ * @return An unmodifiable collection view of the cached entries
+ */
+ Collection> asCollection();
+
+ /**
+ * Returns the cached entries as an array of tuples.
+ *
+ * @return An array view of the cached entries
+ */
+ Tuple[] asTupleArray();
+}
diff --git a/src/main/java/dev/manere/utils/cachable/impl/CachableImpl.java b/src/main/java/dev/manere/utils/cachable/impl/CachableImpl.java
new file mode 100644
index 0000000..5dafd22
--- /dev/null
+++ b/src/main/java/dev/manere/utils/cachable/impl/CachableImpl.java
@@ -0,0 +1,147 @@
+package dev.manere.utils.cachable.impl;
+
+import dev.manere.utils.cachable.Cachable;
+import dev.manere.utils.cachable.CachableSnapshot;
+import dev.manere.utils.consumers.PairConsumer;
+import dev.manere.utils.model.Tuple;
+import org.jetbrains.annotations.NotNull;
+
+import java.util.Collection;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+
+public class CachableImpl implements Cachable {
+ /**
+ * Internal {@link ConcurrentHashMap}.
+ */
+ final Map cache = new ConcurrentHashMap<>();
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public V val(K key) {
+ return cache.get(key);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public K key(V val) {
+ for (Map.Entry entry : cache.entrySet()) {
+ if (entry.getValue().equals(val)) {
+ return entry.getKey();
+ }
+ }
+
+ return null;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public boolean hasKey(K key) {
+ return cache.containsKey(key);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public boolean hasVal(V val) {
+ return cache.containsValue(val);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void cache(K key, V val) {
+ cache.put(key, val);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void del(K key, V val) {
+ if (cache.get(key).equals(val)) {
+ cache.remove(key);
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void del(K key) {
+ cache.remove(key);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void cacheAll(Collection> entries) {
+ for (Tuple entry : entries) {
+ cache(entry.key(), entry.val());
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void cacheAll(Map entries) {
+ for (Map.Entry entry : entries.entrySet()) {
+ K key = entry.getKey();
+ V val = entry.getValue();
+
+ cache(key, val);
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void delAll(Collection keys) {
+ for (K key : keys) {
+ cache.remove(key);
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void forEach(PairConsumer forEach) {
+ cache.forEach(forEach::execute);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public int cached() {
+ return cache.size();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void clear() {
+ cache.clear();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public @NotNull CachableSnapshot snapshot() {
+ return new CachableSnapshotImpl<>(this);
+ }
+}
diff --git a/src/main/java/dev/manere/utils/cachable/impl/CachableSnapshotImpl.java b/src/main/java/dev/manere/utils/cachable/impl/CachableSnapshotImpl.java
new file mode 100644
index 0000000..e4249aa
--- /dev/null
+++ b/src/main/java/dev/manere/utils/cachable/impl/CachableSnapshotImpl.java
@@ -0,0 +1,69 @@
+package dev.manere.utils.cachable.impl;
+
+import dev.manere.utils.cachable.CachableSnapshot;
+import dev.manere.utils.model.Tuple;
+
+import java.lang.reflect.Array;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+import java.util.Map;
+
+public class CachableSnapshotImpl implements CachableSnapshot {
+ /**
+ * Internal {@link CachableImpl}
+ */
+ private final CachableImpl cachable;
+
+ CachableSnapshotImpl(CachableImpl cachable) {
+ this.cachable = cachable;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public Map asMap() {
+ return cachable.cache;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public List> asList() {
+ List> list = new ArrayList<>();
+
+ for (K key : cachable.cache.keySet()) {
+ for (V val : cachable.cache.values()) {
+ list.add(Tuple.duo(key, val));
+ }
+ }
+
+ return list;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public Collection> asCollection() {
+ return asList();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public Tuple[] asTupleArray() {
+ @SuppressWarnings("unchecked")
+ Tuple[] tuples = (Tuple[]) Array.newInstance(Tuple.class, asList().size());
+
+ int i = 0;
+ for (Tuple tuple : asList()) {
+ tuples[i++] = tuple;
+ }
+
+ return tuples;
+ }
+}
diff --git a/src/main/java/dev/manere/utils/command/CommandSettings.java b/src/main/java/dev/manere/utils/command/CommandConfig.java
similarity index 65%
rename from src/main/java/dev/manere/utils/command/CommandSettings.java
rename to src/main/java/dev/manere/utils/command/CommandConfig.java
index ec472ff..a78f2c2 100644
--- a/src/main/java/dev/manere/utils/command/CommandSettings.java
+++ b/src/main/java/dev/manere/utils/command/CommandConfig.java
@@ -1,27 +1,27 @@
package dev.manere.utils.command;
-import dev.manere.utils.command.builder.dispatcher.CommandDispatcher;
-import dev.manere.utils.command.builder.dispatcher.SuggestionDispatcher;
+import dev.manere.utils.command.impl.dispatcher.CommandDispatcher;
+import dev.manere.utils.command.impl.dispatcher.SuggestionDispatcher;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
-import java.util.List;
+import java.util.ArrayList;
/**
* Class representing settings for a {@link Commander} command.
*/
-public class CommandSettings {
+public class CommandConfig {
private CommandDispatcher executes;
private SuggestionDispatcher completes;
- private CommandType type;
+ private CommandTypes type;
/**
* Creates settings with default executor and completer.
*/
- public CommandSettings() {
- this.type = CommandType.PLUGIN_YML;
+ public CommandConfig() {
+ this.type = CommandTypes.PLUGIN_YML;
this.executes = context -> true;
- this.completes = context -> List.of();
+ this.completes = context -> new ArrayList<>();
}
/**
@@ -30,8 +30,8 @@ public CommandSettings() {
* @param executes The execute dispatcher
* @param completes The complete dispatcher
*/
- public CommandSettings(CommandDispatcher executes, SuggestionDispatcher completes) {
- this.type = CommandType.PLUGIN_YML;
+ public CommandConfig(CommandDispatcher executes, SuggestionDispatcher completes) {
+ this.type = CommandTypes.PLUGIN_YML;
this.executes = executes;
this.completes = completes;
}
@@ -43,7 +43,7 @@ public CommandSettings(CommandDispatcher executes, SuggestionDispatcher complete
* @param executes The execute dispatcher
* @param completes The complete dispatcher
*/
- public CommandSettings(CommandType type, CommandDispatcher executes, SuggestionDispatcher completes) {
+ public CommandConfig(CommandTypes type, CommandDispatcher executes, SuggestionDispatcher completes) {
this.type = type;
this.executes = executes;
this.completes = completes;
@@ -54,8 +54,8 @@ public CommandSettings(CommandType type, CommandDispatcher executes, SuggestionD
*
* @return The default settings
*/
- public static @NotNull CommandSettings settings() {
- return new CommandSettings();
+ public static @NotNull CommandConfig settings() {
+ return new CommandConfig();
}
/**
@@ -65,8 +65,8 @@ public CommandSettings(CommandType type, CommandDispatcher executes, SuggestionD
* @param completes The complete dispatcher
* @return The settings
*/
- public static @NotNull CommandSettings settings(@Nullable CommandDispatcher executes, @Nullable SuggestionDispatcher completes) {
- return new CommandSettings(executes, completes);
+ public static @NotNull CommandConfig settings(@Nullable CommandDispatcher executes, @Nullable SuggestionDispatcher completes) {
+ return new CommandConfig(executes, completes);
}
/**
@@ -77,8 +77,8 @@ public CommandSettings(CommandType type, CommandDispatcher executes, SuggestionD
* @param completes The complete dispatcher
* @return The settings
*/
- public static @NotNull CommandSettings settings(@NotNull CommandType type, @Nullable CommandDispatcher executes, @Nullable SuggestionDispatcher completes) {
- return new CommandSettings(type, executes, completes);
+ public static @NotNull CommandConfig settings(@NotNull CommandTypes type, @Nullable CommandDispatcher executes, @Nullable SuggestionDispatcher completes) {
+ return new CommandConfig(type, executes, completes);
}
/**
@@ -96,7 +96,7 @@ public CommandSettings(CommandType type, CommandDispatcher executes, SuggestionD
* @param executes The new dispatcher
* @return This settings instance
*/
- public @NotNull CommandSettings executes(@Nullable CommandDispatcher executes) {
+ public @NotNull CommandConfig executes(@Nullable CommandDispatcher executes) {
this.executes = executes;
return this;
}
@@ -116,7 +116,7 @@ public CommandSettings(CommandType type, CommandDispatcher executes, SuggestionD
* @param completes The new dispatcher
* @return This settings instance
*/
- public @NotNull CommandSettings completes(@Nullable SuggestionDispatcher completes) {
+ public @NotNull CommandConfig completes(@Nullable SuggestionDispatcher completes) {
this.completes = completes;
return this;
}
@@ -126,7 +126,7 @@ public CommandSettings(CommandType type, CommandDispatcher executes, SuggestionD
*
* @return The type
*/
- public @NotNull CommandType type() {
+ public @NotNull CommandTypes type() {
return type;
}
@@ -136,7 +136,7 @@ public CommandSettings(CommandType type, CommandDispatcher executes, SuggestionD
* @param type The new type
* @return This settings instance
*/
- public @NotNull CommandSettings type(@NotNull CommandType type) {
+ public @NotNull CommandConfig type(@NotNull CommandTypes type) {
this.type = type;
return this;
}
diff --git a/src/main/java/dev/manere/utils/command/CommandType.java b/src/main/java/dev/manere/utils/command/CommandType.java
deleted file mode 100644
index 9ffca0f..0000000
--- a/src/main/java/dev/manere/utils/command/CommandType.java
+++ /dev/null
@@ -1,22 +0,0 @@
-package dev.manere.utils.command;
-
-import org.bukkit.command.CommandMap;
-import org.bukkit.plugin.java.JavaPlugin;
-
-/**
- * An enumeration representing the registration system to use.
- */
-public enum CommandType {
-
- /**
- * Self-explanatory. Uses the plugin.yml file
- * and {@link JavaPlugin#getCommand(String)} to retrieve and register the command.
- */
- PLUGIN_YML,
-
- /**
- * Used for registering commands via the {@link CommandMap}
- * Does not require the command to be in the plugin.yml of your project.
- */
- COMMAND_MAP,
-}
diff --git a/src/main/java/dev/manere/utils/command/CommandTypes.java b/src/main/java/dev/manere/utils/command/CommandTypes.java
new file mode 100644
index 0000000..a00dbcb
--- /dev/null
+++ b/src/main/java/dev/manere/utils/command/CommandTypes.java
@@ -0,0 +1,77 @@
+package dev.manere.utils.command;
+
+import org.bukkit.Bukkit;
+import org.bukkit.command.CommandMap;
+import org.bukkit.plugin.java.JavaPlugin;
+
+/**
+ * An enumeration representing the registration system to use.
+ */
+public class CommandTypes {
+ private final int type;
+
+ private CommandTypes(int type) {
+ this.type = type;
+ }
+
+ /**
+ * Self-explanatory. Uses the plugin.yml file
+ * and {@link JavaPlugin#getCommand(String)} to retrieve and register the command.
+ */
+ public static final CommandTypes PLUGIN_YML = CommandTypes.type(0);
+
+ /**
+ * Used for registering commands via the {@link CommandMap}
+ * Does not require the command to be in the plugin.yml of your project.
+ *
+ * If you have a command of {@code /hello} and your plugin's name is HelloPlugin
+ * then it will register with the default namespace of your plugin: {@code /helloplugin:hello}
+ *
+ * Access to the command map is provided via the {@link Bukkit#getCommandMap()} method.
+ */
+ public static final CommandTypes COMMAND_MAP = CommandTypes.type(1);
+
+ public static CommandTypes pluginYml() {
+ return PLUGIN_YML;
+ }
+
+ public static CommandTypes plugin() {
+ return pluginYml();
+ }
+
+ public static CommandTypes descriptionFile() {
+ return pluginYml();
+ }
+
+ public static CommandTypes descFile() {
+ return pluginYml();
+ }
+
+ public static CommandTypes pluginMeta() {
+ return pluginYml();
+ }
+
+ public static CommandTypes meta() {
+ return pluginYml();
+ }
+
+ public static CommandTypes commandMap() {
+ return COMMAND_MAP;
+ }
+
+ public static CommandTypes map() {
+ return commandMap();
+ }
+
+ public static CommandTypes paper() {
+ return commandMap();
+ }
+
+ public int type() {
+ return type;
+ }
+
+ public static CommandTypes type(int type) {
+ return new CommandTypes(type);
+ }
+}
diff --git a/src/main/java/dev/manere/utils/command/Commander.java b/src/main/java/dev/manere/utils/command/Commander.java
index f6bfd75..0471f14 100644
--- a/src/main/java/dev/manere/utils/command/Commander.java
+++ b/src/main/java/dev/manere/utils/command/Commander.java
@@ -1,21 +1,21 @@
package dev.manere.utils.command;
import dev.manere.utils.command.annotation.AutoRegister;
-import dev.manere.utils.command.builder.CommandBuilder;
-import dev.manere.utils.command.builder.dispatcher.CommandDispatcher;
-import dev.manere.utils.command.builder.dispatcher.SuggestionDispatcher;
+import dev.manere.utils.command.impl.Commands;
+import dev.manere.utils.command.impl.dispatcher.CommandDispatcher;
+import dev.manere.utils.command.impl.dispatcher.SuggestionDispatcher;
import org.jetbrains.annotations.NotNull;
import java.util.ArrayList;
import java.util.List;
/**
- * Bukkit-like wrapper for a command, uses {@link CommandBuilder}.
- * @see CommandBuilder
+ * Bukkit-like wrapper for a command, uses {@link Commands}.
+ * @see Commands
* @see AutoRegister
*/
public abstract class Commander implements CommandDispatcher, SuggestionDispatcher {
- private CommandSettings settings;
+ private CommandConfig settings;
private String name;
private final List aliases = new ArrayList<>();
private String description;
@@ -27,7 +27,7 @@ public abstract class Commander implements CommandDispatcher, SuggestionDispatch
* @param name The name of the command to use for registration.
*/
public Commander(String name) {
- this.settings = CommandSettings.settings();
+ this.settings = CommandConfig.settings();
this.name = name;
}
@@ -36,7 +36,7 @@ public Commander(String name) {
*
* @return The command settings
*/
- public @NotNull CommandSettings settings() {
+ public @NotNull CommandConfig settings() {
return settings;
}
@@ -55,7 +55,7 @@ public Commander(String name) {
* @param settings The new settings
* @return This commander instance
*/
- public @NotNull Commander settings(@NotNull CommandSettings settings) {
+ public @NotNull Commander settings(@NotNull CommandConfig settings) {
this.settings = settings;
return this;
}
diff --git a/src/main/java/dev/manere/utils/command/annotation/AutoRegister.java b/src/main/java/dev/manere/utils/command/annotation/AutoRegister.java
index 9f30ff6..da50d8f 100644
--- a/src/main/java/dev/manere/utils/command/annotation/AutoRegister.java
+++ b/src/main/java/dev/manere/utils/command/annotation/AutoRegister.java
@@ -16,6 +16,4 @@
*/
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE)
-public @interface AutoRegister {
-
-}
+public @interface AutoRegister {}
diff --git a/src/main/java/dev/manere/utils/command/annotation/AutoRegisterHandler.java b/src/main/java/dev/manere/utils/command/annotation/AutoRegisterHandler.java
index 698191a..89268d0 100644
--- a/src/main/java/dev/manere/utils/command/annotation/AutoRegisterHandler.java
+++ b/src/main/java/dev/manere/utils/command/annotation/AutoRegisterHandler.java
@@ -1,11 +1,11 @@
package dev.manere.utils.command.annotation;
-import dev.manere.utils.command.CommandType;
+import dev.manere.utils.command.CommandTypes;
import dev.manere.utils.command.Commander;
import dev.manere.utils.event.EventListener;
import dev.manere.utils.library.Utils;
import dev.manere.utils.logger.Loggers;
-import dev.manere.utils.model.Duo;
+import dev.manere.utils.model.Tuple;
import dev.manere.utils.registration.Registrar;
import org.bukkit.plugin.java.JavaPlugin;
import org.jetbrains.annotations.NotNull;
@@ -25,7 +25,6 @@
* @see AutoRegister
*/
public class AutoRegisterHandler {
-
/**
* Scans the project using this library and then
* attempts to register the class as an event listener or command.
@@ -59,7 +58,7 @@ public static void scanAndRegister() {
}
}
- private static @NotNull Duo findInstance(@NotNull Class> clazz) {
+ private static @NotNull Tuple findInstance(@NotNull Class> clazz) {
Constructor>[] constructors = clazz.getDeclaredConstructors();
Object instance = null;
@@ -101,12 +100,12 @@ else if (Modifier.isPrivate(modifiers)) {
}
- return new Duo<>(mode, instance);
+ return new Tuple<>(mode, instance);
}
private static void autoRegister(@NotNull Class> clazz) {
JavaPlugin plugin = Utils.plugin();
- Duo tuple = findInstance(clazz);
+ Tuple tuple = findInstance(clazz);
Object instance = tuple.val();
@@ -128,7 +127,7 @@ private static void autoRegister(@NotNull Class> clazz) {
} else if (Commander.class.isAssignableFrom(clazz)) {
Commander commander = (Commander) instance;
- if (commander.settings().type() == CommandType.PLUGIN_YML) {
+ if (commander.settings().type() == CommandTypes.PLUGIN_YML) {
Registrar.command(commander);
} else {
Registrar.command(
@@ -183,7 +182,7 @@ private static void autoRegister(@NotNull Class> clazz) {
return classes;
}
- private static @NotNull File src() {
+ public static @NotNull File src() {
try {
JavaPlugin plugin = (JavaPlugin) Utils.plugin().getServer().getPluginManager().getPlugin(Utils.plugin().getName());
Method getFileMethod = JavaPlugin.class.getDeclaredMethod("getFile");
diff --git a/src/main/java/dev/manere/utils/command/args/Argument.java b/src/main/java/dev/manere/utils/command/args/Argument.java
index 7cd448c..f05fb9b 100644
--- a/src/main/java/dev/manere/utils/command/args/Argument.java
+++ b/src/main/java/dev/manere/utils/command/args/Argument.java
@@ -2,8 +2,8 @@
import dev.manere.utils.command.args.custom.CustomArgument;
import dev.manere.utils.command.args.exception.ArgumentExType;
-import dev.manere.utils.command.builder.dispatcher.CommandContext;
-import dev.manere.utils.command.builder.dispatcher.SuggestionDispatcher;
+import dev.manere.utils.command.impl.dispatcher.CommandContext;
+import dev.manere.utils.command.impl.dispatcher.SuggestionDispatcher;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
diff --git a/src/main/java/dev/manere/utils/command/args/custom/CustomArgument.java b/src/main/java/dev/manere/utils/command/args/custom/CustomArgument.java
index d916ba1..f846a65 100644
--- a/src/main/java/dev/manere/utils/command/args/custom/CustomArgument.java
+++ b/src/main/java/dev/manere/utils/command/args/custom/CustomArgument.java
@@ -1,7 +1,7 @@
package dev.manere.utils.command.args.custom;
import dev.manere.utils.command.args.exception.ArgumentParseException;
-import dev.manere.utils.command.builder.dispatcher.CommandContext;
+import dev.manere.utils.command.impl.dispatcher.CommandContext;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -11,7 +11,6 @@
* @param The type to which the argument will be parsed.
*/
public interface CustomArgument {
-
/**
* Parses the given argument into the specified type.
*
diff --git a/src/main/java/dev/manere/utils/command/args/custom/CustomListArgument.java b/src/main/java/dev/manere/utils/command/args/custom/CustomListArgument.java
index b0419c3..3d5310c 100644
--- a/src/main/java/dev/manere/utils/command/args/custom/CustomListArgument.java
+++ b/src/main/java/dev/manere/utils/command/args/custom/CustomListArgument.java
@@ -1,7 +1,7 @@
package dev.manere.utils.command.args.custom;
import dev.manere.utils.command.args.exception.ArgumentParseException;
-import dev.manere.utils.command.builder.dispatcher.CommandContext;
+import dev.manere.utils.command.impl.dispatcher.CommandContext;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -10,8 +10,7 @@
/**
* Represents a custom argument that deals with a list of string arguments.
*/
-public abstract class CustomListArgument implements CustomArgument> {
-
+public abstract class CustomListArgument implements CustomArgument> {
/**
* Parses a list of string arguments into a specific type.
*
@@ -20,7 +19,7 @@ public abstract class CustomListArgument implements CustomArgument> {
* @throws ArgumentParseException If an error occurs during the parsing process.
*/
@Nullable
- public abstract String parse(@Nullable List args) throws ArgumentParseException;
+ public abstract T parse(@Nullable List args) throws ArgumentParseException;
/**
* Parses a specific string argument at the given index into a specific type.
@@ -31,7 +30,7 @@ public abstract class CustomListArgument implements CustomArgument> {
* @throws ArgumentParseException If an error occurs during the parsing process.
*/
@Nullable
- public abstract String parse(@NotNull CommandContext ctx, int indexStart) throws ArgumentParseException;
+ public abstract T parse(@NotNull CommandContext ctx, int indexStart) throws ArgumentParseException;
/**
* Parses a string argument into a list of a specific type.
@@ -41,7 +40,7 @@ public abstract class CustomListArgument implements CustomArgument> {
* @return The parsed list, or null if parsing fails.
*/
@Nullable
- public List> parse(@NotNull CommandContext ctx, @Nullable String arg) {
+ public List parse(@NotNull CommandContext ctx, @Nullable String arg) {
return null;
}
}
diff --git a/src/main/java/dev/manere/utils/command/args/entity/CachedOfflinePlayerArgument.java b/src/main/java/dev/manere/utils/command/args/entity/CachedOfflinePlayerArgument.java
index 83b524e..83cdf6f 100644
--- a/src/main/java/dev/manere/utils/command/args/entity/CachedOfflinePlayerArgument.java
+++ b/src/main/java/dev/manere/utils/command/args/entity/CachedOfflinePlayerArgument.java
@@ -3,7 +3,7 @@
import dev.manere.utils.command.args.exception.ArgumentParseException;
import dev.manere.utils.command.args.exception.ArgumentExType;
import dev.manere.utils.command.args.custom.CustomArgument;
-import dev.manere.utils.command.builder.dispatcher.CommandContext;
+import dev.manere.utils.command.impl.dispatcher.CommandContext;
import dev.manere.utils.server.ServerUtils;
import org.bukkit.OfflinePlayer;
import org.jetbrains.annotations.NotNull;
diff --git a/src/main/java/dev/manere/utils/command/args/entity/EntityTypeArgument.java b/src/main/java/dev/manere/utils/command/args/entity/EntityTypeArgument.java
index bd8fb7c..0a294c6 100644
--- a/src/main/java/dev/manere/utils/command/args/entity/EntityTypeArgument.java
+++ b/src/main/java/dev/manere/utils/command/args/entity/EntityTypeArgument.java
@@ -3,7 +3,7 @@
import dev.manere.utils.command.args.exception.ArgumentParseException;
import dev.manere.utils.command.args.exception.ArgumentExType;
import dev.manere.utils.command.args.custom.CustomArgument;
-import dev.manere.utils.command.builder.dispatcher.CommandContext;
+import dev.manere.utils.command.impl.dispatcher.CommandContext;
import org.bukkit.entity.EntityType;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
diff --git a/src/main/java/dev/manere/utils/command/args/entity/OfflinePlayerArgument.java b/src/main/java/dev/manere/utils/command/args/entity/OfflinePlayerArgument.java
index 54efc30..63a6f12 100644
--- a/src/main/java/dev/manere/utils/command/args/entity/OfflinePlayerArgument.java
+++ b/src/main/java/dev/manere/utils/command/args/entity/OfflinePlayerArgument.java
@@ -3,7 +3,7 @@
import dev.manere.utils.command.args.exception.ArgumentParseException;
import dev.manere.utils.command.args.exception.ArgumentExType;
import dev.manere.utils.command.args.custom.CustomArgument;
-import dev.manere.utils.command.builder.dispatcher.CommandContext;
+import dev.manere.utils.command.impl.dispatcher.CommandContext;
import dev.manere.utils.server.ServerUtils;
import org.bukkit.OfflinePlayer;
import org.jetbrains.annotations.NotNull;
diff --git a/src/main/java/dev/manere/utils/command/args/entity/PlayerArgument.java b/src/main/java/dev/manere/utils/command/args/entity/PlayerArgument.java
index bf42ffc..fbc8e02 100644
--- a/src/main/java/dev/manere/utils/command/args/entity/PlayerArgument.java
+++ b/src/main/java/dev/manere/utils/command/args/entity/PlayerArgument.java
@@ -3,7 +3,7 @@
import dev.manere.utils.command.args.exception.ArgumentParseException;
import dev.manere.utils.command.args.exception.ArgumentExType;
import dev.manere.utils.command.args.custom.CustomArgument;
-import dev.manere.utils.command.builder.dispatcher.CommandContext;
+import dev.manere.utils.command.impl.dispatcher.CommandContext;
import dev.manere.utils.player.PlayerUtils;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
diff --git a/src/main/java/dev/manere/utils/command/args/exception/ArgumentExType.java b/src/main/java/dev/manere/utils/command/args/exception/ArgumentExType.java
index 2e12e57..d04715b 100644
--- a/src/main/java/dev/manere/utils/command/args/exception/ArgumentExType.java
+++ b/src/main/java/dev/manere/utils/command/args/exception/ArgumentExType.java
@@ -1,5 +1,7 @@
package dev.manere.utils.command.args.exception;
+import dev.manere.utils.command.args.primitive.IntegerArgument;
+
/**
* Enum representing different types of argument parsing exceptions.
*/
@@ -17,5 +19,11 @@ public enum ArgumentExType {
/**
* Indicates that the syntax of the command is invalid. (Incorrect Usage)
*/
- INVALID_SYNTAX
+ INVALID_SYNTAX,
+
+ /**
+ * Indicates that the argument provided is not within the expected integer range.
+ * @see IntegerArgument
+ */
+ INVALID_RANGE
}
diff --git a/src/main/java/dev/manere/utils/command/args/exception/ArgumentParseException.java b/src/main/java/dev/manere/utils/command/args/exception/ArgumentParseException.java
index 377deb6..a374f15 100644
--- a/src/main/java/dev/manere/utils/command/args/exception/ArgumentParseException.java
+++ b/src/main/java/dev/manere/utils/command/args/exception/ArgumentParseException.java
@@ -3,7 +3,7 @@
/**
* Exception thrown when there is an issue parsing command arguments.
*/
-public class ArgumentParseException extends Exception {
+public class ArgumentParseException extends RuntimeException {
private final ArgumentExType type;
/**
diff --git a/src/main/java/dev/manere/utils/command/args/misc/GamemodeArgument.java b/src/main/java/dev/manere/utils/command/args/misc/GamemodeArgument.java
index 1bc8322..8fffa41 100644
--- a/src/main/java/dev/manere/utils/command/args/misc/GamemodeArgument.java
+++ b/src/main/java/dev/manere/utils/command/args/misc/GamemodeArgument.java
@@ -3,7 +3,7 @@
import dev.manere.utils.command.args.exception.ArgumentParseException;
import dev.manere.utils.command.args.exception.ArgumentExType;
import dev.manere.utils.command.args.custom.CustomArgument;
-import dev.manere.utils.command.builder.dispatcher.CommandContext;
+import dev.manere.utils.command.impl.dispatcher.CommandContext;
import org.bukkit.GameMode;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
diff --git a/src/main/java/dev/manere/utils/command/args/primitive/BooleanArgument.java b/src/main/java/dev/manere/utils/command/args/primitive/BooleanArgument.java
index 0c04a0d..8220893 100644
--- a/src/main/java/dev/manere/utils/command/args/primitive/BooleanArgument.java
+++ b/src/main/java/dev/manere/utils/command/args/primitive/BooleanArgument.java
@@ -3,7 +3,7 @@
import dev.manere.utils.command.args.exception.ArgumentParseException;
import dev.manere.utils.command.args.exception.ArgumentExType;
import dev.manere.utils.command.args.custom.CustomArgument;
-import dev.manere.utils.command.builder.dispatcher.CommandContext;
+import dev.manere.utils.command.impl.dispatcher.CommandContext;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
diff --git a/src/main/java/dev/manere/utils/command/args/primitive/DoubleArgument.java b/src/main/java/dev/manere/utils/command/args/primitive/DoubleArgument.java
index ef27566..8549e78 100644
--- a/src/main/java/dev/manere/utils/command/args/primitive/DoubleArgument.java
+++ b/src/main/java/dev/manere/utils/command/args/primitive/DoubleArgument.java
@@ -3,7 +3,7 @@
import dev.manere.utils.command.args.exception.ArgumentParseException;
import dev.manere.utils.command.args.exception.ArgumentExType;
import dev.manere.utils.command.args.custom.CustomArgument;
-import dev.manere.utils.command.builder.dispatcher.CommandContext;
+import dev.manere.utils.command.impl.dispatcher.CommandContext;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
diff --git a/src/main/java/dev/manere/utils/command/args/primitive/FloatArgument.java b/src/main/java/dev/manere/utils/command/args/primitive/FloatArgument.java
index e03d289..7011069 100644
--- a/src/main/java/dev/manere/utils/command/args/primitive/FloatArgument.java
+++ b/src/main/java/dev/manere/utils/command/args/primitive/FloatArgument.java
@@ -3,7 +3,7 @@
import dev.manere.utils.command.args.exception.ArgumentParseException;
import dev.manere.utils.command.args.exception.ArgumentExType;
import dev.manere.utils.command.args.custom.CustomArgument;
-import dev.manere.utils.command.builder.dispatcher.CommandContext;
+import dev.manere.utils.command.impl.dispatcher.CommandContext;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
diff --git a/src/main/java/dev/manere/utils/command/args/primitive/IntegerArgument.java b/src/main/java/dev/manere/utils/command/args/primitive/IntegerArgument.java
index e2e8364..cd39c48 100644
--- a/src/main/java/dev/manere/utils/command/args/primitive/IntegerArgument.java
+++ b/src/main/java/dev/manere/utils/command/args/primitive/IntegerArgument.java
@@ -3,15 +3,32 @@
import dev.manere.utils.command.args.exception.ArgumentParseException;
import dev.manere.utils.command.args.exception.ArgumentExType;
import dev.manere.utils.command.args.custom.CustomArgument;
-import dev.manere.utils.command.builder.dispatcher.CommandContext;
+import dev.manere.utils.command.impl.dispatcher.CommandContext;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
public class IntegerArgument implements CustomArgument {
+ private final @Nullable Integer max;
+ private final @Nullable Integer min;
+
+ public IntegerArgument(int min, int max) {
+ this.max = max;
+ this.min = min;
+ }
+
+ public IntegerArgument() {
+ this.min = null;
+ this.max = null;
+ }
+
public static IntegerArgument arg() {
return new IntegerArgument();
}
+ public static IntegerArgument arg(@Nullable Integer min, @Nullable Integer max) {
+ return new IntegerArgument(min, max);
+ }
+
/**
* {@inheritDoc}
*/
@@ -22,7 +39,17 @@ public static IntegerArgument arg() {
}
try {
- return Integer.parseInt(arg);
+ int value = Integer.parseInt(arg);
+
+ if (min != null && value < min) {
+ throw new ArgumentParseException("Value must be greater than " + min, ArgumentExType.INVALID_RANGE);
+ }
+
+ if (max != null && value > max) {
+ throw new ArgumentParseException("Value must be less than " + max, ArgumentExType.INVALID_RANGE);
+ }
+
+ return value;
} catch (NumberFormatException e) {
throw new ArgumentParseException("Invalid Integer/Number provided.", ArgumentExType.INVALID_SYNTAX);
}
diff --git a/src/main/java/dev/manere/utils/command/args/primitive/LongArgument.java b/src/main/java/dev/manere/utils/command/args/primitive/LongArgument.java
index 9b116bc..b6562b8 100644
--- a/src/main/java/dev/manere/utils/command/args/primitive/LongArgument.java
+++ b/src/main/java/dev/manere/utils/command/args/primitive/LongArgument.java
@@ -3,7 +3,7 @@
import dev.manere.utils.command.args.exception.ArgumentParseException;
import dev.manere.utils.command.args.exception.ArgumentExType;
import dev.manere.utils.command.args.custom.CustomArgument;
-import dev.manere.utils.command.builder.dispatcher.CommandContext;
+import dev.manere.utils.command.impl.dispatcher.CommandContext;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
diff --git a/src/main/java/dev/manere/utils/command/args/text/ComponentArgument.java b/src/main/java/dev/manere/utils/command/args/text/ComponentArgument.java
index 02f7514..7bd7e85 100644
--- a/src/main/java/dev/manere/utils/command/args/text/ComponentArgument.java
+++ b/src/main/java/dev/manere/utils/command/args/text/ComponentArgument.java
@@ -3,7 +3,7 @@
import dev.manere.utils.command.args.exception.ArgumentParseException;
import dev.manere.utils.command.args.exception.ArgumentExType;
import dev.manere.utils.command.args.custom.CustomArgument;
-import dev.manere.utils.command.builder.dispatcher.CommandContext;
+import dev.manere.utils.command.impl.dispatcher.CommandContext;
import dev.manere.utils.text.color.TextStyle;
import net.kyori.adventure.text.Component;
import org.jetbrains.annotations.NotNull;
diff --git a/src/main/java/dev/manere/utils/command/args/text/ComponentListArgument.java b/src/main/java/dev/manere/utils/command/args/text/ComponentListArgument.java
new file mode 100644
index 0000000..399fd84
--- /dev/null
+++ b/src/main/java/dev/manere/utils/command/args/text/ComponentListArgument.java
@@ -0,0 +1,44 @@
+package dev.manere.utils.command.args.text;
+
+import dev.manere.utils.command.args.custom.CustomListArgument;
+import dev.manere.utils.command.args.exception.ArgumentExType;
+import dev.manere.utils.command.args.exception.ArgumentParseException;
+import dev.manere.utils.command.impl.dispatcher.CommandContext;
+import dev.manere.utils.text.color.TextStyle;
+import net.kyori.adventure.text.Component;
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
+
+import java.util.List;
+
+public class ComponentListArgument extends CustomListArgument {
+ public static ComponentListArgument arg() {
+ return new ComponentListArgument();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public @Nullable Component parse(@Nullable List args) throws ArgumentParseException {
+ if (args == null || args.isEmpty()) {
+ throw new ArgumentParseException("CustomArgument list cannot be null or empty", ArgumentExType.ARG_IS_NULL);
+ }
+
+ return TextStyle.style(String.join(" ", args));
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public @Nullable Component parse(@NotNull CommandContext ctx, int indexStart) throws ArgumentParseException {
+ List rawArgs = ctx.rawArgs();
+
+ if (indexStart < 0 || indexStart >= rawArgs.size()) {
+ throw new ArgumentParseException("Invalid indexStart value", ArgumentExType.INVALID_SYNTAX);
+ }
+
+ return parse(rawArgs.subList(indexStart, rawArgs.size()));
+ }
+}
diff --git a/src/main/java/dev/manere/utils/command/args/text/StringArgument.java b/src/main/java/dev/manere/utils/command/args/text/StringArgument.java
index ebf3c55..72a222f 100644
--- a/src/main/java/dev/manere/utils/command/args/text/StringArgument.java
+++ b/src/main/java/dev/manere/utils/command/args/text/StringArgument.java
@@ -3,7 +3,7 @@
import dev.manere.utils.command.args.exception.ArgumentParseException;
import dev.manere.utils.command.args.exception.ArgumentExType;
import dev.manere.utils.command.args.custom.CustomArgument;
-import dev.manere.utils.command.builder.dispatcher.CommandContext;
+import dev.manere.utils.command.impl.dispatcher.CommandContext;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
diff --git a/src/main/java/dev/manere/utils/command/args/text/StringListArgument.java b/src/main/java/dev/manere/utils/command/args/text/StringListArgument.java
index d868921..4d0e5c3 100644
--- a/src/main/java/dev/manere/utils/command/args/text/StringListArgument.java
+++ b/src/main/java/dev/manere/utils/command/args/text/StringListArgument.java
@@ -3,13 +3,13 @@
import dev.manere.utils.command.args.exception.ArgumentParseException;
import dev.manere.utils.command.args.exception.ArgumentExType;
import dev.manere.utils.command.args.custom.CustomListArgument;
-import dev.manere.utils.command.builder.dispatcher.CommandContext;
+import dev.manere.utils.command.impl.dispatcher.CommandContext;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.List;
-public class StringListArgument extends CustomListArgument {
+public class StringListArgument extends CustomListArgument {
public static StringListArgument arg() {
return new StringListArgument();
}
diff --git a/src/main/java/dev/manere/utils/command/args/text/TextArgument.java b/src/main/java/dev/manere/utils/command/args/text/TextArgument.java
index 570d784..e8049ca 100644
--- a/src/main/java/dev/manere/utils/command/args/text/TextArgument.java
+++ b/src/main/java/dev/manere/utils/command/args/text/TextArgument.java
@@ -3,7 +3,7 @@
import dev.manere.utils.command.args.exception.ArgumentParseException;
import dev.manere.utils.command.args.exception.ArgumentExType;
import dev.manere.utils.command.args.custom.CustomArgument;
-import dev.manere.utils.command.builder.dispatcher.CommandContext;
+import dev.manere.utils.command.impl.dispatcher.CommandContext;
import dev.manere.utils.text.Text;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
diff --git a/src/main/java/dev/manere/utils/command/args/text/TextListArgument.java b/src/main/java/dev/manere/utils/command/args/text/TextListArgument.java
new file mode 100644
index 0000000..f5c8329
--- /dev/null
+++ b/src/main/java/dev/manere/utils/command/args/text/TextListArgument.java
@@ -0,0 +1,43 @@
+package dev.manere.utils.command.args.text;
+
+import dev.manere.utils.command.args.custom.CustomListArgument;
+import dev.manere.utils.command.args.exception.ArgumentExType;
+import dev.manere.utils.command.args.exception.ArgumentParseException;
+import dev.manere.utils.command.impl.dispatcher.CommandContext;
+import dev.manere.utils.text.Text;
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
+
+import java.util.List;
+
+public class TextListArgument extends CustomListArgument {
+ public static TextListArgument arg() {
+ return new TextListArgument();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public @Nullable Text parse(@Nullable List args) throws ArgumentParseException {
+ if (args == null || args.isEmpty()) {
+ throw new ArgumentParseException("CustomArgument list cannot be null or empty", ArgumentExType.ARG_IS_NULL);
+ }
+
+ return Text.text(String.join(" ", args));
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public @Nullable Text parse(@NotNull CommandContext ctx, int indexStart) throws ArgumentParseException {
+ List rawArgs = ctx.rawArgs();
+
+ if (indexStart < 0 || indexStart >= rawArgs.size()) {
+ throw new ArgumentParseException("Invalid indexStart value", ArgumentExType.INVALID_SYNTAX);
+ }
+
+ return parse(rawArgs.subList(indexStart, rawArgs.size()));
+ }
+}
diff --git a/src/main/java/dev/manere/utils/command/builder/CommandBuilder.java b/src/main/java/dev/manere/utils/command/builder/CommandBuilder.java
deleted file mode 100644
index 1782e17..0000000
--- a/src/main/java/dev/manere/utils/command/builder/CommandBuilder.java
+++ /dev/null
@@ -1,237 +0,0 @@
-package dev.manere.utils.command.builder;
-
-import dev.manere.utils.command.CommandType;
-import dev.manere.utils.command.args.Argument;
-import dev.manere.utils.command.builder.alias.CommandAliasBuilder;
-import dev.manere.utils.command.builder.dispatcher.CommandContext;
-import dev.manere.utils.command.builder.dispatcher.CommandDispatcher;
-import dev.manere.utils.command.builder.dispatcher.SuggestionDispatcher;
-import dev.manere.utils.command.builder.permission.CommandPermissionBuilder;
-import dev.manere.utils.text.color.TextStyle;
-import org.bukkit.command.Command;
-import org.bukkit.command.CommandSender;
-import org.jetbrains.annotations.NotNull;
-import org.jetbrains.annotations.Nullable;
-
-import java.util.ArrayList;
-import java.util.List;
-import java.util.function.Predicate;
-
-/**
- * A utility class for building and configuring Bukkit plugin commands.
- */
-public class CommandBuilder {
- private final String name;
- private final CommandType type;
- private CommandDispatcher dispatcher;
- private SuggestionDispatcher suggestionDispatcher;
- private final Command command;
- private final List> requirements;
- private final List> args;
-
- /**
- * Constructs a new CommandBuilder with the specified name and type.
- *
- * @param name The name of the command.
- * @param type The type of the command.
- */
- public CommandBuilder(@NotNull String name, @NotNull CommandType type) {
- this.name = name;
- this.type = type;
- this.requirements = new ArrayList<>();
- this.args = new ArrayList<>();
- this.command = new Command(name) {
- @Override
- public boolean execute(@NotNull CommandSender sender, @NotNull String label, @NotNull String[] args) {
- return true;
- }
- };
- }
-
- /**
- * Create a new CommandBuilder with the specified name and type.
- *
- * @param name The name of the command.
- * @param type The type of the command.
- * @return A new CommandBuilder instance.
- */
- public static @NotNull CommandBuilder command(@NotNull String name, @NotNull CommandType type) {
- return new CommandBuilder(name, type);
- }
-
- /**
- * Create a new CommandBuilder with the specified name and default (PLUGIN_YML) type.
- *
- * @param name The name of the command.
- * @return A new CommandBuilder instance.
- */
- public static @NotNull CommandBuilder command(@NotNull String name) {
- return CommandBuilder.command(name, CommandType.PLUGIN_YML);
- }
-
- /**
- * Adds a predicate/filter to the command.
- * Return true if you want to stop the execution
- * of the command.
- *
- * @param predicate What to run.
- * @return This CommandBuilder instance for method chaining.
- */
- public @NotNull CommandBuilder requirement(@NotNull Predicate predicate) {
- requirements().add(predicate);
- return this;
- }
-
- /**
- * Returns the list of filters.
- *
- * @return The list of filters.
- */
- public @NotNull List> requirements() {
- return this.requirements;
- }
-
- /**
- * Returns the underlying Bukkit Command associated with this CommandBuilder.
- *
- * @return The Bukkit Command object.
- */
- public @NotNull Command command() {
- return command;
- }
-
- /**
- * Gets the description of the command.
- *
- * @return The description of the command.
- */
- public @NotNull String description() {
- return command.getDescription();
- }
-
- /**
- * Sets the description of the command.
- *
- * @param description The new description for the command.
- * @return This CommandBuilder instance for method chaining.
- */
- public @NotNull CommandBuilder description(@NotNull String description) {
- this.command.setDescription(description);
- return this;
- }
-
- /**
- * Returns a CommandPermissionBuilder instance for setting custom permissions for the command.
- *
- * @return A CommandPermissionBuilder instance.
- */
- public @NotNull CommandPermissionBuilder permission() {
- return new CommandPermissionBuilder(this);
- }
-
- /**
- * Sets the usage description for the command.
- *
- * @param usage The usage description for the command.
- * @return This CommandBuilder instance for method chaining.
- */
- public @NotNull CommandBuilder usage(@NotNull String usage) {
- this.command.setUsage(TextStyle.legacy(usage));
- return this;
- }
-
- /**
- * Returns the usage message associated with this CommandBuilder.
- *
- * @return The usage message associated with this CommandBuilder.
- */
- public @NotNull String usage() {
- return this.command.getUsage();
- }
-
- /**
- * Returns a CommandAliasBuilder instance for managing command aliases.
- *
- * @return A CommandAliasBuilder instance.
- */
- public @NotNull CommandAliasBuilder aliases() {
- return new CommandAliasBuilder(this);
- }
-
- /**
- * Sets the CommandDispatcher for executing the command.
- *
- * @param dispatcher The CommandDispatcher for executing the command.
- * @return This CommandBuilder instance for method chaining.
- */
- public @NotNull CommandBuilder executes(@NotNull CommandDispatcher dispatcher) {
- this.dispatcher = dispatcher;
- return this;
- }
-
- /**
- * Returns the CommandDispatcher associated with this CommandBuilder.
- *
- * @return The CommandDispatcher for executing the command.
- */
- public @Nullable CommandDispatcher executes() {
- return dispatcher;
- }
-
- /**
- * Sets the SuggestionDispatcher for handling command suggestions.
- *
- * @param suggestionDispatcher The SuggestionDispatcher for handling command suggestions.
- * @return This CommandBuilder instance for method chaining.
- */
- public @NotNull CommandBuilder completes(@Nullable SuggestionDispatcher suggestionDispatcher) {
- this.suggestionDispatcher = suggestionDispatcher;
- return this;
- }
-
- /**
- * Returns the SuggestionDispatcher associated with this CommandBuilder.
- *
- * @return The SuggestionDispatcher for handling command suggestions.
- */
- public @Nullable SuggestionDispatcher completes() {
- return suggestionDispatcher;
- }
-
- /**
- * Gets the name of the command.
- *
- * @return The name of the command.
- */
- public @NotNull String name() {
- return name;
- }
-
- /**
- * Gets the type of the command.
- *
- * @return The type of the command
- */
- public @NotNull CommandType type() {
- return type;
- }
-
-
- public @NotNull CommandBuilder argument(@NotNull Argument> arg) {
- this.args.add(arg);
- return this;
- }
-
- public @NotNull List> args() {
- return args;
- }
-
- /**
- * Builds and returns a CommandBuilderHandler for handling the command.
- *
- * @return A CommandBuilderHandler for handling the command.
- */
- public @NotNull CommandBuilderHandler build() {
- return new CommandBuilderHandler(this);
- }
-}
diff --git a/src/main/java/dev/manere/utils/command/impl/CommandInfo.java b/src/main/java/dev/manere/utils/command/impl/CommandInfo.java
new file mode 100644
index 0000000..88d19e6
--- /dev/null
+++ b/src/main/java/dev/manere/utils/command/impl/CommandInfo.java
@@ -0,0 +1,86 @@
+package dev.manere.utils.command.impl;
+
+import net.kyori.adventure.text.Component;
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
+
+import java.util.Arrays;
+import java.util.List;
+
+public class CommandInfo {
+ final @NotNull Commands builder;
+ private @Nullable String namespace;
+ private @Nullable String description;
+ private @Nullable String permission;
+ private @Nullable Component permissionMessage;
+ private @Nullable String usage;
+ private @Nullable List aliases;
+
+ public CommandInfo(@NotNull Commands builder) {
+ this.builder = builder;
+ }
+
+ public String namespace() {
+ return namespace;
+ }
+
+ public CommandInfo namespace(String namespace) {
+ this.namespace = namespace;
+ return this;
+ }
+
+ public String description() {
+ return description;
+ }
+
+ public CommandInfo description(String description) {
+ this.description = description;
+ return this;
+ }
+
+ public String permission() {
+ return permission;
+ }
+
+ public CommandInfo permission(String permission) {
+ this.permission = permission;
+ return this;
+ }
+
+ public CommandInfo permission(String prefix, String suffix) {
+ this.permission = prefix + "." + suffix;
+ return this;
+ }
+
+ public Component permissionMessage() {
+ return permissionMessage;
+ }
+
+ public CommandInfo permissionMessage(Component permissionMessage) {
+ this.permissionMessage = permissionMessage;
+ return this;
+ }
+
+ public String usage() {
+ return usage;
+ }
+
+ public CommandInfo usage(String usage) {
+ this.usage = usage;
+ return this;
+ }
+
+ public List aliases() {
+ return aliases;
+ }
+
+ public CommandInfo aliases(List aliases) {
+ this.aliases = aliases;
+ return this;
+ }
+
+ public CommandInfo aliases(String... aliases) {
+ this.aliases = Arrays.asList(aliases);
+ return this;
+ }
+}
diff --git a/src/main/java/dev/manere/utils/command/impl/Commands.java b/src/main/java/dev/manere/utils/command/impl/Commands.java
new file mode 100644
index 0000000..24fd87b
--- /dev/null
+++ b/src/main/java/dev/manere/utils/command/impl/Commands.java
@@ -0,0 +1,422 @@
+package dev.manere.utils.command.impl;
+
+import dev.manere.utils.command.CommandTypes;
+import dev.manere.utils.command.args.Argument;
+import dev.manere.utils.command.impl.alias.CommandAliasBuilder;
+import dev.manere.utils.command.impl.dispatcher.CommandContext;
+import dev.manere.utils.command.impl.dispatcher.CommandDispatcher;
+import dev.manere.utils.command.impl.dispatcher.SuggestionDispatcher;
+import dev.manere.utils.command.impl.permission.CommandPermission;
+import dev.manere.utils.command.impl.permission.CommandPermissionBuilder;
+import dev.manere.utils.library.Utils;
+import dev.manere.utils.text.color.TextStyle;
+import net.kyori.adventure.text.Component;
+import org.bukkit.command.Command;
+import org.bukkit.command.CommandSender;
+import org.jetbrains.annotations.ApiStatus;
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import java.util.function.Consumer;
+import java.util.function.Predicate;
+
+/**
+ * Allows you to easily create commands non-reliant on Brigadier,
+ * made very simple and easy to use,
+ * allows for a variety of options
+ * and a lot of customisable features.
+ *
+ * WARNING:
+ * When using {@code new Commands(Command command)} or {@link Commands#legacy(Command)} you will lose
+ * the Argument> arguments. Don't use that unless you need to.
+ *
+ * REQUIREMENTS:
+ *
When adding a requirement using {@link Commands#requirement(Predicate)} you should return:
+ * - {@code true} if you want to stop execution of the command,
+ *
+ * - {@code false} if you want to continue execution of the command.
+ *
+ * COMMAND TYPES:
+ *
You will find documentation for Command Types in {@link CommandTypes}
+ *
+ * @see CommandDispatcher
+ * @see SuggestionDispatcher
+ * @see CommandTypes
+ * @see Argument
+ * @see CommandContext
+ */
+public class Commands {
+ private final String name;
+ private final CommandTypes type;
+ private CommandDispatcher dispatcher;
+ private SuggestionDispatcher suggestionDispatcher;
+ private final Command command;
+ private final List> requirements;
+ private final List> args;
+ private String namespace;
+
+ /**
+ * Constructs a new Commands with the specified name and type.
+ *
+ * @param name The name of the command.
+ * @param type The type of the command.
+ */
+ public Commands(@NotNull String name, @NotNull CommandTypes type) {
+ this.name = name;
+ this.type = type;
+ this.requirements = new ArrayList<>();
+ this.args = new ArrayList<>();
+ this.command = new Command(name) {
+ @Override
+ public boolean execute(@NotNull CommandSender sender, @NotNull String label, @NotNull String[] args) {
+ return true;
+ }
+ };
+ }
+
+ public Commands(@NotNull String name) {
+ this(name, CommandTypes.commandMap());
+ }
+
+ private Commands(Command command) {
+ CommandTypes commandType = Utils.plugin().getCommand(command.getName()) != null
+ ? CommandTypes.PLUGIN_YML
+ : CommandTypes.COMMAND_MAP;
+
+ this.name = command.getName();
+ this.type = commandType;
+ this.requirements = new ArrayList<>();
+ this.args = new ArrayList<>();
+ this.command = command;
+
+ this.dispatcher = ctx -> this.command.execute(
+ ctx.sender(),
+ ctx.commandRan(),
+ ctx.rawArgs().toArray(new String[0])
+ );
+
+ this.suggestionDispatcher = ctx -> this.command.tabComplete(
+ ctx.sender(),
+ ctx.commandRan(),
+ ctx.rawArgs().toArray(new String[0])
+ );
+ }
+
+ @ApiStatus.Internal
+ public static @NotNull Commands legacy(Command command) {
+ return new Commands(command);
+ }
+
+ /**
+ * Create a new Commands with the specified name and type.
+ *
+ * @param name The name of the command.
+ * @param type The type of the command.
+ * @return A new Commands instance.
+ */
+ public static @NotNull Commands command(@NotNull String name, @NotNull CommandTypes type) {
+ return new Commands(name, type);
+ }
+
+ /**
+ * Create a new Commands with the specified name and default (PLUGIN_YML) type.
+ *
+ * @param name The name of the command.
+ * @return A new Commands instance.
+ */
+ public static @NotNull Commands command(@NotNull String name) {
+ return new Commands(name);
+ }
+
+ void test() {
+
+ }
+
+ public Commands info(Consumer infoConsumer) {
+ CommandInfo info = new CommandInfo(this);
+ infoConsumer.accept(info);
+
+ if (info.description() != null) description(info.description());
+ if (info.namespace() != null) namespace(info.namespace());
+ if (info.aliases() != null) aliases(info.aliases());
+ if (info.permission() != null) permission(info.permission());
+ if (info.permissionMessage() != null) permissionMessage(info.permissionMessage());
+ if (info.usage() != null) usage(info.usage());
+
+ return this;
+ }
+
+ /**
+ * Returns the command registration namespace.
+ *
+ * @return The command registration namespace.
+ */
+ public @NotNull String namespace() {
+ return namespace == null ? Utils.plugin().getName() : namespace;
+ }
+
+ /**
+ * Sets the command registration namespace.
+ *
+ * @param namespace The new the command registration namespace.
+ * @return This Commands instance for method chaining.
+ */
+ public Commands namespace(@NotNull String namespace) {
+ this.namespace = namespace;
+ return this;
+ }
+
+ /**
+ * Adds a predicate/filter to the command.
+ * Return true if you want to stop the execution
+ * of the command.
+ *
+ * @param predicate What to run.
+ * @return This Commands instance for method chaining.
+ */
+ public @NotNull Commands requirement(@NotNull Predicate predicate) {
+ requirements().add(predicate);
+ return this;
+ }
+
+ /**
+ * Returns the list of filters.
+ *
+ * @return The list of filters.
+ */
+ public @NotNull List> requirements() {
+ return this.requirements;
+ }
+
+ /**
+ * Returns the underlying Bukkit Command associated with this command.
+ *
+ * @return The Bukkit Command object.
+ */
+ public @NotNull Command command() {
+ return command;
+ }
+
+ /**
+ * Gets the description of the command.
+ *
+ * @return The description of the command.
+ */
+ public @NotNull String description() {
+ return command.getDescription();
+ }
+
+ /**
+ * Sets the description of the command.
+ *
+ * @param description The new description for the command.
+ * @return This Commands instance for method chaining.
+ */
+ public @NotNull Commands description(@NotNull String description) {
+ this.command.setDescription(description);
+ return this;
+ }
+
+ /**
+ * Returns a CommandPermissionBuilder instance for setting custom permissions for the command.
+ *
+ * @return A CommandPermissionBuilder instance.
+ */
+ public @NotNull CommandPermissionBuilder permission() {
+ return new CommandPermissionBuilder(this);
+ }
+
+ /**
+ * Sets the required permission for the command.
+ *
+ * @param permission The permission to require for the command.
+ * @return This Commands instance for method chaining.
+ */
+ public @NotNull Commands permission(@NotNull String permission) {
+ return permission()
+ .type(CommandPermission.CUSTOM)
+ .custom(permission)
+ .build();
+ }
+
+ /**
+ * Sets the required permission for the command.
+ *
+ * @param prefix The permission prefix to require for the command.
+ * If your permission is `kits . kit` then the prefix
+ * is {@code kits}
+ * @param suffix The permission suffix to require for the command.
+ * If your permission is `kits . kit` then the suffix
+ * is {@code kit}
+ *
+ * @return This Commands instance for method chaining.
+ */
+ public @NotNull Commands permission(@NotNull String prefix, @NotNull String suffix) {
+ return permission()
+ .type(CommandPermission.CUSTOM)
+ .custom(prefix, suffix)
+ .build();
+ }
+
+ /**
+ * Sets the 'insufficient permissions' message for the command.
+ *
+ * @param permissionMessage The 'insufficient permissions' message for the command.
+ * @return This Commands instance for method chaining.
+ */
+ public @NotNull Commands permissionMessage(@NotNull Component permissionMessage) {
+ command().permissionMessage(permissionMessage);
+ return this;
+ }
+
+ /**
+ * Sets the usage description for the command.
+ *
+ * @param usage The usage description for the command.
+ * @return This Commands instance for method chaining.
+ */
+ public @NotNull Commands usage(@NotNull String usage) {
+ this.command.setUsage(TextStyle.legacy(usage));
+ return this;
+ }
+
+ /**
+ * Returns the usage message associated with this command.
+ *
+ * @return The usage message associated with this command.
+ */
+ public @NotNull String usage() {
+ return this.command.getUsage();
+ }
+
+ /**
+ * Returns a CommandAliasBuilder instance for managing command aliases.
+ *
+ * @return A CommandAliasBuilder instance.
+ */
+ public @NotNull CommandAliasBuilder aliases() {
+ return new CommandAliasBuilder(this);
+ }
+
+ /**
+ * Sets the aliases for the command.
+ *
+ * @param aliases The aliases for the command.
+ * @return This Commands instance for method chaining.
+ */
+ public @NotNull Commands aliases(@NotNull String... aliases) {
+ return aliases(Arrays.asList(aliases));
+ }
+
+ /**
+ * Sets the aliases for the command.
+ *
+ * @param aliases The aliases for the command.
+ * @return This Commands instance for method chaining.
+ */
+ public @NotNull Commands aliases(@NotNull List aliases) {
+ return aliases().aliases(aliases).build();
+ }
+
+ /**
+ * Sets the CommandDispatcher for executing the command.
+ *
+ * @param dispatcher The CommandDispatcher for executing the command.
+ * @return This Commands instance for method chaining.
+ */
+ public @NotNull Commands executes(@NotNull CommandDispatcher dispatcher) {
+ this.dispatcher = dispatcher;
+ return this;
+ }
+
+ /**
+ * Returns the CommandDispatcher associated with this command.
+ *
+ * @return The CommandDispatcher for executing the command.
+ */
+ public @Nullable CommandDispatcher executes() {
+ return dispatcher;
+ }
+
+ /**
+ * Sets the SuggestionDispatcher for handling command suggestions.
+ *
+ * @param suggestionDispatcher The SuggestionDispatcher for handling command suggestions.
+ * @return This Commands instance for method chaining.
+ */
+ public @NotNull Commands completes(@Nullable SuggestionDispatcher suggestionDispatcher) {
+ this.suggestionDispatcher = suggestionDispatcher;
+ return this;
+ }
+
+ /**
+ * Returns the SuggestionDispatcher associated with this command.
+ *
+ * @return The SuggestionDispatcher for handling command suggestions.
+ */
+ public @Nullable SuggestionDispatcher completes() {
+ return suggestionDispatcher;
+ }
+
+ /**
+ * Gets the name of the command.
+ *
+ * @return The name of the command.
+ */
+ public @NotNull String name() {
+ return name;
+ }
+
+ /**
+ * Gets the type of the command.
+ *
+ * @return The type of the command
+ */
+ public @NotNull CommandTypes type() {
+ return type;
+ }
+
+ /**
+ * Adds an argument to the command.
+ * @param argument The argument to add
+ * @return This Commands instance for method chaining.
+ */
+ public @NotNull Commands argument(@NotNull Argument> argument) {
+ this.args.add(argument);
+ return this;
+ }
+
+ /**
+ * Adds an argument to the command.
+ * @param argument The argument to add
+ * @return This Commands instance for method chaining.
+ */
+ public @NotNull Commands arg(@NotNull Argument> argument) {
+ return argument(argument);
+ }
+
+ @NotNull
+ public List> args() {
+ return args;
+ }
+
+ /**
+ * Builds and returns a CommandsRegistrar for handling the command.
+ *
+ * @return A CommandsRegistrar for handling the command.
+ */
+ public @NotNull CommandsRegistrar build() {
+ return new CommandsRegistrar(this);
+ }
+
+ /**
+ * Attempts to register the command
+ * with the plugin obtained by {@link Utils#plugin()}
+ */
+ public void register() {
+ build().register();
+ }
+}
diff --git a/src/main/java/dev/manere/utils/command/builder/CommandBuilderHandler.java b/src/main/java/dev/manere/utils/command/impl/CommandsRegistrar.java
similarity index 88%
rename from src/main/java/dev/manere/utils/command/builder/CommandBuilderHandler.java
rename to src/main/java/dev/manere/utils/command/impl/CommandsRegistrar.java
index 61fb6c8..b90f24c 100644
--- a/src/main/java/dev/manere/utils/command/builder/CommandBuilderHandler.java
+++ b/src/main/java/dev/manere/utils/command/impl/CommandsRegistrar.java
@@ -1,7 +1,7 @@
-package dev.manere.utils.command.builder;
+package dev.manere.utils.command.impl;
import dev.manere.utils.command.args.Argument;
-import dev.manere.utils.command.builder.dispatcher.CommandContext;
+import dev.manere.utils.command.impl.dispatcher.CommandContext;
import dev.manere.utils.library.Utils;
import dev.manere.utils.registration.Registrar;
import org.bukkit.plugin.java.JavaPlugin;
@@ -11,11 +11,10 @@
import java.util.function.Predicate;
/**
- * Class related to finally registering a CommandBuilder.
+ * Class related to finally registering a Commands.
* @param commandBuilder The command builder to handle.
*/
-public record CommandBuilderHandler(@NotNull CommandBuilder commandBuilder) {
-
+public record CommandsRegistrar(@NotNull Commands commandBuilder) {
/**
* Attempts to register the command
* with the plugin obtained by {@link Utils#plugin()}
@@ -31,8 +30,8 @@ public void register() {
*/
@SuppressWarnings("DataFlowIssue")
public void register(@NotNull JavaPlugin plugin) {
- switch (commandBuilder.type()) {
- case PLUGIN_YML -> {
+ switch (commandBuilder.type().type()) {
+ case 0 -> {
if (plugin.getCommand(commandBuilder.name()) == null) throw new NullPointerException(
"The plugin.yml file is missing a definition for the command you are trying to register." +
" Add the command definition to your plugin.yml to fix this."
@@ -68,7 +67,7 @@ public void register(@NotNull JavaPlugin plugin) {
}
}
- case COMMAND_MAP -> Registrar.commandMap(this);
+ case 1 -> Registrar.commandMap(this);
}
}
}
diff --git a/src/main/java/dev/manere/utils/command/builder/alias/CommandAliasBuilder.java b/src/main/java/dev/manere/utils/command/impl/alias/CommandAliasBuilder.java
similarity index 66%
rename from src/main/java/dev/manere/utils/command/builder/alias/CommandAliasBuilder.java
rename to src/main/java/dev/manere/utils/command/impl/alias/CommandAliasBuilder.java
index 39531e8..f048647 100644
--- a/src/main/java/dev/manere/utils/command/builder/alias/CommandAliasBuilder.java
+++ b/src/main/java/dev/manere/utils/command/impl/alias/CommandAliasBuilder.java
@@ -1,24 +1,24 @@
-package dev.manere.utils.command.builder.alias;
+package dev.manere.utils.command.impl.alias;
-import dev.manere.utils.command.builder.CommandBuilder;
+import dev.manere.utils.command.impl.Commands;
import org.jetbrains.annotations.NotNull;
import java.util.ArrayList;
import java.util.List;
/**
- * A builder class for managing aliases for a command associated with a CommandBuilder.
+ * A builder class for managing aliases for a command associated with a Commands.
*/
public class CommandAliasBuilder {
- private final CommandBuilder commandBuilder;
+ private final Commands commandBuilder;
private final List aliases;
/**
- * Constructs a new CommandAliasBuilder associated with the specified CommandBuilder.
+ * Constructs a new CommandAliasBuilder associated with the specified Commands.
*
- * @param commandBuilder The CommandBuilder associated with this CommandAliasBuilder.
+ * @param commandBuilder The Commands associated with this CommandAliasBuilder.
*/
- public CommandAliasBuilder(@NotNull CommandBuilder commandBuilder) {
+ public CommandAliasBuilder(@NotNull Commands commandBuilder) {
this.commandBuilder = commandBuilder;
this.aliases = commandBuilder.command().getAliases().isEmpty() ? new ArrayList<>() : commandBuilder.command().getAliases();
}
@@ -43,7 +43,12 @@ public CommandAliasBuilder(@NotNull CommandBuilder commandBuilder) {
return aliases;
}
-
+ /**
+ * Sets the aliases for the command.
+ *
+ * @param aliases The aliases for the command.
+ * @return This CommandAliasBuilder instance for method chaining.
+ */
public @NotNull CommandAliasBuilder aliases(@NotNull List aliases) {
this.aliases.clear();
@@ -55,22 +60,13 @@ public CommandAliasBuilder(@NotNull CommandBuilder commandBuilder) {
}
/**
- * Gets the associated CommandBuilder.
- *
- * @return The CommandBuilder associated with this CommandAliasBuilder.
- */
- public @NotNull CommandBuilder commandBuilder() {
- return commandBuilder;
- }
-
- /**
- * Builds and associates the list of aliases with the CommandBuilder.
+ * Builds and associates the list of aliases with the Commands.
*
- * @return The CommandBuilder with the associated aliases.
+ * @return The Commands with the associated aliases.
*/
- public @NotNull CommandBuilder build() {
+ public @NotNull Commands build() {
if (!aliases.isEmpty()) {
- commandBuilder().command().setAliases(aliases);
+ commandBuilder.command().setAliases(aliases);
}
return commandBuilder;
diff --git a/src/main/java/dev/manere/utils/command/builder/dispatcher/CommandContext.java b/src/main/java/dev/manere/utils/command/impl/dispatcher/CommandContext.java
similarity index 72%
rename from src/main/java/dev/manere/utils/command/builder/dispatcher/CommandContext.java
rename to src/main/java/dev/manere/utils/command/impl/dispatcher/CommandContext.java
index 6e1bf7c..64f3421 100644
--- a/src/main/java/dev/manere/utils/command/builder/dispatcher/CommandContext.java
+++ b/src/main/java/dev/manere/utils/command/impl/dispatcher/CommandContext.java
@@ -1,4 +1,4 @@
-package dev.manere.utils.command.builder.dispatcher;
+package dev.manere.utils.command.impl.dispatcher;
import dev.manere.utils.command.args.Argument;
import dev.manere.utils.command.args.custom.CustomArgument;
@@ -204,7 +204,7 @@ public boolean senderIsPlayer() {
if (rawArgs.size() <= index || rawArgAt(index) == null) {
try {
- if (argument.type() instanceof CustomListArgument arg) return arg.parse(this, 0);
+ if (argument.type() instanceof CustomListArgument> arg) return arg.parse(this, 0);
if (argument.defaultVal() == null) return null;
return argument.type().parse(this, argument.defaultVal());
@@ -214,7 +214,7 @@ public boolean senderIsPlayer() {
}
} else if (rawArgAt(index) != null) {
try {
- if (argument.type() instanceof CustomListArgument arg) return arg.parse(this, index);
+ if (argument.type() instanceof CustomListArgument> arg) return arg.parse(this, index);
return argument.type().parse(this, rawArgAt(index));
} catch (ArgumentParseException e) {
@@ -226,6 +226,62 @@ public boolean senderIsPlayer() {
return null;
}
+ /**
+ * Returns the argument of the identifier with the specified type.
+ *
+ * @param identifier The identifier of the argument.
+ * @param type The type parameter for the generic method.
+ * @param The type parameter for the generic method.
+ * @return The argument of the specified type.
+ */
+ public @Nullable T argAt(@NotNull String identifier, @NotNull Class type) {
+ for (Argument> arg : args) {
+ if (arg.identifier().equalsIgnoreCase(identifier)) {
+ return argAt(args.indexOf(arg), type);
+ }
+ }
+
+ return null;
+ }
+
+ /**
+ * Returns the argument at the specified index with the specified type.
+ *
+ * @param index The index of the argument.
+ * @param type The type parameter for the generic method.
+ * @param The type parameter for the generic method.
+ * @return The argument at the specified index with the specified type.
+ */
+ @SuppressWarnings("unchecked")
+ public @Nullable T argAt(int index, @NotNull Class type) {
+ Argument> argument = args.get(index);
+
+ if (argument == null || rawArgs == null || rawArgs.isEmpty()) return null;
+
+ if (rawArgs.size() <= index || rawArgAt(index) == null) {
+ try {
+ if (argument.type() instanceof CustomListArgument> arg) return (T) arg.parse(this, 0);
+ if (argument.defaultVal() == null) return null;
+
+ return type.cast(argument.type().parse(this, argument.defaultVal()));
+ } catch (ArgumentParseException err) {
+ if (argument.onError() != null) argument.onError().apply(this, err.type());
+ else throw new RuntimeException(err.getMessage());
+ }
+ } else if (rawArgAt(index) != null) {
+ try {
+ if (argument.type() instanceof CustomListArgument> arg) return (T) arg.parse(this, index);
+
+ return type.cast(argument.type().parse(this, rawArgAt(index)));
+ } catch (ArgumentParseException e) {
+ if (argument.onError() != null) argument.onError().apply(this, e.type());
+ else throw new RuntimeException(e.getMessage());
+ }
+ }
+
+ return null;
+ }
+
public int argPos(String identifier) {
for (Argument> arg : args) {
if (arg.identifier().equalsIgnoreCase(identifier)) {
@@ -244,4 +300,22 @@ public int argPos(String identifier) {
public @NotNull List> args() {
return args;
}
+
+ /**
+ * Returns the size of all arguments.
+ *
+ * @return The size of all arguments.
+ */
+ public int argSize() {
+ return rawArgs().size();
+ }
+
+ /**
+ * Returns the size of all arguments.
+ *
+ * @return The size of all arguments.
+ */
+ public int size() {
+ return argSize();
+ }
}
diff --git a/src/main/java/dev/manere/utils/command/builder/dispatcher/CommandDispatcher.java b/src/main/java/dev/manere/utils/command/impl/dispatcher/CommandDispatcher.java
similarity index 89%
rename from src/main/java/dev/manere/utils/command/builder/dispatcher/CommandDispatcher.java
rename to src/main/java/dev/manere/utils/command/impl/dispatcher/CommandDispatcher.java
index e9c2661..5b75d1f 100644
--- a/src/main/java/dev/manere/utils/command/builder/dispatcher/CommandDispatcher.java
+++ b/src/main/java/dev/manere/utils/command/impl/dispatcher/CommandDispatcher.java
@@ -1,4 +1,4 @@
-package dev.manere.utils.command.builder.dispatcher;
+package dev.manere.utils.command.impl.dispatcher;
import org.jetbrains.annotations.NotNull;
@@ -6,7 +6,6 @@
* An interface for executing commands based on the provided command context.
*/
public interface CommandDispatcher {
-
/**
* Executes a command based on the provided command context.
*
diff --git a/src/main/java/dev/manere/utils/command/builder/dispatcher/SuggestionDispatcher.java b/src/main/java/dev/manere/utils/command/impl/dispatcher/SuggestionDispatcher.java
similarity index 91%
rename from src/main/java/dev/manere/utils/command/builder/dispatcher/SuggestionDispatcher.java
rename to src/main/java/dev/manere/utils/command/impl/dispatcher/SuggestionDispatcher.java
index 889428f..a13ecd2 100644
--- a/src/main/java/dev/manere/utils/command/builder/dispatcher/SuggestionDispatcher.java
+++ b/src/main/java/dev/manere/utils/command/impl/dispatcher/SuggestionDispatcher.java
@@ -1,4 +1,4 @@
-package dev.manere.utils.command.builder.dispatcher;
+package dev.manere.utils.command.impl.dispatcher;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -9,7 +9,6 @@
* An interface for providing command suggestions based on the provided command context.
*/
public interface SuggestionDispatcher {
-
/**
* Generates a list of command suggestions based on the provided command context.
*
diff --git a/src/main/java/dev/manere/utils/command/builder/permission/CommandPermission.java b/src/main/java/dev/manere/utils/command/impl/permission/CommandPermission.java
similarity index 78%
rename from src/main/java/dev/manere/utils/command/builder/permission/CommandPermission.java
rename to src/main/java/dev/manere/utils/command/impl/permission/CommandPermission.java
index a271206..aedf1ed 100644
--- a/src/main/java/dev/manere/utils/command/builder/permission/CommandPermission.java
+++ b/src/main/java/dev/manere/utils/command/impl/permission/CommandPermission.java
@@ -1,10 +1,9 @@
-package dev.manere.utils.command.builder.permission;
+package dev.manere.utils.command.impl.permission;
/**
* An enumeration representing different types of command permissions.
*/
public enum CommandPermission {
-
/**
* Represents a custom command permission type.
*/
diff --git a/src/main/java/dev/manere/utils/command/builder/permission/CommandPermissionBuilder.java b/src/main/java/dev/manere/utils/command/impl/permission/CommandPermissionBuilder.java
similarity index 80%
rename from src/main/java/dev/manere/utils/command/builder/permission/CommandPermissionBuilder.java
rename to src/main/java/dev/manere/utils/command/impl/permission/CommandPermissionBuilder.java
index f2878fe..5c3af2e 100644
--- a/src/main/java/dev/manere/utils/command/builder/permission/CommandPermissionBuilder.java
+++ b/src/main/java/dev/manere/utils/command/impl/permission/CommandPermissionBuilder.java
@@ -1,25 +1,25 @@
-package dev.manere.utils.command.builder.permission;
+package dev.manere.utils.command.impl.permission;
-import dev.manere.utils.command.builder.CommandBuilder;
+import dev.manere.utils.command.impl.Commands;
import net.kyori.adventure.text.Component;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
/**
- * A builder class for setting custom permissions for a command associated with a CommandBuilder.
+ * A builder class for setting custom permissions for a command associated with a Commands.
*/
public class CommandPermissionBuilder {
- private final CommandBuilder commandBuilder;
+ private final Commands commandBuilder;
private CommandPermission type;
private String custom;
private Component message;
/**
- * Constructs a new CommandPermissionBuilder associated with the specified CommandBuilder.
+ * Constructs a new CommandPermissionBuilder associated with the specified Commands.
*
- * @param commandBuilder The CommandBuilder associated with this CommandPermissionBuilder.
+ * @param commandBuilder The Commands associated with this CommandPermissionBuilder.
*/
- public CommandPermissionBuilder(@NotNull CommandBuilder commandBuilder) {
+ public CommandPermissionBuilder(@NotNull Commands commandBuilder) {
this.commandBuilder = commandBuilder;
}
@@ -57,11 +57,11 @@ public CommandPermissionBuilder(@NotNull CommandBuilder commandBuilder) {
}
/**
- * Gets the associated CommandBuilder.
+ * Gets the associated Commands.
*
- * @return The CommandBuilder associated with this CommandPermissionBuilder.
+ * @return The Commands associated with this CommandPermissionBuilder.
*/
- public @NotNull CommandBuilder commandBuilder() {
+ public @NotNull Commands commandBuilder() {
return commandBuilder;
}
@@ -105,11 +105,11 @@ public CommandPermissionBuilder(@NotNull CommandBuilder commandBuilder) {
}
/**
- * Builds and associates the command permission with the CommandBuilder.
+ * Builds and associates the command permission with the Commands.
*
- * @return The CommandBuilder with the associated command permission.
+ * @return The Commands with the associated command permission.
*/
- public @NotNull CommandBuilder build() {
+ public @NotNull Commands build() {
commandBuilder().command().setPermission(custom());
if (message() != null) {
diff --git a/src/main/java/dev/manere/utils/config/Config.java b/src/main/java/dev/manere/utils/config/Config.java
index c0c0054..258f8ff 100644
--- a/src/main/java/dev/manere/utils/config/Config.java
+++ b/src/main/java/dev/manere/utils/config/Config.java
@@ -14,7 +14,6 @@
* Utility class for managing and interacting with configuration settings in a Bukkit plugin.
*/
public class Config {
-
/**
* Retrieves the singleton instance of the Config class.
*
diff --git a/src/main/java/dev/manere/utils/config/section/ConfigSection.java b/src/main/java/dev/manere/utils/config/section/ConfigSection.java
index c634f24..9f44218 100644
--- a/src/main/java/dev/manere/utils/config/section/ConfigSection.java
+++ b/src/main/java/dev/manere/utils/config/section/ConfigSection.java
@@ -11,7 +11,7 @@
* This class provides methods for creating, modifying, and retrieving values from the specified section.
*/
public class ConfigSection {
- public final ConfigurationSection section;
+ final ConfigurationSection section;
public final String sectionPath;
/**
diff --git a/src/main/java/dev/manere/utils/config/section/ConfigSelection.java b/src/main/java/dev/manere/utils/config/section/ConfigSelection.java
index a8f360d..68d493b 100644
--- a/src/main/java/dev/manere/utils/config/section/ConfigSelection.java
+++ b/src/main/java/dev/manere/utils/config/section/ConfigSelection.java
@@ -2,7 +2,7 @@
import dev.manere.utils.config.ConfigKey;
import dev.manere.utils.config.val.ConfigVal;
-import dev.manere.utils.model.Duo;
+import dev.manere.utils.model.Tuple;
import org.jetbrains.annotations.NotNull;
import java.util.function.Consumer;
@@ -11,8 +11,7 @@
* Utility class for selecting and iterating over keys and values within a specific section of the plugin's configuration.
*/
public class ConfigSelection {
-
- private final ConfigSection section;
+ final ConfigSection section;
/**
* Constructs a ConfigSelection for the specified ConfigSection.
@@ -38,10 +37,10 @@ public ConfigSelection(@NotNull ConfigSection section) {
*
* @param consumer The consumer to apply to each key-value pair.
*/
- public void forEach(@NotNull Consumer> consumer) {
+ public void forEach(@NotNull Consumer> consumer) {
if (this.section.section != null) {
for (String key : this.section.section.getKeys(false)) {
- consumer.accept(new Duo<>(ConfigKey.key(key), ConfigKey.key(key).val()));
+ consumer.accept(Tuple.duo(ConfigKey.key(key), ConfigKey.key(key).val()));
}
}
}
diff --git a/src/main/java/dev/manere/utils/config/setter/ConfigSectionSetter.java b/src/main/java/dev/manere/utils/config/setter/ConfigSectionSetter.java
index 038e0c7..cf45fb1 100644
--- a/src/main/java/dev/manere/utils/config/setter/ConfigSectionSetter.java
+++ b/src/main/java/dev/manere/utils/config/setter/ConfigSectionSetter.java
@@ -16,7 +16,6 @@
* Utility class for setting values in a specific section of the plugin's configuration.
*/
public class ConfigSectionSetter {
-
private final ConfigSection configSection;
private Object val;
private String key;
diff --git a/src/main/java/dev/manere/utils/config/setter/ConfigSetter.java b/src/main/java/dev/manere/utils/config/setter/ConfigSetter.java
index 701be5b..5162fec 100644
--- a/src/main/java/dev/manere/utils/config/setter/ConfigSetter.java
+++ b/src/main/java/dev/manere/utils/config/setter/ConfigSetter.java
@@ -16,7 +16,6 @@
* Utility class for setting values in the plugin's configuration.
*/
public class ConfigSetter {
-
private ConfigKey key;
private Object val;
private boolean defaultVal;
diff --git a/src/main/java/dev/manere/utils/config/val/ConfigList.java b/src/main/java/dev/manere/utils/config/val/ConfigList.java
index 6ecb094..3b64ed2 100644
--- a/src/main/java/dev/manere/utils/config/val/ConfigList.java
+++ b/src/main/java/dev/manere/utils/config/val/ConfigList.java
@@ -14,7 +14,6 @@
* Represents a list of values in the configuration associated with a specific ConfigVal.
*/
public record ConfigList(@NotNull ConfigVal val) {
-
/**
* Creates a new ConfigList instance with the specified ConfigVal.
*
diff --git a/src/main/java/dev/manere/utils/config/val/ConfigVal.java b/src/main/java/dev/manere/utils/config/val/ConfigVal.java
index 93db616..966d7dd 100644
--- a/src/main/java/dev/manere/utils/config/val/ConfigVal.java
+++ b/src/main/java/dev/manere/utils/config/val/ConfigVal.java
@@ -16,9 +16,9 @@
* Represents a value associated with a configuration key.
*/
public class ConfigVal {
- public final ConfigKey key;
- public final Object object;
- public final String path;
+ private final ConfigKey key;
+ private final Object object;
+ final String path;
/**
* Constructs a ConfigVal with the specified ConfigKey.
@@ -139,4 +139,8 @@ public boolean asBoolean() {
public @Nullable ConfigList asListOf() {
return ConfigList.list(this);
}
+
+ public ConfigKey key() {
+ return key;
+ }
}
diff --git a/src/main/java/dev/manere/utils/consumers/PairConsumer.java b/src/main/java/dev/manere/utils/consumers/PairConsumer.java
new file mode 100644
index 0000000..deb0c29
--- /dev/null
+++ b/src/main/java/dev/manere/utils/consumers/PairConsumer.java
@@ -0,0 +1,18 @@
+package dev.manere.utils.consumers;
+
+/**
+ * The {@code PairConsumer} interface represents an entity capable of executing an operation
+ * that involves two parameters of different types.
+ *
+ * @param The type of the first parameter.
+ * @param The type of the second parameter.
+ */
+public interface PairConsumer {
+ /**
+ * Executes an operation with the given parameters.
+ *
+ * @param firstParam The first parameter of type A.
+ * @param secondParam The second parameter of type B.
+ */
+ void execute(A firstParam, B secondParam);
+}
diff --git a/src/main/java/dev/manere/utils/consumers/TripleConsumer.java b/src/main/java/dev/manere/utils/consumers/TripleConsumer.java
new file mode 100644
index 0000000..35b0620
--- /dev/null
+++ b/src/main/java/dev/manere/utils/consumers/TripleConsumer.java
@@ -0,0 +1,20 @@
+package dev.manere.utils.consumers;
+
+/**
+ * The {@code TripleConsumer} interface represents an entity capable of executing an operation
+ * that involves three parameters of different types.
+ *
+ * @param The type of the first parameter.
+ * @param The type of the second parameter.
+ * @param The type of the third parameter.
+ */
+public interface TripleConsumer {
+ /**
+ * Executes an operation with the given parameters.
+ *
+ * @param firstParam The first parameter of type A.
+ * @param secondParam The second parameter of type B.
+ * @param thirdParam The third parameter of type C.
+ */
+ void execute(A firstParam, B secondParam, C thirdParam);
+}
diff --git a/src/main/java/dev/manere/utils/context/Context.java b/src/main/java/dev/manere/utils/context/Context.java
new file mode 100644
index 0000000..409a6b4
--- /dev/null
+++ b/src/main/java/dev/manere/utils/context/Context.java
@@ -0,0 +1,36 @@
+package dev.manere.utils.context;
+
+import dev.manere.utils.command.impl.dispatcher.CommandContext;
+
+/**
+ * The {@code Context} interface represents a context associated with a specific type of source.
+ * It provides a method to retrieve the source associated with the context.
+ *
+ * A context should be a class to store multiple values and provide utility methods on them.
+ * An example is {@link CommandContext} which is a context class for commands.
+ *
+ * @param The type of the source associated with the context.
+ */
+public interface Context {
+ /**
+ * Retrieves the source associated with this context.
+ *
+ * @return The source associated with this context.
+ */
+ S source();
+
+ /**
+ * The {@code Source} interface represents a wrapper for a specific type of source.
+ * It provides a method to unwrap and obtain the original source object.
+ *
+ * @param The type of the source object.
+ */
+ interface Source {
+ /**
+ * Unwraps and obtains the original source object.
+ *
+ * @return The original source object.
+ */
+ T unwrap();
+ }
+}
diff --git a/src/main/java/dev/manere/utils/elo/ELO.java b/src/main/java/dev/manere/utils/elo/ELO.java
index 0d442f6..8953233 100644
--- a/src/main/java/dev/manere/utils/elo/ELO.java
+++ b/src/main/java/dev/manere/utils/elo/ELO.java
@@ -8,7 +8,6 @@
* This class provides methods to calculate ELO ratings for two players after a match.
*/
public class ELO {
-
/**
* Calculate the new ELO ratings for two players after a match.
*
diff --git a/src/main/java/dev/manere/utils/elo/Ratings.java b/src/main/java/dev/manere/utils/elo/Ratings.java
index 3681eeb..cbb8c9e 100644
--- a/src/main/java/dev/manere/utils/elo/Ratings.java
+++ b/src/main/java/dev/manere/utils/elo/Ratings.java
@@ -27,7 +27,7 @@ public Ratings(int playerElo1, int playerElo2) {
* @param playerElo1 The initial ELO rating of the first player.
* @param playerElo2 The initial ELO rating of the second player.
*/
- public static Ratings ratings(int playerElo1, int playerElo2) {
+ public static Ratings of(int playerElo1, int playerElo2) {
return new Ratings<>(playerElo1, playerElo2);
}
diff --git a/src/main/java/dev/manere/utils/elo/Winner.java b/src/main/java/dev/manere/utils/elo/Winner.java
index 38c338d..50e842e 100644
--- a/src/main/java/dev/manere/utils/elo/Winner.java
+++ b/src/main/java/dev/manere/utils/elo/Winner.java
@@ -4,7 +4,6 @@
* An enumeration representing the winner of a match.
*/
public enum Winner {
-
/**
* Represents that the first player (Player ONE) is the winner.
*/
@@ -13,5 +12,13 @@ public enum Winner {
/**
* Represents that the second player (Player TWO) is the winner.
*/
- TWO
+ TWO;
+
+ public static Winner one() {
+ return Winner.ONE;
+ }
+
+ public static Winner two() {
+ return Winner.TWO;
+ }
}
diff --git a/src/main/java/dev/manere/utils/event/builder/EventBuilder.java b/src/main/java/dev/manere/utils/event/builder/EventBuilder.java
index 6c5c3a2..5add2ae 100644
--- a/src/main/java/dev/manere/utils/event/builder/EventBuilder.java
+++ b/src/main/java/dev/manere/utils/event/builder/EventBuilder.java
@@ -3,11 +3,11 @@
import dev.manere.utils.library.Utils;
import org.bukkit.event.Event;
import org.bukkit.plugin.java.JavaPlugin;
-import org.bukkit.util.Consumer;
import org.jetbrains.annotations.NotNull;
import java.util.ArrayList;
import java.util.List;
+import java.util.function.Consumer;
/**
* The EventBuilder class is used to easily listen to events without
@@ -16,9 +16,8 @@
* @param Any subclass of {@link Event}
*/
public class EventBuilder {
-
- public final List