Only owners can rollback

This commit is contained in:
Jesse Boyd 2016-10-02 17:55:24 +11:00
parent 2682540de5
commit d2413daca1
No known key found for this signature in database
GPG Key ID: 59F1DE6293AF6E1F
12 changed files with 83 additions and 29 deletions

View File

@ -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<Player> fp) {
public BukkitMask getMask(final FawePlayer<Player> 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);

View File

@ -27,7 +27,7 @@ public class FactionsOneFeature extends BukkitMaskManager implements Listener {
}
@Override
public BukkitMask getMask(final FawePlayer<Player> fp) {
public BukkitMask getMask(final FawePlayer<Player> 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<Player> players = (List<Player>) methodGetOnlinePlayers.invoke(fac);
if (!players.contains(player)) {

View File

@ -23,7 +23,7 @@ public class FactionsUUIDFeature extends BukkitMaskManager implements Listener {
}
@Override
public BukkitMask getMask(final FawePlayer<Player> fp) {
public BukkitMask getMask(final FawePlayer<Player> 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;
}

View File

@ -21,13 +21,13 @@ public class GriefPreventionFeature extends BukkitMaskManager implements Listene
}
@Override
public BukkitMask getMask(final FawePlayer<Player> fp) {
public BukkitMask getMask(final FawePlayer<Player> 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());

View File

@ -24,14 +24,14 @@ public class PlotMeFeature extends BukkitMaskManager implements Listener {
}
@Override
public BukkitMask getMask(final FawePlayer<Player> fp) {
public BukkitMask getMask(final FawePlayer<Player> 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())));

View File

@ -25,7 +25,7 @@ public class PreciousStonesFeature extends BukkitMaskManager implements Listener
}
@Override
public FaweMask getMask(final FawePlayer<Player> fp) {
public FaweMask getMask(final FawePlayer<Player> fp, MaskType type) {
final Player player = fp.parent;
final Location location = player.getLocation();
final List<Field> 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);

View File

@ -22,12 +22,12 @@ public class ResidenceFeature extends BukkitMaskManager implements Listener {
}
@Override
public BukkitMask getMask(final FawePlayer<Player> fp) {
public BukkitMask getMask(final FawePlayer<Player> 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();

View File

@ -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<T> {
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

View File

@ -3,6 +3,12 @@ package com.boydti.fawe.regions;
import com.boydti.fawe.object.FawePlayer;
public abstract class FaweMaskManager<T> {
public enum MaskType {
OWNER,
MEMBER
}
private final String key;
public FaweMaskManager(final String plugin) {
@ -18,5 +24,11 @@ public abstract class FaweMaskManager<T> {
return this.key;
}
public abstract FaweMask getMask(final FawePlayer<T> player);
public FaweMask getMask(final FawePlayer<T> player) {
return getMask(player, MaskType.MEMBER);
}
public FaweMask getMask(final FawePlayer<T> player, MaskType type) {
return getMask(player);
}
}

View File

@ -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<RegionWrapper> 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);

View File

@ -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<RegionWrapper> mask = TaskManager.IMP.sync(new RunnableVal<HashSet<RegionWrapper>>() {
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)};

View File

@ -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<DiskStorageHistory>() {
@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);