From 735c64333bcd3eca02e8afae08ff5195a2a97f02 Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Thu, 8 Aug 2024 21:29:44 -0300 Subject: [PATCH 01/73] fixing git --- .../wlib/command/CommandManager.java | 2 +- .../wlib/inventory/item/ItemButton.java | 30 +++++++++++++++---- .../wizardlybump17/wlib/item/ItemBuilder.java | 7 ++--- .../wlib/listener/EntityListener.java | 11 +++++-- 4 files changed, 37 insertions(+), 13 deletions(-) diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/CommandManager.java b/commands/src/main/java/com/wizardlybump17/wlib/command/CommandManager.java index 07509831..371354f6 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/CommandManager.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/CommandManager.java @@ -34,7 +34,7 @@ public void registerCommands(Object... objects) { MethodHandle handle; try { - handle = MethodHandles.lookup().findVirtual(object.getClass(), method.getName(), MethodType.methodType(method.getReturnType(), method.getParameterTypes())); + handle = MethodHandles.publicLookup().findVirtual(object.getClass(), method.getName(), MethodType.methodType(method.getReturnType(), method.getParameterTypes())); } catch (NoSuchMethodException | IllegalAccessException e) { holder.getLogger().log(Level.SEVERE, "Error while trying to get the MethodHandle for " + method.getName() + " at " + object.getClass().getName(), e); continue; diff --git a/core/src/main/java/com/wizardlybump17/wlib/inventory/item/ItemButton.java b/core/src/main/java/com/wizardlybump17/wlib/inventory/item/ItemButton.java index 06bf6c28..559d3026 100644 --- a/core/src/main/java/com/wizardlybump17/wlib/inventory/item/ItemButton.java +++ b/core/src/main/java/com/wizardlybump17/wlib/inventory/item/ItemButton.java @@ -2,6 +2,8 @@ import com.wizardlybump17.wlib.item.ItemBuilder; import com.wizardlybump17.wlib.object.Pair; +import com.wizardlybump17.wlib.util.bukkit.ConfigUtil; +import com.wizardlybump17.wlib.util.bukkit.config.ConfigSound; import lombok.Data; import lombok.NonNull; import org.bukkit.Material; @@ -11,9 +13,7 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import java.util.HashMap; -import java.util.LinkedHashMap; -import java.util.Map; +import java.util.*; import java.util.function.Supplier; @Data @@ -34,6 +34,7 @@ public class ItemButton implements ConfigurationSerializable, Cloneable { private ClickAction clickAction; @NonNull private Map customData; + private @NonNull List clickSounds; public ItemButton(@NotNull ItemStack item) { this(item, null, new HashMap<>()); @@ -56,9 +57,14 @@ public ItemButton(@NotNull Supplier item, @Nullable ClickAction click } public ItemButton(@NotNull Supplier item, @Nullable ClickAction clickAction, @NonNull Map customData) { + this(item, clickAction, customData, new ArrayList<>()); + } + + public ItemButton(@NotNull Supplier item, @Nullable ClickAction clickAction, @NonNull Map customData, @NonNull List clickSounds) { this.item = item; this.clickAction = clickAction; this.customData = customData; + this.clickSounds = clickSounds; } public ItemButton(@NotNull Pair pair) { @@ -81,6 +87,10 @@ public ItemButton(@NonNull ItemBuilder itemBuilder, @Nullable ClickAction clickA this(itemBuilder::build, clickAction, customData); } + public ItemButton(@NonNull ItemBuilder itemBuilder, @Nullable ClickAction clickAction, @NonNull Map customData, @NonNull List clickSounds) { + this(itemBuilder::build, clickAction, customData, clickSounds); + } + @NotNull @Override public Map serialize() { @@ -88,15 +98,18 @@ public Map serialize() { map.put("item", ItemBuilder.fromItemStack(item.get())); if (!customData.isEmpty()) map.put("custom-data", customData); + if (!clickSounds.isEmpty()) + map.put("click-sounds", clickSounds); return map; } @Override public ItemButton clone() { return new ItemButton( - item.get().clone(), + item.get()::clone, clickAction, - new HashMap<>(customData) + new HashMap<>(customData), + new ArrayList<>(clickSounds) ); } @@ -104,6 +117,11 @@ public ItemButton clone() { public static ItemButton deserialize(Map map) { ItemBuilder itemBuilder = (ItemBuilder) map.get("item"); Map customData = (Map) map.get("custom-data"); - return new ItemButton(itemBuilder, null, customData == null ? new HashMap<>() : customData); + return new ItemButton( + itemBuilder, + null, + customData == null ? new HashMap<>() : customData, + ConfigUtil.get("click-sounds", map, ArrayList::new) + ); } } diff --git a/core/src/main/java/com/wizardlybump17/wlib/item/ItemBuilder.java b/core/src/main/java/com/wizardlybump17/wlib/item/ItemBuilder.java index dc547831..3e1bca80 100644 --- a/core/src/main/java/com/wizardlybump17/wlib/item/ItemBuilder.java +++ b/core/src/main/java/com/wizardlybump17/wlib/item/ItemBuilder.java @@ -7,7 +7,6 @@ import com.wizardlybump17.wlib.util.MapUtils; import com.wizardlybump17.wlib.util.bukkit.ConfigUtil; import com.wizardlybump17.wlib.util.bukkit.NamespacedKeyUtil; -import com.wizardlybump17.wlib.util.bukkit.StringUtil; import lombok.NonNull; import org.bukkit.Material; import org.bukkit.NamespacedKey; @@ -145,11 +144,11 @@ public int damage() { } public ItemBuilder lore(@Nullable String... lore) { - return consumeMeta(meta -> meta.setLore(lore == null ? null : StringUtil.colorize(Arrays.asList(lore)))); + return consumeMeta(meta -> meta.setLore(lore == null ? null : Arrays.asList(lore))); } public ItemBuilder lore(@Nullable List lore) { - return consumeMeta(meta -> meta.setLore(StringUtil.colorize(lore))); + return consumeMeta(meta -> meta.setLore(lore)); } public ItemBuilder itemFlags(@NotNull ItemFlag... itemFlags) { @@ -241,7 +240,7 @@ public String displayName() { } public ItemBuilder displayName(@Nullable String displayName) { - return consumeMeta(meta -> meta.setDisplayName(StringUtil.colorize(displayName))); + return consumeMeta(meta -> meta.setDisplayName(displayName)); } @NotNull diff --git a/core/src/main/java/com/wizardlybump17/wlib/listener/EntityListener.java b/core/src/main/java/com/wizardlybump17/wlib/listener/EntityListener.java index 99c23bf5..28382af8 100644 --- a/core/src/main/java/com/wizardlybump17/wlib/listener/EntityListener.java +++ b/core/src/main/java/com/wizardlybump17/wlib/listener/EntityListener.java @@ -2,9 +2,11 @@ import com.wizardlybump17.wlib.inventory.CustomInventory; import com.wizardlybump17.wlib.inventory.CustomInventoryHolder; +import com.wizardlybump17.wlib.inventory.item.ClickAction; import com.wizardlybump17.wlib.inventory.item.ItemButton; import com.wizardlybump17.wlib.inventory.paginated.PaginatedInventory; import lombok.RequiredArgsConstructor; +import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; import org.bukkit.event.Listener; @@ -30,8 +32,13 @@ public void onClick(InventoryClickEvent event) { final CustomInventory customInventory = paginatedInventory.getCurrentInventory(); ItemButton item = customInventory.getButton(event.getRawSlot()); - if (item != null && item.getClickAction() != null) - item.getClickAction().onClick(event, paginatedInventory); + if (item == null) + return; + + ClickAction clickAction = item.getClickAction(); + if (clickAction != null) + clickAction.onClick(event, paginatedInventory); + item.getClickSounds().forEach(sound -> sound.play((Player) event.getWhoClicked())); } @EventHandler(priority = EventPriority.LOWEST) From 4c36438cd99ac04dae1e6cf30831cd7bc2c2224c Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Thu, 15 Aug 2024 18:53:07 -0300 Subject: [PATCH 02/73] applying the colors when getting from the config --- .../wlib/util/bukkit/StringUtil.java | 16 ++++++++++++++++ .../wizardlybump17/wlib/item/ItemBuilder.java | 5 +++-- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/bukkit-utils/src/main/java/com/wizardlybump17/wlib/util/bukkit/StringUtil.java b/bukkit-utils/src/main/java/com/wizardlybump17/wlib/util/bukkit/StringUtil.java index 3c3d0d6f..b9e50776 100644 --- a/bukkit-utils/src/main/java/com/wizardlybump17/wlib/util/bukkit/StringUtil.java +++ b/bukkit-utils/src/main/java/com/wizardlybump17/wlib/util/bukkit/StringUtil.java @@ -1,5 +1,6 @@ package com.wizardlybump17.wlib.util.bukkit; +import lombok.NonNull; import lombok.experimental.UtilityClass; import net.md_5.bungee.api.ChatColor; import org.bukkit.Color; @@ -11,6 +12,7 @@ import java.util.Collections; import java.util.List; import java.util.ListIterator; +import java.util.function.Supplier; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -78,6 +80,20 @@ public static List colorize(List strings) { return strings; } + public static @NonNull List colorize(@NonNull List strings, @Nullable Supplier> listSupplier) { + if (listSupplier == null) { + ListIterator iterator = strings.listIterator(); + while (iterator.hasNext()) + iterator.set(colorize(iterator.next())); + return strings; + } + + List list = listSupplier.get(); + for (String string : strings) + list.add(colorize(string)); + return list; + } + /** * A beautiful method to use instead of {@link Object#toString()}.
* If the object is a {@link Vector} or a {@link Location}, it will return a string with the coordinates diff --git a/core/src/main/java/com/wizardlybump17/wlib/item/ItemBuilder.java b/core/src/main/java/com/wizardlybump17/wlib/item/ItemBuilder.java index 3e1bca80..e4b4641e 100644 --- a/core/src/main/java/com/wizardlybump17/wlib/item/ItemBuilder.java +++ b/core/src/main/java/com/wizardlybump17/wlib/item/ItemBuilder.java @@ -7,6 +7,7 @@ import com.wizardlybump17.wlib.util.MapUtils; import com.wizardlybump17.wlib.util.bukkit.ConfigUtil; import com.wizardlybump17.wlib.util.bukkit.NamespacedKeyUtil; +import com.wizardlybump17.wlib.util.bukkit.StringUtil; import lombok.NonNull; import org.bukkit.Material; import org.bukkit.NamespacedKey; @@ -442,8 +443,8 @@ public static ItemBuilder deserialize(Map map) { .rawNBTTags(ConfigUtil.get("raw-nbt-tags", map, Collections.emptyMap())) .amount(ConfigUtil.get("amount", map, 1)) .damage(ConfigUtil.get("damage", map, 0)) - .displayName(ConfigUtil.get("display-name", map, (String) null)) - .lore(ConfigUtil.get("lore", map, Collections.emptyList())) + .displayName(ConfigUtil.map("display-name", map, () -> null, StringUtil::fancy)) + .lore(ConfigUtil., List>map("lore", map, Collections::emptyList, lore -> StringUtil.colorize(lore, ArrayList::new))) .itemFlags(ConfigUtil.>get("item-flags", map, Collections.emptyList()).stream().map(ItemFlag::valueOf).collect(Collectors.toSet())) .enchantments(MapUtils.mapKeys(ConfigUtil.>get("enchantments", map, Collections.emptyMap()), string -> Enchantment.getByKey(NamespacedKeyUtil.fromString(string)))) .nbtTags(ItemAdapter.getInstance().deserializeContainer(ConfigUtil.get("nbt-tags", map, Collections.emptyMap()))) From 180f3a2758a99a9ba7441d545a2e38e9ce02a635 Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Fri, 6 Sep 2024 21:48:44 -0300 Subject: [PATCH 03/73] improved the logging --- .../wizardlybump17/wlib/database/Database.java | 18 +++++++++++++----- .../wlib/database/MySQLDatabase.java | 6 ++++++ .../wlib/database/SQLiteDatabase.java | 13 ++++++++++--- 3 files changed, 29 insertions(+), 8 deletions(-) diff --git a/database/src/main/java/com/wizardlybump17/wlib/database/Database.java b/database/src/main/java/com/wizardlybump17/wlib/database/Database.java index ee3c670f..fdcb2f26 100644 --- a/database/src/main/java/com/wizardlybump17/wlib/database/Database.java +++ b/database/src/main/java/com/wizardlybump17/wlib/database/Database.java @@ -8,15 +8,23 @@ import java.sql.*; import java.util.*; import java.util.function.Consumer; +import java.util.logging.Level; +import java.util.logging.Logger; @Data @RequiredArgsConstructor(access = AccessLevel.PROTECTED) +//TODO this class should rethrow the exceptions public abstract class Database> { private final M model; private final DatabaseHolder holder; protected final Properties properties; protected Connection connection; + private final @NonNull Logger logger; + + public Database(@NonNull M model, @NonNull DatabaseHolder holder, @NonNull Properties properties) { + this(model, holder, properties, holder.getLogger()); + } public boolean isClosed() { return connection == null; @@ -29,7 +37,7 @@ public void open(Consumer> callback) { if (callback != null) callback.accept(this); } catch (Exception e) { - e.printStackTrace(); + getLogger().log(Level.SEVERE, "Error while opening the database connection", e); } } @@ -49,7 +57,7 @@ public void close(Consumer> callback) { if (callback != null) callback.accept(this); } catch (Exception e) { - e.printStackTrace(); + getLogger().log(Level.SEVERE, "Error while closing the database connection", e); } } @@ -57,7 +65,7 @@ public Database update(String command, Object... replacements) { try { returnUpdate(command, replacements).close(); } catch (SQLException e) { - e.printStackTrace(); + getLogger().log(Level.SEVERE, "Error while executing \"" + command + "\" with the arguments " + Arrays.toString(replacements), e); } return this; } @@ -77,7 +85,7 @@ public PreparedStatement returnUpdate(String command, Object... replacements) { statement.executeUpdate(); return statement; } catch (Exception e) { - e.printStackTrace(); + getLogger().log(Level.SEVERE, "Error while executing \"" + command + "\" with the arguments " + Arrays.toString(replacements), e); } return null; } @@ -96,7 +104,7 @@ public ResultSet query(String query, Object... replacements) { statement.setObject(i + 1, replacements[i]); return statement.executeQuery(); } catch (Exception e) { - e.printStackTrace(); + getLogger().log(Level.SEVERE, "Error while executing \"" + query + "\" with the arguments " + Arrays.toString(replacements), e); return null; } } diff --git a/database/src/main/java/com/wizardlybump17/wlib/database/MySQLDatabase.java b/database/src/main/java/com/wizardlybump17/wlib/database/MySQLDatabase.java index 0198be7b..3b2f4e30 100644 --- a/database/src/main/java/com/wizardlybump17/wlib/database/MySQLDatabase.java +++ b/database/src/main/java/com/wizardlybump17/wlib/database/MySQLDatabase.java @@ -1,9 +1,11 @@ package com.wizardlybump17.wlib.database; import com.wizardlybump17.wlib.database.model.MySQLDatabaseModel; +import lombok.NonNull; import java.sql.PreparedStatement; import java.util.Properties; +import java.util.logging.Logger; import java.util.regex.Pattern; public class MySQLDatabase extends Database { @@ -14,6 +16,10 @@ public MySQLDatabase(MySQLDatabaseModel model, Properties properties, DatabaseHo super(model, holder, properties); } + public MySQLDatabase(@NonNull MySQLDatabaseModel model, @NonNull Properties properties, @NonNull DatabaseHolder holder, @NonNull Logger logger) { + super(model, holder, properties, logger); + } + @Override public final String getJdbcUrl() { return getModel().getBaseUrl() diff --git a/database/src/main/java/com/wizardlybump17/wlib/database/SQLiteDatabase.java b/database/src/main/java/com/wizardlybump17/wlib/database/SQLiteDatabase.java index 26f56447..786134cc 100644 --- a/database/src/main/java/com/wizardlybump17/wlib/database/SQLiteDatabase.java +++ b/database/src/main/java/com/wizardlybump17/wlib/database/SQLiteDatabase.java @@ -3,11 +3,14 @@ import com.wizardlybump17.wlib.database.model.SQLiteDatabaseModel; import lombok.EqualsAndHashCode; import lombok.Getter; +import lombok.NonNull; import java.io.File; import java.sql.PreparedStatement; import java.util.Properties; import java.util.function.Consumer; +import java.util.logging.Level; +import java.util.logging.Logger; import java.util.regex.Pattern; @Getter @@ -23,6 +26,11 @@ public SQLiteDatabase(SQLiteDatabaseModel model, Properties properties, Database file = new File(holder.getDataFolder(), properties.getProperty("database", "database.db")); } + public SQLiteDatabase(@NonNull SQLiteDatabaseModel model, @NonNull Properties properties, @NonNull DatabaseHolder holder, @NonNull Logger logger) { + super(model, holder, properties, logger); + file = new File(holder.getDataFolder(), properties.getProperty("database", "database.db")); + } + @Override public void open(Consumer> callback) { try { @@ -33,11 +41,10 @@ public void open(Consumer> callback) { Class.forName("org.sqlite.JDBC"); } catch (ClassNotFoundException e) { - getHolder().getLogger().severe("SQLite driver not found"); - e.printStackTrace(); + getLogger().log(Level.SEVERE, "The SQLite driver was not found", e); return; } catch (Exception e) { - e.printStackTrace(); + getLogger().log(Level.SEVERE, "Error while connecting to the SQLite database", e); return; } From 5e7a81a7ae16ff986398157996c92290876f80e8 Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Wed, 11 Sep 2024 22:26:00 -0300 Subject: [PATCH 04/73] added methods to manipulate constructors reflectively --- .../wlib/util/ReflectionUtil.java | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/utils/src/main/java/com/wizardlybump17/wlib/util/ReflectionUtil.java b/utils/src/main/java/com/wizardlybump17/wlib/util/ReflectionUtil.java index 90d36472..2b99699e 100644 --- a/utils/src/main/java/com/wizardlybump17/wlib/util/ReflectionUtil.java +++ b/utils/src/main/java/com/wizardlybump17/wlib/util/ReflectionUtil.java @@ -4,8 +4,11 @@ import lombok.experimental.UtilityClass; import org.jetbrains.annotations.Nullable; +import java.lang.reflect.Constructor; import java.lang.reflect.Field; +import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; +import java.util.Arrays; import java.util.logging.Level; import java.util.logging.Logger; @@ -71,4 +74,24 @@ public static Method getMethod(@NonNull String name, @NonNull Class clazz, @N return null; } } + + public static @Nullable Constructor getConstructor(@NonNull Class clazz, @NonNull Class... parameters) { + try { + return clazz.getDeclaredConstructor(parameters); + } catch (NoSuchMethodException e) { + LOGGER.log(Level.SEVERE, "Error while fetching the " + Arrays.stream(parameters).map(Class::getName).toList() + " constructor in the " + clazz.getName() + " class."); + return null; + } + } + + public static @NonNull T invokeConstructor(@NonNull Constructor constructor, Object... parameters) { + try { + constructor.setAccessible(true); + T value = constructor.newInstance(parameters); + constructor.setAccessible(false); + return value; + } catch (InstantiationException | IllegalAccessException | InvocationTargetException e) { + throw new IllegalStateException("Error while creating a new " + constructor.getDeclaringClass().getName() + " instance with the parameters " + Arrays.toString(parameters)); + } + } } From 7653270c6fa2401881bcc8bcab6f05cb4d262068 Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Wed, 11 Sep 2024 22:26:19 -0300 Subject: [PATCH 05/73] version changed --- build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index 33df5d57..b50239ec 100644 --- a/build.gradle +++ b/build.gradle @@ -7,7 +7,7 @@ apply plugin: 'maven-publish' allprojects { group = 'com.wizardlybump17.wlib' - version = '1.6.4' + version = '1.6.5' apply plugin: 'com.github.johnrengelman.shadow' apply plugin: 'java' From d81be3f48263158d9cda27b50083602fa62a5de0 Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Fri, 20 Sep 2024 16:00:08 -0300 Subject: [PATCH 06/73] using the "escape" parameter --- .../src/main/java/com/wizardlybump17/wlib/util/StringUtil.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/utils/src/main/java/com/wizardlybump17/wlib/util/StringUtil.java b/utils/src/main/java/com/wizardlybump17/wlib/util/StringUtil.java index 62f615f8..58ee5aae 100644 --- a/utils/src/main/java/com/wizardlybump17/wlib/util/StringUtil.java +++ b/utils/src/main/java/com/wizardlybump17/wlib/util/StringUtil.java @@ -100,7 +100,7 @@ public static String fixName(String name) { StringBuilder placeholder = new StringBuilder(); boolean escaped = false; for (char current : chars) { - if (current == ESCAPE && !escaped) { + if (current == escape && !escaped) { escaped = true; continue; } From b2598d7312b740e300a1b2d606ecefe0a12b1de9 Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Fri, 20 Sep 2024 16:15:19 -0300 Subject: [PATCH 07/73] added the DateReader class --- commands/build.gradle | 1 + .../wlib/command/args/ArgsReaderRegistry.java | 1 + .../wlib/command/args/reader/DateReader.java | 25 +++++++++++++++++++ 3 files changed, 27 insertions(+) create mode 100644 commands/src/main/java/com/wizardlybump17/wlib/command/args/reader/DateReader.java diff --git a/commands/build.gradle b/commands/build.gradle index bad6d434..1b70a3f2 100644 --- a/commands/build.gradle +++ b/commands/build.gradle @@ -8,4 +8,5 @@ dependencies { project(':objects'), project(':utils') ) + implementation("com.github.sisyphsu:dateparser:1.0.11") } diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/args/ArgsReaderRegistry.java b/commands/src/main/java/com/wizardlybump17/wlib/command/args/ArgsReaderRegistry.java index caf39aa9..09c8f99d 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/args/ArgsReaderRegistry.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/args/ArgsReaderRegistry.java @@ -27,6 +27,7 @@ public class ArgsReaderRegistry extends Registry>, INSTANCE.add(new BigDecimalArgsReader()); INSTANCE.add(new UUIDReader()); INSTANCE.add(new BooleanReader()); + INSTANCE.add(new DateReader()); } private ArgsReaderRegistry() { diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/args/reader/DateReader.java b/commands/src/main/java/com/wizardlybump17/wlib/command/args/reader/DateReader.java new file mode 100644 index 00000000..6460d671 --- /dev/null +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/args/reader/DateReader.java @@ -0,0 +1,25 @@ +package com.wizardlybump17.wlib.command.args.reader; + +import com.github.sisyphsu.dateparser.DateParserUtils; +import lombok.NonNull; +import org.jetbrains.annotations.Nullable; + +import java.time.format.DateTimeParseException; +import java.util.Date; + +public class DateReader extends ArgsReader { + + @Override + public @NonNull Class getType() { + return Date.class; + } + + @Override + public @Nullable Date read(@NonNull String string) { + try { + return DateParserUtils.parseDate(string); + } catch (DateTimeParseException e) { + return null; //i need to rework the command system :C + } + } +} From 548cd8ef5c4f33bf69252ae98eeb8c1c19a8c8dd Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Fri, 20 Sep 2024 16:29:01 -0300 Subject: [PATCH 08/73] relocating the dateparser dependency --- commands/build.gradle | 4 ++++ core/build.gradle | 1 + 2 files changed, 5 insertions(+) diff --git a/commands/build.gradle b/commands/build.gradle index 1b70a3f2..0453aaab 100644 --- a/commands/build.gradle +++ b/commands/build.gradle @@ -10,3 +10,7 @@ dependencies { ) implementation("com.github.sisyphsu:dateparser:1.0.11") } + +shadowJar { + relocate("com.github.sisyphsu", "com.wizardlybump17.wlib.libs.com.github.sisyphsu") +} diff --git a/core/build.gradle b/core/build.gradle index 13935b63..776fb140 100644 --- a/core/build.gradle +++ b/core/build.gradle @@ -40,4 +40,5 @@ processResources { shadowJar { archiveFileName = 'WLib-v' + project.version + '.jar' + relocate("com.github.sisyphsu", "com.wizardlybump17.wlib.libs.com.github.sisyphsu") } From bf0fb5687ebecbfd910baa396fbe5af8cd36f6f3 Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Fri, 20 Sep 2024 18:21:29 -0300 Subject: [PATCH 09/73] added support for some prefixed dates --- .../wlib/command/args/reader/DateReader.java | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/args/reader/DateReader.java b/commands/src/main/java/com/wizardlybump17/wlib/command/args/reader/DateReader.java index 6460d671..70f576eb 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/args/reader/DateReader.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/args/reader/DateReader.java @@ -5,10 +5,32 @@ import org.jetbrains.annotations.Nullable; import java.time.format.DateTimeParseException; +import java.util.Calendar; import java.util.Date; +import java.util.HashMap; +import java.util.Map; +import java.util.function.Supplier; public class DateReader extends ArgsReader { + //i could do a dedicated system for this, but this one is simpler and works so idc + public static final @NonNull Map> PROVIDERS = new HashMap<>(); + + static { + PROVIDERS.put("now", Date::new); + PROVIDERS.put("today", () -> getToday().getTime()); + PROVIDERS.put("yesterday", () -> { + Calendar today = getToday(); + today.add(Calendar.DAY_OF_YEAR, -1); + return today.getTime(); + }); + PROVIDERS.put("tomorrow", () -> { + Calendar today = getToday(); + today.add(Calendar.DAY_OF_YEAR, 1); + return today.getTime(); + }); + } + @Override public @NonNull Class getType() { return Date.class; @@ -16,10 +38,23 @@ public class DateReader extends ArgsReader { @Override public @Nullable Date read(@NonNull String string) { + Supplier provider = PROVIDERS.get(string.toLowerCase()); + if (provider != null) + return provider.get(); + try { return DateParserUtils.parseDate(string); } catch (DateTimeParseException e) { return null; //i need to rework the command system :C } } + + public static @NonNull Calendar getToday() { + Calendar calendar = Calendar.getInstance(); + calendar.set(Calendar.HOUR_OF_DAY, 0); + calendar.set(Calendar.MINUTE, 0); + calendar.set(Calendar.SECOND, 0); + calendar.set(Calendar.MILLISECOND, 0); + return calendar; + } } From 92c37243f433fcb4a218606f86bb3b609fc3f117 Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Tue, 24 Sep 2024 23:53:36 -0300 Subject: [PATCH 10/73] uhum, did it complain about it only now? --- .../wlib/adapter/v1_20_R3/GlowEnchantment.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/versions/v1_20_R3/src/main/java/com/wizardlybump17/wlib/adapter/v1_20_R3/GlowEnchantment.java b/versions/v1_20_R3/src/main/java/com/wizardlybump17/wlib/adapter/v1_20_R3/GlowEnchantment.java index f7fb09a0..6e24b301 100644 --- a/versions/v1_20_R3/src/main/java/com/wizardlybump17/wlib/adapter/v1_20_R3/GlowEnchantment.java +++ b/versions/v1_20_R3/src/main/java/com/wizardlybump17/wlib/adapter/v1_20_R3/GlowEnchantment.java @@ -58,4 +58,9 @@ public boolean canEnchantItem(@NonNull ItemStack itemStack) { public @NonNull NamespacedKey getKey() { return KEY; } + + @Override + public @NonNull String getTranslationKey() { + return "wlib.glow"; + } } From 4869353dfe6b43ce5c486598b8345604fbedf8af Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Tue, 24 Sep 2024 23:54:04 -0300 Subject: [PATCH 11/73] reworked the ItemFilter. A total of 0 plugins will break --- .../wizardlybump17/wlib/item/ItemFilter.java | 161 +++++++++--------- 1 file changed, 78 insertions(+), 83 deletions(-) diff --git a/core/src/main/java/com/wizardlybump17/wlib/item/ItemFilter.java b/core/src/main/java/com/wizardlybump17/wlib/item/ItemFilter.java index 33ddc98e..e3a4ee1f 100644 --- a/core/src/main/java/com/wizardlybump17/wlib/item/ItemFilter.java +++ b/core/src/main/java/com/wizardlybump17/wlib/item/ItemFilter.java @@ -1,32 +1,27 @@ package com.wizardlybump17.wlib.item; import com.wizardlybump17.wlib.util.MapUtils; +import com.wizardlybump17.wlib.util.bukkit.ConfigUtil; import lombok.Getter; +import lombok.NonNull; import lombok.RequiredArgsConstructor; import org.bukkit.configuration.serialization.ConfigurationSerializable; import org.bukkit.configuration.serialization.SerializableAs; import org.bukkit.enchantments.Enchantment; import org.bukkit.inventory.ItemStack; -import org.jetbrains.annotations.NotNull; -import java.util.ArrayList; +import java.util.EnumMap; import java.util.List; import java.util.Map; import java.util.Set; -import java.util.regex.Matcher; -import java.util.regex.Pattern; import java.util.stream.Collectors; -@SerializableAs("item-filter") +@SerializableAs("WLib:ItemFilter") @RequiredArgsConstructor @Getter public class ItemFilter implements ConfigurationSerializable { - private static final Pattern STARTS_WITH = Pattern.compile("(.+)\\*"); - private static final Pattern ENDS_WITH = Pattern.compile("\\*(.+)"); - private static final Pattern CONTAINS = Pattern.compile("\\*(.+)\\*"); - - private final List> filters; + private final Map filters; /** * @param items the items to test @@ -58,50 +53,50 @@ public boolean testAll(Iterable items) { @SuppressWarnings("unchecked") public boolean accept(ItemStack item) { ItemBuilder builder = ItemBuilder.fromItemStack(item); - for (Map filtersMap : filters) { - for (Map.Entry entry : filtersMap.entrySet()) { - Object object = entry.getValue(); - switch (entry.getKey()) { - case MATERIAL -> { - if (!testMaterial(object.toString(), builder)) - return false; - } - case AMOUNT -> { - if (!testAmount(object.toString(), builder)) - return false; - } - case DAMAGE -> { - if (!testDamage(object.toString(), builder)) - return false; - } - case DISPLAY_NAME -> { - if (!testDisplayName(object.toString(), builder)) - return false; - } - case LORE -> { - if (!testLore((List) object, builder)) - return false; - } - case ENCHANTMENTS -> { - if (!testEnchantments((Map) object, builder)) - return false; - } - case ITEM_FLAGS -> { - if (!testItemFlags((List) object, builder)) - return false; - } - case GLOW -> { - if (!testGlow((boolean) object, builder)) - return false; - } - case UNBREAKABLE -> { - if (!testUnbreakable((boolean) object, builder)) - return false; - } - case NBT_TAGS -> { - if (!testNbtTags((Map) object, builder)) - return false; - } + for (Map.Entry entry : filters.entrySet()) { + FilterType type = entry.getKey(); + Object object = entry.getValue(); + + switch (type) { + case MATERIAL -> { + if (!testMaterial(object.toString(), builder)) + return false; + } + case AMOUNT -> { + if (!testAmount(object.toString(), builder)) + return false; + } + case DAMAGE -> { + if (!testDamage(object.toString(), builder)) + return false; + } + case DISPLAY_NAME -> { + if (!testDisplayName(object.toString(), builder)) + return false; + } + case LORE -> { + if (!testLore((List) object, builder)) + return false; + } + case ENCHANTMENTS -> { + if (!testEnchantments((Map) object, builder)) + return false; + } + case ITEM_FLAGS -> { + if (!testItemFlags((List) object, builder)) + return false; + } + case GLOW -> { + if (!testGlow((boolean) object, builder)) + return false; + } + case UNBREAKABLE -> { + if (!testUnbreakable((boolean) object, builder)) + return false; + } + case NBT_TAGS -> { + if (!testNbtTags((Map) object, builder)) + return false; } } } @@ -145,7 +140,7 @@ public static boolean testLore(List lore, ItemBuilder builder) { if (lore != null && !builder.lore().isEmpty()) { for (String line : lore) - if (!testString(line, builder.lore())) + if (!testStrings(line, builder.lore())) return false; return true; } @@ -176,7 +171,7 @@ public static boolean testItemFlags(List itemFlags, ItemBuilder builder) if (itemFlags != null && !flags.isEmpty()) { for (String flag : itemFlags) - if (!testString(flag, flags)) + if (!testStrings(flag, flags)) return false; return true; } @@ -213,17 +208,14 @@ public static boolean testString(String base, String string) { return true; if (!base.isEmpty() && string != null) { - Matcher containsMatcher = CONTAINS.matcher(base); - if (containsMatcher.matches()) - return string.contains(containsMatcher.group(1)); + if (base.charAt(0) == '*' && base.charAt(base.length() - 1) == '*') //contains + return string.contains(base.substring(1, base.length() - 2)); - Matcher startMatcher = STARTS_WITH.matcher(base); - if (startMatcher.matches()) - return string.startsWith(startMatcher.group(1)); + if (base.charAt(0) == '*') //starts with + return string.startsWith(base.substring(1)); - Matcher endMatcher = ENDS_WITH.matcher(base); - if (endMatcher.matches()) - return string.endsWith(endMatcher.group(1)); + if (base.charAt(base.length() - 1) == '*') //ends with + return string.endsWith(base.substring(0, base.length() - 2)); return string.equals(base); } @@ -231,7 +223,7 @@ public static boolean testString(String base, String string) { return false; } - public static boolean testString(String base, Iterable strings) { + public static boolean testStrings(String base, Iterable strings) { for (String string : strings) if (testString(base, string)) return true; @@ -239,21 +231,18 @@ public static boolean testString(String base, Iterable strings) { } public static boolean testInt(String base, int i) { - Matcher containsMatcher = CONTAINS.matcher(base); - if (containsMatcher.matches()) { - int value = Integer.parseInt(containsMatcher.group(1)); + if (base.charAt(0) == '=') { //equals + int value = Integer.parseInt(base.substring(1)); return i == value; } - Matcher startsMatcher = STARTS_WITH.matcher(base); - if (startsMatcher.matches()) { - int value = Integer.parseInt(startsMatcher.group(1)); + if (base.charAt(0) == '>') { //greater than + int value = Integer.parseInt(base.substring(1)); return i >= value; } - Matcher endsMatcher = ENDS_WITH.matcher(base); - if (endsMatcher.matches()) { - int value = Integer.parseInt(endsMatcher.group(1)); + if (base.charAt(base.length() - 1) == '<') { //less than + int value = Integer.parseInt(base.substring(0, base.length() - 2)); return i <= value; } @@ -261,15 +250,21 @@ public static boolean testInt(String base, int i) { } @Override - public @NotNull Map serialize() { - return Map.of("filters", filters.stream().map(map -> MapUtils.mapKeys(map, Enum::name)).toList()); + public @NonNull Map serialize() { + return Map.of("filters", MapUtils.mapKeys(filters, Enum::name)); } - @SuppressWarnings("unchecked") - public static ItemFilter deserialize(Map args) { - List> filters = new ArrayList<>(); - for (Map map : ((List>) args.get("filters"))) - filters.add(MapUtils.mapKeys(map, key -> FilterType.valueOf(key.toUpperCase()))); - return new ItemFilter(filters); + public static ItemFilter deserialize(@NonNull Map map) { + return new ItemFilter( + ConfigUtil., Map>map( + "filters", + map, + filters -> MapUtils.mapKeys( + filters, + () -> new EnumMap<>(FilterType.class), + filter -> FilterType.valueOf(filter.toUpperCase()) + ) + ) + ); } } From e1bd5662e786eef8e527bf37268b8d4825bcfedf Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Wed, 25 Sep 2024 12:53:06 -0300 Subject: [PATCH 12/73] version changed --- build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index b50239ec..d3e16379 100644 --- a/build.gradle +++ b/build.gradle @@ -7,7 +7,7 @@ apply plugin: 'maven-publish' allprojects { group = 'com.wizardlybump17.wlib' - version = '1.6.5' + version = '1.6.6' apply plugin: 'com.github.johnrengelman.shadow' apply plugin: 'java' From 443168f0d2b4b6f5e758df6b60ba0970450b4bdb Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Fri, 4 Oct 2024 00:15:16 -0300 Subject: [PATCH 13/73] excluding the lombok --- commands/build.gradle | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/commands/build.gradle b/commands/build.gradle index 0453aaab..f57b9327 100644 --- a/commands/build.gradle +++ b/commands/build.gradle @@ -8,7 +8,9 @@ dependencies { project(':objects'), project(':utils') ) - implementation("com.github.sisyphsu:dateparser:1.0.11") + implementation("com.github.sisyphsu:dateparser:1.0.11") { + exclude(group: "org.projectlombok", module: "lombok") + } } shadowJar { From 50b26d3c300611bedbf70236bda7c739f22189c2 Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Fri, 4 Oct 2024 00:45:14 -0300 Subject: [PATCH 14/73] removed the workflow --- .github/workflows/gradle-publish.yml | 27 --------------------------- 1 file changed, 27 deletions(-) delete mode 100644 .github/workflows/gradle-publish.yml diff --git a/.github/workflows/gradle-publish.yml b/.github/workflows/gradle-publish.yml deleted file mode 100644 index df420f89..00000000 --- a/.github/workflows/gradle-publish.yml +++ /dev/null @@ -1,27 +0,0 @@ -name: Publish -on: - release: - types: - - created -jobs: - build: - runs-on: ubuntu-latest - permissions: - contents: read - packages: write - steps: - - uses: actions/checkout@v2 - - name: Set up JDK 16 - uses: actions/setup-java@v2 - with: - java-version: '16' - distribution: adopt - server-id: github - settings-path: ${{ github.workspace }} - - name: Build - run: gradle build - - name: Publish - run: gradle publish - env: - USERNAME: ${{ github.actor }} - TOKEN: ${{ secrets.GITHUB_TOKEN }} From 75469cb77af16f8880fe5e107a4066636ed0b967 Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Thu, 10 Oct 2024 22:50:30 -0300 Subject: [PATCH 15/73] added support for the attribute system --- .../wizardlybump17/wlib/item/ItemBuilder.java | 40 +++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/core/src/main/java/com/wizardlybump17/wlib/item/ItemBuilder.java b/core/src/main/java/com/wizardlybump17/wlib/item/ItemBuilder.java index e4b4641e..deb60fc1 100644 --- a/core/src/main/java/com/wizardlybump17/wlib/item/ItemBuilder.java +++ b/core/src/main/java/com/wizardlybump17/wlib/item/ItemBuilder.java @@ -1,5 +1,7 @@ package com.wizardlybump17.wlib.item; +import com.google.common.collect.ImmutableMultimap; +import com.google.common.collect.Multimap; import com.wizardlybump17.wlib.adapter.ItemAdapter; import com.wizardlybump17.wlib.item.handler.ItemMetaHandler; import com.wizardlybump17.wlib.item.handler.model.ItemMetaHandlerModel; @@ -11,6 +13,8 @@ import lombok.NonNull; import org.bukkit.Material; import org.bukkit.NamespacedKey; +import org.bukkit.attribute.Attribute; +import org.bukkit.attribute.AttributeModifier; import org.bukkit.configuration.serialization.ConfigurationSerializable; import org.bukkit.configuration.serialization.SerializableAs; import org.bukkit.enchantments.Enchantment; @@ -367,6 +371,25 @@ public ItemBuilder mergeNbtTags(ItemBuilder other) { return this; } + public @NonNull ItemBuilder attribute(@NonNull Attribute attribute, @NonNull AttributeModifier modifier) { + return consumeMeta(meta -> meta.addAttributeModifier(attribute, modifier)); + } + + public @NonNull ItemBuilder attributes(@Nullable Multimap modifiers) { + return consumeMeta(meta -> meta.setAttributeModifiers(modifiers)); + } + + public @NonNull ItemBuilder attributes(@Nullable Map> attributes) { + consumeMeta(meta -> meta.setAttributeModifiers(null)); + if (attributes == null || attributes.isEmpty()) + return this; + return consumeMeta(meta -> attributes.forEach((attribute, modifiers) -> modifiers.forEach(modifier -> meta.addAttributeModifier(attribute, modifier)))); + } + + public @NonNull Multimap attributes() { + return getFromMeta(ItemMeta::getAttributeModifiers, ImmutableMultimap.of()); + } + public ItemStack build() { return item; } @@ -400,6 +423,10 @@ public Map serialize() { if (glow()) result.put("glow", true); + Multimap attributes = attributes(); + if (!attributes.isEmpty()) + result.put("attributes", MapUtils.mapKeys(attributes.asMap(), TreeMap::new, Enum::name)); + if (metaHandler != null) metaHandler.serialize(result); @@ -453,6 +480,19 @@ public static ItemBuilder deserialize(Map map) { .customData(ConfigUtil.get("custom-data", map, Collections.emptyMap())) .glow(ConfigUtil.get("glow", map, false)); + Optional + .ofNullable(ConfigUtil.>, Map>>map( + "attributes", + map, + () -> null, + attributes -> MapUtils.mapKeys( + attributes, + () -> new EnumMap<>(Attribute.class), + type -> Attribute.valueOf(type.toUpperCase()) + ) + )) + .ifPresent(result::attributes); + ItemMetaHandlerModel metaHandlerModel = ItemMetaHandlerModel.getApplicableModel(result.type()); result.metaHandler(metaHandlerModel == null ? null : metaHandlerModel.createHandler(result)); From 1d9c01d8621fe3e99cb134e3271c47d9b50c355e Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Mon, 14 Oct 2024 11:16:54 -0300 Subject: [PATCH 16/73] using the StringUtil to apply the placeholders --- .../wizardlybump17/wlib/item/ItemBuilder.java | 32 +++++++++---------- 1 file changed, 15 insertions(+), 17 deletions(-) diff --git a/core/src/main/java/com/wizardlybump17/wlib/item/ItemBuilder.java b/core/src/main/java/com/wizardlybump17/wlib/item/ItemBuilder.java index deb60fc1..4a57cc04 100644 --- a/core/src/main/java/com/wizardlybump17/wlib/item/ItemBuilder.java +++ b/core/src/main/java/com/wizardlybump17/wlib/item/ItemBuilder.java @@ -5,7 +5,6 @@ import com.wizardlybump17.wlib.adapter.ItemAdapter; import com.wizardlybump17.wlib.item.handler.ItemMetaHandler; import com.wizardlybump17.wlib.item.handler.model.ItemMetaHandlerModel; -import com.wizardlybump17.wlib.util.CollectionUtil; import com.wizardlybump17.wlib.util.MapUtils; import com.wizardlybump17.wlib.util.bukkit.ConfigUtil; import com.wizardlybump17.wlib.util.bukkit.NamespacedKeyUtil; @@ -263,24 +262,23 @@ public PersistentDataContainer container() { } public ItemBuilder replaceDisplayNameLore(Map replacements) { - String displayName = displayName(); - List lore = lore(); - - for (Map.Entry entry : replacements.entrySet()) { - Object value = entry.getValue(); - if (value == null) - value = "null"; - - displayName = displayName.replace(entry.getKey(), value.toString()); - if (value instanceof String string) - lore = new CollectionUtil<>(lore).replace(entry.getKey(), string).getCollection(); - else if (value instanceof Iterable iterable) - lore = new CollectionUtil<>(lore).replace(entry.getKey(), iterable).getCollection(); - else - lore = new CollectionUtil<>(lore).replace(entry.getKey(), value.toString()).getCollection(); + Iterator> iterator = replacements.entrySet().iterator(); + while (iterator.hasNext()) { + Map.Entry entry = iterator.next(); + String key = entry.getKey(); + + if (key.charAt(0) != '{' || key.charAt(key.length() - 1) != '}') + continue; + + iterator.remove(); + replacements.put(key.substring(1, key.length() - 1), entry.getValue()); } - return displayName(displayName).lore(lore); + return displayName(com.wizardlybump17.wlib.util.StringUtil.applyPlaceholders(displayName(), replacements)) + .lore(lore().stream() + .map(line -> com.wizardlybump17.wlib.util.StringUtil.applyPlaceholders(line, replacements)) + .toList() + ); } public ItemBuilder unbreakable(boolean unbreakable) { From d1dcb2b105845cb9eb8121396577820897449680 Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Mon, 14 Oct 2024 11:39:11 -0300 Subject: [PATCH 17/73] appending the key if it was not found --- .../java/com/wizardlybump17/wlib/util/StringUtil.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/utils/src/main/java/com/wizardlybump17/wlib/util/StringUtil.java b/utils/src/main/java/com/wizardlybump17/wlib/util/StringUtil.java index 58ee5aae..cf848b11 100644 --- a/utils/src/main/java/com/wizardlybump17/wlib/util/StringUtil.java +++ b/utils/src/main/java/com/wizardlybump17/wlib/util/StringUtil.java @@ -118,8 +118,12 @@ public static String fixName(String name) { if (placeholder.isEmpty()) throw new PlaceholderException("Unexpected placeholder end"); - Object value = placeholders.get(placeholder.substring(1)); - builder.append(value); + String key = placeholder.substring(1); + Object value = placeholders.get(key); + if (value == null) + builder.append(begin).append(key).append(end); + else + builder.append(value); placeholder.setLength(0); continue; } From 0706e58146d16a6f143225a2f4623b9a04abebb9 Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Sat, 26 Oct 2024 17:23:30 -0300 Subject: [PATCH 18/73] appending lists to the lore --- .../wizardlybump17/wlib/item/ItemBuilder.java | 25 ++++++++++++++++--- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/core/src/main/java/com/wizardlybump17/wlib/item/ItemBuilder.java b/core/src/main/java/com/wizardlybump17/wlib/item/ItemBuilder.java index 4a57cc04..683ea5e5 100644 --- a/core/src/main/java/com/wizardlybump17/wlib/item/ItemBuilder.java +++ b/core/src/main/java/com/wizardlybump17/wlib/item/ItemBuilder.java @@ -274,11 +274,28 @@ public ItemBuilder replaceDisplayNameLore(Map replacements) { replacements.put(key.substring(1, key.length() - 1), entry.getValue()); } + List lore = new ArrayList<>(lore()); + ListIterator loreIterator = lore.listIterator(); + while (loreIterator.hasNext()) { + String line = loreIterator.next(); + + if (line.length() < 2 || line.charAt(0) != com.wizardlybump17.wlib.util.StringUtil.PLACEHOLDER_BEGIN || line.charAt(line.length() - 1) != com.wizardlybump17.wlib.util.StringUtil.PLACEHOLDER_END) { + loreIterator.set(com.wizardlybump17.wlib.util.StringUtil.applyPlaceholders(line, replacements)); + continue; + } + + Object object = replacements.get(line.substring(1, line.length() - 1)); + if (object instanceof Collection collection) { + loreIterator.remove(); + collection.forEach(element -> loreIterator.add(String.valueOf(element))); + continue; + } + + loreIterator.set(com.wizardlybump17.wlib.util.StringUtil.applyPlaceholders(line, replacements)); + } + return displayName(com.wizardlybump17.wlib.util.StringUtil.applyPlaceholders(displayName(), replacements)) - .lore(lore().stream() - .map(line -> com.wizardlybump17.wlib.util.StringUtil.applyPlaceholders(line, replacements)) - .toList() - ); + .lore(lore); } public ItemBuilder unbreakable(boolean unbreakable) { From ead9501d78a538f0b48811d22c463e9d6f3a4e66 Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Sat, 26 Oct 2024 17:50:01 -0300 Subject: [PATCH 19/73] version changed --- build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index d3e16379..b3f35803 100644 --- a/build.gradle +++ b/build.gradle @@ -7,7 +7,7 @@ apply plugin: 'maven-publish' allprojects { group = 'com.wizardlybump17.wlib' - version = '1.6.6' + version = '1.6.7' apply plugin: 'com.github.johnrengelman.shadow' apply plugin: 'java' From ac45e0937e00fc77d36e3274060f9c7ecfde70ff Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Tue, 12 Nov 2024 23:40:41 -0300 Subject: [PATCH 20/73] reworked the command system --- .../bungee/command/BungeeCommandExecutor.java | 21 +- .../bungee/command/BungeeCommandManager.java | 2 +- ...{GenericSender.java => CommandSender.java} | 15 +- .../command/sender/ProxiedPlayerSender.java | 42 --- .../wlib/command/CommandManager.java | 97 ++---- .../wlib/command/CommandSender.java | 12 - .../wlib/command/RegisteredCommand.java | 275 ------------------ .../command/{ => annotation}/Command.java | 4 +- .../command/data/AnnotationCommandData.java | 96 ++++++ .../wlib/command/data/CommandData.java | 66 +++++ .../command/exception/CommandException.java | 21 ++ .../command/executor/CommandExecutor.java | 12 + .../command/extractor/CommandExtractor.java | 13 + .../extractor/DirectCommandExtractor.java | 16 + .../extractor/MethodCommandExtractor.java | 44 +++ .../wlib/command/holder/CommandExecutor.java | 3 +- .../command/registered/RegisteredCommand.java | 131 +++++++++ .../registered/RegisteredMethodCommand.java | 122 ++++++++ .../wlib/command/BukkitCommandExecutor.java | 37 +-- .../wlib/command/sender/AbstractSender.java | 39 --- .../command/sender/BlockCommandSender.java | 8 - .../wlib/command/sender/CommandSender.java | 52 ++++ .../wlib/command/sender/ConsoleSender.java | 10 - .../wlib/command/sender/GenericSender.java | 21 -- .../wlib/command/sender/PlayerSender.java | 10 - 25 files changed, 629 insertions(+), 540 deletions(-) rename bungee/src/main/java/com/wizardlybump17/wlib/bungee/command/sender/{GenericSender.java => CommandSender.java} (64%) delete mode 100644 bungee/src/main/java/com/wizardlybump17/wlib/bungee/command/sender/ProxiedPlayerSender.java delete mode 100644 commands/src/main/java/com/wizardlybump17/wlib/command/RegisteredCommand.java rename commands/src/main/java/com/wizardlybump17/wlib/command/{ => annotation}/Command.java (96%) create mode 100644 commands/src/main/java/com/wizardlybump17/wlib/command/data/AnnotationCommandData.java create mode 100644 commands/src/main/java/com/wizardlybump17/wlib/command/data/CommandData.java create mode 100644 commands/src/main/java/com/wizardlybump17/wlib/command/exception/CommandException.java create mode 100644 commands/src/main/java/com/wizardlybump17/wlib/command/executor/CommandExecutor.java create mode 100644 commands/src/main/java/com/wizardlybump17/wlib/command/extractor/CommandExtractor.java create mode 100644 commands/src/main/java/com/wizardlybump17/wlib/command/extractor/DirectCommandExtractor.java create mode 100644 commands/src/main/java/com/wizardlybump17/wlib/command/extractor/MethodCommandExtractor.java create mode 100644 commands/src/main/java/com/wizardlybump17/wlib/command/registered/RegisteredCommand.java create mode 100644 commands/src/main/java/com/wizardlybump17/wlib/command/registered/RegisteredMethodCommand.java delete mode 100644 core/src/main/java/com/wizardlybump17/wlib/command/sender/AbstractSender.java delete mode 100644 core/src/main/java/com/wizardlybump17/wlib/command/sender/BlockCommandSender.java create mode 100644 core/src/main/java/com/wizardlybump17/wlib/command/sender/CommandSender.java delete mode 100644 core/src/main/java/com/wizardlybump17/wlib/command/sender/ConsoleSender.java delete mode 100644 core/src/main/java/com/wizardlybump17/wlib/command/sender/GenericSender.java delete mode 100644 core/src/main/java/com/wizardlybump17/wlib/command/sender/PlayerSender.java diff --git a/bungee/src/main/java/com/wizardlybump17/wlib/bungee/command/BungeeCommandExecutor.java b/bungee/src/main/java/com/wizardlybump17/wlib/bungee/command/BungeeCommandExecutor.java index 57ed1875..743da1c2 100644 --- a/bungee/src/main/java/com/wizardlybump17/wlib/bungee/command/BungeeCommandExecutor.java +++ b/bungee/src/main/java/com/wizardlybump17/wlib/bungee/command/BungeeCommandExecutor.java @@ -1,13 +1,13 @@ package com.wizardlybump17.wlib.bungee.command; -import com.wizardlybump17.wlib.bungee.command.sender.GenericSender; -import com.wizardlybump17.wlib.bungee.command.sender.ProxiedPlayerSender; +import com.wizardlybump17.wlib.bungee.command.sender.CommandSender; import com.wizardlybump17.wlib.command.CommandManager; -import com.wizardlybump17.wlib.command.CommandSender; +import com.wizardlybump17.wlib.command.exception.CommandException; import com.wizardlybump17.wlib.command.holder.CommandExecutor; -import net.md_5.bungee.api.connection.ProxiedPlayer; import net.md_5.bungee.api.plugin.Command; +import java.util.logging.Level; + public class BungeeCommandExecutor extends Command implements CommandExecutor { private final CommandManager manager; @@ -18,17 +18,16 @@ public BungeeCommandExecutor(CommandManager manager, String name) { } @Override - public void execute(CommandSender sender, String commandName, String[] args) { + public void execute(com.wizardlybump17.wlib.command.CommandSender sender, String commandName, String[] args) throws CommandException { manager.execute(sender, commandName + " " + String.join(" ", args)); } @Override public void execute(net.md_5.bungee.api.CommandSender sender, String[] args) { - CommandSender realSender; - if (sender instanceof ProxiedPlayer) - realSender = new ProxiedPlayerSender((ProxiedPlayer) sender); - else - realSender = new GenericSender(sender); - execute(realSender, getName(), args); + try { + execute(new CommandSender(sender), getName(), args); + } catch (CommandException e) { + manager.getHolder().getLogger().log(Level.SEVERE, "Error while executing a command", e); + } } } diff --git a/bungee/src/main/java/com/wizardlybump17/wlib/bungee/command/BungeeCommandManager.java b/bungee/src/main/java/com/wizardlybump17/wlib/bungee/command/BungeeCommandManager.java index 48c0b047..416de0ef 100644 --- a/bungee/src/main/java/com/wizardlybump17/wlib/bungee/command/BungeeCommandManager.java +++ b/bungee/src/main/java/com/wizardlybump17/wlib/bungee/command/BungeeCommandManager.java @@ -1,7 +1,7 @@ package com.wizardlybump17.wlib.bungee.command; import com.wizardlybump17.wlib.command.CommandManager; -import com.wizardlybump17.wlib.command.RegisteredCommand; +import com.wizardlybump17.wlib.command.registered.RegisteredCommand; import net.md_5.bungee.api.plugin.Command; import net.md_5.bungee.api.plugin.Plugin; diff --git a/bungee/src/main/java/com/wizardlybump17/wlib/bungee/command/sender/GenericSender.java b/bungee/src/main/java/com/wizardlybump17/wlib/bungee/command/sender/CommandSender.java similarity index 64% rename from bungee/src/main/java/com/wizardlybump17/wlib/bungee/command/sender/GenericSender.java rename to bungee/src/main/java/com/wizardlybump17/wlib/bungee/command/sender/CommandSender.java index 86698b06..ef0ddda4 100644 --- a/bungee/src/main/java/com/wizardlybump17/wlib/bungee/command/sender/GenericSender.java +++ b/bungee/src/main/java/com/wizardlybump17/wlib/bungee/command/sender/CommandSender.java @@ -1,11 +1,13 @@ package com.wizardlybump17.wlib.bungee.command.sender; -import com.wizardlybump17.wlib.command.CommandSender; import lombok.RequiredArgsConstructor; import net.md_5.bungee.api.chat.TextComponent; +import net.md_5.bungee.api.connection.ConnectedPlayer; +import net.md_5.bungee.api.connection.ProxiedPlayer; +import org.jetbrains.annotations.NotNull; @RequiredArgsConstructor -public class GenericSender implements CommandSender { +public class CommandSender implements com.wizardlybump17.wlib.command.CommandSender { private final net.md_5.bungee.api.CommandSender handle; @@ -34,12 +36,11 @@ public boolean hasPermission(String permission) { return handle.hasPermission(permission); } - @Override - public GenericSender toGeneric() { - return this; + public @NotNull ProxiedPlayer asProxiedPlayer() { + return (ProxiedPlayer) handle; } - public static boolean isGeneric() { - return true; + public @NotNull ConnectedPlayer asConnectedPlayer() { + return (ConnectedPlayer) handle; } } diff --git a/bungee/src/main/java/com/wizardlybump17/wlib/bungee/command/sender/ProxiedPlayerSender.java b/bungee/src/main/java/com/wizardlybump17/wlib/bungee/command/sender/ProxiedPlayerSender.java deleted file mode 100644 index d2fca3f7..00000000 --- a/bungee/src/main/java/com/wizardlybump17/wlib/bungee/command/sender/ProxiedPlayerSender.java +++ /dev/null @@ -1,42 +0,0 @@ -package com.wizardlybump17.wlib.bungee.command.sender; - -import com.wizardlybump17.wlib.command.CommandSender; -import lombok.RequiredArgsConstructor; -import net.md_5.bungee.api.chat.TextComponent; -import net.md_5.bungee.api.connection.ProxiedPlayer; - -@RequiredArgsConstructor -public class ProxiedPlayerSender implements CommandSender { - - private final ProxiedPlayer handle; - - @Override - public ProxiedPlayer getHandle() { - return handle; - } - - @Override - public void sendMessage(String message) { - handle.sendMessage(TextComponent.fromLegacyText(message)); - } - - @Override - public void sendMessage(String... messages) { - handle.sendMessage(TextComponent.fromLegacyText(String.join("\n", messages))); - } - - @Override - public String getName() { - return handle.getName(); - } - - @Override - public boolean hasPermission(String permission) { - return handle.hasPermission(permission); - } - - @Override - public GenericSender toGeneric() { - return new GenericSender(handle); - } -} diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/CommandManager.java b/commands/src/main/java/com/wizardlybump17/wlib/command/CommandManager.java index 371354f6..957ee572 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/CommandManager.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/CommandManager.java @@ -1,22 +1,17 @@ package com.wizardlybump17.wlib.command; +import com.wizardlybump17.wlib.command.data.CommandData; +import com.wizardlybump17.wlib.command.exception.CommandException; +import com.wizardlybump17.wlib.command.extractor.CommandExtractor; import com.wizardlybump17.wlib.command.holder.CommandHolder; -import com.wizardlybump17.wlib.util.ReflectionUtil; +import com.wizardlybump17.wlib.command.registered.RegisteredCommand; import lombok.Getter; import lombok.NonNull; import lombok.RequiredArgsConstructor; -import org.jetbrains.annotations.Nullable; +import org.jetbrains.annotations.NotNull; -import java.lang.invoke.MethodHandle; -import java.lang.invoke.MethodHandles; -import java.lang.invoke.MethodType; import java.lang.reflect.Field; -import java.lang.reflect.Method; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.logging.Level; +import java.util.*; @Getter @RequiredArgsConstructor @@ -25,35 +20,12 @@ public class CommandManager { private final List commands = new ArrayList<>(); protected final CommandHolder holder; private final @NonNull Map, Map> fieldCache = new HashMap<>(); + private final @NotNull Set commandExtractors = new HashSet<>(); public void registerCommands(Object... objects) { - for (Object object : objects) { - for (Method method : object.getClass().getDeclaredMethods()) { - if (!method.isAnnotationPresent(Command.class) || method.getParameterCount() == 0 || !CommandSender.class.isAssignableFrom(method.getParameterTypes()[0])) - continue; - - MethodHandle handle; - try { - handle = MethodHandles.publicLookup().findVirtual(object.getClass(), method.getName(), MethodType.methodType(method.getReturnType(), method.getParameterTypes())); - } catch (NoSuchMethodException | IllegalAccessException e) { - holder.getLogger().log(Level.SEVERE, "Error while trying to get the MethodHandle for " + method.getName() + " at " + object.getClass().getName(), e); - continue; - } - - RegisteredCommand command = new RegisteredCommand( - method.getAnnotation(Command.class), - object, - method, - handle - ); - - commands.add(command); - com.wizardlybump17.wlib.command.holder.Command holderCommand = holder.getCommand(command.getName()); - if (holderCommand != null) - holderCommand.setExecutor(holderCommand.getDefaultExecutor(this, command.getName())); - } - } - + for (Object object : objects) + for (CommandExtractor extractor : commandExtractors) + commands.addAll(extractor.extract(this, holder, object)); commands.sort(null); } @@ -61,22 +33,26 @@ public void unregisterCommands() { commands.clear(); } - public void execute(CommandSender sender, String string) { + public void execute(CommandSender sender, String string) throws CommandException { if (commands.isEmpty()) return; for (RegisteredCommand registeredCommand : commands) { - Command command = registeredCommand.getCommand(); + CommandData command = registeredCommand.getCommand(); CommandResult result = registeredCommand.execute(sender, string); switch (result) { case PERMISSION_FAIL -> { - handleMessage(registeredCommand, sender, command.permissionMessage(), command.permissionMessageIsField()); + String message = command.getPermissionMessage(); + if (message != null) + sender.sendMessage(message); return; } case INVALID_SENDER -> { - handleMessage(registeredCommand, sender, command.invalidSenderMessage(), command.invalidSenderMessageIsField()); + String message = command.getInvalidSenderMessage(); + if (message != null) + sender.sendMessage(message); return; } @@ -87,40 +63,9 @@ public void execute(CommandSender sender, String string) { } } - protected void handleMessage(@NonNull RegisteredCommand registeredCommand, @NonNull CommandSender sender, @NonNull String message, boolean isField) { - if (!isField) { - if (!message.isEmpty()) - sender.sendMessage(message); - return; - } - - String fieldMessage = getFieldMessage(registeredCommand, message); - if (fieldMessage != null) - sender.sendMessage(fieldMessage); - } - - protected @Nullable String getFieldMessage(@NonNull RegisteredCommand registeredCommand, @NonNull String fieldName) { - Map fields = fieldCache.computeIfAbsent(registeredCommand.getObject().getClass(), clazz -> { - Map map = new HashMap<>(); - for (Field field : clazz.getDeclaredFields()) - map.put(field.getName(), field); - return map; - }); - - Field field = fields.get(fieldName); - if (field == null) - return null; - - Object fieldValue = ReflectionUtil.getFieldValue(field, registeredCommand.getObject()); - return fieldValue == null ? null : fieldValue.toString(); - } - @NonNull public List<@NonNull String> autoComplete(@NonNull CommandSender sender, @NonNull String string) { - List result = new ArrayList<>(); - for (RegisteredCommand command : commands) - result.addAll(command.autoComplete(sender, string)); - return result; + return List.of(); } public List getCommand(String name) { @@ -131,10 +76,10 @@ public List getCommand(String name) { return commands; } - public List getCommands(Object object) { + public List getCommands(@NotNull Object object) { List commands = new ArrayList<>(this.commands.size()); for (RegisteredCommand command : this.commands) - if (command.getObject() == object) + if (command.isOwnedBy(object)) commands.add(command); return commands; } diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/CommandSender.java b/commands/src/main/java/com/wizardlybump17/wlib/command/CommandSender.java index c4b89aa3..127a3037 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/CommandSender.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/CommandSender.java @@ -1,7 +1,5 @@ package com.wizardlybump17.wlib.command; -import org.jetbrains.annotations.Nullable; - /** * Represents a command sender, someone that can trigger commands. * @@ -21,14 +19,4 @@ public interface CommandSender { String getName(); boolean hasPermission(String permission); - - /** - * Used to convert this CommandSender to a generic sender, a command sender that can be anything - * - * @return the generic sender - */ - @Nullable - default CommandSender toGeneric() { - return null; - } } diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/RegisteredCommand.java b/commands/src/main/java/com/wizardlybump17/wlib/command/RegisteredCommand.java deleted file mode 100644 index 5ae2885e..00000000 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/RegisteredCommand.java +++ /dev/null @@ -1,275 +0,0 @@ -package com.wizardlybump17.wlib.command; - -import com.wizardlybump17.wlib.command.args.ArgsNode; -import com.wizardlybump17.wlib.command.args.ArgsReaderRegistry; -import com.wizardlybump17.wlib.command.args.ArgsReaderType; -import com.wizardlybump17.wlib.command.args.reader.ArgsReader; -import com.wizardlybump17.wlib.command.args.reader.ArgsReaderException; -import com.wizardlybump17.wlib.object.Pair; -import lombok.Getter; -import lombok.NonNull; -import org.jetbrains.annotations.NotNull; - -import java.lang.invoke.MethodHandle; -import java.lang.reflect.Method; -import java.lang.reflect.Parameter; -import java.util.*; - -@Getter -public class RegisteredCommand implements Comparable { - - private final Command command; - private final Object object; - private final Method method; - private final List nodes = new ArrayList<>(); - private final @NonNull MethodHandle methodHandle; - - public RegisteredCommand(Command command, Object object, Method method, @NonNull MethodHandle methodHandle) { - this.command = command; - this.object = object; - this.method = method; - this.methodHandle = methodHandle; - prepareNodes(); - } - - private void prepareNodes() { - String[] commandArgs = command.execution().split(" "); - - Class[] types = method.getParameterTypes(); - Parameter[] parameters = method.getParameters(); - int index = 1; //skipping the first type because of the CommandSender - for (String commandArg : commandArgs) { - if (!requiredArgs(commandArg)) { - nodes.add(new ArgsNode( - commandArg, - false, - null, - null, - false - )); - continue; - } - - Description description = parameters[index].getAnnotation(Description.class); - - ArgsReaderType argsReaderType = parameters[index].getAnnotation(ArgsReaderType.class); - if (argsReaderType == null && Argument.class.isAssignableFrom(types[index])) - throw new IllegalArgumentException("the \"" + commandArg + "\" argument requires the " + ArgsReaderType.class.getName() + " annotation"); - - ArgsReader reader; - if (argsReaderType == null) - reader = ArgsReaderRegistry.INSTANCE.getReader(types[index]); - else - reader = ArgsReaderRegistry.INSTANCE.get(argsReaderType.value()); - if (reader == null) - throw new IllegalArgumentException("no reader found for " + types[index].getName()); - - nodes.add(new ArgsNode( - trim(commandArg), - true, - reader, - description == null ? null : description.value(), - Argument.class.isAssignableFrom(types[index]) - )); - - index++; - } - } - - public String getName() { - return command.execution().split(" ")[0]; - } - - @Override - public int compareTo(@NotNull RegisteredCommand o) { - if (o.command.priority() == -1 && command.priority() == -1) { - int args = compareArgs(o); - - if (args == 0) - return compareSize(o); - - return args; - } - - return Integer.compare(o.command.priority(), command.priority()); - } - - private int compareArgs(RegisteredCommand other) { - return Integer.compare(other.command.execution().split(" ").length, command.execution().split(" ").length); - } - - private int compareSize(RegisteredCommand other) { - return Integer.compare(other.command.execution().length(), command.execution().length()); - } - - public Optional>> parse(String input, boolean autoComplete) throws ArgsReaderException { - List toParse = new ArrayList<>(); - checkArrays(input, toParse, autoComplete); - - List> result = new ArrayList<>(nodes.size()); - - if (parseRequiredOnly(result, toParse, autoComplete)) - return Optional.of(result); - - return Optional.empty(); - } - - private boolean parseRequiredOnly(List> target, List strings, boolean autoComplete) throws ArgsReaderException { - if (autoComplete && nodes.size() > strings.size()) - return false; - - for (int i = 0; i < nodes.size() && i < strings.size(); i++) { - ArgsNode node = nodes.get(i); - if (!node.isUserInput()) { - if (!node.getName().equalsIgnoreCase(strings.get(i))) - return false; - - continue; - } - - Object parse = node.parse(strings.get(i)); - if (parse == ArgsNode.EMPTY) - continue; - - target.add(new Pair<>(node, parse)); - } - - return true; - } - - private void checkArrays(String input, List target, boolean autoComplete) throws ArgsReaderException { - StringBuilder builder = new StringBuilder(); - boolean inArray = false; - for (String s : input.split(" ")) { - if (s.startsWith("\"") && s.endsWith("\"") && !s.endsWith("\\\"") && s.length() != 1) { //"string" | single word - target.add(s.substring(1, s.length() - 1)); - continue; - } - - if (s.startsWith("\"")) { //"string | it is starting the array - builder.append(s.substring(1).replace("\\\"", "\"")).append(" "); - inArray = true; - continue; - } - - if (s.endsWith("\"") && !s.endsWith("\\\"")) { //string" | it is ending the array - builder.append(s.replace("\\\"", "\""), 0, s.length() - 1); - target.add(builder.toString()); - builder = new StringBuilder(); - inArray = false; - continue; - } - - if (!builder.isEmpty()) { //string | it is in the array - builder.append(s.replace("\\\"", "\"")).append(" "); - continue; - } - - target.add(s.replace("\\\"", "\"")); //string | it is not in the array - } - - if (inArray && !autoComplete) - throw new ArgsReaderException("Invalid array"); - } - - public CommandResult execute(CommandSender sender, String string) { - try { - Optional>> parse = parse(string, true); - if (parse.isEmpty()) - return CommandResult.ARGS_FAIL; - - if (!getSenderType().isInstance(sender) && !isSenderGeneric()) - return CommandResult.INVALID_SENDER; - - Object[] objects = parse.get().stream().map(Pair::getSecond).toArray(); - return executeInternal(sender, objects); - } catch (ArgsReaderException e) { - return CommandResult.EXCEPTION; - } - } - - private CommandResult executeInternal(CommandSender sender, Object[] objects) { - try { - if (!command.permission().isEmpty() && !sender.hasPermission(command.permission())) - return CommandResult.PERMISSION_FAIL; - - List list = new ArrayList<>(Arrays.asList(objects)); - list.add(0, isSenderGeneric() ? sender.toGeneric() : sender); - - if (list.size() != method.getParameterCount()) - return CommandResult.ARGS_FAIL; - - list.add(0, object); - methodHandle.invokeWithArguments(list); - return CommandResult.SUCCESS; - } catch (Throwable e) { - e.printStackTrace(); - return CommandResult.METHOD_FAIL; - } - } - - @NonNull - public List<@NonNull String> autoComplete(@NonNull CommandSender sender, @NonNull String string) { - if (nodes.size() == 1) - return Collections.emptyList(); - - if (!getSenderType().isInstance(sender) && !isSenderGeneric()) - return Collections.emptyList(); - - try { - Optional>> parse = parse(string, false); - if (parse.isEmpty()) - return Collections.emptyList(); - - String[] split = string.split(" "); - String lastString = split[split.length - 1]; - - List> pairs = parse.get(); - - if (pairs.isEmpty()) { - ArgsNode secondNode = nodes.get(1); - ArgsReader secondNodeReader = secondNode.getReader(); - return secondNodeReader == null ? List.of(secondNode.getName()) : secondNodeReader.autoComplete(sender, lastString); - } - - Pair lastPair = pairs.get(pairs.size() - 1); - - ArgsNode node = lastPair.getFirst(); - ArgsReader reader = node.getReader(); - - return reader == null ? List.of(node.getName()) : reader.autoComplete(sender, lastString); - } catch (ArgsReaderException e) { - e.printStackTrace(); - return Collections.emptyList(); - } - } - - @Override - public String toString() { - return "RegisteredCommand{" + command.execution() + "}"; - } - - @SuppressWarnings("unchecked") - public Class> getSenderType() { - return (Class>) method.getParameterTypes()[0]; - } - - public boolean isSenderGeneric() { - boolean result = false; - try { - result = (Boolean) getSenderType().getDeclaredMethod("isGeneric").invoke(null); - } catch (NoSuchMethodException ignored) { - } catch (Exception e) { - e.printStackTrace(); - } - return result; - } - - private static String trim(String string) { - return string.substring(1, string.length() - 1); - } - - private static boolean requiredArgs(String string) { - return string.startsWith("<") && string.endsWith(">"); - } -} \ No newline at end of file diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/Command.java b/commands/src/main/java/com/wizardlybump17/wlib/command/annotation/Command.java similarity index 96% rename from commands/src/main/java/com/wizardlybump17/wlib/command/Command.java rename to commands/src/main/java/com/wizardlybump17/wlib/command/annotation/Command.java index ca53cf22..1009d78b 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/Command.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/annotation/Command.java @@ -1,4 +1,6 @@ -package com.wizardlybump17.wlib.command; +package com.wizardlybump17.wlib.command.annotation; + +import com.wizardlybump17.wlib.command.CommandSender; import java.lang.annotation.ElementType; import java.lang.annotation.Retention; diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/data/AnnotationCommandData.java b/commands/src/main/java/com/wizardlybump17/wlib/command/data/AnnotationCommandData.java new file mode 100644 index 00000000..b659ea2e --- /dev/null +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/data/AnnotationCommandData.java @@ -0,0 +1,96 @@ +package com.wizardlybump17.wlib.command.data; + +import com.wizardlybump17.wlib.command.annotation.Command; +import com.wizardlybump17.wlib.util.ReflectionUtil; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import java.lang.reflect.Field; +import java.util.HashMap; +import java.util.Map; +import java.util.Objects; + +public class AnnotationCommandData implements CommandData { + + private final @NotNull Command annotation; + private final @NotNull Object object; + private final @NotNull Map fieldCache = new HashMap<>(); + + public AnnotationCommandData(@NotNull Command annotation, @NotNull Object object) { + this.annotation = annotation; + this.object = object; + } + + @Override + public @NotNull String getExecution() { + return annotation.execution(); + } + + @Override + public @Nullable String getPermission() { + String permission = annotation.permission(); + return permission.isBlank() ? CommandData.super.getPermission() : permission; + } + + @Override + public @Nullable String getPermissionMessage() { + return getMessage(annotation.permissionMessage(), annotation.permissionMessageIsField(), CommandData.super.getPermissionMessage()); + } + + @Override + public int getPriority() { + int priority = annotation.priority(); + return priority == -1 ? CommandData.super.getPriority() : priority; + } + + @Override + public @Nullable String getDescription() { + String description = annotation.description(); + return description.isBlank() ? CommandData.super.getDescription() : description; + } + + @Override + public @Nullable String getInvalidSenderMessage() { + return getMessage(annotation.invalidSenderMessage(), annotation.invalidSenderMessageIsField(), CommandData.super.getInvalidSenderMessage()); + } + + protected @Nullable String getMessage(@NotNull String message, boolean isField, @Nullable String defaultMessage) { + if (isField) { + return ReflectionUtil.getFieldValue( + fieldCache.computeIfAbsent( + message, + $ -> ReflectionUtil.getField(message, object.getClass()) + ), + object + ); + } + return message.isBlank() ? defaultMessage : message; + } + + public @NotNull Command getAnnotation() { + return annotation; + } + + + @Override + public boolean equals(Object object1) { + if (object1 == null || getClass() != object1.getClass()) + return false; + AnnotationCommandData that = (AnnotationCommandData) object1; + return Objects.equals(annotation, that.annotation) && Objects.equals(object, that.object) && Objects.equals(fieldCache, that.fieldCache); + } + + @Override + public int hashCode() { + return Objects.hash(annotation, object, fieldCache); + } + + @Override + public String toString() { + return "AnnotationCommandData{" + + "annotation=" + annotation + + ", object=" + object + + ", fieldCache=" + fieldCache + + '}'; + } +} diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/data/CommandData.java b/commands/src/main/java/com/wizardlybump17/wlib/command/data/CommandData.java new file mode 100644 index 00000000..9c077a5d --- /dev/null +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/data/CommandData.java @@ -0,0 +1,66 @@ +package com.wizardlybump17.wlib.command.data; + +import com.wizardlybump17.wlib.command.CommandSender; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +public interface CommandData { + + /** + *

How the sender must type the command in order for it to be triggered. + * Example:

command hello world
+ * In the example above, the sender must type /command hello world, so it can be triggered. + * To add parameters that depends on the sender input, just put the parameter between <>. + *
+ * Example:
command <hello> world

+ *

The type of each parameter is defined in the method that have this annotation. + * An example for the command above: + *

+     *  @Command(execution = "command <hello> world")
+     *  public void commandHelloWorld(GenericSender sender, String hello) {
+     *      System.out.println(sender.getName() + " executed the hello world command with the argument " + hello);
+     *  }
+     * 

+ * + * @return how the command must be sent to be triggered + * @see com.wizardlybump17.wlib.command.args.reader.ArgsReader + */ + @NotNull String getExecution(); + + /** + * @return which permission the sender must have to trigger this command + */ + default @Nullable String getPermission() { + return null; + } + + /** + *

Used when the {@link CommandSender} does not have the required {@link #getPermission()}.

+ * @return the message to be sent when the {@link CommandSender} does not have the required {@link #getPermission()} + */ + default @Nullable String getPermissionMessage() { + return null; + } + + /** + * @return the priority of this command + */ + default int getPriority() { + return getExecution().split(" ").length; + } + + /** + * @return the description of this command + */ + default @Nullable String getDescription() { + return null; + } + + /** + *

Used when the {@link CommandSender} is not valid for this command.

+ * @return the message to be sent when the {@link CommandSender} is not valid for this command + */ + default @Nullable String getInvalidSenderMessage() { + return null; + } +} diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/exception/CommandException.java b/commands/src/main/java/com/wizardlybump17/wlib/command/exception/CommandException.java new file mode 100644 index 00000000..7c99b73f --- /dev/null +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/exception/CommandException.java @@ -0,0 +1,21 @@ +package com.wizardlybump17.wlib.command.exception; + +import org.jetbrains.annotations.NotNull; + +public class CommandException extends Exception { + + public CommandException() { + } + + public CommandException(@NotNull String message) { + super(message); + } + + public CommandException(@NotNull String message, @NotNull Throwable cause) { + super(message, cause); + } + + public CommandException(@NotNull Throwable cause) { + super(cause); + } +} diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/executor/CommandExecutor.java b/commands/src/main/java/com/wizardlybump17/wlib/command/executor/CommandExecutor.java new file mode 100644 index 00000000..298f73b7 --- /dev/null +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/executor/CommandExecutor.java @@ -0,0 +1,12 @@ +package com.wizardlybump17.wlib.command.executor; + +import com.wizardlybump17.wlib.command.CommandSender; +import com.wizardlybump17.wlib.command.exception.CommandException; +import org.jetbrains.annotations.NotNull; + +import java.util.Map; + +public interface CommandExecutor { + + void execute(@NotNull CommandSender sender, @NotNull Map args) throws CommandException; +} diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/extractor/CommandExtractor.java b/commands/src/main/java/com/wizardlybump17/wlib/command/extractor/CommandExtractor.java new file mode 100644 index 00000000..8f1d4373 --- /dev/null +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/extractor/CommandExtractor.java @@ -0,0 +1,13 @@ +package com.wizardlybump17.wlib.command.extractor; + +import com.wizardlybump17.wlib.command.CommandManager; +import com.wizardlybump17.wlib.command.holder.CommandHolder; +import com.wizardlybump17.wlib.command.registered.RegisteredCommand; +import org.jetbrains.annotations.NotNull; + +import java.util.List; + +public interface CommandExtractor { + + @NotNull List extract(@NotNull CommandManager manager, @NotNull CommandHolder holder, @NotNull Object object); +} diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/extractor/DirectCommandExtractor.java b/commands/src/main/java/com/wizardlybump17/wlib/command/extractor/DirectCommandExtractor.java new file mode 100644 index 00000000..bb21f6c5 --- /dev/null +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/extractor/DirectCommandExtractor.java @@ -0,0 +1,16 @@ +package com.wizardlybump17.wlib.command.extractor; + +import com.wizardlybump17.wlib.command.CommandManager; +import com.wizardlybump17.wlib.command.holder.CommandHolder; +import com.wizardlybump17.wlib.command.registered.RegisteredCommand; +import org.jetbrains.annotations.NotNull; + +import java.util.List; + +public class DirectCommandExtractor implements CommandExtractor { + + @Override + public @NotNull List extract(@NotNull CommandManager manager, @NotNull CommandHolder holder, @NotNull Object object) { + return object instanceof RegisteredCommand command ? List.of(command) : List.of(); + } +} diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/extractor/MethodCommandExtractor.java b/commands/src/main/java/com/wizardlybump17/wlib/command/extractor/MethodCommandExtractor.java new file mode 100644 index 00000000..3e650e68 --- /dev/null +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/extractor/MethodCommandExtractor.java @@ -0,0 +1,44 @@ +package com.wizardlybump17.wlib.command.extractor; + +import com.wizardlybump17.wlib.command.CommandManager; +import com.wizardlybump17.wlib.command.CommandSender; +import com.wizardlybump17.wlib.command.annotation.Command; +import com.wizardlybump17.wlib.command.holder.CommandHolder; +import com.wizardlybump17.wlib.command.registered.RegisteredCommand; +import com.wizardlybump17.wlib.command.registered.RegisteredMethodCommand; +import org.jetbrains.annotations.NotNull; + +import java.lang.reflect.Method; +import java.util.ArrayList; +import java.util.List; +import java.util.logging.Level; + +public class MethodCommandExtractor implements CommandExtractor { + + @Override + public @NotNull List extract(@NotNull CommandManager manager, @NotNull CommandHolder holder, @NotNull Object object) { + List commands = new ArrayList<>(); + for (Method method : object.getClass().getDeclaredMethods()) { + if (!method.isAnnotationPresent(Command.class) || method.getParameterCount() == 0 || !CommandSender.class.isAssignableFrom(method.getParameterTypes()[0])) + continue; + + RegisteredMethodCommand command; + try { + command = new RegisteredMethodCommand( + method.getAnnotation(Command.class), + object, + method + ); + } catch (Exception e) { + holder.getLogger().log(Level.SEVERE, "Error while creating a command", e); + continue; + } + + commands.add(command); + com.wizardlybump17.wlib.command.holder.Command holderCommand = holder.getCommand(command.getName()); + if (holderCommand != null) + holderCommand.setExecutor(holderCommand.getDefaultExecutor(manager, command.getName())); + } + return commands; + } +} diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/holder/CommandExecutor.java b/commands/src/main/java/com/wizardlybump17/wlib/command/holder/CommandExecutor.java index de8e1475..24bf890b 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/holder/CommandExecutor.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/holder/CommandExecutor.java @@ -2,11 +2,12 @@ import com.wizardlybump17.wlib.command.CommandSender; import com.wizardlybump17.wlib.command.args.reader.ArgsReaderException; +import com.wizardlybump17.wlib.command.exception.CommandException; /** * Interface for intercepting commands when they are called */ public interface CommandExecutor { - void execute(CommandSender sender, String commandName, String[] args) throws ArgsReaderException; + void execute(CommandSender sender, String commandName, String[] args) throws ArgsReaderException, CommandException; } diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/registered/RegisteredCommand.java b/commands/src/main/java/com/wizardlybump17/wlib/command/registered/RegisteredCommand.java new file mode 100644 index 00000000..3106237f --- /dev/null +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/registered/RegisteredCommand.java @@ -0,0 +1,131 @@ +package com.wizardlybump17.wlib.command.registered; + +import com.wizardlybump17.wlib.command.CommandResult; +import com.wizardlybump17.wlib.command.CommandSender; +import com.wizardlybump17.wlib.command.args.ArgsNode; +import com.wizardlybump17.wlib.command.args.reader.ArgsReaderException; +import com.wizardlybump17.wlib.command.data.CommandData; +import com.wizardlybump17.wlib.command.exception.CommandException; +import com.wizardlybump17.wlib.command.executor.CommandExecutor; +import com.wizardlybump17.wlib.util.StringUtil; +import org.jetbrains.annotations.NotNull; + +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Optional; + +public class RegisteredCommand implements Comparable { + + private final @NotNull CommandData command; + private final @NotNull List nodes; + private final @NotNull CommandExecutor executor; + + public RegisteredCommand(@NotNull CommandData command, @NotNull List nodes, @NotNull CommandExecutor executor) { + this.command = command; + this.nodes = nodes; + this.executor = executor; + } + + public RegisteredCommand(@NotNull CommandData command, @NotNull List nodes) { + this.command = command; + this.nodes = nodes; + executor = createExecutor(); + } + + protected CommandExecutor createExecutor() { + throw new UnsupportedOperationException(); + } + + public String getName() { + return command.getExecution().split(" ")[0]; + } + + @Override + public int compareTo(@NotNull RegisteredCommand o) { + return Integer.compare(o.command.getPriority(), command.getPriority()); + } + + public Optional> parse(String input) throws ArgsReaderException { + List toParse = StringUtil.parseQuotedStrings(input); + + LinkedHashMap result = new LinkedHashMap<>(); + + if (checkNodes(result, toParse)) + return Optional.of(result); + + return Optional.empty(); + } + + protected boolean checkNodes(LinkedHashMap target, List strings) throws ArgsReaderException { + if (nodes.size() > strings.size()) + return false; + + for (int i = 0; i < nodes.size() && i < strings.size(); i++) { + ArgsNode node = nodes.get(i); + if (!node.isUserInput()) { + if (node.getName().equalsIgnoreCase(strings.get(i))) + continue; + return false; + } + + Object parse = node.parse(strings.get(i)); + if (parse != ArgsNode.EMPTY) + target.put(node.getName(), parse); + } + + return true; + } + + public @NotNull CommandResult execute(@NotNull CommandSender sender, @NotNull String string) throws CommandException { + if (!canExecute(sender)) + return CommandResult.INVALID_SENDER; + + String permission = command.getPermission(); + if (permission != null && !sender.hasPermission(permission)) + return CommandResult.PERMISSION_FAIL; + + try { + Optional> parse = parse(string); + if (parse.isEmpty()) + return CommandResult.ARGS_FAIL; + + LinkedHashMap args = parse.get(); + if (!isValidArgs(args)) + return CommandResult.ARGS_FAIL; + + executor.execute(sender, args); + return CommandResult.SUCCESS; + } catch (ArgsReaderException e) { + return CommandResult.EXCEPTION; + } + } + + protected boolean isValidArgs(@NotNull LinkedHashMap args) { + return true; + } + + public boolean canExecute(@NotNull CommandSender sender) { + return true; + } + + @Override + public String toString() { + return "RegisteredCommand{" + command.getExecution() + "}"; + } + + public @NotNull CommandData getCommand() { + return command; + } + + public @NotNull CommandExecutor getExecutor() { + return executor; + } + + public @NotNull List getNodes() { + return nodes; + } + + public boolean isOwnedBy(@NotNull Object object) { + return false; + } +} \ No newline at end of file diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/registered/RegisteredMethodCommand.java b/commands/src/main/java/com/wizardlybump17/wlib/command/registered/RegisteredMethodCommand.java new file mode 100644 index 00000000..afa08270 --- /dev/null +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/registered/RegisteredMethodCommand.java @@ -0,0 +1,122 @@ +package com.wizardlybump17.wlib.command.registered; + +import com.wizardlybump17.wlib.command.Argument; +import com.wizardlybump17.wlib.command.Description; +import com.wizardlybump17.wlib.command.annotation.Command; +import com.wizardlybump17.wlib.command.args.ArgsNode; +import com.wizardlybump17.wlib.command.args.ArgsReaderRegistry; +import com.wizardlybump17.wlib.command.args.ArgsReaderType; +import com.wizardlybump17.wlib.command.args.reader.ArgsReader; +import com.wizardlybump17.wlib.command.data.AnnotationCommandData; +import com.wizardlybump17.wlib.command.exception.CommandException; +import com.wizardlybump17.wlib.command.executor.CommandExecutor; +import lombok.Getter; +import org.jetbrains.annotations.NotNull; + +import java.lang.invoke.MethodHandle; +import java.lang.invoke.MethodHandles; +import java.lang.invoke.MethodType; +import java.lang.reflect.Method; +import java.lang.reflect.Parameter; +import java.util.ArrayList; +import java.util.LinkedHashMap; +import java.util.List; + +@Getter +public class RegisteredMethodCommand extends RegisteredCommand { + + private final @NotNull Command annotation; + private final @NotNull Object object; + private final @NotNull Method method; + private final @NotNull MethodHandle methodHandle; + + public RegisteredMethodCommand(@NotNull Command annotation, @NotNull Object object, @NotNull Method method) throws NoSuchMethodException, IllegalAccessException { + super( + new AnnotationCommandData( + annotation, + object + ), + new ArrayList<>() + ); + this.annotation = annotation; + this.object = object; + this.method = method; + methodHandle = MethodHandles.lookup().findVirtual(object.getClass(), method.getName(), MethodType.methodType(method.getReturnType(), method.getParameterTypes())); + prepareNodes(); + } + + @Override + protected CommandExecutor createExecutor() { + return (sender, args) -> { + List objects = new ArrayList<>(args.values()); + objects.add(0, sender); + try { + methodHandle.invokeWithArguments(objects); + } catch (Throwable e) { + throw new CommandException("Error while executing the command " + getCommand().getExecution() + " with the arguments " + args, e); + } + }; + } + + protected void prepareNodes() { + String[] commandArgs = getCommand().getExecution().split(" "); + + Class[] types = method.getParameterTypes(); + Parameter[] parameters = method.getParameters(); + int index = 1; //skipping the first type because of the CommandSender + for (String commandArg : commandArgs) { + if (!isRequiredArgs(commandArg)) { + getNodes().add(new ArgsNode( + commandArg, + false, + null, + null, + false + )); + continue; + } + + Description description = parameters[index].getAnnotation(Description.class); + + ArgsReaderType argsReaderType = parameters[index].getAnnotation(ArgsReaderType.class); + if (argsReaderType == null && Argument.class.isAssignableFrom(types[index])) + throw new IllegalArgumentException("the \"" + commandArg + "\" argument requires the " + ArgsReaderType.class.getName() + " annotation"); + + ArgsReader reader; + if (argsReaderType == null) + reader = ArgsReaderRegistry.INSTANCE.getReader(types[index]); + else + reader = ArgsReaderRegistry.INSTANCE.get(argsReaderType.value()); + if (reader == null) + throw new IllegalArgumentException("no reader found for " + types[index].getName()); + + getNodes().add(new ArgsNode( + trim(commandArg), + true, + reader, + description == null ? null : description.value(), + Argument.class.isAssignableFrom(types[index]) + )); + + index++; + } + } + + @Override + protected boolean isValidArgs(@NotNull LinkedHashMap args) { + return args.size() + 1 == method.getParameterCount(); + } + + @Override + public boolean isOwnedBy(@NotNull Object object) { + return this.object == object; + } + + private static String trim(String string) { + return string.substring(1, string.length() - 1); + } + + private static boolean isRequiredArgs(String string) { + return string.startsWith("<") && string.endsWith(">"); + } +} \ No newline at end of file diff --git a/core/src/main/java/com/wizardlybump17/wlib/command/BukkitCommandExecutor.java b/core/src/main/java/com/wizardlybump17/wlib/command/BukkitCommandExecutor.java index c5577b03..c17fb0b0 100644 --- a/core/src/main/java/com/wizardlybump17/wlib/command/BukkitCommandExecutor.java +++ b/core/src/main/java/com/wizardlybump17/wlib/command/BukkitCommandExecutor.java @@ -1,54 +1,39 @@ package com.wizardlybump17.wlib.command; -import com.wizardlybump17.wlib.command.sender.ConsoleSender; -import com.wizardlybump17.wlib.command.sender.GenericSender; -import com.wizardlybump17.wlib.command.sender.PlayerSender; +import com.wizardlybump17.wlib.command.exception.CommandException; import lombok.RequiredArgsConstructor; -import lombok.SneakyThrows; import org.bukkit.command.Command; -import org.bukkit.command.CommandSender; -import org.bukkit.command.*; -import org.bukkit.entity.Player; +import org.bukkit.command.TabExecutor; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import java.util.List; +import java.util.logging.Level; @RequiredArgsConstructor public class BukkitCommandExecutor implements TabExecutor, com.wizardlybump17.wlib.command.holder.CommandExecutor { private final CommandManager manager; - @SneakyThrows @Override - public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, String[] args) { - execute(getSender(sender), command.getName(), args); + public boolean onCommand(@NotNull org.bukkit.command.CommandSender sender, @NotNull Command command, @NotNull String label, String[] args) { + try { + execute(new com.wizardlybump17.wlib.command.sender.CommandSender(sender), command.getName(), args); + } catch (CommandException e) { + manager.getHolder().getLogger().log(Level.SEVERE, "Error while executing a command", e); + } return false; } @Override - public void execute(com.wizardlybump17.wlib.command.CommandSender sender, String commandName, String[] args) { + public void execute(com.wizardlybump17.wlib.command.CommandSender sender, String commandName, String[] args) throws CommandException { String commandExecution = commandName + " " + String.join(" ", args); manager.execute(sender, commandExecution); } @Nullable @Override - public List onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) { -// String fullCommand = command.getName() + " " + String.join(" ", args); -// List suggestions = manager.autoComplete(getSender(sender), fullCommand); -// ArrayList strings = StringUtil.copyPartialMatches(args[args.length - 1], suggestions, new ArrayList<>(suggestions.size())); -// return strings; + public List onTabComplete(@NotNull org.bukkit.command.CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) { return null; } - - private com.wizardlybump17.wlib.command.CommandSender getSender(CommandSender original) { - if (original instanceof Player player) - return new PlayerSender(player); - if (original instanceof ConsoleCommandSender consoleSender) - return new ConsoleSender(consoleSender); - if (original instanceof BlockCommandSender blockSender) - return new com.wizardlybump17.wlib.command.sender.BlockCommandSender(blockSender); - return new GenericSender(original); - } } diff --git a/core/src/main/java/com/wizardlybump17/wlib/command/sender/AbstractSender.java b/core/src/main/java/com/wizardlybump17/wlib/command/sender/AbstractSender.java deleted file mode 100644 index 98af7103..00000000 --- a/core/src/main/java/com/wizardlybump17/wlib/command/sender/AbstractSender.java +++ /dev/null @@ -1,39 +0,0 @@ -package com.wizardlybump17.wlib.command.sender; - -import com.wizardlybump17.wlib.command.CommandSender; -import lombok.Getter; -import lombok.NonNull; -import lombok.RequiredArgsConstructor; - -@RequiredArgsConstructor -@Getter -public abstract class AbstractSender implements CommandSender { - - private final S handle; - - @Override - public void sendMessage(String message) { - handle.sendMessage(message); - } - - @Override - public void sendMessage(String... message) { - handle.sendMessage(String.join("\n", message)); - } - - @Override - public String getName() { - return handle.getName(); - } - - @Override - public boolean hasPermission(String permission) { - return handle.hasPermission(permission); - } - - @Override - @NonNull - public GenericSender toGeneric() { - return new GenericSender(handle); - } -} diff --git a/core/src/main/java/com/wizardlybump17/wlib/command/sender/BlockCommandSender.java b/core/src/main/java/com/wizardlybump17/wlib/command/sender/BlockCommandSender.java deleted file mode 100644 index 2f3b8455..00000000 --- a/core/src/main/java/com/wizardlybump17/wlib/command/sender/BlockCommandSender.java +++ /dev/null @@ -1,8 +0,0 @@ -package com.wizardlybump17.wlib.command.sender; - -public class BlockCommandSender extends AbstractSender { - - public BlockCommandSender(org.bukkit.command.BlockCommandSender handle) { - super(handle); - } -} diff --git a/core/src/main/java/com/wizardlybump17/wlib/command/sender/CommandSender.java b/core/src/main/java/com/wizardlybump17/wlib/command/sender/CommandSender.java new file mode 100644 index 00000000..db06a313 --- /dev/null +++ b/core/src/main/java/com/wizardlybump17/wlib/command/sender/CommandSender.java @@ -0,0 +1,52 @@ +package com.wizardlybump17.wlib.command.sender; + +import org.bukkit.command.BlockCommandSender; +import org.bukkit.command.ConsoleCommandSender; +import org.bukkit.entity.Player; +import org.jetbrains.annotations.NotNull; + +public class CommandSender implements com.wizardlybump17.wlib.command.CommandSender { + + private final @NotNull org.bukkit.command.CommandSender handle; + + public CommandSender(@NotNull org.bukkit.command.CommandSender handle) { + this.handle = handle; + } + + @Override + public org.bukkit.command.CommandSender getHandle() { + return handle; + } + + @Override + public void sendMessage(String message) { + handle.sendMessage(message); + } + + @Override + public void sendMessage(String... message) { + handle.sendMessage(String.join("\n", message)); + } + + @Override + public String getName() { + return handle.getName(); + } + + @Override + public boolean hasPermission(String permission) { + return handle.hasPermission(permission); + } + + public @NotNull BlockCommandSender asBlockCommand() { + return (BlockCommandSender) handle; + } + + public @NotNull ConsoleCommandSender asConsole() { + return (ConsoleCommandSender) handle; + } + + public @NotNull Player asPlayer() { + return (Player) handle; + } +} diff --git a/core/src/main/java/com/wizardlybump17/wlib/command/sender/ConsoleSender.java b/core/src/main/java/com/wizardlybump17/wlib/command/sender/ConsoleSender.java deleted file mode 100644 index 46e55e01..00000000 --- a/core/src/main/java/com/wizardlybump17/wlib/command/sender/ConsoleSender.java +++ /dev/null @@ -1,10 +0,0 @@ -package com.wizardlybump17.wlib.command.sender; - -import org.bukkit.command.ConsoleCommandSender; - -public class ConsoleSender extends AbstractSender { - - public ConsoleSender(ConsoleCommandSender handle) { - super(handle); - } -} diff --git a/core/src/main/java/com/wizardlybump17/wlib/command/sender/GenericSender.java b/core/src/main/java/com/wizardlybump17/wlib/command/sender/GenericSender.java deleted file mode 100644 index d223526d..00000000 --- a/core/src/main/java/com/wizardlybump17/wlib/command/sender/GenericSender.java +++ /dev/null @@ -1,21 +0,0 @@ -package com.wizardlybump17.wlib.command.sender; - -import lombok.NonNull; -import org.bukkit.command.CommandSender; - -public class GenericSender extends AbstractSender { - - public GenericSender(CommandSender handle) { - super(handle); - } - - @Override - @NonNull - public GenericSender toGeneric() { - return this; - } - - public static boolean isGeneric() { - return true; - } -} diff --git a/core/src/main/java/com/wizardlybump17/wlib/command/sender/PlayerSender.java b/core/src/main/java/com/wizardlybump17/wlib/command/sender/PlayerSender.java deleted file mode 100644 index ac2f08eb..00000000 --- a/core/src/main/java/com/wizardlybump17/wlib/command/sender/PlayerSender.java +++ /dev/null @@ -1,10 +0,0 @@ -package com.wizardlybump17.wlib.command.sender; - -import org.bukkit.entity.Player; - -public class PlayerSender extends AbstractSender { - - public PlayerSender(Player handle) { - super(handle); - } -} From b0181a6880d63241918a8ce63cac9cd53efb7a41 Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Tue, 12 Nov 2024 23:48:58 -0300 Subject: [PATCH 21/73] registering the command extractors --- .../wizardlybump17/wlib/command/CommandManager.java | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/CommandManager.java b/commands/src/main/java/com/wizardlybump17/wlib/command/CommandManager.java index 957ee572..6f8509a9 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/CommandManager.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/CommandManager.java @@ -3,18 +3,18 @@ import com.wizardlybump17.wlib.command.data.CommandData; import com.wizardlybump17.wlib.command.exception.CommandException; import com.wizardlybump17.wlib.command.extractor.CommandExtractor; +import com.wizardlybump17.wlib.command.extractor.DirectCommandExtractor; +import com.wizardlybump17.wlib.command.extractor.MethodCommandExtractor; import com.wizardlybump17.wlib.command.holder.CommandHolder; import com.wizardlybump17.wlib.command.registered.RegisteredCommand; import lombok.Getter; import lombok.NonNull; -import lombok.RequiredArgsConstructor; import org.jetbrains.annotations.NotNull; import java.lang.reflect.Field; import java.util.*; @Getter -@RequiredArgsConstructor public class CommandManager { private final List commands = new ArrayList<>(); @@ -22,6 +22,12 @@ public class CommandManager { private final @NonNull Map, Map> fieldCache = new HashMap<>(); private final @NotNull Set commandExtractors = new HashSet<>(); + public CommandManager(@NotNull CommandHolder holder) { + this.holder = holder; + commandExtractors.add(new MethodCommandExtractor()); + commandExtractors.add(new DirectCommandExtractor()); + } + public void registerCommands(Object... objects) { for (Object object : objects) for (CommandExtractor extractor : commandExtractors) From 45288435cb5a3e98acc4e862eae635e987f573b4 Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Tue, 12 Nov 2024 23:49:07 -0300 Subject: [PATCH 22/73] fixed the arguments list --- .../wlib/command/registered/RegisteredMethodCommand.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/registered/RegisteredMethodCommand.java b/commands/src/main/java/com/wizardlybump17/wlib/command/registered/RegisteredMethodCommand.java index afa08270..5641650b 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/registered/RegisteredMethodCommand.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/registered/RegisteredMethodCommand.java @@ -49,7 +49,8 @@ public RegisteredMethodCommand(@NotNull Command annotation, @NotNull Object obje protected CommandExecutor createExecutor() { return (sender, args) -> { List objects = new ArrayList<>(args.values()); - objects.add(0, sender); + objects.add(0, object); + objects.add(1, sender); try { methodHandle.invokeWithArguments(objects); } catch (Throwable e) { From 272137f2284e8876a953bf6f09a2992e38075159 Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Wed, 13 Nov 2024 16:46:56 -0300 Subject: [PATCH 23/73] weakened the constructor's visibility --- .../wlib/command/registered/RegisteredCommand.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/registered/RegisteredCommand.java b/commands/src/main/java/com/wizardlybump17/wlib/command/registered/RegisteredCommand.java index 3106237f..d204d162 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/registered/RegisteredCommand.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/registered/RegisteredCommand.java @@ -26,7 +26,7 @@ public RegisteredCommand(@NotNull CommandData command, @NotNull List n this.executor = executor; } - public RegisteredCommand(@NotNull CommandData command, @NotNull List nodes) { + protected RegisteredCommand(@NotNull CommandData command, @NotNull List nodes) { this.command = command; this.nodes = nodes; executor = createExecutor(); From e22e0131bc546f478a6f5d75b17a4ad8650aa0e4 Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Wed, 13 Nov 2024 17:06:36 -0300 Subject: [PATCH 24/73] added the CommandManager#registerCommands(Collection) method --- .../java/com/wizardlybump17/wlib/command/CommandManager.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/CommandManager.java b/commands/src/main/java/com/wizardlybump17/wlib/command/CommandManager.java index 6f8509a9..feb35181 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/CommandManager.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/CommandManager.java @@ -35,6 +35,11 @@ public void registerCommands(Object... objects) { commands.sort(null); } + public void registerCommands(@NotNull Collection commands) { + this.commands.addAll(commands); + this.commands.sort(null); + } + public void unregisterCommands() { commands.clear(); } From f58b63cf8bcd39f2a32c3277179b8efa841d1749 Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Wed, 13 Nov 2024 17:34:01 -0300 Subject: [PATCH 25/73] added the CommandData#getName() method --- .../com/wizardlybump17/wlib/command/data/CommandData.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/data/CommandData.java b/commands/src/main/java/com/wizardlybump17/wlib/command/data/CommandData.java index 9c077a5d..bf0c98e2 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/data/CommandData.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/data/CommandData.java @@ -63,4 +63,8 @@ default int getPriority() { default @Nullable String getInvalidSenderMessage() { return null; } + + default @NotNull String getName() { + return getExecution().split(" ")[0]; + } } From 8046e8f79d193e95bf9ff1ba9f973f2366a4a443 Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Wed, 13 Nov 2024 17:34:29 -0300 Subject: [PATCH 26/73] added the RegisteredCommand#onRegister(CommandManager) method --- .../wizardlybump17/wlib/command/CommandManager.java | 11 ++++++++--- .../wlib/command/registered/RegisteredCommand.java | 4 ++++ 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/CommandManager.java b/commands/src/main/java/com/wizardlybump17/wlib/command/CommandManager.java index feb35181..6c4146f7 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/CommandManager.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/CommandManager.java @@ -29,13 +29,18 @@ public CommandManager(@NotNull CommandHolder holder) { } public void registerCommands(Object... objects) { - for (Object object : objects) - for (CommandExtractor extractor : commandExtractors) - commands.addAll(extractor.extract(this, holder, object)); + for (Object object : objects) { + for (CommandExtractor extractor : commandExtractors) { + List commands = extractor.extract(this, holder, object); + commands.forEach(command -> command.onRegister(this)); + this.commands.addAll(commands); + } + } commands.sort(null); } public void registerCommands(@NotNull Collection commands) { + commands.forEach(command -> command.onRegister(this)); this.commands.addAll(commands); this.commands.sort(null); } diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/registered/RegisteredCommand.java b/commands/src/main/java/com/wizardlybump17/wlib/command/registered/RegisteredCommand.java index d204d162..26e7d3f7 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/registered/RegisteredCommand.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/registered/RegisteredCommand.java @@ -1,5 +1,6 @@ package com.wizardlybump17.wlib.command.registered; +import com.wizardlybump17.wlib.command.CommandManager; import com.wizardlybump17.wlib.command.CommandResult; import com.wizardlybump17.wlib.command.CommandSender; import com.wizardlybump17.wlib.command.args.ArgsNode; @@ -128,4 +129,7 @@ public String toString() { public boolean isOwnedBy(@NotNull Object object) { return false; } + + public void onRegister(@NotNull CommandManager manager) { + } } \ No newline at end of file From 3f0866b5b5f2481b3714bf3a5937038ae7a2a789 Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Wed, 13 Nov 2024 17:34:39 -0300 Subject: [PATCH 27/73] added the RegisteredPluginCommand class --- .../registered/RegisteredPluginCommand.java | 44 +++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 core/src/main/java/com/wizardlybump17/wlib/command/registered/RegisteredPluginCommand.java diff --git a/core/src/main/java/com/wizardlybump17/wlib/command/registered/RegisteredPluginCommand.java b/core/src/main/java/com/wizardlybump17/wlib/command/registered/RegisteredPluginCommand.java new file mode 100644 index 00000000..f1a6fd8e --- /dev/null +++ b/core/src/main/java/com/wizardlybump17/wlib/command/registered/RegisteredPluginCommand.java @@ -0,0 +1,44 @@ +package com.wizardlybump17.wlib.command.registered; + +import com.wizardlybump17.wlib.command.CommandManager; +import com.wizardlybump17.wlib.command.args.ArgsNode; +import com.wizardlybump17.wlib.command.data.CommandData; +import com.wizardlybump17.wlib.command.exception.CommandException; +import com.wizardlybump17.wlib.command.executor.CommandExecutor; +import org.bukkit.command.Command; +import org.bukkit.command.CommandMap; +import org.bukkit.command.CommandSender; +import org.jetbrains.annotations.NotNull; + +import java.util.List; +import java.util.logging.Level; + +public class RegisteredPluginCommand extends RegisteredCommand { + + private final @NotNull String fallback; + + public RegisteredPluginCommand(@NotNull CommandData command, @NotNull List nodes, @NotNull CommandExecutor executor, @NotNull String fallback) { + super(command, nodes, executor); + this.fallback = fallback; + } + + public @NotNull String getFallback() { + return fallback; + } + + @Override + public void onRegister(@NotNull CommandManager manager) { + CommandMap commandMap = null; + commandMap.register(getCommand().getName(), fallback, new Command(getCommand().getName()) { + @Override + public boolean execute(@NotNull CommandSender sender, @NotNull String label, @NotNull String[] args) { + try { + RegisteredPluginCommand.this.execute(new com.wizardlybump17.wlib.command.sender.CommandSender(sender), String.join(" ", args)); + } catch (CommandException e) { + manager.getHolder().getLogger().log(Level.SEVERE, "Error while executing a command.", e); + } + return false; + } + }); + } +} From 5b24ac621fab46bcba79c9008bdf5ffee2f390d3 Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Wed, 13 Nov 2024 22:00:16 -0300 Subject: [PATCH 28/73] added the CommandMapAdapter system --- .../adapter/command/CommandMapAdapter.java | 28 ++++++++++++++++ .../v1_16_R3/command/CommandMapAdapter.java | 33 +++++++++++++++++++ 2 files changed, 61 insertions(+) create mode 100644 versions/adapter/src/main/java/com/wizardlybump17/wlib/adapter/command/CommandMapAdapter.java create mode 100644 versions/v1_16_R3/src/main/java/com/wizardlybump17/wlib/adapter/v1_16_R3/command/CommandMapAdapter.java diff --git a/versions/adapter/src/main/java/com/wizardlybump17/wlib/adapter/command/CommandMapAdapter.java b/versions/adapter/src/main/java/com/wizardlybump17/wlib/adapter/command/CommandMapAdapter.java new file mode 100644 index 00000000..14a001ae --- /dev/null +++ b/versions/adapter/src/main/java/com/wizardlybump17/wlib/adapter/command/CommandMapAdapter.java @@ -0,0 +1,28 @@ +package com.wizardlybump17.wlib.adapter.command; + +import org.bukkit.command.Command; +import org.bukkit.command.CommandMap; +import org.jetbrains.annotations.NotNull; + +import java.util.Map; + +public abstract class CommandMapAdapter { + + private static CommandMapAdapter instance; + + public abstract @NotNull CommandMap getCommandMap(); + + public abstract void unregisterCommand(@NotNull String command); + + public abstract @NotNull Map getCommands(); + + public static CommandMapAdapter getInstance() { + return instance; + } + + public static void setInstance(@NotNull CommandMapAdapter instance) { + if (CommandMapAdapter.instance != null) + throw new IllegalStateException("The CommandAdapter instance is already set."); + CommandMapAdapter.instance = instance; + } +} diff --git a/versions/v1_16_R3/src/main/java/com/wizardlybump17/wlib/adapter/v1_16_R3/command/CommandMapAdapter.java b/versions/v1_16_R3/src/main/java/com/wizardlybump17/wlib/adapter/v1_16_R3/command/CommandMapAdapter.java new file mode 100644 index 00000000..b9e7ea3f --- /dev/null +++ b/versions/v1_16_R3/src/main/java/com/wizardlybump17/wlib/adapter/v1_16_R3/command/CommandMapAdapter.java @@ -0,0 +1,33 @@ +package com.wizardlybump17.wlib.adapter.v1_16_R3.command; + +import com.wizardlybump17.wlib.util.ReflectionUtil; +import org.bukkit.Bukkit; +import org.bukkit.command.Command; +import org.bukkit.command.CommandMap; +import org.bukkit.command.SimpleCommandMap; +import org.jetbrains.annotations.NotNull; + +import java.util.Map; + +public class CommandMapAdapter extends com.wizardlybump17.wlib.adapter.command.CommandMapAdapter { + + public static final @NotNull CommandMap COMMAND_MAP = ReflectionUtil.getFieldValue(ReflectionUtil.getField("commandMap", Bukkit.getServer().getClass()), Bukkit.getServer()); + public static final @NotNull Map COMMANDS = ReflectionUtil.getFieldValue(ReflectionUtil.getField("knownCommands", SimpleCommandMap.class), COMMAND_MAP); + + @Override + public @NotNull CommandMap getCommandMap() { + return COMMAND_MAP; + } + + @Override + public void unregisterCommand(@NotNull String command) { + Command removed = COMMANDS.remove(command); + if (removed != null) + removed.unregister(COMMAND_MAP); + } + + @Override + public @NotNull Map getCommands() { + return COMMANDS; + } +} From 88b3209b231610d6d331c9dd3778fc4b26e13eff Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Wed, 13 Nov 2024 22:00:42 -0300 Subject: [PATCH 29/73] added the RegisteredCommand#onUnregister(CommandManager) method --- .../wlib/command/registered/RegisteredCommand.java | 3 +++ .../wlib/command/registered/RegisteredPluginCommand.java | 8 +++++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/registered/RegisteredCommand.java b/commands/src/main/java/com/wizardlybump17/wlib/command/registered/RegisteredCommand.java index 26e7d3f7..03a6faac 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/registered/RegisteredCommand.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/registered/RegisteredCommand.java @@ -132,4 +132,7 @@ public boolean isOwnedBy(@NotNull Object object) { public void onRegister(@NotNull CommandManager manager) { } + + public void onUnregister(@NotNull CommandManager manager) { + } } \ No newline at end of file diff --git a/core/src/main/java/com/wizardlybump17/wlib/command/registered/RegisteredPluginCommand.java b/core/src/main/java/com/wizardlybump17/wlib/command/registered/RegisteredPluginCommand.java index f1a6fd8e..a5e79ff1 100644 --- a/core/src/main/java/com/wizardlybump17/wlib/command/registered/RegisteredPluginCommand.java +++ b/core/src/main/java/com/wizardlybump17/wlib/command/registered/RegisteredPluginCommand.java @@ -1,5 +1,6 @@ package com.wizardlybump17.wlib.command.registered; +import com.wizardlybump17.wlib.adapter.command.CommandMapAdapter; import com.wizardlybump17.wlib.command.CommandManager; import com.wizardlybump17.wlib.command.args.ArgsNode; import com.wizardlybump17.wlib.command.data.CommandData; @@ -28,7 +29,7 @@ public RegisteredPluginCommand(@NotNull CommandData command, @NotNull List Date: Wed, 13 Nov 2024 22:05:59 -0300 Subject: [PATCH 30/73] added the CommandMapAdapter for the other versions --- .../java/com/wizardlybump17/wlib/WLib.java | 11 +++++++ .../v1_17_R1/command/CommandMapAdapter.java | 33 +++++++++++++++++++ .../v1_18_R1/command/CommandMapAdapter.java | 33 +++++++++++++++++++ .../v1_18_R2/command/CommandMapAdapter.java | 33 +++++++++++++++++++ .../v1_19_R1/command/CommandMapAdapter.java | 33 +++++++++++++++++++ .../v1_19_R2/command/CommandMapAdapter.java | 33 +++++++++++++++++++ .../v1_19_R3/command/CommandMapAdapter.java | 33 +++++++++++++++++++ .../v1_20_R1/command/CommandMapAdapter.java | 33 +++++++++++++++++++ .../v1_20_R2/command/CommandMapAdapter.java | 33 +++++++++++++++++++ .../v1_20_R3/command/CommandMapAdapter.java | 33 +++++++++++++++++++ 10 files changed, 308 insertions(+) create mode 100644 versions/v1_17_R1/src/main/java/com/wizardlybump17/wlib/adapter/v1_17_R1/command/CommandMapAdapter.java create mode 100644 versions/v1_18_R1/src/main/java/com/wizardlybump17/wlib/adapter/v1_18_R1/command/CommandMapAdapter.java create mode 100644 versions/v1_18_R2/src/main/java/com/wizardlybump17/wlib/adapter/v1_18_R2/command/CommandMapAdapter.java create mode 100644 versions/v1_19_R1/src/main/java/com/wizardlybump17/wlib/adapter/v1_19_R1/command/CommandMapAdapter.java create mode 100644 versions/v1_19_R2/src/main/java/com/wizardlybump17/wlib/adapter/v1_19_R2/command/CommandMapAdapter.java create mode 100644 versions/v1_19_R3/src/main/java/com/wizardlybump17/wlib/adapter/v1_19_R3/command/CommandMapAdapter.java create mode 100644 versions/v1_20_R1/src/main/java/com/wizardlybump17/wlib/adapter/v1_20_R1/command/CommandMapAdapter.java create mode 100644 versions/v1_20_R2/src/main/java/com/wizardlybump17/wlib/adapter/v1_20_R2/command/CommandMapAdapter.java create mode 100644 versions/v1_20_R3/src/main/java/com/wizardlybump17/wlib/adapter/v1_20_R3/command/CommandMapAdapter.java diff --git a/core/src/main/java/com/wizardlybump17/wlib/WLib.java b/core/src/main/java/com/wizardlybump17/wlib/WLib.java index 5360dca2..e4905f1f 100644 --- a/core/src/main/java/com/wizardlybump17/wlib/WLib.java +++ b/core/src/main/java/com/wizardlybump17/wlib/WLib.java @@ -3,6 +3,7 @@ import com.wizardlybump17.wlib.adapter.EnchantmentAdapter; import com.wizardlybump17.wlib.adapter.ItemAdapter; import com.wizardlybump17.wlib.adapter.PotionEffectTypeAdapter; +import com.wizardlybump17.wlib.adapter.command.CommandMapAdapter; import com.wizardlybump17.wlib.adapter.v1_19_R2.player.PlayerAdapter; import com.wizardlybump17.wlib.command.args.ArgsReaderRegistry; import com.wizardlybump17.wlib.command.reader.*; @@ -121,60 +122,70 @@ private void setupAdapters() { PlayerAdapter.setInstance(new com.wizardlybump17.wlib.adapter.v1_16_R3.player.PlayerAdapter()); PotionEffectTypeAdapter.setInstance(new com.wizardlybump17.wlib.adapter.v1_16_R3.PotionEffectTypeAdapter()); EnchantmentAdapter.setInstance(new EnchantmentAdapter()); + CommandMapAdapter.setInstance(new com.wizardlybump17.wlib.adapter.v1_16_R3.command.CommandMapAdapter()); } case V1_17_1 -> { ItemAdapter.setInstance(new com.wizardlybump17.wlib.adapter.v1_17_R1.ItemAdapter()); PlayerAdapter.setInstance(new com.wizardlybump17.wlib.adapter.v1_17_R1.player.PlayerAdapter()); PotionEffectTypeAdapter.setInstance(new com.wizardlybump17.wlib.adapter.v1_17_R1.PotionEffectTypeAdapter()); EnchantmentAdapter.setInstance(new EnchantmentAdapter()); + CommandMapAdapter.setInstance(new com.wizardlybump17.wlib.adapter.v1_17_R1.command.CommandMapAdapter()); } case V1_18 -> { ItemAdapter.setInstance(new com.wizardlybump17.wlib.adapter.v1_18_R1.ItemAdapter()); PlayerAdapter.setInstance(new com.wizardlybump17.wlib.adapter.v1_18_R1.player.PlayerAdapter()); PotionEffectTypeAdapter.setInstance(new com.wizardlybump17.wlib.adapter.v1_18_R1.PotionEffectTypeAdapter()); EnchantmentAdapter.setInstance(new EnchantmentAdapter()); + CommandMapAdapter.setInstance(new com.wizardlybump17.wlib.adapter.v1_18_R1.command.CommandMapAdapter()); } case V1_18_2 -> { ItemAdapter.setInstance(new com.wizardlybump17.wlib.adapter.v1_18_R2.ItemAdapter()); PlayerAdapter.setInstance(new com.wizardlybump17.wlib.adapter.v1_18_R2.player.PlayerAdapter()); PotionEffectTypeAdapter.setInstance(new com.wizardlybump17.wlib.adapter.v1_18_R2.PotionEffectTypeAdapter()); EnchantmentAdapter.setInstance(new EnchantmentAdapter()); + CommandMapAdapter.setInstance(new com.wizardlybump17.wlib.adapter.v1_18_R2.command.CommandMapAdapter()); } case V1_19 -> { ItemAdapter.setInstance(new com.wizardlybump17.wlib.adapter.v1_19_R1.ItemAdapter()); PlayerAdapter.setInstance(new com.wizardlybump17.wlib.adapter.v1_19_R1.player.PlayerAdapter()); PotionEffectTypeAdapter.setInstance(new com.wizardlybump17.wlib.adapter.v1_19_R1.PotionEffectTypeAdapter()); EnchantmentAdapter.setInstance(new EnchantmentAdapter()); + CommandMapAdapter.setInstance(new com.wizardlybump17.wlib.adapter.v1_19_R1.command.CommandMapAdapter()); } case V1_19_3 -> { ItemAdapter.setInstance(new com.wizardlybump17.wlib.adapter.v1_19_R2.ItemAdapter()); PlayerAdapter.setInstance(new com.wizardlybump17.wlib.adapter.v1_19_R2.player.PlayerAdapter()); PotionEffectTypeAdapter.setInstance(new com.wizardlybump17.wlib.adapter.v1_19_R2.PotionEffectTypeAdapter()); EnchantmentAdapter.setInstance(new EnchantmentAdapter()); + CommandMapAdapter.setInstance(new com.wizardlybump17.wlib.adapter.v1_19_R2.command.CommandMapAdapter()); } case V1_19_4 -> { ItemAdapter.setInstance(new com.wizardlybump17.wlib.adapter.v1_19_R3.ItemAdapter()); PlayerAdapter.setInstance(new com.wizardlybump17.wlib.adapter.v1_19_R3.player.PlayerAdapter()); PotionEffectTypeAdapter.setInstance(new com.wizardlybump17.wlib.adapter.v1_19_R3.PotionEffectTypeAdapter()); EnchantmentAdapter.setInstance(new EnchantmentAdapter()); + CommandMapAdapter.setInstance(new com.wizardlybump17.wlib.adapter.v1_19_R3.command.CommandMapAdapter()); } case V1_20_1 -> { ItemAdapter.setInstance(new com.wizardlybump17.wlib.adapter.v1_20_R1.ItemAdapter()); PlayerAdapter.setInstance(new com.wizardlybump17.wlib.adapter.v1_20_R1.player.PlayerAdapter()); PotionEffectTypeAdapter.setInstance(new com.wizardlybump17.wlib.adapter.v1_20_R1.PotionEffectTypeAdapter()); EnchantmentAdapter.setInstance(new EnchantmentAdapter()); + CommandMapAdapter.setInstance(new com.wizardlybump17.wlib.adapter.v1_20_R1.command.CommandMapAdapter()); } case V1_20_2 -> { ItemAdapter.setInstance(new com.wizardlybump17.wlib.adapter.v1_20_R2.ItemAdapter()); PlayerAdapter.setInstance(new com.wizardlybump17.wlib.adapter.v1_20_R2.player.PlayerAdapter()); PotionEffectTypeAdapter.setInstance(new com.wizardlybump17.wlib.adapter.v1_20_R2.PotionEffectTypeAdapter()); EnchantmentAdapter.setInstance(new EnchantmentAdapter()); + CommandMapAdapter.setInstance(new com.wizardlybump17.wlib.adapter.v1_20_R2.command.CommandMapAdapter()); } case V1_20_4 -> { ItemAdapter.setInstance(new com.wizardlybump17.wlib.adapter.v1_20_R3.ItemAdapter()); PlayerAdapter.setInstance(new com.wizardlybump17.wlib.adapter.v1_20_R3.player.PlayerAdapter()); PotionEffectTypeAdapter.setInstance(new com.wizardlybump17.wlib.adapter.v1_20_R3.PotionEffectTypeAdapter()); EnchantmentAdapter.setInstance(new com.wizardlybump17.wlib.adapter.v1_20_R3.EnchantmentAdapter()); + CommandMapAdapter.setInstance(new com.wizardlybump17.wlib.adapter.v1_20_R3.command.CommandMapAdapter()); } } diff --git a/versions/v1_17_R1/src/main/java/com/wizardlybump17/wlib/adapter/v1_17_R1/command/CommandMapAdapter.java b/versions/v1_17_R1/src/main/java/com/wizardlybump17/wlib/adapter/v1_17_R1/command/CommandMapAdapter.java new file mode 100644 index 00000000..6faf8ecc --- /dev/null +++ b/versions/v1_17_R1/src/main/java/com/wizardlybump17/wlib/adapter/v1_17_R1/command/CommandMapAdapter.java @@ -0,0 +1,33 @@ +package com.wizardlybump17.wlib.adapter.v1_17_R1.command; + +import com.wizardlybump17.wlib.util.ReflectionUtil; +import org.bukkit.Bukkit; +import org.bukkit.command.Command; +import org.bukkit.command.CommandMap; +import org.bukkit.command.SimpleCommandMap; +import org.jetbrains.annotations.NotNull; + +import java.util.Map; + +public class CommandMapAdapter extends com.wizardlybump17.wlib.adapter.command.CommandMapAdapter { + + public static final @NotNull CommandMap COMMAND_MAP = ReflectionUtil.getFieldValue(ReflectionUtil.getField("commandMap", Bukkit.getServer().getClass()), Bukkit.getServer()); + public static final @NotNull Map COMMANDS = ReflectionUtil.getFieldValue(ReflectionUtil.getField("knownCommands", SimpleCommandMap.class), COMMAND_MAP); + + @Override + public @NotNull CommandMap getCommandMap() { + return COMMAND_MAP; + } + + @Override + public void unregisterCommand(@NotNull String command) { + Command removed = COMMANDS.remove(command); + if (removed != null) + removed.unregister(COMMAND_MAP); + } + + @Override + public @NotNull Map getCommands() { + return COMMANDS; + } +} diff --git a/versions/v1_18_R1/src/main/java/com/wizardlybump17/wlib/adapter/v1_18_R1/command/CommandMapAdapter.java b/versions/v1_18_R1/src/main/java/com/wizardlybump17/wlib/adapter/v1_18_R1/command/CommandMapAdapter.java new file mode 100644 index 00000000..9b01a952 --- /dev/null +++ b/versions/v1_18_R1/src/main/java/com/wizardlybump17/wlib/adapter/v1_18_R1/command/CommandMapAdapter.java @@ -0,0 +1,33 @@ +package com.wizardlybump17.wlib.adapter.v1_18_R1.command; + +import com.wizardlybump17.wlib.util.ReflectionUtil; +import org.bukkit.Bukkit; +import org.bukkit.command.Command; +import org.bukkit.command.CommandMap; +import org.bukkit.command.SimpleCommandMap; +import org.jetbrains.annotations.NotNull; + +import java.util.Map; + +public class CommandMapAdapter extends com.wizardlybump17.wlib.adapter.command.CommandMapAdapter { + + public static final @NotNull CommandMap COMMAND_MAP = ReflectionUtil.getFieldValue(ReflectionUtil.getField("commandMap", Bukkit.getServer().getClass()), Bukkit.getServer()); + public static final @NotNull Map COMMANDS = ReflectionUtil.getFieldValue(ReflectionUtil.getField("knownCommands", SimpleCommandMap.class), COMMAND_MAP); + + @Override + public @NotNull CommandMap getCommandMap() { + return COMMAND_MAP; + } + + @Override + public void unregisterCommand(@NotNull String command) { + Command removed = COMMANDS.remove(command); + if (removed != null) + removed.unregister(COMMAND_MAP); + } + + @Override + public @NotNull Map getCommands() { + return COMMANDS; + } +} diff --git a/versions/v1_18_R2/src/main/java/com/wizardlybump17/wlib/adapter/v1_18_R2/command/CommandMapAdapter.java b/versions/v1_18_R2/src/main/java/com/wizardlybump17/wlib/adapter/v1_18_R2/command/CommandMapAdapter.java new file mode 100644 index 00000000..9302abad --- /dev/null +++ b/versions/v1_18_R2/src/main/java/com/wizardlybump17/wlib/adapter/v1_18_R2/command/CommandMapAdapter.java @@ -0,0 +1,33 @@ +package com.wizardlybump17.wlib.adapter.v1_18_R2.command; + +import com.wizardlybump17.wlib.util.ReflectionUtil; +import org.bukkit.Bukkit; +import org.bukkit.command.Command; +import org.bukkit.command.CommandMap; +import org.bukkit.command.SimpleCommandMap; +import org.jetbrains.annotations.NotNull; + +import java.util.Map; + +public class CommandMapAdapter extends com.wizardlybump17.wlib.adapter.command.CommandMapAdapter { + + public static final @NotNull CommandMap COMMAND_MAP = ReflectionUtil.getFieldValue(ReflectionUtil.getField("commandMap", Bukkit.getServer().getClass()), Bukkit.getServer()); + public static final @NotNull Map COMMANDS = ReflectionUtil.getFieldValue(ReflectionUtil.getField("knownCommands", SimpleCommandMap.class), COMMAND_MAP); + + @Override + public @NotNull CommandMap getCommandMap() { + return COMMAND_MAP; + } + + @Override + public void unregisterCommand(@NotNull String command) { + Command removed = COMMANDS.remove(command); + if (removed != null) + removed.unregister(COMMAND_MAP); + } + + @Override + public @NotNull Map getCommands() { + return COMMANDS; + } +} diff --git a/versions/v1_19_R1/src/main/java/com/wizardlybump17/wlib/adapter/v1_19_R1/command/CommandMapAdapter.java b/versions/v1_19_R1/src/main/java/com/wizardlybump17/wlib/adapter/v1_19_R1/command/CommandMapAdapter.java new file mode 100644 index 00000000..6866c760 --- /dev/null +++ b/versions/v1_19_R1/src/main/java/com/wizardlybump17/wlib/adapter/v1_19_R1/command/CommandMapAdapter.java @@ -0,0 +1,33 @@ +package com.wizardlybump17.wlib.adapter.v1_19_R1.command; + +import com.wizardlybump17.wlib.util.ReflectionUtil; +import org.bukkit.Bukkit; +import org.bukkit.command.Command; +import org.bukkit.command.CommandMap; +import org.bukkit.command.SimpleCommandMap; +import org.jetbrains.annotations.NotNull; + +import java.util.Map; + +public class CommandMapAdapter extends com.wizardlybump17.wlib.adapter.command.CommandMapAdapter { + + public static final @NotNull CommandMap COMMAND_MAP = ReflectionUtil.getFieldValue(ReflectionUtil.getField("commandMap", Bukkit.getServer().getClass()), Bukkit.getServer()); + public static final @NotNull Map COMMANDS = ReflectionUtil.getFieldValue(ReflectionUtil.getField("knownCommands", SimpleCommandMap.class), COMMAND_MAP); + + @Override + public @NotNull CommandMap getCommandMap() { + return COMMAND_MAP; + } + + @Override + public void unregisterCommand(@NotNull String command) { + Command removed = COMMANDS.remove(command); + if (removed != null) + removed.unregister(COMMAND_MAP); + } + + @Override + public @NotNull Map getCommands() { + return COMMANDS; + } +} diff --git a/versions/v1_19_R2/src/main/java/com/wizardlybump17/wlib/adapter/v1_19_R2/command/CommandMapAdapter.java b/versions/v1_19_R2/src/main/java/com/wizardlybump17/wlib/adapter/v1_19_R2/command/CommandMapAdapter.java new file mode 100644 index 00000000..e48d139b --- /dev/null +++ b/versions/v1_19_R2/src/main/java/com/wizardlybump17/wlib/adapter/v1_19_R2/command/CommandMapAdapter.java @@ -0,0 +1,33 @@ +package com.wizardlybump17.wlib.adapter.v1_19_R2.command; + +import com.wizardlybump17.wlib.util.ReflectionUtil; +import org.bukkit.Bukkit; +import org.bukkit.command.Command; +import org.bukkit.command.CommandMap; +import org.bukkit.command.SimpleCommandMap; +import org.jetbrains.annotations.NotNull; + +import java.util.Map; + +public class CommandMapAdapter extends com.wizardlybump17.wlib.adapter.command.CommandMapAdapter { + + public static final @NotNull CommandMap COMMAND_MAP = ReflectionUtil.getFieldValue(ReflectionUtil.getField("commandMap", Bukkit.getServer().getClass()), Bukkit.getServer()); + public static final @NotNull Map COMMANDS = ReflectionUtil.getFieldValue(ReflectionUtil.getField("knownCommands", SimpleCommandMap.class), COMMAND_MAP); + + @Override + public @NotNull CommandMap getCommandMap() { + return COMMAND_MAP; + } + + @Override + public void unregisterCommand(@NotNull String command) { + Command removed = COMMANDS.remove(command); + if (removed != null) + removed.unregister(COMMAND_MAP); + } + + @Override + public @NotNull Map getCommands() { + return COMMANDS; + } +} diff --git a/versions/v1_19_R3/src/main/java/com/wizardlybump17/wlib/adapter/v1_19_R3/command/CommandMapAdapter.java b/versions/v1_19_R3/src/main/java/com/wizardlybump17/wlib/adapter/v1_19_R3/command/CommandMapAdapter.java new file mode 100644 index 00000000..d9a8b9b4 --- /dev/null +++ b/versions/v1_19_R3/src/main/java/com/wizardlybump17/wlib/adapter/v1_19_R3/command/CommandMapAdapter.java @@ -0,0 +1,33 @@ +package com.wizardlybump17.wlib.adapter.v1_19_R3.command; + +import com.wizardlybump17.wlib.util.ReflectionUtil; +import org.bukkit.Bukkit; +import org.bukkit.command.Command; +import org.bukkit.command.CommandMap; +import org.bukkit.command.SimpleCommandMap; +import org.jetbrains.annotations.NotNull; + +import java.util.Map; + +public class CommandMapAdapter extends com.wizardlybump17.wlib.adapter.command.CommandMapAdapter { + + public static final @NotNull CommandMap COMMAND_MAP = ReflectionUtil.getFieldValue(ReflectionUtil.getField("commandMap", Bukkit.getServer().getClass()), Bukkit.getServer()); + public static final @NotNull Map COMMANDS = ReflectionUtil.getFieldValue(ReflectionUtil.getField("knownCommands", SimpleCommandMap.class), COMMAND_MAP); + + @Override + public @NotNull CommandMap getCommandMap() { + return COMMAND_MAP; + } + + @Override + public void unregisterCommand(@NotNull String command) { + Command removed = COMMANDS.remove(command); + if (removed != null) + removed.unregister(COMMAND_MAP); + } + + @Override + public @NotNull Map getCommands() { + return COMMANDS; + } +} diff --git a/versions/v1_20_R1/src/main/java/com/wizardlybump17/wlib/adapter/v1_20_R1/command/CommandMapAdapter.java b/versions/v1_20_R1/src/main/java/com/wizardlybump17/wlib/adapter/v1_20_R1/command/CommandMapAdapter.java new file mode 100644 index 00000000..0eb5914f --- /dev/null +++ b/versions/v1_20_R1/src/main/java/com/wizardlybump17/wlib/adapter/v1_20_R1/command/CommandMapAdapter.java @@ -0,0 +1,33 @@ +package com.wizardlybump17.wlib.adapter.v1_20_R1.command; + +import com.wizardlybump17.wlib.util.ReflectionUtil; +import org.bukkit.Bukkit; +import org.bukkit.command.Command; +import org.bukkit.command.CommandMap; +import org.bukkit.command.SimpleCommandMap; +import org.jetbrains.annotations.NotNull; + +import java.util.Map; + +public class CommandMapAdapter extends com.wizardlybump17.wlib.adapter.command.CommandMapAdapter { + + public static final @NotNull CommandMap COMMAND_MAP = ReflectionUtil.getFieldValue(ReflectionUtil.getField("commandMap", Bukkit.getServer().getClass()), Bukkit.getServer()); + public static final @NotNull Map COMMANDS = ReflectionUtil.getFieldValue(ReflectionUtil.getField("knownCommands", SimpleCommandMap.class), COMMAND_MAP); + + @Override + public @NotNull CommandMap getCommandMap() { + return COMMAND_MAP; + } + + @Override + public void unregisterCommand(@NotNull String command) { + Command removed = COMMANDS.remove(command); + if (removed != null) + removed.unregister(COMMAND_MAP); + } + + @Override + public @NotNull Map getCommands() { + return COMMANDS; + } +} diff --git a/versions/v1_20_R2/src/main/java/com/wizardlybump17/wlib/adapter/v1_20_R2/command/CommandMapAdapter.java b/versions/v1_20_R2/src/main/java/com/wizardlybump17/wlib/adapter/v1_20_R2/command/CommandMapAdapter.java new file mode 100644 index 00000000..df1da3a4 --- /dev/null +++ b/versions/v1_20_R2/src/main/java/com/wizardlybump17/wlib/adapter/v1_20_R2/command/CommandMapAdapter.java @@ -0,0 +1,33 @@ +package com.wizardlybump17.wlib.adapter.v1_20_R2.command; + +import com.wizardlybump17.wlib.util.ReflectionUtil; +import org.bukkit.Bukkit; +import org.bukkit.command.Command; +import org.bukkit.command.CommandMap; +import org.bukkit.command.SimpleCommandMap; +import org.jetbrains.annotations.NotNull; + +import java.util.Map; + +public class CommandMapAdapter extends com.wizardlybump17.wlib.adapter.command.CommandMapAdapter { + + public static final @NotNull CommandMap COMMAND_MAP = ReflectionUtil.getFieldValue(ReflectionUtil.getField("commandMap", Bukkit.getServer().getClass()), Bukkit.getServer()); + public static final @NotNull Map COMMANDS = ReflectionUtil.getFieldValue(ReflectionUtil.getField("knownCommands", SimpleCommandMap.class), COMMAND_MAP); + + @Override + public @NotNull CommandMap getCommandMap() { + return COMMAND_MAP; + } + + @Override + public void unregisterCommand(@NotNull String command) { + Command removed = COMMANDS.remove(command); + if (removed != null) + removed.unregister(COMMAND_MAP); + } + + @Override + public @NotNull Map getCommands() { + return COMMANDS; + } +} diff --git a/versions/v1_20_R3/src/main/java/com/wizardlybump17/wlib/adapter/v1_20_R3/command/CommandMapAdapter.java b/versions/v1_20_R3/src/main/java/com/wizardlybump17/wlib/adapter/v1_20_R3/command/CommandMapAdapter.java new file mode 100644 index 00000000..6aedfc2b --- /dev/null +++ b/versions/v1_20_R3/src/main/java/com/wizardlybump17/wlib/adapter/v1_20_R3/command/CommandMapAdapter.java @@ -0,0 +1,33 @@ +package com.wizardlybump17.wlib.adapter.v1_20_R3.command; + +import com.wizardlybump17.wlib.util.ReflectionUtil; +import org.bukkit.Bukkit; +import org.bukkit.command.Command; +import org.bukkit.command.CommandMap; +import org.bukkit.command.SimpleCommandMap; +import org.jetbrains.annotations.NotNull; + +import java.util.Map; + +public class CommandMapAdapter extends com.wizardlybump17.wlib.adapter.command.CommandMapAdapter { + + public static final @NotNull CommandMap COMMAND_MAP = ReflectionUtil.getFieldValue(ReflectionUtil.getField("commandMap", Bukkit.getServer().getClass()), Bukkit.getServer()); + public static final @NotNull Map COMMANDS = ReflectionUtil.getFieldValue(ReflectionUtil.getField("knownCommands", SimpleCommandMap.class), COMMAND_MAP); + + @Override + public @NotNull CommandMap getCommandMap() { + return COMMAND_MAP; + } + + @Override + public void unregisterCommand(@NotNull String command) { + Command removed = COMMANDS.remove(command); + if (removed != null) + removed.unregister(COMMAND_MAP); + } + + @Override + public @NotNull Map getCommands() { + return COMMANDS; + } +} From c60e2ec2a0996a4a4c9f7bb6511d9c68a8c8f0fa Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Wed, 13 Nov 2024 22:07:22 -0300 Subject: [PATCH 31/73] renamed to RegisteredBukkitCommand --- ...teredPluginCommand.java => RegisteredBukkitCommand.java} | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) rename core/src/main/java/com/wizardlybump17/wlib/command/registered/{RegisteredPluginCommand.java => RegisteredBukkitCommand.java} (90%) diff --git a/core/src/main/java/com/wizardlybump17/wlib/command/registered/RegisteredPluginCommand.java b/core/src/main/java/com/wizardlybump17/wlib/command/registered/RegisteredBukkitCommand.java similarity index 90% rename from core/src/main/java/com/wizardlybump17/wlib/command/registered/RegisteredPluginCommand.java rename to core/src/main/java/com/wizardlybump17/wlib/command/registered/RegisteredBukkitCommand.java index a5e79ff1..e1c55caa 100644 --- a/core/src/main/java/com/wizardlybump17/wlib/command/registered/RegisteredPluginCommand.java +++ b/core/src/main/java/com/wizardlybump17/wlib/command/registered/RegisteredBukkitCommand.java @@ -14,11 +14,11 @@ import java.util.List; import java.util.logging.Level; -public class RegisteredPluginCommand extends RegisteredCommand { +public class RegisteredBukkitCommand extends RegisteredCommand { private final @NotNull String fallback; - public RegisteredPluginCommand(@NotNull CommandData command, @NotNull List nodes, @NotNull CommandExecutor executor, @NotNull String fallback) { + public RegisteredBukkitCommand(@NotNull CommandData command, @NotNull List nodes, @NotNull CommandExecutor executor, @NotNull String fallback) { super(command, nodes, executor); this.fallback = fallback; } @@ -34,7 +34,7 @@ public void onRegister(@NotNull CommandManager manager) { @Override public boolean execute(@NotNull CommandSender sender, @NotNull String label, @NotNull String[] args) { try { - RegisteredPluginCommand.this.execute(new com.wizardlybump17.wlib.command.sender.CommandSender(sender), String.join(" ", args)); + RegisteredBukkitCommand.this.execute(new com.wizardlybump17.wlib.command.sender.CommandSender(sender), String.join(" ", args)); } catch (CommandException e) { manager.getHolder().getLogger().log(Level.SEVERE, "Error while executing a command.", e); } From c81482e043d6cf117faa689b03f9d6b6f5a8444a Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Wed, 13 Nov 2024 22:12:25 -0300 Subject: [PATCH 32/73] added the ArgsNode.literal(String) method --- .../java/com/wizardlybump17/wlib/command/args/ArgsNode.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/args/ArgsNode.java b/commands/src/main/java/com/wizardlybump17/wlib/command/args/ArgsNode.java index afb04352..f0149eb2 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/args/ArgsNode.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/args/ArgsNode.java @@ -42,4 +42,8 @@ public Object parse(String input) throws ArgsReaderException { return object; } + + public static @NotNull ArgsNode literal(@NotNull String string) { + return new ArgsNode(string, false, null, null, false); + } } From 0afb70e7dbf6bf25ee6be63604cecd48c371b99f Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Wed, 13 Nov 2024 22:25:06 -0300 Subject: [PATCH 33/73] calling the RegisteredCommand#onUnregister(CommandManager) method when unregistering the commands --- .../java/com/wizardlybump17/wlib/command/CommandManager.java | 1 + 1 file changed, 1 insertion(+) diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/CommandManager.java b/commands/src/main/java/com/wizardlybump17/wlib/command/CommandManager.java index 6c4146f7..1a1888f2 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/CommandManager.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/CommandManager.java @@ -46,6 +46,7 @@ public void registerCommands(@NotNull Collection commands) { } public void unregisterCommands() { + commands.forEach(command -> command.onUnregister(this)); commands.clear(); } From b4cdfc155feeb18f9c854d1ae80559ad87b0553c Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Wed, 13 Nov 2024 22:48:08 -0300 Subject: [PATCH 34/73] using the public lookup --- .../wlib/command/registered/RegisteredMethodCommand.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/registered/RegisteredMethodCommand.java b/commands/src/main/java/com/wizardlybump17/wlib/command/registered/RegisteredMethodCommand.java index 5641650b..721860f0 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/registered/RegisteredMethodCommand.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/registered/RegisteredMethodCommand.java @@ -41,7 +41,7 @@ public RegisteredMethodCommand(@NotNull Command annotation, @NotNull Object obje this.annotation = annotation; this.object = object; this.method = method; - methodHandle = MethodHandles.lookup().findVirtual(object.getClass(), method.getName(), MethodType.methodType(method.getReturnType(), method.getParameterTypes())); + methodHandle = MethodHandles.publicLookup().findVirtual(object.getClass(), method.getName(), MethodType.methodType(method.getReturnType(), method.getParameterTypes())); prepareNodes(); } From f0749457e8b69680df0936c707b008360cfe8420 Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Wed, 13 Nov 2024 22:56:12 -0300 Subject: [PATCH 35/73] unregistering the command properly --- .../wlib/command/registered/RegisteredBukkitCommand.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/core/src/main/java/com/wizardlybump17/wlib/command/registered/RegisteredBukkitCommand.java b/core/src/main/java/com/wizardlybump17/wlib/command/registered/RegisteredBukkitCommand.java index e1c55caa..b303c099 100644 --- a/core/src/main/java/com/wizardlybump17/wlib/command/registered/RegisteredBukkitCommand.java +++ b/core/src/main/java/com/wizardlybump17/wlib/command/registered/RegisteredBukkitCommand.java @@ -45,6 +45,10 @@ public boolean execute(@NotNull CommandSender sender, @NotNull String label, @No @Override public void onUnregister(@NotNull CommandManager manager) { - CommandMapAdapter.getInstance().unregisterCommand(fallback + ":" + getCommand().getName()); + CommandMapAdapter adapter = CommandMapAdapter.getInstance(); + + String name = getCommand().getName(); + adapter.unregisterCommand(name); + adapter.unregisterCommand(fallback + ":" + name); } } From a6f8dcc8b6e689463e77f6cbcb3e05734d1d4810 Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Wed, 13 Nov 2024 23:07:10 -0300 Subject: [PATCH 36/73] using the fields instead of their values --- .../v1_16_R3/command/CommandMapAdapter.java | 16 ++++++++++------ .../v1_17_R1/command/CommandMapAdapter.java | 16 ++++++++++------ .../v1_18_R1/command/CommandMapAdapter.java | 16 ++++++++++------ .../v1_18_R2/command/CommandMapAdapter.java | 16 ++++++++++------ .../v1_19_R1/command/CommandMapAdapter.java | 16 ++++++++++------ .../v1_19_R2/command/CommandMapAdapter.java | 16 ++++++++++------ .../v1_19_R3/command/CommandMapAdapter.java | 16 ++++++++++------ .../v1_20_R1/command/CommandMapAdapter.java | 16 ++++++++++------ .../v1_20_R2/command/CommandMapAdapter.java | 16 ++++++++++------ .../v1_20_R3/command/CommandMapAdapter.java | 16 ++++++++++------ 10 files changed, 100 insertions(+), 60 deletions(-) diff --git a/versions/v1_16_R3/src/main/java/com/wizardlybump17/wlib/adapter/v1_16_R3/command/CommandMapAdapter.java b/versions/v1_16_R3/src/main/java/com/wizardlybump17/wlib/adapter/v1_16_R3/command/CommandMapAdapter.java index b9e7ea3f..f2461fd8 100644 --- a/versions/v1_16_R3/src/main/java/com/wizardlybump17/wlib/adapter/v1_16_R3/command/CommandMapAdapter.java +++ b/versions/v1_16_R3/src/main/java/com/wizardlybump17/wlib/adapter/v1_16_R3/command/CommandMapAdapter.java @@ -7,27 +7,31 @@ import org.bukkit.command.SimpleCommandMap; import org.jetbrains.annotations.NotNull; +import java.lang.reflect.Field; import java.util.Map; public class CommandMapAdapter extends com.wizardlybump17.wlib.adapter.command.CommandMapAdapter { - public static final @NotNull CommandMap COMMAND_MAP = ReflectionUtil.getFieldValue(ReflectionUtil.getField("commandMap", Bukkit.getServer().getClass()), Bukkit.getServer()); - public static final @NotNull Map COMMANDS = ReflectionUtil.getFieldValue(ReflectionUtil.getField("knownCommands", SimpleCommandMap.class), COMMAND_MAP); + public static final @NotNull Field COMMAND_MAP = ReflectionUtil.getField("commandMap", Bukkit.getServer().getClass()); + public static final @NotNull Field COMMANDS = ReflectionUtil.getField("knownCommands", SimpleCommandMap.class); @Override public @NotNull CommandMap getCommandMap() { - return COMMAND_MAP; + return ReflectionUtil.getFieldValue(COMMAND_MAP, Bukkit.getServer()); } @Override public void unregisterCommand(@NotNull String command) { - Command removed = COMMANDS.remove(command); + Map commands = getCommands(); + CommandMap commandMap = getCommandMap(); + + Command removed = commands.remove(command); if (removed != null) - removed.unregister(COMMAND_MAP); + removed.unregister(commandMap); } @Override public @NotNull Map getCommands() { - return COMMANDS; + return ReflectionUtil.getFieldValue(COMMANDS, getCommandMap()); } } diff --git a/versions/v1_17_R1/src/main/java/com/wizardlybump17/wlib/adapter/v1_17_R1/command/CommandMapAdapter.java b/versions/v1_17_R1/src/main/java/com/wizardlybump17/wlib/adapter/v1_17_R1/command/CommandMapAdapter.java index 6faf8ecc..3e6d948d 100644 --- a/versions/v1_17_R1/src/main/java/com/wizardlybump17/wlib/adapter/v1_17_R1/command/CommandMapAdapter.java +++ b/versions/v1_17_R1/src/main/java/com/wizardlybump17/wlib/adapter/v1_17_R1/command/CommandMapAdapter.java @@ -7,27 +7,31 @@ import org.bukkit.command.SimpleCommandMap; import org.jetbrains.annotations.NotNull; +import java.lang.reflect.Field; import java.util.Map; public class CommandMapAdapter extends com.wizardlybump17.wlib.adapter.command.CommandMapAdapter { - public static final @NotNull CommandMap COMMAND_MAP = ReflectionUtil.getFieldValue(ReflectionUtil.getField("commandMap", Bukkit.getServer().getClass()), Bukkit.getServer()); - public static final @NotNull Map COMMANDS = ReflectionUtil.getFieldValue(ReflectionUtil.getField("knownCommands", SimpleCommandMap.class), COMMAND_MAP); + public static final @NotNull Field COMMAND_MAP = ReflectionUtil.getField("commandMap", Bukkit.getServer().getClass()); + public static final @NotNull Field COMMANDS = ReflectionUtil.getField("knownCommands", SimpleCommandMap.class); @Override public @NotNull CommandMap getCommandMap() { - return COMMAND_MAP; + return ReflectionUtil.getFieldValue(COMMAND_MAP, Bukkit.getServer()); } @Override public void unregisterCommand(@NotNull String command) { - Command removed = COMMANDS.remove(command); + Map commands = getCommands(); + CommandMap commandMap = getCommandMap(); + + Command removed = commands.remove(command); if (removed != null) - removed.unregister(COMMAND_MAP); + removed.unregister(commandMap); } @Override public @NotNull Map getCommands() { - return COMMANDS; + return ReflectionUtil.getFieldValue(COMMANDS, getCommandMap()); } } diff --git a/versions/v1_18_R1/src/main/java/com/wizardlybump17/wlib/adapter/v1_18_R1/command/CommandMapAdapter.java b/versions/v1_18_R1/src/main/java/com/wizardlybump17/wlib/adapter/v1_18_R1/command/CommandMapAdapter.java index 9b01a952..aa747170 100644 --- a/versions/v1_18_R1/src/main/java/com/wizardlybump17/wlib/adapter/v1_18_R1/command/CommandMapAdapter.java +++ b/versions/v1_18_R1/src/main/java/com/wizardlybump17/wlib/adapter/v1_18_R1/command/CommandMapAdapter.java @@ -7,27 +7,31 @@ import org.bukkit.command.SimpleCommandMap; import org.jetbrains.annotations.NotNull; +import java.lang.reflect.Field; import java.util.Map; public class CommandMapAdapter extends com.wizardlybump17.wlib.adapter.command.CommandMapAdapter { - public static final @NotNull CommandMap COMMAND_MAP = ReflectionUtil.getFieldValue(ReflectionUtil.getField("commandMap", Bukkit.getServer().getClass()), Bukkit.getServer()); - public static final @NotNull Map COMMANDS = ReflectionUtil.getFieldValue(ReflectionUtil.getField("knownCommands", SimpleCommandMap.class), COMMAND_MAP); + public static final @NotNull Field COMMAND_MAP = ReflectionUtil.getField("commandMap", Bukkit.getServer().getClass()); + public static final @NotNull Field COMMANDS = ReflectionUtil.getField("knownCommands", SimpleCommandMap.class); @Override public @NotNull CommandMap getCommandMap() { - return COMMAND_MAP; + return ReflectionUtil.getFieldValue(COMMAND_MAP, Bukkit.getServer()); } @Override public void unregisterCommand(@NotNull String command) { - Command removed = COMMANDS.remove(command); + Map commands = getCommands(); + CommandMap commandMap = getCommandMap(); + + Command removed = commands.remove(command); if (removed != null) - removed.unregister(COMMAND_MAP); + removed.unregister(commandMap); } @Override public @NotNull Map getCommands() { - return COMMANDS; + return ReflectionUtil.getFieldValue(COMMANDS, getCommandMap()); } } diff --git a/versions/v1_18_R2/src/main/java/com/wizardlybump17/wlib/adapter/v1_18_R2/command/CommandMapAdapter.java b/versions/v1_18_R2/src/main/java/com/wizardlybump17/wlib/adapter/v1_18_R2/command/CommandMapAdapter.java index 9302abad..cdb45016 100644 --- a/versions/v1_18_R2/src/main/java/com/wizardlybump17/wlib/adapter/v1_18_R2/command/CommandMapAdapter.java +++ b/versions/v1_18_R2/src/main/java/com/wizardlybump17/wlib/adapter/v1_18_R2/command/CommandMapAdapter.java @@ -7,27 +7,31 @@ import org.bukkit.command.SimpleCommandMap; import org.jetbrains.annotations.NotNull; +import java.lang.reflect.Field; import java.util.Map; public class CommandMapAdapter extends com.wizardlybump17.wlib.adapter.command.CommandMapAdapter { - public static final @NotNull CommandMap COMMAND_MAP = ReflectionUtil.getFieldValue(ReflectionUtil.getField("commandMap", Bukkit.getServer().getClass()), Bukkit.getServer()); - public static final @NotNull Map COMMANDS = ReflectionUtil.getFieldValue(ReflectionUtil.getField("knownCommands", SimpleCommandMap.class), COMMAND_MAP); + public static final @NotNull Field COMMAND_MAP = ReflectionUtil.getField("commandMap", Bukkit.getServer().getClass()); + public static final @NotNull Field COMMANDS = ReflectionUtil.getField("knownCommands", SimpleCommandMap.class); @Override public @NotNull CommandMap getCommandMap() { - return COMMAND_MAP; + return ReflectionUtil.getFieldValue(COMMAND_MAP, Bukkit.getServer()); } @Override public void unregisterCommand(@NotNull String command) { - Command removed = COMMANDS.remove(command); + Map commands = getCommands(); + CommandMap commandMap = getCommandMap(); + + Command removed = commands.remove(command); if (removed != null) - removed.unregister(COMMAND_MAP); + removed.unregister(commandMap); } @Override public @NotNull Map getCommands() { - return COMMANDS; + return ReflectionUtil.getFieldValue(COMMANDS, getCommandMap()); } } diff --git a/versions/v1_19_R1/src/main/java/com/wizardlybump17/wlib/adapter/v1_19_R1/command/CommandMapAdapter.java b/versions/v1_19_R1/src/main/java/com/wizardlybump17/wlib/adapter/v1_19_R1/command/CommandMapAdapter.java index 6866c760..a5ce6522 100644 --- a/versions/v1_19_R1/src/main/java/com/wizardlybump17/wlib/adapter/v1_19_R1/command/CommandMapAdapter.java +++ b/versions/v1_19_R1/src/main/java/com/wizardlybump17/wlib/adapter/v1_19_R1/command/CommandMapAdapter.java @@ -7,27 +7,31 @@ import org.bukkit.command.SimpleCommandMap; import org.jetbrains.annotations.NotNull; +import java.lang.reflect.Field; import java.util.Map; public class CommandMapAdapter extends com.wizardlybump17.wlib.adapter.command.CommandMapAdapter { - public static final @NotNull CommandMap COMMAND_MAP = ReflectionUtil.getFieldValue(ReflectionUtil.getField("commandMap", Bukkit.getServer().getClass()), Bukkit.getServer()); - public static final @NotNull Map COMMANDS = ReflectionUtil.getFieldValue(ReflectionUtil.getField("knownCommands", SimpleCommandMap.class), COMMAND_MAP); + public static final @NotNull Field COMMAND_MAP = ReflectionUtil.getField("commandMap", Bukkit.getServer().getClass()); + public static final @NotNull Field COMMANDS = ReflectionUtil.getField("knownCommands", SimpleCommandMap.class); @Override public @NotNull CommandMap getCommandMap() { - return COMMAND_MAP; + return ReflectionUtil.getFieldValue(COMMAND_MAP, Bukkit.getServer()); } @Override public void unregisterCommand(@NotNull String command) { - Command removed = COMMANDS.remove(command); + Map commands = getCommands(); + CommandMap commandMap = getCommandMap(); + + Command removed = commands.remove(command); if (removed != null) - removed.unregister(COMMAND_MAP); + removed.unregister(commandMap); } @Override public @NotNull Map getCommands() { - return COMMANDS; + return ReflectionUtil.getFieldValue(COMMANDS, getCommandMap()); } } diff --git a/versions/v1_19_R2/src/main/java/com/wizardlybump17/wlib/adapter/v1_19_R2/command/CommandMapAdapter.java b/versions/v1_19_R2/src/main/java/com/wizardlybump17/wlib/adapter/v1_19_R2/command/CommandMapAdapter.java index e48d139b..4b7b0639 100644 --- a/versions/v1_19_R2/src/main/java/com/wizardlybump17/wlib/adapter/v1_19_R2/command/CommandMapAdapter.java +++ b/versions/v1_19_R2/src/main/java/com/wizardlybump17/wlib/adapter/v1_19_R2/command/CommandMapAdapter.java @@ -7,27 +7,31 @@ import org.bukkit.command.SimpleCommandMap; import org.jetbrains.annotations.NotNull; +import java.lang.reflect.Field; import java.util.Map; public class CommandMapAdapter extends com.wizardlybump17.wlib.adapter.command.CommandMapAdapter { - public static final @NotNull CommandMap COMMAND_MAP = ReflectionUtil.getFieldValue(ReflectionUtil.getField("commandMap", Bukkit.getServer().getClass()), Bukkit.getServer()); - public static final @NotNull Map COMMANDS = ReflectionUtil.getFieldValue(ReflectionUtil.getField("knownCommands", SimpleCommandMap.class), COMMAND_MAP); + public static final @NotNull Field COMMAND_MAP = ReflectionUtil.getField("commandMap", Bukkit.getServer().getClass()); + public static final @NotNull Field COMMANDS = ReflectionUtil.getField("knownCommands", SimpleCommandMap.class); @Override public @NotNull CommandMap getCommandMap() { - return COMMAND_MAP; + return ReflectionUtil.getFieldValue(COMMAND_MAP, Bukkit.getServer()); } @Override public void unregisterCommand(@NotNull String command) { - Command removed = COMMANDS.remove(command); + Map commands = getCommands(); + CommandMap commandMap = getCommandMap(); + + Command removed = commands.remove(command); if (removed != null) - removed.unregister(COMMAND_MAP); + removed.unregister(commandMap); } @Override public @NotNull Map getCommands() { - return COMMANDS; + return ReflectionUtil.getFieldValue(COMMANDS, getCommandMap()); } } diff --git a/versions/v1_19_R3/src/main/java/com/wizardlybump17/wlib/adapter/v1_19_R3/command/CommandMapAdapter.java b/versions/v1_19_R3/src/main/java/com/wizardlybump17/wlib/adapter/v1_19_R3/command/CommandMapAdapter.java index d9a8b9b4..e0b6df28 100644 --- a/versions/v1_19_R3/src/main/java/com/wizardlybump17/wlib/adapter/v1_19_R3/command/CommandMapAdapter.java +++ b/versions/v1_19_R3/src/main/java/com/wizardlybump17/wlib/adapter/v1_19_R3/command/CommandMapAdapter.java @@ -7,27 +7,31 @@ import org.bukkit.command.SimpleCommandMap; import org.jetbrains.annotations.NotNull; +import java.lang.reflect.Field; import java.util.Map; public class CommandMapAdapter extends com.wizardlybump17.wlib.adapter.command.CommandMapAdapter { - public static final @NotNull CommandMap COMMAND_MAP = ReflectionUtil.getFieldValue(ReflectionUtil.getField("commandMap", Bukkit.getServer().getClass()), Bukkit.getServer()); - public static final @NotNull Map COMMANDS = ReflectionUtil.getFieldValue(ReflectionUtil.getField("knownCommands", SimpleCommandMap.class), COMMAND_MAP); + public static final @NotNull Field COMMAND_MAP = ReflectionUtil.getField("commandMap", Bukkit.getServer().getClass()); + public static final @NotNull Field COMMANDS = ReflectionUtil.getField("knownCommands", SimpleCommandMap.class); @Override public @NotNull CommandMap getCommandMap() { - return COMMAND_MAP; + return ReflectionUtil.getFieldValue(COMMAND_MAP, Bukkit.getServer()); } @Override public void unregisterCommand(@NotNull String command) { - Command removed = COMMANDS.remove(command); + Map commands = getCommands(); + CommandMap commandMap = getCommandMap(); + + Command removed = commands.remove(command); if (removed != null) - removed.unregister(COMMAND_MAP); + removed.unregister(commandMap); } @Override public @NotNull Map getCommands() { - return COMMANDS; + return ReflectionUtil.getFieldValue(COMMANDS, getCommandMap()); } } diff --git a/versions/v1_20_R1/src/main/java/com/wizardlybump17/wlib/adapter/v1_20_R1/command/CommandMapAdapter.java b/versions/v1_20_R1/src/main/java/com/wizardlybump17/wlib/adapter/v1_20_R1/command/CommandMapAdapter.java index 0eb5914f..98a07dd8 100644 --- a/versions/v1_20_R1/src/main/java/com/wizardlybump17/wlib/adapter/v1_20_R1/command/CommandMapAdapter.java +++ b/versions/v1_20_R1/src/main/java/com/wizardlybump17/wlib/adapter/v1_20_R1/command/CommandMapAdapter.java @@ -7,27 +7,31 @@ import org.bukkit.command.SimpleCommandMap; import org.jetbrains.annotations.NotNull; +import java.lang.reflect.Field; import java.util.Map; public class CommandMapAdapter extends com.wizardlybump17.wlib.adapter.command.CommandMapAdapter { - public static final @NotNull CommandMap COMMAND_MAP = ReflectionUtil.getFieldValue(ReflectionUtil.getField("commandMap", Bukkit.getServer().getClass()), Bukkit.getServer()); - public static final @NotNull Map COMMANDS = ReflectionUtil.getFieldValue(ReflectionUtil.getField("knownCommands", SimpleCommandMap.class), COMMAND_MAP); + public static final @NotNull Field COMMAND_MAP = ReflectionUtil.getField("commandMap", Bukkit.getServer().getClass()); + public static final @NotNull Field COMMANDS = ReflectionUtil.getField("knownCommands", SimpleCommandMap.class); @Override public @NotNull CommandMap getCommandMap() { - return COMMAND_MAP; + return ReflectionUtil.getFieldValue(COMMAND_MAP, Bukkit.getServer()); } @Override public void unregisterCommand(@NotNull String command) { - Command removed = COMMANDS.remove(command); + Map commands = getCommands(); + CommandMap commandMap = getCommandMap(); + + Command removed = commands.remove(command); if (removed != null) - removed.unregister(COMMAND_MAP); + removed.unregister(commandMap); } @Override public @NotNull Map getCommands() { - return COMMANDS; + return ReflectionUtil.getFieldValue(COMMANDS, getCommandMap()); } } diff --git a/versions/v1_20_R2/src/main/java/com/wizardlybump17/wlib/adapter/v1_20_R2/command/CommandMapAdapter.java b/versions/v1_20_R2/src/main/java/com/wizardlybump17/wlib/adapter/v1_20_R2/command/CommandMapAdapter.java index df1da3a4..b14f309f 100644 --- a/versions/v1_20_R2/src/main/java/com/wizardlybump17/wlib/adapter/v1_20_R2/command/CommandMapAdapter.java +++ b/versions/v1_20_R2/src/main/java/com/wizardlybump17/wlib/adapter/v1_20_R2/command/CommandMapAdapter.java @@ -7,27 +7,31 @@ import org.bukkit.command.SimpleCommandMap; import org.jetbrains.annotations.NotNull; +import java.lang.reflect.Field; import java.util.Map; public class CommandMapAdapter extends com.wizardlybump17.wlib.adapter.command.CommandMapAdapter { - public static final @NotNull CommandMap COMMAND_MAP = ReflectionUtil.getFieldValue(ReflectionUtil.getField("commandMap", Bukkit.getServer().getClass()), Bukkit.getServer()); - public static final @NotNull Map COMMANDS = ReflectionUtil.getFieldValue(ReflectionUtil.getField("knownCommands", SimpleCommandMap.class), COMMAND_MAP); + public static final @NotNull Field COMMAND_MAP = ReflectionUtil.getField("commandMap", Bukkit.getServer().getClass()); + public static final @NotNull Field COMMANDS = ReflectionUtil.getField("knownCommands", SimpleCommandMap.class); @Override public @NotNull CommandMap getCommandMap() { - return COMMAND_MAP; + return ReflectionUtil.getFieldValue(COMMAND_MAP, Bukkit.getServer()); } @Override public void unregisterCommand(@NotNull String command) { - Command removed = COMMANDS.remove(command); + Map commands = getCommands(); + CommandMap commandMap = getCommandMap(); + + Command removed = commands.remove(command); if (removed != null) - removed.unregister(COMMAND_MAP); + removed.unregister(commandMap); } @Override public @NotNull Map getCommands() { - return COMMANDS; + return ReflectionUtil.getFieldValue(COMMANDS, getCommandMap()); } } diff --git a/versions/v1_20_R3/src/main/java/com/wizardlybump17/wlib/adapter/v1_20_R3/command/CommandMapAdapter.java b/versions/v1_20_R3/src/main/java/com/wizardlybump17/wlib/adapter/v1_20_R3/command/CommandMapAdapter.java index 6aedfc2b..2c867d02 100644 --- a/versions/v1_20_R3/src/main/java/com/wizardlybump17/wlib/adapter/v1_20_R3/command/CommandMapAdapter.java +++ b/versions/v1_20_R3/src/main/java/com/wizardlybump17/wlib/adapter/v1_20_R3/command/CommandMapAdapter.java @@ -7,27 +7,31 @@ import org.bukkit.command.SimpleCommandMap; import org.jetbrains.annotations.NotNull; +import java.lang.reflect.Field; import java.util.Map; public class CommandMapAdapter extends com.wizardlybump17.wlib.adapter.command.CommandMapAdapter { - public static final @NotNull CommandMap COMMAND_MAP = ReflectionUtil.getFieldValue(ReflectionUtil.getField("commandMap", Bukkit.getServer().getClass()), Bukkit.getServer()); - public static final @NotNull Map COMMANDS = ReflectionUtil.getFieldValue(ReflectionUtil.getField("knownCommands", SimpleCommandMap.class), COMMAND_MAP); + public static final @NotNull Field COMMAND_MAP = ReflectionUtil.getField("commandMap", Bukkit.getServer().getClass()); + public static final @NotNull Field COMMANDS = ReflectionUtil.getField("knownCommands", SimpleCommandMap.class); @Override public @NotNull CommandMap getCommandMap() { - return COMMAND_MAP; + return ReflectionUtil.getFieldValue(COMMAND_MAP, Bukkit.getServer()); } @Override public void unregisterCommand(@NotNull String command) { - Command removed = COMMANDS.remove(command); + Map commands = getCommands(); + CommandMap commandMap = getCommandMap(); + + Command removed = commands.remove(command); if (removed != null) - removed.unregister(COMMAND_MAP); + removed.unregister(commandMap); } @Override public @NotNull Map getCommands() { - return COMMANDS; + return ReflectionUtil.getFieldValue(COMMANDS, getCommandMap()); } } From 519250dbf6e04ccb244cc9b1388152d84c126d26 Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Thu, 14 Nov 2024 18:58:01 -0300 Subject: [PATCH 37/73] added the RequiredSenderType annotation --- .../command/annotation/RequiredSenderType.java | 15 +++++++++++++++ .../registered/RegisteredMethodCommand.java | 10 ++++++++++ 2 files changed, 25 insertions(+) create mode 100644 commands/src/main/java/com/wizardlybump17/wlib/command/annotation/RequiredSenderType.java diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/annotation/RequiredSenderType.java b/commands/src/main/java/com/wizardlybump17/wlib/command/annotation/RequiredSenderType.java new file mode 100644 index 00000000..23b76cb8 --- /dev/null +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/annotation/RequiredSenderType.java @@ -0,0 +1,15 @@ +package com.wizardlybump17.wlib.command.annotation; + +import org.jetbrains.annotations.NotNull; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +@Target(ElementType.METHOD) +@Retention(RetentionPolicy.RUNTIME) +public @interface RequiredSenderType { + + @NotNull Class value(); +} diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/registered/RegisteredMethodCommand.java b/commands/src/main/java/com/wizardlybump17/wlib/command/registered/RegisteredMethodCommand.java index 721860f0..32cd5520 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/registered/RegisteredMethodCommand.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/registered/RegisteredMethodCommand.java @@ -1,8 +1,10 @@ package com.wizardlybump17.wlib.command.registered; import com.wizardlybump17.wlib.command.Argument; +import com.wizardlybump17.wlib.command.CommandSender; import com.wizardlybump17.wlib.command.Description; import com.wizardlybump17.wlib.command.annotation.Command; +import com.wizardlybump17.wlib.command.annotation.RequiredSenderType; import com.wizardlybump17.wlib.command.args.ArgsNode; import com.wizardlybump17.wlib.command.args.ArgsReaderRegistry; import com.wizardlybump17.wlib.command.args.ArgsReaderType; @@ -12,6 +14,7 @@ import com.wizardlybump17.wlib.command.executor.CommandExecutor; import lombok.Getter; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import java.lang.invoke.MethodHandle; import java.lang.invoke.MethodHandles; @@ -29,6 +32,7 @@ public class RegisteredMethodCommand extends RegisteredCommand { private final @NotNull Object object; private final @NotNull Method method; private final @NotNull MethodHandle methodHandle; + private final @Nullable RequiredSenderType requiredSenderType; public RegisteredMethodCommand(@NotNull Command annotation, @NotNull Object object, @NotNull Method method) throws NoSuchMethodException, IllegalAccessException { super( @@ -43,6 +47,7 @@ public RegisteredMethodCommand(@NotNull Command annotation, @NotNull Object obje this.method = method; methodHandle = MethodHandles.publicLookup().findVirtual(object.getClass(), method.getName(), MethodType.methodType(method.getReturnType(), method.getParameterTypes())); prepareNodes(); + requiredSenderType = method.getAnnotation(RequiredSenderType.class); } @Override @@ -120,4 +125,9 @@ private static String trim(String string) { private static boolean isRequiredArgs(String string) { return string.startsWith("<") && string.endsWith(">"); } + + @Override + public boolean canExecute(@NotNull CommandSender sender) { + return requiredSenderType == null || requiredSenderType.value().isInstance(sender); + } } \ No newline at end of file From 9417cd907b707e4628f6d4bfacdda9edd4aa2800 Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Thu, 14 Nov 2024 19:01:29 -0300 Subject: [PATCH 38/73] moved the sender check to the RegisteredCommand --- .../command/registered/RegisteredCommand.java | 10 +++++++--- .../registered/RegisteredMethodCommand.java | 16 +++++++--------- 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/registered/RegisteredCommand.java b/commands/src/main/java/com/wizardlybump17/wlib/command/registered/RegisteredCommand.java index 03a6faac..911f9fdb 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/registered/RegisteredCommand.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/registered/RegisteredCommand.java @@ -10,6 +10,7 @@ import com.wizardlybump17.wlib.command.executor.CommandExecutor; import com.wizardlybump17.wlib.util.StringUtil; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import java.util.LinkedHashMap; import java.util.List; @@ -20,16 +21,19 @@ public class RegisteredCommand implements Comparable { private final @NotNull CommandData command; private final @NotNull List nodes; private final @NotNull CommandExecutor executor; + private final @Nullable Class requiredSenderType; - public RegisteredCommand(@NotNull CommandData command, @NotNull List nodes, @NotNull CommandExecutor executor) { + public RegisteredCommand(@NotNull CommandData command, @NotNull List nodes, @NotNull CommandExecutor executor, @Nullable Class requiredSenderType) { this.command = command; this.nodes = nodes; this.executor = executor; + this.requiredSenderType = requiredSenderType; } - protected RegisteredCommand(@NotNull CommandData command, @NotNull List nodes) { + protected RegisteredCommand(@NotNull CommandData command, @NotNull List nodes, @Nullable Class requiredSenderType) { this.command = command; this.nodes = nodes; + this.requiredSenderType = requiredSenderType; executor = createExecutor(); } @@ -106,7 +110,7 @@ protected boolean isValidArgs(@NotNull LinkedHashMap args) { } public boolean canExecute(@NotNull CommandSender sender) { - return true; + return requiredSenderType == null || requiredSenderType.isInstance(sender.getHandle()); } @Override diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/registered/RegisteredMethodCommand.java b/commands/src/main/java/com/wizardlybump17/wlib/command/registered/RegisteredMethodCommand.java index 32cd5520..dba6d9ee 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/registered/RegisteredMethodCommand.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/registered/RegisteredMethodCommand.java @@ -1,7 +1,6 @@ package com.wizardlybump17.wlib.command.registered; import com.wizardlybump17.wlib.command.Argument; -import com.wizardlybump17.wlib.command.CommandSender; import com.wizardlybump17.wlib.command.Description; import com.wizardlybump17.wlib.command.annotation.Command; import com.wizardlybump17.wlib.command.annotation.RequiredSenderType; @@ -32,7 +31,6 @@ public class RegisteredMethodCommand extends RegisteredCommand { private final @NotNull Object object; private final @NotNull Method method; private final @NotNull MethodHandle methodHandle; - private final @Nullable RequiredSenderType requiredSenderType; public RegisteredMethodCommand(@NotNull Command annotation, @NotNull Object object, @NotNull Method method) throws NoSuchMethodException, IllegalAccessException { super( @@ -40,14 +38,19 @@ public RegisteredMethodCommand(@NotNull Command annotation, @NotNull Object obje annotation, object ), - new ArrayList<>() + new ArrayList<>(), + getRequireSenderType(method) ); this.annotation = annotation; this.object = object; this.method = method; methodHandle = MethodHandles.publicLookup().findVirtual(object.getClass(), method.getName(), MethodType.methodType(method.getReturnType(), method.getParameterTypes())); prepareNodes(); - requiredSenderType = method.getAnnotation(RequiredSenderType.class); + } + + protected static @Nullable Class getRequireSenderType(@NotNull Method method) { + RequiredSenderType type = method.getAnnotation(RequiredSenderType.class); + return type == null ? null : type.value(); } @Override @@ -125,9 +128,4 @@ private static String trim(String string) { private static boolean isRequiredArgs(String string) { return string.startsWith("<") && string.endsWith(">"); } - - @Override - public boolean canExecute(@NotNull CommandSender sender) { - return requiredSenderType == null || requiredSenderType.value().isInstance(sender); - } } \ No newline at end of file From c45cd78b077124f739231aca7bb6966a60e28af9 Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Thu, 14 Nov 2024 19:03:38 -0300 Subject: [PATCH 39/73] moved the sender type requirement to the CommandData interface --- .../wizardlybump17/wlib/command/data/CommandData.java | 7 +++++++ .../wlib/command/registered/RegisteredCommand.java | 11 ++++------- .../command/registered/RegisteredMethodCommand.java | 10 +--------- 3 files changed, 12 insertions(+), 16 deletions(-) diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/data/CommandData.java b/commands/src/main/java/com/wizardlybump17/wlib/command/data/CommandData.java index bf0c98e2..b6eb9874 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/data/CommandData.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/data/CommandData.java @@ -67,4 +67,11 @@ default int getPriority() { default @NotNull String getName() { return getExecution().split(" ")[0]; } + + /** + * @return the {@link CommandSender#getHandle()} that can execute this command + */ + default @Nullable Class getSenderHandleType() { + return null; + } } diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/registered/RegisteredCommand.java b/commands/src/main/java/com/wizardlybump17/wlib/command/registered/RegisteredCommand.java index 911f9fdb..e7e0c6c0 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/registered/RegisteredCommand.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/registered/RegisteredCommand.java @@ -10,7 +10,6 @@ import com.wizardlybump17.wlib.command.executor.CommandExecutor; import com.wizardlybump17.wlib.util.StringUtil; import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; import java.util.LinkedHashMap; import java.util.List; @@ -21,19 +20,16 @@ public class RegisteredCommand implements Comparable { private final @NotNull CommandData command; private final @NotNull List nodes; private final @NotNull CommandExecutor executor; - private final @Nullable Class requiredSenderType; - public RegisteredCommand(@NotNull CommandData command, @NotNull List nodes, @NotNull CommandExecutor executor, @Nullable Class requiredSenderType) { + public RegisteredCommand(@NotNull CommandData command, @NotNull List nodes, @NotNull CommandExecutor executor) { this.command = command; this.nodes = nodes; this.executor = executor; - this.requiredSenderType = requiredSenderType; } - protected RegisteredCommand(@NotNull CommandData command, @NotNull List nodes, @Nullable Class requiredSenderType) { + protected RegisteredCommand(@NotNull CommandData command, @NotNull List nodes) { this.command = command; this.nodes = nodes; - this.requiredSenderType = requiredSenderType; executor = createExecutor(); } @@ -110,7 +106,8 @@ protected boolean isValidArgs(@NotNull LinkedHashMap args) { } public boolean canExecute(@NotNull CommandSender sender) { - return requiredSenderType == null || requiredSenderType.isInstance(sender.getHandle()); + Class type = command.getSenderHandleType(); + return type == null || type.isInstance(sender); } @Override diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/registered/RegisteredMethodCommand.java b/commands/src/main/java/com/wizardlybump17/wlib/command/registered/RegisteredMethodCommand.java index dba6d9ee..721860f0 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/registered/RegisteredMethodCommand.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/registered/RegisteredMethodCommand.java @@ -3,7 +3,6 @@ import com.wizardlybump17.wlib.command.Argument; import com.wizardlybump17.wlib.command.Description; import com.wizardlybump17.wlib.command.annotation.Command; -import com.wizardlybump17.wlib.command.annotation.RequiredSenderType; import com.wizardlybump17.wlib.command.args.ArgsNode; import com.wizardlybump17.wlib.command.args.ArgsReaderRegistry; import com.wizardlybump17.wlib.command.args.ArgsReaderType; @@ -13,7 +12,6 @@ import com.wizardlybump17.wlib.command.executor.CommandExecutor; import lombok.Getter; import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; import java.lang.invoke.MethodHandle; import java.lang.invoke.MethodHandles; @@ -38,8 +36,7 @@ public RegisteredMethodCommand(@NotNull Command annotation, @NotNull Object obje annotation, object ), - new ArrayList<>(), - getRequireSenderType(method) + new ArrayList<>() ); this.annotation = annotation; this.object = object; @@ -48,11 +45,6 @@ public RegisteredMethodCommand(@NotNull Command annotation, @NotNull Object obje prepareNodes(); } - protected static @Nullable Class getRequireSenderType(@NotNull Method method) { - RequiredSenderType type = method.getAnnotation(RequiredSenderType.class); - return type == null ? null : type.value(); - } - @Override protected CommandExecutor createExecutor() { return (sender, args) -> { From ecbdb5c3a37560541f61791847d4ae4cfb40cd4c Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Thu, 14 Nov 2024 19:05:56 -0300 Subject: [PATCH 40/73] deleted the unused file --- .../command/annotation/RequiredSenderType.java | 15 --------------- 1 file changed, 15 deletions(-) delete mode 100644 commands/src/main/java/com/wizardlybump17/wlib/command/annotation/RequiredSenderType.java diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/annotation/RequiredSenderType.java b/commands/src/main/java/com/wizardlybump17/wlib/command/annotation/RequiredSenderType.java deleted file mode 100644 index 23b76cb8..00000000 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/annotation/RequiredSenderType.java +++ /dev/null @@ -1,15 +0,0 @@ -package com.wizardlybump17.wlib.command.annotation; - -import org.jetbrains.annotations.NotNull; - -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -@Target(ElementType.METHOD) -@Retention(RetentionPolicy.RUNTIME) -public @interface RequiredSenderType { - - @NotNull Class value(); -} From a874f8aaf7b4f3ea39f3dc32b07ae3f87ac5dec8 Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Thu, 14 Nov 2024 19:06:21 -0300 Subject: [PATCH 41/73] improved the sender checking --- .../com/wizardlybump17/wlib/command/annotation/Command.java | 6 ++++++ .../wlib/command/data/AnnotationCommandData.java | 4 ++++ .../com/wizardlybump17/wlib/command/data/CommandData.java | 4 ++-- .../wlib/command/registered/RegisteredCommand.java | 3 +-- 4 files changed, 13 insertions(+), 4 deletions(-) diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/annotation/Command.java b/commands/src/main/java/com/wizardlybump17/wlib/command/annotation/Command.java index 1009d78b..1628fcf0 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/annotation/Command.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/annotation/Command.java @@ -1,6 +1,7 @@ package com.wizardlybump17.wlib.command.annotation; import com.wizardlybump17.wlib.command.CommandSender; +import org.jetbrains.annotations.NotNull; import java.lang.annotation.ElementType; import java.lang.annotation.Retention; @@ -83,4 +84,9 @@ * @return if the {@link #invalidSenderMessage()} is a field in the class that have this annotation */ boolean invalidSenderMessageIsField() default false; + + /** + * @return the type of the {@link CommandSender#getHandle()} that can execute this command + */ + @NotNull Class senderType() default Object.class; } diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/data/AnnotationCommandData.java b/commands/src/main/java/com/wizardlybump17/wlib/command/data/AnnotationCommandData.java index b659ea2e..38fc9b9b 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/data/AnnotationCommandData.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/data/AnnotationCommandData.java @@ -71,6 +71,10 @@ public int getPriority() { return annotation; } + @Override + public @NotNull Class getSenderType() { + return annotation.senderType(); + } @Override public boolean equals(Object object1) { diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/data/CommandData.java b/commands/src/main/java/com/wizardlybump17/wlib/command/data/CommandData.java index b6eb9874..504eb6c9 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/data/CommandData.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/data/CommandData.java @@ -71,7 +71,7 @@ default int getPriority() { /** * @return the {@link CommandSender#getHandle()} that can execute this command */ - default @Nullable Class getSenderHandleType() { - return null; + default @NotNull Class getSenderType() { + return Object.class; } } diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/registered/RegisteredCommand.java b/commands/src/main/java/com/wizardlybump17/wlib/command/registered/RegisteredCommand.java index e7e0c6c0..dc438338 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/registered/RegisteredCommand.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/registered/RegisteredCommand.java @@ -106,8 +106,7 @@ protected boolean isValidArgs(@NotNull LinkedHashMap args) { } public boolean canExecute(@NotNull CommandSender sender) { - Class type = command.getSenderHandleType(); - return type == null || type.isInstance(sender); + return command.getSenderType().isInstance(sender); } @Override From 04af805ab1bdc5df68ceba8fa51ca6d7583bfd3f Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Thu, 14 Nov 2024 21:58:46 -0300 Subject: [PATCH 42/73] fixed the RegisteredCommand#canExecute(CommandSender) method by checking the CommandSender#getHandle() --- .../wlib/command/registered/RegisteredCommand.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/registered/RegisteredCommand.java b/commands/src/main/java/com/wizardlybump17/wlib/command/registered/RegisteredCommand.java index dc438338..bb7d19a6 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/registered/RegisteredCommand.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/registered/RegisteredCommand.java @@ -106,7 +106,7 @@ protected boolean isValidArgs(@NotNull LinkedHashMap args) { } public boolean canExecute(@NotNull CommandSender sender) { - return command.getSenderType().isInstance(sender); + return command.getSenderType().isInstance(sender.getHandle()); } @Override From 4ba17578fa31f03e25268462e584ac9e7c9adcae Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Fri, 15 Nov 2024 00:45:30 -0300 Subject: [PATCH 43/73] made CommandData be an abstract class --- .../command/data/AnnotationCommandData.java | 12 ++++++------ .../wlib/command/data/CommandData.java | 18 +++++++++--------- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/data/AnnotationCommandData.java b/commands/src/main/java/com/wizardlybump17/wlib/command/data/AnnotationCommandData.java index 38fc9b9b..e45d26f0 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/data/AnnotationCommandData.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/data/AnnotationCommandData.java @@ -10,7 +10,7 @@ import java.util.Map; import java.util.Objects; -public class AnnotationCommandData implements CommandData { +public class AnnotationCommandData extends CommandData { private final @NotNull Command annotation; private final @NotNull Object object; @@ -29,29 +29,29 @@ public AnnotationCommandData(@NotNull Command annotation, @NotNull Object object @Override public @Nullable String getPermission() { String permission = annotation.permission(); - return permission.isBlank() ? CommandData.super.getPermission() : permission; + return permission.isBlank() ? super.getPermission() : permission; } @Override public @Nullable String getPermissionMessage() { - return getMessage(annotation.permissionMessage(), annotation.permissionMessageIsField(), CommandData.super.getPermissionMessage()); + return getMessage(annotation.permissionMessage(), annotation.permissionMessageIsField(), super.getPermissionMessage()); } @Override public int getPriority() { int priority = annotation.priority(); - return priority == -1 ? CommandData.super.getPriority() : priority; + return priority == -1 ? super.getPriority() : priority; } @Override public @Nullable String getDescription() { String description = annotation.description(); - return description.isBlank() ? CommandData.super.getDescription() : description; + return description.isBlank() ? super.getDescription() : description; } @Override public @Nullable String getInvalidSenderMessage() { - return getMessage(annotation.invalidSenderMessage(), annotation.invalidSenderMessageIsField(), CommandData.super.getInvalidSenderMessage()); + return getMessage(annotation.invalidSenderMessage(), annotation.invalidSenderMessageIsField(), super.getInvalidSenderMessage()); } protected @Nullable String getMessage(@NotNull String message, boolean isField, @Nullable String defaultMessage) { diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/data/CommandData.java b/commands/src/main/java/com/wizardlybump17/wlib/command/data/CommandData.java index 504eb6c9..c38112cb 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/data/CommandData.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/data/CommandData.java @@ -4,7 +4,7 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -public interface CommandData { +public abstract class CommandData { /** *

How the sender must type the command in order for it to be triggered. @@ -25,12 +25,12 @@ public interface CommandData { * @return how the command must be sent to be triggered * @see com.wizardlybump17.wlib.command.args.reader.ArgsReader */ - @NotNull String getExecution(); + public abstract @NotNull String getExecution(); /** * @return which permission the sender must have to trigger this command */ - default @Nullable String getPermission() { + public @Nullable String getPermission() { return null; } @@ -38,21 +38,21 @@ public interface CommandData { *

Used when the {@link CommandSender} does not have the required {@link #getPermission()}.

* @return the message to be sent when the {@link CommandSender} does not have the required {@link #getPermission()} */ - default @Nullable String getPermissionMessage() { + public @Nullable String getPermissionMessage() { return null; } /** * @return the priority of this command */ - default int getPriority() { + public int getPriority() { return getExecution().split(" ").length; } /** * @return the description of this command */ - default @Nullable String getDescription() { + public @Nullable String getDescription() { return null; } @@ -60,18 +60,18 @@ default int getPriority() { *

Used when the {@link CommandSender} is not valid for this command.

* @return the message to be sent when the {@link CommandSender} is not valid for this command */ - default @Nullable String getInvalidSenderMessage() { + public @Nullable String getInvalidSenderMessage() { return null; } - default @NotNull String getName() { + public final @NotNull String getName() { return getExecution().split(" ")[0]; } /** * @return the {@link CommandSender#getHandle()} that can execute this command */ - default @NotNull Class getSenderType() { + public @NotNull Class getSenderType() { return Object.class; } } From 25b9e5bd66d01c142273cfdfd9a29a1ffb76502c Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Fri, 15 Nov 2024 00:45:58 -0300 Subject: [PATCH 44/73] added the SimpleCommandData system --- .../wlib/command/data/CommandData.java | 4 + .../wlib/command/data/SimpleCommandData.java | 151 ++++++++++++++++++ 2 files changed, 155 insertions(+) create mode 100644 commands/src/main/java/com/wizardlybump17/wlib/command/data/SimpleCommandData.java diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/data/CommandData.java b/commands/src/main/java/com/wizardlybump17/wlib/command/data/CommandData.java index c38112cb..4d32e6d8 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/data/CommandData.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/data/CommandData.java @@ -74,4 +74,8 @@ public int getPriority() { public @NotNull Class getSenderType() { return Object.class; } + + public static @NotNull SimpleCommandData.Builder builder() { + return new SimpleCommandData.Builder(); + } } diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/data/SimpleCommandData.java b/commands/src/main/java/com/wizardlybump17/wlib/command/data/SimpleCommandData.java new file mode 100644 index 00000000..f26df07f --- /dev/null +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/data/SimpleCommandData.java @@ -0,0 +1,151 @@ +package com.wizardlybump17.wlib.command.data; + +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import java.util.Objects; + +public class SimpleCommandData extends CommandData { + + private final @NotNull String execution; + private final @Nullable String permission; + private final @Nullable String permissionMessage; + private final int priority; + private final @Nullable String description; + private final @Nullable String invalidSenderMessage; + private final @NotNull Class senderType; + + public SimpleCommandData(@NotNull String execution, @Nullable String permission, @Nullable String permissionMessage, int priority, @Nullable String description, @Nullable String invalidSenderMessage, @NotNull Class senderType) { + this.execution = execution; + this.permission = permission; + this.permissionMessage = permissionMessage; + this.priority = priority; + this.description = description; + this.invalidSenderMessage = invalidSenderMessage; + this.senderType = senderType; + } + + @Override + public @NotNull String getExecution() { + return execution; + } + + @Override + public @Nullable String getPermission() { + return permission; + } + + @Override + public @Nullable String getPermissionMessage() { + return permissionMessage; + } + + @Override + public int getPriority() { + return priority; + } + + @Override + public @Nullable String getDescription() { + return description; + } + + @Override + public @Nullable String getInvalidSenderMessage() { + return invalidSenderMessage; + } + + @Override + public @NotNull Class getSenderType() { + return senderType; + } + + public static class Builder { + + Builder() { + } + + private @Nullable String execution; + private @Nullable String permission; + private @Nullable String permissionMessage; + private @Nullable Integer priority; + private @Nullable String description; + private @Nullable String invalidSenderMessage; + private @Nullable Class senderType; + + public @Nullable String execution() { + return execution; + } + + public @NotNull Builder execution(@Nullable String execution) { + this.execution = execution; + return this; + } + + public @Nullable String permission() { + return permission; + } + + public @NotNull Builder permission(@Nullable String permission) { + this.permission = permission; + return this; + } + + public @Nullable String permissionMessage() { + return permissionMessage; + } + + public @NotNull Builder permissionMessage(@Nullable String permissionMessage) { + this.permissionMessage = permissionMessage; + return this; + } + + public @Nullable Integer priority() { + return priority; + } + + public @NotNull Builder priority(@Nullable Integer priority) { + this.priority = priority; + return this; + } + + public @Nullable String description() { + return description; + } + + public @NotNull Builder description(@Nullable String description) { + this.description = description; + return this; + } + + public @Nullable String invalidSenderMessage() { + return invalidSenderMessage; + } + + public @NotNull Builder invalidSenderMessage(@Nullable String invalidSenderMessage) { + this.invalidSenderMessage = invalidSenderMessage; + return this; + } + + public @Nullable Class senderType() { + return senderType; + } + + public @NotNull Builder senderType(@Nullable Class senderType) { + this.senderType = senderType; + return this; + } + + public @NotNull CommandData build() { + return new SimpleCommandData( + Objects.requireNonNull(execution, "The execution can not be null"), + permission, + permissionMessage, + priority == null ? execution.split(" ").length : priority, + description, + invalidSenderMessage, + senderType == null ? Object.class : senderType + ); + } + } +} From 9052f1f68ec3c5427e6059f8e282d74365332234 Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Fri, 15 Nov 2024 18:03:47 -0300 Subject: [PATCH 45/73] added the ArgsNode.userInput(String, ArgsReader) method --- .../java/com/wizardlybump17/wlib/command/args/ArgsNode.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/args/ArgsNode.java b/commands/src/main/java/com/wizardlybump17/wlib/command/args/ArgsNode.java index f0149eb2..daf4b08b 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/args/ArgsNode.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/args/ArgsNode.java @@ -46,4 +46,8 @@ public Object parse(String input) throws ArgsReaderException { public static @NotNull ArgsNode literal(@NotNull String string) { return new ArgsNode(string, false, null, null, false); } + + public static @NotNull ArgsNode userInput(@NotNull String name, @NotNull ArgsReader reader) { + return new ArgsNode(name, true, reader, null, false); + } } From f3eb68a990f9103fc3c3fb0ba975fa8b7b463cca Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Fri, 15 Nov 2024 18:13:44 -0300 Subject: [PATCH 46/73] added the CommandSender#hasId(UUID) method --- .../wlib/bungee/command/sender/CommandSender.java | 7 +++++++ .../com/wizardlybump17/wlib/command/CommandSender.java | 6 ++++++ .../wizardlybump17/wlib/command/sender/CommandSender.java | 8 ++++++++ 3 files changed, 21 insertions(+) diff --git a/bungee/src/main/java/com/wizardlybump17/wlib/bungee/command/sender/CommandSender.java b/bungee/src/main/java/com/wizardlybump17/wlib/bungee/command/sender/CommandSender.java index ef0ddda4..2796fa68 100644 --- a/bungee/src/main/java/com/wizardlybump17/wlib/bungee/command/sender/CommandSender.java +++ b/bungee/src/main/java/com/wizardlybump17/wlib/bungee/command/sender/CommandSender.java @@ -6,6 +6,8 @@ import net.md_5.bungee.api.connection.ProxiedPlayer; import org.jetbrains.annotations.NotNull; +import java.util.UUID; + @RequiredArgsConstructor public class CommandSender implements com.wizardlybump17.wlib.command.CommandSender { @@ -43,4 +45,9 @@ public boolean hasPermission(String permission) { public @NotNull ConnectedPlayer asConnectedPlayer() { return (ConnectedPlayer) handle; } + + @Override + public boolean hasId(@NotNull UUID id) { + return handle instanceof ProxiedPlayer player && player.getUniqueId().equals(id); + } } diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/CommandSender.java b/commands/src/main/java/com/wizardlybump17/wlib/command/CommandSender.java index 127a3037..29f36f6c 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/CommandSender.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/CommandSender.java @@ -1,5 +1,9 @@ package com.wizardlybump17.wlib.command; +import org.jetbrains.annotations.NotNull; + +import java.util.UUID; + /** * Represents a command sender, someone that can trigger commands. * @@ -19,4 +23,6 @@ public interface CommandSender { String getName(); boolean hasPermission(String permission); + + boolean hasId(@NotNull UUID id); } diff --git a/core/src/main/java/com/wizardlybump17/wlib/command/sender/CommandSender.java b/core/src/main/java/com/wizardlybump17/wlib/command/sender/CommandSender.java index db06a313..4d25ce26 100644 --- a/core/src/main/java/com/wizardlybump17/wlib/command/sender/CommandSender.java +++ b/core/src/main/java/com/wizardlybump17/wlib/command/sender/CommandSender.java @@ -2,9 +2,12 @@ import org.bukkit.command.BlockCommandSender; import org.bukkit.command.ConsoleCommandSender; +import org.bukkit.entity.Entity; import org.bukkit.entity.Player; import org.jetbrains.annotations.NotNull; +import java.util.UUID; + public class CommandSender implements com.wizardlybump17.wlib.command.CommandSender { private final @NotNull org.bukkit.command.CommandSender handle; @@ -49,4 +52,9 @@ public boolean hasPermission(String permission) { public @NotNull Player asPlayer() { return (Player) handle; } + + @Override + public boolean hasId(@NotNull UUID id) { + return handle instanceof Entity entity && entity.getUniqueId().equals(id); + } } From 8fac630155375ef80d1402d3d7eb90a18ddb82c6 Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Fri, 15 Nov 2024 19:20:04 -0300 Subject: [PATCH 47/73] added the ArgsNode.userInput(String, Class) method --- .../java/com/wizardlybump17/wlib/command/args/ArgsNode.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/args/ArgsNode.java b/commands/src/main/java/com/wizardlybump17/wlib/command/args/ArgsNode.java index daf4b08b..23d07d47 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/args/ArgsNode.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/args/ArgsNode.java @@ -50,4 +50,8 @@ public Object parse(String input) throws ArgsReaderException { public static @NotNull ArgsNode userInput(@NotNull String name, @NotNull ArgsReader reader) { return new ArgsNode(name, true, reader, null, false); } + + public static @NotNull ArgsNode userInput(@NotNull String name, @NotNull Class type) { + return userInput(name, ArgsReaderRegistry.INSTANCE.getReader(type)); + } } From 421a46f3d8bcb1406c496f3a0c75d5cdae05528a Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Fri, 15 Nov 2024 21:35:36 -0300 Subject: [PATCH 48/73] using the CommandManager to execute the command instead --- .../command/registered/RegisteredBukkitCommand.java | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/core/src/main/java/com/wizardlybump17/wlib/command/registered/RegisteredBukkitCommand.java b/core/src/main/java/com/wizardlybump17/wlib/command/registered/RegisteredBukkitCommand.java index b303c099..ef9f9b61 100644 --- a/core/src/main/java/com/wizardlybump17/wlib/command/registered/RegisteredBukkitCommand.java +++ b/core/src/main/java/com/wizardlybump17/wlib/command/registered/RegisteredBukkitCommand.java @@ -13,6 +13,7 @@ import java.util.List; import java.util.logging.Level; +import java.util.logging.Logger; public class RegisteredBukkitCommand extends RegisteredCommand { @@ -30,13 +31,16 @@ public RegisteredBukkitCommand(@NotNull CommandData command, @NotNull List Date: Fri, 15 Nov 2024 21:35:56 -0300 Subject: [PATCH 49/73] removed the unused field --- .../java/com/wizardlybump17/wlib/command/CommandManager.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/CommandManager.java b/commands/src/main/java/com/wizardlybump17/wlib/command/CommandManager.java index 1a1888f2..cb4cda0f 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/CommandManager.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/CommandManager.java @@ -11,7 +11,6 @@ import lombok.NonNull; import org.jetbrains.annotations.NotNull; -import java.lang.reflect.Field; import java.util.*; @Getter @@ -19,7 +18,6 @@ public class CommandManager { private final List commands = new ArrayList<>(); protected final CommandHolder holder; - private final @NonNull Map, Map> fieldCache = new HashMap<>(); private final @NotNull Set commandExtractors = new HashSet<>(); public CommandManager(@NotNull CommandHolder holder) { From faadaeab23290e8bc81979292504ec2c30725384 Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Fri, 15 Nov 2024 21:45:52 -0300 Subject: [PATCH 50/73] made the CommandManager store commands using a Map where the key is the command name. Removed lombok --- .../wlib/command/CommandManager.java | 82 +++++++++++-------- 1 file changed, 48 insertions(+), 34 deletions(-) diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/CommandManager.java b/commands/src/main/java/com/wizardlybump17/wlib/command/CommandManager.java index cb4cda0f..09eedbe5 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/CommandManager.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/CommandManager.java @@ -7,17 +7,14 @@ import com.wizardlybump17.wlib.command.extractor.MethodCommandExtractor; import com.wizardlybump17.wlib.command.holder.CommandHolder; import com.wizardlybump17.wlib.command.registered.RegisteredCommand; -import lombok.Getter; -import lombok.NonNull; import org.jetbrains.annotations.NotNull; import java.util.*; -@Getter public class CommandManager { - private final List commands = new ArrayList<>(); - protected final CommandHolder holder; + private final @NotNull Map> commands = new HashMap<>(); + protected final @NotNull CommandHolder holder; private final @NotNull Set commandExtractors = new HashSet<>(); public CommandManager(@NotNull CommandHolder holder) { @@ -26,33 +23,41 @@ public CommandManager(@NotNull CommandHolder holder) { commandExtractors.add(new DirectCommandExtractor()); } - public void registerCommands(Object... objects) { - for (Object object : objects) { - for (CommandExtractor extractor : commandExtractors) { - List commands = extractor.extract(this, holder, object); - commands.forEach(command -> command.onRegister(this)); - this.commands.addAll(commands); - } - } - commands.sort(null); + public void registerCommands(@NotNull Object @NotNull ... objects) { + for (Object object : objects) + for (CommandExtractor extractor : commandExtractors) + registerCommands(extractor.extract(this, holder, object)); } public void registerCommands(@NotNull Collection commands) { - commands.forEach(command -> command.onRegister(this)); - this.commands.addAll(commands); - this.commands.sort(null); + commands.forEach(this::registerCommand); + } + + public void registerCommand(@NotNull RegisteredCommand command) { + command.onRegister(this); + commands.computeIfAbsent(command.getName().toLowerCase(), $ -> new TreeSet<>()).add(command); } public void unregisterCommands() { - commands.forEach(command -> command.onUnregister(this)); + commands.forEach((name, commands) -> { + commands.forEach(command -> command.onUnregister(this)); + commands.clear(); + }); commands.clear(); } - public void execute(CommandSender sender, String string) throws CommandException { + public void execute(@NotNull CommandSender sender, @NotNull String string) throws CommandException { if (commands.isEmpty()) return; - for (RegisteredCommand registeredCommand : commands) { + int spaceIndex = string.indexOf(' '); + String name; + if (spaceIndex == -1) + name = string; + else + name = string.substring(0, spaceIndex); + + for (RegisteredCommand registeredCommand : commands.getOrDefault(name, Set.of())) { CommandData command = registeredCommand.getCommand(); CommandResult result = registeredCommand.execute(sender, string); @@ -78,24 +83,33 @@ public void execute(CommandSender sender, String string) throws CommandExcept } } - @NonNull - public List<@NonNull String> autoComplete(@NonNull CommandSender sender, @NonNull String string) { + public @NotNull List<@NotNull String> autoComplete(@NotNull CommandSender sender, @NotNull String string) { return List.of(); } - public List getCommand(String name) { - List commands = new ArrayList<>(this.commands.size()); - for (RegisteredCommand command : this.commands) - if (command.getName().equalsIgnoreCase(name)) - commands.add(command); - return commands; + public @NotNull List getCommands(@NotNull String name) { + Set commands = this.commands.get(name); + return commands == null ? List.of() : List.copyOf(commands); + } + + public @NotNull List getCommands(@NotNull Object object) { + List result = new ArrayList<>(commands.size()); + for (Set commands : this.commands.values()) + for (RegisteredCommand command : commands) + if (command.isOwnedBy(object)) + result.add(command); + return result; + } + + public @NotNull CommandHolder getHolder() { + return holder; + } + + public @NotNull Map> getCommands() { + return Map.copyOf(commands); } - public List getCommands(@NotNull Object object) { - List commands = new ArrayList<>(this.commands.size()); - for (RegisteredCommand command : this.commands) - if (command.isOwnedBy(object)) - commands.add(command); - return commands; + public @NotNull Set getCommandExtractors() { + return Set.copyOf(commandExtractors); } } \ No newline at end of file From 7f15598907a48a7d307600c82fea1f0b2c682b95 Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Fri, 15 Nov 2024 21:46:04 -0300 Subject: [PATCH 51/73] annotated with NotNull --- .../wlib/bungee/command/BungeeCommandManager.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/bungee/src/main/java/com/wizardlybump17/wlib/bungee/command/BungeeCommandManager.java b/bungee/src/main/java/com/wizardlybump17/wlib/bungee/command/BungeeCommandManager.java index 416de0ef..bfd1bafa 100644 --- a/bungee/src/main/java/com/wizardlybump17/wlib/bungee/command/BungeeCommandManager.java +++ b/bungee/src/main/java/com/wizardlybump17/wlib/bungee/command/BungeeCommandManager.java @@ -4,6 +4,7 @@ import com.wizardlybump17.wlib.command.registered.RegisteredCommand; import net.md_5.bungee.api.plugin.Command; import net.md_5.bungee.api.plugin.Plugin; +import org.jetbrains.annotations.NotNull; public class BungeeCommandManager extends CommandManager { @@ -12,7 +13,7 @@ public BungeeCommandManager(BungeeCommandHolder holder) { } @Override - public void registerCommands(Object... objects) { + public void registerCommands(@NotNull Object @NotNull ... objects) { super.registerCommands(objects); for (Object object : objects) { for (RegisteredCommand command : getCommands(object)) { From a83e178f74ab00688097137f9dc137fa861ed392 Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Fri, 15 Nov 2024 21:47:48 -0300 Subject: [PATCH 52/73] added methods to manipulate the CommandManager#getCommandExtractors() --- .../wizardlybump17/wlib/command/CommandManager.java | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/CommandManager.java b/commands/src/main/java/com/wizardlybump17/wlib/command/CommandManager.java index 09eedbe5..1594d6d9 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/CommandManager.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/CommandManager.java @@ -112,4 +112,16 @@ public void execute(@NotNull CommandSender sender, @NotNull String string) th public @NotNull Set getCommandExtractors() { return Set.copyOf(commandExtractors); } + + public void addCommandExtractor(@NotNull CommandExtractor extractor) { + commandExtractors.add(extractor); + } + + public void removeCommandExtractor(@NotNull CommandExtractor extractor) { + commandExtractors.remove(extractor); + } + + public boolean hasCommandExtractor(@NotNull CommandExtractor extractor) { + return commandExtractors.contains(extractor); + } } \ No newline at end of file From e7d02f136f98962f4bd026eaa500b95daa686335 Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Fri, 15 Nov 2024 22:00:31 -0300 Subject: [PATCH 53/73] using a List instead --- .../wlib/command/CommandManager.java | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/CommandManager.java b/commands/src/main/java/com/wizardlybump17/wlib/command/CommandManager.java index 1594d6d9..449d4636 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/CommandManager.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/CommandManager.java @@ -13,7 +13,7 @@ public class CommandManager { - private final @NotNull Map> commands = new HashMap<>(); + private final @NotNull Map> commands = new HashMap<>(); protected final @NotNull CommandHolder holder; private final @NotNull Set commandExtractors = new HashSet<>(); @@ -35,7 +35,9 @@ public void registerCommands(@NotNull Collection commands) { public void registerCommand(@NotNull RegisteredCommand command) { command.onRegister(this); - commands.computeIfAbsent(command.getName().toLowerCase(), $ -> new TreeSet<>()).add(command); + List commands = this.commands.computeIfAbsent(command.getName().toLowerCase(), $ -> new ArrayList<>()); + commands.add(command); + commands.sort(null); } public void unregisterCommands() { @@ -57,7 +59,7 @@ public void execute(@NotNull CommandSender sender, @NotNull String string) th else name = string.substring(0, spaceIndex); - for (RegisteredCommand registeredCommand : commands.getOrDefault(name, Set.of())) { + for (RegisteredCommand registeredCommand : commands.getOrDefault(name, List.of())) { CommandData command = registeredCommand.getCommand(); CommandResult result = registeredCommand.execute(sender, string); @@ -88,13 +90,13 @@ public void execute(@NotNull CommandSender sender, @NotNull String string) th } public @NotNull List getCommands(@NotNull String name) { - Set commands = this.commands.get(name); + List commands = this.commands.get(name); return commands == null ? List.of() : List.copyOf(commands); } public @NotNull List getCommands(@NotNull Object object) { List result = new ArrayList<>(commands.size()); - for (Set commands : this.commands.values()) + for (List commands : this.commands.values()) for (RegisteredCommand command : commands) if (command.isOwnedBy(object)) result.add(command); @@ -105,7 +107,7 @@ public void execute(@NotNull CommandSender sender, @NotNull String string) th return holder; } - public @NotNull Map> getCommands() { + public @NotNull Map> getCommands() { return Map.copyOf(commands); } From fb83f0bb9922704741860f9676c70229f4892048 Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Sat, 23 Nov 2024 20:56:25 -0300 Subject: [PATCH 54/73] moved to the proper package and renamed the classes implementing CommandSender --- .../wlib/bungee/command/BungeeCommandExecutor.java | 6 +++--- .../sender/{CommandSender.java => BungeeCommandSender.java} | 2 +- .../com/wizardlybump17/wlib/command/CommandManager.java | 1 + .../com/wizardlybump17/wlib/command/annotation/Command.java | 2 +- .../wizardlybump17/wlib/command/args/reader/ArgsReader.java | 2 +- .../wlib/command/args/reader/BooleanReader.java | 2 +- .../wizardlybump17/wlib/command/args/reader/ByteReader.java | 2 +- .../wlib/command/args/reader/DoubleReader.java | 2 +- .../wlib/command/args/reader/FloatReader.java | 2 +- .../wlib/command/args/reader/IntegerReader.java | 2 +- .../wlib/command/args/reader/ShortReader.java | 2 +- .../wlib/command/args/reader/StringReader.java | 2 +- .../wizardlybump17/wlib/command/args/reader/UUIDReader.java | 2 +- .../wlib/command/completer/ArgumentCompleter.java | 2 +- .../com/wizardlybump17/wlib/command/data/CommandData.java | 2 +- .../wlib/command/executor/CommandExecutor.java | 2 +- .../wlib/command/extractor/MethodCommandExtractor.java | 2 +- .../wizardlybump17/wlib/command/holder/CommandExecutor.java | 2 +- .../wlib/command/registered/RegisteredCommand.java | 2 +- .../wlib/command/{ => sender}/CommandSender.java | 2 +- .../wizardlybump17/wlib/command/BukkitCommandExecutor.java | 6 ++++-- .../wlib/command/completer/EntityTypeArgumentCompleter.java | 2 +- .../wlib/command/completer/MaterialArgumentCompleter.java | 2 +- .../wlib/command/completer/PlayerArgumentCompleter.java | 2 +- .../wlib/command/reader/BlockDataArgsReader.java | 2 +- .../wlib/command/reader/EntityTypeArgsReader.java | 2 +- .../wlib/command/reader/MapJsonArgsReader.java | 2 +- .../wizardlybump17/wlib/command/reader/MaterialReader.java | 2 +- .../wlib/command/reader/OfflinePlayerReader.java | 2 +- .../wizardlybump17/wlib/command/reader/PlayerReader.java | 2 +- .../wlib/command/registered/RegisteredBukkitCommand.java | 3 ++- .../sender/{CommandSender.java => BukkitCommandSender.java} | 4 ++-- 32 files changed, 39 insertions(+), 35 deletions(-) rename bungee/src/main/java/com/wizardlybump17/wlib/bungee/command/sender/{CommandSender.java => BungeeCommandSender.java} (91%) rename commands/src/main/java/com/wizardlybump17/wlib/command/{ => sender}/CommandSender.java (91%) rename core/src/main/java/com/wizardlybump17/wlib/command/sender/{CommandSender.java => BukkitCommandSender.java} (87%) diff --git a/bungee/src/main/java/com/wizardlybump17/wlib/bungee/command/BungeeCommandExecutor.java b/bungee/src/main/java/com/wizardlybump17/wlib/bungee/command/BungeeCommandExecutor.java index 743da1c2..cca749bd 100644 --- a/bungee/src/main/java/com/wizardlybump17/wlib/bungee/command/BungeeCommandExecutor.java +++ b/bungee/src/main/java/com/wizardlybump17/wlib/bungee/command/BungeeCommandExecutor.java @@ -1,6 +1,6 @@ package com.wizardlybump17.wlib.bungee.command; -import com.wizardlybump17.wlib.bungee.command.sender.CommandSender; +import com.wizardlybump17.wlib.bungee.command.sender.BungeeCommandSender; import com.wizardlybump17.wlib.command.CommandManager; import com.wizardlybump17.wlib.command.exception.CommandException; import com.wizardlybump17.wlib.command.holder.CommandExecutor; @@ -18,14 +18,14 @@ public BungeeCommandExecutor(CommandManager manager, String name) { } @Override - public void execute(com.wizardlybump17.wlib.command.CommandSender sender, String commandName, String[] args) throws CommandException { + public void execute(com.wizardlybump17.wlib.command.sender.CommandSender sender, String commandName, String[] args) throws CommandException { manager.execute(sender, commandName + " " + String.join(" ", args)); } @Override public void execute(net.md_5.bungee.api.CommandSender sender, String[] args) { try { - execute(new CommandSender(sender), getName(), args); + execute(new BungeeCommandSender(sender), getName(), args); } catch (CommandException e) { manager.getHolder().getLogger().log(Level.SEVERE, "Error while executing a command", e); } diff --git a/bungee/src/main/java/com/wizardlybump17/wlib/bungee/command/sender/CommandSender.java b/bungee/src/main/java/com/wizardlybump17/wlib/bungee/command/sender/BungeeCommandSender.java similarity index 91% rename from bungee/src/main/java/com/wizardlybump17/wlib/bungee/command/sender/CommandSender.java rename to bungee/src/main/java/com/wizardlybump17/wlib/bungee/command/sender/BungeeCommandSender.java index 2796fa68..702f31eb 100644 --- a/bungee/src/main/java/com/wizardlybump17/wlib/bungee/command/sender/CommandSender.java +++ b/bungee/src/main/java/com/wizardlybump17/wlib/bungee/command/sender/BungeeCommandSender.java @@ -9,7 +9,7 @@ import java.util.UUID; @RequiredArgsConstructor -public class CommandSender implements com.wizardlybump17.wlib.command.CommandSender { +public class BungeeCommandSender implements com.wizardlybump17.wlib.command.sender.CommandSender { private final net.md_5.bungee.api.CommandSender handle; diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/CommandManager.java b/commands/src/main/java/com/wizardlybump17/wlib/command/CommandManager.java index 449d4636..08bff110 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/CommandManager.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/CommandManager.java @@ -7,6 +7,7 @@ import com.wizardlybump17.wlib.command.extractor.MethodCommandExtractor; import com.wizardlybump17.wlib.command.holder.CommandHolder; import com.wizardlybump17.wlib.command.registered.RegisteredCommand; +import com.wizardlybump17.wlib.command.sender.CommandSender; import org.jetbrains.annotations.NotNull; import java.util.*; diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/annotation/Command.java b/commands/src/main/java/com/wizardlybump17/wlib/command/annotation/Command.java index 1628fcf0..b941b23b 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/annotation/Command.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/annotation/Command.java @@ -1,6 +1,6 @@ package com.wizardlybump17.wlib.command.annotation; -import com.wizardlybump17.wlib.command.CommandSender; +import com.wizardlybump17.wlib.command.sender.CommandSender; import org.jetbrains.annotations.NotNull; import java.lang.annotation.ElementType; diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/args/reader/ArgsReader.java b/commands/src/main/java/com/wizardlybump17/wlib/command/args/reader/ArgsReader.java index 3ca7ecee..d8a6fa5a 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/args/reader/ArgsReader.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/args/reader/ArgsReader.java @@ -1,6 +1,6 @@ package com.wizardlybump17.wlib.command.args.reader; -import com.wizardlybump17.wlib.command.CommandSender; +import com.wizardlybump17.wlib.command.sender.CommandSender; import lombok.NonNull; import org.jetbrains.annotations.Nullable; diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/args/reader/BooleanReader.java b/commands/src/main/java/com/wizardlybump17/wlib/command/args/reader/BooleanReader.java index ef854c6a..539558be 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/args/reader/BooleanReader.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/args/reader/BooleanReader.java @@ -1,6 +1,6 @@ package com.wizardlybump17.wlib.command.args.reader; -import com.wizardlybump17.wlib.command.CommandSender; +import com.wizardlybump17.wlib.command.sender.CommandSender; import lombok.NonNull; import java.util.List; diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/args/reader/ByteReader.java b/commands/src/main/java/com/wizardlybump17/wlib/command/args/reader/ByteReader.java index 6b7e920d..00c9056c 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/args/reader/ByteReader.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/args/reader/ByteReader.java @@ -1,6 +1,6 @@ package com.wizardlybump17.wlib.command.args.reader; -import com.wizardlybump17.wlib.command.CommandSender; +import com.wizardlybump17.wlib.command.sender.CommandSender; import lombok.NonNull; import java.util.List; diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/args/reader/DoubleReader.java b/commands/src/main/java/com/wizardlybump17/wlib/command/args/reader/DoubleReader.java index 9dd12592..b7c4f356 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/args/reader/DoubleReader.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/args/reader/DoubleReader.java @@ -1,6 +1,6 @@ package com.wizardlybump17.wlib.command.args.reader; -import com.wizardlybump17.wlib.command.CommandSender; +import com.wizardlybump17.wlib.command.sender.CommandSender; import lombok.NonNull; import java.util.List; diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/args/reader/FloatReader.java b/commands/src/main/java/com/wizardlybump17/wlib/command/args/reader/FloatReader.java index 1541cf68..f90a346a 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/args/reader/FloatReader.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/args/reader/FloatReader.java @@ -1,6 +1,6 @@ package com.wizardlybump17.wlib.command.args.reader; -import com.wizardlybump17.wlib.command.CommandSender; +import com.wizardlybump17.wlib.command.sender.CommandSender; import lombok.NonNull; import java.util.List; diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/args/reader/IntegerReader.java b/commands/src/main/java/com/wizardlybump17/wlib/command/args/reader/IntegerReader.java index 111c3c09..5123f358 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/args/reader/IntegerReader.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/args/reader/IntegerReader.java @@ -1,6 +1,6 @@ package com.wizardlybump17.wlib.command.args.reader; -import com.wizardlybump17.wlib.command.CommandSender; +import com.wizardlybump17.wlib.command.sender.CommandSender; import lombok.NonNull; import java.util.List; diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/args/reader/ShortReader.java b/commands/src/main/java/com/wizardlybump17/wlib/command/args/reader/ShortReader.java index af95f3ff..14e84005 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/args/reader/ShortReader.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/args/reader/ShortReader.java @@ -1,6 +1,6 @@ package com.wizardlybump17.wlib.command.args.reader; -import com.wizardlybump17.wlib.command.CommandSender; +import com.wizardlybump17.wlib.command.sender.CommandSender; import lombok.NonNull; import java.util.List; diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/args/reader/StringReader.java b/commands/src/main/java/com/wizardlybump17/wlib/command/args/reader/StringReader.java index e6719a67..93f2c9c4 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/args/reader/StringReader.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/args/reader/StringReader.java @@ -1,6 +1,6 @@ package com.wizardlybump17.wlib.command.args.reader; -import com.wizardlybump17.wlib.command.CommandSender; +import com.wizardlybump17.wlib.command.sender.CommandSender; import lombok.NonNull; import java.util.List; diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/args/reader/UUIDReader.java b/commands/src/main/java/com/wizardlybump17/wlib/command/args/reader/UUIDReader.java index d061710b..d9f4c7db 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/args/reader/UUIDReader.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/args/reader/UUIDReader.java @@ -1,6 +1,6 @@ package com.wizardlybump17.wlib.command.args.reader; -import com.wizardlybump17.wlib.command.CommandSender; +import com.wizardlybump17.wlib.command.sender.CommandSender; import lombok.NonNull; import java.util.List; diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/completer/ArgumentCompleter.java b/commands/src/main/java/com/wizardlybump17/wlib/command/completer/ArgumentCompleter.java index 187191c0..f0145c0d 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/completer/ArgumentCompleter.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/completer/ArgumentCompleter.java @@ -1,6 +1,6 @@ package com.wizardlybump17.wlib.command.completer; -import com.wizardlybump17.wlib.command.CommandSender; +import com.wizardlybump17.wlib.command.sender.CommandSender; import lombok.NonNull; import java.util.List; diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/data/CommandData.java b/commands/src/main/java/com/wizardlybump17/wlib/command/data/CommandData.java index 4d32e6d8..9dd74ef5 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/data/CommandData.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/data/CommandData.java @@ -1,6 +1,6 @@ package com.wizardlybump17.wlib.command.data; -import com.wizardlybump17.wlib.command.CommandSender; +import com.wizardlybump17.wlib.command.sender.CommandSender; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/executor/CommandExecutor.java b/commands/src/main/java/com/wizardlybump17/wlib/command/executor/CommandExecutor.java index 298f73b7..a0c3720a 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/executor/CommandExecutor.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/executor/CommandExecutor.java @@ -1,7 +1,7 @@ package com.wizardlybump17.wlib.command.executor; -import com.wizardlybump17.wlib.command.CommandSender; import com.wizardlybump17.wlib.command.exception.CommandException; +import com.wizardlybump17.wlib.command.sender.CommandSender; import org.jetbrains.annotations.NotNull; import java.util.Map; diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/extractor/MethodCommandExtractor.java b/commands/src/main/java/com/wizardlybump17/wlib/command/extractor/MethodCommandExtractor.java index 3e650e68..354da31d 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/extractor/MethodCommandExtractor.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/extractor/MethodCommandExtractor.java @@ -1,11 +1,11 @@ package com.wizardlybump17.wlib.command.extractor; import com.wizardlybump17.wlib.command.CommandManager; -import com.wizardlybump17.wlib.command.CommandSender; import com.wizardlybump17.wlib.command.annotation.Command; import com.wizardlybump17.wlib.command.holder.CommandHolder; import com.wizardlybump17.wlib.command.registered.RegisteredCommand; import com.wizardlybump17.wlib.command.registered.RegisteredMethodCommand; +import com.wizardlybump17.wlib.command.sender.CommandSender; import org.jetbrains.annotations.NotNull; import java.lang.reflect.Method; diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/holder/CommandExecutor.java b/commands/src/main/java/com/wizardlybump17/wlib/command/holder/CommandExecutor.java index 24bf890b..05321945 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/holder/CommandExecutor.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/holder/CommandExecutor.java @@ -1,8 +1,8 @@ package com.wizardlybump17.wlib.command.holder; -import com.wizardlybump17.wlib.command.CommandSender; import com.wizardlybump17.wlib.command.args.reader.ArgsReaderException; import com.wizardlybump17.wlib.command.exception.CommandException; +import com.wizardlybump17.wlib.command.sender.CommandSender; /** * Interface for intercepting commands when they are called diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/registered/RegisteredCommand.java b/commands/src/main/java/com/wizardlybump17/wlib/command/registered/RegisteredCommand.java index bb7d19a6..aa31aea1 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/registered/RegisteredCommand.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/registered/RegisteredCommand.java @@ -2,12 +2,12 @@ import com.wizardlybump17.wlib.command.CommandManager; import com.wizardlybump17.wlib.command.CommandResult; -import com.wizardlybump17.wlib.command.CommandSender; import com.wizardlybump17.wlib.command.args.ArgsNode; import com.wizardlybump17.wlib.command.args.reader.ArgsReaderException; import com.wizardlybump17.wlib.command.data.CommandData; import com.wizardlybump17.wlib.command.exception.CommandException; import com.wizardlybump17.wlib.command.executor.CommandExecutor; +import com.wizardlybump17.wlib.command.sender.CommandSender; import com.wizardlybump17.wlib.util.StringUtil; import org.jetbrains.annotations.NotNull; diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/CommandSender.java b/commands/src/main/java/com/wizardlybump17/wlib/command/sender/CommandSender.java similarity index 91% rename from commands/src/main/java/com/wizardlybump17/wlib/command/CommandSender.java rename to commands/src/main/java/com/wizardlybump17/wlib/command/sender/CommandSender.java index 29f36f6c..0786ac74 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/CommandSender.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/sender/CommandSender.java @@ -1,4 +1,4 @@ -package com.wizardlybump17.wlib.command; +package com.wizardlybump17.wlib.command.sender; import org.jetbrains.annotations.NotNull; diff --git a/core/src/main/java/com/wizardlybump17/wlib/command/BukkitCommandExecutor.java b/core/src/main/java/com/wizardlybump17/wlib/command/BukkitCommandExecutor.java index c17fb0b0..c878081f 100644 --- a/core/src/main/java/com/wizardlybump17/wlib/command/BukkitCommandExecutor.java +++ b/core/src/main/java/com/wizardlybump17/wlib/command/BukkitCommandExecutor.java @@ -1,6 +1,8 @@ package com.wizardlybump17.wlib.command; import com.wizardlybump17.wlib.command.exception.CommandException; +import com.wizardlybump17.wlib.command.sender.BukkitCommandSender; +import com.wizardlybump17.wlib.command.sender.CommandSender; import lombok.RequiredArgsConstructor; import org.bukkit.command.Command; import org.bukkit.command.TabExecutor; @@ -18,7 +20,7 @@ public class BukkitCommandExecutor implements TabExecutor, com.wizardlybump17.wl @Override public boolean onCommand(@NotNull org.bukkit.command.CommandSender sender, @NotNull Command command, @NotNull String label, String[] args) { try { - execute(new com.wizardlybump17.wlib.command.sender.CommandSender(sender), command.getName(), args); + execute(new BukkitCommandSender(sender), command.getName(), args); } catch (CommandException e) { manager.getHolder().getLogger().log(Level.SEVERE, "Error while executing a command", e); } @@ -26,7 +28,7 @@ public boolean onCommand(@NotNull org.bukkit.command.CommandSender sender, @NotN } @Override - public void execute(com.wizardlybump17.wlib.command.CommandSender sender, String commandName, String[] args) throws CommandException { + public void execute(CommandSender sender, String commandName, String[] args) throws CommandException { String commandExecution = commandName + " " + String.join(" ", args); manager.execute(sender, commandExecution); } diff --git a/core/src/main/java/com/wizardlybump17/wlib/command/completer/EntityTypeArgumentCompleter.java b/core/src/main/java/com/wizardlybump17/wlib/command/completer/EntityTypeArgumentCompleter.java index de7bf8f4..2068365d 100644 --- a/core/src/main/java/com/wizardlybump17/wlib/command/completer/EntityTypeArgumentCompleter.java +++ b/core/src/main/java/com/wizardlybump17/wlib/command/completer/EntityTypeArgumentCompleter.java @@ -1,6 +1,6 @@ package com.wizardlybump17.wlib.command.completer; -import com.wizardlybump17.wlib.command.CommandSender; +import com.wizardlybump17.wlib.command.sender.CommandSender; import lombok.NonNull; import org.bukkit.entity.EntityType; diff --git a/core/src/main/java/com/wizardlybump17/wlib/command/completer/MaterialArgumentCompleter.java b/core/src/main/java/com/wizardlybump17/wlib/command/completer/MaterialArgumentCompleter.java index 6ded4874..8c72508f 100644 --- a/core/src/main/java/com/wizardlybump17/wlib/command/completer/MaterialArgumentCompleter.java +++ b/core/src/main/java/com/wizardlybump17/wlib/command/completer/MaterialArgumentCompleter.java @@ -1,6 +1,6 @@ package com.wizardlybump17.wlib.command.completer; -import com.wizardlybump17.wlib.command.CommandSender; +import com.wizardlybump17.wlib.command.sender.CommandSender; import lombok.NonNull; import org.bukkit.Material; diff --git a/core/src/main/java/com/wizardlybump17/wlib/command/completer/PlayerArgumentCompleter.java b/core/src/main/java/com/wizardlybump17/wlib/command/completer/PlayerArgumentCompleter.java index 2d963104..29145e42 100644 --- a/core/src/main/java/com/wizardlybump17/wlib/command/completer/PlayerArgumentCompleter.java +++ b/core/src/main/java/com/wizardlybump17/wlib/command/completer/PlayerArgumentCompleter.java @@ -1,6 +1,6 @@ package com.wizardlybump17.wlib.command.completer; -import com.wizardlybump17.wlib.command.CommandSender; +import com.wizardlybump17.wlib.command.sender.CommandSender; import lombok.NonNull; import org.bukkit.Bukkit; import org.bukkit.entity.Player; diff --git a/core/src/main/java/com/wizardlybump17/wlib/command/reader/BlockDataArgsReader.java b/core/src/main/java/com/wizardlybump17/wlib/command/reader/BlockDataArgsReader.java index dca102c3..8b9ca548 100644 --- a/core/src/main/java/com/wizardlybump17/wlib/command/reader/BlockDataArgsReader.java +++ b/core/src/main/java/com/wizardlybump17/wlib/command/reader/BlockDataArgsReader.java @@ -1,8 +1,8 @@ package com.wizardlybump17.wlib.command.reader; -import com.wizardlybump17.wlib.command.CommandSender; import com.wizardlybump17.wlib.command.args.reader.ArgsReader; import com.wizardlybump17.wlib.command.args.reader.ArgsReaderException; +import com.wizardlybump17.wlib.command.sender.CommandSender; import lombok.NonNull; import org.bukkit.Bukkit; import org.bukkit.Material; diff --git a/core/src/main/java/com/wizardlybump17/wlib/command/reader/EntityTypeArgsReader.java b/core/src/main/java/com/wizardlybump17/wlib/command/reader/EntityTypeArgsReader.java index 4ca9a7ce..c6986ffb 100644 --- a/core/src/main/java/com/wizardlybump17/wlib/command/reader/EntityTypeArgsReader.java +++ b/core/src/main/java/com/wizardlybump17/wlib/command/reader/EntityTypeArgsReader.java @@ -1,7 +1,7 @@ package com.wizardlybump17.wlib.command.reader; -import com.wizardlybump17.wlib.command.CommandSender; import com.wizardlybump17.wlib.command.args.reader.ArgsReader; +import com.wizardlybump17.wlib.command.sender.CommandSender; import lombok.NonNull; import org.bukkit.entity.EntityType; diff --git a/core/src/main/java/com/wizardlybump17/wlib/command/reader/MapJsonArgsReader.java b/core/src/main/java/com/wizardlybump17/wlib/command/reader/MapJsonArgsReader.java index a456c1c8..d7c82251 100644 --- a/core/src/main/java/com/wizardlybump17/wlib/command/reader/MapJsonArgsReader.java +++ b/core/src/main/java/com/wizardlybump17/wlib/command/reader/MapJsonArgsReader.java @@ -2,9 +2,9 @@ import com.google.gson.Gson; import com.google.gson.JsonSyntaxException; -import com.wizardlybump17.wlib.command.CommandSender; import com.wizardlybump17.wlib.command.args.reader.ArgsReader; import com.wizardlybump17.wlib.command.args.reader.ArgsReaderException; +import com.wizardlybump17.wlib.command.sender.CommandSender; import lombok.NonNull; import java.util.List; diff --git a/core/src/main/java/com/wizardlybump17/wlib/command/reader/MaterialReader.java b/core/src/main/java/com/wizardlybump17/wlib/command/reader/MaterialReader.java index 8251dd9c..2daf7f90 100644 --- a/core/src/main/java/com/wizardlybump17/wlib/command/reader/MaterialReader.java +++ b/core/src/main/java/com/wizardlybump17/wlib/command/reader/MaterialReader.java @@ -1,7 +1,7 @@ package com.wizardlybump17.wlib.command.reader; -import com.wizardlybump17.wlib.command.CommandSender; import com.wizardlybump17.wlib.command.args.reader.ArgsReader; +import com.wizardlybump17.wlib.command.sender.CommandSender; import lombok.NonNull; import org.bukkit.Material; diff --git a/core/src/main/java/com/wizardlybump17/wlib/command/reader/OfflinePlayerReader.java b/core/src/main/java/com/wizardlybump17/wlib/command/reader/OfflinePlayerReader.java index 5da69881..46c29ea4 100644 --- a/core/src/main/java/com/wizardlybump17/wlib/command/reader/OfflinePlayerReader.java +++ b/core/src/main/java/com/wizardlybump17/wlib/command/reader/OfflinePlayerReader.java @@ -1,7 +1,7 @@ package com.wizardlybump17.wlib.command.reader; -import com.wizardlybump17.wlib.command.CommandSender; import com.wizardlybump17.wlib.command.args.reader.ArgsReader; +import com.wizardlybump17.wlib.command.sender.CommandSender; import lombok.NonNull; import org.bukkit.Bukkit; import org.bukkit.OfflinePlayer; diff --git a/core/src/main/java/com/wizardlybump17/wlib/command/reader/PlayerReader.java b/core/src/main/java/com/wizardlybump17/wlib/command/reader/PlayerReader.java index ddb38aa7..1521ff37 100644 --- a/core/src/main/java/com/wizardlybump17/wlib/command/reader/PlayerReader.java +++ b/core/src/main/java/com/wizardlybump17/wlib/command/reader/PlayerReader.java @@ -1,7 +1,7 @@ package com.wizardlybump17.wlib.command.reader; -import com.wizardlybump17.wlib.command.CommandSender; import com.wizardlybump17.wlib.command.args.reader.ArgsReader; +import com.wizardlybump17.wlib.command.sender.CommandSender; import lombok.NonNull; import org.bukkit.Bukkit; import org.bukkit.entity.Player; diff --git a/core/src/main/java/com/wizardlybump17/wlib/command/registered/RegisteredBukkitCommand.java b/core/src/main/java/com/wizardlybump17/wlib/command/registered/RegisteredBukkitCommand.java index ef9f9b61..46ea8992 100644 --- a/core/src/main/java/com/wizardlybump17/wlib/command/registered/RegisteredBukkitCommand.java +++ b/core/src/main/java/com/wizardlybump17/wlib/command/registered/RegisteredBukkitCommand.java @@ -6,6 +6,7 @@ import com.wizardlybump17.wlib.command.data.CommandData; import com.wizardlybump17.wlib.command.exception.CommandException; import com.wizardlybump17.wlib.command.executor.CommandExecutor; +import com.wizardlybump17.wlib.command.sender.BukkitCommandSender; import org.bukkit.command.Command; import org.bukkit.command.CommandMap; import org.bukkit.command.CommandSender; @@ -38,7 +39,7 @@ public void onRegister(@NotNull CommandManager manager) { @Override public boolean execute(@NotNull CommandSender sender, @NotNull String label, @NotNull String[] args) { try { - manager.execute(new com.wizardlybump17.wlib.command.sender.CommandSender(sender), name + " " + String.join(" ", args)); + manager.execute(new BukkitCommandSender(sender), name + " " + String.join(" ", args)); } catch (CommandException e) { logger.log(Level.SEVERE, "Error while executing a command.", e); } diff --git a/core/src/main/java/com/wizardlybump17/wlib/command/sender/CommandSender.java b/core/src/main/java/com/wizardlybump17/wlib/command/sender/BukkitCommandSender.java similarity index 87% rename from core/src/main/java/com/wizardlybump17/wlib/command/sender/CommandSender.java rename to core/src/main/java/com/wizardlybump17/wlib/command/sender/BukkitCommandSender.java index 4d25ce26..e1f3fc9a 100644 --- a/core/src/main/java/com/wizardlybump17/wlib/command/sender/CommandSender.java +++ b/core/src/main/java/com/wizardlybump17/wlib/command/sender/BukkitCommandSender.java @@ -8,11 +8,11 @@ import java.util.UUID; -public class CommandSender implements com.wizardlybump17.wlib.command.CommandSender { +public class BukkitCommandSender implements CommandSender { private final @NotNull org.bukkit.command.CommandSender handle; - public CommandSender(@NotNull org.bukkit.command.CommandSender handle) { + public BukkitCommandSender(@NotNull org.bukkit.command.CommandSender handle) { this.handle = handle; } From 47e9fe107102601532250867dc405af0aac36319 Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Sat, 23 Nov 2024 21:00:34 -0300 Subject: [PATCH 55/73] added the BasicCommandSender class --- .../command/sender/BasicCommandSender.java | 92 +++++++++++++++++++ 1 file changed, 92 insertions(+) create mode 100644 commands/src/main/java/com/wizardlybump17/wlib/command/sender/BasicCommandSender.java diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/sender/BasicCommandSender.java b/commands/src/main/java/com/wizardlybump17/wlib/command/sender/BasicCommandSender.java new file mode 100644 index 00000000..bc51474e --- /dev/null +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/sender/BasicCommandSender.java @@ -0,0 +1,92 @@ +package com.wizardlybump17.wlib.command.sender; + +import org.jetbrains.annotations.NotNull; + +import java.util.Objects; +import java.util.UUID; +import java.util.function.Consumer; +import java.util.function.Predicate; + +public class BasicCommandSender implements CommandSender { + + private final @NotNull S handle; + private final @NotNull String name; + private final @NotNull UUID id; + private final @NotNull Consumer messageConsumer; + private final @NotNull Predicate permissionTest; + + public BasicCommandSender(@NotNull S handle, @NotNull String name, @NotNull UUID id, @NotNull Consumer messageConsumer, @NotNull Predicate permissionTest) { + this.handle = handle; + this.name = name; + this.id = id; + this.messageConsumer = messageConsumer; + this.permissionTest = permissionTest; + } + + @Override + public @NotNull S getHandle() { + return handle; + } + + @Override + public void sendMessage(String message) { + messageConsumer.accept(message); + } + + @Override + public void sendMessage(String... messages) { + sendMessage(String.join("\n", messages)); + } + + @Override + public @NotNull String getName() { + return name; + } + + @Override + public boolean hasPermission(String permission) { + return permissionTest.test(permission); + } + + @Override + public boolean hasId(@NotNull UUID id) { + return id.equals(this.id); + } + + public @NotNull UUID getId() { + return id; + } + + public @NotNull Consumer getMessageConsumer() { + return messageConsumer; + } + + public @NotNull Predicate getPermissionTest() { + return permissionTest; + } + + @Override + public boolean equals(Object o) { + if (o == null || getClass() != o.getClass()) + return false; + BasicCommandSender that = (BasicCommandSender) o; + return Objects.equals(handle, that.handle) && Objects.equals(name, that.name) && Objects.equals(id, that.id) + && Objects.equals(messageConsumer, that.messageConsumer) && Objects.equals(permissionTest, that.permissionTest); + } + + @Override + public int hashCode() { + return Objects.hash(handle, name, id, messageConsumer, permissionTest); + } + + @Override + public String toString() { + return "BasicCommandSender{" + + "handle=" + handle + + ", name='" + name + '\'' + + ", id=" + id + + ", messageConsumer=" + messageConsumer + + ", permissionTest=" + permissionTest + + '}'; + } +} From 5f1c5cd434761d98494d8ab09328682ce19bb109 Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Sat, 23 Nov 2024 21:05:29 -0300 Subject: [PATCH 56/73] added the builder system --- .../command/sender/BasicCommandSender.java | 72 +++++++++++++++++++ 1 file changed, 72 insertions(+) diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/sender/BasicCommandSender.java b/commands/src/main/java/com/wizardlybump17/wlib/command/sender/BasicCommandSender.java index bc51474e..8f2d8f86 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/sender/BasicCommandSender.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/sender/BasicCommandSender.java @@ -1,6 +1,7 @@ package com.wizardlybump17.wlib.command.sender; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import java.util.Objects; import java.util.UUID; @@ -89,4 +90,75 @@ public String toString() { ", permissionTest=" + permissionTest + '}'; } + + public static Builder builder() { + return new Builder<>(); + } + + public static class Builder { + + private @Nullable S handle; + private @Nullable String name; + private @Nullable UUID id; + private @Nullable Consumer messageConsumer; + private @Nullable Predicate permissionTest; + + protected Builder() { + } + + public @Nullable S handle() { + return handle; + } + + public @NotNull Builder handle(@Nullable S handle) { + this.handle = handle; + return this; + } + + public @Nullable String name() { + return name; + } + + public @NotNull Builder name(@Nullable String name) { + this.name = name; + return this; + } + + public @Nullable UUID id() { + return id; + } + + public @NotNull Builder id(@Nullable UUID id) { + this.id = id; + return this; + } + + public @Nullable Consumer messageConsumer() { + return messageConsumer; + } + + public @NotNull Builder messageConsumer(@Nullable Consumer messageConsumer) { + this.messageConsumer = messageConsumer; + return this; + } + + public @Nullable Predicate permissionTest() { + return permissionTest; + } + + public @NotNull Builder permissionTest(@Nullable Predicate permissionTest) { + this.permissionTest = permissionTest; + return this; + } + + public @NotNull BasicCommandSender build() { + return new BasicCommandSender<>( + Objects.requireNonNull(handle, "the 'handler' can not be null"), + Objects.requireNonNull(name, "the 'name' can not be null"), + Objects.requireNonNull(id, "the 'id' can not be null"), + messageConsumer == null ? System.out::println : messageConsumer, + permissionTest == null ? permission -> true : permissionTest + ); + } + } } From 986fb3959880ed28d4fd07fa4d124dd99ccf3805 Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Sat, 23 Nov 2024 21:11:28 -0300 Subject: [PATCH 57/73] added some tests for the BasicCommandSender --- .../test/sender/BasicCommandSenderTests.java | 64 +++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 commands/src/test/java/com/wizardlybump17/wlib/command/test/sender/BasicCommandSenderTests.java diff --git a/commands/src/test/java/com/wizardlybump17/wlib/command/test/sender/BasicCommandSenderTests.java b/commands/src/test/java/com/wizardlybump17/wlib/command/test/sender/BasicCommandSenderTests.java new file mode 100644 index 00000000..6c66a360 --- /dev/null +++ b/commands/src/test/java/com/wizardlybump17/wlib/command/test/sender/BasicCommandSenderTests.java @@ -0,0 +1,64 @@ +package com.wizardlybump17.wlib.command.test.sender; + +import com.wizardlybump17.wlib.command.sender.BasicCommandSender; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; + +import java.util.UUID; + +class BasicCommandSenderTests { + + @Test + void testPermissionsAllTrue() { + String name = "Test Sender"; + BasicCommandSender sender = BasicCommandSender.builder() + .handle(new Object()) + .name(name) + .id(UUID.nameUUIDFromBytes(name.getBytes())) + .permissionTest(permission -> true) + .build(); + Assertions.assertTrue(sender.hasPermission("test0.permission0")); + Assertions.assertTrue(sender.hasPermission("test0.permission1")); + Assertions.assertTrue(sender.hasPermission("test0.permission2")); + Assertions.assertTrue(sender.hasPermission("test1.permission0")); + Assertions.assertTrue(sender.hasPermission("test1.permission1")); + Assertions.assertTrue(sender.hasPermission("test1.permission2")); + } + + @Test + void testPermissionsAllFalse() { + String name = "Test Sender"; + BasicCommandSender sender = BasicCommandSender.builder() + .handle(new Object()) + .name(name) + .id(UUID.nameUUIDFromBytes(name.getBytes())) + .permissionTest(permission -> false) + .build(); + Assertions.assertFalse(sender.hasPermission("test0.permission0")); + Assertions.assertFalse(sender.hasPermission("test0.permission1")); + Assertions.assertFalse(sender.hasPermission("test0.permission2")); + Assertions.assertFalse(sender.hasPermission("test1.permission0")); + Assertions.assertFalse(sender.hasPermission("test1.permission1")); + Assertions.assertFalse(sender.hasPermission("test1.permission2")); + } + + @Test + void testSpecificPermissions() { + String name = "Test Sender"; + BasicCommandSender sender = BasicCommandSender.builder() + .handle(new Object()) + .name(name) + .id(UUID.nameUUIDFromBytes(name.getBytes())) + .permissionTest(permission -> permission.startsWith("test0.")) + .build(); + Assertions.assertTrue(sender.hasPermission("test0.permission0")); + Assertions.assertTrue(sender.hasPermission("test0.permission1")); + Assertions.assertTrue(sender.hasPermission("test0.permission2")); + Assertions.assertFalse(sender.hasPermission("test1.permission0")); + Assertions.assertFalse(sender.hasPermission("test1.permission1")); + Assertions.assertFalse(sender.hasPermission("test1.permission2")); + Assertions.assertFalse(sender.hasPermission("test2.permission0")); + Assertions.assertFalse(sender.hasPermission("test2.permission1")); + Assertions.assertFalse(sender.hasPermission("test2.permission2")); + } +} From f63124803de8db0de319fb309ba50be6f77c2f7c Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Wed, 4 Dec 2024 23:07:40 -0300 Subject: [PATCH 58/73] added the annotations dependency to the test scope --- commands/build.gradle | 1 + 1 file changed, 1 insertion(+) diff --git a/commands/build.gradle b/commands/build.gradle index f57b9327..2497418c 100644 --- a/commands/build.gradle +++ b/commands/build.gradle @@ -11,6 +11,7 @@ dependencies { implementation("com.github.sisyphsu:dateparser:1.0.11") { exclude(group: "org.projectlombok", module: "lombok") } + testCompileOnly("org.jetbrains:annotations:26.0.1") } shadowJar { From fe6cbc3e2defb63c000640e1fadf271b60b899cc Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Tue, 14 Jan 2025 18:06:50 -0300 Subject: [PATCH 59/73] version changed --- build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index b3f35803..c3dc551d 100644 --- a/build.gradle +++ b/build.gradle @@ -7,7 +7,7 @@ apply plugin: 'maven-publish' allprojects { group = 'com.wizardlybump17.wlib' - version = '1.6.7' + version = '1.6.7-ncs' apply plugin: 'com.github.johnrengelman.shadow' apply plugin: 'java' From f3d9f582c2c100925c535df9565b749f46b24117 Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Tue, 14 Jan 2025 18:09:51 -0300 Subject: [PATCH 60/73] improved the build.gradle --- build.gradle | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/build.gradle b/build.gradle index c3dc551d..dd316298 100644 --- a/build.gradle +++ b/build.gradle @@ -3,14 +3,13 @@ plugins { id 'maven-publish' } -apply plugin: 'maven-publish' - allprojects { - group = 'com.wizardlybump17.wlib' - version = '1.6.7-ncs' - apply plugin: 'com.github.johnrengelman.shadow' apply plugin: 'java' + apply plugin: 'maven-publish' + + group = 'com.wizardlybump17.wlib' + version = '1.6.7-ncs' repositories { mavenLocal() @@ -24,6 +23,10 @@ allprojects { compileJava { options.encoding = 'UTF-8' } + + assemble { + dependsOn(shadowJar) + } } java { @@ -32,8 +35,6 @@ allprojects { } subprojects { - apply plugin: 'maven-publish' - if (project.name == 'versions' || project.name.matches('v\\d_\\d+_R\\d+')) { tasks.withType(PublishToMavenRepository).configureEach { it.enabled = false @@ -79,8 +80,4 @@ subprojects { events "passed", "skipped", "failed", "standardOut", "standardError" } } - - build { - dependsOn(test, shadowJar) - } } \ No newline at end of file From 6017fed0990fc5bcd79f72643537dfb31f86b7d5 Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Sat, 15 Feb 2025 17:54:56 -0300 Subject: [PATCH 61/73] added the MiniMessageUtil class --- bukkit-utils/build.gradle | 3 ++ .../wlib/util/bukkit/MiniMessageUtil.java | 39 +++++++++++++++++++ 2 files changed, 42 insertions(+) create mode 100644 bukkit-utils/src/main/java/com/wizardlybump17/wlib/util/bukkit/MiniMessageUtil.java diff --git a/bukkit-utils/build.gradle b/bukkit-utils/build.gradle index 00e702b8..970dd5b2 100644 --- a/bukkit-utils/build.gradle +++ b/bukkit-utils/build.gradle @@ -4,6 +4,9 @@ dependencies { 'org.spigotmc:spigot:1.17.1-R0.1-SNAPSHOT', 'org.jetbrains:annotations:23.0.0', ) + compileOnly("net.kyori:adventure-api:4.18.0") + compileOnly("net.kyori:adventure-text-minimessage:4.18.0") + compileOnly("net.kyori:adventure-platform-bukkit:4.3.4") implementation( project(':utils') ) diff --git a/bukkit-utils/src/main/java/com/wizardlybump17/wlib/util/bukkit/MiniMessageUtil.java b/bukkit-utils/src/main/java/com/wizardlybump17/wlib/util/bukkit/MiniMessageUtil.java new file mode 100644 index 00000000..6cbc701a --- /dev/null +++ b/bukkit-utils/src/main/java/com/wizardlybump17/wlib/util/bukkit/MiniMessageUtil.java @@ -0,0 +1,39 @@ +package com.wizardlybump17.wlib.util.bukkit; + +import net.kyori.adventure.text.Component; +import net.kyori.adventure.text.minimessage.MiniMessage; +import net.kyori.adventure.text.minimessage.tag.Tag; +import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver; +import org.jetbrains.annotations.NotNull; + +import java.util.Map; + +public final class MiniMessageUtil { + + private MiniMessageUtil() { + } + + public static @NotNull Component getMessage(@NotNull String message, @NotNull Map placeholders) { + MiniMessage miniMessage = MiniMessage.miniMessage(); + if (placeholders.isEmpty()) + return miniMessage.deserialize(message); + + TagResolver[] resolvers = new TagResolver[placeholders.size()]; + int resolverIndex = 0; + for (Map.Entry entry : placeholders.entrySet()) { + String key = entry.getKey(); + Object value = entry.getValue(); + resolvers[resolverIndex++] = TagResolver.builder() + .tag( + key, + Tag.inserting(value instanceof Component component ? component : Component.text(String.valueOf(value))) + ) + .build(); + } + return miniMessage.deserialize(message, resolvers); + } + + public static @NotNull Component getMessage(@NotNull String message) { + return getMessage(message, Map.of()); + } +} From 1384fd877e5c392fa362cb51f002a506bf0555c5 Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Sat, 15 Feb 2025 22:27:26 -0300 Subject: [PATCH 62/73] added support for the Adventure API on non-Paper environments --- core/build.gradle | 3 +++ .../main/java/com/wizardlybump17/wlib/WLib.java | 14 ++++++++++++++ .../wlib/command/sender/BukkitCommandSender.java | 11 +++++++++++ core/src/main/resources/plugin.yml | 6 +++++- 4 files changed, 33 insertions(+), 1 deletion(-) diff --git a/core/build.gradle b/core/build.gradle index 776fb140..b31666b8 100644 --- a/core/build.gradle +++ b/core/build.gradle @@ -4,6 +4,9 @@ dependencies { 'org.jetbrains:annotations:23.1.0', 'org.spigotmc:spigot:1.17.1-R0.1-SNAPSHOT', ) + compileOnly("net.kyori:adventure-api:4.18.0") + compileOnly("net.kyori:adventure-text-minimessage:4.18.0") + compileOnly("net.kyori:adventure-platform-bukkit:4.3.4") annotationProcessor('org.projectlombok:lombok:1.18.24') implementation( diff --git a/core/src/main/java/com/wizardlybump17/wlib/WLib.java b/core/src/main/java/com/wizardlybump17/wlib/WLib.java index e4905f1f..bf90d6db 100644 --- a/core/src/main/java/com/wizardlybump17/wlib/WLib.java +++ b/core/src/main/java/com/wizardlybump17/wlib/WLib.java @@ -29,15 +29,18 @@ import com.wizardlybump17.wlib.util.bukkit.particle.*; import lombok.Getter; import lombok.NonNull; +import net.kyori.adventure.platform.bukkit.BukkitAudiences; import org.bukkit.Bukkit; import org.bukkit.configuration.serialization.ConfigurationSerialization; import org.bukkit.event.HandlerList; import org.bukkit.plugin.java.JavaPlugin; +import org.jetbrains.annotations.NotNull; @Getter public class WLib extends JavaPlugin { private final SaveControllersTask saveControllersTask = new SaveControllersTask(getLogger()); + private BukkitAudiences audiences; @Override public void onLoad() { @@ -64,6 +67,8 @@ protected void initConfigs() { @Override public void onEnable() { + audiences = BukkitAudiences.create(this); + Bukkit.getPluginManager().registerEvents(new EntityListener(), this); Bukkit.getPluginManager().registerEvents(new PlayerListener(this), this); @@ -76,6 +81,11 @@ public void onEnable() { public void onDisable() { HandlerList.unregisterAll(this); saveControllersTask.cancel(); + + if (audiences != null) { + audiences.close(); + audiences = null; + } } private void initCommandSystem() { @@ -205,4 +215,8 @@ public static WLib getInstance() { public static @NonNull String getServerVersion() { return Bukkit.getServer().getClass().getName().split("\\.")[3]; } + + public @NotNull BukkitAudiences getAudiences() { + return audiences; + } } diff --git a/core/src/main/java/com/wizardlybump17/wlib/command/sender/BukkitCommandSender.java b/core/src/main/java/com/wizardlybump17/wlib/command/sender/BukkitCommandSender.java index e1f3fc9a..d0b7f928 100644 --- a/core/src/main/java/com/wizardlybump17/wlib/command/sender/BukkitCommandSender.java +++ b/core/src/main/java/com/wizardlybump17/wlib/command/sender/BukkitCommandSender.java @@ -1,11 +1,14 @@ package com.wizardlybump17.wlib.command.sender; +import com.wizardlybump17.wlib.WLib; +import com.wizardlybump17.wlib.util.bukkit.MiniMessageUtil; import org.bukkit.command.BlockCommandSender; import org.bukkit.command.ConsoleCommandSender; import org.bukkit.entity.Entity; import org.bukkit.entity.Player; import org.jetbrains.annotations.NotNull; +import java.util.Map; import java.util.UUID; public class BukkitCommandSender implements CommandSender { @@ -31,6 +34,14 @@ public void sendMessage(String... message) { handle.sendMessage(String.join("\n", message)); } + public void sendMiniMessage(@NotNull String message, @NotNull Map placeholders) { + WLib.getInstance().getAudiences().sender(handle).sendMessage(MiniMessageUtil.getMessage(message, placeholders)); + } + + public void sendMiniMessage(@NotNull String message) { + sendMiniMessage(message, Map.of()); + } + @Override public String getName() { return handle.getName(); diff --git a/core/src/main/resources/plugin.yml b/core/src/main/resources/plugin.yml index dee76513..35676d43 100644 --- a/core/src/main/resources/plugin.yml +++ b/core/src/main/resources/plugin.yml @@ -3,4 +3,8 @@ main: com.wizardlybump17.wlib.WLib version: '${version}' author: WizardlyBump17 api-version: '1.13' -load: STARTUP \ No newline at end of file +load: STARTUP +libraries: + - net.kyori:adventure-api:4.18.0 + - net.kyori:adventure-text-minimessage:4.18.0 + - net.kyori:adventure-platform-bukkit:4.3.4 From 618c6ce3c90150644a25aa32ba3db1c1387c21ae Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Sat, 15 Feb 2025 22:54:41 -0300 Subject: [PATCH 63/73] added some methods with some Adventure stuff --- .../command/sender/BukkitCommandSender.java | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/core/src/main/java/com/wizardlybump17/wlib/command/sender/BukkitCommandSender.java b/core/src/main/java/com/wizardlybump17/wlib/command/sender/BukkitCommandSender.java index d0b7f928..d13d6355 100644 --- a/core/src/main/java/com/wizardlybump17/wlib/command/sender/BukkitCommandSender.java +++ b/core/src/main/java/com/wizardlybump17/wlib/command/sender/BukkitCommandSender.java @@ -2,6 +2,9 @@ import com.wizardlybump17.wlib.WLib; import com.wizardlybump17.wlib.util.bukkit.MiniMessageUtil; +import net.kyori.adventure.chat.ChatType; +import net.kyori.adventure.text.Component; +import net.kyori.adventure.text.ComponentLike; import org.bukkit.command.BlockCommandSender; import org.bukkit.command.ConsoleCommandSender; import org.bukkit.entity.Entity; @@ -42,6 +45,22 @@ public void sendMiniMessage(@NotNull String message) { sendMiniMessage(message, Map.of()); } + public void sendMessage(@NotNull Component message) { + WLib.getInstance().getAudiences().sender(handle).sendMessage(message); + } + + public void sendMessage(@NotNull Component message, @NotNull ChatType.Bound type) { + WLib.getInstance().getAudiences().sender(handle).sendMessage(message, type); + } + + public void sendMessage(@NotNull ComponentLike message) { + WLib.getInstance().getAudiences().sender(handle).sendMessage(message); + } + + public void sendMessage(@NotNull ComponentLike message, @NotNull ChatType.Bound type) { + WLib.getInstance().getAudiences().sender(handle).sendMessage(message, type); + } + @Override public String getName() { return handle.getName(); From 8c12af809cb5e45d644e500c72fe419f6ecd7dc3 Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Wed, 16 Apr 2025 23:59:22 -0300 Subject: [PATCH 64/73] version changed :D --- build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index dd316298..4be88fab 100644 --- a/build.gradle +++ b/build.gradle @@ -9,7 +9,7 @@ allprojects { apply plugin: 'maven-publish' group = 'com.wizardlybump17.wlib' - version = '1.6.7-ncs' + version = '1.6.7-ncs-1' repositories { mavenLocal() From 756ca770fe343e4ec625cea2c08026adc375aac8 Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Sat, 24 May 2025 14:23:02 -0300 Subject: [PATCH 65/73] using suppliers --- .../wlib/command/data/SimpleCommandData.java | 131 +++++++++++++----- 1 file changed, 98 insertions(+), 33 deletions(-) diff --git a/commands/src/main/java/com/wizardlybump17/wlib/command/data/SimpleCommandData.java b/commands/src/main/java/com/wizardlybump17/wlib/command/data/SimpleCommandData.java index f26df07f..66905c05 100644 --- a/commands/src/main/java/com/wizardlybump17/wlib/command/data/SimpleCommandData.java +++ b/commands/src/main/java/com/wizardlybump17/wlib/command/data/SimpleCommandData.java @@ -3,19 +3,19 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import java.util.Objects; +import java.util.function.Supplier; public class SimpleCommandData extends CommandData { - private final @NotNull String execution; - private final @Nullable String permission; - private final @Nullable String permissionMessage; - private final int priority; - private final @Nullable String description; - private final @Nullable String invalidSenderMessage; - private final @NotNull Class senderType; + private final @NotNull Supplier execution; + private final @NotNull Supplier permission; + private final @NotNull Supplier permissionMessage; + private final @NotNull Supplier priority; + private final @NotNull Supplier description; + private final @NotNull Supplier invalidSenderMessage; + private final @NotNull Supplier> senderType; - public SimpleCommandData(@NotNull String execution, @Nullable String permission, @Nullable String permissionMessage, int priority, @Nullable String description, @Nullable String invalidSenderMessage, @NotNull Class senderType) { + public SimpleCommandData(@NotNull Supplier execution, @NotNull Supplier permission, @NotNull Supplier permissionMessage, @NotNull Supplier priority, @NotNull Supplier description, @NotNull Supplier invalidSenderMessage, @NotNull Supplier> senderType) { this.execution = execution; this.permission = permission; this.permissionMessage = permissionMessage; @@ -25,39 +25,51 @@ public SimpleCommandData(@NotNull String execution, @Nullable String permission, this.senderType = senderType; } + public SimpleCommandData(@NotNull String execution, @Nullable String permission, @Nullable String permissionMessage, int priority, @Nullable String description, @Nullable String invalidSenderMessage, @NotNull Class senderType) { + this( + () -> execution, + () -> permission, + () -> permissionMessage, + () -> priority, + () -> description, + () -> invalidSenderMessage, + () -> senderType + ); + } + @Override public @NotNull String getExecution() { - return execution; + return execution.get(); } @Override public @Nullable String getPermission() { - return permission; + return permission.get(); } @Override public @Nullable String getPermissionMessage() { - return permissionMessage; + return permissionMessage.get(); } @Override public int getPriority() { - return priority; + return priority.get(); } @Override public @Nullable String getDescription() { - return description; + return description.get(); } @Override public @Nullable String getInvalidSenderMessage() { - return invalidSenderMessage; + return invalidSenderMessage.get(); } @Override public @NotNull Class getSenderType() { - return senderType; + return senderType.get(); } public static class Builder { @@ -65,86 +77,139 @@ public static class Builder { Builder() { } - private @Nullable String execution; - private @Nullable String permission; - private @Nullable String permissionMessage; - private @Nullable Integer priority; - private @Nullable String description; - private @Nullable String invalidSenderMessage; - private @Nullable Class senderType; + private @Nullable Supplier execution; + private @Nullable Supplier permission; + private @Nullable Supplier permissionMessage; + private @Nullable Supplier priority; + private @Nullable Supplier description; + private @Nullable Supplier invalidSenderMessage; + private @Nullable Supplier> senderType; public @Nullable String execution() { - return execution; + return execution == null ? null : execution.get(); } public @NotNull Builder execution(@Nullable String execution) { + this.execution = () -> execution; + return this; + } + + public @NotNull Builder execution(@Nullable Supplier execution) { this.execution = execution; return this; } public @Nullable String permission() { - return permission; + return permission == null ? null : permission.get(); } public @NotNull Builder permission(@Nullable String permission) { + this.permission = () -> permission; + return this; + } + + public @NotNull Builder permission(@Nullable Supplier permission) { this.permission = permission; return this; } public @Nullable String permissionMessage() { - return permissionMessage; + return permissionMessage == null ? null : permissionMessage.get(); } public @NotNull Builder permissionMessage(@Nullable String permissionMessage) { + this.permissionMessage = () -> permissionMessage; + return this; + } + + public @NotNull Builder permissionMessage(@Nullable Supplier permissionMessage) { this.permissionMessage = permissionMessage; return this; } public @Nullable Integer priority() { - return priority; + return priority == null ? null : priority.get(); } public @NotNull Builder priority(@Nullable Integer priority) { + this.priority = () -> priority; + return this; + } + + public @NotNull Builder priority(@Nullable Supplier priority) { this.priority = priority; return this; } public @Nullable String description() { - return description; + return description == null ? null : description.get(); } public @NotNull Builder description(@Nullable String description) { + this.description = () -> description; + return this; + } + + public @NotNull Builder description(@Nullable Supplier description) { this.description = description; return this; } public @Nullable String invalidSenderMessage() { - return invalidSenderMessage; + return invalidSenderMessage == null ? null : invalidSenderMessage.get(); } public @NotNull Builder invalidSenderMessage(@Nullable String invalidSenderMessage) { + this.invalidSenderMessage = () -> invalidSenderMessage; + return this; + } + + public @NotNull Builder invalidSenderMessage(@Nullable Supplier invalidSenderMessage) { this.invalidSenderMessage = invalidSenderMessage; return this; } public @Nullable Class senderType() { - return senderType; + return senderType == null ? null : senderType.get(); } public @NotNull Builder senderType(@Nullable Class senderType) { + this.senderType = () -> senderType; + return this; + } + + public @NotNull Builder senderType(@Nullable Supplier> senderType) { this.senderType = senderType; return this; } public @NotNull CommandData build() { + String execution = execution(); + if (execution == null) + throw new NullPointerException("The execution can not be null"); + + String permission = permission(); + String permissionMessage = permissionMessage(); + + Integer priority = priority(); + if (priority == null) + priority = execution.split(" ").length; + + String description = description(); + String invalidSenderMessage = invalidSenderMessage(); + + Class senderType = senderType(); + if (senderType == null) + senderType = Object.class; + return new SimpleCommandData( - Objects.requireNonNull(execution, "The execution can not be null"), + execution, permission, permissionMessage, - priority == null ? execution.split(" ").length : priority, + priority, description, invalidSenderMessage, - senderType == null ? Object.class : senderType + senderType ); } } From 5d9087eb361fb3d24ef68210a85f2b63796c5517 Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Sat, 24 May 2025 17:59:40 -0300 Subject: [PATCH 66/73] version changed --- build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index 4be88fab..2809708c 100644 --- a/build.gradle +++ b/build.gradle @@ -9,7 +9,7 @@ allprojects { apply plugin: 'maven-publish' group = 'com.wizardlybump17.wlib' - version = '1.6.7-ncs-1' + version = '1.6.7-ncs-2' repositories { mavenLocal() From 9254ad8c80224130e4304ba9a7037ce7ac432e3e Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Mon, 14 Jul 2025 17:17:42 -0300 Subject: [PATCH 67/73] sync with 1.20.6+ --- .../java/com/wizardlybump17/wlib/WLib.java | 5 +++ .../command/reader/NamespacedKeyReader.java | 2 +- .../command/sender/BukkitCommandSender.java | 30 --------------- .../v1_19_R1/command/CommandMapAdapter.java | 37 ------------------- .../v1_19_R2/command/CommandMapAdapter.java | 37 ------------------- .../v1_19_R3/command/CommandMapAdapter.java | 37 ------------------- .../v1_20_R1/command/CommandMapAdapter.java | 37 ------------------- .../v1_20_R2/command/CommandMapAdapter.java | 37 ------------------- .../adapter/v1_20_R3/GlowEnchantment.java | 0 .../v1_20_R3/command/CommandMapAdapter.java | 37 ------------------- .../v1_20_R4}/command/CommandMapAdapter.java | 12 ++---- .../v1_21_R1}/command/CommandMapAdapter.java | 12 ++---- .../v1_21_R3}/command/CommandMapAdapter.java | 12 ++---- .../v1_21_R5}/command/CommandMapAdapter.java | 12 ++---- 14 files changed, 18 insertions(+), 289 deletions(-) delete mode 100644 versions/v1_19_R1/src/main/java/com/wizardlybump17/wlib/adapter/v1_19_R1/command/CommandMapAdapter.java delete mode 100644 versions/v1_19_R2/src/main/java/com/wizardlybump17/wlib/adapter/v1_19_R2/command/CommandMapAdapter.java delete mode 100644 versions/v1_19_R3/src/main/java/com/wizardlybump17/wlib/adapter/v1_19_R3/command/CommandMapAdapter.java delete mode 100644 versions/v1_20_R1/src/main/java/com/wizardlybump17/wlib/adapter/v1_20_R1/command/CommandMapAdapter.java delete mode 100644 versions/v1_20_R2/src/main/java/com/wizardlybump17/wlib/adapter/v1_20_R2/command/CommandMapAdapter.java delete mode 100644 versions/v1_20_R3/src/main/java/com/wizardlybump17/wlib/adapter/v1_20_R3/GlowEnchantment.java delete mode 100644 versions/v1_20_R3/src/main/java/com/wizardlybump17/wlib/adapter/v1_20_R3/command/CommandMapAdapter.java rename versions/{v1_16_R3/src/main/java/com/wizardlybump17/wlib/adapter/v1_16_R3 => v1_20_R4/src/main/java/com/wizardlybump17/wlib/adapter/v1_20_R4}/command/CommandMapAdapter.java (55%) rename versions/{v1_17_R1/src/main/java/com/wizardlybump17/wlib/adapter/v1_17_R1 => v1_21_R1/src/main/java/com/wizardlybump17/wlib/adapter/v1_21_R1}/command/CommandMapAdapter.java (55%) rename versions/{v1_18_R1/src/main/java/com/wizardlybump17/wlib/adapter/v1_18_R1 => v1_21_R3/src/main/java/com/wizardlybump17/wlib/adapter/v1_21_R3}/command/CommandMapAdapter.java (55%) rename versions/{v1_18_R2/src/main/java/com/wizardlybump17/wlib/adapter/v1_18_R2 => v1_21_R5/src/main/java/com/wizardlybump17/wlib/adapter/v1_21_R5}/command/CommandMapAdapter.java (55%) diff --git a/core/src/main/java/com/wizardlybump17/wlib/WLib.java b/core/src/main/java/com/wizardlybump17/wlib/WLib.java index a8a09a00..56079ba8 100644 --- a/core/src/main/java/com/wizardlybump17/wlib/WLib.java +++ b/core/src/main/java/com/wizardlybump17/wlib/WLib.java @@ -2,6 +2,7 @@ import com.wizardlybump17.wlib.adapter.AttributeAdapter; import com.wizardlybump17.wlib.adapter.ItemAdapter; +import com.wizardlybump17.wlib.adapter.command.CommandMapAdapter; import com.wizardlybump17.wlib.adapter.player.PlayerAdapter; import com.wizardlybump17.wlib.command.args.ArgsReaderRegistry; import com.wizardlybump17.wlib.command.reader.*; @@ -120,21 +121,25 @@ private void setupAdapters() { ItemAdapter.setInstance(new com.wizardlybump17.wlib.adapter.v1_20_R4.ItemAdapter()); PlayerAdapter.setInstance(new com.wizardlybump17.wlib.adapter.v1_20_R4.player.PlayerAdapter()); AttributeAdapter.setInstance(new com.wizardlybump17.wlib.adapter.v1_20_R4.AttributeAdapter()); + CommandMapAdapter.setInstance(new com.wizardlybump17.wlib.adapter.v1_20_R4.command.CommandMapAdapter()); } case "1.21", "1.21.1" -> { ItemAdapter.setInstance(new com.wizardlybump17.wlib.adapter.v1_21_R1.ItemAdapter()); PlayerAdapter.setInstance(new com.wizardlybump17.wlib.adapter.v1_21_R1.player.PlayerAdapter()); AttributeAdapter.setInstance(new com.wizardlybump17.wlib.adapter.v1_21_R1.AttributeAdapter()); + CommandMapAdapter.setInstance(new com.wizardlybump17.wlib.adapter.v1_21_R1.command.CommandMapAdapter()); } case "1.21.4" -> { ItemAdapter.setInstance(new com.wizardlybump17.wlib.adapter.v1_21_R3.ItemAdapter()); PlayerAdapter.setInstance(new com.wizardlybump17.wlib.adapter.v1_21_R3.player.PlayerAdapter()); AttributeAdapter.setInstance(new com.wizardlybump17.wlib.adapter.v1_21_R3.AttributeAdapter()); + CommandMapAdapter.setInstance(new com.wizardlybump17.wlib.adapter.v1_21_R3.command.CommandMapAdapter()); } case "1.21.6", "1.21.7" -> { ItemAdapter.setInstance(new com.wizardlybump17.wlib.adapter.v1_21_R5.ItemAdapter()); PlayerAdapter.setInstance(new com.wizardlybump17.wlib.adapter.v1_21_R5.player.PlayerAdapter()); AttributeAdapter.setInstance(new com.wizardlybump17.wlib.adapter.v1_21_R5.AttributeAdapter()); + CommandMapAdapter.setInstance(new com.wizardlybump17.wlib.adapter.v1_21_R5.command.CommandMapAdapter()); } default -> getLogger().severe("The server version (" + version + ") is not supported by WLib yet."); } diff --git a/core/src/main/java/com/wizardlybump17/wlib/command/reader/NamespacedKeyReader.java b/core/src/main/java/com/wizardlybump17/wlib/command/reader/NamespacedKeyReader.java index b9e78278..82154cc5 100644 --- a/core/src/main/java/com/wizardlybump17/wlib/command/reader/NamespacedKeyReader.java +++ b/core/src/main/java/com/wizardlybump17/wlib/command/reader/NamespacedKeyReader.java @@ -1,7 +1,7 @@ package com.wizardlybump17.wlib.command.reader; -import com.wizardlybump17.wlib.command.CommandSender; import com.wizardlybump17.wlib.command.args.reader.ArgsReader; +import com.wizardlybump17.wlib.command.sender.CommandSender; import lombok.NonNull; import org.bukkit.NamespacedKey; import org.jetbrains.annotations.NotNull; diff --git a/core/src/main/java/com/wizardlybump17/wlib/command/sender/BukkitCommandSender.java b/core/src/main/java/com/wizardlybump17/wlib/command/sender/BukkitCommandSender.java index d13d6355..e1f3fc9a 100644 --- a/core/src/main/java/com/wizardlybump17/wlib/command/sender/BukkitCommandSender.java +++ b/core/src/main/java/com/wizardlybump17/wlib/command/sender/BukkitCommandSender.java @@ -1,17 +1,11 @@ package com.wizardlybump17.wlib.command.sender; -import com.wizardlybump17.wlib.WLib; -import com.wizardlybump17.wlib.util.bukkit.MiniMessageUtil; -import net.kyori.adventure.chat.ChatType; -import net.kyori.adventure.text.Component; -import net.kyori.adventure.text.ComponentLike; import org.bukkit.command.BlockCommandSender; import org.bukkit.command.ConsoleCommandSender; import org.bukkit.entity.Entity; import org.bukkit.entity.Player; import org.jetbrains.annotations.NotNull; -import java.util.Map; import java.util.UUID; public class BukkitCommandSender implements CommandSender { @@ -37,30 +31,6 @@ public void sendMessage(String... message) { handle.sendMessage(String.join("\n", message)); } - public void sendMiniMessage(@NotNull String message, @NotNull Map placeholders) { - WLib.getInstance().getAudiences().sender(handle).sendMessage(MiniMessageUtil.getMessage(message, placeholders)); - } - - public void sendMiniMessage(@NotNull String message) { - sendMiniMessage(message, Map.of()); - } - - public void sendMessage(@NotNull Component message) { - WLib.getInstance().getAudiences().sender(handle).sendMessage(message); - } - - public void sendMessage(@NotNull Component message, @NotNull ChatType.Bound type) { - WLib.getInstance().getAudiences().sender(handle).sendMessage(message, type); - } - - public void sendMessage(@NotNull ComponentLike message) { - WLib.getInstance().getAudiences().sender(handle).sendMessage(message); - } - - public void sendMessage(@NotNull ComponentLike message, @NotNull ChatType.Bound type) { - WLib.getInstance().getAudiences().sender(handle).sendMessage(message, type); - } - @Override public String getName() { return handle.getName(); diff --git a/versions/v1_19_R1/src/main/java/com/wizardlybump17/wlib/adapter/v1_19_R1/command/CommandMapAdapter.java b/versions/v1_19_R1/src/main/java/com/wizardlybump17/wlib/adapter/v1_19_R1/command/CommandMapAdapter.java deleted file mode 100644 index a5ce6522..00000000 --- a/versions/v1_19_R1/src/main/java/com/wizardlybump17/wlib/adapter/v1_19_R1/command/CommandMapAdapter.java +++ /dev/null @@ -1,37 +0,0 @@ -package com.wizardlybump17.wlib.adapter.v1_19_R1.command; - -import com.wizardlybump17.wlib.util.ReflectionUtil; -import org.bukkit.Bukkit; -import org.bukkit.command.Command; -import org.bukkit.command.CommandMap; -import org.bukkit.command.SimpleCommandMap; -import org.jetbrains.annotations.NotNull; - -import java.lang.reflect.Field; -import java.util.Map; - -public class CommandMapAdapter extends com.wizardlybump17.wlib.adapter.command.CommandMapAdapter { - - public static final @NotNull Field COMMAND_MAP = ReflectionUtil.getField("commandMap", Bukkit.getServer().getClass()); - public static final @NotNull Field COMMANDS = ReflectionUtil.getField("knownCommands", SimpleCommandMap.class); - - @Override - public @NotNull CommandMap getCommandMap() { - return ReflectionUtil.getFieldValue(COMMAND_MAP, Bukkit.getServer()); - } - - @Override - public void unregisterCommand(@NotNull String command) { - Map commands = getCommands(); - CommandMap commandMap = getCommandMap(); - - Command removed = commands.remove(command); - if (removed != null) - removed.unregister(commandMap); - } - - @Override - public @NotNull Map getCommands() { - return ReflectionUtil.getFieldValue(COMMANDS, getCommandMap()); - } -} diff --git a/versions/v1_19_R2/src/main/java/com/wizardlybump17/wlib/adapter/v1_19_R2/command/CommandMapAdapter.java b/versions/v1_19_R2/src/main/java/com/wizardlybump17/wlib/adapter/v1_19_R2/command/CommandMapAdapter.java deleted file mode 100644 index 4b7b0639..00000000 --- a/versions/v1_19_R2/src/main/java/com/wizardlybump17/wlib/adapter/v1_19_R2/command/CommandMapAdapter.java +++ /dev/null @@ -1,37 +0,0 @@ -package com.wizardlybump17.wlib.adapter.v1_19_R2.command; - -import com.wizardlybump17.wlib.util.ReflectionUtil; -import org.bukkit.Bukkit; -import org.bukkit.command.Command; -import org.bukkit.command.CommandMap; -import org.bukkit.command.SimpleCommandMap; -import org.jetbrains.annotations.NotNull; - -import java.lang.reflect.Field; -import java.util.Map; - -public class CommandMapAdapter extends com.wizardlybump17.wlib.adapter.command.CommandMapAdapter { - - public static final @NotNull Field COMMAND_MAP = ReflectionUtil.getField("commandMap", Bukkit.getServer().getClass()); - public static final @NotNull Field COMMANDS = ReflectionUtil.getField("knownCommands", SimpleCommandMap.class); - - @Override - public @NotNull CommandMap getCommandMap() { - return ReflectionUtil.getFieldValue(COMMAND_MAP, Bukkit.getServer()); - } - - @Override - public void unregisterCommand(@NotNull String command) { - Map commands = getCommands(); - CommandMap commandMap = getCommandMap(); - - Command removed = commands.remove(command); - if (removed != null) - removed.unregister(commandMap); - } - - @Override - public @NotNull Map getCommands() { - return ReflectionUtil.getFieldValue(COMMANDS, getCommandMap()); - } -} diff --git a/versions/v1_19_R3/src/main/java/com/wizardlybump17/wlib/adapter/v1_19_R3/command/CommandMapAdapter.java b/versions/v1_19_R3/src/main/java/com/wizardlybump17/wlib/adapter/v1_19_R3/command/CommandMapAdapter.java deleted file mode 100644 index e0b6df28..00000000 --- a/versions/v1_19_R3/src/main/java/com/wizardlybump17/wlib/adapter/v1_19_R3/command/CommandMapAdapter.java +++ /dev/null @@ -1,37 +0,0 @@ -package com.wizardlybump17.wlib.adapter.v1_19_R3.command; - -import com.wizardlybump17.wlib.util.ReflectionUtil; -import org.bukkit.Bukkit; -import org.bukkit.command.Command; -import org.bukkit.command.CommandMap; -import org.bukkit.command.SimpleCommandMap; -import org.jetbrains.annotations.NotNull; - -import java.lang.reflect.Field; -import java.util.Map; - -public class CommandMapAdapter extends com.wizardlybump17.wlib.adapter.command.CommandMapAdapter { - - public static final @NotNull Field COMMAND_MAP = ReflectionUtil.getField("commandMap", Bukkit.getServer().getClass()); - public static final @NotNull Field COMMANDS = ReflectionUtil.getField("knownCommands", SimpleCommandMap.class); - - @Override - public @NotNull CommandMap getCommandMap() { - return ReflectionUtil.getFieldValue(COMMAND_MAP, Bukkit.getServer()); - } - - @Override - public void unregisterCommand(@NotNull String command) { - Map commands = getCommands(); - CommandMap commandMap = getCommandMap(); - - Command removed = commands.remove(command); - if (removed != null) - removed.unregister(commandMap); - } - - @Override - public @NotNull Map getCommands() { - return ReflectionUtil.getFieldValue(COMMANDS, getCommandMap()); - } -} diff --git a/versions/v1_20_R1/src/main/java/com/wizardlybump17/wlib/adapter/v1_20_R1/command/CommandMapAdapter.java b/versions/v1_20_R1/src/main/java/com/wizardlybump17/wlib/adapter/v1_20_R1/command/CommandMapAdapter.java deleted file mode 100644 index 98a07dd8..00000000 --- a/versions/v1_20_R1/src/main/java/com/wizardlybump17/wlib/adapter/v1_20_R1/command/CommandMapAdapter.java +++ /dev/null @@ -1,37 +0,0 @@ -package com.wizardlybump17.wlib.adapter.v1_20_R1.command; - -import com.wizardlybump17.wlib.util.ReflectionUtil; -import org.bukkit.Bukkit; -import org.bukkit.command.Command; -import org.bukkit.command.CommandMap; -import org.bukkit.command.SimpleCommandMap; -import org.jetbrains.annotations.NotNull; - -import java.lang.reflect.Field; -import java.util.Map; - -public class CommandMapAdapter extends com.wizardlybump17.wlib.adapter.command.CommandMapAdapter { - - public static final @NotNull Field COMMAND_MAP = ReflectionUtil.getField("commandMap", Bukkit.getServer().getClass()); - public static final @NotNull Field COMMANDS = ReflectionUtil.getField("knownCommands", SimpleCommandMap.class); - - @Override - public @NotNull CommandMap getCommandMap() { - return ReflectionUtil.getFieldValue(COMMAND_MAP, Bukkit.getServer()); - } - - @Override - public void unregisterCommand(@NotNull String command) { - Map commands = getCommands(); - CommandMap commandMap = getCommandMap(); - - Command removed = commands.remove(command); - if (removed != null) - removed.unregister(commandMap); - } - - @Override - public @NotNull Map getCommands() { - return ReflectionUtil.getFieldValue(COMMANDS, getCommandMap()); - } -} diff --git a/versions/v1_20_R2/src/main/java/com/wizardlybump17/wlib/adapter/v1_20_R2/command/CommandMapAdapter.java b/versions/v1_20_R2/src/main/java/com/wizardlybump17/wlib/adapter/v1_20_R2/command/CommandMapAdapter.java deleted file mode 100644 index b14f309f..00000000 --- a/versions/v1_20_R2/src/main/java/com/wizardlybump17/wlib/adapter/v1_20_R2/command/CommandMapAdapter.java +++ /dev/null @@ -1,37 +0,0 @@ -package com.wizardlybump17.wlib.adapter.v1_20_R2.command; - -import com.wizardlybump17.wlib.util.ReflectionUtil; -import org.bukkit.Bukkit; -import org.bukkit.command.Command; -import org.bukkit.command.CommandMap; -import org.bukkit.command.SimpleCommandMap; -import org.jetbrains.annotations.NotNull; - -import java.lang.reflect.Field; -import java.util.Map; - -public class CommandMapAdapter extends com.wizardlybump17.wlib.adapter.command.CommandMapAdapter { - - public static final @NotNull Field COMMAND_MAP = ReflectionUtil.getField("commandMap", Bukkit.getServer().getClass()); - public static final @NotNull Field COMMANDS = ReflectionUtil.getField("knownCommands", SimpleCommandMap.class); - - @Override - public @NotNull CommandMap getCommandMap() { - return ReflectionUtil.getFieldValue(COMMAND_MAP, Bukkit.getServer()); - } - - @Override - public void unregisterCommand(@NotNull String command) { - Map commands = getCommands(); - CommandMap commandMap = getCommandMap(); - - Command removed = commands.remove(command); - if (removed != null) - removed.unregister(commandMap); - } - - @Override - public @NotNull Map getCommands() { - return ReflectionUtil.getFieldValue(COMMANDS, getCommandMap()); - } -} diff --git a/versions/v1_20_R3/src/main/java/com/wizardlybump17/wlib/adapter/v1_20_R3/GlowEnchantment.java b/versions/v1_20_R3/src/main/java/com/wizardlybump17/wlib/adapter/v1_20_R3/GlowEnchantment.java deleted file mode 100644 index e69de29b..00000000 diff --git a/versions/v1_20_R3/src/main/java/com/wizardlybump17/wlib/adapter/v1_20_R3/command/CommandMapAdapter.java b/versions/v1_20_R3/src/main/java/com/wizardlybump17/wlib/adapter/v1_20_R3/command/CommandMapAdapter.java deleted file mode 100644 index 2c867d02..00000000 --- a/versions/v1_20_R3/src/main/java/com/wizardlybump17/wlib/adapter/v1_20_R3/command/CommandMapAdapter.java +++ /dev/null @@ -1,37 +0,0 @@ -package com.wizardlybump17.wlib.adapter.v1_20_R3.command; - -import com.wizardlybump17.wlib.util.ReflectionUtil; -import org.bukkit.Bukkit; -import org.bukkit.command.Command; -import org.bukkit.command.CommandMap; -import org.bukkit.command.SimpleCommandMap; -import org.jetbrains.annotations.NotNull; - -import java.lang.reflect.Field; -import java.util.Map; - -public class CommandMapAdapter extends com.wizardlybump17.wlib.adapter.command.CommandMapAdapter { - - public static final @NotNull Field COMMAND_MAP = ReflectionUtil.getField("commandMap", Bukkit.getServer().getClass()); - public static final @NotNull Field COMMANDS = ReflectionUtil.getField("knownCommands", SimpleCommandMap.class); - - @Override - public @NotNull CommandMap getCommandMap() { - return ReflectionUtil.getFieldValue(COMMAND_MAP, Bukkit.getServer()); - } - - @Override - public void unregisterCommand(@NotNull String command) { - Map commands = getCommands(); - CommandMap commandMap = getCommandMap(); - - Command removed = commands.remove(command); - if (removed != null) - removed.unregister(commandMap); - } - - @Override - public @NotNull Map getCommands() { - return ReflectionUtil.getFieldValue(COMMANDS, getCommandMap()); - } -} diff --git a/versions/v1_16_R3/src/main/java/com/wizardlybump17/wlib/adapter/v1_16_R3/command/CommandMapAdapter.java b/versions/v1_20_R4/src/main/java/com/wizardlybump17/wlib/adapter/v1_20_R4/command/CommandMapAdapter.java similarity index 55% rename from versions/v1_16_R3/src/main/java/com/wizardlybump17/wlib/adapter/v1_16_R3/command/CommandMapAdapter.java rename to versions/v1_20_R4/src/main/java/com/wizardlybump17/wlib/adapter/v1_20_R4/command/CommandMapAdapter.java index f2461fd8..8b710d61 100644 --- a/versions/v1_16_R3/src/main/java/com/wizardlybump17/wlib/adapter/v1_16_R3/command/CommandMapAdapter.java +++ b/versions/v1_20_R4/src/main/java/com/wizardlybump17/wlib/adapter/v1_20_R4/command/CommandMapAdapter.java @@ -1,23 +1,17 @@ -package com.wizardlybump17.wlib.adapter.v1_16_R3.command; +package com.wizardlybump17.wlib.adapter.v1_20_R4.command; -import com.wizardlybump17.wlib.util.ReflectionUtil; import org.bukkit.Bukkit; import org.bukkit.command.Command; import org.bukkit.command.CommandMap; -import org.bukkit.command.SimpleCommandMap; import org.jetbrains.annotations.NotNull; -import java.lang.reflect.Field; import java.util.Map; public class CommandMapAdapter extends com.wizardlybump17.wlib.adapter.command.CommandMapAdapter { - public static final @NotNull Field COMMAND_MAP = ReflectionUtil.getField("commandMap", Bukkit.getServer().getClass()); - public static final @NotNull Field COMMANDS = ReflectionUtil.getField("knownCommands", SimpleCommandMap.class); - @Override public @NotNull CommandMap getCommandMap() { - return ReflectionUtil.getFieldValue(COMMAND_MAP, Bukkit.getServer()); + return Bukkit.getCommandMap(); } @Override @@ -32,6 +26,6 @@ public void unregisterCommand(@NotNull String command) { @Override public @NotNull Map getCommands() { - return ReflectionUtil.getFieldValue(COMMANDS, getCommandMap()); + return getCommandMap().getKnownCommands(); } } diff --git a/versions/v1_17_R1/src/main/java/com/wizardlybump17/wlib/adapter/v1_17_R1/command/CommandMapAdapter.java b/versions/v1_21_R1/src/main/java/com/wizardlybump17/wlib/adapter/v1_21_R1/command/CommandMapAdapter.java similarity index 55% rename from versions/v1_17_R1/src/main/java/com/wizardlybump17/wlib/adapter/v1_17_R1/command/CommandMapAdapter.java rename to versions/v1_21_R1/src/main/java/com/wizardlybump17/wlib/adapter/v1_21_R1/command/CommandMapAdapter.java index 3e6d948d..b16dd490 100644 --- a/versions/v1_17_R1/src/main/java/com/wizardlybump17/wlib/adapter/v1_17_R1/command/CommandMapAdapter.java +++ b/versions/v1_21_R1/src/main/java/com/wizardlybump17/wlib/adapter/v1_21_R1/command/CommandMapAdapter.java @@ -1,23 +1,17 @@ -package com.wizardlybump17.wlib.adapter.v1_17_R1.command; +package com.wizardlybump17.wlib.adapter.v1_21_R1.command; -import com.wizardlybump17.wlib.util.ReflectionUtil; import org.bukkit.Bukkit; import org.bukkit.command.Command; import org.bukkit.command.CommandMap; -import org.bukkit.command.SimpleCommandMap; import org.jetbrains.annotations.NotNull; -import java.lang.reflect.Field; import java.util.Map; public class CommandMapAdapter extends com.wizardlybump17.wlib.adapter.command.CommandMapAdapter { - public static final @NotNull Field COMMAND_MAP = ReflectionUtil.getField("commandMap", Bukkit.getServer().getClass()); - public static final @NotNull Field COMMANDS = ReflectionUtil.getField("knownCommands", SimpleCommandMap.class); - @Override public @NotNull CommandMap getCommandMap() { - return ReflectionUtil.getFieldValue(COMMAND_MAP, Bukkit.getServer()); + return Bukkit.getCommandMap(); } @Override @@ -32,6 +26,6 @@ public void unregisterCommand(@NotNull String command) { @Override public @NotNull Map getCommands() { - return ReflectionUtil.getFieldValue(COMMANDS, getCommandMap()); + return getCommandMap().getKnownCommands(); } } diff --git a/versions/v1_18_R1/src/main/java/com/wizardlybump17/wlib/adapter/v1_18_R1/command/CommandMapAdapter.java b/versions/v1_21_R3/src/main/java/com/wizardlybump17/wlib/adapter/v1_21_R3/command/CommandMapAdapter.java similarity index 55% rename from versions/v1_18_R1/src/main/java/com/wizardlybump17/wlib/adapter/v1_18_R1/command/CommandMapAdapter.java rename to versions/v1_21_R3/src/main/java/com/wizardlybump17/wlib/adapter/v1_21_R3/command/CommandMapAdapter.java index aa747170..774a5bd1 100644 --- a/versions/v1_18_R1/src/main/java/com/wizardlybump17/wlib/adapter/v1_18_R1/command/CommandMapAdapter.java +++ b/versions/v1_21_R3/src/main/java/com/wizardlybump17/wlib/adapter/v1_21_R3/command/CommandMapAdapter.java @@ -1,23 +1,17 @@ -package com.wizardlybump17.wlib.adapter.v1_18_R1.command; +package com.wizardlybump17.wlib.adapter.v1_21_R3.command; -import com.wizardlybump17.wlib.util.ReflectionUtil; import org.bukkit.Bukkit; import org.bukkit.command.Command; import org.bukkit.command.CommandMap; -import org.bukkit.command.SimpleCommandMap; import org.jetbrains.annotations.NotNull; -import java.lang.reflect.Field; import java.util.Map; public class CommandMapAdapter extends com.wizardlybump17.wlib.adapter.command.CommandMapAdapter { - public static final @NotNull Field COMMAND_MAP = ReflectionUtil.getField("commandMap", Bukkit.getServer().getClass()); - public static final @NotNull Field COMMANDS = ReflectionUtil.getField("knownCommands", SimpleCommandMap.class); - @Override public @NotNull CommandMap getCommandMap() { - return ReflectionUtil.getFieldValue(COMMAND_MAP, Bukkit.getServer()); + return Bukkit.getCommandMap(); } @Override @@ -32,6 +26,6 @@ public void unregisterCommand(@NotNull String command) { @Override public @NotNull Map getCommands() { - return ReflectionUtil.getFieldValue(COMMANDS, getCommandMap()); + return getCommandMap().getKnownCommands(); } } diff --git a/versions/v1_18_R2/src/main/java/com/wizardlybump17/wlib/adapter/v1_18_R2/command/CommandMapAdapter.java b/versions/v1_21_R5/src/main/java/com/wizardlybump17/wlib/adapter/v1_21_R5/command/CommandMapAdapter.java similarity index 55% rename from versions/v1_18_R2/src/main/java/com/wizardlybump17/wlib/adapter/v1_18_R2/command/CommandMapAdapter.java rename to versions/v1_21_R5/src/main/java/com/wizardlybump17/wlib/adapter/v1_21_R5/command/CommandMapAdapter.java index cdb45016..8ae75ce3 100644 --- a/versions/v1_18_R2/src/main/java/com/wizardlybump17/wlib/adapter/v1_18_R2/command/CommandMapAdapter.java +++ b/versions/v1_21_R5/src/main/java/com/wizardlybump17/wlib/adapter/v1_21_R5/command/CommandMapAdapter.java @@ -1,23 +1,17 @@ -package com.wizardlybump17.wlib.adapter.v1_18_R2.command; +package com.wizardlybump17.wlib.adapter.v1_21_R5.command; -import com.wizardlybump17.wlib.util.ReflectionUtil; import org.bukkit.Bukkit; import org.bukkit.command.Command; import org.bukkit.command.CommandMap; -import org.bukkit.command.SimpleCommandMap; import org.jetbrains.annotations.NotNull; -import java.lang.reflect.Field; import java.util.Map; public class CommandMapAdapter extends com.wizardlybump17.wlib.adapter.command.CommandMapAdapter { - public static final @NotNull Field COMMAND_MAP = ReflectionUtil.getField("commandMap", Bukkit.getServer().getClass()); - public static final @NotNull Field COMMANDS = ReflectionUtil.getField("knownCommands", SimpleCommandMap.class); - @Override public @NotNull CommandMap getCommandMap() { - return ReflectionUtil.getFieldValue(COMMAND_MAP, Bukkit.getServer()); + return Bukkit.getCommandMap(); } @Override @@ -32,6 +26,6 @@ public void unregisterCommand(@NotNull String command) { @Override public @NotNull Map getCommands() { - return ReflectionUtil.getFieldValue(COMMANDS, getCommandMap()); + return getCommandMap().getKnownCommands(); } } From 43d2c2dbc1138cae1604d40ff9d948ab17541e30 Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Mon, 14 Jul 2025 17:21:26 -0300 Subject: [PATCH 68/73] added the Adapter interface --- .../wizardlybump17/wlib/adapter/Adapter.java | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 versions/adapter/src/main/java/com/wizardlybump17/wlib/adapter/Adapter.java diff --git a/versions/adapter/src/main/java/com/wizardlybump17/wlib/adapter/Adapter.java b/versions/adapter/src/main/java/com/wizardlybump17/wlib/adapter/Adapter.java new file mode 100644 index 00000000..637b85e1 --- /dev/null +++ b/versions/adapter/src/main/java/com/wizardlybump17/wlib/adapter/Adapter.java @@ -0,0 +1,18 @@ +package com.wizardlybump17.wlib.adapter; + +import org.bukkit.Bukkit; +import org.jetbrains.annotations.NotNull; + +import java.util.Set; + +public interface Adapter { + + @NotNull Set getMinecraftVersions(); + + default void checkIsOnRightVersion() { + String current = Bukkit.getMinecraftVersion(); + Set expected = getMinecraftVersions(); + if (!expected.contains(current)) + throw new IllegalStateException("Expected Minecraft version(s) " + expected + ", but currently running " + current); + } +} From efa2b8db58f2114936d6d0ece821eda459587438 Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Mon, 14 Jul 2025 17:28:10 -0300 Subject: [PATCH 69/73] added versions to stuff --- .../wlib/adapter/AttributeAdapter.java | 3 ++- .../wizardlybump17/wlib/adapter/ItemAdapter.java | 3 ++- .../wlib/adapter/command/CommandMapAdapter.java | 4 +++- .../wlib/adapter/player/PlayerAdapter.java | 4 +++- .../wlib/adapter/v1_20_R4/AttributeAdapter.java | 2 +- .../wlib/adapter/v1_20_R4/BaseAdapter.java | 14 ++++++++++++++ .../wlib/adapter/v1_20_R4/ItemAdapter.java | 2 +- .../v1_20_R4/command/CommandMapAdapter.java | 3 ++- .../adapter/v1_20_R4/player/PlayerAdapter.java | 3 ++- .../wlib/adapter/v1_21_R1/AttributeAdapter.java | 2 +- .../wlib/adapter/v1_21_R1/BaseAdapter.java | 14 ++++++++++++++ .../wlib/adapter/v1_21_R1/ItemAdapter.java | 2 +- .../v1_21_R1/command/CommandMapAdapter.java | 3 ++- .../adapter/v1_21_R1/player/PlayerAdapter.java | 3 ++- .../wlib/adapter/v1_21_R3/AttributeAdapter.java | 2 +- .../wlib/adapter/v1_21_R3/BaseAdapter.java | 14 ++++++++++++++ .../wlib/adapter/v1_21_R3/ItemAdapter.java | 2 +- .../v1_21_R3/command/CommandMapAdapter.java | 9 ++++++++- .../adapter/v1_21_R3/player/PlayerAdapter.java | 3 ++- .../wlib/adapter/v1_21_R5/AttributeAdapter.java | 2 +- .../wlib/adapter/v1_21_R5/BaseAdapter.java | 14 ++++++++++++++ .../wlib/adapter/v1_21_R5/ItemAdapter.java | 2 +- .../v1_21_R5/command/CommandMapAdapter.java | 3 ++- .../adapter/v1_21_R5/player/PlayerAdapter.java | 3 ++- 24 files changed, 96 insertions(+), 20 deletions(-) create mode 100644 versions/v1_20_R4/src/main/java/com/wizardlybump17/wlib/adapter/v1_20_R4/BaseAdapter.java create mode 100644 versions/v1_21_R1/src/main/java/com/wizardlybump17/wlib/adapter/v1_21_R1/BaseAdapter.java create mode 100644 versions/v1_21_R3/src/main/java/com/wizardlybump17/wlib/adapter/v1_21_R3/BaseAdapter.java create mode 100644 versions/v1_21_R5/src/main/java/com/wizardlybump17/wlib/adapter/v1_21_R5/BaseAdapter.java diff --git a/versions/adapter/src/main/java/com/wizardlybump17/wlib/adapter/AttributeAdapter.java b/versions/adapter/src/main/java/com/wizardlybump17/wlib/adapter/AttributeAdapter.java index 184f178e..fcf80d9b 100644 --- a/versions/adapter/src/main/java/com/wizardlybump17/wlib/adapter/AttributeAdapter.java +++ b/versions/adapter/src/main/java/com/wizardlybump17/wlib/adapter/AttributeAdapter.java @@ -7,7 +7,7 @@ import java.util.Map; -public abstract class AttributeAdapter { +public abstract class AttributeAdapter implements Adapter { private static AttributeAdapter instance; @@ -24,6 +24,7 @@ public static AttributeAdapter getInstance() { public static void setInstance(@NotNull AttributeAdapter instance) { if (AttributeAdapter.instance != null) throw new IllegalStateException("The AttributeAdapter is already set"); + instance.checkIsOnRightVersion(); AttributeAdapter.instance = instance; } } diff --git a/versions/adapter/src/main/java/com/wizardlybump17/wlib/adapter/ItemAdapter.java b/versions/adapter/src/main/java/com/wizardlybump17/wlib/adapter/ItemAdapter.java index 4a8543f8..ae806240 100644 --- a/versions/adapter/src/main/java/com/wizardlybump17/wlib/adapter/ItemAdapter.java +++ b/versions/adapter/src/main/java/com/wizardlybump17/wlib/adapter/ItemAdapter.java @@ -11,7 +11,7 @@ import java.util.Map; -public abstract class ItemAdapter { +public abstract class ItemAdapter implements Adapter { public static final PersistentDataAdapterContext PERSISTENT_DATA_ADAPTER_CONTEXT = new ItemStack(Material.BOW).getItemMeta().getPersistentDataContainer().getAdapterContext(); private static ItemAdapter instance; @@ -21,6 +21,7 @@ public static ItemAdapter getInstance() { } public static void setInstance(ItemAdapter instance) { + instance.checkIsOnRightVersion(); if (ItemAdapter.instance == null) ItemAdapter.instance = instance; } diff --git a/versions/adapter/src/main/java/com/wizardlybump17/wlib/adapter/command/CommandMapAdapter.java b/versions/adapter/src/main/java/com/wizardlybump17/wlib/adapter/command/CommandMapAdapter.java index 14a001ae..d0948ef1 100644 --- a/versions/adapter/src/main/java/com/wizardlybump17/wlib/adapter/command/CommandMapAdapter.java +++ b/versions/adapter/src/main/java/com/wizardlybump17/wlib/adapter/command/CommandMapAdapter.java @@ -1,12 +1,13 @@ package com.wizardlybump17.wlib.adapter.command; +import com.wizardlybump17.wlib.adapter.Adapter; import org.bukkit.command.Command; import org.bukkit.command.CommandMap; import org.jetbrains.annotations.NotNull; import java.util.Map; -public abstract class CommandMapAdapter { +public abstract class CommandMapAdapter implements Adapter { private static CommandMapAdapter instance; @@ -23,6 +24,7 @@ public static CommandMapAdapter getInstance() { public static void setInstance(@NotNull CommandMapAdapter instance) { if (CommandMapAdapter.instance != null) throw new IllegalStateException("The CommandAdapter instance is already set."); + instance.checkIsOnRightVersion(); CommandMapAdapter.instance = instance; } } diff --git a/versions/adapter/src/main/java/com/wizardlybump17/wlib/adapter/player/PlayerAdapter.java b/versions/adapter/src/main/java/com/wizardlybump17/wlib/adapter/player/PlayerAdapter.java index b072bcd4..dc1ea6c0 100644 --- a/versions/adapter/src/main/java/com/wizardlybump17/wlib/adapter/player/PlayerAdapter.java +++ b/versions/adapter/src/main/java/com/wizardlybump17/wlib/adapter/player/PlayerAdapter.java @@ -1,5 +1,6 @@ package com.wizardlybump17.wlib.adapter.player; +import com.wizardlybump17.wlib.adapter.Adapter; import lombok.Getter; import lombok.NonNull; import org.bukkit.conversations.Conversation; @@ -9,7 +10,7 @@ import java.util.List; import java.util.function.Predicate; -public abstract class PlayerAdapter { +public abstract class PlayerAdapter implements Adapter { @Getter private static PlayerAdapter instance; @@ -23,6 +24,7 @@ public abstract class PlayerAdapter { public static void setInstance(PlayerAdapter instance) { if (PlayerAdapter.instance != null) throw new IllegalStateException("The PlayerAdapter instance is already set"); + instance.checkIsOnRightVersion(); PlayerAdapter.instance = instance; } } diff --git a/versions/v1_20_R4/src/main/java/com/wizardlybump17/wlib/adapter/v1_20_R4/AttributeAdapter.java b/versions/v1_20_R4/src/main/java/com/wizardlybump17/wlib/adapter/v1_20_R4/AttributeAdapter.java index 5f5d0355..7d9b36b2 100644 --- a/versions/v1_20_R4/src/main/java/com/wizardlybump17/wlib/adapter/v1_20_R4/AttributeAdapter.java +++ b/versions/v1_20_R4/src/main/java/com/wizardlybump17/wlib/adapter/v1_20_R4/AttributeAdapter.java @@ -10,7 +10,7 @@ import java.util.*; -public class AttributeAdapter extends com.wizardlybump17.wlib.adapter.AttributeAdapter { +public class AttributeAdapter extends com.wizardlybump17.wlib.adapter.AttributeAdapter implements BaseAdapter { @Override public Attribute getAttribute(@NotNull String name) { diff --git a/versions/v1_20_R4/src/main/java/com/wizardlybump17/wlib/adapter/v1_20_R4/BaseAdapter.java b/versions/v1_20_R4/src/main/java/com/wizardlybump17/wlib/adapter/v1_20_R4/BaseAdapter.java new file mode 100644 index 00000000..7ea70e18 --- /dev/null +++ b/versions/v1_20_R4/src/main/java/com/wizardlybump17/wlib/adapter/v1_20_R4/BaseAdapter.java @@ -0,0 +1,14 @@ +package com.wizardlybump17.wlib.adapter.v1_20_R4; + +import com.wizardlybump17.wlib.adapter.Adapter; +import org.jetbrains.annotations.NotNull; + +import java.util.Set; + +public interface BaseAdapter extends Adapter { + + @Override + default @NotNull Set getMinecraftVersions() { + return Set.of("1.20.5", "1.20.6"); + } +} diff --git a/versions/v1_20_R4/src/main/java/com/wizardlybump17/wlib/adapter/v1_20_R4/ItemAdapter.java b/versions/v1_20_R4/src/main/java/com/wizardlybump17/wlib/adapter/v1_20_R4/ItemAdapter.java index 279537a1..97300bcf 100644 --- a/versions/v1_20_R4/src/main/java/com/wizardlybump17/wlib/adapter/v1_20_R4/ItemAdapter.java +++ b/versions/v1_20_R4/src/main/java/com/wizardlybump17/wlib/adapter/v1_20_R4/ItemAdapter.java @@ -13,7 +13,7 @@ import java.lang.reflect.Field; import java.util.*; -public class ItemAdapter extends com.wizardlybump17.wlib.adapter.ItemAdapter { +public class ItemAdapter extends com.wizardlybump17.wlib.adapter.ItemAdapter implements BaseAdapter { public static final @NotNull Class CRAFT_META_ITEM = ReflectionUtil.getClass("org.bukkit.craftbukkit.inventory.CraftMetaItem"); public static final @NotNull Field CUSTOM_TAG = ReflectionUtil.getField("customTag", CRAFT_META_ITEM); diff --git a/versions/v1_20_R4/src/main/java/com/wizardlybump17/wlib/adapter/v1_20_R4/command/CommandMapAdapter.java b/versions/v1_20_R4/src/main/java/com/wizardlybump17/wlib/adapter/v1_20_R4/command/CommandMapAdapter.java index 8b710d61..94ac9b3a 100644 --- a/versions/v1_20_R4/src/main/java/com/wizardlybump17/wlib/adapter/v1_20_R4/command/CommandMapAdapter.java +++ b/versions/v1_20_R4/src/main/java/com/wizardlybump17/wlib/adapter/v1_20_R4/command/CommandMapAdapter.java @@ -1,5 +1,6 @@ package com.wizardlybump17.wlib.adapter.v1_20_R4.command; +import com.wizardlybump17.wlib.adapter.v1_20_R4.BaseAdapter; import org.bukkit.Bukkit; import org.bukkit.command.Command; import org.bukkit.command.CommandMap; @@ -7,7 +8,7 @@ import java.util.Map; -public class CommandMapAdapter extends com.wizardlybump17.wlib.adapter.command.CommandMapAdapter { +public class CommandMapAdapter extends com.wizardlybump17.wlib.adapter.command.CommandMapAdapter implements BaseAdapter { @Override public @NotNull CommandMap getCommandMap() { diff --git a/versions/v1_20_R4/src/main/java/com/wizardlybump17/wlib/adapter/v1_20_R4/player/PlayerAdapter.java b/versions/v1_20_R4/src/main/java/com/wizardlybump17/wlib/adapter/v1_20_R4/player/PlayerAdapter.java index 11318aa5..71fe32ee 100644 --- a/versions/v1_20_R4/src/main/java/com/wizardlybump17/wlib/adapter/v1_20_R4/player/PlayerAdapter.java +++ b/versions/v1_20_R4/src/main/java/com/wizardlybump17/wlib/adapter/v1_20_R4/player/PlayerAdapter.java @@ -1,5 +1,6 @@ package com.wizardlybump17.wlib.adapter.v1_20_R4.player; +import com.wizardlybump17.wlib.adapter.v1_20_R4.BaseAdapter; import com.wizardlybump17.wlib.util.ReflectionUtil; import lombok.NonNull; import org.bukkit.conversations.Conversation; @@ -13,7 +14,7 @@ import java.util.List; import java.util.function.Predicate; -public class PlayerAdapter extends com.wizardlybump17.wlib.adapter.player.PlayerAdapter { +public class PlayerAdapter extends com.wizardlybump17.wlib.adapter.player.PlayerAdapter implements BaseAdapter { public static final @NonNull Field CONVERSATION_TRACKER = ReflectionUtil.getField("conversationTracker", CraftPlayer.class); public static final @NonNull Field CONVERSATION_QUEUE = ReflectionUtil.getField("conversationQueue", ConversationTracker.class); diff --git a/versions/v1_21_R1/src/main/java/com/wizardlybump17/wlib/adapter/v1_21_R1/AttributeAdapter.java b/versions/v1_21_R1/src/main/java/com/wizardlybump17/wlib/adapter/v1_21_R1/AttributeAdapter.java index 6f0a7eae..fe6590ce 100644 --- a/versions/v1_21_R1/src/main/java/com/wizardlybump17/wlib/adapter/v1_21_R1/AttributeAdapter.java +++ b/versions/v1_21_R1/src/main/java/com/wizardlybump17/wlib/adapter/v1_21_R1/AttributeAdapter.java @@ -10,7 +10,7 @@ import java.util.*; -public class AttributeAdapter extends com.wizardlybump17.wlib.adapter.AttributeAdapter { +public class AttributeAdapter extends com.wizardlybump17.wlib.adapter.AttributeAdapter implements BaseAdapter { @Override public Attribute getAttribute(@NotNull String name) { diff --git a/versions/v1_21_R1/src/main/java/com/wizardlybump17/wlib/adapter/v1_21_R1/BaseAdapter.java b/versions/v1_21_R1/src/main/java/com/wizardlybump17/wlib/adapter/v1_21_R1/BaseAdapter.java new file mode 100644 index 00000000..63cac7d5 --- /dev/null +++ b/versions/v1_21_R1/src/main/java/com/wizardlybump17/wlib/adapter/v1_21_R1/BaseAdapter.java @@ -0,0 +1,14 @@ +package com.wizardlybump17.wlib.adapter.v1_21_R1; + +import com.wizardlybump17.wlib.adapter.Adapter; +import org.jetbrains.annotations.NotNull; + +import java.util.Set; + +public interface BaseAdapter extends Adapter { + + @Override + default @NotNull Set getMinecraftVersions() { + return Set.of("1.21", "1.21.1"); + } +} diff --git a/versions/v1_21_R1/src/main/java/com/wizardlybump17/wlib/adapter/v1_21_R1/ItemAdapter.java b/versions/v1_21_R1/src/main/java/com/wizardlybump17/wlib/adapter/v1_21_R1/ItemAdapter.java index f03ab120..8645b097 100644 --- a/versions/v1_21_R1/src/main/java/com/wizardlybump17/wlib/adapter/v1_21_R1/ItemAdapter.java +++ b/versions/v1_21_R1/src/main/java/com/wizardlybump17/wlib/adapter/v1_21_R1/ItemAdapter.java @@ -13,7 +13,7 @@ import java.lang.reflect.Field; import java.util.*; -public class ItemAdapter extends com.wizardlybump17.wlib.adapter.ItemAdapter { +public class ItemAdapter extends com.wizardlybump17.wlib.adapter.ItemAdapter implements BaseAdapter { public static final @NotNull Class CRAFT_META_ITEM = ReflectionUtil.getClass("org.bukkit.craftbukkit.inventory.CraftMetaItem"); public static final @NotNull Field CUSTOM_TAG = ReflectionUtil.getField("customTag", CRAFT_META_ITEM); diff --git a/versions/v1_21_R1/src/main/java/com/wizardlybump17/wlib/adapter/v1_21_R1/command/CommandMapAdapter.java b/versions/v1_21_R1/src/main/java/com/wizardlybump17/wlib/adapter/v1_21_R1/command/CommandMapAdapter.java index b16dd490..733af580 100644 --- a/versions/v1_21_R1/src/main/java/com/wizardlybump17/wlib/adapter/v1_21_R1/command/CommandMapAdapter.java +++ b/versions/v1_21_R1/src/main/java/com/wizardlybump17/wlib/adapter/v1_21_R1/command/CommandMapAdapter.java @@ -1,5 +1,6 @@ package com.wizardlybump17.wlib.adapter.v1_21_R1.command; +import com.wizardlybump17.wlib.adapter.v1_21_R1.BaseAdapter; import org.bukkit.Bukkit; import org.bukkit.command.Command; import org.bukkit.command.CommandMap; @@ -7,7 +8,7 @@ import java.util.Map; -public class CommandMapAdapter extends com.wizardlybump17.wlib.adapter.command.CommandMapAdapter { +public class CommandMapAdapter extends com.wizardlybump17.wlib.adapter.command.CommandMapAdapter implements BaseAdapter { @Override public @NotNull CommandMap getCommandMap() { diff --git a/versions/v1_21_R1/src/main/java/com/wizardlybump17/wlib/adapter/v1_21_R1/player/PlayerAdapter.java b/versions/v1_21_R1/src/main/java/com/wizardlybump17/wlib/adapter/v1_21_R1/player/PlayerAdapter.java index d0177d11..555178f6 100644 --- a/versions/v1_21_R1/src/main/java/com/wizardlybump17/wlib/adapter/v1_21_R1/player/PlayerAdapter.java +++ b/versions/v1_21_R1/src/main/java/com/wizardlybump17/wlib/adapter/v1_21_R1/player/PlayerAdapter.java @@ -1,5 +1,6 @@ package com.wizardlybump17.wlib.adapter.v1_21_R1.player; +import com.wizardlybump17.wlib.adapter.v1_21_R1.BaseAdapter; import com.wizardlybump17.wlib.util.ReflectionUtil; import lombok.NonNull; import org.bukkit.conversations.Conversation; @@ -13,7 +14,7 @@ import java.util.List; import java.util.function.Predicate; -public class PlayerAdapter extends com.wizardlybump17.wlib.adapter.player.PlayerAdapter { +public class PlayerAdapter extends com.wizardlybump17.wlib.adapter.player.PlayerAdapter implements BaseAdapter { public static final @NonNull Field CONVERSATION_TRACKER = ReflectionUtil.getField("conversationTracker", CraftPlayer.class); public static final @NonNull Field CONVERSATION_QUEUE = ReflectionUtil.getField("conversationQueue", ConversationTracker.class); diff --git a/versions/v1_21_R3/src/main/java/com/wizardlybump17/wlib/adapter/v1_21_R3/AttributeAdapter.java b/versions/v1_21_R3/src/main/java/com/wizardlybump17/wlib/adapter/v1_21_R3/AttributeAdapter.java index 61f449eb..6395ce15 100644 --- a/versions/v1_21_R3/src/main/java/com/wizardlybump17/wlib/adapter/v1_21_R3/AttributeAdapter.java +++ b/versions/v1_21_R3/src/main/java/com/wizardlybump17/wlib/adapter/v1_21_R3/AttributeAdapter.java @@ -10,7 +10,7 @@ import java.util.*; -public class AttributeAdapter extends com.wizardlybump17.wlib.adapter.AttributeAdapter { +public class AttributeAdapter extends com.wizardlybump17.wlib.adapter.AttributeAdapter implements BaseAdapter { public static final @NotNull Map ATTRIBUTES; diff --git a/versions/v1_21_R3/src/main/java/com/wizardlybump17/wlib/adapter/v1_21_R3/BaseAdapter.java b/versions/v1_21_R3/src/main/java/com/wizardlybump17/wlib/adapter/v1_21_R3/BaseAdapter.java new file mode 100644 index 00000000..5aff8ce7 --- /dev/null +++ b/versions/v1_21_R3/src/main/java/com/wizardlybump17/wlib/adapter/v1_21_R3/BaseAdapter.java @@ -0,0 +1,14 @@ +package com.wizardlybump17.wlib.adapter.v1_21_R3; + +import com.wizardlybump17.wlib.adapter.Adapter; +import org.jetbrains.annotations.NotNull; + +import java.util.Set; + +public interface BaseAdapter extends Adapter { + + @Override + default @NotNull Set getMinecraftVersions() { + return Set.of("1.21.4"); + } +} diff --git a/versions/v1_21_R3/src/main/java/com/wizardlybump17/wlib/adapter/v1_21_R3/ItemAdapter.java b/versions/v1_21_R3/src/main/java/com/wizardlybump17/wlib/adapter/v1_21_R3/ItemAdapter.java index 742ad62e..60f773dd 100644 --- a/versions/v1_21_R3/src/main/java/com/wizardlybump17/wlib/adapter/v1_21_R3/ItemAdapter.java +++ b/versions/v1_21_R3/src/main/java/com/wizardlybump17/wlib/adapter/v1_21_R3/ItemAdapter.java @@ -13,7 +13,7 @@ import java.lang.reflect.Field; import java.util.*; -public class ItemAdapter extends com.wizardlybump17.wlib.adapter.ItemAdapter { +public class ItemAdapter extends com.wizardlybump17.wlib.adapter.ItemAdapter implements BaseAdapter { public static final @NotNull Class CRAFT_META_ITEM = ReflectionUtil.getClass("org.bukkit.craftbukkit.inventory.CraftMetaItem"); public static final @NotNull Field CUSTOM_TAG = ReflectionUtil.getField("customTag", CRAFT_META_ITEM); diff --git a/versions/v1_21_R3/src/main/java/com/wizardlybump17/wlib/adapter/v1_21_R3/command/CommandMapAdapter.java b/versions/v1_21_R3/src/main/java/com/wizardlybump17/wlib/adapter/v1_21_R3/command/CommandMapAdapter.java index 774a5bd1..cb84658e 100644 --- a/versions/v1_21_R3/src/main/java/com/wizardlybump17/wlib/adapter/v1_21_R3/command/CommandMapAdapter.java +++ b/versions/v1_21_R3/src/main/java/com/wizardlybump17/wlib/adapter/v1_21_R3/command/CommandMapAdapter.java @@ -1,13 +1,15 @@ package com.wizardlybump17.wlib.adapter.v1_21_R3.command; +import com.wizardlybump17.wlib.adapter.v1_21_R3.BaseAdapter; import org.bukkit.Bukkit; import org.bukkit.command.Command; import org.bukkit.command.CommandMap; import org.jetbrains.annotations.NotNull; import java.util.Map; +import java.util.Set; -public class CommandMapAdapter extends com.wizardlybump17.wlib.adapter.command.CommandMapAdapter { +public class CommandMapAdapter extends com.wizardlybump17.wlib.adapter.command.CommandMapAdapter implements BaseAdapter { @Override public @NotNull CommandMap getCommandMap() { @@ -28,4 +30,9 @@ public void unregisterCommand(@NotNull String command) { public @NotNull Map getCommands() { return getCommandMap().getKnownCommands(); } + + @Override + public @NotNull Set getMinecraftVersions() { + return Set.of("1.20.6"); + } } diff --git a/versions/v1_21_R3/src/main/java/com/wizardlybump17/wlib/adapter/v1_21_R3/player/PlayerAdapter.java b/versions/v1_21_R3/src/main/java/com/wizardlybump17/wlib/adapter/v1_21_R3/player/PlayerAdapter.java index bade240a..b0c67d71 100644 --- a/versions/v1_21_R3/src/main/java/com/wizardlybump17/wlib/adapter/v1_21_R3/player/PlayerAdapter.java +++ b/versions/v1_21_R3/src/main/java/com/wizardlybump17/wlib/adapter/v1_21_R3/player/PlayerAdapter.java @@ -1,5 +1,6 @@ package com.wizardlybump17.wlib.adapter.v1_21_R3.player; +import com.wizardlybump17.wlib.adapter.v1_21_R3.BaseAdapter; import com.wizardlybump17.wlib.util.ReflectionUtil; import lombok.NonNull; import org.bukkit.conversations.Conversation; @@ -13,7 +14,7 @@ import java.util.List; import java.util.function.Predicate; -public class PlayerAdapter extends com.wizardlybump17.wlib.adapter.player.PlayerAdapter { +public class PlayerAdapter extends com.wizardlybump17.wlib.adapter.player.PlayerAdapter implements BaseAdapter { public static final @NonNull Field CONVERSATION_TRACKER = ReflectionUtil.getField("conversationTracker", CraftPlayer.class); public static final @NonNull Field CONVERSATION_QUEUE = ReflectionUtil.getField("conversationQueue", ConversationTracker.class); diff --git a/versions/v1_21_R5/src/main/java/com/wizardlybump17/wlib/adapter/v1_21_R5/AttributeAdapter.java b/versions/v1_21_R5/src/main/java/com/wizardlybump17/wlib/adapter/v1_21_R5/AttributeAdapter.java index 634e10bd..5dc3fefa 100644 --- a/versions/v1_21_R5/src/main/java/com/wizardlybump17/wlib/adapter/v1_21_R5/AttributeAdapter.java +++ b/versions/v1_21_R5/src/main/java/com/wizardlybump17/wlib/adapter/v1_21_R5/AttributeAdapter.java @@ -10,7 +10,7 @@ import java.util.*; -public class AttributeAdapter extends com.wizardlybump17.wlib.adapter.AttributeAdapter { +public class AttributeAdapter extends com.wizardlybump17.wlib.adapter.AttributeAdapter implements BaseAdapter { public static final @NotNull Map ATTRIBUTES; diff --git a/versions/v1_21_R5/src/main/java/com/wizardlybump17/wlib/adapter/v1_21_R5/BaseAdapter.java b/versions/v1_21_R5/src/main/java/com/wizardlybump17/wlib/adapter/v1_21_R5/BaseAdapter.java new file mode 100644 index 00000000..0fac3342 --- /dev/null +++ b/versions/v1_21_R5/src/main/java/com/wizardlybump17/wlib/adapter/v1_21_R5/BaseAdapter.java @@ -0,0 +1,14 @@ +package com.wizardlybump17.wlib.adapter.v1_21_R5; + +import com.wizardlybump17.wlib.adapter.Adapter; +import org.jetbrains.annotations.NotNull; + +import java.util.Set; + +public interface BaseAdapter extends Adapter { + + @Override + default @NotNull Set getMinecraftVersions() { + return Set.of("1.21.6", "1.21.7"); + } +} diff --git a/versions/v1_21_R5/src/main/java/com/wizardlybump17/wlib/adapter/v1_21_R5/ItemAdapter.java b/versions/v1_21_R5/src/main/java/com/wizardlybump17/wlib/adapter/v1_21_R5/ItemAdapter.java index 2e6d606d..f5f9bf24 100644 --- a/versions/v1_21_R5/src/main/java/com/wizardlybump17/wlib/adapter/v1_21_R5/ItemAdapter.java +++ b/versions/v1_21_R5/src/main/java/com/wizardlybump17/wlib/adapter/v1_21_R5/ItemAdapter.java @@ -12,7 +12,7 @@ import java.lang.reflect.Field; import java.util.*; -public class ItemAdapter extends com.wizardlybump17.wlib.adapter.ItemAdapter { +public class ItemAdapter extends com.wizardlybump17.wlib.adapter.ItemAdapter implements BaseAdapter { public static final @NotNull Class CRAFT_META_ITEM = ReflectionUtil.getClass("org.bukkit.craftbukkit.inventory.CraftMetaItem"); public static final @NotNull Field CUSTOM_TAG = ReflectionUtil.getField("customTag", CRAFT_META_ITEM); diff --git a/versions/v1_21_R5/src/main/java/com/wizardlybump17/wlib/adapter/v1_21_R5/command/CommandMapAdapter.java b/versions/v1_21_R5/src/main/java/com/wizardlybump17/wlib/adapter/v1_21_R5/command/CommandMapAdapter.java index 8ae75ce3..6a575088 100644 --- a/versions/v1_21_R5/src/main/java/com/wizardlybump17/wlib/adapter/v1_21_R5/command/CommandMapAdapter.java +++ b/versions/v1_21_R5/src/main/java/com/wizardlybump17/wlib/adapter/v1_21_R5/command/CommandMapAdapter.java @@ -1,5 +1,6 @@ package com.wizardlybump17.wlib.adapter.v1_21_R5.command; +import com.wizardlybump17.wlib.adapter.v1_21_R5.BaseAdapter; import org.bukkit.Bukkit; import org.bukkit.command.Command; import org.bukkit.command.CommandMap; @@ -7,7 +8,7 @@ import java.util.Map; -public class CommandMapAdapter extends com.wizardlybump17.wlib.adapter.command.CommandMapAdapter { +public class CommandMapAdapter extends com.wizardlybump17.wlib.adapter.command.CommandMapAdapter implements BaseAdapter { @Override public @NotNull CommandMap getCommandMap() { diff --git a/versions/v1_21_R5/src/main/java/com/wizardlybump17/wlib/adapter/v1_21_R5/player/PlayerAdapter.java b/versions/v1_21_R5/src/main/java/com/wizardlybump17/wlib/adapter/v1_21_R5/player/PlayerAdapter.java index 38cb57f7..6943fb3b 100644 --- a/versions/v1_21_R5/src/main/java/com/wizardlybump17/wlib/adapter/v1_21_R5/player/PlayerAdapter.java +++ b/versions/v1_21_R5/src/main/java/com/wizardlybump17/wlib/adapter/v1_21_R5/player/PlayerAdapter.java @@ -1,5 +1,6 @@ package com.wizardlybump17.wlib.adapter.v1_21_R5.player; +import com.wizardlybump17.wlib.adapter.v1_21_R5.BaseAdapter; import com.wizardlybump17.wlib.util.ReflectionUtil; import org.bukkit.conversations.Conversation; import org.bukkit.craftbukkit.conversations.ConversationTracker; @@ -13,7 +14,7 @@ import java.util.List; import java.util.function.Predicate; -public class PlayerAdapter extends com.wizardlybump17.wlib.adapter.player.PlayerAdapter { +public class PlayerAdapter extends com.wizardlybump17.wlib.adapter.player.PlayerAdapter implements BaseAdapter { public static final @NotNull Field CONVERSATION_TRACKER = ReflectionUtil.getField("conversationTracker", CraftPlayer.class); public static final @NotNull Field CONVERSATION_QUEUE = ReflectionUtil.getField("conversationQueue", ConversationTracker.class); From 4b2f1f86864e4ca128d1ebd069edaf7b3be878c4 Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Mon, 14 Jul 2025 17:34:05 -0300 Subject: [PATCH 70/73] changed the branch --- .github/workflows/publish.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 5412ecfe..d6154336 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -6,7 +6,7 @@ on: - published push: branches: - - 1.20.6\+ + - new-command-system-1.20.6\+ env: USERNAME: ${{ github.actor }} From b665d6a30b5b8fa5afb6f109d68427563b0a2543 Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Mon, 14 Jul 2025 17:34:29 -0300 Subject: [PATCH 71/73] changed the version schema --- build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index 18f5c128..62228895 100644 --- a/build.gradle +++ b/build.gradle @@ -9,7 +9,7 @@ allprojects { apply plugin: 'maven-publish' group = 'com.wizardlybump17.wlib' - version = "1.6.8-ncs+1.20.6" + ("true".equalsIgnoreCase(System.getenv("WLIB_SNAPSHOT")) ? "-SNAPSHOT." + System.getenv("WLIB_SNAPSHOT_NUMBER") : "") + version = "1.6.8-ncs-1.20.6+" + ("true".equalsIgnoreCase(System.getenv("WLIB_SNAPSHOT")) ? "-SNAPSHOT." + System.getenv("WLIB_SNAPSHOT_NUMBER") : "") repositories { mavenLocal() From c0d2f6912b7dee7fb641178939f504b5526590a1 Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Mon, 14 Jul 2025 17:36:31 -0300 Subject: [PATCH 72/73] there is no + on the name --- .github/workflows/publish.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index d6154336..eb18b0c8 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -6,7 +6,7 @@ on: - published push: branches: - - new-command-system-1.20.6\+ + - new-command-system-1.20.6 env: USERNAME: ${{ github.actor }} From 949a401cf87717ea59fbb0185a448455fa84b1db Mon Sep 17 00:00:00 2001 From: WizardlyBump17 Date: Mon, 14 Jul 2025 18:22:41 -0300 Subject: [PATCH 73/73] subprojects --- build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index 62228895..014ee24d 100644 --- a/build.gradle +++ b/build.gradle @@ -3,7 +3,7 @@ plugins { id 'maven-publish' } -allprojects { +subprojects { apply plugin: "com.gradleup.shadow" apply plugin: 'java' apply plugin: 'maven-publish'