Bug fixes with external placeholders when null and deluxecompatibility on plugin load

This commit is contained in:
rockyhawk64 2025-05-02 13:34:23 +10:00
parent 9d50429d49
commit 6f50ebd709
3 changed files with 26 additions and 25 deletions

View File

@ -96,7 +96,6 @@ public class Context {
public InventorySaver inventorySaver;
public ItemStackSerializer itemSerializer;
public PlayerInputUtils inputUtils;
public CompatibilityConverter deluxeConverter;
public Context(CommandPanels pl) {
plugin = pl;
@ -108,23 +107,30 @@ public class Context {
//get plugin classes
version = new VersionManager();
downloader = new PanelDownloader(this);
panelData = new DataLoader(this);
inventorySaver = new InventorySaver(this);
configHandler = new ConfigHandler(this);
econ = null;
deluxeConverter = new CompatibilityConverter(this);
reloader = new ReloadCommand(this);
commands = new CommandRunner(this);
panelDataPlayers = new DataManager();
try {
// Check all the minimessage classes exist before loading
Class.forName("net.kyori.adventure.text.Component");
Class.forName("net.kyori.adventure.text.format.TextDecoration");
Class.forName("net.kyori.adventure.text.minimessage.MiniMessage");
Class.forName("net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer");
miniMessage = new MiniMessage(this);
} catch (ClassNotFoundException ignore) {
miniMessage = null;
}
placeholders = new Placeholders(this);
debug = new DebugManager();
text = new CreateText(this);
hex = new HexColours(this);
miniMessage = null;
panelData = new DataLoader(this);
inventorySaver = new InventorySaver(this);
configHandler = new ConfigHandler(this);
econ = null;
reloader = new ReloadCommand(this);
commands = new CommandRunner(this);
panelDataPlayers = new DataManager();
openPanel = new OpenPanel(this);
itemBuilder = new ItemBuilder(this);
@ -177,17 +183,6 @@ public class Context {
Bukkit.getServer().getPluginManager().registerEvents(new LegacyPlayerEvent(this), plugin);
}
try {
// Check all the minimessage classes exist before loading
Class.forName("net.kyori.adventure.text.Component");
Class.forName("net.kyori.adventure.text.format.TextDecoration");
Class.forName("net.kyori.adventure.text.minimessage.MiniMessage");
Class.forName("net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer");
miniMessage = new MiniMessage(this);
} catch (ClassNotFoundException ignore) {
//do not initialise miniMessage
}
Bukkit.getServer().getPluginManager().registerEvents(new InteractionHandler(this), plugin);
Bukkit.getServer().getPluginManager().registerEvents(inventorySaver, plugin);
Bukkit.getServer().getPluginManager().registerEvents(inputUtils, plugin);

View File

@ -2,6 +2,7 @@ package me.rockyhawk.commandpanels.commands;
import me.rockyhawk.commandpanels.Context;
import me.rockyhawk.commandpanels.api.Panel;
import me.rockyhawk.commandpanels.generate.deluxecompatibility.CompatibilityConverter;
import me.rockyhawk.commandpanels.manager.session.PanelPosition;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
@ -99,7 +100,8 @@ public class ReloadCommand implements CommandExecutor {
//if a yaml file is missing the 'panels' at the files root
if(!checkPanels(YamlConfiguration.loadConfiguration(new File(directory + File.separator + fileName)))){
//try converting the file
YamlConfiguration convertedYaml = ctx.deluxeConverter.tryConversion(fileName, YamlConfiguration.loadConfiguration(new File(directory + File.separator + fileName)));
CompatibilityConverter deluxeConverter = new CompatibilityConverter(ctx);
YamlConfiguration convertedYaml = deluxeConverter.tryConversion(fileName, YamlConfiguration.loadConfiguration(new File(directory + File.separator + fileName)));
if(convertedYaml != null){
//the conversion was successful
for (String tempName : Objects.requireNonNull(convertedYaml.getConfigurationSection("panels")).getKeys(false)) {

View File

@ -42,6 +42,10 @@ public class PlaceholderAPI extends PlaceholderExpansion {
*/
@Override
public String onRequest(OfflinePlayer player, @NotNull String identifier) {
return ctx.placeholders.resolvePlaceholder(null, PanelPosition.Top, (Player)player, identifier);
try {
return ctx.placeholders.resolvePlaceholder(null, PanelPosition.Top, (Player) player, identifier);
}catch (Exception e){
return "null";
}
}
}