Solved Register new type

  • 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!

Spartan9802

Member
Jan 26, 2017
158
8
18
26
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 ....
 
Java:
/*Register new type*/
Classes.registerClass(new ClassInfo<>(MyType.class, "mytype")
.parser(new Parser<MyType>() {
@Override
public MyType parse(String s, ParseContext parseContext) {
return null;
} 

/*Could it be parsed in scripts or not*/
@Override
public boolean canParse(ParseContext context) {
return false;
}

/*How it would be parsed in scripts*/
@Override
public String toString(MyType myType, int i) {
return myType.toString();
}

/*How it parsed inside variable*/
@Override
public String toVariableNameString(MyType myType) {
return myType.toString();
}

/*How variables are parsing with this type*/
@Override
public String getVariableNamePattern() {
return ".+";
}
}));
 
  • Like
Reactions: Spartan9802
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:
Java:
private Expression<Inventory> inv;
public void execute(Event e) {
    Inventory inv = this.inv.getSingle(e);
    if (inv instanceof CraftingInventory) {
        //Then do your stuffs
    }
}
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.
 
I have use this ^^

Java:
@Override
    protected void execute(Event e) {

        if (inv.getSingle(e).getType() == InventoryType.WORKBENCH);
            
            CraftingInventory invc = (CraftingInventory) this.inv.getSingle(e);
            invc.setResult(item.getSingle(e));
    }
 
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:
Java:
private Expression<Inventory> inv;
public void execute(Event e) {
    Inventory inv = this.inv.getSingle(e);
    if (inv instanceof CraftingInventory) {
        //Then do your stuffs
    }
}
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.
Oh, totally forgot about that xD

Last seen Bukkit docs a while ago