Generic cleanup, made LiftRope support more block types (including trapdoors), closes #69
This commit is contained in:
parent
8fe6e6766a
commit
46c40bd2cc
9 changed files with 123 additions and 554 deletions
|
@ -17,7 +17,7 @@ import tech.sbdevelopment.v10lift.managers.DataManager;
|
||||||
import tech.sbdevelopment.v10lift.managers.ForbiddenBlockManager;
|
import tech.sbdevelopment.v10lift.managers.ForbiddenBlockManager;
|
||||||
import tech.sbdevelopment.v10lift.sbutils.LocationSerializer;
|
import tech.sbdevelopment.v10lift.sbutils.LocationSerializer;
|
||||||
import tech.sbdevelopment.v10lift.utils.ConfigUtil;
|
import tech.sbdevelopment.v10lift.utils.ConfigUtil;
|
||||||
import tech.sbdevelopment.v10lift.utils.DirectionUtil;
|
import tech.sbdevelopment.v10lift.utils.BlockStateUtil;
|
||||||
import tech.sbdevelopment.v10lift.utils.DoorUtil;
|
import tech.sbdevelopment.v10lift.utils.DoorUtil;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
|
@ -180,35 +180,7 @@ public class V10LiftAPI {
|
||||||
* @return 0 if added, -1 if null or doesn't exists, -2 if forbidden, -3 if already added
|
* @return 0 if added, -1 if null or doesn't exists, -2 if forbidden, -3 if already added
|
||||||
*/
|
*/
|
||||||
public int addBlockToLift(Set<LiftBlock> blocks, @Nonnull Block block) {
|
public int addBlockToLift(Set<LiftBlock> blocks, @Nonnull Block block) {
|
||||||
Material type = block.getType();
|
return addBlockToLift(blocks, new LiftBlock(block));
|
||||||
LiftBlock lb;
|
|
||||||
if (XMaterial.supports(13)) {
|
|
||||||
if (type.toString().contains("SIGN")) {
|
|
||||||
Bukkit.getLogger().info("Block instanceof Dir 1.13 & is sign");
|
|
||||||
lb = new LiftBlock(block.getWorld().getName(), block.getX(), block.getY(), block.getZ(), type, DirectionUtil.getDirection(block), ((Sign) block.getState()).getLines());
|
|
||||||
} else if (block.getBlockData() instanceof org.bukkit.block.data.Directional && block.getBlockData() instanceof org.bukkit.block.data.Bisected) {
|
|
||||||
Bukkit.getLogger().info("Block instanceof Dir 1.13 & bisected");
|
|
||||||
lb = new LiftBlock(block.getWorld().getName(), block.getX(), block.getY(), block.getZ(), type, DirectionUtil.getDirection(block), DirectionUtil.getBisected(block));
|
|
||||||
} else if (block.getBlockData() instanceof org.bukkit.block.data.Directional) {
|
|
||||||
Bukkit.getLogger().info("Block instanceof Dir 1.13");
|
|
||||||
lb = new LiftBlock(block.getWorld().getName(), block.getX(), block.getY(), block.getZ(), type, DirectionUtil.getDirection(block));
|
|
||||||
} else if (block.getBlockData() instanceof org.bukkit.block.data.type.Slab) {
|
|
||||||
Bukkit.getLogger().info("Block instanceof Slab 1.13");
|
|
||||||
lb = new LiftBlock(block.getWorld().getName(), block.getX(), block.getY(), block.getZ(), type, DirectionUtil.getSlabType(block));
|
|
||||||
} else {
|
|
||||||
Bukkit.getLogger().info("Block not instanceof Dir 1.13");
|
|
||||||
lb = new LiftBlock(block.getWorld().getName(), block.getX(), block.getY(), block.getZ(), type);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if (type.toString().contains("SIGN")) {
|
|
||||||
Bukkit.getLogger().info("Block instanceof Dir 1.12 & is sign");
|
|
||||||
lb = new LiftBlock(block.getWorld().getName(), block.getX(), block.getY(), block.getZ(), type, block.getState().getRawData(), ((Sign) block.getState()).getLines());
|
|
||||||
} else {
|
|
||||||
Bukkit.getLogger().info("Block no sign 1.12");
|
|
||||||
lb = new LiftBlock(block.getWorld().getName(), block.getX(), block.getY(), block.getZ(), type, block.getState().getRawData());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return addBlockToLift(blocks, lb);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -237,34 +209,7 @@ public class V10LiftAPI {
|
||||||
public int removeBlockFromLift(String liftName, Block block) {
|
public int removeBlockFromLift(String liftName, Block block) {
|
||||||
if (liftName == null || block == null || !DataManager.containsLift(liftName)) return -1;
|
if (liftName == null || block == null || !DataManager.containsLift(liftName)) return -1;
|
||||||
Lift lift = DataManager.getLift(liftName);
|
Lift lift = DataManager.getLift(liftName);
|
||||||
Material type = block.getType();
|
LiftBlock lb = new LiftBlock(block);
|
||||||
LiftBlock lb;
|
|
||||||
if (XMaterial.supports(13)) {
|
|
||||||
if (type.toString().contains("SIGN")) {
|
|
||||||
Bukkit.getLogger().info("Block instanceof Dir 1.13 & is sign");
|
|
||||||
lb = new LiftBlock(block.getWorld().getName(), block.getX(), block.getY(), block.getZ(), type, DirectionUtil.getDirection(block), ((Sign) block.getState()).getLines());
|
|
||||||
} else if (block.getBlockData() instanceof org.bukkit.block.data.Directional && block.getBlockData() instanceof org.bukkit.block.data.Bisected) {
|
|
||||||
Bukkit.getLogger().info("Block instanceof Dir 1.13 & bisected");
|
|
||||||
lb = new LiftBlock(block.getWorld().getName(), block.getX(), block.getY(), block.getZ(), type, DirectionUtil.getDirection(block), DirectionUtil.getBisected(block));
|
|
||||||
} else if (block.getBlockData() instanceof org.bukkit.block.data.Directional) {
|
|
||||||
Bukkit.getLogger().info("Block instanceof Dir 1.13");
|
|
||||||
lb = new LiftBlock(block.getWorld().getName(), block.getX(), block.getY(), block.getZ(), type, DirectionUtil.getDirection(block));
|
|
||||||
} else if (block.getBlockData() instanceof org.bukkit.block.data.type.Slab) {
|
|
||||||
Bukkit.getLogger().info("Block instanceof Slab 1.13");
|
|
||||||
lb = new LiftBlock(block.getWorld().getName(), block.getX(), block.getY(), block.getZ(), type, DirectionUtil.getSlabType(block));
|
|
||||||
} else {
|
|
||||||
Bukkit.getLogger().info("Block not instanceof Dir 1.13");
|
|
||||||
lb = new LiftBlock(block.getWorld().getName(), block.getX(), block.getY(), block.getZ(), type);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if (type.toString().contains("SIGN")) {
|
|
||||||
Bukkit.getLogger().info("Block instanceof Dir 1.12 & is sign");
|
|
||||||
lb = new LiftBlock(block.getWorld().getName(), block.getX(), block.getY(), block.getZ(), type, block.getState().getRawData(), ((Sign) block.getState()).getLines());
|
|
||||||
} else {
|
|
||||||
Bukkit.getLogger().info("Block no sign 1.12");
|
|
||||||
lb = new LiftBlock(block.getWorld().getName(), block.getX(), block.getY(), block.getZ(), type, block.getState().getRawData());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (!lift.getBlocks().contains(lb)) return -2;
|
if (!lift.getBlocks().contains(lb)) return -2;
|
||||||
lift.getBlocks().remove(lb);
|
lift.getBlocks().remove(lb);
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -293,35 +238,8 @@ public class V10LiftAPI {
|
||||||
*/
|
*/
|
||||||
public int switchBlockAtLift(TreeSet<LiftBlock> blocks, Block block) {
|
public int switchBlockAtLift(TreeSet<LiftBlock> blocks, Block block) {
|
||||||
if (blocks == null || block == null) return -1;
|
if (blocks == null || block == null) return -1;
|
||||||
Material type = block.getType();
|
if (ForbiddenBlockManager.isForbidden(block.getType())) return -2;
|
||||||
if (ForbiddenBlockManager.isForbidden(type)) return -2;
|
LiftBlock lb = new LiftBlock(block);
|
||||||
LiftBlock lb;
|
|
||||||
if (XMaterial.supports(13)) {
|
|
||||||
if (type.toString().contains("SIGN")) {
|
|
||||||
Bukkit.getLogger().info("Block instanceof Dir 1.13 & is sign");
|
|
||||||
lb = new LiftBlock(block.getWorld().getName(), block.getX(), block.getY(), block.getZ(), type, DirectionUtil.getDirection(block), ((Sign) block.getState()).getLines());
|
|
||||||
} else if (block.getBlockData() instanceof org.bukkit.block.data.Directional && block.getBlockData() instanceof org.bukkit.block.data.Bisected) {
|
|
||||||
Bukkit.getLogger().info("Block instanceof Dir 1.13 & bisected");
|
|
||||||
lb = new LiftBlock(block.getWorld().getName(), block.getX(), block.getY(), block.getZ(), type, DirectionUtil.getDirection(block), DirectionUtil.getBisected(block));
|
|
||||||
} else if (block.getBlockData() instanceof org.bukkit.block.data.Directional) {
|
|
||||||
Bukkit.getLogger().info("Block instanceof Dir 1.13");
|
|
||||||
lb = new LiftBlock(block.getWorld().getName(), block.getX(), block.getY(), block.getZ(), type, DirectionUtil.getDirection(block));
|
|
||||||
} else if (block.getBlockData() instanceof org.bukkit.block.data.type.Slab) {
|
|
||||||
Bukkit.getLogger().info("Block instanceof Slab 1.13");
|
|
||||||
lb = new LiftBlock(block.getWorld().getName(), block.getX(), block.getY(), block.getZ(), type, DirectionUtil.getSlabType(block));
|
|
||||||
} else {
|
|
||||||
Bukkit.getLogger().info("Block not instanceof Dir 1.13");
|
|
||||||
lb = new LiftBlock(block.getWorld().getName(), block.getX(), block.getY(), block.getZ(), type);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if (type.toString().contains("SIGN")) {
|
|
||||||
Bukkit.getLogger().info("Block instanceof Dir 1.12 & is sign");
|
|
||||||
lb = new LiftBlock(block.getWorld().getName(), block.getX(), block.getY(), block.getZ(), type, block.getState().getRawData(), ((Sign) block.getState()).getLines());
|
|
||||||
} else {
|
|
||||||
Bukkit.getLogger().info("Block no sign 1.12");
|
|
||||||
lb = new LiftBlock(block.getWorld().getName(), block.getX(), block.getY(), block.getZ(), type, block.getState().getRawData());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (blocks.contains(lb)) {
|
if (blocks.contains(lb)) {
|
||||||
blocks.remove(lb);
|
blocks.remove(lb);
|
||||||
return 1;
|
return 1;
|
||||||
|
@ -469,9 +387,6 @@ public class V10LiftAPI {
|
||||||
Block block = Objects.requireNonNull(Bukkit.getWorld(lb.getWorld()), "World is null at closeDoor").getBlockAt(lb.getX(), lb.getY(), lb.getZ());
|
Block block = Objects.requireNonNull(Bukkit.getWorld(lb.getWorld()), "World is null at closeDoor").getBlockAt(lb.getX(), lb.getY(), lb.getZ());
|
||||||
BlockState state = block.getState();
|
BlockState state = block.getState();
|
||||||
state.setType(lb.getMat());
|
state.setType(lb.getMat());
|
||||||
if (!XMaterial.supports(13)) {
|
|
||||||
state.setRawData(lb.getData());
|
|
||||||
}
|
|
||||||
state.update(true);
|
state.update(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -900,16 +815,7 @@ public class V10LiftAPI {
|
||||||
if (block.getType() != mat) return -2;
|
if (block.getType() != mat) return -2;
|
||||||
}
|
}
|
||||||
|
|
||||||
BlockFace face;
|
LiftRope rope = new LiftRope(block, minY, maxY);
|
||||||
if (XMaterial.supports(13)) {
|
|
||||||
face = DirectionUtil.getDirection(block);
|
|
||||||
} else {
|
|
||||||
BlockState state = block.getState();
|
|
||||||
org.bukkit.material.Ladder ladder = (org.bukkit.material.Ladder) state.getData();
|
|
||||||
face = ladder.getAttachedFace();
|
|
||||||
}
|
|
||||||
|
|
||||||
LiftRope rope = new LiftRope(mat, face, world.getName(), x, minY, maxY, z);
|
|
||||||
DataManager.getLift(lift).getRopes().add(rope);
|
DataManager.getLift(lift).getRopes().add(rope);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
|
@ -28,7 +28,6 @@ public class Lift {
|
||||||
@Setter
|
@Setter
|
||||||
private LinkedHashMap<String, Floor> queue = null;
|
private LinkedHashMap<String, Floor> queue = null;
|
||||||
private final HashSet<LiftRope> ropes = new HashSet<>();
|
private final HashSet<LiftRope> ropes = new HashSet<>();
|
||||||
private transient final ArrayList<V10Entity> toMove = new ArrayList<>();
|
|
||||||
@Setter
|
@Setter
|
||||||
private int speed;
|
private int speed;
|
||||||
@Setter
|
@Setter
|
||||||
|
|
|
@ -5,6 +5,7 @@ import lombok.NoArgsConstructor;
|
||||||
import lombok.Setter;
|
import lombok.Setter;
|
||||||
import lombok.ToString;
|
import lombok.ToString;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.block.Block;
|
||||||
import org.bukkit.block.BlockFace;
|
import org.bukkit.block.BlockFace;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
|
@ -26,11 +27,16 @@ public class LiftBlock implements Comparable<LiftBlock> {
|
||||||
//Only used for cabine blocks, because those need caching!
|
//Only used for cabine blocks, because those need caching!
|
||||||
@Setter
|
@Setter
|
||||||
private Material mat;
|
private Material mat;
|
||||||
private byte data;
|
@Setter
|
||||||
private BlockFace face;
|
private BlockFace face;
|
||||||
|
@Setter
|
||||||
private String bisected;
|
private String bisected;
|
||||||
private String slabtype;
|
@Setter
|
||||||
|
private String slabType;
|
||||||
|
@Setter
|
||||||
private String[] signLines;
|
private String[] signLines;
|
||||||
|
@Setter
|
||||||
|
private Boolean open;
|
||||||
|
|
||||||
//Only used for inputs!
|
//Only used for inputs!
|
||||||
private String floor;
|
private String floor;
|
||||||
|
@ -41,7 +47,7 @@ public class LiftBlock implements Comparable<LiftBlock> {
|
||||||
public Map<String, Object>[] serializedItemStacks = null;
|
public Map<String, Object>[] serializedItemStacks = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A floor based liftblock, without material (no caching)
|
* Create a floor based liftblock, without material (no caching)
|
||||||
*
|
*
|
||||||
* @param world The world
|
* @param world The world
|
||||||
* @param x The x-pos
|
* @param x The x-pos
|
||||||
|
@ -55,182 +61,40 @@ public class LiftBlock implements Comparable<LiftBlock> {
|
||||||
this.y = y;
|
this.y = y;
|
||||||
this.z = z;
|
this.z = z;
|
||||||
this.mat = null;
|
this.mat = null;
|
||||||
this.data = 0;
|
|
||||||
this.face = null;
|
this.face = null;
|
||||||
this.signLines = null;
|
this.signLines = null;
|
||||||
this.floor = floor;
|
this.floor = floor;
|
||||||
this.bisected = null;
|
this.bisected = null;
|
||||||
this.slabtype = null;
|
this.slabType = null;
|
||||||
|
this.open = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 1.12 liftblock, with material and data [NO SIGN]
|
* Create a new liftblock from a block
|
||||||
*
|
*
|
||||||
* @param world The world
|
* @param block The block
|
||||||
* @param x The x-pos
|
|
||||||
* @param y The y-pos
|
|
||||||
* @param z The z-pos
|
|
||||||
* @param mat The Material of the block
|
|
||||||
* @param data The data of the block
|
|
||||||
*/
|
*/
|
||||||
public LiftBlock(String world, int x, int y, int z, Material mat, byte data) {
|
public LiftBlock(Block block) {
|
||||||
this.world = world;
|
this.world = block.getWorld().getName();
|
||||||
this.x = x;
|
this.x = block.getX();
|
||||||
this.y = y;
|
this.y = block.getY();
|
||||||
this.z = z;
|
this.z = block.getZ();
|
||||||
this.mat = mat;
|
this.mat = block.getType();
|
||||||
this.face = null;
|
if (block.getBlockData() instanceof org.bukkit.block.data.Directional) {
|
||||||
this.data = data;
|
this.face = ((org.bukkit.block.data.Directional) block.getBlockData()).getFacing();
|
||||||
this.signLines = null;
|
|
||||||
this.floor = null;
|
|
||||||
this.bisected = null;
|
|
||||||
this.slabtype = null;
|
|
||||||
}
|
}
|
||||||
|
if (block.getBlockData() instanceof org.bukkit.block.data.Bisected) {
|
||||||
/**
|
this.bisected = ((org.bukkit.block.data.Bisected) block.getBlockData()).getHalf().name();
|
||||||
* 1.12 liftblock (signs)
|
|
||||||
*
|
|
||||||
* @param world The world
|
|
||||||
* @param x The x-pos
|
|
||||||
* @param y The y-pos
|
|
||||||
* @param z The z-pos
|
|
||||||
* @param mat The Material of the block
|
|
||||||
* @param data The data of the block
|
|
||||||
* @param signLines The lines of the sign
|
|
||||||
*/
|
|
||||||
public LiftBlock(String world, int x, int y, int z, Material mat, byte data, String[] signLines) {
|
|
||||||
this.world = world;
|
|
||||||
this.x = x;
|
|
||||||
this.y = y;
|
|
||||||
this.z = z;
|
|
||||||
this.mat = mat;
|
|
||||||
this.face = null;
|
|
||||||
this.data = data;
|
|
||||||
this.signLines = signLines;
|
|
||||||
this.floor = null;
|
|
||||||
this.bisected = null;
|
|
||||||
this.slabtype = null;
|
|
||||||
}
|
}
|
||||||
|
if (block.getBlockData() instanceof org.bukkit.block.data.type.Slab) {
|
||||||
/**
|
this.slabType = ((org.bukkit.block.data.type.Slab) block.getBlockData()).getType().name();
|
||||||
* 1.13 liftblock, without a direction
|
|
||||||
*
|
|
||||||
* @param world The world
|
|
||||||
* @param x The x-pos
|
|
||||||
* @param y The y-pos
|
|
||||||
* @param z The z-pos
|
|
||||||
* @param mat The Material of the block
|
|
||||||
*/
|
|
||||||
public LiftBlock(String world, int x, int y, int z, Material mat) {
|
|
||||||
this.world = world;
|
|
||||||
this.x = x;
|
|
||||||
this.y = y;
|
|
||||||
this.z = z;
|
|
||||||
this.mat = mat;
|
|
||||||
this.face = null;
|
|
||||||
this.data = 0;
|
|
||||||
this.signLines = null;
|
|
||||||
this.floor = null;
|
|
||||||
this.bisected = null;
|
|
||||||
this.slabtype = null;
|
|
||||||
}
|
}
|
||||||
|
if (block.getState() instanceof org.bukkit.block.Sign) {
|
||||||
/**
|
this.signLines = ((org.bukkit.block.Sign) block.getState()).getLines();
|
||||||
* 1.13 liftblock with a direction
|
|
||||||
*
|
|
||||||
* @param world The world
|
|
||||||
* @param x The x-pos
|
|
||||||
* @param y The y-pos
|
|
||||||
* @param z The z-pos
|
|
||||||
* @param mat The Material of the block
|
|
||||||
* @param face The blockface of the block
|
|
||||||
*/
|
|
||||||
public LiftBlock(String world, int x, int y, int z, Material mat, BlockFace face) {
|
|
||||||
this.world = world;
|
|
||||||
this.x = x;
|
|
||||||
this.y = y;
|
|
||||||
this.z = z;
|
|
||||||
this.mat = mat;
|
|
||||||
this.face = face;
|
|
||||||
this.data = 0;
|
|
||||||
this.signLines = null;
|
|
||||||
this.floor = null;
|
|
||||||
this.bisected = null;
|
|
||||||
this.slabtype = null;
|
|
||||||
}
|
}
|
||||||
|
if (block.getBlockData() instanceof org.bukkit.block.data.Openable) {
|
||||||
/**
|
this.open = ((org.bukkit.block.data.Openable) block.getBlockData()).isOpen();
|
||||||
* 1.13 liftblock, with a direction and a bisected
|
|
||||||
*
|
|
||||||
* @param world The world
|
|
||||||
* @param x The x-pos
|
|
||||||
* @param y The y-pos
|
|
||||||
* @param z The z-pos
|
|
||||||
* @param mat The Material of the block
|
|
||||||
* @param face The blockface of the block
|
|
||||||
* @param bisected The bisected of the block
|
|
||||||
*/
|
|
||||||
public LiftBlock(String world, int x, int y, int z, Material mat, BlockFace face, String bisected) {
|
|
||||||
this.world = world;
|
|
||||||
this.x = x;
|
|
||||||
this.y = y;
|
|
||||||
this.z = z;
|
|
||||||
this.mat = mat;
|
|
||||||
this.face = face;
|
|
||||||
this.data = 0;
|
|
||||||
this.signLines = null;
|
|
||||||
this.floor = null;
|
|
||||||
this.bisected = bisected;
|
|
||||||
this.slabtype = null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 1/13 liftblock (sign)
|
|
||||||
*
|
|
||||||
* @param world The world
|
|
||||||
* @param x The x-pos
|
|
||||||
* @param y The y-pos
|
|
||||||
* @param z The z-pos
|
|
||||||
* @param mat The Material of the block
|
|
||||||
* @param face The blockface of the block
|
|
||||||
* @param signLines The lines of the sign
|
|
||||||
*/
|
|
||||||
public LiftBlock(String world, int x, int y, int z, Material mat, BlockFace face, String[] signLines) {
|
|
||||||
this.world = world;
|
|
||||||
this.x = x;
|
|
||||||
this.y = y;
|
|
||||||
this.z = z;
|
|
||||||
this.mat = mat;
|
|
||||||
this.face = face;
|
|
||||||
this.data = 0;
|
|
||||||
this.signLines = signLines;
|
|
||||||
this.floor = null;
|
|
||||||
this.bisected = null;
|
|
||||||
this.slabtype = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 1.13 liftblock (slab)
|
|
||||||
*
|
|
||||||
* @param world The world
|
|
||||||
* @param x The x-pos
|
|
||||||
* @param y The y-pos
|
|
||||||
* @param z The z-pos
|
|
||||||
* @param mat The Material of the block
|
|
||||||
* @param slabtype The typ of slab (low, high, double)
|
|
||||||
*/
|
|
||||||
public LiftBlock(String world, int x, int y, int z, Material mat, String slabtype) {
|
|
||||||
this.world = world;
|
|
||||||
this.x = x;
|
|
||||||
this.y = y;
|
|
||||||
this.z = z;
|
|
||||||
this.mat = mat;
|
|
||||||
this.face = null;
|
|
||||||
this.data = 0;
|
|
||||||
this.signLines = null;
|
|
||||||
this.floor = null;
|
|
||||||
this.bisected = null;
|
|
||||||
this.slabtype = slabtype;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -5,6 +5,7 @@ import lombok.NoArgsConstructor;
|
||||||
import lombok.Setter;
|
import lombok.Setter;
|
||||||
import lombok.ToString;
|
import lombok.ToString;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.block.Block;
|
||||||
import org.bukkit.block.BlockFace;
|
import org.bukkit.block.BlockFace;
|
||||||
|
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
@ -18,7 +19,10 @@ import java.util.Objects;
|
||||||
@ToString
|
@ToString
|
||||||
public class LiftRope {
|
public class LiftRope {
|
||||||
private Material type;
|
private Material type;
|
||||||
|
//If it's Directional
|
||||||
private BlockFace face;
|
private BlockFace face;
|
||||||
|
//If it's Openable
|
||||||
|
private boolean open;
|
||||||
private String world;
|
private String world;
|
||||||
private int x;
|
private int x;
|
||||||
private int minY;
|
private int minY;
|
||||||
|
@ -29,23 +33,24 @@ public class LiftRope {
|
||||||
/**
|
/**
|
||||||
* Construct a new liftrope
|
* Construct a new liftrope
|
||||||
*
|
*
|
||||||
* @param type The material of the rope
|
* @param block The block
|
||||||
* @param face The face of the rope
|
|
||||||
* @param world The world
|
|
||||||
* @param x The x-pos
|
|
||||||
* @param minY The starting x-pos
|
* @param minY The starting x-pos
|
||||||
* @param maxY The stopping x-pos
|
* @param maxY The stopping x-pos
|
||||||
* @param z The z-pos
|
|
||||||
*/
|
*/
|
||||||
public LiftRope(Material type, BlockFace face, String world, int x, int minY, int maxY, int z) {
|
public LiftRope(Block block, int minY, int maxY) {
|
||||||
this.type = type;
|
this.type = block.getType();
|
||||||
this.face = face;
|
this.world = block.getWorld().getName();
|
||||||
this.world = world;
|
this.x = block.getX();
|
||||||
this.x = x;
|
|
||||||
this.minY = minY;
|
this.minY = minY;
|
||||||
this.maxY = maxY;
|
this.maxY = maxY;
|
||||||
this.z = z;
|
this.z = block.getZ();
|
||||||
this.currently = minY;
|
this.currently = block.getY();
|
||||||
|
if (block.getBlockData() instanceof org.bukkit.block.data.Directional) {
|
||||||
|
this.face = ((org.bukkit.block.data.Directional) block.getBlockData()).getFacing();
|
||||||
|
}
|
||||||
|
if (block.getBlockData() instanceof org.bukkit.block.data.Openable) {
|
||||||
|
this.open = ((org.bukkit.block.data.Openable) block.getBlockData()).isOpen();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -1,102 +0,0 @@
|
||||||
package tech.sbdevelopment.v10lift.api.objects;
|
|
||||||
|
|
||||||
import lombok.Getter;
|
|
||||||
import lombok.NoArgsConstructor;
|
|
||||||
import lombok.Setter;
|
|
||||||
import lombok.ToString;
|
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
import org.bukkit.Location;
|
|
||||||
import org.bukkit.entity.Entity;
|
|
||||||
|
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* A v10entity object, for an entity in the lift.
|
|
||||||
*/
|
|
||||||
@Getter
|
|
||||||
@NoArgsConstructor
|
|
||||||
@ToString
|
|
||||||
public class V10Entity {
|
|
||||||
private UUID entityUUID;
|
|
||||||
private String world;
|
|
||||||
private int locX;
|
|
||||||
private int locY;
|
|
||||||
private int locZ;
|
|
||||||
private int y;
|
|
||||||
@Setter
|
|
||||||
private short step;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Construct a new V10LiftEntity
|
|
||||||
*
|
|
||||||
* @param entityUUID The UUID of the entity
|
|
||||||
* @param worldName The world
|
|
||||||
* @param x The x-pos
|
|
||||||
* @param y The y-pos
|
|
||||||
* @param z The z-pos
|
|
||||||
* @param cury The current y-pos
|
|
||||||
*/
|
|
||||||
public V10Entity(UUID entityUUID, String worldName, int x, int y, int z, int cury) {
|
|
||||||
this.entityUUID = entityUUID;
|
|
||||||
this.world = worldName;
|
|
||||||
this.locX = x;
|
|
||||||
this.locY = y;
|
|
||||||
this.locZ = z;
|
|
||||||
this.y = cury;
|
|
||||||
this.step = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Move a entity up
|
|
||||||
*/
|
|
||||||
public void moveUp() {
|
|
||||||
if (entityUUID == null) return;
|
|
||||||
Entity entity = Bukkit.getEntity(entityUUID);
|
|
||||||
if (entity == null || entity.isDead()) return;
|
|
||||||
locY = y + step;
|
|
||||||
entity.teleport(new Location(Bukkit.getWorld(world), locX, locY, locZ));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Move a entity down
|
|
||||||
*/
|
|
||||||
public void moveDown() {
|
|
||||||
if (entityUUID == null) return;
|
|
||||||
Entity entity = Bukkit.getEntity(entityUUID);
|
|
||||||
if (entity == null || entity.isDead()) return;
|
|
||||||
locY = y - step;
|
|
||||||
entity.teleport(new Location(Bukkit.getWorld(world), locX, locY, locZ));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean equals(Object o) {
|
|
||||||
if (this == o) return true;
|
|
||||||
if (o == null) return false;
|
|
||||||
UUID uuid;
|
|
||||||
if (o instanceof V10Entity) {
|
|
||||||
Entity ent = Bukkit.getEntity(((V10Entity) o).getEntityUUID());
|
|
||||||
if (ent == null || ent.isDead()) {
|
|
||||||
Entity e = Bukkit.getEntity(entityUUID);
|
|
||||||
return e == null || e.isDead();
|
|
||||||
}
|
|
||||||
uuid = ent.getUniqueId();
|
|
||||||
} else if (o instanceof Entity) {
|
|
||||||
Entity ent = (Entity) o;
|
|
||||||
if (ent.isDead()) {
|
|
||||||
Entity e = Bukkit.getEntity(entityUUID);
|
|
||||||
return e == null || e.isDead();
|
|
||||||
}
|
|
||||||
uuid = ((Entity) o).getUniqueId();
|
|
||||||
} else
|
|
||||||
return false;
|
|
||||||
Entity e = Bukkit.getEntity(entityUUID);
|
|
||||||
if (e == null || e.isDead())
|
|
||||||
return false;
|
|
||||||
return uuid == e.getUniqueId();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int hashCode() {
|
|
||||||
return 31 + ((entityUUID == null) ? 0 : entityUUID.hashCode());
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -18,7 +18,7 @@ import tech.sbdevelopment.v10lift.managers.AntiCopyBlockManager;
|
||||||
import tech.sbdevelopment.v10lift.managers.DataManager;
|
import tech.sbdevelopment.v10lift.managers.DataManager;
|
||||||
import tech.sbdevelopment.v10lift.sbutils.LocationSerializer;
|
import tech.sbdevelopment.v10lift.sbutils.LocationSerializer;
|
||||||
import tech.sbdevelopment.v10lift.utils.ConfigUtil;
|
import tech.sbdevelopment.v10lift.utils.ConfigUtil;
|
||||||
import tech.sbdevelopment.v10lift.utils.DirectionUtil;
|
import tech.sbdevelopment.v10lift.utils.BlockStateUtil;
|
||||||
|
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
@ -153,7 +153,6 @@ public class MoveLift implements Runnable {
|
||||||
Bukkit.getLogger().info("[V10Lift] Lift " + liftName + " reaches the upper rope end but won't stop!!");
|
Bukkit.getLogger().info("[V10Lift] Lift " + liftName + " reaches the upper rope end but won't stop!!");
|
||||||
|
|
||||||
V10LiftAPI.getInstance().setDefective(liftName, true);
|
V10LiftAPI.getInstance().setDefective(liftName, true);
|
||||||
lift.getToMove().clear();
|
|
||||||
queueIterator.remove();
|
queueIterator.remove();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -214,22 +213,17 @@ public class MoveLift implements Runnable {
|
||||||
|
|
||||||
BlockState state = nextBlock.getState();
|
BlockState state = nextBlock.getState();
|
||||||
state.setType(lib.getMat());
|
state.setType(lib.getMat());
|
||||||
if (!XMaterial.supports(13)) {
|
|
||||||
state.setRawData(lib.getData());
|
|
||||||
}
|
|
||||||
state.update(true);
|
state.update(true);
|
||||||
|
|
||||||
if (XMaterial.supports(13)) {
|
if (XMaterial.supports(13)) {
|
||||||
DirectionUtil.setDirection(nextBlock, lib.getFace());
|
BlockStateUtil.setDirection(nextBlock, lib.getFace());
|
||||||
DirectionUtil.setBisected(nextBlock, lib.getBisected());
|
BlockStateUtil.setBisected(nextBlock, lib.getBisected());
|
||||||
DirectionUtil.setSlabType(nextBlock, lib.getSlabtype());
|
BlockStateUtil.setSlabType(nextBlock, lib.getSlabType());
|
||||||
|
BlockStateUtil.setOpen(nextBlock, lib.getOpen());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (direction == LiftDirection.UP) { //Teleportation is only required if we go up, for down gravity works fine. ;)
|
if (direction == LiftDirection.UP) { //Teleportation is only required if we go up, for down gravity works fine. ;)
|
||||||
for (Entity ent : nextBlock.getChunk().getEntities()) {
|
for (Entity ent : nextBlock.getChunk().getEntities()) {
|
||||||
V10Entity v10ent = new V10Entity(ent.getUniqueId(), null, 0, 0, 0, 0);
|
|
||||||
if (lift.getToMove().contains(v10ent)) continue;
|
|
||||||
|
|
||||||
Location entLoc = ent.getLocation();
|
Location entLoc = ent.getLocation();
|
||||||
if ((entLoc.getBlockY() == lib.getY() || entLoc.getBlockY() + 1 == lib.getY()) && entLoc.getBlockX() == lib.getX() && entLoc.getBlockZ() == lib.getZ()) {
|
if ((entLoc.getBlockY() == lib.getY() || entLoc.getBlockY() + 1 == lib.getY()) && entLoc.getBlockX() == lib.getX() && entLoc.getBlockZ() == lib.getZ()) {
|
||||||
entLoc.setY(entLoc.getY() + 1);
|
entLoc.setY(entLoc.getY() + 1);
|
||||||
|
@ -247,36 +241,17 @@ public class MoveLift implements Runnable {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Iterator<V10Entity> toMoveIterator = lift.getToMove().iterator();
|
|
||||||
while (toMoveIterator.hasNext()) {
|
|
||||||
V10Entity v10ent = toMoveIterator.next();
|
|
||||||
if (v10ent.getStep() > 0) {
|
|
||||||
if (direction == LiftDirection.UP) v10ent.moveUp();
|
|
||||||
else v10ent.moveDown();
|
|
||||||
if (v10ent.getStep() > 16) {
|
|
||||||
toMoveIterator.remove();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
v10ent.setStep((short) (v10ent.getStep() + 1));
|
|
||||||
}
|
|
||||||
|
|
||||||
for (LiftBlock lib : antiCopyBlocks) {
|
for (LiftBlock lib : antiCopyBlocks) {
|
||||||
Block block = Bukkit.getWorld(lib.getWorld()).getBlockAt(lib.getX(), lib.getY(), lib.getZ());
|
Block block = Bukkit.getWorld(lib.getWorld()).getBlockAt(lib.getX(), lib.getY(), lib.getZ());
|
||||||
if (lib.getMat() == null) lib.setMat(Material.AIR);
|
if (lib.getMat() == null) lib.setMat(Material.AIR);
|
||||||
|
|
||||||
BlockState state = block.getState();
|
BlockState state = block.getState();
|
||||||
state.setType(lib.getMat());
|
state.setType(lib.getMat());
|
||||||
if (!XMaterial.supports(13)) {
|
|
||||||
state.setRawData(lib.getData());
|
|
||||||
}
|
|
||||||
state.update(true);
|
state.update(true);
|
||||||
|
BlockStateUtil.setDirection(block, lib.getFace());
|
||||||
if (XMaterial.supports(13)) {
|
BlockStateUtil.setBisected(block, lib.getBisected());
|
||||||
DirectionUtil.setDirection(block, lib.getFace());
|
BlockStateUtil.setSlabType(block, lib.getSlabType());
|
||||||
DirectionUtil.setBisected(block, lib.getBisected());
|
BlockStateUtil.setOpen(block, lib.getOpen());
|
||||||
DirectionUtil.setSlabType(block, lib.getSlabtype());
|
|
||||||
}
|
|
||||||
|
|
||||||
lift.getBlocks().add(lib);
|
lift.getBlocks().add(lib);
|
||||||
|
|
||||||
if (lib.getSignLines() != null) {
|
if (lib.getSignLines() != null) {
|
||||||
|
@ -333,7 +308,6 @@ public class MoveLift implements Runnable {
|
||||||
Bukkit.getLogger().info("[V10Lift] Lift " + liftName + " reaches the upper rope end but won't stop!!");
|
Bukkit.getLogger().info("[V10Lift] Lift " + liftName + " reaches the upper rope end but won't stop!!");
|
||||||
|
|
||||||
V10LiftAPI.getInstance().setDefective(liftName, true);
|
V10LiftAPI.getInstance().setDefective(liftName, true);
|
||||||
lift.getToMove().clear();
|
|
||||||
queueIterator.remove();
|
queueIterator.remove();
|
||||||
|
|
||||||
stopAfter = true;
|
stopAfter = true;
|
||||||
|
@ -345,21 +319,13 @@ public class MoveLift implements Runnable {
|
||||||
if (rope.getType() == null) rope.setType(Material.AIR);
|
if (rope.getType() == null) rope.setType(Material.AIR);
|
||||||
|
|
||||||
block.setType(rope.getType());
|
block.setType(rope.getType());
|
||||||
if (XMaterial.supports(13)) {
|
BlockStateUtil.setDirection(block, rope.getFace());
|
||||||
DirectionUtil.setDirection(block, rope.getFace());
|
BlockStateUtil.setOpen(block, rope.isOpen());
|
||||||
} else {
|
|
||||||
BlockState state = block.getState();
|
|
||||||
org.bukkit.material.Ladder ladder = new org.bukkit.material.Ladder(rope.getType());
|
|
||||||
ladder.setFacingDirection(rope.getFace());
|
|
||||||
state.setData(ladder);
|
|
||||||
state.update(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (stopAfter) return;
|
if (stopAfter) return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
lift.getToMove().clear();
|
|
||||||
queueIterator.remove();
|
queueIterator.remove();
|
||||||
|
|
||||||
for (LiftBlock lib : lift.getBlocks()) {
|
for (LiftBlock lib : lift.getBlocks()) {
|
||||||
|
|
|
@ -233,7 +233,7 @@ public class PlayerInteractListener implements Listener {
|
||||||
LiftBlock start = DataManager.getRopeEditPlayer(p.getUniqueId());
|
LiftBlock start = DataManager.getRopeEditPlayer(p.getUniqueId());
|
||||||
Block now = e.getClickedBlock();
|
Block now = e.getClickedBlock();
|
||||||
if (start == null) {
|
if (start == null) {
|
||||||
ConfigUtil.sendMessage(e.getPlayer(), "Rope.Delete");
|
ConfigUtil.sendMessage(e.getPlayer(), "Rope.ClickOnEnd");
|
||||||
DataManager.addRopeEditPlayer(p.getUniqueId(), new LiftBlock(now.getWorld().getName(), now.getX(), now.getY(), now.getZ(), (String) null));
|
DataManager.addRopeEditPlayer(p.getUniqueId(), new LiftBlock(now.getWorld().getName(), now.getX(), now.getY(), now.getZ(), (String) null));
|
||||||
} else if (start.equals(new LiftBlock(now.getWorld().getName(), now.getX(), now.getY(), now.getZ(), (String) null))) {
|
} else if (start.equals(new LiftBlock(now.getWorld().getName(), now.getX(), now.getY(), now.getZ(), (String) null))) {
|
||||||
DataManager.addRopeEditPlayer(p.getUniqueId(), null);
|
DataManager.addRopeEditPlayer(p.getUniqueId(), null);
|
||||||
|
@ -283,12 +283,7 @@ public class PlayerInteractListener implements Listener {
|
||||||
ConfigUtil.sendMessage(e.getPlayer(), "Door.BlacklistedMaterial", Collections.singletonMap("%Name%", e.getClickedBlock().getType().toString().toLowerCase()));
|
ConfigUtil.sendMessage(e.getPlayer(), "Door.BlacklistedMaterial", Collections.singletonMap("%Name%", e.getClickedBlock().getType().toString().toLowerCase()));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
LiftBlock lb;
|
LiftBlock lb = new LiftBlock(block);
|
||||||
if (XMaterial.supports(13)) {
|
|
||||||
lb = new LiftBlock(block.getWorld().getName(), block.getX(), block.getY(), block.getZ(), block.getType());
|
|
||||||
} else {
|
|
||||||
lb = new LiftBlock(block.getWorld().getName(), block.getX(), block.getY(), block.getZ(), block.getType(), block.getState().getRawData());
|
|
||||||
}
|
|
||||||
Lift lift = DataManager.getLift(DataManager.getEditPlayer(p.getUniqueId()));
|
Lift lift = DataManager.getLift(DataManager.getEditPlayer(p.getUniqueId()));
|
||||||
Floor floor = lift.getFloors().get(DataManager.getDoorEditPlayer(p.getUniqueId()));
|
Floor floor = lift.getFloors().get(DataManager.getDoorEditPlayer(p.getUniqueId()));
|
||||||
if (DoorUtil.isOpenable(block)) {
|
if (DoorUtil.isOpenable(block)) {
|
||||||
|
|
|
@ -1,17 +1,14 @@
|
||||||
package tech.sbdevelopment.v10lift.utils;
|
package tech.sbdevelopment.v10lift.utils;
|
||||||
|
|
||||||
import com.cryptomorin.xseries.XMaterial;
|
|
||||||
import org.bukkit.block.Block;
|
import org.bukkit.block.Block;
|
||||||
import org.bukkit.block.BlockFace;
|
import org.bukkit.block.BlockFace;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
public class DirectionUtil {
|
public class BlockStateUtil {
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
public static BlockFace getDirection(@Nonnull Block block) {
|
public static BlockFace getDirection(@Nonnull Block block) {
|
||||||
if (!XMaterial.supports(13)) return null;
|
|
||||||
if (block.getBlockData() instanceof org.bukkit.block.data.Directional) {
|
if (block.getBlockData() instanceof org.bukkit.block.data.Directional) {
|
||||||
org.bukkit.block.data.Directional dir = (org.bukkit.block.data.Directional) block.getBlockData();
|
org.bukkit.block.data.Directional dir = (org.bukkit.block.data.Directional) block.getBlockData();
|
||||||
return dir.getFacing();
|
return dir.getFacing();
|
||||||
|
@ -19,9 +16,8 @@ public class DirectionUtil {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void setDirection(@Nonnull Block block, BlockFace blockFace) {
|
public static void setDirection(@Nonnull Block block, @Nonnull BlockFace blockFace) {
|
||||||
if (!XMaterial.supports(13)) return;
|
if (block.getBlockData() instanceof org.bukkit.block.data.Directional) {
|
||||||
if (blockFace != null && block.getBlockData() instanceof org.bukkit.block.data.Directional) {
|
|
||||||
org.bukkit.block.data.BlockData bd = block.getBlockData();
|
org.bukkit.block.data.BlockData bd = block.getBlockData();
|
||||||
org.bukkit.block.data.Directional dir = (org.bukkit.block.data.Directional) bd;
|
org.bukkit.block.data.Directional dir = (org.bukkit.block.data.Directional) bd;
|
||||||
dir.setFacing(blockFace);
|
dir.setFacing(blockFace);
|
||||||
|
@ -31,7 +27,6 @@ public class DirectionUtil {
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
public static String getBisected(@Nonnull Block block) {
|
public static String getBisected(@Nonnull Block block) {
|
||||||
if (!XMaterial.supports(13)) return null;
|
|
||||||
if (block.getBlockData() instanceof org.bukkit.block.data.Bisected) {
|
if (block.getBlockData() instanceof org.bukkit.block.data.Bisected) {
|
||||||
org.bukkit.block.data.Bisected bis = (org.bukkit.block.data.Bisected) block.getBlockData();
|
org.bukkit.block.data.Bisected bis = (org.bukkit.block.data.Bisected) block.getBlockData();
|
||||||
return bis.getHalf().toString();
|
return bis.getHalf().toString();
|
||||||
|
@ -40,9 +35,7 @@ public class DirectionUtil {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void setBisected(@Nonnull Block block, String bisected) {
|
public static void setBisected(@Nonnull Block block, String bisected) {
|
||||||
if (!XMaterial.supports(13)) return;
|
|
||||||
if (bisected != null && block.getBlockData() instanceof org.bukkit.block.data.Bisected) {
|
if (bisected != null && block.getBlockData() instanceof org.bukkit.block.data.Bisected) {
|
||||||
|
|
||||||
org.bukkit.block.data.Bisected.Half half;
|
org.bukkit.block.data.Bisected.Half half;
|
||||||
try {
|
try {
|
||||||
half = org.bukkit.block.data.Bisected.Half.valueOf(bisected);
|
half = org.bukkit.block.data.Bisected.Half.valueOf(bisected);
|
||||||
|
@ -60,7 +53,6 @@ public class DirectionUtil {
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
public static String getSlabType(@Nonnull Block block) {
|
public static String getSlabType(@Nonnull Block block) {
|
||||||
if (!XMaterial.supports(13)) return null;
|
|
||||||
if (block.getBlockData() instanceof org.bukkit.block.data.type.Slab) {
|
if (block.getBlockData() instanceof org.bukkit.block.data.type.Slab) {
|
||||||
org.bukkit.block.data.type.Slab slab = (org.bukkit.block.data.type.Slab) block.getBlockData();
|
org.bukkit.block.data.type.Slab slab = (org.bukkit.block.data.type.Slab) block.getBlockData();
|
||||||
return slab.getType().toString();
|
return slab.getType().toString();
|
||||||
|
@ -68,10 +60,8 @@ public class DirectionUtil {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void setSlabType(@Nonnull Block block, String slabtype) {
|
public static void setSlabType(@Nonnull Block block, @Nonnull String slabtype) {
|
||||||
if (!XMaterial.supports(13)) return;
|
if (block.getBlockData() instanceof org.bukkit.block.data.type.Slab) {
|
||||||
if (slabtype != null && block.getBlockData() instanceof org.bukkit.block.data.type.Slab) {
|
|
||||||
|
|
||||||
org.bukkit.block.data.type.Slab.Type type;
|
org.bukkit.block.data.type.Slab.Type type;
|
||||||
try {
|
try {
|
||||||
type = org.bukkit.block.data.type.Slab.Type.valueOf(slabtype);
|
type = org.bukkit.block.data.type.Slab.Type.valueOf(slabtype);
|
||||||
|
@ -86,4 +76,20 @@ public class DirectionUtil {
|
||||||
block.setBlockData(bd);
|
block.setBlockData(bd);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public static Boolean isOpen(@Nonnull Block block) {
|
||||||
|
if (block.getBlockData() instanceof org.bukkit.block.data.Openable) {
|
||||||
|
org.bukkit.block.data.Openable trapdoor = (org.bukkit.block.data.Openable) block.getBlockData();
|
||||||
|
return trapdoor.isOpen();
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void setOpen(@Nonnull Block block, boolean state) {
|
||||||
|
if (block.getBlockData() instanceof org.bukkit.block.data.Openable) {
|
||||||
|
org.bukkit.block.data.Openable trapdoor = (org.bukkit.block.data.Openable) block.getBlockData();
|
||||||
|
trapdoor.setOpen(state);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -4,14 +4,12 @@ import com.cryptomorin.xseries.XMaterial;
|
||||||
import com.cryptomorin.xseries.XSound;
|
import com.cryptomorin.xseries.XSound;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.block.Block;
|
import org.bukkit.block.Block;
|
||||||
import org.bukkit.block.BlockState;
|
|
||||||
import org.bukkit.block.data.Bisected;
|
import org.bukkit.block.data.Bisected;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
|
|
||||||
/* Openable codes sponsored by MrWouter <3 */
|
/* Openable codes sponsored by MrWouter <3 */
|
||||||
public class DoorUtil {
|
public class DoorUtil {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Open a door, with 1.12.x- and 1.13.x+ support
|
* Open a door, with 1.12.x- and 1.13.x+ support
|
||||||
*
|
*
|
||||||
|
@ -23,8 +21,7 @@ public class DoorUtil {
|
||||||
if (b.getType().toString().contains("DOOR") && b.getType() != XMaterial.IRON_DOOR.parseMaterial())
|
if (b.getType().toString().contains("DOOR") && b.getType() != XMaterial.IRON_DOOR.parseMaterial())
|
||||||
XSound.BLOCK_WOODEN_DOOR_OPEN.play(b.getLocation());
|
XSound.BLOCK_WOODEN_DOOR_OPEN.play(b.getLocation());
|
||||||
if (b.getType().toString().contains("GATE")) XSound.BLOCK_FENCE_GATE_OPEN.play(b.getLocation());
|
if (b.getType().toString().contains("GATE")) XSound.BLOCK_FENCE_GATE_OPEN.play(b.getLocation());
|
||||||
if (XMaterial.supports(13)) {
|
|
||||||
//1.13+
|
|
||||||
org.bukkit.block.data.BlockData blockData = b.getBlockData();
|
org.bukkit.block.data.BlockData blockData = b.getBlockData();
|
||||||
if (isOpenable(b)) {
|
if (isOpenable(b)) {
|
||||||
org.bukkit.block.data.Openable op = (org.bukkit.block.data.Openable) blockData;
|
org.bukkit.block.data.Openable op = (org.bukkit.block.data.Openable) blockData;
|
||||||
|
@ -35,20 +32,6 @@ public class DoorUtil {
|
||||||
b.setBlockData(blockData);
|
b.setBlockData(blockData);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
//1.12-
|
|
||||||
BlockState state = b.getState();
|
|
||||||
if (isOpenable(b)) {
|
|
||||||
org.bukkit.material.Openable openable = (org.bukkit.material.Openable) state.getData();
|
|
||||||
if (openable.isOpen()) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
openable.setOpen(true);
|
|
||||||
state.setData((org.bukkit.material.MaterialData) openable);
|
|
||||||
state.update();
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -63,8 +46,7 @@ public class DoorUtil {
|
||||||
if (b.getType().toString().contains("DOOR") && b.getType() != XMaterial.IRON_DOOR.parseMaterial())
|
if (b.getType().toString().contains("DOOR") && b.getType() != XMaterial.IRON_DOOR.parseMaterial())
|
||||||
XSound.BLOCK_WOODEN_DOOR_CLOSE.play(b.getLocation());
|
XSound.BLOCK_WOODEN_DOOR_CLOSE.play(b.getLocation());
|
||||||
if (b.getType().toString().contains("GATE")) XSound.BLOCK_FENCE_GATE_CLOSE.play(b.getLocation());
|
if (b.getType().toString().contains("GATE")) XSound.BLOCK_FENCE_GATE_CLOSE.play(b.getLocation());
|
||||||
if (XMaterial.supports(13)) {
|
|
||||||
//1.13+
|
|
||||||
org.bukkit.block.data.BlockData blockData = b.getBlockData();
|
org.bukkit.block.data.BlockData blockData = b.getBlockData();
|
||||||
if (isOpenable(b)) {
|
if (isOpenable(b)) {
|
||||||
org.bukkit.block.data.Openable op = (org.bukkit.block.data.Openable) blockData;
|
org.bukkit.block.data.Openable op = (org.bukkit.block.data.Openable) blockData;
|
||||||
|
@ -75,20 +57,6 @@ public class DoorUtil {
|
||||||
b.setBlockData(blockData);
|
b.setBlockData(blockData);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
//1.12-
|
|
||||||
BlockState state = b.getState();
|
|
||||||
if (isOpenable(b)) {
|
|
||||||
org.bukkit.material.Openable openable = (org.bukkit.material.Openable) state.getData();
|
|
||||||
if (!openable.isOpen()) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
openable.setOpen(false);
|
|
||||||
state.setData((org.bukkit.material.MaterialData) openable);
|
|
||||||
state.update();
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -98,17 +66,8 @@ public class DoorUtil {
|
||||||
* @param b The block
|
* @param b The block
|
||||||
* @return true if Openable, false if not
|
* @return true if Openable, false if not
|
||||||
*/
|
*/
|
||||||
public static boolean isOpenable(Block b) {
|
public static boolean isOpenable(@Nonnull Block b) {
|
||||||
if (b == null) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if (XMaterial.supports(13)) {
|
|
||||||
//1.13+
|
|
||||||
return b.getBlockData() instanceof org.bukkit.block.data.Openable;
|
return b.getBlockData() instanceof org.bukkit.block.data.Openable;
|
||||||
} else {
|
|
||||||
//1.12-
|
|
||||||
return b.getState().getData() instanceof org.bukkit.material.Openable;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -120,8 +79,6 @@ public class DoorUtil {
|
||||||
public static Location getLowerLocationOfDoor(@Nonnull Block block) {
|
public static Location getLowerLocationOfDoor(@Nonnull Block block) {
|
||||||
if (!isDoor(block)) return block.getLocation();
|
if (!isDoor(block)) return block.getLocation();
|
||||||
|
|
||||||
if (XMaterial.supports(13)) {
|
|
||||||
//1.13+
|
|
||||||
org.bukkit.block.data.type.Door door = (org.bukkit.block.data.type.Door) block.getBlockData();
|
org.bukkit.block.data.type.Door door = (org.bukkit.block.data.type.Door) block.getBlockData();
|
||||||
Location lower;
|
Location lower;
|
||||||
if (door.getHalf() == Bisected.Half.TOP) {
|
if (door.getHalf() == Bisected.Half.TOP) {
|
||||||
|
@ -136,23 +93,6 @@ public class DoorUtil {
|
||||||
lower = block.getLocation();
|
lower = block.getLocation();
|
||||||
}
|
}
|
||||||
return lower;
|
return lower;
|
||||||
} else {
|
|
||||||
//1.12-
|
|
||||||
org.bukkit.material.Door door = (org.bukkit.material.Door) block.getState().getData();
|
|
||||||
Location lower;
|
|
||||||
if (door.isTopHalf()) {
|
|
||||||
lower = block.getLocation().subtract(0, 1, 0);
|
|
||||||
} else {
|
|
||||||
if (!door.isOpen()) {
|
|
||||||
lower = block.getLocation().subtract(0, 1, 0);
|
|
||||||
if (isOpenable(lower.getBlock()))
|
|
||||||
return lower;
|
|
||||||
else return block.getLocation();
|
|
||||||
}
|
|
||||||
lower = block.getLocation();
|
|
||||||
}
|
|
||||||
return lower;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -161,17 +101,7 @@ public class DoorUtil {
|
||||||
* @param b The block
|
* @param b The block
|
||||||
* @return true if a Door, false if not
|
* @return true if a Door, false if not
|
||||||
*/
|
*/
|
||||||
public static boolean isDoor(Block b) {
|
public static boolean isDoor(@Nonnull Block b) {
|
||||||
if (b == null) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if (XMaterial.supports(13)) {
|
|
||||||
//1.13+
|
|
||||||
return b.getBlockData() instanceof org.bukkit.block.data.type.Door;
|
return b.getBlockData() instanceof org.bukkit.block.data.type.Door;
|
||||||
} else {
|
|
||||||
//1.12-
|
|
||||||
return b.getState().getData() instanceof org.bukkit.material.Door;
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
Loading…
Reference in a new issue