Skip to content

⚙️ Parse loot table .json files into usable itemstacks easily

License

Notifications You must be signed in to change notification settings

Szczurowsky/LootTableParser

Repository files navigation

LootTableParser

Parse loot table .json files into usable itemstacks easily

Build with java No one asked for this

Usefull links

Helpful links:

Paper version

  • 1.20.1+

Szczurowsky Repository (Maven or Gradle) ️

<repository>
    <id>szczurowsky-repository-releases</id>
    <name>Szczurowsky Repository</name>
    <url>https://repo.szczurowsky.pl/releases</url>
</repository>
maven {
    url = uri("https://repo.szczurowsky.pl/releases")
}

Dependencies (Maven or Gradle)

Framework Core

<dependency>
    <groupId>pl.szczurowsky</groupId>
    <artifactId>loot-table-parse</artifactId>
    <version>1.0.2</version>
</dependency>
implementation("pl.szczurowsky:loot-table-parse:1.0.2")

Important note!

It's worth to mention that library uses NBT-API for parsing NBT data, because of that we highly advise to shade NBT-API into your plugin.

Click here to see how to shade NBT-API into your plugin.

Usage

Example use cases

Fetch loot table from CDN and give player items
public class ExamplePlugin extends JavaPlugin {

    private ParsedLootTable parsedLootTable;
    
    @Override
    public void onEnable() {
        this.parsedLootTable = new ParsedLootTable(new URL("https://example.com/loot-table"));
        try {
            parsedLootTable.fetch();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    
}
public class ExampleListener implements Listener {

    private final ParsedLootTable parsedLootTable;
    
    public ExampleListener(ParsedLootTable parsedLootTable) {
        this.parsedLootTable = parsedLootTable;
    }
    
    @EventHandler
    public void onPlayerJoin(PlayerJoinEvent event) {
        Player player = event.getPlayer();
        this.parsedLootTable.getLoot(false).forEach(item -> player.getInventory().addItem(item));
    }
    
}