From c33474e0f904439f6f1ea0ebcea486e8acb98bc9 Mon Sep 17 00:00:00 2001 From: sk89q Date: Sat, 2 Apr 2011 01:16:10 -0700 Subject: [PATCH] Added /god back in. --- plugin.yml | 45 ++----- .../bukkit/ConfigurationManager.java | 73 +++++++++- .../worldguard/bukkit/WorldGuardPlugin.java | 2 + .../bukkit/commands/GeneralCommands.java | 126 ++++++++++++++++++ 4 files changed, 212 insertions(+), 34 deletions(-) create mode 100644 src/com/sk89q/worldguard/bukkit/commands/GeneralCommands.java diff --git a/plugin.yml b/plugin.yml index 0e176b4f..b082b9e2 100644 --- a/plugin.yml +++ b/plugin.yml @@ -9,50 +9,29 @@ commands: description: Re-enables fire spread if he has been disabled with /stopfire usage: / god: - description: Toggles god mode - usage: / [other player] + description: Enable god mode + usage: / [player] + ungod: + description: Disable god mode + usage: / [player] heal: description: Heal yourself or another - usage: / [other player] + usage: / [player] slay: description: Slay yourself or another - usage: / [other player] + usage: / [player] stack: description: Stacks items in the player's inventory usage: / aliases: ; region: description: Adjust protected regions - usage: / ... + usage: / ... aliases: [rg, regions] - rd: - description: Alias for /region define - usage: same as /region define - rc: - description: Alias for /region claim - usage: same as /region claim - rf: - description: Alias for /region flag - usage: same as /region flag - ri: - description: Alias for /region info - usage: same as /region info - rlist: - description: Alias for /region list - usage: same as /region list - rp: - description: Alias for /region priority - usage: same as /region priority locate: description: Set your compass towards a person usage: / - reloadwg: - description: Reload WorldGuard's configuration - usage: / - tpregion: - description: Ports you to the region - usage: / ... - aliases: tpr - buyregion: - description: Buy a buyable region - usage: / [info] \ No newline at end of file + worldguard: + description: WorldGuard commands + aliases: wg + usage: / \ No newline at end of file diff --git a/src/com/sk89q/worldguard/bukkit/ConfigurationManager.java b/src/com/sk89q/worldguard/bukkit/ConfigurationManager.java index 87e8acd3..6bd8b524 100644 --- a/src/com/sk89q/worldguard/bukkit/ConfigurationManager.java +++ b/src/com/sk89q/worldguard/bukkit/ConfigurationManager.java @@ -22,8 +22,11 @@ import com.sk89q.worldguard.blacklist.Blacklist; import java.io.File; import java.util.HashMap; +import java.util.HashSet; import java.util.Map; +import java.util.Set; import org.bukkit.World; +import org.bukkit.entity.Player; import org.bukkit.util.config.Configuration; /** @@ -45,6 +48,16 @@ public class ConfigurationManager { */ private Map worlds; + /** + * List of people with god mode. + */ + private Set hasGodMode = new HashSet(); + + /** + * List of people who can breathe underwater. + */ + private Set hasAmphibious = new HashSet(); + public boolean suppressTickSyncWarnings; /** @@ -116,7 +129,65 @@ public void forgetPlayer(LocalPlayer player) { if (bl != null) { bl.forgetPlayer(player); } - } + + hasGodMode.remove(player.getName()); + hasAmphibious.remove(player.getName()); + } + + /** + * Enable god mode for a player. + * + * @param player + */ + public void enableGodMode(Player player) { + hasGodMode.add(player.getName()); + } + + /** + * Disable god mode for a player. + * + * @param player + */ + public void disableGodMode(Player player) { + hasGodMode.remove(player.getName()); + } + + /** + * Check to see if god mode is enabled for a player. + * + * @param player + * @return + */ + public boolean hasGodMode(Player player) { + return hasGodMode.contains(player.getName()); + } + + /** + * Enable amphibious mode for a player. + * + * @param player + */ + public void enableAmphibiousMode(Player player) { + hasAmphibious.add(player.getName()); + } + + /** + * Disable amphibious mode for a player. + * + * @param player + */ + public void disableAmphibiousMode(Player player) { + hasAmphibious.remove(player.getName()); + } + + /** + * Check to see if amphibious mode is enabled for a player. + * + * @param player + * @return + */ + public boolean hasAmphibiousMode(Player player) { + return hasAmphibious.contains(player.getName()); } } diff --git a/src/com/sk89q/worldguard/bukkit/WorldGuardPlugin.java b/src/com/sk89q/worldguard/bukkit/WorldGuardPlugin.java index 2953778d..2083a768 100644 --- a/src/com/sk89q/worldguard/bukkit/WorldGuardPlugin.java +++ b/src/com/sk89q/worldguard/bukkit/WorldGuardPlugin.java @@ -33,6 +33,7 @@ import com.sk89q.worldedit.bukkit.WorldEditPlugin; import com.sk89q.worldguard.LocalPlayer; import com.sk89q.worldguard.TickSyncDelayLoggerFilter; +import com.sk89q.worldguard.bukkit.commands.GeneralCommands; import com.sk89q.worldguard.bukkit.commands.ProtectionCommands; import com.sk89q.worldguard.bukkit.commands.ToggleCommands; import com.sk89q.worldguard.protection.*; @@ -96,6 +97,7 @@ public boolean hasPermission(CommandSender player, String perm) { // Register command classes commands.register(ToggleCommands.class); commands.register(ProtectionCommands.class); + commands.register(GeneralCommands.class); } /** diff --git a/src/com/sk89q/worldguard/bukkit/commands/GeneralCommands.java b/src/com/sk89q/worldguard/bukkit/commands/GeneralCommands.java new file mode 100644 index 00000000..1b574896 --- /dev/null +++ b/src/com/sk89q/worldguard/bukkit/commands/GeneralCommands.java @@ -0,0 +1,126 @@ +// $Id$ +/* + * WorldGuard + * Copyright (C) 2010 sk89q + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . +*/ + +package com.sk89q.worldguard.bukkit.commands; + +import org.bukkit.ChatColor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; +import com.sk89q.minecraft.util.commands.Command; +import com.sk89q.minecraft.util.commands.CommandContext; +import com.sk89q.minecraft.util.commands.CommandException; +import com.sk89q.worldguard.bukkit.ConfigurationManager; +import com.sk89q.worldguard.bukkit.WorldGuardPlugin; + +public class GeneralCommands { + + @Command(aliases = {"god"}, + usage = "[player]", + desc = "Enable godmode on a player", + flags = "", min = 0, max = 1) + public static void god(CommandContext args, WorldGuardPlugin plugin, + CommandSender sender) throws CommandException { + ConfigurationManager config = plugin.getGlobalConfiguration(); + + Iterable targets = null; + boolean included = false; + + // Detect arguments based on the number of arguments provided + if (args.argsLength() == 0) { + targets = plugin.matchPlayers(plugin.checkPlayer(sender)); + + // Check permissions! + plugin.checkPermission(sender, "worldguard.god"); + } else if (args.argsLength() == 1) { + targets = plugin.matchPlayers(sender, args.getString(0)); + + // Check permissions! + plugin.checkPermission(sender, "worldguard.god.other"); + } + + for (Player player : targets) { + config.enableGodMode(player); + + // Tell the user + if (player.equals(sender)) { + player.sendMessage(ChatColor.YELLOW + "God mode enabled!"); + + // Keep track of this + included = true; + } else { + player.sendMessage(ChatColor.YELLOW + "God enabled by " + + plugin.toName(sender) + "."); + + } + } + + // The player didn't receive any items, then we need to send the + // user a message so s/he know that something is indeed working + if (!included && args.hasFlag('s')) { + sender.sendMessage(ChatColor.YELLOW.toString() + "Players now have god mode."); + } + } + + @Command(aliases = {"ungod"}, + usage = "[player]", + desc = "Disable godmode on a player", + flags = "", min = 0, max = 1) + public static void ungod(CommandContext args, WorldGuardPlugin plugin, + CommandSender sender) throws CommandException { + ConfigurationManager config = plugin.getGlobalConfiguration(); + + Iterable targets = null; + boolean included = false; + + // Detect arguments based on the number of arguments provided + if (args.argsLength() == 0) { + targets = plugin.matchPlayers(plugin.checkPlayer(sender)); + + // Check permissions! + plugin.checkPermission(sender, "worldguard.god"); + } else if (args.argsLength() == 1) { + targets = plugin.matchPlayers(sender, args.getString(0)); + + // Check permissions! + plugin.checkPermission(sender, "worldguard.god.other"); + } + + for (Player player : targets) { + config.disableGodMode(player); + + // Tell the user + if (player.equals(sender)) { + player.sendMessage(ChatColor.YELLOW + "God mode disabled!"); + + // Keep track of this + included = true; + } else { + player.sendMessage(ChatColor.YELLOW + "God disabled by " + + plugin.toName(sender) + "."); + + } + } + + // The player didn't receive any items, then we need to send the + // user a message so s/he know that something is indeed working + if (!included && args.hasFlag('s')) { + sender.sendMessage(ChatColor.YELLOW.toString() + "Players now have god mode."); + } + } +}