forked from RepoMirrors/kami-blue
Save binds correctly
I should really rewrite the settings system.
This commit is contained in:
parent
136e0155a4
commit
3e7d3cd414
|
@ -1,8 +1,12 @@
|
|||
package me.zeroeightsix.kami.module;
|
||||
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.JsonPrimitive;
|
||||
import me.zeroeightsix.kami.KamiMod;
|
||||
import me.zeroeightsix.kami.event.events.RenderEvent;
|
||||
import me.zeroeightsix.kami.module.modules.movement.Sprint;
|
||||
import me.zeroeightsix.kami.setting.FieldConverter;
|
||||
import me.zeroeightsix.kami.setting.Setting;
|
||||
import me.zeroeightsix.kami.setting.SettingsClass;
|
||||
import me.zeroeightsix.kami.util.Bind;
|
||||
|
@ -19,7 +23,7 @@ public class Module extends SettingsClass {
|
|||
private final String name = getAnnotation().name();
|
||||
private final String description = getAnnotation().description();
|
||||
private final Category category = getAnnotation().category();
|
||||
@Setting(name = "Bind", hidden = true)
|
||||
@Setting(name = "Bind", hidden = true, converter = BindsConverter.class)
|
||||
private Bind bind = Bind.none();
|
||||
@Setting(name = "Enabled", hidden = true)
|
||||
private boolean enabled;
|
||||
|
@ -152,4 +156,33 @@ public class Module extends SettingsClass {
|
|||
*/
|
||||
public void destroy(){};
|
||||
|
||||
public static class BindsConverter implements FieldConverter {
|
||||
|
||||
public BindsConverter() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public JsonElement toJson(StaticSetting setting) {
|
||||
Bind bind = (Bind) setting.getValue();
|
||||
if (bind.isEmpty()) return null;
|
||||
JsonObject object = new JsonObject();
|
||||
object.add("shift", new JsonPrimitive(bind.isShift()));
|
||||
object.add("alt", new JsonPrimitive(bind.isAlt()));
|
||||
object.add("ctrl", new JsonPrimitive(bind.isCtrl()));
|
||||
object.add("key", new JsonPrimitive(bind.getKey()));
|
||||
return object;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object fromJson(StaticSetting setting, JsonElement value) {
|
||||
if (value == null || value.isJsonNull()) return Bind.none();
|
||||
JsonObject object = value.getAsJsonObject();
|
||||
boolean shift = object.get("shift").getAsBoolean();
|
||||
boolean alt = object.get("alt").getAsBoolean();
|
||||
boolean ctrl = object.get("ctrl").getAsBoolean();
|
||||
int key = object.get("key").getAsInt();
|
||||
return new Bind(ctrl, alt, shift, key);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
package me.zeroeightsix.kami.setting;
|
||||
|
||||
import me.zeroeightsix.kami.util.Bind;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.util.ArrayList;
|
||||
|
@ -150,7 +152,7 @@ public class SettingsClass {
|
|||
}
|
||||
}
|
||||
|
||||
if (value.getClass() == ArrayList.class) {
|
||||
if (value.getClass() == ArrayList.class || value.getClass() == Bind.class) {
|
||||
try {
|
||||
field.set(holder, value);
|
||||
return;
|
||||
|
|
Loading…
Reference in New Issue