commit 73cbd909b273df9e70353af8112cf6c4860542cc
parent ea71cee8914dc89b2de9703b93b0e3341f9766fa
Author: chunksize <reisingerluca@gmail.com>
Date: Mon, 6 Nov 2023 20:32:50 +0100
feat: Added custom portal event handler
Diffstat:
1 file changed, 34 insertions(+), 3 deletions(-)
diff --git a/src/poppy/Main.java b/src/poppy/Main.java
@@ -11,6 +11,7 @@ import org.bukkit.WorldCreator;
import org.bukkit.WorldType;
import org.bukkit.World.Environment;
import org.bukkit.block.Block;
+import org.bukkit.block.BlockFace;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
@@ -188,14 +189,44 @@ public class Main extends JavaPlugin implements Listener
{
final Player player = event.getPlayer();
- if (event.getCause() == TeleportCause.NETHER_PORTAL)
+ if (event.getCause() == TeleportCause.NETHER_PORTAL);
{
- return;
+ if (player.getWorld().getName().equals("survival"))
+ {
+ event.setTo(new Location(Bukkit.getWorld("survival_nether"), event.getFrom().getBlockX() / 8, event.getFrom().getBlockY(), event.getFrom().getBlockZ() / 8));
+ }
+
+ else if (player.getWorld().getName().equals("survival_nether"))
+ {
+ event.setTo(new Location(Bukkit.getWorld("survival"), event.getFrom().getBlockX() * 8, event.getFrom().getBlockY(), event.getFrom().getBlockZ() * 8));
+ }
}
+ // TODO ugly code quick fix only!!!
+
if (event.getCause() == TeleportCause.END_PORTAL)
{
- return;
+ if (player.getWorld().getName().equals("survival")) {
+ Location loc = new Location(Bukkit.getWorld("survival_the_end"), 100, 50, 0);
+ event.setTo(loc);
+ Block block = loc.getBlock();
+ for (int x = block.getX() - 2; x <= block.getX() + 2; x++) {
+ for (int z = block.getZ() - 2; z <= block.getZ() + 2; z++) {
+ Block platformBlock = loc.getWorld().getBlockAt(x, block.getY() - 1, z);
+ if (platformBlock.getType() != Material.OBSIDIAN) {
+ platformBlock.setType(Material.OBSIDIAN);
+ }
+ for (int yMod = 1; yMod <= 3; yMod++) {
+ Block b = platformBlock.getRelative(BlockFace.UP, yMod);
+ if (b.getType() != Material.AIR) {
+ b.setType(Material.AIR);
+ }
+ }
+ }
+ }
+ } else if (player.getWorld().getName().equals("survival_the_end")) {
+ event.setTo(Bukkit.getWorld("survival").getSpawnLocation());
+ }
}
}