Format code [skip actions]

This commit is contained in:
github-actions 2023-05-11 02:23:43 +00:00
parent f51fd55cb5
commit f9906c4492
730 changed files with 29212 additions and 29159 deletions

View File

@ -128,23 +128,27 @@ public final class AccountCommand implements CommandHandler {
} }
case "list" -> { case "list" -> {
CommandHandler.sendMessage(sender, "Note: This command might take a while to complete."); CommandHandler.sendMessage(sender, "Note: This command might take a while to complete.");
CommandHandler.sendMessage(sender, CommandHandler.sendMessage(
"Accounts: \n" + DatabaseManager.getAccountDatastore() sender,
.find(Account.class).stream() "Accounts: \n"
.map(acc -> "%s: %s (%s)".formatted( + DatabaseManager.getAccountDatastore().find(Account.class).stream()
acc.getId(), acc.getUsername(), .map(
acc.getReservedPlayerUid() == 0 ? acc ->
this.getPlayerUid(acc) : "%s: %s (%s)"
acc.getReservedPlayerUid())) .formatted(
.collect(Collectors.joining("\n")) acc.getId(),
); acc.getUsername(),
acc.getReservedPlayerUid() == 0
? this.getPlayerUid(acc)
: acc.getReservedPlayerUid()))
.collect(Collectors.joining("\n")));
} }
} }
} }
/** /**
* Returns the UID of the player associated with the given account. * Returns the UID of the player associated with the given account. If the player is not found,
* If the player is not found, returns "no UID". * returns "no UID".
* *
* @param account The account to get the UID of. * @param account The account to get the UID of.
* @return The UID of the player associated with the given account. * @return The UID of the player associated with the given account.

View File

@ -1,11 +1,14 @@
package emu.grasscutter.command.commands; package emu.grasscutter.command.commands;
import static emu.grasscutter.GameConstants.*;
import static emu.grasscutter.command.CommandHelpers.*;
import emu.grasscutter.command.Command; import emu.grasscutter.command.Command;
import emu.grasscutter.command.CommandHandler; import emu.grasscutter.command.CommandHandler;
import emu.grasscutter.data.GameData; import emu.grasscutter.data.GameData;
import emu.grasscutter.data.GameDepot; import emu.grasscutter.data.GameDepot;
import emu.grasscutter.data.excels.avatar.AvatarData;
import emu.grasscutter.data.excels.ItemData; import emu.grasscutter.data.excels.ItemData;
import emu.grasscutter.data.excels.avatar.AvatarData;
import emu.grasscutter.data.excels.reliquary.ReliquaryAffixData; import emu.grasscutter.data.excels.reliquary.ReliquaryAffixData;
import emu.grasscutter.data.excels.reliquary.ReliquaryMainPropData; import emu.grasscutter.data.excels.reliquary.ReliquaryMainPropData;
import emu.grasscutter.game.avatar.Avatar; import emu.grasscutter.game.avatar.Avatar;
@ -14,45 +17,50 @@ import emu.grasscutter.game.inventory.ItemType;
import emu.grasscutter.game.player.Player; import emu.grasscutter.game.player.Player;
import emu.grasscutter.game.props.ActionReason; import emu.grasscutter.game.props.ActionReason;
import emu.grasscutter.game.props.FightProperty; import emu.grasscutter.game.props.FightProperty;
import emu.grasscutter.utils.SparseSet;
import lombok.Setter;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; 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.regex.Pattern; import java.util.regex.Pattern;
import lombok.Setter;
import static emu.grasscutter.GameConstants.*;
import static emu.grasscutter.command.CommandHelpers.*;
@Command( @Command(
label = "give", label = "give",
aliases = {"g", "item", "giveitem"}, aliases = {"g", "item", "giveitem"},
usage = { usage = {
"(<itemId>|<avatarId>|all|weapons|mats|avatars) [lv<level>] [r<refinement>] [x<amount>] [c<constellation>] [sl<skilllevel>]", "(<itemId>|<avatarId>|all|weapons|mats|avatars) [lv<level>] [r<refinement>] [x<amount>] [c<constellation>] [sl<skilllevel>]",
"<artifactId> [lv<level>] [x<amount>] [<mainPropId>] [<appendPropId>[,<times>]]..."}, "<artifactId> [lv<level>] [x<amount>] [<mainPropId>] [<appendPropId>[,<times>]]..."
},
permission = "player.give", permission = "player.give",
permissionTargeted = "player.give.others", permissionTargeted = "player.give.others",
threading = true) threading = true)
public final class GiveCommand implements CommandHandler { public final class GiveCommand implements CommandHandler {
private static final Map<Pattern, BiConsumer<GiveItemParameters, Integer>> intCommandHandlers = Map.ofEntries( private static final Map<Pattern, BiConsumer<GiveItemParameters, Integer>> intCommandHandlers =
Map.ofEntries(
Map.entry(lvlRegex, GiveItemParameters::setLvl), Map.entry(lvlRegex, GiveItemParameters::setLvl),
Map.entry(refineRegex, GiveItemParameters::setRefinement), Map.entry(refineRegex, GiveItemParameters::setRefinement),
Map.entry(amountRegex, GiveItemParameters::setAmount), Map.entry(amountRegex, GiveItemParameters::setAmount),
Map.entry(constellationRegex, GiveItemParameters::setConstellation), Map.entry(constellationRegex, GiveItemParameters::setConstellation),
Map.entry(skillLevelRegex, GiveItemParameters::setSkillLevel) Map.entry(skillLevelRegex, GiveItemParameters::setSkillLevel));
);
private static Avatar makeAvatar(GiveItemParameters param) { private static Avatar makeAvatar(GiveItemParameters param) {
return makeAvatar(param.avatarData, param.lvl, Avatar.getMinPromoteLevel(param.lvl), param.constellation, param.skillLevel); return makeAvatar(
param.avatarData,
param.lvl,
Avatar.getMinPromoteLevel(param.lvl),
param.constellation,
param.skillLevel);
} }
private static Avatar makeAvatar(AvatarData avatarData, int level, int promoteLevel, int constellation, int skillLevel) { private static Avatar makeAvatar(
AvatarData avatarData, int level, int promoteLevel, int constellation, int skillLevel) {
Avatar avatar = new Avatar(avatarData); Avatar avatar = new Avatar(avatarData);
avatar.setLevel(level); avatar.setLevel(level);
avatar.setPromoteLevel(promoteLevel); avatar.setPromoteLevel(promoteLevel);
avatar.getSkillDepot().getSkillsAndEnergySkill().forEach(id -> avatar.setSkillLevel(id, skillLevel)); avatar
.getSkillDepot()
.getSkillsAndEnergySkill()
.forEach(id -> avatar.setSkillLevel(id, skillLevel));
avatar.forceConstellationLevel(constellation); avatar.forceConstellationLevel(constellation);
avatar.recalcStats(true); avatar.recalcStats(true);
avatar.save(); avatar.save();
@ -62,12 +70,16 @@ public final class GiveCommand implements CommandHandler {
private static void giveAllAvatars(Player player, GiveItemParameters param) { private static void giveAllAvatars(Player player, GiveItemParameters param) {
int promoteLevel = Avatar.getMinPromoteLevel(param.lvl); int promoteLevel = Avatar.getMinPromoteLevel(param.lvl);
if (param.constellation < 0 || param.constellation > 6) if (param.constellation < 0 || param.constellation > 6)
param.constellation = 6; // constellation's default is -1 so if no parameters set for constellations it'll automatically be 6 param.constellation =
6; // constellation's default is -1 so if no parameters set for constellations it'll
// automatically be 6
for (AvatarData avatarData : GameData.getAvatarDataMap().values()) { for (AvatarData avatarData : GameData.getAvatarDataMap().values()) {
int id = avatarData.getId(); int id = avatarData.getId();
if (id < 10000002 || id >= 11000000) continue; // Exclude test avatars if (id < 10000002 || id >= 11000000) continue; // Exclude test avatars
// Don't try to add each avatar to the current team // Don't try to add each avatar to the current team
player.addAvatar(makeAvatar(avatarData, param.lvl, promoteLevel, param.constellation, param.skillLevel), false); player.addAvatar(
makeAvatar(avatarData, param.lvl, promoteLevel, param.constellation, param.skillLevel),
false);
} }
} }
@ -76,8 +88,7 @@ public final class GiveCommand implements CommandHandler {
int totalExp = 0; int totalExp = 0;
if (param.data.getItemType() == ItemType.ITEM_WEAPON) { if (param.data.getItemType() == ItemType.ITEM_WEAPON) {
int rankLevel = param.data.getRankLevel(); int rankLevel = param.data.getRankLevel();
for (int i = 1; i < param.lvl; i++) for (int i = 1; i < param.lvl; i++) totalExp += GameData.getWeaponExpRequired(rankLevel, i);
totalExp += GameData.getWeaponExpRequired(rankLevel, i);
} }
List<GameItem> items = new ArrayList<>(param.amount); List<GameItem> items = new ArrayList<>(param.amount);
@ -98,8 +109,7 @@ public final class GiveCommand implements CommandHandler {
param.lvl = Math.min(param.lvl, param.data.getMaxLevel()); param.lvl = Math.min(param.lvl, param.data.getMaxLevel());
int rank = param.data.getRankLevel(); int rank = param.data.getRankLevel();
int totalExp = 0; int totalExp = 0;
for (int i = 1; i < param.lvl; i++) for (int i = 1; i < param.lvl; i++) totalExp += GameData.getRelicExpRequired(rank, i);
totalExp += GameData.getRelicExpRequired(rank, i);
List<GameItem> items = new ArrayList<>(param.amount); List<GameItem> items = new ArrayList<>(param.amount);
for (int i = 0; i < param.amount; i++) { for (int i = 0; i < param.amount; i++) {
@ -121,15 +131,17 @@ public final class GiveCommand implements CommandHandler {
return items; return items;
} }
private static int getArtifactMainProp(ItemData itemData, FightProperty prop) throws IllegalArgumentException { private static int getArtifactMainProp(ItemData itemData, FightProperty prop)
throws IllegalArgumentException {
if (prop != FightProperty.FIGHT_PROP_NONE) if (prop != FightProperty.FIGHT_PROP_NONE)
for (ReliquaryMainPropData data : GameDepot.getRelicMainPropList(itemData.getMainPropDepotId())) for (ReliquaryMainPropData data :
if (data.getWeight() > 0 && data.getFightProp() == prop) GameDepot.getRelicMainPropList(itemData.getMainPropDepotId()))
return data.getId(); if (data.getWeight() > 0 && data.getFightProp() == prop) return data.getId();
throw new IllegalArgumentException(); throw new IllegalArgumentException();
} }
private static List<Integer> getArtifactAffixes(ItemData itemData, FightProperty prop) throws IllegalArgumentException { private static List<Integer> getArtifactAffixes(ItemData itemData, FightProperty prop)
throws IllegalArgumentException {
if (prop == FightProperty.FIGHT_PROP_NONE) { if (prop == FightProperty.FIGHT_PROP_NONE) {
throw new IllegalArgumentException(); throw new IllegalArgumentException();
} }
@ -142,7 +154,8 @@ public final class GiveCommand implements CommandHandler {
return affixes; return affixes;
} }
private static int getAppendPropId(String substatText, ItemData itemData) throws IllegalArgumentException { private static int getAppendPropId(String substatText, ItemData itemData)
throws IllegalArgumentException {
// If the given substat text is an integer, we just use that as the append prop ID. // If the given substat text is an integer, we just use that as the append prop ID.
try { try {
return Integer.parseInt(substatText); return Integer.parseInt(substatText);
@ -159,7 +172,8 @@ public final class GiveCommand implements CommandHandler {
substatTier = Integer.parseInt(substatArgs[1]); substatTier = Integer.parseInt(substatArgs[1]);
} }
List<Integer> substats = getArtifactAffixes(itemData, FightProperty.getPropByShortName(substatType)); List<Integer> substats =
getArtifactAffixes(itemData, FightProperty.getPropByShortName(substatType));
if (substats.isEmpty()) { if (substats.isEmpty()) {
throw new IllegalArgumentException(); throw new IllegalArgumentException();
@ -171,7 +185,8 @@ public final class GiveCommand implements CommandHandler {
} }
} }
private static void parseRelicArgs(GiveItemParameters param, List<String> args) throws IllegalArgumentException { private static void parseRelicArgs(GiveItemParameters param, List<String> args)
throws IllegalArgumentException {
// Get the main stat from the arguments. // Get the main stat from the arguments.
// If the given argument is an integer, we use that. // If the given argument is an integer, we use that.
// If not, we check if the argument string is in the main prop map. // If not, we check if the argument string is in the main prop map.
@ -181,7 +196,8 @@ public final class GiveCommand implements CommandHandler {
param.mainPropId = Integer.parseInt(mainPropIdString); param.mainPropId = Integer.parseInt(mainPropIdString);
} catch (NumberFormatException ignored) { } catch (NumberFormatException ignored) {
// This can in turn throw an exception which we don't want to catch here. // This can in turn throw an exception which we don't want to catch here.
param.mainPropId = getArtifactMainProp(param.data, FightProperty.getPropByShortName(mainPropIdString)); param.mainPropId =
getArtifactMainProp(param.data, FightProperty.getPropByShortName(mainPropIdString));
} }
// Get substats. // Get substats.
@ -262,7 +278,8 @@ public final class GiveCommand implements CommandHandler {
giveAllWeapons(player, param); giveAllWeapons(player, param);
} }
private GiveItemParameters parseArgs(Player sender, List<String> args) throws IllegalArgumentException { private GiveItemParameters parseArgs(Player sender, List<String> args)
throws IllegalArgumentException {
GiveItemParameters param = new GiveItemParameters(); GiveItemParameters param = new GiveItemParameters();
// Extract any tagged arguments (e.g. "lv90", "x100", "r5") // Extract any tagged arguments (e.g. "lv90", "x100", "r5")
@ -304,7 +321,9 @@ public final class GiveCommand implements CommandHandler {
param.avatarData = GameData.getAvatarDataMap().get(param.id - 1000 + 10_000_000); param.avatarData = GameData.getAvatarDataMap().get(param.id - 1000 + 10_000_000);
isRelic = ((param.data != null) && (param.data.getItemType() == ItemType.ITEM_RELIQUARY)); isRelic = ((param.data != null) && (param.data.getItemType() == ItemType.ITEM_RELIQUARY));
if (!isRelic && !args.isEmpty() && (param.amount == 1)) { // A concession for the people that truly hate [x<amount>]. if (!isRelic
&& !args.isEmpty()
&& (param.amount == 1)) { // A concession for the people that truly hate [x<amount>].
try { try {
param.amount = Integer.parseInt(args.remove(0)); param.amount = Integer.parseInt(args.remove(0));
} catch (NumberFormatException e) { } catch (NumberFormatException e) {
@ -382,7 +401,8 @@ public final class GiveCommand implements CommandHandler {
if (param.avatarData != null) { if (param.avatarData != null) {
Avatar avatar = makeAvatar(param); Avatar avatar = makeAvatar(param);
targetPlayer.addAvatar(avatar); targetPlayer.addAvatar(avatar);
CommandHandler.sendTranslatedMessage(sender, "commands.give.given_avatar", param.id, param.lvl, targetPlayer.getUid()); CommandHandler.sendTranslatedMessage(
sender, "commands.give.given_avatar", param.id, param.lvl, targetPlayer.getUid());
return; return;
} }
// If it's not an avatar, it needs to be a valid item // If it's not an avatar, it needs to be a valid item
@ -393,16 +413,34 @@ public final class GiveCommand implements CommandHandler {
switch (param.data.getItemType()) { switch (param.data.getItemType()) {
case ITEM_WEAPON: case ITEM_WEAPON:
targetPlayer.getInventory().addItems(makeUnstackableItems(param), ActionReason.SubfieldDrop); targetPlayer
CommandHandler.sendTranslatedMessage(sender, "commands.give.given_with_level_and_refinement", param.id, param.lvl, param.refinement, param.amount, targetPlayer.getUid()); .getInventory()
.addItems(makeUnstackableItems(param), ActionReason.SubfieldDrop);
CommandHandler.sendTranslatedMessage(
sender,
"commands.give.given_with_level_and_refinement",
param.id,
param.lvl,
param.refinement,
param.amount,
targetPlayer.getUid());
return; return;
case ITEM_RELIQUARY: case ITEM_RELIQUARY:
targetPlayer.getInventory().addItems(makeArtifacts(param), ActionReason.SubfieldDrop); targetPlayer.getInventory().addItems(makeArtifacts(param), ActionReason.SubfieldDrop);
CommandHandler.sendTranslatedMessage(sender, "commands.give.given_level", param.id, param.lvl, param.amount, targetPlayer.getUid()); CommandHandler.sendTranslatedMessage(
sender,
"commands.give.given_level",
param.id,
param.lvl,
param.amount,
targetPlayer.getUid());
return; return;
default: default:
targetPlayer.getInventory().addItem(new GameItem(param.data, param.amount), ActionReason.SubfieldDrop); targetPlayer
CommandHandler.sendTranslatedMessage(sender, "commands.give.given", param.amount, param.id, targetPlayer.getUid()); .getInventory()
.addItem(new GameItem(param.data, param.amount), ActionReason.SubfieldDrop);
CommandHandler.sendTranslatedMessage(
sender, "commands.give.given", param.amount, param.id, targetPlayer.getUid());
} }
} catch (IllegalArgumentException ignored) { } catch (IllegalArgumentException ignored) {
} }
@ -418,16 +456,11 @@ public final class GiveCommand implements CommandHandler {
private static class GiveItemParameters { private static class GiveItemParameters {
public int id; public int id;
@Setter @Setter public int lvl = 0;
public int lvl = 0; @Setter public int amount = 1;
@Setter @Setter public int refinement = 1;
public int amount = 1; @Setter public int constellation = -1;
@Setter @Setter public int skillLevel = 1;
public int refinement = 1;
@Setter
public int constellation = -1;
@Setter
public int skillLevel = 1;
public int mainPropId = -1; public int mainPropId = -1;
public List<Integer> appendPropIdList; public List<Integer> appendPropIdList;
public ItemData data; public ItemData data;

View File

@ -5,7 +5,6 @@ import emu.grasscutter.game.quest.GameQuest;
import emu.grasscutter.game.quest.QuestValueExec; import emu.grasscutter.game.quest.QuestValueExec;
import emu.grasscutter.game.quest.enums.QuestExec; import emu.grasscutter.game.quest.enums.QuestExec;
import emu.grasscutter.game.quest.handlers.QuestExecHandler; import emu.grasscutter.game.quest.handlers.QuestExecHandler;
import java.util.Objects; import java.util.Objects;
@QuestValueExec(QuestExec.QUEST_EXEC_SET_IS_GAME_TIME_LOCKED) @QuestValueExec(QuestExec.QUEST_EXEC_SET_IS_GAME_TIME_LOCKED)

View File

@ -510,8 +510,7 @@ public final class Scene {
this.finishLoading(); this.finishLoading();
this.checkPlayerRespawn(); this.checkPlayerRespawn();
if (this.tickCount++ % 10 == 0) if (this.tickCount++ % 10 == 0) this.broadcastPacket(new PacketSceneTimeNotify(this));
this.broadcastPacket(new PacketSceneTimeNotify(this));
} }
/** Validates a player's current position. Teleports the player if the player is out of bounds. */ /** Validates a player's current position. Teleports the player if the player is out of bounds. */

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.Grasscutter.ServerRunMode; import emu.grasscutter.Grasscutter.ServerRunMode;
import emu.grasscutter.data.GameData; import emu.grasscutter.data.GameData;
@ -12,16 +14,14 @@ import emu.grasscutter.utils.objects.HandbookBody;
import io.javalin.Javalin; import io.javalin.Javalin;
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;
private final boolean serve; private final boolean serve;
/** /**
* Constructor for the handbook router. * Constructor for the handbook router. Enables serving the handbook if the handbook file is
* Enables serving the handbook if the handbook file is found. * found.
*/ */
public HandbookHandler() { public HandbookHandler() {
this.handbook = FileUtils.readResource("/handbook.html"); this.handbook = FileUtils.readResource("/handbook.html");
@ -44,8 +44,7 @@ public final class HandbookHandler implements Router {
* @return True if the server can execute handbook commands. * @return True if the server can execute handbook commands.
*/ */
private boolean controlSupported() { private boolean controlSupported() {
return HANDBOOK.enable && return HANDBOOK.enable && Grasscutter.getRunMode() == ServerRunMode.HYBRID;
Grasscutter.getRunMode() == ServerRunMode.HYBRID;
} }
/** /**
@ -101,16 +100,16 @@ public final class HandbookHandler implements Router {
var avatar = new Avatar(avatarData); var avatar = new Avatar(avatarData);
avatar.setLevel(request.getLevel()); avatar.setLevel(request.getLevel());
avatar.setPromoteLevel(Avatar.getMinPromoteLevel(avatar.getLevel())); avatar.setPromoteLevel(Avatar.getMinPromoteLevel(avatar.getLevel()));
avatar.getSkillDepot().getSkillsAndEnergySkill().forEach(id -> avatar
avatar.setSkillLevel(id, request.getTalentLevels())); .getSkillDepot()
.getSkillsAndEnergySkill()
.forEach(id -> avatar.setSkillLevel(id, request.getTalentLevels()));
avatar.forceConstellationLevel(request.getConstellations()); avatar.forceConstellationLevel(request.getConstellations());
avatar.recalcStats(true); avatar.save(); avatar.recalcStats(true);
avatar.save();
player.addAvatar(avatar); // Add the avatar. player.addAvatar(avatar); // Add the avatar.
ctx.json(HandbookBody.Response.builder() ctx.json(HandbookBody.Response.builder().status(200).message("Avatar granted.").build());
.status(200)
.message("Avatar granted.")
.build());
} catch (NumberFormatException ignored) { } catch (NumberFormatException ignored) {
ctx.status(500).result("Invalid player UID or avatar ID."); ctx.status(500).result("Invalid player UID or avatar ID.");
} catch (Exception exception) { } catch (Exception exception) {
@ -159,10 +158,7 @@ public final class HandbookHandler implements Router {
// Add the item to the inventory. // Add the item to the inventory.
player.getInventory().addItem(itemStack, ActionReason.Gm); player.getInventory().addItem(itemStack, ActionReason.Gm);
ctx.json(HandbookBody.Response.builder() ctx.json(HandbookBody.Response.builder().status(200).message("Item granted.").build());
.status(200)
.message("Item granted.")
.build());
} catch (NumberFormatException ignored) { } catch (NumberFormatException ignored) {
ctx.status(500).result("Invalid player UID or item ID."); ctx.status(500).result("Invalid player UID or item ID.");
} catch (Exception exception) { } catch (Exception exception) {

View File

@ -10,9 +10,12 @@ public final class PacketWindSeedClientNotify extends BasePacket {
public PacketWindSeedClientNotify(byte[] compiledLua) { public PacketWindSeedClientNotify(byte[] compiledLua) {
super(PacketOpcodes.WindSeedClientNotify); super(PacketOpcodes.WindSeedClientNotify);
this.setData(WindSeedClientNotify.newBuilder() this.setData(
.setAreaNotify(AreaNotify.newBuilder() WindSeedClientNotify.newBuilder()
.setAreaId(1).setAreaType(1) .setAreaNotify(
AreaNotify.newBuilder()
.setAreaId(1)
.setAreaType(1)
.setAreaCode(ByteString.copyFrom(compiledLua)))); .setAreaCode(ByteString.copyFrom(compiledLua))));
} }
} }

View File

@ -9,8 +9,6 @@ import emu.grasscutter.game.inventory.ItemType;
import emu.grasscutter.game.props.SceneType; import emu.grasscutter.game.props.SceneType;
import emu.grasscutter.utils.JsonUtils; import emu.grasscutter.utils.JsonUtils;
import emu.grasscutter.utils.Language; import emu.grasscutter.utils.Language;
import lombok.AllArgsConstructor;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.nio.file.Files; import java.nio.file.Files;
@ -19,6 +17,7 @@ import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import lombok.AllArgsConstructor;
public interface Dumpers { public interface Dumpers {
// See `src/handbook/data/README.md` for attributions. // See `src/handbook/data/README.md` for attributions.
@ -66,25 +65,34 @@ public interface Dumpers {
// Convert all registered commands to an info map. // Convert all registered commands to an info map.
var dump = new HashMap<String, CommandInfo>(); var dump = new HashMap<String, CommandInfo>();
commandMap.getAnnotationsAsList().forEach(command -> { commandMap
.getAnnotationsAsList()
.forEach(
command -> {
var description = Dumpers.commandDescription(locale, command); var description = Dumpers.commandDescription(locale, command);
var labels = new ArrayList<String>(){{ var labels =
new ArrayList<String>() {
{
this.add(command.label()); this.add(command.label());
this.addAll(List.of(command.aliases())); this.addAll(List.of(command.aliases()));
}}; }
};
// Add the command info to the list. // Add the command info to the list.
dump.put(command.label(), new CommandInfo( dump.put(
labels, description, List.of(command.usage()), List.of( command.label(),
command.permission(), command.permissionTargeted()), new CommandInfo(
labels,
description,
List.of(command.usage()),
List.of(command.permission(), command.permissionTargeted()),
command.targetRequirement())); command.targetRequirement()));
}); });
try { try {
// Create a file for the dump. // Create a file for the dump.
var file = new File("commands.json"); var file = new File("commands.json");
if (file.exists() && !file.delete()) if (file.exists() && !file.delete()) throw new RuntimeException("Failed to delete file.");
throw new RuntimeException("Failed to delete file.");
if (!file.exists() && !file.createNewFile()) if (!file.exists() && !file.createNewFile())
throw new RuntimeException("Failed to create file."); throw new RuntimeException("Failed to create file.");
@ -107,19 +115,25 @@ public interface Dumpers {
// Convert all known avatars to an avatar map. // Convert all known avatars to an avatar map.
var dump = new HashMap<Integer, AvatarInfo>(); var dump = new HashMap<Integer, AvatarInfo>();
GameData.getAvatarDataMap().forEach((id, avatar) -> { GameData.getAvatarDataMap()
.forEach(
(id, avatar) -> {
var langHash = avatar.getNameTextMapHash(); var langHash = avatar.getNameTextMapHash();
dump.put(id, new AvatarInfo( dump.put(
langHash == 0 ? avatar.getName() : Language.getTextMapKey(langHash).get(locale), id,
avatar.getQualityType().equals("QUALITY_PURPLE") ? Quality.EPIC : Quality.LEGENDARY new AvatarInfo(
)); langHash == 0
? avatar.getName()
: Language.getTextMapKey(langHash).get(locale),
avatar.getQualityType().equals("QUALITY_PURPLE")
? Quality.EPIC
: Quality.LEGENDARY));
}); });
try { try {
// Create a file for the dump. // Create a file for the dump.
var file = new File("avatars.csv"); var file = new File("avatars.csv");
if (file.exists() && !file.delete()) if (file.exists() && !file.delete()) throw new RuntimeException("Failed to delete file.");
throw new RuntimeException("Failed to delete file.");
if (!file.exists() && !file.createNewFile()) if (!file.exists() && !file.createNewFile())
throw new RuntimeException("Failed to create file."); throw new RuntimeException("Failed to create file.");
@ -142,16 +156,22 @@ public interface Dumpers {
// Convert all known items to an item map. // Convert all known items to an item map.
var originalDump = new ArrayList<ItemInfo>(); var originalDump = new ArrayList<ItemInfo>();
GameData.getItemDataMap().forEach((id, item) -> originalDump.add(new ItemInfo(id, GameData.getItemDataMap()
.forEach(
(id, item) ->
originalDump.add(
new ItemInfo(
id,
Language.getTextMapKey(item.getNameTextMapHash()).get(locale), Language.getTextMapKey(item.getNameTextMapHash()).get(locale),
Quality.from(item.getRankLevel()), item.getItemType(), Quality.from(item.getRankLevel()),
item.getIcon().length() > 0 ? item.getIcon().substring(3) : "" item.getItemType(),
))); item.getIcon().length() > 0 ? item.getIcon().substring(3) : "")));
// Create a new dump with filtered duplicates. // Create a new dump with filtered duplicates.
var names = new ArrayList<String>(); var names = new ArrayList<String>();
var dump = new HashMap<Integer, ItemInfo>(); var dump = new HashMap<Integer, ItemInfo>();
originalDump.forEach(item -> { originalDump.forEach(
item -> {
// Validate the item. // Validate the item.
if (item.name.contains("[CHS]")) return; if (item.name.contains("[CHS]")) return;
if (names.contains(item.name)) return; if (names.contains(item.name)) return;
@ -164,8 +184,7 @@ public interface Dumpers {
try { try {
// Create a file for the dump. // Create a file for the dump.
var file = new File("items.csv"); var file = new File("items.csv");
if (file.exists() && !file.delete()) if (file.exists() && !file.delete()) throw new RuntimeException("Failed to delete file.");
throw new RuntimeException("Failed to delete file.");
if (!file.exists() && !file.createNewFile()) if (!file.exists() && !file.createNewFile())
throw new RuntimeException("Failed to create file."); throw new RuntimeException("Failed to create file.");
@ -176,9 +195,7 @@ public interface Dumpers {
} }
} }
/** /** Dumps all scenes to a JSON file. */
* Dumps all scenes to a JSON file.
*/
static void dumpScenes() { static void dumpScenes() {
// Reload resources. // Reload resources.
ResourceLoader.loadAll(); ResourceLoader.loadAll();
@ -186,14 +203,15 @@ public interface Dumpers {
// Convert all known scenes to a scene map. // Convert all known scenes to a scene map.
var dump = new HashMap<Integer, SceneInfo>(); var dump = new HashMap<Integer, SceneInfo>();
GameData.getSceneDataMap().forEach((id, scene) -> GameData.getSceneDataMap()
.forEach(
(id, scene) ->
dump.put(id, new SceneInfo(scene.getScriptData(), scene.getSceneType()))); dump.put(id, new SceneInfo(scene.getScriptData(), scene.getSceneType())));
try { try {
// Create a file for the dump. // Create a file for the dump.
var file = new File("scenes.csv"); var file = new File("scenes.csv");
if (file.exists() && !file.delete()) if (file.exists() && !file.delete()) throw new RuntimeException("Failed to delete file.");
throw new RuntimeException("Failed to delete file.");
if (!file.exists() && !file.createNewFile()) if (!file.exists() && !file.createNewFile())
throw new RuntimeException("Failed to create file."); throw new RuntimeException("Failed to create file.");
@ -216,20 +234,23 @@ public interface Dumpers {
// Convert all known avatars to an avatar map. // Convert all known avatars to an avatar map.
var dump = new HashMap<Integer, EntityInfo>(); var dump = new HashMap<Integer, EntityInfo>();
GameData.getMonsterDataMap().forEach((id, monster) -> { GameData.getMonsterDataMap()
.forEach(
(id, monster) -> {
var langHash = monster.getNameTextMapHash(); var langHash = monster.getNameTextMapHash();
dump.put(id, new EntityInfo( dump.put(
langHash == 0 ? monster.getMonsterName() : id,
Language.getTextMapKey(langHash).get(locale), new EntityInfo(
monster.getMonsterName() langHash == 0
)); ? monster.getMonsterName()
: Language.getTextMapKey(langHash).get(locale),
monster.getMonsterName()));
}); });
try { try {
// Create a file for the dump. // Create a file for the dump.
var file = new File("entities.csv"); var file = new File("entities.csv");
if (file.exists() && !file.delete()) if (file.exists() && !file.delete()) throw new RuntimeException("Failed to delete file.");
throw new RuntimeException("Failed to delete file.");
if (!file.exists() && !file.createNewFile()) if (!file.exists() && !file.createNewFile())
throw new RuntimeException("Failed to create file."); throw new RuntimeException("Failed to create file.");
@ -256,8 +277,7 @@ public interface Dumpers {
@Override @Override
public String toString() { public String toString() {
return this.name + "," return this.name + "," + this.quality;
+ this.quality;
} }
} }
@ -271,10 +291,7 @@ public interface Dumpers {
@Override @Override
public String toString() { public String toString() {
return this.name + "," return this.name + "," + this.quality + "," + this.type + "," + this.icon;
+ this.quality + ","
+ this.type + ","
+ this.icon;
} }
} }
@ -285,8 +302,7 @@ public interface Dumpers {
@Override @Override
public String toString() { public String toString() {
return this.identifier + "," return this.identifier + "," + this.type;
+ this.type;
} }
} }
@ -297,13 +313,17 @@ public interface Dumpers {
@Override @Override
public String toString() { public String toString() {
return this.name + "," return this.name + "," + this.internal;
+ this.internal;
} }
} }
enum Quality { enum Quality {
LEGENDARY, EPIC, RARE, UNCOMMON, COMMON, UNKNOWN; LEGENDARY,
EPIC,
RARE,
UNCOMMON,
COMMON,
UNKNOWN;
/** /**
* Convert a rank level to a quality. * Convert a rank level to a quality.

View File

@ -8,10 +8,9 @@ import emu.grasscutter.BuildConfig;
import emu.grasscutter.Grasscutter; import emu.grasscutter.Grasscutter;
import emu.grasscutter.Grasscutter.ServerRunMode; import emu.grasscutter.Grasscutter.ServerRunMode;
import emu.grasscutter.net.packet.PacketOpcodesUtils; import emu.grasscutter.net.packet.PacketOpcodesUtils;
import emu.grasscutter.tools.Dumpers;
import java.util.Map; import java.util.Map;
import java.util.function.Function; import java.util.function.Function;
import emu.grasscutter.tools.Dumpers;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
/** A parser for start-up arguments. */ /** A parser for start-up arguments. */