Added /onlinemode command.

This commit is contained in:
Steven Lawson 2012-09-18 20:30:18 -04:00
parent 5c86bf4d0f
commit bf13858d47
3 changed files with 75 additions and 1 deletions

View file

@ -0,0 +1,71 @@
package me.StevenLawson.TotalFreedomMod.Commands;
import me.StevenLawson.TotalFreedomMod.TFM_Log;
import me.StevenLawson.TotalFreedomMod.TFM_Util;
import me.StevenLawson.TotalFreedomMod.TotalFreedomMod;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.PropertyManager;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
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 (!senderIsConsole)
{
sender.sendMessage(TotalFreedomMod.MSG_NO_PERMS);
return true;
}
if (args.length < 1)
{
sender.sendMessage("Server is currently running with 'online-mode=" + (server.getOnlineMode() ? "true" : "false") + "'.");
sender.sendMessage("Use \"/onlinemode on\" and \"/onlinemode off\" to change online mode.");
}
else
{
boolean online_mode;
if (args[0].equalsIgnoreCase("on"))
{
online_mode = true;
}
else if (args[0].equalsIgnoreCase("off"))
{
online_mode = false;
}
else
{
return false;
}
try
{
PropertyManager prop_man = MinecraftServer.getServer().getPropertyManager();
prop_man.a("online-mode", online_mode);
prop_man.savePropertiesFile();
if (online_mode)
{
for (Player p : server.getOnlinePlayers())
{
p.kickPlayer("Server is activating \"online-mode=true\". Please reconnect.");
}
}
TFM_Util.adminAction(sender.getName(), "Switched 'online-mode=" + (server.getOnlineMode() ? "true" : "false") + "'.", true);
server.reload();
}
catch (Exception ex)
{
TFM_Log.severe(ex);
}
}
return true;
}
}

View file

@ -409,7 +409,7 @@ public class TFM_PlayerListener implements Listener
if (block_command)
{
TFM_Util.autoEject(p, "That command is prohibited.");
TFM_Util.autoEject(p, "You used a prohibited command: " + command);
TFM_Util.bcastMsg(p.getName() + " was automatically kicked for using harmful commands.", ChatColor.RED);
}
else

View file

@ -110,6 +110,9 @@ commands:
nonuke:
description: Superadmin command - Attempt to detect "invisible griefers" and "nukers".
usage: /<command> <on | off> [range] [blockrate]
onlinemode:
description: Console command - Switch server online-mode on and off.
usage: /<command> <on | off>
op:
description: Makes a player operator
usage: /<command> <playername>