From 091fb23aace95cca6e5356a0795659241a4e4c15 Mon Sep 17 00:00:00 2001 From: alexcrea <42614139+alexcrea@users.noreply.github.com> Date: Mon, 8 Jul 2024 17:06:39 +0200 Subject: [PATCH] Add get every registered for Enchantment, Conflict and Material group. Also updated some javadoc. --- .../xyz/alexcrea/cuanvil/api/ConflictAPI.java | 45 ++++++---- .../alexcrea/cuanvil/api/ConflictBuilder.java | 88 +++++++++++-------- .../alexcrea/cuanvil/api/EnchantmentApi.java | 52 +++++++---- .../cuanvil/api/MaterialGroupApi.java | 20 +++-- .../cuanvil/enchant/CAEnchantment.java | 7 +- .../cuanvil/enchant/CAEnchantmentBase.java | 5 ++ .../enchant/CAEnchantmentRegistry.java | 18 ++-- .../wrapped/CAEnchantSquaredEnchantment.java | 4 +- .../enchant/wrapped/CAVanillaEnchantment.java | 3 + 9 files changed, 155 insertions(+), 87 deletions(-) diff --git a/src/main/java/xyz/alexcrea/cuanvil/api/ConflictAPI.java b/src/main/java/xyz/alexcrea/cuanvil/api/ConflictAPI.java index a0a077a..478b856 100644 --- a/src/main/java/xyz/alexcrea/cuanvil/api/ConflictAPI.java +++ b/src/main/java/xyz/alexcrea/cuanvil/api/ConflictAPI.java @@ -11,7 +11,9 @@ import xyz.alexcrea.cuanvil.enchant.CAEnchantment; import xyz.alexcrea.cuanvil.group.*; import xyz.alexcrea.cuanvil.gui.config.global.EnchantConflictGui; +import java.util.Collections; import java.util.HashSet; +import java.util.List; import java.util.Set; /** @@ -27,8 +29,8 @@ public class ConflictAPI { * Write and add a conflict. * Will not write the conflict if it already exists. * - * @param builder the conflict builder to base on - * @return true if successful + * @param builder The conflict builder to base on + * @return True if successful. */ public boolean addConflict(@NotNull ConflictBuilder builder){ FileConfiguration config = ConfigHolder.CONFLICT_HOLDER.getConfig(); @@ -48,8 +50,8 @@ public class ConflictAPI { /** * Append builders stored enchantments into conflict. * - * @param builder the builder source - * @param conflict the conflict target + * @param builder The builder source + * @param conflict The conflict target */ protected void appendEnchantments(@NotNull ConflictBuilder builder, @NotNull EnchantConflictGroup conflict){ for (String enchantmentName : builder.getEnchantmentNames()){ @@ -69,9 +71,9 @@ public class ConflictAPI { /** * Append an enchantment. * - * @param conflict the conflict target - * @param enchantment the enchantment - * @return true if successful + * @param conflict The conflict target + * @param enchantment The enchantment + * @return True if successful. */ protected boolean appendEnchantment(@NotNull EnchantConflictGroup conflict, @Nullable CAEnchantment enchantment){ if(enchantment == null) @@ -83,8 +85,8 @@ public class ConflictAPI { /** * Extract group abstract material group. * - * @param builder the builder source - * @return the abstract material group from the builder + * @param builder The builder source + * @return The abstract material group from the builder. */ protected AbstractMaterialGroup extractGroup(@NotNull ConflictBuilder builder){ ItemGroupManager itemGroupManager = ConfigHolder.ITEM_GROUP_HOLDER.getItemGroupsManager(); @@ -110,8 +112,8 @@ public class ConflictAPI { *
* You may want to use {@link #addConflict(ConflictBuilder)} instead as it is more performance in most case as this function will reload every conflict. * - * @param builder the builder - * @return true if successful + * @param builder The builder + * @return True if successful. */ public boolean writeConflict(@NotNull ConflictBuilder builder){ return writeConflict(builder, true); @@ -122,9 +124,9 @@ public class ConflictAPI { *
* You should use {@link #addConflict(ConflictBuilder)} or {@link #writeConflict(ConflictBuilder)} instead
*
- * @param builder the builder
- * @param updatePlanned if we should plan a global update for conflicts
- * @return true if successful
+ * @param builder The builder
+ * @param updatePlanned If we should plan a global update for conflicts
+ * @return True if successful.
*/
public boolean writeConflict(@NotNull ConflictBuilder builder, boolean updatePlanned){
FileConfiguration config = ConfigHolder.CONFLICT_HOLDER.getConfig();
@@ -153,8 +155,8 @@ public class ConflictAPI {
/**
* Extract every enchantment names from a builder.
- * @param builder the builder storing the enchantments
- * @return builder's stored enchantment
+ * @param builder The builder storing the enchantments
+ * @return Builder's stored enchantment.
*/
@NotNull
private Set
* This value represent how many enchantment contained on this conflict can be applied to before conflict is considered active.
* That mean new enchantment will not be able to be added to the item and present enchantment will not have its level upgraded.
@@ -131,8 +143,8 @@ public class ConflictBuilder {
/**
* Sets conflict name.
*
- * @param name the name
- * @return the name
+ * @param name The name
+ * @return This conflict builder instance.
*/
public ConflictBuilder setName(String name) {
this.name = name;
@@ -140,15 +152,15 @@ public class ConflictBuilder {
}
/**
- * Sets max number of conflicting enchantment before conflict is active.
+ * Sets maximum number of conflicting enchantment before conflict is active.
*
* This value represent how many enchantment contained on this conflict can be applied to before conflict is considered active.
* That mean new enchantment will not be able to be added to the item and present enchantment will not have its level upgraded.
*
* In vanilla. material restriction have this value set to 0 and enchantment conflict set to 1.
*
- * @param maxBeforeConflict the max before conflict
- * @return the max before conflict
+ * @param maxBeforeConflict The max before conflict
+ * @return This conflict builder instance.
*/
public ConflictBuilder setMaxBeforeConflict(int maxBeforeConflict) {
this.maxBeforeConflict = maxBeforeConflict;
@@ -158,8 +170,8 @@ public class ConflictBuilder {
/**
* Add a conflicting enchantment by name.
*
- * @param enchantmentName the enchantment name
- * @return this conflict builder instance
+ * @param enchantmentName The enchantment name
+ * @return This conflict builder instance.
*/
@NotNull
public ConflictBuilder addEnchantment(@NotNull String enchantmentName){
@@ -170,8 +182,8 @@ public class ConflictBuilder {
/**
* Add a conflicting enchantment by key.
*
- * @param enchantmentKey the enchantment key
- * @return this conflict builder instance
+ * @param enchantmentKey The enchantment key
+ * @return This conflict builder instance.
*/
@NotNull
public ConflictBuilder addEnchantment(@NotNull NamespacedKey enchantmentKey){
@@ -182,8 +194,8 @@ public class ConflictBuilder {
/**
* Add a conflicting enchantment by instance.
*
- * @param enchantment the enchantment
- * @return this conflict builder instance
+ * @param enchantment The enchantment
+ * @return This conflict builder instance.
*/
@NotNull
public ConflictBuilder addEnchantment(@NotNull CAEnchantment enchantment){
@@ -194,8 +206,8 @@ public class ConflictBuilder {
/**
* Remove conflicting enchantment by name.
*
- * @param enchantmentName the enchantment name
- * @return this conflict builder instance
+ * @param enchantmentName The enchantment name
+ * @return This conflict builder instance.
*/
@NotNull
public ConflictBuilder removeEnchantment(@NotNull String enchantmentName){
@@ -206,8 +218,8 @@ public class ConflictBuilder {
/**
* Remove conflicting enchantment by key.
*
- * @param enchantmentKey the enchantment key
- * @return this conflict builder instance
+ * @param enchantmentKey The enchantment key
+ * @return This conflict builder instance.
*/
@NotNull
public ConflictBuilder removeEnchantment(@NotNull NamespacedKey enchantmentKey){
@@ -218,8 +230,8 @@ public class ConflictBuilder {
/**
* Remove enchantment by instance.
*
- * @param enchantment the enchantment
- * @return this conflict builder instance
+ * @param enchantment The enchantment
+ * @return This conflict builder instance.
*/
@NotNull
public ConflictBuilder removeEnchantment(@NotNull CAEnchantment enchantment){
@@ -237,8 +249,8 @@ public class ConflictBuilder {
* with {@link #setMaxBeforeConflict(int) maxBeforeConflict} set to 0.
* Then only pickaxe will be able to have efficiency.
*
- * @param groupName the group name
- * @return this conflict builder instance
+ * @param groupName The group name
+ * @return This conflict builder instance.
*/
@NotNull
public ConflictBuilder addExcludedGroup(@NotNull String groupName){
@@ -257,8 +269,8 @@ public class ConflictBuilder {
* with {@link #setMaxBeforeConflict(int) maxBeforeConflict} set to 0.
* Then only pickaxe will be able to have efficiency.
*
- * @param group the group
- * @return this conflict builder instance
+ * @param group The group
+ * @return this conflict builder instance.
*/
@NotNull
public ConflictBuilder addExcludedGroup(@NotNull AbstractMaterialGroup group){
@@ -276,8 +288,8 @@ public class ConflictBuilder {
* with {@link #setMaxBeforeConflict(int) maxBeforeConflict} set to 0.
* Then only pickaxe will be able to have efficiency.
*
- * @param groupName the group name
- * @return this conflict builder instance
+ * @param groupName The group name
+ * @return This conflict builder instance.
*/
@NotNull
public ConflictBuilder removeExcludedGroup(@NotNull String groupName){
@@ -296,8 +308,8 @@ public class ConflictBuilder {
* with {@link #setMaxBeforeConflict(int) maxBeforeConflict} set to 0.
* Then only pickaxe will be able to have efficiency.
*
- * @param group the group
- * @return this conflict builder instance
+ * @param group The group
+ * @return This conflict builder instance.
*/
@NotNull
public ConflictBuilder removeExcludedGroup(@NotNull AbstractMaterialGroup group){
@@ -307,7 +319,7 @@ public class ConflictBuilder {
/**
* Copy this conflict builder.
*
- * @return a copy of this conflict builder
+ * @return A copy of this conflict builder.
*/
@NotNull
public ConflictBuilder copy() {
diff --git a/src/main/java/xyz/alexcrea/cuanvil/api/EnchantmentApi.java b/src/main/java/xyz/alexcrea/cuanvil/api/EnchantmentApi.java
index 08471a0..a41aa55 100644
--- a/src/main/java/xyz/alexcrea/cuanvil/api/EnchantmentApi.java
+++ b/src/main/java/xyz/alexcrea/cuanvil/api/EnchantmentApi.java
@@ -9,6 +9,9 @@ import xyz.alexcrea.cuanvil.enchant.CAEnchantmentRegistry;
import xyz.alexcrea.cuanvil.enchant.EnchantmentRarity;
import xyz.alexcrea.cuanvil.enchant.wrapped.CAVanillaEnchantment;
+import java.util.Collections;
+import java.util.Map;
+
/**
* Custom Anvil api for enchantment registry.
*/
@@ -20,8 +23,8 @@ public class EnchantmentApi {
/**
* Register an enchantment.
*
- * @param enchantment the enchantment to register
- * @return true if successful
+ * @param enchantment The enchantment to register
+ * @return True if successful.
*/
public static boolean registerEnchantment(@NotNull CAEnchantment enchantment){
return CAEnchantmentRegistry.getInstance().register(enchantment);
@@ -30,9 +33,9 @@ public class EnchantmentApi {
/**
* Register an enchantment by minecraft registered enchantment instance.
*
- * @param enchantment the enchantment to register
- * @param defaultRarity the default rarity of the provided enchantment
- * @return true if successful
+ * @param enchantment The enchantment to register
+ * @param defaultRarity The default rarity of the provided enchantment
+ * @return True if successful.
*/
public static boolean registerEnchantment(@NotNull Enchantment enchantment, @Nullable EnchantmentRarity defaultRarity){
if(defaultRarity == null)
@@ -43,9 +46,11 @@ public class EnchantmentApi {
/**
* Register an enchantment by minecraft registered enchantment instance.
+ *
+ * Please note that this function assume the provided enchantment is registered into minecraft registry.
*
- * @param enchantment the enchantment to register
- * @return true if successful
+ * @param enchantment The enchantment to register
+ * @return True if successful.
*/
public static boolean registerEnchantment(@NotNull Enchantment enchantment){
return registerEnchantment(new CAVanillaEnchantment(enchantment));
@@ -54,8 +59,8 @@ public class EnchantmentApi {
/**
* Unregister an enchantment by its key.
*
- * @param key the enchantment key to unregister
- * @return true if successful
+ * @param key The enchantment key to unregister
+ * @return True if successful.
*/
public static boolean unregisterEnchantment(@NotNull NamespacedKey key){
CAEnchantment enchantment = CAEnchantmentRegistry.getInstance().getByKey(key);
@@ -65,8 +70,8 @@ public class EnchantmentApi {
/**
* Unregister an enchantment.
*
- * @param enchantment the enchantment to unregister
- * @return true if successful
+ * @param enchantment The enchantment to unregister
+ * @return True if successful.
*/
public static boolean unregisterEnchantment(@NotNull CAEnchantment enchantment){
return CAEnchantmentRegistry.getInstance().unregister(enchantment);
@@ -75,18 +80,18 @@ public class EnchantmentApi {
/**
* Unregister an enchantment by his bukkit enchantment.
*
- * @param enchantment the enchantment to unregister
- * @return true if successful
+ * @param enchantment The enchantment to unregister
+ * @return True if successful.
*/
public static boolean unregisterEnchantment(@NotNull Enchantment enchantment){
return unregisterEnchantment(enchantment.getKey());
}
/**
- * Get by key a enchantment.
+ * Get by key an enchantment.
*
- * @param key the key used to fetch
- * @return the custom anvil enchantment
+ * @param key The key used to fetch
+ * @return The custom anvil enchantment of this key. null if not found.
*/
@Nullable
public static CAEnchantment getByKey(@NotNull NamespacedKey key){
@@ -94,14 +99,23 @@ public class EnchantmentApi {
}
/**
- * Get by name a enchantment.
+ * Get by name an enchantment.
*
- * @param name the name used to fetch
- * @return the custom anvil enchantment
+ * @param name The name used to fetch
+ * @return The custom anvil enchantment of this name. null if not found.
*/
@Nullable
public static CAEnchantment getByName(@NotNull String name){
return CAEnchantmentRegistry.getInstance().getByName(name);
}
+ /**
+ * Get every registered custom anvil enchantments.
+ * @return An immutable map of enchantment key as map key and custom anvil enchantment as value.
+ */
+ @NotNull
+ public Map