Solved Double Jumping plugin not working properly

Discussion in 'Plugin Development' started by Techno, Jul 22, 2014.

Thread Status:
Not open for further replies.
  1. Hey everyone, I've made a double jump plugin and was planning on uploading it to Bukkit Dev but I found an error. When your in survival and not-oped (So that you don't have permission) you can fly for some reason.. But your not supposed to be able to fly.. Just be able to jump once and not double jump.

    Code:
    Code:
    package me.Bill4788.DoubleJumpa;
     
    import org.bukkit.GameMode;
    import org.bukkit.Material;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.player.PlayerMoveEvent;
    import org.bukkit.event.player.PlayerToggleFlightEvent;
    import org.bukkit.plugin.java.JavaPlugin;
     
     
    public class Main extends JavaPlugin implements Listener {
    public void onEnable() {
    getServer().getPluginManager().registerEvents(this, this);
     
    getConfig().options().copyDefaults(true);
    saveConfig();
     
    }
     
    // Events
    @EventHandler
    public void onPlayerToggleFlight(PlayerToggleFlightEvent e) {
    if (e.getPlayer().hasPermission("doublejumpa.use")) {
    if (!(e.getPlayer().getWorld().getName().equals(getConfig().getString("worldname"))))
    return;
     
    Player pe = e.getPlayer();
     
    if (pe.getGameMode() == GameMode.CREATIVE)
    return;
     
    e.setCancelled(true);
    pe.setAllowFlight(false);
    pe.setFlying(false);
    pe.setVelocity(pe.getLocation().getDirection().multiply(1.5).setY(1));
    }
    }
     
    @EventHandler
    public void onPlayerMove(PlayerMoveEvent move) {
    if (move.getPlayer().hasPermission("doublejumpa.use")) {
    if (!(move.getPlayer().getWorld().getName().equals(getConfig().getString("worldname"))))
    return;
     
    Player p = move.getPlayer();
     
    if ((p.getGameMode() != GameMode.CREATIVE) && (p.getLocation().subtract(0, 1, 0).getBlock().getType() != Material.AIR) && (!p.isFlying())) {
    p.setAllowFlight(false);
    }
    }
    }
    }
    
    Thanks, Techno :)
     
  2. Offline

    xmarinusx

    Techno
    Are you 100% sure the player doesn't have the permission through a permission plugin?
     
  3. Offline

    stormneo7

    You set it to false during the PlayerMoveEvent while the block under then is not air. That's suppose to be set to true.
    Code:java
    1. if ((p.getGameMode() != GameMode.CREATIVE) && (p.getLocation().subtract(0, 1, 0).getBlock().getType() != Material.AIR) && (!p.isFlying())) {
    2. p.setAllowFlight(false);
     
  4. Offline

    AoH_Ruthless

    stormneo7
    Wrong. OP wants the player to not be able to fly.

    Techno
    Do you have any other plugins on your test server?
     
  5. Offline

    stormneo7

    Man you must be blind. Read the code. Tell me where does he allow the player to fly.
    That's the effect of double jump. You toggle fly and it sends you up. Unfortunately, there is no fly toggle as they're all false.
     
  6. Offline

    AoH_Ruthless

    stormneo7
    He wants it so when the player moves, they don't trigger flight by accident ..
     
  7. Offline

    stormneo7

    Flight is triggered when you double press space, not move. Are you new to Minecraft?
    You can't double press space by "accident".
     

  8. No, not really..
     
  9. Offline

    AoH_Ruthless

    stormneo7
    No, I am not unaware of this feature of Minecraft. Maybe "by accident" was poor word choice. He wants the plugin to block flight execution when the player hits space bar twice. Setting allow flight to false should effectively block flight execution. However, if OP sets allow Flight to true, then the player might be able to fly...
     
  10. Offline

    stormneo7

    Then his method will not work.
     
  11. Offline

    AoH_Ruthless

    Techno
    Have you tried debugging your PlayerToggleFlightEvent?

    stormneo7
    ?
     

  12. Thanks, that fixed it for me :)
     
  13. Offline

    artish1

    Techno
    Set that to true please.
     
  14. Offline

    stormneo7

    This is really insanity. You're telling him to debug PlayerToggleFlightEvent when I just said there is no way his method will work if the player has fly mode enabled. The only possible way for this to work is if the player gets gamemode.

    And if you still can't comprehend that, let me example in ABSOLUTE detail incase you are still unclear.
    /fly stormneo7 - Toggles Flight for Me, using his code, I try to double jump, it'll turn off my fly and set my velocity.
    Of course, this is me not in gamemode creative.
    [​IMG]

    Now in case that I am in gamemode creative, the code will have no effect as, obviously, it cuts off if I am.

    If you coded something to do p.setAllowedFlight(true) and p.setFlying(true), the event will trigger and the player would obviously, like I exampled above, be toggled and their velocity rendered.

    [​IMG]

    His code will work if he did what I told him to do above by changing the p.setAllowedFlight(false); in his player move event to true. This way, the Player will have flight enabled and if they try to fly, it will be disabled, velocified, and then fall. Afterwards, when they touch the ground, their flight will be re-enabled for them to double jump again.

    Is there any other misunderstanding?
     
Thread Status:
Not open for further replies.

Share This Page