From 1145598aaa0c8330c0740aa1f569d00fac56f846 Mon Sep 17 00:00:00 2001 From: kyrptonaught Date: Sat, 24 Feb 2024 14:56:11 -0500 Subject: [PATCH] Fix SyncedKeybinds --- .../serverutils/syncedKeybinds/SyncedKeybinds.java | 3 ++- .../serverutils/syncedKeybinds/SyncedKeybindsConfig.java | 7 ++++--- .../syncedKeybinds/SyncedKeybindsNetworking.java | 4 ++-- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/main/java/net/kyrptonaught/serverutils/syncedKeybinds/SyncedKeybinds.java b/src/main/java/net/kyrptonaught/serverutils/syncedKeybinds/SyncedKeybinds.java index 2b41721..da5328f 100644 --- a/src/main/java/net/kyrptonaught/serverutils/syncedKeybinds/SyncedKeybinds.java +++ b/src/main/java/net/kyrptonaught/serverutils/syncedKeybinds/SyncedKeybinds.java @@ -5,6 +5,7 @@ import net.kyrptonaught.serverutils.ModuleWConfig; import net.kyrptonaught.serverutils.ServerUtilsMod; import net.minecraft.server.network.ServerPlayerEntity; +import net.minecraft.util.Identifier; public class SyncedKeybinds extends ModuleWConfig { @@ -21,7 +22,7 @@ public SyncedKeybindsConfig createDefaultConfig() { return new SyncedKeybindsConfig(); } - public static void keybindPressed(ServerPlayerEntity player, String keyPressed) { + public static void keybindPressed(ServerPlayerEntity player, Identifier keyPressed) { SyncedKeybindsConfig.KeybindConfigItem keybind = ServerUtilsMod.SyncedKeybindsModule.getConfig().keybinds.get(keyPressed); if (keybind != null) CMDHelper.executeAs(player, keybind.triggerCMD); diff --git a/src/main/java/net/kyrptonaught/serverutils/syncedKeybinds/SyncedKeybindsConfig.java b/src/main/java/net/kyrptonaught/serverutils/syncedKeybinds/SyncedKeybindsConfig.java index 207c036..0813433 100644 --- a/src/main/java/net/kyrptonaught/serverutils/syncedKeybinds/SyncedKeybindsConfig.java +++ b/src/main/java/net/kyrptonaught/serverutils/syncedKeybinds/SyncedKeybindsConfig.java @@ -2,20 +2,21 @@ import net.kyrptonaught.serverutils.AbstractConfigFile; import net.minecraft.network.PacketByteBuf; +import net.minecraft.util.Identifier; import java.util.HashMap; public class SyncedKeybindsConfig extends AbstractConfigFile { - public HashMap keybinds = new HashMap<>(); + public HashMap keybinds = new HashMap<>(); public static class KeybindConfigItem { public String triggerCMD; public String keybinding; public String controllerBind; - public void writeToPacket(String id, PacketByteBuf packetByteBuf) { - packetByteBuf.writeString(id); + public void writeToPacket(Identifier id, PacketByteBuf packetByteBuf) { + packetByteBuf.writeIdentifier(id); packetByteBuf.writeString(keybinding); packetByteBuf.writeString(controllerBind); } diff --git a/src/main/java/net/kyrptonaught/serverutils/syncedKeybinds/SyncedKeybindsNetworking.java b/src/main/java/net/kyrptonaught/serverutils/syncedKeybinds/SyncedKeybindsNetworking.java index 0dc8852..b94905a 100644 --- a/src/main/java/net/kyrptonaught/serverutils/syncedKeybinds/SyncedKeybindsNetworking.java +++ b/src/main/java/net/kyrptonaught/serverutils/syncedKeybinds/SyncedKeybindsNetworking.java @@ -16,7 +16,7 @@ public class SyncedKeybindsNetworking { public static void registerReceivePacket() { ServerPlayNetworking.registerGlobalReceiver(KEYBIND_PRESSED_PACKET, (server, player, serverPlayNetworkHandler, packetByteBuf, packetSender) -> { - String keybindId = packetByteBuf.readIdentifier().toString(); + Identifier keybindId = packetByteBuf.readIdentifier(); server.execute(() -> { SyncedKeybinds.keybindPressed(player, keybindId); @@ -24,7 +24,7 @@ public static void registerReceivePacket() { }); } - public static void syncKeybindsToClient(HashMap keybinds, PacketSender packetSender) { + public static void syncKeybindsToClient(HashMap keybinds, PacketSender packetSender) { PacketByteBuf packetByteBuf = new PacketByteBuf(Unpooled.buffer()); packetByteBuf.writeInt(keybinds.size()); keybinds.forEach((s, keybindConfigItem) -> keybindConfigItem.writeToPacket(s, packetByteBuf));