I am Having Problems With My Kangaroo Kit

Discussion in 'Plugin Development' started by Brett Basinger, Mar 22, 2014.

Thread Status:
Not open for further replies.
  1. Offline

    Brett Basinger

    I currently own a kitpvp server and I have been making kits and I tried to make a kangaroo kit, but the problem is that you can constantly click the kangaroo kit and fly, I was hoping some one could help this is my EventHandler for it.













    @EventHandler
    public void onInteractK(PlayerInteractEvent event) {
    Player p = event.getPlayer();
    if (p.getItemInHand().getType() == Material.FIREWORK) {
    if (event.getAction() == Action.LEFT_CLICK_AIR
    || event.getAction() == Action.LEFT_CLICK_BLOCK
    || event.getAction() == Action.RIGHT_CLICK_BLOCK
    || event.getAction() == Action.RIGHT_CLICK_AIR)
    event.setCancelled(true);
    if (!plugin.kanga.contains(p)) {
    if (!(p.isSneaking())) {
    event.setCancelled(true);
    p.setAllowFlight(false);
    p.setFlying(false);
    p.setVelocity(p.getLocation().getDirection().multiply(1.5)
    .setY(1));
     
  2. Offline

    GaaTavares

    You must check if the player is on the ground to set the velocity..
     
  3. Offline

    Brett Basinger

    Not to sound like a noob but how would I do that?
     
  4. Offline

    rohan576

    Code:java
    1. if (player.getFallDistance == 0) {
    2. // Continue
    3. }
     
  5. Offline

    Brett Basinger

    I am getting errors with that
    Code:java
    1. @EventHandler
    2. public void onInteractK(PlayerInteractEvent event) {
    3. Player p = event.getPlayer();
    4. if (p.getItemInHand().getType() == Material.FIREWORK) {
    5. if (event.getAction() == Action.LEFT_CLICK_AIR
    6. || event.getAction() == Action.LEFT_CLICK_BLOCK
    7. || event.getAction() == Action.RIGHT_CLICK_BLOCK
    8. || event.getAction() == Action.RIGHT_CLICK_AIR)
    9. if (Player.getFallDistance == 0) {
    10.  
    11. }
    12. event.setCancelled(true);
    13. if (!plugin.kanga.contains(p)) {
    14. if (!(p.isSneaking())) {
    15. event.setCancelled(true);
    16. p.setAllowFlight(false);
    17. p.setFlying(false);
    18. p.setVelocity(p.getLocation().getDirection().multiply(1.5)
    19. .setY(1));
     
  6. Offline

    GaaTavares

    Try that:
    Code:java
    1. @EventHandler
    2. public void onInteractK(PlayerInteractEvent event) {
    3. Player p = event.getPlayer();
    4. if (p.getItemInHand().getType() == Material.FIREWORK) {
    5. if (event.getAction() == Action.LEFT_CLICK_AIR
    6. || event.getAction() == Action.LEFT_CLICK_BLOCK
    7. || event.getAction() == Action.RIGHT_CLICK_BLOCK
    8. || event.getAction() == Action.RIGHT_CLICK_AIR){
    9. event.setCancelled(true);
    10. if (plugin.kanga.contains(p)) {
    11. if (!(p.isSneaking())) {
    12. if (p.getFallDistance() == 0){
    13. event.setCancelled(true);
    14. p.setAllowFlight(false);
    15. p.setFlying(false);
    16. p.setVelocity(p.getLocation().getDirection().multiply(1.5)
    17. .setY(1));
    18. }}}}
    19.  
     
  7. Offline

    tylersyme

    Brett Basinger
    Try doing this to check

    Code:java
    1. if (p.getLocation().add(0.0, -1.0, 0.0).getBlock().getType() != Material.AIR) { //If the block below the player is not air
    2.  
    3. }


    There's also a deprecated boolean method - 'player.isOnGround()'
    Not sure how dependable that one is though
     
  8. Offline

    Brett Basinger

    I think the deprecated Boolean method might be needed, haven't checked
     
  9. Offline

    Brett Basinger

    Code:java
    1. @EventHandler
    2. public void OnClick(PlayerInteractEvent e)
    3. {
    4. Player p = e.getPlayer();
    5. if (p.hasPermission("kits.tier1"));
    6. {
    7. e.setCancelled(true);
    8. if (p.getItemInHand().getType() == Material.FIREWORK);
    9. if (plugin.kanga.contains(p.getName()));
    10. Block b = p.getLocation().getBlock();
    11. if ((b.getType() !=Material.AIR) ||
    12. (b.getRelative(BlockFace.DOWN).getType() !=Material.AIR)) {
    13. if(!p.isSneaking())
    14. {
    15. p.setFallDistance(-5.0F);
    16. Vector vector = p.getEyeLocation().getDirection();
    17. vector.multiply(0.6F);
    18. vector.setY(1.0F);
    19. p.setVelocity(vector);
    20. }
    21. else
    22. {
    23. p.setFallDistance(-5.0F);
    24. Vector vector = p.getEyeLocation().getDirection();
    25. vector.multiply(1.2F);
    26. vector.setY(0.8D);
    27. p.setVelocity(vector);


    I finally got this to work, thank you all who helped me

    I got a New Problem

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 7, 2016
Thread Status:
Not open for further replies.

Share This Page