SteamWar/BauSystem2.0
Archiviert
12
0
Signed-off-by: yoyosource <yoyosource@nidido.de>
Dieser Commit ist enthalten in:
yoyosource 2022-05-19 16:38:10 +02:00
Ursprung 3813e9206b
Commit d3e1f54124
3 geänderte Dateien mit 18 neuen und 25 gelöschten Zeilen

Datei anzeigen

@ -46,24 +46,23 @@ public class SmartPlaceListener implements Listener {
@EventHandler @EventHandler
public void onBlockPlace(BlockPlaceEvent event) { public void onBlockPlace(BlockPlaceEvent event) {
if (event.getPlayer().isSneaking() && Config.getInstance().get(event.getPlayer()).getPlainValueOrDefault("smartPlace", false)) { if (!Config.getInstance().get(event.getPlayer()).getPlainValueOrDefault("smartPlace", false)) return;
SmartPlaceBehaviour.SmartPlaceResult smartPlaceResult = SmartPlaceBehaviour.SmartPlaceResult.IGNORED; SmartPlaceBehaviour.SmartPlaceResult smartPlaceResult = SmartPlaceBehaviour.SmartPlaceResult.IGNORED;
for (SmartPlaceBehaviour smartPlaceBehaviour : smartPlaceBehaviours) { for (SmartPlaceBehaviour smartPlaceBehaviour : smartPlaceBehaviours) {
if (smartPlaceBehaviour.getType() == SmartPlaceBehaviour.SmartPlaceType.PLACE) { if (smartPlaceBehaviour.getType() == SmartPlaceBehaviour.SmartPlaceType.PLACE) {
smartPlaceBehaviour.place(event); smartPlaceResult = smartPlaceBehaviour.place(event);
} }
if (smartPlaceResult == SmartPlaceBehaviour.SmartPlaceResult.APPLIED) { if (smartPlaceResult == SmartPlaceBehaviour.SmartPlaceResult.APPLIED) {
break; break;
} }
} }
} }
}
@EventHandler @EventHandler
public void onPlayerInteract(PlayerInteractEvent event) { public void onPlayerInteract(PlayerInteractEvent event) {
if (!Config.getInstance().get(event.getPlayer()).getPlainValueOrDefault("smartPlace", false)) return;
if (event.getAction() != Action.RIGHT_CLICK_BLOCK) return; if (event.getAction() != Action.RIGHT_CLICK_BLOCK) return;
if (event.getPlayer().getGameMode() == GameMode.SPECTATOR) return; if (event.getPlayer().getGameMode() == GameMode.SPECTATOR) return;
if (!Config.getInstance().get(event.getPlayer()).getPlainValueOrDefault("smartPlace", false)) return;
for (SmartPlaceBehaviour smartPlaceBehaviour : smartPlaceBehaviours) { for (SmartPlaceBehaviour smartPlaceBehaviour : smartPlaceBehaviours) {
SmartPlaceBehaviour.SmartPlaceResult smartPlaceResult = SmartPlaceBehaviour.SmartPlaceResult.IGNORED; SmartPlaceBehaviour.SmartPlaceResult smartPlaceResult = SmartPlaceBehaviour.SmartPlaceResult.IGNORED;

Datei anzeigen

@ -39,7 +39,7 @@ public class BlockPlaceBehaviour implements SmartPlaceBehaviour {
@Override @Override
public SmartPlaceResult place(BlockPlaceEvent event) { public SmartPlaceResult place(BlockPlaceEvent event) {
if (event.getBlockAgainst().getType().isInteractable()) { if (!event.getPlayer().isSneaking()) {
return SmartPlaceResult.IGNORED; return SmartPlaceResult.IGNORED;
} }

Datei anzeigen

@ -43,26 +43,20 @@ public class BlockRotatingBehaviour implements SmartPlaceBehaviour {
@Override @Override
public SmartPlaceResult interact(PlayerInteractEvent event) { public SmartPlaceResult interact(PlayerInteractEvent event) {
if (event.getClickedBlock().getType() == event.getMaterial() || event.getMaterial() == Material.HOPPER) {
if (!(event.getClickedBlock().getState() instanceof InventoryHolder)) { if (!(event.getClickedBlock().getState() instanceof InventoryHolder)) {
return SmartPlaceResult.IGNORED; return SmartPlaceResult.IGNORED;
} }
} else {
BlockData blockData = event.getMaterial().createBlockData(); BlockData blockData = event.getMaterial().createBlockData();
if (blockData instanceof Directional) { if (!(blockData instanceof Directional) && !(blockData instanceof Rotatable)) {
return SmartPlaceResult.IGNORED; return SmartPlaceResult.IGNORED;
} }
if (blockData instanceof Rotatable) {
return SmartPlaceResult.IGNORED;
}
}
// TODO: Fix block setting
event.setUseInteractedBlock(Event.Result.DENY); event.setUseInteractedBlock(Event.Result.DENY);
World world = event.getPlayer().getWorld(); World world = event.getPlayer().getWorld();
Block block = world.getBlockAt(event.getClickedBlock().getX() + event.getBlockFace().getModX(), event.getClickedBlock().getY() + event.getBlockFace().getModY(), event.getClickedBlock().getZ() + event.getBlockFace().getModZ()); Block block = world.getBlockAt(event.getClickedBlock().getX() + event.getBlockFace().getModX(), event.getClickedBlock().getY() + event.getBlockFace().getModY(), event.getClickedBlock().getZ() + event.getBlockFace().getModZ());
block.setType(event.getMaterial()); block.setType(event.getMaterial());
BlockData blockData = event.getItem().getType().createBlockData(); blockData = event.getItem().getType().createBlockData();
BlockFace blockFace = event.getBlockFace(); BlockFace blockFace = event.getBlockFace();
if (block.getType() == Material.HOPPER || block.getType() == Material.OBSERVER) { if (block.getType() == Material.HOPPER || block.getType() == Material.OBSERVER) {
blockFace = blockFace.getOppositeFace(); blockFace = blockFace.getOppositeFace();