Skip to content

Commit 5696e49

Browse files
committed
improved plugin dependency checks
1 parent 1ea16a7 commit 5696e49

File tree

2 files changed

+23
-10
lines changed

2 files changed

+23
-10
lines changed

src/java/de/ntcomputer/minecraft/controllablemobs/api/ControllableMobs.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package de.ntcomputer.minecraft.controllablemobs.api;
22

33
import java.util.HashMap;
4+
import java.util.Map;
45
import java.util.logging.Logger;
56

67
import net.minecraft.server.v1_6_R3.EntityInsentient;
@@ -22,7 +23,7 @@
2223
*
2324
*/
2425
public final class ControllableMobs {
25-
private static final HashMap<LivingEntity,ControllableMob<?>> entities = new HashMap<LivingEntity,ControllableMob<?>>();
26+
private static final Map<LivingEntity,ControllableMob<?>> entities = new HashMap<LivingEntity,ControllableMob<?>>();
2627

2728
static {
2829
onLoad();
@@ -42,7 +43,7 @@ private static void onLoad() {
4243
return;
4344
}
4445
}
45-
} catch(Exception e) {}
46+
} catch(Throwable t) {}
4647
Logger.getLogger("Minecraft").info("[ControllableMobsAPI] initialized by an unknown component");
4748
}
4849

src/java/de/ntcomputer/minecraft/controllablemobs/plugin/ControllableMobsAPIPlugin.java

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import org.bukkit.event.EventHandler;
77
import org.bukkit.event.Listener;
88
import org.bukkit.event.server.PluginEnableEvent;
9+
import org.bukkit.plugin.PluginDescriptionFile;
910
import org.bukkit.plugin.java.JavaPlugin;
1011

1112
public class ControllableMobsAPIPlugin extends JavaPlugin implements Listener, Runnable {
@@ -26,27 +27,38 @@ public void run() {
2627
if(this.usedBy.size()==1) {
2728
this.getLogger().info(" is used by the plugin ["+this.usedBy.get(0)+"]");
2829
} else {
29-
String plugins = "["+usedBy.get(0)+"]";
30-
for(int i=1; i<usedBy.size(); i++) {
31-
plugins+= ", ["+this.usedBy.get(i)+"]";
30+
StringBuilder sb = new StringBuilder();
31+
sb.append(" is used by the plugins [").append(usedBy.get(0)).append("]");
32+
int size = this.usedBy.size();
33+
for(int i=1; i<size; i++) {
34+
sb.append(", [").append(this.usedBy.get(i)).append("]");
3235
}
33-
this.getLogger().info(" is used by the plugins "+plugins);
36+
this.getLogger().info(sb.toString());
3437
}
3538
}
3639
}
3740

41+
private boolean containsIgnoreCase(List<String> list, String object) {
42+
if(list==null) return false;
43+
object = object.trim();
44+
for(String str: list) {
45+
if(str.trim().equalsIgnoreCase(object)) return true;
46+
}
47+
return false;
48+
}
49+
3850
@EventHandler
3951
public void onPluginEnabled(PluginEnableEvent event) {
4052
if(event.getPlugin()==this) return;
41-
final List<String> depend = event.getPlugin().getDescription().getDepend();
42-
if(depend!=null && depend.contains(this.getName())) {
43-
this.usedBy.add(event.getPlugin().getDescription().getFullName());
53+
PluginDescriptionFile desc = event.getPlugin().getDescription();
54+
String name = this.getName();
55+
if( this.containsIgnoreCase(desc.getDepend(), name) || this.containsIgnoreCase(desc.getSoftDepend(), name)) {
56+
this.usedBy.add(desc.getFullName());
4457
}
4558
}
4659

4760
@Override
4861
public void onDisable() {
49-
this.usedBy.clear();
5062
this.usedBy = null;
5163
}
5264

0 commit comments

Comments
 (0)