Run spotlessApply

This commit is contained in:
KingRainbow44
2023-05-27 00:40:07 -04:00
parent d0dde9bc2f
commit 980905817b
1382 changed files with 1306681 additions and 1216557 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -1,5 +1,7 @@
package emu.grasscutter.server.dispatch;
import static emu.grasscutter.config.Configuration.DISPATCH_INFO;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import emu.grasscutter.Grasscutter;
@@ -10,12 +12,6 @@ import emu.grasscutter.utils.Crypto;
import emu.grasscutter.utils.DispatchUtils;
import emu.grasscutter.utils.JsonUtils;
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.URI;
import java.nio.ByteBuffer;
@@ -26,8 +22,11 @@ import java.util.List;
import java.util.Map;
import java.util.function.BiConsumer;
import java.util.function.Consumer;
import static emu.grasscutter.config.Configuration.DISPATCH_INFO;
import lombok.Getter;
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 {
@Getter private final Logger logger = Grasscutter.getLogger();
@@ -154,7 +153,8 @@ public final class DispatchClient extends WebSocketClient implements IDispatcher
var fields = fieldsList.toArray(new String[0]);
// Return the response object.
this.sendMessage(PacketIds.GetPlayerByAccountRsp, DispatchUtils.getPlayerByAccount(accountId, fields));
this.sendMessage(
PacketIds.GetPlayerByAccountRsp, DispatchUtils.getPlayerByAccount(accountId, fields));
}
/**

View File

@@ -1,5 +1,7 @@
package emu.grasscutter.server.dispatch;
import static emu.grasscutter.config.Configuration.DISPATCH_INFO;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.JsonElement;
@@ -7,9 +9,6 @@ import com.google.gson.JsonObject;
import emu.grasscutter.utils.Crypto;
import emu.grasscutter.utils.JsonAdapters.ByteArrayAdapter;
import emu.grasscutter.utils.objects.JObject;
import org.java_websocket.WebSocket;
import org.slf4j.Logger;
import java.nio.charset.StandardCharsets;
import java.util.LinkedList;
import java.util.List;
@@ -19,8 +18,8 @@ import java.util.concurrent.TimeUnit;
import java.util.function.BiConsumer;
import java.util.function.Consumer;
import java.util.function.Function;
import static emu.grasscutter.config.Configuration.DISPATCH_INFO;
import org.java_websocket.WebSocket;
import org.slf4j.Logger;
public interface IDispatcher {
Gson JSON =

View File

@@ -153,9 +153,7 @@ public class GameSession implements GameSessionManager.KcpChannel {
public void handleReceive(byte[] bytes) {
// Decrypt and turn back into a packet
if (this.getState() != SessionState.WAITING_FOR_TOKEN)
Crypto.xor(bytes, useSecretKey() ?
Crypto.ENCRYPT_KEY :
Crypto.DISPATCH_KEY);
Crypto.xor(bytes, useSecretKey() ? Crypto.ENCRYPT_KEY : Crypto.DISPATCH_KEY);
ByteBuf packet = Unpooled.wrappedBuffer(bytes);
// Log

View File

@@ -6,18 +6,19 @@ import emu.grasscutter.net.proto.GachaWishRspOuterClass.GachaWishRsp;
public class PacketGachaWishRsp extends BasePacket {
public PacketGachaWishRsp(int gachaType, int scheduleId, int itemId, int progress, int maxProgress) {
public PacketGachaWishRsp(
int gachaType, int scheduleId, int itemId, int progress, int maxProgress) {
super(PacketOpcodes.GachaWishRsp);
GachaWishRsp proto = GachaWishRsp.newBuilder()
.setGachaType(gachaType)
.setGachaScheduleId(scheduleId)
.setTenCostItemId(itemId)
.setWishProgress(progress)
.setWishMaxProgress(maxProgress)
.build();
GachaWishRsp proto =
GachaWishRsp.newBuilder()
.setGachaType(gachaType)
.setGachaScheduleId(scheduleId)
.setTenCostItemId(itemId)
.setWishProgress(progress)
.setWishMaxProgress(maxProgress)
.build();
this.setData(proto);
}
}

View File

@@ -12,7 +12,6 @@ import emu.grasscutter.net.proto.ItemParamOuterClass;
import emu.grasscutter.net.proto.ShopGoodsOuterClass.ShopGoods;
import emu.grasscutter.net.proto.ShopOuterClass.Shop;
import emu.grasscutter.utils.Utils;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
@@ -22,33 +21,47 @@ public class PacketGetShopRsp extends BasePacket {
super(PacketOpcodes.GetShopRsp);
// TODO: CityReputationLevel
Shop.Builder shop = Shop.newBuilder()
.setShopType(shopType)
.setCityId(1) //mock
.setCityReputationLevel(10); //mock
Shop.Builder shop =
Shop.newBuilder()
.setShopType(shopType)
.setCityId(1) // mock
.setCityReputationLevel(10); // mock
ShopSystem manager = Grasscutter.getGameServer().getShopSystem();
if (manager.getShopData().get(shopType) != null) {
List<ShopInfo> list = manager.getShopData().get(shopType);
List<ShopGoods> goodsList = new ArrayList<>();
for (ShopInfo info : list) {
ShopGoods.Builder goods = ShopGoods.newBuilder()
.setGoodsId(info.getGoodsId())
.setGoodsItem(ItemParamOuterClass.ItemParam.newBuilder().setItemId(info.getGoodsItem().getId()).setCount(info.getGoodsItem().getCount()).build())
.setScoin(info.getScoin())
.setHcoin(info.getHcoin())
.setBuyLimit(info.getBuyLimit())
.setBeginTime(info.getBeginTime())
.setEndTime(info.getEndTime())
.setMinLevel(info.getMinLevel())
.setMaxLevel(info.getMaxLevel())
.setMcoin(info.getMcoin());
ShopGoods.Builder goods =
ShopGoods.newBuilder()
.setGoodsId(info.getGoodsId())
.setGoodsItem(
ItemParamOuterClass.ItemParam.newBuilder()
.setItemId(info.getGoodsItem().getId())
.setCount(info.getGoodsItem().getCount())
.build())
.setScoin(info.getScoin())
.setHcoin(info.getHcoin())
.setBuyLimit(info.getBuyLimit())
.setBeginTime(info.getBeginTime())
.setEndTime(info.getEndTime())
.setMinLevel(info.getMinLevel())
.setMaxLevel(info.getMaxLevel())
.setMcoin(info.getMcoin());
// These fields are deprecated as of REL3.7
// .setDisableType(info.getDisableType())
// .setSecondarySheetId(info.getSecondarySheetId());
// These fields are deprecated as of REL3.7
// .setDisableType(info.getDisableType())
// .setSecondarySheetId(info.getSecondarySheetId());
if (info.getCostItemList() != null) {
goods.addAllCostItemList(info.getCostItemList().stream().map(x -> ItemParamOuterClass.ItemParam.newBuilder().setItemId(x.getId()).setCount(x.getCount()).build()).collect(Collectors.toList()));
goods.addAllCostItemList(
info.getCostItemList().stream()
.map(
x ->
ItemParamOuterClass.ItemParam.newBuilder()
.setItemId(x.getId())
.setCount(x.getCount())
.build())
.collect(Collectors.toList()));
}
if (info.getPreGoodsIdList() != null) {
goods.addAllPreGoodsIdList(info.getPreGoodsIdList());

View File

@@ -1,5 +1,7 @@
package emu.grasscutter.utils;
import static emu.grasscutter.config.Configuration.DISPATCH_INFO;
import com.google.gson.JsonObject;
import emu.grasscutter.Grasscutter;
import emu.grasscutter.auth.AuthenticationSystem.AuthenticationRequest;
@@ -13,12 +15,9 @@ import emu.grasscutter.server.http.objects.LoginTokenRequestJson;
import emu.grasscutter.utils.objects.HandbookBody;
import emu.grasscutter.utils.objects.HandbookBody.*;
import emu.grasscutter.utils.objects.JObject;
import javax.annotation.Nullable;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.TimeUnit;
import static emu.grasscutter.config.Configuration.DISPATCH_INFO;
import javax.annotation.Nullable;
public interface DispatchUtils {
/**
@@ -164,9 +163,8 @@ public interface DispatchUtils {
}
/**
* Fetches the values of fields for a player.
* Uses an account to find the player.
* Similar to {@link DispatchUtils#getPlayerFields(int, String...)}
* Fetches the values of fields for a player. Uses an account to find the player. Similar to
* {@link DispatchUtils#getPlayerFields(int, String...)}
*
* @param accountId The account ID.
* @param fields The fields to fetch.
@@ -176,17 +174,15 @@ public interface DispatchUtils {
return switch (Grasscutter.getRunMode()) {
case DISPATCH_ONLY -> {
// Create a request for player fields.
var request = JObject.c()
.add("accountId", accountId)
.add("fields", fields);
var request = JObject.c().add("accountId", accountId).add("fields", fields);
// Wait for the request to complete.
yield Grasscutter.getDispatchServer()
.await(
request.gson(),
PacketIds.GetPlayerByAccountReq,
PacketIds.GetPlayerByAccountRsp,
IDispatcher.DEFAULT_PARSER);
.await(
request.gson(),
PacketIds.GetPlayerByAccountReq,
PacketIds.GetPlayerByAccountRsp,
IDispatcher.DEFAULT_PARSER);
}
case HYBRID, GAME_ONLY -> {
// Get the player by the account.

View File

@@ -3,15 +3,13 @@ package emu.grasscutter.utils.objects;
import com.google.gson.JsonNull;
import com.google.gson.JsonObject;
import emu.grasscutter.server.dispatch.IDispatcher;
import java.lang.reflect.Field;
import java.util.Arrays;
import java.util.HashMap;
public interface FieldFetch {
/**
* Fetches the specified fields.
* Serializes them into a JSON object.
* Fetches the specified fields. Serializes them into a JSON object.
*
* @param fields The fields to fetch.
* @return The JSON object containing the fields.
@@ -21,7 +19,7 @@ public interface FieldFetch {
var fieldValues = new JsonObject();
var fieldMap = new HashMap<String, Field>();
Arrays.stream(this.getClass().getDeclaredFields())
.forEach(field -> fieldMap.put(field.getName(), field));
.forEach(field -> fieldMap.put(field.getName(), field));
// Find the values of all requested fields.
for (var fieldName : fields) {

View File

@@ -5,7 +5,6 @@ import com.google.gson.internal.LinkedTreeMap;
import com.google.gson.stream.JsonReader;
import com.google.gson.stream.JsonWriter;
import emu.grasscutter.utils.JsonUtils;
import java.io.IOException;
/* Replica of JsonObject. Includes chaining. */