Исходник Обновленная система кфг | Expensive 3.1

Начинающий
Статус
Оффлайн
Регистрация
12 Авг 2021
Сообщения
161
Реакции[?]
4
Поинты[?]
3K

Перед прочтением основного контента ниже, пожалуйста, обратите внимание на обновление внутри секции Майна на нашем форуме. У нас появились:

  • бесплатные читы для Майнкрафт — любое использование на свой страх и риск;
  • маркетплейс Майнкрафт — абсолютно любая коммерция, связанная с игрой, за исключением продажи читов (аккаунты, предоставления услуг, поиск кодеров читов и так далее);
  • приватные читы для Minecraft — в этом разделе только платные хаки для игры, покупайте группу "Продавец" и выставляйте на продажу свой софт;
  • обсуждения и гайды — всё тот же раздел с вопросами, но теперь модернизированный: поиск нужных хаков, пати с игроками-читерами и другая полезная информация.

Спасибо!

Сохраняет и загружает положение драггинга в\из кфг


Config.java:
package felon.gang.config;

import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import felon.gang.Felon;
import felon.gang.functions.settings.Setting;
import felon.gang.functions.settings.impl.*;
import felon.gang.ui.styles.Style;
import felon.gang.utils.client.IMinecraft;
import felon.gang.utils.drag.DragManager;
import felon.gang.utils.drag.Dragging;
import lombok.Getter;
import net.minecraft.client.Minecraft;

import java.io.File;
import java.util.Map;
import java.util.function.Consumer;

[USER=270918]@Getter[/USER]
public class Config implements IMinecraft {
    private final File file;
    private final String name;
    public static String currentConfig = "autocfg";

    Felon instance = Felon.getInstance();

    public Config(String name) {
        this.name = name;
        this.file = new File(new File(Minecraft.getInstance().gameDir, "\\felon\\configs"), name + ".cfg");
    }

    public void loadConfig(JsonObject jsonObject) {
        if (jsonObject == null) {
            return;
        }

        if (jsonObject.has("functions")) {
            loadFunctionSettings(jsonObject.getAsJsonObject("functions"));
        }

        if (jsonObject.has("styles")) {
            loadStyleSettings(jsonObject.getAsJsonObject("styles"));
        }

        if (jsonObject.has("draggables")) {
            loadDraggables(jsonObject.getAsJsonArray("draggables"));
        }
    }

    private void loadDraggables(JsonArray draggablesArray) {
        for (JsonElement element : draggablesArray) {
            JsonObject draggableObject = element.getAsJsonObject();
            String name = draggableObject.get("name").getAsString();
            Dragging dragging = DragManager.draggables.get(name);
            if (dragging != null) {
                dragging.setX(draggableObject.get("x").getAsInt());
                dragging.setY(draggableObject.get("y").getAsInt());
            }
        }
    }

    private void loadStyleSettings(JsonObject stylesObject) {
        for (Map.Entry<String, JsonElement> entry : stylesObject.entrySet()) {
            String styleName = entry.getKey();
            JsonObject styleObject = entry.getValue().getAsJsonObject();
            Style style = findStyleByName(styleName);
            if (style != null && styleObject.has("selected")) {
                boolean isSelected = styleObject.get("selected").getAsBoolean();
                if (isSelected) {
                    instance.getStyleManager().setCurrentStyle(style);
                }
            }
        }
    }

    private Style findStyleByName(String styleName) {
        for (Style style : instance.getStyleManager().getStyleList()) {
            if (style.getStyleName().equalsIgnoreCase(styleName)) {
                return style;
            }
        }
        return null;
    }

    private void loadFunctionSettings(JsonObject functionsObject) {
        instance.getFunctionRegistry().getFunctions().forEach(f -> {
            JsonObject moduleObject = functionsObject.getAsJsonObject(f.getName().toLowerCase());
            if (moduleObject == null) {
                return;
            }

            f.setState(false, true);
            loadSettingFromJson(moduleObject, "bind", value -> f.setBind(value.getAsInt()));
            loadSettingFromJson(moduleObject, "state", value -> f.setState(value.getAsBoolean(), true));
            f.getSettings().forEach(setting -> loadIndividualSetting(moduleObject, setting));
        });
    }

    private void loadIndividualSetting(JsonObject moduleObject, Setting<?> setting) {
        JsonElement settingElement = moduleObject.get(setting.getName());

        if (settingElement == null || settingElement.isJsonNull()) {
            return;
        }

        if (setting instanceof SliderSetting) {
            ((SliderSetting) setting).set(settingElement.getAsFloat());
        } else if (setting instanceof BooleanSetting) {
            ((BooleanSetting) setting).set(settingElement.getAsBoolean());
        } else if (setting instanceof ColorSetting) {
            ((ColorSetting) setting).set(settingElement.getAsInt());
        } else if (setting instanceof ModeSetting) {
            ((ModeSetting) setting).set(settingElement.getAsString());
        } else if (setting instanceof BindSetting) {
            ((BindSetting) setting).set(settingElement.getAsInt());
        } else if (setting instanceof StringSetting) {
            ((StringSetting) setting).set(settingElement.getAsString());
        } else if (setting instanceof ModeListSetting) {
            loadModeListSetting((ModeListSetting) setting, moduleObject);
        }
    }

    private void loadModeListSetting(ModeListSetting setting, JsonObject moduleObject) {
        JsonObject elements = moduleObject.getAsJsonObject(setting.getName());
        setting.get().forEach(option -> {
            JsonElement optionElement = elements.get(option.getName());
            if (optionElement != null && !optionElement.isJsonNull()) {
                option.set(optionElement.getAsBoolean());
            }
        });
    }

    private void loadSettingFromJson(JsonObject jsonObject, String key, Consumer<JsonElement> consumer) {
        JsonElement element = jsonObject.get(key);
        if (element != null && !element.isJsonNull()) {
            consumer.accept(element);
        }
    }

    public JsonElement saveConfig() {
        JsonObject functionsObject = new JsonObject();
        JsonObject stylesObject = new JsonObject();
        JsonArray draggablesArray = new JsonArray();

        saveFunctionSettings(functionsObject);
        saveStyleSettings(stylesObject);
        saveDraggables(draggablesArray);

        JsonObject newObject = new JsonObject();
        newObject.add("functions", functionsObject);
        newObject.add("styles", stylesObject);
        newObject.add("draggables", draggablesArray);

        return newObject;
    }

    private void saveFunctionSettings(JsonObject functionsObject) {
        instance.getFunctionRegistry().getFunctions().forEach(module -> {
            JsonObject moduleObject = new JsonObject();

            moduleObject.addProperty("bind", module.getBind());
            moduleObject.addProperty("state", module.isState());

            module.getSettings().forEach(setting -> saveIndividualSetting(moduleObject, setting));

            functionsObject.add(module.getName().toLowerCase(), moduleObject);
        });
    }

    private void saveIndividualSetting(JsonObject moduleObject, Setting<?> setting) {
        if (setting instanceof BooleanSetting) {
            moduleObject.addProperty(setting.getName(), ((BooleanSetting) setting).get());
        } else if (setting instanceof SliderSetting) {
            moduleObject.addProperty(setting.getName(), ((SliderSetting) setting).get());
        } else if (setting instanceof ModeSetting) {
            moduleObject.addProperty(setting.getName(), ((ModeSetting) setting).get());
        } else if (setting instanceof ColorSetting) {
            moduleObject.addProperty(setting.getName(), ((ColorSetting) setting).get());
        } else if (setting instanceof BindSetting) {
            moduleObject.addProperty(setting.getName(), ((BindSetting) setting).get());
        } else if (setting instanceof StringSetting) {
            moduleObject.addProperty(setting.getName(), ((StringSetting) setting).get());
        } else if (setting instanceof ModeListSetting) {
            saveModeListSetting(moduleObject, (ModeListSetting) setting);
        }
    }

    private void saveModeListSetting(JsonObject moduleObject, ModeListSetting setting) {
        JsonObject elements = new JsonObject();
        setting.get().forEach(option -> elements.addProperty(option.getName(), option.get()));
        moduleObject.add(setting.getName(), elements);
    }

    private void saveStyleSettings(JsonObject stylesObject) {
        for (Style style : instance.getStyleManager().getStyleList()) {
            JsonObject styleObject = new JsonObject();
            styleObject.addProperty("selected", instance.getStyleManager().getCurrentStyle() == style);
            stylesObject.add(style.getStyleName(), styleObject);
        }
    }

    private void saveDraggables(JsonArray draggablesArray) {
        for (Map.Entry<String, Dragging> entry : DragManager.draggables.entrySet()) {
            JsonObject draggableObject = new JsonObject();
            draggableObject.addProperty("name", entry.getKey());
            draggableObject.addProperty("x", entry.getValue().getX());
            draggableObject.addProperty("y", entry.getValue().getY());
            draggablesArray.add(draggableObject);
        }
    }
}
ConfigStorage.java:
package felon.gang.config;

import com.google.gson.GsonBuilder;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;

import net.minecraft.client.Minecraft;

import java.io.*;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;


public class ConfigStorage {
    public final Logger logger = Logger.getLogger(ConfigStorage.class.getName());

    public final File CONFIG_DIR = new File(Minecraft.getInstance().gameDir, "\\felon\\configs");
    public final File AUTOCFG_DIR = new File(CONFIG_DIR, "autocfg.cfg");

    public final JsonParser jsonParser = new JsonParser();

    public void init() throws IOException {
        setupFolder();
    }

    public void writeDefaultConfig() {
        String json = """
                {
                  "functions": {
                  },
                  "styles": {
                  },
                  "draggables": [
                  ]
                }
                """;

        try (FileWriter writer = new FileWriter(AUTOCFG_DIR)) {
            writer.write(json);
            writer.flush();
            logger.log(Level.INFO, "Created default system configuration!");
        } catch (IOException e) {
            logger.log(Level.INFO, "Failed to create default system configuration file", e);
        }
    }

    public void setupFolder() {
        if (!CONFIG_DIR.exists()) {
            CONFIG_DIR.mkdirs();
        } else if (AUTOCFG_DIR.exists()) {
            loadConfiguration("autocfg");
            logger.log(Level.INFO, "Load system configuration...");
        } else {
            logger.log(Level.INFO, "Creating system configuration...");
            try {
                AUTOCFG_DIR.createNewFile();
                writeDefaultConfig();
                logger.log(Level.INFO, "Created!");
            } catch (IOException e) {
                logger.log(Level.INFO, "Failed to create system configuration file", e);
            }
        }
    }

    public boolean isEmpty() {
        return getConfigs().isEmpty();
    }

    public List<Config> getConfigs() {
        List<Config> configs = new ArrayList<>();
        File[] configFiles = CONFIG_DIR.listFiles();

        if (configFiles != null) {
            for (File configFile : configFiles) {
                if (configFile.isFile() && configFile.getName().endsWith(".cfg")) {
                    String configName = configFile.getName().replace(".cfg", "");
                    Config config = findConfig(configName);
                    if (config != null) {
                        configs.add(config);
                    }
                }
            }
        }

        return configs;
    }


    public void loadConfiguration(String configuration) {
        Config config = findConfig(configuration);
        Config.currentConfig = configuration;
        try {
            FileReader reader = new FileReader(config.getFile());
            JsonParser parser = new JsonParser();
            JsonObject object = (JsonObject) parser.parse(reader);
            config.loadConfig(object);
        } catch (FileNotFoundException e) {
            logger.log(Level.WARNING, "Not Found Exception", e);
        } catch (NullPointerException pointerException) {
            logger.log(Level.INFO, "Fatal error in Config!", pointerException);
        }
    }

    public void saveConfiguration(String configuration) {
        Config config = new Config(configuration);
        String contentPrettyPrint = new GsonBuilder().setPrettyPrinting().create().toJson(config.saveConfig());
        try {
            FileWriter writer = new FileWriter(config.getFile());
            writer.write(contentPrettyPrint);
            writer.close();
        } catch (IOException e) {
            logger.log(Level.WARNING, "File not found!", e);
        } catch (NullPointerException e) {
            logger.log(Level.INFO, "Fatal Error in Config!", e);
        }
    }

    public static void saveConfiguration_static(String configuration) {
        Config config = new Config(configuration);
        String contentPrettyPrint = new GsonBuilder().setPrettyPrinting().create().toJson(config.saveConfig());
        try {
            FileWriter writer = new FileWriter(config.getFile());
            writer.write(contentPrettyPrint);
            writer.close();
        } catch (IOException e) {
            System.out.println("File not found! " + e);
        } catch (NullPointerException e) {
            System.out.println("Fatal Error in Config! " + e);
        }
    }

    public Config findConfig(String configName) {
        if (configName == null) return null;
        if (new File(CONFIG_DIR, configName + ".cfg").exists())
            return new Config(configName);
        return null;
    }
}
DragManager.java:
package felon.gang.utils.drag;

import java.util.LinkedHashMap;
import java.util.logging.Logger;



public class DragManager {

    public static final Logger logger = Logger.getLogger(DragManager.class.getName());
    public static LinkedHashMap<String, Dragging> draggables = new LinkedHashMap<>();

}
 
Забаненный
Статус
Оффлайн
Регистрация
2 Фев 2024
Сообщения
852
Реакции[?]
7
Поинты[?]
4K
Обратите внимание, пользователь заблокирован на форуме. Не рекомендуется проводить сделки.
Сохраняет и загружает положение драггинга в\из кфг


Config.java:
package felon.gang.config;

import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import felon.gang.Felon;
import felon.gang.functions.settings.Setting;
import felon.gang.functions.settings.impl.*;
import felon.gang.ui.styles.Style;
import felon.gang.utils.client.IMinecraft;
import felon.gang.utils.drag.DragManager;
import felon.gang.utils.drag.Dragging;
import lombok.Getter;
import net.minecraft.client.Minecraft;

import java.io.File;
import java.util.Map;
import java.util.function.Consumer;

[USER=270918]@Getter[/USER]
public class Config implements IMinecraft {
    private final File file;
    private final String name;
    public static String currentConfig = "autocfg";

    Felon instance = Felon.getInstance();

    public Config(String name) {
        this.name = name;
        this.file = new File(new File(Minecraft.getInstance().gameDir, "\\felon\\configs"), name + ".cfg");
    }

    public void loadConfig(JsonObject jsonObject) {
        if (jsonObject == null) {
            return;
        }

        if (jsonObject.has("functions")) {
            loadFunctionSettings(jsonObject.getAsJsonObject("functions"));
        }

        if (jsonObject.has("styles")) {
            loadStyleSettings(jsonObject.getAsJsonObject("styles"));
        }

        if (jsonObject.has("draggables")) {
            loadDraggables(jsonObject.getAsJsonArray("draggables"));
        }
    }

    private void loadDraggables(JsonArray draggablesArray) {
        for (JsonElement element : draggablesArray) {
            JsonObject draggableObject = element.getAsJsonObject();
            String name = draggableObject.get("name").getAsString();
            Dragging dragging = DragManager.draggables.get(name);
            if (dragging != null) {
                dragging.setX(draggableObject.get("x").getAsInt());
                dragging.setY(draggableObject.get("y").getAsInt());
            }
        }
    }

    private void loadStyleSettings(JsonObject stylesObject) {
        for (Map.Entry<String, JsonElement> entry : stylesObject.entrySet()) {
            String styleName = entry.getKey();
            JsonObject styleObject = entry.getValue().getAsJsonObject();
            Style style = findStyleByName(styleName);
            if (style != null && styleObject.has("selected")) {
                boolean isSelected = styleObject.get("selected").getAsBoolean();
                if (isSelected) {
                    instance.getStyleManager().setCurrentStyle(style);
                }
            }
        }
    }

    private Style findStyleByName(String styleName) {
        for (Style style : instance.getStyleManager().getStyleList()) {
            if (style.getStyleName().equalsIgnoreCase(styleName)) {
                return style;
            }
        }
        return null;
    }

    private void loadFunctionSettings(JsonObject functionsObject) {
        instance.getFunctionRegistry().getFunctions().forEach(f -> {
            JsonObject moduleObject = functionsObject.getAsJsonObject(f.getName().toLowerCase());
            if (moduleObject == null) {
                return;
            }

            f.setState(false, true);
            loadSettingFromJson(moduleObject, "bind", value -> f.setBind(value.getAsInt()));
            loadSettingFromJson(moduleObject, "state", value -> f.setState(value.getAsBoolean(), true));
            f.getSettings().forEach(setting -> loadIndividualSetting(moduleObject, setting));
        });
    }

    private void loadIndividualSetting(JsonObject moduleObject, Setting<?> setting) {
        JsonElement settingElement = moduleObject.get(setting.getName());

        if (settingElement == null || settingElement.isJsonNull()) {
            return;
        }

        if (setting instanceof SliderSetting) {
            ((SliderSetting) setting).set(settingElement.getAsFloat());
        } else if (setting instanceof BooleanSetting) {
            ((BooleanSetting) setting).set(settingElement.getAsBoolean());
        } else if (setting instanceof ColorSetting) {
            ((ColorSetting) setting).set(settingElement.getAsInt());
        } else if (setting instanceof ModeSetting) {
            ((ModeSetting) setting).set(settingElement.getAsString());
        } else if (setting instanceof BindSetting) {
            ((BindSetting) setting).set(settingElement.getAsInt());
        } else if (setting instanceof StringSetting) {
            ((StringSetting) setting).set(settingElement.getAsString());
        } else if (setting instanceof ModeListSetting) {
            loadModeListSetting((ModeListSetting) setting, moduleObject);
        }
    }

    private void loadModeListSetting(ModeListSetting setting, JsonObject moduleObject) {
        JsonObject elements = moduleObject.getAsJsonObject(setting.getName());
        setting.get().forEach(option -> {
            JsonElement optionElement = elements.get(option.getName());
            if (optionElement != null && !optionElement.isJsonNull()) {
                option.set(optionElement.getAsBoolean());
            }
        });
    }

    private void loadSettingFromJson(JsonObject jsonObject, String key, Consumer<JsonElement> consumer) {
        JsonElement element = jsonObject.get(key);
        if (element != null && !element.isJsonNull()) {
            consumer.accept(element);
        }
    }

    public JsonElement saveConfig() {
        JsonObject functionsObject = new JsonObject();
        JsonObject stylesObject = new JsonObject();
        JsonArray draggablesArray = new JsonArray();

        saveFunctionSettings(functionsObject);
        saveStyleSettings(stylesObject);
        saveDraggables(draggablesArray);

        JsonObject newObject = new JsonObject();
        newObject.add("functions", functionsObject);
        newObject.add("styles", stylesObject);
        newObject.add("draggables", draggablesArray);

        return newObject;
    }

    private void saveFunctionSettings(JsonObject functionsObject) {
        instance.getFunctionRegistry().getFunctions().forEach(module -> {
            JsonObject moduleObject = new JsonObject();

            moduleObject.addProperty("bind", module.getBind());
            moduleObject.addProperty("state", module.isState());

            module.getSettings().forEach(setting -> saveIndividualSetting(moduleObject, setting));

            functionsObject.add(module.getName().toLowerCase(), moduleObject);
        });
    }

    private void saveIndividualSetting(JsonObject moduleObject, Setting<?> setting) {
        if (setting instanceof BooleanSetting) {
            moduleObject.addProperty(setting.getName(), ((BooleanSetting) setting).get());
        } else if (setting instanceof SliderSetting) {
            moduleObject.addProperty(setting.getName(), ((SliderSetting) setting).get());
        } else if (setting instanceof ModeSetting) {
            moduleObject.addProperty(setting.getName(), ((ModeSetting) setting).get());
        } else if (setting instanceof ColorSetting) {
            moduleObject.addProperty(setting.getName(), ((ColorSetting) setting).get());
        } else if (setting instanceof BindSetting) {
            moduleObject.addProperty(setting.getName(), ((BindSetting) setting).get());
        } else if (setting instanceof StringSetting) {
            moduleObject.addProperty(setting.getName(), ((StringSetting) setting).get());
        } else if (setting instanceof ModeListSetting) {
            saveModeListSetting(moduleObject, (ModeListSetting) setting);
        }
    }

    private void saveModeListSetting(JsonObject moduleObject, ModeListSetting setting) {
        JsonObject elements = new JsonObject();
        setting.get().forEach(option -> elements.addProperty(option.getName(), option.get()));
        moduleObject.add(setting.getName(), elements);
    }

    private void saveStyleSettings(JsonObject stylesObject) {
        for (Style style : instance.getStyleManager().getStyleList()) {
            JsonObject styleObject = new JsonObject();
            styleObject.addProperty("selected", instance.getStyleManager().getCurrentStyle() == style);
            stylesObject.add(style.getStyleName(), styleObject);
        }
    }

    private void saveDraggables(JsonArray draggablesArray) {
        for (Map.Entry<String, Dragging> entry : DragManager.draggables.entrySet()) {
            JsonObject draggableObject = new JsonObject();
            draggableObject.addProperty("name", entry.getKey());
            draggableObject.addProperty("x", entry.getValue().getX());
            draggableObject.addProperty("y", entry.getValue().getY());
            draggablesArray.add(draggableObject);
        }
    }
}
ConfigStorage.java:
package felon.gang.config;

import com.google.gson.GsonBuilder;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;

import net.minecraft.client.Minecraft;

import java.io.*;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;


public class ConfigStorage {
    public final Logger logger = Logger.getLogger(ConfigStorage.class.getName());

    public final File CONFIG_DIR = new File(Minecraft.getInstance().gameDir, "\\felon\\configs");
    public final File AUTOCFG_DIR = new File(CONFIG_DIR, "autocfg.cfg");

    public final JsonParser jsonParser = new JsonParser();

    public void init() throws IOException {
        setupFolder();
    }

    public void writeDefaultConfig() {
        String json = """
                {
                  "functions": {
                  },
                  "styles": {
                  },
                  "draggables": [
                  ]
                }
                """;

        try (FileWriter writer = new FileWriter(AUTOCFG_DIR)) {
            writer.write(json);
            writer.flush();
            logger.log(Level.INFO, "Created default system configuration!");
        } catch (IOException e) {
            logger.log(Level.INFO, "Failed to create default system configuration file", e);
        }
    }

    public void setupFolder() {
        if (!CONFIG_DIR.exists()) {
            CONFIG_DIR.mkdirs();
        } else if (AUTOCFG_DIR.exists()) {
            loadConfiguration("autocfg");
            logger.log(Level.INFO, "Load system configuration...");
        } else {
            logger.log(Level.INFO, "Creating system configuration...");
            try {
                AUTOCFG_DIR.createNewFile();
                writeDefaultConfig();
                logger.log(Level.INFO, "Created!");
            } catch (IOException e) {
                logger.log(Level.INFO, "Failed to create system configuration file", e);
            }
        }
    }

    public boolean isEmpty() {
        return getConfigs().isEmpty();
    }

    public List<Config> getConfigs() {
        List<Config> configs = new ArrayList<>();
        File[] configFiles = CONFIG_DIR.listFiles();

        if (configFiles != null) {
            for (File configFile : configFiles) {
                if (configFile.isFile() && configFile.getName().endsWith(".cfg")) {
                    String configName = configFile.getName().replace(".cfg", "");
                    Config config = findConfig(configName);
                    if (config != null) {
                        configs.add(config);
                    }
                }
            }
        }

        return configs;
    }


    public void loadConfiguration(String configuration) {
        Config config = findConfig(configuration);
        Config.currentConfig = configuration;
        try {
            FileReader reader = new FileReader(config.getFile());
            JsonParser parser = new JsonParser();
            JsonObject object = (JsonObject) parser.parse(reader);
            config.loadConfig(object);
        } catch (FileNotFoundException e) {
            logger.log(Level.WARNING, "Not Found Exception", e);
        } catch (NullPointerException pointerException) {
            logger.log(Level.INFO, "Fatal error in Config!", pointerException);
        }
    }

    public void saveConfiguration(String configuration) {
        Config config = new Config(configuration);
        String contentPrettyPrint = new GsonBuilder().setPrettyPrinting().create().toJson(config.saveConfig());
        try {
            FileWriter writer = new FileWriter(config.getFile());
            writer.write(contentPrettyPrint);
            writer.close();
        } catch (IOException e) {
            logger.log(Level.WARNING, "File not found!", e);
        } catch (NullPointerException e) {
            logger.log(Level.INFO, "Fatal Error in Config!", e);
        }
    }

    public static void saveConfiguration_static(String configuration) {
        Config config = new Config(configuration);
        String contentPrettyPrint = new GsonBuilder().setPrettyPrinting().create().toJson(config.saveConfig());
        try {
            FileWriter writer = new FileWriter(config.getFile());
            writer.write(contentPrettyPrint);
            writer.close();
        } catch (IOException e) {
            System.out.println("File not found! " + e);
        } catch (NullPointerException e) {
            System.out.println("Fatal Error in Config! " + e);
        }
    }

    public Config findConfig(String configName) {
        if (configName == null) return null;
        if (new File(CONFIG_DIR, configName + ".cfg").exists())
            return new Config(configName);
        return null;
    }
}
DragManager.java:
package felon.gang.utils.drag;

import java.util.LinkedHashMap;
import java.util.logging.Logger;



public class DragManager {

    public static final Logger logger = Logger.getLogger(DragManager.class.getName());
    public static LinkedHashMap<String, Dragging> draggables = new LinkedHashMap<>();

}
Пока я сливал как сохранять драги ты сделал их в кфг я люблю тебя бро
Сохраняет и загружает положение драггинга в\из кфг


Config.java:
package felon.gang.config;

import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import felon.gang.Felon;
import felon.gang.functions.settings.Setting;
import felon.gang.functions.settings.impl.*;
import felon.gang.ui.styles.Style;
import felon.gang.utils.client.IMinecraft;
import felon.gang.utils.drag.DragManager;
import felon.gang.utils.drag.Dragging;
import lombok.Getter;
import net.minecraft.client.Minecraft;

import java.io.File;
import java.util.Map;
import java.util.function.Consumer;

[USER=270918]@Getter[/USER]
public class Config implements IMinecraft {
    private final File file;
    private final String name;
    public static String currentConfig = "autocfg";

    Felon instance = Felon.getInstance();

    public Config(String name) {
        this.name = name;
        this.file = new File(new File(Minecraft.getInstance().gameDir, "\\felon\\configs"), name + ".cfg");
    }

    public void loadConfig(JsonObject jsonObject) {
        if (jsonObject == null) {
            return;
        }

        if (jsonObject.has("functions")) {
            loadFunctionSettings(jsonObject.getAsJsonObject("functions"));
        }

        if (jsonObject.has("styles")) {
            loadStyleSettings(jsonObject.getAsJsonObject("styles"));
        }

        if (jsonObject.has("draggables")) {
            loadDraggables(jsonObject.getAsJsonArray("draggables"));
        }
    }

    private void loadDraggables(JsonArray draggablesArray) {
        for (JsonElement element : draggablesArray) {
            JsonObject draggableObject = element.getAsJsonObject();
            String name = draggableObject.get("name").getAsString();
            Dragging dragging = DragManager.draggables.get(name);
            if (dragging != null) {
                dragging.setX(draggableObject.get("x").getAsInt());
                dragging.setY(draggableObject.get("y").getAsInt());
            }
        }
    }

    private void loadStyleSettings(JsonObject stylesObject) {
        for (Map.Entry<String, JsonElement> entry : stylesObject.entrySet()) {
            String styleName = entry.getKey();
            JsonObject styleObject = entry.getValue().getAsJsonObject();
            Style style = findStyleByName(styleName);
            if (style != null && styleObject.has("selected")) {
                boolean isSelected = styleObject.get("selected").getAsBoolean();
                if (isSelected) {
                    instance.getStyleManager().setCurrentStyle(style);
                }
            }
        }
    }

    private Style findStyleByName(String styleName) {
        for (Style style : instance.getStyleManager().getStyleList()) {
            if (style.getStyleName().equalsIgnoreCase(styleName)) {
                return style;
            }
        }
        return null;
    }

    private void loadFunctionSettings(JsonObject functionsObject) {
        instance.getFunctionRegistry().getFunctions().forEach(f -> {
            JsonObject moduleObject = functionsObject.getAsJsonObject(f.getName().toLowerCase());
            if (moduleObject == null) {
                return;
            }

            f.setState(false, true);
            loadSettingFromJson(moduleObject, "bind", value -> f.setBind(value.getAsInt()));
            loadSettingFromJson(moduleObject, "state", value -> f.setState(value.getAsBoolean(), true));
            f.getSettings().forEach(setting -> loadIndividualSetting(moduleObject, setting));
        });
    }

    private void loadIndividualSetting(JsonObject moduleObject, Setting<?> setting) {
        JsonElement settingElement = moduleObject.get(setting.getName());

        if (settingElement == null || settingElement.isJsonNull()) {
            return;
        }

        if (setting instanceof SliderSetting) {
            ((SliderSetting) setting).set(settingElement.getAsFloat());
        } else if (setting instanceof BooleanSetting) {
            ((BooleanSetting) setting).set(settingElement.getAsBoolean());
        } else if (setting instanceof ColorSetting) {
            ((ColorSetting) setting).set(settingElement.getAsInt());
        } else if (setting instanceof ModeSetting) {
            ((ModeSetting) setting).set(settingElement.getAsString());
        } else if (setting instanceof BindSetting) {
            ((BindSetting) setting).set(settingElement.getAsInt());
        } else if (setting instanceof StringSetting) {
            ((StringSetting) setting).set(settingElement.getAsString());
        } else if (setting instanceof ModeListSetting) {
            loadModeListSetting((ModeListSetting) setting, moduleObject);
        }
    }

    private void loadModeListSetting(ModeListSetting setting, JsonObject moduleObject) {
        JsonObject elements = moduleObject.getAsJsonObject(setting.getName());
        setting.get().forEach(option -> {
            JsonElement optionElement = elements.get(option.getName());
            if (optionElement != null && !optionElement.isJsonNull()) {
                option.set(optionElement.getAsBoolean());
            }
        });
    }

    private void loadSettingFromJson(JsonObject jsonObject, String key, Consumer<JsonElement> consumer) {
        JsonElement element = jsonObject.get(key);
        if (element != null && !element.isJsonNull()) {
            consumer.accept(element);
        }
    }

    public JsonElement saveConfig() {
        JsonObject functionsObject = new JsonObject();
        JsonObject stylesObject = new JsonObject();
        JsonArray draggablesArray = new JsonArray();

        saveFunctionSettings(functionsObject);
        saveStyleSettings(stylesObject);
        saveDraggables(draggablesArray);

        JsonObject newObject = new JsonObject();
        newObject.add("functions", functionsObject);
        newObject.add("styles", stylesObject);
        newObject.add("draggables", draggablesArray);

        return newObject;
    }

    private void saveFunctionSettings(JsonObject functionsObject) {
        instance.getFunctionRegistry().getFunctions().forEach(module -> {
            JsonObject moduleObject = new JsonObject();

            moduleObject.addProperty("bind", module.getBind());
            moduleObject.addProperty("state", module.isState());

            module.getSettings().forEach(setting -> saveIndividualSetting(moduleObject, setting));

            functionsObject.add(module.getName().toLowerCase(), moduleObject);
        });
    }

    private void saveIndividualSetting(JsonObject moduleObject, Setting<?> setting) {
        if (setting instanceof BooleanSetting) {
            moduleObject.addProperty(setting.getName(), ((BooleanSetting) setting).get());
        } else if (setting instanceof SliderSetting) {
            moduleObject.addProperty(setting.getName(), ((SliderSetting) setting).get());
        } else if (setting instanceof ModeSetting) {
            moduleObject.addProperty(setting.getName(), ((ModeSetting) setting).get());
        } else if (setting instanceof ColorSetting) {
            moduleObject.addProperty(setting.getName(), ((ColorSetting) setting).get());
        } else if (setting instanceof BindSetting) {
            moduleObject.addProperty(setting.getName(), ((BindSetting) setting).get());
        } else if (setting instanceof StringSetting) {
            moduleObject.addProperty(setting.getName(), ((StringSetting) setting).get());
        } else if (setting instanceof ModeListSetting) {
            saveModeListSetting(moduleObject, (ModeListSetting) setting);
        }
    }

    private void saveModeListSetting(JsonObject moduleObject, ModeListSetting setting) {
        JsonObject elements = new JsonObject();
        setting.get().forEach(option -> elements.addProperty(option.getName(), option.get()));
        moduleObject.add(setting.getName(), elements);
    }

    private void saveStyleSettings(JsonObject stylesObject) {
        for (Style style : instance.getStyleManager().getStyleList()) {
            JsonObject styleObject = new JsonObject();
            styleObject.addProperty("selected", instance.getStyleManager().getCurrentStyle() == style);
            stylesObject.add(style.getStyleName(), styleObject);
        }
    }

    private void saveDraggables(JsonArray draggablesArray) {
        for (Map.Entry<String, Dragging> entry : DragManager.draggables.entrySet()) {
            JsonObject draggableObject = new JsonObject();
            draggableObject.addProperty("name", entry.getKey());
            draggableObject.addProperty("x", entry.getValue().getX());
            draggableObject.addProperty("y", entry.getValue().getY());
            draggablesArray.add(draggableObject);
        }
    }
}
ConfigStorage.java:
package felon.gang.config;

import com.google.gson.GsonBuilder;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;

import net.minecraft.client.Minecraft;

import java.io.*;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;


public class ConfigStorage {
    public final Logger logger = Logger.getLogger(ConfigStorage.class.getName());

    public final File CONFIG_DIR = new File(Minecraft.getInstance().gameDir, "\\felon\\configs");
    public final File AUTOCFG_DIR = new File(CONFIG_DIR, "autocfg.cfg");

    public final JsonParser jsonParser = new JsonParser();

    public void init() throws IOException {
        setupFolder();
    }

    public void writeDefaultConfig() {
        String json = """
                {
                  "functions": {
                  },
                  "styles": {
                  },
                  "draggables": [
                  ]
                }
                """;

        try (FileWriter writer = new FileWriter(AUTOCFG_DIR)) {
            writer.write(json);
            writer.flush();
            logger.log(Level.INFO, "Created default system configuration!");
        } catch (IOException e) {
            logger.log(Level.INFO, "Failed to create default system configuration file", e);
        }
    }

    public void setupFolder() {
        if (!CONFIG_DIR.exists()) {
            CONFIG_DIR.mkdirs();
        } else if (AUTOCFG_DIR.exists()) {
            loadConfiguration("autocfg");
            logger.log(Level.INFO, "Load system configuration...");
        } else {
            logger.log(Level.INFO, "Creating system configuration...");
            try {
                AUTOCFG_DIR.createNewFile();
                writeDefaultConfig();
                logger.log(Level.INFO, "Created!");
            } catch (IOException e) {
                logger.log(Level.INFO, "Failed to create system configuration file", e);
            }
        }
    }

    public boolean isEmpty() {
        return getConfigs().isEmpty();
    }

    public List<Config> getConfigs() {
        List<Config> configs = new ArrayList<>();
        File[] configFiles = CONFIG_DIR.listFiles();

        if (configFiles != null) {
            for (File configFile : configFiles) {
                if (configFile.isFile() && configFile.getName().endsWith(".cfg")) {
                    String configName = configFile.getName().replace(".cfg", "");
                    Config config = findConfig(configName);
                    if (config != null) {
                        configs.add(config);
                    }
                }
            }
        }

        return configs;
    }


    public void loadConfiguration(String configuration) {
        Config config = findConfig(configuration);
        Config.currentConfig = configuration;
        try {
            FileReader reader = new FileReader(config.getFile());
            JsonParser parser = new JsonParser();
            JsonObject object = (JsonObject) parser.parse(reader);
            config.loadConfig(object);
        } catch (FileNotFoundException e) {
            logger.log(Level.WARNING, "Not Found Exception", e);
        } catch (NullPointerException pointerException) {
            logger.log(Level.INFO, "Fatal error in Config!", pointerException);
        }
    }

    public void saveConfiguration(String configuration) {
        Config config = new Config(configuration);
        String contentPrettyPrint = new GsonBuilder().setPrettyPrinting().create().toJson(config.saveConfig());
        try {
            FileWriter writer = new FileWriter(config.getFile());
            writer.write(contentPrettyPrint);
            writer.close();
        } catch (IOException e) {
            logger.log(Level.WARNING, "File not found!", e);
        } catch (NullPointerException e) {
            logger.log(Level.INFO, "Fatal Error in Config!", e);
        }
    }

    public static void saveConfiguration_static(String configuration) {
        Config config = new Config(configuration);
        String contentPrettyPrint = new GsonBuilder().setPrettyPrinting().create().toJson(config.saveConfig());
        try {
            FileWriter writer = new FileWriter(config.getFile());
            writer.write(contentPrettyPrint);
            writer.close();
        } catch (IOException e) {
            System.out.println("File not found! " + e);
        } catch (NullPointerException e) {
            System.out.println("Fatal Error in Config! " + e);
        }
    }

    public Config findConfig(String configName) {
        if (configName == null) return null;
        if (new File(CONFIG_DIR, configName + ".cfg").exists())
            return new Config(configName);
        return null;
    }
}
DragManager.java:
package felon.gang.utils.drag;

import java.util.LinkedHashMap;
import java.util.logging.Logger;



public class DragManager {

    public static final Logger logger = Logger.getLogger(DragManager.class.getName());
    public static LinkedHashMap<String, Dragging> draggables = new LinkedHashMap<>();

}
Оно автоматически сохраняет или Нада в shutdown сделать сохранения?
 
Начинающий
Статус
Оффлайн
Регистрация
8 Апр 2023
Сообщения
219
Реакции[?]
20
Поинты[?]
23K
Код:
    public boolean isEmpty() {
        return getConfigs().isEmpty();
    }

public Config findConfig(String configName) {
        if (configName == null) return null;
        if (new File(CONFIG_DIR, configName + ".cfg").exists())
            return new Config(configName);
        return null;
    }
Эта система сериализации/дисериализации просто пушка
 
Начинающий
Статус
Оффлайн
Регистрация
12 Авг 2021
Сообщения
161
Реакции[?]
4
Поинты[?]
3K
Оно автоматически сохраняет или Нада в shutdown сделать сохранения?
при сохранении и загрузке кфг все сохраняет и загружает, а само через время ничего не делает
 
Забаненный
Статус
Оффлайн
Регистрация
2 Фев 2024
Сообщения
852
Реакции[?]
7
Поинты[?]
4K
Обратите внимание, пользователь заблокирован на форуме. Не рекомендуется проводить сделки.
Начинающий
Статус
Оффлайн
Регистрация
5 Апр 2023
Сообщения
389
Реакции[?]
1
Поинты[?]
2K
Сохраняет и загружает положение драггинга в\из кфг


Config.java:
package felon.gang.config;

import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import felon.gang.Felon;
import felon.gang.functions.settings.Setting;
import felon.gang.functions.settings.impl.*;
import felon.gang.ui.styles.Style;
import felon.gang.utils.client.IMinecraft;
import felon.gang.utils.drag.DragManager;
import felon.gang.utils.drag.Dragging;
import lombok.Getter;
import net.minecraft.client.Minecraft;

import java.io.File;
import java.util.Map;
import java.util.function.Consumer;

[USER=270918]@Getter[/USER]
public class Config implements IMinecraft {
    private final File file;
    private final String name;
    public static String currentConfig = "autocfg";

    Felon instance = Felon.getInstance();

    public Config(String name) {
        this.name = name;
        this.file = new File(new File(Minecraft.getInstance().gameDir, "\\felon\\configs"), name + ".cfg");
    }

    public void loadConfig(JsonObject jsonObject) {
        if (jsonObject == null) {
            return;
        }

        if (jsonObject.has("functions")) {
            loadFunctionSettings(jsonObject.getAsJsonObject("functions"));
        }

        if (jsonObject.has("styles")) {
            loadStyleSettings(jsonObject.getAsJsonObject("styles"));
        }

        if (jsonObject.has("draggables")) {
            loadDraggables(jsonObject.getAsJsonArray("draggables"));
        }
    }

    private void loadDraggables(JsonArray draggablesArray) {
        for (JsonElement element : draggablesArray) {
            JsonObject draggableObject = element.getAsJsonObject();
            String name = draggableObject.get("name").getAsString();
            Dragging dragging = DragManager.draggables.get(name);
            if (dragging != null) {
                dragging.setX(draggableObject.get("x").getAsInt());
                dragging.setY(draggableObject.get("y").getAsInt());
            }
        }
    }

    private void loadStyleSettings(JsonObject stylesObject) {
        for (Map.Entry<String, JsonElement> entry : stylesObject.entrySet()) {
            String styleName = entry.getKey();
            JsonObject styleObject = entry.getValue().getAsJsonObject();
            Style style = findStyleByName(styleName);
            if (style != null && styleObject.has("selected")) {
                boolean isSelected = styleObject.get("selected").getAsBoolean();
                if (isSelected) {
                    instance.getStyleManager().setCurrentStyle(style);
                }
            }
        }
    }

    private Style findStyleByName(String styleName) {
        for (Style style : instance.getStyleManager().getStyleList()) {
            if (style.getStyleName().equalsIgnoreCase(styleName)) {
                return style;
            }
        }
        return null;
    }

    private void loadFunctionSettings(JsonObject functionsObject) {
        instance.getFunctionRegistry().getFunctions().forEach(f -> {
            JsonObject moduleObject = functionsObject.getAsJsonObject(f.getName().toLowerCase());
            if (moduleObject == null) {
                return;
            }

            f.setState(false, true);
            loadSettingFromJson(moduleObject, "bind", value -> f.setBind(value.getAsInt()));
            loadSettingFromJson(moduleObject, "state", value -> f.setState(value.getAsBoolean(), true));
            f.getSettings().forEach(setting -> loadIndividualSetting(moduleObject, setting));
        });
    }

    private void loadIndividualSetting(JsonObject moduleObject, Setting<?> setting) {
        JsonElement settingElement = moduleObject.get(setting.getName());

        if (settingElement == null || settingElement.isJsonNull()) {
            return;
        }

        if (setting instanceof SliderSetting) {
            ((SliderSetting) setting).set(settingElement.getAsFloat());
        } else if (setting instanceof BooleanSetting) {
            ((BooleanSetting) setting).set(settingElement.getAsBoolean());
        } else if (setting instanceof ColorSetting) {
            ((ColorSetting) setting).set(settingElement.getAsInt());
        } else if (setting instanceof ModeSetting) {
            ((ModeSetting) setting).set(settingElement.getAsString());
        } else if (setting instanceof BindSetting) {
            ((BindSetting) setting).set(settingElement.getAsInt());
        } else if (setting instanceof StringSetting) {
            ((StringSetting) setting).set(settingElement.getAsString());
        } else if (setting instanceof ModeListSetting) {
            loadModeListSetting((ModeListSetting) setting, moduleObject);
        }
    }

    private void loadModeListSetting(ModeListSetting setting, JsonObject moduleObject) {
        JsonObject elements = moduleObject.getAsJsonObject(setting.getName());
        setting.get().forEach(option -> {
            JsonElement optionElement = elements.get(option.getName());
            if (optionElement != null && !optionElement.isJsonNull()) {
                option.set(optionElement.getAsBoolean());
            }
        });
    }

    private void loadSettingFromJson(JsonObject jsonObject, String key, Consumer<JsonElement> consumer) {
        JsonElement element = jsonObject.get(key);
        if (element != null && !element.isJsonNull()) {
            consumer.accept(element);
        }
    }

    public JsonElement saveConfig() {
        JsonObject functionsObject = new JsonObject();
        JsonObject stylesObject = new JsonObject();
        JsonArray draggablesArray = new JsonArray();

        saveFunctionSettings(functionsObject);
        saveStyleSettings(stylesObject);
        saveDraggables(draggablesArray);

        JsonObject newObject = new JsonObject();
        newObject.add("functions", functionsObject);
        newObject.add("styles", stylesObject);
        newObject.add("draggables", draggablesArray);

        return newObject;
    }

    private void saveFunctionSettings(JsonObject functionsObject) {
        instance.getFunctionRegistry().getFunctions().forEach(module -> {
            JsonObject moduleObject = new JsonObject();

            moduleObject.addProperty("bind", module.getBind());
            moduleObject.addProperty("state", module.isState());

            module.getSettings().forEach(setting -> saveIndividualSetting(moduleObject, setting));

            functionsObject.add(module.getName().toLowerCase(), moduleObject);
        });
    }

    private void saveIndividualSetting(JsonObject moduleObject, Setting<?> setting) {
        if (setting instanceof BooleanSetting) {
            moduleObject.addProperty(setting.getName(), ((BooleanSetting) setting).get());
        } else if (setting instanceof SliderSetting) {
            moduleObject.addProperty(setting.getName(), ((SliderSetting) setting).get());
        } else if (setting instanceof ModeSetting) {
            moduleObject.addProperty(setting.getName(), ((ModeSetting) setting).get());
        } else if (setting instanceof ColorSetting) {
            moduleObject.addProperty(setting.getName(), ((ColorSetting) setting).get());
        } else if (setting instanceof BindSetting) {
            moduleObject.addProperty(setting.getName(), ((BindSetting) setting).get());
        } else if (setting instanceof StringSetting) {
            moduleObject.addProperty(setting.getName(), ((StringSetting) setting).get());
        } else if (setting instanceof ModeListSetting) {
            saveModeListSetting(moduleObject, (ModeListSetting) setting);
        }
    }

    private void saveModeListSetting(JsonObject moduleObject, ModeListSetting setting) {
        JsonObject elements = new JsonObject();
        setting.get().forEach(option -> elements.addProperty(option.getName(), option.get()));
        moduleObject.add(setting.getName(), elements);
    }

    private void saveStyleSettings(JsonObject stylesObject) {
        for (Style style : instance.getStyleManager().getStyleList()) {
            JsonObject styleObject = new JsonObject();
            styleObject.addProperty("selected", instance.getStyleManager().getCurrentStyle() == style);
            stylesObject.add(style.getStyleName(), styleObject);
        }
    }

    private void saveDraggables(JsonArray draggablesArray) {
        for (Map.Entry<String, Dragging> entry : DragManager.draggables.entrySet()) {
            JsonObject draggableObject = new JsonObject();
            draggableObject.addProperty("name", entry.getKey());
            draggableObject.addProperty("x", entry.getValue().getX());
            draggableObject.addProperty("y", entry.getValue().getY());
            draggablesArray.add(draggableObject);
        }
    }
}
ConfigStorage.java:
package felon.gang.config;

import com.google.gson.GsonBuilder;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;

import net.minecraft.client.Minecraft;

import java.io.*;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;


public class ConfigStorage {
    public final Logger logger = Logger.getLogger(ConfigStorage.class.getName());

    public final File CONFIG_DIR = new File(Minecraft.getInstance().gameDir, "\\felon\\configs");
    public final File AUTOCFG_DIR = new File(CONFIG_DIR, "autocfg.cfg");

    public final JsonParser jsonParser = new JsonParser();

    public void init() throws IOException {
        setupFolder();
    }

    public void writeDefaultConfig() {
        String json = """
                {
                  "functions": {
                  },
                  "styles": {
                  },
                  "draggables": [
                  ]
                }
                """;

        try (FileWriter writer = new FileWriter(AUTOCFG_DIR)) {
            writer.write(json);
            writer.flush();
            logger.log(Level.INFO, "Created default system configuration!");
        } catch (IOException e) {
            logger.log(Level.INFO, "Failed to create default system configuration file", e);
        }
    }

    public void setupFolder() {
        if (!CONFIG_DIR.exists()) {
            CONFIG_DIR.mkdirs();
        } else if (AUTOCFG_DIR.exists()) {
            loadConfiguration("autocfg");
            logger.log(Level.INFO, "Load system configuration...");
        } else {
            logger.log(Level.INFO, "Creating system configuration...");
            try {
                AUTOCFG_DIR.createNewFile();
                writeDefaultConfig();
                logger.log(Level.INFO, "Created!");
            } catch (IOException e) {
                logger.log(Level.INFO, "Failed to create system configuration file", e);
            }
        }
    }

    public boolean isEmpty() {
        return getConfigs().isEmpty();
    }

    public List<Config> getConfigs() {
        List<Config> configs = new ArrayList<>();
        File[] configFiles = CONFIG_DIR.listFiles();

        if (configFiles != null) {
            for (File configFile : configFiles) {
                if (configFile.isFile() && configFile.getName().endsWith(".cfg")) {
                    String configName = configFile.getName().replace(".cfg", "");
                    Config config = findConfig(configName);
                    if (config != null) {
                        configs.add(config);
                    }
                }
            }
        }

        return configs;
    }


    public void loadConfiguration(String configuration) {
        Config config = findConfig(configuration);
        Config.currentConfig = configuration;
        try {
            FileReader reader = new FileReader(config.getFile());
            JsonParser parser = new JsonParser();
            JsonObject object = (JsonObject) parser.parse(reader);
            config.loadConfig(object);
        } catch (FileNotFoundException e) {
            logger.log(Level.WARNING, "Not Found Exception", e);
        } catch (NullPointerException pointerException) {
            logger.log(Level.INFO, "Fatal error in Config!", pointerException);
        }
    }

    public void saveConfiguration(String configuration) {
        Config config = new Config(configuration);
        String contentPrettyPrint = new GsonBuilder().setPrettyPrinting().create().toJson(config.saveConfig());
        try {
            FileWriter writer = new FileWriter(config.getFile());
            writer.write(contentPrettyPrint);
            writer.close();
        } catch (IOException e) {
            logger.log(Level.WARNING, "File not found!", e);
        } catch (NullPointerException e) {
            logger.log(Level.INFO, "Fatal Error in Config!", e);
        }
    }

    public static void saveConfiguration_static(String configuration) {
        Config config = new Config(configuration);
        String contentPrettyPrint = new GsonBuilder().setPrettyPrinting().create().toJson(config.saveConfig());
        try {
            FileWriter writer = new FileWriter(config.getFile());
            writer.write(contentPrettyPrint);
            writer.close();
        } catch (IOException e) {
            System.out.println("File not found! " + e);
        } catch (NullPointerException e) {
            System.out.println("Fatal Error in Config! " + e);
        }
    }

    public Config findConfig(String configName) {
        if (configName == null) return null;
        if (new File(CONFIG_DIR, configName + ".cfg").exists())
            return new Config(configName);
        return null;
    }
}
DragManager.java:
package felon.gang.utils.drag;

import java.util.LinkedHashMap;
import java.util.logging.Logger;



public class DragManager {

    public static final Logger logger = Logger.getLogger(DragManager.class.getName());
    public static LinkedHashMap<String, Dragging> draggables = new LinkedHashMap<>();

}
:seemsgood:
 
Начинающий
Статус
Оффлайн
Регистрация
10 Ноя 2023
Сообщения
124
Реакции[?]
0
Поинты[?]
0
Сохраняет и загружает положение драггинга в\из кфг


Config.java:
package felon.gang.config;

import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import felon.gang.Felon;
import felon.gang.functions.settings.Setting;
import felon.gang.functions.settings.impl.*;
import felon.gang.ui.styles.Style;
import felon.gang.utils.client.IMinecraft;
import felon.gang.utils.drag.DragManager;
import felon.gang.utils.drag.Dragging;
import lombok.Getter;
import net.minecraft.client.Minecraft;

import java.io.File;
import java.util.Map;
import java.util.function.Consumer;

[USER=270918]@Getter[/USER]
public class Config implements IMinecraft {
    private final File file;
    private final String name;
    public static String currentConfig = "autocfg";

    Felon instance = Felon.getInstance();

    public Config(String name) {
        this.name = name;
        this.file = new File(new File(Minecraft.getInstance().gameDir, "\\felon\\configs"), name + ".cfg");
    }

    public void loadConfig(JsonObject jsonObject) {
        if (jsonObject == null) {
            return;
        }

        if (jsonObject.has("functions")) {
            loadFunctionSettings(jsonObject.getAsJsonObject("functions"));
        }

        if (jsonObject.has("styles")) {
            loadStyleSettings(jsonObject.getAsJsonObject("styles"));
        }

        if (jsonObject.has("draggables")) {
            loadDraggables(jsonObject.getAsJsonArray("draggables"));
        }
    }

    private void loadDraggables(JsonArray draggablesArray) {
        for (JsonElement element : draggablesArray) {
            JsonObject draggableObject = element.getAsJsonObject();
            String name = draggableObject.get("name").getAsString();
            Dragging dragging = DragManager.draggables.get(name);
            if (dragging != null) {
                dragging.setX(draggableObject.get("x").getAsInt());
                dragging.setY(draggableObject.get("y").getAsInt());
            }
        }
    }

    private void loadStyleSettings(JsonObject stylesObject) {
        for (Map.Entry<String, JsonElement> entry : stylesObject.entrySet()) {
            String styleName = entry.getKey();
            JsonObject styleObject = entry.getValue().getAsJsonObject();
            Style style = findStyleByName(styleName);
            if (style != null && styleObject.has("selected")) {
                boolean isSelected = styleObject.get("selected").getAsBoolean();
                if (isSelected) {
                    instance.getStyleManager().setCurrentStyle(style);
                }
            }
        }
    }

    private Style findStyleByName(String styleName) {
        for (Style style : instance.getStyleManager().getStyleList()) {
            if (style.getStyleName().equalsIgnoreCase(styleName)) {
                return style;
            }
        }
        return null;
    }

    private void loadFunctionSettings(JsonObject functionsObject) {
        instance.getFunctionRegistry().getFunctions().forEach(f -> {
            JsonObject moduleObject = functionsObject.getAsJsonObject(f.getName().toLowerCase());
            if (moduleObject == null) {
                return;
            }

            f.setState(false, true);
            loadSettingFromJson(moduleObject, "bind", value -> f.setBind(value.getAsInt()));
            loadSettingFromJson(moduleObject, "state", value -> f.setState(value.getAsBoolean(), true));
            f.getSettings().forEach(setting -> loadIndividualSetting(moduleObject, setting));
        });
    }

    private void loadIndividualSetting(JsonObject moduleObject, Setting<?> setting) {
        JsonElement settingElement = moduleObject.get(setting.getName());

        if (settingElement == null || settingElement.isJsonNull()) {
            return;
        }

        if (setting instanceof SliderSetting) {
            ((SliderSetting) setting).set(settingElement.getAsFloat());
        } else if (setting instanceof BooleanSetting) {
            ((BooleanSetting) setting).set(settingElement.getAsBoolean());
        } else if (setting instanceof ColorSetting) {
            ((ColorSetting) setting).set(settingElement.getAsInt());
        } else if (setting instanceof ModeSetting) {
            ((ModeSetting) setting).set(settingElement.getAsString());
        } else if (setting instanceof BindSetting) {
            ((BindSetting) setting).set(settingElement.getAsInt());
        } else if (setting instanceof StringSetting) {
            ((StringSetting) setting).set(settingElement.getAsString());
        } else if (setting instanceof ModeListSetting) {
            loadModeListSetting((ModeListSetting) setting, moduleObject);
        }
    }

    private void loadModeListSetting(ModeListSetting setting, JsonObject moduleObject) {
        JsonObject elements = moduleObject.getAsJsonObject(setting.getName());
        setting.get().forEach(option -> {
            JsonElement optionElement = elements.get(option.getName());
            if (optionElement != null && !optionElement.isJsonNull()) {
                option.set(optionElement.getAsBoolean());
            }
        });
    }

    private void loadSettingFromJson(JsonObject jsonObject, String key, Consumer<JsonElement> consumer) {
        JsonElement element = jsonObject.get(key);
        if (element != null && !element.isJsonNull()) {
            consumer.accept(element);
        }
    }

    public JsonElement saveConfig() {
        JsonObject functionsObject = new JsonObject();
        JsonObject stylesObject = new JsonObject();
        JsonArray draggablesArray = new JsonArray();

        saveFunctionSettings(functionsObject);
        saveStyleSettings(stylesObject);
        saveDraggables(draggablesArray);

        JsonObject newObject = new JsonObject();
        newObject.add("functions", functionsObject);
        newObject.add("styles", stylesObject);
        newObject.add("draggables", draggablesArray);

        return newObject;
    }

    private void saveFunctionSettings(JsonObject functionsObject) {
        instance.getFunctionRegistry().getFunctions().forEach(module -> {
            JsonObject moduleObject = new JsonObject();

            moduleObject.addProperty("bind", module.getBind());
            moduleObject.addProperty("state", module.isState());

            module.getSettings().forEach(setting -> saveIndividualSetting(moduleObject, setting));

            functionsObject.add(module.getName().toLowerCase(), moduleObject);
        });
    }

    private void saveIndividualSetting(JsonObject moduleObject, Setting<?> setting) {
        if (setting instanceof BooleanSetting) {
            moduleObject.addProperty(setting.getName(), ((BooleanSetting) setting).get());
        } else if (setting instanceof SliderSetting) {
            moduleObject.addProperty(setting.getName(), ((SliderSetting) setting).get());
        } else if (setting instanceof ModeSetting) {
            moduleObject.addProperty(setting.getName(), ((ModeSetting) setting).get());
        } else if (setting instanceof ColorSetting) {
            moduleObject.addProperty(setting.getName(), ((ColorSetting) setting).get());
        } else if (setting instanceof BindSetting) {
            moduleObject.addProperty(setting.getName(), ((BindSetting) setting).get());
        } else if (setting instanceof StringSetting) {
            moduleObject.addProperty(setting.getName(), ((StringSetting) setting).get());
        } else if (setting instanceof ModeListSetting) {
            saveModeListSetting(moduleObject, (ModeListSetting) setting);
        }
    }

    private void saveModeListSetting(JsonObject moduleObject, ModeListSetting setting) {
        JsonObject elements = new JsonObject();
        setting.get().forEach(option -> elements.addProperty(option.getName(), option.get()));
        moduleObject.add(setting.getName(), elements);
    }

    private void saveStyleSettings(JsonObject stylesObject) {
        for (Style style : instance.getStyleManager().getStyleList()) {
            JsonObject styleObject = new JsonObject();
            styleObject.addProperty("selected", instance.getStyleManager().getCurrentStyle() == style);
            stylesObject.add(style.getStyleName(), styleObject);
        }
    }

    private void saveDraggables(JsonArray draggablesArray) {
        for (Map.Entry<String, Dragging> entry : DragManager.draggables.entrySet()) {
            JsonObject draggableObject = new JsonObject();
            draggableObject.addProperty("name", entry.getKey());
            draggableObject.addProperty("x", entry.getValue().getX());
            draggableObject.addProperty("y", entry.getValue().getY());
            draggablesArray.add(draggableObject);
        }
    }
}
ConfigStorage.java:
package felon.gang.config;

import com.google.gson.GsonBuilder;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;

import net.minecraft.client.Minecraft;

import java.io.*;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;


public class ConfigStorage {
    public final Logger logger = Logger.getLogger(ConfigStorage.class.getName());

    public final File CONFIG_DIR = new File(Minecraft.getInstance().gameDir, "\\felon\\configs");
    public final File AUTOCFG_DIR = new File(CONFIG_DIR, "autocfg.cfg");

    public final JsonParser jsonParser = new JsonParser();

    public void init() throws IOException {
        setupFolder();
    }

    public void writeDefaultConfig() {
        String json = """
                {
                  "functions": {
                  },
                  "styles": {
                  },
                  "draggables": [
                  ]
                }
                """;

        try (FileWriter writer = new FileWriter(AUTOCFG_DIR)) {
            writer.write(json);
            writer.flush();
            logger.log(Level.INFO, "Created default system configuration!");
        } catch (IOException e) {
            logger.log(Level.INFO, "Failed to create default system configuration file", e);
        }
    }

    public void setupFolder() {
        if (!CONFIG_DIR.exists()) {
            CONFIG_DIR.mkdirs();
        } else if (AUTOCFG_DIR.exists()) {
            loadConfiguration("autocfg");
            logger.log(Level.INFO, "Load system configuration...");
        } else {
            logger.log(Level.INFO, "Creating system configuration...");
            try {
                AUTOCFG_DIR.createNewFile();
                writeDefaultConfig();
                logger.log(Level.INFO, "Created!");
            } catch (IOException e) {
                logger.log(Level.INFO, "Failed to create system configuration file", e);
            }
        }
    }

    public boolean isEmpty() {
        return getConfigs().isEmpty();
    }

    public List<Config> getConfigs() {
        List<Config> configs = new ArrayList<>();
        File[] configFiles = CONFIG_DIR.listFiles();

        if (configFiles != null) {
            for (File configFile : configFiles) {
                if (configFile.isFile() && configFile.getName().endsWith(".cfg")) {
                    String configName = configFile.getName().replace(".cfg", "");
                    Config config = findConfig(configName);
                    if (config != null) {
                        configs.add(config);
                    }
                }
            }
        }

        return configs;
    }


    public void loadConfiguration(String configuration) {
        Config config = findConfig(configuration);
        Config.currentConfig = configuration;
        try {
            FileReader reader = new FileReader(config.getFile());
            JsonParser parser = new JsonParser();
            JsonObject object = (JsonObject) parser.parse(reader);
            config.loadConfig(object);
        } catch (FileNotFoundException e) {
            logger.log(Level.WARNING, "Not Found Exception", e);
        } catch (NullPointerException pointerException) {
            logger.log(Level.INFO, "Fatal error in Config!", pointerException);
        }
    }

    public void saveConfiguration(String configuration) {
        Config config = new Config(configuration);
        String contentPrettyPrint = new GsonBuilder().setPrettyPrinting().create().toJson(config.saveConfig());
        try {
            FileWriter writer = new FileWriter(config.getFile());
            writer.write(contentPrettyPrint);
            writer.close();
        } catch (IOException e) {
            logger.log(Level.WARNING, "File not found!", e);
        } catch (NullPointerException e) {
            logger.log(Level.INFO, "Fatal Error in Config!", e);
        }
    }

    public static void saveConfiguration_static(String configuration) {
        Config config = new Config(configuration);
        String contentPrettyPrint = new GsonBuilder().setPrettyPrinting().create().toJson(config.saveConfig());
        try {
            FileWriter writer = new FileWriter(config.getFile());
            writer.write(contentPrettyPrint);
            writer.close();
        } catch (IOException e) {
            System.out.println("File not found! " + e);
        } catch (NullPointerException e) {
            System.out.println("Fatal Error in Config! " + e);
        }
    }

    public Config findConfig(String configName) {
        if (configName == null) return null;
        if (new File(CONFIG_DIR, configName + ".cfg").exists())
            return new Config(configName);
        return null;
    }
}
DragManager.java:
package felon.gang.utils.drag;

import java.util.LinkedHashMap;
import java.util.logging.Logger;



public class DragManager {

    public static final Logger logger = Logger.getLogger(DragManager.class.getName());
    public static LinkedHashMap<String, Dragging> draggables = new LinkedHashMap<>();

}
+rep
 
Забаненный
Статус
Оффлайн
Регистрация
2 Фев 2024
Сообщения
852
Реакции[?]
7
Поинты[?]
4K
Обратите внимание, пользователь заблокирован на форуме. Не рекомендуется проводить сделки.
Забаненный
Статус
Оффлайн
Регистрация
2 Фев 2024
Сообщения
852
Реакции[?]
7
Поинты[?]
4K
Обратите внимание, пользователь заблокирован на форуме. Не рекомендуется проводить сделки.
Сохраняет и загружает положение драггинга в\из кфг


Config.java:
package felon.gang.config;

import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import felon.gang.Felon;
import felon.gang.functions.settings.Setting;
import felon.gang.functions.settings.impl.*;
import felon.gang.ui.styles.Style;
import felon.gang.utils.client.IMinecraft;
import felon.gang.utils.drag.DragManager;
import felon.gang.utils.drag.Dragging;
import lombok.Getter;
import net.minecraft.client.Minecraft;

import java.io.File;
import java.util.Map;
import java.util.function.Consumer;

[USER=270918]@Getter[/USER]
public class Config implements IMinecraft {
    private final File file;
    private final String name;
    public static String currentConfig = "autocfg";

    Felon instance = Felon.getInstance();

    public Config(String name) {
        this.name = name;
        this.file = new File(new File(Minecraft.getInstance().gameDir, "\\felon\\configs"), name + ".cfg");
    }

    public void loadConfig(JsonObject jsonObject) {
        if (jsonObject == null) {
            return;
        }

        if (jsonObject.has("functions")) {
            loadFunctionSettings(jsonObject.getAsJsonObject("functions"));
        }

        if (jsonObject.has("styles")) {
            loadStyleSettings(jsonObject.getAsJsonObject("styles"));
        }

        if (jsonObject.has("draggables")) {
            loadDraggables(jsonObject.getAsJsonArray("draggables"));
        }
    }

    private void loadDraggables(JsonArray draggablesArray) {
        for (JsonElement element : draggablesArray) {
            JsonObject draggableObject = element.getAsJsonObject();
            String name = draggableObject.get("name").getAsString();
            Dragging dragging = DragManager.draggables.get(name);
            if (dragging != null) {
                dragging.setX(draggableObject.get("x").getAsInt());
                dragging.setY(draggableObject.get("y").getAsInt());
            }
        }
    }

    private void loadStyleSettings(JsonObject stylesObject) {
        for (Map.Entry<String, JsonElement> entry : stylesObject.entrySet()) {
            String styleName = entry.getKey();
            JsonObject styleObject = entry.getValue().getAsJsonObject();
            Style style = findStyleByName(styleName);
            if (style != null && styleObject.has("selected")) {
                boolean isSelected = styleObject.get("selected").getAsBoolean();
                if (isSelected) {
                    instance.getStyleManager().setCurrentStyle(style);
                }
            }
        }
    }

    private Style findStyleByName(String styleName) {
        for (Style style : instance.getStyleManager().getStyleList()) {
            if (style.getStyleName().equalsIgnoreCase(styleName)) {
                return style;
            }
        }
        return null;
    }

    private void loadFunctionSettings(JsonObject functionsObject) {
        instance.getFunctionRegistry().getFunctions().forEach(f -> {
            JsonObject moduleObject = functionsObject.getAsJsonObject(f.getName().toLowerCase());
            if (moduleObject == null) {
                return;
            }

            f.setState(false, true);
            loadSettingFromJson(moduleObject, "bind", value -> f.setBind(value.getAsInt()));
            loadSettingFromJson(moduleObject, "state", value -> f.setState(value.getAsBoolean(), true));
            f.getSettings().forEach(setting -> loadIndividualSetting(moduleObject, setting));
        });
    }

    private void loadIndividualSetting(JsonObject moduleObject, Setting<?> setting) {
        JsonElement settingElement = moduleObject.get(setting.getName());

        if (settingElement == null || settingElement.isJsonNull()) {
            return;
        }

        if (setting instanceof SliderSetting) {
            ((SliderSetting) setting).set(settingElement.getAsFloat());
        } else if (setting instanceof BooleanSetting) {
            ((BooleanSetting) setting).set(settingElement.getAsBoolean());
        } else if (setting instanceof ColorSetting) {
            ((ColorSetting) setting).set(settingElement.getAsInt());
        } else if (setting instanceof ModeSetting) {
            ((ModeSetting) setting).set(settingElement.getAsString());
        } else if (setting instanceof BindSetting) {
            ((BindSetting) setting).set(settingElement.getAsInt());
        } else if (setting instanceof StringSetting) {
            ((StringSetting) setting).set(settingElement.getAsString());
        } else if (setting instanceof ModeListSetting) {
            loadModeListSetting((ModeListSetting) setting, moduleObject);
        }
    }

    private void loadModeListSetting(ModeListSetting setting, JsonObject moduleObject) {
        JsonObject elements = moduleObject.getAsJsonObject(setting.getName());
        setting.get().forEach(option -> {
            JsonElement optionElement = elements.get(option.getName());
            if (optionElement != null && !optionElement.isJsonNull()) {
                option.set(optionElement.getAsBoolean());
            }
        });
    }

    private void loadSettingFromJson(JsonObject jsonObject, String key, Consumer<JsonElement> consumer) {
        JsonElement element = jsonObject.get(key);
        if (element != null && !element.isJsonNull()) {
            consumer.accept(element);
        }
    }

    public JsonElement saveConfig() {
        JsonObject functionsObject = new JsonObject();
        JsonObject stylesObject = new JsonObject();
        JsonArray draggablesArray = new JsonArray();

        saveFunctionSettings(functionsObject);
        saveStyleSettings(stylesObject);
        saveDraggables(draggablesArray);

        JsonObject newObject = new JsonObject();
        newObject.add("functions", functionsObject);
        newObject.add("styles", stylesObject);
        newObject.add("draggables", draggablesArray);

        return newObject;
    }

    private void saveFunctionSettings(JsonObject functionsObject) {
        instance.getFunctionRegistry().getFunctions().forEach(module -> {
            JsonObject moduleObject = new JsonObject();

            moduleObject.addProperty("bind", module.getBind());
            moduleObject.addProperty("state", module.isState());

            module.getSettings().forEach(setting -> saveIndividualSetting(moduleObject, setting));

            functionsObject.add(module.getName().toLowerCase(), moduleObject);
        });
    }

    private void saveIndividualSetting(JsonObject moduleObject, Setting<?> setting) {
        if (setting instanceof BooleanSetting) {
            moduleObject.addProperty(setting.getName(), ((BooleanSetting) setting).get());
        } else if (setting instanceof SliderSetting) {
            moduleObject.addProperty(setting.getName(), ((SliderSetting) setting).get());
        } else if (setting instanceof ModeSetting) {
            moduleObject.addProperty(setting.getName(), ((ModeSetting) setting).get());
        } else if (setting instanceof ColorSetting) {
            moduleObject.addProperty(setting.getName(), ((ColorSetting) setting).get());
        } else if (setting instanceof BindSetting) {
            moduleObject.addProperty(setting.getName(), ((BindSetting) setting).get());
        } else if (setting instanceof StringSetting) {
            moduleObject.addProperty(setting.getName(), ((StringSetting) setting).get());
        } else if (setting instanceof ModeListSetting) {
            saveModeListSetting(moduleObject, (ModeListSetting) setting);
        }
    }

    private void saveModeListSetting(JsonObject moduleObject, ModeListSetting setting) {
        JsonObject elements = new JsonObject();
        setting.get().forEach(option -> elements.addProperty(option.getName(), option.get()));
        moduleObject.add(setting.getName(), elements);
    }

    private void saveStyleSettings(JsonObject stylesObject) {
        for (Style style : instance.getStyleManager().getStyleList()) {
            JsonObject styleObject = new JsonObject();
            styleObject.addProperty("selected", instance.getStyleManager().getCurrentStyle() == style);
            stylesObject.add(style.getStyleName(), styleObject);
        }
    }

    private void saveDraggables(JsonArray draggablesArray) {
        for (Map.Entry<String, Dragging> entry : DragManager.draggables.entrySet()) {
            JsonObject draggableObject = new JsonObject();
            draggableObject.addProperty("name", entry.getKey());
            draggableObject.addProperty("x", entry.getValue().getX());
            draggableObject.addProperty("y", entry.getValue().getY());
            draggablesArray.add(draggableObject);
        }
    }
}
ConfigStorage.java:
package felon.gang.config;

import com.google.gson.GsonBuilder;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;

import net.minecraft.client.Minecraft;

import java.io.*;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;


public class ConfigStorage {
    public final Logger logger = Logger.getLogger(ConfigStorage.class.getName());

    public final File CONFIG_DIR = new File(Minecraft.getInstance().gameDir, "\\felon\\configs");
    public final File AUTOCFG_DIR = new File(CONFIG_DIR, "autocfg.cfg");

    public final JsonParser jsonParser = new JsonParser();

    public void init() throws IOException {
        setupFolder();
    }

    public void writeDefaultConfig() {
        String json = """
                {
                  "functions": {
                  },
                  "styles": {
                  },
                  "draggables": [
                  ]
                }
                """;

        try (FileWriter writer = new FileWriter(AUTOCFG_DIR)) {
            writer.write(json);
            writer.flush();
            logger.log(Level.INFO, "Created default system configuration!");
        } catch (IOException e) {
            logger.log(Level.INFO, "Failed to create default system configuration file", e);
        }
    }

    public void setupFolder() {
        if (!CONFIG_DIR.exists()) {
            CONFIG_DIR.mkdirs();
        } else if (AUTOCFG_DIR.exists()) {
            loadConfiguration("autocfg");
            logger.log(Level.INFO, "Load system configuration...");
        } else {
            logger.log(Level.INFO, "Creating system configuration...");
            try {
                AUTOCFG_DIR.createNewFile();
                writeDefaultConfig();
                logger.log(Level.INFO, "Created!");
            } catch (IOException e) {
                logger.log(Level.INFO, "Failed to create system configuration file", e);
            }
        }
    }

    public boolean isEmpty() {
        return getConfigs().isEmpty();
    }

    public List<Config> getConfigs() {
        List<Config> configs = new ArrayList<>();
        File[] configFiles = CONFIG_DIR.listFiles();

        if (configFiles != null) {
            for (File configFile : configFiles) {
                if (configFile.isFile() && configFile.getName().endsWith(".cfg")) {
                    String configName = configFile.getName().replace(".cfg", "");
                    Config config = findConfig(configName);
                    if (config != null) {
                        configs.add(config);
                    }
                }
            }
        }

        return configs;
    }


    public void loadConfiguration(String configuration) {
        Config config = findConfig(configuration);
        Config.currentConfig = configuration;
        try {
            FileReader reader = new FileReader(config.getFile());
            JsonParser parser = new JsonParser();
            JsonObject object = (JsonObject) parser.parse(reader);
            config.loadConfig(object);
        } catch (FileNotFoundException e) {
            logger.log(Level.WARNING, "Not Found Exception", e);
        } catch (NullPointerException pointerException) {
            logger.log(Level.INFO, "Fatal error in Config!", pointerException);
        }
    }

    public void saveConfiguration(String configuration) {
        Config config = new Config(configuration);
        String contentPrettyPrint = new GsonBuilder().setPrettyPrinting().create().toJson(config.saveConfig());
        try {
            FileWriter writer = new FileWriter(config.getFile());
            writer.write(contentPrettyPrint);
            writer.close();
        } catch (IOException e) {
            logger.log(Level.WARNING, "File not found!", e);
        } catch (NullPointerException e) {
            logger.log(Level.INFO, "Fatal Error in Config!", e);
        }
    }

    public static void saveConfiguration_static(String configuration) {
        Config config = new Config(configuration);
        String contentPrettyPrint = new GsonBuilder().setPrettyPrinting().create().toJson(config.saveConfig());
        try {
            FileWriter writer = new FileWriter(config.getFile());
            writer.write(contentPrettyPrint);
            writer.close();
        } catch (IOException e) {
            System.out.println("File not found! " + e);
        } catch (NullPointerException e) {
            System.out.println("Fatal Error in Config! " + e);
        }
    }

    public Config findConfig(String configName) {
        if (configName == null) return null;
        if (new File(CONFIG_DIR, configName + ".cfg").exists())
            return new Config(configName);
        return null;
    }
}
DragManager.java:
package felon.gang.utils.drag;

import java.util.LinkedHashMap;
import java.util.logging.Logger;



public class DragManager {

    public static final Logger logger = Logger.getLogger(DragManager.class.getName());
    public static LinkedHashMap<String, Dragging> draggables = new LinkedHashMap<>();

}
1716488423223.png
помоги
 
Забаненный
Статус
Оффлайн
Регистрация
2 Фев 2024
Сообщения
852
Реакции[?]
7
Поинты[?]
4K
Обратите внимание, пользователь заблокирован на форуме. Не рекомендуется проводить сделки.
Начинающий
Статус
Оффлайн
Регистрация
5 Апр 2023
Сообщения
389
Реакции[?]
1
Поинты[?]
2K
code:
 public void loadConfiguration(String configuration) {
        Config config = findConfig(configuration);
        try {
            FileReader reader = new FileReader(config.getFile());
            JsonParser parser = new JsonParser();
            JsonObject object = (JsonObject) parser.parse(reader);
            config.loadConfig(object);
        } catch (FileNotFoundException e) {
            logger.log(Level.WARNING, "Not Found Exception", e);
        } catch (NullPointerException pointerException) {
            logger.log(Level.WARNING, "Fatal error in Config!", pointerException);
        }
    }

    public void saveConfiguration(String configuration) {
        Config config = new Config(configuration);
        String contentPrettyPrint = new GsonBuilder().setPrettyPrinting().create().toJson(config.saveConfig());
        try {
            FileWriter writer = new FileWriter(config.getFile());
            writer.write(contentPrettyPrint);
            writer.close();
        } catch (IOException e) {
            logger.log(Level.WARNING, "File not found!", e);
        } catch (NullPointerException e) {
            logger.log(Level.WARNING, "Fatal Error in Config!", e);
        }
    }
мб поможет
 
Забаненный
Статус
Оффлайн
Регистрация
2 Фев 2024
Сообщения
852
Реакции[?]
7
Поинты[?]
4K
Обратите внимание, пользователь заблокирован на форуме. Не рекомендуется проводить сделки.
code:
 public void loadConfiguration(String configuration) {
        Config config = findConfig(configuration);
        try {
            FileReader reader = new FileReader(config.getFile());
            JsonParser parser = new JsonParser();
            JsonObject object = (JsonObject) parser.parse(reader);
            config.loadConfig(object);
        } catch (FileNotFoundException e) {
            logger.log(Level.WARNING, "Not Found Exception", e);
        } catch (NullPointerException pointerException) {
            logger.log(Level.WARNING, "Fatal error in Config!", pointerException);
        }
    }

    public void saveConfiguration(String configuration) {
        Config config = new Config(configuration);
        String contentPrettyPrint = new GsonBuilder().setPrettyPrinting().create().toJson(config.saveConfig());
        try {
            FileWriter writer = new FileWriter(config.getFile());
            writer.write(contentPrettyPrint);
            writer.close();
        } catch (IOException e) {
            logger.log(Level.WARNING, "File not found!", e);
        } catch (NullPointerException e) {
            logger.log(Level.WARNING, "Fatal Error in Config!", e);
        }
    }
мб поможет
и чо это
 
Сверху Снизу