mirror of
https://github.com/alexcrea/CustomAnvil.git
synced 2026-06-23 16:16:17 +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)
|
* 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
|
* as the plugin was initially coded with vanilla enchantment in head
|
||||||
*/
|
*/
|
||||||
|
@SuppressWarnings("unused")
|
||||||
public interface CAEnchantment {
|
public interface CAEnchantment {
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -52,10 +53,16 @@ public interface CAEnchantment {
|
||||||
int defaultMaxLevel();
|
int defaultMaxLevel();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check if the enchantment have specialised group operation.
|
* Check if the enchantment have specialised get bulk operation.
|
||||||
* @return If the enchantment is optimised for group 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.
|
* Check if the player is allowed to use this enchantment.
|
||||||
|
|
@ -89,15 +96,20 @@ 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. Should not get changed.
|
||||||
* @return The enchantment level.
|
* @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.
|
* Get current level of the enchantment.
|
||||||
* @param item Item to search the level for.
|
* @param item Item to search the level for. Should not get changed.
|
||||||
* @param meta Meta of the provided item. It will not be changed and not be set on the item.
|
* @param meta Meta of the provided item. Should not get changed.
|
||||||
* @return Current leve of this enchantment on item. or 0 if absent.
|
* @return Current leve of this enchantment on item. or 0 if absent.
|
||||||
*/
|
*/
|
||||||
int getLevel(@NotNull ItemStack item, @NotNull ItemMeta meta);
|
int getLevel(@NotNull ItemStack item, @NotNull ItemMeta meta);
|
||||||
|
|
@ -158,7 +170,7 @@ public interface CAEnchantment {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Clean unoptimised enchants
|
// Clean unoptimised enchants
|
||||||
for (CAEnchantment enchant : CAEnchantmentRegistry.getInstance().unoptimisedValues()) {
|
for (CAEnchantment enchant : CAEnchantmentRegistry.getInstance().unoptimisedCleanValues()) {
|
||||||
if(enchant.isEnchantmentPresent(item)){
|
if(enchant.isEnchantmentPresent(item)){
|
||||||
enchant.removeFrom(item);
|
enchant.removeFrom(item);
|
||||||
}
|
}
|
||||||
|
|
@ -196,7 +208,7 @@ public interface CAEnchantment {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Unoptimised enchantment get
|
// Unoptimised enchantment get
|
||||||
findEnchantsFromSelectedList(item, meta, enchantments, registry.unoptimisedValues());
|
findEnchantsFromSelectedList(item, meta, enchantments, registry.unoptimisedGetValues());
|
||||||
|
|
||||||
return enchantments;
|
return enchantments;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -72,7 +72,12 @@ public abstract class CAEnchantmentBase implements CAEnchantment {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isOptimised(){
|
public boolean isGetOptimised(){
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isCleanOptimised(){
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -81,12 +86,6 @@ public abstract class CAEnchantmentBase implements CAEnchantment {
|
||||||
return true;
|
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){
|
public boolean isEnchantmentPresent(@NotNull ItemStack item){
|
||||||
ItemMeta meta = item.getItemMeta();
|
ItemMeta meta = item.getItemMeta();
|
||||||
if(meta == null) return false;
|
if(meta == null) return false;
|
||||||
|
|
|
||||||
|
|
@ -20,12 +20,14 @@ public class CAEnchantmentRegistry {
|
||||||
// Register enchantment functions
|
// Register enchantment functions
|
||||||
private final HashMap<NamespacedKey, CAEnchantment> byKeyMap;
|
private final HashMap<NamespacedKey, CAEnchantment> byKeyMap;
|
||||||
private final HashMap<String, CAEnchantment> byNameMap;
|
private final HashMap<String, CAEnchantment> byNameMap;
|
||||||
private final List<CAEnchantment> unoptimisedValues;
|
private final List<CAEnchantment> unoptimisedGetValues;
|
||||||
|
private final List<CAEnchantment> unoptimisedCleanValues;
|
||||||
|
|
||||||
private CAEnchantmentRegistry() {
|
private CAEnchantmentRegistry() {
|
||||||
byKeyMap = new HashMap<>();
|
byKeyMap = new HashMap<>();
|
||||||
byNameMap = 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);
|
byKeyMap.put(enchantment.getKey(), enchantment);
|
||||||
byNameMap.put(enchantment.getName(), enchantment);
|
byNameMap.put(enchantment.getName(), enchantment);
|
||||||
|
|
||||||
if(!enchantment.isOptimised()){
|
if(!enchantment.isGetOptimised()){
|
||||||
unoptimisedValues.add(enchantment);
|
unoptimisedGetValues.add(enchantment);
|
||||||
}
|
}
|
||||||
|
if(!enchantment.isCleanOptimised()){
|
||||||
|
unoptimisedCleanValues.add(enchantment);
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -86,7 +92,8 @@ public class CAEnchantmentRegistry {
|
||||||
byKeyMap.remove(enchantment.getKey());
|
byKeyMap.remove(enchantment.getKey());
|
||||||
byNameMap.remove(enchantment.getName());
|
byNameMap.remove(enchantment.getName());
|
||||||
|
|
||||||
unoptimisedValues.remove(enchantment);
|
unoptimisedGetValues.remove(enchantment);
|
||||||
|
unoptimisedCleanValues.remove(enchantment);
|
||||||
return true;
|
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.
|
* @return List of unoptimised enchantments.
|
||||||
*/
|
*/
|
||||||
@NotNull
|
@NotNull
|
||||||
public List<CAEnchantment> unoptimisedValues() {
|
public List<CAEnchantment> unoptimisedGetValues() {
|
||||||
return unoptimisedValues;
|
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
|
@Override
|
||||||
public boolean isOptimised() {
|
public boolean isGetOptimised() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isCleanOptimised() {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -32,7 +32,12 @@ public class CAVanillaEnchantment extends CAEnchantmentBase {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isOptimised() {
|
public boolean isGetOptimised() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isCleanOptimised() {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue