Higher Jumping

Discussion in 'Plugin Development' started by CraftCreeper6, Jan 23, 2014.

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

    CraftCreeper6

    Hello, I am here to ask you a question. I am wondering how I would allow a player to jump high when say an Iron Axe is right clicked, does any body know how this would be done?
     
  2. Offline

    rangersmash

    Some pesudo code -

    PlayerInteractEvent

    if player holding Material.IronAxe

    if player is op (or whatever)

    Vector jump = player.getLocation().getDirection().multiply(0.2).setY(1.1); <- These lines is what adds the jump
    player.setVelocity(player.getVelocity().add(jump));
     
  3. Online

    CraftCreeper6

    Hmm I will send you my code. It does not seem to work.
    Code:
    ItemStack ironaxe = new ItemStack(Material.IRON_AXE);
                            ItemMeta iameta = ironaxe.getItemMeta();
                            iameta.setDisplayName("§c§nHigh Jump");
                            List<String> lorename1 = new ArrayList<String>();
                            lorename1
                                    .add(ChatColor.DARK_PURPLE
                                            + "Right click to jump high in the sky and deal AOE damage when you hit the ground!");
                            iameta.setLore(lorename1);
                            ironaxe.setItemMeta(iameta);
                            if (event.getAction() == Action.RIGHT_CLICK_BLOCK
                                    || event.getAction() == Action.RIGHT_CLICK_AIR) {
                            if (event.getItem().getType().equals(ironaxe)) {
                                p.setFlying(false);
                                Vector jump = p.getLocation().getDirection().multiply(0.2).setY(1.1);
                                p.setVelocity(p.getVelocity().add(jump));
     
  4. Offline

    rangersmash

    When doing -
    if (event.getItem().getType().equals(ironAxe)) {

    }

    Change it to

    if (event.getItem().equals(ironAxe))

    If not, just check the item's name if it's correct.
     
  5. Online

    CraftCreeper6

    This does not seem to work :/ Code:
    Code:java
    1. ItemStack ironaxe = new ItemStack(Material.IRON_AXE);
    2. ItemMeta iameta = ironaxe.getItemMeta();
    3. iameta.setDisplayName("§c§nHigh Jump");
    4. List<String> lorename1 = new ArrayList<String>();
    5. lorename1
    6. .add(ChatColor.DARK_PURPLE
    7. + "Right click to jump high in the sky and deal AOE damage when you hit the ground!");
    8. iameta.setLore(lorename1);
    9. ironaxe.setItemMeta(iameta);
    10. if (event.getAction() == Action.RIGHT_CLICK_BLOCK
    11. || event.getAction() == Action.RIGHT_CLICK_AIR) {
    12. if (event.getItem().equals(ironaxe)) {
    13. p.setFlying(false);
    14. Vector jump = p.getLocation().getDirection().multiply(0.2).setY(1.1);
    15. p.setVelocity(p.getVelocity().add(jump));
     
  6. Offline

    rangersmash

    Code:
                            if (event.getAction() == Action.RIGHT_CLICK_BLOCK
                                    || event.getAction() == Action.RIGHT_CLICK_AIR) {
                            if (event.getItem().hasItemMeta()) {
                            if (event.getItem().getItemMeta().getDisplayName().equalsIgnoreCase("§c§nHigh Jump")){ // Check this line, might not be right. If it works, remove the new ItemStack code
                                p.setFlying(false);
                                Vector jump = p.getLocation().getDirection().multiply(0.2).setY(1.1);
                                p.setVelocity(p.getVelocity().add(jump));
    Just very quickly wrote this, may not work but you get the idea. Check the name rather than the actual item and you should be fine.
     
  7. Online

    CraftCreeper6

  8. Offline

    rangersmash

    Let me go test it quickly in a test envirnoment. I shall reply will the attempted fixed code! CraftCreeper6

    EDIT: Use ChatColor.### instead of the section sign, may be a issue? Also, is there any errors and can I suggest you add debugs, so System.out.println("") after every if() for example to see whats not happening.
     
  9. Online

    CraftCreeper6

    Thank you rangersmash. You can test on my server if you like, it has the full plugin. I'll PM you the IP if you want me to?!
     
  10. Offline

    rangersmash

  11. Offline

    Wantsome909

  12. Online

    CraftCreeper6

  13. Offline

    Wantsome909

    CraftCreeper6
    Code:java
    1.  
    2. @Override
    3. onEnabled(){
    4. PluginManager pm = getServer().getPluginManager();
    5. pm.registerEvents(this, this);
    6. }
     
Thread Status:
Not open for further replies.

Share This Page