9
0
mirror of https://github.com/HibiscusMC/HMCCosmetics.git synced 2025-12-30 12:29:16 +00:00

add cosmetic playEmote command

This commit is contained in:
LoJoSho
2023-02-24 10:19:39 -06:00
parent 985e797f83
commit abce477f0d
5 changed files with 58 additions and 10 deletions

View File

@@ -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 <emoteId> [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;
}

View File

@@ -26,7 +26,7 @@ public class CosmeticCommandTabComplete implements TabCompleter {
@Override
public List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String alias, @NotNull String[] args) {
List<String> completions = new ArrayList<>();
List<String> finalCompletitons = new ArrayList<>();
List<String> 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<String> applyCommandComplete(CosmeticUser user, String[] args) {

View File

@@ -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();
}

View File

@@ -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.