MiniGames/src/main/java/net/knarcraft/minigames/container/SerializableMaterial.java
EpicKnarvik97 1acaebb3bc Parkour implementation safety save 2
This is just a safety save in case the code gets too broken to fix.
2023-04-13 20:13:29 +02:00

53 lines
1.3 KiB
Java

package net.knarcraft.minigames.container;
import org.bukkit.Material;
import org.jetbrains.annotations.NotNull;
import java.util.HashMap;
import java.util.Map;
/**
* A material container able to be serialized
*/
public class SerializableMaterial extends SerializableContainer<Material> {
/**
* Instantiates a new serializable material
*
* @param material <p>The material to contain</p>
*/
public SerializableMaterial(Material material) {
super(material);
}
@Override
public SerializableContainer<Material> getSerializable(Material value) {
return new SerializableMaterial(value);
}
@NotNull
@Override
public Map<String, Object> serialize() {
Map<String, Object> data = new HashMap<>();
data.put("name", getRawValue().name());
return data;
}
/**
* Deserializes a serialized material
*
* @param data <p>The serialized data</p>
* @return <p>The deserialized material</p>
*/
@SuppressWarnings("unused")
public static SerializableMaterial deserialize(Map<String, Object> data) {
Material material = Material.matchMaterial((String) data.get("name"));
if (material == null) {
return null;
} else {
return new SerializableMaterial(material);
}
}
}