Format code [skip actions]

This commit is contained in:
github-actions 2023-05-31 23:57:51 +00:00
parent 77a70c7880
commit bcf54dd6ba
7 changed files with 57 additions and 60 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.*; import ch.qos.logback.classic.*;
import emu.grasscutter.auth.*; import emu.grasscutter.auth.*;
import emu.grasscutter.command.*; import emu.grasscutter.command.*;
@ -18,20 +21,16 @@ import emu.grasscutter.tools.Tools;
import emu.grasscutter.utils.*; import emu.grasscutter.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.*;
import java.util.Calendar;
import java.util.concurrent.*;
import javax.annotation.Nullable;
import lombok.*; import lombok.*;
import org.jline.reader.*; import org.jline.reader.*;
import org.jline.terminal.*; import org.jline.terminal.*;
import org.reflections.Reflections; import org.reflections.Reflections;
import org.slf4j.LoggerFactory; 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 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");

View File

@ -10,17 +10,18 @@ import emu.grasscutter.game.world.*;
import emu.grasscutter.net.proto.SceneEntityInfoOuterClass.SceneEntityInfo; import emu.grasscutter.net.proto.SceneEntityInfoOuterClass.SceneEntityInfo;
import emu.grasscutter.scripts.EntityControllerScriptManager; import emu.grasscutter.scripts.EntityControllerScriptManager;
import it.unimi.dsi.fastutil.ints.*; import it.unimi.dsi.fastutil.ints.*;
import lombok.*;
import javax.annotation.Nullable; import javax.annotation.Nullable;
import lombok.*;
@ToString(callSuper = true) @ToString(callSuper = true)
public class EntityWeapon extends EntityBaseGadget { public class EntityWeapon extends EntityBaseGadget {
@Getter private final GadgetData gadgetData; @Getter private final GadgetData gadgetData;
@Getter(onMethod_ = @Override) @Setter
@Getter(onMethod_ = @Override)
@Setter
private int gadgetId; private int gadgetId;
@Nullable @Getter
private ConfigEntityGadget configGadget; @Nullable @Getter private ConfigEntityGadget configGadget;
@Getter(onMethod_ = @Override, lazy = true) @Getter(onMethod_ = @Override, lazy = true)
private final Int2FloatMap fightProperties = new Int2FloatOpenHashMap(); private final Int2FloatMap fightProperties = new Int2FloatOpenHashMap();
@ -50,21 +51,20 @@ public class EntityWeapon extends EntityBaseGadget {
} }
this.id = scene.getWorld().getNextEntityId(EntityIdType.WEAPON); this.id = scene.getWorld().getNextEntityId(EntityIdType.WEAPON);
Grasscutter.getLogger().trace("New weapon entity {} in scene {}.", Grasscutter.getLogger()
this.id, this.getScene().getId()); .trace("New weapon entity {} in scene {}.", this.id, this.getScene().getId());
this.initAbilities(); this.initAbilities();
} }
private void addConfigAbility(ConfigAbilityData abilityData){ private void addConfigAbility(ConfigAbilityData abilityData) {
var data = GameData.getAbilityData(abilityData.getAbilityName()); var data = GameData.getAbilityData(abilityData.getAbilityName());
if (data != null) this.getWorld().getHost() if (data != null) this.getWorld().getHost().getAbilityManager().addAbilityToEntity(this, data);
.getAbilityManager().addAbilityToEntity(this, data);
} }
@Override @Override
public void initAbilities() { public void initAbilities() {
//TODO: handle pre-dynamic, static and dynamic here // TODO: handle pre-dynamic, static and dynamic here
if (this.configGadget != null && this.configGadget.getAbilities() != null) { if (this.configGadget != null && this.configGadget.getAbilities() != null) {
for (var ability : this.configGadget.getAbilities()) { for (var ability : this.configGadget.getAbilities()) {
this.addConfigAbility(ability); this.addConfigAbility(ability);

View File

@ -9,10 +9,9 @@ import emu.grasscutter.game.player.Player;
import emu.grasscutter.net.proto.InvestigationMonsterOuterClass; import emu.grasscutter.net.proto.InvestigationMonsterOuterClass;
import emu.grasscutter.scripts.data.*; import emu.grasscutter.scripts.data.*;
import emu.grasscutter.server.game.*; import emu.grasscutter.server.game.*;
import org.luaj.vm2.LuaError;
import java.util.*; import java.util.*;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
import org.luaj.vm2.LuaError;
public class WorldDataSystem extends BaseGameSystem { public class WorldDataSystem extends BaseGameSystem {
private final Map<String, ChestInteractHandler> chestInteractHandlerMap; // chestType-Handler private final Map<String, ChestInteractHandler> chestInteractHandlerMap; // chestType-Handler
@ -56,8 +55,10 @@ public class WorldDataSystem extends BaseGameSystem {
.filter(imd -> imd.getMonsterIdList().get(0) == monsterId) .filter(imd -> imd.getMonsterIdList().get(0) == monsterId)
.findFirst(); .findFirst();
return investigationMonsterData.map(monsterData -> GameData.getRewardPreviewDataMap() return investigationMonsterData
.get(monsterData.getRewardPreviewId())).orElse(null); .map(
monsterData -> GameData.getRewardPreviewDataMap().get(monsterData.getRewardPreviewId()))
.orElse(null);
} }
private SceneGroup getInvestigationGroup(int sceneId, int groupId) { private SceneGroup getInvestigationGroup(int sceneId, int groupId) {

View File

@ -5,11 +5,10 @@ import emu.grasscutter.Grasscutter;
import emu.grasscutter.plugin.api.ServerHelper; import emu.grasscutter.plugin.api.ServerHelper;
import emu.grasscutter.server.game.GameServer; import emu.grasscutter.server.game.GameServer;
import emu.grasscutter.utils.FileUtils; import emu.grasscutter.utils.FileUtils;
import lombok.EqualsAndHashCode;
import org.slf4j.*;
import java.io.*; import java.io.*;
import java.net.URLClassLoader; import java.net.URLClassLoader;
import lombok.EqualsAndHashCode;
import org.slf4j.*;
/** The base class for all plugins to extend. */ /** The base class for all plugins to extend. */
@EqualsAndHashCode @EqualsAndHashCode

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;
@ -8,19 +10,15 @@ import emu.grasscutter.utils.objects.*;
import emu.grasscutter.utils.objects.HandbookBody.Action; import emu.grasscutter.utils.objects.HandbookBody.Action;
import io.javalin.Javalin; import io.javalin.Javalin;
import io.javalin.http.*; import io.javalin.http.*;
import java.util.*; import java.util.*;
import java.util.concurrent.*; import java.util.concurrent.*;
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 String handbook; private String handbook;
private final boolean serve; private final boolean serve;
private final Map<String, Integer> currentRequests private final Map<String, Integer> currentRequests = new ConcurrentHashMap<>();
= new ConcurrentHashMap<>();
/** /**
* Constructor for the handbook router. Enables serving the handbook if the handbook file is * Constructor for the handbook router. Enables serving the handbook if the handbook file is
@ -41,13 +39,16 @@ public final class HandbookHandler implements Router {
// Create a new task to reset the request count. // Create a new task to reset the request count.
if (HANDBOOK.limits.enabled) { if (HANDBOOK.limits.enabled) {
new Timer().scheduleAtFixedRate(new TimerTask() { new Timer()
.scheduleAtFixedRate(
new TimerTask() {
@Override @Override
public void run() { public void run() {
currentRequests.clear(); currentRequests.clear();
} }
}, 0, TimeUnit.SECONDS.toMillis( },
HANDBOOK.limits.interval)); 0,
TimeUnit.SECONDS.toMillis(HANDBOOK.limits.interval));
} }
} }
@ -90,9 +91,7 @@ public final class HandbookHandler implements Router {
var count = this.currentRequests.getOrDefault(address, 0); var count = this.currentRequests.getOrDefault(address, 0);
if (++count >= limits.maxRequests) { if (++count >= limits.maxRequests) {
// Respond to the request. // Respond to the request.
ctx.status(429).result(JObject.c() ctx.status(429).result(JObject.c().add("timestamp", System.currentTimeMillis()).toString());
.add("timestamp", System.currentTimeMillis())
.toString());
return false; return false;
} }
@ -244,11 +243,12 @@ public final class HandbookHandler implements Router {
// Parse the request body into a class. // Parse the request body into a class.
var request = ctx.bodyAsClass(HandbookBody.SpawnEntity.class); var request = ctx.bodyAsClass(HandbookBody.SpawnEntity.class);
// Check the entity limit. // Check the entity limit.
var entityLimit = HANDBOOK.limits.enabled ? var entityLimit =
Math.max(HANDBOOK.limits.maxEntities, 0) : HANDBOOK.limits.enabled ? Math.max(HANDBOOK.limits.maxEntities, 0) : Long.MAX_VALUE;
Long.MAX_VALUE;
if (request.getAmount() > entityLimit) { if (request.getAmount() > entityLimit) {
ctx.status(400).result(JObject.c() ctx.status(400)
.result(
JObject.c()
.add("timestamp", System.currentTimeMillis()) .add("timestamp", System.currentTimeMillis())
.add("error", "Entity limit exceeded.") .add("error", "Entity limit exceeded.")
.toString()); .toString());

View File

@ -1,5 +1,8 @@
package emu.grasscutter.utils; 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.Grasscutter;
import emu.grasscutter.config.ConfigContainer; import emu.grasscutter.config.ConfigContainer;
import emu.grasscutter.data.DataLoader; import emu.grasscutter.data.DataLoader;
@ -7,9 +10,6 @@ import emu.grasscutter.game.world.Position;
import io.javalin.http.Context; import io.javalin.http.Context;
import io.netty.buffer.*; import io.netty.buffer.*;
import it.unimi.dsi.fastutil.ints.*; import it.unimi.dsi.fastutil.ints.*;
import org.slf4j.Logger;
import javax.annotation.Nullable;
import java.io.*; import java.io.*;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import java.nio.file.*; import java.nio.file.*;
@ -17,9 +17,8 @@ import java.time.*;
import java.time.temporal.TemporalAdjusters; import java.time.temporal.TemporalAdjusters;
import java.util.*; import java.util.*;
import java.util.concurrent.ThreadLocalRandom; import java.util.concurrent.ThreadLocalRandom;
import javax.annotation.Nullable;
import static emu.grasscutter.utils.FileUtils.getResourcePath; import org.slf4j.Logger;
import static emu.grasscutter.utils.lang.Language.translate;
@SuppressWarnings({"UnusedReturnValue", "BooleanMethodIsAlwaysInverted"}) @SuppressWarnings({"UnusedReturnValue", "BooleanMethodIsAlwaysInverted"})
public final class Utils { public final class Utils {

View File

@ -1,5 +1,8 @@
package emu.grasscutter.utils.lang; package emu.grasscutter.utils.lang;
import static emu.grasscutter.config.Configuration.FALLBACK_LANGUAGE;
import static emu.grasscutter.utils.FileUtils.*;
import com.google.gson.*; import com.google.gson.*;
import emu.grasscutter.Grasscutter; import emu.grasscutter.Grasscutter;
import emu.grasscutter.data.*; import emu.grasscutter.data.*;
@ -8,8 +11,6 @@ import emu.grasscutter.game.player.Player;
import emu.grasscutter.utils.*; import emu.grasscutter.utils.*;
import it.unimi.dsi.fastutil.ints.*; import it.unimi.dsi.fastutil.ints.*;
import it.unimi.dsi.fastutil.objects.*; import it.unimi.dsi.fastutil.objects.*;
import lombok.EqualsAndHashCode;
import java.io.*; import java.io.*;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import java.nio.file.*; import java.nio.file.*;
@ -17,9 +18,7 @@ import java.util.*;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
import java.util.regex.*; import java.util.regex.*;
import java.util.stream.*; import java.util.stream.*;
import lombok.EqualsAndHashCode;
import static emu.grasscutter.config.Configuration.FALLBACK_LANGUAGE;
import static emu.grasscutter.utils.FileUtils.*;
public final class Language { public final class Language {
private static final Map<String, Language> cachedLanguages = new ConcurrentHashMap<>(); private static final Map<String, Language> cachedLanguages = new ConcurrentHashMap<>();