Advertisement
Guest User

Untitled

a guest
Mar 15th, 2014
262
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. public class WalljumpHandler implements Listener {
  2.    
  3.     public enum Direction {
  4.         SOUTH,
  5.         EAST,
  6.         NORTH,
  7.         WEST
  8.     }
  9.    
  10.     public static Direction getExactDirection(Player player) {
  11.        
  12.         float yaw = player.getLocation().getYaw();
  13.         yaw = yaw / 90;
  14.         yaw = (float)Math.round(yaw);
  15.        
  16.         if (yaw == -4 || yaw == 0 || yaw == 4) {
  17.             return Direction.SOUTH;
  18.         } if (yaw == -1 || yaw == 3) {
  19.             return Direction.EAST;
  20.         } if (yaw == -2 || yaw == 2) {
  21.             return Direction.NORTH;
  22.         }if (yaw == -3 || yaw == 1) {
  23.             return Direction.WEST;
  24.         }
  25.        
  26.         return null;
  27.     }
  28.    
  29.     @SuppressWarnings("deprecation")
  30.     @EventHandler
  31.     public void onWalljump(PlayerToggleSneakEvent e) {
  32.         Player player = e.getPlayer();
  33.         if (!player.isOnGround() && !player.isFlying() && player.getExp() >= 1) {
  34.            
  35.             boolean walljumped = false;
  36.             if (getExactDirection(player) == Direction.EAST) {
  37.                 if (player.getLocation().add(0.5, 0, 0).getBlock().getType().isSolid()) {
  38.                     player.playEffect(player.getLocation().add(0.5, 0, 0), Effect.STEP_SOUND, player.getLocation().add(0.5, 0, 0).getBlock().getType());
  39.                     player.setVelocity(new Vector(player.getVelocity().getX() - 0.4, 0.90, player.getVelocity().getZ()));
  40.                     walljumped = true;
  41.                 }
  42.             } else if (getExactDirection(player) == Direction.WEST) {
  43.                 if (player.getLocation().subtract(0.5, 0, 0).getBlock().getType().isSolid()) {
  44.                     player.playEffect(player.getLocation().subtract(0.5, 0, 0), Effect.STEP_SOUND, player.getLocation().subtract(0.5, 0, 0).getBlock().getType());
  45.                     player.setVelocity(new Vector(player.getVelocity().getX() + 0.4,0.90, player.getVelocity().getZ()));
  46.                     walljumped = true;
  47.                 }
  48.             } else if (getExactDirection(player) == Direction.SOUTH) {
  49.                 if (player.getLocation().add(0, 0, 0.5).getBlock().getType().isSolid()) {
  50.                     player.playEffect(player.getLocation().add(0, 0, 0.5), Effect.STEP_SOUND, player.getLocation().add(0, 0, 0.5).getBlock().getType());
  51.                     player.setVelocity(new Vector(player.getVelocity().getX(), 0.90, player.getVelocity().getZ() - 0.4));
  52.                     walljumped = true;
  53.                 }
  54.             } else if (getExactDirection(player) == Direction.NORTH) {
  55.                 if (player.getLocation().subtract(0, 0, 0.5).getBlock().getType().isSolid()) {
  56.                     player.playEffect(player.getLocation().subtract(0, 0, 0.5), Effect.STEP_SOUND, player.getLocation().subtract(0, 0, 0.5).getBlock().getType());
  57.                     player.setVelocity(new Vector(player.getVelocity().getX(), 0.90, player.getVelocity().getZ() + 0.4));
  58.                     walljumped = true;
  59.                 }
  60.             }
  61.             if (walljumped) {
  62.                 player.setExp(0);
  63.                 Assassin.getPlugin().recharge(player, 1);
  64.             }
  65.         }
  66.     }
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement