Skip to content

Commit

Permalink
Merge pull request #16 from TWME-TW/dev
Browse files Browse the repository at this point in the history
Fix: Resolve issue with CustomModelData not working.
  • Loading branch information
TWME-TW authored Aug 2, 2024
2 parents 95ebb98 + c1ae2c2 commit 46b4347
Show file tree
Hide file tree
Showing 7 changed files with 68 additions and 9 deletions.
12 changes: 11 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>dev.twme</groupId>
<artifactId>DebugStickPro</artifactId>
<version>0.4.7</version>
<version>0.4.8</version>
<packaging>jar</packaging>

<name>DebugStickPro</name>
Expand Down Expand Up @@ -71,6 +71,10 @@
<id>coreprotect</id>
<url>https://maven.playpro.com/</url>
</repository>
<repository>
<id>placeholderapi</id>
<url>https://repo.extendedclip.com/content/repositories/placeholderapi/</url>
</repository>
</repositories>

<dependencies>
Expand All @@ -86,6 +90,12 @@
<version>22.4</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>me.clip</groupId>
<artifactId>placeholderapi</artifactId>
<version>2.11.6</version>
<scope>provided</scope>
</dependency>
</dependencies>

<distributionManagement>
Expand Down
6 changes: 6 additions & 0 deletions src/main/java/dev/twme/debugstickpro/DebugStickPro.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import dev.twme.debugstickpro.config.ConfigLoader;
import dev.twme.debugstickpro.display.ActionBarDisplayTask;
import dev.twme.debugstickpro.hook.CoreProtectUtil;
import dev.twme.debugstickpro.hook.PlaceholderAPIUtil;
import dev.twme.debugstickpro.listeners.*;
import dev.twme.debugstickpro.localization.LangFileManager;
import dev.twme.debugstickpro.localization.PlayerLanguageManager;
Expand Down Expand Up @@ -60,6 +61,11 @@ public void onEnable() {
Log.warning("CoreProtect is not loaded or is not compatible with this version of the plugin.");
}

boolean isPlaceholderAPILoaded = PlaceholderAPIUtil.initPlaceholderAPI();
if (!isPlaceholderAPILoaded) {
Log.warning("PlaceholderAPI is not loaded or is not compatible with this version of the plugin.");
}

ConfigLoader.getInstance().load();

LangFileManager.initialization();
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/dev/twme/debugstickpro/config/ConfigLoader.java
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,8 @@ private void loadValues() {
lore.add(mm.deserialize(loreString));
}
ConfigFile.DebugStickItem.Lore = lore;
ConfigFile.DebugStickItem.CustomModelData.Enabled = config.getBoolean("CustomModelData.DebugStickItem.Enabled");
ConfigFile.DebugStickItem.CustomModelData.CustomModelData = config.getInt("CustomModelData.DebugStickItem.CustomModelData");
ConfigFile.DebugStickItem.CustomModelData.Enabled = config.getBoolean("DebugStickItem.CustomModelData.Enabled");
ConfigFile.DebugStickItem.CustomModelData.CustomModelData = config.getInt("DebugStickItem.CustomModelData.CustomModelData");

ConfigFile.WhitelistWorlds.Enabled = config.getBoolean("WhitelistWorlds.Enabled");
ConfigFile.WhitelistWorlds.Worlds = new HashSet<>(config.getStringList("WhitelistWorlds.Worlds"));
Expand Down
37 changes: 37 additions & 0 deletions src/main/java/dev/twme/debugstickpro/hook/PlaceholderAPIUtil.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package dev.twme.debugstickpro.hook;

import me.clip.placeholderapi.PlaceholderAPI;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;

import java.util.List;

public class PlaceholderAPIUtil {
private static boolean isPlaceholderAPILoaded = false;

public static boolean initPlaceholderAPI() {
if (Bukkit.getPluginManager().getPlugin("PlaceholderAPI") != null) {
isPlaceholderAPILoaded = true;
return true;
} else {
isPlaceholderAPILoaded = false;
return false;
}
}

public static String insertPAPI(Player player, String text) {
if (isPlaceholderAPILoaded && player != null) {
return PlaceholderAPI.setPlaceholders(player, text);
} else {
return text;
}
}

public static List<String> insertPAPI(Player player, List<String> list) {
if (isPlaceholderAPILoaded && player != null) {
return PlaceholderAPI.setPlaceholders(player, list);
} else {
return list;
}
}
}
10 changes: 6 additions & 4 deletions src/main/java/dev/twme/debugstickpro/localization/I18n.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package dev.twme.debugstickpro.localization;

import dev.twme.debugstickpro.config.ConfigFile;
import dev.twme.debugstickpro.hook.PlaceholderAPIUtil;
import org.bukkit.Bukkit;

import java.util.List;
import java.util.UUID;
Expand All @@ -11,15 +13,15 @@ public class I18n {
* Get the translated string of the key
*
* @param playerUUID the UUID of the player
* @param key the key of the string
* @param key the key of the string
* @return the string of the key
*/
public static String string(UUID playerUUID, String key) {

String playerLocale = PlayerLanguageManager.getLocale(playerUUID);
LangFileReader lang = LangFileManager.getLang(playerLocale);

return lang.getString(key);
return PlaceholderAPIUtil.insertPAPI(Bukkit.getPlayer(playerUUID), lang.getString(key));
}

/**
Expand All @@ -39,15 +41,15 @@ public static String string(String key) {
* Get the translated list of the key
*
* @param playerUUID the UUID of the player
* @param key the key of the list
* @param key the key of the list
* @return the list of the key
*/
public static List<String> list(UUID playerUUID, String key) {

String playerLocale = PlayerLanguageManager.getLocale(playerUUID);
LangFileReader lang = LangFileManager.getLang(playerLocale);

return lang.getList(key);
return PlaceholderAPIUtil.insertPAPI(Bukkit.getPlayer(playerUUID), lang.getList(key));
}

public static List<String> list(String key) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,10 @@ public static boolean isDebugStickItem(ItemStack item) {
return false;
}
if (ConfigFile.DebugStickItem.CustomModelData.Enabled) {
if (item.getItemMeta().getCustomModelData() != ConfigFile.DebugStickItem.CustomModelData.CustomModelData) {
if (!item.getItemMeta().hasCustomModelData()) {
return false;
}
return item.getItemMeta().getCustomModelData() == ConfigFile.DebugStickItem.CustomModelData.CustomModelData;
}
return true;
}
Expand All @@ -44,10 +45,12 @@ public static ItemStack getDebugStickItem() {
itemMeta.lore(ConfigFile.DebugStickItem.Lore);
itemMeta.getPersistentDataContainer().set(PersistentKeys.DEBUG_STICK_ITEM, PersistentDataType.STRING, "debugstickpro");
if (ConfigFile.DebugStickItem.CustomModelData.Enabled) {
Log.warning("CustomModelData is enabled");
itemMeta.setCustomModelData(ConfigFile.DebugStickItem.CustomModelData.CustomModelData);
itemStack.setItemMeta(itemMeta);
return itemStack;
}
itemStack.setItemMeta(itemMeta);

return itemStack;
}
}
1 change: 1 addition & 0 deletions src/main/resources/plugin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ authors: [TWME]
website: https://github.com/TWME-TW/DebugStickPro
softdepend:
- CoreProtect
- PlaceholderAPI
commands:
debugstickpro:
description: DebugStickPro command
Expand Down

0 comments on commit 46b4347

Please sign in to comment.