diff --git a/build.gradle.kts b/build.gradle.kts index 7fe31d11..ecb396e9 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -32,6 +32,7 @@ allprojects { artifact() } } + maven("https://maven.enginehub.org/repo/") } dependencies { @@ -51,7 +52,8 @@ dependencies { compileOnly("me.clip:placeholderapi:2.11.1") compileOnly("com.ticxo.modelengine:api:R3.0.1") compileOnly("com.github.oraxen:oraxen:-SNAPSHOT") - compileOnly("com.github.LoneDev6:API-ItemsAdder:3.2.5") // TODO Work on this + compileOnly("com.github.LoneDev6:API-ItemsAdder:3.2.5") + compileOnly("com.sk89q.worldguard:worldguard-bukkit:7.1.0-SNAPSHOT") //compileOnly("com.github.Fisher2911:FisherLib:master-SNAPSHOT") implementation("net.kyori:adventure-api:4.11.0") @@ -87,13 +89,13 @@ tasks { dependsOn(":v1_19_R1:reobfJar") mergeServiceFiles() - relocate("dev.triumphteam.gui", "com.hisbiscus.hmccosmetics.gui") - relocate("me.mattstudios.mf", "com.hisbiscus.hmccosmetics.mf") - relocate("net.kyori.adventure", "com.hisbiscus.hmccosmetics.adventure") - relocate("org.spongepowered.configurate", "com.hisbiscus.hmccosmetics.configurate") - relocate("org.bstats", "com.hisbiscus.hmccosmetics.bstats") - relocate("com.zaxxer.hikaricp", "com.hisbiscus.hmccosmetics.hikaricp") - relocate("com.j256.ormlite", "com.hisbiscus.hmccosmetics.ormlite") + relocate("dev.triumphteam.gui", "com.hisbiscusmc.hmccosmetics.gui") + relocate("me.mattstudios.mf", "com.hisbiscusmc.hmccosmetics.mf") + relocate("net.kyori.adventure", "com.hisbiscusmc.hmccosmetics.adventure") + relocate("org.spongepowered.configurate", "com.hisbiscusmc.hmccosmetics.configurate") + relocate("org.bstats", "com.hisbiscusmc.hmccosmetics.bstats") + relocate("com.zaxxer.hikaricp", "com.hisbiscusmc.hmccosmetics.hikaricp") + relocate("com.j256.ormlite", "com.hisbiscusmc.hmccosmetics.ormlite") //relocate("it.unimi.dsi", "com.hisbiscus.hmccosmetics.dsi") archiveFileName.set("HMCCosmetics.jar") @@ -116,7 +118,7 @@ bukkit { apiVersion = "1.19" authors = listOf("LoJoSho") depend = listOf("ProtocolLib") - softDepend = listOf("ModelEngine", "Oraxen", "ItemsAdder", "HMCColor") + softDepend = listOf("ModelEngine", "Oraxen", "ItemsAdder", "HMCColor", "WorldGuard") version = "${project.version}" commands { diff --git a/common/build.gradle.kts b/common/build.gradle.kts index e76d22e4..a5800248 100644 --- a/common/build.gradle.kts +++ b/common/build.gradle.kts @@ -12,6 +12,7 @@ dependencies { compileOnly("com.github.oraxen:oraxen:-SNAPSHOT") compileOnly("com.github.LoneDev6:API-ItemsAdder:3.2.5") compileOnly("com.hibiscus:hmccolor:0.1-SNAPSHOT") + compileOnly("com.sk89q.worldguard:worldguard-bukkit:7.1.0-SNAPSHOT") //compileOnly("com.github.Fisher2911:FisherLib:master-SNAPSHOT") implementation("net.kyori:adventure-api:4.11.0") diff --git a/common/src/main/java/com/hibiscusmc/hmccosmetics/HMCCosmeticsPlugin.java b/common/src/main/java/com/hibiscusmc/hmccosmetics/HMCCosmeticsPlugin.java index 56f805f5..a01c4ec2 100644 --- a/common/src/main/java/com/hibiscusmc/hmccosmetics/HMCCosmeticsPlugin.java +++ b/common/src/main/java/com/hibiscusmc/hmccosmetics/HMCCosmeticsPlugin.java @@ -7,20 +7,18 @@ import com.hibiscusmc.hmccosmetics.config.Settings; import com.hibiscusmc.hmccosmetics.config.WardrobeSettings; import com.hibiscusmc.hmccosmetics.config.serializer.ItemSerializer; import com.hibiscusmc.hmccosmetics.config.serializer.LocationSerializer; -import com.hibiscusmc.hmccosmetics.cosmetic.Cosmetic; import com.hibiscusmc.hmccosmetics.cosmetic.Cosmetics; import com.hibiscusmc.hmccosmetics.database.Database; import com.hibiscusmc.hmccosmetics.gui.Menus; import com.hibiscusmc.hmccosmetics.hooks.PAPIHook; +import com.hibiscusmc.hmccosmetics.hooks.worldguard.WGHook; import com.hibiscusmc.hmccosmetics.hooks.items.ItemHooks; +import com.hibiscusmc.hmccosmetics.hooks.worldguard.WGListener; import com.hibiscusmc.hmccosmetics.listener.PlayerConnectionListener; import com.hibiscusmc.hmccosmetics.listener.PlayerGameListener; import com.hibiscusmc.hmccosmetics.nms.NMSHandlers; -import com.hibiscusmc.hmccosmetics.user.CosmeticUser; -import com.hibiscusmc.hmccosmetics.user.CosmeticUsers; import com.hibiscusmc.hmccosmetics.util.misc.Translation; import org.bukkit.Bukkit; -import org.bukkit.Color; import org.bukkit.Location; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; @@ -74,6 +72,17 @@ public final class HMCCosmeticsPlugin extends JavaPlugin { if (Bukkit.getPluginManager().getPlugin("PlaceholderAPI") != null) { new PAPIHook().register(); } + if (Bukkit.getPluginManager().getPlugin("WorldGuard") != null) { + getServer().getPluginManager().registerEvents(new WGListener(), this); + } + } + + @Override + public void onLoad() { + // WorldGuard + if (Bukkit.getPluginManager().getPlugin("WorldGuard") != null) { + new WGHook(); + } } @Override diff --git a/common/src/main/java/com/hibiscusmc/hmccosmetics/cosmetic/CosmeticSlot.java b/common/src/main/java/com/hibiscusmc/hmccosmetics/cosmetic/CosmeticSlot.java index a405937d..5aff5ede 100644 --- a/common/src/main/java/com/hibiscusmc/hmccosmetics/cosmetic/CosmeticSlot.java +++ b/common/src/main/java/com/hibiscusmc/hmccosmetics/cosmetic/CosmeticSlot.java @@ -5,6 +5,7 @@ public enum CosmeticSlot { CHESTPLATE, LEGGINGS, BOOTS, + MAINHAND, OFFHAND, BACKPACK, BALLOON diff --git a/common/src/main/java/com/hibiscusmc/hmccosmetics/cosmetic/types/CosmeticBalloonType.java b/common/src/main/java/com/hibiscusmc/hmccosmetics/cosmetic/types/CosmeticBalloonType.java index db1b6e51..068b31b0 100644 --- a/common/src/main/java/com/hibiscusmc/hmccosmetics/cosmetic/types/CosmeticBalloonType.java +++ b/common/src/main/java/com/hibiscusmc/hmccosmetics/cosmetic/types/CosmeticBalloonType.java @@ -41,7 +41,6 @@ public class CosmeticBalloonType extends Cosmetic { viewer.add(player); PacketManager.sendTeleportPacket(user.getBalloonEntity().getPufferfishBalloonId(), actual, false, viewer); - PacketManager.sendLeashPacket(user.getBalloonEntity().getPufferfishBalloonId(), player.getEntityId(), viewer); } public String getModelName() { diff --git a/common/src/main/java/com/hibiscusmc/hmccosmetics/cosmetic/types/CosmeticMainhandType.java b/common/src/main/java/com/hibiscusmc/hmccosmetics/cosmetic/types/CosmeticMainhandType.java new file mode 100644 index 00000000..679d6f42 --- /dev/null +++ b/common/src/main/java/com/hibiscusmc/hmccosmetics/cosmetic/types/CosmeticMainhandType.java @@ -0,0 +1,49 @@ +package com.hibiscusmc.hmccosmetics.cosmetic.types; + +import com.hibiscusmc.hmccosmetics.HMCCosmeticsPlugin; +import com.hibiscusmc.hmccosmetics.config.serializer.ItemSerializer; +import com.hibiscusmc.hmccosmetics.cosmetic.Cosmetic; +import com.hibiscusmc.hmccosmetics.user.CosmeticUser; +import com.hibiscusmc.hmccosmetics.util.packets.PacketManager; +import org.bukkit.Material; +import org.bukkit.entity.Player; +import org.bukkit.inventory.ItemStack; +import org.spongepowered.configurate.ConfigurationNode; +import org.spongepowered.configurate.serialize.SerializationException; + +public class CosmeticMainhandType extends Cosmetic { + + private ItemStack itemStack; + + public CosmeticMainhandType(String id, ConfigurationNode config) { + super(id, config); + + this.itemStack = generateItemStack(config.node("item")); + + setEquipable(true); + } + + @Override + public void update(CosmeticUser user) { + Player player = user.getPlayer(); + + } + + private ItemStack generateItemStack(ConfigurationNode config) { + try { + ItemStack item = ItemSerializer.INSTANCE.deserialize(ItemStack.class, config); + if (item == null) { + HMCCosmeticsPlugin.getInstance().getLogger().severe("Unable to create item for " + getId()); + return new ItemStack(Material.AIR); + } + return item; + } catch (SerializationException e) { + HMCCosmeticsPlugin.getInstance().getLogger().severe("Fatal error encountered for " + getId() + " regarding Serialization of item"); + throw new RuntimeException(e); + } + } + + public ItemStack getItemStack() { + return itemStack; + } +} diff --git a/common/src/main/java/com/hibiscusmc/hmccosmetics/entities/BalloonEntity.java b/common/src/main/java/com/hibiscusmc/hmccosmetics/entities/BalloonEntity.java index 08a8d58e..572b5be0 100644 --- a/common/src/main/java/com/hibiscusmc/hmccosmetics/entities/BalloonEntity.java +++ b/common/src/main/java/com/hibiscusmc/hmccosmetics/entities/BalloonEntity.java @@ -68,10 +68,12 @@ public class BalloonEntity { final ModeledEntity model = ModelEngineAPI.api.getModeledEntity(modelEntity.getUniqueId()); if (model == null) { spawnModel(id, color); + HMCCosmeticsPlugin.getInstance().getLogger().info("model is null"); return; } - if (model.getRangeManager().getPlayerInRange().contains(player)) return; + //if (model.getRangeManager().getPlayerInRange().contains(player)) return; model.showToPlayer(player); + HMCCosmeticsPlugin.getInstance().getLogger().info("Show to player"); } public void removePlayerFromModel(final Player player) { final ModeledEntity model = ModelEngineAPI.api.getModeledEntity(modelEntity.getUniqueId()); @@ -79,6 +81,7 @@ public class BalloonEntity { if (model == null) return; model.hideFromPlayer(player); + HMCCosmeticsPlugin.getInstance().getLogger().info("Hidden from player"); } public Entity getModelEntity() { diff --git a/common/src/main/java/com/hibiscusmc/hmccosmetics/hooks/worldguard/WGHook.java b/common/src/main/java/com/hibiscusmc/hmccosmetics/hooks/worldguard/WGHook.java new file mode 100644 index 00000000..a9779e41 --- /dev/null +++ b/common/src/main/java/com/hibiscusmc/hmccosmetics/hooks/worldguard/WGHook.java @@ -0,0 +1,36 @@ +package com.hibiscusmc.hmccosmetics.hooks.worldguard; + +import com.hibiscusmc.hmccosmetics.HMCCosmeticsPlugin; +import com.sk89q.worldguard.WorldGuard; +import com.sk89q.worldguard.protection.flags.Flag; +import com.sk89q.worldguard.protection.flags.StateFlag; +import com.sk89q.worldguard.protection.flags.registry.FlagConflictException; +import com.sk89q.worldguard.protection.flags.registry.FlagRegistry; + +public class WGHook { + + public static StateFlag COSMETIC_ENABLE_FLAG; + + public WGHook() { + FlagRegistry registry = WorldGuard.getInstance().getFlagRegistry(); + try { + StateFlag flag = new StateFlag("cosmetic-enable", false); + registry.register(flag); + COSMETIC_ENABLE_FLAG = flag; // only set + } catch (FlagConflictException e) { + Flag existing = registry.get("cosmetic-enable"); + if (existing instanceof StateFlag) { + COSMETIC_ENABLE_FLAG = (StateFlag) existing; + } else { + HMCCosmeticsPlugin.getInstance().getLogger().severe("WorldGuard Unable to be hooked!"); + // types don't match - this is bad news! some other plugin conflicts with you + // hopefully this never actually happens + } + } + } + + public static StateFlag getCosmeticEnableFlag() { + return COSMETIC_ENABLE_FLAG; + } + +} diff --git a/common/src/main/java/com/hibiscusmc/hmccosmetics/hooks/worldguard/WGListener.java b/common/src/main/java/com/hibiscusmc/hmccosmetics/hooks/worldguard/WGListener.java new file mode 100644 index 00000000..08f96095 --- /dev/null +++ b/common/src/main/java/com/hibiscusmc/hmccosmetics/hooks/worldguard/WGListener.java @@ -0,0 +1,36 @@ +package com.hibiscusmc.hmccosmetics.hooks.worldguard; + +import com.hibiscusmc.hmccosmetics.user.CosmeticUser; +import com.hibiscusmc.hmccosmetics.user.CosmeticUsers; +import com.sk89q.worldedit.bukkit.BukkitAdapter; +import com.sk89q.worldguard.WorldGuard; +import com.sk89q.worldguard.protection.ApplicableRegionSet; +import com.sk89q.worldguard.protection.regions.ProtectedRegion; +import com.sk89q.worldguard.protection.regions.RegionContainer; +import com.sk89q.worldguard.protection.regions.RegionQuery; +import org.bukkit.Location; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.player.PlayerMoveEvent; + +public class WGListener implements Listener { + + @EventHandler + public void onPlayerMove(PlayerMoveEvent event) { + Location location = event.getPlayer().getLocation(); + com.sk89q.worldedit.util.Location loc = BukkitAdapter.adapt(location); + RegionContainer region = WorldGuard.getInstance().getPlatform().getRegionContainer(); + RegionQuery query = region.createQuery(); + ApplicableRegionSet set = query.getApplicableRegions(loc); + // TODO: Add more cosmetics + CosmeticUser user = CosmeticUsers.getUser(event.getPlayer()); + if (set.getRegions().size() == 0) { + user.showCosmetics(); + } + for (ProtectedRegion protectedRegion : set.getRegions()) { + if (protectedRegion.getFlags().containsKey(WGHook.getCosmeticEnableFlag())) { + user.hideCosmetics(); + } + } + } +} diff --git a/common/src/main/java/com/hibiscusmc/hmccosmetics/listener/PlayerConnectionListener.java b/common/src/main/java/com/hibiscusmc/hmccosmetics/listener/PlayerConnectionListener.java index 4af55b16..6b0c0a4b 100644 --- a/common/src/main/java/com/hibiscusmc/hmccosmetics/listener/PlayerConnectionListener.java +++ b/common/src/main/java/com/hibiscusmc/hmccosmetics/listener/PlayerConnectionListener.java @@ -41,7 +41,6 @@ public class PlayerConnectionListener implements Listener { for (Entity entity : event.getPlayer().getPassengers()) { if (entity.getType() == EntityType.ARMOR_STAND) { entity.remove(); - entity.remove(); } } } 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 06bd499f..254f8d77 100644 --- a/common/src/main/java/com/hibiscusmc/hmccosmetics/listener/PlayerGameListener.java +++ b/common/src/main/java/com/hibiscusmc/hmccosmetics/listener/PlayerGameListener.java @@ -24,10 +24,7 @@ import org.bukkit.event.Listener; import org.bukkit.event.entity.EntityDamageEvent; import org.bukkit.event.inventory.ClickType; import org.bukkit.event.inventory.InventoryClickEvent; -import org.bukkit.event.player.PlayerItemDamageEvent; -import org.bukkit.event.player.PlayerMoveEvent; -import org.bukkit.event.player.PlayerTeleportEvent; -import org.bukkit.event.player.PlayerToggleSneakEvent; +import org.bukkit.event.player.*; import org.bukkit.inventory.EquipmentSlot; import org.bukkit.inventory.ItemStack; import org.bukkit.persistence.PersistentDataType; @@ -125,7 +122,9 @@ public class PlayerGameListener implements Listener { @EventHandler public void onPlayerArmorDamage(PlayerItemDamageEvent event) { // Possibly look into cancelling the event, then handling the damage on our own. + if (event.isCancelled()) return; + HMCCosmeticsPlugin.getInstance().getLogger().info("PlayerItemDamageEvent"); int slot = -1; int w = 36; @@ -143,7 +142,10 @@ public class PlayerGameListener implements Listener { CosmeticUser user = CosmeticUsers.getUser(event.getPlayer().getUniqueId()); CosmeticSlot cosmeticSlot = InventoryUtils.BukkitCosmeticSlot(slot); - if (!user.hasCosmeticInSlot(cosmeticSlot)) return; + if (!user.hasCosmeticInSlot(cosmeticSlot)) { + HMCCosmeticsPlugin.getInstance().getLogger().info("No cosmetic in " + cosmeticSlot); + return; + } Bukkit.getScheduler().runTaskLater(HMCCosmeticsPlugin.getInstance(), () -> { HMCCosmeticsPlugin.getInstance().getLogger().info("PlayerItemDamageEvent UpdateCosmetic " + cosmeticSlot); @@ -151,6 +153,14 @@ public class PlayerGameListener implements Listener { }, 2); } + @EventHandler + public void onMainHandSwitch(PlayerChangedMainHandEvent event) { + CosmeticUser user = CosmeticUsers.getUser(event.getPlayer().getUniqueId()); + + // TODO: Mainhand cosmetics + //user.updateCosmetic(CosmeticSlot.MAINHAND); + } + private void registerInventoryClickListener() { ProtocolLibrary.getProtocolManager().addPacketListener(new PacketAdapter(HMCCosmeticsPlugin.getInstance(), ListenerPriority.NORMAL, PacketType.Play.Client.WINDOW_CLICK) { @Override diff --git a/common/src/main/java/com/hibiscusmc/hmccosmetics/user/CosmeticUser.java b/common/src/main/java/com/hibiscusmc/hmccosmetics/user/CosmeticUser.java index 9210383c..e33dc93d 100644 --- a/common/src/main/java/com/hibiscusmc/hmccosmetics/user/CosmeticUser.java +++ b/common/src/main/java/com/hibiscusmc/hmccosmetics/user/CosmeticUser.java @@ -9,6 +9,7 @@ import com.hibiscusmc.hmccosmetics.cosmetic.types.CosmeticBackpackType; import com.hibiscusmc.hmccosmetics.cosmetic.types.CosmeticBalloonType; import com.hibiscusmc.hmccosmetics.entities.BalloonEntity; import com.hibiscusmc.hmccosmetics.nms.NMSHandlers; +import com.hibiscusmc.hmccosmetics.util.InventoryUtils; import com.hibiscusmc.hmccosmetics.util.PlayerUtils; import com.hibiscusmc.hmccosmetics.util.packets.PacketManager; import org.bukkit.Bukkit; @@ -33,8 +34,14 @@ public class CosmeticUser { // Cosmetic Settings/Toggles private boolean hideBackpack; + private boolean hideCosmetics; private HashMap colors = new HashMap<>(); + public CosmeticUser() { + hideBackpack = false; + hideCosmetics = false; + } + public CosmeticUser(UUID uuid) { this.uniqueId = uuid; @@ -129,6 +136,9 @@ public class CosmeticUser { public ItemStack getUserCosmeticItem(Cosmetic cosmetic) { ItemStack item = null; + if (hideCosmetics) { + return getPlayer().getInventory().getItem(InventoryUtils.getEquipmentSlot(cosmetic.getSlot())); + } if (cosmetic instanceof CosmeticArmorType) { CosmeticArmorType cosmetic1 = (CosmeticArmorType) cosmetic; item = cosmetic1.getCosmeticItem(); @@ -210,6 +220,11 @@ public class CosmeticUser { if (this.balloonEntity != null) return; this.balloonEntity = NMSHandlers.getHandler().spawnBalloon(this, cosmeticBalloonType); + + List viewer = PlayerUtils.getNearbyPlayers(player); + viewer.add(player); + + PacketManager.sendLeashPacket(getBalloonEntity().getPufferfishBalloonId(), player.getEntityId(), viewer); } public void despawnBalloon() { @@ -296,4 +311,39 @@ public class CosmeticUser { hideBackpack = false; } } + + public void hideCosmetics() { + if (hideCosmetics == true) return; + hideCosmetics = true; + if (hasCosmeticInSlot(CosmeticSlot.BALLOON)) { + getBalloonEntity().removePlayerFromModel(getPlayer()); + List viewer = PlayerUtils.getNearbyPlayers(getPlayer()); + PacketManager.sendLeashPacket(getBalloonEntity().getPufferfishBalloonId(), -1, viewer); + } + if (hasCosmeticInSlot(CosmeticSlot.BACKPACK)) { + //CosmeticBackpackType cosmeticBackpackType = (CosmeticBackpackType) getCosmetic(CosmeticSlot.BACKPACK); + getPlayer().removePassenger(invisibleArmorstand); + invisibleArmorstand.getEquipment().clear(); + } + updateCosmetic(); + HMCCosmeticsPlugin.getInstance().getLogger().info("HideCosmetics"); + } + + public void showCosmetics() { + if (hideCosmetics == false) return; + hideCosmetics = false; + if (hasCosmeticInSlot(CosmeticSlot.BALLOON)) { + CosmeticBalloonType balloonType = (CosmeticBalloonType) getCosmetic(CosmeticSlot.BALLOON); + getBalloonEntity().addPlayerToModel(getPlayer(), balloonType.getModelName()); + List viewer = PlayerUtils.getNearbyPlayers(getPlayer()); + PacketManager.sendLeashPacket(getBalloonEntity().getPufferfishBalloonId(), getPlayer().getEntityId(), viewer); + } + if (hasCosmeticInSlot(CosmeticSlot.BACKPACK)) { + CosmeticBackpackType cosmeticBackpackType = (CosmeticBackpackType) getCosmetic(CosmeticSlot.BACKPACK); + ItemStack item = getUserCosmeticItem(cosmeticBackpackType); + invisibleArmorstand.getEquipment().setHelmet(item); + } + updateCosmetic(); + HMCCosmeticsPlugin.getInstance().getLogger().info("ShowCosmetics"); + } } diff --git a/common/src/main/java/com/hibiscusmc/hmccosmetics/util/InventoryUtils.java b/common/src/main/java/com/hibiscusmc/hmccosmetics/util/InventoryUtils.java index cef8ea20..ae48ceec 100644 --- a/common/src/main/java/com/hibiscusmc/hmccosmetics/util/InventoryUtils.java +++ b/common/src/main/java/com/hibiscusmc/hmccosmetics/util/InventoryUtils.java @@ -48,6 +48,7 @@ public class InventoryUtils { public static CosmeticSlot BukkitCosmeticSlot(EquipmentSlot slot) { return switch (slot) { + case HAND -> CosmeticSlot.MAINHAND; case OFF_HAND -> CosmeticSlot.OFFHAND; case FEET -> CosmeticSlot.BOOTS; case LEGS -> CosmeticSlot.LEGGINGS; @@ -59,16 +60,16 @@ public class InventoryUtils { public static CosmeticSlot BukkitCosmeticSlot(int slot) { switch (slot) { - case 39 -> { + case 36 -> { return CosmeticSlot.HELMET; } - case 38 -> { + case 37 -> { return CosmeticSlot.CHESTPLATE; } - case 37 -> { + case 38 -> { return CosmeticSlot.LEGGINGS; } - case 36 -> { + case 39 -> { return CosmeticSlot.BOOTS; } case 40 -> { diff --git a/common/src/main/java/com/hibiscusmc/hmccosmetics/util/packets/PacketManager.java b/common/src/main/java/com/hibiscusmc/hmccosmetics/util/packets/PacketManager.java index d4d03d6b..0c147cb7 100644 --- a/common/src/main/java/com/hibiscusmc/hmccosmetics/util/packets/PacketManager.java +++ b/common/src/main/java/com/hibiscusmc/hmccosmetics/util/packets/PacketManager.java @@ -16,6 +16,7 @@ import org.bukkit.Location; import org.bukkit.entity.Entity; import org.bukkit.entity.EntityType; import org.bukkit.entity.Player; +import org.bukkit.inventory.EquipmentSlot; import java.util.List; import java.util.UUID; @@ -89,7 +90,6 @@ public class PacketManager extends BasePacket { if (cosmeticSlot == CosmeticSlot.BACKPACK || cosmeticSlot == CosmeticSlot.BALLOON) return; NMSHandlers.getHandler().equipmentSlotUpdate(entityId, user, cosmeticSlot, sendTo); - } public static void armorStandMetaPacket( diff --git a/v1_19_R1/src/main/java/com/hibiscusmc/hmccosmetics/nms/v1_19_R1/NMSHandler.java b/v1_19_R1/src/main/java/com/hibiscusmc/hmccosmetics/nms/v1_19_R1/NMSHandler.java index 35a7f3e4..fe5ed4a8 100644 --- a/v1_19_R1/src/main/java/com/hibiscusmc/hmccosmetics/nms/v1_19_R1/NMSHandler.java +++ b/v1_19_R1/src/main/java/com/hibiscusmc/hmccosmetics/nms/v1_19_R1/NMSHandler.java @@ -6,6 +6,7 @@ import com.hibiscusmc.hmccosmetics.cosmetic.CosmeticSlot; import com.hibiscusmc.hmccosmetics.cosmetic.types.CosmeticArmorType; import com.hibiscusmc.hmccosmetics.cosmetic.types.CosmeticBackpackType; import com.hibiscusmc.hmccosmetics.cosmetic.types.CosmeticBalloonType; +import com.hibiscusmc.hmccosmetics.cosmetic.types.CosmeticMainhandType; import com.hibiscusmc.hmccosmetics.entities.BalloonEntity; import com.hibiscusmc.hmccosmetics.user.CosmeticUser; import com.hibiscusmc.hmccosmetics.util.InventoryUtils; @@ -120,7 +121,7 @@ public class NMSHandler implements com.hibiscusmc.hmccosmetics.nms.NMSHandler { if (!(user.getCosmetic(cosmeticSlot) instanceof CosmeticArmorType)) { nmsSlot = CraftEquipmentSlot.getNMS(InventoryUtils.getEquipmentSlot(cosmeticSlot)); - nmsItem = CraftItemStack.asNMSCopy(new org.bukkit.inventory.ItemStack(Material.AIR)); + nmsItem = CraftItemStack.asNMSCopy(user.getPlayer().getInventory().getItem(InventoryUtils.getEquipmentSlot(cosmeticSlot))); Pair pair = new Pair<>(nmsSlot, nmsItem); @@ -146,6 +147,29 @@ public class NMSHandler implements com.hibiscusmc.hmccosmetics.nms.NMSHandler { for (Player p : sendTo) sendPacket(p, packet); } + public void equipmentSlotUpdate( + int entityId, + CosmeticUser user, + org.bukkit.inventory.EquipmentSlot slot, + List sendTo + ) { + EquipmentSlot nmsSlot = null; + net.minecraft.world.item.ItemStack nmsItem = null; + + CosmeticMainhandType cosmetic = (CosmeticMainhandType) user.getCosmetic(CosmeticSlot.MAINHAND); + ItemStack item = new ItemStack(Material.AIR); //cosmetic.getItem() + + nmsSlot = CraftEquipmentSlot.getNMS(slot); + nmsItem = CraftItemStack.asNMSCopy(item); + + Pair pair = new Pair<>(nmsSlot, nmsItem); + + List> pairs = Collections.singletonList(pair); + + ClientboundSetEquipmentPacket packet = new ClientboundSetEquipmentPacket(entityId, pairs); + for (Player p : sendTo) sendPacket(p, packet); + } + public void sendPacket(Player player, Packet packet) { ServerPlayer serverPlayer = ((CraftPlayer) player).getHandle(); ServerPlayerConnection connection = serverPlayer.connection;