commands now handled by commandhandler, updated /region info and /region flag for extended flag data

This commit is contained in:
Redecouverte 2011-02-24 21:10:54 +01:00
parent 5411a294e7
commit 17e9105b9c
25 changed files with 2181 additions and 1037 deletions

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,50 @@
// $Id$
/*
* WorldGuard
* Copyright (C) 2010 sk89q <http://www.sk89q.com>
*
* 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 <http://www.gnu.org/licenses/>.
*/
package com.sk89q.worldguard.bukkit.commands;
import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
import com.sk89q.worldguard.bukkit.commands.CommandHandler.CommandHandlingException;
import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;
/**
*
* @author Michael
*/
public class CommandAllowFire extends WgCommand {
public boolean handle(CommandSender sender, String senderName, String command, String[] args, CommandHandler ch, WorldGuardPlugin wg) throws CommandHandlingException
{
ch.checkPermission(sender, "/stopfire");
ch.checkArgs(args, 0, 0);
if (wg.fireSpreadDisableToggle) {
wg.getServer().broadcastMessage(ChatColor.YELLOW
+ "Fire spread has been globally re-enabled by " + senderName + ".");
} else {
sender.sendMessage(ChatColor.YELLOW + "Fire spread was already globally enabled.");
}
wg.fireSpreadDisableToggle = false;
return true;
}
}

View File

@ -0,0 +1,81 @@
// $Id$
/*
* WorldGuard
* Copyright (C) 2010 sk89q <http://www.sk89q.com>
*
* 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 <http://www.gnu.org/licenses/>.
*/
package com.sk89q.worldguard.bukkit.commands;
import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
import com.sk89q.worldguard.bukkit.commands.CommandHandler.CommandHandlingException;
import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import static com.sk89q.worldguard.bukkit.BukkitUtil.*;
/**
*
* @author Michael
*/
public class CommandGod extends WgCommand {
public boolean handle(CommandSender sender, String senderName, String command, String[] args, CommandHandler ch, WorldGuardPlugin wg) throws CommandHandlingException {
if (!(sender instanceof Player)) {
sender.sendMessage("Only players may use this command");
return true;
}
Player player = (Player) sender;
ch.checkPermission(player, "/god");
ch.checkArgs(args, 0, 1);
// Allow setting other people invincible
if (args.length > 0) {
if (!wg.hasPermission(player, "/godother")) {
player.sendMessage(ChatColor.RED + "You don't have permission to make others invincible.");
return true;
}
Player other = matchSinglePlayer(wg.getServer(), args[0]);
if (other == null) {
player.sendMessage(ChatColor.RED + "Player not found.");
} else {
if (!wg.invinciblePlayers.contains(other.getName())) {
wg.invinciblePlayers.add(other.getName());
player.sendMessage(ChatColor.YELLOW + other.getName() + " is now invincible!");
other.sendMessage(ChatColor.YELLOW + player.getName() + " has made you invincible!");
} else {
wg.invinciblePlayers.remove(other.getName());
player.sendMessage(ChatColor.YELLOW + other.getName() + " is no longer invincible.");
other.sendMessage(ChatColor.YELLOW + player.getName() + " has taken away your invincibility.");
}
}
// Invincibility for one's self
} else {
if (!wg.invinciblePlayers.contains(player.getName())) {
wg.invinciblePlayers.add(player.getName());
player.sendMessage(ChatColor.YELLOW + "You are now invincible!");
} else {
wg.invinciblePlayers.remove(player.getName());
player.sendMessage(ChatColor.YELLOW + "You are no longer invincible.");
}
}
return true;
}
}

View File

@ -0,0 +1,278 @@
// $Id$
/*
* WorldGuard
* Copyright (C) 2010 sk89q <http://www.sk89q.com>
*
* 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 <http://www.gnu.org/licenses/>.
*/
package com.sk89q.worldguard.bukkit.commands;
import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
import com.sk89q.worldguard.domains.DefaultDomain;
import java.util.HashMap;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
/**
*
* @author Michael
*/
public class CommandHandler {
private WorldGuardPlugin wg;
private Map<String, WgCommand> commandMap;
private static Pattern groupPattern = Pattern.compile("^[gG]:(.+)$");
public static int CMD_LIST_SIZE = 9;
public CommandHandler(WorldGuardPlugin wg)
{
this.wg = wg;
this.commandMap = new HashMap<String, WgCommand>();
this.commandMap.put("allowfire", new CommandAllowFire());
this.commandMap.put("god", new CommandGod());
this.commandMap.put("heal", new CommandHeal());
this.commandMap.put("locate", new CommandLocate());
this.commandMap.put("region", new RegionCommandHandler());
this.commandMap.put("reloadwg", new CommandReloadWG());
this.commandMap.put("slay", new CommandSlay());
this.commandMap.put("stack", new CommandStack());
this.commandMap.put("stopfire", new CommandStopFire());
}
public boolean handleCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {
try {
String cmdName = cmd.getName().toLowerCase();
WgCommand wgcmd = commandMap.get(cmdName);
if (wgcmd == null) {
return false;
}
String senderName = sender instanceof Player ? ((Player)sender).getName() : "Console";
wgcmd.handle(sender, senderName, cmdName, args, this, wg);
return true;
} catch (InsufficientArgumentsException e) {
if (e.getHelp() != null) {
sender.sendMessage(ChatColor.RED + e.getHelp());
return true;
} else {
return false;
}
} catch (InsufficientPermissionsException e) {
sender.sendMessage(ChatColor.RED + "You don't have sufficient permission.");
return true;
} catch (CommandHandlingException e) {
return true;
} catch (Throwable t) {
sender.sendMessage(ChatColor.RED + "ERROR: " + t.getMessage());
t.printStackTrace();
return true;
}
}
/**
* Checks to make sure that there are enough but not too many arguments.
*
* @param args
* @param min
* @param max -1 for no maximum
* @throws InsufficientArgumentsException
*/
public static void checkArgs(String[] args, int min, int max)
throws InsufficientArgumentsException {
if (args.length < min || (max != -1 && args.length > max)) {
throw new InsufficientArgumentsException();
}
}
/**
* Checks to make sure that there are enough but not too many arguments.
*
* @param args
* @param min
* @param max -1 for no maximum
* @param help
* @throws InsufficientArgumentsException
*/
public static void checkArgs(String[] args, int min, int max, String help)
throws InsufficientArgumentsException {
if (args.length < min || (max != -1 && args.length > max)) {
throw new InsufficientArgumentsException(help);
}
}
/**
* Thrown when command handling has raised an exception.
*
* @author sk89q
*/
public static class CommandHandlingException extends Exception {
private static final long serialVersionUID = 7912130636812036780L;
}
/**
* Thrown when a player has insufficient permissions.
*
* @author sk89q
*/
public static class InsufficientPermissionsException extends CommandHandlingException {
private static final long serialVersionUID = 9087662707619954750L;
}
/**
* Thrown when a command wasn't given sufficient arguments.
*
* @author sk89q
*/
public static class InsufficientArgumentsException extends CommandHandlingException {
private static final long serialVersionUID = 4153597953889773788L;
private final String help;
public InsufficientArgumentsException() {
help = null;
}
public InsufficientArgumentsException(String msg) {
this.help = msg;
}
public String getHelp() {
return help;
}
}
/**
* Checks for the command or /region.
*
* @param player
* @param cmd
* @return
*/
public boolean canUseRegionCommand(Player player, String cmd) {
return wg.hasPermission(player, "/region")
|| wg.hasPermission(player, cmd);
}
/**
* Checks to see if there are sufficient permissions, otherwise an exception
* is raised in that case.
*
* @param player
* @param permission
* @throws InsufficientPermissionsException
*/
public void checkRegionPermission(Player player, String permission)
throws InsufficientPermissionsException {
if (!wg.hasPermission(player, "/region") && !wg.hasPermission(player, permission)) {
throw new InsufficientPermissionsException();
}
}
/**
* Checks to see if there are sufficient permissions, otherwise an exception
* is raised in that case.
*
* @param sender
* @param permission
* @throws InsufficientPermissionsException
*/
public void checkPermission(CommandSender sender, String permission)
throws InsufficientPermissionsException {
if (!(sender instanceof Player)) {
return;
}
if (!wg.hasPermission((Player)sender, permission)) {
throw new InsufficientPermissionsException();
}
}
/**
* Parse a group/player DefaultDomain specification for areas.
*
* @param domain
* @param split
* @param startIndex
*/
public static void addToDomain(DefaultDomain domain,
String[] split, int startIndex) {
for (int i = startIndex; i < split.length; i++) {
String s = split[i];
Matcher m = groupPattern.matcher(s);
if (m.matches()) {
domain.addGroup(m.group(1));
} else {
domain.addPlayer(s);
}
}
}
/**
* Parse a group/player DefaultDomain specification for areas.
*
* @param domain
* @param split
* @param startIndex
*/
public static void removeFromDomain(DefaultDomain domain,
String[] split, int startIndex) {
for (int i = startIndex; i < split.length; i++) {
String s = split[i];
Matcher m = groupPattern.matcher(s);
if (m.matches()) {
domain.removeGroup(m.group(1));
} else {
domain.removePlayer(s);
}
}
}
/**
* Parse a group/player DefaultDomain specification for areas.
*
* @param split
* @param startIndex
* @return
*/
public static DefaultDomain parseDomainString(String[] split, int startIndex) {
DefaultDomain domain = new DefaultDomain();
for (int i = startIndex; i < split.length; i++) {
String s = split[i];
Matcher m = groupPattern.matcher(s);
if (m.matches()) {
domain.addGroup(m.group(1));
} else {
domain.addPlayer(s);
}
}
return domain;
}
}

View File

@ -0,0 +1,67 @@
// $Id$
/*
* WorldGuard
* Copyright (C) 2010 sk89q <http://www.sk89q.com>
*
* 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 <http://www.gnu.org/licenses/>.
*/
package com.sk89q.worldguard.bukkit.commands;
import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
import com.sk89q.worldguard.bukkit.commands.CommandHandler.CommandHandlingException;
import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import static com.sk89q.worldguard.bukkit.BukkitUtil.*;
/**
*
* @author Michael
*/
public class CommandHeal extends WgCommand {
public boolean handle(CommandSender sender, String senderName, String command, String[] args, CommandHandler ch, WorldGuardPlugin wg) throws CommandHandlingException {
if (!(sender instanceof Player)) {
sender.sendMessage("Only players may use this command");
return true;
}
Player player = (Player) sender;
ch.checkPermission(player, "/heal");
ch.checkArgs(args, 0, 1);
// Allow healing other people
if (args.length > 0) {
if (!wg.hasPermission(player, "/healother")) {
player.sendMessage(ChatColor.RED + "You don't have permission to heal others.");
return true;
}
Player other = matchSinglePlayer(wg.getServer(), args[0]);
if (other == null) {
player.sendMessage(ChatColor.RED + "Player not found.");
} else {
other.setHealth(20);
player.sendMessage(ChatColor.YELLOW + other.getName() + " has been healed!");
other.sendMessage(ChatColor.YELLOW + player.getName() + " has healed you!");
}
} else {
player.setHealth(20);
player.sendMessage(ChatColor.YELLOW + "You have been healed!");
}
return true;
}
}

View File

@ -0,0 +1,79 @@
// $Id$
/*
* WorldGuard
* Copyright (C) 2010 sk89q <http://www.sk89q.com>
*
* 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 <http://www.gnu.org/licenses/>.
*/
package com.sk89q.worldguard.bukkit.commands;
import com.sk89q.worldguard.bukkit.BukkitUtil;
import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
import com.sk89q.worldguard.bukkit.commands.CommandHandler.CommandHandlingException;
import org.bukkit.ChatColor;
import org.bukkit.Location;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
/**
*
* @author Michael
*/
public class CommandLocate extends WgCommand {
public boolean handle(CommandSender sender, String senderName, String command, String[] args, CommandHandler ch, WorldGuardPlugin wg) throws CommandHandlingException {
if (!(sender instanceof Player)) {
sender.sendMessage("Only players may use this command");
return true;
}
Player player = (Player) sender;
ch.checkPermission(player, "/locate");
ch.checkArgs(args, 0, 3);
if (args.length == 1) {
String name = args[0];
Player target = BukkitUtil.matchSinglePlayer(wg.getServer(), name);
if (target != null) {
player.setCompassTarget(target.getLocation());
player.sendMessage(ChatColor.YELLOW + "Compass target set to " + target.getName() + ".");
} else {
player.sendMessage(ChatColor.RED + "Could not find player.");
}
} else if (args.length == 3) {
try {
Location loc = new Location(
player.getWorld(),
Integer.parseInt(args[0]),
Integer.parseInt(args[1]),
Integer.parseInt(args[2]));
player.setCompassTarget(loc);
player.sendMessage(ChatColor.YELLOW + "Compass target set to "
+ loc.getBlockX() + ","
+ loc.getBlockY() + ","
+ loc.getBlockZ() + ".");
} catch (NumberFormatException e) {
player.sendMessage(ChatColor.RED + "Invalid number specified");
}
} else if (args.length == 0) {
player.setCompassTarget(player.getWorld().getSpawnLocation());
player.sendMessage(ChatColor.YELLOW + "Compass reset to the spawn location.");
} else {
return false;
}
return true;
}
}

View File

@ -0,0 +1,91 @@
// $Id$
/*
* WorldGuard
* Copyright (C) 2010 sk89q <http://www.sk89q.com>
*
* 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 <http://www.gnu.org/licenses/>.
*/
package com.sk89q.worldguard.bukkit.commands;
import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
import com.sk89q.worldguard.bukkit.commands.CommandHandler.CommandHandlingException;
import com.sk89q.worldguard.protection.regionmanager.RegionManager;
import com.sk89q.worldguard.protection.regions.ProtectedRegion;
import java.io.IOException;
import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
/**
*
* @author Michael
*/
public class CommandRegionAddMember extends WgCommand {
public boolean handle(CommandSender sender, String senderName, String command, String[] args, CommandHandler ch, WorldGuardPlugin wg) throws CommandHandlingException {
if (!(sender instanceof Player)) {
sender.sendMessage("Only players may use this command");
return true;
}
Player player = (Player) sender;
if (!wg.hasPermission(player, "/regionclaim") && !wg.hasPermission(player, "/regionmembership")) {
ch.checkRegionPermission(player, "/regiondefine");
}
ch.checkArgs(args, 2, -1, "/region add[member|owner] <id> [player1 [group1 [players/groups...]]]");
String action = command;
boolean isOwner = action.equalsIgnoreCase("addowner");
RegionManager mgr = wg.getGlobalRegionManager().getRegionManager(player.getWorld().getName());
String id = args[0].toLowerCase();
if (!mgr.hasRegion(id)) {
player.sendMessage(ChatColor.RED + "A region with ID '"
+ id + "' doesn't exist.");
return true;
}
ProtectedRegion existing = mgr.getRegion(id);
if (!ch.canUseRegionCommand(player, "/regiondefine")
&& !existing.isOwner(wg.wrapPlayer(player))) {
player.sendMessage(ChatColor.RED + "You don't own this region.");
return true;
}
if (isOwner) {
ch.addToDomain(existing.getOwners(), args, 1);
} else {
ch.addToDomain(existing.getMembers(), args, 1);
}
try {
mgr.save();
player.sendMessage(ChatColor.YELLOW + "Region updated!");
player.sendMessage(ChatColor.GRAY + "Current owners: "
+ existing.getOwners().toUserFriendlyString());
player.sendMessage(ChatColor.GRAY + "Current members: "
+ existing.getMembers().toUserFriendlyString());
} catch (IOException e) {
player.sendMessage(ChatColor.RED + "Region database failed to save: "
+ e.getMessage());
}
return true;
}
}

View File

@ -0,0 +1,119 @@
// $Id$
/*
* WorldGuard
* Copyright (C) 2010 sk89q <http://www.sk89q.com>
*
* 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 <http://www.gnu.org/licenses/>.
*/
package com.sk89q.worldguard.bukkit.commands;
import com.sk89q.worldedit.BlockVector;
import com.sk89q.worldedit.IncompleteRegionException;
import com.sk89q.worldedit.LocalSession;
import com.sk89q.worldedit.bukkit.BukkitWorld;
import com.sk89q.worldedit.bukkit.WorldEditPlugin;
import com.sk89q.worldedit.regions.Polygonal2DRegion;
import com.sk89q.worldedit.regions.Region;
import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
import com.sk89q.worldguard.bukkit.commands.CommandHandler.CommandHandlingException;
import com.sk89q.worldguard.protection.regionmanager.RegionManager;
import com.sk89q.worldguard.protection.regions.ProtectedCuboidRegion;
import com.sk89q.worldguard.protection.regions.ProtectedPolygonalRegion;
import com.sk89q.worldguard.protection.regions.ProtectedRegion;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.plugin.Plugin;
/**
*
* @author Michael
*/
public class CommandRegionClaim extends WgCommand {
public boolean handle(CommandSender sender, String senderName, String command, String[] args, CommandHandler ch, WorldGuardPlugin wg) throws CommandHandlingException {
if (!(sender instanceof Player)) {
sender.sendMessage("Only players may use this command");
return true;
}
Player player = (Player) sender;
Plugin wePlugin = wg.getServer().getPluginManager().getPlugin("WorldEdit");
if (wePlugin == null) {
player.sendMessage(ChatColor.RED + "WorldEdit must be installed and enabled!");
return true;
}
ch.checkRegionPermission(player, "/regionclaim");
ch.checkArgs(args, 1, 1, "/region claim <id>");
try {
String id = args[0].toLowerCase();
RegionManager mgr = wg.getGlobalRegionManager().getRegionManager(player.getWorld().getName());
ProtectedRegion existing = mgr.getRegion(id);
if (existing != null) {
if (!existing.getOwners().contains(wg.wrapPlayer(player))) {
player.sendMessage(ChatColor.RED + "You don't own this region.");
return true;
}
}
WorldEditPlugin worldEdit = (WorldEditPlugin) wePlugin;
LocalSession session = worldEdit.getSession(player);
Region weRegion;
weRegion = session.getSelection(new BukkitWorld(player.getWorld()));
ProtectedRegion region;
if (weRegion instanceof Polygonal2DRegion) {
Polygonal2DRegion pweRegion = (Polygonal2DRegion) weRegion;
int minY = pweRegion.getMinimumPoint().getBlockY();
int maxY = pweRegion.getMaximumPoint().getBlockY();
region = new ProtectedPolygonalRegion(id, pweRegion.getPoints(), minY, maxY);
} else {
BlockVector min = weRegion.getMinimumPoint().toBlockVector();
BlockVector max = weRegion.getMaximumPoint().toBlockVector();
region = new ProtectedCuboidRegion(id, min, max);
}
if (mgr.overlapsUnownedRegion(region, wg.wrapPlayer(player))) {
player.sendMessage(ChatColor.RED + "This region overlaps with someone else's region.");
return true;
}
region.getOwners().addPlayer(player.getName());
mgr.addRegion(region);
mgr.save();
player.sendMessage(ChatColor.YELLOW + "Region saved as " + id + ".");
} catch (IncompleteRegionException e) {
player.sendMessage(ChatColor.RED + "You must first define an area in WorldEdit.");
} catch (IOException e) {
player.sendMessage(ChatColor.RED + "Region database failed to save: "
+ e.getMessage());
}
return true;
}
}

View File

@ -0,0 +1,102 @@
// $Id$
/*
* WorldGuard
* Copyright (C) 2010 sk89q <http://www.sk89q.com>
*
* 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 <http://www.gnu.org/licenses/>.
*/
package com.sk89q.worldguard.bukkit.commands;
import com.sk89q.worldedit.BlockVector;
import com.sk89q.worldedit.IncompleteRegionException;
import com.sk89q.worldedit.LocalSession;
import com.sk89q.worldedit.bukkit.BukkitWorld;
import com.sk89q.worldedit.bukkit.WorldEditPlugin;
import com.sk89q.worldedit.regions.Polygonal2DRegion;
import com.sk89q.worldedit.regions.Region;
import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
import com.sk89q.worldguard.bukkit.commands.CommandHandler.CommandHandlingException;
import com.sk89q.worldguard.protection.regionmanager.RegionManager;
import com.sk89q.worldguard.protection.regions.ProtectedCuboidRegion;
import com.sk89q.worldguard.protection.regions.ProtectedPolygonalRegion;
import com.sk89q.worldguard.protection.regions.ProtectedRegion;
import java.io.IOException;
import org.bukkit.ChatColor;
import org.bukkit.World;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.plugin.Plugin;
/**
*
* @author Michael
*/
public class CommandRegionDefine extends WgCommand {
public boolean handle(CommandSender sender, String senderName, String command, String[] args, CommandHandler ch, WorldGuardPlugin wg) throws CommandHandlingException {
if (!(sender instanceof Player)) {
sender.sendMessage("Only players may use this command");
return true;
}
Player player = (Player) sender;
Plugin wePlugin = wg.getServer().getPluginManager().getPlugin("WorldEdit");
if (wePlugin == null) {
player.sendMessage(ChatColor.RED + "WorldEdit must be installed and enabled!");
return true;
}
ch.checkRegionPermission(player, "/regiondefine");
ch.checkArgs(args, 1, -1, "/region define <id> [owner1 [owner2 [owners...]]]");
try {
String id = args[0].toLowerCase();
WorldEditPlugin worldEdit = (WorldEditPlugin) wePlugin;
World w = player.getWorld();
LocalSession session = worldEdit.getSession(player);
Region weRegion = session.getSelection(new BukkitWorld(w));
ProtectedRegion region;
if (weRegion instanceof Polygonal2DRegion) {
Polygonal2DRegion pweRegion = (Polygonal2DRegion) weRegion;
int minY = pweRegion.getMinimumPoint().getBlockY();
int maxY = pweRegion.getMaximumPoint().getBlockY();
region = new ProtectedPolygonalRegion(id, pweRegion.getPoints(), minY, maxY);
} else {
BlockVector min = weRegion.getMinimumPoint().toBlockVector();
BlockVector max = weRegion.getMaximumPoint().toBlockVector();
region = new ProtectedCuboidRegion(id, min, max);
}
if (args.length >= 2) {
region.setOwners(ch.parseDomainString(args, 1));
}
RegionManager mgr = wg.getGlobalRegionManager().getRegionManager(w.getName());
mgr.addRegion(region);
mgr.save();
player.sendMessage(ChatColor.YELLOW + "Region saved as " + id + ".");
} catch (IncompleteRegionException e) {
player.sendMessage(ChatColor.RED + "You must first define an area in WorldEdit.");
} catch (IOException e) {
player.sendMessage(ChatColor.RED + "Region database failed to save: "
+ e.getMessage());
}
return true;
}
}

View File

@ -0,0 +1,79 @@
// $Id$
/*
* WorldGuard
* Copyright (C) 2010 sk89q <http://www.sk89q.com>
*
* 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 <http://www.gnu.org/licenses/>.
*/
package com.sk89q.worldguard.bukkit.commands;
import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
import com.sk89q.worldguard.bukkit.commands.CommandHandler.CommandHandlingException;
import com.sk89q.worldguard.protection.regionmanager.RegionManager;
import com.sk89q.worldguard.protection.regions.ProtectedRegion;
import java.io.IOException;
import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
/**
*
* @author Michael
*/
public class CommandRegionDelete extends WgCommand {
public boolean handle(CommandSender sender, String senderName, String command, String[] args, CommandHandler ch, WorldGuardPlugin wg) throws CommandHandlingException {
if (!(sender instanceof Player)) {
sender.sendMessage("Only players may use this command");
return true;
}
Player player = (Player) sender;
if (!wg.hasPermission(player, "/regionclaim")) {
ch.checkRegionPermission(player, "/regiondelete");
}
ch.checkArgs(args, 0, 1, "/region delete <id>");
try {
String id = args[0].toLowerCase();
RegionManager mgr = wg.getGlobalRegionManager().getRegionManager(player.getWorld().getName());
if (!mgr.hasRegion(id)) {
player.sendMessage(ChatColor.RED + "A region with ID '"
+ id + "' doesn't exist.");
return true;
}
ProtectedRegion existing = mgr.getRegion(id);
if (!ch.canUseRegionCommand(player, "/regiondelete")
&& !existing.isOwner(wg.wrapPlayer(player))) {
player.sendMessage(ChatColor.RED + "You don't own this region.");
return true;
}
mgr.removeRegion(id);
mgr.save();
player.sendMessage(ChatColor.YELLOW + "Region removed!");
} catch (IOException e) {
player.sendMessage(ChatColor.RED + "Region database failed to save: "
+ e.getMessage());
}
return true;
}
}

View File

@ -0,0 +1,185 @@
// $Id$
/*
* WorldGuard
* Copyright (C) 2010 sk89q <http://www.sk89q.com>
*
* 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 <http://www.gnu.org/licenses/>.
*/
package com.sk89q.worldguard.bukkit.commands;
import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
import com.sk89q.worldguard.bukkit.commands.CommandHandler.CommandHandlingException;
import com.sk89q.worldguard.protection.regionmanager.RegionManager;
import com.sk89q.worldguard.protection.regions.AreaFlags;
import com.sk89q.worldguard.protection.regions.ProtectedRegion;
import java.io.IOException;
import org.bukkit.ChatColor;
import org.bukkit.Location;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
/**
*
* @author Michael
*/
public class CommandRegionFlag extends WgCommand {
public boolean handle(CommandSender sender, String senderName, String command, String[] args, CommandHandler ch, WorldGuardPlugin wg) throws CommandHandlingException {
if (!(sender instanceof Player)) {
sender.sendMessage("Only players may use this command");
return true;
}
Player player = (Player) sender;
ch.checkRegionPermission(player, "/regiondefine");
ch.checkArgs(args, 3, 4, "/region flag <regionid> <name> (<subname>) <value>");
try {
String id = args[0].toLowerCase();
String nameStr = args[1];
String subnameStr = null;
String valueStr = null;
if (args.length < 4) {
valueStr = args[2];
} else {
subnameStr = args[2];
valueStr = args[3];
}
RegionManager mgr = wg.getGlobalRegionManager().getRegionManager(player.getWorld().getName());
ProtectedRegion region = mgr.getRegion(id);
if (region == null) {
player.sendMessage(ChatColor.RED + "Could not find a region by that ID.");
return true;
}
FlagInfo nfo = FlagInfo.getFlagInfo(nameStr, subnameStr);
if (nfo == null) {
if(nameStr.equals("spawn"))
{
if (valueStr.equals("set")) {
player.sendMessage(ChatColor.YELLOW + "Region '" + id + "' updated. Flag spawn set to current location");
AreaFlags flags = region.getFlags();
Location l = player.getLocation();
flags.setFlag("spawn", "x", l.getX());
flags.setFlag("spawn", "y", l.getY());
flags.setFlag("spawn", "z", l.getZ());
flags.setFlag("spawn", "yaw", l.getYaw());
flags.setFlag("spawn", "pitch", l.getPitch());
flags.setFlag("spawn", "world", l.getWorld().getName());
} else {
AreaFlags flags = region.getFlags();
flags.setFlag("spawn", "x", (String)null);
flags.setFlag("spawn", "y", (String)null);
flags.setFlag("spawn", "z", (String)null);
flags.setFlag("spawn", "yaw", (String)null);
flags.setFlag("spawn", "pitch", (String)null);
flags.setFlag("spawn", "world", (String)null);
player.sendMessage(ChatColor.YELLOW + "Region '" + id + "' updated. Flag spawn removed.");
}
}
else
{
player.sendMessage(ChatColor.RED + "Unknown flag specified.");
}
return true;
}
boolean validValue = false;
switch (nfo.type) {
case STRING: {
validValue = true;
break;
}
case INT: {
validValue = true;
try {
Integer val = Integer.valueOf(valueStr);
} catch (Exception e) {
validValue = false;
}
break;
}
case BOOLEAN: {
valueStr = valueStr.toLowerCase();
if (valueStr.equals("on")) {
valueStr = "true";
} else if (valueStr.equals("allow")) {
valueStr = "true";
}
validValue = true;
break;
}
case FLOAT: {
validValue = true;
try {
Float val = Float.valueOf(valueStr);
} catch (Exception e) {
validValue = false;
}
break;
}
case DOUBLE: {
validValue = true;
try {
Double val = Double.valueOf(valueStr);
} catch (Exception e) {
validValue = false;
}
break;
}
case STATE: {
validValue = true;
if (valueStr.equalsIgnoreCase("allow")) {
valueStr = AreaFlags.State.ALLOW.toString();
} else if (valueStr.equalsIgnoreCase("deny")) {
valueStr = AreaFlags.State.DENY.toString();
} else if (valueStr.equalsIgnoreCase("none")) {
valueStr = AreaFlags.State.NONE.toString();
} else {
validValue = false;
}
break;
}
default: {
validValue = false;
break;
}
}
String fullFlagname = nameStr;
if (subnameStr != null) {
nameStr += " " + subnameStr;
}
if (!validValue) {
player.sendMessage(ChatColor.RED + "Invalid value '" + valueStr + "' for flag " + fullFlagname);
return true;
}
region.getFlags().setFlag(nfo.flagName, nfo.flagSubName, valueStr);
mgr.save();
player.sendMessage(ChatColor.YELLOW + "Region '" + id + "' updated. Flag " + fullFlagname + " set to " + valueStr);
} catch (IOException e) {
player.sendMessage(ChatColor.RED + "Region database failed to save: "
+ e.getMessage());
}
return true;
}
}

View File

@ -0,0 +1,101 @@
// $Id$
/*
* WorldGuard
* Copyright (C) 2010 sk89q <http://www.sk89q.com>
*
* 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 <http://www.gnu.org/licenses/>.
*/
package com.sk89q.worldguard.bukkit.commands;
import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
import com.sk89q.worldguard.bukkit.commands.CommandHandler.CommandHandlingException;
import com.sk89q.worldguard.domains.DefaultDomain;
import com.sk89q.worldguard.protection.regionmanager.RegionManager;
import com.sk89q.worldguard.protection.regions.AreaFlags;
import com.sk89q.worldguard.protection.regions.AreaFlags.State;
import com.sk89q.worldguard.protection.regions.ProtectedRegion;
import java.util.Map;
import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
/**
*
* @author Michael
*/
public class CommandRegionInfo extends WgCommand {
public boolean handle(CommandSender sender, String senderName, String command, String[] args, CommandHandler ch, WorldGuardPlugin wg) throws CommandHandlingException {
if (!(sender instanceof Player)) {
sender.sendMessage("Only players may use this command");
return true;
}
Player player = (Player) sender;
ch.checkRegionPermission(player, "/regioninfo");
ch.checkArgs(args, 1, 1, "/region info <id>");
RegionManager mgr = wg.getGlobalRegionManager().getRegionManager(player.getWorld().getName());
String id = args[0].toLowerCase();
if (!mgr.hasRegion(id)) {
player.sendMessage(ChatColor.RED + "A region with ID '"
+ id + "' doesn't exist.");
return true;
}
ProtectedRegion region = mgr.getRegion(id);
AreaFlags flags = region.getFlags();
DefaultDomain owners = region.getOwners();
DefaultDomain members = region.getMembers();
player.sendMessage(ChatColor.YELLOW + "Region: " + id
+ ChatColor.GRAY + " (type: " + region.getTypeName() + ")");
player.sendMessage(ChatColor.BLUE + "Priority: " + region.getPriority());
StringBuilder s = new StringBuilder();
for (FlagInfo nfo : FlagInfo.getFlagInfoList()) {
String fullName = nfo.name;
if (nfo.subName != null) {
fullName += " " + nfo.subName;
}
String value = flags.getFlag(nfo.flagName, nfo.flagSubName);
if (value != null) {
s.append(fullName + ": " + value + ", ");
}
}
String spawnTest = flags.getFlag("spawn", "x");
if(spawnTest != null)
{
s.append("spawn: set");
}
else
{
s.append("spawn: not set");
}
player.sendMessage(ChatColor.BLUE + "Flags: " + s.toString());
player.sendMessage(ChatColor.BLUE + "Parent: "
+ (region.getParent() == null ? "(none)" : region.getParent().getId()));
player.sendMessage(ChatColor.LIGHT_PURPLE + "Owners: "
+ owners.toUserFriendlyString());
player.sendMessage(ChatColor.LIGHT_PURPLE + "Members: "
+ members.toUserFriendlyString());
return true;
}
}

View File

@ -0,0 +1,86 @@
// $Id$
/*
* WorldGuard
* Copyright (C) 2010 sk89q <http://www.sk89q.com>
*
* 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 <http://www.gnu.org/licenses/>.
*/
package com.sk89q.worldguard.bukkit.commands;
import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
import com.sk89q.worldguard.bukkit.commands.CommandHandler.CommandHandlingException;
import com.sk89q.worldguard.protection.regionmanager.RegionManager;
import com.sk89q.worldguard.protection.regions.ProtectedRegion;
import java.util.Arrays;
import java.util.Map;
import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
/**
*
* @author Michael
*/
public class CommandRegionList extends WgCommand {
public boolean handle(CommandSender sender, String senderName, String command, String[] args, CommandHandler ch, WorldGuardPlugin wg) throws CommandHandlingException {
if (!(sender instanceof Player)) {
sender.sendMessage("Only players may use this command");
return true;
}
Player player = (Player) sender;
ch.checkRegionPermission(player, "/regionlist");
ch.checkArgs(args, 0, 1, "/region list [page]");
int page = 0;
if (args.length >= 1) {
try {
page = Math.max(0, Integer.parseInt(args[0]) - 1);
} catch (NumberFormatException e) {
page = 0;
}
}
RegionManager mgr = wg.getGlobalRegionManager().getRegionManager(player.getWorld().getName());
Map<String, ProtectedRegion> regions = mgr.getRegions();
int size = regions.size();
int pages = (int) Math.ceil(size / (float) ch.CMD_LIST_SIZE);
String[] regionIDList = new String[size];
int index = 0;
for (String id : regions.keySet()) {
regionIDList[index] = id;
index++;
}
Arrays.sort(regionIDList);
player.sendMessage(ChatColor.RED + "Regions (page "
+ (page + 1) + " of " + pages + "):");
if (page < pages) {
for (int i = page * ch.CMD_LIST_SIZE; i < page * ch.CMD_LIST_SIZE + ch.CMD_LIST_SIZE; i++) {
if (i >= size) {
break;
}
player.sendMessage(ChatColor.YELLOW.toString() + (i + 1) + ". " + regionIDList[i]);
}
}
return true;
}
}

View File

@ -0,0 +1,57 @@
// $Id$
/*
* WorldGuard
* Copyright (C) 2010 sk89q <http://www.sk89q.com>
*
* 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 <http://www.gnu.org/licenses/>.
*/
package com.sk89q.worldguard.bukkit.commands;
import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
import com.sk89q.worldguard.bukkit.commands.CommandHandler.CommandHandlingException;
import com.sk89q.worldguard.protection.regionmanager.RegionManager;
import java.io.IOException;
import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
/**
*
* @author Michael
*/
public class CommandRegionLoad extends WgCommand {
public boolean handle(CommandSender sender, String senderName, String command, String[] args, CommandHandler ch, WorldGuardPlugin wg) throws CommandHandlingException {
if (!(sender instanceof Player)) {
sender.sendMessage("Only players may use this command");
return true;
}
Player player = (Player) sender;
ch.checkRegionPermission(player, "/regionload");
ch.checkArgs(args, 0, 0, "/region load");
try {
RegionManager mgr = wg.getGlobalRegionManager().getRegionManager(player.getWorld().getName());
mgr.load();
player.sendMessage(ChatColor.YELLOW + "Region database loaded from file!");
} catch (IOException e) {
player.sendMessage(ChatColor.RED + "Region database failed to load: "
+ e.getMessage());
}
return true;
}
}

View File

@ -0,0 +1,88 @@
// $Id$
/*
* WorldGuard
* Copyright (C) 2010 sk89q <http://www.sk89q.com>
*
* 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 <http://www.gnu.org/licenses/>.
*/
package com.sk89q.worldguard.bukkit.commands;
import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
import com.sk89q.worldguard.bukkit.commands.CommandHandler.CommandHandlingException;
import com.sk89q.worldguard.protection.regionmanager.RegionManager;
import com.sk89q.worldguard.protection.regions.ProtectedRegion;
import java.io.IOException;
import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
/**
*
* @author Michael
*/
public class CommandRegionRemoveMember extends WgCommand {
public boolean handle(CommandSender sender, String senderName, String command, String[] args, CommandHandler ch, WorldGuardPlugin wg) throws CommandHandlingException {
if (!(sender instanceof Player)) {
sender.sendMessage("Only players may use this command");
return true;
}
Player player = (Player) sender;
if (!wg.hasPermission(player, "/regionclaim") && !wg.hasPermission(player, "/regionmembership")) {
ch.checkRegionPermission(player, "/regiondefine");
}
ch.checkArgs(args, 2, -1, "/region removeowner <id> [owner1 [owner2 [owners...]]]");
String action = command;
boolean isOwner = action.equalsIgnoreCase("removeowner");
RegionManager mgr = wg.getGlobalRegionManager().getRegionManager(player.getWorld().getName());
String id = args[0].toLowerCase();
if (!mgr.hasRegion(id)) {
player.sendMessage(ChatColor.RED + "A region with ID '"
+ id + "' doesn't exist.");
return true;
}
ProtectedRegion existing = mgr.getRegion(id);
if (!ch.canUseRegionCommand(player, "/regiondefine")
&& !existing.isOwner(wg.wrapPlayer(player))) {
player.sendMessage(ChatColor.RED + "You don't own this region.");
return true;
}
if (isOwner) {
ch.removeFromDomain(existing.getOwners(), args, 1);
} else {
ch.removeFromDomain(existing.getMembers(), args, 1);
}
try {
mgr.save();
player.sendMessage(ChatColor.YELLOW + "Region updated!");
player.sendMessage(ChatColor.GRAY + "Current owners: "
+ existing.getOwners().toUserFriendlyString());
player.sendMessage(ChatColor.GRAY + "Current members: "
+ existing.getMembers().toUserFriendlyString());
} catch (IOException e) {
player.sendMessage(ChatColor.RED + "Region database failed to save: "
+ e.getMessage());
}
return true;
}
}

View File

@ -0,0 +1,57 @@
// $Id$
/*
* WorldGuard
* Copyright (C) 2010 sk89q <http://www.sk89q.com>
*
* 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 <http://www.gnu.org/licenses/>.
*/
package com.sk89q.worldguard.bukkit.commands;
import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
import com.sk89q.worldguard.bukkit.commands.CommandHandler.CommandHandlingException;
import com.sk89q.worldguard.protection.regionmanager.RegionManager;
import java.io.IOException;
import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
/**
*
* @author Michael
*/
public class CommandRegionSave extends WgCommand {
public boolean handle(CommandSender sender, String senderName, String command, String[] args, CommandHandler ch, WorldGuardPlugin wg) throws CommandHandlingException {
if (!(sender instanceof Player)) {
sender.sendMessage("Only players may use this command");
return true;
}
Player player = (Player) sender;
ch.checkRegionPermission(player, "/regionsave");
ch.checkArgs(args, 0, 0, "/region save");
try {
RegionManager mgr = wg.getGlobalRegionManager().getRegionManager(player.getWorld().getName());
mgr.save();
player.sendMessage(ChatColor.YELLOW + "Region database saved to file!");
} catch (IOException e) {
player.sendMessage(ChatColor.RED + "Region database failed to save: "
+ e.getMessage());
}
return true;
}
}

View File

@ -0,0 +1,99 @@
// $Id$
/*
* WorldGuard
* Copyright (C) 2010 sk89q <http://www.sk89q.com>
*
* 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 <http://www.gnu.org/licenses/>.
*/
package com.sk89q.worldguard.bukkit.commands;
import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
import com.sk89q.worldguard.bukkit.commands.CommandHandler.CommandHandlingException;
import com.sk89q.worldguard.protection.regionmanager.RegionManager;
import com.sk89q.worldguard.protection.regions.ProtectedRegion;
import com.sk89q.worldguard.protection.regions.ProtectedRegion.CircularInheritanceException;
import java.io.IOException;
import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
/**
*
* @author Michael
*/
public class CommandRegionSetParent extends WgCommand {
public boolean handle(CommandSender sender, String senderName, String command, String[] args, CommandHandler ch, WorldGuardPlugin wg) throws CommandHandlingException {
if (!(sender instanceof Player)) {
sender.sendMessage("Only players may use this command");
return true;
}
Player player = (Player) sender;
if (!wg.hasPermission(player, "/regionclaim")) {
ch.checkRegionPermission(player, "/regiondefine");
}
ch.checkArgs(args, 1, 2, "/region setparent <id> <parent-id>");
String id = args[0].toLowerCase();
String parentId = args.length > 1 ? args[1].toLowerCase() : null;
RegionManager mgr = wg.getGlobalRegionManager().getRegionManager(player.getWorld().getName());
ProtectedRegion region = mgr.getRegion(id);
if (region == null) {
player.sendMessage(ChatColor.RED + "Could not find a region with ID: " + id);
return true;
}
if (!ch.canUseRegionCommand(player, "/regiondefine")
&& !region.isOwner(wg.wrapPlayer(player))) {
player.sendMessage(ChatColor.RED + "You need to own the target regions");
return true;
}
ProtectedRegion parent = null;
// Set a parent
if (parentId != null) {
parent = mgr.getRegion(parentId);
if (parent == null) {
player.sendMessage(ChatColor.RED + "Could not find a region with ID: " + parentId);
return true;
}
if (!ch.canUseRegionCommand(player, "/regiondefine")
&& !parent.isOwner(wg.wrapPlayer(player))) {
player.sendMessage(ChatColor.RED + "You need to own the parent region.");
return true;
}
}
try {
region.setParent(parent);
mgr.save();
player.sendMessage(ChatColor.YELLOW + "Region '" + id + "' updated.");
} catch (CircularInheritanceException e) {
player.sendMessage(ChatColor.RED + "Circular inheritance detected. The operation failed.");
} catch (IOException e) {
player.sendMessage(ChatColor.RED + "Region database failed to save: "
+ e.getMessage());
}
return true;
}
}

View File

@ -0,0 +1,65 @@
// $Id$
/*
* WorldGuard
* Copyright (C) 2010 sk89q <http://www.sk89q.com>
*
* 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 <http://www.gnu.org/licenses/>.
*/
package com.sk89q.worldguard.bukkit.commands;
import com.sk89q.worldguard.bukkit.LoggerToChatHandler;
import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
import com.sk89q.worldguard.bukkit.commands.CommandHandler.CommandHandlingException;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
/**
*
* @author Michael
*/
public class CommandReloadWG extends WgCommand {
public boolean handle(CommandSender sender, String senderName, String command, String[] args, CommandHandler ch, WorldGuardPlugin wg) throws CommandHandlingException {
if (!(sender instanceof Player)) {
sender.sendMessage("Only players may use this command");
return true;
}
Player player = (Player) sender;
ch.checkPermission(player, "/reloadwg");
ch.checkArgs(args, 0, 0);
LoggerToChatHandler handler = new LoggerToChatHandler(player);
handler.setLevel(Level.ALL);
Logger minecraftLogger = Logger.getLogger("Minecraft");
minecraftLogger.addHandler(handler);
try {
wg.loadConfiguration();
wg.postReload();
player.sendMessage("WorldGuard configuration reloaded.");
} catch (Throwable t) {
player.sendMessage("Error while reloading: "
+ t.getMessage());
} finally {
minecraftLogger.removeHandler(handler);
}
return true;
}
}

View File

@ -0,0 +1,69 @@
// $Id$
/*
* WorldGuard
* Copyright (C) 2010 sk89q <http://www.sk89q.com>
*
* 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 <http://www.gnu.org/licenses/>.
*/
package com.sk89q.worldguard.bukkit.commands;
import com.sk89q.worldguard.bukkit.BukkitUtil;
import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
import com.sk89q.worldguard.bukkit.commands.CommandHandler.CommandHandlingException;
import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
/**
*
* @author Michael
*/
public class CommandSlay extends WgCommand {
public boolean handle(CommandSender sender, String senderName, String command, String[] args, CommandHandler ch, WorldGuardPlugin wg) throws CommandHandlingException {
if (!(sender instanceof Player)) {
sender.sendMessage("Only players may use this command");
return true;
}
Player player = (Player) sender;
ch.checkPermission(player, "/slay");
ch.checkArgs(args, 0, 1);
// Allow killing other people
if (args.length > 0) {
if (!wg.hasPermission(player, "/slayother")) {
player.sendMessage(ChatColor.RED + "You don't have permission to kill others.");
return true;
}
Player other = BukkitUtil.matchSinglePlayer(wg.getServer(), args[0]);
if (other == null) {
player.sendMessage(ChatColor.RED + "Player not found.");
} else {
other.setHealth(0);
player.sendMessage(ChatColor.YELLOW + other.getName() + " has been killed!");
other.sendMessage(ChatColor.YELLOW + player.getName() + " has killed you!");
}
} else {
player.setHealth(0);
player.sendMessage(ChatColor.YELLOW + "You have committed suicide!");
}
return true;
}
}

View File

@ -0,0 +1,109 @@
// $Id$
/*
* WorldGuard
* Copyright (C) 2010 sk89q <http://www.sk89q.com>
*
* 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 <http://www.gnu.org/licenses/>.
*/
package com.sk89q.worldguard.bukkit.commands;
import com.sk89q.worldedit.blocks.ItemType;
import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
import com.sk89q.worldguard.bukkit.commands.CommandHandler.CommandHandlingException;
import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
/**
*
* @author Michael
*/
public class CommandStack extends WgCommand {
public boolean handle(CommandSender sender, String senderName, String command, String[] args, CommandHandler ch, WorldGuardPlugin wg) throws CommandHandlingException {
if (!(sender instanceof Player)) {
sender.sendMessage("Only players may use this command");
return true;
}
Player player = (Player) sender;
ch.checkPermission(player, "/stack");
ch.checkArgs(args, 0, 0);
ItemStack[] items = player.getInventory().getContents();
int len = items.length;
int affected = 0;
for (int i = 0; i < len; i++) {
ItemStack item = items[i];
// Avoid infinite stacks and stacks with durability
if (item == null || item.getAmount() <= 0
|| ItemType.shouldNotStack(item.getTypeId())) {
continue;
}
// Ignore buckets
if (item.getTypeId() >= 325 && item.getTypeId() <= 327) {
continue;
}
if (item.getAmount() < 64) {
int needed = 64 - item.getAmount(); // Number of needed items until 64
// Find another stack of the same type
for (int j = i + 1; j < len; j++) {
ItemStack item2 = items[j];
// Avoid infinite stacks and stacks with durability
if (item2 == null || item2.getAmount() <= 0
|| ItemType.shouldNotStack(item.getTypeId())) {
continue;
}
// Same type?
// Blocks store their color in the damage value
if (item2.getTypeId() == item.getTypeId()
&& (!ItemType.usesDamageValue(item.getTypeId())
|| item.getDurability() == item2.getDurability())) {
// This stack won't fit in the parent stack
if (item2.getAmount() > needed) {
item.setAmount(64);
item2.setAmount(item2.getAmount() - needed);
break;
// This stack will
} else {
items[j] = null;
item.setAmount(item.getAmount() + item2.getAmount());
needed = 64 - item.getAmount();
}
affected++;
}
}
}
}
if (affected > 0) {
player.getInventory().setContents(items);
}
player.sendMessage(ChatColor.YELLOW + "Items compacted into stacks!");
return true;
}
}

View File

@ -0,0 +1,56 @@
// $Id$
/*
* WorldGuard
* Copyright (C) 2010 sk89q <http://www.sk89q.com>
*
* 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 <http://www.gnu.org/licenses/>.
*/
package com.sk89q.worldguard.bukkit.commands;
import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
import com.sk89q.worldguard.bukkit.commands.CommandHandler.CommandHandlingException;
import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
/**
*
* @author Michael
*/
public class CommandStopFire extends WgCommand {
public boolean handle(CommandSender sender, String senderName, String command, String[] args, CommandHandler ch, WorldGuardPlugin wg) throws CommandHandlingException {
if (!(sender instanceof Player)) {
sender.sendMessage("Only players may use this command");
return true;
}
Player player = (Player) sender;
ch.checkPermission(sender, "/stopfire");
ch.checkArgs(args, 0, 0);
if (!wg.fireSpreadDisableToggle) {
wg.getServer().broadcastMessage(ChatColor.YELLOW
+ "Fire spread has been globally disabled by " + senderName + ".");
} else {
sender.sendMessage(ChatColor.YELLOW + "Fire spread was already globally disabled.");
}
wg.fireSpreadDisableToggle = true;
return true;
}
}

View File

@ -0,0 +1,96 @@
// $Id$
/*
* WorldGuard
* Copyright (C) 2010 sk89q <http://www.sk89q.com>
*
* 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 <http://www.gnu.org/licenses/>.
*/
package com.sk89q.worldguard.bukkit.commands;
import java.util.ArrayList;
import java.util.List;
/**
*
* @author Michael
*/
public class FlagInfo {
public static enum FlagValueType { STRING, BOOLEAN, INT, FLOAT, DOUBLE, STATE };
public String name;
public String subName;
public FlagValueType type;
public String flagName;
public String flagSubName;
private static List<FlagInfo> flagList;
static {
flagList = new ArrayList<FlagInfo>();
flagList.add(new FlagInfo("msg", "g", FlagValueType.STRING, "msg", "g"));
flagList.add(new FlagInfo("msg", "f", FlagValueType.STRING, "msg", "f"));
flagList.add(new FlagInfo("cs", "*", FlagValueType.STRING, "creaturespawn", "*"));
flagList.add(new FlagInfo("heal", "delay", FlagValueType.INT, "heal", "delay"));
flagList.add(new FlagInfo("heal", "amount", FlagValueType.INT, "heal", "amount"));
flagList.add(new FlagInfo("passthrough", null, FlagValueType.STATE, "states", "passthrough"));
flagList.add(new FlagInfo("build", null, FlagValueType.STATE, "states", "build"));
flagList.add(new FlagInfo("pvp", null, FlagValueType.STATE, "states", "pvp"));
flagList.add(new FlagInfo("mobdamage", null, FlagValueType.STATE, "states", "mobdamage"));
flagList.add(new FlagInfo("creeper", null, FlagValueType.STATE, "states", "creeper"));
flagList.add(new FlagInfo("tnt", null, FlagValueType.STATE, "states", "tnt"));
flagList.add(new FlagInfo("lighter", null, FlagValueType.STATE, "states", "lighter"));
flagList.add(new FlagInfo("firespread", null, FlagValueType.STATE, "states", "firespread"));
flagList.add(new FlagInfo("lavafirespread", null, FlagValueType.STATE, "states", "lavafirespread"));
flagList.add(new FlagInfo("chest", null, FlagValueType.STATE, "states", "chest"));
}
public static FlagInfo getFlagInfo(String name, String subName) {
System.out.println(name + " " + subName);
for (FlagInfo nfo : flagList) {
if (name.equals(nfo.name)) {
if (subName == null && nfo.subName == null) {
return nfo;
} else if (nfo.subName != null) {
if (nfo.subName.equals("*")) {
return nfo;
}
else if(subName != null && subName.equals(nfo.subName))
{
return nfo;
}
}
}
}
return null;
}
public static List<FlagInfo> getFlagInfoList() {
return flagList;
}
public FlagInfo(String name, String subName, FlagValueType type, String flagName, String flagSubName)
{
this.name = name;
this.subName = subName;
this.type = type;
this.flagName = flagName;
this.flagSubName = flagSubName;
}
}

View File

@ -0,0 +1,79 @@
// $Id$
/*
* WorldGuard
* Copyright (C) 2010 sk89q <http://www.sk89q.com>
*
* 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 <http://www.gnu.org/licenses/>.
*/
package com.sk89q.worldguard.bukkit.commands;
import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
import com.sk89q.worldguard.bukkit.commands.CommandHandler.CommandHandlingException;
import java.util.HashMap;
import java.util.Map;
import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;
/**
*
* @author Michael
*/
public class RegionCommandHandler extends WgCommand {
private Map<String, WgCommand> commandMap;
public RegionCommandHandler()
{
this.commandMap = new HashMap<String, WgCommand>();
this.commandMap.put("addmember", new CommandRegionAddMember());
this.commandMap.put("addowner", new CommandRegionAddMember());
this.commandMap.put("claim", new CommandRegionClaim());
this.commandMap.put("define", new CommandRegionDefine());
this.commandMap.put("delete", new CommandRegionDelete());
this.commandMap.put("flag", new CommandRegionFlag());
this.commandMap.put("info", new CommandRegionInfo());
this.commandMap.put("list", new CommandRegionList());
this.commandMap.put("load", new CommandRegionLoad());
this.commandMap.put("removemember", new CommandRegionRemoveMember());
this.commandMap.put("removeowner", new CommandRegionRemoveMember());
this.commandMap.put("save", new CommandRegionSave());
this.commandMap.put("setparent", new CommandRegionSetParent());
}
public boolean handle(CommandSender sender, String senderName, String command, String[] args, CommandHandler ch, WorldGuardPlugin wg) throws CommandHandlingException {
if (!wg.useRegions) {
sender.sendMessage(ChatColor.RED + "Regions are disabled.");
return true;
}
ch.checkArgs(args, 1, -1);
String subCommand = args[0].toLowerCase();
WgCommand wgcmd = commandMap.get(subCommand);
if (wgcmd == null) {
return false;
}
String[] subArgs = new String[args.length - 1];
System.arraycopy(args, 1, subArgs, 0, args.length - 1);
wgcmd.handle(sender, senderName, subCommand, subArgs, ch, wg);
return true;
}
}

View File

@ -0,0 +1,38 @@
// $Id$
/*
* WorldGuard
* Copyright (C) 2010 sk89q <http://www.sk89q.com>
*
* 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 <http://www.gnu.org/licenses/>.
*/
package com.sk89q.worldguard.bukkit.commands;
import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
import com.sk89q.worldguard.bukkit.commands.CommandHandler.CommandHandlingException;
import com.sk89q.worldguard.bukkit.commands.CommandHandler.InsufficientArgumentsException;
import com.sk89q.worldguard.bukkit.commands.CommandHandler.InsufficientPermissionsException;
import org.bukkit.command.CommandSender;
/**
*
* @author Michael
*/
public abstract class WgCommand {
public abstract boolean handle(CommandSender sender, String senderName, String command, String[] args, CommandHandler ch, WorldGuardPlugin wg) throws CommandHandlingException;
}

View File

@ -96,7 +96,6 @@ private ProtectedRegion getTestRegion1() {
domain.addPlayer("tetsu");
region.setOwners(domain);
region.setEnterMessage("hello there!");
region.setPriority(444);
return region;
@ -120,8 +119,7 @@ private ProtectedRegion getTestRegion2() {
domain.addPlayer("ester");
domain.addPlayer("amy");
region.setOwners(domain);
region.setEnterMessage("Testing");
region.setPriority(555);
return region;