I need help

Discussion in 'Community Feedback and Suggestions' started by ZevoGaems, Apr 14, 2017.

  1. In this area I need help for my punishment plugin but I don't know how to make it. I am new to java so please do not get mad but I need help to fix this else statement cause it keeps coming up as a error.
    Code (Text):
                        else {
                            sender.sendMessage(ChatColor.RED + "Usage: /kick <player> <reason>");
                            return true;
                        } else if (cmd.getName().equalsIgnoreCase("ban")) {
                         
                        }
                    }
    The whole plugin looks like this so far
    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")) {
                           
                        }
                    }
        }
    }
            return false;
        }
    }
     
     
  2. Your else and else if are on the same indentation
     
  3. Can you please elaborate on that. I am new to java
     
  4. Okay I'm not gonna copy and code as I'm on a phone, but I'll try to explain everything as simply as possible:
    First things first is if a player doesn't have the permission minegrid.punish you don't need to then do a if player does have it, in simple terms if he doesn't not have it, he does have it.
    Next things next go to the if find is equal to kick and go to the { bracket, and click just after it and it should light up, scroll down and find the other high lighted bracket, this is where the end of the kick code is and you should put the else if after that.
    EDIT:
    Just realised my simple version of the permissions wasn't that simple, in even simpler terms if a player doesn't have a permission, he can't have it as well so you don't need to check to see if he has it
     
    #4 Heraldry, Apr 14, 2017
    Last edited: Apr 14, 2017
  5. Ok what @Heraldry ? If the player doesn't have the permission, he does? I said if the player doesn't have the permission then tell them that they do not have the permission to do the command.

    I have found out what you mean by the second thing so that is good but I am kind of concerned about what you said first.
     
  6. No offense bro but i would recommend you reading more about java since this is something you should know before starting with bukkit.. I dont want to sound harsh but just take another peek on how the condition works in java..
     
  7. Read my edit cx
    I realised it wasn't that clear.
    Basically if he doesn't have a permission then he can't have it as well, so you don't need to check if he has the permission (You still need to check if he doesn't).
    Code:
    Code (Text):
     If (!(player.hasPermission("me.me") {

             player.sendMessage("You do not have permission");
              Return true;
        }

        player.sendMessage("you do have permission");

    }
    f
     
  8. Ok @Heraldry would it still work if I didn't do that. If it doesn't work if I do that this is what I hear you saying. "I have to keep checking to make sure the player has the permission"
     
  9. You need to check if the player doesn't have the permission so you can send a no permissions message, once you've returned it eliminates the chance to not have the permission, therefore the player must have the permission
     
  10. Are you talking about the kick or the ban @Heraldry ? If you are talking about the ban then I know I can just copy and paste it.
     
  11. Ok.

    1) Make your title more detailed
    2) Wrong category, Next time post in Spigot Plugin Development.
     
  12. please. use args properly..
    Code (Java):
    else if (cmd.getName().equalsIgnoreCase("ban")) {
    just no
    close the other argument, and start again with
    Code (Java):
    if(args[0].equalsIgnoreCase("ban")) {
     
  13. if() {} else {}: proper usage

    if() else if(){}: proper usage

    if() else {} else {}: non proper usage. a boolean can only have 2 states (it's a primitive type so no null), true and false
     
    • Agree Agree x 1
  14. For the second one:
    Lets represent the stuff in brackets for the ifs in Runnables:
    Runnable r1 = new Runnable() {
    public void run() {
    blah blah blah.
    }
    }
    and so on.

    if(condition1) r1.run(); else if(condition 2) {}

    is the same as saying

    if(condition1) {
    r1.run();
    } else {
    if(condition2) {
    blah blah blah....
    }
    }
     
  15. Hmmm... very interesting...