mirror of
https://github.com/alexcrea/CustomAnvil.git
synced 2026-06-23 08:14:00 +02:00
Update gui on enchantment registering.
This commit is contained in:
parent
0761c70286
commit
1bd3328281
2 changed files with 29 additions and 15 deletions
|
|
@ -8,6 +8,8 @@ import xyz.alexcrea.cuanvil.enchant.CAEnchantment;
|
|||
import xyz.alexcrea.cuanvil.enchant.CAEnchantmentRegistry;
|
||||
import xyz.alexcrea.cuanvil.enchant.EnchantmentRarity;
|
||||
import xyz.alexcrea.cuanvil.enchant.wrapped.CAVanillaEnchantment;
|
||||
import xyz.alexcrea.cuanvil.gui.config.global.EnchantCostConfigGui;
|
||||
import xyz.alexcrea.cuanvil.gui.config.global.EnchantLimitConfigGui;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.Map;
|
||||
|
|
@ -27,7 +29,13 @@ public class EnchantmentApi {
|
|||
* @return True if successful.
|
||||
*/
|
||||
public static boolean registerEnchantment(@NotNull CAEnchantment enchantment){
|
||||
return CAEnchantmentRegistry.getInstance().register(enchantment);
|
||||
if(!CAEnchantmentRegistry.getInstance().register(enchantment)) return false;
|
||||
|
||||
// Add enchantment to gui.
|
||||
EnchantCostConfigGui.INSTANCE.updateValueForGeneric(enchantment, true);
|
||||
EnchantLimitConfigGui.INSTANCE.updateValueForGeneric(enchantment, true);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -56,6 +64,20 @@ public class EnchantmentApi {
|
|||
return registerEnchantment(new CAVanillaEnchantment(enchantment));
|
||||
}
|
||||
|
||||
/**
|
||||
* Unregister an enchantment.
|
||||
*
|
||||
* @param enchantment The enchantment to unregister
|
||||
* @return True if successful.
|
||||
*/
|
||||
public static boolean unregisterEnchantment(@Nullable CAEnchantment enchantment){
|
||||
// Remove from gui
|
||||
EnchantCostConfigGui.INSTANCE.removeGeneric(enchantment);
|
||||
EnchantLimitConfigGui.INSTANCE.removeGeneric(enchantment);
|
||||
|
||||
return CAEnchantmentRegistry.getInstance().unregister(enchantment);
|
||||
}
|
||||
|
||||
/**
|
||||
* Unregister an enchantment by its key.
|
||||
*
|
||||
|
|
@ -64,17 +86,7 @@ public class EnchantmentApi {
|
|||
*/
|
||||
public static boolean unregisterEnchantment(@NotNull NamespacedKey key){
|
||||
CAEnchantment enchantment = CAEnchantmentRegistry.getInstance().getByKey(key);
|
||||
return CAEnchantmentRegistry.getInstance().unregister(enchantment);
|
||||
}
|
||||
|
||||
/**
|
||||
* Unregister an enchantment.
|
||||
*
|
||||
* @param enchantment The enchantment to unregister
|
||||
* @return True if successful.
|
||||
*/
|
||||
public static boolean unregisterEnchantment(@NotNull CAEnchantment enchantment){
|
||||
return CAEnchantmentRegistry.getInstance().unregister(enchantment);
|
||||
return unregisterEnchantment(enchantment);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -89,7 +89,7 @@ public class CAEnchantmentRegistry {
|
|||
* @return If the operation was successful.
|
||||
*/
|
||||
|
||||
public boolean unregister(CAEnchantment enchantment){
|
||||
public boolean unregister(@Nullable CAEnchantment enchantment){
|
||||
if(enchantment == null) return false;
|
||||
byKeyMap.remove(enchantment.getKey());
|
||||
byNameMap.remove(enchantment.getName());
|
||||
|
|
@ -103,7 +103,8 @@ public class CAEnchantmentRegistry {
|
|||
* @param key Key to fetch.
|
||||
* @return Registered enchantment. null if absent.
|
||||
*/
|
||||
public @Nullable CAEnchantment getByKey(@NotNull NamespacedKey key){
|
||||
@Nullable
|
||||
public CAEnchantment getByKey(@NotNull NamespacedKey key){
|
||||
return byKeyMap.get(key);
|
||||
}
|
||||
|
||||
|
|
@ -112,7 +113,8 @@ public class CAEnchantmentRegistry {
|
|||
* @param name Name to fetch.
|
||||
* @return Registered enchantment. null if absent.
|
||||
*/
|
||||
public @Nullable CAEnchantment getByName(@NotNull String name){
|
||||
@Nullable
|
||||
public CAEnchantment getByName(@NotNull String name){
|
||||
return byNameMap.get(name);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue