How can i make a disable command as the same as the enable command?

Discussion in 'Plugin Development' started by niblaplayz, Jan 20, 2018.

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

    niblaplayz

    Hi there developers! I wanna make a core/custom essentials but it's hard to make the /fly

    I wanna make that if i am not flying when i type /fly and i fly. But when i am flying then when i type /fly
    it will deactivate :) How do i?


    Code:
    Code:
    package me.niblaplayz.fly;
    
    import org.bukkit.ChatColor;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.plugin.java.JavaPlugin;
    
    public class Main extends JavaPlugin {
    
        String igprefix = "[Flight]";
        String consoleprefix = "[Flight]";
       
        public void onEnable() {
            System.out.println(consoleprefix + "Aktivert");
        }
       
        public void onDisable() {
            System.out.println(consoleprefix + "Deaktivert");
        }
       
        public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {
           
            Player p = (Player) sender;
           
            if (commandLabel.equalsIgnoreCase("fly")) {
                p.sendMessage(ChatColor.GREEN + "[NiblaFly]" + " FlyModus Aktivert");
                p.setAllowFlight(true);
            }
            else if (commandLabel.equalsIgnoreCase("fly")){
                p.sendMessage(ChatColor.GREEN + "[NiblaFly]" + ChatColor.RED + " FlyModus Deaktivert");
                p.setAllowFlight(false);
            }
           
            return true;
           
        }
       
    }
    

    plugin.yml:
    Code:
    
    name: FlyModus
    version: 1.0
    main: me.niblaplayz.fly.Main
    author: niblaplayz
    description: Du kan fly
    
    commands:
         fly:
             usage: /<command>
             description: Gjør så du kan fly
     
    Last edited by a moderator: Jan 21, 2018
  2. Online

    timtower Administrator Administrator Moderator

    @niblaplayz Have a list of UUID's that have enabled or disabled fly.
     
  3. Offline

    niblaplayz

    How do i?
     
  4. Online

    timtower Administrator Administrator Moderator

    Make a variable for it
     
  5. Offline

    Colinus999

    Use org.bukkit.entity.Player#isFlying and org.bukkit.entity.Player#setFlying:
    Code:
    Player p; // Your player
    p.setFlying(!p.isFlying()); // Invert flying
    or
    Code:
    Player p; // Your player
    if(p.isFlying()) {
        p.setFlying(false);
        p.sendMessage(ChatColor.RED+"Flying disabled");
    } else {
        p.setFlying(true);
        p.sendMessage(ChatColor.GREEN+"Flying enabled");
    }
    
     
Thread Status:
Not open for further replies.

Share This Page