Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add an untested adventure component persister
- Loading branch information
Showing
5 changed files
with
34 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
src/main/java/net/citizensnpcs/api/persistence/ComponentPersister.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package net.citizensnpcs.api.persistence; | ||
|
||
import com.google.common.io.BaseEncoding; | ||
|
||
import net.citizensnpcs.api.util.DataKey; | ||
import net.kyori.adventure.text.Component; | ||
import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer; | ||
|
||
public class ComponentPersister implements Persister<Component> { | ||
@Override | ||
public Component create(DataKey root) { | ||
String component = root.getString(""); | ||
return GsonComponentSerializer.gson().deserialize(new String(BaseEncoding.base64().decode(component))); | ||
} | ||
|
||
@Override | ||
public void save(Component text, DataKey root) { | ||
String output = GsonComponentSerializer.gson().serialize(text); | ||
root.setString("", BaseEncoding.base64().encode(output.getBytes())); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters