9
0
mirror of https://github.com/HibiscusMC/HMCCosmetics.git synced 2025-12-27 19:09:19 +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;
}
}