reload cosmetics

This commit is contained in:
2025-04-02 01:40:06 +02:00
parent a8f2ecf3cf
commit 5040aadc7c
10 changed files with 77 additions and 58 deletions
@@ -6,6 +6,7 @@ import java.util.Map;
public class SaturnParser {
public String method = "";
public String error;
private Map<String, String> params = new HashMap<>();
public SaturnParser(String input) throws IOException {
@@ -16,7 +17,7 @@ public class SaturnParser {
}
if (parts[0].startsWith("!")) {
throw new IOException(parts[0]);
error = input;
}
method = parts[0];
@@ -6,6 +6,7 @@ import java.util.HashMap;
import java.util.Map;
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientLifecycleEvents;
import net.fabricmc.fabric.api.client.message.v1.ClientReceiveMessageEvents;
import net.minecraft.client.MinecraftClient;
import org.saturnclient.saturnclient.SaturnClient;
@@ -109,6 +110,12 @@ public class SaturnSocket {
playerNames.entrySet().removeIf(entry -> entry.getValue().equals(uuid));
}
break;
default:
if (parser.error != null) {
SaturnClient.LOGGER.error("Error from the server: " + parser.error);
}
break;
}
}
} catch (IOException e) {
@@ -142,6 +149,16 @@ public class SaturnSocket {
public static void afterAuth() {
PlayerTracker.initialize();
ClientReceiveMessageEvents.CHAT.register((message, signedMessage, sender, params, receptionTimestamp) -> {
String msg = message.getString();
if (msg.contains("$SATURN_RELOAD")) {
String name = sender.getName();
SaturnClient.LOGGER.info("Reloading player: " + name);
player(name, sender.getId().toString().replace("-", ""));
}
});
}
public static void setCloak(String cloakName) {
@@ -169,11 +186,14 @@ public class SaturnSocket {
}
}
public static void joinServer(String ip) {
try {
writer.println("join_server@ip=" + ip);
} catch (Exception e) {
SaturnClient.LOGGER.error("Request failed", e);
public static void sendReload() {
for (Map.Entry<String, String> player : playerNames.entrySet()) {
if (players.containsKey(player.getValue()) && !player.getValue().equals(uuid)) {
MinecraftClient.getInstance().player.networkHandler
.sendChatCommand("msg " + player.getKey() + " "
+ "$SATURN_RELOAD if you are seeing this as a player, please report this to https://github.com/saturnclientmc/saturnclient/issues");
;
}
}
}
}
@@ -16,11 +16,9 @@ import org.saturnclient.saturnclient.SaturnClient;
public class ConfigManager {
private static File configFile = new File(
MinecraftClient.getInstance().runDirectory,
"saturn.json"
);
private static Map<String, Map<String, Property<?>>> properties =
new HashMap<>();
MinecraftClient.getInstance().runDirectory,
"saturn.json");
private static Map<String, Map<String, Property<?>>> properties = new HashMap<>();
private String namespace;
@@ -45,49 +43,35 @@ public class ConfigManager {
}
JsonObject jsonObject = JsonParser.parseString(
new String(Files.readAllBytes(configFile.toPath()))
).getAsJsonObject();
new String(Files.readAllBytes(configFile.toPath()))).getAsJsonObject();
for (String namespace : properties.keySet()) {
JsonElement configElement = jsonObject.get(namespace);
if (configElement == null) continue;
if (configElement == null)
continue;
JsonObject config = jsonObject.get(namespace).getAsJsonObject();
if (config == null) {
SaturnClient.LOGGER.warn(
"No config found for namespace: " + namespace
);
continue;
}
Map<String, Property<?>> propertyMap = properties.get(
namespace
);
namespace);
for (String propertyName : propertyMap.keySet()) {
JsonElement c = config.get(propertyName);
if (c == null) {
SaturnClient.LOGGER.warn(
"No property found in config for " + propertyName
);
continue;
}
SaturnClient.LOGGER.info("got prop " + c);
Property<?> p = propertyMap.get(propertyName);
SaturnClient.LOGGER.info(
"setting prop " + propertyName + " to " + p.value
);
SaturnClient.LOGGER.info("Property type: " + p.getType());
if (p.matchesJson(c)) {
switch (p.getType()) {
case BOOLEAN:
((Property<Boolean>) p).value =
c.getAsBoolean();
((Property<Boolean>) p).value = c.getAsBoolean();
break;
case INTEGER:
((Property<Integer>) p).value = c.getAsInt();
@@ -106,8 +90,7 @@ public class ConfigManager {
}
} else {
SaturnClient.LOGGER.warn(
"Property does not match JSON: " + propertyName
);
"Property does not match JSON: " + propertyName);
}
}
}
@@ -126,8 +109,7 @@ public class ConfigManager {
for (String namespace : properties.keySet()) {
JsonObject namespaceConfig = new JsonObject();
Map<String, Property<?>> propertyMap = properties.get(
namespace
);
namespace);
// Iterate through each property in the namespace
for (String propertyName : propertyMap.keySet()) {
@@ -138,33 +120,27 @@ public class ConfigManager {
switch (property.getType()) {
case BOOLEAN:
propertyValue = new JsonPrimitive(
(Boolean) property.value
);
(Boolean) property.value);
break;
case INTEGER:
propertyValue = new JsonPrimitive(
(Integer) property.value
);
(Integer) property.value);
break;
case FLOAT:
propertyValue = new JsonPrimitive(
(Float) property.value
);
(Float) property.value);
break;
case STRING:
propertyValue = new JsonPrimitive(
(String) property.value
);
(String) property.value);
break;
case HEX:
propertyValue = new JsonPrimitive(
(Integer) property.value
);
(Integer) property.value);
break;
default:
SaturnClient.LOGGER.warn(
"Unknown property type for: " + propertyName
);
"Unknown property type for: " + propertyName);
break;
}
@@ -2,7 +2,6 @@ package org.saturnclient.saturnclient.cosmetics;
import java.util.ArrayList;
import java.util.List;
import org.saturnclient.saturnclient.auth.SaturnPlayer;
import org.saturnclient.saturnclient.auth.SaturnSocket;
@@ -16,6 +15,7 @@ public class Hats {
public static void setHat(String uuid, String hatName) {
setHatSilent(uuid, hatName);
SaturnSocket.setHat(hatName);
SaturnSocket.sendReload();
}
public static void setHatSilent(String uuid, String hatName) {
@@ -44,6 +44,7 @@ public class Cloaks {
public static void setCloak(String uuid, String cloakName) {
SaturnSocket.setCloak(cloakName);
setCloakSilent(uuid, cloakName);
SaturnSocket.sendReload();
SaturnClient.LOGGER.info("Cloak set to " + cloakName);
}
@@ -0,0 +1,23 @@
package org.saturnclient.saturnclient.mixin;
import org.jetbrains.annotations.Nullable;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import net.minecraft.client.gui.hud.ChatHud;
import net.minecraft.client.gui.hud.MessageIndicator;
import net.minecraft.network.message.MessageSignatureData;
import net.minecraft.text.Text;
@Mixin(ChatHud.class)
public class SaturnReload {
@Inject(method = "addMessage(Lnet/minecraft/text/Text;Lnet/minecraft/network/message/MessageSignatureData;Lnet/minecraft/client/gui/hud/MessageIndicator;)V", at = @At("HEAD"), cancellable = true)
public void onAddMessage(Text message, @Nullable MessageSignatureData signatureData,
@Nullable MessageIndicator indicator, CallbackInfo ci) {
if (message.toString().contains("$SATURN_RELOAD")) {
ci.cancel();
}
}
}