Solved Args problem!

Discussion in 'Plugin Development' started by BearProgrammer, Aug 7, 2014.

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

    Necrodoom

    BearProgrammer that's because you keep insistingly trying to print args[1], expecting by some whatever some other result, without actually trying to reach desired result.
     
    AdamQpzm likes this.
  2. Offline

    BearProgrammer

    no, i tryed alot of times with "s" and this is still send the first word. Maybe im starter but not an idiot.
     
  3. Offline

    Necrodoom

  4. Offline

    BearProgrammer

    [/i] cuz if you do [/i] with out the "/" bukkit forum make it Italic font.

    Code:java
    1. package me.sahar.com;
    2.  
    3. import java.util.Scanner;
    4. import java.util.logging.Logger;
    5.  
    6. import org.bukkit.Bukkit;
    7. import org.bukkit.command.Command;
    8. import org.bukkit.command.CommandSender;
    9. import org.bukkit.entity.Player;
    10. import org.bukkit.event.player.PlayerMoveEvent;
    11. import org.bukkit.plugin.PluginDescriptionFile;
    12. import org.bukkit.plugin.java.JavaPlugin;
    13.  
    14. public class Main extends JavaPlugin {
    15. public final Logger logger = Logger.getLogger("Minecraft");
    16. public static Main plugin;
    17.  
    18. @Override
    19. public void onEnable() {
    20. PluginDescriptionFile pdf = this.getDescription();
    21. this.logger.info(pdf.getName() + " Version" + pdf.getVersion()
    22. + " Has been enabled!");
    23. }
    24.  
    25. @Override
    26. public void onDisable() {
    27. PluginDescriptionFile pdf = this.getDescription();
    28. this.logger.info(pdf.getName() + " Version" + pdf.getVersion()
    29. + " Has been disabled!");
    30. }
    31.  
    32. @SuppressWarnings("unused")
    33. public boolean onCommand(CommandSender sender, Command cmd,
    34. String commandLabel, String[] args) {
    35. if (commandLabel.equalsIgnoreCase("sendmessage")) {
    36. if (args.length == 0) {
    37. sender.sendMessage("Enter a player name.");
    38. return true;
    39. }
    40. if (args.length == 1) {
    41. Player target = Bukkit.getServer().getPlayer(args[0]);
    42. if (target == null) {
    43. sender.sendMessage("Player didnt found! " + args[0] + ".");
    44. return true;
    45. }
    46. sender.sendMessage("Please enter a message.");
    47. return true;
    48. }
    49. if (args.length >= 2) {
    50. Player target = Bukkit.getServer().getPlayer(args[0]);
    51. StringBuilder sb = new StringBuilder("");
    52. for(int i = 1; i<args.length; i++){
    53. sb.append(args[/i]).append(" ");
    54. String s = sb.toString();
    55. target.sendMessage(s);
    56. sender.sendMessage("Message sends sucsfully!");
    57. return true;
    58. }
    59. }
    60. }
    61. return true;
    62. }
    63. }
    64.  
     
  5. Offline

    Necrodoom

  6. Offline

    BearProgrammer

    What is messed up with the loop brackets? Its looks fine..
     
  7. Offline

    Necrodoom

    BearProgrammer aside from the fact that you only ever loop the for once before sending s as message and returning from the onCommand?
     
  8. Offline

    iBecameALoaf

    remove the bracket on line 58, and add one after String s = sb.toString()
     
  9. Offline

    BearProgrammer

    What?...
     
  10. Offline

    Necrodoom

    BearProgrammer if you do not know how a for loop works, please read a Java tutorial such as oracle's - there's only so much I can try guide you, you need to understand what your code does yourself.
     
  11. Offline

    iBecameALoaf

  12. Offline

    BearProgrammer

    I do waht you wirte to me.. and this do somethink strange... look at the chat:
    http://www.siz.co.il/my.php?i=znemiwm2zy5m.png
     
  13. Offline

    Necrodoom

    BearProgrammer that's because, you, again, blindly copy-pasted an instruction without understanding why.
    You need to understand how for loop works.
    Noticed you used an Israeli website, so you may understand heb-glish (out of Hebrew keyboards at the moment)

    Ata charih lehavin Java lifnei sheets menase letahnet.
     
  14. Offline

    BearProgrammer

    Im not isreali -.- Im just knows that website as good Photos uploading website.

    well fuck that if u Keep telling me that im really bad in java thats not Help.

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

    Gnat008

    BearProgrammer
    He didn't say that. He said you do not yet understand what we are trying to tell you. There is a difference.
    For this, try looking at this.
    Then, look at your code line by line, and see if it makes sense.
     
  16. Offline

    mazentheamazin

    BearProgrammer
    I don't think he's saying you are bad at programming in Java, he's saying you don't know Java. There's nothing wrong with that, but if you're going to make Bukkit plugins you should know Java. Like I said multiple times before:
     
    iBecameALoaf and Gnat008 like this.
  17. Offline

    BearProgrammer

    Thanks alot! SOLVED
     
Thread Status:
Not open for further replies.

Share This Page