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

feat: allow for multiple emotes in one bbmodel file

This commit is contained in:
Craftinators
2023-05-05 18:39:14 -04:00
parent f793f4e67a
commit 79f33ca0d1
3 changed files with 35 additions and 22 deletions

View File

@@ -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<String, String> 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<String, AnimationPack> packEntry : PlayerAnimator.api.getAnimationManager().getRegistry().entrySet()) {
Set<String> 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<String, AnimationPack> 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<String, String> getEmoteMap() {
return emoteMap;
}
}

View File

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

View File

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