Skip to content
Permalink
Browse files

Add /rg toggle-bypass command to turn off region bypass temporarily.

Makes it easier to test things without op/de-op, switching ranks, etc
all the time.
  • Loading branch information...
wizjany committed Oct 6, 2019
1 parent 4c9812d commit 3ebaaf9c8b51826d8ea2e24c34dcf04cea378567
@@ -136,13 +136,14 @@ private boolean isWhitelisted(Cause cause, World world, boolean pvp) {
if (rootCause instanceof Player) {
Player player = (Player) rootCause;
LocalPlayer localPlayer = WorldGuardPlugin.inst().wrapPlayer(player);
WorldConfiguration config = getWorldConfig(BukkitAdapter.adapt(world));
com.sk89q.worldedit.world.World localWorld = BukkitAdapter.adapt(world);
WorldConfiguration config = getWorldConfig(localWorld);

if (config.fakePlayerBuildOverride && InteropUtils.isFakePlayer(player)) {
return true;
}

return !pvp && new RegionPermissionModel(localPlayer).mayIgnoreRegionProtection(BukkitAdapter.adapt(world));
return !pvp && WorldGuard.getInstance().getPlatform().getSessionManager().hasBypass(localPlayer, localWorld);
} else {
return false;
}
@@ -682,9 +682,9 @@ public void onCreatePortal(PortalCreateEvent event) {
LocalPlayer associable = null;
if (event.getEntity() instanceof Player) {
associable = plugin.wrapPlayer(((Player) event.getEntity()));
}
if (WorldGuard.getInstance().getPlatform().getSessionManager().hasBypass(associable, world)) {
return;
if (WorldGuard.getInstance().getPlatform().getSessionManager().hasBypass(associable, world)) {
return;
}
}
BlockVector3 min = null;
BlockVector3 max = null;
@@ -25,6 +25,7 @@
import com.sk89q.minecraft.util.commands.Command;
import com.sk89q.minecraft.util.commands.CommandContext;
import com.sk89q.minecraft.util.commands.CommandException;
import com.sk89q.minecraft.util.commands.CommandPermissions;
import com.sk89q.minecraft.util.commands.CommandPermissionsException;
import com.sk89q.worldedit.WorldEdit;
import com.sk89q.worldedit.command.util.AsyncCommandBuilder;
@@ -73,6 +74,7 @@
import com.sk89q.worldguard.protection.regions.ProtectedRegion.CircularInheritanceException;
import com.sk89q.worldguard.protection.regions.RegionContainer;
import com.sk89q.worldguard.protection.util.DomainInputResolver.UserLocatorPolicy;
import com.sk89q.worldguard.session.Session;
import com.sk89q.worldguard.util.Enums;
import com.sk89q.worldguard.util.logging.LoggerToChatHandler;

@@ -1097,6 +1099,21 @@ public void teleport(CommandContext args, Actor sender) throws CommandException
"Unable to teleport to region '" + existing.getId() + "'.");
}

@Command(aliases = {"toggle-bypass", "bypass"},
desc = "Toggle region bypassing, effectively ignoring bypass permissions.")
@CommandPermissions({"worldguard.region.toggle-bypass"})
public void toggleBypass(CommandContext args, Actor sender) throws CommandException {
LocalPlayer player = worldGuard.checkPlayer(sender);
Session session = WorldGuard.getInstance().getPlatform().getSessionManager().get(player);
if (session.hasBypassDisabled()) {
session.setBypassDisabled(false);
player.print("You are now bypassing region protection (as long as you have permission).");
} else {
session.setBypassDisabled(true);
player.print("You are no longer bypassing region protection.");
}
}

private static class FlagListBuilder implements Callable<Component> {
private final FlagRegistry flagRegistry;
private final RegionPermissionModel permModel;
@@ -23,6 +23,7 @@
import com.sk89q.worldedit.extension.platform.Actor;
import com.sk89q.worldedit.world.World;
import com.sk89q.worldguard.LocalPlayer;
import com.sk89q.worldguard.WorldGuard;
import com.sk89q.worldguard.protection.flags.Flag;
import com.sk89q.worldguard.protection.regions.ProtectedRegion;

@@ -37,7 +38,13 @@ public RegionPermissionModel(Actor sender) {
super(sender);
}

/**
* @deprecated Check {@code WorldGuard.getInstance().getPlatform().getSessionManager().hasBypass(..)} instead
*/
@Deprecated
public boolean mayIgnoreRegionProtection(World world) {
if (getSender() instanceof LocalPlayer)
return WorldGuard.getInstance().getPlatform().getSessionManager().hasBypass((LocalPlayer) getSender(), world);
return hasPluginPermission("region.bypass." + world.getName());
}

@@ -127,7 +127,9 @@ public boolean unregisterHandler(Handler.Factory<? extends Handler> factory) {

@Override
public boolean hasBypass(LocalPlayer player, World world) {
return bypassCache.getUnchecked(new WorldPlayerTuple(world, player));
Session sess = getIfPresent(player);
return sess != null && !sess.hasBypassDisabled()
&& bypassCache.getUnchecked(new WorldPlayerTuple(world, player));
}

@Override
@@ -44,6 +44,7 @@
public class Session {

private final SessionManager manager;
private boolean disableBypass;
private final HashMap<Class<?>, Handler> handlers = Maps.newLinkedHashMap();
private Location lastValid;
private Set<ProtectedRegion> lastRegionSet;
@@ -217,4 +218,18 @@ public Location testMoveTo(LocalPlayer player, Location to, MoveType moveType, b
return null;
}

/**
* @return true if the owner of this session should not bypass protection, even if they have bypass permissions
*/
public boolean hasBypassDisabled() {
return disableBypass;
}

/**
* Toggle bypass disabling for this session.
* @param disabled true to disable region bypass
*/
public void setBypassDisabled(boolean disabled) {
disableBypass = disabled;
}
}

0 comments on commit 3ebaaf9

Please sign in to comment.
You can’t perform that action at this time.