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.World;
import org.bukkit.block.Block; import org.bukkit.block.Block;
import org.bukkit.block.BlockFace; 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.*;
import java.util.Set;
public class Panzern { 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 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<>(); private Set<Location> current = new HashSet<>();
@ -66,85 +68,51 @@ public class Panzern {
Location toCheck = current.iterator().next(); Location toCheck = current.iterator().next();
current.remove(toCheck); current.remove(toCheck);
Set<Location> adjacent = new HashSet<>(); Map<BlockFace, Block> adjacent = new HashMap<>();
boolean hasRedstone = false; Set<Material> adjacentMaterials = new HashSet<>();
boolean belowRedstone = false;
boolean belowCarpet = false;
boolean adjacentPiston = false;
boolean adjacentSlime = false;
for (BlockFace blockFace : BLOCK_FACES) { for (BlockFace blockFace : BLOCK_FACES) {
Location now = toCheck.clone().add(blockFace.getModX(), blockFace.getModY(), blockFace.getModZ()); Location now = toCheck.clone().add(blockFace.getModX(), blockFace.getModY(), blockFace.getModZ());
if (inRegion(now)) { if (inRegion(now)) {
adjacent.add(now); Block temp = world.getBlockAt(now);
} adjacent.put(blockFace, temp);
Block block = world.getBlockAt(now); adjacentMaterials.add(temp.getType());
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;
} }
} }
if (blockFace != BlockFace.UP && blockFace != BlockFace.DOWN) { Block currentBlock = world.getBlockAt(toCheck);
hasRedstone |= block.getType() == Material.REDSTONE_WIRE;
} PanzernResult panzernResult = PanzernResult.DEFAULT;
if (blockFace == BlockFace.DOWN) { for (PanzernAlgorithm panzernAlgorithm : panzernAlgorithmList) {
belowRedstone |= block.getType() == Material.REDSTONE_WIRE; PanzernResult temp = panzernAlgorithm.check(currentBlock, adjacent, adjacentMaterials);
belowCarpet |= block.getType().name().contains("CARPET"); if (temp != null && temp != PanzernResult.DEFAULT) {
} panzernResult = temp;
if (blockFace == BlockFace.DOWN && stairCheck(now)) { break;
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;
} }
} }
} switch (panzernResult) {
current.addAll(adjacent); case EMPTY:
emptyBlocks.add(currentBlock.getLocation());
if (belowCarpet || adjacentPiston) {
emptyBlocks.add(toCheck);
return; return;
} case SLAB:
if (adjacentSlime) { currentBlock.setType(slabMaterial);
world.getBlockAt(toCheck).setType(Material.JUKEBOX); break;
} else if (belowRedstone && hasRedstone) { case BLOCK:
world.getBlockAt(toCheck).setType(slabMaterial); case DEFAULT:
} else { currentBlock.setType(blockMaterial);
world.getBlockAt(toCheck).setType(blockMaterial); break;
} case UNMOVABLE:
currentBlock.setType(Material.JUKEBOX);
break;
default:
emptyBlocks.add(currentBlock.getLocation());
break;
} }
private boolean stairCheck(Location location) { adjacent.forEach((blockFace, temp) -> {
Block block = world.getBlockAt(location); if (temp.getType().isAir() && !emptyBlocks.contains(temp.getLocation())) {
if (block.getBlockData() instanceof Stairs) { current.add(temp.getLocation());
Stairs stairs = (Stairs) block.getBlockData();
return stairs.getHalf() == Bisected.Half.BOTTOM;
} }
return false; });
} }
private boolean inRegion(Location location) { private boolean inRegion(Location location) {
@ -154,7 +122,7 @@ public class Panzern {
if (location.getBlockX() <= pos2.getBlockX()) { if (location.getBlockX() <= pos2.getBlockX()) {
if (location.getBlockY() <= pos2.getBlockY()) { if (location.getBlockY() <= pos2.getBlockY()) {
if (location.getBlockZ() <= pos2.getBlockZ()) { 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.ConfigConverter;
import de.steamwar.bausystem.configplayer.Config; import de.steamwar.bausystem.configplayer.Config;
import de.steamwar.bausystem.features.gui.BauGUI; 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.ScriptExecutor;
import de.steamwar.bausystem.features.script.SpecialCommand; import de.steamwar.bausystem.features.script.SpecialCommand;
import de.steamwar.bausystem.linkage.specific.BauGuiItem; 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)), 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)), 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)), 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; private final int order;