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 b8da7434..1ebe9310 100644 --- a/common/src/main/java/com/hibiscusmc/hmccosmetics/config/Settings.java +++ b/common/src/main/java/com/hibiscusmc/hmccosmetics/config/Settings.java @@ -2,6 +2,7 @@ package com.hibiscusmc.hmccosmetics.config; import com.hibiscusmc.hmccosmetics.HMCCosmeticsPlugin; import com.hibiscusmc.hmccosmetics.cosmetic.CosmeticSlot; +import com.hibiscusmc.hmccosmetics.util.MessagesUtil; import org.bukkit.inventory.EquipmentSlot; import org.bukkit.util.Vector; import org.spongepowered.configurate.ConfigurationNode; @@ -36,6 +37,10 @@ public class Settings { private static final String HOOK_ITEMADDER_PATH = "itemsadder"; private static final String HOOK_RELOAD_CHANGE_PATH = "reload-on-change"; private static final String COSMETIC_EMOTE_CHECK_PATH = "emote-block-check"; + 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"; + private static final String COSMETIC_ADD_ENCHANTS_BOOTS_PATH = "boots-add-enchantments"; private static String defaultMenu; private static String dyeMenuName; @@ -52,6 +57,10 @@ public class Settings { private static boolean forcePermissionJoin; private static boolean itemsAdderChangeReload; private static boolean cosmeticEmoteBlockCheck; + private static boolean addHelmetEnchants; + private static boolean addChestplateEnchants; + private static boolean addLeggingEnchants; + private static boolean addBootsEnchants; private static int lookDownPitch; private static int viewDistance; private static int tickPeriod; @@ -84,6 +93,10 @@ public class Settings { forcePermissionJoin = cosmeticSettings.node(FORCE_PERMISSION_JOIN_PATH).getBoolean(false); emoteDistance = cosmeticSettings.node(EMOTE_DISTANCE_PATH).getDouble(-3); cosmeticEmoteBlockCheck = cosmeticSettings.node(COSMETIC_EMOTE_CHECK_PATH).getBoolean(true); + addHelmetEnchants = cosmeticSettings.node(COSMETIC_ADD_ENCHANTS_HELMET_PATH).getBoolean(false); + addChestplateEnchants = cosmeticSettings.node(COSMETIC_ADD_ENCHANTS_CHESTPLATE_PATH).getBoolean(false); + addLeggingEnchants = cosmeticSettings.node(COSMETIC_ADD_ENCHANTS_LEGGINGS_PATH).getBoolean(false); + addBootsEnchants = cosmeticSettings.node(COSMETIC_ADD_ENCHANTS_BOOTS_PATH).getBoolean(false); tickPeriod = cosmeticSettings.node(TICK_PERIOD_PATH).getInt(-1); lookDownPitch = cosmeticSettings.node(LOOK_DOWN_PITCH_PATH).getInt(); @@ -227,6 +240,26 @@ public class Settings { return cosmeticEmoteBlockCheck; } + public static boolean getShouldAddEnchants(EquipmentSlot slot) { + switch (slot) { + case HEAD -> { + return addHelmetEnchants; + } + case CHEST -> { + return addChestplateEnchants; + } + case LEGS -> { + return addLeggingEnchants; + } + case FEET -> { + return addBootsEnchants; + } + default -> { + return false; + } + } + } + public static void setDebugMode(boolean newSetting) { debugMode = newSetting; diff --git a/common/src/main/java/com/hibiscusmc/hmccosmetics/cosmetic/types/CosmeticArmorType.java b/common/src/main/java/com/hibiscusmc/hmccosmetics/cosmetic/types/CosmeticArmorType.java index ec9cc150..cebca21e 100644 --- a/common/src/main/java/com/hibiscusmc/hmccosmetics/cosmetic/types/CosmeticArmorType.java +++ b/common/src/main/java/com/hibiscusmc/hmccosmetics/cosmetic/types/CosmeticArmorType.java @@ -1,12 +1,16 @@ package com.hibiscusmc.hmccosmetics.cosmetic.types; +import com.hibiscusmc.hmccosmetics.config.Settings; import com.hibiscusmc.hmccosmetics.cosmetic.Cosmetic; +import com.hibiscusmc.hmccosmetics.nms.NMSHandlers; import com.hibiscusmc.hmccosmetics.user.CosmeticUser; import com.hibiscusmc.hmccosmetics.util.InventoryUtils; +import com.hibiscusmc.hmccosmetics.util.MessagesUtil; import com.hibiscusmc.hmccosmetics.util.packets.PacketManager; import org.bukkit.Bukkit; import org.bukkit.entity.Player; import org.bukkit.inventory.EquipmentSlot; +import org.bukkit.inventory.ItemStack; import org.jetbrains.annotations.NotNull; import org.spongepowered.configurate.ConfigurationNode; @@ -24,10 +28,17 @@ public class CosmeticArmorType extends Cosmetic { public void update(@NotNull CosmeticUser user) { Player player = Bukkit.getPlayer(user.getUniqueId()); if (player == null) return; + ItemStack cosmeticItem = user.getUserCosmeticItem(this); if (equipSlot.equals(EquipmentSlot.OFF_HAND)) { if (!player.getInventory().getItemInOffHand().getType().isAir()) return; } - PacketManager.equipmentSlotUpdate(player, getSlot(), PacketManager.getViewers(player.getLocation())); + ItemStack equippedItem = player.getInventory().getItem(equipSlot); + if (Settings.getShouldAddEnchants(equipSlot)) { + cosmeticItem.addUnsafeEnchantments(equippedItem.getEnchantments()); + } + + NMSHandlers.getHandler().equipmentSlotUpdate(player.getEntityId(), equipSlot, cosmeticItem, PacketManager.getViewers(player.getLocation())); + //PacketManager.equipmentSlotUpdate(player, getSlot(), PacketManager.getViewers(player.getLocation())); Old method } public EquipmentSlot getEquipSlot() { diff --git a/common/src/main/resources/config.yml b/common/src/main/resources/config.yml index ac183714..8824bde7 100644 --- a/common/src/main/resources/config.yml +++ b/common/src/main/resources/config.yml @@ -26,6 +26,11 @@ cosmetic-settings: emote-distance: -3 # This shows how far away the camera should be while a player is doing an emote. Negative is behind player. emote-block-check: true # If the server should check if the block is open (prevents players viewing through blocks) + 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. + leggings-add-enchantments: false # If the plugin should keep enchants on leggings. This is useful as some enchantments are client side only. + boots-add-enchantments: false # If the plugin should keep enchants on boots. This is useful as some enchantments are client side only. + # view distance in blocks that other players will see the backpack cosmetic # setting this to lower than the server player view distance should fix the # bug where players see random backpacks. Put -1 to ignore and send packets to everyone.