From: Hendrik <nh...@us...> - 2007-04-16 18:57:41
|
Update of /cvsroot/arianne/stendhal/src/games/stendhal/server/entity In directory sc8-pr-cvs11.sourceforge.net:/tmp/cvs-serv3939/src/games/stendhal/server/entity Modified Files: Tag: VERSION_00_RELEASE_59 PersonalChest.java Log Message: fixed personal chests (second try) 1701665 Index: PersonalChest.java =================================================================== RCS file: /cvsroot/arianne/stendhal/src/games/stendhal/server/entity/PersonalChest.java,v retrieving revision 1.19.2.1 retrieving revision 1.19.2.2 diff -C2 -d -r1.19.2.1 -r1.19.2.2 *** PersonalChest.java 16 Apr 2007 05:42:54 -0000 1.19.2.1 --- PersonalChest.java 16 Apr 2007 18:56:49 -0000 1.19.2.2 *************** *** 7,10 **** --- 7,12 ---- import games.stendhal.server.events.TurnNotifier; + import java.lang.reflect.Constructor; + import java.lang.reflect.InvocationTargetException; import java.util.LinkedList; import java.util.List; *************** *** 15,18 **** --- 17,22 ---- import marauroa.common.game.RPSlot; + import org.apache.log4j.Logger; + /** * A PersonalChest is a Chest that can be used by everyone, but shows *************** *** 27,30 **** --- 31,35 ---- */ public class PersonalChest extends Chest { + private static Logger logger = Logger.getLogger(PersonalChest.class); /** *************** *** 74,78 **** for (RPObject item : getBankSlot()) { ! content.add(new Item((Item) item)); } --- 79,87 ---- for (RPObject item : getBankSlot()) { ! try { ! content.add(cloneItem(item)); ! } catch (Exception e) { ! logger.error("Cannot clone item " + item, e); ! } } *************** *** 100,103 **** --- 109,133 ---- } + + /** + * Copies an item + * + * + * @param item item to copy + * @return copy + * @throws SecurityException + * @throws NoSuchMethodException + * @throws IllegalArgumentException + * @throws InstantiationException + * @throws IllegalAccessException + * @throws InvocationTargetException + */ + private RPObject cloneItem(RPObject item) throws SecurityException, NoSuchMethodException, IllegalArgumentException, InstantiationException, IllegalAccessException, InvocationTargetException { + Class clazz = item.getClass(); + Constructor ctor = clazz.getConstructor(clazz); + Item clone = (Item) ctor.newInstance(item); + return clone; + } + /** * Get the slot that holds items for this chest. |