This repository has been archived by the owner on Dec 21, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
User config operation now only happen locally and are synced via command
- Loading branch information
1 parent
76b7fe1
commit 8c7f330
Showing
3 changed files
with
10 additions
and
101 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
52 changes: 3 additions & 49 deletions
52
src/main/java/net/kyrptonaught/LEMBackend/userConfig/UserConfigRouter.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 |
---|---|---|
@@ -1,72 +1,26 @@ | ||
package net.kyrptonaught.LEMBackend.userConfig; | ||
|
||
import com.google.gson.JsonArray; | ||
import com.google.gson.JsonObject; | ||
import io.javalin.http.Context; | ||
import net.kyrptonaught.LEMBackend.ModuleRouter; | ||
|
||
import java.util.concurrent.ConcurrentHashMap; | ||
|
||
public class UserConfigRouter extends ModuleRouter<UserConfigModule> { | ||
|
||
@Override | ||
public void addRoutes() { | ||
route(HTTP.GET, "/v0/{secret}/getUserConfig/{uuid}", this::getUserConfig); | ||
route(HTTP.POST, "/v0/{secret}/syncUserConfig/{uuid}/{key}/{value}", this::syncUserConfig); | ||
route(HTTP.POST, "/v0/{secret}/removeUserConfig/{uuid}/{key}", this::removeUserConfig); | ||
route(HTTP.POST, "/v0/{secret}/userConfigSaveToPreset/{uuid}/{preset}", this::saveToPreset); | ||
route(HTTP.POST, "/v0/{secret}/userConfigLoadFromPreset/{uuid}/{preset}", this::loadFromPreset); | ||
route(HTTP.POST, "/v0/{secret}/unloadUserConfig/{uuid}", this::unloadPlayer); | ||
route(HTTP.POST, "/v0/{secret}/syncUserConfig/{uuid}", this::syncUserConfig); | ||
} | ||
|
||
public void getUserConfig(Context ctx) { | ||
String uuid = ctx.pathParam("uuid"); | ||
|
||
ConcurrentHashMap<String, String> dataStorage = module.getValues(uuid); | ||
ctx.json(dataStorage); | ||
ctx.json(module.loadPlayer(uuid)); | ||
} | ||
|
||
public void syncUserConfig(Context ctx) { | ||
String key = ctx.pathParam("key"); | ||
String uuid = ctx.pathParam("uuid"); | ||
String value = ctx.pathParam("value"); | ||
|
||
module.setValue(uuid, key, value); | ||
ctx.result("success"); | ||
} | ||
|
||
public void removeUserConfig(Context ctx) { | ||
String key = ctx.pathParam("key"); | ||
String uuid = ctx.pathParam("uuid"); | ||
|
||
module.removeValue(uuid, key); | ||
ctx.result("success"); | ||
} | ||
|
||
public void saveToPreset(Context ctx) { | ||
String uuid = ctx.pathParam("uuid"); | ||
String presetID = ctx.pathParam("preset"); | ||
|
||
JsonObject keys = ctx.bodyAsClass(JsonObject.class); | ||
module.saveToPreset(uuid, presetID, keys); | ||
ctx.result("success"); | ||
} | ||
|
||
public void loadFromPreset(Context ctx) { | ||
String uuid = ctx.pathParam("uuid"); | ||
String presetID = ctx.pathParam("preset"); | ||
|
||
JsonArray keys = ctx.bodyAsClass(JsonArray.class); | ||
module.loadFromPreset(uuid, presetID, keys); | ||
|
||
ConcurrentHashMap<String, String> dataStorage = module.getValues(uuid); | ||
ctx.json(dataStorage); | ||
} | ||
|
||
public void unloadPlayer(Context ctx) { | ||
String uuid = ctx.pathParam("uuid"); | ||
|
||
module.unloadPlayer(uuid); | ||
module.syncPlayer(uuid, ctx.body()); | ||
ctx.result("success"); | ||
} | ||
} |