- [FEAT] New APIs for Maintenance Mode and rewrite commands system
- [FEAT] Improved config system to fix old loading bugs and support JSON - [FEAT] LuckPerms support for commands
This commit is contained in:
@@ -3,7 +3,7 @@
|
||||
@@ -2,9 +2,9 @@
|
||||
|
||||
import com.hypherionmc.craterlib.client.gui.config.CraterConfigScreen;
|
||||
import com.hypherionmc.craterlib.core.config.ModuleConfig;
|
||||
import com.hypherionmc.craterlib.core.config.AbstractConfig;
|
||||
+import com.mojang.blaze3d.vertex.PoseStack;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.Font;
|
||||
|
@@ -0,0 +1,20 @@
|
||||
--- a/Common/src/main/java/com/hypherionmc/craterlib/mixin/events/ServerStatusMixin.java
|
||||
+++ b/Common/src/main/java/com/hypherionmc/craterlib/mixin/events/ServerStatusMixin.java
|
||||
@@ -14,13 +14,13 @@
|
||||
@Mixin(ServerStatus.class)
|
||||
public class ServerStatusMixin {
|
||||
|
||||
- @Inject(method = "favicon", at = @At("RETURN"), cancellable = true)
|
||||
- private void injectIconEvent(CallbackInfoReturnable<Optional<ServerStatus.Favicon>> cir) {
|
||||
- ServerStatusEvent.FaviconRequestEvent event = new ServerStatusEvent.FaviconRequestEvent(cir.getReturnValue().isEmpty() ? Optional.empty() : Optional.of(new WrappedServerStatus.WrappedFavicon(cir.getReturnValue().get())));
|
||||
+ @Inject(method = "getFavicon", at = @At("RETURN"), cancellable = true)
|
||||
+ private void injectIconEvent(CallbackInfoReturnable<String> cir) {
|
||||
+ ServerStatusEvent.FaviconRequestEvent event = new ServerStatusEvent.FaviconRequestEvent(cir.getReturnValue().isEmpty() ? Optional.empty() : Optional.of(new WrappedServerStatus.WrappedFavicon(cir.getReturnValue())));
|
||||
CraterEventBus.INSTANCE.postEvent(event);
|
||||
|
||||
if (event.getNewIcon().isPresent()) {
|
||||
- cir.setReturnValue(Optional.of(event.getNewIcon().get().toMojang()));
|
||||
+ cir.setReturnValue(event.getNewIcon().get().toMojang());
|
||||
}
|
||||
}
|
||||
|
@@ -0,0 +1,49 @@
|
||||
--- /dev/null
|
||||
+++ b/Common/src/main/java/com/hypherionmc/craterlib/mixin/events/ServerStatusPacketListenerMixin.java
|
||||
@@ -1,0 +1,46 @@
|
||||
+package com.hypherionmc.craterlib.mixin.events;
|
||||
+
|
||||
+import com.hypherionmc.craterlib.api.events.server.ServerStatusEvent;
|
||||
+import com.hypherionmc.craterlib.core.event.CraterEventBus;
|
||||
+import com.hypherionmc.craterlib.utils.ChatUtils;
|
||||
+import net.minecraft.network.Connection;
|
||||
+import net.minecraft.network.protocol.status.ClientboundStatusResponsePacket;
|
||||
+import net.minecraft.network.protocol.status.ServerStatus;
|
||||
+import net.minecraft.network.protocol.status.ServerboundStatusRequestPacket;
|
||||
+import net.minecraft.server.MinecraftServer;
|
||||
+import net.minecraft.server.network.ServerStatusPacketListenerImpl;
|
||||
+import org.spongepowered.asm.mixin.Final;
|
||||
+import org.spongepowered.asm.mixin.Mixin;
|
||||
+import org.spongepowered.asm.mixin.Shadow;
|
||||
+import org.spongepowered.asm.mixin.injection.At;
|
||||
+import org.spongepowered.asm.mixin.injection.Inject;
|
||||
+import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
+
|
||||
+@Mixin(ServerStatusPacketListenerImpl.class)
|
||||
+public class ServerStatusPacketListenerMixin {
|
||||
+
|
||||
+ @Shadow @Final private Connection connection;
|
||||
+
|
||||
+ @Shadow @Final private MinecraftServer server;
|
||||
+
|
||||
+ @Inject(method = "handleStatusRequest",
|
||||
+ at = @At(
|
||||
+ value = "INVOKE",
|
||||
+ target = "Lnet/minecraft/network/Connection;send(Lnet/minecraft/network/protocol/Packet;)V",
|
||||
+ shift = At.Shift.BEFORE),
|
||||
+ cancellable = true
|
||||
+ )
|
||||
+ private void injectHandleStatusRequest(ServerboundStatusRequestPacket arg, CallbackInfo ci) {
|
||||
+ ServerStatusEvent.StatusRequestEvent event = new ServerStatusEvent.StatusRequestEvent(ChatUtils.mojangToAdventure(server.getStatus().getDescription()));
|
||||
+ CraterEventBus.INSTANCE.postEvent(event);
|
||||
+
|
||||
+ if (event.getNewStatus() != null) {
|
||||
+ ci.cancel();
|
||||
+ ServerStatus serverStatus = this.server.getStatus();
|
||||
+ serverStatus.setDescription(ChatUtils.adventureToMojang(event.getNewStatus()));
|
||||
+
|
||||
+ this.connection.send(new ClientboundStatusResponsePacket(serverStatus));
|
||||
+ }
|
||||
+ }
|
||||
+
|
||||
+}
|
@@ -8,4 +8,4 @@
|
||||
+ internal.sendSuccess(ChatUtils.adventureToMojang(supplier.get()), bl);
|
||||
}
|
||||
|
||||
public CommandSourceStack toMojang() {
|
||||
public void sendFailure(Component text) {
|
||||
|
@@ -0,0 +1,46 @@
|
||||
--- a/Common/src/main/java/com/hypherionmc/craterlib/nojang/network/protocol/status/WrappedServerStatus.java
|
||||
+++ b/Common/src/main/java/com/hypherionmc/craterlib/nojang/network/protocol/status/WrappedServerStatus.java
|
||||
@@ -3,26 +3,38 @@
|
||||
import net.minecraft.network.protocol.status.ServerStatus;
|
||||
import org.jetbrains.annotations.ApiStatus;
|
||||
|
||||
+import java.nio.charset.StandardCharsets;
|
||||
+import java.util.Base64;
|
||||
+
|
||||
public final class WrappedServerStatus {
|
||||
|
||||
public static final class WrappedFavicon {
|
||||
|
||||
- private final ServerStatus.Favicon internal;
|
||||
+ private final String internal;
|
||||
+ private final byte[] iconBytes;
|
||||
|
||||
public WrappedFavicon(byte[] iconBytes) {
|
||||
- internal = new ServerStatus.Favicon(iconBytes);
|
||||
+ this.iconBytes = iconBytes;
|
||||
+
|
||||
+ if (iconBytes != null) {
|
||||
+ byte[] encoded = Base64.getEncoder().encode(iconBytes);
|
||||
+ internal = "data:image/png;base64," + new String(encoded, StandardCharsets.UTF_8);
|
||||
+ } else {
|
||||
+ internal = null;
|
||||
+ }
|
||||
}
|
||||
|
||||
@ApiStatus.Internal
|
||||
- public WrappedFavicon(ServerStatus.Favicon internal) {
|
||||
+ public WrappedFavicon(String internal) {
|
||||
this.internal = internal;
|
||||
+ this.iconBytes = new byte[0];
|
||||
}
|
||||
|
||||
public byte[] iconBytes() {
|
||||
- return internal.iconBytes();
|
||||
+ return iconBytes;
|
||||
}
|
||||
|
||||
- public ServerStatus.Favicon toMojang() {
|
||||
+ public String toMojang() {
|
||||
return internal;
|
||||
}
|
||||
|
@@ -0,0 +1,12 @@
|
||||
--- a/Common/src/main/resources/craterlib.mixins.json
|
||||
+++ b/Common/src/main/resources/craterlib.mixins.json
|
||||
@@ -17,7 +17,8 @@
|
||||
"events.PlayerAdvancementsMixin",
|
||||
"events.PlayerListMixin",
|
||||
"events.ServerPlayerMixin",
|
||||
- "events.ServerStatusMixin"
|
||||
+ "events.ServerStatusMixin",
|
||||
+ "events.ServerStatusPacketListenerMixin"
|
||||
],
|
||||
"injectors": {
|
||||
"defaultRequire": 1
|
Reference in New Issue
Block a user