From bf13858d473a424ee1505d5db4fa08de533ae4ca Mon Sep 17 00:00:00 2001 From: Steven Lawson Date: Tue, 18 Sep 2012 20:30:18 -0400 Subject: [PATCH] Added /onlinemode command. --- .../Commands/Command_onlinemode.java | 71 +++++++++++++++++++ .../Listener/TFM_PlayerListener.java | 2 +- src/plugin.yml | 3 + 3 files changed, 75 insertions(+), 1 deletion(-) create mode 100644 src/me/StevenLawson/TotalFreedomMod/Commands/Command_onlinemode.java diff --git a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_onlinemode.java b/src/me/StevenLawson/TotalFreedomMod/Commands/Command_onlinemode.java new file mode 100644 index 0000000..9ce07c2 --- /dev/null +++ b/src/me/StevenLawson/TotalFreedomMod/Commands/Command_onlinemode.java @@ -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; + } +} diff --git a/src/me/StevenLawson/TotalFreedomMod/Listener/TFM_PlayerListener.java b/src/me/StevenLawson/TotalFreedomMod/Listener/TFM_PlayerListener.java index 57bde91..c58f709 100644 --- a/src/me/StevenLawson/TotalFreedomMod/Listener/TFM_PlayerListener.java +++ b/src/me/StevenLawson/TotalFreedomMod/Listener/TFM_PlayerListener.java @@ -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 diff --git a/src/plugin.yml b/src/plugin.yml index cbbbdc2..d43f800 100644 --- a/src/plugin.yml +++ b/src/plugin.yml @@ -110,6 +110,9 @@ commands: nonuke: description: Superadmin command - Attempt to detect "invisible griefers" and "nukers". usage: / [range] [blockrate] + onlinemode: + description: Console command - Switch server online-mode on and off. + usage: / op: description: Makes a player operator usage: /