From: Hendrik <nh...@us...> - 2007-06-30 21:43:29
|
Update of /cvsroot/arianne/stendhal/src/games/stendhal/server/scripting In directory sc8-pr-cvs11.sourceforge.net:/tmp/cvs-serv22061/src/games/stendhal/server/scripting Modified Files: ScriptingSandbox.java Log Message: Fixed unwanted object retention bug Index: ScriptingSandbox.java =================================================================== RCS file: /cvsroot/arianne/stendhal/src/games/stendhal/server/scripting/ScriptingSandbox.java,v retrieving revision 1.14 retrieving revision 1.15 diff -C2 -d -r1.14 -r1.15 *** ScriptingSandbox.java 11 Jun 2007 03:03:22 -0000 1.14 --- ScriptingSandbox.java 30 Jun 2007 21:43:28 -0000 1.15 *************** *** 12,17 **** import games.stendhal.server.entity.player.Player; ! import java.util.ArrayList; import java.util.List; import marauroa.common.Log4J; --- 12,20 ---- import games.stendhal.server.entity.player.Player; ! import java.util.HashSet; import java.util.List; + import java.util.Map; + import java.util.Set; + import java.util.WeakHashMap; import marauroa.common.Log4J; *************** *** 22,28 **** public abstract class ScriptingSandbox { ! private ArrayList<NPC> loadedNPCs = new ArrayList<NPC>(); ! ! private ArrayList<RPObject> loadedRPObjects = new ArrayList<RPObject>(); private String exceptionMessage; --- 25,33 ---- public abstract class ScriptingSandbox { ! // loadedNPCs and loadedRPObject are Sets. They are implemented using ! // maps because there are no WeakSets in Java. (In current Sun ! // Java HashSet is implemented using HashMap anyway). ! private Map<NPC, Object> loadedNPCs = new WeakHashMap<NPC, Object>(); ! private Map<RPObject, Object> loadedRPObjects = new WeakHashMap<RPObject, Object>(); private String exceptionMessage; *************** *** 89,93 **** zone.add(npc); StendhalRPRuleProcessor.get().addNPC(npc); ! loadedNPCs.add(npc); logger.info(filename + " added NPC: " + npc); } --- 94,98 ---- zone.add(npc); StendhalRPRuleProcessor.get().addNPC(npc); ! loadedNPCs.put(npc, null); logger.info(filename + " added NPC: " + npc); } *************** *** 98,102 **** zone.assignRPObjectID(object); zone.add(object); ! loadedRPObjects.add(object); logger.info(filename + " added object: " + object); } --- 103,107 ---- zone.assignRPObjectID(object); zone.add(object); ! loadedRPObjects.put(object, null); logger.info(filename + " added object: " + object); } *************** *** 123,130 **** } - public List<RPObject> getCreatedRPObjects() { - return loadedRPObjects; - } - public Creature add(Creature template, int x, int y) { Creature creature = template.getInstance(); --- 128,131 ---- *************** *** 134,138 **** zone.add(creature); StendhalRPRuleProcessor.get().addNPC(creature); ! loadedNPCs.add(creature); logger.info(filename + " added creature: " + creature); } else { --- 135,139 ---- zone.add(creature); StendhalRPRuleProcessor.get().addNPC(creature); ! loadedNPCs.put(creature, null); logger.info(filename + " added creature: " + creature); } else { *************** *** 200,208 **** Log4J.startMethod(logger, "unload"); ! for (NPC npc : (List<NPC>) loadedNPCs.clone()) { remove(npc); } ! for (RPObject object : (List<RPObject>) loadedRPObjects.clone()) { remove(object); } --- 201,211 ---- Log4J.startMethod(logger, "unload"); ! Set<NPC> setNPC = new HashSet<NPC>(loadedNPCs.keySet()); ! for (NPC npc : setNPC) { remove(npc); } ! Set<RPObject> setRPObject = new HashSet<RPObject>(loadedRPObjects.keySet()); ! for (RPObject object : setRPObject) { remove(object); } |