Code fully working for 1.13+ (except saving)

This commit is contained in:
stijnb1234 2020-02-02 16:20:20 +01:00
parent 52758e18a1
commit 847267713e
5 changed files with 61 additions and 4 deletions

View file

@ -3,6 +3,7 @@ package nl.SBDeveloper.V10Lift.API.Objects;
import lombok.Getter; import lombok.Getter;
import lombok.Setter; import lombok.Setter;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.block.BlockFace;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
import java.util.Map; import java.util.Map;
@ -17,6 +18,7 @@ public class LiftBlock implements Comparable<LiftBlock> {
//Only used for cabine blocks, because those need caching! //Only used for cabine blocks, because those need caching!
@Getter private final Material mat; @Getter private final Material mat;
@Getter private final byte data; @Getter private final byte data;
@Getter private final BlockFace face;
@Getter private final String[] signLines; @Getter private final String[] signLines;
//Only used for inputs! //Only used for inputs!
@ -33,6 +35,7 @@ public class LiftBlock implements Comparable<LiftBlock> {
this.z = z; this.z = z;
this.mat = null; this.mat = null;
this.data = 0; this.data = 0;
this.face = null;
this.signLines = null; this.signLines = null;
this.floor = floor; this.floor = floor;
} }
@ -43,6 +46,7 @@ public class LiftBlock implements Comparable<LiftBlock> {
this.y = y; this.y = y;
this.z = z; this.z = z;
this.mat = mat; this.mat = mat;
this.face = null;
this.data = 0; this.data = 0;
this.signLines = null; this.signLines = null;
this.floor = null; this.floor = null;
@ -54,17 +58,19 @@ public class LiftBlock implements Comparable<LiftBlock> {
this.y = y; this.y = y;
this.z = z; this.z = z;
this.mat = mat; this.mat = mat;
this.face = null;
this.data = data; this.data = data;
this.signLines = null; this.signLines = null;
this.floor = 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.world = world;
this.x = x; this.x = x;
this.y = y; this.y = y;
this.z = z; this.z = z;
this.mat = mat; this.mat = mat;
this.face = face;
this.data = 0; this.data = 0;
this.signLines = signLines; this.signLines = signLines;
this.floor = null; this.floor = null;
@ -76,6 +82,7 @@ public class LiftBlock implements Comparable<LiftBlock> {
this.y = y; this.y = y;
this.z = z; this.z = z;
this.mat = mat; this.mat = mat;
this.face = null;
this.data = data; this.data = data;
this.signLines = signLines; this.signLines = signLines;
this.floor = null; this.floor = null;

View file

@ -2,6 +2,8 @@ package nl.SBDeveloper.V10Lift.API.Objects;
import lombok.Getter; import lombok.Getter;
import lombok.Setter; import lombok.Setter;
import org.bukkit.Rotation;
import org.bukkit.block.BlockFace;
@Getter @Setter @Getter @Setter
public class LiftSign { public class LiftSign {

View file

@ -2,6 +2,7 @@ package nl.SBDeveloper.V10Lift.API.Runnables;
import nl.SBDeveloper.V10Lift.API.Objects.*; import nl.SBDeveloper.V10Lift.API.Objects.*;
import nl.SBDeveloper.V10Lift.Managers.DataManager; import nl.SBDeveloper.V10Lift.Managers.DataManager;
import nl.SBDeveloper.V10Lift.Utils.DirectionUtil;
import nl.SBDeveloper.V10Lift.Utils.LocationSerializer; import nl.SBDeveloper.V10Lift.Utils.LocationSerializer;
import nl.SBDeveloper.V10Lift.Utils.XMaterial; import nl.SBDeveloper.V10Lift.Utils.XMaterial;
import nl.SBDeveloper.V10Lift.Utils.XSound; import nl.SBDeveloper.V10Lift.Utils.XSound;
@ -11,6 +12,7 @@ import org.bukkit.block.Block;
import org.bukkit.block.BlockState; import org.bukkit.block.BlockState;
import org.bukkit.block.Chest; import org.bukkit.block.Chest;
import org.bukkit.block.Sign; import org.bukkit.block.Sign;
import org.bukkit.block.data.Directional;
import org.bukkit.entity.Entity; import org.bukkit.entity.Entity;
import org.bukkit.inventory.Inventory; import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
@ -189,6 +191,9 @@ public class MoveLift implements Runnable {
state.setRawData(lib.getData()); state.setRawData(lib.getData());
} }
state.update(true); state.update(true);
if (block.getBlockData() instanceof Directional) {
DirectionUtil.setDirection(block, lib.getFace());
}
lb = lift.getBlocks().first(); 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()) { 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); v10ent = new V10Entity(ent, null, 0);
@ -229,6 +234,9 @@ public class MoveLift implements Runnable {
state.setRawData(lib.getData()); state.setRawData(lib.getData());
} }
state.update(true); state.update(true);
if (block.getBlockData() instanceof Directional) {
DirectionUtil.setDirection(block, lib.getFace());
}
lift.getBlocks().add(lib); lift.getBlocks().add(lib);
if (lib.getSignLines() != null) { if (lib.getSignLines() != null) {
bs = block.getState(); bs = block.getState();
@ -314,6 +322,9 @@ public class MoveLift implements Runnable {
state.setRawData(lib.getData()); state.setRawData(lib.getData());
} }
state.update(true); state.update(true);
if (block.getBlockData() instanceof Directional) {
DirectionUtil.setDirection(block, lib.getFace());
}
} }
veiter = lift.getToMove().iterator(); veiter = lift.getToMove().iterator();
while (veiter.hasNext()) { while (veiter.hasNext()) {
@ -334,6 +345,9 @@ public class MoveLift implements Runnable {
state.setRawData(lib.getData()); state.setRawData(lib.getData());
} }
state.update(true); state.update(true);
if (block.getBlockData() instanceof Directional) {
DirectionUtil.setDirection(block, lib.getFace());
}
lift.getBlocks().add(lib); lift.getBlocks().add(lib);
if (lib.getSignLines() != null) { if (lib.getSignLines() != null) {
bs = block.getState(); bs = block.getState();

View file

@ -6,6 +6,7 @@ import nl.SBDeveloper.V10Lift.API.Runnables.MoveLift;
import nl.SBDeveloper.V10Lift.Managers.AntiCopyBlockManager; import nl.SBDeveloper.V10Lift.Managers.AntiCopyBlockManager;
import nl.SBDeveloper.V10Lift.Managers.DataManager; import nl.SBDeveloper.V10Lift.Managers.DataManager;
import nl.SBDeveloper.V10Lift.Managers.ForbiddenBlockManager; import nl.SBDeveloper.V10Lift.Managers.ForbiddenBlockManager;
import nl.SBDeveloper.V10Lift.Utils.DirectionUtil;
import nl.SBDeveloper.V10Lift.Utils.LocationSerializer; import nl.SBDeveloper.V10Lift.Utils.LocationSerializer;
import nl.SBDeveloper.V10Lift.Utils.XMaterial; import nl.SBDeveloper.V10Lift.Utils.XMaterial;
import nl.SBDeveloper.V10Lift.V10LiftPlugin; import nl.SBDeveloper.V10Lift.V10LiftPlugin;
@ -157,7 +158,8 @@ public class V10LiftAPI {
if (type.toString().contains("SIGN")) { if (type.toString().contains("SIGN")) {
//SIGN //SIGN
if (XMaterial.isNewVersion()) { 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 { } else {
Bukkit.getLogger().info("Using deprecated method! " + block.getState().getRawData()); 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()); 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")) { if (type.toString().contains("SIGN")) {
//SIGN //SIGN
if (XMaterial.isNewVersion()) { 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 { } else {
Bukkit.getLogger().info("Using deprecated method! " + block.getState().getRawData()); 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()); 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")) { if (type.toString().contains("SIGN")) {
//SIGN //SIGN
if (XMaterial.isNewVersion()) { 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 { } else {
Bukkit.getLogger().info("Using deprecated method! " + block.getState().getRawData()); 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()); lb = new LiftBlock(block.getWorld().getName(), block.getX(), block.getY(), block.getZ(), type, block.getState().getRawData(), ((Sign) block.getState()).getLines());

View file

@ -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);
}
}
}