diff --git a/build.gradle.kts b/build.gradle.kts index e40ef2af..67470640 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -197,6 +197,12 @@ bukkit { register("hmccosmetics.cmd.emote") { default = BukkitPluginDescription.Permission.Default.TRUE } + register("hmccosmetics.cmd.playemote") { + default = BukkitPluginDescription.Permission.Default.OP + } + register("hmccosmetics.cmd.playemote.other") { + default = BukkitPluginDescription.Permission.Default.OP + } register("hmccosmetics.cmd.emote.other") { default = BukkitPluginDescription.Permission.Default.OP } 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 11278635..63943b83 100644 --- a/common/src/main/java/com/hibiscusmc/hmccosmetics/command/CosmeticCommand.java +++ b/common/src/main/java/com/hibiscusmc/hmccosmetics/command/CosmeticCommand.java @@ -15,6 +15,7 @@ import com.hibiscusmc.hmccosmetics.user.CosmeticUser; import com.hibiscusmc.hmccosmetics.user.CosmeticUsers; import com.hibiscusmc.hmccosmetics.util.MessagesUtil; import com.hibiscusmc.hmccosmetics.util.ServerUtils; +import com.ticxo.playeranimator.api.PlayerAnimator; import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder; import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver; import org.apache.commons.lang3.EnumUtils; @@ -403,6 +404,38 @@ public class CosmeticCommand implements CommandExecutor { cosmeticEmoteType.run(user); return true; } + + case ("playemote") -> { + // /cosmetic playEmote [playerName] + if (!sender.hasPermission("hmccosmetics.cmd.playemote")) { + if (!silent) MessagesUtil.sendMessage(sender, "no-permission"); + return true; + } + + if (args.length < 2) { + if (!silent) MessagesUtil.sendMessage(player, "not-enough-args"); + return true; + } + + if (args.length >= 2) { + if (!PlayerAnimator.api.getAnimationManager().getRegistry().keySet().contains(args[1])) { + MessagesUtil.sendDebugMessages("Did not contain " + args[1]); + if (!silent) MessagesUtil.sendMessage(sender, "emote-invalid"); + return true; + } + } + + if (sender.hasPermission("hmccosmetics.cmd.playemote.other")) { + if (args.length >= 3) player = Bukkit.getPlayer(args[2]); + } + if (player == null) { + if (!silent) MessagesUtil.sendMessage(sender, "invalid-player"); + return true; + } + CosmeticUser user = CosmeticUsers.getUser(player); + user.getUserEmoteManager().playEmote(args[1]); + return true; + } } return true; } 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 a922fa7a..9a66402f 100644 --- a/common/src/main/java/com/hibiscusmc/hmccosmetics/command/CosmeticCommandTabComplete.java +++ b/common/src/main/java/com/hibiscusmc/hmccosmetics/command/CosmeticCommandTabComplete.java @@ -26,7 +26,7 @@ public class CosmeticCommandTabComplete implements TabCompleter { @Override public List onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String alias, @NotNull String[] args) { List completions = new ArrayList<>(); - List finalCompletitons = new ArrayList<>(); + List finalCompletions = new ArrayList<>(); if (args.length == 1) { if (hasPermission(sender, "hmccosmetics.cmd.apply")) completions.add("apply"); @@ -41,8 +41,9 @@ public class CosmeticCommandTabComplete implements TabCompleter { if (hasPermission(sender, "hmccosmetics.cmd.show")) completions.add("show"); if (hasPermission(sender, "hmccosmetics.cmd.debug")) completions.add("debug"); if (hasPermission(sender, "hmccosmetics.cmd.emote")) completions.add("emote"); + if (hasPermission(sender, "hmccosmetics.cmd.playemote")) completions.add("playemote"); - StringUtil.copyPartialMatches(args[0], completions, finalCompletitons); + StringUtil.copyPartialMatches(args[0], completions, finalCompletions); } if (!(sender instanceof Player)) return completions; @@ -79,8 +80,11 @@ public class CosmeticCommandTabComplete implements TabCompleter { completions.add("viewerlocation"); completions.add("leavelocation"); } + case "playemote" -> { + completions.addAll(PlayerAnimator.api.getAnimationManager().getRegistry().keySet()); + } } - StringUtil.copyPartialMatches(args[1], completions, finalCompletitons); + StringUtil.copyPartialMatches(args[1], completions, finalCompletions); } if (args.length == 3) { String subcommand = args[0].toLowerCase(); @@ -88,13 +92,13 @@ public class CosmeticCommandTabComplete implements TabCompleter { case "dye" -> { completions.add("#FFFFFF"); } - case "menu", "apply", "unapply" -> { + case "menu", "apply", "unapply", "playemote" -> { for (Player player : Bukkit.getOnlinePlayers()) { completions.add(player.getName()); } } } - StringUtil.copyPartialMatches(args[2], completions, finalCompletitons); + StringUtil.copyPartialMatches(args[2], completions, finalCompletions); } if (args.length == 4) { @@ -104,11 +108,11 @@ public class CosmeticCommandTabComplete implements TabCompleter { completions.add("#FFFFFF"); } } - StringUtil.copyPartialMatches(args[3], completions, finalCompletitons); + StringUtil.copyPartialMatches(args[3], completions, finalCompletions); } - Collections.sort(finalCompletitons); - return finalCompletitons; + Collections.sort(finalCompletions); + return finalCompletions; } private static List applyCommandComplete(CosmeticUser user, String[] args) { 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 2c64d1b4..b4a9ae4d 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 @@ -15,11 +15,15 @@ public class UserEmoteManager { public void playEmote(CosmeticEmoteType cosmeticEmoteType) { MessagesUtil.sendDebugMessages("playEmote " + cosmeticEmoteType.getAnimationId()); + playEmote(cosmeticEmoteType.getAnimationId()); + } + + public void playEmote(String animationId) { if (isPlayingEmote()) return; if (user.isInWardrobe()) return; try { model = new UserEmoteModel(user); - model.playAnimation(cosmeticEmoteType.getAnimationId()); + model.playAnimation(animationId); } catch (Exception e) { e.printStackTrace(); } 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 26f7f720..0decd824 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 @@ -37,7 +37,8 @@ public class UserEmoteModel extends PlayerModel { @Override public void playAnimation(String id) { - id = id + "." + id + "." + id; // Make into a format that playerAnimator works with. Requires 3 splits. + if (id.contains(":")) id = id.split(":", 2)[1]; + if (!id.contains(".")) id = id + "." + id + "." + id; // Make into a format that playerAnimator works with. Requires 3 splits. super.playAnimation(id); emotePlaying = id; // Add config option that either allows player to move or forces them into a spot.