From 0300bece46f359d095a52c2aef5efab5c6316e97 Mon Sep 17 00:00:00 2001 From: Danila Fedorin Date: Fri, 28 Jul 2017 15:18:23 -0700 Subject: [PATCH] Load default plugin without jars. --- src/org/nwapw/abacus/Abacus.java | 2 ++ src/org/nwapw/abacus/plugin/PluginManager.java | 11 +++++++++-- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/org/nwapw/abacus/Abacus.java b/src/org/nwapw/abacus/Abacus.java index 4d50e38..3343d71 100644 --- a/src/org/nwapw/abacus/Abacus.java +++ b/src/org/nwapw/abacus/Abacus.java @@ -2,6 +2,7 @@ package org.nwapw.abacus; import org.nwapw.abacus.plugin.PluginManager; //import org.nwapw.abacus.plugin.StandardPlugin; +import org.nwapw.abacus.plugin.StandardPlugin; import org.nwapw.abacus.window.Window; import org.nwapw.abacus.plugin.ClassFinder; @@ -25,6 +26,7 @@ public class Abacus { e.printStackTrace(); } manager = new PluginManager(); + manager.addInstantiated(new StandardPlugin(manager)); try { ClassFinder.loadJars("plugins") .forEach(plugin -> manager.addClass(plugin)); diff --git a/src/org/nwapw/abacus/plugin/PluginManager.java b/src/org/nwapw/abacus/plugin/PluginManager.java index 62b8bb1..8bb3879 100644 --- a/src/org/nwapw/abacus/plugin/PluginManager.java +++ b/src/org/nwapw/abacus/plugin/PluginManager.java @@ -12,10 +12,14 @@ import java.util.*; */ public class PluginManager { + /** + * List of classes loaded by this manager. + */ + private Set> loadedPluginClasses; /** * A list of loaded plugins. */ - private List plugins; + private Set plugins; /** * List of functions that have been cached, * that is, found in a plugin and returned. @@ -43,7 +47,8 @@ public class PluginManager { * Creates a new plugin manager. */ public PluginManager(){ - plugins = new ArrayList<>(); + loadedPluginClasses = new HashSet<>(); + plugins = new HashSet<>(); cachedFunctions = new HashMap<>(); cachedOperators = new HashMap<>(); allFunctions = new HashSet<>(); @@ -104,7 +109,9 @@ public class PluginManager { * @param plugin the plugin to add. */ public void addInstantiated(Plugin plugin){ + if(loadedPluginClasses.contains(plugin.getClass())) return; plugins.add(plugin); + loadedPluginClasses.add(plugin.getClass()); } /**