Use configured unsafe blocks in height validator

This commit is contained in:
Phoenix616 2022-03-08 14:41:16 +01:00
parent 3ecf194913
commit 4a77bf1519
No known key found for this signature in database
GPG Key ID: 40E2321E71738EB0
3 changed files with 14 additions and 5 deletions

View File

@ -258,7 +258,7 @@ public class RandomTeleport extends JavaPlugin implements RandomTeleportAPI {
private void initValidators() {
locationValidators.add(new WorldborderValidator());
locationValidators.add(new HeightValidator());
locationValidators.add(new HeightValidator(unsafeBlocks));
locationValidators.add(new ProtectionValidator());
locationValidators.add(new BlockValidator(safeBlocks));
}

View File

@ -20,13 +20,21 @@ package de.themoep.randomteleport.searcher.validators;
import de.themoep.randomteleport.searcher.RandomSearcher;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import java.util.Collections;
import java.util.EnumSet;
public class HeightValidator extends LocationValidator {
public HeightValidator() {
private final EnumSet<Material> unsafeBlocks;
public HeightValidator(Material[] unsafeBlocks) {
super("height");
this.unsafeBlocks = EnumSet.noneOf(Material.class);
Collections.addAll(this.unsafeBlocks, unsafeBlocks);
}
@Override
@ -49,7 +57,7 @@ public class HeightValidator extends LocationValidator {
return isSafe(block.getRelative(BlockFace.UP)) && isSafe(block.getRelative(BlockFace.UP, 2));
}
private static boolean isSafe(Block block) {
return block.isPassable() && !block.isLiquid();
private boolean isSafe(Block block) {
return block.isPassable() && !block.isLiquid() && !unsafeBlocks.contains(block.getType());
}
}

View File

@ -21,7 +21,7 @@ safe-blocks:
- end_stone
- netherrack
# Blocks unsafe when in "--force blocks" mode
# Blocks not to teleport on or into
unsafe-blocks:
- air
- water
@ -96,6 +96,7 @@ unsafe-blocks:
- dark_oak_door
- end_rod
- end_gateway
- powder_snow
sign-variables:
- "[RTP]"