Done 👌

This commit is contained in:
NotMyFault 2019-04-19 19:01:17 +02:00
parent c56ba112d1
commit e27b6fb6c3
3 changed files with 71 additions and 106 deletions

View File

@ -7,8 +7,7 @@ import org.bukkit.World;
/** /**
* @author MikeMatrix * @author MikeMatrix
*/ */
public class BlockWrapper public class BlockWrapper {
{
private int id; private int id;
private Material type; private Material type;
@ -22,8 +21,7 @@ public class BlockWrapper
* @param block * @param block
*/ */
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
public BlockWrapper(final AsyncBlock block) public BlockWrapper(final AsyncBlock block) {
{
this.setId(block.getTypeId()); this.setId(block.getTypeId());
this.setX(block.getX()); this.setX(block.getX());
this.setY(block.getY()); this.setY(block.getY());
@ -35,111 +33,93 @@ public class BlockWrapper
/** /**
* @return the data * @return the data
*/ */
public final int getPropertyId() public final int getPropertyId() {
{
return this.data; return this.data;
} }
/**
* @param data the data to set
*/
public final void setPropertyId(final int data) {
this.data = data;
}
public Material getType() { public Material getType() {
return type; return type;
} }
public void setType(Material type) {
this.type = type;
}
/** /**
* @return the id * @return the id
*/ */
public final int getId() public final int getId() {
{
return this.id; return this.id;
} }
/**
* @param id the id to set
*/
public final void setId(final int id) {
this.id = id;
}
/** /**
* @return the world * @return the world
*/ */
public final World getWorld() public final World getWorld() {
{
return this.world; return this.world;
} }
/**
* @param world the world to set
*/
public final void setWorld(final World world) {
this.world = world;
}
/** /**
* @return the x * @return the x
*/ */
public final int getX() public final int getX() {
{
return this.x; return this.x;
} }
/**
* @param x the x to set
*/
public final void setX(final int x) {
this.x = x;
}
/** /**
* @return the y * @return the y
*/ */
public final int getY() public final int getY() {
{
return this.y; return this.y;
} }
/**
* @param y the y to set
*/
public final void setY(final int y) {
this.y = y;
}
/** /**
* @return the z * @return the z
*/ */
public final int getZ() public final int getZ() {
{
return this.z; return this.z;
} }
/** /**
* @param data * @param z the z to set
* the data to set
*/ */
public final void setPropertyId(final int data) public final void setZ(final int z) {
{
this.data = data;
}
/**
* @param id
* the id to set
*/
public final void setId(final int id)
{
this.id = id;
}
/**
* @param world
* the world to set
*/
public final void setWorld(final World world)
{
this.world = world;
}
/**
* @param x
* the x to set
*/
public final void setX(final int x)
{
this.x = x;
}
/**
* @param y
* the y to set
*/
public final void setY(final int y)
{
this.y = y;
}
/**
* @param z
* the z to set
*/
public final void setZ(final int z)
{
this.z = z; this.z = z;
} }
public void setType(Material type) {
this.type = type;
}
} }

View File

@ -1,4 +1,3 @@
package com.thevoxelbox.voxelsniper.util; package com.thevoxelbox.voxelsniper.util;
import com.thevoxelbox.voxelsniper.Undo; import com.thevoxelbox.voxelsniper.Undo;
@ -10,26 +9,23 @@ import org.bukkit.block.data.BlockData;
/** /**
* *
*/ */
public class UndoDelegate implements BlockChangeDelegate public class UndoDelegate implements BlockChangeDelegate {
{
private final World targetWorld; private final World targetWorld;
private Undo currentUndo; private Undo currentUndo;
public Undo getUndo() public UndoDelegate(World targetWorld) {
{ this.targetWorld = targetWorld;
this.currentUndo = new Undo();
}
public Undo getUndo() {
final Undo pastUndo = currentUndo; final Undo pastUndo = currentUndo;
currentUndo = new Undo(); currentUndo = new Undo();
return pastUndo; return pastUndo;
} }
public UndoDelegate(World targetWorld)
{
this.targetWorld = targetWorld;
this.currentUndo = new Undo();
}
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
public boolean setBlock(Block b) public boolean setBlock(Block b) {
{
this.currentUndo.put(this.targetWorld.getBlockAt(b.getLocation())); this.currentUndo.put(this.targetWorld.getBlockAt(b.getLocation()));
this.targetWorld.getBlockAt(b.getLocation()).setBlockData(b.getBlockData()); this.targetWorld.getBlockAt(b.getLocation()).setBlockData(b.getBlockData());
return true; return true;
@ -48,14 +44,12 @@ public class UndoDelegate implements BlockChangeDelegate
} }
@Override @Override
public int getHeight() public int getHeight() {
{
return this.targetWorld.getMaxHeight(); return this.targetWorld.getMaxHeight();
} }
@Override @Override
public boolean isEmpty(int x, int y, int z) public boolean isEmpty(int x, int y, int z) {
{
return this.targetWorld.getBlockAt(x, y, z).isEmpty(); return this.targetWorld.getBlockAt(x, y, z).isEmpty();
} }
} }

View File

@ -16,39 +16,34 @@ import java.util.List;
/** /**
* Container class for multiple ID/Datavalue pairs. * Container class for multiple ID/Datavalue pairs.
*/ */
public class VoxelList public class VoxelList {
{
private BlockMask mask = new BlockMask(); private BlockMask mask = new BlockMask();
/** /**
* Adds the specified id, data value pair to the VoxelList. A data value of -1 will operate on all data values of that id. * Adds the specified id, data value pair to the VoxelList. A data value of -1 will operate on all data values of that id.
* *
* @param i * @param i
*/ */
public void add(BlockState i) public void add(BlockState i) {
{
this.mask = mask.toBuilder().add(i).build(NullExtent.INSTANCE); this.mask = mask.toBuilder().add(i).build(NullExtent.INSTANCE);
} }
public void add(BlockMask mask) public void add(BlockMask mask) {
{
this.mask = (BlockMask) mask.and(mask); this.mask = (BlockMask) mask.and(mask);
} }
/** /**
* Removes the specified id, data value pair from the VoxelList. * Removes the specified id, data value pair from the VoxelList.
* *
* @return true if this list contained the specified element * @return true if this list contained the specified element
*/ */
public boolean removeValue(final BlockState state) public boolean removeValue(final BlockState state) {
{
this.mask = mask.toBuilder().remove(state).build(NullExtent.INSTANCE); this.mask = mask.toBuilder().remove(state).build(NullExtent.INSTANCE);
return true; return true;
} }
public boolean removeValue(final BlockMask state) public boolean removeValue(final BlockMask state) {
{
this.mask = (BlockMask) mask.and(state.inverse()); this.mask = (BlockMask) mask.and(state.inverse());
return true; return true;
} }
@ -57,16 +52,14 @@ public class VoxelList
* @param i * @param i
* @return true if this list contains the specified element * @return true if this list contains the specified element
*/ */
public boolean contains(final BlockData i) public boolean contains(final BlockData i) {
{
return mask.test(BukkitAdapter.adapt(i)); return mask.test(BukkitAdapter.adapt(i));
} }
/** /**
* Clears the VoxelList. * Clears the VoxelList.
*/ */
public void clear() public void clear() {
{
mask = mask.toBuilder().clear().build(NullExtent.INSTANCE); mask = mask.toBuilder().clear().build(NullExtent.INSTANCE);
} }
@ -75,8 +68,7 @@ public class VoxelList
* *
* @return true if this list contains no elements * @return true if this list contains no elements
*/ */
public boolean isEmpty() public boolean isEmpty() {
{
return mask.toBuilder().isEmpty(); return mask.toBuilder().isEmpty();
} }
@ -85,8 +77,7 @@ public class VoxelList
* *
* @return defensive copy of the List with pairs * @return defensive copy of the List with pairs
*/ */
public String toString() public String toString() {
{
return mask.toString(); return mask.toString();
} }