SteamWar/BauSystem2.0
Archiviert
12
0

Add PanzernAlgorithm

Signed-off-by: yoyosource <yoyosource@nidido.de>
Dieser Commit ist enthalten in:
yoyosource 2021-10-05 10:12:17 +02:00
Ursprung 423f6247c0
Commit 3401f644a1
9 geänderte Dateien mit 351 neuen und 77 gelöschten Zeilen

Datei anzeigen

@ -24,15 +24,17 @@ import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.block.data.Bisected;
import org.bukkit.block.data.Directional;
import org.bukkit.block.data.type.Stairs;
import java.util.HashSet;
import java.util.Set;
import java.util.*;
public class Panzern {
private static List<PanzernAlgorithm> panzernAlgorithmList = new ArrayList<>();
public static void add(PanzernAlgorithm panzernAlgorithm) {
panzernAlgorithmList.add(panzernAlgorithm);
}
private static final BlockFace[] BLOCK_FACES = new BlockFace[]{BlockFace.NORTH, BlockFace.SOUTH, BlockFace.EAST, BlockFace.WEST, BlockFace.UP, BlockFace.DOWN};
private Set<Location> current = new HashSet<>();
@ -66,85 +68,51 @@ public class Panzern {
Location toCheck = current.iterator().next();
current.remove(toCheck);
Set<Location> adjacent = new HashSet<>();
boolean hasRedstone = false;
boolean belowRedstone = false;
boolean belowCarpet = false;
boolean adjacentPiston = false;
boolean adjacentSlime = false;
Map<BlockFace, Block> adjacent = new HashMap<>();
Set<Material> adjacentMaterials = new HashSet<>();
for (BlockFace blockFace : BLOCK_FACES) {
Location now = toCheck.clone().add(blockFace.getModX(), blockFace.getModY(), blockFace.getModZ());
if (inRegion(now)) {
adjacent.add(now);
}
Block block = world.getBlockAt(now);
if (block.getType() == Material.SLIME_BLOCK || block.getType() == Material.HONEY_BLOCK) {
adjacentSlime = true;
}
if (block.getType() == Material.PISTON || block.getType() == Material.STICKY_PISTON) {
Directional directional = (Directional) block.getBlockData();
if (directional.getFacing() == blockFace.getOppositeFace()) {
adjacentPiston = true;
Block temp = world.getBlockAt(now);
adjacent.put(blockFace, temp);
adjacentMaterials.add(temp.getType());
}
}
if (blockFace != BlockFace.UP && blockFace != BlockFace.DOWN) {
hasRedstone |= block.getType() == Material.REDSTONE_WIRE;
}
if (blockFace == BlockFace.DOWN) {
belowRedstone |= block.getType() == Material.REDSTONE_WIRE;
belowCarpet |= block.getType().name().contains("CARPET");
}
if (blockFace == BlockFace.DOWN && stairCheck(now)) {
belowCarpet = true;
}
now = toCheck.clone().add(blockFace.getModX() * 2, blockFace.getModY() * 2, blockFace.getModZ() * 2);
Block blockOuter = world.getBlockAt(now);
if (blockFace == BlockFace.DOWN && stairCheck(now)) {
belowCarpet = true;
}
if (blockFace != BlockFace.DOWN && blockFace != BlockFace.UP) {
now = toCheck.clone().add(blockFace.getModX(), -2, blockFace.getModZ());
Block blockOuterOther = world.getBlockAt(now);
if (stairCheck(now)) {
Stairs stairs = (Stairs) blockOuterOther.getBlockData();
if (stairs.getFacing() == blockFace) {
belowCarpet = true;
}
}
}
if (block.getType().isAir()) {
continue;
}
if (blockOuter.getType() == Material.PISTON || blockOuter.getType() == Material.STICKY_PISTON) {
Directional directional = (Directional) blockOuter.getBlockData();
if (directional.getFacing() == blockFace.getOppositeFace()) {
adjacentPiston = true;
Block currentBlock = world.getBlockAt(toCheck);
PanzernResult panzernResult = PanzernResult.DEFAULT;
for (PanzernAlgorithm panzernAlgorithm : panzernAlgorithmList) {
PanzernResult temp = panzernAlgorithm.check(currentBlock, adjacent, adjacentMaterials);
if (temp != null && temp != PanzernResult.DEFAULT) {
panzernResult = temp;
break;
}
}
}
current.addAll(adjacent);
if (belowCarpet || adjacentPiston) {
emptyBlocks.add(toCheck);
switch (panzernResult) {
case EMPTY:
emptyBlocks.add(currentBlock.getLocation());
return;
}
if (adjacentSlime) {
world.getBlockAt(toCheck).setType(Material.JUKEBOX);
} else if (belowRedstone && hasRedstone) {
world.getBlockAt(toCheck).setType(slabMaterial);
} else {
world.getBlockAt(toCheck).setType(blockMaterial);
}
case SLAB:
currentBlock.setType(slabMaterial);
break;
case BLOCK:
case DEFAULT:
currentBlock.setType(blockMaterial);
break;
case UNMOVABLE:
currentBlock.setType(Material.JUKEBOX);
break;
default:
emptyBlocks.add(currentBlock.getLocation());
break;
}
private boolean stairCheck(Location location) {
Block block = world.getBlockAt(location);
if (block.getBlockData() instanceof Stairs) {
Stairs stairs = (Stairs) block.getBlockData();
return stairs.getHalf() == Bisected.Half.BOTTOM;
adjacent.forEach((blockFace, temp) -> {
if (temp.getType().isAir() && !emptyBlocks.contains(temp.getLocation())) {
current.add(temp.getLocation());
}
return false;
});
}
private boolean inRegion(Location location) {
@ -154,7 +122,7 @@ public class Panzern {
if (location.getBlockX() <= pos2.getBlockX()) {
if (location.getBlockY() <= pos2.getBlockY()) {
if (location.getBlockZ() <= pos2.getBlockZ()) {
return world.getBlockAt(location).getType().isAir() && !emptyBlocks.contains(location);
return true;
}
}
}

Datei anzeigen

@ -0,0 +1,34 @@
/*
* This file is a part of the SteamWar software.
*
* Copyright (C) 2021 SteamWar.de-Serverteam
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package de.steamwar.bausystem.features.panzern;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import java.util.Map;
import java.util.Set;
public interface PanzernAlgorithm {
final BlockFace[] BLOCK_FACES = new BlockFace[]{BlockFace.NORTH, BlockFace.SOUTH, BlockFace.EAST, BlockFace.WEST, BlockFace.UP, BlockFace.DOWN};
final BlockFace[] HORIZONTAL_FACES = new BlockFace[]{BlockFace.NORTH, BlockFace.SOUTH, BlockFace.EAST, BlockFace.WEST};
PanzernResult check(Block source, Map<BlockFace, Block> adjacent, Set<Material> adjacentMaterials);
}

Datei anzeigen

@ -0,0 +1,28 @@
/*
* This file is a part of the SteamWar software.
*
* Copyright (C) 2021 SteamWar.de-Serverteam
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package de.steamwar.bausystem.features.panzern;
public enum PanzernResult {
EMPTY,
SLAB,
UNMOVABLE,
BLOCK,
DEFAULT
}

Datei anzeigen

@ -0,0 +1,43 @@
/*
* This file is a part of the SteamWar software.
*
* Copyright (C) 2021 SteamWar.de-Serverteam
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package de.steamwar.bausystem.features.panzern.algorithms;
import de.steamwar.bausystem.features.panzern.PanzernAlgorithm;
import de.steamwar.bausystem.features.panzern.PanzernResult;
import de.steamwar.bausystem.linkage.LinkageType;
import de.steamwar.bausystem.linkage.Linked;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import java.util.Map;
import java.util.Set;
@Linked(LinkageType.PANZERN)
public class AdjacentHoney implements PanzernAlgorithm {
@Override
public PanzernResult check(Block source, Map<BlockFace, Block> adjacent, Set<Material> adjacentMaterials) {
if (adjacentMaterials.contains(Material.HONEY_BLOCK)) {
return PanzernResult.UNMOVABLE;
}
return PanzernResult.DEFAULT;
}
}

Datei anzeigen

@ -0,0 +1,43 @@
/*
* This file is a part of the SteamWar software.
*
* Copyright (C) 2021 SteamWar.de-Serverteam
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package de.steamwar.bausystem.features.panzern.algorithms;
import de.steamwar.bausystem.features.panzern.PanzernAlgorithm;
import de.steamwar.bausystem.features.panzern.PanzernResult;
import de.steamwar.bausystem.linkage.LinkageType;
import de.steamwar.bausystem.linkage.Linked;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import java.util.Map;
import java.util.Set;
@Linked(LinkageType.PANZERN)
public class AdjacentSlime implements PanzernAlgorithm {
@Override
public PanzernResult check(Block source, Map<BlockFace, Block> adjacent, Set<Material> adjacentMaterials) {
if (adjacentMaterials.contains(Material.SLIME_BLOCK)) {
return PanzernResult.UNMOVABLE;
}
return PanzernResult.DEFAULT;
}
}

Datei anzeigen

@ -0,0 +1,43 @@
/*
* This file is a part of the SteamWar software.
*
* Copyright (C) 2021 SteamWar.de-Serverteam
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package de.steamwar.bausystem.features.panzern.algorithms;
import de.steamwar.bausystem.features.panzern.PanzernAlgorithm;
import de.steamwar.bausystem.features.panzern.PanzernResult;
import de.steamwar.bausystem.linkage.LinkageType;
import de.steamwar.bausystem.linkage.Linked;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import java.util.Map;
import java.util.Set;
@Linked(LinkageType.PANZERN)
public class CarpetWalkWay implements PanzernAlgorithm {
@Override
public PanzernResult check(Block source, Map<BlockFace, Block> adjacent, Set<Material> adjacentMaterials) {
if (adjacent.containsKey(BlockFace.DOWN) && adjacent.get(BlockFace.DOWN).getType().name().contains("CARPET")) {
return PanzernResult.EMPTY;
}
return PanzernResult.DEFAULT;
}
}

Datei anzeigen

@ -0,0 +1,49 @@
/*
* This file is a part of the SteamWar software.
*
* Copyright (C) 2021 SteamWar.de-Serverteam
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package de.steamwar.bausystem.features.panzern.algorithms;
import de.steamwar.bausystem.features.panzern.PanzernAlgorithm;
import de.steamwar.bausystem.features.panzern.PanzernResult;
import de.steamwar.bausystem.linkage.LinkageType;
import de.steamwar.bausystem.linkage.Linked;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import java.util.Map;
import java.util.Set;
@Linked(LinkageType.PANZERN)
public class SlabOnRedstone implements PanzernAlgorithm {
@Override
public PanzernResult check(Block source, Map<BlockFace, Block> adjacent, Set<Material> adjacentMaterials) {
boolean hasRedstone = false;
for (BlockFace blockFace : HORIZONTAL_FACES) {
if (adjacent.containsKey(blockFace) && adjacent.get(blockFace).getType() == Material.REDSTONE_WIRE) {
hasRedstone = true;
}
}
if (hasRedstone && adjacent.containsKey(BlockFace.DOWN) && adjacent.get(BlockFace.DOWN).getType() == Material.REDSTONE_WIRE) {
return PanzernResult.SLAB;
}
return PanzernResult.DEFAULT;
}
}

Datei anzeigen

@ -0,0 +1,63 @@
/*
* This file is a part of the SteamWar software.
*
* Copyright (C) 2021 SteamWar.de-Serverteam
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package de.steamwar.bausystem.features.panzern.algorithms;
import de.steamwar.bausystem.features.panzern.PanzernAlgorithm;
import de.steamwar.bausystem.features.panzern.PanzernResult;
import de.steamwar.bausystem.linkage.LinkageType;
import de.steamwar.bausystem.linkage.Linked;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.block.data.Bisected;
import org.bukkit.block.data.type.Stairs;
import java.util.Map;
import java.util.Set;
@Linked(LinkageType.PANZERN)
public class StairWalkWay implements PanzernAlgorithm {
@Override
public PanzernResult check(Block source, Map<BlockFace, Block> adjacent, Set<Material> adjacentMaterials) {
if (adjacent.containsKey(BlockFace.DOWN) && stairCheck(adjacent.get(BlockFace.DOWN))) {
return PanzernResult.EMPTY;
}
if (stairCheck(source.getRelative(0, -2, 0))) {
return PanzernResult.EMPTY;
}
for (BlockFace blockFace : HORIZONTAL_FACES) {
Block current = source.getRelative(blockFace.getModX(), -2, blockFace.getModZ());
if (stairCheck(current)) {
if (((Stairs) current.getBlockData()).getFacing() == blockFace) {
return PanzernResult.EMPTY;
}
}
}
return PanzernResult.DEFAULT;
}
private boolean stairCheck(Block block) {
if (block.getBlockData() instanceof Stairs) {
return ((Stairs) block.getBlockData()).getHalf() == Bisected.Half.BOTTOM;
}
return false;
}
}

Datei anzeigen

@ -23,6 +23,8 @@ import de.steamwar.bausystem.BauSystem;
import de.steamwar.bausystem.configplayer.ConfigConverter;
import de.steamwar.bausystem.configplayer.Config;
import de.steamwar.bausystem.features.gui.BauGUI;
import de.steamwar.bausystem.features.panzern.Panzern;
import de.steamwar.bausystem.features.panzern.PanzernAlgorithm;
import de.steamwar.bausystem.features.script.ScriptExecutor;
import de.steamwar.bausystem.features.script.SpecialCommand;
import de.steamwar.bausystem.linkage.specific.BauGuiItem;
@ -55,7 +57,8 @@ public enum LinkageType {
BAU_GUI_ITEM(3, false, BauGuiItem.class::isAssignableFrom, o -> BauGUI.addItem((BauGuiItem) o)),
SCRIPT_COMMAND(4, false, SpecialCommand.class::isAssignableFrom, o -> ScriptExecutor.SPECIAL_COMMANDS.add((SpecialCommand) o)),
CONFIG_CONVERTER(5, false, ConfigConverter.class::isAssignableFrom, o -> Config.addConfigConverter((ConfigConverter) o)),
SCOREBOARD(6, false, ScoreboardItem.class::isAssignableFrom, o -> {});
SCOREBOARD(6, false, ScoreboardItem.class::isAssignableFrom, o -> {}),
PANZERN(7, false, PanzernAlgorithm.class::isAssignableFrom, o -> Panzern.add((PanzernAlgorithm) o));
private final int order;