Skip to content

Commit

Permalink
Fix SyncedKeybinds
Browse files Browse the repository at this point in the history
  • Loading branch information
kyrptonaught committed Feb 24, 2024
1 parent 95f14b6 commit 1145598
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<SyncedKeybindsConfig> {

Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, KeybindConfigItem> keybinds = new HashMap<>();
public HashMap<Identifier, KeybindConfigItem> 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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@ 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);
});
});
}

public static void syncKeybindsToClient(HashMap<String, SyncedKeybindsConfig.KeybindConfigItem> keybinds, PacketSender packetSender) {
public static void syncKeybindsToClient(HashMap<Identifier, SyncedKeybindsConfig.KeybindConfigItem> keybinds, PacketSender packetSender) {
PacketByteBuf packetByteBuf = new PacketByteBuf(Unpooled.buffer());
packetByteBuf.writeInt(keybinds.size());
keybinds.forEach((s, keybindConfigItem) -> keybindConfigItem.writeToPacket(s, packetByteBuf));
Expand Down

0 comments on commit 1145598

Please sign in to comment.