Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a LootTable Serializer #7528

Merged
Changes from 2 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,37 @@ 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());
Burbulinis marked this conversation as resolved.
Show resolved Hide resolved
return fields;
}

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

@Override
protected LootTable deserialize(Fields fields) throws StreamCorruptedException {
NamespacedKey key = fields.getAndRemoveObject("key", NamespacedKey.class);
if (key == null)
throw new IllegalArgumentException();
Burbulinis marked this conversation as resolved.
Show resolved Hide resolved
return Bukkit.getLootTable(key);
}

@Override
public boolean mustSyncDeserialization() {
return false;
Burbulinis marked this conversation as resolved.
Show resolved Hide resolved
}

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

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