mirror of
https://github.com/alexcrea/CustomAnvil.git
synced 2026-06-23 16:16:17 +02:00
Fix api initial issue. (#15)
- Deleted object will now not be re added by default. - Config Event is now also triggered on reload cmd. (reload cmd now also apply update/compatibility fix)
This commit is contained in:
commit
dd831425bd
16 changed files with 307 additions and 52 deletions
|
|
@ -1,12 +1,11 @@
|
|||
import cn.lalaki.pub.BaseCentralPortalPlusExtension
|
||||
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
|
||||
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
|
||||
|
||||
plugins {
|
||||
kotlin("jvm") version "2.0.0"
|
||||
java
|
||||
id("org.jetbrains.dokka").version("1.9.20")
|
||||
id("io.github.goooler.shadow").version("8.1.8") // using fork of com.github.johnrengelman.shadow to support java 1.21
|
||||
id("io.github.goooler.shadow").version("8.1.8") // using fork of com.github.johnrengelman.shadow to support java 1.21. edit I do not need java 1.21 now so should be replaced ?
|
||||
// Maven publish
|
||||
`maven-publish`
|
||||
signing
|
||||
|
|
|
|||
|
|
@ -9,7 +9,9 @@ import xyz.alexcrea.cuanvil.config.ConfigHolder;
|
|||
import xyz.alexcrea.cuanvil.group.EnchantConflictGroup;
|
||||
import xyz.alexcrea.cuanvil.gui.config.global.EnchantConflictGui;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Custom Anvil api for conflict registry.
|
||||
|
|
@ -30,18 +32,34 @@ public class ConflictAPI {
|
|||
* @return True if successful.
|
||||
*/
|
||||
public static boolean addConflict(@NotNull ConflictBuilder builder){
|
||||
return addConflict(builder, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Write and add a conflict.
|
||||
* Will not write the conflict if it already exists.
|
||||
*
|
||||
* @param builder The conflict builder to be based on
|
||||
* @param overrideDeleted If we should write even if the conflict was previously deleted.
|
||||
* @return True if successful.
|
||||
*/
|
||||
public static boolean addConflict(@NotNull ConflictBuilder builder, boolean overrideDeleted){
|
||||
FileConfiguration config = ConfigHolder.CONFLICT_HOLDER.getConfig();
|
||||
|
||||
// Test if conflict can be added
|
||||
if(!overrideDeleted && ConfigHolder.CONFLICT_HOLDER.isDeleted(builder.getName())) return false;
|
||||
if(config.contains(builder.getName())) return false;
|
||||
|
||||
if(!writeConflict(builder, false)) return false;
|
||||
|
||||
EnchantConflictGroup conflict = builder.build();
|
||||
|
||||
EnchantConflictGroup conflict = builder.build();
|
||||
// Register conflict
|
||||
ConfigHolder.CONFLICT_HOLDER.getConflictManager().addConflict(conflict);
|
||||
|
||||
// Add conflict to gui
|
||||
EnchantConflictGui.INSTANCE.updateValueForGeneric(conflict, true);
|
||||
EnchantConflictGui conflictGui = EnchantConflictGui.getCurrentInstance();
|
||||
if(conflictGui != null) conflictGui.updateValueForGeneric(conflict, true);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
@ -118,11 +136,13 @@ public class ConflictAPI {
|
|||
ConfigHolder.CONFLICT_HOLDER.getConflictManager().removeConflict(conflict);
|
||||
|
||||
// Write as null and save to file
|
||||
ConfigHolder.CONFLICT_HOLDER.getConfig().set(conflict.getName(), null);
|
||||
ConfigHolder.CONFLICT_HOLDER.delete(conflict.getName());
|
||||
prepareSaveTask();
|
||||
|
||||
// Remove from gui
|
||||
EnchantConflictGui.INSTANCE.removeGeneric(conflict);
|
||||
EnchantConflictGui conflictGui = EnchantConflictGui.getCurrentInstance();
|
||||
if(conflictGui != null) conflictGui.removeGeneric(conflict);
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
@ -147,14 +167,16 @@ public class ConflictAPI {
|
|||
|
||||
reloadChangeTask = Bukkit.getScheduler().scheduleSyncDelayedTask(CustomAnvil.instance, ()->{
|
||||
ConfigHolder.CONFLICT_HOLDER.reload();
|
||||
EnchantConflictGui.INSTANCE.reloadValues();
|
||||
EnchantConflictGui conflictGui = EnchantConflictGui.getCurrentInstance();
|
||||
if(conflictGui != null) conflictGui.reloadValues();
|
||||
|
||||
reloadChangeTask = -1;
|
||||
}, 0L);
|
||||
|
||||
}
|
||||
|
||||
static void logConflictOrigin(@NotNull ConflictBuilder builder){
|
||||
CustomAnvil.instance.getLogger().warning("Conflict " + builder.getName() +" came from " + builder.getSourceName() + ".");
|
||||
CustomAnvil.instance.getLogger().warning("Conflict " + builder.getName() + " came from " + builder.getSourceName() + ".");
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -29,10 +29,24 @@ public class CustomAnvilRecipeApi {
|
|||
* @return True if successful.
|
||||
*/
|
||||
public static boolean addRecipe(@NotNull AnvilRecipeBuilder builder){
|
||||
return addRecipe(builder, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Write and add a custom anvil recipe.
|
||||
* Will not write the recipe if it already exists.
|
||||
*
|
||||
* @param builder The recipe builder to be based on
|
||||
* @param overrideDeleted If we should write even if the recipe was previously deleted.
|
||||
* @return True if successful.
|
||||
*/
|
||||
public static boolean addRecipe(@NotNull AnvilRecipeBuilder builder, boolean overrideDeleted){
|
||||
FileConfiguration config = ConfigHolder.CUSTOM_RECIPE_HOLDER.getConfig();
|
||||
String name = builder.getName();
|
||||
|
||||
if(!overrideDeleted && ConfigHolder.CUSTOM_RECIPE_HOLDER.isDeleted(builder.getName())) return false;
|
||||
if(config.contains(builder.getName())) return false;
|
||||
|
||||
if(builder.getName().contains(".")) {
|
||||
CustomAnvil.instance.getLogger().warning("Custom anvil recipe " + name + " contain \".\" in its name but should not. this recipe is ignored.");
|
||||
return false;
|
||||
|
|
@ -58,7 +72,8 @@ public class CustomAnvilRecipeApi {
|
|||
prepareSaveTask();
|
||||
|
||||
// Add from gui
|
||||
CustomRecipeConfigGui.INSTANCE.updateValueForGeneric(recipe, true);
|
||||
CustomRecipeConfigGui recipeConfigGui = CustomRecipeConfigGui.getCurrentInstance();
|
||||
if(recipeConfigGui != null) recipeConfigGui.updateValueForGeneric(recipe, true);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
@ -74,11 +89,12 @@ public class CustomAnvilRecipeApi {
|
|||
ConfigHolder.CUSTOM_RECIPE_HOLDER.getRecipeManager().cleanRemove(recipe);
|
||||
|
||||
// Write as null and save to file
|
||||
ConfigHolder.CUSTOM_RECIPE_HOLDER.getConfig().set(recipe.getName(), null);
|
||||
ConfigHolder.CUSTOM_RECIPE_HOLDER.delete(recipe.getName());
|
||||
prepareSaveTask();
|
||||
|
||||
// Remove from gui
|
||||
CustomRecipeConfigGui.INSTANCE.removeGeneric(recipe);
|
||||
CustomRecipeConfigGui recipeConfigGui = CustomRecipeConfigGui.getCurrentInstance();
|
||||
if(recipeConfigGui != null) recipeConfigGui.removeGeneric(recipe);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -27,22 +27,41 @@ public class MaterialGroupApi {
|
|||
private static int saveChangeTask = -1;
|
||||
private static int reloadChangeTask = -1;
|
||||
|
||||
|
||||
/**
|
||||
* Write and add a group.
|
||||
* Will not write the group if it already exists.
|
||||
*
|
||||
* @param group the group to add
|
||||
* @param group The group to add
|
||||
* @return true if successful.
|
||||
*/
|
||||
public static boolean addMaterialGroup(@NotNull AbstractMaterialGroup group){
|
||||
return addMaterialGroup(group, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Write and add a group.
|
||||
* Will not write the group if it already exists.
|
||||
*
|
||||
* @param group The group to add
|
||||
* @param overrideDeleted If we should write even if the group was previously deleted.
|
||||
* @return true if successful.
|
||||
*/
|
||||
public static boolean addMaterialGroup(@NotNull AbstractMaterialGroup group, boolean overrideDeleted){
|
||||
ItemGroupManager itemGroupManager = ConfigHolder.ITEM_GROUP_HOLDER.getItemGroupsManager();
|
||||
|
||||
// Test if it exists/existed
|
||||
if(!overrideDeleted && ConfigHolder.ITEM_GROUP_HOLDER.isDeleted(group.getName())) return false;
|
||||
if(itemGroupManager.get(group.getName()) != null) return false;
|
||||
|
||||
// Add group
|
||||
itemGroupManager.getGroupMap().put(group.getName(), group);
|
||||
|
||||
if(!writeMaterialGroup(group, false)) return false;
|
||||
|
||||
if(group instanceof IncludeGroup includeGroup){
|
||||
GroupConfigGui.INSTANCE.updateValueForGeneric(includeGroup, true);
|
||||
GroupConfigGui configGui = GroupConfigGui.getCurrentInstance();
|
||||
if(configGui != null) configGui.updateValueForGeneric(includeGroup, true);
|
||||
}
|
||||
|
||||
if(ConfigOptions.INSTANCE.getVerboseDebugLog()){
|
||||
|
|
@ -145,12 +164,13 @@ public class MaterialGroupApi {
|
|||
ConfigHolder.ITEM_GROUP_HOLDER.getItemGroupsManager().groupMap.remove(group.getName());
|
||||
|
||||
// Write as null and save to file
|
||||
ConfigHolder.ITEM_GROUP_HOLDER.getConfig().set(group.getName(), null);
|
||||
ConfigHolder.ITEM_GROUP_HOLDER.delete(group.getName());
|
||||
prepareSaveTask();
|
||||
|
||||
// Remove from gui
|
||||
if(group instanceof IncludeGroup includeGroup){
|
||||
GroupConfigGui.INSTANCE.removeGeneric(includeGroup);
|
||||
GroupConfigGui configGui = GroupConfigGui.getCurrentInstance();
|
||||
if(configGui != null) configGui.removeGeneric(includeGroup);
|
||||
}
|
||||
|
||||
return true;
|
||||
|
|
@ -176,7 +196,10 @@ public class MaterialGroupApi {
|
|||
|
||||
reloadChangeTask = Bukkit.getScheduler().scheduleSyncDelayedTask(CustomAnvil.instance, ()->{
|
||||
ConfigHolder.ITEM_GROUP_HOLDER.reload();
|
||||
GroupConfigGui.INSTANCE.reloadValues();
|
||||
|
||||
GroupConfigGui configGui = GroupConfigGui.getCurrentInstance();
|
||||
if(configGui != null) configGui.reloadValues();
|
||||
|
||||
reloadChangeTask = -1;
|
||||
}, 0L);
|
||||
|
||||
|
|
|
|||
|
|
@ -4,13 +4,17 @@ import com.google.common.io.Files;
|
|||
import io.delilaheve.CustomAnvil;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import xyz.alexcrea.cuanvil.group.EnchantConflictManager;
|
||||
import xyz.alexcrea.cuanvil.group.ItemGroupManager;
|
||||
import xyz.alexcrea.cuanvil.recipe.CustomAnvilRecipeManager;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.logging.Level;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public abstract class ConfigHolder {
|
||||
|
||||
// Available configuration:
|
||||
|
|
@ -140,7 +144,7 @@ public abstract class ConfigHolder {
|
|||
Files.copy(base, firstBackup);
|
||||
sufficientSuccess = true;
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
CustomAnvil.instance.getLogger().log(Level.WARNING, "Could not copy backup saving config " + base.getName(), e);
|
||||
}
|
||||
}
|
||||
// save last backup
|
||||
|
|
@ -200,15 +204,126 @@ public abstract class ConfigHolder {
|
|||
YamlConfiguration configuration = CustomAnvil.instance.reloadResource(
|
||||
getConfigFileName() + getConfigFileExtension(), hardFail);
|
||||
if (configuration == null) return false;
|
||||
|
||||
this.configuration = configuration;
|
||||
reload();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public abstract static class DeletableResource extends ResourceConfigHolder{
|
||||
|
||||
private static final String DELETED_FOLDER_PATH = "deleted";
|
||||
|
||||
private final @NotNull File parent;
|
||||
private final @NotNull File deletedConfigFile;
|
||||
|
||||
private @Nullable YamlConfiguration deletedListConfig;
|
||||
private DeletableResource(String resourceName) {
|
||||
super(resourceName);
|
||||
this.parent = new File(CustomAnvil.instance.getDataFolder(), DELETED_FOLDER_PATH);
|
||||
this.deletedConfigFile = new File(this.parent, "deleted_" + resourceName + getConfigFileExtension());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean reloadFromDisk(boolean hardFail) {
|
||||
if(!super.reloadFromDisk(hardFail)) return false;
|
||||
loadDeletedListFile(hardFail);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private void loadDeletedListFile(boolean hardFail){
|
||||
this.deletedListConfig = CustomAnvil.instance.reloadResource(this.deletedConfigFile, hardFail);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Test if the provided element was deleted.
|
||||
* @param objectPath The object path to delete.
|
||||
* @return True if successful.
|
||||
*/
|
||||
public boolean isDeleted(String objectPath){
|
||||
if(this.deletedListConfig == null) return false;
|
||||
|
||||
return this.deletedListConfig.getBoolean(objectPath, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete a certain object by its path. do not save the config.
|
||||
* @param objectPath The object path to delete.
|
||||
* @return True if successful.
|
||||
*/
|
||||
public boolean delete(String objectPath){
|
||||
return delete(objectPath, false, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete a certain object by its path.
|
||||
* @param objectPath The object path to delete.
|
||||
* @param doSave If we should save the config after deleting.
|
||||
* @param doBackup If we should create a backup.
|
||||
* @return True if successful.
|
||||
*/
|
||||
public boolean delete(String objectPath, boolean doSave, boolean doBackup){
|
||||
// Create deleted list if it does not yet exist
|
||||
if(this.deletedListConfig == null){
|
||||
this.parent.mkdirs();
|
||||
try {
|
||||
this.deletedConfigFile.createNewFile();
|
||||
} catch (IOException e) {
|
||||
CustomAnvil.instance.getLogger().log(Level.WARNING, "Could not create " + this.deletedConfigFile.getPath(), e);
|
||||
}
|
||||
loadDeletedListFile(false);
|
||||
|
||||
// Something was wrong somehow
|
||||
if(this.deletedListConfig == null) return false;
|
||||
}
|
||||
|
||||
// Add to the deleted config
|
||||
this.deletedListConfig.set(objectPath, true);
|
||||
this.getConfig().set(objectPath, null);
|
||||
|
||||
// Save the deleted config (may not be the most efficient, but I will handle it later)
|
||||
if(doSave){
|
||||
return saveToDisk(doBackup);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean saveToDisk(boolean doBackup) {
|
||||
boolean deletedSaveSuccess = saveDeletedList();
|
||||
|
||||
return super.saveToDisk(doBackup) && deletedSaveSuccess;
|
||||
}
|
||||
|
||||
/**
|
||||
* Save list of deleted elements.
|
||||
* @return true if successful.
|
||||
*/
|
||||
public boolean saveDeletedList() {
|
||||
if(this.deletedListConfig == null) return true;
|
||||
|
||||
try {
|
||||
this.deletedListConfig.save(this.deletedConfigFile);
|
||||
} catch (IOException e) {
|
||||
CustomAnvil.instance.getLogger().log(Level.WARNING, "Could not save " + this.deletedConfigFile.getPath(), e);
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
// Class for itemGroupsManager config
|
||||
public static class ItemGroupConfigHolder extends ResourceConfigHolder {
|
||||
public static class ItemGroupConfigHolder extends DeletableResource {
|
||||
private static final String FILE_NAME = "item_groups";
|
||||
|
||||
ItemGroupManager itemGroupsManager;
|
||||
|
|
@ -235,7 +350,7 @@ public abstract class ConfigHolder {
|
|||
}
|
||||
|
||||
// Class for enchant conflict config
|
||||
public static class ConflictConfigHolder extends ResourceConfigHolder {
|
||||
public static class ConflictConfigHolder extends DeletableResource {
|
||||
private static final String FILE_NAME = "enchant_conflict";
|
||||
|
||||
EnchantConflictManager conflictManager;
|
||||
|
|
@ -259,10 +374,9 @@ public abstract class ConfigHolder {
|
|||
}
|
||||
|
||||
// Class for unit repair config
|
||||
public static class UnitRepairHolder extends ResourceConfigHolder {
|
||||
public static class UnitRepairHolder extends DeletableResource {
|
||||
private static final String ITEM_GROUP_FILE_NAME = "unit_repair_item";
|
||||
|
||||
|
||||
private UnitRepairHolder() {
|
||||
super(ITEM_GROUP_FILE_NAME);
|
||||
}
|
||||
|
|
@ -275,7 +389,7 @@ public abstract class ConfigHolder {
|
|||
|
||||
|
||||
// Class for custom anvil craft
|
||||
public static class CustomAnvilCraftHolder extends ResourceConfigHolder {
|
||||
public static class CustomAnvilCraftHolder extends DeletableResource {
|
||||
private static final String CUSTOM_RECIPE_FILE_NAME = "custom_recipes";
|
||||
CustomAnvilRecipeManager recipeManager;
|
||||
|
||||
|
|
|
|||
|
|
@ -82,7 +82,7 @@ public class MainConfigGui extends ChestGui {
|
|||
enchantConflictMeta.setLore(Collections.singletonList("\u00A77Click here to open enchantment conflict menu"));
|
||||
enchantConflictItemstack.setItemMeta(enchantConflictMeta);
|
||||
|
||||
GuiItem enchantConflictItem = GuiGlobalItems.goToGuiItem(enchantConflictItemstack, EnchantConflictGui.INSTANCE);
|
||||
GuiItem enchantConflictItem = GuiGlobalItems.goToGuiItem(enchantConflictItemstack, EnchantConflictGui.getInstance());
|
||||
pane.bindItem('4', enchantConflictItem);
|
||||
|
||||
// Group config items
|
||||
|
|
@ -94,7 +94,7 @@ public class MainConfigGui extends ChestGui {
|
|||
groupMeta.setLore(Collections.singletonList("\u00A77Click here to open material group menu"));
|
||||
groupItemstack.setItemMeta(groupMeta);
|
||||
|
||||
GuiItem groupConfigItem = GuiGlobalItems.goToGuiItem(groupItemstack, GroupConfigGui.INSTANCE);
|
||||
GuiItem groupConfigItem = GuiGlobalItems.goToGuiItem(groupItemstack, GroupConfigGui.getInstance());
|
||||
|
||||
pane.bindItem('5', groupConfigItem);
|
||||
|
||||
|
|
@ -107,7 +107,7 @@ public class MainConfigGui extends ChestGui {
|
|||
unitRepairMeta.setLore(Collections.singletonList("\u00A77Click here to open anvil unit repair menu"));
|
||||
unirRepairItemstack.setItemMeta(unitRepairMeta);
|
||||
|
||||
GuiItem unitRepairItem = GuiGlobalItems.goToGuiItem(unirRepairItemstack, UnitRepairConfigGui.INSTANCE);
|
||||
GuiItem unitRepairItem = GuiGlobalItems.goToGuiItem(unirRepairItemstack, UnitRepairConfigGui.getInstance());
|
||||
pane.bindItem('6', unitRepairItem);
|
||||
|
||||
// Custom recipe item
|
||||
|
|
@ -119,7 +119,7 @@ public class MainConfigGui extends ChestGui {
|
|||
customRecipeMeta.setLore(Collections.singletonList("\u00A77Click here to open anvil custom recipe menu"));
|
||||
customRecipeItemstack.setItemMeta(customRecipeMeta);
|
||||
|
||||
GuiItem customRecipeItem = GuiGlobalItems.goToGuiItem(customRecipeItemstack, CustomRecipeConfigGui.INSTANCE);
|
||||
GuiItem customRecipeItem = GuiGlobalItems.goToGuiItem(customRecipeItemstack, CustomRecipeConfigGui.getInstance());
|
||||
pane.bindItem('7', customRecipeItem);
|
||||
|
||||
// quit item
|
||||
|
|
|
|||
|
|
@ -5,6 +5,8 @@ import org.bukkit.Material;
|
|||
import org.bukkit.inventory.ItemFlag;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import xyz.alexcrea.cuanvil.config.ConfigHolder;
|
||||
import xyz.alexcrea.cuanvil.gui.config.list.MappedGuiListConfigGui;
|
||||
import xyz.alexcrea.cuanvil.gui.config.list.elements.CustomRecipeSubSettingGui;
|
||||
|
|
@ -17,10 +19,18 @@ import java.util.Collection;
|
|||
public class CustomRecipeConfigGui extends MappedGuiListConfigGui<AnvilCustomRecipe, CustomRecipeSubSettingGui> {
|
||||
|
||||
|
||||
public final static CustomRecipeConfigGui INSTANCE = new CustomRecipeConfigGui();
|
||||
private static CustomRecipeConfigGui INSTANCE = new CustomRecipeConfigGui();
|
||||
|
||||
static {
|
||||
INSTANCE.init();
|
||||
@Nullable
|
||||
public static CustomRecipeConfigGui getCurrentInstance(){
|
||||
return INSTANCE;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static CustomRecipeConfigGui getInstance(){
|
||||
if(INSTANCE == null) INSTANCE = new CustomRecipeConfigGui();
|
||||
|
||||
return INSTANCE;
|
||||
}
|
||||
|
||||
private CustomRecipeConfigGui() {
|
||||
|
|
|
|||
|
|
@ -5,6 +5,8 @@ import org.bukkit.configuration.file.FileConfiguration;
|
|||
import org.bukkit.inventory.ItemFlag;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import xyz.alexcrea.cuanvil.config.ConfigHolder;
|
||||
import xyz.alexcrea.cuanvil.group.EnchantConflictGroup;
|
||||
import xyz.alexcrea.cuanvil.group.IncludeGroup;
|
||||
|
|
@ -18,14 +20,25 @@ import java.util.Collection;
|
|||
|
||||
public class EnchantConflictGui extends MappedGuiListConfigGui<EnchantConflictGroup, EnchantConflictSubSettingGui> {
|
||||
|
||||
public static final EnchantConflictGui INSTANCE = new EnchantConflictGui();
|
||||
private static EnchantConflictGui INSTANCE;
|
||||
|
||||
static {
|
||||
INSTANCE.init();
|
||||
@Nullable
|
||||
public static EnchantConflictGui getCurrentInstance(){
|
||||
return INSTANCE;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static EnchantConflictGui getInstance(){
|
||||
if(INSTANCE == null) INSTANCE = new EnchantConflictGui();
|
||||
|
||||
return INSTANCE;
|
||||
}
|
||||
|
||||
|
||||
private EnchantConflictGui() {
|
||||
super( "Conflict Config");
|
||||
|
||||
init();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -5,6 +5,8 @@ import org.bukkit.configuration.ConfigurationSection;
|
|||
import org.bukkit.inventory.ItemFlag;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import xyz.alexcrea.cuanvil.config.ConfigHolder;
|
||||
import xyz.alexcrea.cuanvil.group.AbstractMaterialGroup;
|
||||
import xyz.alexcrea.cuanvil.group.GroupType;
|
||||
|
|
@ -20,14 +22,24 @@ import java.util.Collection;
|
|||
|
||||
public class GroupConfigGui extends MappedGuiListConfigGui<IncludeGroup, GroupConfigSubSettingGui> {
|
||||
|
||||
public final static GroupConfigGui INSTANCE = new GroupConfigGui();
|
||||
private static GroupConfigGui INSTANCE;
|
||||
|
||||
static {
|
||||
INSTANCE.init();
|
||||
@Nullable
|
||||
public static GroupConfigGui getCurrentInstance(){
|
||||
return INSTANCE;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static GroupConfigGui getInstance(){
|
||||
if(INSTANCE == null) INSTANCE = new GroupConfigGui();
|
||||
|
||||
return INSTANCE;
|
||||
}
|
||||
|
||||
public GroupConfigGui() {
|
||||
super("Group Config");
|
||||
|
||||
init();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -6,6 +6,8 @@ import org.bukkit.Material;
|
|||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import xyz.alexcrea.cuanvil.config.ConfigHolder;
|
||||
import xyz.alexcrea.cuanvil.gui.config.ask.SelectItemTypeGui;
|
||||
import xyz.alexcrea.cuanvil.gui.config.list.MappedGuiListConfigGui;
|
||||
|
|
@ -18,14 +20,24 @@ import java.util.Collection;
|
|||
|
||||
public class UnitRepairConfigGui extends MappedGuiListConfigGui<Material, UnitRepairElementListGui> {
|
||||
|
||||
public static final UnitRepairConfigGui INSTANCE = new UnitRepairConfigGui();
|
||||
private static UnitRepairConfigGui INSTANCE;
|
||||
|
||||
static {
|
||||
INSTANCE.init();
|
||||
@Nullable
|
||||
public static UnitRepairConfigGui getCurrentInstance(){
|
||||
return INSTANCE;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static UnitRepairConfigGui getInstance(){
|
||||
if(INSTANCE == null) INSTANCE = new UnitRepairConfigGui();
|
||||
|
||||
return INSTANCE;
|
||||
}
|
||||
|
||||
private UnitRepairConfigGui() {
|
||||
super("Unit Repair Config");
|
||||
|
||||
init();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -120,7 +120,7 @@ public class CustomRecipeSubSettingGui extends MappedToListSubSettingGui {
|
|||
cleanAndBeUnusable();
|
||||
|
||||
// Update config file storage
|
||||
ConfigHolder.CUSTOM_RECIPE_HOLDER.getConfig().set(this.anvilRecipe.toString(), null);
|
||||
ConfigHolder.CUSTOM_RECIPE_HOLDER.delete(this.anvilRecipe.toString());
|
||||
|
||||
// Save
|
||||
boolean success = true;
|
||||
|
|
|
|||
|
|
@ -127,7 +127,7 @@ public class EnchantConflictSubSettingGui extends MappedToListSubSettingGui impl
|
|||
cleanAndBeUnusable();
|
||||
|
||||
// Update config file storage
|
||||
ConfigHolder.CONFLICT_HOLDER.getConfig().set(this.enchantConflict.toString(), null);
|
||||
ConfigHolder.CONFLICT_HOLDER.delete(this.enchantConflict.toString());
|
||||
|
||||
// Save
|
||||
boolean success = true;
|
||||
|
|
|
|||
|
|
@ -129,7 +129,7 @@ public class GroupConfigSubSettingGui extends MappedToListSubSettingGui implemen
|
|||
cleanAndBeUnusable();
|
||||
|
||||
// Update config file storage
|
||||
ConfigHolder.CUSTOM_RECIPE_HOLDER.getConfig().set(this.group.getName(), null);
|
||||
ConfigHolder.CUSTOM_RECIPE_HOLDER.delete(this.group.getName());
|
||||
|
||||
// Save
|
||||
boolean success = true;
|
||||
|
|
|
|||
|
|
@ -316,7 +316,11 @@ public class DoubleSettingGui extends AbstractSettingGui {
|
|||
@Override
|
||||
public boolean onSave() {
|
||||
if(isNull()){
|
||||
if(this.holder.config instanceof ConfigHolder.DeletableResource deletableResource){
|
||||
deletableResource.delete(this.holder.configPath);
|
||||
}else{
|
||||
this.holder.config.getConfig().set(this.holder.configPath, null);
|
||||
}
|
||||
}else{
|
||||
this.holder.config.getConfig().set(this.holder.configPath, now.doubleValue());
|
||||
}
|
||||
|
|
|
|||
|
|
@ -128,6 +128,10 @@ class CustomAnvil : JavaPlugin() {
|
|||
// temporary: handle 1.21 update
|
||||
Update_1_21.handleUpdate()
|
||||
|
||||
// Register enchantment of compatible plugin and load configuration change.
|
||||
DependencyManager.handleCompatibilityConfig()
|
||||
|
||||
// Call config event
|
||||
val configReadyEvent = CAConfigReadyEvent()
|
||||
server.pluginManager.callEvent(configReadyEvent)
|
||||
|
||||
|
|
@ -135,8 +139,6 @@ class CustomAnvil : JavaPlugin() {
|
|||
MainConfigGui.getInstance().init(DependencyManager.packetManager)
|
||||
GuiSharedConstant.loadConstants()
|
||||
|
||||
// Register enchantment of compatible plugin and load configuration change.
|
||||
DependencyManager.handleCompatibilityConfig()
|
||||
}
|
||||
|
||||
fun reloadResource(
|
||||
|
|
@ -148,20 +150,34 @@ class CustomAnvil : JavaPlugin() {
|
|||
if (!file.exists()) {
|
||||
saveResource(resourceName, false)
|
||||
}
|
||||
|
||||
return reloadResource(file, hardFailSafe)
|
||||
}
|
||||
|
||||
// Unlike above function. this function will not clone default from jar.
|
||||
fun reloadResource(
|
||||
resourceFile: File,
|
||||
hardFailSafe: Boolean = true
|
||||
): YamlConfiguration? {
|
||||
// Test if file exist
|
||||
if (!resourceFile.exists()) {
|
||||
return null
|
||||
}
|
||||
|
||||
// Load resource
|
||||
val yamlConfig = YamlConfiguration()
|
||||
try {
|
||||
val configReader = FileReader(file)
|
||||
val configReader = FileReader(resourceFile)
|
||||
yamlConfig.load(configReader)
|
||||
} catch (test: Exception) {
|
||||
if (hardFailSafe) {
|
||||
// This is important and may impact gameplay if it does not load.
|
||||
// Failsafe is to stop the plugin
|
||||
logger.severe("Resource $resourceName Could not be load or reload.")
|
||||
logger.severe("Resource ${resourceFile.path} Could not be load or reload.")
|
||||
logger.severe("Disabling plugin.")
|
||||
Bukkit.getPluginManager().disablePlugin(this)
|
||||
} else {
|
||||
logger.warning("Resource $resourceName Could not be load or reload.")
|
||||
logger.warning("Resource ${resourceFile.path} Could not be load or reload.")
|
||||
}
|
||||
return null
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,11 +1,15 @@
|
|||
package xyz.alexcrea.cuanvil.command
|
||||
|
||||
import io.delilaheve.CustomAnvil
|
||||
import org.bukkit.Bukkit
|
||||
import org.bukkit.command.Command
|
||||
import org.bukkit.command.CommandExecutor
|
||||
import org.bukkit.command.CommandSender
|
||||
import xyz.alexcrea.cuanvil.api.event.CAConfigReadyEvent
|
||||
import xyz.alexcrea.cuanvil.config.ConfigHolder
|
||||
import xyz.alexcrea.cuanvil.dependency.DependencyManager
|
||||
import xyz.alexcrea.cuanvil.gui.config.global.*
|
||||
import xyz.alexcrea.cuanvil.update.Update_1_21
|
||||
|
||||
class ReloadExecutor : CommandExecutor {
|
||||
override fun onCommand(sender: CommandSender, cmd: Command, cmdstr: String, args: Array<out String>): Boolean {
|
||||
|
|
@ -39,10 +43,20 @@ class ReloadExecutor : CommandExecutor {
|
|||
EnchantCostConfigGui.getInstance()?.updateGuiValues()
|
||||
EnchantLimitConfigGui.getInstance()?.updateGuiValues()
|
||||
|
||||
EnchantConflictGui.INSTANCE.reloadValues()
|
||||
GroupConfigGui.INSTANCE.reloadValues()
|
||||
UnitRepairConfigGui.INSTANCE.reloadValues()
|
||||
CustomRecipeConfigGui.INSTANCE.reloadValues()
|
||||
EnchantConflictGui.getCurrentInstance()?.reloadValues()
|
||||
GroupConfigGui.getCurrentInstance()?.reloadValues()
|
||||
UnitRepairConfigGui.getCurrentInstance()?.reloadValues()
|
||||
CustomRecipeConfigGui.getCurrentInstance()?.reloadValues()
|
||||
|
||||
// temporary: handle 1.21 update
|
||||
Update_1_21.handleUpdate()
|
||||
|
||||
// Register enchantment of compatible plugin and load configuration change.
|
||||
DependencyManager.handleCompatibilityConfig()
|
||||
|
||||
// Call event
|
||||
val configReadyEvent = CAConfigReadyEvent()
|
||||
Bukkit.getServer().pluginManager.callEvent(configReadyEvent)
|
||||
|
||||
return true
|
||||
} catch (e: Exception) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue