Resource [Tutorial] Making a /Fly plugin

Discussion in 'Spigot Plugin Development' started by M7MDMCGamer, Apr 28, 2017.

  1. if you are begginer use this tutorial
    in this tutorial we will make a simple plugin when type /fly it enable flying if it disabled if it enabled it will disable it

    first lets add the command
    Code (Text):

    package me.m7mdmcgamer;

    import org.bukkit.ChatColor;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.plugin.java.JavaPlugin;


    public class Main extends JavaPlugin {

     public void onEnable(){

     }
     public void onDisable(){
     }
     public boolean onCommand(CommandSender sender,Command cmd,String label,String[] args){
       if(cmd.getName().equalsIgnoreCase("fly")){

         
         return true;
       }
       return true;
     }
     }

     
    now we need check if sender has permissions
    Code (Text):

    package me.m7mdmcgamer;

    import org.bukkit.ChatColor;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.plugin.java.JavaPlugin;


    public class Main extends JavaPlugin {

     public void onEnable(){

     }
     public void onDisable(){
     }
     public boolean onCommand(CommandSender sender,Command cmd,String label,String[] args){
       if(cmd.getName().equalsIgnoreCase("fly")){
           if(!sender.hasPermission("pluginname.fly")){
               sender.sendMessage(ChatColor.DARK_RED + "You Dont Have Permissions For Using This Command.")
           return true;
           }
           
         return true;
       }
       return true;
     }
     }

     
    now we will check if fly is disabled if disabled we will enable it
    Code (Text):

    package me.m7mdmcgamer;

    import org.bukkit.ChatColor;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.plugin.java.JavaPlugin;


    public class Main extends JavaPlugin {

     public void onEnable(){

     }
     public void onDisable(){
     }
     public boolean onCommand(CommandSender sender,Command cmd,String label,String[] args){
     Player player = (Player) sender;
       if(cmd.getName().equalsIgnoreCase("fly")){
           if(!sender.hasPermission("pluginname.fly")){
               sender.sendMessage(ChatColor.DARK_RED + "You Dont Have Permissions For Using This Command.")
           return true;
           }
           
          if(player.getAllowFlight() == false){
             player.setAllowFlight(true);
             return true;
          }
         return true;
       }
       return true;
     }
     }

     
    now if fly is enabled disable it
    Code (Text):

    package me.m7mdmcgamer;

    import org.bukkit.ChatColor;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.plugin.java.JavaPlugin;


    public class Main extends JavaPlugin {

     public void onEnable(){

     }
     public void onDisable(){
     }
     public boolean onCommand(CommandSender sender,Command cmd,String label,String[] args){
     Player player = (Player) sender;
       if(cmd.getName().equalsIgnoreCase("fly")){
           if(!sender.hasPermission("pluginname.fly")){
               sender.sendMessage(ChatColor.DARK_RED + "You Dont Have Permissions For Using This Command.")
           return true;
           }
           
          if(player.getAllowFlight() == false){
             player.setAllowFlight(true);
             return true;
          }
           player.setAllowFlight(false);
         return true;
       }
       return true;
     }
     }

     
     
    • Funny Funny x 6
    • Optimistic Optimistic x 3
    • Useful Useful x 1
  2. Like said on your other thread, it's pretty pointless.
     
  3. This doesn't really look like a tutorial, as much as a copy and paste a plugin that will error out if a person in console will do /fly. And also mention nothing about the plugin.yml
     
    • Agree Agree x 3
  4. You didn't explain anything, you just did it.
    Btw,
    if(player.getAllowFlight() == false){
    player.setAllowFlight(true);
    return true;
    }
    1. ffs STOP USING == false \ == true, It's so fucking stupid, just put a !.
    2. You don't need that. Nothing will happen if you set true to true.

    Learn before you teach.
     
    • Agree Agree x 2
    • Like Like x 1
  5. This is pretty much useless lol
     
  6. Alright, no one is perfect.

    1. Dont use useless onEnable() and onDisable() methods

    2. What if the player is a sender? Make sure to check if the sender is a player first ( if (sender instanceof Player) )

    3. Dont use == true || == false
    Simply use nothing or !
    Example:
    if (player.canFly()) > if the player can fly its true
    If (!player.canFly()) > if the player cant fly its true

    4. Make sure you short the code (Windows: CTRL + SHIFT + F), will look much cleaner

    5. You didn't explain anything. Make sure you tell what certain things do.
     
    • Agree Agree x 2
  7. Also you don't need to check if the player can fly
     
  8. There is another method right? Don't really remember it
     
  9. I think you can use

    player.setAllowFlight(!player.getAllowFlight())

    Or that other method that I forgot
     
  10. You don't need to check that at all.
    just
    player.setAllowFlight(true);
    You know what happens when you set 'true' to 'true'? nothing. that check is useless.
     
  11. But you might want to disable fly?
     
  12. Hmm. Right, didn't thought about that. ( I'm tired as shit, it's late night for me now )
     
  13. Ty for this but i made it myself! xd

    JustBrim
     
  14. Don't override methods 'onEnable' and 'onDisable', if their bodies are empty.
     
  15. Did you really have to bump this? Really?
     
    • Agree Agree x 2