mirror of
https://github.com/HibiscusMC/HMCCosmetics.git
synced 2025-12-27 02:49:08 +00:00
Compare commits
5 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
cd80bc746e | ||
|
|
d96a8e5622 | ||
|
|
53091f102e | ||
|
|
1d24881df1 | ||
|
|
ae0dc7bd14 |
@@ -8,7 +8,7 @@ plugins {
|
|||||||
}
|
}
|
||||||
|
|
||||||
group = "com.hibiscusmc"
|
group = "com.hibiscusmc"
|
||||||
version = "2.4.3"
|
version = "2.4.4"
|
||||||
|
|
||||||
allprojects {
|
allprojects {
|
||||||
apply(plugin = "java")
|
apply(plugin = "java")
|
||||||
|
|||||||
@@ -89,8 +89,8 @@ public final class HMCCosmeticsPlugin extends JavaPlugin {
|
|||||||
onLatestVersion = checker.isUsingLatestVersion();
|
onLatestVersion = checker.isUsingLatestVersion();
|
||||||
// File setup
|
// File setup
|
||||||
saveDefaultConfig();
|
saveDefaultConfig();
|
||||||
//saveResource("translations.yml", false);
|
|
||||||
if (!Path.of(getDataFolder().getPath(), "messages.yml").toFile().exists()) saveResource("messages.yml", false);
|
if (!Path.of(getDataFolder().getPath(), "messages.yml").toFile().exists()) saveResource("messages.yml", false);
|
||||||
|
if (!Path.of(getDataFolder().getPath(), "translations.yml").toFile().exists()) saveResource("translations.yml", false);
|
||||||
if (!Path.of(getDataFolder().getPath() + "/cosmetics/").toFile().exists()) saveResource("cosmetics/defaultcosmetics.yml", false);
|
if (!Path.of(getDataFolder().getPath() + "/cosmetics/").toFile().exists()) saveResource("cosmetics/defaultcosmetics.yml", false);
|
||||||
if (!Path.of(getDataFolder().getPath() + "/menus/").toFile().exists()) saveResource("menus/defaultmenu.yml", false);
|
if (!Path.of(getDataFolder().getPath() + "/menus/").toFile().exists()) saveResource("menus/defaultmenu.yml", false);
|
||||||
|
|
||||||
@@ -104,11 +104,15 @@ public final class HMCCosmeticsPlugin extends JavaPlugin {
|
|||||||
// Configuration Sync
|
// Configuration Sync
|
||||||
final File configFile = Path.of(getInstance().getDataFolder().getPath(), "config.yml").toFile();
|
final File configFile = Path.of(getInstance().getDataFolder().getPath(), "config.yml").toFile();
|
||||||
final File messageFile = Path.of(getInstance().getDataFolder().getPath(), "messages.yml").toFile();
|
final File messageFile = Path.of(getInstance().getDataFolder().getPath(), "messages.yml").toFile();
|
||||||
|
final File translationFile = Path.of(getInstance().getDataFolder().getPath(), "translations.yml").toFile();
|
||||||
try {
|
try {
|
||||||
CommentedConfiguration.loadConfiguration(configFile).syncWithConfig(configFile, getInstance().getResource("config.yml"),
|
CommentedConfiguration.loadConfiguration(configFile).syncWithConfig(configFile, getInstance().getResource("config.yml"),
|
||||||
"database-settings", "debug-mode", "wardrobe.viewer-location", "wardrobe.npc-location", "wardrobe.wardrobe-location", "wardrobe.leave-location");
|
"database-settings", "debug-mode", "wardrobe.viewer-location", "wardrobe.npc-location", "wardrobe.wardrobe-location", "wardrobe.leave-location");
|
||||||
CommentedConfiguration.loadConfiguration(messageFile).syncWithConfig(messageFile, getInstance().getResource("messages.yml"));
|
CommentedConfiguration.loadConfiguration(messageFile).syncWithConfig(messageFile, getInstance().getResource("messages.yml"));
|
||||||
} catch (Exception e) {}
|
CommentedConfiguration.loadConfiguration(translationFile).syncWithConfig(translationFile, getInstance().getResource("translations.yml"));
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
// Setup
|
// Setup
|
||||||
setup();
|
setup();
|
||||||
|
|||||||
@@ -39,7 +39,7 @@ public class HookGeary extends Hook {
|
|||||||
if (enabled) {
|
if (enabled) {
|
||||||
PrefabKey prefabKey = PrefabKey.Companion.ofOrNull(itemId);
|
PrefabKey prefabKey = PrefabKey.Companion.ofOrNull(itemId);
|
||||||
if (prefabKey == null) return null;
|
if (prefabKey == null) return null;
|
||||||
return ItemTrackingKt.getItemTracking().createItem(prefabKey, null);
|
return ItemTrackingKt.getGearyItems().createItem(prefabKey, null);
|
||||||
} else return new ItemStack(Material.AIR);
|
} else return new ItemStack(Material.AIR);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -69,9 +69,9 @@ public class HMCPlaceholderExpansion extends PlaceholderExpansion {
|
|||||||
Cosmetic cosmetic = Cosmetics.getCosmetic(placeholderArgs.get(1));
|
Cosmetic cosmetic = Cosmetics.getCosmetic(placeholderArgs.get(1));
|
||||||
if (cosmetic == null) return "INVALID_COSMETIC";
|
if (cosmetic == null) return "INVALID_COSMETIC";
|
||||||
Cosmetic currentCosmetic = user.getCosmetic(cosmetic.getSlot());
|
Cosmetic currentCosmetic = user.getCosmetic(cosmetic.getSlot());
|
||||||
if (currentCosmetic == null) return "false";
|
if (currentCosmetic == null) return TranslationUtil.getTranslation("using-cosmetic", String.valueOf(false)); // I hate this way of handling translations
|
||||||
if (currentCosmetic.getId() == cosmetic.getId()) return "true";
|
if (currentCosmetic.getId() == cosmetic.getId()) return TranslationUtil.getTranslation("using-cosmetic", String.valueOf(true));
|
||||||
return "false";
|
return TranslationUtil.getTranslation("using-cosmetic", String.valueOf(false));
|
||||||
}
|
}
|
||||||
case "current":
|
case "current":
|
||||||
if (placeholderArgs == null) {
|
if (placeholderArgs == null) {
|
||||||
@@ -82,26 +82,29 @@ public class HMCPlaceholderExpansion extends PlaceholderExpansion {
|
|||||||
if (slot == null) return null;
|
if (slot == null) return null;
|
||||||
if (user.getCosmetic(slot) == null) return null;
|
if (user.getCosmetic(slot) == null) return null;
|
||||||
if (placeholderArgs.size() == 2) return user.getCosmetic(slot).getId();
|
if (placeholderArgs.size() == 2) return user.getCosmetic(slot).getId();
|
||||||
|
|
||||||
|
String output;
|
||||||
switch (placeholderArgs.get(2).toLowerCase()) {
|
switch (placeholderArgs.get(2).toLowerCase()) {
|
||||||
case "material" -> {
|
case "material" -> {
|
||||||
return getMaterialName(user.getCosmetic(slot));
|
output = getMaterialName(user.getCosmetic(slot));
|
||||||
}
|
}
|
||||||
case "custommodeldata" -> {
|
case "custommodeldata" -> {
|
||||||
return getModelData(user.getCosmetic(slot));
|
output = getModelData(user.getCosmetic(slot));
|
||||||
}
|
}
|
||||||
case "name" -> {
|
case "name" -> {
|
||||||
return getItemName(user.getCosmetic(slot));
|
output = getItemName(user.getCosmetic(slot));
|
||||||
}
|
}
|
||||||
case "lore" -> {
|
case "lore" -> {
|
||||||
return getItemLore(user.getCosmetic(slot));
|
output = getItemLore(user.getCosmetic(slot));
|
||||||
}
|
}
|
||||||
case "permission" -> {
|
case "permission" -> {
|
||||||
return user.getCosmetic(slot).getPermission();
|
output = user.getCosmetic(slot).getPermission();
|
||||||
}
|
}
|
||||||
default -> {
|
default -> {
|
||||||
return user.getCosmetic(slot).getId();
|
output = user.getCosmetic(slot).getId();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return TranslationUtil.getTranslation("current-cosmetic", String.valueOf(output));
|
||||||
}
|
}
|
||||||
case "unlocked":
|
case "unlocked":
|
||||||
if (placeholderArgs == null) {
|
if (placeholderArgs == null) {
|
||||||
@@ -121,7 +124,7 @@ public class HMCPlaceholderExpansion extends PlaceholderExpansion {
|
|||||||
return "INVALID_COSMETIC";
|
return "INVALID_COSMETIC";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return TranslationUtil.getTranslation("unlockedCosmetic", String.valueOf(user.canEquipCosmetic(cosmetic)));
|
return TranslationUtil.getTranslation("unlocked-cosmetic", String.valueOf(user.canEquipCosmetic(cosmetic)));
|
||||||
}
|
}
|
||||||
case "equipped":
|
case "equipped":
|
||||||
if (placeholderArgs == null) {
|
if (placeholderArgs == null) {
|
||||||
@@ -131,11 +134,7 @@ public class HMCPlaceholderExpansion extends PlaceholderExpansion {
|
|||||||
String args1 = placeholderArgs.get(1);
|
String args1 = placeholderArgs.get(1);
|
||||||
|
|
||||||
if (EnumUtils.isValidEnum(CosmeticSlot.class, args1.toUpperCase())) {
|
if (EnumUtils.isValidEnum(CosmeticSlot.class, args1.toUpperCase())) {
|
||||||
if (user.getCosmetic(CosmeticSlot.valueOf(args1.toUpperCase())) != null) {
|
return TranslationUtil.getTranslation("equipped-cosmetic", String.valueOf(user.getCosmetic(CosmeticSlot.valueOf(args1.toUpperCase())) != null));
|
||||||
return "true";
|
|
||||||
} else {
|
|
||||||
return "false";
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
MessagesUtil.sendDebugMessages(args1);
|
MessagesUtil.sendDebugMessages(args1);
|
||||||
@@ -154,14 +153,10 @@ public class HMCPlaceholderExpansion extends PlaceholderExpansion {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (user.getCosmetic(cosmetic.getSlot()) == null) return "false";
|
if (user.getCosmetic(cosmetic.getSlot()) == null) return "false";
|
||||||
if (cosmetic.getId() == user.getCosmetic(cosmetic.getSlot()).getId()) {
|
return TranslationUtil.getTranslation("equipped-cosmetic", String.valueOf(cosmetic.getId() == user.getCosmetic(cosmetic.getSlot()).getId()));
|
||||||
return "true";
|
|
||||||
} else {
|
|
||||||
return "false";
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
case "wardrobe-enabled":
|
case "wardrobe-enabled":
|
||||||
return String.valueOf(user.isInWardrobe());
|
return TranslationUtil.getTranslation("in-wardrobe", String.valueOf(user.isInWardrobe()));
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,20 @@
|
|||||||
|
package com.hibiscusmc.hmccosmetics.util;
|
||||||
|
|
||||||
|
public class TranslationPair {
|
||||||
|
|
||||||
|
private String key;
|
||||||
|
private String value;
|
||||||
|
|
||||||
|
public TranslationPair(String key, String value) {
|
||||||
|
this.key = key;
|
||||||
|
this.value = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getKey() {
|
||||||
|
return key;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getValue() {
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -2,38 +2,37 @@ package com.hibiscusmc.hmccosmetics.util;
|
|||||||
|
|
||||||
import org.spongepowered.configurate.ConfigurationNode;
|
import org.spongepowered.configurate.ConfigurationNode;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
public class TranslationUtil {
|
public class TranslationUtil {
|
||||||
|
|
||||||
private static HashMap<String, String> keys = new HashMap<>();
|
// unlocked-cosmetic -> true -> True
|
||||||
|
private static HashMap<String, List<TranslationPair>> keys = new HashMap<>();
|
||||||
|
|
||||||
public static void setup(ConfigurationNode config) {
|
public static void setup(ConfigurationNode config) {
|
||||||
// TODO: Finish this
|
|
||||||
/*
|
|
||||||
for (ConfigurationNode node : config.childrenMap().values()) {
|
for (ConfigurationNode node : config.childrenMap().values()) {
|
||||||
HashMap<Pair> translableMessages = new HashMap<>();
|
ArrayList<TranslationPair> pairs = new ArrayList<>();
|
||||||
for (ConfigurationNode translatableMessage : node.childrenMap().values()) {
|
for (ConfigurationNode translatableMessage : node.childrenMap().values()) {
|
||||||
translableMessages.put( new Pair<>(translatableMessage.key().toString(), translatableMessage.getString()))
|
String key = translatableMessage.key().toString();
|
||||||
|
key.replaceAll("'", ""); // Autoupdater adds ' to it? Removes it from the key
|
||||||
|
TranslationPair pair = new TranslationPair(key, translatableMessage.getString());
|
||||||
|
pairs.add(pair);
|
||||||
MessagesUtil.sendDebugMessages("setupTranslation key:" + node.key().toString() + " | " + node);
|
MessagesUtil.sendDebugMessages("setupTranslation key:" + node.key().toString() + " | " + node);
|
||||||
|
MessagesUtil.sendDebugMessages("Overall Key " + node.key().toString());
|
||||||
|
MessagesUtil.sendDebugMessages("Key '" + pair.getKey() + "' Value '" + pair.getValue() + "'");
|
||||||
}
|
}
|
||||||
keys.put(node.key().toString().toLowerCase(), HashMap);
|
keys.put(node.key().toString().toLowerCase(), pairs);
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String getTranslation(String key, String message) {
|
public static String getTranslation(String key, String message) {
|
||||||
// TODO: Finish this
|
List<TranslationPair> pairs = keys.get(key);
|
||||||
return message;
|
for (TranslationPair pair : pairs) {
|
||||||
/*
|
if (pair.getKey() == message) return pair.getValue();
|
||||||
key = key.toLowerCase();
|
|
||||||
MessagesUtil.sendDebugMessages("getTranslation key:" + key + " | " + message);
|
|
||||||
if (!keys.containsKey(key)) return message;
|
|
||||||
List<Pair> config = keys.get(key);
|
|
||||||
if (config.getFirst() == message) {
|
|
||||||
return config.getSecond().toString();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return message;
|
return message;
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -306,8 +306,8 @@ public class PacketManager extends BasePacket {
|
|||||||
WrappedGameProfile wrappedGameProfile = new WrappedGameProfile(uuid, name);
|
WrappedGameProfile wrappedGameProfile = new WrappedGameProfile(uuid, name);
|
||||||
WrappedSignedProperty skinData = PlayerUtils.getSkin(skinnedPlayer);
|
WrappedSignedProperty skinData = PlayerUtils.getSkin(skinnedPlayer);
|
||||||
if (skinData != null) wrappedGameProfile.getProperties().put("textures", skinData);
|
if (skinData != null) wrappedGameProfile.getProperties().put("textures", skinData);
|
||||||
// For sor some reason 1.19.2 handles it on the 0 field index, every other verison handles it on the 1
|
// For sor some reason <1.19.2 handles it on the 0 field index, newer versions handles it on the 1
|
||||||
if (NMSHandlers.getVersion().contains("v1_19_R1")) {
|
if (NMSHandlers.getVersion().contains("v1_17_R1") || NMSHandlers.getVersion().contains("v1_18_R2") || NMSHandlers.getVersion().contains("v1_19_R1")) {
|
||||||
info.getHandle().getPlayerInfoDataLists().write(0, Collections.singletonList(new PlayerInfoData(
|
info.getHandle().getPlayerInfoDataLists().write(0, Collections.singletonList(new PlayerInfoData(
|
||||||
wrappedGameProfile,
|
wrappedGameProfile,
|
||||||
0,
|
0,
|
||||||
|
|||||||
@@ -1,3 +1,15 @@
|
|||||||
unlockedCosmetic:
|
unlocked-cosmetic:
|
||||||
true: "True"
|
true: "true"
|
||||||
false: "false"
|
false: "false"
|
||||||
|
equipped-cosmetic:
|
||||||
|
true: "true"
|
||||||
|
false: "false"
|
||||||
|
in-wardrobe:
|
||||||
|
true: "true"
|
||||||
|
false: "false"
|
||||||
|
using-cosmetic:
|
||||||
|
true: "true"
|
||||||
|
false: "false"
|
||||||
|
current-cosmetic:
|
||||||
|
true: "true"
|
||||||
|
false: "false"
|
||||||
|
|||||||
Reference in New Issue
Block a user