}
@Override
public void perform(final Player player, final RPAction action) {
final Entity inspected = getTarget(player, action);
if (inspected == null) {
final String text = "Entity not found";
player.sendPrivateText(text);
return;
}
String clazz = inspected.getRPClass().getName();
String name = "";
if (inspected.has(NAME)) {
name = inspected.get(NAME);
}
if (inspected.isContained()) {
RPObject slot = inspected.getContainer();
new GameEvent(player.getName(), "removed", name + " " + clazz, slot.getID().toString(), Integer.toString(inspected.getX()), Integer.toString(inspected.getY())).raise();
// items should be added to itemlog as well, to help tracing problems
if (inspected instanceof Item) {
// String slotName = null;
// if (inspected.getContainerSlot() != null) {
// slotName = inspected.getContainerSlot().getName();
// }
// String quantity = inspected.get("quantity");
// if (quantity == null) {
// quantity = "1";
// }
new ItemLogger().destroy(player, inspected.getContainerSlot(), inspected, "admin");
}
String slotname = inspected.getContainerSlot().getName();
int objectID = inspected.getID().getObjectID();
if (null != inspected.getContainerSlot().remove(inspected.getID())) {
if (slot instanceof Entity) {
((Entity) slot).notifyWorldAboutChanges();
}
player.sendPrivateText("Removed contained " + name + " " + clazz + " with ID " + objectID + " from " + slotname);
} else {
player.sendPrivateText("could not remove contained " + inspected + " " + clazz + " with ID " + objectID + " from " + slotname);
}
} else {
if (inspected instanceof Player) {
final String text = "You can't remove players";
player.sendPrivateText(text);
return;
}
if (inspected instanceof SpeakerNPC) {
final String text = "You can't remove SpeakerNPCs";
player.sendPrivateText(text);
return;
}
if (inspected instanceof Portal) {
final String text = "You can't remove portals. Try blocking it with a few of /script AdminSign.class.";
player.sendPrivateText(text);
return;
}
final StendhalRPZone zone = inspected.getZone();
if (inspected instanceof RPEntity) {
if (inspected instanceof Creature) {
// *destroyed creatures should not drop items
((Creature) inspected).clearDropItemList();
}
((RPEntity) inspected).onDead(player);
} else if ((inspected instanceof Item) || (inspected instanceof FlowerGrower) || (inspected instanceof Blood) || (inspected instanceof Corpse)) {
// items should be added to itemlog as well, to help tracing problems
if (inspected instanceof Item) {
String quantity = inspected.get("quantity");
if (quantity == null) {
quantity = "1";
}
new ItemLogger().destroy(player, null, inspected, "admin");
}
zone.remove(inspected);
} else {
player.sendPrivateText("You can't remove this type of entity");
return;
}
if (inspected instanceof TurnListener) {
TurnListener listener = (TurnListener) inspected;
TurnNotifier.get().dontNotify(listener);
}
new GameEvent(player.getName(), "removed", name + " " + clazz, zone.getName(), Integer.toString(inspected.getX()), Integer.toString(inspected.getY())).raise();
player.sendPrivateText("Removed " + name + " " + clazz + " with ID " + action.get(TARGET));
}
}