[REQ] Block Replace [Name Your Prize, i can pay for it]

Discussion in 'Archived: Plugin Requests' started by Marius A. Winsjansen, Sep 16, 2011.

  1. Np, use your time!! :) i am over happy you did this in like, an houre! damn!!! :D
     
  2. Offline

    DrAgonmoray

    Would a config similar to this be ok?
    Code:
    default: 30
    1: 10
    42: 20
    34: 100
    Where default is the default time to wait, and the numbers before the : is the id, and the numbers after is the wait time.

    good? or have a better idea?
     
  3. that would be SO awsome!!! :D
     
  4. Offline

    DrAgonmoray

    Alright, I'll take a whack at it :p
     
  5. Just figured that out, should work:
    Code:
    long d = X; //X = default;
          for(Entry<String, Object> o: config.getAll().entrySet())
          {
            try
            {
              if(old == Integer.parseInt(o.getKey())
              {
                d = (Long)o.getValue();
                break;
              }
            }
            catch(NumberFormatException e)
            {
            }
          }
    :)

    //EDIT: Cleaned the example up a bit.
     
    DrAgonmoray likes this.
  6. Lovly, cant w8 to test it :D
     
  7. Offline

    DrAgonmoray

    I actually came up with a bit more elegant solution. :)
    I'll be uploading in a sec.

    Edit: Here it is:
    http://dl.dropbox.com/u/32736336/DropBlocks.jar
    Delete your config so it can make a new one.
    Here's an example config:
    Code:
    default: 30
    1: 10
    With that config, stone will come back in 10 minutes. Anything else will come back in the default 30 minutes.

    Untested, but it should work.
     
  8. default: 30 1: 10 42: 20 34: 100

    So i just do like that? :D
     
  9. Offline

    DrAgonmoray

    I think that would work, but put each option on a new line. :)
     
  10. yeah i did on the thread to, but, i dont know why it ended on one line xD
     
  11. Offline

    DrAgonmoray

    Silly forum formatting. xD
    Lemme know if it works.
    I'll test it myself too.

    Edit:
    it errors, i'll work on a fix.
     
  12. Don't forget the newlines:
    default: 30
    1: 10
    42: 20
    34: 100
    ;)
    Looks really nice. :) But is jad doing something wrong or is this line a bit stupid:
    Code:
    return (long)((Integer)plugin.times.get(Integer.valueOf(id))).intValue();
    :confused:
     
    DrAgonmoray likes this.
  13. Offline

    DrAgonmoray

    I don't even want to know what that mess is, lol.
    it appears that yaml doesn't like nodes to be numbers. :|
     
  14. It's one possible reply for getTime(int id) ... but well, I think jad formatted it that crazy... :D

    //EDIT: But what it does is really messy:
    1. convert int to int: Integer.valueOf(id)
    2. get the value from the HashMap.
    3. convert the value to an int: ((Integer)plugin.times.get(Integer.valueOf(id)))
    4. convert the result of 3 to an int: *.intValue()
    5. convert that to long and return it: return (long)*

    But wait, if I think about it maybe that's javas way to do this, because in fact it doesn't convert from int to int, it converts from int to Integer and vice-versa... Strange java... :confused:
     
    DrAgonmoray likes this.
  15. It dont work now, not the defualt nor the others:/
     
  16. Offline

    DrAgonmoray

    Yeah, I'm trying to fix it. I'm going to have to use a different system D:
     
  17. What's the problem? (Want to help :))
     
    DrAgonmoray likes this.
  18. Thansk for all the hard work guys!! Its very nice that you do this!!
     
  19. Offline

    DrAgonmoray

    Yaml doesn't like integers as nodes. I think I've got a solution. testing now.
     
  20. You mean numbers? Because a node has to be a string, I think?
     
    DrAgonmoray likes this.
  21. Offline

    DrAgonmoray

    k it works now.
    http://dl.dropbox.com/u/32736336/DropBlocks.jar
    New config:
    Code:
    default: 2
    group1:
        time: 1
        ids:
        - 1
        - 5
    bbq:
        time: 5
        ids:
        - 42
        - 49
        - 12
    
    Now we have "groups"
    every id in a certain group shares the same time. So All ids in group1 will respawn in 1 minute. All ids in 'bbq' will respawn in 5 minutes. Everything else will respawn in default minutes.

    You can have as many ids as you want in each id list, and you can name the groups whatever you like. :)
     
  22. Nice, would you send me the sources? The decompiled ones are so messy and I want to implement a feature... :p
     
    DrAgonmoray likes this.
  23. Offline

    DrAgonmoray

    :eek: what feature?
    http://pastebin.com/2mbBQfqt
     
  24. Offline

    Celeixen

    Man, your an absolute BOSS! i don't need this plugin of course but amazing work helping that guy :)
     
    DrAgonmoray likes this.
  25. Offline

    DrAgonmoray

    lol, go tell that to @M1sT3rM4n please. :)
     
  26. Offline

    Celeixen

    DrAgonmoray likes this.
  27. Offline

    DrAgonmoray

  28. @DrAgonmoray:
    This one:
    Show Spoiler
    Code:
    diff -Nru net/livecraft/DrAgonmoray/DropBlocks/Config.java net.new/livecraft/DrAgonmoray/DropBlocks/Config.java
    --- net/livecraft/DrAgonmoray/DropBlocks/Config.java    2011-09-17 06:30:55.000000000 +0200
    +++ net.new/livecraft/DrAgonmoray/DropBlocks/Config.java    2011-09-17 06:26:18.000000000 +0200
    @@ -2,6 +2,7 @@
    
     import java.io.File;
    
    +import org.bukkit.Material;
     import org.bukkit.util.config.Configuration;
    
     public class Config {
    @@ -42,9 +43,19 @@
             public void loadconfig() {
                     config.load();
                     plugin.time = readInt("default", 30);
    +                int i;
                     for (String key : config.getKeys()) {
                             if (!key.equals("default")) {
    -                                for (int i : config.getIntList(key+".ids", null)) {
    +                                for (Object o: config.getList(key+".ids")) {
    +                                        i = -1;
    +                                        try
    +                                        {
    +                                            i = Integer.parseInt((String)o);
    +                                        }
    +                                        catch(NumberFormatException e)
    +                                        {
    +                                            i = Material.getMaterial(((String)o).replace(" ", "_").toUpperCase()).getId();
    +                                        }
                                             if(i > 0)
                                               plugin.times.put(i, config.getInt(key+".time", plugin.time));
                                     }
                             }

    I hope you understand these patch syntax and I hope you see what it will do. ;)
     
    DrAgonmoray likes this.
  29. Offline

    DrAgonmoray

    Yay for support for material names :D
     
  30. Damn, i didnt think i would get so much help and so good respond for my plugin!!
    Thank you all SO much for the help!!! This is SO awsome plugin for my server and you really made the server good for me now!!! :D
     

Share This Page