diff --git a/src/main/java/io/github/gaming32/worldhost/config/ConfigProperty.java b/src/main/java/io/github/gaming32/worldhost/config/ConfigProperty.java index 45a8816..e3cb24a 100644 --- a/src/main/java/io/github/gaming32/worldhost/config/ConfigProperty.java +++ b/src/main/java/io/github/gaming32/worldhost/config/ConfigProperty.java @@ -8,6 +8,8 @@ @Retention(RetentionPolicy.RUNTIME) @Target(ElementType.METHOD) public @interface ConfigProperty { + int order(); + @Retention(RetentionPolicy.RUNTIME) @Target(ElementType.METHOD) @interface EnumFallback { diff --git a/src/main/java/io/github/gaming32/worldhost/config/WorldHostConfig.java b/src/main/java/io/github/gaming32/worldhost/config/WorldHostConfig.java index a2754ce..93d0323 100644 --- a/src/main/java/io/github/gaming32/worldhost/config/WorldHostConfig.java +++ b/src/main/java/io/github/gaming32/worldhost/config/WorldHostConfig.java @@ -121,7 +121,7 @@ public void setServerIp(String serverIp) { this.serverIp = serverIp; } - @ConfigProperty + @ConfigProperty(order = 1) @ConfigProperty.EnumFallback("right") public OnlineStatusLocation getOnlineStatusLocation() { return onlineStatusLocation; @@ -131,7 +131,7 @@ public void setOnlineStatusLocation(OnlineStatusLocation onlineStatusLocation) { this.onlineStatusLocation = onlineStatusLocation; } - @ConfigProperty + @ConfigProperty(order = 2) public boolean isEnableFriends() { return enableFriends; } @@ -140,7 +140,7 @@ public void setEnableFriends(boolean enableFriends) { this.enableFriends = enableFriends; } - @ConfigProperty + @ConfigProperty(order = 3) public boolean isEnableReconnectionToasts() { return enableReconnectionToasts; } @@ -149,7 +149,7 @@ public void setEnableReconnectionToasts(boolean enableReconnectionToasts) { this.enableReconnectionToasts = enableReconnectionToasts; } - @ConfigProperty + @ConfigProperty(order = 4) public boolean isNoUPnP() { return noUPnP; } @@ -158,7 +158,7 @@ public void setNoUPnP(boolean noUPnP) { this.noUPnP = noUPnP; } - @ConfigProperty + @ConfigProperty(order = 5) public boolean isUseShortIp() { return useShortIp; } @@ -167,7 +167,7 @@ public void setUseShortIp(boolean useShortIp) { this.useShortIp = useShortIp; } - @ConfigProperty + @ConfigProperty(order = 6) public boolean isShowOutdatedWorldHost() { return showOutdatedWorldHost; } @@ -176,7 +176,7 @@ public void setShowOutdatedWorldHost(boolean showOutdatedWorldHost) { this.showOutdatedWorldHost = showOutdatedWorldHost; } - @ConfigProperty + @ConfigProperty(order = 7) public boolean isShareButton() { return shareButton; } @@ -185,7 +185,7 @@ public void setShareButton(boolean shareButton) { this.shareButton = shareButton; } - @ConfigProperty + @ConfigProperty(order = 8) public boolean isAllowFriendRequests() { return allowFriendRequests; } @@ -194,7 +194,7 @@ public void setAllowFriendRequests(boolean allowFriendRequests) { this.allowFriendRequests = allowFriendRequests; } - @ConfigProperty + @ConfigProperty(order = 9) public boolean isAnnounceFriendsOnline() { return announceFriendsOnline; } diff --git a/src/main/java/io/github/gaming32/worldhost/config/option/ConfigOption.java b/src/main/java/io/github/gaming32/worldhost/config/option/ConfigOption.java index a9fe57f..f5bc866 100644 --- a/src/main/java/io/github/gaming32/worldhost/config/option/ConfigOption.java +++ b/src/main/java/io/github/gaming32/worldhost/config/option/ConfigOption.java @@ -1,6 +1,7 @@ package io.github.gaming32.worldhost.config.option; import io.github.gaming32.worldhost.WorldHost; +import io.github.gaming32.worldhost.config.ConfigProperty; import io.github.gaming32.worldhost.config.WorldHostConfig; import net.minecraft.client.gui.components.Button; import org.quiltmc.parsers.json.JsonReader; @@ -11,16 +12,24 @@ public abstract sealed class ConfigOption permits EnumOption, YesNoOption { protected final PropertyDescriptor property; + private final int order; private Runnable onSet = null; protected ConfigOption(PropertyDescriptor property) { this.property = property; + + final ConfigProperty info = property.getReadMethod().getAnnotation(ConfigProperty.class); + order = info.order(); } public String getName() { return property.getName(); } + public int getOrder() { + return order; + } + public void onSet(Runnable onSet) { if (this.onSet == null) { this.onSet = onSet; diff --git a/src/main/java/io/github/gaming32/worldhost/config/option/ConfigOptions.java b/src/main/java/io/github/gaming32/worldhost/config/option/ConfigOptions.java index a7f7222..edb2adf 100644 --- a/src/main/java/io/github/gaming32/worldhost/config/option/ConfigOptions.java +++ b/src/main/java/io/github/gaming32/worldhost/config/option/ConfigOptions.java @@ -10,6 +10,7 @@ import java.beans.Introspector; import java.beans.PropertyDescriptor; import java.util.Arrays; +import java.util.Comparator; import java.util.Map; import java.util.Objects; import java.util.function.Function; @@ -29,6 +30,7 @@ private ConfigOptions() { return Arrays.stream(Introspector.getBeanInfo(WorldHostConfig.class).getPropertyDescriptors()) .map(ConfigOptions::createConfigOption) .filter(Objects::nonNull) + .sorted(Comparator.comparingInt(ConfigOption::getOrder)) .collect(ImmutableMap.toImmutableMap(ConfigOption::getName, Function.identity())); } catch (IntrospectionException e) { throw new IllegalStateException(e);