TotalFreedomMod/src/main/java/me/totalfreedom/totalfreedommod/command/Command_mbconfig.java

252 lines
8.2 KiB
Java
Raw Normal View History

2018-05-13 19:49:13 +00:00
package me.totalfreedom.totalfreedommod.command;
2019-01-29 04:57:41 +00:00
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Date;
2019-01-29 04:57:41 +00:00
import java.util.List;
2018-05-13 19:49:13 +00:00
import me.totalfreedom.totalfreedommod.masterbuilder.MasterBuilder;
import me.totalfreedom.totalfreedommod.player.FPlayer;
import me.totalfreedom.totalfreedommod.rank.Rank;
import me.totalfreedom.totalfreedommod.util.FUtil;
import net.pravian.aero.util.Ips;
import org.apache.commons.lang.StringUtils;
2018-05-13 19:49:13 +00:00
import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
@CommandPermissions(level = Rank.OP, source = SourceType.BOTH, blockHostConsole = true)
@CommandParameters(description = "List, add, or remove master builders, reload the master builder list, or view the info of master builders.", usage = "/<command> <list | reload | | <add | remove | info> <username>>")
2018-05-13 19:49:13 +00:00
public class Command_mbconfig extends FreedomCommand
{
@Override
public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
{
if (args.length < 1)
{
return false;
}
switch (args[0])
{
case "list":
{
msg("Master Builders: " + StringUtils.join(plugin.mbl.getMasterBuilderNames(), ", "), ChatColor.GOLD);
return true;
}
case "reload":
{
checkRank(Rank.SENIOR_ADMIN);
FUtil.adminAction(sender.getName(), "Reloading the Master Builder list", true);
plugin.mbl.load();
msg("Master Builder list reloaded!");
return true;
}
case "info":
{
if (args.length < 2)
{
return false;
}
checkRank(Rank.SUPER_ADMIN);
MasterBuilder masterBuilder = plugin.mbl.getEntryByName(args[1]);
if (masterBuilder == null)
{
final Player player = getPlayer(args[1]);
if (player != null)
{
masterBuilder = plugin.mbl.getMasterBuilder(player);
}
}
if (masterBuilder == null)
{
msg("Master Builder not found: " + args[1]);
}
else
{
msg(masterBuilder.toString());
}
return true;
}
case "add":
{
if (args.length < 2)
{
return false;
}
checkConsole();
checkRank(Rank.TELNET_ADMIN);
2018-05-13 19:49:13 +00:00
// Player already on the list?
final Player player = getPlayer(args[1]);
if (player != null && plugin.mbl.isMasterBuilder(player))
{
msg("That player is already on the Master Builder list.");
return true;
}
// Find the entry
String name = player != null ? player.getName() : args[1];
MasterBuilder masterBuilder = null;
for (MasterBuilder loopMasterBuilder : plugin.mbl.getAllMasterBuilders().values())
{
if (loopMasterBuilder.getName().equalsIgnoreCase(name))
{
masterBuilder = loopMasterBuilder;
break;
}
}
if (masterBuilder == null) // New entry
{
checkRank(Rank.SENIOR_ADMIN);
2019-04-23 07:36:51 +00:00
if (!FUtil.canManageMasterBuilders(sender.getName()))
{
noPerms();
}
2018-05-13 19:49:13 +00:00
if (player == null)
{
msg(FreedomCommand.PLAYER_NOT_FOUND);
return true;
}
FUtil.adminAction(sender.getName(), "Adding " + player.getName() + " to the Master Builder list", true);
plugin.mbl.addMasterBuilder(new MasterBuilder(player));
if (player != null)
{
plugin.rm.updateDisplay(player);
}
}
else // Existing admin
{
FUtil.adminAction(sender.getName(), "Readding " + masterBuilder.getName() + " to the Master Builder list", true);
if (player != null)
{
masterBuilder.setName(player.getName());
masterBuilder.addIp(Ips.getIp(player));
}
masterBuilder.setLastLogin(new Date());
plugin.mbl.save();
plugin.mbl.updateTables();
if (player != null)
{
plugin.rm.updateDisplay(player);
}
}
if (player != null)
{
final FPlayer fPlayer = plugin.pl.getPlayer(player);
if (fPlayer.getFreezeData().isFrozen())
{
fPlayer.getFreezeData().setFrozen(false);
msg(player.getPlayer(), "You have been unfrozen.");
}
if (!player.isOp())
{
player.setOp(true);
player.sendMessage(YOU_ARE_OP);
}
plugin.pv.removeEntry(player.getName()); // master builders can't have player verification entries
}
return true;
}
case "remove":
{
if (args.length < 2)
{
return false;
}
checkConsole();
checkRank(Rank.SENIOR_ADMIN);
2019-04-23 07:36:51 +00:00
if (!FUtil.canManageMasterBuilders(sender.getName()))
2018-05-13 19:49:13 +00:00
{
noPerms();
}
Player player = getPlayer(args[1]);
MasterBuilder masterBuilder = player != null ? plugin.mbl.getMasterBuilder(player) : plugin.mbl.getEntryByName(args[1]);
if (masterBuilder == null)
{
msg("Master Builder not found: " + args[1]);
2018-05-13 19:49:13 +00:00
return true;
}
FUtil.adminAction(sender.getName(), "Removing " + masterBuilder.getName() + " from the Master Builder list", true);
plugin.mbl.removeMasterBuilder(masterBuilder);
if (player != null)
{
plugin.rm.updateDisplay(player);
}
return true;
}
default:
{
return false;
}
}
}
2019-01-29 04:57:41 +00:00
@Override
public List<String> getTabCompleteOptions(CommandSender sender, Command command, String alias, String[] args)
{
if (sender instanceof Player)
{
if (args.length == 1)
{
List<String> arguments = new ArrayList<>();
arguments.add("list");
if (plugin.al.isAdmin(sender))
{
arguments.add("info");
}
return arguments;
}
else if (args.length == 2 && args[0].equals("info") && plugin.al.isAdmin(sender))
{
return plugin.al.getActiveAdminNames();
}
return Collections.emptyList();
}
else
{
if (args.length == 1)
{
return Arrays.asList("add", "remove", "reload", "list", "info");
}
else if (args.length == 2)
{
if (args[0].equals("add") || args[0].equals("remove") || args[0].equals("setrank") || args[0].equals("info"))
{
return FUtil.getPlayerList();
}
}
}
return Collections.emptyList();
}
2018-05-13 19:49:13 +00:00
}