freebuild region restrictions (bukkit)
+ tweak undo/redo messages
This commit is contained in:
Jesse Boyd 2018-10-13 15:20:21 +11:00
parent 934897ff1c
commit 47ce67c325
No known key found for this signature in database
GPG Key ID: 59F1DE6293AF6E1F
9 changed files with 203 additions and 22 deletions

View File

@ -569,6 +569,15 @@ public class FaweBukkit implements IFawe, Listener {
}
}
if (Settings.IMP.EXPERIMENTAL.FREEBUILD) {
try {
managers.add(new FreeBuildRegion());
Fawe.debug("Plugin '<internal.freebuild>' found. Using it now.");
} catch (final Throwable e) {
MainUtil.handleError(e);
}
}
return managers;
}
//

View File

@ -0,0 +1,110 @@
package com.boydti.fawe.bukkit.regions;
import com.boydti.fawe.bukkit.wrapper.AsyncBlock;
import com.boydti.fawe.bukkit.wrapper.AsyncWorld;
import com.boydti.fawe.object.FawePlayer;
import com.boydti.fawe.object.queue.NullFaweQueue;
import com.boydti.fawe.regions.FaweMask;
import com.sk89q.worldedit.Vector;
import com.sk89q.worldedit.bukkit.BukkitUtil;
import com.sk89q.worldedit.regions.CuboidRegion;
import com.sk89q.worldedit.regions.Region;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.entity.Player;
import org.bukkit.event.EventException;
import org.bukkit.event.EventPriority;
import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.plugin.RegisteredListener;
import java.util.ArrayList;
public class FreeBuildRegion extends BukkitMaskManager {
private final ArrayList<RegisteredListener> listeners;
public FreeBuildRegion() {
super("freebuild");
this.listeners = new ArrayList<>();
RegisteredListener[] listeners = BlockBreakEvent.getHandlerList().getRegisteredListeners();
for (RegisteredListener listener : listeners) {
if (listener.getPriority() == EventPriority.MONITOR) continue;
if (!listener.isIgnoringCancelled()) continue;
this.listeners.add(listener);
}
}
@Override
public boolean isExclusive() {
return true;
}
@Override
public FaweMask getMask(FawePlayer<Player> player, MaskType type) {
if (type != MaskType.MEMBER) return null;
ArrayList<RegisteredListener> currRegList = new ArrayList<>();
for (RegisteredListener listener : this.listeners) {
String name = listener.getPlugin().getName();
if (!player.hasPermission("fawe.freebuild." + name.toLowerCase())) continue;
currRegList.add(listener);
}
if (currRegList.isEmpty()) return null;
RegisteredListener[] listeners = currRegList.toArray(new RegisteredListener[currRegList.size()]);
World bukkitWorld = player.parent.getWorld();
AsyncWorld asyncWorld = AsyncWorld.wrap(bukkitWorld);
Vector vec1 = new Vector(0, 0, 0);
Vector vec2 = vec1;
Location pos1 = BukkitUtil.toLocation(bukkitWorld, vec1);
Location pos2 = BukkitUtil.toLocation(bukkitWorld, vec2);
AsyncBlock block = new AsyncBlock(asyncWorld, new NullFaweQueue(asyncWorld.getWorldName()), 0, 0, 0);
BlockBreakEvent event = new BlockBreakEvent(block, player.parent);
return new BukkitMask(pos1, pos2) {
@Override
public String getName() {
return "freebuild-global";
}
@Override
public boolean isValid(FawePlayer player, MaskType type) {
return bukkitWorld == ((FawePlayer<Player>)player).parent.getWorld() && type == MaskType.MEMBER;
}
@Override
public Region getRegion() {
return new CuboidRegion(vec1, vec2) {
@Override
public boolean contains(int x, int z) {
return contains(x, 127, z);
}
private int lastX = Integer.MIN_VALUE, lastZ = Integer.MIN_VALUE;
private boolean lastResult;
@Override
public boolean contains(int x, int y, int z) {
if (x == lastX && z == lastZ) return lastResult;
lastX = x;
lastZ = z;
event.setCancelled(false);
block.setPosition(x, y, z);
try {
synchronized (Bukkit.getPluginManager()) {
for (RegisteredListener listener : listeners) {
listener.callEvent(event);
}
}
} catch (EventException e) {
throw new RuntimeException(e);
}
return lastResult = !event.isCancelled();
}
};
}
};
}
}

View File

@ -21,9 +21,9 @@ import org.bukkit.plugin.Plugin;
public class AsyncBlock implements Block {
public final int z;
public final int y;
public final int x;
public int z;
public int y;
public int x;
public final FaweQueue queue;
public final AsyncWorld world;
@ -284,4 +284,10 @@ public class AsyncBlock implements Block {
public void removeMetadata(String metadataKey, Plugin owningPlugin) {
}
public void setPosition(int x, int y, int z) {
this.x = x;
this.y = y;
this.z = z;
}
}

View File

@ -91,9 +91,9 @@ public enum BBC {
COMMAND_HISTORY_CLEAR("History cleared", "WorldEdit.History"),
COMMAND_REDO_ERROR("Nothing left to redo. (See also `/inspect` and `/frb`)", "WorldEdit.History"),
COMMAND_HISTORY_OTHER_ERROR("Unable to find session for %s0.", "WorldEdit.History"),
COMMAND_REDO_SUCCESS("Redo successful.", "WorldEdit.History"),
COMMAND_REDO_SUCCESS("Redo successful%s0.", "WorldEdit.History"),
COMMAND_UNDO_ERROR("Nothing left to undo. (See also `/inspect` and `/frb`)", "WorldEdit.History"),
COMMAND_UNDO_SUCCESS("Undo successful.", "WorldEdit.History"),
COMMAND_UNDO_SUCCESS("Undo successful%s0.", "WorldEdit.History"),
OPERATION("Operation queued (%s0)", "WorldEdit.Operation"),

View File

@ -357,6 +357,13 @@ public class Settings extends Config {
" - "
})
public boolean MODERN_CRAFTSCRIPTS = false;
@Comment({
"[SAFE] Experimental freebuild region restrictions",
" - PERM: fawe.freebuild",
" - PERM: fawe.freebuild.<plugin>"
})
public boolean FREEBUILD = false;
}
public static class WEB {

View File

@ -56,4 +56,8 @@ public abstract class FaweMaskManager<T> {
private boolean hasMemberPermission(FawePlayer fp) {
return fp.hasPermission("fawe." + getKey() + ".member");
}
public boolean isExclusive() {
return false;
}
}

View File

@ -125,16 +125,19 @@ public class WEManager {
}
}
if (!removed) return regions.toArray(new Region[regions.size()]);
masks.clear();
}
}
Set<FaweMask> tmpMasks = new HashSet<>();
for (final FaweMaskManager manager : managers) {
if (player.hasPermission("fawe." + manager.getKey())) {
try {
if (manager.isExclusive() && !masks.isEmpty()) continue;
final FaweMask mask = manager.getMask(player, FaweMaskManager.MaskType.getDefaultMaskType());
if (mask != null) {
regions.add(mask.getRegion());
masks.add(mask);
if (manager.isExclusive()) break;
}
} catch (Throwable e) {
e.printStackTrace();

View File

@ -0,0 +1,35 @@
package com.boydti.fawe.util.terrain;
import java.util.Arrays;
import static com.boydti.fawe.util.MathMan.pairInt;
public final class Erosion {
private final int area;
private float[][] terrainHeight;
private float[][] waterHeight;
private long[] queue_2;
private long[] queue;
private int queueIndex;
public Erosion(int width, int length) {
this.area = width * length;
queue = new long[area];
Arrays.fill(queue, -1);
}
public void addWater(int x, int z, float amt) {
waterHeight[x][z] += amt;
queue[queueIndex++] = pairInt(x, z);
}
public void propogateWater() {
}
}

View File

@ -233,8 +233,9 @@ public class HistoryCommands extends MethodCommands {
public void undo(Player player, LocalSession session, CommandContext context) throws WorldEditException {
int times = Math.max(1, context.getInteger(0, 1));
FawePlayer.wrap(player).checkConfirmation(() -> {
for (int i = 0; i < times; ++i) {
EditSession undone;
EditSession undone = null;
int i = 0;
for (; i < times; ++i) {
if (context.argsLength() < 2) {
undone = session.undo(session.getBlockBag(player), player);
} else {
@ -245,14 +246,16 @@ public class HistoryCommands extends MethodCommands {
break;
}
undone = sess.undo(session.getBlockBag(player), player);
if (undone == null) break;
}
if (undone != null) {
BBC.COMMAND_UNDO_SUCCESS.send(player);
}
if (undone == null) i--;
if (i > 0) {
BBC.COMMAND_UNDO_SUCCESS.send(player, i == 1 ? "" : " x" + i);
worldEdit.flushBlockBag(player, undone);
} else {
BBC.COMMAND_UNDO_ERROR.send(player);
break;
}
if (undone == null) {
BBC.COMMAND_UNDO_ERROR.send(player);
}
}, getArguments(context), times, 50, context);
}
@ -269,8 +272,9 @@ public class HistoryCommands extends MethodCommands {
int times = Math.max(1, args.getInteger(0, 1));
for (int i = 0; i < times; ++i) {
EditSession redone;
EditSession redone = null;
int i = 0;
for (; i < times; ++i) {
if (args.argsLength() < 2) {
redone = session.redo(session.getBlockBag(player), player);
} else {
@ -281,13 +285,16 @@ public class HistoryCommands extends MethodCommands {
break;
}
redone = sess.redo(session.getBlockBag(player), player);
if (redone == null) break;
}
if (redone != null) {
BBC.COMMAND_REDO_SUCCESS.send(player);
}
if (redone == null) i--;
if (i > 0) {
BBC.COMMAND_REDO_SUCCESS.send(player, i == 1 ? "" : " x" + i);
worldEdit.flushBlockBag(player, redone);
} else {
BBC.COMMAND_REDO_ERROR.send(player);
}
if (redone == null) {
BBC.COMMAND_REDO_ERROR.send(player);
}
}