diff --git a/bukkit0/src/main/java/com/boydti/fawe/bukkit/regions/FactionsFeature.java b/bukkit0/src/main/java/com/boydti/fawe/bukkit/regions/FactionsFeature.java index 02d66509..f460862f 100644 --- a/bukkit0/src/main/java/com/boydti/fawe/bukkit/regions/FactionsFeature.java +++ b/bukkit0/src/main/java/com/boydti/fawe/bukkit/regions/FactionsFeature.java @@ -4,6 +4,7 @@ import com.boydti.fawe.bukkit.FaweBukkit; import com.boydti.fawe.object.FawePlayer; import com.massivecraft.factions.entity.BoardColl; import com.massivecraft.factions.entity.Faction; +import com.massivecraft.factions.entity.MPlayer; import com.massivecraft.massivecore.ps.PS; import org.bukkit.Chunk; import org.bukkit.Location; @@ -23,13 +24,27 @@ public class FactionsFeature extends BukkitMaskManager implements Listener { } @Override - public BukkitMask getMask(final FawePlayer fp) { + public BukkitMask getMask(final FawePlayer fp, MaskType type) { final Player player = fp.parent; final Location loc = player.getLocation(); final PS ps = PS.valueOf(loc); final Faction fac = BoardColl.get().getFactionAt(ps); if (fac != null) { - if (fac.getOnlinePlayers().contains(player)) { + if (type == MaskType.OWNER) { + MPlayer leader = fac.getLeader(); + if (leader != null && fp.getUUID().equals(leader.getUuid())) { + final Chunk chunk = loc.getChunk(); + final Location pos1 = new Location(loc.getWorld(), chunk.getX() * 16, 0, chunk.getZ() * 16); + final Location pos2 = new Location(loc.getWorld(), (chunk.getX() * 16) + 15, 156, (chunk.getZ() * 16) + 15); + return new BukkitMask(pos1, pos2) { + @Override + public String getName() { + return "CHUNK:" + loc.getChunk().getX() + "," + loc.getChunk().getZ(); + } + }; + } + } + else if (fac.getOnlinePlayers().contains(player)) { if (fac.getComparisonName().equals("wilderness") == false) { final Chunk chunk = loc.getChunk(); final Location pos1 = new Location(loc.getWorld(), chunk.getX() * 16, 0, chunk.getZ() * 16); diff --git a/bukkit0/src/main/java/com/boydti/fawe/bukkit/regions/FactionsOneFeature.java b/bukkit0/src/main/java/com/boydti/fawe/bukkit/regions/FactionsOneFeature.java index 61ce2fa4..82d84c38 100644 --- a/bukkit0/src/main/java/com/boydti/fawe/bukkit/regions/FactionsOneFeature.java +++ b/bukkit0/src/main/java/com/boydti/fawe/bukkit/regions/FactionsOneFeature.java @@ -27,7 +27,7 @@ public class FactionsOneFeature extends BukkitMaskManager implements Listener { } @Override - public BukkitMask getMask(final FawePlayer fp) { + public BukkitMask getMask(final FawePlayer fp, MaskType type) { final Player player = fp.parent; final Chunk chunk = player.getLocation().getChunk(); final boolean perm = Perm.hasPermission(FawePlayer.wrap(player), "fawe.factions.wilderness"); @@ -36,7 +36,7 @@ public class FactionsOneFeature extends BukkitMaskManager implements Listener { int count = 32; - if (this.isAdded(locs, world, player, perm)) { + if (this.isAdded(locs, world, player, perm, type)) { boolean hasPerm = true; RegionWrapper chunkSelection; @@ -47,28 +47,28 @@ public class FactionsOneFeature extends BukkitMaskManager implements Listener { chunkSelection = new RegionWrapper(locs.maxX + 1, locs.maxX + 1, locs.minZ, locs.maxZ); - if (this.isAdded(chunkSelection, world, player, perm)) { + if (this.isAdded(chunkSelection, world, player, perm, type)) { locs.maxX += 1; hasPerm = true; } chunkSelection = new RegionWrapper(locs.minX - 1, locs.minX - 1, locs.minZ, locs.maxZ); - if (this.isAdded(chunkSelection, world, player, perm)) { + if (this.isAdded(chunkSelection, world, player, perm, type)) { locs.minX -= 1; hasPerm = true; } chunkSelection = new RegionWrapper(locs.minX, locs.maxX, locs.maxZ + 1, locs.maxZ + 1); - if (this.isAdded(chunkSelection, world, player, perm)) { + if (this.isAdded(chunkSelection, world, player, perm, type)) { locs.maxZ += 1; hasPerm = true; } chunkSelection = new RegionWrapper(locs.minX, locs.maxX, locs.minZ - 1, locs.minZ - 1); - if (this.isAdded(chunkSelection, world, player, perm)) { + if (this.isAdded(chunkSelection, world, player, perm, type)) { locs.minZ -= 1; hasPerm = true; } @@ -86,7 +86,7 @@ public class FactionsOneFeature extends BukkitMaskManager implements Listener { return null; } - public boolean isAdded(final RegionWrapper locs, final World world, final Player player, final boolean perm) { + public boolean isAdded(final RegionWrapper locs, final World world, final Player player, final boolean perm, MaskType type) { try { for (int x = locs.minX; x <= locs.maxX; x++) { for (int z = locs.minZ; z <= locs.maxZ; z++) { @@ -94,6 +94,10 @@ public class FactionsOneFeature extends BukkitMaskManager implements Listener { if (fac == null) { return false; } + if (type == MaskType.OWNER) { + Object leader = fac.getClass().getDeclaredMethod("getFPlayerLeader").invoke(fac); + return player.getName().equals(leader.getClass().getDeclaredMethod("getName").invoke(leader)); + } Method methodGetOnlinePlayers = fac.getClass().getDeclaredMethod("getOnlinePlayers"); List players = (List) methodGetOnlinePlayers.invoke(fac); if (!players.contains(player)) { diff --git a/bukkit0/src/main/java/com/boydti/fawe/bukkit/regions/FactionsUUIDFeature.java b/bukkit0/src/main/java/com/boydti/fawe/bukkit/regions/FactionsUUIDFeature.java index 9ab5668c..d278a291 100644 --- a/bukkit0/src/main/java/com/boydti/fawe/bukkit/regions/FactionsUUIDFeature.java +++ b/bukkit0/src/main/java/com/boydti/fawe/bukkit/regions/FactionsUUIDFeature.java @@ -23,7 +23,7 @@ public class FactionsUUIDFeature extends BukkitMaskManager implements Listener { } @Override - public BukkitMask getMask(final FawePlayer fp) { + public BukkitMask getMask(final FawePlayer fp, MaskType type) { final Player player = fp.parent; final Chunk chunk = player.getLocation().getChunk(); final boolean perm = Perm.hasPermission(FawePlayer.wrap(player), "fawe.factions.wilderness"); @@ -32,7 +32,7 @@ public class FactionsUUIDFeature extends BukkitMaskManager implements Listener { int count = 32; - if (this.isAdded(locs, world, player, perm)) { + if (this.isAdded(locs, world, player, perm, type)) { boolean hasPerm = true; RegionWrapper chunkSelection; @@ -43,28 +43,28 @@ public class FactionsUUIDFeature extends BukkitMaskManager implements Listener { chunkSelection = new RegionWrapper(locs.maxX + 1, locs.maxX + 1, locs.minZ, locs.maxZ); - if (this.isAdded(chunkSelection, world, player, perm)) { + if (this.isAdded(chunkSelection, world, player, perm, type)) { locs.maxX += 1; hasPerm = true; } chunkSelection = new RegionWrapper(locs.minX - 1, locs.minX - 1, locs.minZ, locs.maxZ); - if (this.isAdded(chunkSelection, world, player, perm)) { + if (this.isAdded(chunkSelection, world, player, perm, type)) { locs.minX -= 1; hasPerm = true; } chunkSelection = new RegionWrapper(locs.minX, locs.maxX, locs.maxZ + 1, locs.maxZ + 1); - if (this.isAdded(chunkSelection, world, player, perm)) { + if (this.isAdded(chunkSelection, world, player, perm, type)) { locs.maxZ += 1; hasPerm = true; } chunkSelection = new RegionWrapper(locs.minX, locs.maxX, locs.minZ - 1, locs.minZ - 1); - if (this.isAdded(chunkSelection, world, player, perm)) { + if (this.isAdded(chunkSelection, world, player, perm, type)) { locs.minZ -= 1; hasPerm = true; } @@ -82,13 +82,14 @@ public class FactionsUUIDFeature extends BukkitMaskManager implements Listener { return null; } - public boolean isAdded(final RegionWrapper locs, final World world, final Player player, final boolean perm) { + public boolean isAdded(final RegionWrapper locs, final World world, final Player player, final boolean perm, MaskType type) { for (int x = locs.minX; x <= locs.maxX; x++) { for (int z = locs.minZ; z <= locs.maxZ; z++) { final Faction fac = this.instance.getFactionAt(new FLocation(world.getName(), x, z)); if (fac == null) { return false; } + // TODO types if (!fac.getOnlinePlayers().contains(player)) { return false; } diff --git a/bukkit0/src/main/java/com/boydti/fawe/bukkit/regions/GriefPreventionFeature.java b/bukkit0/src/main/java/com/boydti/fawe/bukkit/regions/GriefPreventionFeature.java index b2613f45..6b5f2c41 100644 --- a/bukkit0/src/main/java/com/boydti/fawe/bukkit/regions/GriefPreventionFeature.java +++ b/bukkit0/src/main/java/com/boydti/fawe/bukkit/regions/GriefPreventionFeature.java @@ -21,13 +21,13 @@ public class GriefPreventionFeature extends BukkitMaskManager implements Listene } @Override - public BukkitMask getMask(final FawePlayer fp) { + public BukkitMask getMask(final FawePlayer fp, MaskType type) { final Player player = fp.parent; final Location location = player.getLocation(); final Claim claim = GriefPrevention.instance.dataStore.getClaimAt(location, true, null); if (claim != null) { final String uuid = player.getUniqueId().toString(); - if (claim.getOwnerName().equalsIgnoreCase(player.getName()) || claim.getOwnerName().equals(uuid) || claim.allowBuild(player, Material.AIR) == null) { + if (claim.getOwnerName().equalsIgnoreCase(player.getName()) || claim.getOwnerName().equals(uuid) || (type == MaskType.MEMBER && (claim.allowBuild(player, Material.AIR) == null))) { claim.getGreaterBoundaryCorner().getBlockX(); final Location pos1 = new Location(location.getWorld(), claim.getLesserBoundaryCorner().getBlockX(), 0, claim.getLesserBoundaryCorner().getBlockZ()); final Location pos2 = new Location(location.getWorld(), claim.getGreaterBoundaryCorner().getBlockX(), 256, claim.getGreaterBoundaryCorner().getBlockZ()); diff --git a/bukkit0/src/main/java/com/boydti/fawe/bukkit/regions/PlotMeFeature.java b/bukkit0/src/main/java/com/boydti/fawe/bukkit/regions/PlotMeFeature.java index 5c6c7911..cb4e3d80 100644 --- a/bukkit0/src/main/java/com/boydti/fawe/bukkit/regions/PlotMeFeature.java +++ b/bukkit0/src/main/java/com/boydti/fawe/bukkit/regions/PlotMeFeature.java @@ -24,14 +24,14 @@ public class PlotMeFeature extends BukkitMaskManager implements Listener { } @Override - public BukkitMask getMask(final FawePlayer fp) { + public BukkitMask getMask(final FawePlayer fp, MaskType type) { final Player player = fp.parent; final Location location = player.getLocation(); final Plot plot = this.plotme.getPlotMeCoreManager().getPlotById(new BukkitPlayer(player)); if (plot == null) { return null; } - final boolean isallowed = plot.isAllowed(player.getUniqueId()); + final boolean isallowed = type == MaskType.MEMBER ? plot.isAllowed(player.getUniqueId()) : player.getUniqueId().equals(plot.getOwnerId()); if (isallowed) { final Location pos1 = new Location(location.getWorld(), this.plotme.getGenManager(player.getWorld().getName()).bottomX(plot.getId(), new BukkitWorld(player.getWorld())), 0, this.plotme .getGenManager(player.getWorld().getName()).bottomZ(plot.getId(), new BukkitWorld(player.getWorld()))); diff --git a/bukkit0/src/main/java/com/boydti/fawe/bukkit/regions/PreciousStonesFeature.java b/bukkit0/src/main/java/com/boydti/fawe/bukkit/regions/PreciousStonesFeature.java index f7e6234a..ace030b9 100644 --- a/bukkit0/src/main/java/com/boydti/fawe/bukkit/regions/PreciousStonesFeature.java +++ b/bukkit0/src/main/java/com/boydti/fawe/bukkit/regions/PreciousStonesFeature.java @@ -25,7 +25,7 @@ public class PreciousStonesFeature extends BukkitMaskManager implements Listener } @Override - public FaweMask getMask(final FawePlayer fp) { + public FaweMask getMask(final FawePlayer fp, MaskType type) { final Player player = fp.parent; final Location location = player.getLocation(); final List fields = PreciousStones.API().getFieldsProtectingArea(FieldFlag.ALL, location); @@ -35,7 +35,7 @@ public class PreciousStonesFeature extends BukkitMaskManager implements Listener String name = player.getName(); boolean member = fp.hasPermission("fawe.preciousstones.member"); for (final Field myField : fields) { - if (myField.isOwner(name) || (member && myField.getAllAllowed().contains(player.getName()))) { + if (myField.isOwner(name) || (type == MaskType.MEMBER && member && myField.getAllAllowed().contains(player.getName()))) { BlockVector pos1 = new BlockVector(myField.getMinx(), myField.getMiny(), myField.getMinz()); BlockVector pos2 = new BlockVector(myField.getMaxx(), myField.getMaxy(), myField.getMaxz()); return new FaweMask(pos1, pos2, "FIELD: " + myField); diff --git a/bukkit0/src/main/java/com/boydti/fawe/bukkit/regions/ResidenceFeature.java b/bukkit0/src/main/java/com/boydti/fawe/bukkit/regions/ResidenceFeature.java index 018019cc..9b1443c1 100644 --- a/bukkit0/src/main/java/com/boydti/fawe/bukkit/regions/ResidenceFeature.java +++ b/bukkit0/src/main/java/com/boydti/fawe/bukkit/regions/ResidenceFeature.java @@ -22,12 +22,12 @@ public class ResidenceFeature extends BukkitMaskManager implements Listener { } @Override - public BukkitMask getMask(final FawePlayer fp) { + public BukkitMask getMask(final FawePlayer fp, MaskType type) { final Player player = fp.parent; final Location location = player.getLocation(); final ClaimedResidence residence = Residence.getResidenceManager().getByLoc(location); if (residence != null) { - if (residence.getPlayersInResidence().contains(player)) { + if (residence.getOwner().equals(player.getName()) || residence.getOwner().equals(player.getUniqueId().toString()) || type == MaskType.MEMBER && residence.getPlayersInResidence().contains(player)) { final CuboidArea area = residence.getAreaArray()[0]; final Location pos1 = area.getHighLoc(); final Location pos2 = area.getLowLoc(); diff --git a/core/src/main/java/com/boydti/fawe/object/FawePlayer.java b/core/src/main/java/com/boydti/fawe/object/FawePlayer.java index ed4c2209..1a782f50 100644 --- a/core/src/main/java/com/boydti/fawe/object/FawePlayer.java +++ b/core/src/main/java/com/boydti/fawe/object/FawePlayer.java @@ -6,6 +6,7 @@ import com.boydti.fawe.config.BBC; import com.boydti.fawe.config.Settings; import com.boydti.fawe.object.clipboard.DiskOptimizedClipboard; import com.boydti.fawe.object.exception.FaweException; +import com.boydti.fawe.regions.FaweMaskManager; import com.boydti.fawe.util.MainUtil; import com.boydti.fawe.util.SetQueue; import com.boydti.fawe.util.TaskManager; @@ -341,6 +342,10 @@ public abstract class FawePlayer { return WEManager.IMP.getMask(this); } + public RegionWrapper[] getCurrentRegions(FaweMaskManager.MaskType type) { + return WEManager.IMP.getMask(this, type); + } + /** * Set the player's WorldEdit selection to the following CuboidRegion * @param region diff --git a/core/src/main/java/com/boydti/fawe/regions/FaweMaskManager.java b/core/src/main/java/com/boydti/fawe/regions/FaweMaskManager.java index ad94dfd5..2235e320 100644 --- a/core/src/main/java/com/boydti/fawe/regions/FaweMaskManager.java +++ b/core/src/main/java/com/boydti/fawe/regions/FaweMaskManager.java @@ -3,6 +3,12 @@ package com.boydti.fawe.regions; import com.boydti.fawe.object.FawePlayer; public abstract class FaweMaskManager { + + public enum MaskType { + OWNER, + MEMBER + } + private final String key; public FaweMaskManager(final String plugin) { @@ -18,5 +24,11 @@ public abstract class FaweMaskManager { return this.key; } - public abstract FaweMask getMask(final FawePlayer player); + public FaweMask getMask(final FawePlayer player) { + return getMask(player, MaskType.MEMBER); + } + + public FaweMask getMask(final FawePlayer player, MaskType type) { + return getMask(player); + } } diff --git a/core/src/main/java/com/boydti/fawe/regions/general/plot/PlotSquaredFeature.java b/core/src/main/java/com/boydti/fawe/regions/general/plot/PlotSquaredFeature.java index 64910141..d784e4d2 100644 --- a/core/src/main/java/com/boydti/fawe/regions/general/plot/PlotSquaredFeature.java +++ b/core/src/main/java/com/boydti/fawe/regions/general/plot/PlotSquaredFeature.java @@ -63,11 +63,11 @@ public class PlotSquaredFeature extends FaweMaskManager { } @Override - public FaweMask getMask(FawePlayer fp) { + public FaweMask getMask(FawePlayer fp, MaskType type) { final PlotPlayer pp = PlotPlayer.wrap(fp.parent); final HashSet regions; Plot plot = pp.getCurrentPlot(); - if (plot != null && (plot.isOwner(pp.getUUID()) || plot.getTrusted().contains(pp.getUUID()) || (plot.getMembers().contains(pp.getUUID()) && pp.hasPermission("fawe.plotsquared.member")))) { + if (plot != null && (plot.isOwner(pp.getUUID()) || (type == MaskType.MEMBER && (plot.getTrusted().contains(pp.getUUID()) || (plot.getMembers().contains(pp.getUUID()) && pp.hasPermission("fawe.plotsquared.member")))))) { regions = plot.getRegions(); } else { regions = WEManager.getMask(pp); diff --git a/core/src/main/java/com/boydti/fawe/util/WEManager.java b/core/src/main/java/com/boydti/fawe/util/WEManager.java index 39a60a4e..8419176f 100644 --- a/core/src/main/java/com/boydti/fawe/util/WEManager.java +++ b/core/src/main/java/com/boydti/fawe/util/WEManager.java @@ -62,12 +62,17 @@ public class WEManager { } } + @Deprecated + public RegionWrapper[] getMask(final FawePlayer player) { + return getMask(player, FaweMaskManager.MaskType.MEMBER); + } + /** * Get a player's mask * @param player * @return */ - public RegionWrapper[] getMask(final FawePlayer player) { + public RegionWrapper[] getMask(final FawePlayer player, FaweMaskManager.MaskType type) { // HashSet mask = TaskManager.IMP.sync(new RunnableVal>() { if (player.hasPermission("fawe.bypass") || !Settings.REGION_RESTRICTIONS) { return new RegionWrapper[] {new RegionWrapper(Integer.MIN_VALUE, Integer.MAX_VALUE, Integer.MIN_VALUE, Integer.MAX_VALUE)}; diff --git a/core/src/main/java/com/sk89q/worldedit/command/HistoryCommands.java b/core/src/main/java/com/sk89q/worldedit/command/HistoryCommands.java index 5159717c..8b021600 100644 --- a/core/src/main/java/com/sk89q/worldedit/command/HistoryCommands.java +++ b/core/src/main/java/com/sk89q/worldedit/command/HistoryCommands.java @@ -27,11 +27,15 @@ import com.boydti.fawe.database.DBHandler; import com.boydti.fawe.database.RollbackDatabase; import com.boydti.fawe.logging.rollback.RollbackOptimizedHistory; import com.boydti.fawe.object.FawePlayer; +import com.boydti.fawe.object.FaweQueue; +import com.boydti.fawe.object.MaskedFaweQueue; import com.boydti.fawe.object.RegionWrapper; import com.boydti.fawe.object.RunnableVal; import com.boydti.fawe.object.changeset.DiskStorageHistory; +import com.boydti.fawe.regions.FaweMaskManager; import com.boydti.fawe.util.EditSessionBuilder; import com.boydti.fawe.util.MainUtil; +import com.boydti.fawe.util.SetQueue; import com.sk89q.minecraft.util.commands.Command; import com.sk89q.minecraft.util.commands.CommandContext; import com.sk89q.minecraft.util.commands.CommandPermissions; @@ -147,6 +151,14 @@ public class HistoryCommands { RollbackDatabase database = DBHandler.IMP.getDatabase(world); final AtomicInteger count = new AtomicInteger(); final FawePlayer fp = FawePlayer.wrap(player); + + final FaweQueue finalQueue; + RegionWrapper[] allowedRegions = fp.getCurrentRegions(FaweMaskManager.MaskType.OWNER); + if (allowedRegions.length != 1 || !allowedRegions[0].isGlobal()) { + finalQueue = new MaskedFaweQueue(SetQueue.IMP.getNewQueue(fp.getWorld(), true, false), allowedRegions); + } else { + finalQueue = SetQueue.IMP.getNewQueue(fp.getWorld(), true, false); + } database.getPotentialEdits(other, System.currentTimeMillis() - timeDiff, bot, top, new RunnableVal() { @Override public void run(DiskStorageHistory edit) { @@ -157,7 +169,7 @@ public class HistoryCommands { .checkMemory(false) .changeSet(edit) .limitUnlimited() - .queue(fp.getMaskedFaweQueue(false)) + .queue(finalQueue) .build(); session.setSize(1); session.undo(session);