SteamWar/BauSystem2.0
Archiviert
12
0

QOL #203

Zusammengeführt
YoyoNow hat 44 Commits von QOL nach master 2023-10-06 14:59:48 +02:00 zusammengeführt
2 geänderte Dateien mit 24 neuen und 16 gelöschten Zeilen
Nur Änderungen aus Commit cc8c6ba61d werden angezeigt - Alle Commits anzeigen

Datei anzeigen

@ -80,6 +80,9 @@ public class SmartPlaceListener implements Listener {
} }
player.playSound(block.getLocation(), soundGroup.getPlaceSound(), soundGroup.getVolume() * 0.8F, soundGroup.getPitch() * 0.8F); 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 // Fix Double sound for original player
} }

Datei anzeigen

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