QOL #203
@ -80,6 +80,9 @@ public class SmartPlaceListener implements Listener {
|
||||
}
|
||||
player.playSound(block.getLocation(), soundGroup.getPlaceSound(), soundGroup.getVolume() * 0.8F, soundGroup.getPitch() * 0.8F);
|
||||
});
|
||||
if (result.wasForced()) {
|
||||
event.getPlayer().playSound(block.getLocation(), soundGroup.getPlaceSound(), soundGroup.getVolume() * 0.8F, soundGroup.getPitch() * 0.8F);
|
||||
}
|
||||
}
|
||||
// Fix Double sound for original player
|
||||
}
|
||||
|
@ -39,6 +39,7 @@ import org.bukkit.util.RayTraceResult;
|
||||
import org.bukkit.util.Vector;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@UtilityClass
|
||||
@ -143,35 +144,36 @@ public class PlaceItemUtils {
|
||||
Material typeToPlace = ITEM_MATERIAL_TO_BLOCK_MATERIAL.getOrDefault(itemStack.getType(), itemStack.getType());
|
||||
|
||||
BlockData blockData = null;
|
||||
AtomicBoolean usedForcePlace = new AtomicBoolean();
|
||||
if (againstSide == BlockFace.NORTH || againstSide == BlockFace.SOUTH || againstSide == BlockFace.EAST || againstSide == BlockFace.WEST) {
|
||||
// Try Wall Placement first
|
||||
blockData = toBlockData(player, blockDataMeta, BLOCK_MATERIAL_TO_WALL_BLOCK_MATERIAL.getOrDefault(typeToPlace, typeToPlace));
|
||||
if (blockData != null && !canPlace(block, blockData, force)) {
|
||||
if (blockData != null && !canPlace(block, blockData, force, usedForcePlace)) {
|
||||
// Check if default Rotation from input could be valid
|
||||
BlockFace rotation = getRotation(blockData);
|
||||
setRotation(blockData, againstSide);
|
||||
if (!canPlace(block, blockData, force)) {
|
||||
if (!canPlace(block, blockData, force, usedForcePlace)) {
|
||||
setRotation(blockData, rotation);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Try default Placement
|
||||
if (blockData == null || !canPlace(block, blockData, force)) {
|
||||
if (blockData == null || !canPlace(block, blockData, force, usedForcePlace)) {
|
||||
blockData = toBlockData(player, blockDataMeta, typeToPlace);
|
||||
}
|
||||
|
||||
if (blockData != null && !canPlace(block, blockData, force)) {
|
||||
if (blockData != null && !canPlace(block, blockData, force, usedForcePlace)) {
|
||||
if (blockData instanceof FaceAttachable) {
|
||||
// FaceAttachable Blocks should be placed on the Ceiling/Floor if possible
|
||||
// This applies mainly to Lever and Buttons
|
||||
FaceAttachable faceAttachable = (FaceAttachable) blockData;
|
||||
boolean topFirst = isHitHalfTop(player);
|
||||
faceAttachable.setAttachedFace(topFirst ? FaceAttachable.AttachedFace.CEILING : FaceAttachable.AttachedFace.FLOOR);
|
||||
if (!canPlace(block, blockData, force)) {
|
||||
if (!canPlace(block, blockData, force, usedForcePlace)) {
|
||||
faceAttachable.setAttachedFace(topFirst ? FaceAttachable.AttachedFace.FLOOR : FaceAttachable.AttachedFace.CEILING);
|
||||
}
|
||||
if (!canPlace(block, blockData, force)) {
|
||||
if (!canPlace(block, blockData, force, usedForcePlace)) {
|
||||
return PlaceItemResult.NO_VALID_PLACEMENT;
|
||||
}
|
||||
}
|
||||
@ -263,10 +265,6 @@ public class PlaceItemUtils {
|
||||
redstoneWire.setFace(BlockFace.WEST, RedstoneWire.Connection.SIDE);
|
||||
}
|
||||
|
||||
if (force) {
|
||||
|
||||
}
|
||||
|
||||
if (rotateAway) {
|
||||
// Rotate the other way if rotateAway is set to true
|
||||
BlockFace blockFace = getRotation(blockData);
|
||||
@ -281,7 +279,7 @@ public class PlaceItemUtils {
|
||||
}
|
||||
|
||||
// Check if the Block can be build
|
||||
BlockCanBuildEvent blockCanBuildEvent = new BlockCanBuildEvent(against, player, blockData, canPlace(block, blockData, force));
|
||||
BlockCanBuildEvent blockCanBuildEvent = new BlockCanBuildEvent(against, player, blockData, canPlace(block, blockData, force, usedForcePlace));
|
||||
Bukkit.getPluginManager().callEvent(blockCanBuildEvent);
|
||||
if (!blockCanBuildEvent.isBuildable()) return PlaceItemResult.NO_BUILD;
|
||||
|
||||
@ -338,7 +336,7 @@ public class PlaceItemUtils {
|
||||
Bisected bisected = (Bisected) blockData;
|
||||
Block blockAbove = block.getRelative(0, 1, 0);
|
||||
bisected.setHalf(Bisected.Half.TOP);
|
||||
if (canPlace(blockAbove, blockData, force)) {
|
||||
if (canPlace(blockAbove, blockData, force, usedForcePlace)) {
|
||||
if (blockData instanceof Waterlogged) {
|
||||
((Waterlogged) blockData).setWaterlogged(blockAbove.getType() == Material.WATER);
|
||||
}
|
||||
@ -375,7 +373,7 @@ public class PlaceItemUtils {
|
||||
SoundGroup soundGroup = blockData.getSoundGroup();
|
||||
block.getWorld().playSound(block.getLocation(), soundGroup.getPlaceSound(), soundGroup.getVolume() * 0.8F, soundGroup.getPitch() * 0.8F);
|
||||
}
|
||||
return PlaceItemResult.SUCCESS;
|
||||
return usedForcePlace.get() ? PlaceItemResult.SUCCESS_FORCE : PlaceItemResult.SUCCESS;
|
||||
}
|
||||
|
||||
public BlockFace[] axis = { BlockFace.NORTH, BlockFace.EAST, BlockFace.SOUTH, BlockFace.WEST };
|
||||
@ -523,9 +521,11 @@ public class PlaceItemUtils {
|
||||
return blockData.getClass().getName().contains("Tall");
|
||||
}
|
||||
|
||||
private boolean canPlace(Block block, BlockData blockData, boolean force) {
|
||||
if (!force && !block.canPlace(blockData)) return false;
|
||||
if (block.getType().isSolid()) return false;
|
||||
private boolean canPlace(Block block, BlockData blockData, boolean force, AtomicBoolean usedForcePlace) {
|
||||
if (!block.canPlace(blockData)) {
|
||||
if (force) usedForcePlace.set(true);
|
||||
return force;
|
||||
}
|
||||
return replaceables.contains(block.getType().name());
|
||||
}
|
||||
|
||||
@ -540,8 +540,13 @@ public class PlaceItemUtils {
|
||||
NO_DOUBLE_HIGH_BLOCK_SPACE(false),
|
||||
NO_PLACE_INSIDE_PLAYER(false),
|
||||
SUCCESS(true),
|
||||
SUCCESS_FORCE(true),
|
||||
;
|
||||
|
||||
private final boolean success;
|
||||
|
||||
public boolean wasForced() {
|
||||
return this == SUCCESS_FORCE;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
In neuem Issue referenzieren
Einen Benutzer sperren