Skip to content

Commit af13b61

Browse files
committed
Version 0.3.0
1 parent c3919ba commit af13b61

File tree

9 files changed

+83
-81
lines changed

9 files changed

+83
-81
lines changed

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
plugins {
2-
id("fabric-loom") version("1.11-SNAPSHOT") apply(false)
2+
id("fabric-loom") version("1.13-SNAPSHOT") apply(false)
33

44
// https://github.com/ReplayMod/preprocessor
55
// https://github.com/Fallen-Breath/preprocessor

changelog.md

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

3+
- Migrate to official mappings
34
- Fix unable to save the config on first startup
45
- Support for 1.21.10

common.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ configurations {
6666
dependencies {
6767
// loom
6868
minecraft("com.mojang:minecraft:${project.minecraft_version}")
69-
mappings("net.fabricmc:yarn:${project.yarn_mappings}:v2")
69+
mappings(loom.layered() { officialMojangMappings() })
7070

7171
// fabric
7272
modImplementation("net.fabricmc:fabric-loader:${project.loader_version}")

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ loader_version=0.17.2
66
# Mod Properties
77
mod_id=authlib-proxy-for-server
88
mod_name=AuthlibProxyForServer
9-
mod_version=0.2.3
9+
mod_version=0.3.0
1010
mod_version_type=release
1111
group=com.ayakacraft
1212
archives_base_name=authlib-proxy-for-server

src/main/java/com/ayakacraft/authlibproxyforserver/commands/AuthProxyCommand.java

Lines changed: 67 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,10 @@
3030
import com.mojang.brigadier.arguments.IntegerArgumentType;
3131
import com.mojang.brigadier.arguments.StringArgumentType;
3232
import com.mojang.brigadier.context.CommandContext;
33-
import net.minecraft.server.command.ServerCommandSource;
34-
import net.minecraft.text.Text;
35-
import net.minecraft.util.Formatting;
36-
import net.minecraft.util.Pair;
33+
import com.mojang.datafixers.util.Pair;
34+
import net.minecraft.ChatFormatting;
35+
import net.minecraft.commands.CommandSourceStack;
36+
import net.minecraft.network.chat.Component;
3737

3838
import java.io.IOException;
3939
import java.net.URI;
@@ -43,14 +43,14 @@
4343
import static com.ayakacraft.authlibproxyforserver.AuthlibProxyForServer.LOGGER;
4444
import static com.ayakacraft.authlibproxyforserver.AuthlibProxyForServer.config;
4545
import static com.ayakacraft.authlibproxyforserver.AuthlibProxyForServer.proxy;
46-
import static net.minecraft.server.command.CommandManager.argument;
47-
import static net.minecraft.server.command.CommandManager.literal;
46+
import static net.minecraft.commands.Commands.argument;
47+
import static net.minecraft.commands.Commands.literal;
4848

4949
public final class AuthProxyCommand {
5050

5151
private static final int TCPING_TIMES = 5;
5252

53-
private static int display(CommandContext<ServerCommandSource> context) {
53+
private static int display(CommandContext<CommandSourceStack> context) {
5454
sendFeedback(
5555
context.getSource(),
5656
proxyText(),
@@ -60,12 +60,12 @@ private static int display(CommandContext<ServerCommandSource> context) {
6060
return 1;
6161
}
6262

63-
private static int enable(CommandContext<ServerCommandSource> context) {
64-
ServerCommandSource source = context.getSource();
63+
private static int enable(CommandContext<CommandSourceStack> context) {
64+
CommandSourceStack source = context.getSource();
6565
if (config.enabled) {
6666
sendFeedback(
6767
source,
68-
Text.literal("Proxy already enabled"),
68+
Component.literal("Proxy already enabled"),
6969
false
7070
);
7171
return 1;
@@ -76,18 +76,18 @@ private static int enable(CommandContext<ServerCommandSource> context) {
7676
}
7777
sendFeedback(
7878
source,
79-
Text.literal("Proxy enabled, restart the server to apply"),
79+
Component.literal("Proxy enabled, restart the server to apply"),
8080
true
8181
);
8282
return 1;
8383
}
8484

85-
private static int disable(CommandContext<ServerCommandSource> context) {
86-
ServerCommandSource source = context.getSource();
85+
private static int disable(CommandContext<CommandSourceStack> context) {
86+
CommandSourceStack source = context.getSource();
8787
if (!config.enabled) {
8888
sendFeedback(
8989
source,
90-
Text.literal("Proxy already disabled"),
90+
Component.literal("Proxy already disabled"),
9191
false
9292
);
9393
return 1;
@@ -98,22 +98,22 @@ private static int disable(CommandContext<ServerCommandSource> context) {
9898
}
9999
sendFeedback(
100100
source,
101-
Text.literal("Proxy disabled, restart the server to apply"),
101+
Component.literal("Proxy disabled, restart the server to apply"),
102102
true
103103
);
104104
return 1;
105105
}
106106

107-
private static int port(CommandContext<ServerCommandSource> context) {
108-
ServerCommandSource source = context.getSource();
109-
int port = IntegerArgumentType.getInteger(context, "port");
107+
private static int port(CommandContext<CommandSourceStack> context) {
108+
CommandSourceStack source = context.getSource();
109+
int port = IntegerArgumentType.getInteger(context, "port");
110110
config.port = (short) port;
111111
if (saveConfig(source)) {
112112
return 0;
113113
}
114114
sendFeedback(
115115
source,
116-
Text.literal("Proxy port set to " + port),
116+
Component.literal("Proxy port set to " + port),
117117
true
118118
);
119119
sendFeedback(
@@ -124,16 +124,16 @@ private static int port(CommandContext<ServerCommandSource> context) {
124124
return 1;
125125
}
126126

127-
private static int host(CommandContext<ServerCommandSource> context) {
128-
ServerCommandSource source = context.getSource();
129-
String host = StringArgumentType.getString(context, "host");
127+
private static int host(CommandContext<CommandSourceStack> context) {
128+
CommandSourceStack source = context.getSource();
129+
String host = StringArgumentType.getString(context, "host");
130130
config.host = host;
131131
if (saveConfig(source)) {
132132
return 0;
133133
}
134134
sendFeedback(
135135
source,
136-
Text.literal("Proxy host set to " + host),
136+
Component.literal("Proxy host set to " + host),
137137
true
138138
);
139139
sendFeedback(
@@ -144,15 +144,15 @@ private static int host(CommandContext<ServerCommandSource> context) {
144144
return 1;
145145
}
146146

147-
private static int type(CommandContext<ServerCommandSource> context, String type) {
148-
ServerCommandSource source = context.getSource();
147+
private static int type(CommandContext<CommandSourceStack> context, String type) {
148+
CommandSourceStack source = context.getSource();
149149
config.type = ProxyConfig.ProxyType.valueOf(type);
150150
if (saveConfig(source)) {
151151
return 0;
152152
}
153153
sendFeedback(
154154
source,
155-
Text.literal("Proxy type set to " + type),
155+
Component.literal("Proxy type set to " + type),
156156
true
157157
);
158158
sendFeedback(
@@ -163,7 +163,7 @@ private static int type(CommandContext<ServerCommandSource> context, String type
163163
return 1;
164164
}
165165

166-
private static int ping(CommandContext<ServerCommandSource> context) {
166+
private static int ping(CommandContext<CommandSourceStack> context) {
167167
Set<String> hosts = Sets.newHashSet();
168168
//#if MC>=12006
169169
com.mojang.authlib.Environment env = com.ayakacraft.authlibproxyforserver.mixin.YggdrasilAuthenticationServiceAccessor.determineEnvironment();
@@ -187,46 +187,46 @@ private static int ping(CommandContext<ServerCommandSource> context) {
187187
/**
188188
* @return true if failed
189189
*/
190-
private static boolean saveConfig(ServerCommandSource source) {
190+
private static boolean saveConfig(CommandSourceStack source) {
191191
try {
192192
AuthlibProxyForServer.saveConfig(config.validate());
193193
} catch (IOException e) {
194-
source.sendError(Text.literal("Error saving config"));
194+
source.sendFailure(Component.literal("Error saving config"));
195195
LOGGER.error("Error saving config", e);
196196
return true;
197197
} catch (ProxyConfig.InvalidProxyConfigException e) {
198-
source.sendError(Text.literal(e.getMessage()));
198+
source.sendFailure(Component.literal(e.getMessage()));
199199
LOGGER.error(e);
200200
return true;
201201
}
202202
return false;
203203
}
204204

205-
private static Text proxyText() {
206-
return Text.literal("Proxy for authlib: " + proxy.toString());
207-
}
208-
209205
@PreprocessPattern
210-
private static Text li(String str) {
206+
private static Component li(String str) {
211207
//#if MC>=11900
212-
return Text.literal(str);
208+
return Component.literal(str);
213209
//#else
214-
//$$ return new net.minecraft.text.LiteralText(str);
210+
//$$ return new net.minecraft.network.chat.TextComponent(str);
215211
//#endif
216212
}
217213

218-
private static void sendFeedback(ServerCommandSource source, Text txt, boolean broadcastToOps) {
214+
private static Component proxyText() {
215+
return Component.literal("Proxy for authlib: " + proxy.toString());
216+
}
217+
218+
private static void sendFeedback(CommandSourceStack source, Component txt, boolean broadcastToOps) {
219219
//#if MC>=12000
220-
source.sendFeedback(() -> txt, broadcastToOps);
220+
source.sendSuccess(() -> txt, broadcastToOps);
221221
//#else
222-
//$$ source.sendFeedback(txt, broadcastToOps);
222+
//$$ source.sendSuccess(txt, broadcastToOps);
223223
//#endif
224224
}
225225

226-
public static void register(CommandDispatcher<ServerCommandSource> dispatcher) {
226+
public static void register(CommandDispatcher<CommandSourceStack> dispatcher) {
227227
dispatcher.register(
228228
literal("authproxy")
229-
.requires(source -> source.hasPermissionLevel(source.getServer().getOpPermissionLevel()))
229+
.requires(source -> source.hasPermission(source.getServer().getOperatorUserPermissionLevel()))
230230
.executes(AuthProxyCommand::display)
231231
.then(literal("enable").executes(AuthProxyCommand::enable))
232232
.then(literal("disable").executes(AuthProxyCommand::disable))
@@ -248,45 +248,45 @@ public static void register(CommandDispatcher<ServerCommandSource> dispatcher) {
248248

249249
private static class TcpingThread extends Thread {
250250

251-
private static Text packetLossStatusText(int packetsReceived) {
252-
double packetLoss = 1D - (double) packetsReceived / AuthProxyCommand.TCPING_TIMES;
253-
Formatting colour;
251+
private static Component packetLossStatusText(int packetsReceived) {
252+
double packetLoss = 1D - (double) packetsReceived / AuthProxyCommand.TCPING_TIMES;
253+
ChatFormatting colour;
254254
if (packetLoss > 0.8D) {
255-
colour = Formatting.RED;
255+
colour = ChatFormatting.RED;
256256
} else if (packetLoss > 0.2D) {
257-
colour = Formatting.YELLOW;
257+
colour = ChatFormatting.YELLOW;
258258
} else {
259-
colour = Formatting.GREEN;
259+
colour = ChatFormatting.GREEN;
260260
}
261-
return Text.literal(String.format("%d packets transmitted, %d packets received, ", TCPING_TIMES, packetsReceived))
262-
.append(Text.literal(String.format("%.1f%%", packetLoss * 100)).formatted(colour))
263-
.append(Text.literal(" packet loss"));
261+
return Component.literal(String.format("%d packets transmitted, %d packets received, ", TCPING_TIMES, packetsReceived))
262+
.append(Component.literal(String.format("%.1f%%", packetLoss * 100)).withStyle(colour))
263+
.append(Component.literal(" packet loss"));
264264
}
265265

266-
private static Text averagePingText(long ping) {
267-
Formatting colour;
266+
private static Component averagePingText(long ping) {
267+
ChatFormatting colour;
268268
if (ping > 1000) {
269-
colour = Formatting.LIGHT_PURPLE;
269+
colour = ChatFormatting.LIGHT_PURPLE;
270270
} else if (ping >= 800) {
271-
colour = Formatting.RED;
271+
colour = ChatFormatting.RED;
272272
} else if (ping >= 300) {
273-
colour = Formatting.YELLOW;
273+
colour = ChatFormatting.YELLOW;
274274
} else {
275-
colour = Formatting.GREEN;
275+
colour = ChatFormatting.GREEN;
276276
}
277-
return Text.literal("Average ping: ")
278-
.append(Text.literal(ping + "ms").formatted(colour));
277+
return Component.literal("Average ping: ")
278+
.append(Component.literal(ping + "ms").withStyle(colour));
279279
}
280280

281281
private final Set<String> hosts;
282282

283-
private final ServerCommandSource source;
283+
private final CommandSourceStack source;
284284

285285
private final Map<String, Pair<Long, Integer>> results;
286286

287287
private long startTimeMillis;
288288

289-
public TcpingThread(Set<String> hosts, ServerCommandSource source) {
289+
public TcpingThread(Set<String> hosts, CommandSourceStack source) {
290290
super("TCPing Thread");
291291
this.hosts = hosts;
292292
this.source = source;
@@ -297,33 +297,33 @@ private synchronized void saveResult(String host, Pair<Long, Integer> res) {
297297
results.put(host, res);
298298
if (results.size() >= hosts.size()) {
299299
results.forEach(this::sendResult);
300-
sendFeedback(source, Text.literal("Ping finished after " + (System.currentTimeMillis() - startTimeMillis) + "ms"), false);
300+
sendFeedback(source, Component.literal("Ping finished after " + (System.currentTimeMillis() - startTimeMillis) + "ms"), false);
301301
}
302302
}
303303

304304
private void sendResult(String h, Pair<Long, Integer> r) {
305305
sendFeedback(
306306
source,
307-
Text.literal(String.format("Ping for '%s':", h)),
307+
Component.literal(String.format("Ping for '%s':", h)),
308308
false
309309
);
310310
sendFeedback(
311311
source,
312-
packetLossStatusText(r.getRight()),
312+
packetLossStatusText(r.getSecond()),
313313
false
314314
);
315-
if (r.getRight() > 0) {
315+
if (r.getSecond() > 0) {
316316
sendFeedback(
317317
source,
318-
averagePingText(r.getLeft() / r.getRight()),
318+
averagePingText(r.getFirst() / r.getSecond()),
319319
false
320320
);
321321
}
322322
}
323323

324324
@Override
325325
public void run() {
326-
sendFeedback(source, Text.literal("Ping started"), false);
326+
sendFeedback(source, Component.literal("Ping started"), false);
327327
startTimeMillis = System.currentTimeMillis();
328328
hosts.forEach(host -> new Thread(() ->
329329
saveResult(host, NetworkUtils.tcpingMultiple(URI.create(host), proxy, TCPING_TIMES))).start()

src/main/java/com/ayakacraft/authlibproxyforserver/mixin/CommandManagerMixin.java renamed to src/main/java/com/ayakacraft/authlibproxyforserver/mixin/CommandsMixin.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,36 +22,36 @@
2222

2323
import com.ayakacraft.authlibproxyforserver.commands.AuthProxyCommand;
2424
import com.mojang.brigadier.CommandDispatcher;
25-
import net.minecraft.server.command.CommandManager;
26-
import net.minecraft.server.command.ServerCommandSource;
25+
import net.minecraft.commands.CommandSourceStack;
26+
import net.minecraft.commands.Commands;
2727
import org.spongepowered.asm.mixin.Final;
2828
import org.spongepowered.asm.mixin.Mixin;
2929
import org.spongepowered.asm.mixin.Shadow;
3030
import org.spongepowered.asm.mixin.injection.At;
3131
import org.spongepowered.asm.mixin.injection.Inject;
3232
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
3333

34-
@Mixin(CommandManager.class)
35-
public class CommandManagerMixin {
34+
@Mixin(Commands.class)
35+
public class CommandsMixin {
3636

3737
@Shadow
3838
@Final
39-
private CommandDispatcher<ServerCommandSource> dispatcher;
39+
private CommandDispatcher<CommandSourceStack> dispatcher;
4040

4141
@Inject(method = "<init>", at = @At("RETURN"))
4242
private void onRegister(
4343
//#if MC>=11900
44-
CommandManager.RegistrationEnvironment commandSelection, net.minecraft.command.CommandRegistryAccess commandBuildContext,
44+
Commands.CommandSelection commandSelection, net.minecraft.commands.CommandBuildContext commandBuildContext,
4545
//#elseif MC>=11600
46-
//$$ CommandManager.RegistrationEnvironment commandSelection,
46+
//$$ Commands.CommandSelection commandSelection,
4747
//#else
4848
//$$ boolean isDedicated,
4949
//#endif
5050
CallbackInfo ci
5151
) {
5252
if (
5353
//#if MC>=11600
54-
commandSelection == CommandManager.RegistrationEnvironment.DEDICATED
54+
commandSelection == Commands.CommandSelection.DEDICATED
5555
//#else
5656
//$$ isDedicated
5757
//#endif

0 commit comments

Comments
 (0)