Format code [skip actions]

This commit is contained in:
github-actions 2023-05-30 19:40:39 +00:00
parent 36a35c11aa
commit c69a889e66
13 changed files with 145 additions and 146 deletions

View File

@ -1,5 +1,8 @@
package emu.grasscutter; package emu.grasscutter;
import static emu.grasscutter.config.Configuration.SERVER;
import static emu.grasscutter.utils.lang.Language.translate;
import ch.qos.logback.classic.Level; import ch.qos.logback.classic.Level;
import ch.qos.logback.classic.Logger; import ch.qos.logback.classic.Logger;
import emu.grasscutter.auth.AuthenticationSystem; import emu.grasscutter.auth.AuthenticationSystem;
@ -31,6 +34,16 @@ import emu.grasscutter.utils.StartupArguments;
import emu.grasscutter.utils.Utils; import emu.grasscutter.utils.Utils;
import emu.grasscutter.utils.lang.Language; import emu.grasscutter.utils.lang.Language;
import io.netty.util.concurrent.FastThreadLocalThread; import io.netty.util.concurrent.FastThreadLocalThread;
import java.io.File;
import java.io.FileWriter;
import java.io.IOError;
import java.io.IOException;
import java.util.Calendar;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.LinkedBlockingDeque;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
import javax.annotation.Nullable;
import lombok.Getter; import lombok.Getter;
import lombok.Setter; import lombok.Setter;
import org.jline.reader.EndOfFileException; import org.jline.reader.EndOfFileException;
@ -42,20 +55,6 @@ import org.jline.terminal.TerminalBuilder;
import org.reflections.Reflections; import org.reflections.Reflections;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import javax.annotation.Nullable;
import java.io.File;
import java.io.FileWriter;
import java.io.IOError;
import java.io.IOException;
import java.util.Calendar;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.LinkedBlockingDeque;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
import static emu.grasscutter.config.Configuration.SERVER;
import static emu.grasscutter.utils.lang.Language.translate;
public final class Grasscutter { public final class Grasscutter {
public static final File configFile = new File("./config.json"); public static final File configFile = new File("./config.json");
public static final Reflections reflector = new Reflections("emu.grasscutter"); public static final Reflections reflector = new Reflections("emu.grasscutter");
@ -81,12 +80,16 @@ public final class Grasscutter {
private static LineReader consoleLineReader = null; private static LineReader consoleLineReader = null;
@Getter private static final ExecutorService threadPool = new ThreadPoolExecutor( @Getter
6, 6, 60, TimeUnit.SECONDS, private static final ExecutorService threadPool =
new ThreadPoolExecutor(
6,
6,
60,
TimeUnit.SECONDS,
new LinkedBlockingDeque<>(), new LinkedBlockingDeque<>(),
FastThreadLocalThread::new, FastThreadLocalThread::new,
new ThreadPoolExecutor.AbortPolicy() new ThreadPoolExecutor.AbortPolicy());
);
static { static {
// Declare logback configuration. // Declare logback configuration.

View File

@ -1,5 +1,7 @@
package emu.grasscutter.database; package emu.grasscutter.database;
import static com.mongodb.client.model.Filters.eq;
import dev.morphia.query.FindOptions; import dev.morphia.query.FindOptions;
import dev.morphia.query.Sort; import dev.morphia.query.Sort;
import dev.morphia.query.experimental.filters.Filters; import dev.morphia.query.experimental.filters.Filters;
@ -21,20 +23,20 @@ import emu.grasscutter.game.quest.GameMainQuest;
import emu.grasscutter.game.world.SceneGroupInstance; import emu.grasscutter.game.world.SceneGroupInstance;
import emu.grasscutter.utils.objects.Returnable; import emu.grasscutter.utils.objects.Returnable;
import io.netty.util.concurrent.FastThreadLocalThread; import io.netty.util.concurrent.FastThreadLocalThread;
import java.util.List; import java.util.List;
import java.util.concurrent.*; import java.util.concurrent.*;
import java.util.stream.Stream; import java.util.stream.Stream;
import static com.mongodb.client.model.Filters.eq;
public final class DatabaseHelper { public final class DatabaseHelper {
private static final ExecutorService eventExecutor = new ThreadPoolExecutor( private static final ExecutorService eventExecutor =
6, 6, 60, TimeUnit.SECONDS, new ThreadPoolExecutor(
6,
6,
60,
TimeUnit.SECONDS,
new LinkedBlockingDeque<>(), new LinkedBlockingDeque<>(),
FastThreadLocalThread::new, FastThreadLocalThread::new,
new ThreadPoolExecutor.AbortPolicy() new ThreadPoolExecutor.AbortPolicy());
);
/** /**
* Saves an object on the account datastore. * Saves an object on the account datastore.
@ -42,8 +44,7 @@ public final class DatabaseHelper {
* @param object The object to save. * @param object The object to save.
*/ */
public static void saveAccountAsync(Object object) { public static void saveAccountAsync(Object object) {
DatabaseHelper.eventExecutor.submit(() -> DatabaseHelper.eventExecutor.submit(() -> DatabaseManager.getAccountDatastore().save(object));
DatabaseManager.getAccountDatastore().save(object));
} }
/** /**
@ -52,13 +53,11 @@ public final class DatabaseHelper {
* @param object The object to save. * @param object The object to save.
*/ */
public static void saveGameAsync(Object object) { public static void saveGameAsync(Object object) {
DatabaseHelper.eventExecutor.submit(() -> DatabaseHelper.eventExecutor.submit(() -> DatabaseHelper.saveGameAsync(object));
DatabaseHelper.saveGameAsync(object));
} }
/** /**
* Runs a runnable on the event executor. * Runs a runnable on the event executor. Should be limited to database-related operations.
* Should be limited to database-related operations.
* *
* @param runnable The runnable to run. * @param runnable The runnable to run.
*/ */
@ -76,7 +75,8 @@ public final class DatabaseHelper {
var future = new CompletableFuture<T>(); var future = new CompletableFuture<T>();
// Run the task on the event executor. // Run the task on the event executor.
DatabaseHelper.eventExecutor.submit(() -> { DatabaseHelper.eventExecutor.submit(
() -> {
try { try {
future.complete(task.invoke()); future.complete(task.invoke());
} catch (Exception e) { } catch (Exception e) {
@ -221,9 +221,12 @@ public final class DatabaseHelper {
} }
int uid = player.getUid(); int uid = player.getUid();
DatabaseHelper.asyncOperation(() -> { DatabaseHelper.asyncOperation(
() -> {
// Delete data from collections // Delete data from collections
DatabaseManager.getGameDatabase().getCollection("achievements").deleteMany(eq("uid", uid)); DatabaseManager.getGameDatabase()
.getCollection("achievements")
.deleteMany(eq("uid", uid));
DatabaseManager.getGameDatabase().getCollection("activities").deleteMany(eq("uid", uid)); DatabaseManager.getGameDatabase().getCollection("activities").deleteMany(eq("uid", uid));
DatabaseManager.getGameDatabase().getCollection("homes").deleteMany(eq("ownerUid", uid)); DatabaseManager.getGameDatabase().getCollection("homes").deleteMany(eq("ownerUid", uid));
DatabaseManager.getGameDatabase().getCollection("mail").deleteMany(eq("ownerUid", uid)); DatabaseManager.getGameDatabase().getCollection("mail").deleteMany(eq("ownerUid", uid));
@ -231,16 +234,25 @@ public final class DatabaseHelper {
DatabaseManager.getGameDatabase().getCollection("gachas").deleteMany(eq("ownerId", uid)); DatabaseManager.getGameDatabase().getCollection("gachas").deleteMany(eq("ownerId", uid));
DatabaseManager.getGameDatabase().getCollection("items").deleteMany(eq("ownerId", uid)); DatabaseManager.getGameDatabase().getCollection("items").deleteMany(eq("ownerId", uid));
DatabaseManager.getGameDatabase().getCollection("quests").deleteMany(eq("ownerUid", uid)); DatabaseManager.getGameDatabase().getCollection("quests").deleteMany(eq("ownerUid", uid));
DatabaseManager.getGameDatabase().getCollection("battlepass").deleteMany(eq("ownerUid", uid)); DatabaseManager.getGameDatabase()
.getCollection("battlepass")
.deleteMany(eq("ownerUid", uid));
// Delete friendships. // Delete friendships.
// Here, we need to make sure to not only delete the deleted account's friendships, // Here, we need to make sure to not only delete the deleted account's friendships,
// but also all friendship entries for that account's friends. // but also all friendship entries for that account's friends.
DatabaseManager.getGameDatabase().getCollection("friendships").deleteMany(eq("ownerId", uid)); DatabaseManager.getGameDatabase()
DatabaseManager.getGameDatabase().getCollection("friendships").deleteMany(eq("friendId", uid)); .getCollection("friendships")
.deleteMany(eq("ownerId", uid));
DatabaseManager.getGameDatabase()
.getCollection("friendships")
.deleteMany(eq("friendId", uid));
// Delete the player last. // Delete the player last.
DatabaseManager.getGameDatastore().find(Player.class).filter(Filters.eq("id", uid)).delete(); DatabaseManager.getGameDatastore()
.find(Player.class)
.filter(Filters.eq("id", uid))
.delete();
// Finally, delete the account itself. // Finally, delete the account itself.
DatabaseManager.getAccountDatastore() DatabaseManager.getAccountDatastore()
@ -360,8 +372,7 @@ public final class DatabaseHelper {
} }
public static void deleteItem(GameItem item) { public static void deleteItem(GameItem item) {
DatabaseHelper.asyncOperation(() -> DatabaseHelper.asyncOperation(() -> DatabaseManager.getGameDatastore().delete(item));
DatabaseManager.getGameDatastore().delete(item));
} }
/** /**
@ -399,8 +410,7 @@ public final class DatabaseHelper {
} }
public static void deleteFriendship(Friendship friendship) { public static void deleteFriendship(Friendship friendship) {
DatabaseHelper.asyncOperation(() -> DatabaseHelper.asyncOperation(() -> DatabaseManager.getGameDatastore().delete(friendship));
DatabaseManager.getGameDatastore().delete(friendship));
} }
public static Friendship getReverseFriendship(Friendship friendship) { public static Friendship getReverseFriendship(Friendship friendship) {
@ -460,8 +470,7 @@ public final class DatabaseHelper {
} }
public static void deleteMail(Mail mail) { public static void deleteMail(Mail mail) {
DatabaseHelper.asyncOperation(() -> DatabaseHelper.asyncOperation(() -> DatabaseManager.getGameDatastore().delete(mail));
DatabaseManager.getGameDatastore().delete(mail));
} }
public static List<GameMainQuest> getAllQuests(Player player) { public static List<GameMainQuest> getAllQuests(Player player) {
@ -477,8 +486,7 @@ public final class DatabaseHelper {
} }
public static void deleteQuest(GameMainQuest quest) { public static void deleteQuest(GameMainQuest quest) {
DatabaseHelper.asyncOperation(() -> DatabaseHelper.asyncOperation(() -> DatabaseManager.getGameDatastore().delete(quest));
DatabaseManager.getGameDatastore().delete(quest));
} }
public static GameHome getHomeByUid(int id) { public static GameHome getHomeByUid(int id) {

View File

@ -1,5 +1,7 @@
package emu.grasscutter.database; package emu.grasscutter.database;
import static emu.grasscutter.config.Configuration.DATABASE;
import com.mongodb.MongoCommandException; import com.mongodb.MongoCommandException;
import com.mongodb.client.MongoClient; import com.mongodb.client.MongoClient;
import com.mongodb.client.MongoClients; import com.mongodb.client.MongoClients;
@ -16,8 +18,6 @@ import emu.grasscutter.Grasscutter.ServerRunMode;
import emu.grasscutter.game.Account; import emu.grasscutter.game.Account;
import org.reflections.Reflections; import org.reflections.Reflections;
import static emu.grasscutter.config.Configuration.DATABASE;
public final class DatabaseManager { public final class DatabaseManager {
private static Datastore gameDatastore; private static Datastore gameDatastore;
private static Datastore dispatchDatastore; private static Datastore dispatchDatastore;

View File

@ -22,12 +22,13 @@ public abstract class AbilityActionHandler {
default -> throw new RuntimeException("Unknown target type: " + target); default -> throw new RuntimeException("Unknown target type: " + target);
case "Self" -> entity; case "Self" -> entity;
case "Team" -> ability.getPlayerOwner().getTeamManager().getEntity(); case "Team" -> ability.getPlayerOwner().getTeamManager().getEntity();
case "OriginOwner" -> ability.getPlayerOwner() case "OriginOwner" -> ability.getPlayerOwner().getTeamManager().getCurrentAvatarEntity();
.getTeamManager().getCurrentAvatarEntity();
case "Owner" -> ability.getOwner(); case "Owner" -> ability.getOwner();
case "Applier" -> entity; // TODO: Validate. case "Applier" -> entity; // TODO: Validate.
case "CurLocalAvatar" -> ability.getPlayerOwner() case "CurLocalAvatar" -> ability
.getTeamManager().getCurrentAvatarEntity(); // TODO: Validate. .getPlayerOwner()
.getTeamManager()
.getCurrentAvatarEntity(); // TODO: Validate.
case "CasterOriginOwner" -> null; // TODO: Figure out. case "CasterOriginOwner" -> null; // TODO: Figure out.
}; };
} }

View File

@ -9,7 +9,8 @@ import emu.grasscutter.game.entity.GameEntity;
@AbilityAction(AbilityModifierAction.Type.CopyGlobalValue) @AbilityAction(AbilityModifierAction.Type.CopyGlobalValue)
public final class ActionCopyGlobalValue extends AbilityActionHandler { public final class ActionCopyGlobalValue extends AbilityActionHandler {
@Override @Override
public boolean execute(Ability ability, AbilityModifierAction action, ByteString abilityData, GameEntity entity) { public boolean execute(
Ability ability, AbilityModifierAction action, ByteString abilityData, GameEntity entity) {
// Get the entities referred to. // Get the entities referred to.
var source = this.getTarget(ability, entity, action.srcTarget); var source = this.getTarget(ability, entity, action.srcTarget);
var destination = this.getTarget(ability, entity, action.dstTarget); var destination = this.getTarget(ability, entity, action.dstTarget);

View File

@ -1,5 +1,7 @@
package emu.grasscutter.game.inventory; package emu.grasscutter.game.inventory;
import static emu.grasscutter.config.Configuration.INVENTORY_LIMITS;
import emu.grasscutter.Grasscutter; import emu.grasscutter.Grasscutter;
import emu.grasscutter.data.GameData; import emu.grasscutter.data.GameData;
import emu.grasscutter.data.common.ItemParamData; import emu.grasscutter.data.common.ItemParamData;
@ -20,14 +22,11 @@ import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap; import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
import it.unimi.dsi.fastutil.longs.Long2ObjectMap; import it.unimi.dsi.fastutil.longs.Long2ObjectMap;
import it.unimi.dsi.fastutil.longs.Long2ObjectOpenHashMap; import it.unimi.dsi.fastutil.longs.Long2ObjectOpenHashMap;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
import static emu.grasscutter.config.Configuration.INVENTORY_LIMITS;
public class Inventory extends BasePlayerManager implements Iterable<GameItem> { public class Inventory extends BasePlayerManager implements Iterable<GameItem> {
private final Long2ObjectMap<GameItem> store; private final Long2ObjectMap<GameItem> store;
private final Int2ObjectMap<InventoryTab> inventoryTypes; private final Int2ObjectMap<InventoryTab> inventoryTypes;

View File

@ -41,15 +41,14 @@ import emu.grasscutter.server.event.player.PlayerTeleportEvent;
import emu.grasscutter.server.packet.send.*; import emu.grasscutter.server.packet.send.*;
import emu.grasscutter.utils.objects.KahnsSort; import emu.grasscutter.utils.objects.KahnsSort;
import it.unimi.dsi.fastutil.ints.Int2ObjectMap; import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
import lombok.Getter;
import lombok.Setter;
import lombok.val;
import javax.annotation.Nullable;
import java.util.*; import java.util.*;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.CopyOnWriteArrayList; import java.util.concurrent.CopyOnWriteArrayList;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import javax.annotation.Nullable;
import lombok.Getter;
import lombok.Setter;
import lombok.val;
public final class Scene { public final class Scene {
@Getter private final World world; @Getter private final World world;

View File

@ -1,5 +1,7 @@
package emu.grasscutter.server.dispatch; package emu.grasscutter.server.dispatch;
import static emu.grasscutter.config.Configuration.DISPATCH_INFO;
import com.google.gson.JsonElement; import com.google.gson.JsonElement;
import com.google.gson.JsonObject; import com.google.gson.JsonObject;
import emu.grasscutter.Grasscutter; import emu.grasscutter.Grasscutter;
@ -11,12 +13,6 @@ import emu.grasscutter.utils.Crypto;
import emu.grasscutter.utils.DispatchUtils; import emu.grasscutter.utils.DispatchUtils;
import emu.grasscutter.utils.JsonUtils; import emu.grasscutter.utils.JsonUtils;
import emu.grasscutter.utils.objects.HandbookBody; import emu.grasscutter.utils.objects.HandbookBody;
import lombok.Getter;
import org.java_websocket.WebSocket;
import org.java_websocket.client.WebSocketClient;
import org.java_websocket.handshake.ServerHandshake;
import org.slf4j.Logger;
import java.net.ConnectException; import java.net.ConnectException;
import java.net.URI; import java.net.URI;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
@ -27,8 +23,11 @@ import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.function.BiConsumer; import java.util.function.BiConsumer;
import java.util.function.Consumer; import java.util.function.Consumer;
import lombok.Getter;
import static emu.grasscutter.config.Configuration.DISPATCH_INFO; import org.java_websocket.WebSocket;
import org.java_websocket.client.WebSocketClient;
import org.java_websocket.handshake.ServerHandshake;
import org.slf4j.Logger;
public final class DispatchClient extends WebSocketClient implements IDispatcher { public final class DispatchClient extends WebSocketClient implements IDispatcher {
@Getter private final Logger logger = Grasscutter.getLogger(); @Getter private final Logger logger = Grasscutter.getLogger();

View File

@ -1,17 +1,13 @@
package emu.grasscutter.server.dispatch; package emu.grasscutter.server.dispatch;
import static emu.grasscutter.config.Configuration.DISPATCH_INFO;
import com.google.gson.JsonElement; import com.google.gson.JsonElement;
import com.google.gson.JsonObject; import com.google.gson.JsonObject;
import emu.grasscutter.Grasscutter; import emu.grasscutter.Grasscutter;
import emu.grasscutter.database.DatabaseHelper; import emu.grasscutter.database.DatabaseHelper;
import emu.grasscutter.server.event.dispatch.ServerMessageEvent; import emu.grasscutter.server.event.dispatch.ServerMessageEvent;
import emu.grasscutter.utils.Crypto; import emu.grasscutter.utils.Crypto;
import lombok.Getter;
import org.java_websocket.WebSocket;
import org.java_websocket.handshake.ClientHandshake;
import org.java_websocket.server.WebSocketServer;
import org.slf4j.Logger;
import java.net.InetSocketAddress; import java.net.InetSocketAddress;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
@ -20,8 +16,11 @@ import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.function.BiConsumer; import java.util.function.BiConsumer;
import java.util.function.Consumer; import java.util.function.Consumer;
import lombok.Getter;
import static emu.grasscutter.config.Configuration.DISPATCH_INFO; import org.java_websocket.WebSocket;
import org.java_websocket.handshake.ClientHandshake;
import org.java_websocket.server.WebSocketServer;
import org.slf4j.Logger;
/* Internal communications server. */ /* Internal communications server. */
public final class DispatchServer extends WebSocketServer implements IDispatcher { public final class DispatchServer extends WebSocketServer implements IDispatcher {

View File

@ -1,5 +1,7 @@
package emu.grasscutter.server.dispatch; package emu.grasscutter.server.dispatch;
import static emu.grasscutter.config.Configuration.DISPATCH_INFO;
import com.google.gson.Gson; import com.google.gson.Gson;
import com.google.gson.GsonBuilder; import com.google.gson.GsonBuilder;
import com.google.gson.JsonElement; import com.google.gson.JsonElement;
@ -7,9 +9,6 @@ import com.google.gson.JsonObject;
import emu.grasscutter.utils.Crypto; import emu.grasscutter.utils.Crypto;
import emu.grasscutter.utils.JsonAdapters.ByteArrayAdapter; import emu.grasscutter.utils.JsonAdapters.ByteArrayAdapter;
import emu.grasscutter.utils.objects.JObject; import emu.grasscutter.utils.objects.JObject;
import org.java_websocket.WebSocket;
import org.slf4j.Logger;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import java.util.Base64; import java.util.Base64;
import java.util.LinkedList; import java.util.LinkedList;
@ -20,8 +19,8 @@ import java.util.concurrent.TimeUnit;
import java.util.function.BiConsumer; import java.util.function.BiConsumer;
import java.util.function.Consumer; import java.util.function.Consumer;
import java.util.function.Function; import java.util.function.Function;
import org.java_websocket.WebSocket;
import static emu.grasscutter.config.Configuration.DISPATCH_INFO; import org.slf4j.Logger;
public interface IDispatcher { public interface IDispatcher {
Gson JSON = Gson JSON =
@ -255,7 +254,8 @@ public interface IDispatcher {
* @param binary Whether the data is binary. * @param binary Whether the data is binary.
*/ */
default void sendServerMessage(byte[] data, boolean binary) { default void sendServerMessage(byte[] data, boolean binary) {
var message = new JObject() var message =
new JObject()
.add("binary", binary) .add("binary", binary)
.add("data", Base64.getEncoder().encodeToString(data)) .add("data", Base64.getEncoder().encodeToString(data))
.gson(); .gson();
@ -264,8 +264,7 @@ public interface IDispatcher {
} }
/** /**
* Sends a server message to the client. * Sends a server message to the client. The data is sent as a string.
* The data is sent as a string.
* *
* @param data The data to send. * @param data The data to send.
*/ */
@ -274,8 +273,7 @@ public interface IDispatcher {
} }
/** /**
* Sends a server message to the client. * Sends a server message to the client. The data is sent as a byte array.
* The data is sent as a byte array.
* *
* @param data The data to send. * @param data The data to send.
*/ */
@ -284,8 +282,7 @@ public interface IDispatcher {
} }
/** /**
* Sends a server message to the client. * Sends a server message to the client. The data is sent as a JSON object.
* The data is sent as a JSON object.
* *
* @param data The data to send. * @param data The data to send.
*/ */

View File

@ -4,12 +4,11 @@ import com.google.gson.JsonElement;
import com.google.gson.JsonObject; import com.google.gson.JsonObject;
import emu.grasscutter.server.dispatch.IDispatcher; import emu.grasscutter.server.dispatch.IDispatcher;
import emu.grasscutter.server.event.Event; import emu.grasscutter.server.event.Event;
import java.util.Base64;
import lombok.Getter; import lombok.Getter;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import org.java_websocket.WebSocket; import org.java_websocket.WebSocket;
import java.util.Base64;
@Getter @Getter
@RequiredArgsConstructor @RequiredArgsConstructor
public final class ServerMessageEvent extends Event { public final class ServerMessageEvent extends Event {
@ -22,8 +21,7 @@ public final class ServerMessageEvent extends Event {
public static void invoke(WebSocket client, JsonElement object) { public static void invoke(WebSocket client, JsonElement object) {
var message = IDispatcher.decode(object); var message = IDispatcher.decode(object);
var isBinary = message.get("binary").getAsBoolean(); var isBinary = message.get("binary").getAsBoolean();
var data = Base64.getDecoder().decode( var data = Base64.getDecoder().decode(message.get("data").getAsString());
message.get("data").getAsString());
// Create the event and invoke it. // Create the event and invoke it.
new ServerMessageEvent(client, isBinary, data).call(); new ServerMessageEvent(client, isBinary, data).call();
@ -46,16 +44,13 @@ public final class ServerMessageEvent extends Event {
* @return The message as a JSON object. * @return The message as a JSON object.
*/ */
public JsonObject asJson() { public JsonObject asJson() {
return IDispatcher.JSON.fromJson( return IDispatcher.JSON.fromJson(this.asString(), JsonObject.class);
this.asString(), JsonObject.class);
} }
/** /**
* @return The message as a JSON object. * @return The message as a JSON object. The type is specified.
* The type is specified.
*/ */
public <T> T asJson(Class<T> type) { public <T> T asJson(Class<T> type) {
return IDispatcher.JSON.fromJson( return IDispatcher.JSON.fromJson(this.asString(), type);
this.asString(), type);
} }
} }

View File

@ -1,5 +1,7 @@
package emu.grasscutter.server.http.documentation; package emu.grasscutter.server.http.documentation;
import static emu.grasscutter.config.Configuration.HANDBOOK;
import emu.grasscutter.Grasscutter; import emu.grasscutter.Grasscutter;
import emu.grasscutter.auth.AuthenticationSystem.AuthenticationRequest; import emu.grasscutter.auth.AuthenticationSystem.AuthenticationRequest;
import emu.grasscutter.server.http.Router; import emu.grasscutter.server.http.Router;
@ -11,8 +13,6 @@ import io.javalin.Javalin;
import io.javalin.http.ContentType; import io.javalin.http.ContentType;
import io.javalin.http.Context; import io.javalin.http.Context;
import static emu.grasscutter.config.Configuration.HANDBOOK;
/** Handles requests for the new GM Handbook. */ /** Handles requests for the new GM Handbook. */
public final class HandbookHandler implements Router { public final class HandbookHandler implements Router {
private final byte[] handbook; private final byte[] handbook;
@ -102,8 +102,7 @@ public final class HandbookHandler implements Router {
} else { } else {
ctx.status(result.getStatus()) ctx.status(result.getStatus())
.result(result.getBody()) .result(result.getBody())
.contentType( .contentType(result.isHtml() ? ContentType.TEXT_HTML : ContentType.TEXT_PLAIN);
result.isHtml() ? ContentType.TEXT_HTML : ContentType.TEXT_PLAIN);
} }
} }
} }

View File

@ -1,5 +1,7 @@
package emu.grasscutter.utils; package emu.grasscutter.utils;
import static emu.grasscutter.config.Configuration.*;
import ch.qos.logback.classic.Level; import ch.qos.logback.classic.Level;
import ch.qos.logback.classic.Logger; import ch.qos.logback.classic.Logger;
import emu.grasscutter.BuildConfig; import emu.grasscutter.BuildConfig;
@ -7,13 +9,10 @@ import emu.grasscutter.GameConstants;
import emu.grasscutter.Grasscutter; import emu.grasscutter.Grasscutter;
import emu.grasscutter.net.packet.PacketOpcodesUtils; import emu.grasscutter.net.packet.PacketOpcodesUtils;
import emu.grasscutter.tools.Dumpers; import emu.grasscutter.tools.Dumpers;
import org.slf4j.LoggerFactory;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.function.Function; import java.util.function.Function;
import org.slf4j.LoggerFactory;
import static emu.grasscutter.config.Configuration.*;
/** A parser for start-up arguments. */ /** A parser for start-up arguments. */
public interface StartupArguments { public interface StartupArguments {