",
desc="send a sample message")
def onSampleCommand(sender, command, label, args):
@@ -437,7 +487,10 @@ plugin.py
def onDisable(self):
print "sample plugin disabled"
-
+
+ def onLoaded(self):
+ print "sample plugin load complete"
+
def onCommand(self, sender, command, label, args):
msg = "sample plugin command"
print msg
diff --git a/src/main/java/net/lahwran/bukkit/jython/PluginImporter.java b/src/main/java/net/lahwran/bukkit/jython/PluginImporter.java
index 2ce173e..9d739b6 100644
--- a/src/main/java/net/lahwran/bukkit/jython/PluginImporter.java
+++ b/src/main/java/net/lahwran/bukkit/jython/PluginImporter.java
@@ -10,7 +10,7 @@
import org.python.core.PyObject;
import org.python.core.PyString;
import org.python.core.PyTuple;
-import org.python.modules.imp;
+import org.python.modules._imp;
/**
* Unfinished importer to separate plugins into their own namespaces, possibly also import
@@ -61,7 +61,7 @@ private PyObject retrieveModule(String name) {
PyString pypath = new PyString(pluginpath.getAbsolutePath());
PyObject[] elements = new PyObject[] {pypath};
PyList paths = new PyList(elements);
- PyObject result = imp.find_module(subname, paths);
+ PyObject result = _imp.find_module(subname, paths);
if (result != null) {
PyTuple info = (PyTuple) result;
diff --git a/src/main/java/net/lahwran/bukkit/jython/PythonHooks.java b/src/main/java/net/lahwran/bukkit/jython/PythonHooks.java
index 9324b98..87c492e 100644
--- a/src/main/java/net/lahwran/bukkit/jython/PythonHooks.java
+++ b/src/main/java/net/lahwran/bukkit/jython/PythonHooks.java
@@ -52,6 +52,11 @@ public class PythonHooks {
*/
PyFunction onDisable;
+ /**
+ * Function to call when plugin is initialized
+ */
+ PyFunction onLoaded;
+
/**
* List of handlers to register
*/
@@ -247,6 +252,21 @@ public PyFunction disable(PyFunction func) {
return func;
}
+ /**
+ * Python decorator. functions decorated with this are called on load complete
+ *
+ * @hook.load_complete
+ * def loaded():
+ * print "load complete!"
+ *
+ * @param func function to decorate
+ * @return decorated function
+ */
+ public PyFunction load_complete(PyFunction func) {
+ onLoaded = func;
+ return func;
+ }
+
/**
* Python decorator. functions decorated with this are called as event handlers
* @param type event type
diff --git a/src/main/java/net/lahwran/bukkit/jython/PythonPlugin.java b/src/main/java/net/lahwran/bukkit/jython/PythonPlugin.java
index 5d80ef1..da6b4fe 100644
--- a/src/main/java/net/lahwran/bukkit/jython/PythonPlugin.java
+++ b/src/main/java/net/lahwran/bukkit/jython/PythonPlugin.java
@@ -27,6 +27,9 @@
import org.bukkit.plugin.PluginLogger;
import org.bukkit.plugin.java.JavaPlugin;
import org.python.util.PythonInterpreter;
+import org.python.core.util.FileUtil;
+import org.python.core.PyFile;
+import org.python.core.PyString;
import com.avaje.ebean.EbeanServer;
import com.avaje.ebeaninternal.api.SpiEbeanServer;
@@ -274,6 +277,11 @@ public PluginCommand getCommand(String name) {
*/
public void onLoad() {}
+ public void onLoaded() {
+ if (hooks.onLoaded != null)
+ hooks.onLoaded.__call__();
+ }
+
public ChunkGenerator getDefaultWorldGenerator(String worldName, String id) {
getServer().getLogger().severe("Plugin " + getDescription().getFullName() + " does not contain any generators that may be used in the default world!");
return null;
@@ -335,6 +343,19 @@ public InputStream getResource(String filename) {
}
}
+ public PyFile getPyResource(PyString filename) {
+ if(filename == null) {
+ throw new IllegalArgumentException("Filename cannot be null");
+ }
+
+ try {
+ return FileUtil.wrap(dataFile.getStream(filename.asString()));
+ } catch (IOException e) {
+ //just return null and do not print stack trace as JavaPlugin's getResource does not print it either
+ return null;
+ }
+ }
+
@Override
public void saveResource(String resourcePath, boolean replace) {
if (resourcePath == null || resourcePath.equals("")) {
diff --git a/src/main/java/net/lahwran/bukkit/jython/PythonPluginLoader.java b/src/main/java/net/lahwran/bukkit/jython/PythonPluginLoader.java
index e78a837..a8461da 100644
--- a/src/main/java/net/lahwran/bukkit/jython/PythonPluginLoader.java
+++ b/src/main/java/net/lahwran/bukkit/jython/PythonPluginLoader.java
@@ -171,10 +171,7 @@ private Plugin loadPlugin(File file, boolean ignoreSoftDependencies, PluginDataF
ArrayList depend;
try {
- depend = (ArrayList) description.getDepend();
- if (depend == null) {
- depend = new ArrayList();
- }
+ depend = new ArrayList(description.getDepend());
} catch (ClassCastException ex) {
throw new InvalidPluginException(ex);
}
@@ -288,6 +285,8 @@ private Plugin loadPlugin(File file, boolean ignoreSoftDependencies, PluginDataF
result.initialize(this, server, description, dataFolder, file);
result.setDataFile(data);
+
+ result.onLoaded();
} catch (Throwable t) {
if (data.shouldAddPathEntry() && pythonpath.__contains__(filepath)) {
diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml
index 4b476db..670c173 100644
--- a/src/main/resources/plugin.yml
+++ b/src/main/resources/plugin.yml
@@ -1,3 +1,3 @@
name: PythonLoader
main: com.master.bukkit.python.PythonLoader
-version: 0.3.4
+version: 0.3.6