Fly Help

Discussion in 'Plugin Development' started by DubstepPrins, Nov 19, 2014.

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

    DubstepPrins

    Hello!

    I'm a newbie at coding and am trying to kind of start coding my own plugins.
    So I've started coding a /Fly command, however I need some help with it!
    Code:java
    1. if(cmd.getName().equalsIgnoreCase("fly")) {
    2. sender.sendMessage(ChatColor.GREEN + "Fly has been enabled!");
    3. player.setAllowFlight(true);
    4. player.setFlySpeed(1);
    5. player.setFlying(true);
    6. }
    7. if(cmd.getName().equalsIgnoreCase("fly")) {
    8. sender.sendMessage(ChatColor.GREEN + "Fly has been disabled!");
    9. player.setFlying(false);
    10. player.setFlySpeed(0);
    11. player.setAllowFlight(false);

    As you can see we have both the enable and disable command.
    Now I'm wondering how I can make it like they don't run at the same time, that it's permanent until you use the command again to disable flight.
    This is what I get: http://prntscr.com/581hl2 .

    Thanks.
     
  2. Offline

    SuperOriginal

    You're checking if the cmd is equal to "fly" in both if statements, so of course they will both be true at the same time. You can either make a separate command that disables flight, or you can use an array list to store the UUID of players that are in flight mode. Then, when they run the command, check if their UUID is in the list. If it is, turn off flight and remove them from the list. If it is not, then add them and turn on flight.
     
  3. Offline

    DubstepPrins

    Ok thanks! Will try this out.
     
  4. Offline

    jeussa


    or you could add the check as the one in line 2 of the example below

    Code:java
    1. if(cmd.getName().equalsIgnoreCase("fly")){
    2. if(player.getAllowFlight()){
    3. sender.sendMessage(ChatColor.GREEN + "Fly has been disabled!");
    4. player.setFlying(false);
    5. player.setFlySpeed(0);
    6. player.setAllowFlight(false);
    7. }else{
    8. sender.sendMessage(ChatColor.GREEN + "Fly has been enabled!");
    9. player.setAllowFlight(true);
    10. player.setFlySpeed(1);
    11. player.setFlying(true);
    12. }
    13. }
     
    DubstepPrins likes this.
  5. Offline

    SuperOriginal

    That's probably easier for this plugin^

    But if you ever want to make a different plugin with a toggle in the future you can use my method.
     
Thread Status:
Not open for further replies.

Share This Page