TotalFreedomMod/src/main/java/me/totalfreedom/totalfreedommod/commands/Command_op.java

61 lines
1.9 KiB
Java
Raw Normal View History

package me.totalfreedom.totalfreedommod.commands;
import me.totalfreedom.totalfreedommod.rank.PlayerRank;
import me.totalfreedom.totalfreedommod.util.DepreciationAggregator;
import me.totalfreedom.totalfreedommod.util.FUtil;
import org.bukkit.ChatColor;
import org.bukkit.OfflinePlayer;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
@CommandPermissions(level = PlayerRank.OP, source = SourceType.BOTH)
@CommandParameters(description = "Makes a player operator", usage = "/<command> <playername>")
public class Command_op extends FreedomCommand
{
@Override
public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
{
if (args.length != 1)
{
return false;
}
if (args[0].equalsIgnoreCase("all") || args[0].equalsIgnoreCase("everyone"))
{
playerMsg("Correct usage: /opall");
return true;
}
OfflinePlayer player = null;
for (Player onlinePlayer : server.getOnlinePlayers())
{
if (args[0].equalsIgnoreCase(onlinePlayer.getName()))
{
player = onlinePlayer;
}
}
// if the player is not online
if (player == null)
{
if (plugin.al.isAdmin(sender) || senderIsConsole)
{
player = DepreciationAggregator.getOfflinePlayer(server, args[0]);
}
else
{
playerMsg("That player is not online.");
playerMsg("You don't have permissions to OP offline players.", ChatColor.YELLOW);
return true;
}
}
FUtil.adminAction(sender.getName(), "Opping " + player.getName(), false);
player.setOp(true);
return true;
}
}