Plugin won't work and no errors

Discussion in 'Spigot Plugin Development' started by ZevoGaems, Apr 14, 2017.

  1. I have a punishment plugin at the moment and it only kicks at the moment. I tried adding a ban command but just left it with the kick feature to make sure I set it up correct and when I put it in my server the whole plugin doesn't work at all.
    Code (Text):
    package pw.LoopTurn.Punishment;

    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.event.Listener;
    import org.bukkit.plugin.java.JavaPlugin;

    public class Main extends JavaPlugin implements Listener {
        public void onEnable() {
            getLogger().info("Punishments have been enabled");
        }
        public void onDisble() {
            getLogger().info("Punishments have been disabled");
        }
        public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
            if (cmd.getName().equalsIgnoreCase("kick")) {
                if (!sender.hasPermission("minegrid.punish")) {
                    sender.sendMessage(ChatColor.RED + "You do not have permission");
                    return true;
                } else if (sender.hasPermission("minegrid.punish")) {
                    if (args.length == 0) {
                        sender.sendMessage(ChatColor.RED + "Usage: /kick <player> <reason>");
                        return true;
                    }
                    if (args.length != 0) {
                        if ((args[0].length() > 3) && args[0].length() < 16) {

                            String pName = args[0];
                            final Player target = Bukkit.getPlayerExact(pName);

                            if (target != null) {
                                StringBuilder message = new StringBuilder();

                                for (int i = 1; i < args.length; i++) {
                                    message.append(args[i] + " ");
                                }
                                target.kickPlayer(ChatColor.RED + "You have been kicked from the server" + "\n"
                                        + ChatColor.RED + "Reason: " + ChatColor.RED + message);
                                sender.sendMessage(ChatColor.GREEN + target.getName() + ChatColor.GREEN + " has succesfully been kicked!" + "\n"
                                        + ChatColor.GREEN + "Reason: " + message);
                                return true;

                            } else if (target == null) {
                                sender.sendMessage(ChatColor.RED + "" + ChatColor.UNDERLINE + pName + ChatColor.RED
                                        + " does not exist");
                                return true;
                            }
                        } else if (args[0].length() < 3) {
                            sender.sendMessage(ChatColor.RED + "Username is too short!");
                            return true;
                        } else if (args[0].length() > 16) {
                            sender.sendMessage(ChatColor.RED + "Username is too long!");
                            return true;
                        }

                        else {
                            sender.sendMessage(ChatColor.RED + "Usage: /kick <player> <reason>");
                            return true;
                        }
                    }
        }
    } else if (cmd.getName().equalsIgnoreCase("ban"))
        if (!sender.hasPermission("minegrid.punish")) {
            sender.sendMessage(ChatColor.RED + "You do not have permission");
            return true;
        } else if (sender.hasPermission("minegrid.punish")) {
            if (args.length == 0) {
                sender.sendMessage(ChatColor.RED + "Usage: /ban <player> <reason>");
                return true;
            }
            if (args.length != 0) {
                if ((args[0].length() > 3) && args[0].length() < 16) {

                    String pName = args[0];
                    final Player target = Bukkit.getPlayerExact(pName);

                    if (target != null) {
                        StringBuilder message = new StringBuilder();

                        for (int i = 1; i < args.length; i++) {
                            message.append(args[i] + " ");
                        }
                        target.kickPlayer(ChatColor.RED + "You have been banned from the server" + "\n"
                                + ChatColor.RED + "Reason: " + ChatColor.RED + message);
                        sender.sendMessage(ChatColor.GREEN + target.getName() + ChatColor.GREEN + " has succesfully been kicked!" + "\n"
                                + ChatColor.GREEN + "Reason: " + message);
                        return true;

                    } else if (target == null) {
                        sender.sendMessage(ChatColor.RED + "" + ChatColor.UNDERLINE + pName + ChatColor.RED
                                + " does not exist");
                        return true;
                    }
                } else if (args[0].length() < 3) {
                    sender.sendMessage(ChatColor.RED + "Username is too short!");
                    return true;
                } else if (args[0].length() > 16) {
                    sender.sendMessage(ChatColor.RED + "Username is too long!");
                    return true;
                }

                else {
                    sender.sendMessage(ChatColor.RED + "Usage: /ban <player> <reason>");
                    return true;
                }
            }
    }
        }
    }
     
     
  2. Can I see you're plugin.yml as well?
     
  3. Code (Text):
    main: pw.LoopTurn.Punishment.Main
    name: PunishmentBeta12
    version: 1.0
    author: LoopTurn_
    description: Punishes Players

    commands:
        kick:
           description: Removes a player from the server
           usage: /<command> (player) (reason)
        ban:
           description: Removes a player from the server forever
           usage: /<command> (player) (reason)
       
    There is my plugin.yml @Fluddershy
     
  4. Maybe try a shorter name?
    Also it may be because you have two plugins that have the same code, make sure to delete the ones that aren't being used.
     
  5. You're username is too long/short messages won't happen if the name is invalid because the code is read top to bottom, add it before the username is null, also I know people with names that have 3 letters.
     
    • Like Like x 1
  6. If you get no errors then how it is possible to not work? i mean if u had something wrong in plugin.yml or somewhere, when u open the start of the server it should show you that something goes wrong. Go check that out. And also i don't think you should create space between description and commands.
     
  7. @Nosma_Stew actually the space between is perfectly fine. I think most people will agree with me when I say that it looks more organized.