-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e0e9f4f
commit 6a8d73a
Showing
9 changed files
with
183 additions
and
8 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
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
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
55 changes: 55 additions & 0 deletions
55
src/main/java/dev/codedsakura/blossom/back/data/PlayerDeathData.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,55 @@ | ||
package dev.codedsakura.blossom.back.data; | ||
|
||
import com.google.gson.Gson; | ||
import com.google.gson.GsonBuilder; | ||
import dev.codedsakura.blossom.back.BlossomBack; | ||
import dev.codedsakura.blossom.lib.data.DataController; | ||
import dev.codedsakura.blossom.lib.teleport.TeleportUtils; | ||
import net.minecraft.server.world.ServerWorld; | ||
|
||
import java.io.BufferedReader; | ||
import java.io.InputStreamReader; | ||
import java.io.OutputStreamWriter; | ||
import java.util.HashMap; | ||
import java.util.UUID; | ||
|
||
public class PlayerDeathData extends DataController<HashMap<UUID, TeleportUtils.TeleportDestination>> { | ||
private final Gson GSON = new GsonBuilder() | ||
.registerTypeAdapter(ServerWorld.class, new ServerWorldSerializer()) | ||
.setPrettyPrinting() | ||
.serializeNulls() | ||
.disableHtmlEscaping() | ||
.create(); | ||
|
||
@Override | ||
public HashMap<UUID, TeleportUtils.TeleportDestination> defaultData() { | ||
return new HashMap<>(); | ||
} | ||
|
||
@Override | ||
public String getFilename() { | ||
return "BlossomBack.deaths"; | ||
} | ||
|
||
public void updateData() { | ||
data.putAll(BlossomBack.DEATHS); | ||
this.write(); | ||
} | ||
|
||
public TeleportUtils.TeleportDestination get(UUID player) { | ||
if (data.containsKey(player)) { | ||
return data.get(player); | ||
} | ||
return BlossomBack.DEATHS.get(player); | ||
} | ||
|
||
@Override | ||
protected HashMap<UUID, TeleportUtils.TeleportDestination> readJson(InputStreamReader reader) { | ||
return GSON.fromJson(new BufferedReader(reader), getType()); | ||
} | ||
|
||
@Override | ||
protected void writeJson(OutputStreamWriter writer) { | ||
GSON.toJson(data, writer); | ||
} | ||
} |
54 changes: 54 additions & 0 deletions
54
src/main/java/dev/codedsakura/blossom/back/data/PlayerTeleportData.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,54 @@ | ||
package dev.codedsakura.blossom.back.data; | ||
|
||
import com.google.gson.Gson; | ||
import com.google.gson.GsonBuilder; | ||
import dev.codedsakura.blossom.lib.data.DataController; | ||
import dev.codedsakura.blossom.lib.teleport.TeleportUtils; | ||
import net.minecraft.server.world.ServerWorld; | ||
|
||
import java.io.BufferedReader; | ||
import java.io.InputStreamReader; | ||
import java.io.OutputStreamWriter; | ||
import java.util.HashMap; | ||
import java.util.UUID; | ||
|
||
public class PlayerTeleportData extends DataController<HashMap<UUID, TeleportUtils.TeleportDestination>> { | ||
private final Gson GSON = new GsonBuilder() | ||
.registerTypeAdapter(ServerWorld.class, new ServerWorldSerializer()) | ||
.setPrettyPrinting() | ||
.serializeNulls() | ||
.disableHtmlEscaping() | ||
.create(); | ||
|
||
@Override | ||
public HashMap<UUID, TeleportUtils.TeleportDestination> defaultData() { | ||
return new HashMap<>(); | ||
} | ||
|
||
@Override | ||
public String getFilename() { | ||
return "BlossomBack.teleports"; | ||
} | ||
|
||
public void updateData() { | ||
data.putAll(TeleportUtils.getAllLastTeleports()); | ||
this.write(); | ||
} | ||
|
||
public TeleportUtils.TeleportDestination get(UUID player) { | ||
if (data.containsKey(player)) { | ||
return data.get(player); | ||
} | ||
return TeleportUtils.getLastTeleport(player); | ||
} | ||
|
||
@Override | ||
protected HashMap<UUID, TeleportUtils.TeleportDestination> readJson(InputStreamReader reader) { | ||
return GSON.fromJson(new BufferedReader(reader), getType()); | ||
} | ||
|
||
@Override | ||
protected void writeJson(OutputStreamWriter writer) { | ||
GSON.toJson(data, writer); | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
src/main/java/dev/codedsakura/blossom/back/data/ServerWorldSerializer.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,24 @@ | ||
package dev.codedsakura.blossom.back.data; | ||
|
||
import com.google.gson.*; | ||
import net.minecraft.registry.RegistryKey; | ||
import net.minecraft.registry.RegistryKeys; | ||
import net.minecraft.server.MinecraftServer; | ||
import net.minecraft.server.world.ServerWorld; | ||
import net.minecraft.util.Identifier; | ||
|
||
import java.lang.reflect.Type; | ||
|
||
public class ServerWorldSerializer implements JsonSerializer<ServerWorld>, JsonDeserializer<ServerWorld> { | ||
public static MinecraftServer server; | ||
|
||
@Override | ||
public ServerWorld deserialize(JsonElement jsonElement, Type type, JsonDeserializationContext jsonDeserializationContext) throws JsonParseException { | ||
return server.getWorld(RegistryKey.of(RegistryKeys.WORLD, new Identifier(jsonElement.getAsString()))); | ||
} | ||
|
||
@Override | ||
public JsonElement serialize(ServerWorld serverWorld, Type type, JsonSerializationContext jsonSerializationContext) { | ||
return new JsonPrimitive(serverWorld.getRegistryKey().getValue().toString()); | ||
} | ||
} |
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