Package games.stendhal.server.script

Source Code of games.stendhal.server.script.ResetSlot

/* $Id: ResetSlot.java,v 1.3 2010/12/31 10:17:31 kiheru Exp $ */
/***************************************************************************
*                   (C) Copyright 2003-2010 - Stendhal                    *
***************************************************************************
***************************************************************************
*                                                                         *
*   This program is free software; you can redistribute it and/or modify  *
*   it under the terms of the GNU General Public License as published by  *
*   the Free Software Foundation; either version 2 of the License, or     *
*   (at your option) any later version.                                   *
*                                                                         *
***************************************************************************/
package games.stendhal.server.script;

import games.stendhal.server.core.engine.SingletonRepository;
import games.stendhal.server.core.scripting.ScriptImpl;
import games.stendhal.server.entity.player.Player;

import java.util.List;

import marauroa.common.game.RPObject;
import marauroa.common.game.RPSlot;

/**
* Resets an RPSlot.
*
* @author kymara
*/
public class ResetSlot extends ScriptImpl {

  @Override
  public void execute(final Player admin, final List<String> args) {
    super.execute(admin, args);

    // admin help
    if (args.size() < 2) {
      admin.sendPrivateText("Need player name and slot name as parameter.");
      return;
    }

    // find the player and slot
    final Player player = SingletonRepository.getRuleProcessor().getPlayer(args.get(0));
    if (player == null) {
      admin.sendPrivateText("No such player: " + args.get(0));
      return;
    }
    final RPSlot slot = player.getSlot(args.get(1));
    if (slot == null) {
      admin.sendPrivateText("No such slot: " + args.get(1));
      return;
    }

    // remove old store object
    final RPObject rpObject = slot.iterator().next();
    slot.remove(rpObject.getID());

    // create new store object
    slot.add(new RPObject());

    // notify the player
    player.sendPrivateText("Your " + args.get(1) + " state was reset by "
        + admin.getTitle());
  }
}
TOP

Related Classes of games.stendhal.server.script.ResetSlot

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.