[全民写端]#6添加Setting

简介: 写Setting类

首发于Enaium的个人博客


一. 写Setting类

package cn.enaium.coreium.setting;

import cn.enaium.coreium.module.Module;

import java.util.ArrayList;

public class Setting {
   

    private Module module;
    private String name;
    private boolean toggle;
    private double currentValueDouble, minValueDouble, maxValueDouble;
    private int currentValueInt, minValueInt, maxValueInt;
    private float currentValueFloat, minValueFloat, maxValueFloat;
    private ArrayList<String> modes;
    private String currentMode;
    private Category category;

    public enum Category {
   
        BOOLEAN,
        VALUE_INT,
        VALUE_DOUBLE,
        VALUE_FLOAT,
        MODE;
    }

    public Setting(Module module, String name, boolean toggle) {
   
        this.module = module;
        this.name = name;
        this.toggle = toggle;
        this.category = Category.BOOLEAN;
    }

    public Setting(Module module, String name, int currentValueInt, int minValueInt, int maxValueInt) {
   
        this.module = module;
        this.name = name;
        this.currentValueInt = currentValueInt;
        this.minValueInt = minValueInt;
        this.maxValueInt = maxValueInt;
        this.category = Category.VALUE_INT;
    }

    public Setting(Module module, String name, double currentValueDouble, double minValueDouble, double maxValueDouble) {
   
        this.module = module;
        this.name = name;
        this.currentValueDouble = currentValueDouble;
        this.minValueDouble = minValueDouble;
        this.maxValueDouble = maxValueDouble;
        this.category = Category.VALUE_DOUBLE;
    }

    public Setting(Module module, String name, float currentValueFloat, float minValueFloat, float maxValueFloat) {
   
        this.module = module;
        this.name = name;
        this.currentValueFloat = currentValueFloat;
        this.minValueFloat = minValueFloat;
        this.maxValueFloat = maxValueFloat;
        this.category = Category.VALUE_FLOAT;
    }

    public Setting(Module m, String n, String currentMode, ArrayList<String> options) {
   
        this.module = m;
        this.name = n;
        this.currentMode = currentMode;
        this.modes = options;
        this.category = Category.MODE;
    }

    public Module getModule() {
   
        return module;
    }

    public void setModule(Module module) {
   
        this.module = module;
    }

    public String getName() {
   
        return name;
    }

    public void setName(String name) {
   
        this.name = name;
    }

    public boolean isToggle() {
   
        return toggle;
    }

    public void setToggle(boolean toggle) {
   
        this.toggle = toggle;
    }

    public double getCurrentValueDouble() {
   
        return currentValueDouble;
    }

    public void setCurrentValueDouble(double currentValueDouble) {
   
        this.currentValueDouble = currentValueDouble;
    }

    public double getMinValueDouble() {
   
        return minValueDouble;
    }

    public void setMinValueDouble(double minValueDouble) {
   
        this.minValueDouble = minValueDouble;
    }

    public double getMaxValueDouble() {
   
        return maxValueDouble;
    }

    public void setMaxValueDouble(double maxValueDouble) {
   
        this.maxValueDouble = maxValueDouble;
    }

    public int getCurrentValueInt() {
   
        return currentValueInt;
    }

    public void setCurrentValueInt(int currentValueInt) {
   
        this.currentValueInt = currentValueInt;
    }

    public int getMinValueInt() {
   
        return minValueInt;
    }

    public void setMinValueInt(int minValueInt) {
   
        this.minValueInt = minValueInt;
    }

    public int getMaxValueInt() {
   
        return maxValueInt;
    }

    public void setMaxValueInt(int maxValueInt) {
   
        this.maxValueInt = maxValueInt;
    }

    public float getCurrentValueFloat() {
   
        return currentValueFloat;
    }

    public void setCurrentValueFloat(float currentValueFloat) {
   
        this.currentValueFloat = currentValueFloat;
    }

    public float getMinValueFloat() {
   
        return minValueFloat;
    }

    public void setMinValueFloat(float minValueFloat) {
   
        this.minValueFloat = minValueFloat;
    }

    public float getMaxValueFloat() {
   
        return maxValueFloat;
    }

    public void setMaxValueFloat(float maxValueFloat) {
   
        this.maxValueFloat = maxValueFloat;
    }

    public ArrayList<String> getModes() {
   
        return modes;
    }

    public void setModes(ArrayList<String> modes) {
   
        this.modes = modes;
    }

    public String getCurrentMode() {
   
        return currentMode;
    }

    public void setCurrentMode(String currentMode) {
   
        this.currentMode = currentMode;
    }

    public boolean isBoolean() {
   
        return this.category.equals(Category.BOOLEAN);
    }

    public boolean isValueInt() {
   
        return this.category.equals(Category.VALUE_INT);
    }

    public boolean isValueDouble() {
   
        return this.category.equals(Category.VALUE_DOUBLE);
    }

    public boolean isValueFloat() {
   
        return this.category.equals(Category.VALUE_FLOAT);
    }

    public boolean isMode() {
   
        return this.category.equals(Category.MODE);
    }
}

二. 写SettingManager

package cn.enaium.coreium.setting;

import cn.enaium.coreium.module.Module;

import java.util.ArrayList;

public class SettingManager {
   
    private ArrayList<Setting> settings;

    public SettingManager() {
   
        this.settings = new ArrayList();
    }

    public void addSetting(Setting s) {
   
        this.settings.add(s);
    }

    public ArrayList<Setting> getSettings() {
   
        return this.settings;
    }

    public ArrayList<Setting> getSettingsForModule(Module m) {
   
        ArrayList<Setting> settings = new ArrayList<Setting>();

        for (Setting s : this.settings) {
   
            if (s.getModule().equals(m))
                settings.add(s);
        }

        if (settings.isEmpty())
            return null;

        return settings;
    }
}

三. 添加在Start

    [...]
    public SettingManager settingManager;

    public void start() {
   
        [...]
        settingManager = new SettingManager();
        [...]
    }
目录
相关文章
|
8月前
|
人工智能 自然语言处理
离颠覆好莱坞又近了一步!Pika推出Lip Sync(口型同步)
【2月更文挑战第13天】离颠覆好莱坞又近了一步!Pika推出Lip Sync(口型同步)
216 1
离颠覆好莱坞又近了一步!Pika推出Lip Sync(口型同步)
|
3月前
|
Java
在Java多线程编程中,`wait()`和`notify()`方法的相遇如同一场奇妙的邂逅
在Java多线程编程中,`wait()`和`notify()`方法的相遇如同一场奇妙的邂逅。它们用于线程间通信,使线程能够协作完成任务。通过这些方法,生产者和消费者线程可以高效地管理共享资源,确保程序的有序运行。正确使用这些方法需要遵循同步规则,避免虚假唤醒等问题。示例代码展示了如何在生产者-消费者模型中使用`wait()`和`notify()`。
39 1
|
7月前
|
Java
当JAVA多线程遇上wait()和notify():一场奇妙的邂逅
【6月更文挑战第20天】JAVA多线程中,wait()和notify()是线程通信的关键。wait()让线程释放锁进入等待,直到被notify()或notifyAll()唤醒。它们用于协调如生产者-消费者问题中的线程协作,确保在同步块内调用,并伴随条件检查以防止虚假唤醒。示例代码展示了一个简单的共享队列,其中生产和消费使用wait/notify实现同步。
45 0
[全民写端]#2设置启动和停止
在你想要的地方新建一个类
74 0
[全民写端]#2设置启动和停止
|
Java
[全民写端]#4添加Event和Module
在EntityPlayerSP类里面找到onUpdate方法 在第一行写 new EventUpdate().call();
85 0
[全民写端]#7添加Command
在ModuleManager中添加getModule方法
81 0
[全民写端]#7添加Command
|
C++
[全民写端]#3添加OptiFine
删除src\minecraft所有内容 将Optifine解压进去(保留你写的包)
101 0
[全民写端]#3添加OptiFine
|
算法
PAT甲级 1003. Emergency(25分)
PAT甲级 1003. Emergency(25分)
97 0
PAT甲级 1003. Emergency(25分)