Skip to content

Commit

Permalink
Add elevator
Browse files Browse the repository at this point in the history
- Add jump and sneak events on calcite block (elevator)
  • Loading branch information
DocSystem committed Oct 18, 2022
1 parent f847e8a commit 274030f
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions src/main/java/fr/efreicraft/eclobby/listeners/TechZone.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerInteractEntityEvent;
import org.bukkit.event.player.PlayerMoveEvent;
import org.bukkit.event.player.PlayerToggleSneakEvent;
import org.bukkit.inventory.Inventory;

public class TechZone implements Listener {
Expand Down Expand Up @@ -45,4 +46,47 @@ public void onRightClickOnAEItemFrame(PlayerInteractEntityEvent event) {
player.openInventory(ae_storage);
}
}

@EventHandler
public void onJump(PlayerMoveEvent event) {
Player player = event.getPlayer();
float playerYaw = player.getLocation().getYaw();
float playerPitch = player.getLocation().getPitch();
Location blockUnderPlayerLoc = new Location(player.getWorld(), event.getFrom().getX(), event.getFrom().getY() - 1, event.getFrom().getZ());
Material blockUnderPlayer = blockUnderPlayerLoc.getBlock().getType();
if (event.getTo().getY() > event.getFrom().getY()) {
if (blockUnderPlayer == Material.CALCITE) {
// loop all blocks between player and 10 blocks above player
for (int i = 1; i <= 10; i++) {
Location loc = new Location(player.getWorld(), event.getFrom().getX(), event.getFrom().getY() + i, event.getFrom().getZ(), playerYaw, playerPitch);
Material block = loc.getBlock().getType();
if (block == Material.CALCITE) {
player.teleport(new Location(player.getWorld(), loc.getX(), loc.getY() + 1, loc.getZ(), playerYaw, playerPitch));
break;
}
}
}
}
}

@EventHandler
public void onSneak(PlayerToggleSneakEvent event) {
Player player = event.getPlayer();
float playerYaw = player.getLocation().getYaw();
float playerPitch = player.getLocation().getPitch();
Location blockUnderPlayerLoc = new Location(player.getWorld(), player.getLocation().getX(), player.getLocation().getY() - 1, player.getLocation().getZ());
Material blockUnderPlayer = blockUnderPlayerLoc.getBlock().getType();
if (player.isSneaking()) {
if (blockUnderPlayer == Material.CALCITE) {
for (int i = -2; i >= -11; i--) {
Location loc = new Location(player.getWorld(), player.getLocation().getX(), player.getLocation().getY() + i, player.getLocation().getZ(), playerYaw, playerPitch);
Material block = loc.getBlock().getType();
if (block == Material.CALCITE) {
player.teleport(new Location(player.getWorld(), loc.getX(), loc.getY() + 1, loc.getZ(), playerYaw, playerPitch));
break;
}
}
}
}
}
}

0 comments on commit 274030f

Please sign in to comment.