Format code [skip actions]

This commit is contained in:
github-actions 2023-05-18 07:59:07 +00:00
parent b6b9d3d744
commit 33ba227982
13 changed files with 194 additions and 180 deletions

View File

@ -1,5 +1,8 @@
package emu.grasscutter;
import static emu.grasscutter.config.Configuration.SERVER;
import static emu.grasscutter.utils.Language.translate;
import ch.qos.logback.classic.Level;
import ch.qos.logback.classic.Logger;
import emu.grasscutter.auth.AuthenticationSystem;
@ -26,6 +29,12 @@ import emu.grasscutter.server.http.handlers.GenericHandler;
import emu.grasscutter.server.http.handlers.LogHandler;
import emu.grasscutter.tools.Tools;
import emu.grasscutter.utils.*;
import java.io.File;
import java.io.FileWriter;
import java.io.IOError;
import java.io.IOException;
import java.util.Calendar;
import javax.annotation.Nullable;
import lombok.Getter;
import lombok.Setter;
import org.jline.reader.EndOfFileException;
@ -37,16 +46,6 @@ import org.jline.terminal.TerminalBuilder;
import org.reflections.Reflections;
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 static emu.grasscutter.config.Configuration.SERVER;
import static emu.grasscutter.utils.Language.translate;
public final class Grasscutter {
public static final File configFile = new File("./config.json");
public static final Reflections reflector = new Reflections("emu.grasscutter");

View File

@ -1,5 +1,9 @@
package emu.grasscutter.data;
import static emu.grasscutter.utils.FileUtils.getDataPath;
import static emu.grasscutter.utils.FileUtils.getResourcePath;
import static emu.grasscutter.utils.Language.translate;
import com.google.gson.annotations.SerializedName;
import emu.grasscutter.Grasscutter;
import emu.grasscutter.data.binout.*;
@ -30,12 +34,6 @@ import it.unimi.dsi.fastutil.Pair;
import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
import it.unimi.dsi.fastutil.ints.IntArrayList;
import it.unimi.dsi.fastutil.ints.IntArraySet;
import lombok.SneakyThrows;
import lombok.val;
import org.reflections.Reflections;
import javax.script.Bindings;
import javax.script.CompiledScript;
import java.io.IOException;
import java.io.InputStreamReader;
import java.nio.file.Files;
@ -48,10 +46,11 @@ import java.util.concurrent.CopyOnWriteArraySet;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import static emu.grasscutter.utils.FileUtils.getDataPath;
import static emu.grasscutter.utils.FileUtils.getResourcePath;
import static emu.grasscutter.utils.Language.translate;
import javax.script.Bindings;
import javax.script.CompiledScript;
import lombok.SneakyThrows;
import lombok.val;
import org.reflections.Reflections;
public final class ResourceLoader {
@ -142,36 +141,44 @@ public final class ResourceLoader {
var errors = new ConcurrentLinkedQueue<Pair<String, Exception>>();
var excelBinOutput = ResourceLoader.loadResources(true, errors);
// Load ability lists.
var abilities = ResourceLoader.runAsync(() -> {
ResourceLoader.loadAbilityEmbryos();
ResourceLoader.loadOpenConfig();
ResourceLoader.loadAbilityModifiers();
});
var abilities =
ResourceLoader.runAsync(
() -> {
ResourceLoader.loadAbilityEmbryos();
ResourceLoader.loadOpenConfig();
ResourceLoader.loadAbilityModifiers();
});
// Load spawn data and quests.
var scene = ResourceLoader.runAsync(() -> {
ResourceLoader.loadSpawnData();
ResourceLoader.loadQuests();
ResourceLoader.loadScriptSceneData();
});
var scene =
ResourceLoader.runAsync(
() -> {
ResourceLoader.loadSpawnData();
ResourceLoader.loadQuests();
ResourceLoader.loadScriptSceneData();
});
// Load default home layout
var entities = ResourceLoader.runAsync(() -> {
ResourceLoader.loadHomeworldDefaultSaveData();
ResourceLoader.loadNpcBornData();
ResourceLoader.loadBlossomResources();
ResourceLoader.cacheTalentLevelSets();
});
var entities =
ResourceLoader.runAsync(
() -> {
ResourceLoader.loadHomeworldDefaultSaveData();
ResourceLoader.loadNpcBornData();
ResourceLoader.loadBlossomResources();
ResourceLoader.cacheTalentLevelSets();
});
// Load custom server resources.
var customServer = ResourceLoader.runAsync(() -> {
ResourceLoader.loadConfigLevelEntityData();
ResourceLoader.loadQuestShareConfig();
ResourceLoader.loadGadgetMappings();
ResourceLoader.loadActivityCondGroups();
ResourceLoader.loadGroupReplacements();
ResourceLoader.loadTrialAvatarCustomData();
var customServer =
ResourceLoader.runAsync(
() -> {
ResourceLoader.loadConfigLevelEntityData();
ResourceLoader.loadQuestShareConfig();
ResourceLoader.loadGadgetMappings();
ResourceLoader.loadActivityCondGroups();
ResourceLoader.loadGroupReplacements();
ResourceLoader.loadTrialAvatarCustomData();
EntityControllerScriptManager.load();
});
EntityControllerScriptManager.load();
});
// Wait for all futures to complete.
var futures = new ArrayList<>(List.of(textMaps, abilities, scene, entities, customServer));
@ -181,13 +188,13 @@ public final class ResourceLoader {
// Load dependent-resources.
GameDepot.load(); // Process into depots
ResourceLoader.loadScenePoints(); // Load scene points.
ResourceLoader.loadScenePoints(); // Load scene points.
// Log any errors.
errors.forEach(
pair ->
Grasscutter.getLogger()
.error("Error loading resource file: " + pair.left(), pair.right() + "."));
pair ->
Grasscutter.getLogger()
.error("Error loading resource file: " + pair.left(), pair.right() + "."));
// Calculate the ending time.
var endTime = System.nanoTime();
@ -207,29 +214,35 @@ public final class ResourceLoader {
*
* @param doReload Whether to reload resources.
*/
public static List<CompletableFuture<Boolean>> loadResources(boolean doReload, Queue<Pair<String, Exception>> errors) {
public static List<CompletableFuture<Boolean>> loadResources(
boolean doReload, Queue<Pair<String, Exception>> errors) {
// Load all resources in parallel.
return ResourceLoader.getResourceDefClassesPrioritySets().stream()
.map(classes -> classes.stream()
.parallel().unordered()
.map(c -> {
var type = c.getAnnotation(ResourceType.class);
if (type == null) return null;
.map(
classes ->
classes.stream()
.parallel()
.unordered()
.map(
c -> {
var type = c.getAnnotation(ResourceType.class);
if (type == null) return null;
var map = GameData.getMapByResourceDef(c);
if (map == null) return null;
var map = GameData.getMapByResourceDef(c);
if (map == null) return null;
return ResourceLoader.runAsync(() -> {
try {
loadFromResource(c, type, map, doReload);
} catch (Exception e) {
errors.add(Pair.of(Arrays.toString(type.name()), e));
}
});
})
.toList()
).flatMap(Collection::stream)
.toList();
return ResourceLoader.runAsync(
() -> {
try {
loadFromResource(c, type, map, doReload);
} catch (Exception e) {
errors.add(Pair.of(Arrays.toString(type.name()), e));
}
});
})
.toList())
.flatMap(Collection::stream)
.toList();
}
@SuppressWarnings("rawtypes")
@ -277,35 +290,38 @@ public final class ResourceLoader {
private static void loadScenePoints() {
val pattern = Pattern.compile("scene([0-9]+)_point\\.json");
try (var stream = Files.newDirectoryStream(getResourcePath("BinOutput/Scene/Point"), "scene*_point.json")) {
stream.forEach(path -> {
var matcher = pattern.matcher(path.getFileName().toString());
if (!matcher.find()) return;
var sceneId = Integer.parseInt(matcher.group(1));
try (var stream =
Files.newDirectoryStream(getResourcePath("BinOutput/Scene/Point"), "scene*_point.json")) {
stream.forEach(
path -> {
var matcher = pattern.matcher(path.getFileName().toString());
if (!matcher.find()) return;
var sceneId = Integer.parseInt(matcher.group(1));
ScenePointConfig config; try {
config = JsonUtils.loadToClass(path, ScenePointConfig.class);
} catch (Exception e) {
e.printStackTrace();
return;
}
ScenePointConfig config;
try {
config = JsonUtils.loadToClass(path, ScenePointConfig.class);
} catch (Exception e) {
e.printStackTrace();
return;
}
if (config.points == null) return;
if (config.points == null) return;
var scenePoints = new IntArrayList();
config.points.forEach(
(pointId, pointData) -> {
var scenePoint = new ScenePointEntry(sceneId, pointData);
scenePoints.add((int) pointId);
pointData.setId(pointId);
var scenePoints = new IntArrayList();
config.points.forEach(
(pointId, pointData) -> {
var scenePoint = new ScenePointEntry(sceneId, pointData);
scenePoints.add((int) pointId);
pointData.setId(pointId);
GameData.getScenePointIdList().add((int) pointId);
GameData.getScenePointEntryMap().put((sceneId << 16) + pointId, scenePoint);
GameData.getScenePointIdList().add((int) pointId);
GameData.getScenePointEntryMap().put((sceneId << 16) + pointId, scenePoint);
pointData.updateDailyDungeon();
pointData.updateDailyDungeon();
});
GameData.getScenePointsPerScene().put(sceneId, scenePoints);
});
GameData.getScenePointsPerScene().put(sceneId, scenePoints);
});
} catch (IOException ignored) {
Grasscutter.getLogger()
.error("Scene point files cannot be found, you cannot use teleport waypoints!");
@ -656,19 +672,32 @@ public final class ResourceLoader {
}
}
/**
* Loads data from parsed files.
*/
/** Loads data from parsed files. */
private static List<CompletableFuture<Boolean>> loadConfigData() {
var tasks = new ArrayList<CompletableFuture<Boolean>>();
// Load config data.
tasks.add(ResourceLoader.runAsync(() ->
loadConfigData(GameData.getAvatarConfigData(), "BinOutput/Avatar/", ConfigEntityAvatar.class)));
tasks.add(ResourceLoader.runAsync(() ->
loadConfigData(GameData.getMonsterConfigData(), "BinOutput/Monster/", ConfigEntityMonster.class)));
tasks.add(ResourceLoader.runAsync(() ->
loadConfigDataMap(GameData.getGadgetConfigData(), "BinOutput/Gadget/", ConfigEntityGadget.class)));
tasks.add(
ResourceLoader.runAsync(
() ->
loadConfigData(
GameData.getAvatarConfigData(),
"BinOutput/Avatar/",
ConfigEntityAvatar.class)));
tasks.add(
ResourceLoader.runAsync(
() ->
loadConfigData(
GameData.getMonsterConfigData(),
"BinOutput/Monster/",
ConfigEntityMonster.class)));
tasks.add(
ResourceLoader.runAsync(
() ->
loadConfigDataMap(
GameData.getGadgetConfigData(),
"BinOutput/Gadget/",
ConfigEntityGadget.class)));
return tasks;
}

View File

@ -1,5 +1,7 @@
package emu.grasscutter.database;
import static emu.grasscutter.config.Configuration.DATABASE;
import com.mongodb.MongoCommandException;
import com.mongodb.client.MongoClient;
import com.mongodb.client.MongoClients;
@ -16,8 +18,6 @@ import emu.grasscutter.Grasscutter.ServerRunMode;
import emu.grasscutter.game.Account;
import org.reflections.Reflections;
import static emu.grasscutter.config.Configuration.DATABASE;
public final class DatabaseManager {
private static Datastore gameDatastore;
private static Datastore dispatchDatastore;
@ -35,18 +35,12 @@ public final class DatabaseManager {
return getGameDatastore().getDatabase();
}
/**
* Performs the database initialization process.
* This occurs on a separate thread.
*/
/** Performs the database initialization process. This occurs on a separate thread. */
public static void initializeAsync() {
new Thread(DatabaseManager::initialize).start();
}
/**
* Performs the database initialization process.
* This method is blocking.
*/
/** Performs the database initialization process. This method is blocking. */
public static void initialize() {
// Initialize
MongoClient gameMongoClient = MongoClients.create(DATABASE.game.connectionUri);

View File

@ -1,5 +1,7 @@
package emu.grasscutter.game.gacha;
import static emu.grasscutter.config.Configuration.GAME_OPTIONS;
import com.sun.nio.file.SensitivityWatchEventModifier;
import emu.grasscutter.Grasscutter;
import emu.grasscutter.data.DataLoader;
@ -30,14 +32,11 @@ import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
import it.unimi.dsi.fastutil.ints.IntArrayList;
import it.unimi.dsi.fastutil.ints.IntList;
import org.greenrobot.eventbus.Subscribe;
import java.nio.file.*;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.ThreadLocalRandom;
import static emu.grasscutter.config.Configuration.GAME_OPTIONS;
import org.greenrobot.eventbus.Subscribe;
public class GachaSystem extends BaseGameSystem {
private static final int starglitterId = 221;

View File

@ -1,5 +1,7 @@
package emu.grasscutter.game.managers.energy;
import static emu.grasscutter.config.Configuration.GAME_OPTIONS;
import com.google.protobuf.InvalidProtocolBufferException;
import emu.grasscutter.Grasscutter;
import emu.grasscutter.data.DataLoader;
@ -28,13 +30,10 @@ import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
import it.unimi.dsi.fastutil.objects.Object2IntMap;
import it.unimi.dsi.fastutil.objects.Object2IntOpenHashMap;
import lombok.Getter;
import java.util.List;
import java.util.Optional;
import java.util.concurrent.ThreadLocalRandom;
import static emu.grasscutter.config.Configuration.GAME_OPTIONS;
import lombok.Getter;
public class EnergyManager extends BasePlayerManager {
private static final Int2ObjectMap<List<EnergyDropInfo>> energyDropData =

View File

@ -2,9 +2,8 @@ package emu.grasscutter.game.props;
import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
import lombok.Getter;
import java.util.stream.Stream;
import lombok.Getter;
public enum PlayerProperty {
PROP_NONE(0),

View File

@ -1,5 +1,7 @@
package emu.grasscutter.game.shop;
import static emu.grasscutter.config.Configuration.GAME_OPTIONS;
import emu.grasscutter.Grasscutter;
import emu.grasscutter.data.DataLoader;
import emu.grasscutter.data.GameData;
@ -11,13 +13,10 @@ import emu.grasscutter.server.game.GameServer;
import emu.grasscutter.utils.Utils;
import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import static emu.grasscutter.config.Configuration.GAME_OPTIONS;
public class ShopSystem extends BaseGameSystem {
private static final int REFRESH_HOUR = 4; // In GMT+8 server
private static final String TIME_ZONE = "Asia/Shanghai"; // GMT+8 Timezone

View File

@ -11,13 +11,12 @@ import emu.grasscutter.server.game.GameServer;
import emu.grasscutter.server.packet.send.PacketServerAnnounceNotify;
import emu.grasscutter.server.packet.send.PacketServerAnnounceRevokeNotify;
import emu.grasscutter.utils.Utils;
import java.util.*;
import lombok.AccessLevel;
import lombok.Data;
import lombok.Getter;
import lombok.experimental.FieldDefaults;
import java.util.*;
@Getter
public class AnnouncementSystem extends BaseGameSystem {
private final Map<Integer, AnnounceConfigItem> announceConfigItemMap;

View File

@ -16,13 +16,12 @@ import emu.grasscutter.scripts.data.SceneGroup;
import emu.grasscutter.scripts.data.SceneMonster;
import emu.grasscutter.server.game.BaseGameSystem;
import emu.grasscutter.server.game.GameServer;
import org.luaj.vm2.LuaError;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.concurrent.ConcurrentHashMap;
import org.luaj.vm2.LuaError;
public class WorldDataSystem extends BaseGameSystem {
private final Map<String, ChestInteractHandler> chestInteractHandlerMap; // chestType-Handler

View File

@ -1,15 +1,13 @@
package emu.grasscutter.plugin;
import static emu.grasscutter.utils.Language.translate;
import emu.grasscutter.Grasscutter;
import emu.grasscutter.server.event.Event;
import emu.grasscutter.server.event.EventHandler;
import emu.grasscutter.server.event.HandlerPriority;
import emu.grasscutter.utils.FileUtils;
import emu.grasscutter.utils.JsonUtils;
import lombok.AllArgsConstructor;
import lombok.Getter;
import javax.annotation.Nullable;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.InputStreamReader;
@ -20,8 +18,9 @@ import java.net.URLClassLoader;
import java.util.*;
import java.util.jar.JarEntry;
import java.util.jar.JarFile;
import static emu.grasscutter.utils.Language.translate;
import javax.annotation.Nullable;
import lombok.AllArgsConstructor;
import lombok.Getter;
/** Manages the server's plugins and the event system. */
public final class PluginManager {

View File

@ -1,5 +1,9 @@
package emu.grasscutter.server.game;
import static emu.grasscutter.config.Configuration.DISPATCH_INFO;
import static emu.grasscutter.config.Configuration.GAME_INFO;
import static emu.grasscutter.utils.Language.translate;
import emu.grasscutter.GameConstants;
import emu.grasscutter.Grasscutter;
import emu.grasscutter.Grasscutter.ServerRunMode;
@ -38,22 +42,17 @@ import emu.grasscutter.server.event.internal.ServerStopEvent;
import emu.grasscutter.server.event.types.ServerEvent;
import emu.grasscutter.server.scheduler.ServerTaskScheduler;
import emu.grasscutter.task.TaskMap;
import kcp.highway.ChannelConfig;
import kcp.highway.KcpServer;
import lombok.Getter;
import lombok.Setter;
import lombok.SneakyThrows;
import java.net.InetSocketAddress;
import java.net.URI;
import java.time.Instant;
import java.time.OffsetDateTime;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
import static emu.grasscutter.config.Configuration.DISPATCH_INFO;
import static emu.grasscutter.config.Configuration.GAME_INFO;
import static emu.grasscutter.utils.Language.translate;
import kcp.highway.ChannelConfig;
import kcp.highway.KcpServer;
import lombok.Getter;
import lombok.Setter;
import lombok.SneakyThrows;
@Getter
public final class GameServer extends KcpServer {
@ -143,13 +142,14 @@ public final class GameServer extends KcpServer {
this.init(GameSessionManager.getListener(), channelConfig, address);
// Load game managers asyncronously.
ResourceLoader.runAsync(() -> {
EnergyManager.initialize();
StaminaManager.initialize();
CookingManager.initialize();
CookingCompoundManager.initialize();
CombineManger.initialize();
});
ResourceLoader.runAsync(
() -> {
EnergyManager.initialize();
StaminaManager.initialize();
CookingManager.initialize();
CookingCompoundManager.initialize();
CombineManger.initialize();
});
// Game Server base
this.address = address;

View File

@ -1,5 +1,8 @@
package emu.grasscutter.tools;
import static emu.grasscutter.utils.FileUtils.getResourcePath;
import static emu.grasscutter.utils.Language.getTextMapKey;
import emu.grasscutter.GameConstants;
import emu.grasscutter.Grasscutter;
import emu.grasscutter.command.CommandHandler;
@ -17,10 +20,6 @@ import emu.grasscutter.utils.Language;
import emu.grasscutter.utils.Language.TextStrings;
import it.unimi.dsi.fastutil.ints.Int2IntRBTreeMap;
import it.unimi.dsi.fastutil.ints.Int2ObjectRBTreeMap;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.val;
import java.io.*;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
@ -32,9 +31,9 @@ import java.util.function.Function;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
import java.util.stream.LongStream;
import static emu.grasscutter.utils.FileUtils.getResourcePath;
import static emu.grasscutter.utils.Language.getTextMapKey;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.val;
public final class Tools {
/**

View File

@ -1,5 +1,9 @@
package emu.grasscutter.utils;
import static emu.grasscutter.config.Configuration.FALLBACK_LANGUAGE;
import static emu.grasscutter.utils.FileUtils.getCachePath;
import static emu.grasscutter.utils.FileUtils.getResourcePath;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import emu.grasscutter.Grasscutter;
@ -13,8 +17,6 @@ import it.unimi.dsi.fastutil.ints.IntOpenHashSet;
import it.unimi.dsi.fastutil.ints.IntSet;
import it.unimi.dsi.fastutil.objects.Object2IntMap;
import it.unimi.dsi.fastutil.objects.Object2IntOpenHashMap;
import lombok.EqualsAndHashCode;
import java.io.*;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
@ -26,10 +28,7 @@ import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
import static emu.grasscutter.config.Configuration.FALLBACK_LANGUAGE;
import static emu.grasscutter.utils.FileUtils.getCachePath;
import static emu.grasscutter.utils.FileUtils.getResourcePath;
import lombok.EqualsAndHashCode;
public final class Language {
private static final Map<String, Language> cachedLanguages = new ConcurrentHashMap<>();
@ -345,26 +344,27 @@ public final class Language {
long cacheModified = Files.getLastModifiedTime(TEXTMAP_CACHE_PATH).toMillis();
var stream = Files.list(getResourcePath("TextMap"));
var textmapsModified = stream.filter(path ->
path.toString().endsWith(".json"))
.map(
path -> {
try {
return Files.getLastModifiedTime(path).toMillis();
} catch (Exception ignored) {
Grasscutter.getLogger()
.debug("Exception while checking modified time: {}.", path);
return Long.MAX_VALUE; // Don't use cache, something has gone wrong
}
})
.max(Long::compare)
.get();
var textmapsModified =
stream
.filter(path -> path.toString().endsWith(".json"))
.map(
path -> {
try {
return Files.getLastModifiedTime(path).toMillis();
} catch (Exception ignored) {
Grasscutter.getLogger()
.debug("Exception while checking modified time: {}.", path);
return Long.MAX_VALUE; // Don't use cache, something has gone wrong
}
})
.max(Long::compare)
.get();
stream.close();
Grasscutter.getLogger()
.debug(
"Cache modified %d, textmap modified %d."
.formatted(cacheModified, textmapsModified));
.debug(
"Cache modified %d, textmap modified %d."
.formatted(cacheModified, textmapsModified));
if (textmapsModified < cacheModified) {
// Try loading from cache
Grasscutter.getLogger().debug("Loading cached 'TextMaps'...");