SteamWar/FightSystem
Archiviert
13
1

Waterremover improvements #225

Manuell gemergt
Lixfel hat 1 Commits von improveWaterremover nach master 2021-01-02 13:16:39 +01:00 zusammengeführt

Datei anzeigen

@ -20,7 +20,7 @@
package de.steamwar.fightsystem.utils; package de.steamwar.fightsystem.utils;
import de.steamwar.core.Core; import de.steamwar.core.Core;
import org.bukkit.Material; import de.steamwar.fightsystem.Config;
import org.bukkit.block.Block; import org.bukkit.block.Block;
import org.bukkit.block.BlockFace; import org.bukkit.block.BlockFace;
@ -29,48 +29,33 @@ import java.util.List;
public class WaterRemover { public class WaterRemover {
private WaterRemover(){} private WaterRemover(){}
private static final int MIN_Y = Config.AlignWater ? Config.TeamBlueCornerY + Config.WaterDepth : Config.TeamBlueCornerY;
public static void add(List<Block> l) { public static void add(List<Block> l) {
for(Block b : l){ for(Block b : l){
//b cannot be water or air due to current explosion //b cannot be water or air due to current explosion
int startX = b.getX(); checkBlock(b.getRelative(BlockFace.UP));
int startY = b.getY(); checkBlock(b.getRelative(BlockFace.EAST));
int startZ = b.getZ(); checkBlock(b.getRelative(BlockFace.WEST));
try{ checkBlock(b.getRelative(BlockFace.NORTH));
checkBlock(b.getRelative(BlockFace.EAST), startX, startY, startZ); checkBlock(b.getRelative(BlockFace.SOUTH));
checkBlock(b.getRelative(BlockFace.WEST), startX, startY, startZ);
checkBlock(b.getRelative(BlockFace.NORTH), startX, startY, startZ);
checkBlock(b.getRelative(BlockFace.SOUTH), startX, startY, startZ);
checkBlock(b.getRelative(BlockFace.UP), startX, startY, startZ);
}catch(IsAnOcean e){
//ignore
}
} }
} }
private static void checkBlock(Block b, int startX, int startY, int startZ) throws IsAnOcean { private static void checkBlock(Block b) {
if(!removeWater(b)) if(!removeWater(b))
return; return;
// If distance to original block is greater than 20 if(b.getY() < MIN_Y)
if(Math.abs(startX - b.getX()) + Math.abs(startY - b.getY() + Math.abs(startZ - b.getZ())) >= 20){ return;
b.setType(Material.WATER);
throw new IsAnOcean();
}
try{ checkBlock(b.getRelative(BlockFace.UP));
checkBlock(b.getRelative(BlockFace.EAST), startX, startY, startZ); checkBlock(b.getRelative(BlockFace.EAST));
checkBlock(b.getRelative(BlockFace.WEST), startX, startY, startZ); checkBlock(b.getRelative(BlockFace.WEST));
checkBlock(b.getRelative(BlockFace.NORTH), startX, startY, startZ); checkBlock(b.getRelative(BlockFace.NORTH));
checkBlock(b.getRelative(BlockFace.SOUTH), startX, startY, startZ); checkBlock(b.getRelative(BlockFace.SOUTH));
checkBlock(b.getRelative(BlockFace.UP), startX, startY, startZ);
}catch(IsAnOcean e){
b.setType(Material.WATER);
throw e;
} }
}
private static class IsAnOcean extends Throwable{}
public static boolean isWater(Block block){ public static boolean isWater(Block block){
switch(Core.getVersion()){ switch(Core.getVersion()){