Prevent suffocation while using /rtp (#445)

* rtp: check for suffocation before teleport

* safety resolvers: teleport to middle of block

* rtp: Fix negative coordinates being off by one

* unsafe blocks: add campfires and magma

* unsafe blocks: deduplicate block id formatting
This commit is contained in:
Jacob McSwain authored and GitHub committed 2023-06-29 10:05:57 +01:00
1 parent 377e46ff92
commit 771c16ed1a
6 files changed
+118 -26

No files matched your search

@@ -36,6 +36,16 @@ public class UnsafeBlocks {
@YamlKey("unsafe_blocks")
public List<String> unsafeBlocks;
@YamlKey("safe_occupation_blocks")
public List<String> safeOccupationBlocks;
private String formatBlockId(@NotNull String blockId) {
if (!blockId.startsWith(Key.MINECRAFT_NAMESPACE + ":")) {
blockId = Key.MINECRAFT_NAMESPACE + ":" + blockId;
}
return blockId;
}
/**
* Returns if the block, by provided identifier, is unsafe
*
@@ -43,12 +53,21 @@ public class UnsafeBlocks {
* @return {@code true} if the block is on the unsafe blocks list, {@code false} otherwise
*/
public boolean isUnsafe(@NotNull String blockId) {
if (!blockId.startsWith(Key.MINECRAFT_NAMESPACE + ":")) {
blockId = Key.MINECRAFT_NAMESPACE + ":" + blockId;
}
blockId = this.formatBlockId(blockId);
return unsafeBlocks.contains(blockId);
}
/**
* Returns if the block, by provided identifier, is unsafe to stand in
*
* @param blockId The block identifier (e.g. {@code minecraft:stone})
* @return {@code true} if the block is on the unsafe blocks list, {@code false} otherwise
*/
public boolean isUnsafeToOccupy(@NotNull String blockId) {
blockId = this.formatBlockId(blockId);
return !safeOccupationBlocks.contains(blockId);
}
@SuppressWarnings("unused")
public UnsafeBlocks() {
}