PluginCommands.java

Discussion in 'Plugin Development' started by poxsgaming, Jun 3, 2014.

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

    poxsgaming

    Hi I was wondering if someone could help me with this, I'm helping a friend with parts in this plugin while he's doing the more complicated parts.

    I'm completely stuck here and I have very small knowledge in coding.

    I'm trying to set all these commands, I did the most I could and I typed in ()'s what I need it to do, and I can't find anything online on how to pull up the <player_name> or <skill_name> parts so it can be used in game and used with the aliases I have set.

    I would really appreciate the help!

    Or at least some pointers or examples of how it's done and I can do the rest from there.

    Code:java
    1. public class RsLevelsCommands implements CommandExecutor {
    2.  
    3. @Override
    4. public boolean onCommand(CommandSender sender, Command cmd, String label,
    5. String[] args) {
    6. if (cmd.getName().equalsIgnoreCase("rslevels")){
    7. sender.sendMessage("/s list: \n "
    8. + " Lists all skills active in the server. \n"
    9. + "/s xp give <player_name> <skill_name>: \n"
    10. + " Gives a player given amount of exp. \n"
    11. + "/s xp set <player_name> <skill_name>: \n"
    12. + " Sets players xp to a given amount. \n"
    13. + "/s level set <player_name> <skill_name>: \n"
    14. + " Sets players level to a given amount. \n"
    15. + "/s guide <skill_name>: \n"
    16. + " Shows a scoreboard indicating the amount of exp gained in the searched skill. \n"
    17. + "/s monitor: \n"
    18. + " Shows a scoreboard indicating exp gained per action. \n"
    19. + "/s tracker: \n"
    20. + " Shows scoreboard indicating exp on the 2 most recent trained skills. \n"
    21. + "/s highscore <skill_name>: \n"
    22. + " Shows scoreboard of top 10 players in each skill. \n"
    23. + "/s stats: \n"
    24. + " Shows your skill levels on a scoreboard. \n"
    25. + "/s stats <player_name>: \n"
    26. + " Shows searched players name on a scoreboard. \n"
    27. + "/s reset <skill_name>: \n"
    28. + " Allows player to reset skill level to 1. \n"
    29. + "/s reset <skill_name> <player_name>: \n"
    30. + " Allows player to reset other players level to 1.");
    31.  
    32. if (args[0].equals("list")){
    33. sender.sendMessage("Current active skills: \n"
    34. + "(something that lists all active skills in a list");
    35. }
    36. if (args[0].equals("xp give")){
    37.  
    38. sender.sendMessage("You have given (something that gets the player name) (given xp) in (skill)");
    39. }
    40. if (args[0].equals("xp set (something that gets the player name) (something that gets the skill name)")){
    41. //something
    42. sender.sendMessage("You have set (something that gets the player name) exp to (given xp) in (skill)");
    43. }
    44. if (args[0].equals("level set (something that gets the player name) (something that gets the skill name)")){
    45. //something
    46. sender.sendMessage("You have set (something that gets the player name) level to (given level) in (skill)");
    47. }
    48. if (args[0].equals("xp guide (something that gets the skill name)")){
    49. //something
    50. }
    51. if (args[0].equals("monitor")){
    52. //something
    53. }
    54. if (args[0].equals("tracker")){
    55. //something
    56. }
    57. if (args[0].equals("highscore (something that gets the skill name)")){
    58. //something
    59. }
    60. if (args[0].equals("stats")){
    61. //something
    62. }
    63. if (args[0].equals("stats (something that gets the player name)")){
    64. //something
    65. }
    66. if (args[0].equals("reset (something that gets the skill name)")){
    67. //something
    68. sender.sendMessage("You have reseted your skill level to 1 in (skill)");
    69. }
    70. if (args[0].equals("reset (something that gets the player name) (something that gets the skill name)")){
    71. //something
    72. sender.sendMessage("You have reseted (something that gets player name) skill level to 1 in (skill)");
    73. }
    74. return true;
    75. }
    76.  
    77. return false;
    78. }
    79.  
    80. }
     
  2. How many other files are there? Could I see the main file? And plugin.yml?
     
  3. Offline

    poxsgaming

    [​IMG]
     
  4. Also, for getting players you want to do :-

    Player p = Bukkit.getPlayer(args[0]); // or which ever argument it is.

    In Main, are you importing the commands from the command executor file?

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

    poxsgaming

    Is it possible to see an example of how it would be finished, with one of the ones that ask for 3 methods?


    For example, how would I interpret the parts I put in ()'s in code?

    Code:java
    1. if (args[0].equals("xp set (something that gets the player name) (something that gets the skill name)")){
    2. //something
    3. sender.sendMessage("You have set (something that gets the player name) exp to (given xp) in (skill)");
     
  6. Okay, so let's go through xpgive. For this sake, I'm going to put xp and give together.

    Code:
    if (cmd.getName().equalsIgnoreCase("s")) {
         if (args[0].equalsIgnoreCase("xpgive")) {
              Player p = Bukkit.getPlayer(args[1]); // converts the arg, from a string to a player.
              String skill = args[2]; // defines skill as argument 2
              int xp = args[3];
              xpgive(p, skill, xp); // if you had this function, this would work
         }
    }
    Untested, may not work.
     
  7. Offline

    poxsgaming

    s is an alias of rslevels

    I'll test that out, and move it around with the stuff that needs to be implemented. thanks for the help!

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 30, 2016
  8. No problem! Happy to help.
     
Thread Status:
Not open for further replies.

Share This Page