Miscellaneous changes
This commit is contained in:
@@ -37,11 +37,6 @@ import java.util.logging.Logger;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public abstract class EcoPlugin extends JavaPlugin {
|
||||
/**
|
||||
* Loaded eco plugins.
|
||||
*/
|
||||
public static final List<String> LOADED_ECO_PLUGINS = new ArrayList<>();
|
||||
|
||||
/**
|
||||
* The spigot resource ID of the plugin.
|
||||
*/
|
||||
@@ -301,7 +296,7 @@ public abstract class EcoPlugin extends JavaPlugin {
|
||||
this.langYml = new LangYml(this);
|
||||
this.configYml = new ConfigYml(this);
|
||||
|
||||
LOADED_ECO_PLUGINS.add(this.getName().toLowerCase());
|
||||
Eco.getHandler().addNewPlugin(this);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -665,4 +660,23 @@ public abstract class EcoPlugin extends JavaPlugin {
|
||||
|
||||
super.reloadConfig();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get an EcoPlugin by name.
|
||||
*
|
||||
* @param pluginName The name.
|
||||
* @return The plugin.
|
||||
*/
|
||||
public static EcoPlugin getPlugin(@NotNull final String pluginName) {
|
||||
return Eco.getHandler().getPluginByName(pluginName);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all EcoPlugin names.
|
||||
*
|
||||
* @return The set of names.
|
||||
*/
|
||||
public static Set<String> getPluginNames() {
|
||||
return new HashSet<>(Eco.getHandler().getLoadedPlugins());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,8 +13,10 @@ import com.willfp.eco.core.integrations.placeholder.PlaceholderIntegration;
|
||||
import com.willfp.eco.core.proxy.Cleaner;
|
||||
import com.willfp.eco.core.proxy.ProxyFactory;
|
||||
import com.willfp.eco.core.scheduling.Scheduler;
|
||||
import org.bukkit.NamespacedKey;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
public interface Handler {
|
||||
@@ -132,4 +134,34 @@ public interface Handler {
|
||||
* @return The cleaner.
|
||||
*/
|
||||
Cleaner getCleaner();
|
||||
|
||||
/**
|
||||
* Get a localized string.
|
||||
*
|
||||
* @param key The key.
|
||||
* @return The string.
|
||||
*/
|
||||
String getLocalizedString(@NotNull NamespacedKey key);
|
||||
|
||||
/**
|
||||
* Add new plugin.
|
||||
*
|
||||
* @param plugin The plugin.
|
||||
*/
|
||||
void addNewPlugin(@NotNull EcoPlugin plugin);
|
||||
|
||||
/**
|
||||
* Get plugin by name.
|
||||
*
|
||||
* @param name The name.
|
||||
* @return The plugin.
|
||||
*/
|
||||
EcoPlugin getPluginByName(@NotNull String name);
|
||||
|
||||
/**
|
||||
* Get all loaded eco plugins.
|
||||
*
|
||||
* @return A list of plugin names in lowercase.
|
||||
*/
|
||||
List<String> getLoadedPlugins();
|
||||
}
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
package com.willfp.eco.util;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.willfp.eco.core.Eco;
|
||||
import com.willfp.eco.core.integrations.placeholder.PlaceholderManager;
|
||||
import lombok.experimental.UtilityClass;
|
||||
import net.md_5.bungee.api.ChatColor;
|
||||
import org.bukkit.NamespacedKey;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
@@ -42,8 +44,8 @@ public class StringUtils {
|
||||
/**
|
||||
* Translate a list of strings - converts Placeholders and Color codes.
|
||||
*
|
||||
* @param list The messages to translate.
|
||||
* @param player The player to translate placeholders with respect to.
|
||||
* @param list The messages to translate.
|
||||
* @param player The player to translate placeholders with respect to.
|
||||
* @return The message, translated.
|
||||
*/
|
||||
public List<String> translateList(@NotNull final List<String> list,
|
||||
@@ -246,4 +248,14 @@ public class StringUtils {
|
||||
}
|
||||
return string;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a localized string.
|
||||
*
|
||||
* @param key The key.
|
||||
* @return The string.
|
||||
*/
|
||||
public String getLocalizedString(@NotNull final NamespacedKey key) {
|
||||
return Eco.getHandler().getLocalizedString(key);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,6 +16,8 @@ public class EcoCleaner implements Cleaner {
|
||||
factory.clean();
|
||||
}
|
||||
|
||||
Plugins.LOADED_ECO_PLUGINS.remove(plugin.getName().toLowerCase());
|
||||
|
||||
if (plugin.getClass().getClassLoader() instanceof URLClassLoader urlClassLoader) {
|
||||
try {
|
||||
urlClassLoader.close();
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
package com.willfp.eco.internal;
|
||||
|
||||
import com.willfp.eco.core.EcoPlugin;
|
||||
import lombok.experimental.UtilityClass;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@UtilityClass
|
||||
public class Plugins {
|
||||
public static final Map<String, EcoPlugin> LOADED_ECO_PLUGINS = new HashMap<>();
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
package com.willfp.eco.internal.i18n;
|
||||
|
||||
import com.willfp.eco.core.EcoPlugin;
|
||||
import lombok.experimental.UtilityClass;
|
||||
import org.apache.commons.lang.Validate;
|
||||
import org.bukkit.NamespacedKey;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
@UtilityClass
|
||||
public class LocalizationUtils {
|
||||
public LocalizedString getStringFromKey(@NotNull final NamespacedKey key) {
|
||||
Validate.isTrue(EcoPlugin.getPluginNames().contains(key.getNamespace()));
|
||||
|
||||
EcoPlugin source = EcoPlugin.getPlugin(key.getNamespace());
|
||||
|
||||
assert source != null;
|
||||
|
||||
String message = source.getLangYml().getStringOrNull("messages." + key.getKey());
|
||||
|
||||
if (message == null) {
|
||||
return new LocalizedString(source, key.getKey());
|
||||
} else {
|
||||
return new LocalizedMessage(source, key.getKey());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
package com.willfp.eco.internal.i18n;
|
||||
|
||||
import com.willfp.eco.core.EcoPlugin;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class LocalizedMessage extends LocalizedString {
|
||||
/**
|
||||
* Create a localized message.
|
||||
*
|
||||
* @param plugin The plugin.
|
||||
* @param id The message id.
|
||||
*/
|
||||
public LocalizedMessage(@NotNull final EcoPlugin plugin,
|
||||
@NotNull final String id) {
|
||||
super(plugin, id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return this.getPlugin().getLangYml().getMessage(this.getId());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
package com.willfp.eco.internal.i18n;
|
||||
|
||||
import com.willfp.eco.core.EcoPlugin;
|
||||
import com.willfp.eco.core.PluginDependent;
|
||||
import lombok.Getter;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class LocalizedString extends PluginDependent<EcoPlugin> {
|
||||
/**
|
||||
* The message ID.
|
||||
*/
|
||||
@Getter
|
||||
private final String id;
|
||||
|
||||
/**
|
||||
* Create a localized message.
|
||||
*
|
||||
* @param plugin The plugin.
|
||||
* @param id The message id.
|
||||
*/
|
||||
public LocalizedString(@NotNull final EcoPlugin plugin,
|
||||
@NotNull final String id) {
|
||||
super(plugin);
|
||||
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return this.getPlugin().getLangYml().getString(id);
|
||||
}
|
||||
}
|
||||
@@ -16,6 +16,7 @@ import com.willfp.eco.core.proxy.Cleaner;
|
||||
import com.willfp.eco.core.proxy.ProxyFactory;
|
||||
import com.willfp.eco.core.scheduling.Scheduler;
|
||||
import com.willfp.eco.internal.EcoCleaner;
|
||||
import com.willfp.eco.internal.Plugins;
|
||||
import com.willfp.eco.internal.config.EcoConfigFactory;
|
||||
import com.willfp.eco.internal.config.updating.EcoConfigHandler;
|
||||
import com.willfp.eco.internal.drops.EcoDropQueueFactory;
|
||||
@@ -25,12 +26,16 @@ import com.willfp.eco.internal.factory.EcoMetadataValueFactory;
|
||||
import com.willfp.eco.internal.factory.EcoNamespacedKeyFactory;
|
||||
import com.willfp.eco.internal.factory.EcoRunnableFactory;
|
||||
import com.willfp.eco.internal.gui.EcoGUIFactory;
|
||||
import com.willfp.eco.internal.i18n.LocalizationUtils;
|
||||
import com.willfp.eco.internal.integrations.PlaceholderIntegrationPAPI;
|
||||
import com.willfp.eco.internal.logging.EcoLogger;
|
||||
import com.willfp.eco.internal.proxy.EcoProxyFactory;
|
||||
import com.willfp.eco.internal.scheduling.EcoScheduler;
|
||||
import org.bukkit.NamespacedKey;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
public final class EcoHandler extends EcoSpigotPlugin implements Handler {
|
||||
@@ -110,6 +115,7 @@ public final class EcoHandler extends EcoSpigotPlugin implements Handler {
|
||||
if (cleaner == null) {
|
||||
cleaner = new EcoCleaner();
|
||||
}
|
||||
|
||||
return cleaner;
|
||||
}
|
||||
|
||||
@@ -117,4 +123,24 @@ public final class EcoHandler extends EcoSpigotPlugin implements Handler {
|
||||
public ProxyFactory createProxyFactory(@NotNull final EcoPlugin plugin) {
|
||||
return new EcoProxyFactory(plugin);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getLocalizedString(@NotNull final NamespacedKey key) {
|
||||
return LocalizationUtils.getStringFromKey(key).toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addNewPlugin(@NotNull final EcoPlugin plugin) {
|
||||
Plugins.LOADED_ECO_PLUGINS.put(plugin.getName().toLowerCase(), plugin);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getLoadedPlugins() {
|
||||
return new ArrayList<>(Plugins.LOADED_ECO_PLUGINS.keySet());
|
||||
}
|
||||
|
||||
@Override
|
||||
public EcoPlugin getPluginByName(@NotNull final String name) {
|
||||
return Plugins.LOADED_ECO_PLUGINS.get(name.toLowerCase());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user