diff --git a/common/src/main/java/com/hibiscusmc/hmccosmetics/HMCCosmeticsPlugin.java b/common/src/main/java/com/hibiscusmc/hmccosmetics/HMCCosmeticsPlugin.java index d0ce232b..7aa907a6 100644 --- a/common/src/main/java/com/hibiscusmc/hmccosmetics/HMCCosmeticsPlugin.java +++ b/common/src/main/java/com/hibiscusmc/hmccosmetics/HMCCosmeticsPlugin.java @@ -20,7 +20,6 @@ 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.user.manager.UserEmoteManager; import com.hibiscusmc.hmccosmetics.util.MessagesUtil; import com.hibiscusmc.hmccosmetics.util.TranslationUtil; import com.jeff_media.updatechecker.UpdateCheckSource; @@ -44,6 +43,8 @@ import org.spongepowered.configurate.yaml.YamlConfigurationLoader; import java.io.File; import java.nio.file.Path; +import java.util.Arrays; +import java.util.HashMap; import java.util.Map; public final class HMCCosmeticsPlugin extends JavaPlugin { @@ -55,6 +56,7 @@ public final class HMCCosmeticsPlugin extends JavaPlugin { private static boolean hasModelEngine = false; private static boolean onLatestVersion = true; private static String latestVersion = ""; + private static final Map emoteMap = new HashMap<>(); @Override public void onEnable() { @@ -241,23 +243,7 @@ public final class HMCCosmeticsPlugin extends JavaPlugin { } } - File emoteFolder = new File(getInstance().getDataFolder().getPath() + "/emotes/"); - if (emoteFolder.exists()) { - PlayerAnimator.api.getAnimationManager().clearRegistry(); - File[] emotesFiles = emoteFolder.listFiles(); - for (File emoteFile : emotesFiles) { - if (!emoteFile.getName().contains("bbmodel")) continue; - String animationName = FilenameUtils.removeExtension(emoteFile.getName()); - PlayerAnimator.api.getAnimationManager().importAnimations(animationName, emoteFile); - MessagesUtil.sendDebugMessages("Added '" + animationName + "' to Player Animator "); - } - - /* - for (Map.Entry packEntry : PlayerAnimator.api.getAnimationManager().getRegistry().entrySet()) { - Set animationNames = packEntry.getValue().getAnimations().keySet().stream().map(animation -> packEntry.getKey().replace(":", ".") + "." + animation).collect(Collectors.toSet()); - } - */ - } + loadEmotes(); getInstance().getLogger().info("Successfully Enabled HMCCosmetics"); getInstance().getLogger().info(Cosmetics.values().size() + " Cosmetics Successfully Setup"); @@ -293,4 +279,31 @@ public final class HMCCosmeticsPlugin extends JavaPlugin { public static String getLatestVersion() { return latestVersion; } + + private static void loadEmotes() { + File emoteDir = new File(getInstance().getDataFolder().getPath() + "/emotes/"); + if (!emoteDir.exists()) return; + + File[] emoteFiles = emoteDir.listFiles(); + if (emoteFiles == null || emoteFiles.length == 0) return; + + emoteFiles = Arrays.stream(emoteFiles).filter(file -> file.getPath().endsWith(".bbmodel")).distinct().toArray(File[]::new); + if (emoteFiles.length == 0) return; + + for (File animationFile : emoteFiles) { + String animationKey = FilenameUtils.removeExtension(animationFile.getName()); + PlayerAnimator.api.getAnimationManager().importAnimations(animationKey, animationFile); + } + + for (Map.Entry packEntry : PlayerAnimator.api.getAnimationManager().getRegistry().entrySet()) { + packEntry.getValue().getAnimations().keySet().forEach(animation -> { + String key = packEntry.getKey().replace(":", ".") + "." + animation; + emoteMap.put(animation, key); + }); + } + } + + public static Map getEmoteMap() { + return emoteMap; + } } 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 46f65cd7..42f966ce 100644 --- a/common/src/main/java/com/hibiscusmc/hmccosmetics/command/CosmeticCommand.java +++ b/common/src/main/java/com/hibiscusmc/hmccosmetics/command/CosmeticCommand.java @@ -429,7 +429,7 @@ public class CosmeticCommand implements CommandExecutor { } if (args.length >= 2) { - if (!PlayerAnimator.api.getAnimationManager().getRegistry().keySet().contains(args[1])) { + if (!HMCCosmeticsPlugin.getEmoteMap().containsKey(args[1])) { MessagesUtil.sendDebugMessages("Did not contain " + args[1]); if (!silent) MessagesUtil.sendMessage(sender, "emote-invalid"); return true; @@ -444,7 +444,7 @@ public class CosmeticCommand implements CommandExecutor { return true; } CosmeticUser user = CosmeticUsers.getUser(player); - user.getUserEmoteManager().playEmote(args[1]); + user.getUserEmoteManager().playEmote(HMCCosmeticsPlugin.getEmoteMap().get(args[1])); 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 563e79ed..b138b3f3 100644 --- a/common/src/main/java/com/hibiscusmc/hmccosmetics/command/CosmeticCommandTabComplete.java +++ b/common/src/main/java/com/hibiscusmc/hmccosmetics/command/CosmeticCommandTabComplete.java @@ -1,5 +1,6 @@ package com.hibiscusmc.hmccosmetics.command; +import com.hibiscusmc.hmccosmetics.HMCCosmeticsPlugin; import com.hibiscusmc.hmccosmetics.cosmetic.Cosmetic; import com.hibiscusmc.hmccosmetics.cosmetic.CosmeticSlot; import com.hibiscusmc.hmccosmetics.cosmetic.Cosmetics; @@ -7,7 +8,6 @@ import com.hibiscusmc.hmccosmetics.gui.Menu; import com.hibiscusmc.hmccosmetics.gui.Menus; import com.hibiscusmc.hmccosmetics.user.CosmeticUser; import com.hibiscusmc.hmccosmetics.user.CosmeticUsers; -import com.ticxo.playeranimator.api.PlayerAnimator; import org.bukkit.Bukkit; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; @@ -82,7 +82,7 @@ public class CosmeticCommandTabComplete implements TabCompleter { completions.add("leavelocation"); } case "playemote" -> { - completions.addAll(PlayerAnimator.api.getAnimationManager().getRegistry().keySet()); + completions.addAll(HMCCosmeticsPlugin.getEmoteMap().keySet()); } } StringUtil.copyPartialMatches(args[1], completions, finalCompletions);