How can i do like players can't send command to himself?

Discussion in 'Plugin Development' started by GorguZ, Jul 1, 2014.

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

    xTigerRebornx

    MoeMix Thats the thing, they usually won't understand. If all you do is throw (poorly) edited code at them, it changes nothing other then the fact that they now have that code. Whether they choose to learn or not is up to them (and from what I've seen, most choose not to). Taking the time to send them an explanation and concepts rather then just sending them their edited code saying "Here is your code, enjoy" will help them rather then just giving them code. This a plugin development section, if all you do is give them their completed code, it'd be no different from a plugin request.
     
  2. Offline

    Necrodoom

    MoeMix it wouldn't even work, your brackets are everywhere. You basically gave him broken code.
     
    xTigerRebornx likes this.
  3. Offline

    GorguZ

    i will just say that the code doesnt work and any people are free to help! I just want to say that please dont steal this thread and talk about anything offtopic...
     
  4. Offline

    chocolate_with

    Try this, not sure if it works.. doing it out of my head.
    Something like

    Code:
    If (args[1] == sender) {
    //A code here to cancel the command.  "Return false;" maybe?
    Sender.sendMessage("you cannot execute this on yourself")
    } else {
    // rest of the code.
    }
    
     
  5. Offline

    Necrodoom

    chocolate_with you are trying to compare a player object with a string. This will never work.

    GorguZ since so many people have tried to provide you with broken code, throw away all spoonfeeding given in this thread, and paste your original code and error.
     
  6. Offline

    afistofirony

    MoeMix / GorguZ The code you posted is a bit messy, as it only executes the command if the player does not have permission to run the command. :confused:

    Try starting with something like this (I'll leave you to fill in the blanks.):

    Code:
    public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
        if (label.equalsIgnoreCase("kram")) {
            if (!sender.hasPermission("kram.sendkram")) {
                // Tell the player he's not allowed to send hugs.
                return true;    // return true means no additional message is sent
            }
     
            if (!(sender instanceof Player)) {
                // Warn the user about how not being a player limits your hugging prowess.
                return true;
            }
     
            Player player = (Player) sender;
     
            // Now, begin.
            switch (args.length) {
                case 1: // The player has input the correct amount of arguments
                    if (player.getName().toLowercase().startsWith(args[0].toLowerCase())) {
                        /**
                        * Bukkit's getPlayer() method uses startsWith() matching.
                        * Here, you should tell the player that he cannot hug himself.
                        */
                        return true;
                    }
     
                    // Code for the hugging goes here.
                    return true;
     
                default: // Any more or any less than 1 argument
                    // Tell the player how to use the command.
                    return true;
            }
        }
     
        return false;
    }
    (P.S. Necrodoom I'm sorry)
     
  7. Offline

    Necrodoom

    afistofirony yay for completely unneeded spoonfeeding that still helps no one at all.

    If you people want to develop some else's plugin for him, there's a section called plugin requests.
     
    xTigerRebornx likes this.
  8. Offline

    Luke_Lax

    No... Not a all. Args[0] would be the player. It goes like: /command 0 1 2 3 ... Etc. in almost every computer language 0 is the start not 1.
     
  9. Offline

    Heirteir

    Guys it shouldn't be this hard to answer a question he should be smart enough to handle it based on all of these responses the answer is simple
    Code:java
    1. if (args[0].equalsIgnoreCase(player.getName())) return;
     
  10. Offline

    MoeMix

    We've all tried. I've given up after people have been accusing me of sending him messy/poor code when It wasn't my full code in the first place. I simply took what he sent me and added in a few things and due to the sloppy brackets (originally provided by the OP) I was accused for spoon-feeding and sending sloppy code...
     
  11. Offline

    GorguZ

    Hmm... I am not sure if its work it give me some errors when i try to my self and offline players (it should make a another error message) but i havent try to others. Would you like to come in on the server?

    It dosent work at all... The code been broken!

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

    Heirteir

    GorguZ
    You been broken....
     
  13. Offline

    GorguZ


    Code:java
    1. package me.gustavleithe.Kram;
    2.  
    3.  
    4. import org.bukkit.ChatColor;
    5. import org.bukkit.command.Command;
    6. import org.bukkit.command.CommandSender;
    7. import org.bukkit.entity.Player;
    8. import org.bukkit.plugin.java.JavaPlugin;
    9.  
    10.  
    11. public class Kram extends JavaPlugin{
    12.  
    13.  
    14.  
    15.  
    16. public void onEnable(){
    17. System.out.println("Kram onEnable");}
    18.  
    19. public void onDisable(){
    20. System.out.println("Kram onDisable");}
    21.  
    22.  
    23.  
    24. public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args){
    25. Player player = (Player) sender;
    26. if(player.hasPermission("kram.sendkram")){
    27. }else{
    28. player.sendMessage(ChatColor.RED + ("Denna funktion är fortfarnde i BETA"));
    29. if(cmd.getName().equalsIgnoreCase("kram")){
    30.  
    31. }
    32.  
    33. if(args.length == 0){
    34. //kram = 0 args //kram gurraplurra01 = 1 args
    35. sender.sendMessage(ChatColor.RED + ("För få argument! Andvänd: /kram spelarnamn för korrekt andvändning!"));
    36. }
    37. else if(args.length == 1){
    38. if (args[1].equals(player.getName())){}
    39.  
    40. sender.sendMessage(ChatColor.GREEN + ("Du har kramat " + ChatColor.YELLOW + player.getName() + ChatColor.GREEN + "!"));
    41. player.sendMessage(ChatColor.GREEN + ("Du har blivit kramad av" + ChatColor.YELLOW + sender.getName() + ChatColor.GREEN + "!"));
    42. }
    43. else{
    44. player.sendMessage("Spelaren är inte online!");
    45. }
    46. }
    47.  
    48. if (args.length > 2) {
    49. sender.sendMessage(ChatColor.RED + ("För många argument! Andvänd: /kram spelarnamn för korrekt andvändning!"));
    50.  
    51.  
    52.  
    53.  
    54.  
    55. if (args[0].equalsIgnoreCase(player.getName())) return false;
    56.  
    57. }
    58. return true;
    59.  
    60.  
    61. }{
    62.  
    63.  
    64. }{
    65.  
    66.  
    67. }{
    68.  
    69.  
    70.  
    71.  
    72.  
    73. }{}}
    74.  
     
  14. Offline

    Heirteir

    GorguZ
    I am not interested in reading different languages. Please post your Stacktrace
     
  15. Offline

    GorguZ

    What the heck did you mean?
     
  16. Offline

    xTigerRebornx

    GorguZ Take Necrodoom 's recommendation, throw away all the code that has been given to you, and try again. You clearly have just been taking code given, throwing it upon each previous code given, and expecting it to work. Start over, without taking all the spoon-fed nonsense.
     
  17. Offline

    GorguZ

    I
    I have post my first code if its that you are meaning?
     
  18. Offline

    Heirteir

    GorguZ
    Please learn basic java and bukkit before posting here.
     
  19. Offline

    GorguZ

    I have been done with many plugins and i hope i can the basic of java...
     
  20. Only because that's exactly what you did, regardless of intentions. Best bet is to never edit somebody else's code in this situation.

    GorguZ I'm sorry, but it's clear that you don't know the basics of Java well enough. You should learn them before touching bukkit. :)
     
  21. Offline

    GorguZ

    Well... The idea its pointless now
     
  22. Offline

    afistofirony

    GorguZ At the very least, fix this? D:

    Code:
                if(player.hasPermission("kram.sendkram")){
                }else{
    Either remove the 'else' or negate the if's condition.
     
  23. Offline

    GorguZ

    The project its on "ice" and i am current work with a another guy and we are making a minigame plugin... Anyways i will fix this later
     
Thread Status:
Not open for further replies.

Share This Page