New Coder Needs A Bit Of Help..

Discussion in 'Plugin Development' started by thegarfish, Jul 30, 2013.

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

    thegarfish

    I am having an issue with the mechanic of coins.. The only command that works is /roteco... Please help if you notice any mistakes.

    Code:java
    1. package me.rot.RotZone;
    2.  
    3. import java.util.logging.Logger;
    4.  
    5.  
    6.  
    7.  
    8.  
    9. import org.bukkit.ChatColor;
    10. import org.bukkit.command.Command;
    11. import org.bukkit.command.CommandSender;
    12. import org.bukkit.entity.Player;
    13. import org.bukkit.plugin.PluginDescriptionFile;
    14. import org.bukkit.plugin.java.JavaPlugin;
    15.  
    16. public class Economy extends JavaPlugin{
    17.  
    18. public final Logger logger = Logger.getLogger("Minecraft");
    19. public static Economy plugin;
    20. int counter = 0;
    21.  
    22. @Override
    23. public void onDisable() {
    24. PluginDescriptionFile pdfFile = this.getDescription();
    25. this.logger.info(pdfFile.getName() + " Has Been Disabled!");
    26. }
    27. @Override
    28. public void onEnable(){
    29. PluginDescriptionFile pdfFile = this.getDescription();
    30. this.logger.info(pdfFile.getName() + " Version " + pdfFile.getVersion() + " Has Been Enabled ");
    31. }
    32.  
    33.  
    34.  
    35. //is operator code
    36.  
    37. public boolean onCommand(CommandSender sender, Command cmd,
    38. String commandLabel, String[] args){
    39. Player player = (Player) sender;
    40. if(commandLabel.equalsIgnoreCase("RotEco")){
    41. if(args.length == 0){
    42. if(player.isOp()){
    43.  
    44. player.sendMessage("----" + ChatColor.GOLD + "RotEco (EventAdmin)" + ChatColor.WHITE + "----");
    45. player.sendMessage(ChatColor.AQUA + "/Coins" + ChatColor.WHITE + " | " + ChatColor.GREEN + "Shows your balance!" );
    46. player.sendMessage(ChatColor.AQUA + "/RInfo" + ChatColor.WHITE + " | " + ChatColor.GREEN + " Displays information about the economy system in the RotZone!!!" );
    47. player.sendMessage(ChatColor.AQUA + "/RGive" + ChatColor.WHITE + " | " + ChatColor.GREEN + "Gives winners of events tokens, dont abuse or you will be banned from the RotZone" );
    48. }else if(commandLabel.equalsIgnoreCase("Coins")){
    49.  
    50. player.sendMessage(ChatColor.AQUA + "You Have 0 coins");
    51. }else if (counter == 1){
    52. player.sendMessage("You have 1 coin!");
    53. }else{
    54. player.sendMessage("You have" + counter + "coins!");
    55. }
    56.  
    57. }else if(commandLabel.equalsIgnoreCase("RInfo")){
    58. player.sendMessage(ChatColor.AQUA + " This Plugin was made and devoloped by rotciv157, This plugin adds an economy based system to the RotZone, Coins can be used to buy ranks, perks, and upgrades. Type /RotEco For more commands!!!");
    59.  
    60. }else if
    61. (commandLabel.equalsIgnoreCase("RGive" + player.getName() ));
    62. }if(args.length == 1){
    63. if(player.getServer().getPlayer(args[0]) != null){
    64. Player targetPlayer = player.getServer().getPlayer(args[0]);
    65. if(player.isOp()){
    66. counter++;
    67. targetPlayer.sendMessage(ChatColor.GREEN + "You have recieved a coin from " + ChatColor.GREEN + player.getName());
    68. targetPlayer.sendMessage(ChatColor.GREEN + "You have" + counter + " Coins");
    69.  
    70.  
    71. //is not operator code
    72.  
    73.  
    74.  
    75.  
    76. }else
    77.  
    78. if(commandLabel.equalsIgnoreCase("RotEco")){
    79.  
    80. player.sendMessage("----" + ChatColor.GOLD + "RotEco" + ChatColor.WHITE + "----");
    81. player.sendMessage(ChatColor.AQUA + "/Coins" + ChatColor.WHITE + " | " + ChatColor.GREEN + "Shows your balance!" );
    82. player.sendMessage(ChatColor.AQUA + "/RInfo" + ChatColor.WHITE + " | " + ChatColor.GREEN + " Displays information about the economy system in the RotZone!!!" );
    83.  
    84. }else if(commandLabel.equalsIgnoreCase("Coins")){
    85. player.sendMessage(ChatColor.AQUA + "You Have" + counter + "Coins!");
    86.  
    87. }else if(commandLabel.equalsIgnoreCase("RInfo")){
    88. player.sendMessage(ChatColor.AQUA + " This Plugin was made and devoloped by rotciv157, This plugin adds an economy based system to the RotZone, Coins can be used to buy ranks, perks, and upgrades. Type /RotEco For more commands!!!");
    89.  
    90. }else if(commandLabel.equalsIgnoreCase("Coins")){
    91. if (counter == 0){
    92. player.sendMessage(ChatColor.AQUA + "You Have 0 coins");
    93. }else if (counter == 1){
    94. player.sendMessage("You have 1 coin!");
    95. }else{
    96. player.sendMessage("You have" + counter + "coins!");
    97. }
    98.  
    99.  
    100.  
    101.  
    102.  
    103.  
    104.  
    105. }
    106. }
    107. }
    108.  
    109. return false;
    110. }
    111. }
    112.  
     
  2. Offline

    monkeymanboy

    can you show your plugin.yml?
     
  3. Offline

    IanM_56

    Could you please elaberate on what the 'problem' is? (Is this your first plugin?)
     
  4. Offline

    thegarfish

    Here you go...
    Code:
    name: RotZone Economy
    main: me.rot.RotZone.Economy
    version: 1.0
    description: >
                Youtube Plugin.
    commands:
      RotEco:
        description: Econmy Commands
      Coins:
        description: Shows balance
      RInfo:
        description: Show Information for the RotEco Plugin
      RGive:
        description: Gives Player coins
    

    I have done other simple plugins before, like broadcasting. But... The issue is that /coins and /rgive don't work.

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

    Firefly

    You have some bracketing issues. If you fix where your brackets are, I'm sure it would work. Just make sure the your if blocks end where you want them to and you don't start an else-if block somewhere you don't want to.
     
  6. Offline

    IanM_56

    Yes, but what is the goal of the plugin.
     
  7. Offline

    rotciv

    A small economy system to be able to add coins to players who win games, ect I am with thegarfish.
     
  8. Offline

    thegarfish

    What Rotciv said.
     
  9. Offline

    rotciv

    Bracket issues could you help me find were??
     
  10. Offline

    IanM_56

    So how is the plugin used? Is it an Economy plugin, a Game, ??? (The current code is not how Economy related functions are done)
     
  11. Offline

    rotciv

    Like mini games, When you win a mini game, I can manually add 1 coin to the winning player
     
  12. Offline

    adam753

    This. You need to fix the indentation of your code. Use one tab per indent (press tab), and try to be consistent with things like where your {'s and }'s go, how you lay out your "else if"s, and most relevantly, which 'if' an else is following. You probably think this is just trivial and you don't need to do it to solve the problem, but I can promise you will have much less problems like these when you adopt some sort of coding style rather than letting it get this messy.
     
  13. Offline

    SnipsRevival

    Your command cannot possibly equal both "RotEco" and "Coins". That is, however, what your code is looking for. Start by fixing that.
     
  14. Offline

    thegarfish


    The plugin will be used in order to reward players who win events. A player wins the event, and event admin gives him a coin. Coins will eventually be spent on thinks withing the zone.


    So the entire reason it isn't working is bracket issues?
     
  15. Offline

    adam753

    Pretty much. I can see at least one bracketing mistake in your code which would have been avoided by more careful laying-out.
    (Not to mention code like this is a nightmare for others to read, which will put others off helping you.)
     
  16. Offline

    IanM_56

    One huge problem is this code does not do what you want. The counter variable would act on all players, you need to save player's coin totals in a config and read and write to that. Also you need to fix your bracketing.

    Bracketing and Code

    He might as well add an alias to his plugin.yml

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

    rotciv

    Could you explain how to properly make a config?
     
Thread Status:
Not open for further replies.

Share This Page