Solved Commands Don't Work

Discussion in 'Plugin Development' started by Jaaakee224, Feb 4, 2014.

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

    Jaaakee224

    None of my commands don't work for my plugin.
    Before you comment, I have my plugin.yml set up correctly, you can check it down below as well.
    I also do not receive any errors in Eclipse or in the Console.

    MaintenanceMode Class (ONLY CLASS)
    Code:java
    1. package me.Jaaakee224.MaintenanceMode;
    2.  
    3. import org.bukkit.ChatColor;
    4. import org.bukkit.command.Command;
    5. import org.bukkit.command.CommandSender;
    6. import org.bukkit.entity.Player;
    7. import org.bukkit.event.EventHandler;
    8. import org.bukkit.event.Listener;
    9. import org.bukkit.event.player.PlayerJoinEvent;
    10.  
    11. import org.bukkit.plugin.java.JavaPlugin;
    12.  
    13. public class MaintenanceMode extends JavaPlugin implements Listener {
    14.  
    15. public void onEnable() {
    16. this.saveDefaultConfig();
    17. this.getServer().getPluginManager().registerEvents(this, this);
    18. }
    19. public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {
    20. if(cmd.getName().equalsIgnoreCase("maintenance-activate")) {
    21. this.getServer().setWhitelist(true);
    22. for (Player p : this.getServer().getOnlinePlayers()) {
    23. if(!p.isOp() && !p.isWhitelisted()) {
    24. p.kickPlayer(this.getConfig().getString("Maintenance-Kick".replaceAll("&", "§")));
    25. this.getServer().broadcastMessage(ChatColor.GOLD + "[Maintenance Mode] " + ChatColor.RESET + this.getConfig().getString("Maintenance-Activate".replaceAll("&", "§")));
    26. } else {
    27. if(cmd.getName().equalsIgnoreCase("maintenance-deactivate")) {
    28. this.getServer().setWhitelist(false);
    29. this.getServer().broadcastMessage(ChatColor.GOLD + "[Maintenance Mode] " + ChatColor.RESET + this.getConfig().getString("Maintenance-Deactivate".replaceAll("&", "§")));
    30. } else {
    31. if(cmd.getName().equalsIgnoreCase("maintenance-reload")) {
    32. reloadConfig();
    33. p.sendMessage(ChatColor.GOLD + "[Maintenance Mode] " + ChatColor.AQUA + "Maintenance Mode successfully reloaded!");
    34. }
    35.  
    36.  
    37. }
    38. }
    39.  
    40. }
    41.  
    42. }
    43. return false;
    44. }
    45.  
    46.  
    47. @EventHandler
    48. public void onPlayerJoin(PlayerJoinEvent e) {
    49. if(e.getPlayer().isOp()) {
    50. e.getPlayer().sendMessage(ChatColor.GOLD + "[Maintenance Mode] " + ChatColor.RESET + this.getConfig().getString("Maintenance-Join".replaceAll("&", "§")));
    51.  
    52. } else {
    53.  
    54. e.getPlayer().kickPlayer(this.getConfig().getString("Maintenance-Kick".replaceAll("&", "§")));
    55.  
    56. }
    57.  
    58. }
    59. }


    Config.yml
    Code:
    Maintenance-Activate: Activated!
    Maintenance-Deactivate: Deactivated!
    Maintenance-Join: Maintenance Join!
    Maintenance-Kick: Maintenance Kick!
    
    Plugin.yml
    Code:
    name: MaintenanceMode
    version: 1.0
    main: me.Jaaakee224.MaintenanceMode.MaintenanceMode
    description: >
                Makes your server has Maintenance!
    commands:
      maintenance-activate:
        description: Activate Maintenance Mode.
      maintenance-deactivate:
        description: Deactivate Maintenance Mode.
      maintenance-reload:
        description: Reload Maintenance Mode.
    
    Added the config.yml & plugin.yml

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 6, 2016
  2. Offline

    hi_guy_5

    try not using }else{
    just close the last command and return if necessary then start the next command like normal
    not sure if it will work but it can't hurt
     
  3. Offline

    Jaaakee224

    hi_guy_5 I used the }else{ statement before, and it worked. I'm not sure.
     
  4. Offline

    hi_guy_5

    do you get an error when you try to use the commands
     
  5. Offline

    Jaaakee224

    hi_guy_5 Nope

    hi_guy_5 It was the } else if

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 6, 2016
Thread Status:
Not open for further replies.

Share This Page