Fixed item frames and paintings not logging directional data
This commit is contained in:
parent
7398f7dfe6
commit
e462e68806
15 changed files with 132 additions and 68 deletions
|
|
@ -451,6 +451,15 @@ public class Util extends Queue {
|
|||
}
|
||||
string = String.join(",", blockDataArray);
|
||||
}
|
||||
else if (!string.contains(":") && (material == Material.PAINTING || BukkitAdapter.ADAPTER.isItemFrame(material))) {
|
||||
int id = getBlockdataId(string, true);
|
||||
if (id > -1) {
|
||||
string = Integer.toString(id);
|
||||
}
|
||||
else {
|
||||
return result;
|
||||
}
|
||||
}
|
||||
else {
|
||||
return result;
|
||||
}
|
||||
|
|
@ -483,7 +492,13 @@ public class Util extends Queue {
|
|||
blockDataArray.add(block);
|
||||
}
|
||||
}
|
||||
result = NAMESPACE + material.name().toLowerCase(Locale.ROOT) + "[" + String.join(",", blockDataArray) + "]";
|
||||
|
||||
if (material == Material.PAINTING || BukkitAdapter.ADAPTER.isItemFrame(material)) {
|
||||
result = String.join(",", blockDataArray);
|
||||
}
|
||||
else {
|
||||
result = NAMESPACE + material.name().toLowerCase(Locale.ROOT) + "[" + String.join(",", blockDataArray) + "]";
|
||||
}
|
||||
}
|
||||
else {
|
||||
result = "";
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@ import org.bukkit.block.Block;
|
|||
import org.bukkit.block.BlockFace;
|
||||
import org.bukkit.block.BlockState;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.Hanging;
|
||||
import org.bukkit.entity.ItemFrame;
|
||||
import org.bukkit.entity.Painting;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
|
@ -26,7 +27,7 @@ public class HangingUtil {
|
|||
}
|
||||
|
||||
@SuppressWarnings({ "unchecked", "rawtypes" })
|
||||
public static void spawnHanging(final BlockState blockstate, final Material rowType, final int rowData, int delay) {
|
||||
public static void spawnHanging(final BlockState blockstate, final Material rowType, final String hangingData, final int rowData, int delay) {
|
||||
Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(CoreProtect.getInstance(), () -> {
|
||||
try {
|
||||
Block block = blockstate.getBlock();
|
||||
|
|
@ -34,51 +35,69 @@ public class HangingUtil {
|
|||
int y = block.getY();
|
||||
int z = block.getZ();
|
||||
|
||||
BlockFace hangingFace = null;
|
||||
if (hangingData != null && !hangingData.contains(":") && hangingData.contains("=")) {
|
||||
try {
|
||||
hangingFace = BlockFace.valueOf(hangingData.split("=")[1].toUpperCase(Locale.ROOT));
|
||||
}
|
||||
catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
for (Entity e : block.getChunk().getEntities()) {
|
||||
if ((BukkitAdapter.ADAPTER.isItemFrame(rowType) && e instanceof ItemFrame) || (rowType.equals(Material.PAINTING) && e instanceof Painting)) {
|
||||
Location el = e.getLocation();
|
||||
if (el.getBlockX() == x && el.getBlockY() == y && el.getBlockZ() == z) {
|
||||
e.remove();
|
||||
break;
|
||||
if (hangingFace == null || ((Hanging) e).getFacing() == hangingFace) {
|
||||
e.remove();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Block c1 = block.getWorld().getBlockAt((x + 1), y, z);
|
||||
Block c2 = block.getWorld().getBlockAt((x - 1), y, z);
|
||||
Block c3 = block.getWorld().getBlockAt(x, y, (z + 1));
|
||||
Block c4 = block.getWorld().getBlockAt(x, y, (z - 1));
|
||||
|
||||
BlockFace faceSet = null;
|
||||
if (!BlockGroup.NON_ATTACHABLE.contains(c1.getType())) {
|
||||
faceSet = BlockFace.WEST;
|
||||
block = c1;
|
||||
}
|
||||
else if (!BlockGroup.NON_ATTACHABLE.contains(c2.getType())) {
|
||||
faceSet = BlockFace.EAST;
|
||||
block = c2;
|
||||
}
|
||||
else if (!BlockGroup.NON_ATTACHABLE.contains(c3.getType())) {
|
||||
faceSet = BlockFace.NORTH;
|
||||
block = c3;
|
||||
}
|
||||
else if (!BlockGroup.NON_ATTACHABLE.contains(c4.getType())) {
|
||||
faceSet = BlockFace.SOUTH;
|
||||
block = c4;
|
||||
}
|
||||
|
||||
BlockFace face = null;
|
||||
if (!Util.solidBlock(Util.getType(block.getRelative(BlockFace.EAST)))) {
|
||||
face = BlockFace.EAST;
|
||||
if (hangingFace == null) {
|
||||
Block c1 = block.getWorld().getBlockAt((x + 1), y, z);
|
||||
Block c2 = block.getWorld().getBlockAt((x - 1), y, z);
|
||||
Block c3 = block.getWorld().getBlockAt(x, y, (z + 1));
|
||||
Block c4 = block.getWorld().getBlockAt(x, y, (z - 1));
|
||||
|
||||
if (!BlockGroup.NON_ATTACHABLE.contains(c1.getType())) {
|
||||
faceSet = BlockFace.WEST;
|
||||
block = c1;
|
||||
}
|
||||
else if (!BlockGroup.NON_ATTACHABLE.contains(c2.getType())) {
|
||||
faceSet = BlockFace.EAST;
|
||||
block = c2;
|
||||
}
|
||||
else if (!BlockGroup.NON_ATTACHABLE.contains(c3.getType())) {
|
||||
faceSet = BlockFace.NORTH;
|
||||
block = c3;
|
||||
}
|
||||
else if (!BlockGroup.NON_ATTACHABLE.contains(c4.getType())) {
|
||||
faceSet = BlockFace.SOUTH;
|
||||
block = c4;
|
||||
}
|
||||
|
||||
if (!Util.solidBlock(Util.getType(block.getRelative(BlockFace.EAST)))) {
|
||||
face = BlockFace.EAST;
|
||||
}
|
||||
else if (!Util.solidBlock(Util.getType(block.getRelative(BlockFace.NORTH)))) {
|
||||
face = BlockFace.NORTH;
|
||||
}
|
||||
else if (!Util.solidBlock(Util.getType(block.getRelative(BlockFace.WEST)))) {
|
||||
face = BlockFace.WEST;
|
||||
}
|
||||
else if (!Util.solidBlock(Util.getType(block.getRelative(BlockFace.SOUTH)))) {
|
||||
face = BlockFace.SOUTH;
|
||||
}
|
||||
}
|
||||
else if (!Util.solidBlock(Util.getType(block.getRelative(BlockFace.NORTH)))) {
|
||||
face = BlockFace.NORTH;
|
||||
}
|
||||
else if (!Util.solidBlock(Util.getType(block.getRelative(BlockFace.WEST)))) {
|
||||
face = BlockFace.WEST;
|
||||
}
|
||||
else if (!Util.solidBlock(Util.getType(block.getRelative(BlockFace.SOUTH)))) {
|
||||
face = BlockFace.SOUTH;
|
||||
else {
|
||||
faceSet = hangingFace;
|
||||
face = hangingFace;
|
||||
}
|
||||
|
||||
if (faceSet != null && face != null) {
|
||||
|
|
@ -105,8 +124,10 @@ public class HangingUtil {
|
|||
}
|
||||
}
|
||||
}
|
||||
Block spawnBlock = block.getRelative(face);
|
||||
Util.setTypeAndData(spawnBlock, Material.AIR, null, true);
|
||||
Block spawnBlock = hangingFace != null ? block : block.getRelative(face);
|
||||
if (hangingFace == null) {
|
||||
Util.setTypeAndData(spawnBlock, Material.AIR, null, true);
|
||||
}
|
||||
Painting hanging = null;
|
||||
try {
|
||||
hanging = block.getWorld().spawn(spawnBlock.getLocation(), Painting.class);
|
||||
|
|
@ -121,8 +142,10 @@ public class HangingUtil {
|
|||
}
|
||||
else if (BukkitAdapter.ADAPTER.isItemFrame(rowType)) {
|
||||
try {
|
||||
Block spawnBlock = block.getRelative(face);
|
||||
Util.setTypeAndData(spawnBlock, Material.AIR, null, true);
|
||||
Block spawnBlock = hangingFace != null ? block : block.getRelative(face);
|
||||
if (hangingFace == null) {
|
||||
Util.setTypeAndData(spawnBlock, Material.AIR, null, true);
|
||||
}
|
||||
Class itemFrame = BukkitAdapter.ADAPTER.getFrameClass(rowType);
|
||||
Entity entity = block.getWorld().spawn(spawnBlock.getLocation(), itemFrame);
|
||||
if (entity instanceof ItemFrame) {
|
||||
|
|
@ -148,14 +171,26 @@ public class HangingUtil {
|
|||
}, delay);
|
||||
}
|
||||
|
||||
public static void removeHanging(final BlockState block, int delay) {
|
||||
public static void removeHanging(final BlockState block, final String hangingData, int delay) {
|
||||
Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(CoreProtect.getInstance(), () -> {
|
||||
try {
|
||||
BlockFace hangingFace = null;
|
||||
if (hangingData != null && !hangingData.contains(":") && hangingData.contains("=")) {
|
||||
try {
|
||||
hangingFace = BlockFace.valueOf(hangingData.split("=")[1].toUpperCase(Locale.ROOT));
|
||||
}
|
||||
catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
for (Entity e : block.getChunk().getEntities()) {
|
||||
if (e instanceof ItemFrame || e instanceof Painting) {
|
||||
Location el = e.getLocation();
|
||||
if (el.getBlockX() == block.getX() && el.getBlockY() == block.getY() && el.getBlockZ() == block.getZ()) {
|
||||
e.remove();
|
||||
if (hangingFace == null || ((Hanging) e).getFacing() == hangingFace) {
|
||||
e.remove();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue