Permalink
Browse files

Fixed a few permission errors.

  • Loading branch information...
me4502 committed Jul 29, 2018
1 parent 8ac5f8f commit dcdd0497d8e0c8ec51b0cb12cc487b42c7c62f4a
@@ -19,10 +19,10 @@
package com.sk89q.worldguard.internal.permission;
import com.sk89q.worldedit.entity.Player;
import com.sk89q.worldedit.extension.platform.Actor;
import com.sk89q.worldedit.world.World;
import com.sk89q.worldguard.LocalPlayer;
import com.sk89q.worldguard.internal.permission.AbstractPermissionModel;
import com.sk89q.worldguard.protection.flags.Flag;
import com.sk89q.worldguard.protection.regions.ProtectedRegion;
@@ -170,7 +170,7 @@ public boolean mayRemoveOwners(ProtectedRegion region) {
* @param region the region
*/
private boolean hasPatternPermission(String perm, ProtectedRegion region) {
if (!(getSender() instanceof LocalPlayer)) {
if (!(getSender() instanceof Player)) {
return true; // Non-players (i.e. console, command blocks, etc.) have full power
}
@@ -42,7 +42,9 @@
import com.sk89q.squirrelid.resolver.ProfileService;
import com.sk89q.wepif.PermissionsResolverManager;
import com.sk89q.worldedit.bukkit.BukkitAdapter;
import com.sk89q.worldedit.bukkit.BukkitCommandSender;
import com.sk89q.worldedit.bukkit.WorldEditPlugin;
import com.sk89q.worldedit.extension.platform.Actor;
import com.sk89q.worldguard.LocalPlayer;
import com.sk89q.worldguard.WorldGuard;
import com.sk89q.worldguard.bukkit.commands.GeneralCommands;
@@ -819,6 +821,19 @@ public LocalPlayer wrapPlayer(Player player, boolean silenced) {
return new BukkitPlayer(this, player, silenced);
}
public Actor wrapCommandSender(CommandSender sender) {
if (sender instanceof Player) {
return wrapPlayer((Player) sender);
}
try {
return new BukkitCommandSender(getWorldEdit(), sender);
} catch (CommandException e) {
e.printStackTrace();
}
return null;
}
/**
* Wrap a player as a LocalPlayer.
*
@@ -65,7 +65,7 @@ public void addMember(CommandContext args, CommandSender sender) throws CommandE
id = region.getId();
// Check permissions
if (!getPermissionModel(plugin.getWorldEdit().wrapCommandSender(sender)).mayAddMembers(region)) {
if (!getPermissionModel(plugin.wrapCommandSender(sender)).mayAddMembers(region)) {
throw new CommandPermissionsException();
}
@@ -164,7 +164,7 @@ public void removeMember(CommandContext args, CommandSender sender) throws Comma
ProtectedRegion region = checkExistingRegion(manager, id, true);
// Check permissions
if (!getPermissionModel(plugin.getWorldEdit().wrapCommandSender(sender)).mayRemoveMembers(region)) {
if (!getPermissionModel(plugin.wrapCommandSender(sender)).mayRemoveMembers(region)) {
throw new CommandPermissionsException();
}
@@ -211,7 +211,7 @@ public void removeOwner(CommandContext args, CommandSender sender) throws Comman
ProtectedRegion region = checkExistingRegion(manager, id, true);
// Check permissions
if (!getPermissionModel(plugin.getWorldEdit().wrapCommandSender(sender)).mayRemoveOwners(region)) {
if (!getPermissionModel(plugin.wrapCommandSender(sender)).mayRemoveOwners(region)) {
throw new CommandPermissionsException();
}
@@ -351,7 +351,7 @@ public void info(CommandContext args, CommandSender sender) throws CommandExcept
warnAboutSaveFailures(sender);
World world = checkWorld(args, sender, 'w'); // Get the world
Actor actor = plugin.getWorldEdit().wrapCommandSender(sender);
Actor actor = plugin.wrapCommandSender(sender);
RegionPermissionModel permModel = getPermissionModel(actor);
// Lookup the existing region
@@ -418,7 +418,7 @@ public void list(CommandContext args, CommandSender sender) throws CommandExcept
World world = checkWorld(args, sender, 'w'); // Get the world
String ownedBy;
Actor actor = plugin.getWorldEdit().wrapCommandSender(sender);
Actor actor = plugin.wrapCommandSender(sender);
// Get page
int page = args.getInteger(0, 1) - 1;
@@ -477,7 +477,7 @@ public void flag(CommandContext args, CommandSender sender) throws CommandExcept
String value = args.argsLength() >= 3 ? args.getJoinedStrings(2) : null;
RegionGroup groupValue = null;
FlagRegistry flagRegistry = WorldGuard.getInstance().getFlagRegistry();
Actor actor = plugin.getWorldEdit().wrapCommandSender(sender);
Actor actor = plugin.wrapCommandSender(sender);
RegionPermissionModel permModel = getPermissionModel(actor);
if (args.hasFlag('e')) {
@@ -649,7 +649,7 @@ public void setPriority(CommandContext args, CommandSender sender) throws Comman
ProtectedRegion existing = checkExistingRegion(manager, args.getString(0), false);
// Check permissions
if (!getPermissionModel(plugin.getWorldEdit().wrapCommandSender(sender)).maySetPriority(existing)) {
if (!getPermissionModel(plugin.wrapCommandSender(sender)).maySetPriority(existing)) {
throw new CommandPermissionsException();
}
@@ -691,7 +691,7 @@ public void setParent(CommandContext args, CommandSender sender) throws CommandE
}
// Check permissions
if (!getPermissionModel(plugin.getWorldEdit().wrapCommandSender(sender)).maySetParent(child, parent)) {
if (!getPermissionModel(plugin.wrapCommandSender(sender)).maySetParent(child, parent)) {
throw new CommandPermissionsException();
}
@@ -751,7 +751,7 @@ public void remove(CommandContext args, CommandSender sender) throws CommandExce
ProtectedRegion existing = checkExistingRegion(manager, args.getString(0), true);
// Check permissions
if (!getPermissionModel(plugin.getWorldEdit().wrapCommandSender(sender)).mayDelete(existing)) {
if (!getPermissionModel(plugin.wrapCommandSender(sender)).mayDelete(existing)) {
throw new CommandPermissionsException();
}
@@ -796,7 +796,7 @@ public void load(CommandContext args, final CommandSender sender) throws Command
}
// Check permissions
if (!getPermissionModel(plugin.getWorldEdit().wrapCommandSender(sender)).mayForceLoadRegions()) {
if (!getPermissionModel(plugin.wrapCommandSender(sender)).mayForceLoadRegions()) {
throw new CommandPermissionsException();
}
@@ -855,7 +855,7 @@ public void save(CommandContext args, final CommandSender sender) throws Command
}
// Check permissions
if (!getPermissionModel(plugin.getWorldEdit().wrapCommandSender(sender)).mayForceSaveRegions()) {
if (!getPermissionModel(plugin.wrapCommandSender(sender)).mayForceSaveRegions()) {
throw new CommandPermissionsException();
}
@@ -904,7 +904,7 @@ public void save(CommandContext args, final CommandSender sender) throws Command
desc = "Migrate from one Protection Database to another.", min = 2, max = 2)
public void migrateDB(CommandContext args, CommandSender sender) throws CommandException {
// Check permissions
if (!getPermissionModel(plugin.getWorldEdit().wrapCommandSender(sender)).mayMigrateRegionStore()) {
if (!getPermissionModel(plugin.wrapCommandSender(sender)).mayMigrateRegionStore()) {
throw new CommandPermissionsException();
}
@@ -981,7 +981,7 @@ public void migrateDB(CommandContext args, CommandSender sender) throws CommandE
desc = "Migrate loaded databases to use UUIDs", max = 0)
public void migrateUuid(CommandContext args, CommandSender sender) throws CommandException {
// Check permissions
if (!getPermissionModel(plugin.getWorldEdit().wrapCommandSender(sender)).mayMigrateRegionNames()) {
if (!getPermissionModel(plugin.wrapCommandSender(sender)).mayMigrateRegionNames()) {
throw new CommandPermissionsException();
}
@@ -27,7 +27,6 @@
import com.sk89q.worldedit.LocalSession;
import com.sk89q.worldedit.Vector;
import com.sk89q.worldedit.WorldEdit;
import com.sk89q.worldedit.bukkit.WorldEditPlugin;
import com.sk89q.worldedit.extension.platform.Actor;
import com.sk89q.worldedit.regions.CuboidRegion;
import com.sk89q.worldedit.regions.Polygonal2DRegion;
@@ -220,10 +219,9 @@ protected static ProtectedRegion checkRegionStandingIn(RegionManager regionManag
* @throws CommandException thrown on an error
*/
protected static Region checkSelection(Player player) throws CommandException {
WorldEditPlugin worldEdit = WorldGuardPlugin.inst().getWorldEdit();
com.sk89q.worldedit.entity.Player wePlayer = worldEdit.wrapPlayer(player);
LocalPlayer localPlayer = WorldGuardPlugin.inst().wrapPlayer(player);
try {
return WorldEdit.getInstance().getSessionManager().get(wePlayer).getRegionSelector(wePlayer.getWorld()).getRegion();
return WorldEdit.getInstance().getSessionManager().get(localPlayer).getRegionSelector(localPlayer.getWorld()).getRegion();
} catch (IncompleteRegionException e) {
throw new CommandException(
"Please select an area first. " +
@@ -350,27 +348,26 @@ protected static void informNewUser(CommandSender sender, RegionManager manager,
* @throws CommandException thrown on a command error
*/
protected static void setPlayerSelection(Player player, ProtectedRegion region) throws CommandException {
WorldEditPlugin worldEdit = WorldGuardPlugin.inst().getWorldEdit();
com.sk89q.worldedit.entity.Player wePlayer = worldEdit.wrapPlayer(player);
LocalPlayer localPlayer = WorldGuardPlugin.inst().wrapPlayer(player);
LocalSession session = WorldEdit.getInstance().getSessionManager().get(wePlayer);
LocalSession session = WorldEdit.getInstance().getSessionManager().get(localPlayer);
// Set selection
if (region instanceof ProtectedCuboidRegion) {
ProtectedCuboidRegion cuboid = (ProtectedCuboidRegion) region;
Vector pt1 = cuboid.getMinimumPoint();
Vector pt2 = cuboid.getMaximumPoint();
session.setRegionSelector(wePlayer.getWorld(), new CuboidRegionSelector(wePlayer.getWorld(), pt1, pt2));
session.setRegionSelector(localPlayer.getWorld(), new CuboidRegionSelector(localPlayer.getWorld(), pt1, pt2));
player.sendMessage(ChatColor.YELLOW + "Region selected as a cuboid.");
} else if (region instanceof ProtectedPolygonalRegion) {
ProtectedPolygonalRegion poly2d = (ProtectedPolygonalRegion) region;
Polygonal2DRegionSelector selector = new Polygonal2DRegionSelector(
wePlayer.getWorld(), poly2d.getPoints(),
localPlayer.getWorld(), poly2d.getPoints(),
poly2d.getMinimumPoint().getBlockY(),
poly2d.getMaximumPoint().getBlockY() );
session.setRegionSelector(wePlayer.getWorld(), selector);
session.setRegionSelector(localPlayer.getWorld(), selector);
player.sendMessage(ChatColor.YELLOW + "Region selected as a polygon.");
} else if (region instanceof GlobalProtectedRegion) {

0 comments on commit dcdd049

Please sign in to comment.