From a4dd0dba88328c5e29d87750881a6c09dd0ccf68 Mon Sep 17 00:00:00 2001 From: Keir Nellyer Date: Mon, 31 Mar 2014 15:28:18 +0100 Subject: [PATCH] Allow 'softdepends' in plugin description --- .../net/md_5/bungee/api/plugin/PluginDescription.java | 4 ++++ .../net/md_5/bungee/api/plugin/PluginManager.java | 11 +++++++++-- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/api/src/main/java/net/md_5/bungee/api/plugin/PluginDescription.java b/api/src/main/java/net/md_5/bungee/api/plugin/PluginDescription.java index f754eb41..ef12ae90 100644 --- a/api/src/main/java/net/md_5/bungee/api/plugin/PluginDescription.java +++ b/api/src/main/java/net/md_5/bungee/api/plugin/PluginDescription.java @@ -36,6 +36,10 @@ public class PluginDescription * Plugin hard dependencies. */ private Set depends = new HashSet<>(); + /** + * Plugin soft dependencies. + */ + private Set softDepends = new HashSet<>(); /** * File we were loaded from. */ diff --git a/api/src/main/java/net/md_5/bungee/api/plugin/PluginManager.java b/api/src/main/java/net/md_5/bungee/api/plugin/PluginManager.java index 87b48c1c..5e21db4c 100644 --- a/api/src/main/java/net/md_5/bungee/api/plugin/PluginManager.java +++ b/api/src/main/java/net/md_5/bungee/api/plugin/PluginManager.java @@ -12,10 +12,12 @@ import java.net.URLClassLoader; import java.util.Arrays; import java.util.Collection; import java.util.HashMap; +import java.util.HashSet; import java.util.Iterator; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; +import java.util.Set; import java.util.Stack; import java.util.jar.JarEntry; import java.util.jar.JarFile; @@ -219,11 +221,16 @@ public class PluginManager return pluginStatuses.get( plugin ); } + // combine all dependencies for 'for loop' + Set dependencies = new HashSet<>(); + dependencies.addAll( plugin.getDepends() ); + dependencies.addAll( plugin.getSoftDepends() ); + // success status boolean status = true; // try to load dependencies first - for ( String dependName : plugin.getDepends() ) + for ( String dependName : dependencies ) { PluginDescription depend = toLoad.get( dependName ); Boolean dependStatus = ( depend != null ) ? pluginStatuses.get( depend ) : Boolean.FALSE; @@ -248,7 +255,7 @@ public class PluginManager } } - if ( dependStatus == Boolean.FALSE ) + if ( dependStatus == Boolean.FALSE && plugin.getDepends().contains( dependName ) ) // only fail if this wasn't a soft dependency { ProxyServer.getInstance().getLogger().log( Level.WARNING, "{0} (required by {1}) is unavailable", new Object[] {