PlayerJumpEvent!

Discussion in 'Plugin Development' started by bodhistrontg, Sep 26, 2013.

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

    bodhistrontg

    I know there is no such thing as a playerjump event but i would like to make it so i can get the player jumps.
     
  2. Offline

    chasechocolate

    There is no official event, however you can use other events such as PlayerMoveEvent and check if the to y > from y.
     
  3. Offline

    bodhistrontg

    chasechocolate i did i have done
    Code:java
    1. public void onPlayerMoveEvent(PlayerMoveEvent e)
    2. {
    3. Player player = e.getPlayer();
    4. int x = player.getLocation().getBlockX();
    5. int y = player.getLocation().getBlockY();
    6. int z = player.getLocation().getBlockZ();
    7. Location loc = new Location(player.getWorld(), x, y+2, z);
    8. Block b = loc.getBlock();
    9. int blocka = loc.getBlock().getTypeId();
    10. if(blocka == 98)
    11. {
    12. Random object = new Random();
    13. int bodhi_is_awesime;
    14.  
    15. for(int counter=1; counter<=1; counter++){
    16. bodhi_is_awesime = 1+object.nextInt(2);
    17.  
    18. if(bodhi_is_awesime == 1){
    19. player.getInventory().addItem(new ItemStack(Material.BLAZE_ROD, 1));
    20. player.sendMessage(ChatColor.DARK_RED + "You got Fire Power left-click to use!");
    21. b.setType(Material.BEDROCK);
    22.  
    23. }else if(bodhi_is_awesime == 2){
    24. player.getInventory().addItem(new ItemStack(Material.SNOW_BALL, 1));
    25. player.sendMessage(ChatColor.BLUE + "You got Ice Power left-click to use!");
    26. b.setType(Material.BEDROCK);
    27. }
    28. }
    29. }
    30. }


    but that will do it any ways even if they just walk under it
     
  4. Offline

    Janmm14

    bodhistrontg
    You have to check if(getFrom().getY() < getTo().getY())
    You could also check if(e.getPlayer().isOnGround()) to only get people start jumping.
     
  5. Offline

    Garris0n

    And you should probably invalidate it on a velocity so they don't get triggered by pvp / tnt etc.
     
  6. Offline

    bodhistrontg

    Garris0n Janmm14 how would i do that so it put in if(getFrom().getY() < getTo().getY()) and then done!? and Garrison the wont be pvping
     
  7. Offline

    Janmm14

    bodhistrontg
    That if will also be true when the player is climing up a ladder.
    I made a plugin some time ago where I had to detect jumping too.
    Code:
        private static final boolean canPlayerHoldHere(final Block b) {
            if (b.isEmpty())
                return false;
            else {
                if (b.isLiquid())
                    return true;
                final Material t = b.getType();
                if (t == Material.LADDER || t == Material.VINE)
                    return true;
            }
            return false;
        }
        
        List<String> jumping = new ArrayList<String>();
     
        @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
        public final void onEvent(final PlayerMoveEvent e) {
            if (!canPlayerHoldHere(e.getTo().getBlock()) && e.getFrom().getY() < e.getTo().getY()) {
                final double d = Math.abs(e.getTo().getY() - Math.round(e.getTo().getY()));
                if (d <= 0.1 || (d >= 0.45 && d <= 0.55))
                    jumping.remove(e.getPlayer().getName())
                else {
                    if (!jumping.contains(e.getPlayer.getName())) {
                        jumping.add(e.getPlayer().getName());
                        //they started a jump
                    }
                }
            }
    
     
    bodhistrontg likes this.
  8. Offline

    Garris0n

    Either way anything that fires a velocity event would trigger it, so you would still have to do it.
     
  9. Offline

    bodhistrontg

    Janmm14 in my case i dont know how i would add that in i have to put this in to //start jumping
    Code:java
    1. Player player = e.getPlayer();
    2. int x = player.getLocation().getBlockX();
    3. int y = player.getLocation().getBlockY();
    4. int z = player.getLocation().getBlockZ();
    5. Block b = loc.getBlock();
    6. int blocka = loc.getBlock().getTypeId();
    7. if(blocka == 98)
    8. {
    9. Random object = new Random();
    10. int bodhi_is_awesime;
    11.  
    12. for(int counter=1; counter<=1; counter++){
    13. bodhi_is_awesime = 1+object.nextInt(2);
    14.  
    15. if(bodhi_is_awesime == 1){
    16. player.getInventory().addItem(new ItemStack(Material.BLAZE_ROD, 1));
    17. player.sendMessage(ChatColor.DARK_RED + "You got Fire Power left-click to use!");
    18. b.setType(Material.BEDROCK);
    19.  
    20. }else if(bodhi_is_awesime == 2){
    21. player.getInventory().addItem(new ItemStack(Material.SNOW_BALL, 1));
    22. player.sendMessage(ChatColor.BLUE + "You got Ice Power left-click to use!");
    23. b.setType(Material.BEDROCK);


    Thank you :D
     
  10. Offline

    xTrollxDudex

    Janmm14
    I'm not sure if it is deprecated but it really doesn't work anymore for most entities
     
  11. Offline

    Janmm14

    xTrollxDudex
    Good edit counter!

    But what do you mean? My code is not for enities.
     
  12. Offline

    xTrollxDudex

Thread Status:
Not open for further replies.

Share This Page