split client and server 5

This commit is contained in:
Sen 2025-05-06 13:32:30 +02:00
parent d37bb7f6cc
commit a6b0f110b1
382 changed files with 23 additions and 23 deletions

View file

@ -14,7 +14,7 @@ import java.util.TreeMap;
import game.packet.SPacketWorld;
import game.util.ExtMath;
import game.world.WorldServer;
import server.Server;
import game.IServer;
public abstract class Config {
public static enum ValueType {
@ -22,7 +22,7 @@ public abstract class Config {
}
private static interface Callback {
void run(Server server);
void run(IServer server);
}
@Target(FIELD)
@ -504,7 +504,7 @@ public abstract class Config {
}
}
public static void set(String key, String value, Server server) {
public static void set(String key, String value, IServer server) {
Config.Value vl = VARS.get(key);
if(vl != null) {
vl.setValue(value);
@ -514,7 +514,7 @@ public abstract class Config {
}
public static class WorldCallback implements Callback {
public void run(Server server) {
public void run(IServer server) {
for(WorldServer world : server.getWorlds()) {
world.updatePhysics();
}
@ -522,7 +522,7 @@ public abstract class Config {
}
}
public static class DistanceCallback implements Callback {
public void run(Server server) {
public void run(IServer server) {
for(WorldServer world : server.getWorlds()) {
world.updateViewRadius();
}

View file

@ -1,38 +0,0 @@
package game.vars;
import java.lang.reflect.Field;
public abstract class BaseVar implements CVar {
public static interface VarFunction {
}
protected final String name;
protected final String display;
protected final Field field;
protected final Object object;
protected final CVarCategory category;
public BaseVar(String name, String display, Field field, Object object, CVarCategory category) {
this.name = name;
this.display = display;
this.field = field;
this.object = object;
this.category = category;
}
public final String getCVarName() {
return this.name;
}
public final String getDisplay() {
return this.display;
}
public final CVarCategory getCategory() {
return this.category;
}
public void setDefault() {
this.parse(this.getDefault());
}
}

View file

@ -1,72 +0,0 @@
package game.vars;
import java.lang.reflect.Field;
import client.gui.element.Toggle;
import game.color.TextColor;
import game.util.Util;
public class BoolVar extends BaseVar {
public static interface BoolFunction extends VarFunction {
void apply(BoolVar cv, boolean value);
}
private final BoolFunction func;
private final boolean def;
public BoolVar(String name, String display, Field field, Object object, CVarCategory category, BoolFunction func) {
super(name, display, field, object, category);
this.func = func;
try {
this.def = field.getBoolean(object);
}
catch(IllegalArgumentException | IllegalAccessException e) {
throw new RuntimeException(e);
}
}
public String getType() {
return TextColor.MAGENTA + "bool";
}
public boolean parse(String str) {
Boolean value = Util.parseBoolean(str);
if(value == null)
return false;
try {
this.field.setBoolean(this.object, value);
}
catch(IllegalArgumentException | IllegalAccessException e) {
throw new RuntimeException(e);
}
if(this.func != null)
this.func.apply(this, value);
return true;
}
public String format() {
try {
return "" + this.field.getBoolean(this.object);
}
catch(IllegalArgumentException | IllegalAccessException e) {
throw new RuntimeException(e);
}
}
public String getDefault() {
return "" + this.def;
}
public Toggle selector(int x, int y, int w, int h) {
try {
return new Toggle(x, y, w, h, this.def, this.field.getBoolean(this.object), new Toggle.Callback() {
public void use(Toggle elem, boolean value) {
BoolVar.this.parse("" + value);
}
}, this.display);
}
catch(IllegalArgumentException | IllegalAccessException e) {
throw new RuntimeException(e);
}
}
}

View file

@ -1,18 +0,0 @@
package game.vars;
import client.gui.element.Element;
import game.util.Displayable;
public interface CVar extends Displayable {
String getType();
CVarCategory getCategory();
String getCVarName();
boolean parse(String str);
String format();
String getDefault();
void setDefault();
default String getValues() {
return null;
}
Element selector(int x, int y, int w, int h);
}

View file

@ -1,23 +0,0 @@
package game.vars;
import game.color.TextColor;
public enum CVarCategory {
SYSTEM(TextColor.RED + "system"),
WINDOW(TextColor.BLUE + "window"),
GUI(TextColor.GREEN + "gui"),
RENDER(TextColor.NEON + "render"),
INPUT(TextColor.ORANGE + "input"),
CONSOLE(TextColor.YELLOW + "console"),
SOUND(TextColor.CRIMSON + "sound");
private final String name;
private CVarCategory(String name) {
this.name = name;
}
public String toString() {
return this.name;
}
}

View file

@ -1,61 +0,0 @@
package game.vars;
import java.lang.reflect.Field;
import client.gui.Style;
import client.gui.element.Label;
import client.gui.element.Slider;
import client.gui.element.Textbox;
import client.gui.element.Textbox.Action;
import game.color.TextColor;
import game.util.Util;
public class ColorVar extends IntVar {
private final boolean alpha;
public ColorVar(String name, String display, Field field, Object object, CVarCategory category, boolean alpha, IntFunction func) {
super(name, display, field, object, category, Integer.MIN_VALUE, Integer.MAX_VALUE, func, null, 0);
this.alpha = alpha;
}
public String getType() {
return this.alpha ? (TextColor.GRAY + "color32") : (TextColor.LGRAY + "color");
}
protected Integer parseValue(String str) {
if(str.length() != (this.alpha ? 8 : 6))
return null;
Integer value = Util.parseInt(str, -16);
return this.alpha || (value & 0xff000000) == 0 ? (this.alpha ? value : (0xff000000 | value)) : null;
}
protected String formatValue(int value) {
return String.format(this.alpha ? "%08x" : "%06x", this.alpha ? value : (value & 0x00ffffff));
}
public Slider selector(int x, int y, int w, int h) {
throw new UnsupportedOperationException("Kann keinen Schieberegler für Farben erstellen");
}
public Label label(int x, int y, int w, int h) {
return new Label(x, y, w, h, this.display);
}
public Textbox editor(int x, int y, int w, int h) {
return new Textbox(x, y, w, h, this.alpha ? 8 : 6, true, new Textbox.Callback() {
public void use(Textbox elem, Textbox.Action value) {
if(value == Action.SEND || value == Action.UNFOCUS)
ColorVar.this.parse(elem.getText());
}
}, this.format());
}
public String getFieldValue(Style style) {
try {
return this.formatValue(this.field.getInt(style));
}
catch(IllegalArgumentException | IllegalAccessException e) {
throw new RuntimeException(e);
}
}
}

View file

@ -1,105 +0,0 @@
package game.vars;
import java.lang.reflect.Field;
import client.gui.element.Dropdown;
import client.gui.element.Element;
import client.gui.element.Switch;
import game.color.TextColor;
import game.util.Identifyable;
import game.util.Util;
public class EnumVar<T extends Enum> extends BaseVar {
public static interface EnumFunction<T extends Enum> extends VarFunction {
void apply(EnumVar cv, T value);
}
private final EnumFunction func;
private final String values;
private final T def;
private final boolean useSwitch;
public EnumVar(String name, String display, Field field, Object object, CVarCategory category, EnumFunction<T> func, boolean useSwitch) {
super(name, display, field, object, category);
this.func = func;
this.useSwitch = useSwitch;
StringBuilder sb = new StringBuilder();
for(T value : (T[])field.getType().getEnumConstants()) {
if(sb.length() > 0)
sb.append(',');
sb.append(value instanceof Identifyable ? ((Identifyable)value).getName() : value.toString());
}
this.values = sb.toString();
try {
this.def = (T)field.get(object);
}
catch(IllegalArgumentException | IllegalAccessException e) {
throw new RuntimeException(e);
}
}
public String getType() {
return TextColor.CYAN + "enum";
}
public boolean parse(String str) {
T value = (T)Util.parseEnum((Class<T>)this.field.getType(), str);
if(value == null)
return false;
try {
this.field.set(this.object, value);
}
catch(IllegalArgumentException | IllegalAccessException e) {
throw new RuntimeException(e);
}
if(this.func != null)
this.func.apply(this, value);
return true;
}
public String format() {
try {
T value = (T)this.field.get(this.object);
return value instanceof Identifyable ? ((Identifyable)value).getName() : value.toString();
}
catch(IllegalArgumentException | IllegalAccessException e) {
throw new RuntimeException(e);
}
}
public String getDefault() {
return this.def instanceof Identifyable ? ((Identifyable)this.def).getName() : this.def.toString();
}
public String getValues() {
return this.values;
}
public Element selector(int x, int y, int w, int h) {
if(this.useSwitch)
return this.switcher(x, y, w, h);
try {
return new Dropdown<T>(x, y, w, h, false, (T[])this.field.getType().getEnumConstants(), this.def, (T)this.field.get(this.object), new Dropdown.Callback<T>() {
public void use(Dropdown<T> elem, T value) {
EnumVar.this.parse(value instanceof Identifyable ? ((Identifyable)value).getName() : value.toString());
}
}, this.display);
}
catch(IllegalArgumentException | IllegalAccessException e) {
throw new RuntimeException(e);
}
}
public Switch switcher(int x, int y, int w, int h) {
try {
return new Switch<T>(x, y, w, h, (T[])this.field.getType().getEnumConstants(), this.def, (T)this.field.get(this.object), new Switch.Callback<T>() {
public void use(Switch<T> elem, T value) {
EnumVar.this.parse(value instanceof Identifyable ? ((Identifyable)value).getName() : value.toString());
}
}, this.display);
}
catch(IllegalArgumentException | IllegalAccessException e) {
throw new RuntimeException(e);
}
}
}

View file

@ -1,103 +0,0 @@
package game.vars;
import java.lang.reflect.Field;
import client.gui.element.Slider;
import game.color.TextColor;
import game.util.ExtMath;
public class FloatVar extends BaseVar {
public static interface FloatFunction extends VarFunction {
void apply(FloatVar cv, float value);
}
private final String unit;
private final String format;
private final int precision;
private final float divider;
private final FloatFunction func;
private final float min;
private final float max;
private final float def;
public static float getDivider(int precision) {
int div = 1;
for(int z = 0; z < precision; z++) {
div *= 10;
}
return (float)div;
}
public FloatVar(String name, String display, Field field, Object object, CVarCategory category, float min, float max, FloatFunction func, String unit, int precision) {
super(name, display, field, object, category);
this.func = func;
this.min = min;
this.max = max;
this.unit = unit;
this.precision = precision;
this.format = "%." + precision + "f";
this.divider = getDivider(precision);
try {
this.def = field.getFloat(object);
}
catch(IllegalArgumentException | IllegalAccessException e) {
throw new RuntimeException(e);
}
}
public String getType() {
return TextColor.YELLOW + "float";
}
public boolean parse(String str) {
float value;
try {
value = Float.parseFloat(str);
}
catch(NumberFormatException e) {
return false;
}
value = ExtMath.clampf(value, this.min, this.max);
int round = (int)(value * this.divider);
value = (float)round / this.divider;
try {
this.field.setFloat(this.object, value);
}
catch(IllegalArgumentException | IllegalAccessException e) {
throw new RuntimeException(e);
}
if(this.func != null)
this.func.apply(this, value);
return true;
}
public String format() {
try {
return String.format(this.format, this.field.getFloat(this.object));
}
catch(IllegalArgumentException | IllegalAccessException e) {
throw new RuntimeException(e);
}
}
public String getDefault() {
return String.format(this.format, this.def);
}
public String getValues() {
return String.format(this.format + ".." + this.format, this.min, this.max);
}
public Slider selector(int x, int y, int w, int h) {
try {
return new Slider(x, y, w, h, this.unit.equals("%") ? -1 : this.precision, this.min, this.max, this.def, this.field.getFloat(this.object), new Slider.FloatCallback() {
public void use(Slider elem, float value) {
FloatVar.this.parse(String.format(FloatVar.this.format, value));
}
}, this.display, this.unit);
}
catch(IllegalArgumentException | IllegalAccessException e) {
throw new RuntimeException(e);
}
}
}

View file

@ -1,95 +0,0 @@
package game.vars;
import java.lang.reflect.Field;
import client.gui.element.Slider;
import game.color.TextColor;
import game.util.ExtMath;
import game.util.Util;
public class IntVar extends BaseVar {
public static interface IntFunction extends VarFunction {
void apply(IntVar cv, int value);
}
private final String unit;
private final int precision;
private final IntFunction func;
private final int min;
private final int max;
private final int def;
public IntVar(String name, String display, Field field, Object object, CVarCategory category, int min, int max, IntFunction func, String unit, int precision) {
super(name, display, field, object, category);
this.func = func;
this.min = min;
this.max = max;
this.unit = unit;
this.precision = precision;
try {
this.def = field.getInt(object);
}
catch(IllegalArgumentException | IllegalAccessException e) {
throw new RuntimeException(e);
}
}
public String getType() {
return TextColor.GREEN + "int";
}
protected Integer parseValue(String str) {
return Util.parseInt(str, 0);
}
protected String formatValue(int value) {
return "" + value;
}
public boolean parse(String str) {
Integer value = this.parseValue(str);
if(value == null)
return false;
value = ExtMath.clampi(value, this.min, this.max);
try {
this.field.setInt(this.object, value);
}
catch(IllegalArgumentException | IllegalAccessException e) {
throw new RuntimeException(e);
}
if(this.func != null)
this.func.apply(this, value);
return true;
}
public String format() {
try {
return this.formatValue(this.field.getInt(this.object));
}
catch(IllegalArgumentException | IllegalAccessException e) {
throw new RuntimeException(e);
}
}
public String getDefault() {
return this.formatValue(this.def);
}
public String getValues() {
return this.min == Integer.MIN_VALUE && this.max == Integer.MAX_VALUE ? null : ((this.min == Integer.MIN_VALUE ? "" : ("" + this.min)) +
".." + (this.max == Integer.MAX_VALUE ? "" : ("" + this.max)));
}
public Slider selector(int x, int y, int w, int h) {
try {
return new Slider(x, y, w, h, this.precision, this.min, this.max, this.def, this.field.getInt(this.object), new Slider.Callback() {
public void use(Slider elem, int value) {
IntVar.this.parse(IntVar.this.formatValue(value));
}
}, this.display, this.unit);
}
catch(IllegalArgumentException | IllegalAccessException e) {
throw new RuntimeException(e);
}
}
}

View file

@ -1,82 +0,0 @@
package game.vars;
import java.lang.reflect.Field;
import client.gui.element.Textbox;
import client.gui.element.Textbox.Action;
import game.color.TextColor;
import game.util.CharValidator;
public class StringVar extends BaseVar {
public static interface StringFunction extends VarFunction {
void apply(StringVar cv, String value);
}
private final StringFunction func;
private final CharValidator validator;
private final String def;
private final int maxLength;
private final boolean allowEmpty;
public StringVar(String name, String display, Field field, Object object, CVarCategory category, int maxLength, StringFunction func, CharValidator validator, boolean allowEmpty) {
super(name, display, field, object, category);
this.func = func;
this.maxLength = maxLength;
this.validator = validator;
this.allowEmpty = allowEmpty;
try {
this.def = (String)field.get(object);
}
catch(IllegalArgumentException | IllegalAccessException e) {
throw new RuntimeException(e);
}
}
public String getType() {
return TextColor.YELLOW + "float";
}
public boolean parse(String str) {
if(this.validator != null)
str = this.validator.filter(str);
if(!this.allowEmpty && str.isEmpty())
return false;
if(str.length() > this.maxLength)
str = str.substring(0, this.maxLength);
try {
this.field.set(this.object, str);
}
catch(IllegalArgumentException | IllegalAccessException e) {
throw new RuntimeException(e);
}
if(this.func != null)
this.func.apply(this, str);
return true;
}
public String format() {
try {
return (String)this.field.get(this.object);
}
catch(IllegalArgumentException | IllegalAccessException e) {
throw new RuntimeException(e);
}
}
public String getDefault() {
return this.def;
}
public Textbox selector(int x, int y, int w, int h) {
return new Textbox(x, y, w, h, this.maxLength, true, new Textbox.Callback() {
public void use(Textbox elem, Textbox.Action value) {
if(value == Action.SEND || value == Action.UNFOCUS) {
if(!StringVar.this.allowEmpty && elem.getText().isEmpty())
elem.setText(StringVar.this.format());
else
StringVar.this.parse(elem.getText());
}
}
}, this.validator, this.format());
}
}

View file

@ -1,30 +0,0 @@
package game.vars;
import static java.lang.annotation.ElementType.FIELD;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import game.util.CharValidator;
import game.vars.BaseVar.VarFunction;
@Target(FIELD)
@Retention(value = RetentionPolicy.RUNTIME)
public @interface Variable {
public static enum IntType {
INT, COLOR, ALPHA;
}
String name();
String display();
CVarCategory category();
float min() default (float)Integer.MIN_VALUE;
float max() default (float)Integer.MAX_VALUE;
IntType type() default IntType.INT;
int precision() default 0;
String unit() default "";
boolean switched() default false;
Class<? extends VarFunction> callback() default VarFunction.class;
Class<? extends CharValidator> validator() default CharValidator.class;
}

File diff suppressed because it is too large Load diff

View file

@ -30,9 +30,25 @@ import game.nbt.NBTLoader;
import game.nbt.NBTTagCompound;
import game.nbt.NBTTagList;
import game.tileentity.TileEntity;
import game.world.Converter.SaveVersion;
public class Region {
public static enum SaveVersion {
ALPHA_1_0("Alpha 1.0 - Beta 1.2"),
BETA_1_3("Beta 1.3 - Release 1.8.9"),
RELEASE_1_9("Release 1.9 - Release 1.12.2"),
RELEASE_1_13("Release 1.13 +");
private final String name;
private SaveVersion(String name) {
this.name = name;
}
public String toString() {
return this.name;
}
}
public static class FolderInfo {
public final long time;
public final long lastPlayed;