From 9f0dc320e886167bc8e79f8e98cbb588d03dbade Mon Sep 17 00:00:00 2001 From: LoJoSho Date: Fri, 9 Dec 2022 11:37:32 -0600 Subject: [PATCH] Work on Balloon dyeing --- .../command/CosmeticCommandTabComplete.java | 8 +++++-- .../hmccosmetics/cosmetic/Cosmetic.java | 3 ++- .../hmccosmetics/entities/BalloonEntity.java | 17 ++++++++++++-- .../hmccosmetics/gui/special/DyeMenu.java | 2 +- .../hmccosmetics/user/CosmeticUser.java | 23 +++++++++++++++---- .../hmccosmetics/user/CosmeticUsers.java | 2 +- .../hmccosmetics/nms/v1_19_R1/NMSHandler.java | 5 ++-- 7 files changed, 47 insertions(+), 13 deletions(-) diff --git a/common/src/main/java/com/hibiscusmc/hmccosmetics/command/CosmeticCommandTabComplete.java b/common/src/main/java/com/hibiscusmc/hmccosmetics/command/CosmeticCommandTabComplete.java index 790e831d..389f4d0a 100644 --- a/common/src/main/java/com/hibiscusmc/hmccosmetics/command/CosmeticCommandTabComplete.java +++ b/common/src/main/java/com/hibiscusmc/hmccosmetics/command/CosmeticCommandTabComplete.java @@ -3,6 +3,8 @@ package com.hibiscusmc.hmccosmetics.command; import com.hibiscusmc.hmccosmetics.cosmetic.CosmeticSlot; import com.hibiscusmc.hmccosmetics.cosmetic.Cosmetics; import com.hibiscusmc.hmccosmetics.gui.Menus; +import com.hibiscusmc.hmccosmetics.user.CosmeticUser; +import com.hibiscusmc.hmccosmetics.user.CosmeticUsers; import org.bukkit.Bukkit; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; @@ -12,7 +14,6 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import java.util.ArrayList; -import java.util.Arrays; import java.util.Collections; import java.util.List; @@ -32,6 +33,9 @@ public class CosmeticCommandTabComplete implements TabCompleter { completions.add("dye"); } + if (!(sender instanceof Player)) return completions; + CosmeticUser user = CosmeticUsers.getUser(((Player) sender).getUniqueId()); + // This needs to be redone. if (args.length >= 2) { if (args[0].equalsIgnoreCase("apply")) { @@ -47,7 +51,7 @@ public class CosmeticCommandTabComplete implements TabCompleter { completions.add(player.getName()); } } else if (args[0].equalsIgnoreCase("dye")) { - for (CosmeticSlot slot : CosmeticSlot.values()) { + for (CosmeticSlot slot : user.getDyeableSlots()) { completions.add(slot.name()); } } diff --git a/common/src/main/java/com/hibiscusmc/hmccosmetics/cosmetic/Cosmetic.java b/common/src/main/java/com/hibiscusmc/hmccosmetics/cosmetic/Cosmetic.java index ba8a0e83..4ea1e6c9 100644 --- a/common/src/main/java/com/hibiscusmc/hmccosmetics/cosmetic/Cosmetic.java +++ b/common/src/main/java/com/hibiscusmc/hmccosmetics/cosmetic/Cosmetic.java @@ -21,6 +21,8 @@ public class Cosmetic { setEquipable(false); setDyable(config.node("dyeable").getBoolean(false)); + HMCCosmeticsPlugin.getInstance().getLogger().info("Dyeable " + dyable); + Cosmetics.addCosmetic(this); } @@ -71,5 +73,4 @@ public class Cosmetic { public void update(CosmeticUser user) { // Override } - } 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 425f0193..08a8d58e 100644 --- a/common/src/main/java/com/hibiscusmc/hmccosmetics/entities/BalloonEntity.java +++ b/common/src/main/java/com/hibiscusmc/hmccosmetics/entities/BalloonEntity.java @@ -7,6 +7,9 @@ import com.hibiscusmc.hmccosmetics.nms.NMSHandlers; import com.ticxo.modelengine.api.ModelEngineAPI; import com.ticxo.modelengine.api.model.ActiveModel; import com.ticxo.modelengine.api.model.ModeledEntity; +import com.ticxo.modelengine.api.nms.entity.fake.BoneRenderer; +import com.ticxo.modelengine.api.nms.entity.fake.FakeEntity; +import org.bukkit.Color; import org.bukkit.Location; import org.bukkit.entity.Entity; import org.bukkit.entity.Player; @@ -27,7 +30,7 @@ public class BalloonEntity { this.modelEntity = NMSHandlers.getHandler().getMEGEntity(location.add(Settings.getBalloonOffset())); } - public void spawnModel(final String id) { + public void spawnModel(final String id, Color color) { HMCCosmeticsPlugin.getInstance().getLogger().info("Attempting Spawning for " + id); if (ModelEngineAPI.api.getModelRegistry().getBlueprint(id) == null) { HMCCosmeticsPlugin.getInstance().getLogger().warning("Invalid Model Engine Blueprint " + id); @@ -36,6 +39,11 @@ public class BalloonEntity { ModeledEntity modeledEntity = ModelEngineAPI.getOrCreateModeledEntity(modelEntity); ActiveModel model = ModelEngineAPI.createActiveModel(ModelEngineAPI.getBlueprint(id)); modeledEntity.addModel(model, false); + if (color != null) { + modeledEntity.getModels().forEach((d, singleModel) -> { + singleModel.getRendererHandler().setColor(color); + }); + } } public void remove() { @@ -49,12 +57,17 @@ public class BalloonEntity { //ModelEngineAPI.removeModeledEntity(megEntity.getUniqueId()); entity.destroy(); + modelEntity.remove(); } public void addPlayerToModel(final Player player, final String id) { + addPlayerToModel(player, id, null); + } + + public void addPlayerToModel(final Player player, final String id, Color color) { final ModeledEntity model = ModelEngineAPI.api.getModeledEntity(modelEntity.getUniqueId()); if (model == null) { - spawnModel(id); + spawnModel(id, color); return; } if (model.getRangeManager().getPlayerInRange().contains(player)) return; diff --git a/common/src/main/java/com/hibiscusmc/hmccosmetics/gui/special/DyeMenu.java b/common/src/main/java/com/hibiscusmc/hmccosmetics/gui/special/DyeMenu.java index 1b9b165e..3f41d729 100644 --- a/common/src/main/java/com/hibiscusmc/hmccosmetics/gui/special/DyeMenu.java +++ b/common/src/main/java/com/hibiscusmc/hmccosmetics/gui/special/DyeMenu.java @@ -5,6 +5,7 @@ import com.hibiscusmc.hmccolor.gui.guis.Gui; import com.hibiscusmc.hmccolor.gui.guis.GuiItem; import com.hibiscusmc.hmccosmetics.config.Settings; import com.hibiscusmc.hmccosmetics.cosmetic.Cosmetic; +import com.hibiscusmc.hmccosmetics.cosmetic.types.CosmeticBalloonType; import com.hibiscusmc.hmccosmetics.user.CosmeticUser; import com.hibiscusmc.hmccosmetics.util.misc.Placeholder; import org.bukkit.Color; @@ -20,7 +21,6 @@ public class DyeMenu { public static void openMenu(CosmeticUser user, Cosmetic cosmetic) { - ItemStack originalItem = user.getUserCosmeticItem(cosmetic); if (originalItem == null || !cosmetic.isDyable()) return; 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 cfe59f79..f879dc6e 100644 --- a/common/src/main/java/com/hibiscusmc/hmccosmetics/user/CosmeticUser.java +++ b/common/src/main/java/com/hibiscusmc/hmccosmetics/user/CosmeticUser.java @@ -13,6 +13,7 @@ import com.hibiscusmc.hmccosmetics.util.PlayerUtils; import com.hibiscusmc.hmccosmetics.util.packets.PacketManager; import org.bukkit.Bukkit; import org.bukkit.Color; +import org.bukkit.Material; import org.bukkit.entity.ArmorStand; import org.bukkit.entity.Entity; import org.bukkit.entity.Player; @@ -20,10 +21,7 @@ import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.ItemMeta; import org.bukkit.inventory.meta.LeatherArmorMeta; -import java.util.Collection; -import java.util.HashMap; -import java.util.List; -import java.util.UUID; +import java.util.*; public class CosmeticUser { @@ -141,6 +139,9 @@ public class CosmeticUser { item = cosmetic1.getBackpackItem(); HMCCosmeticsPlugin.getInstance().getLogger().info("GetUserCosemticUser Backpack"); } + if (cosmetic instanceof CosmeticBalloonType) { + item = new ItemStack(Material.LEATHER_HORSE_ARMOR); + } if (item == null) { HMCCosmeticsPlugin.getInstance().getLogger().info("GetUserCosemticUser Item is null"); return null; @@ -238,6 +239,20 @@ public class CosmeticUser { return Bukkit.getPlayer(uniqueId); } + public Color getCosmeticColor(CosmeticSlot slot) { + return colors.get(slot); + } + + public List getDyeableSlots() { + ArrayList dyableSlots = new ArrayList(); + + for (Cosmetic cosmetic : getCosmetic()) { + if (cosmetic.isDyable()) dyableSlots.add(cosmetic.getSlot()); + } + + return dyableSlots; + } + public boolean hasCosmetic(Cosmetic cosmetic) { if (!cosmetic.requiresPermission()) return true; if (getPlayer().hasPermission(cosmetic.getPermission())) return true; diff --git a/common/src/main/java/com/hibiscusmc/hmccosmetics/user/CosmeticUsers.java b/common/src/main/java/com/hibiscusmc/hmccosmetics/user/CosmeticUsers.java index 19e90328..052c4ce9 100644 --- a/common/src/main/java/com/hibiscusmc/hmccosmetics/user/CosmeticUsers.java +++ b/common/src/main/java/com/hibiscusmc/hmccosmetics/user/CosmeticUsers.java @@ -44,7 +44,7 @@ public class CosmeticUsers { if (entity.getType().equals(EntityType.PLAYER)) return null; return COSMETIC_USERS.get(entity.getUniqueId()); } - + public static CosmeticUser getUser(String playerName) { return getUser(Bukkit.getPlayer(playerName).getUniqueId()); } 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 abeb6cda..e0052d9c 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 @@ -2,6 +2,7 @@ package com.hibiscusmc.hmccosmetics.nms.v1_19_R1; import com.hibiscusmc.hmccosmetics.HMCCosmeticsPlugin; import com.hibiscusmc.hmccosmetics.config.Settings; +import com.hibiscusmc.hmccosmetics.cosmetic.CosmeticSlot; import com.hibiscusmc.hmccosmetics.cosmetic.types.CosmeticBackpackType; import com.hibiscusmc.hmccosmetics.cosmetic.types.CosmeticBalloonType; import com.hibiscusmc.hmccosmetics.entities.BalloonEntity; @@ -89,8 +90,8 @@ public class NMSHandler implements com.hibiscusmc.hmccosmetics.nms.NMSHandler { List sentTo = PlayerUtils.getNearbyPlayers(player.getLocation()); balloonEntity1.getModelEntity().teleport(user.getPlayer().getLocation().add(Settings.getBalloonOffset())); - balloonEntity1.spawnModel(cosmeticBalloonType.getModelName()); - balloonEntity1.addPlayerToModel(player, cosmeticBalloonType.getModelName()); + balloonEntity1.spawnModel(cosmeticBalloonType.getModelName(), user.getCosmeticColor(cosmeticBalloonType.getSlot())); + balloonEntity1.addPlayerToModel(player, cosmeticBalloonType.getModelName(), user.getCosmeticColor(cosmeticBalloonType.getSlot())); PacketManager.sendEntitySpawnPacket(newLoc, balloonEntity1.getPufferfishBalloonId(), EntityType.PUFFERFISH, balloonEntity1.getPufferfishBalloonUniqueId(), sentTo); PacketManager.sendInvisibilityPacket(balloonEntity1.getPufferfishBalloonId(), sentTo);