Strange config stuff....

Discussion in 'Plugin Development' started by dmoney12321, Nov 18, 2013.

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

    dmoney12321

    Heres the code:
    Code:java
    1. package me.Dmoney12321.WhereToSell;
    2.  
    3. import java.io.File;
    4. import java.util.logging.Logger;
    5.  
    6. import org.bukkit.ChatColor;
    7. import org.bukkit.command.Command;
    8. import org.bukkit.command.CommandSender;
    9. import org.bukkit.entity.Player;
    10. import org.bukkit.plugin.PluginDescriptionFile;
    11. import org.bukkit.plugin.java.JavaPlugin;
    12.  
    13. public class WhereToSell extends JavaPlugin
    14. {
    15. public final Logger logger = Logger.getLogger("Minecraft");
    16. public static WhereToSell plugin;
    17.  
    18. @Override
    19. public void onDisable()
    20. {
    21. PluginDescriptionFile pdfFile = this.getDescription();
    22. this.logger.info(pdfFile.getName() + " Has Been Disabled!");
    23. }
    24.  
    25. @Override
    26. public void onEnable()
    27. {
    28. PluginDescriptionFile pdfFile = this.getDescription();
    29. this.logger.info(pdfFile.getName() + "Version" + pdfFile.getVersion() + " Has Been Enabled!");
    30. File configFile = new File(getDataFolder() + File.separator + "config.yml");
    31. if (!configFile.exists()){
    32. getConfig().options().copyDefaults(true);
    33. saveDefaultConfig();
    34. this.getLogger().info("Generating config.yml...");
    35. this.getConfig().addDefault("selldiamond", "Default");
    36. this.getConfig().addDefault("buydiamond", "Default");
    37. this.saveConfig();
    38. }
    39. else if(configFile.exists()){
    40. this.getLogger().info("Reloading config.yml");
    41. this.reloadConfig();
    42. this.saveConfig();
    43.  
    44. }
    45.  
    46. }
    47.  
    48. public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args){
    49. Player p = (Player) sender;
    50. if(cmd.getName().equalsIgnoreCase("wts")){
    51. //Sends error message if no args are entered.
    52. if (args.length == 0){
    53. p.sendMessage(ChatColor.RED + "Correct usage is /wts (item name)");
    54. }
    55. //Help args (Sends info)
    56. else if (args[0].equalsIgnoreCase("help")){
    57. p.sendMessage(ChatColor.LIGHT_PURPLE + "WhereToSell by Dmoney12321. Do /wts (item name) to find out where you can sell said item.");
    58. p.sendMessage(ChatColor.LIGHT_PURPLE + "Example: /wts diamond would send you a message saying where you can sell diamond");
    59. }
    60. //begin item naming
    61. else if (args[0].equalsIgnoreCase("diamond")){
    62. p.sendMessage(ChatColor.LIGHT_PURPLE + "You can sell this item at " + this.getConfig().getString("selldiamond"));
    63. }
    64. }
    65. //
    66. //
    67. //
    68. //
    69. // WHERE TO BUY COMMANDS
    70. //
    71. //
    72. //
    73. //
    74. else if (cmd.getName().equalsIgnoreCase("wtb")){
    75. //Sends error message if no args are entered.
    76. if (args.length == 0){
    77. p.sendMessage(ChatColor.RED + "Correct usage is /wtb (item name)");
    78. }
    79. //Help args (Sends info)
    80. else if (args[0].equalsIgnoreCase("help")){
    81. p.sendMessage(ChatColor.LIGHT_PURPLE + "WhereToBuy by Dmoney12321. Do /wtb (item name) to find out where you can buy said item.");
    82. p.sendMessage(ChatColor.LIGHT_PURPLE + "Example: /wtb diamond would send you a message saying where you can buy diamond");
    83. }
    84. //Begin item naming.
    85. else if (args[0].equalsIgnoreCase("diamond")){
    86. p.sendMessage(ChatColor.LIGHT_PURPLE + "You can buy this item at " + this.getConfig().getString("buydiamond"));
    87. }
    88. }
    89. else if (cmd.getName().equalsIgnoreCase("wtreload")){
    90. if(p.isOp()){
    91. this.reloadConfig();
    92. this.saveConfig();
    93. p.sendMessage(ChatColor.GREEN + "Reloaded.");
    94. }
    95. else if(!p.isOp()){
    96. p.sendMessage(ChatColor.RED + "Sorry, you cannot do that.");
    97. }
    98. }
    99. return false;
    100. }
    101. }

    And the config:
    Code:
    buydiamond: /warp 18c
    selldiamond: /warp 18x
    But for some reason when i type the command /wts diamond or /wtb diamond it only says You can buy this item at Default or You can sell this item and Default.
    Why?
     
  2. Offline

    the_merciless

    I read and here is my reply.

    Get some manners and ask more politely
     
  3. Offline

    dmoney12321

    Bump. Please help me guys! :(
     
  4. Offline

    L33m4n123

    thats why I guess

    Code:
    this.getConfig().addDefault("selldiamond", "Default");
                this.getConfig().addDefault("buydiamond", "Default");
     
  5. Offline

    dmoney12321

    L33m4n123
    I have tried with an without them. Doesnt work for either :(
     
  6. Offline

    AoH_Ruthless

    dmoney12321
    Right before after each closing bracket, add a return true statement so it doesn't fall through.
     
  7. Offline

    The_Doctor_123

    Umm.. excuse me? I don't see how he was rude?
     
  8. Offline

    L33m4n123


    He edited his Thread titel by now
     
  9. Offline

    The_Doctor_123

  10. Offline

    L33m4n123

    Trust me his thread titel was something like

    NEED HELP NOW!!

    and if you change the title via the Thread Tool you do not see that any post was edited since no post was edited
     
  11. Offline

    The_Doctor_123

  12. Offline

    sgavster

    Don't use 'this' just remove that, it should work
     
  13. Offline

    jacklin213

    you do not need to call
    Code:
    this.saveConfig();
    when after you call
    Code:
    this.reloadConfig();
    and if your going to use
    Code:
    getConfig().options().copyDefaults(true);
    saveDefaultConfig();
    dont use
    Code:
    this.getConfig().addDefault("selldiamond", "Default");
    this.getConfig().addDefault("buydiamond", "Default");


    No that will do nothing, the modifier 'this' just refers back to the same class, it makes no difference whatsoever
     
Thread Status:
Not open for further replies.

Share This Page