This commit is contained in:
Jesse Boyd 2017-04-18 22:56:38 +10:00
parent 093854f34e
commit b5e500e716
No known key found for this signature in database
GPG Key ID: 59F1DE6293AF6E1F
10 changed files with 205 additions and 254 deletions

View File

@ -390,6 +390,20 @@ public class FaweBukkit implements IFawe, Listener {
} }
return managers; return managers;
} }
//
// @EventHandler
// public void onWorldLoad(WorldLoadEvent event) {
// org.bukkit.World world = event.getWorld();
// world.setKeepSpawnInMemory(false);
// WorldServer nmsWorld = ((CraftWorld) world).getHandle();
// ChunkProviderServer provider = nmsWorld.getChunkProviderServer();
// try {
// Field fieldChunkLoader = provider.getClass().getDeclaredField("chunkLoader");
// ReflectionUtils.setFailsafeFieldValue(fieldChunkLoader, provider, new FaweChunkLoader());
// } catch (Throwable e) {
// e.printStackTrace();
// }
// }
@EventHandler @EventHandler
public void onChunkLoad(ChunkLoadEvent event) { public void onChunkLoad(ChunkLoadEvent event) {

View File

@ -353,7 +353,7 @@ public class BukkitChunk_1_10 extends CharFaweChunk<Chunk, BukkitQueue_1_10> {
toRemove = new HashMap<>(); toRemove = new HashMap<>();
} }
if (copy != null) { if (copy != null) {
storeTile(tile.getValue(), tile.getKey()); copy.storeTile(tile.getValue(), tile.getKey());
} }
toRemove.put(tile.getKey(), tile.getValue()); toRemove.put(tile.getKey(), tile.getValue());
} }

View File

@ -363,7 +363,7 @@ public class BukkitChunk_1_11 extends CharFaweChunk<Chunk, com.boydti.fawe.bukki
toRemove = new HashMap<>(); toRemove = new HashMap<>();
} }
if (copy != null) { if (copy != null) {
storeTile(tile.getValue(), tile.getKey()); copy.storeTile(tile.getValue(), tile.getKey());
} }
toRemove.put(tile.getKey(), tile.getValue()); toRemove.put(tile.getKey(), tile.getValue());
} }

View File

@ -17,6 +17,7 @@ import com.boydti.fawe.util.EditSessionBuilder;
import com.boydti.fawe.util.MainUtil; import com.boydti.fawe.util.MainUtil;
import com.boydti.fawe.util.MemUtil; import com.boydti.fawe.util.MemUtil;
import com.boydti.fawe.util.SetQueue; import com.boydti.fawe.util.SetQueue;
import com.boydti.fawe.util.StringMan;
import com.boydti.fawe.util.TaskManager; import com.boydti.fawe.util.TaskManager;
import com.boydti.fawe.util.WEManager; import com.boydti.fawe.util.WEManager;
import com.boydti.fawe.wrappers.WorldWrapper; import com.boydti.fawe.wrappers.WorldWrapper;
@ -211,9 +212,10 @@ public class FaweAPI {
} }
/** /**
* If you just need things to look random, use this faster alternative * Use ThreadLocalRandom instead
* @return PseudoRandom * @return
*/ */
@Deprecated
public static PseudoRandom getFastRandom() { public static PseudoRandom getFastRandom() {
return new PseudoRandom(); return new PseudoRandom();
} }

View File

@ -150,18 +150,6 @@ public class HeightMapMCAGenerator extends MCAWriter implements Extent {
return true; return true;
} }
private char get(char[][][] map, int x, int y, int z) {
char[][] yMap = map[y];
if (yMap == null) {
return 0;
}
char[] zMap = yMap[z & 15];
if (zMap == null) {
return 0;
}
return zMap[x & 15];
}
@Override @Override
public BaseBiome getBiome(Vector2D position) { public BaseBiome getBiome(Vector2D position) {
int index = position.getBlockZ() * getWidth() + position.getBlockX(); int index = position.getBlockZ() * getWidth() + position.getBlockX();
@ -247,62 +235,6 @@ public class HeightMapMCAGenerator extends MCAWriter implements Extent {
} }
} }
private void setOverlay(BufferedImage img, char combined, boolean white) {
if (img.getWidth() != getWidth() || img.getHeight() != getLength()) throw new IllegalArgumentException("Input image dimensions do not match the current height map!");
if (overlay == null) overlay = new char[getArea()];
int index = 0;
for (int z = 0; z < getLength(); z++) {
for (int x = 0; x < getWidth(); x++, index++){
int height = img.getRGB(x, z) & 0xFF;
if (height == 255 || height > 0 && white && PseudoRandom.random.nextInt(256) <= height) {
overlay[index] = combined;
}
}
}
}
private void setMain(BufferedImage img, char combined, boolean white) {
if (img.getWidth() != getWidth() || img.getHeight() != getLength()) throw new IllegalArgumentException("Input image dimensions do not match the current height map!");
modifiedMain = true;
int index = 0;
for (int z = 0; z < getLength(); z++) {
for (int x = 0; x < getWidth(); x++, index++){
int height = img.getRGB(x, z) & 0xFF;
if (height == 255 || height > 0 && white && PseudoRandom.random.nextInt(256) <= height) {
main[index] = combined;
}
}
}
}
private void setFloor(BufferedImage img, char combined, boolean white) {
if (img.getWidth() != getWidth() || img.getHeight() != getLength()) throw new IllegalArgumentException("Input image dimensions do not match the current height map!");
int index = 0;
for (int z = 0; z < getLength(); z++) {
for (int x = 0; x < getWidth(); x++, index++){
int height = img.getRGB(x, z) & 0xFF;
if (height == 255 || height > 0 && white && PseudoRandom.random.nextInt(256) <= height) {
floor[index] = combined;
}
}
}
}
private void setColumn(BufferedImage img, char combined, boolean white) {
if (img.getWidth() != getWidth() || img.getHeight() != getLength()) throw new IllegalArgumentException("Input image dimensions do not match the current height map!");
modifiedMain = true;
int index = 0;
for (int z = 0; z < getLength(); z++) {
for (int x = 0; x < getWidth(); x++, index++){
int height = img.getRGB(x, z) & 0xFF;
if (height == 255 || height > 0 && white && PseudoRandom.random.nextInt(256) <= height) {
main[index] = combined;
floor[index] = combined;
}
}
}
}
public void setBiome(Mask mask, byte biome) { public void setBiome(Mask mask, byte biome) {
int index = 0; int index = 0;
for (int z = 0; z < getLength(); z++) { for (int z = 0; z < getLength(); z++) {
@ -318,70 +250,6 @@ public class HeightMapMCAGenerator extends MCAWriter implements Extent {
} }
} }
private void setOverlay(Mask mask, char combined) {
int index = 0;
if (overlay == null) overlay = new char[getArea()];
for (int z = 0; z < getLength(); z++) {
mutable.mutZ(z);
for (int x = 0; x < getWidth(); x++, index++){
int y = heights[index] & 0xFF;
mutable.mutX(x);
mutable.mutY(y);
if (mask.test(mutable)) {
overlay[index] = combined;
}
}
}
}
private void setFloor(Mask mask, char combined) {
int index = 0;
for (int z = 0; z < getLength(); z++) {
mutable.mutZ(z);
for (int x = 0; x < getWidth(); x++, index++){
int y = heights[index] & 0xFF;
mutable.mutX(x);
mutable.mutY(y);
if (mask.test(mutable)) {
floor[index] = combined;
}
}
}
}
private void setMain(Mask mask, char combined) {
modifiedMain = true;
int index = 0;
for (int z = 0; z < getLength(); z++) {
mutable.mutZ(z);
for (int x = 0; x < getWidth(); x++, index++){
int y = heights[index] & 0xFF;
mutable.mutX(x);
mutable.mutY(y);
if (mask.test(mutable)) {
main[index] = combined;
}
}
}
}
private void setColumn(Mask mask, char combined) {
modifiedMain = true;
int index = 0;
for (int z = 0; z < getLength(); z++) {
mutable.mutZ(z);
for (int x = 0; x < getWidth(); x++, index++){
int y = heights[index] & 0xFF;
mutable.mutX(x);
mutable.mutY(y);
if (mask.test(mutable)) {
floor[index] = combined;
main[index] = combined;
}
}
}
}
public void setOverlay(BufferedImage img, Pattern pattern, boolean white) { public void setOverlay(BufferedImage img, Pattern pattern, boolean white) {
if (pattern instanceof BlockPattern) { if (pattern instanceof BlockPattern) {
setOverlay(img, (char) ((BlockPattern) pattern).getBlock().getCombined(), white); setOverlay(img, (char) ((BlockPattern) pattern).getBlock().getCombined(), white);
@ -552,25 +420,6 @@ public class HeightMapMCAGenerator extends MCAWriter implements Extent {
Arrays.fill(biomes, (byte) biome); Arrays.fill(biomes, (byte) biome);
} }
private void setFloor(int value) {
Arrays.fill(floor, (char) value);
}
private void setColumn(int value) {
setFloor(value);
setMain(value);
}
private void setMain(int value) {
modifiedMain = true;
Arrays.fill(main, (char) value);
}
private void setOverlay(int value) {
if (overlay == null) overlay = new char[getArea()];
Arrays.fill(overlay, (char) value);
}
public void setFloor(Pattern value) { public void setFloor(Pattern value) {
if (value instanceof BlockPattern) { if (value instanceof BlockPattern) {
setFloor(((BlockPattern) value).getBlock().getCombined()); setFloor(((BlockPattern) value).getBlock().getCombined());
@ -836,4 +685,155 @@ public class HeightMapMCAGenerator extends MCAWriter implements Extent {
} }
return chunk; return chunk;
} }
private char get(char[][][] map, int x, int y, int z) {
char[][] yMap = map[y];
if (yMap == null) {
return 0;
}
char[] zMap = yMap[z & 15];
if (zMap == null) {
return 0;
}
return zMap[x & 15];
}
private void setOverlay(Mask mask, char combined) {
int index = 0;
if (overlay == null) overlay = new char[getArea()];
for (int z = 0; z < getLength(); z++) {
mutable.mutZ(z);
for (int x = 0; x < getWidth(); x++, index++){
int y = heights[index] & 0xFF;
mutable.mutX(x);
mutable.mutY(y);
if (mask.test(mutable)) {
overlay[index] = combined;
}
}
}
}
private void setFloor(Mask mask, char combined) {
int index = 0;
for (int z = 0; z < getLength(); z++) {
mutable.mutZ(z);
for (int x = 0; x < getWidth(); x++, index++){
int y = heights[index] & 0xFF;
mutable.mutX(x);
mutable.mutY(y);
if (mask.test(mutable)) {
floor[index] = combined;
}
}
}
}
private void setMain(Mask mask, char combined) {
modifiedMain = true;
int index = 0;
for (int z = 0; z < getLength(); z++) {
mutable.mutZ(z);
for (int x = 0; x < getWidth(); x++, index++){
int y = heights[index] & 0xFF;
mutable.mutX(x);
mutable.mutY(y);
if (mask.test(mutable)) {
main[index] = combined;
}
}
}
}
private void setColumn(Mask mask, char combined) {
modifiedMain = true;
int index = 0;
for (int z = 0; z < getLength(); z++) {
mutable.mutZ(z);
for (int x = 0; x < getWidth(); x++, index++){
int y = heights[index] & 0xFF;
mutable.mutX(x);
mutable.mutY(y);
if (mask.test(mutable)) {
floor[index] = combined;
main[index] = combined;
}
}
}
}
private void setFloor(int value) {
Arrays.fill(floor, (char) value);
}
private void setColumn(int value) {
setFloor(value);
setMain(value);
}
private void setMain(int value) {
modifiedMain = true;
Arrays.fill(main, (char) value);
}
private void setOverlay(int value) {
if (overlay == null) overlay = new char[getArea()];
Arrays.fill(overlay, (char) value);
}
private void setOverlay(BufferedImage img, char combined, boolean white) {
if (img.getWidth() != getWidth() || img.getHeight() != getLength()) throw new IllegalArgumentException("Input image dimensions do not match the current height map!");
if (overlay == null) overlay = new char[getArea()];
int index = 0;
for (int z = 0; z < getLength(); z++) {
for (int x = 0; x < getWidth(); x++, index++){
int height = img.getRGB(x, z) & 0xFF;
if (height == 255 || height > 0 && white && PseudoRandom.random.nextInt(256) <= height) {
overlay[index] = combined;
}
}
}
}
private void setMain(BufferedImage img, char combined, boolean white) {
if (img.getWidth() != getWidth() || img.getHeight() != getLength()) throw new IllegalArgumentException("Input image dimensions do not match the current height map!");
modifiedMain = true;
int index = 0;
for (int z = 0; z < getLength(); z++) {
for (int x = 0; x < getWidth(); x++, index++){
int height = img.getRGB(x, z) & 0xFF;
if (height == 255 || height > 0 && white && PseudoRandom.random.nextInt(256) <= height) {
main[index] = combined;
}
}
}
}
private void setFloor(BufferedImage img, char combined, boolean white) {
if (img.getWidth() != getWidth() || img.getHeight() != getLength()) throw new IllegalArgumentException("Input image dimensions do not match the current height map!");
int index = 0;
for (int z = 0; z < getLength(); z++) {
for (int x = 0; x < getWidth(); x++, index++){
int height = img.getRGB(x, z) & 0xFF;
if (height == 255 || height > 0 && white && PseudoRandom.random.nextInt(256) <= height) {
floor[index] = combined;
}
}
}
}
private void setColumn(BufferedImage img, char combined, boolean white) {
if (img.getWidth() != getWidth() || img.getHeight() != getLength()) throw new IllegalArgumentException("Input image dimensions do not match the current height map!");
modifiedMain = true;
int index = 0;
for (int z = 0; z < getLength(); z++) {
for (int x = 0; x < getWidth(); x++, index++){
int height = img.getRGB(x, z) & 0xFF;
if (height == 255 || height > 0 && white && PseudoRandom.random.nextInt(256) <= height) {
main[index] = combined;
floor[index] = combined;
}
}
}
}
} }

View File

@ -2,14 +2,16 @@ package com.boydti.fawe.object;
import com.sk89q.jnbt.NBTInputStream; import com.sk89q.jnbt.NBTInputStream;
import com.sk89q.jnbt.NamedTag; import com.sk89q.jnbt.NamedTag;
import java.io.DataInputStream;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
public class FaweInputStream extends InputStream { public class FaweInputStream extends DataInputStream {
private final InputStream parent; private final InputStream parent;
public FaweInputStream(InputStream parent) { public FaweInputStream(InputStream parent) {
super(parent);
this.parent = parent; this.parent = parent;
} }
@ -17,49 +19,6 @@ public class FaweInputStream extends InputStream {
return parent; return parent;
} }
@Override
public int read() throws IOException {
return parent.read();
}
public long readLong() throws IOException {
return (long)
(read() << 64) +
(read() << 56) +
(read() << 48) +
(read() << 36) +
(read() << 24) +
(read() << 16) +
(read() << 8) +
(read());
}
public int readInt() throws IOException {
return (int)
(read() << 24) +
(read() << 16) +
(read() << 8) +
(read());
}
public short readShort() throws IOException {
return (short) (
(read() << 8) +
read());
}
public byte readByte() throws IOException {
return (byte) read();
}
public int readUnsignedByte() throws IOException {
return read();
}
public int readUnsignedShort() throws IOException {
return (int) readShort() & 0xFFFF;
}
public int readMedium() throws IOException { public int readMedium() throws IOException {
return (int) ( return (int) (
(read() << 16) + (read() << 16) +

View File

@ -2,14 +2,16 @@ package com.boydti.fawe.object;
import com.sk89q.jnbt.NBTOutputStream; import com.sk89q.jnbt.NBTOutputStream;
import com.sk89q.jnbt.Tag; import com.sk89q.jnbt.Tag;
import java.io.DataOutputStream;
import java.io.IOException; import java.io.IOException;
import java.io.OutputStream; import java.io.OutputStream;
public class FaweOutputStream extends OutputStream { public class FaweOutputStream extends DataOutputStream {
private final OutputStream parent; private final OutputStream parent;
public FaweOutputStream(OutputStream parent) { public FaweOutputStream(OutputStream parent) {
super(parent);
this.parent = parent; this.parent = parent;
} }
@ -17,35 +19,12 @@ public class FaweOutputStream extends OutputStream {
return parent; return parent;
} }
@Override
public void write(int b) throws IOException {
parent.write(b);
}
public void write(int b, int amount) throws IOException { public void write(int b, int amount) throws IOException {
for (int i = 0; i < amount; i++) { for (int i = 0; i < amount; i++) {
write(b); write(b);
} }
} }
public void writeLong(long l) throws IOException {
write((byte) (l >>> 64));
write((byte) (l >>> 56));
write((byte) (l >>> 48));
write((byte) (l >>> 36));
write((byte) (l >>> 24));
write((byte) (l >>> 16));
write((byte) (l >>> 8));
write((byte) (l));
}
public void writeInt(int i) throws IOException {
write((byte) (i >>> 24));
write((byte) (i >>> 16));
write((byte) (i >>> 8));
write((byte) (i));
}
public void writeShort(short s) throws IOException { public void writeShort(short s) throws IOException {
write((byte) (s >>> 8)); write((byte) (s >>> 8));
write((byte) (s)); write((byte) (s));

View File

@ -1,5 +1,6 @@
package com.boydti.fawe.object.brush; package com.boydti.fawe.object.brush;
import com.boydti.fawe.object.brush.visualization.VisualExtent;
import com.sk89q.worldedit.EditSession; import com.sk89q.worldedit.EditSession;
import com.sk89q.worldedit.MaxChangedBlocksException; import com.sk89q.worldedit.MaxChangedBlocksException;
import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.Vector;
@ -19,12 +20,13 @@ public class LineBrush implements Brush, ResettableTool {
@Override @Override
public void build(EditSession editSession, Vector position, final Pattern pattern, double size) throws MaxChangedBlocksException { public void build(EditSession editSession, Vector position, final Pattern pattern, double size) throws MaxChangedBlocksException {
boolean visual = (editSession.getExtent() instanceof VisualExtent);
if (pos1 == null) { if (pos1 == null) {
pos1 = position; if (!visual) pos1 = position;
return; return;
} }
editSession.drawLine(pattern, pos1, position, size, !shell, flat); editSession.drawLine(pattern, pos1, position, size, !shell, flat);
if (!select) { if (!select && !visual) {
pos1 = null; pos1 = null;
return; return;
} }

View File

@ -354,21 +354,16 @@ public class PlatformManager {
// At this time, only handle interaction from players // At this time, only handle interaction from players
if (actor instanceof Player) { if (actor instanceof Player) {
final Player player = new LocationMaskedPlayerWrapper(PlayerWrapper.wrap((Player) actor), ((Player) actor).getLocation());
final LocalSession session = worldEdit.getSessionManager().get(actor); final LocalSession session = worldEdit.getSessionManager().get(actor);
Player playerActor = (Player) actor;
if (event.getType() == Interaction.HIT) { if (event.getType() == Interaction.HIT) {
if (player.getItemInHand() == getConfiguration().wandItem) { if (session.isToolControlEnabled() && playerActor.getItemInHand() == getConfiguration().wandItem) {
if (!session.isToolControlEnabled()) { FawePlayer<?> fp = FawePlayer.wrap(playerActor);
if (!fp.hasPermission("worldedit.selection.pos")) {
return; return;
} }
final RegionSelector selector = session.getRegionSelector(playerActor.getWorld());
if (!actor.hasPermission("worldedit.selection.pos")) { final Player player = new LocationMaskedPlayerWrapper(PlayerWrapper.wrap((Player) actor), ((Player) actor).getLocation());
return;
}
final RegionSelector selector = session.getRegionSelector(player.getWorld());
FawePlayer<?> fp = FawePlayer.wrap(player);
fp.runAction(new Runnable() { fp.runAction(new Runnable() {
@Override @Override
public void run() { public void run() {
@ -381,10 +376,11 @@ public class PlatformManager {
event.setCancelled(true); event.setCancelled(true);
return; return;
} }
if (player.isHoldingPickAxe() && session.hasSuperPickAxe()) { if (session.hasSuperPickAxe() && playerActor.isHoldingPickAxe()) {
final BlockTool superPickaxe = session.getSuperPickaxe(); final BlockTool superPickaxe = session.getSuperPickaxe();
if (superPickaxe != null && superPickaxe.canUse(player)) { if (superPickaxe != null && superPickaxe.canUse(playerActor)) {
FawePlayer<?> fp = FawePlayer.wrap(player); FawePlayer<?> fp = FawePlayer.wrap(playerActor);
final Player player = new LocationMaskedPlayerWrapper(PlayerWrapper.wrap((Player) actor), ((Player) actor).getLocation());
fp.runAction(new Runnable() { fp.runAction(new Runnable() {
@Override @Override
public void run() { public void run() {
@ -395,10 +391,11 @@ public class PlatformManager {
return; return;
} }
} }
final Tool tool = session.getTool(player); final Tool tool = session.getTool(playerActor);
if (tool != null && tool instanceof DoubleActionBlockTool) { if (tool != null && tool instanceof DoubleActionBlockTool) {
if (tool.canUse(player)) { if (tool.canUse(playerActor)) {
FawePlayer<?> fp = FawePlayer.wrap(player); FawePlayer<?> fp = FawePlayer.wrap(playerActor);
final Player player = new LocationMaskedPlayerWrapper(PlayerWrapper.wrap((Player) actor), ((Player) actor).getLocation());
fp.runAction(new Runnable() { fp.runAction(new Runnable() {
@Override @Override
public void run() { public void run() {
@ -409,16 +406,13 @@ public class PlatformManager {
} }
} }
} else if (event.getType() == Interaction.OPEN) { } else if (event.getType() == Interaction.OPEN) {
if (player.getItemInHand() == getConfiguration().wandItem) { if (session.isToolControlEnabled() && playerActor.getItemInHand() == getConfiguration().wandItem) {
if (!session.isToolControlEnabled()) { FawePlayer<?> fp = FawePlayer.wrap(playerActor);
if (!fp.hasPermission("worldedit.selection.pos")) {
return; return;
} }
final RegionSelector selector = session.getRegionSelector(playerActor.getWorld());
if (!actor.hasPermission("worldedit.selection.pos")) { final Player player = new LocationMaskedPlayerWrapper(PlayerWrapper.wrap((Player) actor), ((Player) actor).getLocation());
return;
}
final RegionSelector selector = session.getRegionSelector(player.getWorld());
FawePlayer<?> fp = FawePlayer.wrap(player);
fp.runAction(new Runnable() { fp.runAction(new Runnable() {
@Override @Override
public void run() { public void run() {
@ -432,10 +426,11 @@ public class PlatformManager {
return; return;
} }
final Tool tool = session.getTool(player); final Tool tool = session.getTool(playerActor);
if (tool != null && tool instanceof BlockTool) { if (tool != null && tool instanceof BlockTool) {
if (tool.canUse(player)) { if (tool.canUse(playerActor)) {
FawePlayer<?> fp = FawePlayer.wrap(player); FawePlayer<?> fp = FawePlayer.wrap(playerActor);
final Player player = new LocationMaskedPlayerWrapper(PlayerWrapper.wrap((Player) actor), ((Player) actor).getLocation());
fp.runAction(new Runnable() { fp.runAction(new Runnable() {
@Override @Override
public void run() { public void run() {