1. Welcome to skUnity!

    Welcome to skUnity! This is a forum where members of the Skript community can communicate and interact. Skript Resource Creators can post their Resources for all to see and use.

    If you haven't done so already, feel free to join our official Discord server to expand your level of interaction with the comminuty!

    Now, what are you waiting for? Join the community now!

Dismiss Notice
This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Solved Register new type

Discussion in 'Java' started by Spartan9802, May 23, 2017.

  1. Spartan9802

    Spartan9802 Member

    Joined:
    Jan 26, 2017
    Messages:
    158
    Likes Received:
    8
    Good evening,
    I am trying to save a new type (CraftingInventory) but I do not understand how to do: / I looked at several code but none is intuitive for me ....
     
  2. ShaneBee

    Supporter + Addon Developer

    Joined:
    Sep 7, 2017
    Messages:
    2,184
    Likes Received:
    231
    Code (Java):
    1.  
    2. /*Register new type*/
    3. Classes.registerClass(new ClassInfo<>(MyType.class, "mytype")
    4. .parser(new Parser<MyType>() {
    5. @Override
    6. public MyType parse(String s, ParseContext parseContext) {
    7. return null;
    8. }
    9.  
    10. /*Could it be parsed in scripts or not*/
    11. @Override
    12. public boolean canParse(ParseContext context) {
    13. return false;
    14. }
    15.  
    16. /*How it would be parsed in scripts*/
    17. @Override
    18. public String toString(MyType myType, int i) {
    19. return myType.toString();
    20. }
    21.  
    22. /*How it parsed inside variable*/
    23. @Override
    24. public String toVariableNameString(MyType myType) {
    25. return myType.toString();
    26. }
    27.  
    28. /*How variables are parsing with this type*/
    29. @Override
    30. public String getVariableNamePattern() {
    31. return ".+";
    32. }
    33. }));
    34.  
     
    • Like Like x 1
  3. ShaneBee

    Supporter + Addon Developer

    Joined:
    Sep 7, 2017
    Messages:
    2,184
    Likes Received:
    231
    Also, in case the CraftingInventory is the bukkit one, you don't need to register it since it is already by Skript with Inventory.
    It's more easier to use %inventory% in your expression and check if it is the right type of inventory then register two same types:
    Code (Java):
    1. private Expression<Inventory> inv;
    2. public void execute(Event e) {
    3.     Inventory inv = this.inv.getSingle(e);
    4.     if (inv instanceof CraftingInventory) {
    5.         //Then do your stuffs
    6.     }
    7. }
    The same goes when making an expression, if you return CraftingInventory in getReturnType() method, it will work same way since Skript register its super type.
     
  4. ShaneBee

    Supporter + Addon Developer

    Joined:
    Sep 7, 2017
    Messages:
    2,184
    Likes Received:
    231
    I have use this ^^

    Code (Java):
    1. @Override
    2.     protected void execute(Event e) {
    3.  
    4.         if (inv.getSingle(e).getType() == InventoryType.WORKBENCH);
    5.            
    6.             CraftingInventory invc = (CraftingInventory) this.inv.getSingle(e);
    7.             invc.setResult(item.getSingle(e));
    8.     }
     
  5. ShaneBee

    Supporter + Addon Developer

    Joined:
    Sep 7, 2017
    Messages:
    2,184
    Likes Received:
    231
    Oh, totally forgot about that xD

    Last seen Bukkit docs a while ago
     

Share This Page

Loading...