1 /*************************************************************************** 2 * (C) Copyright 2003-2010 - Stendhal * 3 *************************************************************************** 4 *************************************************************************** 5 * * 6 * This program is free software; you can redistribute it and/or modify * 7 * it under the terms of the GNU General Public License as published by * 8 * the Free Software Foundation; either version 2 of the License, or * 9 * (at your option) any later version. * 10 * * 11 ***************************************************************************/ 12 package games.stendhal.server.script; 13 14 import java.util.List; 15 16 import games.stendhal.common.NotificationType; 17 import games.stendhal.server.core.scripting.ScriptImpl; 18 import games.stendhal.server.entity.CollisionAction; 19 import games.stendhal.server.entity.npc.NPCList; 20 import games.stendhal.server.entity.npc.SpeakerNPC; 21 import games.stendhal.server.entity.player.Player; 22 23 /** 24 * Sets NPC to reverse path on collision 25 * 26 * @author AntumDeluge 27 */ 28 public class SetNPCPathReversible extends ScriptImpl { 29 30 @Override execute(Player admin, List<String> args)31 public void execute(Player admin, List<String> args) { 32 String reverseOnCollision = args.get(1).toLowerCase(); 33 super.execute(admin, args); 34 if (args.size() != 2) { 35 admin.sendPrivateText(NotificationType.ERROR, 36 "/script SetNPCPathReversible npc true|false"); 37 return; 38 } 39 SpeakerNPC npc = NPCList.get().get(args.get(0)); 40 /* TODO: merge with NPC's current collision action rather than replace 41 * it. 42 */ 43 if (reverseOnCollision.equals("true")) { 44 npc.setCollisionAction(CollisionAction.REVERSE); 45 } else if (reverseOnCollision.equals("false")) { 46 npc.setCollisionAction(null); 47 } else { 48 admin.sendPrivateText(NotificationType.ERROR, "Unknown argument \"" 49 + reverseOnCollision + "\". Please declare using \"true\"" 50 + " or \"false\"."); 51 } 52 } 53 } 54