From 3b9a426547aa19d13345def58a036802df52aade Mon Sep 17 00:00:00 2001 From: sk89q Date: Sat, 2 Apr 2011 15:39:44 -0700 Subject: [PATCH] Fixed some flags and permissions. --- .../bukkit/WorldGuardPlayerListener.java | 13 ++- .../worldguard/bukkit/WorldGuardPlugin.java | 1 - .../bukkit/WorldGuardVehicleListener.java | 81 ------------------- .../bukkit/commands/RegionCommands.java | 41 ++++++---- .../bukkit/commands/RegionMemberCommands.java | 40 ++++++--- 5 files changed, 65 insertions(+), 111 deletions(-) delete mode 100644 src/com/sk89q/worldguard/bukkit/WorldGuardVehicleListener.java diff --git a/src/com/sk89q/worldguard/bukkit/WorldGuardPlayerListener.java b/src/com/sk89q/worldguard/bukkit/WorldGuardPlayerListener.java index 987ef3be..2f086fd3 100644 --- a/src/com/sk89q/worldguard/bukkit/WorldGuardPlayerListener.java +++ b/src/com/sk89q/worldguard/bukkit/WorldGuardPlayerListener.java @@ -196,10 +196,19 @@ public void handleBlockRightClick(PlayerInteractEvent event) { } } - if (wcfg.useRegions && type == Material.CAKE_BLOCK) { + if (type == Material.CAKE_BLOCK) { if (!set.canBuild(localPlayer)) { player.sendMessage(ChatColor.DARK_RED + "You're not invited to this tea party!"); - + event.setCancelled(true); + return; + } + } + + if (type == Material.RAILS + && (item.getType() == Material.MINECART || item.getType() == Material.BOAT)) { + if (!set.canBuild(localPlayer) + && !set.allows(DefaultFlag.PLACE_VEHICLE)) { + player.sendMessage(ChatColor.DARK_RED + "You don't have permission for this area."); event.setCancelled(true); return; } diff --git a/src/com/sk89q/worldguard/bukkit/WorldGuardPlugin.java b/src/com/sk89q/worldguard/bukkit/WorldGuardPlugin.java index 9e793dd2..aefb17d4 100644 --- a/src/com/sk89q/worldguard/bukkit/WorldGuardPlugin.java +++ b/src/com/sk89q/worldguard/bukkit/WorldGuardPlugin.java @@ -130,7 +130,6 @@ public void onEnable() { (new WorldGuardPlayerListener(this)).registerEvents(); (new WorldGuardBlockListener(this)).registerEvents(); (new WorldGuardEntityListener(this)).registerEvents(); - (new WorldGuardVehicleListener(this)).registerEvents(); // 25 equals about 1s real time getServer().getScheduler().scheduleSyncRepeatingTask( diff --git a/src/com/sk89q/worldguard/bukkit/WorldGuardVehicleListener.java b/src/com/sk89q/worldguard/bukkit/WorldGuardVehicleListener.java deleted file mode 100644 index ee85c57a..00000000 --- a/src/com/sk89q/worldguard/bukkit/WorldGuardVehicleListener.java +++ /dev/null @@ -1,81 +0,0 @@ -// $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; - -import com.sk89q.worldguard.protection.ApplicableRegionSet; -import com.sk89q.worldguard.protection.flags.DefaultFlag; -import com.sk89q.worldguard.protection.managers.RegionManager; -import org.bukkit.entity.Boat; -import org.bukkit.entity.Minecart; -import org.bukkit.entity.Vehicle; -import org.bukkit.event.Event; -import org.bukkit.event.Event.Priority; -import org.bukkit.event.vehicle.VehicleCreateEvent; -import org.bukkit.event.vehicle.VehicleListener; -import org.bukkit.plugin.PluginManager; -import com.sk89q.worldedit.Vector; -import org.bukkit.Location; - -/** - * - * @author DarkLiKally - */ -public class WorldGuardVehicleListener extends VehicleListener { - /** - * Plugin. - */ - private WorldGuardPlugin plugin; - /** - * Construct the object; - * - * @param plugin - */ - public WorldGuardVehicleListener(WorldGuardPlugin plugin) { - this.plugin = plugin; - } - - public void registerEvents() { - - PluginManager pm = plugin.getServer().getPluginManager(); - - pm.registerEvent(Event.Type.VEHICLE_CREATE, this, Priority.High, plugin); - } - - /** - * Called when a vehicle is created by a player. - * - * @param event Relevant event details - */ - @Override - public void onVehicleCreate(VehicleCreateEvent event) { - Vehicle vhcl = event.getVehicle(); - Location vhclLoc = vhcl.getLocation(); - Vector pt = new Vector(vhclLoc.getBlockX(), vhclLoc.getBlockY(), vhclLoc.getBlockZ()); - - if (vhcl instanceof Minecart || vhcl instanceof Boat) { - RegionManager mgr = plugin.getGlobalRegionManager().get(vhcl.getWorld()); - ApplicableRegionSet applicableRegions = mgr.getApplicableRegions(pt); - - if (!applicableRegions.allows(DefaultFlag.PLACE_VEHICLE)) { - vhcl.remove(); - return; - } - } - } -} diff --git a/src/com/sk89q/worldguard/bukkit/commands/RegionCommands.java b/src/com/sk89q/worldguard/bukkit/commands/RegionCommands.java index dd4b71db..70cf6738 100644 --- a/src/com/sk89q/worldguard/bukkit/commands/RegionCommands.java +++ b/src/com/sk89q/worldguard/bukkit/commands/RegionCommands.java @@ -468,11 +468,11 @@ public static void flag(CommandContext args, WorldGuardPlugin plugin, } if (region.isOwner(localPlayer)) { - plugin.checkPermission(sender, "worldguard.region.flag.own"); + plugin.checkPermission(sender, "worldguard.region.flag.own." + id.toLowerCase()); } else if (region.isMember(localPlayer)) { - plugin.checkPermission(sender, "worldguard.region.flag.member"); + plugin.checkPermission(sender, "worldguard.region.flag.member." + id.toLowerCase()); } else { - plugin.checkPermission(sender, "worldguard.region.flag"); + plugin.checkPermission(sender, "worldguard.region.flag." + id.toLowerCase()); } Flag foundFlag = null; @@ -502,6 +502,17 @@ public static void flag(CommandContext args, WorldGuardPlugin plugin, player.sendMessage(ChatColor.RED + "Available flags: " + list); return; } + + if (region.isOwner(localPlayer)) { + plugin.checkPermission(sender, "worldguard.region.flag.flags." + + foundFlag.getName() + ".owner." + id.toLowerCase()); + } else if (region.isMember(localPlayer)) { + plugin.checkPermission(sender, "worldguard.region.flag.flags." + + foundFlag.getName() + ".member." + id.toLowerCase()); + } else { + plugin.checkPermission(sender, "worldguard.region.flag.flags." + + foundFlag.getName() + "." + id.toLowerCase()); + } if (value != null) { try { @@ -559,11 +570,11 @@ public static void setPriority(CommandContext args, WorldGuardPlugin plugin, } if (region.isOwner(localPlayer)) { - plugin.checkPermission(sender, "worldguard.region.setpriority.own"); + plugin.checkPermission(sender, "worldguard.region.setpriority.own." + id.toLowerCase()); } else if (region.isMember(localPlayer)) { - plugin.checkPermission(sender, "worldguard.region.setpriority.member"); + plugin.checkPermission(sender, "worldguard.region.setpriority.member." + id.toLowerCase()); } else { - plugin.checkPermission(sender, "worldguard.region.setpriority"); + plugin.checkPermission(sender, "worldguard.region.setpriority." + id.toLowerCase()); } region.setPriority(priority); @@ -610,19 +621,19 @@ public static void setParent(CommandContext args, WorldGuardPlugin plugin, } if (region.isOwner(localPlayer)) { - plugin.checkPermission(sender, "worldguard.region.setparent.own"); + plugin.checkPermission(sender, "worldguard.region.setparent.own." + id.toLowerCase()); } else if (region.isMember(localPlayer)) { - plugin.checkPermission(sender, "worldguard.region.setparent.member"); + plugin.checkPermission(sender, "worldguard.region.setparent.member." + id.toLowerCase()); } else { - plugin.checkPermission(sender, "worldguard.region.setparent"); + plugin.checkPermission(sender, "worldguard.region.setparent." + id.toLowerCase()); } if (parent.isOwner(localPlayer)) { - plugin.checkPermission(sender, "worldguard.region.setparent.own"); + plugin.checkPermission(sender, "worldguard.region.setparent.own." + id.toLowerCase()); } else if (parent.isMember(localPlayer)) { - plugin.checkPermission(sender, "worldguard.region.setparent.member"); + plugin.checkPermission(sender, "worldguard.region.setparent.member." + id.toLowerCase()); } else { - plugin.checkPermission(sender, "worldguard.region.setparent"); + plugin.checkPermission(sender, "worldguard.region.setparent." + id.toLowerCase()); } try { @@ -664,11 +675,11 @@ public static void remove(CommandContext args, WorldGuardPlugin plugin, } if (region.isOwner(localPlayer)) { - plugin.checkPermission(sender, "worldguard.region.remove.own"); + plugin.checkPermission(sender, "worldguard.region.remove.own." + id.toLowerCase()); } else if (region.isMember(localPlayer)) { - plugin.checkPermission(sender, "worldguard.region.remove.member"); + plugin.checkPermission(sender, "worldguard.region.remove.member." + id.toLowerCase()); } else { - plugin.checkPermission(sender, "worldguard.region.flag"); + plugin.checkPermission(sender, "worldguard.region.remove." + id.toLowerCase()); } mgr.removeRegion(id); diff --git a/src/com/sk89q/worldguard/bukkit/commands/RegionMemberCommands.java b/src/com/sk89q/worldguard/bukkit/commands/RegionMemberCommands.java index 8cbfb955..8e28596d 100644 --- a/src/com/sk89q/worldguard/bukkit/commands/RegionMemberCommands.java +++ b/src/com/sk89q/worldguard/bukkit/commands/RegionMemberCommands.java @@ -49,6 +49,10 @@ public static void addMember(CommandContext args, WorldGuardPlugin plugin, LocalPlayer localPlayer = plugin.wrapPlayer(player); String id = args.getString(0); + + if (id.equalsIgnoreCase("__global__")) { + throw new CommandException("The region cannot be named __global__"); + } RegionManager mgr = plugin.getGlobalRegionManager().get(world); ProtectedRegion region = mgr.getRegion(id); @@ -58,11 +62,11 @@ public static void addMember(CommandContext args, WorldGuardPlugin plugin, } if (region.isOwner(localPlayer)) { - plugin.checkPermission(sender, "worldguard.region.addmember.own"); + plugin.checkPermission(sender, "worldguard.region.addmember.own." + id.toLowerCase()); } else if (region.isMember(localPlayer)) { - plugin.checkPermission(sender, "worldguard.region.addmember.member"); + plugin.checkPermission(sender, "worldguard.region.addmember.member." + id.toLowerCase()); } else { - plugin.checkPermission(sender, "worldguard.region.addmember"); + plugin.checkPermission(sender, "worldguard.region.addmember." + id.toLowerCase()); } RegionUtil.addToDomain(region.getMembers(), args.getPaddedSlice(2, 0), 0); @@ -90,6 +94,10 @@ public static void addOwner(CommandContext args, WorldGuardPlugin plugin, LocalPlayer localPlayer = plugin.wrapPlayer(player); String id = args.getString(0); + + if (id.equalsIgnoreCase("__global__")) { + throw new CommandException("The region cannot be named __global__"); + } RegionManager mgr = plugin.getGlobalRegionManager().get(world); ProtectedRegion region = mgr.getRegion(id); @@ -99,11 +107,11 @@ public static void addOwner(CommandContext args, WorldGuardPlugin plugin, } if (region.isOwner(localPlayer)) { - plugin.checkPermission(sender, "worldguard.region.addowner.own"); + plugin.checkPermission(sender, "worldguard.region.addowner.own." + id.toLowerCase()); } else if (region.isMember(localPlayer)) { - plugin.checkPermission(sender, "worldguard.region.addowner.member"); + plugin.checkPermission(sender, "worldguard.region.addowner.member." + id.toLowerCase()); } else { - plugin.checkPermission(sender, "worldguard.region.addowner"); + plugin.checkPermission(sender, "worldguard.region.addowner." + id.toLowerCase()); } RegionUtil.addToDomain(region.getOwners(), args.getPaddedSlice(2, 0), 0); @@ -131,6 +139,10 @@ public static void removeMember(CommandContext args, WorldGuardPlugin plugin, LocalPlayer localPlayer = plugin.wrapPlayer(player); String id = args.getString(0); + + if (id.equalsIgnoreCase("__global__")) { + throw new CommandException("The region cannot be named __global__"); + } RegionManager mgr = plugin.getGlobalRegionManager().get(world); ProtectedRegion region = mgr.getRegion(id); @@ -140,11 +152,11 @@ public static void removeMember(CommandContext args, WorldGuardPlugin plugin, } if (region.isOwner(localPlayer)) { - plugin.checkPermission(sender, "worldguard.region.removemember.own"); + plugin.checkPermission(sender, "worldguard.region.removemember.own." + id.toLowerCase()); } else if (region.isMember(localPlayer)) { - plugin.checkPermission(sender, "worldguard.region.removemember.member"); + plugin.checkPermission(sender, "worldguard.region.removemember.member." + id.toLowerCase()); } else { - plugin.checkPermission(sender, "worldguard.region.removemember"); + plugin.checkPermission(sender, "worldguard.region.removemember." + id.toLowerCase()); } RegionUtil.removeFromDomain(region.getMembers(), args.getPaddedSlice(2, 0), 0); @@ -172,6 +184,10 @@ public static void removeOwner(CommandContext args, WorldGuardPlugin plugin, LocalPlayer localPlayer = plugin.wrapPlayer(player); String id = args.getString(0); + + if (id.equalsIgnoreCase("__global__")) { + throw new CommandException("The region cannot be named __global__"); + } RegionManager mgr = plugin.getGlobalRegionManager().get(world); ProtectedRegion region = mgr.getRegion(id); @@ -181,11 +197,11 @@ public static void removeOwner(CommandContext args, WorldGuardPlugin plugin, } if (region.isOwner(localPlayer)) { - plugin.checkPermission(sender, "worldguard.region.removeowner.own"); + plugin.checkPermission(sender, "worldguard.region.removeowner.own." + id.toLowerCase()); } else if (region.isMember(localPlayer)) { - plugin.checkPermission(sender, "worldguard.region.removeowner.member"); + plugin.checkPermission(sender, "worldguard.region.removeowner.member." + id.toLowerCase()); } else { - plugin.checkPermission(sender, "worldguard.region.removeowner"); + plugin.checkPermission(sender, "worldguard.region.removeowner." + id.toLowerCase()); } RegionUtil.removeFromDomain(region.getOwners(), args.getPaddedSlice(2, 0), 0);