Update of /cvsroot/arianne/stendhal/src/games/stendhal/server/core/scripting
In directory vz-cvs-4.sog:/tmp/cvs-serv7452/src/games/stendhal/server/core/scripting
Modified Files:
ScriptInJava.java ScriptingSandbox.java ScriptInGroovy.java
Log Message:
call preExecute() and postExecute() before and after the execution of a script
Index: ScriptInJava.java
===================================================================
RCS file: /cvsroot/arianne/stendhal/src/games/stendhal/server/core/scripting/ScriptInJava.java,v
retrieving revision 1.8
retrieving revision 1.9
diff -C2 -d -r1.8 -r1.9
*** ScriptInJava.java 7 Oct 2010 20:12:03 -0000 1.8
--- ScriptInJava.java 1 Sep 2012 12:27:09 -0000 1.9
***************
*** 1,5 ****
- /* $Id$ */
/***************************************************************************
! * (C) Copyright 2003-2010 - Stendhal *
***************************************************************************
***************************************************************************
--- 1,4 ----
/***************************************************************************
! * (C) Copyright 2003-2012 - Stendhal *
***************************************************************************
***************************************************************************
***************
*** 72,75 ****
--- 71,86 ----
}
+ /**
+ * Initial load of this script.
+ *
+ * @param admin
+ * the admin who load it or <code>null</code> on server start.
+ * @param args
+ * the arguments the admin specified or <code>null</code> on
+ * server start.
+ * @param sandbox
+ * all modifications to the game must be done using this object
+ * in order for the script to be unloadable
+ */
@Override
public boolean load(final Player admin, final List<String> args) {
***************
*** 103,106 ****
--- 114,118 ----
try {
+ preExecute(admin, args);
final Method theMethod = script.getClass().getMethod("execute", signature);
theMethod.invoke(script, params);
***************
*** 108,116 ****
--- 120,139 ----
logger.error(e, e);
setMessage(e.getMessage());
+ postExecute(admin, args, false);
return false;
}
+ postExecute(admin, args, true);
return true;
}
+ /**
+ * Executes this script.
+ *
+ * @param admin
+ * the admin who load it or <code>null</code> on server start.
+ * @param args
+ * the arguments the admin specified or <code>null</code> on
+ * server start.
+ */
@Override
public void unload(final Player admin, final List<String> args) {
Index: ScriptInGroovy.java
===================================================================
RCS file: /cvsroot/arianne/stendhal/src/games/stendhal/server/core/scripting/ScriptInGroovy.java,v
retrieving revision 1.7
retrieving revision 1.8
diff -C2 -d -r1.7 -r1.8
*** ScriptInGroovy.java 19 Sep 2010 02:22:53 -0000 1.7
--- ScriptInGroovy.java 1 Sep 2012 12:27:09 -0000 1.8
***************
*** 1,5 ****
- /* $Id$ */
/***************************************************************************
! * (C) Copyright 2003-2010 - Stendhal *
***************************************************************************
***************************************************************************
--- 1,4 ----
/***************************************************************************
! * (C) Copyright 2003-2012 - Stendhal *
***************************************************************************
***************************************************************************
***************
*** 24,27 ****
--- 23,29 ----
import org.apache.log4j.Logger;
+ /**
+ * manages a script written in groovy
+ */
public class ScriptInGroovy extends ScriptingSandbox {
***************
*** 32,35 ****
--- 34,42 ----
private static final Logger logger = Logger.getLogger(ScriptInGroovy.class);
+ /**
+ * manages a script written in groovy
+ *
+ * @param filename filename
+ */
public ScriptInGroovy(final String filename) {
super(filename);
***************
*** 44,49 ****
}
- // ------------------------------------------------------------------------
@Override
public boolean load(final Player player, final List<String> args) {
--- 51,67 ----
}
+ /**
+ * Initial load of this script.
+ *
+ * @param admin
+ * the admin who load it or <code>null</code> on server start.
+ * @param args
+ * the arguments the admin specified or <code>null</code> on
+ * server start.
+ * @param sandbox
+ * all modifications to the game must be done using this object
+ * in order for the script to be unloadable
+ */
@Override
public boolean load(final Player player, final List<String> args) {
***************
*** 57,60 ****
--- 75,79 ----
boolean ret = true;
+ preExecute(player, args);
try {
final File f = new File(groovyScript);
***************
*** 70,76 ****
--- 89,105 ----
}
+ postExecute(player, args, ret);
return (ret);
}
+ /**
+ * Executes this script.
+ *
+ * @param admin
+ * the admin who load it or <code>null</code> on server start.
+ * @param args
+ * the arguments the admin specified or <code>null</code> on
+ * server start.
+ */
@Override
public boolean execute(final Player player, final List<String> args) {
Index: ScriptingSandbox.java
===================================================================
RCS file: /cvsroot/arianne/stendhal/src/games/stendhal/server/core/scripting/ScriptingSandbox.java,v
retrieving revision 1.9
retrieving revision 1.10
diff -C2 -d -r1.9 -r1.10
*** ScriptingSandbox.java 19 Sep 2010 02:22:53 -0000 1.9
--- ScriptingSandbox.java 1 Sep 2012 12:27:09 -0000 1.10
***************
*** 21,24 ****
--- 21,26 ----
import games.stendhal.server.entity.item.Item;
import games.stendhal.server.entity.npc.NPC;
+ import games.stendhal.server.entity.npc.NPCList;
+ import games.stendhal.server.entity.npc.SpeakerNPC;
import games.stendhal.server.entity.player.Player;
***************
*** 171,174 ****
--- 173,185 ----
}
+ /**
+ * Unloads this script.
+ *
+ * @param admin
+ * the admin who load it or <code>null</code> on server start.
+ * @param args
+ * the arguments the admin specified or <code>null</code> on
+ * server start.
+ */
public void unload(final Player player, final List<String> args) {
final Set<NPC> setNPC = new HashSet<NPC>(loadedNPCs.keySet());
***************
*** 177,180 ****
--- 188,194 ----
remove(npc);
}
+ for (SpeakerNPC npc : NPCList.get()) {
+ npc.getEngine().remove(filename);
+ }
final Set<RPObject> setRPObject = new HashSet<RPObject>(
***************
*** 185,188 ****
--- 199,229 ----
}
+ /**
+ * Prepares execution of the script.
+ *
+ * @param player
+ * the admin who load it or <code>null</code> on server start.
+ * @param args
+ * the arguments the admin specified or <code>null</code> on
+ * server start.
+ */
+ protected void preExecute(final Player player, final List<String> args) {
+ // do nothing
+ }
+
+ /**
+ * Cleans up execution of the script.
+ *
+ * @param player
+ * the admin who load it or <code>null</code> on server start.
+ * @param args
+ * the arguments the admin specified or <code>null</code> on
+ * server start.
+ * @param result true, if the execution was successful; false otherwise
+ */
+ protected void postExecute(final Player player, final List<String> args, boolean result) {
+ // do nothing
+ }
+
public boolean execute(final Player player, final List<String> args) {
// do nothing
|