Code fully working for 1.13+ (except saving)
This commit is contained in:
parent
52758e18a1
commit
847267713e
5 changed files with 61 additions and 4 deletions
|
@ -3,6 +3,7 @@ package nl.SBDeveloper.V10Lift.API.Objects;
|
|||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.BlockFace;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.util.Map;
|
||||
|
@ -17,6 +18,7 @@ public class LiftBlock implements Comparable<LiftBlock> {
|
|||
//Only used for cabine blocks, because those need caching!
|
||||
@Getter private final Material mat;
|
||||
@Getter private final byte data;
|
||||
@Getter private final BlockFace face;
|
||||
@Getter private final String[] signLines;
|
||||
|
||||
//Only used for inputs!
|
||||
|
@ -33,6 +35,7 @@ public class LiftBlock implements Comparable<LiftBlock> {
|
|||
this.z = z;
|
||||
this.mat = null;
|
||||
this.data = 0;
|
||||
this.face = null;
|
||||
this.signLines = null;
|
||||
this.floor = floor;
|
||||
}
|
||||
|
@ -43,6 +46,7 @@ public class LiftBlock implements Comparable<LiftBlock> {
|
|||
this.y = y;
|
||||
this.z = z;
|
||||
this.mat = mat;
|
||||
this.face = null;
|
||||
this.data = 0;
|
||||
this.signLines = null;
|
||||
this.floor = null;
|
||||
|
@ -54,17 +58,19 @@ public class LiftBlock implements Comparable<LiftBlock> {
|
|||
this.y = y;
|
||||
this.z = z;
|
||||
this.mat = mat;
|
||||
this.face = null;
|
||||
this.data = data;
|
||||
this.signLines = null;
|
||||
this.floor = null;
|
||||
}
|
||||
|
||||
public LiftBlock(String world, int x, int y, int z, Material mat, String[] signLines) {
|
||||
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;
|
||||
|
@ -76,6 +82,7 @@ public class LiftBlock implements Comparable<LiftBlock> {
|
|||
this.y = y;
|
||||
this.z = z;
|
||||
this.mat = mat;
|
||||
this.face = null;
|
||||
this.data = data;
|
||||
this.signLines = signLines;
|
||||
this.floor = null;
|
||||
|
|
|
@ -2,6 +2,8 @@ package nl.SBDeveloper.V10Lift.API.Objects;
|
|||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import org.bukkit.Rotation;
|
||||
import org.bukkit.block.BlockFace;
|
||||
|
||||
@Getter @Setter
|
||||
public class LiftSign {
|
||||
|
|
|
@ -2,6 +2,7 @@ package nl.SBDeveloper.V10Lift.API.Runnables;
|
|||
|
||||
import nl.SBDeveloper.V10Lift.API.Objects.*;
|
||||
import nl.SBDeveloper.V10Lift.Managers.DataManager;
|
||||
import nl.SBDeveloper.V10Lift.Utils.DirectionUtil;
|
||||
import nl.SBDeveloper.V10Lift.Utils.LocationSerializer;
|
||||
import nl.SBDeveloper.V10Lift.Utils.XMaterial;
|
||||
import nl.SBDeveloper.V10Lift.Utils.XSound;
|
||||
|
@ -11,6 +12,7 @@ import org.bukkit.block.Block;
|
|||
import org.bukkit.block.BlockState;
|
||||
import org.bukkit.block.Chest;
|
||||
import org.bukkit.block.Sign;
|
||||
import org.bukkit.block.data.Directional;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
@ -189,6 +191,9 @@ public class MoveLift implements Runnable {
|
|||
state.setRawData(lib.getData());
|
||||
}
|
||||
state.update(true);
|
||||
if (block.getBlockData() instanceof Directional) {
|
||||
DirectionUtil.setDirection(block, lib.getFace());
|
||||
}
|
||||
lb = lift.getBlocks().first();
|
||||
for (Entity ent : Objects.requireNonNull(Bukkit.getWorld(lib.getWorld()), "World is null at MoveLift").getBlockAt(lib.getX(), lib.getY(), lib.getZ()).getChunk().getEntities()) {
|
||||
v10ent = new V10Entity(ent, null, 0);
|
||||
|
@ -229,6 +234,9 @@ public class MoveLift implements Runnable {
|
|||
state.setRawData(lib.getData());
|
||||
}
|
||||
state.update(true);
|
||||
if (block.getBlockData() instanceof Directional) {
|
||||
DirectionUtil.setDirection(block, lib.getFace());
|
||||
}
|
||||
lift.getBlocks().add(lib);
|
||||
if (lib.getSignLines() != null) {
|
||||
bs = block.getState();
|
||||
|
@ -314,6 +322,9 @@ public class MoveLift implements Runnable {
|
|||
state.setRawData(lib.getData());
|
||||
}
|
||||
state.update(true);
|
||||
if (block.getBlockData() instanceof Directional) {
|
||||
DirectionUtil.setDirection(block, lib.getFace());
|
||||
}
|
||||
}
|
||||
veiter = lift.getToMove().iterator();
|
||||
while (veiter.hasNext()) {
|
||||
|
@ -334,6 +345,9 @@ public class MoveLift implements Runnable {
|
|||
state.setRawData(lib.getData());
|
||||
}
|
||||
state.update(true);
|
||||
if (block.getBlockData() instanceof Directional) {
|
||||
DirectionUtil.setDirection(block, lib.getFace());
|
||||
}
|
||||
lift.getBlocks().add(lib);
|
||||
if (lib.getSignLines() != null) {
|
||||
bs = block.getState();
|
||||
|
|
|
@ -6,6 +6,7 @@ import nl.SBDeveloper.V10Lift.API.Runnables.MoveLift;
|
|||
import nl.SBDeveloper.V10Lift.Managers.AntiCopyBlockManager;
|
||||
import nl.SBDeveloper.V10Lift.Managers.DataManager;
|
||||
import nl.SBDeveloper.V10Lift.Managers.ForbiddenBlockManager;
|
||||
import nl.SBDeveloper.V10Lift.Utils.DirectionUtil;
|
||||
import nl.SBDeveloper.V10Lift.Utils.LocationSerializer;
|
||||
import nl.SBDeveloper.V10Lift.Utils.XMaterial;
|
||||
import nl.SBDeveloper.V10Lift.V10LiftPlugin;
|
||||
|
@ -157,7 +158,8 @@ public class V10LiftAPI {
|
|||
if (type.toString().contains("SIGN")) {
|
||||
//SIGN
|
||||
if (XMaterial.isNewVersion()) {
|
||||
lb = new LiftBlock(block.getWorld().getName(), block.getX(), block.getY(), block.getZ(), type, ((Sign) block.getState()).getLines());
|
||||
Bukkit.getLogger().info("Newest system! " + DirectionUtil.getDirection(block));
|
||||
lb = new LiftBlock(block.getWorld().getName(), block.getX(), block.getY(), block.getZ(), type, DirectionUtil.getDirection(block), ((Sign) block.getState()).getLines());
|
||||
} else {
|
||||
Bukkit.getLogger().info("Using deprecated method! " + block.getState().getRawData());
|
||||
lb = new LiftBlock(block.getWorld().getName(), block.getX(), block.getY(), block.getZ(), type, block.getState().getRawData(), ((Sign) block.getState()).getLines());
|
||||
|
@ -205,7 +207,8 @@ public class V10LiftAPI {
|
|||
if (type.toString().contains("SIGN")) {
|
||||
//SIGN
|
||||
if (XMaterial.isNewVersion()) {
|
||||
lb = new LiftBlock(block.getWorld().getName(), block.getX(), block.getY(), block.getZ(), type, ((Sign) block.getState()).getLines());
|
||||
Bukkit.getLogger().info("Newest system! " + DirectionUtil.getDirection(block));
|
||||
lb = new LiftBlock(block.getWorld().getName(), block.getX(), block.getY(), block.getZ(), type, DirectionUtil.getDirection(block), ((Sign) block.getState()).getLines());
|
||||
} else {
|
||||
Bukkit.getLogger().info("Using deprecated method! " + block.getState().getRawData());
|
||||
lb = new LiftBlock(block.getWorld().getName(), block.getX(), block.getY(), block.getZ(), type, block.getState().getRawData(), ((Sign) block.getState()).getLines());
|
||||
|
@ -254,7 +257,8 @@ public class V10LiftAPI {
|
|||
if (type.toString().contains("SIGN")) {
|
||||
//SIGN
|
||||
if (XMaterial.isNewVersion()) {
|
||||
lb = new LiftBlock(block.getWorld().getName(), block.getX(), block.getY(), block.getZ(), type, ((Sign) block.getState()).getLines());
|
||||
Bukkit.getLogger().info("Newest system! " + DirectionUtil.getDirection(block));
|
||||
lb = new LiftBlock(block.getWorld().getName(), block.getX(), block.getY(), block.getZ(), type, DirectionUtil.getDirection(block), ((Sign) block.getState()).getLines());
|
||||
} else {
|
||||
Bukkit.getLogger().info("Using deprecated method! " + block.getState().getRawData());
|
||||
lb = new LiftBlock(block.getWorld().getName(), block.getX(), block.getY(), block.getZ(), type, block.getState().getRawData(), ((Sign) block.getState()).getLines());
|
||||
|
|
|
@ -0,0 +1,30 @@
|
|||
package nl.SBDeveloper.V10Lift.Utils;
|
||||
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.BlockFace;
|
||||
import org.bukkit.block.data.BlockData;
|
||||
import org.bukkit.block.data.Directional;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
public class DirectionUtil {
|
||||
|
||||
@Nullable
|
||||
public static BlockFace getDirection(@Nonnull Block block) {
|
||||
if (block.getBlockData() instanceof Directional && block.getType().toString().contains("WALL_SIGN")) {
|
||||
Directional dir = (Directional) block.getBlockData();
|
||||
return dir.getFacing();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static void setDirection(@Nonnull Block block, BlockFace blockFace) {
|
||||
if (block.getBlockData() instanceof Directional && block.getType().toString().contains("WALL_SIGN")) {
|
||||
BlockData bd = block.getBlockData();
|
||||
Directional dir = (Directional) bd;
|
||||
dir.setFacing(blockFace);
|
||||
block.setBlockData(bd);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue