TotalFreedomMod/src/me/StevenLawson/TotalFreedomMod/Commands/Command_onlinemode.java

72 lines
2.3 KiB
Java
Raw Normal View History

2012-09-19 00:30:18 +00:00
package me.StevenLawson.TotalFreedomMod.Commands;
import me.StevenLawson.TotalFreedomMod.TFM_AdminList;
2012-09-19 00:30:18 +00:00
import me.StevenLawson.TotalFreedomMod.TFM_Log;
import me.StevenLawson.TotalFreedomMod.TFM_ServerInterface;
2012-09-19 00:30:18 +00:00
import me.StevenLawson.TotalFreedomMod.TFM_Util;
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;
2013-09-17 16:05:53 +00:00
@CommandPermissions(level = AdminLevel.ALL, source = SourceType.BOTH)
@CommandParameters(description = "Switch server online-mode on and off.", usage = "/<command> <on | off>")
2012-09-19 00:30:18 +00:00
public class Command_onlinemode extends TFM_Command
{
@Override
public boolean run(CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
{
if (args.length < 1)
{
playerMsg("Server is currently running with 'online-mode=" + (server.getOnlineMode() ? "true" : "false") + "'.", ChatColor.WHITE);
2013-09-17 16:05:53 +00:00
playerMsg("\"/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 online_mode;
2013-09-17 16:05:53 +00:00
if (sender instanceof Player && !TFM_AdminList.isSeniorAdmin(sender, true))
{
2014-08-23 18:19:25 +00:00
playerMsg(TFM_Command.MSG_NO_PERMS);
return true;
}
2013-09-17 16:05:53 +00:00
2012-09-19 00:30:18 +00:00
if (args[0].equalsIgnoreCase("on"))
{
online_mode = true;
}
else if (args[0].equalsIgnoreCase("off"))
{
online_mode = false;
}
else
{
return false;
}
try
{
TFM_ServerInterface.setOnlineMode(online_mode);
2012-09-19 00:30:18 +00:00
if (online_mode)
{
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
}
}
2012-10-22 21:03:43 +00:00
TFM_Util.adminAction(sender.getName(), "Turning player validation " + (online_mode ? "on" : "off") + ".", true);
2012-09-19 00:30:18 +00:00
server.reload();
}
catch (Exception ex)
2012-09-19 00:30:18 +00:00
{
TFM_Log.severe(ex);
2012-09-19 00:30:18 +00:00
}
}
return true;
}
}