From cfbf74257b6c7259b45501ea39c31ac29871cefd Mon Sep 17 00:00:00 2001 From: LoJoSho Date: Sun, 27 Aug 2023 20:59:56 -0500 Subject: [PATCH] feat: add offhand-always-show option --- .../com/hibiscusmc/hmccosmetics/config/Settings.java | 4 ++++ .../hmccosmetics/listener/PlayerGameListener.java | 12 ++++-------- common/src/main/resources/config.yml | 3 +++ 3 files changed, 11 insertions(+), 8 deletions(-) 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 350e7d9b..95a82d3f 100644 --- a/common/src/main/java/com/hibiscusmc/hmccosmetics/config/Settings.java +++ b/common/src/main/java/com/hibiscusmc/hmccosmetics/config/Settings.java @@ -41,6 +41,7 @@ public class Settings { private static final String COSMETIC_EMOTE_MOVE_CHECK_PATH = "emote-move"; private static final String COSMETIC_PACKET_ENTITY_TELEPORT_COOLDOWN_PATH = "entity-cooldown-teleport-packet"; private static final String COSMETIC_BACKPACK_FORCE_RIDING_PACKET_PATH = "backpack-force-riding-packet"; + private static final String COSMETIC_FORCE_OFFHAND_COSMETIC_SHOW_PATH = "offhand-always-show"; private static final String COSMETIC_ADD_ENCHANTS_HELMET_PATH = "helmet-add-enchantments"; private static final String COSMETIC_ADD_ENCHANTS_CHESTPLATE_PATH = "chest-add-enchantments"; private static final String COSMETIC_ADD_ENCHANTS_LEGGINGS_PATH = "leggings-add-enchantments"; @@ -104,6 +105,8 @@ public class Settings { @Getter private static boolean backpackForceRidingEnabled; @Getter + private static boolean cosmeticForceOffhandCosmeticShow; + @Getter private static int viewDistance; @Getter private static int tickPeriod; @@ -177,6 +180,7 @@ public class Settings { emoteCameraEnabled = cosmeticSettings.node(COSMETIC_EMOTE_CAMERA_PATH).getBoolean(true); emoteMoveCheck = cosmeticSettings.node(COSMETIC_EMOTE_MOVE_CHECK_PATH).getBoolean(false); packetEntityTeleportCooldown = cosmeticSettings.node(COSMETIC_PACKET_ENTITY_TELEPORT_COOLDOWN_PATH).getInt(-1); + cosmeticForceOffhandCosmeticShow = cosmeticSettings.node(COSMETIC_FORCE_OFFHAND_COSMETIC_SHOW_PATH).getBoolean(false); ConfigurationNode menuSettings = source.node(MENU_SETTINGS_PATH); diff --git a/common/src/main/java/com/hibiscusmc/hmccosmetics/listener/PlayerGameListener.java b/common/src/main/java/com/hibiscusmc/hmccosmetics/listener/PlayerGameListener.java index 83cdb317..796afbaf 100644 --- a/common/src/main/java/com/hibiscusmc/hmccosmetics/listener/PlayerGameListener.java +++ b/common/src/main/java/com/hibiscusmc/hmccosmetics/listener/PlayerGameListener.java @@ -480,7 +480,6 @@ public class PlayerGameListener implements Listener { if (user == null) { return; } - List> armor = event.getPacket().getSlotStackPairLists().read(0); for (EquipmentSlot equipmentSlot : EquipmentSlot.values()) { @@ -490,14 +489,11 @@ public class PlayerGameListener implements Listener { continue; } if (equipmentSlot.equals(EquipmentSlot.OFF_HAND)) { - ItemStack item = null; - if (user.getPlayer().getInventory().getItemInOffHand().getType().isAir()) { - if (user.hasCosmeticInSlot(CosmeticSlot.OFFHAND)) item = user.getUserCosmeticItem(CosmeticSlot.OFFHAND); - } else { - item = user.getPlayer().getInventory().getItemInOffHand(); + if (Settings.isCosmeticForceOffhandCosmeticShow() && user.hasCosmeticInSlot(CosmeticSlot.OFFHAND)) { + ItemStack item = user.getUserCosmeticItem(CosmeticSlot.OFFHAND); + Pair pair = new Pair<>(EnumWrappers.ItemSlot.OFFHAND, item); + armor.add(pair); } - Pair pair = new Pair<>(EnumWrappers.ItemSlot.OFFHAND, item); - armor.add(pair); continue; } CosmeticArmorType cosmeticArmor = (CosmeticArmorType) user.getCosmetic(InventoryUtils.BukkitCosmeticSlot(equipmentSlot)); diff --git a/common/src/main/resources/config.yml b/common/src/main/resources/config.yml index d7f60c72..fa4eb713 100644 --- a/common/src/main/resources/config.yml +++ b/common/src/main/resources/config.yml @@ -38,6 +38,9 @@ cosmetic-settings: # This helps reduce the amount of packets sent for packet entities, but reduces accuracy of the entity. This is in milliseconds. -1 to disable. # This is useful for servers with a lot of backpacks, as they are passengers, which means the client will update their position automatically within an area where the entity is located. entity-cooldown-teleport-packet: 500 + # This forces the offhand to always show the cosmetic. False means it will only show when the slot is empty. + # There is a small visual blip for a tick when you put a new item in the offhand slot, hence why its disabled by default. + offhand-always-show: false helmet-add-enchantments: false # If the plugin should keep enchants on helmets. This is useful as some enchantments are client side only. chest-add-enchantments: false # If the plugin should keep enchants on chestplate. This is useful as some enchantments are client side only.