Would this code work

Discussion in 'Plugin Development' started by XgXXSnipz, Jun 22, 2014.

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

    XgXXSnipz

    Im making a plugin and Im new to coding and I would like to know if this would work
    Code:java
    1. public void onEnable(){
    2. Bukkit.getServer().getPluginManager().registerEvents(this, this);
    3. }
    4.  
    5. public boolean onCommand(Command sender, Command cmd, String args[]) {
    6. this.getServer().getScheduler().scheduleSyncDelayedTask(this, new Runnable() {
    7.  
    8. public void run() {
    9. Bukkit.getServer().shutdown();
    10. }
    11. }, 60L);// 60 L == 3 sec, 20 ticks == 1 sec
    12.  
    13. Player p = (Player)sender;
    14.  
    15. if(cmd.getName().equalsIgnoreCase("shutdown"))
    16. if(!p.hasPermission("shutdown.use"));
    17.  
    18. Bukkit.broadcastMessage(ChatColor.RED + "Server shuting down in 3 seconds");
    19. return false;
    20. }
    21. }
    22.  
     
  2. Offline

    Konkz

    New to coding and doing Bukkit plugins, huh? Go learn Java first, my suggestion.

    Secondly, you're registering events and you use no events.

    Thirdly, no. It won't work, your braces make no sense alongside of the logic checks. Learn Java first, please - for sake of people here who try and help actual problems and yourself.
     
  3. XgXXSnipz No It Wont Work

    Corrected Code:
    Code:
        @Override
        public void onEnable() {
            Bukkit.getServer().getPluginManager().registerEvents(this, this);
       
        }
     
        public boolean onCommand(Command sender, Command cmd, String args[]) {
            if(cmd.getName().equalsIgnoreCase("shutdown")) {
                Player p = (Player) sender;
                if(p.hasPermission("shutdown.use")) {
                    Bukkit.broadcastMessage(ChatColor.RED + "Server Shutting Down In 3 Seconds");
                    this.getServer().getScheduler().scheduleSyncDelayedTask(this, new Runnable() {
                        public void run() {
                            Bukkit.getServer().shutdown();
                        }
                   
                    }, 60);
                }
            }
            return false;
       
        }
     
     
    }
    
    If You Want I Will Explain The Mistakes You Did
    [I am Guessing You Have The Plugin.yml Sorted Out For This Command]
     
  4. Offline

    XgXXSnipz

    Yes please explain
     
  5. Offline

    ReggieMOL


    XgXXSnipz well for one everything was lined up in an incorrect order. Also tag him so he gets an alert Herbert_The_Pervert
     
Thread Status:
Not open for further replies.

Share This Page