Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e514609
commit 5c709aa
Showing
4 changed files
with
129 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
plugin/src/main/java/com/denizenscript/denizen/utilities/blocks/SpawnableHelper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package com.denizenscript.denizen.utilities.blocks; | ||
|
||
import com.denizenscript.denizen.utilities.Utilities; | ||
import org.bukkit.Location; | ||
import org.bukkit.Material; | ||
import org.bukkit.World; | ||
|
||
import java.util.HashSet; | ||
|
||
public class SpawnableHelper { | ||
|
||
/** | ||
* Materials that would be a problem to spawn in/on. | ||
*/ | ||
public static HashSet<Material> DANGEROUS_MATERIALS = new HashSet<>(Utilities.allMaterialsThatMatch( | ||
"fire|cactus|water|lava|magma_block|*cauldron|*campfire|*portal" // Core problems | ||
+ "|cobweb|ladder|*fence|*door|end_rod|iron_bars|chain|*wall|*_pane" // Unstable | ||
+ "*egg|*plate|tripwire|*piston")); // Could hurt | ||
|
||
/** | ||
* Returns true if the location would likely be safe to spawn a player at (based on material solidity at, below, and above the location). | ||
*/ | ||
public static boolean isSpawnable(Location loc) { | ||
World w = loc.getWorld(); | ||
if (w == null) { | ||
return false; | ||
} | ||
int x = loc.getBlockX(); | ||
int y = loc.getBlockY(); | ||
int z = loc.getBlockZ(); | ||
if (y - 1 <= w.getMinHeight() || y + 1 >= w.getMaxHeight()) { | ||
return false; | ||
} | ||
if (!w.getBlockAt(x, y + 1, z).getType().isAir()) { | ||
return false; | ||
} | ||
Material self = w.getBlockAt(x, y, z).getType(); | ||
if (self.isSolid()) { | ||
return false; | ||
} | ||
if (DANGEROUS_MATERIALS.contains(self)) { | ||
return false; | ||
} | ||
Material below = w.getBlockAt(x, y - 1, z).getType(); | ||
if (!below.isSolid()) { | ||
return false; | ||
} | ||
if (DANGEROUS_MATERIALS.contains(below)) { | ||
return false; | ||
} | ||
return true; | ||
} | ||
} |