Fix free build restrictions

Dieser Commit ist enthalten in:
Jesse Boyd 2018-09-05 07:09:24 +10:00
Ursprung dfb1195242
Commit 594d72d2fe
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: 59F1DE6293AF6E1F
2 geänderte Dateien mit 43 neuen und 22 gelöschten Zeilen

Datei anzeigen

@ -10,18 +10,17 @@ import com.sk89q.worldedit.Vector;
import com.sk89q.worldedit.bukkit.BukkitAdapter; import com.sk89q.worldedit.bukkit.BukkitAdapter;
import com.sk89q.worldedit.regions.CuboidRegion; import com.sk89q.worldedit.regions.CuboidRegion;
import com.sk89q.worldedit.regions.Region; import com.sk89q.worldedit.regions.Region;
import com.sk89q.worldedit.world.block.BlockTypes;
import org.bukkit.Bukkit;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.World; import org.bukkit.World;
import org.bukkit.block.Block; import org.bukkit.block.Block;
import org.bukkit.block.BlockState;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.Cancellable;
import org.bukkit.event.EventException; import org.bukkit.event.EventException;
import org.bukkit.event.EventPriority; import org.bukkit.event.EventPriority;
import org.bukkit.event.block.BlockBreakEvent; import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.event.block.BlockPlaceEvent; import org.bukkit.event.block.BlockPlaceEvent;
import org.bukkit.inventory.EquipmentSlot;
import org.bukkit.inventory.ItemStack;
import org.bukkit.plugin.RegisteredListener; import org.bukkit.plugin.RegisteredListener;
import java.util.ArrayList; import java.util.ArrayList;
@ -32,7 +31,7 @@ public class FreeBuildRegion extends BukkitMaskManager {
public FreeBuildRegion() { public FreeBuildRegion() {
super("freebuild"); super("freebuild");
this.listeners = new ArrayList<>(); this.listeners = new ArrayList<>();
RegisteredListener[] listeners = BlockPlaceEvent.getHandlerList().getRegisteredListeners(); RegisteredListener[] listeners = BlockBreakEvent.getHandlerList().getRegisteredListeners();
for (RegisteredListener listener : listeners) { for (RegisteredListener listener : listeners) {
if (listener.getPriority() == EventPriority.MONITOR) continue; if (listener.getPriority() == EventPriority.MONITOR) continue;
if (!listener.isIgnoringCancelled()) continue; if (!listener.isIgnoringCancelled()) continue;
@ -57,42 +56,51 @@ public class FreeBuildRegion extends BukkitMaskManager {
if (currRegList.isEmpty()) return null; if (currRegList.isEmpty()) return null;
RegisteredListener[] listeners = currRegList.toArray(new RegisteredListener[currRegList.size()]); RegisteredListener[] listeners = currRegList.toArray(new RegisteredListener[currRegList.size()]);
World world = player.parent.getWorld(); World bukkitWorld = player.parent.getWorld();
AsyncWorld asyncWorld = AsyncWorld.wrap(world); AsyncWorld asyncWorld = AsyncWorld.wrap(bukkitWorld);
Vector vec1 = asyncWorld.getMinimumPoint(); Vector vec1 = new Vector(0, 0, 0);
Vector vec2 = asyncWorld.getMaximumPoint(); Vector vec2 = vec1;
Location pos1 = BukkitAdapter.adapt(world, vec1); Location pos1 = BukkitAdapter.adapt(bukkitWorld, vec1);
Location pos2 = BukkitAdapter.adapt(world, vec2); Location pos2 = BukkitAdapter.adapt(bukkitWorld, vec2);
AsyncBlock block = new AsyncBlock(asyncWorld, new NullFaweQueue(asyncWorld.getWorldName()), 0, 0, 0); AsyncBlock block = new AsyncBlock(asyncWorld, new NullFaweQueue(asyncWorld.getWorldName(), BlockTypes.STONE.getDefaultState()), 0, 0, 0);
BlockBreakEvent event = new BlockBreakEvent(block, player.parent); BlockBreakEvent event = new BlockBreakEvent(block, player.parent);
return new BukkitMask(pos1, pos2) { 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 @Override
public Region getRegion() { public Region getRegion() {
return new CuboidRegion(vec1, vec2) { return new CuboidRegion(vec1, vec2) {
@Override @Override
public boolean contains(int x, int y, int z) { public boolean contains(int x, int z) {
return contains(x, z); return contains(x, 77, z);
} }
private int lastX = Integer.MIN_VALUE, lastZ = Integer.MIN_VALUE; private int lastX = Integer.MIN_VALUE, lastZ = Integer.MIN_VALUE;
private boolean lastResult; private boolean lastResult;
@Override @Override
public boolean contains(int x, int z) { public boolean contains(int x, int y, int z) {
if (x == lastX && z == lastZ) return lastResult; if (x == lastX && z == lastZ) return lastResult;
lastX = x; lastX = x;
lastZ = z; lastZ = z;
int y = 128;
event.setCancelled(false); event.setCancelled(false);
block.setPosition(x, y, z); block.setPosition(x, y, z);
try { try {
for (RegisteredListener listener : listeners) { synchronized (Bukkit.getPluginManager()) {
listener.callEvent(event); for (RegisteredListener listener : listeners) {
if (event.isCancelled()) break; listener.callEvent(event);
}
} }
} catch (EventException e) { } catch (EventException e) {
throw new RuntimeException(e); throw new RuntimeException(e);

Datei anzeigen

@ -7,8 +7,10 @@ import com.boydti.fawe.object.RunnableVal2;
import com.boydti.fawe.object.exception.FaweException; import com.boydti.fawe.object.exception.FaweException;
import com.boydti.fawe.util.SetQueue; import com.boydti.fawe.util.SetQueue;
import com.sk89q.jnbt.CompoundTag; import com.sk89q.jnbt.CompoundTag;
import com.sk89q.worldedit.Vector;
import com.sk89q.worldedit.world.World; import com.sk89q.worldedit.world.World;
import com.sk89q.worldedit.world.biome.BaseBiome; import com.sk89q.worldedit.world.biome.BaseBiome;
import com.sk89q.worldedit.world.block.BlockState;
import com.sk89q.worldedit.world.block.BlockTypes; import com.sk89q.worldedit.world.block.BlockTypes;
import java.io.File; import java.io.File;
@ -19,9 +21,15 @@ import javax.annotation.Nullable;
public class NullFaweQueue implements FaweQueue { public class NullFaweQueue implements FaweQueue {
private final String worldName; private final String worldName;
private final BlockState state;
public NullFaweQueue(String worldName) { public NullFaweQueue(String worldName) {
this(worldName, BlockTypes.AIR.getDefaultState());
}
public NullFaweQueue(String worldName, BlockState state) {
this.worldName = worldName; this.worldName = worldName;
this.state = state;
} }
@Override @Override
@ -179,14 +187,19 @@ public class NullFaweQueue implements FaweQueue {
return 0; return 0;
} }
@Override
public BlockState getBlock(Vector position) {
return state;
}
@Override @Override
public int getCombinedId4Data(int x, int y, int z) throws FaweException.FaweChunkLoadException { public int getCombinedId4Data(int x, int y, int z) throws FaweException.FaweChunkLoadException {
return BlockTypes.AIR.getInternalId(); return state.getInternalId();
} }
@Override @Override
public int getCachedCombinedId4Data(int x, int y, int z) throws FaweException.FaweChunkLoadException { public int getCachedCombinedId4Data(int x, int y, int z) throws FaweException.FaweChunkLoadException {
return BlockTypes.AIR.getInternalId(); return state.getInternalId();
} }
@Override @Override