Skip to content

Commit 052a486

Browse files
committed
refactor server part a bit
1 parent 8f54479 commit 052a486

File tree

10 files changed

+121
-107
lines changed

10 files changed

+121
-107
lines changed

1.20/build.gradle.kts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,13 @@ modrinth {
119119
token = System.getenv("MODRINTH_TOKEN")
120120
projectId = "s0qWsRJC"
121121
versionNumber = "${project.version}"
122-
versionType = "release"
122+
versionType = if (project.version.toString().contains("beta")) {
123+
"beta"
124+
} else if (project.version.toString().contains("alpha")) {
125+
"alpha"
126+
} else {
127+
"release"
128+
}
123129
uploadFile = tasks.remapJar.get()
124130
gameVersions.set(listOf(minecraftVersion))
125131
loaders.set(listOf("quilt", "fabric"))

1.20/src/main/java/io/github/axolotlclient/waypoints/server/AxolotlClientWaypointsServer.java

Lines changed: 22 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -60,30 +60,27 @@ public void onInitializeServer() {
6060
var modifyConfig = Commands.literal("modify_config")
6161
.requires(c -> c.hasPermission(PERMISSION_LEVEL));
6262

63-
for (Field f : Payload.class.getDeclaredFields()) {
64-
if (Modifier.isStatic(f.getModifiers())) {
65-
continue;
66-
}
67-
try {
68-
var wither = Payload.class.getMethod("with" + Character.toUpperCase(f.getName().charAt(0)) + f.getName().substring(1), boolean.class);
69-
70-
modifyConfig.then(Commands.literal(f.getName()).then(Commands.argument(f.getName(), BoolArgumentType.bool()).executes(c -> {
71-
if (options == null) {
72-
options = new Payload();
73-
}
74-
try {
75-
options = (Payload) wither.invoke(options, BoolArgumentType.getBool(c, f.getName()));
76-
} catch (IllegalAccessException | InvocationTargetException e) {
77-
throw new RuntimeException(e);
78-
}
63+
for (var m : Payload.class.getMethods()) {
64+
if (m.getParameterCount() != 1) continue;
65+
if (m.getParameterTypes()[0] != boolean.class) continue;
66+
if (Modifier.isStatic(m.getModifiers())) continue;
67+
for (Field f : Payload.class.getDeclaredFields()) {
68+
if (m.getName().contains(Character.toUpperCase(f.getName().charAt(0)) + f.getName().substring(1))) {
69+
modifyConfig.then(Commands.literal(f.getName()).then(Commands.argument(f.getName(), BoolArgumentType.bool()).executes(c -> {
70+
if (options == null) {
71+
options = new Payload();
72+
}
73+
try {
74+
options = (Payload) m.invoke(options, BoolArgumentType.getBool(c, f.getName()));
75+
} catch (IllegalAccessException | InvocationTargetException e) {
76+
throw new RuntimeException(e);
77+
}
7978

80-
save();
81-
reconfigure(c);
82-
83-
return 0;
84-
})));
85-
} catch (NoSuchMethodException e) {
86-
throw new RuntimeException(e);
79+
save();
80+
reconfigure(c);
81+
return 0;
82+
})));
83+
}
8784
}
8885
}
8986
commandDispatcher.register(Commands.literal(AxolotlClientWaypointsCommon.MODID)
@@ -116,9 +113,8 @@ public void onInitializeServer() {
116113
}
117114

118115
private void reconfigure(CommandContext<CommandSourceStack> c) {
119-
c.getSource().getServer().getPlayerList().getPlayers().forEach(p -> {
120-
ServerPlayNetworking.getSender(p).sendPacket(options);
121-
});
116+
c.getSource().getServer().getPlayerList().getPlayers().forEach(p ->
117+
ServerPlayNetworking.getSender(p).sendPacket(options));
122118
}
123119

124120
private void load() {

1.21.8/build.gradle.kts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,9 +129,15 @@ modrinth {
129129
token = System.getenv("MODRINTH_TOKEN")
130130
projectId = "s0qWsRJC"
131131
versionNumber = "${project.version}"
132-
versionType = "release"
132+
versionType = if (project.version.toString().contains("beta")) {
133+
"beta"
134+
} else if (project.version.toString().contains("alpha")) {
135+
"alpha"
136+
} else {
137+
"release"
138+
}
133139
uploadFile = tasks.remapJar.get()
134-
gameVersions.set(listOf(minecraftVersion))
140+
gameVersions.set(listOf("1.21.7", "1.21.8"))
135141
loaders.set(listOf("quilt", "fabric"))
136142
additionalFiles.set(listOf(tasks.remapSourcesJar))
137143
dependencies {

1.21.8/src/main/java/io/github/axolotlclient/waypoints/server/AxolotlClientWaypointsServer.java

Lines changed: 23 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -63,32 +63,30 @@ public void onInitializeServer() {
6363
var modifyConfig = Commands.literal("modify_config")
6464
.requires(Commands.hasPermission(PERMISSION_LEVEL));
6565

66-
for (Field f : Payload.class.getDeclaredFields()) {
67-
if (Modifier.isStatic(f.getModifiers())) {
68-
continue;
69-
}
70-
try {
71-
var wither = Payload.class.getMethod("with" + Character.toUpperCase(f.getName().charAt(0)) + f.getName().substring(1), boolean.class);
66+
for (var m : Payload.class.getMethods()) {
67+
if (m.getParameterCount() != 1) continue;
68+
if (m.getParameterTypes()[0] != boolean.class) continue;
69+
if (Modifier.isStatic(m.getModifiers())) continue;
70+
for (Field f : Payload.class.getDeclaredFields()) {
71+
if (m.getName().contains(Character.toUpperCase(f.getName().charAt(0)) + f.getName().substring(1))) {
72+
modifyConfig.then(Commands.literal(f.getName()).then(Commands.argument(f.getName(), BoolArgumentType.bool()).executes(c -> {
73+
if (options == null) {
74+
options = new Payload();
75+
}
76+
try {
77+
options = (Payload) m.invoke(options, BoolArgumentType.getBool(c, f.getName()));
78+
} catch (IllegalAccessException | InvocationTargetException e) {
79+
throw new RuntimeException(e);
80+
}
7281

73-
modifyConfig.then(Commands.literal(f.getName()).then(Commands.argument(f.getName(), BoolArgumentType.bool()).executes(c -> {
74-
if (options == null) {
75-
options = new Payload();
76-
}
77-
try {
78-
options = (Payload) wither.invoke(options, BoolArgumentType.getBool(c, f.getName()));
79-
} catch (IllegalAccessException | InvocationTargetException e) {
80-
throw new RuntimeException(e);
81-
}
82-
83-
save();
84-
reconfigure(c);
85-
86-
return 0;
87-
})));
88-
} catch (NoSuchMethodException e) {
89-
throw new RuntimeException(e);
82+
save();
83+
reconfigure(c);
84+
return 0;
85+
})));
86+
}
9087
}
9188
}
89+
9290
commandDispatcher.register(Commands.literal(AxolotlClientWaypointsCommon.MODID)
9391
.then(Commands.literal("reload")
9492
.requires(Commands.hasPermission(PERMISSION_LEVEL)).executes(c -> {
@@ -119,9 +117,8 @@ public void onInitializeServer() {
119117
}
120118

121119
private void reconfigure(CommandContext<CommandSourceStack> c) {
122-
c.getSource().getServer().getPlayerList().getPlayers().forEach(p -> {
123-
p.connection.send(new ClientboundCustomPayloadPacket(options));
124-
});
120+
c.getSource().getServer().getPlayerList().getPlayers().forEach(p ->
121+
p.connection.send(new ClientboundCustomPayloadPacket(options)));
125122
}
126123

127124
private void load() {

1.21/build.gradle.kts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,13 @@ modrinth {
119119
token = System.getenv("MODRINTH_TOKEN")
120120
projectId = "s0qWsRJC"
121121
versionNumber = "${project.version}"
122-
versionType = "release"
122+
versionType = if (project.version.toString().contains("beta")) {
123+
"beta"
124+
} else if (project.version.toString().contains("alpha")) {
125+
"alpha"
126+
} else {
127+
"release"
128+
}
123129
uploadFile = tasks.remapJar.get()
124130
gameVersions.set(listOf("1.21", "1.21.1"))
125131
loaders.set(listOf("quilt", "fabric"))

1.21/src/main/java/io/github/axolotlclient/waypoints/server/AxolotlClientWaypointsServer.java

Lines changed: 22 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -63,30 +63,27 @@ public void onInitializeServer() {
6363
var modifyConfig = Commands.literal("modify_config")
6464
.requires(c -> c.hasPermission(PERMISSION_LEVEL));
6565

66-
for (Field f : Payload.class.getDeclaredFields()) {
67-
if (Modifier.isStatic(f.getModifiers())) {
68-
continue;
69-
}
70-
try {
71-
var wither = Payload.class.getMethod("with" + Character.toUpperCase(f.getName().charAt(0)) + f.getName().substring(1), boolean.class);
72-
73-
modifyConfig.then(Commands.literal(f.getName()).then(Commands.argument(f.getName(), BoolArgumentType.bool()).executes(c -> {
74-
if (options == null) {
75-
options = new Payload();
76-
}
77-
try {
78-
options = (Payload) wither.invoke(options, BoolArgumentType.getBool(c, f.getName()));
79-
} catch (IllegalAccessException | InvocationTargetException e) {
80-
throw new RuntimeException(e);
81-
}
66+
for (var m : Payload.class.getMethods()) {
67+
if (m.getParameterCount() != 1) continue;
68+
if (m.getParameterTypes()[0] != boolean.class) continue;
69+
if (Modifier.isStatic(m.getModifiers())) continue;
70+
for (Field f : Payload.class.getDeclaredFields()) {
71+
if (m.getName().contains(Character.toUpperCase(f.getName().charAt(0)) + f.getName().substring(1))) {
72+
modifyConfig.then(Commands.literal(f.getName()).then(Commands.argument(f.getName(), BoolArgumentType.bool()).executes(c -> {
73+
if (options == null) {
74+
options = new Payload();
75+
}
76+
try {
77+
options = (Payload) m.invoke(options, BoolArgumentType.getBool(c, f.getName()));
78+
} catch (IllegalAccessException | InvocationTargetException e) {
79+
throw new RuntimeException(e);
80+
}
8281

83-
save();
84-
reconfigure(c);
85-
86-
return 0;
87-
})));
88-
} catch (NoSuchMethodException e) {
89-
throw new RuntimeException(e);
82+
save();
83+
reconfigure(c);
84+
return 0;
85+
})));
86+
}
9087
}
9188
}
9289
commandDispatcher.register(Commands.literal(AxolotlClientWaypointsCommon.MODID)
@@ -119,9 +116,8 @@ public void onInitializeServer() {
119116
}
120117

121118
private void reconfigure(CommandContext<CommandSourceStack> c) {
122-
c.getSource().getServer().getPlayerList().getPlayers().forEach(p -> {
123-
p.connection.send(new ClientboundCustomPayloadPacket(options));
124-
});
119+
c.getSource().getServer().getPlayerList().getPlayers().forEach(p ->
120+
p.connection.send(new ClientboundCustomPayloadPacket(options)));
125121
}
126122

127123
private void load() {

1.8.9/build.gradle.kts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,13 @@ modrinth {
142142
token = System.getenv("MODRINTH_TOKEN")
143143
projectId = "s0qWsRJC"
144144
versionNumber = "${project.version}"
145-
versionType = "release"
145+
versionType = if (project.version.toString().contains("beta")) {
146+
"beta"
147+
} else if (project.version.toString().contains("alpha")) {
148+
"alpha"
149+
} else {
150+
"release"
151+
}
146152
uploadFile = tasks.remapJar.get()
147153
gameVersions.set(listOf(minecraftVersion))
148154
loaders.set(listOf("ornithe"))

1.8.9/src/main/java/io/github/axolotlclient/waypoints/server/AxolotlClientWaypointsServer.java

Lines changed: 20 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -55,30 +55,27 @@ public void onInitializeServer() {
5555
var modifyConfig = Commands.literal("modify_config")
5656
.requires(c -> c.hasPermission(PERMISSION_LEVEL));
5757
58-
for (Field f : Payload.class.getDeclaredFields()) {
59-
if (Modifier.isStatic(f.getModifiers())) {
60-
continue;
61-
}
62-
try {
63-
var wither = Payload.class.getMethod("with" + Character.toUpperCase(f.getName().charAt(0)) + f.getName().substring(1), boolean.class);
64-
65-
modifyConfig.then(Commands.literal(f.getName()).then(Commands.argument(f.getName(), BoolArgumentType.bool()).executes(c -> {
66-
if (options == null) {
67-
options = new Payload();
68-
}
69-
try {
70-
options = (Payload) wither.invoke(options, BoolArgumentType.getBool(c, f.getName()));
71-
} catch (IllegalAccessException | InvocationTargetException e) {
72-
throw new RuntimeException(e);
73-
}
58+
for (var m : Payload.class.getMethods()) {
59+
if (m.getParameterCount() != 1) continue;
60+
if (m.getParameterTypes()[0] != boolean.class) continue;
61+
if (Modifier.isStatic(m.getModifiers())) continue;
62+
for (Field f : Payload.class.getDeclaredFields()) {
63+
if (m.getName().contains(Character.toUpperCase(f.getName().charAt(0)) + f.getName().substring(1))) {
64+
modifyConfig.then(Commands.literal(f.getName()).then(Commands.argument(f.getName(), BoolArgumentType.bool()).executes(c -> {
65+
if (options == null) {
66+
options = new Payload();
67+
}
68+
try {
69+
options = (Payload) m.invoke(options, BoolArgumentType.getBool(c, f.getName()));
70+
} catch (IllegalAccessException | InvocationTargetException e) {
71+
throw new RuntimeException(e);
72+
}
7473
75-
save();
76-
reconfigure(c);
77-
78-
return 0;
79-
})));
80-
} catch (NoSuchMethodException e) {
81-
throw new RuntimeException(e);
74+
save();
75+
reconfigure(c);
76+
return 0;
77+
})));
78+
}
8279
}
8380
}
8481
commandDispatcher.register(Commands.literal(AxolotlClientWaypointsCommon.MODID)

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
## Changelog
22

3+
### 0.0.1-beta.9
4+
5+
- Improved reflective command building for server part
6+
37
### 0.0.1-beta.8
48

59
- Fix Minimap Hud scaling

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ org.gradle.parallel=true
66
axolotlclient.modules.all=true
77

88
# Mod Properties
9-
version=0.0.1-beta.8+3.1.5
9+
version=0.0.1-beta.9+3.1.5
1010

1111
maven_group=io.github.axolotlclient.waypoints
1212

0 commit comments

Comments
 (0)