Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class WalljumpHandler implements Listener {
- public enum Direction {
- SOUTH,
- EAST,
- NORTH,
- WEST
- }
- public static Direction getExactDirection(Player player) {
- float yaw = player.getLocation().getYaw();
- yaw = yaw / 90;
- yaw = (float)Math.round(yaw);
- if (yaw == -4 || yaw == 0 || yaw == 4) {
- return Direction.SOUTH;
- } if (yaw == -1 || yaw == 3) {
- return Direction.EAST;
- } if (yaw == -2 || yaw == 2) {
- return Direction.NORTH;
- }if (yaw == -3 || yaw == 1) {
- return Direction.WEST;
- }
- return null;
- }
- @SuppressWarnings("deprecation")
- @EventHandler
- public void onWalljump(PlayerToggleSneakEvent e) {
- Player player = e.getPlayer();
- if (!player.isOnGround() && !player.isFlying() && player.getExp() >= 1) {
- boolean walljumped = false;
- if (getExactDirection(player) == Direction.EAST) {
- if (player.getLocation().add(0.5, 0, 0).getBlock().getType().isSolid()) {
- player.playEffect(player.getLocation().add(0.5, 0, 0), Effect.STEP_SOUND, player.getLocation().add(0.5, 0, 0).getBlock().getType());
- player.setVelocity(new Vector(player.getVelocity().getX() - 0.4, 0.90, player.getVelocity().getZ()));
- walljumped = true;
- }
- } else if (getExactDirection(player) == Direction.WEST) {
- if (player.getLocation().subtract(0.5, 0, 0).getBlock().getType().isSolid()) {
- player.playEffect(player.getLocation().subtract(0.5, 0, 0), Effect.STEP_SOUND, player.getLocation().subtract(0.5, 0, 0).getBlock().getType());
- player.setVelocity(new Vector(player.getVelocity().getX() + 0.4,0.90, player.getVelocity().getZ()));
- walljumped = true;
- }
- } else if (getExactDirection(player) == Direction.SOUTH) {
- if (player.getLocation().add(0, 0, 0.5).getBlock().getType().isSolid()) {
- player.playEffect(player.getLocation().add(0, 0, 0.5), Effect.STEP_SOUND, player.getLocation().add(0, 0, 0.5).getBlock().getType());
- player.setVelocity(new Vector(player.getVelocity().getX(), 0.90, player.getVelocity().getZ() - 0.4));
- walljumped = true;
- }
- } else if (getExactDirection(player) == Direction.NORTH) {
- if (player.getLocation().subtract(0, 0, 0.5).getBlock().getType().isSolid()) {
- player.playEffect(player.getLocation().subtract(0, 0, 0.5), Effect.STEP_SOUND, player.getLocation().subtract(0, 0, 0.5).getBlock().getType());
- player.setVelocity(new Vector(player.getVelocity().getX(), 0.90, player.getVelocity().getZ() + 0.4));
- walljumped = true;
- }
- }
- if (walljumped) {
- player.setExp(0);
- Assassin.getPlugin().recharge(player, 1);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement