info.mallmc.framework.commands.admincommands.SetCurrencyCommand.java Source code

Java tutorial

Introduction

Here is the source code for info.mallmc.framework.commands.admincommands.SetCurrencyCommand.java

Source

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package info.mallmc.framework.commands.admincommands;

import com.google.common.io.ByteArrayDataOutput;
import com.google.common.io.ByteStreams;
import info.mallmc.framework.Framework;
import info.mallmc.framework.api.MallPlayer;
import info.mallmc.framework.api.PermissionSet;
import info.mallmc.framework.api.Rank;
import info.mallmc.framework.messaging.Messaging;
import org.bukkit.Bukkit;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;

/**
 *
 * @author Rushmead
 */
public class SetCurrencyCommand implements CommandExecutor {

    @Override
    public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
        if (sender instanceof Player) {
            Player p = (Player) sender;
            if (MallPlayer.getPlayer(p.getName()).getPermissions().getPower() != PermissionSet.ALL.getPower()) {
                Messaging.sendMessage(p, "global.command.notallowed");
                return false;
            }
        }
        if (args.length == 0 || args.length < 2) {
            Messaging.sendMessage(sender, "global.command.incorrectusage", "/setcurrency <player> <rank>");
            return false;
        }
        if (MallPlayer.getPlayer(args[0]) != null) {
            MallPlayer mp = MallPlayer.getPlayer(args[0]);
            ByteArrayDataOutput out = ByteStreams.newDataOutput();
            out.writeUTF("currencyset");
            out.writeUTF(args[0]);
            out.writeInt(Integer.parseInt(args[1]));

            // If you don't care about the player
            // Player player = Iterables.getFirst(Bukkit.getOnlinePlayers(), null);
            // Else, specify them
            Bukkit.getPlayer(args[0]).sendPluginMessage(Framework.getInstance(), "BungeeCord", out.toByteArray());
            return true;
        }
        return false;
    }

}