feat(ServerCosmetics): hot reloading
All checks were successful
Build the Docker Image / docker (push) Successful in 4m51s
All checks were successful
Build the Docker Image / docker (push) Successful in 4m51s
This commit is contained in:
parent
6a1cec4df9
commit
dc43007b6a
2 changed files with 15 additions and 40 deletions
|
@ -1,7 +1,5 @@
|
|||
package de.pauljako.cosmeticserver;
|
||||
|
||||
import de.craftsblock.craftscore.json.Json;
|
||||
import de.craftsblock.craftscore.json.JsonParser;
|
||||
import de.craftsblock.craftsnet.addon.Addon;
|
||||
import de.craftsblock.craftsnet.api.Handler;
|
||||
|
||||
|
@ -11,11 +9,13 @@ public class CosmeticServer extends Addon {
|
|||
|
||||
|
||||
private static CosmeticServer instance;
|
||||
|
||||
private Json serverCosmetics;
|
||||
|
||||
public final File cosmeticFile = new File(getDataFolder(), "cosmetics.json");
|
||||
private Thread thread;
|
||||
|
||||
public static CosmeticServer instance() {
|
||||
return instance;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
|
||||
|
@ -24,13 +24,10 @@ public class CosmeticServer extends Addon {
|
|||
File assets = new File(getDataFolder(), "assets");
|
||||
assets.mkdirs();
|
||||
|
||||
File file = new File(getDataFolder(), "cosmetics.json");
|
||||
serverCosmetics = JsonParser.parse(file);
|
||||
|
||||
routeRegistry().share("/v1/cosmetic/assets", assets);
|
||||
|
||||
CosmeticSocket socket = new CosmeticSocket();
|
||||
routeRegistry().register((Handler) socket);
|
||||
routeRegistry().register(socket);
|
||||
listenerRegistry().register(socket);
|
||||
new HeartbeatThread();
|
||||
}
|
||||
|
@ -47,12 +44,4 @@ public class CosmeticServer extends Addon {
|
|||
instance = null;
|
||||
|
||||
}
|
||||
|
||||
public Json getServerCosmetics() {
|
||||
return serverCosmetics;
|
||||
}
|
||||
|
||||
public static CosmeticServer instance() {
|
||||
return instance;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,7 +8,9 @@ import de.craftsblock.craftscore.event.ListenerAdapter;
|
|||
import de.craftsblock.craftscore.json.Json;
|
||||
import de.craftsblock.craftscore.json.JsonParser;
|
||||
import de.craftsblock.craftscore.utils.Validator;
|
||||
import de.craftsblock.craftsnet.api.websocket.*;
|
||||
import de.craftsblock.craftsnet.api.websocket.SocketExchange;
|
||||
import de.craftsblock.craftsnet.api.websocket.SocketHandler;
|
||||
import de.craftsblock.craftsnet.api.websocket.WebSocketClient;
|
||||
import de.craftsblock.craftsnet.api.websocket.annotations.Socket;
|
||||
import de.craftsblock.craftsnet.events.sockets.ClientDisconnectEvent;
|
||||
|
||||
|
@ -80,10 +82,7 @@ public class CosmeticSocket implements SocketHandler, ListenerAdapter {
|
|||
data.get("cosmetics").getAsJsonObject().entrySet().forEach(entry -> cosmetics.put(entry.getKey(), entry.getValue()));
|
||||
|
||||
ClientMapping mapping = new ClientMapping(uuid, cosmetics);
|
||||
exchange.broadcast(JsonParser.parse("{}")
|
||||
.set("uuid", uuid.toString())
|
||||
.set("cosmetics", bakeData(cosmetics))
|
||||
.toString());
|
||||
exchange.broadcast(JsonParser.parse("{}").set("uuid", uuid.toString()).set("cosmetics", bakeData(cosmetics)).toString());
|
||||
clients.put(client, mapping);
|
||||
CosmeticSocket.cosmetics.put(uuid, mapping);
|
||||
}
|
||||
|
@ -110,29 +109,21 @@ public class CosmeticSocket implements SocketHandler, ListenerAdapter {
|
|||
}));
|
||||
}
|
||||
|
||||
client.sendMessage(JsonParser.parse("{}")
|
||||
.set("data", array)
|
||||
.toString());
|
||||
client.sendMessage(JsonParser.parse("{}").set("data", array).toString());
|
||||
|
||||
}
|
||||
|
||||
private JsonObject searchServerCosmetic(String type, String name) {
|
||||
Json serverCosmetics = CosmeticServer.instance().getServerCosmetics();
|
||||
Json serverCosmetics = JsonParser.parse(CosmeticServer.instance().cosmeticFile);
|
||||
|
||||
if (!serverCosmetics.contains(type + "." + name)) return null;
|
||||
Json cosmetic = JsonParser.parse(serverCosmetics.get(type + "." + name));
|
||||
String id = cosmetic.contains("id") ? cosmetic.getString("id") : name;
|
||||
return (JsonObject) JsonParser.parse("{}")
|
||||
.set("display", cosmetic.contains("display") ? cosmetic.get("display") : name)
|
||||
.set("name", name)
|
||||
.set("delay", cosmetic.contains("delay") ? cosmetic.getInt("delay") : 30)
|
||||
.set("frames", cosmetic.contains("frames") ? cosmetic.getStringList("frames").size() : 1)
|
||||
.set("url", "https://cosmetic.airclient.pauljako.de/v1/cosmetic/assets/" + type + "/" + name + "/frame_" + id)
|
||||
.getObject();
|
||||
return (JsonObject) JsonParser.parse("{}").set("display", cosmetic.contains("display") ? cosmetic.get("display") : name).set("name", name).set("delay", cosmetic.contains("delay") ? cosmetic.getInt("delay") : 30).set("frames", cosmetic.contains("frames") ? cosmetic.getStringList("frames").size() : 1).set("url", "https://cosmetic.airclient.pauljako.de/v1/cosmetic/assets/" + type + "/" + name + "/frame_" + id).getObject();
|
||||
}
|
||||
|
||||
private JsonObject allServerCosmetics(String type) {
|
||||
Json serverCosmetics = CosmeticServer.instance().getServerCosmetics();
|
||||
Json serverCosmetics = JsonParser.parse(CosmeticServer.instance().cosmeticFile);
|
||||
if (!serverCosmetics.contains(type + ".")) return null;
|
||||
|
||||
Json allCosmetics = Json.empty();
|
||||
|
@ -142,12 +133,7 @@ public class CosmeticSocket implements SocketHandler, ListenerAdapter {
|
|||
|
||||
String id = cosmetic.contains("id") ? cosmetic.getString("id") : cosmeticName;
|
||||
|
||||
Json cosmeticObject = JsonParser.parse("{}")
|
||||
.set("display", cosmetic.contains("display") ? cosmetic.get("display") : cosmeticName)
|
||||
.set("name", cosmeticName)
|
||||
.set("delay", cosmetic.contains("delay") ? cosmetic.getInt("delay") : 30)
|
||||
.set("frames", cosmetic.contains("frames") ? cosmetic.getStringList("frames").size() : 1)
|
||||
.set("url", "https://cosmetic.airclient.pauljako.de/v1/cosmetic/assets/" + type + "/" + cosmeticName + "/frame_" + id);
|
||||
Json cosmeticObject = JsonParser.parse("{}").set("display", cosmetic.contains("display") ? cosmetic.get("display") : cosmeticName).set("name", cosmeticName).set("delay", cosmetic.contains("delay") ? cosmetic.getInt("delay") : 30).set("frames", cosmetic.contains("frames") ? cosmetic.getStringList("frames").size() : 1).set("url", "https://cosmetic.airclient.pauljako.de/v1/cosmetic/assets/" + type + "/" + cosmeticName + "/frame_" + id);
|
||||
|
||||
allCosmetics.set(cosmeticName, cosmeticObject);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue