diff --git a/common/src/main/java/com/hibiscusmc/hmccosmetics/command/CosmeticCommand.java b/common/src/main/java/com/hibiscusmc/hmccosmetics/command/CosmeticCommand.java index 71184d71..46de51df 100644 --- a/common/src/main/java/com/hibiscusmc/hmccosmetics/command/CosmeticCommand.java +++ b/common/src/main/java/com/hibiscusmc/hmccosmetics/command/CosmeticCommand.java @@ -480,7 +480,7 @@ public class CosmeticCommand implements CommandExecutor { return true; } CosmeticUser user = CosmeticUsers.getUser(player); - user.getUserEmoteManager().playEmote(EmoteManager.get(args[1])); + user.getUserEmoteManager().playEmote(args[1]); return true; } } diff --git a/common/src/main/java/com/hibiscusmc/hmccosmetics/cosmetic/types/CosmeticEmoteType.java b/common/src/main/java/com/hibiscusmc/hmccosmetics/cosmetic/types/CosmeticEmoteType.java index 49b6f1d6..e032b0fd 100644 --- a/common/src/main/java/com/hibiscusmc/hmccosmetics/cosmetic/types/CosmeticEmoteType.java +++ b/common/src/main/java/com/hibiscusmc/hmccosmetics/cosmetic/types/CosmeticEmoteType.java @@ -9,11 +9,13 @@ import org.spongepowered.configurate.ConfigurationNode; public class CosmeticEmoteType extends Cosmetic { private final String animationId; + private final String text; public CosmeticEmoteType(String id, ConfigurationNode config) { super(id, config); animationId = config.node("animation").getString(); + text = config.node("text").getString(); MessagesUtil.sendDebugMessages("CosmeticEmoteType Animation id " + animationId); } @@ -29,4 +31,8 @@ public class CosmeticEmoteType extends Cosmetic { public String getAnimationId() { return animationId; } + + public String getText() { + return text; + } } diff --git a/common/src/main/java/com/hibiscusmc/hmccosmetics/nms/NMSHandler.java b/common/src/main/java/com/hibiscusmc/hmccosmetics/nms/NMSHandler.java index 3575efca..722ffbdd 100644 --- a/common/src/main/java/com/hibiscusmc/hmccosmetics/nms/NMSHandler.java +++ b/common/src/main/java/com/hibiscusmc/hmccosmetics/nms/NMSHandler.java @@ -5,6 +5,7 @@ import com.hibiscusmc.hmccosmetics.cosmetic.types.CosmeticBackpackType; import com.hibiscusmc.hmccosmetics.cosmetic.types.CosmeticBalloonType; import com.hibiscusmc.hmccosmetics.user.manager.UserBalloonManager; import com.hibiscusmc.hmccosmetics.user.CosmeticUser; +import net.kyori.adventure.text.Component; import org.bukkit.Location; import org.bukkit.entity.ArmorStand; import org.bukkit.entity.Entity; @@ -27,6 +28,8 @@ public interface NMSHandler { Entity spawnHMCParticleCloud(Location location); + Entity spawnDisplayEntity(Location location, String text); + UserBalloonManager spawnBalloon(CosmeticUser user, CosmeticBalloonType cosmeticBalloonType); void equipmentSlotUpdate( diff --git a/common/src/main/java/com/hibiscusmc/hmccosmetics/user/manager/UserEmoteManager.java b/common/src/main/java/com/hibiscusmc/hmccosmetics/user/manager/UserEmoteManager.java index 6a4237c4..a81774d3 100644 --- a/common/src/main/java/com/hibiscusmc/hmccosmetics/user/manager/UserEmoteManager.java +++ b/common/src/main/java/com/hibiscusmc/hmccosmetics/user/manager/UserEmoteManager.java @@ -4,30 +4,38 @@ import com.hibiscusmc.hmccosmetics.api.PlayerEmoteStartEvent; import com.hibiscusmc.hmccosmetics.api.PlayerEmoteStopEvent; import com.hibiscusmc.hmccosmetics.cosmetic.types.CosmeticEmoteType; import com.hibiscusmc.hmccosmetics.emotes.EmoteManager; +import com.hibiscusmc.hmccosmetics.nms.NMSHandlers; import com.hibiscusmc.hmccosmetics.user.CosmeticUser; import com.hibiscusmc.hmccosmetics.util.MessagesUtil; import org.bukkit.Bukkit; +import org.bukkit.entity.Entity; import org.jetbrains.annotations.NotNull; public class UserEmoteManager { - CosmeticUser user; + private CosmeticUser user; private UserEmoteModel model; + private Entity textEntity; public UserEmoteManager(CosmeticUser user) { this.user = user; } - public void playEmote(@NotNull CosmeticEmoteType cosmeticEmoteType) { - MessagesUtil.sendDebugMessages("playEmote " + cosmeticEmoteType.getAnimationId()); - playEmote(EmoteManager.get(cosmeticEmoteType.getAnimationId())); + public void playEmote(String animationId) { + MessagesUtil.sendDebugMessages("playEmote " + animationId); + playEmote(EmoteManager.get(animationId), null); } - public void playEmote(String animationId) { + public void playEmote(@NotNull CosmeticEmoteType cosmeticEmoteType) { + MessagesUtil.sendDebugMessages("playEmote " + cosmeticEmoteType.getAnimationId()); + playEmote(EmoteManager.get(cosmeticEmoteType.getAnimationId()), cosmeticEmoteType.getText()); + } + + public void playEmote(String emoteAnimation, String text) { if (isPlayingEmote()) return; if (user.isInWardrobe()) return; // API - PlayerEmoteStartEvent event = new PlayerEmoteStartEvent(user, animationId); + PlayerEmoteStartEvent event = new PlayerEmoteStartEvent(user, emoteAnimation); Bukkit.getPluginManager().callEvent(event); if (event.isCancelled()) { return; @@ -35,7 +43,14 @@ public class UserEmoteManager { // Internal try { model = new UserEmoteModel(user); - model.playAnimation(animationId); + // Play animation id + if (emoteAnimation != null) { + model.playAnimation(emoteAnimation); + } + // Show the text + if (text != null && textEntity == null) { + textEntity = NMSHandlers.getHandler().spawnDisplayEntity(user.getPlayer().getLocation().add(0, 3, 0), text); + } } catch (Exception e) { e.printStackTrace(); } @@ -56,6 +71,17 @@ public class UserEmoteManager { } // Internal model.stopAnimation(); + if (textEntity != null) { + textEntity.remove(); + textEntity = null; + } + } + + public void despawnTextEntity() { + if (textEntity != null) { + textEntity.remove(); + textEntity = null; + } } public enum StopEmoteReason { diff --git a/common/src/main/java/com/hibiscusmc/hmccosmetics/user/manager/UserEmoteModel.java b/common/src/main/java/com/hibiscusmc/hmccosmetics/user/manager/UserEmoteModel.java index e7455cf7..6391eaa1 100644 --- a/common/src/main/java/com/hibiscusmc/hmccosmetics/user/manager/UserEmoteModel.java +++ b/common/src/main/java/com/hibiscusmc/hmccosmetics/user/manager/UserEmoteModel.java @@ -36,9 +36,6 @@ public class UserEmoteModel extends PlayerModel { @Override public void playAnimation(@NotNull String id) { - if (id.contains(":")) id = id.split(":", 2)[1]; // A:B -> B -> B.B.B - if (!id.contains(".")) id = id + "." + id + "." + id; // Make into a format that playerAnimator works with. Requires 3 splits. - super.playAnimation(id); emotePlaying = id; @@ -122,6 +119,7 @@ public class UserEmoteModel extends PlayerModel { if (user.getPlayer() != null) player.setInvisible(false); PacketManager.equipmentSlotUpdate(player, false, outsideViewers); + user.getUserEmoteManager().despawnTextEntity(); user.showPlayer(); user.showCosmetics(); }); diff --git a/v1_17_R1/src/main/java/com/hibiscusmc/hmccosmetics/nms/v1_17_R1/NMSHandler.java b/v1_17_R1/src/main/java/com/hibiscusmc/hmccosmetics/nms/v1_17_R1/NMSHandler.java index e5901a56..d39130b0 100644 --- a/v1_17_R1/src/main/java/com/hibiscusmc/hmccosmetics/nms/v1_17_R1/NMSHandler.java +++ b/v1_17_R1/src/main/java/com/hibiscusmc/hmccosmetics/nms/v1_17_R1/NMSHandler.java @@ -13,6 +13,7 @@ import com.hibiscusmc.hmccosmetics.util.MessagesUtil; import com.hibiscusmc.hmccosmetics.util.PlayerUtils; import com.hibiscusmc.hmccosmetics.util.packets.PacketManager; import com.mojang.datafixers.util.Pair; +import net.kyori.adventure.text.Component; import net.minecraft.network.protocol.Packet; import net.minecraft.network.protocol.game.ClientboundContainerSetSlotPacket; import net.minecraft.network.protocol.game.ClientboundSetEquipmentPacket; @@ -97,6 +98,12 @@ public class NMSHandler implements com.hibiscusmc.hmccosmetics.nms.NMSHandler { } + @Override + public org.bukkit.entity.Entity spawnDisplayEntity(Location location, String text) { + return null; + } + + @Override diff --git a/v1_18_R2/src/main/java/com/hibiscusmc/hmccosmetics/nms/v1_18_R2/NMSHandler.java b/v1_18_R2/src/main/java/com/hibiscusmc/hmccosmetics/nms/v1_18_R2/NMSHandler.java index 11e4089e..1ab1763c 100644 --- a/v1_18_R2/src/main/java/com/hibiscusmc/hmccosmetics/nms/v1_18_R2/NMSHandler.java +++ b/v1_18_R2/src/main/java/com/hibiscusmc/hmccosmetics/nms/v1_18_R2/NMSHandler.java @@ -13,6 +13,7 @@ import com.hibiscusmc.hmccosmetics.util.MessagesUtil; import com.hibiscusmc.hmccosmetics.util.PlayerUtils; import com.hibiscusmc.hmccosmetics.util.packets.PacketManager; import com.mojang.datafixers.util.Pair; +import net.kyori.adventure.text.Component; import net.minecraft.network.protocol.Packet; import net.minecraft.network.protocol.game.ClientboundContainerSetSlotPacket; import net.minecraft.network.protocol.game.ClientboundSetEquipmentPacket; @@ -99,6 +100,12 @@ public class NMSHandler implements com.hibiscusmc.hmccosmetics.nms.NMSHandler { } + @Override + public org.bukkit.entity.Entity spawnDisplayEntity(Location location, String text) { + return null; + } + + @Override 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 e72063e2..cceb9d8d 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 @@ -13,6 +13,7 @@ import com.hibiscusmc.hmccosmetics.util.MessagesUtil; import com.hibiscusmc.hmccosmetics.util.PlayerUtils; import com.hibiscusmc.hmccosmetics.util.packets.PacketManager; import com.mojang.datafixers.util.Pair; +import net.kyori.adventure.text.Component; import net.minecraft.network.protocol.Packet; import net.minecraft.network.protocol.game.ClientboundContainerSetSlotPacket; import net.minecraft.network.protocol.game.ClientboundSetEquipmentPacket; @@ -99,6 +100,12 @@ public class NMSHandler implements com.hibiscusmc.hmccosmetics.nms.NMSHandler { } + @Override + public org.bukkit.entity.Entity spawnDisplayEntity(Location location, String text) { + return null; + } + + @Override diff --git a/v1_19_R2/src/main/java/com/hibiscusmc/hmccosmetics/nms/v1_19_R2/NMSHandler.java b/v1_19_R2/src/main/java/com/hibiscusmc/hmccosmetics/nms/v1_19_R2/NMSHandler.java index dd6e80c6..f2cde43e 100644 --- a/v1_19_R2/src/main/java/com/hibiscusmc/hmccosmetics/nms/v1_19_R2/NMSHandler.java +++ b/v1_19_R2/src/main/java/com/hibiscusmc/hmccosmetics/nms/v1_19_R2/NMSHandler.java @@ -13,6 +13,7 @@ import com.hibiscusmc.hmccosmetics.util.MessagesUtil; import com.hibiscusmc.hmccosmetics.util.PlayerUtils; import com.hibiscusmc.hmccosmetics.util.packets.PacketManager; import com.mojang.datafixers.util.Pair; +import net.kyori.adventure.text.Component; import net.minecraft.network.protocol.Packet; import net.minecraft.network.protocol.game.ClientboundContainerSetSlotPacket; import net.minecraft.network.protocol.game.ClientboundSetEquipmentPacket; @@ -99,6 +100,11 @@ public class NMSHandler implements com.hibiscusmc.hmccosmetics.nms.NMSHandler { } + @Override + public org.bukkit.entity.Entity spawnDisplayEntity(Location location, String text) { + return null; + } + @Override diff --git a/v1_19_R3/src/main/java/com/hibiscusmc/hmccosmetics/nms/v1_19_R3/NMSHandler.java b/v1_19_R3/src/main/java/com/hibiscusmc/hmccosmetics/nms/v1_19_R3/NMSHandler.java index 61c8d33a..b0775116 100644 --- a/v1_19_R3/src/main/java/com/hibiscusmc/hmccosmetics/nms/v1_19_R3/NMSHandler.java +++ b/v1_19_R3/src/main/java/com/hibiscusmc/hmccosmetics/nms/v1_19_R3/NMSHandler.java @@ -13,6 +13,7 @@ import com.hibiscusmc.hmccosmetics.util.MessagesUtil; import com.hibiscusmc.hmccosmetics.util.PlayerUtils; import com.hibiscusmc.hmccosmetics.util.packets.PacketManager; import com.mojang.datafixers.util.Pair; +import net.minecraft.network.chat.Component; import net.minecraft.network.protocol.Packet; import net.minecraft.network.protocol.game.ClientboundContainerSetSlotPacket; import net.minecraft.network.protocol.game.ClientboundSetEquipmentPacket; @@ -20,6 +21,7 @@ import net.minecraft.network.protocol.game.ClientboundSetPlayerTeamPacket; import net.minecraft.server.level.ServerLevel; import net.minecraft.server.level.ServerPlayer; import net.minecraft.server.network.ServerPlayerConnection; +import net.minecraft.world.entity.Display; import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.EquipmentSlot; import net.minecraft.world.entity.player.Inventory; @@ -96,10 +98,20 @@ public class NMSHandler implements com.hibiscusmc.hmccosmetics.nms.NMSHandler { return invisibleArmorstand.getBukkitLivingEntity(); //PacketManager.armorStandMetaPacket(invisibleArmorstand.getBukkitEntity(), sentTo); //PacketManager.ridingMountPacket(player.getEntityId(), invisibleArmorstand.getId(), sentTo); - } - + @Override + public org.bukkit.entity.Entity spawnDisplayEntity(Location location, String text) { + Display.TextDisplay entity = new Display.TextDisplay(net.minecraft.world.entity.EntityType.TEXT_DISPLAY, ((CraftWorld) location.getWorld()).getHandle()); + entity.setPos(location.getX(), location.getY(), location.getZ()); + entity.persist = false; + //entity.setText(net.minecraft.network.chat.Component.literal("TEST!")); + entity.setCustomNameVisible(true); + entity.setCustomName(Component.literal(text)); + MessagesUtil.sendDebugMessages("spawnDisplayEntity - " + entity); + ((CraftWorld) location.getWorld()).getHandle().addFreshEntity(entity, CreatureSpawnEvent.SpawnReason.CUSTOM); + return entity.getBukkitEntity(); + } @Override public UserBalloonManager spawnBalloon(CosmeticUser user, CosmeticBalloonType cosmeticBalloonType) {