mirror of
https://github.com/alexcrea/CustomAnvil.git
synced 2026-06-24 00:26:16 +02:00
Add get every registered for Enchantment, Conflict and Material group.
Also updated some javadoc.
This commit is contained in:
parent
fca7bbb416
commit
091fb23aac
9 changed files with 155 additions and 87 deletions
|
|
@ -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 {
|
|||
* <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.
|
||||
*
|
||||
* @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 {
|
|||
* <p>
|
||||
* 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<String> extractEnchantments(@NotNull ConflictBuilder builder){
|
||||
|
|
@ -196,4 +198,15 @@ public class ConflictAPI {
|
|||
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);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -29,10 +29,11 @@ public class ConflictBuilder {
|
|||
/**
|
||||
* Instantiates a new Conflict builder.
|
||||
*
|
||||
* @param source the source
|
||||
* @param name the name
|
||||
* @param name The conflict 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.name = name;
|
||||
|
||||
|
|
@ -41,12 +42,23 @@ public class ConflictBuilder {
|
|||
|
||||
this.excludedGroupNames = new HashSet<>();
|
||||
|
||||
this.maxBeforeConflict = 0;
|
||||
this.maxBeforeConflict = maxBeforeConflict;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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){
|
||||
this(name, null);
|
||||
|
|
@ -55,7 +67,7 @@ public class ConflictBuilder {
|
|||
/**
|
||||
* Gets conflict source.
|
||||
*
|
||||
* @return the conflict source
|
||||
* @return The conflict source.
|
||||
*/
|
||||
@Nullable
|
||||
public Plugin getSource() {
|
||||
|
|
@ -65,7 +77,7 @@ public class ConflictBuilder {
|
|||
/**
|
||||
* Gets conflict source name.
|
||||
*
|
||||
* @return the conflict source
|
||||
* @return The conflict source name.
|
||||
*/
|
||||
@NotNull
|
||||
public String getSourceName() {
|
||||
|
|
@ -77,7 +89,7 @@ public class ConflictBuilder {
|
|||
/**
|
||||
* Gets conflict name.
|
||||
*
|
||||
* @return the name
|
||||
* @return The conflict name.
|
||||
*/
|
||||
@NotNull
|
||||
public String getName() {
|
||||
|
|
@ -87,7 +99,7 @@ public class ConflictBuilder {
|
|||
/**
|
||||
* Gets stored conflicting enchantment names.
|
||||
*
|
||||
* @return the enchantment names
|
||||
* @return The stored enchantment names.
|
||||
*/
|
||||
@NotNull
|
||||
public Set<String> getEnchantmentNames() {
|
||||
|
|
@ -97,7 +109,7 @@ public class ConflictBuilder {
|
|||
/**
|
||||
* Gets stored conflicting enchantment keys.
|
||||
*
|
||||
* @return the enchantment keys
|
||||
* @return The stored enchantment keys.
|
||||
*/
|
||||
@NotNull
|
||||
public Set<NamespacedKey> getEnchantmentKeys() {
|
||||
|
|
@ -107,7 +119,7 @@ public class ConflictBuilder {
|
|||
/**
|
||||
* Gets stored excluded group names.
|
||||
*
|
||||
* @return the group names
|
||||
* @return The stored group names.
|
||||
*/
|
||||
@NotNull
|
||||
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>
|
||||
* 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.
|
||||
* <p>
|
||||
* 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.
|
||||
* <p>
|
||||
* 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() {
|
||||
|
|
|
|||
|
|
@ -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.
|
||||
* <p>
|
||||
* 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<NamespacedKey, CAEnchantment> getRegisteredEnchantments(){
|
||||
return Collections.unmodifiableMap(CAEnchantmentRegistry.getInstance().registeredEnchantments());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -13,11 +13,13 @@ import xyz.alexcrea.cuanvil.group.IncludeGroup;
|
|||
import xyz.alexcrea.cuanvil.group.ItemGroupManager;
|
||||
import xyz.alexcrea.cuanvil.gui.config.global.GroupConfigGui;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.EnumSet;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* The type Material group api.
|
||||
* Custom Anvil api for material group registry.
|
||||
*/
|
||||
@SuppressWarnings("unused")
|
||||
public class MaterialGroupApi {
|
||||
|
|
@ -30,7 +32,7 @@ public class MaterialGroupApi {
|
|||
* Will not write the group if it already exists.
|
||||
*
|
||||
* @param group the group to add
|
||||
* @return true if successful
|
||||
* @return true if successful.
|
||||
*/
|
||||
public boolean addMaterialGroup(@NotNull AbstractMaterialGroup group){
|
||||
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.
|
||||
*
|
||||
* @param group the group to write
|
||||
* @return true if successful
|
||||
* @return true if successful.
|
||||
*/
|
||||
public boolean writeMaterialGroup(@NotNull AbstractMaterialGroup group){
|
||||
return writeMaterialGroup(group, true);
|
||||
|
|
@ -64,7 +66,7 @@ public class MaterialGroupApi {
|
|||
*
|
||||
* @param group the group to write
|
||||
* @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){
|
||||
String name = group.getName();
|
||||
|
|
@ -147,12 +149,20 @@ public class MaterialGroupApi {
|
|||
* Get by name a group.
|
||||
*
|
||||
* @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
|
||||
public static AbstractMaterialGroup getGroup(@NotNull String 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());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,7 +18,8 @@ import java.util.Map;
|
|||
|
||||
/**
|
||||
* 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 {
|
||||
|
||||
|
|
@ -89,6 +90,7 @@ public interface CAEnchantment {
|
|||
/**
|
||||
* Get current level of the enchantment.
|
||||
* @param item Item to search the level for.
|
||||
* @return The enchantment level.
|
||||
*/
|
||||
int getLevel(@NotNull ItemStack item);
|
||||
|
||||
|
|
@ -223,6 +225,8 @@ public interface CAEnchantment {
|
|||
|
||||
/**
|
||||
* Gets an array of all the registered enchantments.
|
||||
*
|
||||
* @param key The enchantment key
|
||||
* @return Array of enchantment.
|
||||
*/
|
||||
static @Nullable CAEnchantment getByKey(@NotNull NamespacedKey key){
|
||||
|
|
@ -231,6 +235,7 @@ public interface CAEnchantment {
|
|||
|
||||
/**
|
||||
* Gets a list of all the unoptimised enchantments.
|
||||
* @param name The enchantment name
|
||||
* @return List of enchantment.
|
||||
*/
|
||||
static @Nullable CAEnchantment getByName(@NotNull String name){
|
||||
|
|
|
|||
|
|
@ -12,6 +12,11 @@ import java.util.ArrayList;
|
|||
import java.util.List;
|
||||
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 {
|
||||
|
||||
@NotNull
|
||||
|
|
|
|||
|
|
@ -8,10 +8,7 @@ import org.jetbrains.annotations.Nullable;
|
|||
import xyz.alexcrea.cuanvil.dependency.DependencyManager;
|
||||
import xyz.alexcrea.cuanvil.enchant.wrapped.CAVanillaEnchantment;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.*;
|
||||
import java.util.logging.Level;
|
||||
|
||||
public class CAEnchantmentRegistry {
|
||||
|
|
@ -121,20 +118,29 @@ public class CAEnchantmentRegistry {
|
|||
|
||||
/**
|
||||
* Gets an array of all the registered enchantments.
|
||||
* @return Array of enchantment.
|
||||
* @return Array of enchantments.
|
||||
*/
|
||||
@NotNull
|
||||
public Collection<CAEnchantment> 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.
|
||||
* @return List of enchantment.
|
||||
* @return List of unoptimised enchantments.
|
||||
*/
|
||||
@NotNull
|
||||
public List<CAEnchantment> unoptimisedValues() {
|
||||
return unoptimisedValues;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -33,8 +33,8 @@ public class CAEnchantSquaredEnchantment extends CAEnchantmentBase {
|
|||
|
||||
@Override
|
||||
public boolean isAllowed(@NotNull HumanEntity human) {
|
||||
if(human instanceof Player){
|
||||
return this.enchant.hasPermission((Player) human);
|
||||
if(human instanceof Player player){
|
||||
return this.enchant.hasPermission(player);
|
||||
}
|
||||
// Not really ideal for maintainability but will probably never be executed. (At least I hope)
|
||||
boolean required = CustomEnchantManager.getInstance().isRequirePermissions();
|
||||
|
|
|
|||
|
|
@ -13,6 +13,9 @@ import xyz.alexcrea.cuanvil.enchant.EnchantmentRarity;
|
|||
|
||||
import java.util.Locale;
|
||||
|
||||
/**
|
||||
* Custom Anvil enchantment implementation for vanilla registered enchantment.
|
||||
*/
|
||||
public class CAVanillaEnchantment extends CAEnchantmentBase {
|
||||
|
||||
private final @NotNull Enchantment enchantment;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue