[API/Snippet/Util] (Proposed) Standard Item Syntax

Discussion in 'Resources' started by Me4502, Jun 24, 2013.

?

Yay or Nay?

  1. Yay

    100.0%
  2. Nay

    0 vote(s)
    0.0%
  3. We need unification, but this isn't the right format to do it with.

    0 vote(s)
    0.0%
Thread Status:
Not open for further replies.
  1. Offline

    Me4502

    Hi, I'm me4502, the developer of CraftBook. You may or may not know of me.

    Basically, I have had a very extensive item parsing syntax coded into CraftBook for a while now, which is very extendable. The format also works well, and CraftBook is open source so anyone can copy it or improve it. I propose, that we use this format as the 'Standard Item Syntax', allowing most bukkit plugins to follow a similar item parsing syntax to lower confusion amongst server administrators.

    The latest version of the proposed syntax can always be found here: https://github.com/sk89q/craftbook/...java/com/sk89q/craftbook/util/ItemSyntax.java

    In the methods, getItem(String), and getStringFromItem(ItemStack). Those two methods convert items into strings, and back again. If you want to improve the format, please make a PR in CraftBook. If everyone starts using this format we can have a more unified server administrating experience with plugin setup and other related activities.

    A wiki page from the CraftBook wiki explaining this syntax is as follows, http://wiki.sk89q.com/wiki/CraftBook/Item_Syntax

    If you have any suggestions, please state them.

    Thankyou,

    ~ Me4502
    Lead Developer of CraftBook.
     
    hawkfalcon, Hoolean and Minecrell like this.
  2. if I didn't need to take your whole craftbook to implement this, I would add it to my plugin, just make 1 class with the methods needed for us to use this format and dont let it depend on other parts of your plugin, nobody wants forget dependencies
     
  3. Offline

    Me4502

    I guess I could make a single class that contains the current version of the syntax.

    Edit: This has now been done.
     
  4. Not to point out flaws for the sake of it (Really like this idea) but it does have a dependency on WorldEdit for the lookup tables.
     
  5. Offline

    Me4502

    I've added a comment above those lines saying remove them to not require WorldEdit.
     
  6. Offline

    Wingzzz

    I'm actually quite in favor of a standard. Not required, but will definitely help to know when problems arise with issues on this related topic, fellow developers have a good/partial grasp. Well done Me4502 on this man ;)
     
  7. Offline

    Me4502


    Thanks :)

    My main aim was to allow unification amongst server admins, but I guess this will also help newbie developers parse those sorts of items from Strings.
     
  8. you said at the second comment that you have a snippet that doesn't depend on other classes, where can we download this?
     
  9. Offline

    Me4502

  10. Offline

    Minecrell

    Me4502 Why is the item name / material name case sensitive? So if someone uses "wood" instead of "WOOD" it doesn't work..
     
  11. Offline

    Me4502


    It's case sensitive? I always have used it fine with no issues typing wood. Are you sure you used it right?
     
  12. Offline

    Minecrell

    Sure, I think you have to use it without WorldEdit :p I tried to use it in my command lib so you can get a item stack from a command. When I type /command wood I don't get wood, but when I type /command WOOD it works.
    Maybe test it without WorldEdit? ;)
    Edit: Maybe I'm doing something wrong with it, I don't know :p
     
  13. Offline

    Me4502


    Okay, I just committed a fix to that.
     
    Minecrell likes this.
  14. Offline

    Minecrell

    Thank you, I didn't even know that method :D
     
  15. Offline

    Me4502


    Yeah, I never use the Material class normally so I had no idea about the case issues.
     
  16. Offline

    Minecrell

    I still prefer the WorldEdit items as of the Material class doesn't allow item names like "enderchest"... You have to write "ender_chest". :(
    Maybe it would be possible to add a option to use WorldEdit if it is loaded on the server, and if not it will use the default Material class...
     
  17. Offline

    Me4502


    Okay, I have now done this.
     
  18. Offline

    Minecrell

    Do you catch the ClassNotFoundException or how does it work?
     
  19. Offline

    Me4502


    I caught anything it throws.
     
  20. Offline

    Minecrell

    Sure, but if WorldEdit is not on the server it should throw a ClassNotFoundException :p
    Thanks a lot!
     
  21. Offline

    Me4502


    I know, but catching everything covers all possible things to happen.
     
  22. Offline

    Minecrell

    But everyone who wants to compile the class still needs WorldEdit in his Build Path, right?
     
  23. Offline

    Me4502


    Yes, if they don't want that they can remove the lines of code
     
  24. Offline

    Minecrell

    Yes but this would remove the option to use WorldEdit whenever possible. Maybe the plugin author doesn't care about the "item name aliases", but I think some users will care, and it would destroy unified syntax as of the user can only use the WorldEdit item names in some plugins.
    Maybe it would be possible with reflection, but I don't know if that would be a really good way to do it..
     
  25. Offline

    Me4502

    The only way to do this is through reflection.. And the performance cost is too high for me to do it to something that could potentially be called a billion times.

    Adding something to the build path is incredibly simple, especially if you use Maven, which is recommended.
     
  26. Offline

    Minecrell

    Sure, for me it isn't a problem, as of I'm using Maven for nearly all my projects. But other authors may don't want to add WorldEdit to every plugin where they need the item syntax.
    However this would be the way how to do it using reflection I think, but I don't know how high is the performance cost for it.
    Code:java
    1. try {
    2. Object item = Class.forName("com.sk89q.worldedit.blocks.ItemType").getMethod("lookup", String.class).invoke(null, dataSplit[0]);
    3. id = (Integer) item.getClass().getMethod("getID").invoke(item);
    4. if (id < 1) id = 1;
    5. }
    6. catch(Exception eee){
    7. Object block = Class.forName("com.sk89q.worldedit.blocks.BlockType").getMethod("lookup", String.class).invoke(null, dataSplit[0]);
    8. id = (Integer) block.getClass().getMethod("getID").invoke(block);
    9. if (id < 1) id = 1;
    10. }
     
  27. Offline

    Me4502


    Okay, I implemented similar.
     
  28. Offline

    Minecrell

    Me4502
    With adding "()" to the method names, it seems not working anymore for me. When I remove them it works. Are you sure you can use them there?
     
  29. Offline

    Me4502

    I fixed that last night, should be all good now
     
    Minecrell likes this.
  30. Offline

    hawkfalcon

    Using this \o/
     
    Minecrell likes this.
Thread Status:
Not open for further replies.

Share This Page