mirror of
https://github.com/darksaid98/HuskHomes.git
synced 2026-12-02 06:28:49 +00:00
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:
1 parent
377e46ff92
commit
771c16ed1a
6 files changed
+118
-26
No files matched your search
@@ -40,15 +40,25 @@ public interface SafetyResolver {
|
||||
CompletableFuture<Optional<Location>> findSafeGroundLocation(@NotNull Location location);
|
||||
|
||||
/**
|
||||
* Returns if the block, by provided identifier, is unsafe
|
||||
* Returns if the block, by provided identifier, is unsafe to stand on
|
||||
*
|
||||
* @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
|
||||
*/
|
||||
default boolean isBlockSafe(@NotNull String blockId) {
|
||||
default boolean isBlockSafeForStanding(@NotNull String blockId) {
|
||||
return !getPlugin().getUnsafeBlocks().isUnsafe(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 able to be occupied, {@code false} otherwise
|
||||
*/
|
||||
default boolean isBlockSafeForOccupation(@NotNull String blockId) {
|
||||
return !getPlugin().getUnsafeBlocks().isUnsafeToOccupy(blockId);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
HuskHomes getPlugin();
|
||||
|
||||
|
||||
@@ -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() {
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user