Remove WorldguardFlag.java

The main functionality of WorldguardFlag.java was ported to Worldguard.java. This *shouldn't* break functionality of either the Worldguard or WorldguardFlag features, but users should be cautious and provide prompt feedback if any unintended changes are found.
This commit is contained in:
IronApollo 2020-05-03 19:45:04 -04:00
parent 0ca81e9d67
commit 65afa79c17
3 changed files with 8 additions and 115 deletions

View File

@ -16,7 +16,6 @@ import com.boydti.fawe.bukkit.regions.GriefPreventionFeature;
import com.boydti.fawe.bukkit.regions.ResidenceFeature;
import com.boydti.fawe.bukkit.regions.TownyFeature;
import com.boydti.fawe.bukkit.regions.Worldguard;
import com.boydti.fawe.bukkit.regions.WorldguardFlag;
import com.boydti.fawe.bukkit.util.BukkitTaskMan;
import com.boydti.fawe.bukkit.util.ItemUtil;
import com.boydti.fawe.bukkit.util.VaultUtil;
@ -214,7 +213,6 @@ public class FaweBukkit implements IFawe, Listener {
if (worldguardPlugin != null && worldguardPlugin.isEnabled()) {
try {
managers.add(new Worldguard(worldguardPlugin));
managers.add(new WorldguardFlag(worldguardPlugin));
log.debug("Attempting to use plugin 'WorldGuard'");
} catch (Throwable ignored) {
}

View File

@ -14,6 +14,7 @@ import com.sk89q.worldguard.LocalPlayer;
import com.sk89q.worldguard.WorldGuard;
import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
import com.sk89q.worldguard.protection.ApplicableRegionSet;
import com.sk89q.worldguard.protection.flags.Flags;
import com.sk89q.worldguard.protection.managers.RegionManager;
import com.sk89q.worldguard.protection.regions.GlobalProtectedRegion;
import com.sk89q.worldguard.protection.regions.ProtectedCuboidRegion;
@ -61,6 +62,10 @@ public class Worldguard extends BukkitMaskManager implements Listener {
return global;
}
final ApplicableRegionSet regions = manager.getApplicableRegions(BlockVector3.at(location.getX(), location.getY(), location.getZ()));
//Merge WorldGuardFlag
if(player.hasPermission("fawe.worldguardflag") && !regions.testState(player, Flags.BUILD, Flags.BLOCK_PLACE, Flags.BLOCK_BREAK)){
return null;
}
for (ProtectedRegion region : regions) {
if (isAllowed(player, region)) {
return region;
@ -70,6 +75,7 @@ public class Worldguard extends BukkitMaskManager implements Listener {
}
public boolean isAllowed(LocalPlayer localplayer, ProtectedRegion region) {
//Check if player is the owner of the region, the region's ID contains the player's name (why?), or if the region's owners contains "*".
if (region.isOwner(localplayer) || region.isOwner(localplayer.getName())) {
return true;
} else if (region.getId().toLowerCase().equals(localplayer.getName().toLowerCase())) {
@ -79,6 +85,8 @@ public class Worldguard extends BukkitMaskManager implements Listener {
} else if (region.isOwner("*")) {
return true;
}
//Check if the player has the FAWE permission for editing in WG regions as member, then checking member status.
if (localplayer.hasPermission("fawe.worldguard.member")) {
if (region.isMember(localplayer) || region.isMember(localplayer.getName())) {
return true;

View File

@ -1,113 +0,0 @@
package com.boydti.fawe.bukkit.regions;
import com.boydti.fawe.bukkit.filter.WorldGuardFilter;
import com.boydti.fawe.regions.FaweMask;
import com.boydti.fawe.regions.general.RegionFilter;
import com.sk89q.worldedit.bukkit.BukkitAdapter;
import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.regions.AbstractRegion;
import com.sk89q.worldguard.LocalPlayer;
import com.sk89q.worldguard.WorldGuard;
import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
import com.sk89q.worldguard.protection.flags.Flags;
import com.sk89q.worldguard.protection.managers.RegionManager;
import com.sk89q.worldguard.protection.regions.ProtectedRegion;
import com.sk89q.worldguard.protection.regions.RegionContainer;
import java.util.Map;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.event.Listener;
import org.bukkit.plugin.Plugin;
public class WorldguardFlag extends BukkitMaskManager implements Listener {
private final WorldGuardPlugin worldguard;
public WorldguardFlag(Plugin plugin) {
super("worldguardflag");
this.worldguard = (WorldGuardPlugin) plugin; // this.getWorldGuard();
}
@Override
public FaweMask getMask(com.sk89q.worldedit.entity.Player wePlayer, MaskType type) {
final Player player = BukkitAdapter.adapt(wePlayer);
final LocalPlayer localplayer = this.worldguard.wrapPlayer(player);
final RegionContainer container = WorldGuard.getInstance().getPlatform()
.getRegionContainer();
final RegionManager manager = container.get(wePlayer.getWorld());
return new FaweMask(new ManagerRegion(manager, localplayer)) {
@Override
public boolean isValid(com.sk89q.worldedit.entity.Player player, MaskType type) {
// We rely on the region mask instead of this
return true;
}
};
}
@Override
public RegionFilter getFilter(String world) {
return new WorldGuardFilter(Bukkit.getWorld(world));
}
/***
* ManagerRegion wraps a RegionManager and will provide results based upon the regions enclosed
*/
private static class ManagerRegion extends AbstractRegion {
private final RegionManager manager;
private final LocalPlayer localplayer;
ManagerRegion(RegionManager manager, LocalPlayer localplayer) {
super(null);
this.manager = manager;
this.localplayer = localplayer;
}
@Override
public BlockVector3 getMinimumPoint() {
BlockVector3 point = null;
for (Map.Entry<String, ProtectedRegion> entry : manager.getRegions().entrySet()) {
BlockVector3 p = entry.getValue().getMinimumPoint();
if (point == null) {
point = p;
continue;
}
point = point.getMinimum(p);
}
return point;
}
@Override
public BlockVector3 getMaximumPoint() {
BlockVector3 point = null;
for (Map.Entry<String, ProtectedRegion> entry : manager.getRegions().entrySet()) {
BlockVector3 p = entry.getValue().getMaximumPoint();
if (point == null) {
point = p;
continue;
}
point = point.getMaximum(p);
}
return point;
}
@Override
public void expand(BlockVector3... changes) {
throw new UnsupportedOperationException("Region is immutable");
}
@Override
public void contract(BlockVector3... changes) {
throw new UnsupportedOperationException("Region is immutable");
}
@Override
public boolean contains(BlockVector3 position) {
// Make sure that all these flags are not denied. Denies override allows. WorldGuardExtraFlags can add Flags.WORLDEDIT
return manager.getApplicableRegions(position)
.testState(localplayer, Flags.BUILD, Flags.BLOCK_PLACE, Flags.BLOCK_BREAK);
}
}
}