mirror of
https://github.com/PlaceholderAPI/PlaceholderAPI
synced 2026-02-26 05:51:12 +01:00
Ensure configurable object is converted from map to object on /papi reload
This commit is contained in:
@@ -2,6 +2,7 @@ package at.helpch.placeholderapi;
|
|||||||
|
|
||||||
import at.helpch.placeholderapi.commands.PlaceholderCommandRouter;
|
import at.helpch.placeholderapi.commands.PlaceholderCommandRouter;
|
||||||
import at.helpch.placeholderapi.configuration.ConfigManager;
|
import at.helpch.placeholderapi.configuration.ConfigManager;
|
||||||
|
import at.helpch.placeholderapi.expansion.PlaceholderExpansion;
|
||||||
import at.helpch.placeholderapi.expansion.manager.CloudExpansionManager;
|
import at.helpch.placeholderapi.expansion.manager.CloudExpansionManager;
|
||||||
import at.helpch.placeholderapi.expansion.manager.LocalExpansionManager;
|
import at.helpch.placeholderapi.expansion.manager.LocalExpansionManager;
|
||||||
import at.helpch.placeholderapi.metrics.MetricsManager;
|
import at.helpch.placeholderapi.metrics.MetricsManager;
|
||||||
@@ -78,6 +79,12 @@ public class PlaceholderAPIPlugin extends JavaPlugin {
|
|||||||
configManager.setup();
|
configManager.setup();
|
||||||
|
|
||||||
localExpansionManager.load(sender);
|
localExpansionManager.load(sender);
|
||||||
|
for (final PlaceholderExpansion expansion : localExpansionManager.getExpansions()) {
|
||||||
|
if (expansion.getExpansionType() == PlaceholderExpansion.Type.INTERNAL) {
|
||||||
|
// when the config gets reloaded, getConfig for internal expansions will return a map instead of the correct object
|
||||||
|
localExpansionManager.createConfig(expansion);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (configManager.config().cloudEnabled()) {
|
if (configManager.config().cloudEnabled()) {
|
||||||
cloudExpansionManager.load();
|
cloudExpansionManager.load();
|
||||||
|
|||||||
@@ -220,21 +220,7 @@ public final class LocalExpansionManager /*implements Listener*/ {
|
|||||||
public boolean register(@NotNull final PlaceholderExpansion expansion) {
|
public boolean register(@NotNull final PlaceholderExpansion expansion) {
|
||||||
final String identifier = expansion.getIdentifier().toLowerCase(Locale.ROOT);
|
final String identifier = expansion.getIdentifier().toLowerCase(Locale.ROOT);
|
||||||
|
|
||||||
if (expansion instanceof Configurable<?> configurable) {
|
createConfig(expansion);
|
||||||
final PlaceholderAPIConfig config = configManager.config();
|
|
||||||
|
|
||||||
if (config.expansions() == null) {
|
|
||||||
config.expansions(new ConcurrentHashMap<>());
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!config.expansions().containsKey(expansion.getIdentifier())) {
|
|
||||||
config.expansions().put(expansion.getIdentifier(), configurable.provideDefault());
|
|
||||||
configManager.save();
|
|
||||||
} else {
|
|
||||||
final Object expansionConfig = configManager.convertExpansion((Map<String, Object>) config.expansions().get(expansion.getIdentifier()), configurable.provideConfigType());
|
|
||||||
config.expansions().put(expansion.getIdentifier(), expansionConfig);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!expansion.canRegister()) {
|
if (!expansion.canRegister()) {
|
||||||
return false;
|
return false;
|
||||||
@@ -307,6 +293,33 @@ public final class LocalExpansionManager /*implements Listener*/ {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates and initializes the configuration for the provided {@link PlaceholderExpansion}.
|
||||||
|
* If the expansion implements the {@link Configurable} interface, this method ensures that
|
||||||
|
* the expansion's default configuration is registered and saved if it is not already present.
|
||||||
|
* If a configuration already exists, it converts and updates it using the provided configuration type.
|
||||||
|
*
|
||||||
|
* @param expansion the {@link PlaceholderExpansion} for which the configuration is being created
|
||||||
|
*/
|
||||||
|
@ApiStatus.Internal
|
||||||
|
public void createConfig(PlaceholderExpansion expansion) {
|
||||||
|
if (expansion instanceof Configurable<?> configurable) {
|
||||||
|
final PlaceholderAPIConfig config = configManager.config();
|
||||||
|
|
||||||
|
if (config.expansions() == null) {
|
||||||
|
config.expansions(new ConcurrentHashMap<>());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!config.expansions().containsKey(expansion.getIdentifier())) {
|
||||||
|
config.expansions().put(expansion.getIdentifier(), configurable.provideDefault());
|
||||||
|
configManager.save();
|
||||||
|
} else {
|
||||||
|
final Object expansionConfig = configManager.convertExpansion((Map<String, Object>) config.expansions().get(expansion.getIdentifier()), configurable.provideConfigType());
|
||||||
|
config.expansions().put(expansion.getIdentifier(), expansionConfig);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@ApiStatus.Internal
|
@ApiStatus.Internal
|
||||||
public boolean unregister(@NotNull final PlaceholderExpansion expansion) {
|
public boolean unregister(@NotNull final PlaceholderExpansion expansion) {
|
||||||
if (expansions.remove(expansion.getIdentifier().toLowerCase(Locale.ROOT)) == null) {
|
if (expansions.remove(expansion.getIdentifier().toLowerCase(Locale.ROOT)) == null) {
|
||||||
|
|||||||
Reference in New Issue
Block a user