Fixed some flags and permissions.

This commit is contained in:
sk89q 2011-04-02 15:39:44 -07:00
parent 989ba0103d
commit 3b9a426547
5 changed files with 65 additions and 111 deletions

View File

@ -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)) { if (!set.canBuild(localPlayer)) {
player.sendMessage(ChatColor.DARK_RED + "You're not invited to this tea party!"); 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); event.setCancelled(true);
return; return;
} }

View File

@ -130,7 +130,6 @@ public void onEnable() {
(new WorldGuardPlayerListener(this)).registerEvents(); (new WorldGuardPlayerListener(this)).registerEvents();
(new WorldGuardBlockListener(this)).registerEvents(); (new WorldGuardBlockListener(this)).registerEvents();
(new WorldGuardEntityListener(this)).registerEvents(); (new WorldGuardEntityListener(this)).registerEvents();
(new WorldGuardVehicleListener(this)).registerEvents();
// 25 equals about 1s real time // 25 equals about 1s real time
getServer().getScheduler().scheduleSyncRepeatingTask( getServer().getScheduler().scheduleSyncRepeatingTask(

View File

@ -1,81 +0,0 @@
// $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;
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;
}
}
}
}

View File

@ -468,11 +468,11 @@ public static void flag(CommandContext args, WorldGuardPlugin plugin,
} }
if (region.isOwner(localPlayer)) { 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)) { } else if (region.isMember(localPlayer)) {
plugin.checkPermission(sender, "worldguard.region.flag.member"); plugin.checkPermission(sender, "worldguard.region.flag.member." + id.toLowerCase());
} else { } else {
plugin.checkPermission(sender, "worldguard.region.flag"); plugin.checkPermission(sender, "worldguard.region.flag." + id.toLowerCase());
} }
Flag<?> foundFlag = null; Flag<?> foundFlag = null;
@ -503,6 +503,17 @@ public static void flag(CommandContext args, WorldGuardPlugin plugin,
return; 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) { if (value != null) {
try { try {
setFlag(region, foundFlag, plugin, sender, value); setFlag(region, foundFlag, plugin, sender, value);
@ -559,11 +570,11 @@ public static void setPriority(CommandContext args, WorldGuardPlugin plugin,
} }
if (region.isOwner(localPlayer)) { 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)) { } else if (region.isMember(localPlayer)) {
plugin.checkPermission(sender, "worldguard.region.setpriority.member"); plugin.checkPermission(sender, "worldguard.region.setpriority.member." + id.toLowerCase());
} else { } else {
plugin.checkPermission(sender, "worldguard.region.setpriority"); plugin.checkPermission(sender, "worldguard.region.setpriority." + id.toLowerCase());
} }
region.setPriority(priority); region.setPriority(priority);
@ -610,19 +621,19 @@ public static void setParent(CommandContext args, WorldGuardPlugin plugin,
} }
if (region.isOwner(localPlayer)) { 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)) { } else if (region.isMember(localPlayer)) {
plugin.checkPermission(sender, "worldguard.region.setparent.member"); plugin.checkPermission(sender, "worldguard.region.setparent.member." + id.toLowerCase());
} else { } else {
plugin.checkPermission(sender, "worldguard.region.setparent"); plugin.checkPermission(sender, "worldguard.region.setparent." + id.toLowerCase());
} }
if (parent.isOwner(localPlayer)) { 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)) { } else if (parent.isMember(localPlayer)) {
plugin.checkPermission(sender, "worldguard.region.setparent.member"); plugin.checkPermission(sender, "worldguard.region.setparent.member." + id.toLowerCase());
} else { } else {
plugin.checkPermission(sender, "worldguard.region.setparent"); plugin.checkPermission(sender, "worldguard.region.setparent." + id.toLowerCase());
} }
try { try {
@ -664,11 +675,11 @@ public static void remove(CommandContext args, WorldGuardPlugin plugin,
} }
if (region.isOwner(localPlayer)) { 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)) { } else if (region.isMember(localPlayer)) {
plugin.checkPermission(sender, "worldguard.region.remove.member"); plugin.checkPermission(sender, "worldguard.region.remove.member." + id.toLowerCase());
} else { } else {
plugin.checkPermission(sender, "worldguard.region.flag"); plugin.checkPermission(sender, "worldguard.region.remove." + id.toLowerCase());
} }
mgr.removeRegion(id); mgr.removeRegion(id);

View File

@ -50,6 +50,10 @@ public static void addMember(CommandContext args, WorldGuardPlugin plugin,
String id = args.getString(0); String id = args.getString(0);
if (id.equalsIgnoreCase("__global__")) {
throw new CommandException("The region cannot be named __global__");
}
RegionManager mgr = plugin.getGlobalRegionManager().get(world); RegionManager mgr = plugin.getGlobalRegionManager().get(world);
ProtectedRegion region = mgr.getRegion(id); ProtectedRegion region = mgr.getRegion(id);
@ -58,11 +62,11 @@ public static void addMember(CommandContext args, WorldGuardPlugin plugin,
} }
if (region.isOwner(localPlayer)) { 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)) { } else if (region.isMember(localPlayer)) {
plugin.checkPermission(sender, "worldguard.region.addmember.member"); plugin.checkPermission(sender, "worldguard.region.addmember.member." + id.toLowerCase());
} else { } else {
plugin.checkPermission(sender, "worldguard.region.addmember"); plugin.checkPermission(sender, "worldguard.region.addmember." + id.toLowerCase());
} }
RegionUtil.addToDomain(region.getMembers(), args.getPaddedSlice(2, 0), 0); RegionUtil.addToDomain(region.getMembers(), args.getPaddedSlice(2, 0), 0);
@ -91,6 +95,10 @@ public static void addOwner(CommandContext args, WorldGuardPlugin plugin,
String id = args.getString(0); String id = args.getString(0);
if (id.equalsIgnoreCase("__global__")) {
throw new CommandException("The region cannot be named __global__");
}
RegionManager mgr = plugin.getGlobalRegionManager().get(world); RegionManager mgr = plugin.getGlobalRegionManager().get(world);
ProtectedRegion region = mgr.getRegion(id); ProtectedRegion region = mgr.getRegion(id);
@ -99,11 +107,11 @@ public static void addOwner(CommandContext args, WorldGuardPlugin plugin,
} }
if (region.isOwner(localPlayer)) { 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)) { } else if (region.isMember(localPlayer)) {
plugin.checkPermission(sender, "worldguard.region.addowner.member"); plugin.checkPermission(sender, "worldguard.region.addowner.member." + id.toLowerCase());
} else { } else {
plugin.checkPermission(sender, "worldguard.region.addowner"); plugin.checkPermission(sender, "worldguard.region.addowner." + id.toLowerCase());
} }
RegionUtil.addToDomain(region.getOwners(), args.getPaddedSlice(2, 0), 0); RegionUtil.addToDomain(region.getOwners(), args.getPaddedSlice(2, 0), 0);
@ -132,6 +140,10 @@ public static void removeMember(CommandContext args, WorldGuardPlugin plugin,
String id = args.getString(0); String id = args.getString(0);
if (id.equalsIgnoreCase("__global__")) {
throw new CommandException("The region cannot be named __global__");
}
RegionManager mgr = plugin.getGlobalRegionManager().get(world); RegionManager mgr = plugin.getGlobalRegionManager().get(world);
ProtectedRegion region = mgr.getRegion(id); ProtectedRegion region = mgr.getRegion(id);
@ -140,11 +152,11 @@ public static void removeMember(CommandContext args, WorldGuardPlugin plugin,
} }
if (region.isOwner(localPlayer)) { 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)) { } else if (region.isMember(localPlayer)) {
plugin.checkPermission(sender, "worldguard.region.removemember.member"); plugin.checkPermission(sender, "worldguard.region.removemember.member." + id.toLowerCase());
} else { } else {
plugin.checkPermission(sender, "worldguard.region.removemember"); plugin.checkPermission(sender, "worldguard.region.removemember." + id.toLowerCase());
} }
RegionUtil.removeFromDomain(region.getMembers(), args.getPaddedSlice(2, 0), 0); RegionUtil.removeFromDomain(region.getMembers(), args.getPaddedSlice(2, 0), 0);
@ -173,6 +185,10 @@ public static void removeOwner(CommandContext args, WorldGuardPlugin plugin,
String id = args.getString(0); String id = args.getString(0);
if (id.equalsIgnoreCase("__global__")) {
throw new CommandException("The region cannot be named __global__");
}
RegionManager mgr = plugin.getGlobalRegionManager().get(world); RegionManager mgr = plugin.getGlobalRegionManager().get(world);
ProtectedRegion region = mgr.getRegion(id); ProtectedRegion region = mgr.getRegion(id);
@ -181,11 +197,11 @@ public static void removeOwner(CommandContext args, WorldGuardPlugin plugin,
} }
if (region.isOwner(localPlayer)) { 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)) { } else if (region.isMember(localPlayer)) {
plugin.checkPermission(sender, "worldguard.region.removeowner.member"); plugin.checkPermission(sender, "worldguard.region.removeowner.member." + id.toLowerCase());
} else { } else {
plugin.checkPermission(sender, "worldguard.region.removeowner"); plugin.checkPermission(sender, "worldguard.region.removeowner." + id.toLowerCase());
} }
RegionUtil.removeFromDomain(region.getOwners(), args.getPaddedSlice(2, 0), 0); RegionUtil.removeFromDomain(region.getOwners(), args.getPaddedSlice(2, 0), 0);