Format code [skip actions]

This commit is contained in:
github-actions 2023-06-02 18:26:45 +00:00
parent d9e8810a5c
commit 43fa6efec9
20 changed files with 108 additions and 124 deletions

View File

@ -1,5 +1,8 @@
package emu.grasscutter;
import static emu.grasscutter.config.Configuration.SERVER;
import static emu.grasscutter.utils.lang.Language.translate;
import ch.qos.logback.classic.*;
import emu.grasscutter.auth.*;
import emu.grasscutter.command.*;
@ -18,20 +21,16 @@ import emu.grasscutter.tools.Tools;
import emu.grasscutter.utils.*;
import emu.grasscutter.utils.lang.Language;
import io.netty.util.concurrent.FastThreadLocalThread;
import java.io.*;
import java.util.Calendar;
import java.util.concurrent.*;
import javax.annotation.Nullable;
import lombok.*;
import org.jline.reader.*;
import org.jline.terminal.*;
import org.reflections.Reflections;
import org.slf4j.LoggerFactory;
import javax.annotation.Nullable;
import java.io.*;
import java.util.Calendar;
import java.util.concurrent.*;
import static emu.grasscutter.config.Configuration.SERVER;
import static emu.grasscutter.utils.lang.Language.translate;
public final class Grasscutter {
public static final File configFile = new File("./config.json");
public static final Reflections reflector = new Reflections("emu.grasscutter");
@ -199,7 +198,8 @@ public final class Grasscutter {
if (!dbExecutor.awaitTermination(5, TimeUnit.SECONDS)) {
dbExecutor.shutdownNow();
}
} catch (InterruptedException ignored) { }
} catch (InterruptedException ignored) {
}
}
/*

View File

@ -1,14 +1,13 @@
package emu.grasscutter.command.commands;
import static emu.grasscutter.utils.lang.Language.translate;
import emu.grasscutter.command.*;
import emu.grasscutter.game.player.Player;
import emu.grasscutter.game.quest.GameQuest;
import java.util.List;
import java.util.stream.Collectors;
import static emu.grasscutter.utils.lang.Language.translate;
@Command(
label = "quest",
aliases = {"q"},
@ -142,11 +141,11 @@ public final class QuestCommand implements CommandHandler {
return;
}
CommandHandler.sendMessage(sender,
group.triggers.entrySet().stream()
.map(entry -> "%s: %s".formatted(entry.getKey(), entry.getValue()))
.collect(Collectors.joining(", "))
);
CommandHandler.sendMessage(
sender,
group.triggers.entrySet().stream()
.map(entry -> "%s: %s".formatted(entry.getKey(), entry.getValue()))
.collect(Collectors.joining(", ")));
}
default -> this.sendUsageMessage(sender);
}

View File

@ -3,9 +3,8 @@ package emu.grasscutter.data.excels;
import com.google.gson.annotations.SerializedName;
import emu.grasscutter.data.*;
import emu.grasscutter.game.talk.TalkExec;
import lombok.*;
import java.util.List;
import lombok.*;
@ResourceType(name = "TalkExcelConfigData.json")
@EqualsAndHashCode(callSuper = false)
@ -40,10 +39,7 @@ public final class TalkConfigData extends GameResource {
if (this.questId <= 0) {
var id = String.valueOf(this.getId());
this.questId = Integer.parseInt(
id.length() < 5 ? "0" :
id.substring(0, 3)
);
this.questId = Integer.parseInt(id.length() < 5 ? "0" : id.substring(0, 3));
}
}

View File

@ -1,5 +1,7 @@
package emu.grasscutter.database;
import static com.mongodb.client.model.Filters.eq;
import dev.morphia.query.*;
import dev.morphia.query.experimental.filters.Filters;
import emu.grasscutter.*;
@ -19,16 +21,14 @@ import emu.grasscutter.game.quest.GameMainQuest;
import emu.grasscutter.game.world.SceneGroupInstance;
import emu.grasscutter.utils.objects.Returnable;
import io.netty.util.concurrent.FastThreadLocalThread;
import lombok.Getter;
import java.util.List;
import java.util.concurrent.*;
import java.util.stream.Stream;
import static com.mongodb.client.model.Filters.eq;
import lombok.Getter;
public final class DatabaseHelper {
@Getter private static final ExecutorService eventExecutor =
@Getter
private static final ExecutorService eventExecutor =
new ThreadPoolExecutor(
6,
6,

View File

@ -1,5 +1,7 @@
package emu.grasscutter.game.avatar;
import static emu.grasscutter.config.Configuration.GAME_OPTIONS;
import dev.morphia.annotations.*;
import emu.grasscutter.GameConstants;
import emu.grasscutter.data.GameData;
@ -30,14 +32,11 @@ import emu.grasscutter.net.proto.TrialAvatarInfoOuterClass.TrialAvatarInfo;
import emu.grasscutter.server.packet.send.*;
import emu.grasscutter.utils.helpers.ProtoHelper;
import it.unimi.dsi.fastutil.ints.*;
import lombok.*;
import org.bson.types.ObjectId;
import javax.annotation.*;
import java.util.*;
import java.util.stream.Stream;
import static emu.grasscutter.config.Configuration.GAME_OPTIONS;
import javax.annotation.*;
import lombok.*;
import org.bson.types.ObjectId;
@Entity(value = "avatars", useDiscriminator = false)
public class Avatar {
@ -1246,12 +1245,12 @@ public class Avatar {
// Add costume if avatar has a costume.
if (GAME_OPTIONS.trialCostumes) {
GameData.getAvatarCostumeDataItemIdMap()
.values()
.forEach(
costumeData -> {
if (costumeData.getCharacterId() != this.getAvatarId()) return;
this.setCostume(costumeData.getId());
});
.values()
.forEach(
costumeData -> {
if (costumeData.getCharacterId() != this.getAvatarId()) return;
this.setCostume(costumeData.getId());
});
}
}

View File

@ -1,13 +1,12 @@
package emu.grasscutter.game.player;
import static emu.grasscutter.config.Configuration.GAME_OPTIONS;
import dev.morphia.annotations.Entity;
import emu.grasscutter.game.avatar.Avatar;
import emu.grasscutter.net.proto.AvatarTeamOuterClass.AvatarTeam;
import java.util.*;
import static emu.grasscutter.config.Configuration.GAME_OPTIONS;
@Entity
public final class TeamInfo {
private String name;

View File

@ -16,11 +16,10 @@ import emu.grasscutter.net.proto.ChildQuestOuterClass.ChildQuest;
import emu.grasscutter.net.proto.ParentQuestOuterClass.ParentQuest;
import emu.grasscutter.server.packet.send.*;
import emu.grasscutter.utils.ConversionUtils;
import lombok.*;
import org.bson.types.ObjectId;
import java.util.*;
import java.util.stream.Collectors;
import lombok.*;
import org.bson.types.ObjectId;
@Entity(value = "quests", useDiscriminator = false)
public class GameMainQuest {

View File

@ -15,10 +15,9 @@ import emu.grasscutter.scripts.data.SceneGroup;
import emu.grasscutter.server.packet.send.*;
import emu.grasscutter.utils.Utils;
import it.unimi.dsi.fastutil.ints.IntIntImmutablePair;
import lombok.*;
import javax.script.Bindings;
import java.util.*;
import javax.script.Bindings;
import lombok.*;
@Entity
public class GameQuest {

View File

@ -1,11 +1,11 @@
package emu.grasscutter.game.quest.content;
import static emu.grasscutter.game.quest.enums.QuestContent.QUEST_CONTENT_COMPLETE_TALK;
import emu.grasscutter.data.excels.quest.QuestData;
import emu.grasscutter.game.quest.*;
import lombok.val;
import static emu.grasscutter.game.quest.enums.QuestContent.QUEST_CONTENT_COMPLETE_TALK;
@QuestValueContent(QUEST_CONTENT_COMPLETE_TALK)
public class ContentCompleteTalk extends BaseContent {
@Override

View File

@ -53,8 +53,11 @@ public class ExecNotifyGroupLua extends QuestExecHandler {
? EventType.EVENT_QUEST_FINISH
: EventType.EVENT_QUEST_START;
scriptManager.callEvent(
new ScriptArgs(groupId, eventType, quest.getSubQuestId(),
quest.getState() == QuestState.QUEST_STATE_FINISHED ? 1 : 0)
new ScriptArgs(
groupId,
eventType,
quest.getSubQuestId(),
quest.getState() == QuestState.QUEST_STATE_FINISHED ? 1 : 0)
.setEventSource(quest.getSubQuestId()));
});

View File

@ -1,13 +1,13 @@
package emu.grasscutter.game.talk;
import static emu.grasscutter.game.quest.enums.QuestCond.QUEST_COND_COMPLETE_TALK;
import static emu.grasscutter.game.quest.enums.QuestContent.*;
import emu.grasscutter.data.GameData;
import emu.grasscutter.data.binout.MainQuestData.TalkData;
import emu.grasscutter.game.player.*;
import lombok.NonNull;
import static emu.grasscutter.game.quest.enums.QuestCond.QUEST_COND_COMPLETE_TALK;
import static emu.grasscutter.game.quest.enums.QuestContent.*;
public final class TalkManager extends BasePlayerManager {
public TalkManager(@NonNull Player player) {
super(player);
@ -33,8 +33,8 @@ public final class TalkManager extends BasePlayerManager {
// Execute the talk action on associated handlers.
talkData
.getFinishExec()
.forEach(e -> player.getServer().getTalkSystem().triggerExec(player, talkData, e));
.getFinishExec()
.forEach(e -> player.getServer().getTalkSystem().triggerExec(player, talkData, e));
// Save the talk value to the quest's data.
this.saveTalkToQuest(talkId, talkData.getQuestId());

View File

@ -22,8 +22,8 @@ import emu.grasscutter.game.props.*;
import emu.grasscutter.game.quest.QuestGroupSuite;
import emu.grasscutter.game.world.data.TeleportProperties;
import emu.grasscutter.net.packet.BasePacket;
import emu.grasscutter.net.proto.AttackResultOuterClass.AttackResult;
import emu.grasscutter.net.proto.*;
import emu.grasscutter.net.proto.AttackResultOuterClass.AttackResult;
import emu.grasscutter.net.proto.VisionTypeOuterClass.VisionType;
import emu.grasscutter.scripts.*;
import emu.grasscutter.scripts.constants.EventType;
@ -33,12 +33,11 @@ import emu.grasscutter.server.event.player.PlayerTeleportEvent;
import emu.grasscutter.server.packet.send.*;
import emu.grasscutter.utils.objects.KahnsSort;
import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
import lombok.*;
import javax.annotation.Nullable;
import java.util.*;
import java.util.concurrent.*;
import java.util.stream.Collectors;
import javax.annotation.Nullable;
import lombok.*;
public final class Scene {
@Getter private final World world;

View File

@ -1,18 +1,17 @@
package emu.grasscutter.plugin;
import static emu.grasscutter.utils.lang.Language.translate;
import emu.grasscutter.Grasscutter;
import emu.grasscutter.server.event.*;
import emu.grasscutter.utils.*;
import lombok.*;
import javax.annotation.Nullable;
import java.io.*;
import java.lang.reflect.Method;
import java.net.*;
import java.util.*;
import java.util.jar.*;
import static emu.grasscutter.utils.lang.Language.translate;
import javax.annotation.Nullable;
import lombok.*;
/** Manages the server's plugins and the event system. */
public final class PluginManager {

View File

@ -1,5 +1,7 @@
package emu.grasscutter.scripts;
import static emu.grasscutter.scripts.constants.EventType.EVENT_TIMER_EVENT;
import com.github.davidmoten.rtreemulti.RTree;
import com.github.davidmoten.rtreemulti.geometry.Geometry;
import emu.grasscutter.Grasscutter;
@ -19,20 +21,17 @@ import emu.grasscutter.server.packet.send.PacketGroupSuiteNotify;
import emu.grasscutter.utils.*;
import io.netty.util.concurrent.FastThreadLocalThread;
import it.unimi.dsi.fastutil.ints.*;
import kotlin.Pair;
import lombok.val;
import org.luaj.vm2.*;
import org.luaj.vm2.lib.jse.CoerceJavaToLua;
import javax.annotation.*;
import java.io.*;
import java.nio.file.Files;
import java.util.*;
import java.util.concurrent.*;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.stream.Collectors;
import static emu.grasscutter.scripts.constants.EventType.EVENT_TIMER_EVENT;
import javax.annotation.*;
import kotlin.Pair;
import lombok.val;
import org.luaj.vm2.*;
import org.luaj.vm2.lib.jse.CoerceJavaToLua;
public class SceneScriptManager {
private final Scene scene;
@ -804,23 +803,24 @@ public class SceneScriptManager {
ScriptLoader.getScriptLib().setSceneScriptManager(this);
var eventType = params.type;
var relevantTriggers = switch (eventType) {
case EventType.EVENT_ENTER_REGION, EventType.EVENT_LEAVE_REGION ->
this.getTriggersByEvent(eventType).stream()
.filter(
t ->
t.getCondition().contains(String.valueOf(params.param1))
&& (t.getSource().isEmpty()
|| t.getSource().equals(params.getEventSource())))
.collect(Collectors.toSet());
default ->
this.getTriggersByEvent(eventType).stream()
.filter(
t -> params.getGroupId() == 0 || t.getCurrentGroup().id == params.getGroupId())
.filter(
t -> (t.getSource().isEmpty() || t.getSource().equals(params.getEventSource())))
.collect(Collectors.toSet());
};
var relevantTriggers =
switch (eventType) {
case EventType.EVENT_ENTER_REGION, EventType.EVENT_LEAVE_REGION -> this
.getTriggersByEvent(eventType)
.stream()
.filter(
t ->
t.getCondition().contains(String.valueOf(params.param1))
&& (t.getSource().isEmpty()
|| t.getSource().equals(params.getEventSource())))
.collect(Collectors.toSet());
default -> this.getTriggersByEvent(eventType).stream()
.filter(
t -> params.getGroupId() == 0 || t.getCurrentGroup().id == params.getGroupId())
.filter(
t -> (t.getSource().isEmpty() || t.getSource().equals(params.getEventSource())))
.collect(Collectors.toSet());
};
for (SceneTrigger trigger : relevantTriggers) {
handleEventForTrigger(params, trigger);

View File

@ -1,5 +1,8 @@
package emu.grasscutter.server.game;
import static emu.grasscutter.config.Configuration.*;
import static emu.grasscutter.utils.lang.Language.translate;
import emu.grasscutter.*;
import emu.grasscutter.Grasscutter.ServerRunMode;
import emu.grasscutter.database.DatabaseHelper;
@ -30,17 +33,13 @@ import emu.grasscutter.server.event.types.ServerEvent;
import emu.grasscutter.server.scheduler.ServerTaskScheduler;
import emu.grasscutter.task.TaskMap;
import emu.grasscutter.utils.Utils;
import kcp.highway.*;
import lombok.*;
import org.jetbrains.annotations.NotNull;
import java.net.*;
import java.time.*;
import java.util.*;
import java.util.concurrent.*;
import static emu.grasscutter.config.Configuration.*;
import static emu.grasscutter.utils.lang.Language.translate;
import kcp.highway.*;
import lombok.*;
import org.jetbrains.annotations.NotNull;
@Getter
public final class GameServer extends KcpServer implements Iterable<Player> {
@ -331,9 +330,7 @@ public final class GameServer extends KcpServer implements Iterable<Player> {
var event = new ServerStopEvent(ServerEvent.Type.GAME, OffsetDateTime.now());
event.call();
this.getPlayers()
.forEach(
(uid, player) -> player.getSession().close());
this.getPlayers().forEach((uid, player) -> player.getSession().close());
this.getWorlds().forEach(World::save);
@ -348,7 +345,8 @@ public final class GameServer extends KcpServer implements Iterable<Player> {
if (!threadPool.awaitTermination(5, TimeUnit.SECONDS)) {
Grasscutter.getLogger().error("Logic thread did not terminate!");
}
} catch (InterruptedException ignored) { }
} catch (InterruptedException ignored) {
}
}
@NotNull @Override

View File

@ -1,5 +1,8 @@
package emu.grasscutter.server.game;
import static emu.grasscutter.config.Configuration.*;
import static emu.grasscutter.utils.lang.Language.translate;
import emu.grasscutter.Grasscutter;
import emu.grasscutter.Grasscutter.ServerDebugMode;
import emu.grasscutter.game.Account;
@ -8,14 +11,10 @@ import emu.grasscutter.net.packet.*;
import emu.grasscutter.server.event.game.SendPacketEvent;
import emu.grasscutter.utils.*;
import io.netty.buffer.*;
import lombok.*;
import java.io.File;
import java.net.InetSocketAddress;
import java.nio.file.Path;
import static emu.grasscutter.config.Configuration.*;
import static emu.grasscutter.utils.lang.Language.translate;
import lombok.*;
public class GameSession implements GameSessionManager.KcpChannel {
private final GameServer server;

View File

@ -4,11 +4,10 @@ import emu.grasscutter.Grasscutter;
import emu.grasscutter.utils.Utils;
import io.netty.buffer.*;
import io.netty.channel.DefaultEventLoop;
import kcp.highway.*;
import lombok.Getter;
import java.net.InetSocketAddress;
import java.util.concurrent.ConcurrentHashMap;
import kcp.highway.*;
import lombok.Getter;
public class GameSessionManager {
@Getter private static final DefaultEventLoop logicThread = new DefaultEventLoop();

View File

@ -1,5 +1,7 @@
package emu.grasscutter.server.http.handlers;
import static emu.grasscutter.utils.lang.Language.translate;
import com.google.gson.JsonObject;
import emu.grasscutter.Grasscutter;
import emu.grasscutter.database.DatabaseHelper;
@ -8,14 +10,11 @@ import emu.grasscutter.server.http.Router;
import emu.grasscutter.utils.*;
import io.javalin.Javalin;
import io.javalin.http.*;
import lombok.Getter;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.*;
import java.util.*;
import static emu.grasscutter.utils.lang.Language.translate;
import lombok.Getter;
/** Handles all gacha-related HTTP requests. */
public final class GachaHandler implements Router {

View File

@ -1,5 +1,8 @@
package emu.grasscutter.utils;
import static emu.grasscutter.utils.FileUtils.getResourcePath;
import static emu.grasscutter.utils.lang.Language.translate;
import emu.grasscutter.Grasscutter;
import emu.grasscutter.config.ConfigContainer;
import emu.grasscutter.data.DataLoader;
@ -8,9 +11,6 @@ import emu.grasscutter.utils.objects.Returnable;
import io.javalin.http.Context;
import io.netty.buffer.*;
import it.unimi.dsi.fastutil.ints.*;
import org.slf4j.Logger;
import javax.annotation.Nullable;
import java.io.*;
import java.lang.reflect.Field;
import java.nio.charset.StandardCharsets;
@ -19,9 +19,8 @@ import java.time.*;
import java.time.temporal.TemporalAdjusters;
import java.util.*;
import java.util.concurrent.ThreadLocalRandom;
import static emu.grasscutter.utils.FileUtils.getResourcePath;
import static emu.grasscutter.utils.lang.Language.translate;
import javax.annotation.Nullable;
import org.slf4j.Logger;
@SuppressWarnings({"UnusedReturnValue", "BooleanMethodIsAlwaysInverted"})
public final class Utils {

View File

@ -3,7 +3,6 @@ package emu.grasscutter.utils.objects;
import com.google.gson.*;
import emu.grasscutter.server.dispatch.IDispatcher;
import emu.grasscutter.utils.Utils;
import java.lang.reflect.Field;
import java.util.*;
@ -18,8 +17,7 @@ public interface FieldFetch {
// Prepare field properties.
var fieldValues = new JsonObject();
var fieldMap = new HashMap<String, Field>();
Utils.getAllFields(this.getClass())
.forEach(field -> fieldMap.put(field.getName(), field));
Utils.getAllFields(this.getClass()).forEach(field -> fieldMap.put(field.getName(), field));
// Find the values of all requested fields.
for (var fieldName : fields) {