Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@
import ch.njol.skript.Skript;
import ch.njol.skript.classes.ClassInfo;
import ch.njol.skript.classes.Parser;
import ch.njol.skript.classes.Serializer;
import ch.njol.skript.expressions.base.EventValueExpression;
import ch.njol.skript.lang.ParseContext;
import ch.njol.skript.lang.util.SimpleEvent;
import ch.njol.skript.registrations.Classes;
import ch.njol.skript.registrations.EventValues;
import ch.njol.yggdrasil.Fields;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.NamespacedKey;
Expand All @@ -18,6 +20,7 @@
import org.jetbrains.annotations.Nullable;

import java.io.IOException;
import java.io.StreamCorruptedException;

public class LootTableModule {

Expand Down Expand Up @@ -53,6 +56,42 @@ public String toVariableNameString(LootTable o) {
return "loot table:" + o.getKey();
}
})
.serializer(new Serializer<>() {
@Override
public Fields serialize(LootTable lootTable) {
Fields fields = new Fields();
fields.putObject("key", lootTable.getKey().toString());
return fields;
}

@Override
public void deserialize(LootTable lootTable, Fields fields) {
assert false;
}

@Override
protected LootTable deserialize(Fields fields) throws StreamCorruptedException {
String key = fields.getAndRemoveObject("key", String.class);
if (key == null)
throw new StreamCorruptedException();

NamespacedKey namespacedKey = NamespacedKey.fromString(key);
if (namespacedKey == null)
throw new StreamCorruptedException();

return Bukkit.getLootTable(namespacedKey);
}

@Override
public boolean mustSyncDeserialization() {
return true;
}

@Override
protected boolean canBeInstantiated() {
return false;
}
})
);

Classes.registerClass(new ClassInfo<>(LootContext.class, "lootcontext")
Expand Down