From a63494ba9fbcfa6c2e8a59fe2efe39d939f4caa1 Mon Sep 17 00:00:00 2001 From: Logan <37521985+LoJoSho@users.noreply.github.com> Date: Sun, 7 Sep 2025 14:05:29 -0500 Subject: [PATCH] feat: make prevent offhand swapping configurable and is now disabled by default, resolves #192 --- .../java/com/hibiscusmc/hmccosmetics/config/Settings.java | 4 ++++ .../hmccosmetics/packets/CosmeticPacketInterface.java | 1 + common/src/main/resources/config.yml | 3 +++ 3 files changed, 8 insertions(+) diff --git a/common/src/main/java/com/hibiscusmc/hmccosmetics/config/Settings.java b/common/src/main/java/com/hibiscusmc/hmccosmetics/config/Settings.java index cd73925d..1598fee1 100644 --- a/common/src/main/java/com/hibiscusmc/hmccosmetics/config/Settings.java +++ b/common/src/main/java/com/hibiscusmc/hmccosmetics/config/Settings.java @@ -47,6 +47,7 @@ public class Settings { private static final String COSMETIC_BACKPACK_FORCE_RIDING_PACKET_PATH = "backpack-force-riding-packet"; private static final String COSMETIC_DESTROY_LOOSE_COSMETIC_PATH = "destroy-loose-cosmetics"; private static final String COSMETIC_BALLOON_HEAD_FORWARD_PATH = "balloon-head-forward"; + private static final String COSMETIC_OFFHAND_PREVENT_SWAPPING = "offhand-prevent-swapping"; private static final String MENU_SETTINGS_PATH = "menu-settings"; private static final String MENU_CLICK_COOLDOWN_PATH = "click-cooldown"; private static final String MENU_CLICK_COOLDOWN_TIME_PATH = "time"; @@ -101,6 +102,8 @@ public class Settings { @Getter private static boolean destroyLooseCosmetics; @Getter + private static boolean preventOffhandSwapping; + @Getter private static boolean backpackForceRidingEnabled; @Getter private static boolean disabledGamemodesEnabled; @@ -192,6 +195,7 @@ public class Settings { forceShowOnJoin = cosmeticSettings.node(FORCE_SHOW_COSMETICS_PATH).getBoolean(false); destroyLooseCosmetics = cosmeticSettings.node(COSMETIC_DESTROY_LOOSE_COSMETIC_PATH).getBoolean(false); backpackForceRidingEnabled = cosmeticSettings.node(COSMETIC_BACKPACK_FORCE_RIDING_PACKET_PATH).getBoolean(false); + preventOffhandSwapping = cosmeticSettings.node(COSMETIC_OFFHAND_PREVENT_SWAPPING).getBoolean(false); cosmeticSettings.node(SLOT_OPTIONS_PATH).childrenMap().forEach((key, value) -> { EquipmentSlot slot = convertConfigToEquipment(key.toString().toLowerCase()); diff --git a/common/src/main/java/com/hibiscusmc/hmccosmetics/packets/CosmeticPacketInterface.java b/common/src/main/java/com/hibiscusmc/hmccosmetics/packets/CosmeticPacketInterface.java index 6076c9ee..f93c1f91 100644 --- a/common/src/main/java/com/hibiscusmc/hmccosmetics/packets/CosmeticPacketInterface.java +++ b/common/src/main/java/com/hibiscusmc/hmccosmetics/packets/CosmeticPacketInterface.java @@ -191,6 +191,7 @@ public class CosmeticPacketInterface implements PacketInterface { @Override public @NotNull PacketAction readPlayerAction(@NotNull Player player, @NotNull PlayerActionWrapper wrapper) { + if (!Settings.isPreventOffhandSwapping()) return PacketAction.NOTHING; String actionType = wrapper.getActionType(); MessagesUtil.sendDebugMessages("EntityStatus Initial " + player.getEntityId() + " - " + actionType); // If it's not SWAP_ITEM_WITH_OFFHAND, ignore diff --git a/common/src/main/resources/config.yml b/common/src/main/resources/config.yml index 411cbfb0..477999b7 100644 --- a/common/src/main/resources/config.yml +++ b/common/src/main/resources/config.yml @@ -30,6 +30,9 @@ cosmetic-settings: display-name: false lore: false + # This prevents the offhand from being swapped with the mainhand. Only affects if a user has a cosmetic in their offhand + offhand-prevent-swapping: false + # This is a list of worlds that cosmetics are hidden in. When a player enters one of these worlds, their cosmetics will be hidden. disabled-worlds: - "disabledworld"