Add get every registered for Enchantment, Conflict and Material group.

Also updated some javadoc.
This commit is contained in:
alexcrea 2024-07-08 17:06:39 +02:00
parent fca7bbb416
commit 091fb23aac
No known key found for this signature in database
GPG key ID: 43FD265DB0DBF91F
9 changed files with 155 additions and 87 deletions

View file

@ -11,7 +11,9 @@ import xyz.alexcrea.cuanvil.enchant.CAEnchantment;
import xyz.alexcrea.cuanvil.group.*; import xyz.alexcrea.cuanvil.group.*;
import xyz.alexcrea.cuanvil.gui.config.global.EnchantConflictGui; import xyz.alexcrea.cuanvil.gui.config.global.EnchantConflictGui;
import java.util.Collections;
import java.util.HashSet; import java.util.HashSet;
import java.util.List;
import java.util.Set; import java.util.Set;
/** /**
@ -27,8 +29,8 @@ public class ConflictAPI {
* Write and add a conflict. * Write and add a conflict.
* Will not write the conflict if it already exists. * Will not write the conflict if it already exists.
* *
* @param builder the conflict builder to base on * @param builder The conflict builder to base on
* @return true if successful * @return True if successful.
*/ */
public boolean addConflict(@NotNull ConflictBuilder builder){ public boolean addConflict(@NotNull ConflictBuilder builder){
FileConfiguration config = ConfigHolder.CONFLICT_HOLDER.getConfig(); FileConfiguration config = ConfigHolder.CONFLICT_HOLDER.getConfig();
@ -48,8 +50,8 @@ public class ConflictAPI {
/** /**
* Append builders stored enchantments into conflict. * Append builders stored enchantments into conflict.
* *
* @param builder the builder source * @param builder The builder source
* @param conflict the conflict target * @param conflict The conflict target
*/ */
protected void appendEnchantments(@NotNull ConflictBuilder builder, @NotNull EnchantConflictGroup conflict){ protected void appendEnchantments(@NotNull ConflictBuilder builder, @NotNull EnchantConflictGroup conflict){
for (String enchantmentName : builder.getEnchantmentNames()){ for (String enchantmentName : builder.getEnchantmentNames()){
@ -69,9 +71,9 @@ public class ConflictAPI {
/** /**
* Append an enchantment. * Append an enchantment.
* *
* @param conflict the conflict target * @param conflict The conflict target
* @param enchantment the enchantment * @param enchantment The enchantment
* @return true if successful * @return True if successful.
*/ */
protected boolean appendEnchantment(@NotNull EnchantConflictGroup conflict, @Nullable CAEnchantment enchantment){ protected boolean appendEnchantment(@NotNull EnchantConflictGroup conflict, @Nullable CAEnchantment enchantment){
if(enchantment == null) if(enchantment == null)
@ -83,8 +85,8 @@ public class ConflictAPI {
/** /**
* Extract group abstract material group. * Extract group abstract material group.
* *
* @param builder the builder source * @param builder The builder source
* @return the abstract material group from the builder * @return The abstract material group from the builder.
*/ */
protected AbstractMaterialGroup extractGroup(@NotNull ConflictBuilder builder){ protected AbstractMaterialGroup extractGroup(@NotNull ConflictBuilder builder){
ItemGroupManager itemGroupManager = ConfigHolder.ITEM_GROUP_HOLDER.getItemGroupsManager(); ItemGroupManager itemGroupManager = ConfigHolder.ITEM_GROUP_HOLDER.getItemGroupsManager();
@ -110,8 +112,8 @@ public class ConflictAPI {
* <p> * <p>
* You may want to use {@link #addConflict(ConflictBuilder)} instead as it is more performance in most case as this function will reload every conflict. * 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 * @param builder The builder
* @return true if successful * @return True if successful.
*/ */
public boolean writeConflict(@NotNull ConflictBuilder builder){ public boolean writeConflict(@NotNull ConflictBuilder builder){
return writeConflict(builder, true); return writeConflict(builder, true);
@ -122,9 +124,9 @@ public class ConflictAPI {
* <p> * <p>
* You should use {@link #addConflict(ConflictBuilder)} or {@link #writeConflict(ConflictBuilder)} instead * You should use {@link #addConflict(ConflictBuilder)} or {@link #writeConflict(ConflictBuilder)} instead
* *
* @param builder the builder * @param builder The builder
* @param updatePlanned if we should plan a global update for conflicts * @param updatePlanned If we should plan a global update for conflicts
* @return true if successful * @return True if successful.
*/ */
public boolean writeConflict(@NotNull ConflictBuilder builder, boolean updatePlanned){ public boolean writeConflict(@NotNull ConflictBuilder builder, boolean updatePlanned){
FileConfiguration config = ConfigHolder.CONFLICT_HOLDER.getConfig(); FileConfiguration config = ConfigHolder.CONFLICT_HOLDER.getConfig();
@ -153,8 +155,8 @@ public class ConflictAPI {
/** /**
* Extract every enchantment names from a builder. * Extract every enchantment names from a builder.
* @param builder the builder storing the enchantments * @param builder The builder storing the enchantments
* @return builder's stored enchantment * @return Builder's stored enchantment.
*/ */
@NotNull @NotNull
private Set<String> extractEnchantments(@NotNull ConflictBuilder builder){ private Set<String> extractEnchantments(@NotNull ConflictBuilder builder){
@ -196,4 +198,15 @@ public class ConflictAPI {
CustomAnvil.instance.getLogger().warning("Conflict " + builder.getName() +" came from " + builder.getSourceName() + "."); CustomAnvil.instance.getLogger().warning("Conflict " + builder.getName() +" came from " + builder.getSourceName() + ".");
} }
/**
* Get every registered conflict.
* @return An immutable collection of conflict.
*/
@NotNull
public List<EnchantConflictGroup> getRegisteredConflict(){
List<EnchantConflictGroup> mutableList = ConfigHolder.CONFLICT_HOLDER.getConflictManager().getConflictList();
return Collections.unmodifiableList(mutableList);
}
} }

View file

@ -29,10 +29,11 @@ public class ConflictBuilder {
/** /**
* Instantiates a new Conflict builder. * Instantiates a new Conflict builder.
* *
* @param source the source * @param name The conflict name
* @param name the name * @param maxBeforeConflict Maximum number of conflicting enchantment before conflict is active
* @param source The conflict source
*/ */
public ConflictBuilder(@NotNull String name, @Nullable Plugin source){ public ConflictBuilder(@NotNull String name, int maxBeforeConflict, @Nullable Plugin source){
this.source = source; this.source = source;
this.name = name; this.name = name;
@ -41,12 +42,23 @@ public class ConflictBuilder {
this.excludedGroupNames = new HashSet<>(); this.excludedGroupNames = new HashSet<>();
this.maxBeforeConflict = 0; this.maxBeforeConflict = maxBeforeConflict;
} }
/** /**
* Instantiates a new Conflict builder. * Instantiates a new Conflict builder.
* *
* @param name the conflict name * @param name The conflict name
* @param source The conflict source
*/
public ConflictBuilder(@NotNull String name, @Nullable Plugin source){
this(name, 0, source);
}
/**
* Instantiates a new Conflict builder.
*
* @param name The conflict name
*/ */
public ConflictBuilder(@NotNull String name){ public ConflictBuilder(@NotNull String name){
this(name, null); this(name, null);
@ -55,7 +67,7 @@ public class ConflictBuilder {
/** /**
* Gets conflict source. * Gets conflict source.
* *
* @return the conflict source * @return The conflict source.
*/ */
@Nullable @Nullable
public Plugin getSource() { public Plugin getSource() {
@ -65,7 +77,7 @@ public class ConflictBuilder {
/** /**
* Gets conflict source name. * Gets conflict source name.
* *
* @return the conflict source * @return The conflict source name.
*/ */
@NotNull @NotNull
public String getSourceName() { public String getSourceName() {
@ -77,7 +89,7 @@ public class ConflictBuilder {
/** /**
* Gets conflict name. * Gets conflict name.
* *
* @return the name * @return The conflict name.
*/ */
@NotNull @NotNull
public String getName() { public String getName() {
@ -87,7 +99,7 @@ public class ConflictBuilder {
/** /**
* Gets stored conflicting enchantment names. * Gets stored conflicting enchantment names.
* *
* @return the enchantment names * @return The stored enchantment names.
*/ */
@NotNull @NotNull
public Set<String> getEnchantmentNames() { public Set<String> getEnchantmentNames() {
@ -97,7 +109,7 @@ public class ConflictBuilder {
/** /**
* Gets stored conflicting enchantment keys. * Gets stored conflicting enchantment keys.
* *
* @return the enchantment keys * @return The stored enchantment keys.
*/ */
@NotNull @NotNull
public Set<NamespacedKey> getEnchantmentKeys() { public Set<NamespacedKey> getEnchantmentKeys() {
@ -107,7 +119,7 @@ public class ConflictBuilder {
/** /**
* Gets stored excluded group names. * Gets stored excluded group names.
* *
* @return the group names * @return The stored group names.
*/ */
@NotNull @NotNull
public Set<String> getExcludedGroupNames() { public Set<String> getExcludedGroupNames() {
@ -115,7 +127,7 @@ public class ConflictBuilder {
} }
/** /**
* Gets max number of conflicting enchantment before conflict is active. * Gets maximum number of conflicting enchantment before conflict is active.
* <p> * <p>
* This value represent how many enchantment contained on this conflict can be applied to before conflict is considered 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. * 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. * Sets conflict name.
* *
* @param name the name * @param name The name
* @return the name * @return This conflict builder instance.
*/ */
public ConflictBuilder setName(String name) { public ConflictBuilder setName(String name) {
this.name = 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.
* <p> * <p>
* This value represent how many enchantment contained on this conflict can be applied to before conflict is considered 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. * That mean new enchantment will not be able to be added to the item and present enchantment will not have its level upgraded.
* <p> * <p>
* In vanilla. material restriction have this value set to 0 and enchantment conflict set to 1. * In vanilla. material restriction have this value set to 0 and enchantment conflict set to 1.
* *
* @param maxBeforeConflict the max before conflict * @param maxBeforeConflict The max before conflict
* @return the max before conflict * @return This conflict builder instance.
*/ */
public ConflictBuilder setMaxBeforeConflict(int maxBeforeConflict) { public ConflictBuilder setMaxBeforeConflict(int maxBeforeConflict) {
this.maxBeforeConflict = maxBeforeConflict; this.maxBeforeConflict = maxBeforeConflict;
@ -158,8 +170,8 @@ public class ConflictBuilder {
/** /**
* Add a conflicting enchantment by name. * Add a conflicting enchantment by name.
* *
* @param enchantmentName the enchantment name * @param enchantmentName The enchantment name
* @return this conflict builder instance * @return This conflict builder instance.
*/ */
@NotNull @NotNull
public ConflictBuilder addEnchantment(@NotNull String enchantmentName){ public ConflictBuilder addEnchantment(@NotNull String enchantmentName){
@ -170,8 +182,8 @@ public class ConflictBuilder {
/** /**
* Add a conflicting enchantment by key. * Add a conflicting enchantment by key.
* *
* @param enchantmentKey the enchantment key * @param enchantmentKey The enchantment key
* @return this conflict builder instance * @return This conflict builder instance.
*/ */
@NotNull @NotNull
public ConflictBuilder addEnchantment(@NotNull NamespacedKey enchantmentKey){ public ConflictBuilder addEnchantment(@NotNull NamespacedKey enchantmentKey){
@ -182,8 +194,8 @@ public class ConflictBuilder {
/** /**
* Add a conflicting enchantment by instance. * Add a conflicting enchantment by instance.
* *
* @param enchantment the enchantment * @param enchantment The enchantment
* @return this conflict builder instance * @return This conflict builder instance.
*/ */
@NotNull @NotNull
public ConflictBuilder addEnchantment(@NotNull CAEnchantment enchantment){ public ConflictBuilder addEnchantment(@NotNull CAEnchantment enchantment){
@ -194,8 +206,8 @@ public class ConflictBuilder {
/** /**
* Remove conflicting enchantment by name. * Remove conflicting enchantment by name.
* *
* @param enchantmentName the enchantment name * @param enchantmentName The enchantment name
* @return this conflict builder instance * @return This conflict builder instance.
*/ */
@NotNull @NotNull
public ConflictBuilder removeEnchantment(@NotNull String enchantmentName){ public ConflictBuilder removeEnchantment(@NotNull String enchantmentName){
@ -206,8 +218,8 @@ public class ConflictBuilder {
/** /**
* Remove conflicting enchantment by key. * Remove conflicting enchantment by key.
* *
* @param enchantmentKey the enchantment key * @param enchantmentKey The enchantment key
* @return this conflict builder instance * @return This conflict builder instance.
*/ */
@NotNull @NotNull
public ConflictBuilder removeEnchantment(@NotNull NamespacedKey enchantmentKey){ public ConflictBuilder removeEnchantment(@NotNull NamespacedKey enchantmentKey){
@ -218,8 +230,8 @@ public class ConflictBuilder {
/** /**
* Remove enchantment by instance. * Remove enchantment by instance.
* *
* @param enchantment the enchantment * @param enchantment The enchantment
* @return this conflict builder instance * @return This conflict builder instance.
*/ */
@NotNull @NotNull
public ConflictBuilder removeEnchantment(@NotNull CAEnchantment enchantment){ public ConflictBuilder removeEnchantment(@NotNull CAEnchantment enchantment){
@ -237,8 +249,8 @@ public class ConflictBuilder {
* with {@link #setMaxBeforeConflict(int) maxBeforeConflict} set to 0. * with {@link #setMaxBeforeConflict(int) maxBeforeConflict} set to 0.
* Then only pickaxe will be able to have efficiency. * Then only pickaxe will be able to have efficiency.
* *
* @param groupName the group name * @param groupName The group name
* @return this conflict builder instance * @return This conflict builder instance.
*/ */
@NotNull @NotNull
public ConflictBuilder addExcludedGroup(@NotNull String groupName){ public ConflictBuilder addExcludedGroup(@NotNull String groupName){
@ -257,8 +269,8 @@ public class ConflictBuilder {
* with {@link #setMaxBeforeConflict(int) maxBeforeConflict} set to 0. * with {@link #setMaxBeforeConflict(int) maxBeforeConflict} set to 0.
* Then only pickaxe will be able to have efficiency. * Then only pickaxe will be able to have efficiency.
* *
* @param group the group * @param group The group
* @return this conflict builder instance * @return this conflict builder instance.
*/ */
@NotNull @NotNull
public ConflictBuilder addExcludedGroup(@NotNull AbstractMaterialGroup group){ public ConflictBuilder addExcludedGroup(@NotNull AbstractMaterialGroup group){
@ -276,8 +288,8 @@ public class ConflictBuilder {
* with {@link #setMaxBeforeConflict(int) maxBeforeConflict} set to 0. * with {@link #setMaxBeforeConflict(int) maxBeforeConflict} set to 0.
* Then only pickaxe will be able to have efficiency. * Then only pickaxe will be able to have efficiency.
* *
* @param groupName the group name * @param groupName The group name
* @return this conflict builder instance * @return This conflict builder instance.
*/ */
@NotNull @NotNull
public ConflictBuilder removeExcludedGroup(@NotNull String groupName){ public ConflictBuilder removeExcludedGroup(@NotNull String groupName){
@ -296,8 +308,8 @@ public class ConflictBuilder {
* with {@link #setMaxBeforeConflict(int) maxBeforeConflict} set to 0. * with {@link #setMaxBeforeConflict(int) maxBeforeConflict} set to 0.
* Then only pickaxe will be able to have efficiency. * Then only pickaxe will be able to have efficiency.
* *
* @param group the group * @param group The group
* @return this conflict builder instance * @return This conflict builder instance.
*/ */
@NotNull @NotNull
public ConflictBuilder removeExcludedGroup(@NotNull AbstractMaterialGroup group){ public ConflictBuilder removeExcludedGroup(@NotNull AbstractMaterialGroup group){
@ -307,7 +319,7 @@ public class ConflictBuilder {
/** /**
* Copy this conflict builder. * Copy this conflict builder.
* *
* @return a copy of this conflict builder * @return A copy of this conflict builder.
*/ */
@NotNull @NotNull
public ConflictBuilder copy() { public ConflictBuilder copy() {

View file

@ -9,6 +9,9 @@ import xyz.alexcrea.cuanvil.enchant.CAEnchantmentRegistry;
import xyz.alexcrea.cuanvil.enchant.EnchantmentRarity; import xyz.alexcrea.cuanvil.enchant.EnchantmentRarity;
import xyz.alexcrea.cuanvil.enchant.wrapped.CAVanillaEnchantment; import xyz.alexcrea.cuanvil.enchant.wrapped.CAVanillaEnchantment;
import java.util.Collections;
import java.util.Map;
/** /**
* Custom Anvil api for enchantment registry. * Custom Anvil api for enchantment registry.
*/ */
@ -20,8 +23,8 @@ public class EnchantmentApi {
/** /**
* Register an enchantment. * Register an enchantment.
* *
* @param enchantment the enchantment to register * @param enchantment The enchantment to register
* @return true if successful * @return True if successful.
*/ */
public static boolean registerEnchantment(@NotNull CAEnchantment enchantment){ public static boolean registerEnchantment(@NotNull CAEnchantment enchantment){
return CAEnchantmentRegistry.getInstance().register(enchantment); return CAEnchantmentRegistry.getInstance().register(enchantment);
@ -30,9 +33,9 @@ public class EnchantmentApi {
/** /**
* Register an enchantment by minecraft registered enchantment instance. * Register an enchantment by minecraft registered enchantment instance.
* *
* @param enchantment the enchantment to register * @param enchantment The enchantment to register
* @param defaultRarity the default rarity of the provided enchantment * @param defaultRarity The default rarity of the provided enchantment
* @return true if successful * @return True if successful.
*/ */
public static boolean registerEnchantment(@NotNull Enchantment enchantment, @Nullable EnchantmentRarity defaultRarity){ public static boolean registerEnchantment(@NotNull Enchantment enchantment, @Nullable EnchantmentRarity defaultRarity){
if(defaultRarity == null) if(defaultRarity == null)
@ -43,9 +46,11 @@ public class EnchantmentApi {
/** /**
* Register an enchantment by minecraft registered enchantment instance. * Register an enchantment by minecraft registered enchantment instance.
* <p>
* Please note that this function assume the provided enchantment is registered into minecraft registry.
* *
* @param enchantment the enchantment to register * @param enchantment The enchantment to register
* @return true if successful * @return True if successful.
*/ */
public static boolean registerEnchantment(@NotNull Enchantment enchantment){ public static boolean registerEnchantment(@NotNull Enchantment enchantment){
return registerEnchantment(new CAVanillaEnchantment(enchantment)); return registerEnchantment(new CAVanillaEnchantment(enchantment));
@ -54,8 +59,8 @@ public class EnchantmentApi {
/** /**
* Unregister an enchantment by its key. * Unregister an enchantment by its key.
* *
* @param key the enchantment key to unregister * @param key The enchantment key to unregister
* @return true if successful * @return True if successful.
*/ */
public static boolean unregisterEnchantment(@NotNull NamespacedKey key){ public static boolean unregisterEnchantment(@NotNull NamespacedKey key){
CAEnchantment enchantment = CAEnchantmentRegistry.getInstance().getByKey(key); CAEnchantment enchantment = CAEnchantmentRegistry.getInstance().getByKey(key);
@ -65,8 +70,8 @@ public class EnchantmentApi {
/** /**
* Unregister an enchantment. * Unregister an enchantment.
* *
* @param enchantment the enchantment to unregister * @param enchantment The enchantment to unregister
* @return true if successful * @return True if successful.
*/ */
public static boolean unregisterEnchantment(@NotNull CAEnchantment enchantment){ public static boolean unregisterEnchantment(@NotNull CAEnchantment enchantment){
return CAEnchantmentRegistry.getInstance().unregister(enchantment); return CAEnchantmentRegistry.getInstance().unregister(enchantment);
@ -75,18 +80,18 @@ public class EnchantmentApi {
/** /**
* Unregister an enchantment by his bukkit enchantment. * Unregister an enchantment by his bukkit enchantment.
* *
* @param enchantment the enchantment to unregister * @param enchantment The enchantment to unregister
* @return true if successful * @return True if successful.
*/ */
public static boolean unregisterEnchantment(@NotNull Enchantment enchantment){ public static boolean unregisterEnchantment(@NotNull Enchantment enchantment){
return unregisterEnchantment(enchantment.getKey()); return unregisterEnchantment(enchantment.getKey());
} }
/** /**
* Get by key a enchantment. * Get by key an enchantment.
* *
* @param key the key used to fetch * @param key The key used to fetch
* @return the custom anvil enchantment * @return The custom anvil enchantment of this key. null if not found.
*/ */
@Nullable @Nullable
public static CAEnchantment getByKey(@NotNull NamespacedKey key){ 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 * @param name The name used to fetch
* @return the custom anvil enchantment * @return The custom anvil enchantment of this name. null if not found.
*/ */
@Nullable @Nullable
public static CAEnchantment getByName(@NotNull String name){ public static CAEnchantment getByName(@NotNull String name){
return CAEnchantmentRegistry.getInstance().getByName(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<NamespacedKey, CAEnchantment> getRegisteredEnchantments(){
return Collections.unmodifiableMap(CAEnchantmentRegistry.getInstance().registeredEnchantments());
}
} }

View file

@ -13,11 +13,13 @@ import xyz.alexcrea.cuanvil.group.IncludeGroup;
import xyz.alexcrea.cuanvil.group.ItemGroupManager; import xyz.alexcrea.cuanvil.group.ItemGroupManager;
import xyz.alexcrea.cuanvil.gui.config.global.GroupConfigGui; import xyz.alexcrea.cuanvil.gui.config.global.GroupConfigGui;
import java.util.Collections;
import java.util.EnumSet; import java.util.EnumSet;
import java.util.Map;
import java.util.Set; import java.util.Set;
/** /**
* The type Material group api. * Custom Anvil api for material group registry.
*/ */
@SuppressWarnings("unused") @SuppressWarnings("unused")
public class MaterialGroupApi { public class MaterialGroupApi {
@ -30,7 +32,7 @@ public class MaterialGroupApi {
* Will not write the group if it already exists. * Will not write the group if it already exists.
* *
* @param group the group to add * @param group the group to add
* @return true if successful * @return true if successful.
*/ */
public boolean addMaterialGroup(@NotNull AbstractMaterialGroup group){ public boolean addMaterialGroup(@NotNull AbstractMaterialGroup group){
ItemGroupManager itemGroupManager = ConfigHolder.ITEM_GROUP_HOLDER.getItemGroupsManager(); ItemGroupManager itemGroupManager = ConfigHolder.ITEM_GROUP_HOLDER.getItemGroupsManager();
@ -51,7 +53,7 @@ public class MaterialGroupApi {
* You may want to use {@link #addMaterialGroup(AbstractMaterialGroup)} instead as it is more performance in most case as this function will reload every conflict. * You may want to use {@link #addMaterialGroup(AbstractMaterialGroup)} instead as it is more performance in most case as this function will reload every conflict.
* *
* @param group the group to write * @param group the group to write
* @return true if successful * @return true if successful.
*/ */
public boolean writeMaterialGroup(@NotNull AbstractMaterialGroup group){ public boolean writeMaterialGroup(@NotNull AbstractMaterialGroup group){
return writeMaterialGroup(group, true); return writeMaterialGroup(group, true);
@ -64,7 +66,7 @@ public class MaterialGroupApi {
* *
* @param group the group to write * @param group the group to write
* @param updatePlanned if we should plan a global update for material groups * @param updatePlanned if we should plan a global update for material groups
* @return true if successful * @return true if successful.
*/ */
public boolean writeMaterialGroup(@NotNull AbstractMaterialGroup group, boolean updatePlanned){ public boolean writeMaterialGroup(@NotNull AbstractMaterialGroup group, boolean updatePlanned){
String name = group.getName(); String name = group.getName();
@ -147,12 +149,20 @@ public class MaterialGroupApi {
* Get by name a group. * Get by name a group.
* *
* @param groupName the group name used to fetch * @param groupName the group name used to fetch
* @return the abstract group of this name * @return the abstract group of this name. null if not found.
*/ */
@Nullable @Nullable
public static AbstractMaterialGroup getGroup(@NotNull String groupName){ public static AbstractMaterialGroup getGroup(@NotNull String groupName){
return ConfigHolder.ITEM_GROUP_HOLDER.getItemGroupsManager().get(groupName); return ConfigHolder.ITEM_GROUP_HOLDER.getItemGroupsManager().get(groupName);
} }
/**
* Get every registered material groups.
* @return An immutable map of group name as its key and group as mapped value.
*/
@NotNull
public Map<String, AbstractMaterialGroup> getRegisteredGroups(){
return Collections.unmodifiableMap(ConfigHolder.ITEM_GROUP_HOLDER.getItemGroupsManager().getGroupMap());
}
} }

View file

@ -18,7 +18,8 @@ import java.util.Map;
/** /**
* Represent an enchantment compatible with Custom Anvil. * Represent an enchantment compatible with Custom Anvil.
* One issue with custom anvil is: it does not handle well duplicate key name (ignoring namespace) as the plugin was coded with vanilla enchantment in head * One issue with custom anvil is: it does not handle well duplicate key name (ignoring namespace)
* as the plugin was initially coded with vanilla enchantment in head
*/ */
public interface CAEnchantment { public interface CAEnchantment {
@ -89,6 +90,7 @@ public interface CAEnchantment {
/** /**
* Get current level of the enchantment. * Get current level of the enchantment.
* @param item Item to search the level for. * @param item Item to search the level for.
* @return The enchantment level.
*/ */
int getLevel(@NotNull ItemStack item); int getLevel(@NotNull ItemStack item);
@ -223,6 +225,8 @@ public interface CAEnchantment {
/** /**
* Gets an array of all the registered enchantments. * Gets an array of all the registered enchantments.
*
* @param key The enchantment key
* @return Array of enchantment. * @return Array of enchantment.
*/ */
static @Nullable CAEnchantment getByKey(@NotNull NamespacedKey key){ static @Nullable CAEnchantment getByKey(@NotNull NamespacedKey key){
@ -231,6 +235,7 @@ public interface CAEnchantment {
/** /**
* Gets a list of all the unoptimised enchantments. * Gets a list of all the unoptimised enchantments.
* @param name The enchantment name
* @return List of enchantment. * @return List of enchantment.
*/ */
static @Nullable CAEnchantment getByName(@NotNull String name){ static @Nullable CAEnchantment getByName(@NotNull String name){

View file

@ -12,6 +12,11 @@ import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Objects; import java.util.Objects;
/**
* Default implementation of an enchantment compatible with Custom Anvil.
* One issue with custom anvil is: it does not handle well duplicate key name (ignoring namespace)
* as the plugin was initially coded with vanilla enchantment in head
*/
public abstract class CAEnchantmentBase implements CAEnchantment { public abstract class CAEnchantmentBase implements CAEnchantment {
@NotNull @NotNull

View file

@ -8,10 +8,7 @@ import org.jetbrains.annotations.Nullable;
import xyz.alexcrea.cuanvil.dependency.DependencyManager; import xyz.alexcrea.cuanvil.dependency.DependencyManager;
import xyz.alexcrea.cuanvil.enchant.wrapped.CAVanillaEnchantment; import xyz.alexcrea.cuanvil.enchant.wrapped.CAVanillaEnchantment;
import java.util.ArrayList; import java.util.*;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.logging.Level; import java.util.logging.Level;
public class CAEnchantmentRegistry { public class CAEnchantmentRegistry {
@ -121,20 +118,29 @@ public class CAEnchantmentRegistry {
/** /**
* Gets an array of all the registered enchantments. * Gets an array of all the registered enchantments.
* @return Array of enchantment. * @return Array of enchantments.
*/ */
@NotNull @NotNull
public Collection<CAEnchantment> values() { public Collection<CAEnchantment> values() {
return byKeyMap.values(); return byKeyMap.values();
} }
/**
* Gets a map of all the registered enchantments.
* @return Map of enchantments.
*/
public Map<NamespacedKey, CAEnchantment> registeredEnchantments() {
return byKeyMap;
}
/** /**
* Gets a list of all the unoptimised enchantments. * Gets a list of all the unoptimised enchantments.
* @return List of enchantment. * @return List of unoptimised enchantments.
*/ */
@NotNull @NotNull
public List<CAEnchantment> unoptimisedValues() { public List<CAEnchantment> unoptimisedValues() {
return unoptimisedValues; return unoptimisedValues;
} }
} }

View file

@ -33,8 +33,8 @@ public class CAEnchantSquaredEnchantment extends CAEnchantmentBase {
@Override @Override
public boolean isAllowed(@NotNull HumanEntity human) { public boolean isAllowed(@NotNull HumanEntity human) {
if(human instanceof Player){ if(human instanceof Player player){
return this.enchant.hasPermission((Player) human); return this.enchant.hasPermission(player);
} }
// Not really ideal for maintainability but will probably never be executed. (At least I hope) // Not really ideal for maintainability but will probably never be executed. (At least I hope)
boolean required = CustomEnchantManager.getInstance().isRequirePermissions(); boolean required = CustomEnchantManager.getInstance().isRequirePermissions();

View file

@ -13,6 +13,9 @@ import xyz.alexcrea.cuanvil.enchant.EnchantmentRarity;
import java.util.Locale; import java.util.Locale;
/**
* Custom Anvil enchantment implementation for vanilla registered enchantment.
*/
public class CAVanillaEnchantment extends CAEnchantmentBase { public class CAVanillaEnchantment extends CAEnchantmentBase {
private final @NotNull Enchantment enchantment; private final @NotNull Enchantment enchantment;