mirror of
https://github.com/songoda/FabledSkyBlock.git
synced 2024-11-26 12:16:30 +01:00
Replace FabledSkyBlock placeholders without PlaceholderAPI installed
This commit is contained in:
parent
2e37efefd4
commit
25e401826c
@ -8,20 +8,20 @@ import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.PluginManager;
|
||||
|
||||
public class PlaceholderManager extends Manager {
|
||||
private final PlaceholderAPI skyBlockPlaceholderAPI;
|
||||
private final boolean placeholderAPIEnabled;
|
||||
private final PlaceholderProcessor placeholderProcessor;
|
||||
|
||||
public PlaceholderManager(SkyBlock plugin) {
|
||||
super(plugin);
|
||||
this.skyBlockPlaceholderAPI = new PlaceholderAPI(this.plugin);
|
||||
|
||||
PluginManager pluginManager = this.plugin.getServer().getPluginManager();
|
||||
this.placeholderAPIEnabled = pluginManager.getPlugin("PlaceholderAPI") != null;
|
||||
this.placeholderProcessor = !this.placeholderAPIEnabled ? new PlaceholderProcessor() : null;
|
||||
}
|
||||
|
||||
public void registerPlaceholders() {
|
||||
if (this.placeholderAPIEnabled) {
|
||||
this.skyBlockPlaceholderAPI.register();
|
||||
new PlaceholderAPI(this.plugin).register();
|
||||
}
|
||||
}
|
||||
|
||||
@ -30,11 +30,35 @@ public class PlaceholderManager extends Manager {
|
||||
}
|
||||
|
||||
public String parsePlaceholders(Player player, String message) {
|
||||
String retValue = message;
|
||||
String retValue;
|
||||
|
||||
if (this.placeholderAPIEnabled) {
|
||||
retValue = me.clip.placeholderapi.PlaceholderAPI.setPlaceholders(player, message);
|
||||
retValue = ChatColor.translateAlternateColorCodes('&', retValue);
|
||||
} else {
|
||||
retValue = manuallyReplaceSkyBlockPlaceholders(player, message);
|
||||
}
|
||||
return retValue;
|
||||
}
|
||||
|
||||
private String manuallyReplaceSkyBlockPlaceholders(Player player, String message) {
|
||||
if (this.placeholderProcessor == null) {
|
||||
return message;
|
||||
}
|
||||
|
||||
String retValue = message;
|
||||
|
||||
int index = retValue.indexOf("%fabledskyblock_");
|
||||
while (index != -1) {
|
||||
int endIndex = retValue.indexOf("%", index + 1);
|
||||
if (endIndex != -1) {
|
||||
String placeholder = retValue.substring(index + 1, endIndex);
|
||||
String result = this.placeholderProcessor.processPlaceholder(player, placeholder);
|
||||
if (result != null) {
|
||||
retValue = retValue.replace("%" + placeholder + "%", result);
|
||||
}
|
||||
}
|
||||
index = retValue.indexOf("%fabledskyblock_", index + 1);
|
||||
}
|
||||
return retValue;
|
||||
}
|
||||
|
@ -42,8 +42,7 @@ public class PlaceholderProcessor {
|
||||
LeaderboardManager leaderboardManager = plugin.getLeaderboardManager();
|
||||
|
||||
FileManager fileManager = plugin.getFileManager();
|
||||
FileConfiguration placeholdersLoad = fileManager.getConfig(
|
||||
new File(plugin.getDataFolder(), "placeholders.yml")).getFileConfiguration();
|
||||
FileConfiguration placeholdersLoad = fileManager.getConfig(new File(plugin.getDataFolder(), "placeholders.yml")).getFileConfiguration();
|
||||
|
||||
if (placeholdersLoad == null) {
|
||||
return "Error";
|
||||
|
@ -31,7 +31,7 @@ public class PlaceholderAPI extends PlaceholderExpansion {
|
||||
return true;
|
||||
}
|
||||
|
||||
public String onPlaceholderRequest(Player player, @NotNull String identifier) {
|
||||
return this.placeholderProcessor.processPlaceholder(player, "fabledskyblock_" + identifier);
|
||||
public String onPlaceholderRequest(Player player, @NotNull String params) {
|
||||
return this.placeholderProcessor.processPlaceholder(player, "fabledskyblock_" + params);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user