Code for Jump Height?

Discussion in 'Plugin Development' started by NoU_X2, Jul 13, 2020.

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

    NoU_X2

    Hi I'm looking for a code that can set your jump height like e.g player.setjumpheight() or something like that.
     
  2. Offline

    Niv-Mizzet

    @NoU_X2 You can't do anything like player.setjumpheight(). You can however check for a player move event, check if its a jump by checking if the y of e(the conventional variable for an event).getTo() is greater than the y of e.getFrom(), and if their difference is 1.25 or greater(1.25 is the average jump height). If so, you can cancel the event, then do e.getPlayer().setVelocity() to the vector between e.getFrom() and e.getTo(), and then do .setY(the amount of blocks.)
    Here's some example code for the vector stuff if that was confusing
    Code:
    e.getPlayer().setVelocity(e.getTo().subtract(e.getFrom()).toVector().setY(jumpheight));
    @NoU_X2 Edited answer.
     
    Last edited: Jul 13, 2020
  3. Offline

    KarimAKL

    That would mean you're going down.

    Also, this would be called if you're simply higher than before, which means that walking onto a slab or something will call it.
     
  4. Offline

    NoU_X2

    I know it was just an example of what I meant. Also I understood a little bit of what you were saying but can you elaborate on what I’m supposed to do. Thanks!
     
  5. Offline

    Niv-Mizzet

    @KarimAKL
    Oops let me fix that.
    So maybe check if the difference is 1.25(the player jump height) or higher? Ill put that in the post too
     
  6. Offline

    KarimAKL

    Good idea but, what if they want to set the jump height to something less than normal?
     
  7. Offline

    Niv-Mizzet

    @KarimAKL the original difference, not the result. They cancel the event then they set the height.
     
  8. Offline

    KarimAKL

  9. Offline

    NoU_X2

    This is what I came up with.
    Code:
    package me.NoU_X2.JumpHigher;
    
    import javax.annotation.Nonnull;
    
    import org.bukkit.entity.Player;
    import org.bukkit.event.Cancellable;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.HandlerList;
    import org.bukkit.event.Listener;
    import org.bukkit.event.player.PlayerEvent;
    import org.bukkit.plugin.java.JavaPlugin;
    
    public class PlayerMoveEvent extends PlayerEvent implements Cancellable {
    
        public PlayerMoveEvent(@Nonnull Player who) {
            super(who);
            // TODO Auto-generated constructor stub
        }
    
        public void onEnable() {
             getServer()).getPluginManager().registerEvents(this, this);
        }
          
            private Object getServer() {
            // TODO Auto-generated method stub
            return null;
        }
    
            @EventHandler
            public <LivingJumpEvent> void onLivingJumpEvent(LivingJumpEvent event) {
                player.getPlayer().setVelocity(null);
              
              
            }
    
            @Override
            public @Nonnull HandlerList getHandlers() {
                // TODO Auto-generated method stub
                return null;
            }
    
            @Override
            public boolean isCancelled() {
                // TODO Auto-generated method stub
                return false;
            }
    
            @Override
            public void setCancelled(boolean arg0) {
                // TODO Auto-generated method stub
              
            }
              
            }
     
    Last edited by a moderator: Jul 14, 2020
  10. Offline

    timtower Administrator Administrator Moderator

    @NoU_X2 You should not make a new PlayerMoveEvent
    And isn't that LivingJumpEvent a forge thing?
     
  11. Offline

    NoU_X2

    As I said before can you elaborate and tell me what to get rid of.
     
  12. Offline

    timtower Administrator Administrator Moderator

    The entire class.
    Listen to the PlayerMoveEvent
    Then follow this:
     
  13. Offline

    NoU_X2

    Please correct me if I'm wrong


    Code:
    package me.NoU_X2.JumpHigher;
    
    import org.bukkit.event.Listener;
    import org.bukkit.plugin.java.JavaPlugin;
    
    import net.minecraft.server.v1_15_R1.EntityBee.e;
    
    import org.bukkit.event.player.PlayerMoveEvent;
    
    public class Jump extends JavaPlugin implements Listener {
       
        @Override
          public void onEnable() {
            getServer().getPluginManager().registerEvents(this, this);
          }
        public void creatureSpawn(PlayerMoveEvent event) {
            int jumpheight = 2;
            event.getPlayer().setVelocity(event.getTo().subtract(event.getFrom()).toVector().setY(jumpheight));
           
        }
           
           
        }
     
  14. Offline

    timtower Administrator Administrator Moderator

    @NoU_X2 Missing the @EventHandler
    Got an import that you don't need.
    You are not checking the height.
     
  15. Offline

    NoU_X2

    Al
    Alright so I got the @EventHandler down and the unused import but how do I check the height? which line is it?
     
  16. Offline

    timtower Administrator Administrator Moderator

    @NoU_X2 The issue is the amount of checks that you need to do.
    Player might be swimming, being shot by tnt cannon, riding a minecart, riding an arrow, walking up a stairs.

    How do you want to find if the player jumped?
     
  17. Offline

    NoU_X2

    Just normal jumping
     
  18. Offline

    timtower Administrator Administrator Moderator

    How do you want to detect that though? There are no events for it.
     
  19. Offline

    NoU_X2

    Can it be when I move?
     
  20. Offline

    timtower Administrator Administrator Moderator

    That is why the PlayerMoveEvent exists, but how do you want to see the difference between somebody climbing up a ladder / stairs versus jumping?
     
  21. Offline

    NoU_X2

    I don't know. What do you think whats best?
     
  22. Offline

    timtower Administrator Administrator Moderator

    Not doing it at all to be honest.

    Why do you want to change the jump height?
     
  23. Offline

    NoU_X2

    So me and my friends can mess and have a play around with the plugin. Just like all the other plugins I made
     
  24. Offline

    timtower Administrator Administrator Moderator

    Might want to make a launcher plugin instead, one that just applies and additional Y vector
     
  25. Offline

    NoU_X2

    Don't know what you mean by that. Anyway whenever I load my plugin up and I get into my server and jump it suffocates me in a wall. How do I fix that without removing the plugin?
     
  26. Offline

    timtower Administrator Administrator Moderator

    https://dev.bukkit.org/projects/playerlauncher
    Something like that

    I don't know what your current code is, but it might be too aggressive on the vector adding.
     
  27. Offline

    NoU_X2

    this is my current code

    Code:
    package me.NoU_X2.JumpHigher;
    
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.plugin.java.JavaPlugin;
    import org.bukkit.event.player.PlayerMoveEvent;
    
    public class Main extends JavaPlugin implements Listener {
       
        @Override
          public void onEnable() {
            getServer().getPluginManager().registerEvents(this, this);
          }
        @EventHandler
        public void creatureSpawn(PlayerMoveEvent event) {
            int jumpheight = 2;
            event.getPlayer().setVelocity(event.getTo().subtract(event.getFrom()).toVector().setY(jumpheight));
           
        }
           
           
        }
     
    Last edited by a moderator: Jul 14, 2020
  28. Offline

    timtower Administrator Administrator Moderator

    @NoU_X2 Now you are always increasing the Y vector.
     
  29. Offline

    NoU_X2

    So what do I have to do?
     
  30. Offline

    timtower Administrator Administrator Moderator

    Add a check to see if they player is even jumping
     
Thread Status:
Not open for further replies.

Share This Page