!improved rpg plugin compatibility messages

This commit is contained in:
Jules 2022-01-31 19:27:59 +01:00
parent 3f1458285a
commit afc2b36a5f
2 changed files with 15 additions and 24 deletions

View File

@ -323,7 +323,7 @@
<dependency> <dependency>
<groupId>com.archyx</groupId> <groupId>com.archyx</groupId>
<artifactId>AureliumSkills</artifactId> <artifactId>AureliumSkills</artifactId>
<version>1.0.6</version> <version>1.2.8</version>
<scope>provided</scope> <scope>provided</scope>
</dependency> </dependency>

View File

@ -57,7 +57,6 @@ import org.jetbrains.annotations.NotNull;
import javax.annotation.Nullable; import javax.annotation.Nullable;
import java.io.File; import java.io.File;
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.logging.Level; import java.util.logging.Level;
@ -369,11 +368,15 @@ public class MMOItems extends LuminePlugin {
public void setRPG(RPGHandler handler) { public void setRPG(RPGHandler handler) {
Validate.notNull(handler, "RPGHandler cannot be null"); Validate.notNull(handler, "RPGHandler cannot be null");
// unregister events from current rpgPlugin instance // Unregister events from current RPGPlugin instance
if (rpgPlugin != null && rpgPlugin instanceof Listener && isEnabled()) HandlerList.unregisterAll((Listener) rpgPlugin); if (rpgPlugin != null && rpgPlugin instanceof Listener && isEnabled())
HandlerList.unregisterAll((Listener) rpgPlugin);
rpgPlugin = handler; rpgPlugin = handler;
if (handler instanceof Listener && isEnabled()) Bukkit.getPluginManager().registerEvents((Listener) handler, this);
// Register new events
if (handler instanceof Listener && isEnabled())
Bukkit.getPluginManager().registerEvents((Listener) handler, this);
} }
/** /**
@ -382,18 +385,13 @@ public class MMOItems extends LuminePlugin {
*/ */
public boolean setRPG(RPGHandler.PluginEnum potentialPlugin) { public boolean setRPG(RPGHandler.PluginEnum potentialPlugin) {
// Check if the plugin is installed
if (Bukkit.getPluginManager().getPlugin(potentialPlugin.getName()) == null) {
MMOItems.plugin.getLogger().log(Level.WARNING, "Could not initialize RPG plugin compatibility with " + potentialPlugin.getName() + ": plugin is not installed");
return false;
}
try { try {
Validate.notNull(Bukkit.getPluginManager().getPlugin(potentialPlugin.getName()), "Plugin is not installed");
setRPG(potentialPlugin.load()); setRPG(potentialPlugin.load());
return true; return true;
// Some loading issue // Some loading issue
} catch (InvocationTargetException | NoSuchMethodException | InstantiationException | IllegalAccessException exception) { } catch (Exception exception) {
MMOItems.plugin.getLogger().log(Level.WARNING, "Could not initialize RPG plugin compatibility with " + potentialPlugin.getName() + ":"); MMOItems.plugin.getLogger().log(Level.WARNING, "Could not initialize RPG plugin compatibility with " + potentialPlugin.getName() + ":");
exception.printStackTrace(); exception.printStackTrace();
return false; return false;
@ -567,22 +565,15 @@ public class MMOItems extends LuminePlugin {
public void findRpgPlugin() { public void findRpgPlugin() {
if (rpgPlugin != null) return; if (rpgPlugin != null) return;
// Preferred rpg provider
String preferred = plugin.getConfig().getString("preferred-rpg-provider", null); String preferred = plugin.getConfig().getString("preferred-rpg-provider", null);
if (preferred != null) if (preferred != null && setRPG(RPGHandler.PluginEnum.valueOf(preferred.toUpperCase())))
try { return;
if (setRPG(RPGHandler.PluginEnum.valueOf(preferred.toUpperCase())))
return;
} catch (IllegalArgumentException exception) {
MMOItems.plugin.getLogger().log(Level.WARNING, "'" + preferred.toUpperCase() + "' is not a valid RPG plugin:");
for (RPGHandler.PluginEnum pgrep : RPGHandler.PluginEnum.values())
MMOItems.plugin.getLogger().log(Level.WARNING, "- " + pgrep.getName());
}
// Look through installed plugins // Look through installed plugins
for (RPGHandler.PluginEnum pluginEnum : RPGHandler.PluginEnum.values()) for (RPGHandler.PluginEnum pluginEnum : RPGHandler.PluginEnum.values())
if (Bukkit.getPluginManager().getPlugin(pluginEnum.getName()) != null) if (Bukkit.getPluginManager().getPlugin(pluginEnum.getName()) != null && setRPG(pluginEnum))
if (setRPG(pluginEnum)) return;
return;
// Just use the default // Just use the default
setRPG(new DefaultHook()); setRPG(new DefaultHook());