mirror of
https://github.com/alexcrea/CustomAnvil.git
synced 2026-06-23 08:14:00 +02:00
Splited optimised get and clean into 2 category.
Also changed getLevel(ItemStack) from CAEnchantmentBase to CAEnchantment
This commit is contained in:
parent
42a028f2fd
commit
0fd12b4185
5 changed files with 64 additions and 27 deletions
|
|
@ -21,6 +21,7 @@ import java.util.Map;
|
|||
* 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
|
||||
*/
|
||||
@SuppressWarnings("unused")
|
||||
public interface CAEnchantment {
|
||||
|
||||
|
||||
|
|
@ -52,10 +53,16 @@ public interface CAEnchantment {
|
|||
int defaultMaxLevel();
|
||||
|
||||
/**
|
||||
* Check if the enchantment have specialised group operation.
|
||||
* @return If the enchantment is optimised for group operation.
|
||||
* Check if the enchantment have specialised get bulk operation.
|
||||
* @return If the enchantment is optimised for get bulk operation.
|
||||
*/
|
||||
boolean isOptimised();
|
||||
boolean isGetOptimised();
|
||||
|
||||
/**
|
||||
* Check if the enchantment have specialised clean bulk operation.
|
||||
* @return If the enchantment is optimised for clean bulk operation.
|
||||
*/
|
||||
boolean isCleanOptimised();
|
||||
|
||||
/**
|
||||
* Check if the player is allowed to use this enchantment.
|
||||
|
|
@ -89,15 +96,20 @@ public interface CAEnchantment {
|
|||
|
||||
/**
|
||||
* Get current level of the enchantment.
|
||||
* @param item Item to search the level for.
|
||||
* @return The enchantment level.
|
||||
* @param item Item to search the level for. Should not get changed.
|
||||
* @return Current leve of this enchantment on item. or 0 if absent.
|
||||
*/
|
||||
int getLevel(@NotNull ItemStack item);
|
||||
default int getLevel(@NotNull ItemStack item){
|
||||
ItemMeta meta = item.getItemMeta();
|
||||
if(meta == null) return 0;
|
||||
|
||||
return getLevel(item, meta);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get current level of the enchantment.
|
||||
* @param item Item to search the level for.
|
||||
* @param meta Meta of the provided item. It will not be changed and not be set on the item.
|
||||
* @param item Item to search the level for. Should not get changed.
|
||||
* @param meta Meta of the provided item. Should not get changed.
|
||||
* @return Current leve of this enchantment on item. or 0 if absent.
|
||||
*/
|
||||
int getLevel(@NotNull ItemStack item, @NotNull ItemMeta meta);
|
||||
|
|
@ -158,7 +170,7 @@ public interface CAEnchantment {
|
|||
}
|
||||
|
||||
// Clean unoptimised enchants
|
||||
for (CAEnchantment enchant : CAEnchantmentRegistry.getInstance().unoptimisedValues()) {
|
||||
for (CAEnchantment enchant : CAEnchantmentRegistry.getInstance().unoptimisedCleanValues()) {
|
||||
if(enchant.isEnchantmentPresent(item)){
|
||||
enchant.removeFrom(item);
|
||||
}
|
||||
|
|
@ -196,7 +208,7 @@ public interface CAEnchantment {
|
|||
}
|
||||
|
||||
// Unoptimised enchantment get
|
||||
findEnchantsFromSelectedList(item, meta, enchantments, registry.unoptimisedValues());
|
||||
findEnchantsFromSelectedList(item, meta, enchantments, registry.unoptimisedGetValues());
|
||||
|
||||
return enchantments;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -72,7 +72,12 @@ public abstract class CAEnchantmentBase implements CAEnchantment {
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean isOptimised(){
|
||||
public boolean isGetOptimised(){
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCleanOptimised(){
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
@ -81,12 +86,6 @@ public abstract class CAEnchantmentBase implements CAEnchantment {
|
|||
return true;
|
||||
}
|
||||
|
||||
public int getLevel(@NotNull ItemStack item){
|
||||
ItemMeta meta = item.getItemMeta();
|
||||
if(meta == null) return 0;
|
||||
return getLevel(item, meta);
|
||||
}
|
||||
|
||||
public boolean isEnchantmentPresent(@NotNull ItemStack item){
|
||||
ItemMeta meta = item.getItemMeta();
|
||||
if(meta == null) return false;
|
||||
|
|
|
|||
|
|
@ -20,12 +20,14 @@ public class CAEnchantmentRegistry {
|
|||
// Register enchantment functions
|
||||
private final HashMap<NamespacedKey, CAEnchantment> byKeyMap;
|
||||
private final HashMap<String, CAEnchantment> byNameMap;
|
||||
private final List<CAEnchantment> unoptimisedValues;
|
||||
private final List<CAEnchantment> unoptimisedGetValues;
|
||||
private final List<CAEnchantment> unoptimisedCleanValues;
|
||||
|
||||
private CAEnchantmentRegistry() {
|
||||
byKeyMap = new HashMap<>();
|
||||
byNameMap = new HashMap<>();
|
||||
unoptimisedValues = new ArrayList<>();
|
||||
unoptimisedGetValues = new ArrayList<>();
|
||||
unoptimisedCleanValues = new ArrayList<>();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -64,9 +66,13 @@ public class CAEnchantmentRegistry {
|
|||
byKeyMap.put(enchantment.getKey(), enchantment);
|
||||
byNameMap.put(enchantment.getName(), enchantment);
|
||||
|
||||
if(!enchantment.isOptimised()){
|
||||
unoptimisedValues.add(enchantment);
|
||||
if(!enchantment.isGetOptimised()){
|
||||
unoptimisedGetValues.add(enchantment);
|
||||
}
|
||||
if(!enchantment.isCleanOptimised()){
|
||||
unoptimisedCleanValues.add(enchantment);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
@ -86,7 +92,8 @@ public class CAEnchantmentRegistry {
|
|||
byKeyMap.remove(enchantment.getKey());
|
||||
byNameMap.remove(enchantment.getName());
|
||||
|
||||
unoptimisedValues.remove(enchantment);
|
||||
unoptimisedGetValues.remove(enchantment);
|
||||
unoptimisedCleanValues.remove(enchantment);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
@ -128,12 +135,21 @@ public class CAEnchantmentRegistry {
|
|||
}
|
||||
|
||||
/**
|
||||
* Gets a list of all the unoptimised enchantments.
|
||||
* Gets a list of all the unoptimised get operation enchantments.
|
||||
* @return List of unoptimised enchantments.
|
||||
*/
|
||||
@NotNull
|
||||
public List<CAEnchantment> unoptimisedValues() {
|
||||
return unoptimisedValues;
|
||||
public List<CAEnchantment> unoptimisedGetValues() {
|
||||
return unoptimisedGetValues;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a list of all the unoptimised clean operation enchantments.
|
||||
* @return List of unoptimised enchantments.
|
||||
*/
|
||||
@NotNull
|
||||
public List<CAEnchantment> unoptimisedCleanValues() {
|
||||
return unoptimisedCleanValues;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -27,7 +27,12 @@ public class CAEnchantSquaredEnchantment extends CAEnchantmentBase {
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean isOptimised() {
|
||||
public boolean isGetOptimised() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCleanOptimised() {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -32,7 +32,12 @@ public class CAVanillaEnchantment extends CAEnchantmentBase {
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean isOptimised() {
|
||||
public boolean isGetOptimised() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCleanOptimised() {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue