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

72 lines
2.2 KiB
Java
Raw Normal View History

package me.totalfreedom.totalfreedommod.command;
2012-09-19 00:30:18 +00:00
import me.totalfreedom.totalfreedommod.rank.PlayerRank;
import me.totalfreedom.totalfreedommod.util.FLog;
import me.totalfreedom.totalfreedommod.util.FUtil;
import org.bukkit.ChatColor;
2012-09-19 00:30:18 +00:00
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
@CommandPermissions(level = PlayerRank.NON_OP, source = SourceType.BOTH)
@CommandParameters(description = "Switch server online-mode on and off.", usage = "/<command> <on | off>")
public class Command_onlinemode extends FreedomCommand
2012-09-19 00:30:18 +00:00
{
2012-09-19 00:30:18 +00:00
@Override
public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
2012-09-19 00:30:18 +00:00
{
if (args.length < 1)
{
msg("Server is currently running with 'online-mode=" + (server.getOnlineMode() ? "true" : "false") + "'.", ChatColor.WHITE);
msg("\"/onlinemode on\" and \"/onlinemode off\" can be used to change online mode from the console.", ChatColor.WHITE);
2012-09-19 00:30:18 +00:00
}
else
{
boolean onlineMode;
2013-09-17 16:05:53 +00:00
if (sender instanceof Player && !plugin.al.isSeniorAdmin(sender))
{
noPerms();
return true;
}
2013-09-17 16:05:53 +00:00
2012-09-19 00:30:18 +00:00
if (args[0].equalsIgnoreCase("on"))
{
onlineMode = true;
2012-09-19 00:30:18 +00:00
}
else if (args[0].equalsIgnoreCase("off"))
{
onlineMode = false;
2012-09-19 00:30:18 +00:00
}
else
{
return false;
}
try
{
plugin.si.setOnlineMode(onlineMode);
2012-09-19 00:30:18 +00:00
if (onlineMode)
2012-09-19 00:30:18 +00:00
{
2013-08-14 14:01:42 +00:00
for (Player player : server.getOnlinePlayers())
2012-09-19 00:30:18 +00:00
{
2013-08-14 14:01:42 +00:00
player.kickPlayer("Server is activating \"online-mode=true\". Please reconnect.");
2012-09-19 00:30:18 +00:00
}
}
FUtil.adminAction(sender.getName(), "Turning player validation " + (onlineMode ? "on" : "off") + ".", true);
2012-09-19 00:30:18 +00:00
server.reload();
}
catch (Exception ex)
2012-09-19 00:30:18 +00:00
{
FLog.severe(ex);
2012-09-19 00:30:18 +00:00
}
}
return true;
}
}