Use namespace for enchantment of conflict

This commit is contained in:
alexcrea 2024-09-07 15:41:59 +02:00
parent 33605dbaf3
commit cc697f2d88
No known key found for this signature in database
GPG key ID: 43FD265DB0DBF91F
5 changed files with 117 additions and 106 deletions

View file

@ -104,7 +104,7 @@ public class EnchantmentApi {
* @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 = CAEnchantment.getByKey(key);
return unregisterEnchantment(enchantment); return unregisterEnchantment(enchantment);
} }
@ -126,7 +126,7 @@ public class EnchantmentApi {
*/ */
@Nullable @Nullable
public static CAEnchantment getByKey(@NotNull NamespacedKey key){ public static CAEnchantment getByKey(@NotNull NamespacedKey key){
return CAEnchantmentRegistry.getInstance().getByKey(key); return CAEnchantment.getByKey(key);
} }
/** /**
@ -137,7 +137,7 @@ public class EnchantmentApi {
*/ */
@Nullable @Nullable
public static CAEnchantment getByName(@NotNull String name){ public static CAEnchantment getByName(@NotNull String name){
return CAEnchantmentRegistry.getInstance().getByName(name); return CAEnchantment.getByName(name);
} }
/** /**

View file

@ -62,6 +62,8 @@ public class CAEnchantmentRegistry {
} }
private static boolean hasWarnedRegistering = false;
/** /**
* Can be used to register new enchantment. * Can be used to register new enchantment.
* <p> * <p>
@ -73,15 +75,18 @@ public class CAEnchantmentRegistry {
public boolean register(@NotNull CAEnchantment enchantment){ public boolean register(@NotNull CAEnchantment enchantment){
if(byKeyMap.containsKey(enchantment.getKey())){ if(byKeyMap.containsKey(enchantment.getKey())){
CustomAnvil.instance.getLogger().log(Level.WARNING, CustomAnvil.instance.getLogger().log(Level.WARNING,
"Duplicate registered enchantment. This should NOT happen.", "Duplicate registered enchantment. This should NOT happen any time.\n" +
"If you are a custom anvil developer. You maybe custom anvil detected your enchantment as a bukkit enchantment. " +
"maybe remove enchantment with the same key before registering yours",
new IllegalStateException(enchantment.getKey()+" enchantment was already registered")); new IllegalStateException(enchantment.getKey()+" enchantment was already registered"));
return false; return false;
} }
if(byNameMap.containsKey(enchantment.getName())){
if((!hasWarnedRegistering) && byNameMap.containsKey(enchantment.getName())){
hasWarnedRegistering = true;
CustomAnvil.instance.getLogger().log(Level.WARNING, CustomAnvil.instance.getLogger().log(Level.WARNING,
"Duplicate registered enchantment name. There will have issue. " + "Duplicate registered enchantment name. Please check that configuration is using namespace.");
"\nI hope this do not happen to you on a production server. If it do, there is probably a plugin trying to register an enchantment with the same name than another one",
new IllegalStateException(enchantment.getKey()+" enchantment name was already registered"));
} }
byKeyMap.put(enchantment.getKey(), enchantment); byKeyMap.put(enchantment.getKey(), enchantment);

View file

@ -258,7 +258,7 @@ public class EnchantConflictSubSettingGui extends MappedToListSubSettingGui impl
String[] enchantKeys = new String[enchantments.size()]; String[] enchantKeys = new String[enchantments.size()];
int index = 0; int index = 0;
for (CAEnchantment enchantment : enchantments) { for (CAEnchantment enchantment : enchantments) {
enchantKeys[index++] = enchantment.getKey().getKey(); enchantKeys[index++] = enchantment.getKey().toString();
} }
ConfigHolder.CONFLICT_HOLDER.getConfig().set(enchantConflict + ".enchantments", enchantKeys); ConfigHolder.CONFLICT_HOLDER.getConfig().set(enchantConflict + ".enchantments", enchantKeys);

View file

@ -94,7 +94,7 @@ class EnchantConflictManager {
// Read and add enchantment to conflict // Read and add enchantment to conflict
val enchantList = section.getStringList(ENCH_LIST_PATH) val enchantList = section.getStringList(ENCH_LIST_PATH)
for (enchantName in enchantList) { for (enchantName in enchantList) {
val enchant = getEnchantByName(enchantName) val enchant = getEnchantByIdentifier(enchantName)
if (enchant == null) { if (enchant == null) {
if (!futureUse) { //TODO future use will be deprecated once the new update system is finished if (!futureUse) { //TODO future use will be deprecated once the new update system is finished
CustomAnvil.instance.logger.warning("Enchantment $enchantName do not exist but was asked for conflict $conflictName") CustomAnvil.instance.logger.warning("Enchantment $enchantName do not exist but was asked for conflict $conflictName")
@ -112,7 +112,13 @@ class EnchantConflictManager {
return conflict return conflict
} }
private fun getEnchantByName(enchantName: String): CAEnchantment? { private fun getEnchantByIdentifier(enchantName: String): CAEnchantment? {
val key = NamespacedKey.fromString(enchantName)
if(key != null){
val enchantment = CAEnchantment.getByKey(key)
if(enchantment != null) return enchantment
}
// Temporary solution for 1.20.5 // Temporary solution for 1.20.5
when(enchantName){ when(enchantName){

View file

@ -16,159 +16,159 @@
# on illegal items # on illegal items
# ---------------------------------------------------- # ----------------------------------------------------
restriction_aqua_affinity: restriction_minecraft_aqua_affinity:
enchantments: [ aqua_affinity ] enchantments: [ minecraft:aqua_affinity ]
notAffectedGroups: [ enchanted_book, helmets ] notAffectedGroups: [ enchanted_book, helmets ]
restriction_bane_of_arthropods: restriction_minecraft_bane_of_arthropods:
enchantments: [ bane_of_arthropods ] enchantments: [ minecraft:bane_of_arthropods ]
notAffectedGroups: [ enchanted_book, melee_weapons ] notAffectedGroups: [ enchanted_book, melee_weapons ]
restriction_blast_protection: restriction_minecraft_blast_protection:
enchantments: [ blast_protection ] enchantments: [ minecraft:blast_protection ]
notAffectedGroups: [ enchanted_book, armors ] notAffectedGroups: [ enchanted_book, armors ]
restriction_channeling: restriction_minecraft_channeling:
enchantments: [ channeling ] enchantments: [ minecraft:channeling ]
notAffectedGroups: [ enchanted_book, trident ] notAffectedGroups: [ enchanted_book, trident ]
restriction_binding_curse: restriction_minecraft_binding_curse:
enchantments: [ binding_curse ] enchantments: [ minecraft:binding_curse ]
notAffectedGroups: [ enchanted_book, wearable ] notAffectedGroups: [ enchanted_book, wearable ]
restriction_vanishing_curse: restriction_minecraft_vanishing_curse:
enchantments: [ vanishing_curse ] enchantments: [ minecraft:vanishing_curse ]
notAffectedGroups: [ enchanted_book, can_vanish ] notAffectedGroups: [ enchanted_book, can_vanish ]
restriction_depth_strider: restriction_minecraft_depth_strider:
enchantments: [ depth_strider ] enchantments: [ minecraft:depth_strider ]
notAffectedGroups: [ enchanted_book, boots ] notAffectedGroups: [ enchanted_book, boots ]
restriction_efficiency: restriction_minecraft_efficiency:
enchantments: [ efficiency ] enchantments: [ minecraft:efficiency ]
notAffectedGroups: [ enchanted_book, tools, shears ] notAffectedGroups: [ enchanted_book, tools, shears ]
restriction_feather_falling: restriction_minecraft_feather_falling:
enchantments: [ feather_falling ] enchantments: [ minecraft:feather_falling ]
notAffectedGroups: [ enchanted_book, boots ] notAffectedGroups: [ enchanted_book, boots ]
restriction_fire_aspect: restriction_minecraft_fire_aspect:
enchantments: [ fire_aspect ] enchantments: [ minecraft:fire_aspect ]
notAffectedGroups: [ enchanted_book, swords ] notAffectedGroups: [ enchanted_book, swords ]
restriction_fire_protection: restriction_minecraft_fire_protection:
enchantments: [ fire_protection ] enchantments: [ minecraft:fire_protection ]
notAffectedGroups: [ enchanted_book, armors ] notAffectedGroups: [ enchanted_book, armors ]
restriction_flame: restriction_minecraft_flame:
enchantments: [ flame ] enchantments: [ minecraft:flame ]
notAffectedGroups: [ enchanted_book, bow ] notAffectedGroups: [ enchanted_book, bow ]
restriction_fortune: restriction_minecraft_fortune:
enchantments: [ fortune ] enchantments: [ minecraft:fortune ]
notAffectedGroups: [ enchanted_book, tools ] notAffectedGroups: [ enchanted_book, tools ]
restriction_frost_walker: restriction_minecraft_frost_walker:
enchantments: [ frost_walker ] enchantments: [ minecraft:frost_walker ]
notAffectedGroups: [ enchanted_book, boots ] notAffectedGroups: [ enchanted_book, boots ]
restriction_impaling: restriction_minecraft_impaling:
enchantments: [ impaling ] enchantments: [ minecraft:impaling ]
notAffectedGroups: [ enchanted_book, trident ] notAffectedGroups: [ enchanted_book, trident ]
restriction_infinity: restriction_minecraft_infinity:
enchantments: [ infinity ] enchantments: [ minecraft:infinity ]
notAffectedGroups: [ enchanted_book, bow ] notAffectedGroups: [ enchanted_book, bow ]
restriction_knockback: restriction_minecraft_knockback:
enchantments: [ knockback ] enchantments: [ minecraft:knockback ]
notAffectedGroups: [ enchanted_book, swords ] notAffectedGroups: [ enchanted_book, swords ]
restriction_looting: restriction_minecraft_looting:
enchantments: [ looting ] enchantments: [ minecraft:looting ]
notAffectedGroups: [ enchanted_book, swords ] notAffectedGroups: [ enchanted_book, swords ]
restriction_loyalty: restriction_minecraft_loyalty:
enchantments: [ loyalty ] enchantments: [ minecraft:loyalty ]
notAffectedGroups: [ enchanted_book, trident ] notAffectedGroups: [ enchanted_book, trident ]
restriction_lure: restriction_minecraft_lure:
enchantments: [ lure ] enchantments: [ minecraft:lure ]
notAffectedGroups: [ enchanted_book, fishing_rod ] notAffectedGroups: [ enchanted_book, fishing_rod ]
restriction_mending: restriction_minecraft_mending:
enchantments: [ mending ] enchantments: [ minecraft:mending ]
notAffectedGroups: [ enchanted_book, can_unbreak ] notAffectedGroups: [ enchanted_book, can_unbreak ]
restriction_multishot: restriction_minecraft_multishot:
enchantments: [ multishot ] enchantments: [ minecraft:multishot ]
notAffectedGroups: [ enchanted_book, crossbow ] notAffectedGroups: [ enchanted_book, crossbow ]
restriction_piercing: restriction_minecraft_piercing:
enchantments: [ piercing ] enchantments: [ minecraft:piercing ]
notAffectedGroups: [ enchanted_book, crossbow ] notAffectedGroups: [ enchanted_book, crossbow ]
restriction_power: restriction_minecraft_power:
enchantments: [ power ] enchantments: [ minecraft:power ]
notAffectedGroups: [ enchanted_book, bow ] notAffectedGroups: [ enchanted_book, bow ]
restriction_projectile_protection: restriction_minecraft_projectile_protection:
enchantments: [ projectile_protection ] enchantments: [ minecraft:projectile_protection ]
notAffectedGroups: [ enchanted_book, armors ] notAffectedGroups: [ enchanted_book, armors ]
restriction_protection: restriction_minecraft_protection:
enchantments: [ protection ] enchantments: [ minecraft:protection ]
notAffectedGroups: [ enchanted_book, armors ] notAffectedGroups: [ enchanted_book, armors ]
restriction_punch: restriction_minecraft_punch:
enchantments: [ punch ] enchantments: [ minecraft:punch ]
notAffectedGroups: [ enchanted_book, bow ] notAffectedGroups: [ enchanted_book, bow ]
restriction_quick_charge: restriction_minecraft_quick_charge:
enchantments: [ quick_charge ] enchantments: [ minecraft:quick_charge ]
notAffectedGroups: [ enchanted_book, crossbow ] notAffectedGroups: [ enchanted_book, crossbow ]
restriction_respiration: restriction_minecraft_respiration:
enchantments: [ respiration ] enchantments: [ minecraft:respiration ]
notAffectedGroups: [ enchanted_book, helmets ] notAffectedGroups: [ enchanted_book, helmets ]
restriction_riptide: restriction_minecraft_riptide:
enchantments: [ riptide ] enchantments: [ minecraft:riptide ]
notAffectedGroups: [ enchanted_book, trident ] notAffectedGroups: [ enchanted_book, trident ]
restriction_sharpness: restriction_minecraft_sharpness:
enchantments: [ sharpness ] enchantments: [ minecraft:sharpness ]
notAffectedGroups: [ enchanted_book, melee_weapons ] notAffectedGroups: [ enchanted_book, melee_weapons ]
restriction_silk_touch: restriction_minecraft_silk_touch:
enchantments: [ silk_touch ] enchantments: [ minecraft:silk_touch ]
notAffectedGroups: [ enchanted_book, tools ] notAffectedGroups: [ enchanted_book, tools ]
restriction_smite: restriction_minecraft_smite:
enchantments: [ smite ] enchantments: [ minecraft:smite ]
notAffectedGroups: [ enchanted_book, melee_weapons ] notAffectedGroups: [ enchanted_book, melee_weapons ]
restriction_soul_speed: restriction_minecraft_soul_speed:
enchantments: [ soul_speed ] enchantments: [ minecraft:soul_speed ]
notAffectedGroups: [ enchanted_book, boots ] notAffectedGroups: [ enchanted_book, boots ]
restriction_sweeping_edge: restriction_minecraft_sweeping_edge:
enchantments: [ sweeping, sweeping_edge ] enchantments: [ minecraft:sweeping, minecraft:sweeping_edge ]
notAffectedGroups: [ enchanted_book, swords ] notAffectedGroups: [ enchanted_book, swords ]
# Do not exist in 1.18, that mean useInFuture will be set to true # Do not exist in 1.18, that mean useInFuture will be set to true
# useInFuture set to true also mean it will not warn if there is an issue # useInFuture set to true also mean it will not warn if there is an issue
restriction_swift_sneak: restriction_minecraft_swift_sneak:
useInFuture: true useInFuture: true
enchantments: [ swift_sneak ] enchantments: [ minecraft:swift_sneak ]
notAffectedGroups: [ enchanted_book, leggings ] notAffectedGroups: [ enchanted_book, leggings ]
restriction_thorns: restriction_minecraft_thorns:
enchantments: [ thorns ] enchantments: [ minecraft:thorns ]
notAffectedGroups: [ enchanted_book, armors ] notAffectedGroups: [ enchanted_book, armors ]
restriction_unbreaking: restriction_minecraft_unbreaking:
enchantments: [ unbreaking ] enchantments: [ minecraft:unbreaking ]
notAffectedGroups: [ enchanted_book, can_unbreak ] notAffectedGroups: [ enchanted_book, can_unbreak ]
# ---------------------------------------------------- # ----------------------------------------------------
@ -180,60 +180,60 @@ restriction_unbreaking:
sword_enchant_conflict: sword_enchant_conflict:
enchantments: enchantments:
- bane_of_arthropods - minecraft:bane_of_arthropods
- smite - minecraft:smite
- sharpness - minecraft:sharpness
notAffectedGroups: [ ] notAffectedGroups: [ ]
maxEnchantmentBeforeConflict: 1 maxEnchantmentBeforeConflict: 1
protection_enchant_conflict: protection_enchant_conflict:
enchantments: enchantments:
- blast_protection - minecraft:blast_protection
- fire_protection - minecraft:fire_protection
- projectile_protection - minecraft:projectile_protection
- protection - minecraft:protection
notAffectedGroups: [ ] notAffectedGroups: [ ]
maxEnchantmentBeforeConflict: 1 maxEnchantmentBeforeConflict: 1
trident_conflict1: trident_conflict1:
enchantments: enchantments:
- channeling - minecraft:channeling
- riptide - minecraft:riptide
notAffectedGroups: [ ] notAffectedGroups: [ ]
maxEnchantmentBeforeConflict: 1 maxEnchantmentBeforeConflict: 1
trident_conflict2: trident_conflict2:
enchantments: enchantments:
- loyalty - minecraft:loyalty
- riptide - minecraft:riptide
notAffectedGroups: [ ] notAffectedGroups: [ ]
maxEnchantmentBeforeConflict: 1 maxEnchantmentBeforeConflict: 1
boot_conflict: boot_conflict:
enchantments: enchantments:
- depth_strider - minecraft:depth_strider
- frost_walker - minecraft:frost_walker
notAffectedGroups: [ ] notAffectedGroups: [ ]
maxEnchantmentBeforeConflict: 1 maxEnchantmentBeforeConflict: 1
tool_conflict: tool_conflict:
enchantments: enchantments:
- fortune - minecraft:fortune
- silk_touch - minecraft:silk_touch
notAffectedGroups: [ ] notAffectedGroups: [ ]
maxEnchantmentBeforeConflict: 1 maxEnchantmentBeforeConflict: 1
bow_conflict: bow_conflict:
enchantments: enchantments:
- mending - minecraft:mending
- infinity - minecraft:infinity
notAffectedGroups: [ ] notAffectedGroups: [ ]
maxEnchantmentBeforeConflict: 1 maxEnchantmentBeforeConflict: 1
crossbow_conflict: crossbow_conflict:
enchantments: enchantments:
- multishot - minecraft:multishot
- piercing - minecraft:piercing
notAffectedGroups: [ ] notAffectedGroups: [ ]
maxEnchantmentBeforeConflict: 1 maxEnchantmentBeforeConflict: 1