mirror of
https://github.com/PlayPro/CoreProtect.git
synced 2024-11-28 12:55:34 +01:00
Fixed item frames and paintings not logging directional data
This commit is contained in:
parent
7398f7dfe6
commit
e462e68806
@ -253,17 +253,17 @@ public class Queue {
|
|||||||
queueStandardData(consumerId, currentConsumer, new String[] { user, null }, new Object[] { block, type });
|
queueStandardData(consumerId, currentConsumer, new String[] { user, null }, new Object[] { block, type });
|
||||||
}
|
}
|
||||||
|
|
||||||
protected static void queueHangingRemove(String user, BlockState block, int delay) {
|
protected static void queueHangingRemove(String user, BlockState block, String blockData, int delay) {
|
||||||
int currentConsumer = Consumer.currentConsumer;
|
int currentConsumer = Consumer.currentConsumer;
|
||||||
int consumerId = Consumer.newConsumerId(currentConsumer);
|
int consumerId = Consumer.newConsumerId(currentConsumer);
|
||||||
addConsumer(currentConsumer, new Object[] { consumerId, Process.HANGING_REMOVE, null, 0, null, 0, delay, null });
|
addConsumer(currentConsumer, new Object[] { consumerId, Process.HANGING_REMOVE, null, 0, null, 0, delay, blockData });
|
||||||
queueStandardData(consumerId, currentConsumer, new String[] { user, null }, block);
|
queueStandardData(consumerId, currentConsumer, new String[] { user, null }, block);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected static void queueHangingSpawn(String user, BlockState block, Material type, int data, int delay) {
|
protected static void queueHangingSpawn(String user, BlockState block, Material type, String blockData, int data, int delay) {
|
||||||
int currentConsumer = Consumer.currentConsumer;
|
int currentConsumer = Consumer.currentConsumer;
|
||||||
int consumerId = Consumer.newConsumerId(currentConsumer);
|
int consumerId = Consumer.newConsumerId(currentConsumer);
|
||||||
addConsumer(currentConsumer, new Object[] { consumerId, Process.HANGING_SPAWN, type, data, null, 0, delay, null });
|
addConsumer(currentConsumer, new Object[] { consumerId, Process.HANGING_SPAWN, type, data, null, 0, delay, blockData });
|
||||||
queueStandardData(consumerId, currentConsumer, new String[] { user, null }, block);
|
queueStandardData(consumerId, currentConsumer, new String[] { user, null }, block);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -281,7 +281,7 @@ public class Queue {
|
|||||||
queueStandardData(consumerId, currentConsumer, new String[] { null, null }, data);
|
queueStandardData(consumerId, currentConsumer, new String[] { null, null }, data);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected static void queueNaturalBlockBreak(String user, BlockState block, Block relative, Material type, int data) {
|
protected static void queueNaturalBlockBreak(String user, BlockState block, Block relative, Material type, String blockData, int data) {
|
||||||
List<BlockState> blockStates = new ArrayList<>();
|
List<BlockState> blockStates = new ArrayList<>();
|
||||||
if (relative != null) {
|
if (relative != null) {
|
||||||
blockStates.add(relative.getState());
|
blockStates.add(relative.getState());
|
||||||
@ -289,7 +289,7 @@ public class Queue {
|
|||||||
|
|
||||||
int currentConsumer = Consumer.currentConsumer;
|
int currentConsumer = Consumer.currentConsumer;
|
||||||
int consumerId = Consumer.newConsumerId(currentConsumer);
|
int consumerId = Consumer.newConsumerId(currentConsumer);
|
||||||
addConsumer(currentConsumer, new Object[] { consumerId, Process.NATURAL_BLOCK_BREAK, type, data, null, 0, 0, null });
|
addConsumer(currentConsumer, new Object[] { consumerId, Process.NATURAL_BLOCK_BREAK, type, data, null, 0, 0, blockData });
|
||||||
Consumer.consumerBlockList.get(currentConsumer).put(consumerId, blockStates);
|
Consumer.consumerBlockList.get(currentConsumer).put(consumerId, blockStates);
|
||||||
queueStandardData(consumerId, currentConsumer, new String[] { user, null }, block);
|
queueStandardData(consumerId, currentConsumer, new String[] { user, null }, block);
|
||||||
}
|
}
|
||||||
|
@ -25,7 +25,7 @@ class BlockBreakProcess {
|
|||||||
SkullBreakLogger.log(preparedStmt, preparedStmtSkulls, batchCount, user, block);
|
SkullBreakLogger.log(preparedStmt, preparedStmtSkulls, batchCount, user, block);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
BlockBreakLogger.log(preparedStmt, batchCount, user, block.getLocation(), Util.getBlockId(blockType), blockDataId, meta, block.getBlockData().getAsString());
|
BlockBreakLogger.log(preparedStmt, batchCount, user, block.getLocation(), Util.getBlockId(blockType), blockDataId, meta, block.getBlockData().getAsString(), blockData);
|
||||||
if (forceData == 5) { // Fix for doors
|
if (forceData == 5) { // Fix for doors
|
||||||
if ((blockType == Material.IRON_DOOR || BlockGroup.DOORS.contains(blockType)) && (replaceType != Material.IRON_DOOR && !BlockGroup.DOORS.contains(replaceType))) {
|
if ((blockType == Material.IRON_DOOR || BlockGroup.DOORS.contains(blockType)) && (replaceType != Material.IRON_DOOR && !BlockGroup.DOORS.contains(replaceType))) {
|
||||||
Door door = (Door) block.getBlockData();
|
Door door = (Door) block.getBlockData();
|
||||||
@ -33,7 +33,7 @@ class BlockBreakProcess {
|
|||||||
blockData = door.getAsString();
|
blockData = door.getAsString();
|
||||||
Location location = block.getLocation();
|
Location location = block.getLocation();
|
||||||
location.setY(location.getY() + 1);
|
location.setY(location.getY() + 1);
|
||||||
BlockBreakLogger.log(preparedStmt, batchCount, user, location, Util.getBlockId(blockType), 0, null, blockData);
|
BlockBreakLogger.log(preparedStmt, batchCount, user, location, Util.getBlockId(blockType), 0, null, blockData, null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -6,10 +6,10 @@ import net.coreprotect.utility.entity.HangingUtil;
|
|||||||
|
|
||||||
class HangingRemoveProcess {
|
class HangingRemoveProcess {
|
||||||
|
|
||||||
static void process(Object object, int delay) {
|
static void process(Object object, String hangingData, int delay) {
|
||||||
if (object instanceof BlockState) {
|
if (object instanceof BlockState) {
|
||||||
BlockState block = (BlockState) object;
|
BlockState block = (BlockState) object;
|
||||||
HangingUtil.removeHanging(block, delay);
|
HangingUtil.removeHanging(block, hangingData, delay);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -7,10 +7,10 @@ import net.coreprotect.utility.entity.HangingUtil;
|
|||||||
|
|
||||||
class HangingSpawnProcess {
|
class HangingSpawnProcess {
|
||||||
|
|
||||||
static void process(Object object, Material type, int data, int delay) {
|
static void process(Object object, Material type, int data, String hangingData, int delay) {
|
||||||
if (object instanceof BlockState) {
|
if (object instanceof BlockState) {
|
||||||
BlockState block = (BlockState) object;
|
BlockState block = (BlockState) object;
|
||||||
HangingUtil.spawnHanging(block, type, data, delay);
|
HangingUtil.spawnHanging(block, type, hangingData, data, delay);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -15,7 +15,7 @@ import net.coreprotect.utility.Util;
|
|||||||
|
|
||||||
class NaturalBlockBreakProcess {
|
class NaturalBlockBreakProcess {
|
||||||
|
|
||||||
static void process(Statement statement, PreparedStatement preparedStmt, int batchCount, int processId, int id, String user, Object object, Material blockType, int blockData) {
|
static void process(Statement statement, PreparedStatement preparedStmt, int batchCount, int processId, int id, String user, Object object, Material blockType, int blockData, String overrideData) {
|
||||||
if (object instanceof BlockState) {
|
if (object instanceof BlockState) {
|
||||||
BlockState block = (BlockState) object;
|
BlockState block = (BlockState) object;
|
||||||
Map<Integer, List<BlockState>> blockLists = Consumer.consumerBlockList.get(processId);
|
Map<Integer, List<BlockState>> blockLists = Consumer.consumerBlockList.get(processId);
|
||||||
@ -28,7 +28,7 @@ class NaturalBlockBreakProcess {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
blockLists.remove(id);
|
blockLists.remove(id);
|
||||||
BlockBreakLogger.log(preparedStmt, batchCount, user, block.getLocation(), Util.getBlockId(blockType), blockData, null, block.getBlockData().getAsString());
|
BlockBreakLogger.log(preparedStmt, batchCount, user, block.getLocation(), Util.getBlockId(blockType), blockData, null, block.getBlockData().getAsString(), overrideData);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -196,13 +196,13 @@ public class Process {
|
|||||||
EntitySpawnProcess.process(statement, object, forceData);
|
EntitySpawnProcess.process(statement, object, forceData);
|
||||||
break;
|
break;
|
||||||
case Process.HANGING_REMOVE:
|
case Process.HANGING_REMOVE:
|
||||||
HangingRemoveProcess.process(object, forceData);
|
HangingRemoveProcess.process(object, (String) data[7], forceData);
|
||||||
break;
|
break;
|
||||||
case Process.HANGING_SPAWN:
|
case Process.HANGING_SPAWN:
|
||||||
HangingSpawnProcess.process(object, blockType, blockData, forceData);
|
HangingSpawnProcess.process(object, blockType, blockData, (String) data[7], forceData);
|
||||||
break;
|
break;
|
||||||
case Process.NATURAL_BLOCK_BREAK:
|
case Process.NATURAL_BLOCK_BREAK:
|
||||||
NaturalBlockBreakProcess.process(statement, preparedStmtBlocks, i, processId, id, user, object, blockType, blockData);
|
NaturalBlockBreakProcess.process(statement, preparedStmtBlocks, i, processId, id, user, object, blockType, blockData, (String) data[7]);
|
||||||
break;
|
break;
|
||||||
case Process.MATERIAL_INSERT:
|
case Process.MATERIAL_INSERT:
|
||||||
MaterialInsertProcess.process(preparedStmtMaterials, statement, i, object, forceData);
|
MaterialInsertProcess.process(preparedStmtMaterials, statement, i, object, forceData);
|
||||||
|
@ -28,7 +28,7 @@ class StructureGrowthProcess {
|
|||||||
int count = 0;
|
int count = 0;
|
||||||
for (BlockState blockState : blockStates) {
|
for (BlockState blockState : blockStates) {
|
||||||
if (count < replaceBlockCount) {
|
if (count < replaceBlockCount) {
|
||||||
BlockBreakLogger.log(preparedStmt, batchCount, user, blockState.getLocation(), Util.getBlockId(blockState.getType()), 0, null, blockState.getBlockData().getAsString());
|
BlockBreakLogger.log(preparedStmt, batchCount, user, blockState.getLocation(), Util.getBlockId(blockState.getType()), 0, null, blockState.getBlockData().getAsString(), null);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
BlockPlaceLogger.log(preparedStmt, batchCount, user, blockState, 0, 0, null, -1, false, null, null, null);
|
BlockPlaceLogger.log(preparedStmt, batchCount, user, blockState, 0, 0, null, -1, false, null, null, null);
|
||||||
|
@ -338,7 +338,7 @@ public class Rollback extends Queue {
|
|||||||
}
|
}
|
||||||
|
|
||||||
BlockData blockData = null;
|
BlockData blockData = null;
|
||||||
if (blockDataString != null && blockDataString.length() > 0) {
|
if (blockDataString != null && blockDataString.contains(":")) {
|
||||||
try {
|
try {
|
||||||
blockData = Bukkit.getServer().createBlockData(blockDataString);
|
blockData = Bukkit.getServer().createBlockData(blockDataString);
|
||||||
}
|
}
|
||||||
@ -564,11 +564,11 @@ public class Rollback extends Queue {
|
|||||||
|
|
||||||
if ((rowType == Material.AIR) && ((BukkitAdapter.ADAPTER.isItemFrame(oldTypeMaterial)) || (oldTypeMaterial == Material.PAINTING))) {
|
if ((rowType == Material.AIR) && ((BukkitAdapter.ADAPTER.isItemFrame(oldTypeMaterial)) || (oldTypeMaterial == Material.PAINTING))) {
|
||||||
int delay = Util.getHangingDelay(hangingDelay, rowWorldId, rowX, rowY, rowZ);
|
int delay = Util.getHangingDelay(hangingDelay, rowWorldId, rowX, rowY, rowZ);
|
||||||
Queue.queueHangingRemove(rowUser, block.getState(), delay);
|
Queue.queueHangingRemove(rowUser, block.getState(), blockDataString, delay);
|
||||||
}
|
}
|
||||||
else if ((BukkitAdapter.ADAPTER.isItemFrame(rowType)) || (rowType == Material.PAINTING)) {
|
else if ((BukkitAdapter.ADAPTER.isItemFrame(rowType)) || (rowType == Material.PAINTING)) {
|
||||||
int delay = Util.getHangingDelay(hangingDelay, rowWorldId, rowX, rowY, rowZ);
|
int delay = Util.getHangingDelay(hangingDelay, rowWorldId, rowX, rowY, rowZ);
|
||||||
Queue.queueHangingSpawn(rowUser, block.getState(), rowType, rowData, delay);
|
Queue.queueHangingSpawn(rowUser, block.getState(), rowType, blockDataString, rowData, delay);
|
||||||
}
|
}
|
||||||
else if ((rowType == Material.ARMOR_STAND)) {
|
else if ((rowType == Material.ARMOR_STAND)) {
|
||||||
Location location1 = block.getLocation();
|
Location location1 = block.getLocation();
|
||||||
|
@ -8,6 +8,7 @@ import org.bukkit.Location;
|
|||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
|
|
||||||
import net.coreprotect.CoreProtect;
|
import net.coreprotect.CoreProtect;
|
||||||
|
import net.coreprotect.bukkit.BukkitAdapter;
|
||||||
import net.coreprotect.config.ConfigHandler;
|
import net.coreprotect.config.ConfigHandler;
|
||||||
import net.coreprotect.database.statement.BlockStatement;
|
import net.coreprotect.database.statement.BlockStatement;
|
||||||
import net.coreprotect.database.statement.UserStatement;
|
import net.coreprotect.database.statement.UserStatement;
|
||||||
@ -21,7 +22,7 @@ public class BlockBreakLogger {
|
|||||||
throw new IllegalStateException("Database class");
|
throw new IllegalStateException("Database class");
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void log(PreparedStatement preparedStmt, int batchCount, String user, Location location, int type, int data, List<Object> meta, String blockData) {
|
public static void log(PreparedStatement preparedStmt, int batchCount, String user, Location location, int type, int data, List<Object> meta, String blockData, String overrideData) {
|
||||||
try {
|
try {
|
||||||
if (ConfigHandler.blacklist.get(user.toLowerCase(Locale.ROOT)) != null || location == null) {
|
if (ConfigHandler.blacklist.get(user.toLowerCase(Locale.ROOT)) != null || location == null) {
|
||||||
return;
|
return;
|
||||||
@ -42,6 +43,9 @@ public class BlockBreakLogger {
|
|||||||
if (checkType == Material.LECTERN) {
|
if (checkType == Material.LECTERN) {
|
||||||
blockData = blockData.replaceFirst("has_book=true", "has_book=false");
|
blockData = blockData.replaceFirst("has_book=true", "has_book=false");
|
||||||
}
|
}
|
||||||
|
else if (checkType == Material.PAINTING || BukkitAdapter.ADAPTER.isItemFrame(checkType)) {
|
||||||
|
blockData = overrideData;
|
||||||
|
}
|
||||||
|
|
||||||
CoreProtectPreLogEvent event = new CoreProtectPreLogEvent(user);
|
CoreProtectPreLogEvent event = new CoreProtectPreLogEvent(user);
|
||||||
CoreProtect.getInstance().getServer().getPluginManager().callEvent(event);
|
CoreProtect.getInstance().getServer().getPluginManager().callEvent(event);
|
||||||
|
@ -36,7 +36,7 @@ public class SkullBreakLogger {
|
|||||||
keys.close();
|
keys.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
BlockBreakLogger.log(preparedStmt, batchCount, user, block.getLocation(), type, skullKey, null, block.getBlockData().getAsString());
|
BlockBreakLogger.log(preparedStmt, batchCount, user, block.getLocation(), type, skullKey, null, block.getBlockData().getAsString(), null);
|
||||||
}
|
}
|
||||||
catch (Exception e) {
|
catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
@ -119,11 +119,13 @@ public final class HangingBreakByEntityListener extends Queue implements Listene
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
String blockData = null;
|
||||||
Material material;
|
Material material;
|
||||||
int itemData = 0;
|
int itemData = 0;
|
||||||
if (entity instanceof ItemFrame) {
|
if (entity instanceof ItemFrame) {
|
||||||
material = BukkitAdapter.ADAPTER.getFrameType(entity);
|
material = BukkitAdapter.ADAPTER.getFrameType(entity);
|
||||||
ItemFrame itemframe = (ItemFrame) entity;
|
ItemFrame itemframe = (ItemFrame) entity;
|
||||||
|
blockData = "FACING=" + itemframe.getFacing().name();
|
||||||
|
|
||||||
if (itemframe.getItem() != null) {
|
if (itemframe.getItem() != null) {
|
||||||
itemData = Util.getBlockId(itemframe.getItem().getType());
|
itemData = Util.getBlockId(itemframe.getItem().getType());
|
||||||
@ -132,11 +134,12 @@ public final class HangingBreakByEntityListener extends Queue implements Listene
|
|||||||
else {
|
else {
|
||||||
material = Material.PAINTING;
|
material = Material.PAINTING;
|
||||||
Painting painting = (Painting) entity;
|
Painting painting = (Painting) entity;
|
||||||
|
blockData = "FACING=" + painting.getFacing().name();
|
||||||
itemData = Util.getArtId(painting.getArt().toString(), true);
|
itemData = Util.getArtId(painting.getArt().toString(), true);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!event.isCancelled() && Config.getConfig(blockEvent.getWorld()).BLOCK_BREAK && !inspecting) {
|
if (!event.isCancelled() && Config.getConfig(blockEvent.getWorld()).BLOCK_BREAK && !inspecting) {
|
||||||
Queue.queueBlockBreak(culprit, blockEvent, material, null, itemData);
|
Queue.queueBlockBreak(culprit, blockEvent, material, blockData, itemData);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -43,11 +43,13 @@ public final class HangingBreakListener extends Queue implements Listener {
|
|||||||
attachedBlock = hangingEntity.getLocation().getBlock().getRelative(attached);
|
attachedBlock = hangingEntity.getLocation().getBlock().getRelative(attached);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
String blockData = null;
|
||||||
Material material;
|
Material material;
|
||||||
int itemData = 0;
|
int itemData = 0;
|
||||||
if (entity instanceof ItemFrame) {
|
if (entity instanceof ItemFrame) {
|
||||||
material = BukkitAdapter.ADAPTER.getFrameType(entity);
|
material = BukkitAdapter.ADAPTER.getFrameType(entity);
|
||||||
ItemFrame itemframe = (ItemFrame) entity;
|
ItemFrame itemframe = (ItemFrame) entity;
|
||||||
|
blockData = "FACING=" + itemframe.getFacing().name();
|
||||||
|
|
||||||
if (itemframe.getItem() != null) {
|
if (itemframe.getItem() != null) {
|
||||||
itemData = Util.getBlockId(itemframe.getItem().getType());
|
itemData = Util.getBlockId(itemframe.getItem().getType());
|
||||||
@ -56,11 +58,12 @@ public final class HangingBreakListener extends Queue implements Listener {
|
|||||||
else {
|
else {
|
||||||
material = Material.PAINTING;
|
material = Material.PAINTING;
|
||||||
Painting painting = (Painting) entity;
|
Painting painting = (Painting) entity;
|
||||||
|
blockData = "FACING=" + painting.getFacing().name();
|
||||||
itemData = Util.getArtId(painting.getArt().toString(), true);
|
itemData = Util.getArtId(painting.getArt().toString(), true);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!event.isCancelled() && Config.getConfig(blockEvent.getWorld()).NATURAL_BREAK) {
|
if (!event.isCancelled() && Config.getConfig(blockEvent.getWorld()).NATURAL_BREAK) {
|
||||||
Queue.queueNaturalBlockBreak(causeName, blockEvent.getState(), attachedBlock, material, itemData);
|
Queue.queueNaturalBlockBreak(causeName, blockEvent.getState(), attachedBlock, material, blockData, itemData);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -26,16 +26,20 @@ public final class HangingPlaceListener extends Queue implements Listener {
|
|||||||
|
|
||||||
if (entity instanceof ItemFrame || entity instanceof Painting) {
|
if (entity instanceof ItemFrame || entity instanceof Painting) {
|
||||||
Block blockEvent = event.getEntity().getLocation().getBlock();
|
Block blockEvent = event.getEntity().getLocation().getBlock();
|
||||||
|
String blockData = null;
|
||||||
Material material;
|
Material material;
|
||||||
int artId;
|
int artId;
|
||||||
|
|
||||||
if (entity instanceof ItemFrame) {
|
if (entity instanceof ItemFrame) {
|
||||||
material = BukkitAdapter.ADAPTER.getFrameType(entity);
|
material = BukkitAdapter.ADAPTER.getFrameType(entity);
|
||||||
|
ItemFrame itemFrame = (ItemFrame) entity;
|
||||||
|
blockData = "FACING=" + itemFrame.getFacing().name();
|
||||||
artId = 0;
|
artId = 0;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
material = Material.PAINTING;
|
material = Material.PAINTING;
|
||||||
Painting painting = (Painting) entity;
|
Painting painting = (Painting) entity;
|
||||||
|
blockData = "FACING=" + painting.getFacing().name();
|
||||||
artId = Util.getArtId(painting.getArt().toString(), true);
|
artId = Util.getArtId(painting.getArt().toString(), true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -48,7 +52,7 @@ public final class HangingPlaceListener extends Queue implements Listener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!event.isCancelled() && Config.getConfig(blockEvent.getWorld()).BLOCK_PLACE && inspect == 0) {
|
if (!event.isCancelled() && Config.getConfig(blockEvent.getWorld()).BLOCK_PLACE && inspect == 0) {
|
||||||
Queue.queueBlockPlace(player.getName(), blockEvent.getState(), blockEvent.getType(), null, material, artId, 1, null);
|
Queue.queueBlockPlace(player.getName(), blockEvent.getState(), blockEvent.getType(), null, material, artId, 1, blockData);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -451,6 +451,15 @@ public class Util extends Queue {
|
|||||||
}
|
}
|
||||||
string = String.join(",", blockDataArray);
|
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 {
|
else {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
@ -483,7 +492,13 @@ public class Util extends Queue {
|
|||||||
blockDataArray.add(block);
|
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 {
|
else {
|
||||||
result = "";
|
result = "";
|
||||||
|
@ -10,6 +10,7 @@ import org.bukkit.block.Block;
|
|||||||
import org.bukkit.block.BlockFace;
|
import org.bukkit.block.BlockFace;
|
||||||
import org.bukkit.block.BlockState;
|
import org.bukkit.block.BlockState;
|
||||||
import org.bukkit.entity.Entity;
|
import org.bukkit.entity.Entity;
|
||||||
|
import org.bukkit.entity.Hanging;
|
||||||
import org.bukkit.entity.ItemFrame;
|
import org.bukkit.entity.ItemFrame;
|
||||||
import org.bukkit.entity.Painting;
|
import org.bukkit.entity.Painting;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
@ -26,7 +27,7 @@ public class HangingUtil {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings({ "unchecked", "rawtypes" })
|
@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(), () -> {
|
Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(CoreProtect.getInstance(), () -> {
|
||||||
try {
|
try {
|
||||||
Block block = blockstate.getBlock();
|
Block block = blockstate.getBlock();
|
||||||
@ -34,51 +35,69 @@ public class HangingUtil {
|
|||||||
int y = block.getY();
|
int y = block.getY();
|
||||||
int z = block.getZ();
|
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()) {
|
for (Entity e : block.getChunk().getEntities()) {
|
||||||
if ((BukkitAdapter.ADAPTER.isItemFrame(rowType) && e instanceof ItemFrame) || (rowType.equals(Material.PAINTING) && e instanceof Painting)) {
|
if ((BukkitAdapter.ADAPTER.isItemFrame(rowType) && e instanceof ItemFrame) || (rowType.equals(Material.PAINTING) && e instanceof Painting)) {
|
||||||
Location el = e.getLocation();
|
Location el = e.getLocation();
|
||||||
if (el.getBlockX() == x && el.getBlockY() == y && el.getBlockZ() == z) {
|
if (el.getBlockX() == x && el.getBlockY() == y && el.getBlockZ() == z) {
|
||||||
e.remove();
|
if (hangingFace == null || ((Hanging) e).getFacing() == hangingFace) {
|
||||||
break;
|
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;
|
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;
|
BlockFace face = null;
|
||||||
if (!Util.solidBlock(Util.getType(block.getRelative(BlockFace.EAST)))) {
|
if (hangingFace == null) {
|
||||||
face = BlockFace.EAST;
|
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)))) {
|
else {
|
||||||
face = BlockFace.NORTH;
|
faceSet = hangingFace;
|
||||||
}
|
face = hangingFace;
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (faceSet != null && face != null) {
|
if (faceSet != null && face != null) {
|
||||||
@ -105,8 +124,10 @@ public class HangingUtil {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Block spawnBlock = block.getRelative(face);
|
Block spawnBlock = hangingFace != null ? block : block.getRelative(face);
|
||||||
Util.setTypeAndData(spawnBlock, Material.AIR, null, true);
|
if (hangingFace == null) {
|
||||||
|
Util.setTypeAndData(spawnBlock, Material.AIR, null, true);
|
||||||
|
}
|
||||||
Painting hanging = null;
|
Painting hanging = null;
|
||||||
try {
|
try {
|
||||||
hanging = block.getWorld().spawn(spawnBlock.getLocation(), Painting.class);
|
hanging = block.getWorld().spawn(spawnBlock.getLocation(), Painting.class);
|
||||||
@ -121,8 +142,10 @@ public class HangingUtil {
|
|||||||
}
|
}
|
||||||
else if (BukkitAdapter.ADAPTER.isItemFrame(rowType)) {
|
else if (BukkitAdapter.ADAPTER.isItemFrame(rowType)) {
|
||||||
try {
|
try {
|
||||||
Block spawnBlock = block.getRelative(face);
|
Block spawnBlock = hangingFace != null ? block : block.getRelative(face);
|
||||||
Util.setTypeAndData(spawnBlock, Material.AIR, null, true);
|
if (hangingFace == null) {
|
||||||
|
Util.setTypeAndData(spawnBlock, Material.AIR, null, true);
|
||||||
|
}
|
||||||
Class itemFrame = BukkitAdapter.ADAPTER.getFrameClass(rowType);
|
Class itemFrame = BukkitAdapter.ADAPTER.getFrameClass(rowType);
|
||||||
Entity entity = block.getWorld().spawn(spawnBlock.getLocation(), itemFrame);
|
Entity entity = block.getWorld().spawn(spawnBlock.getLocation(), itemFrame);
|
||||||
if (entity instanceof ItemFrame) {
|
if (entity instanceof ItemFrame) {
|
||||||
@ -148,14 +171,26 @@ public class HangingUtil {
|
|||||||
}, delay);
|
}, 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(), () -> {
|
Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(CoreProtect.getInstance(), () -> {
|
||||||
try {
|
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()) {
|
for (Entity e : block.getChunk().getEntities()) {
|
||||||
if (e instanceof ItemFrame || e instanceof Painting) {
|
if (e instanceof ItemFrame || e instanceof Painting) {
|
||||||
Location el = e.getLocation();
|
Location el = e.getLocation();
|
||||||
if (el.getBlockX() == block.getX() && el.getBlockY() == block.getY() && el.getBlockZ() == block.getZ()) {
|
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…
Reference in New Issue
Block a user