-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Better safe y determining and offset value in config
- Loading branch information
1 parent
efa86b8
commit 5d0e8b0
Showing
11 changed files
with
89 additions
and
57 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
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
48 changes: 48 additions & 0 deletions
48
OpenSectorLinker/src/main/java/pl/socketbyte/opensectors/linker/util/SafeTeleport.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,48 @@ | ||
package pl.socketbyte.opensectors.linker.util; | ||
|
||
import org.bukkit.Location; | ||
import org.bukkit.Material; | ||
import org.bukkit.World; | ||
import org.bukkit.block.Block; | ||
import org.bukkit.entity.Player; | ||
|
||
import java.util.Stack; | ||
|
||
public class SafeTeleport { | ||
|
||
private final Player player; | ||
private final World world; | ||
|
||
public SafeTeleport(Player player) { | ||
this.player = player; | ||
this.world = player.getWorld(); | ||
} | ||
|
||
public void teleport(int x, int z, int originalY, float yaw, float pitch) { | ||
int y = determineSafeY(x, z); | ||
|
||
if (originalY > y) | ||
y = originalY; | ||
|
||
Location location = new Location(world, x, y, z, yaw, pitch); | ||
player.teleport(location); | ||
} | ||
|
||
private int determineSafeY(int x, int z) { | ||
Stack<Integer> stack = new Stack<>(); | ||
for (int i = 0; i < 256; i++) { | ||
Block block = world.getBlockAt(x, i, z); | ||
Material type = block.getType(); | ||
|
||
if (type == Material.AIR) { | ||
if (stack.isEmpty()) | ||
stack.push(i); | ||
} | ||
else if (!stack.isEmpty() | ||
&& (type == Material.LEAVES | ||
|| type == Material.LEAVES_2)) | ||
stack.pop(); | ||
} | ||
return stack.pop(); | ||
} | ||
} |
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
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