Search in sources :

Example 1 with MageDataCallback

use of com.elmakers.mine.bukkit.api.data.MageDataCallback in project MagicPlugin by elBukkit.

the class MagicSaveCommandExecutor method onCommand.

@Override
public boolean onCommand(final CommandSender sender, Command command, String label, String[] args) {
    Player player;
    if (args.length < 1) {
        return false;
    }
    if (sender instanceof Player) {
        player = (Player) sender;
        if (!player.hasPermission("Magic.commands.msave")) {
            return false;
        }
    }
    player = DeprecatedUtils.getPlayer(args[0]);
    if (player == null) {
        return false;
    }
    String executeCommand = "";
    for (int i = 1; i < args.length; i++) {
        executeCommand = executeCommand + args[i] + " ";
    }
    MagicController controller = (MagicController) api.getController();
    Mage mage = controller.getMage(player);
    final String cmd = executeCommand.trim().replace("@p", mage.getName());
    final Plugin plugin = controller.getPlugin();
    controller.saveMage(mage, true, new MageDataCallback() {

        @Override
        public void run(MageData data) {
            if (cmd.length() > 0) {
                plugin.getServer().dispatchCommand(sender, cmd);
            }
        }
    });
    return true;
}
Also used : Player(org.bukkit.entity.Player) MageDataCallback(com.elmakers.mine.bukkit.api.data.MageDataCallback) MageData(com.elmakers.mine.bukkit.api.data.MageData) Mage(com.elmakers.mine.bukkit.api.magic.Mage) MagicController(com.elmakers.mine.bukkit.magic.MagicController) Plugin(org.bukkit.plugin.Plugin)

Example 2 with MageDataCallback

use of com.elmakers.mine.bukkit.api.data.MageDataCallback in project MagicPlugin by elBukkit.

the class MagicController method sendPlayerToServer.

@Override
public void sendPlayerToServer(final Player player, final String server) {
    MageDataCallback callback = new MageDataCallback() {

        @Override
        public void run(MageData data) {
            Bukkit.getScheduler().runTaskLater(plugin, new ChangeServerTask(plugin, player, server), 1);
        }
    };
    info("Moving " + player.getName() + " to server " + server, 1);
    Mage mage = getRegisteredMage(player);
    if (mage != null) {
        playerQuit(mage, callback);
    } else {
        callback.run(null);
    }
}
Also used : MageDataCallback(com.elmakers.mine.bukkit.api.data.MageDataCallback) MageData(com.elmakers.mine.bukkit.api.data.MageData) Mage(com.elmakers.mine.bukkit.api.magic.Mage)

Aggregations

MageData (com.elmakers.mine.bukkit.api.data.MageData)2 MageDataCallback (com.elmakers.mine.bukkit.api.data.MageDataCallback)2 Mage (com.elmakers.mine.bukkit.api.magic.Mage)2 MagicController (com.elmakers.mine.bukkit.magic.MagicController)1 Player (org.bukkit.entity.Player)1 Plugin (org.bukkit.plugin.Plugin)1