QUICK Question!

Discussion in 'Plugin Development' started by NeoSilky, Oct 5, 2011.

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

    NeoSilky

    How do i delete a file? eg. a .yml file? :D
     
  2. Offline

    Ahniolator

    This should work properly. Let me know, I may have missed something
    Code:java
    1. File exFile = new File(exampleDir + "example.yml");
    2. exFile.delete();
     
  3. Offline

    wwsean08

    if you have that file in a variable, file.delete(), it will remove true or false depending on whether it's successful​
     
  4. Offline

    NeoSilky

    thank you :D

    Also, how do i get integer from yml file?
    Doing

    int likes = profiles.getInt(player.getDisplayName + ".Likes", 0);

    And the config is setup like

    Likes: 2

    always seems to give back 0, even when the numbers in the config change. :/
     
  5. Offline

    wwsean08

    because there is nothing before before the Likes, say it was for me, it would have to say:
    wwsean08.Likes: 2

    for it to give you 2
     
  6. Offline

    Ahniolator

    You have to load the changes in the config every time you save to the file. The information stored in the cache does not change until you reload the file.
    Edit: Or edit it directly
     
  7. Offline

    NeoSilky

    sorry, im on my phone, so it doesn't have my code on, but i have say NeoSilky, then inside that, so kinda set out like 'permissions', as property i have Likes: andthenanumber. i want the fault to be 0, but it doesn't read the path :(

    So do you mean saving the file when its been likes has changed? Or loading it when i ask for it?

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 20, 2016
  8. Offline

    Ahniolator

    You want to save after you change the file, and load it whenever the data in the file has been changed.
     
  9. Offline

    NeoSilky

    ahhh, that makes sense, so when i want the code in the section, load the file? :D

    ALSO... using a string builder? Someone gave me some code, it it gives error, it looks practical to work, it just doesnt :p i just want to get all text after the first args and put it in one string :)
     
  10. Offline

    wwsean08

    well once you get back on your comp upload the string builder code that is erroring and we can take a look
     
  11. Offline

    Ahniolator

    You want to make one string out of many? Would you mind sharing a snippet so I can see what exactly you are trying to do?
     
  12. Offline

    NeoSilky

    hang on, im not on my laptop, but i can c+p the code from an inbox, two secs :)
     
  13. Offline

    oyasunadev

    config.load();
     
  14. Offline

    NeoSilky

    right, i had a look, but i'm pretty sure, this is different to the code i recieved from somewhere which i've been using, but here:

    Code:
    	  StringBuilder message = new StringBuilder();
    	  for(String arg: args)
    	  {
    		message.append(" ");
    		message.append(arg);
    	  }
    	  Strg msg = message.toString().trim();
    Even if it did work, then it still doesnt take away the first args :)

    actually found the code that i was sent by another person, this one should technically work, but it doesn't, they said i should take the String Builder bit of of the if statement i have surreound the code but.... :)

    StringBuilder message = new StringBuilder();
    for(int i = 1; i < args.length; i++)
    {
    message.append(args);
    message.append(' ');
    }


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

    Ahniolator

    I can't really help right now because I'm in class, but if you still are up in two hours I'll be glad to help you :)
     
  16. Offline

    NeoSilky

    i might be, but elsewise, i'll be up at 7, my time, so 11 yours :D
     
  17. Offline

    Ahniolator

    I'll probably be up then too ;)
     
    NeoSilky likes this.
  18. Offline

    Sagacious_Zed Bukkit Docs

    If you are still having trouble concatenating all the elements. Although I ask that, if you use it, credit me as it is a full method.
    Code:java
    1. /**
    2.   * This method concatenates the Strings in an array with a space between
    3.   * them, but ignores the first element in the array.
    4.   *
    5.   * @author SagaciousZed
    6.   * @param args
    7.   * Array of type String to be concatenated
    8.   * @return returns The output string with the elements
    9.   */
    10. private String concatRestArrayWithSpace(String[] args) {
    11. switch (args.length) {
    12. case 0:
    13. case 1:
    14. return "";
    15. case 2:
    16. return args[1];
    17. default:
    18. StringBuilder stringBuilder = new StringBuilder(args[1]);
    19. stringBuilder.append(" ");
    20. for (int n = 2; n < args.length; n++) {
    21. stringBuilder.append(args[n]);
    22. if (n != args.length - 1) {
    23. stringBuilder.append((" "));
    24. }
    25. }
    26. return stringBuilder.toString();
    27. }
    28. }


    EDIT: this is really the kind of problem any programmer worth his salt can solve. How elegant and efficient however, is a different matter.
     
  19. Offline

    ZerothAngel

    I think this should work:
    Code:
    String str = Joiner.on(" ").join(Arrays.copyOfRange(args, 1, args.length));
    
    Joiner is com.google.common.base.Joiner from Google Guava, which I believe CraftBukkit depends on...
     
  20. Offline

    Sagacious_Zed Bukkit Docs

    Found this in the pom.xml
    Code:
        <dependency>
          <groupId>com.google.guava</groupId>
          <artifactId>guava</artifactId>
          <version>10.0</version>
          <type>jar</type>
          <scope>provided</scope>
        </dependency>
    EDIT: and thats an elegant solution.
     
  21. Offline

    ZerothAngel

    Cool. I also never noticed it was an explicit dependency for Bukkit as well, so I take that to mean Guava is "part of the plugin API." :)
     
  22. Offline

    NeoSilky

    I used your code :D It works! Thanks a lot ! :D:D
     
Thread Status:
Not open for further replies.

Share This Page