Fixed GSON issues for 1.14+ & fixed dir blocks

This commit is contained in:
stijnb1234 2020-02-03 19:53:29 +01:00
parent c712ad1775
commit c61063ebdf
5 changed files with 163 additions and 46 deletions

View file

@ -90,6 +90,12 @@
<version>1.18.10</version>
<scope>provided</scope>
</dependency>
<!-- Needed for 1.15, becuase that version is wrong -->
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.8.6</version>
</dependency>
</dependencies>

View file

@ -20,6 +20,7 @@ public class LiftBlock implements Comparable<LiftBlock> {
@Getter private final Material mat;
@Getter private final byte data;
@Getter private final BlockFace face;
@Getter private final Object bisected;
@Getter private final String[] signLines;
//Only used for inputs!
@ -29,6 +30,7 @@ public class LiftBlock implements Comparable<LiftBlock> {
//Only used for chests
public Map<String, Object>[] serializedItemStacks = null;
/* Floor based liftblock, no material */
public LiftBlock(String world, int x, int y, int z, String floor) {
this.world = world;
this.x = x;
@ -39,20 +41,12 @@ public class LiftBlock implements Comparable<LiftBlock> {
this.face = null;
this.signLines = null;
this.floor = floor;
this.bisected = null;
}
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;
}
/** 1.12 liftblocks **/
/* 1.12 liftblock (Directional) */
public LiftBlock(String world, int x, int y, int z, Material mat, byte data) {
this.world = world;
this.x = x;
@ -63,20 +57,10 @@ public class LiftBlock implements Comparable<LiftBlock> {
this.data = data;
this.signLines = null;
this.floor = null;
this.bisected = null;
}
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;
}
/* 1.12 liftblock (sign) */
public LiftBlock(String world, int x, int y, int z, Material mat, byte data, String[] signLines) {
this.world = world;
this.x = x;
@ -87,6 +71,65 @@ public class LiftBlock implements Comparable<LiftBlock> {
this.data = data;
this.signLines = signLines;
this.floor = null;
this.bisected = null;
}
/** 1.13 liftblocks **/
/* 1.13 liftblock (no Dir) */
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;
}
/* 1.13 liftblock (Directional) */
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;
}
/* 1.13 liftblock (dir & bisec) */
public LiftBlock(String world, int x, int y, int z, Material mat, BlockFace face, Object 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;
}
/* 1.13 liftblock (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;
}
@Override

View file

@ -205,6 +205,7 @@ public class MoveLift implements Runnable {
state.update(true);
if (XMaterial.isNewVersion()) {
DirectionUtil.setDirection(block, lib.getFace());
DirectionUtil.setBisected(block, lib.getBisected());
}
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()) {
@ -248,6 +249,7 @@ public class MoveLift implements Runnable {
state.update(true);
if (XMaterial.isNewVersion()) {
DirectionUtil.setDirection(block, lib.getFace());
DirectionUtil.setBisected(block, lib.getBisected());
}
lift.getBlocks().add(lib);
if (lib.getSignLines() != null) {
@ -336,6 +338,7 @@ public class MoveLift implements Runnable {
state.update(true);
if (XMaterial.isNewVersion()) {
DirectionUtil.setDirection(block, lib.getFace());
DirectionUtil.setBisected(block, lib.getBisected());
}
}
veiter = lift.getToMove().iterator();
@ -359,6 +362,7 @@ public class MoveLift implements Runnable {
state.update(true);
if (XMaterial.isNewVersion()) {
DirectionUtil.setDirection(block, lib.getFace());
DirectionUtil.setBisected(block, lib.getBisected());
}
lift.getBlocks().add(lib);
if (lib.getSignLines() != null) {
@ -410,8 +414,9 @@ public class MoveLift implements Runnable {
block = world.getBlockAt(rope.getX(), rope.getCurrently(), rope.getZ());
block.setType(rope.getType());
if (XMaterial.isNewVersion()) {
org.bukkit.block.data.type.Ladder ladder = (org.bukkit.block.data.type.Ladder) block.getBlockData();
ladder.setFacing(rope.getFace());
org.bukkit.block.data.Directional data = (org.bukkit.block.data.Directional) block.getBlockData();
data.setFacing(rope.getFace());
block.setBlockData(data);
} else {
BlockState state = block.getState();
org.bukkit.material.Ladder ladder = new org.bukkit.material.Ladder(rope.getType());
@ -426,8 +431,9 @@ public class MoveLift implements Runnable {
block = world.getBlockAt(rope.getX(), rope.getCurrently(), rope.getZ());
block.setType(rope.getType());
if (XMaterial.isNewVersion()) {
org.bukkit.block.data.type.Ladder ladder = (org.bukkit.block.data.type.Ladder) block.getBlockData();
ladder.setFacing(rope.getFace());
org.bukkit.block.data.Directional data = (org.bukkit.block.data.Directional) block.getBlockData();
data.setFacing(rope.getFace());
block.setBlockData(data);
} else {
BlockState state = block.getState();
org.bukkit.material.Ladder ladder = new org.bukkit.material.Ladder(rope.getType());

View file

@ -173,17 +173,34 @@ public class V10LiftAPI {
public int addBlockToLift(Set<LiftBlock> blocks, @Nonnull Block block) {
Material type = block.getType();
LiftBlock lb;
if (type.toString().contains("SIGN")) {
//SIGN
if (XMaterial.isNewVersion()) {
Class<?> biClass;
try {
biClass = Class.forName("org.bukkit.block.data.Bisected");
} catch (ClassNotFoundException e) {
e.printStackTrace();
return -1;
}
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().getClass().isInstance(biClass)) {
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 {
lb = new LiftBlock(block.getWorld().getName(), block.getX(), block.getY(), block.getZ(), type, block.getState().getRawData(), ((Sign) block.getState()).getLines());
Bukkit.getLogger().info("Block not instanceof Dir 1.13");
lb = new LiftBlock(block.getWorld().getName(), block.getX(), block.getY(), block.getZ(), type);
}
} else {
if (XMaterial.isNewVersion()) {
lb = new LiftBlock(block.getWorld().getName(), block.getX(), block.getY(), block.getZ(), type);
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());
}
}
@ -218,17 +235,34 @@ public class V10LiftAPI {
Lift lift = DataManager.getLift(liftName);
Material type = block.getType();
LiftBlock lb;
if (type.toString().contains("SIGN")) {
//SIGN
if (XMaterial.isNewVersion()) {
Class<?> biClass;
try {
biClass = Class.forName("org.bukkit.block.data.Bisected");
} catch (ClassNotFoundException e) {
e.printStackTrace();
return -1;
}
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().getClass().isInstance(biClass)) {
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 {
lb = new LiftBlock(block.getWorld().getName(), block.getX(), block.getY(), block.getZ(), type, block.getState().getRawData(), ((Sign) block.getState()).getLines());
Bukkit.getLogger().info("Block not instanceof Dir 1.13");
lb = new LiftBlock(block.getWorld().getName(), block.getX(), block.getY(), block.getZ(), type);
}
} else {
if (XMaterial.isNewVersion()) {
lb = new LiftBlock(block.getWorld().getName(), block.getX(), block.getY(), block.getZ(), type);
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());
}
}
@ -263,17 +297,26 @@ public class V10LiftAPI {
Material type = block.getType();
if (getFBM().isForbidden(type)) return -2;
LiftBlock lb;
if (type.toString().contains("SIGN")) {
//SIGN
if (XMaterial.isNewVersion()) {
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 {
lb = new LiftBlock(block.getWorld().getName(), block.getX(), block.getY(), block.getZ(), type, block.getState().getRawData(), ((Sign) block.getState()).getLines());
Bukkit.getLogger().info("Block not instanceof Dir 1.13");
lb = new LiftBlock(block.getWorld().getName(), block.getX(), block.getY(), block.getZ(), type);
}
} else {
if (XMaterial.isNewVersion()) {
lb = new LiftBlock(block.getWorld().getName(), block.getX(), block.getY(), block.getZ(), type);
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());
}
}

View file

@ -2,6 +2,7 @@ package nl.SBDeveloper.V10Lift.Utils;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.block.data.Bisected;
import org.bukkit.block.data.BlockData;
import org.bukkit.block.data.Directional;
@ -20,11 +21,29 @@ public class DirectionUtil {
}
public static void setDirection(@Nonnull Block block, BlockFace blockFace) {
if (block.getBlockData() instanceof Directional) {
if (blockFace != null && block.getBlockData() instanceof Directional) {
BlockData bd = block.getBlockData();
Directional dir = (Directional) bd;
dir.setFacing(blockFace);
block.setBlockData(bd);
}
}
@Nullable
public static Object getBisected(@Nonnull Block block) {
if (block.getBlockData() instanceof Bisected) {
Bisected bis = (Bisected) block.getBlockData();
return bis.getHalf();
}
return null;
}
public static void setBisected(@Nonnull Block block, Object bisected) {
if (bisected != null && block.getBlockData() instanceof Bisected && bisected instanceof Bisected.Half) {
BlockData bd = block.getBlockData();
Bisected bis = (Bisected) bd;
bis.setHalf((Bisected.Half) bisected);
block.setBlockData(bd);
}
}
}