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
Nur Änderungen aus Commit b956f34a7e werden angezeigt - Alle Commits anzeigen

Datei anzeigen

@ -20,11 +20,15 @@
package de.steamwar.bausystem.features.util;
import de.steamwar.bausystem.BauSystem;
import de.steamwar.entity.REntityServer;
import de.steamwar.entity.RFallingBlockEntity;
import de.steamwar.linkage.Linked;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.ToString;
import net.md_5.bungee.api.ChatMessageType;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
@ -37,10 +41,7 @@ import org.bukkit.event.Listener;
import org.bukkit.event.block.Action;
import org.bukkit.event.player.PlayerInteractEvent;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Set;
import java.util.*;
import java.util.concurrent.atomic.AtomicBoolean;
@Linked
@ -59,6 +60,7 @@ public class PistonCalculator implements Listener {
boolean pulling = blockType == Material.STICKY_PISTON && (clickedBlock.getRelative(piston.getFacing()).getType() == Material.AIR || piston.isExtended());
CalculationResult result = calc(clickedBlock, piston.getFacing(), (pulling ? piston.getFacing().getOppositeFace() : piston.getFacing()));
result.entityServer.addPlayer(event.getPlayer());
BauSystem.MESSAGE.sendPrefixless("PISTON_INFO", event.getPlayer(), ChatMessageType.ACTION_BAR, result.unmovable ? "§c" : (result.tooMany ? "§e" : "§a"), result.amount);
}
@ -66,7 +68,7 @@ public class PistonCalculator implements Listener {
private CalculationResult calc(Block origin, BlockFace facing, BlockFace direction) {
Set<Block> blockSet = new HashSet<>();
AtomicBoolean unmovable = new AtomicBoolean();
Set<Location> unmovable = new HashSet<>();
Block calcOrigin = origin;
if (facing != direction) calcOrigin = origin.getRelative(facing, 3);
@ -95,21 +97,30 @@ public class PistonCalculator implements Listener {
blockSet.remove(origin);
if (facing != direction) blockSet.remove(origin.getRelative(facing, 1));
return new CalculationResult(blockSet.size(), blockSet.size() > 12, unmovable.get());
REntityServer entityServer = new REntityServer();
for (Location loc : unmovable) {
RFallingBlockEntity rFallingBlockEntity = new RFallingBlockEntity(entityServer, loc.clone().add(0.5, 0, 0.5), Material.RED_STAINED_GLASS);
rFallingBlockEntity.setGlowing(true);
rFallingBlockEntity.setNoGravity(true);
rFallingBlockEntity.setInvisible(true);
}
Bukkit.getScheduler().runTaskLater(BauSystem.getInstance(), entityServer::close, 20);
return new CalculationResult(blockSet.size(), blockSet.size() > 12, !unmovable.isEmpty(), entityServer);
}
private void calcDirection(Block origin, Block blockOrigin, Block calcOrigin, Block ignore, BlockFace facing, BlockFace direction, Set<Block> blockSet, List<Block> toCalc, AtomicBoolean unmovable) {
private void calcDirection(Block origin, Block blockOrigin, Block calcOrigin, Block ignore, BlockFace facing, BlockFace direction, Set<Block> blockSet, List<Block> toCalc, Set<Location> unmovable) {
for (int i = 1; i < 13; i++) {
Block block = calcOrigin.getRelative(direction, i);
if (block.equals(ignore)) return;
if (block.getPistonMoveReaction() == PistonMoveReaction.BREAK) return;
if (!isPiston(block) && (block.getPistonMoveReaction() == PistonMoveReaction.BLOCK || block.getPistonMoveReaction() == PistonMoveReaction.IGNORE || block.getState() instanceof TileState)) {
unmovable.set(true);
unmovable.add(block.getLocation());
return;
}
if (block.getType().isAir()) return;
if (facing == direction && block.equals(blockOrigin)) {
unmovable.set(true);
unmovable.add(block.getLocation());
return;
}
if (facing != direction && (block.equals(origin) || block.getRelative(facing.getOppositeFace()).equals(origin))) return;
@ -127,10 +138,10 @@ public class PistonCalculator implements Listener {
@AllArgsConstructor
@Getter
@ToString
private static class CalculationResult {
private int amount;
private boolean tooMany;
private boolean unmovable;
private REntityServer entityServer;
}
}