mirror of
https://github.com/Grasscutters/Grasscutter.git
synced 2026-05-27 12:10:14 +08:00
Format code [skip actions]
This commit is contained in:
@@ -230,7 +230,11 @@ public final class CommandMap {
|
||||
if (SERVER.logCommands) {
|
||||
if (player != null) {
|
||||
Grasscutter.getLogger()
|
||||
.info("Command used by [{} (Player UID: {})]: {}", player.getAccount().getUsername(), player.getUid(), rawMessage);
|
||||
.info(
|
||||
"Command used by [{} (Player UID: {})]: {}",
|
||||
player.getAccount().getUsername(),
|
||||
player.getUid(),
|
||||
rawMessage);
|
||||
} else {
|
||||
Grasscutter.getLogger().info("Command used by server console: {}", rawMessage);
|
||||
}
|
||||
@@ -344,10 +348,13 @@ public final class CommandMap {
|
||||
this.registerCommand(cmdData.label(), (CommandHandler) object);
|
||||
else
|
||||
Grasscutter.getLogger()
|
||||
.error("Class {} is not a CommandHandler!", annotated.getName());
|
||||
.error("Class {} is not a CommandHandler!", annotated.getName());
|
||||
} catch (Exception exception) {
|
||||
Grasscutter.getLogger()
|
||||
.error("Failed to register command handler for {}", annotated.getSimpleName(), exception);
|
||||
.error(
|
||||
"Failed to register command handler for {}",
|
||||
annotated.getSimpleName(),
|
||||
exception);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -136,18 +136,19 @@ public final class AchievementCommand implements CommandHandler {
|
||||
|
||||
parseInt(args.remove(0))
|
||||
.ifPresentOrElse(
|
||||
integer -> parseInt(args.remove(0))
|
||||
.ifPresentOrElse(
|
||||
progress -> {
|
||||
var ret = achievements.progress(integer, progress);
|
||||
switch (ret.getRet()) {
|
||||
case SUCCESS -> sendSuccessMessage(
|
||||
sender, "progress", targetPlayer.getNickname(), integer, progress);
|
||||
case ACHIEVEMENT_NOT_FOUND -> CommandHandler.sendTranslatedMessage(
|
||||
sender, ret.getRet().getKey());
|
||||
}
|
||||
},
|
||||
() -> this.sendUsageMessage(sender)),
|
||||
integer ->
|
||||
parseInt(args.remove(0))
|
||||
.ifPresentOrElse(
|
||||
progress -> {
|
||||
var ret = achievements.progress(integer, progress);
|
||||
switch (ret.getRet()) {
|
||||
case SUCCESS -> sendSuccessMessage(
|
||||
sender, "progress", targetPlayer.getNickname(), integer, progress);
|
||||
case ACHIEVEMENT_NOT_FOUND -> CommandHandler.sendTranslatedMessage(
|
||||
sender, ret.getRet().getKey());
|
||||
}
|
||||
},
|
||||
() -> this.sendUsageMessage(sender)),
|
||||
() -> this.sendUsageMessage(sender));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
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.CommandHandler;
|
||||
import emu.grasscutter.data.GameData;
|
||||
@@ -14,30 +17,50 @@ import emu.grasscutter.game.inventory.ItemType;
|
||||
import emu.grasscutter.game.player.Player;
|
||||
import emu.grasscutter.game.props.ActionReason;
|
||||
import emu.grasscutter.game.props.FightProperty;
|
||||
import lombok.Setter;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.function.BiConsumer;
|
||||
import java.util.regex.Pattern;
|
||||
import lombok.Setter;
|
||||
|
||||
import static emu.grasscutter.GameConstants.*;
|
||||
import static emu.grasscutter.command.CommandHelpers.*;
|
||||
|
||||
@Command(label = "give", aliases = {"g", "item", "giveitem"}, usage = {"(<itemId>|<avatarId>|all|weapons|mats|avatars) [lv<level>] [r<refinement>] [x<amount>] [c<constellation>] [sl<skilllevel>]", "<artifactId> [lv<level>] [x<amount>] [<mainPropId>] [<appendPropId>[,<times>]]..."}, permission = "player.give", permissionTargeted = "player.give.others", threading = true)
|
||||
@Command(
|
||||
label = "give",
|
||||
aliases = {"g", "item", "giveitem"},
|
||||
usage = {
|
||||
"(<itemId>|<avatarId>|all|weapons|mats|avatars) [lv<level>] [r<refinement>] [x<amount>] [c<constellation>] [sl<skilllevel>]",
|
||||
"<artifactId> [lv<level>] [x<amount>] [<mainPropId>] [<appendPropId>[,<times>]]..."
|
||||
},
|
||||
permission = "player.give",
|
||||
permissionTargeted = "player.give.others",
|
||||
threading = true)
|
||||
public final class GiveCommand implements CommandHandler {
|
||||
private static final Map<Pattern, BiConsumer<GiveItemParameters, Integer>> intCommandHandlers = Map.ofEntries(Map.entry(lvlRegex, GiveItemParameters::setLvl), Map.entry(refineRegex, GiveItemParameters::setRefinement), Map.entry(amountRegex, GiveItemParameters::setAmount), Map.entry(constellationRegex, GiveItemParameters::setConstellation), Map.entry(skillLevelRegex, GiveItemParameters::setSkillLevel));
|
||||
private static final Map<Pattern, BiConsumer<GiveItemParameters, Integer>> intCommandHandlers =
|
||||
Map.ofEntries(
|
||||
Map.entry(lvlRegex, GiveItemParameters::setLvl),
|
||||
Map.entry(refineRegex, GiveItemParameters::setRefinement),
|
||||
Map.entry(amountRegex, GiveItemParameters::setAmount),
|
||||
Map.entry(constellationRegex, GiveItemParameters::setConstellation),
|
||||
Map.entry(skillLevelRegex, GiveItemParameters::setSkillLevel));
|
||||
|
||||
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.setLevel(level);
|
||||
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.recalcStats(true);
|
||||
avatar.save();
|
||||
@@ -47,13 +70,16 @@ public final class GiveCommand implements CommandHandler {
|
||||
private static void giveAllAvatars(Player player, GiveItemParameters param) {
|
||||
int promoteLevel = Avatar.getMinPromoteLevel(param.lvl);
|
||||
if (param.constellation < 0 || param.constellation > 6)
|
||||
param.constellation = 6; // constellation's default is -1 so if no parameters set for constellations it'll
|
||||
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()) {
|
||||
int id = avatarData.getId();
|
||||
if (id < 10000002 || id >= 11000000) continue; // Exclude test avatars
|
||||
// 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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -93,7 +119,7 @@ public final class GiveCommand implements CommandHandler {
|
||||
item.setTotalExp(totalExp);
|
||||
int numAffixes = param.data.getAppendPropNum() + (param.lvl - 1) / 4;
|
||||
if (param.mainPropId > 0) // Keep random mainProp if we didn't specify one
|
||||
item.setMainPropId(param.mainPropId);
|
||||
item.setMainPropId(param.mainPropId);
|
||||
if (param.appendPropIdList != null) {
|
||||
item.getAppendPropIdList().clear();
|
||||
item.getAppendPropIdList().addAll(param.appendPropIdList);
|
||||
@@ -105,14 +131,17 @@ public final class GiveCommand implements CommandHandler {
|
||||
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)
|
||||
for (ReliquaryMainPropData data : GameDepot.getRelicMainPropList(itemData.getMainPropDepotId()))
|
||||
for (ReliquaryMainPropData data :
|
||||
GameDepot.getRelicMainPropList(itemData.getMainPropDepotId()))
|
||||
if (data.getWeight() > 0 && data.getFightProp() == prop) return data.getId();
|
||||
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) {
|
||||
throw new IllegalArgumentException();
|
||||
}
|
||||
@@ -125,7 +154,8 @@ public final class GiveCommand implements CommandHandler {
|
||||
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.
|
||||
try {
|
||||
return Integer.parseInt(substatText);
|
||||
@@ -142,7 +172,8 @@ public final class GiveCommand implements CommandHandler {
|
||||
substatTier = Integer.parseInt(substatArgs[1]);
|
||||
}
|
||||
|
||||
List<Integer> substats = getArtifactAffixes(itemData, FightProperty.getPropByShortName(substatType));
|
||||
List<Integer> substats =
|
||||
getArtifactAffixes(itemData, FightProperty.getPropByShortName(substatType));
|
||||
|
||||
if (substats.isEmpty()) {
|
||||
throw new IllegalArgumentException();
|
||||
@@ -154,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.
|
||||
// If the given argument is an integer, we use that.
|
||||
// If not, we check if the argument string is in the main prop map.
|
||||
@@ -164,7 +196,8 @@ public final class GiveCommand implements CommandHandler {
|
||||
param.mainPropId = Integer.parseInt(mainPropIdString);
|
||||
} catch (NumberFormatException ignored) {
|
||||
// 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.
|
||||
@@ -245,7 +278,8 @@ public final class GiveCommand implements CommandHandler {
|
||||
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();
|
||||
|
||||
// Extract any tagged arguments (e.g. "lv90", "x100", "r5")
|
||||
@@ -287,7 +321,9 @@ public final class GiveCommand implements CommandHandler {
|
||||
param.avatarData = GameData.getAvatarDataMap().get(param.id - 1000 + 10_000_000);
|
||||
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 {
|
||||
param.amount = Integer.parseInt(args.remove(0));
|
||||
} catch (NumberFormatException e) {
|
||||
@@ -365,7 +401,8 @@ public final class GiveCommand implements CommandHandler {
|
||||
if (param.avatarData != null) {
|
||||
Avatar avatar = makeAvatar(param);
|
||||
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;
|
||||
}
|
||||
// If it's not an avatar, it needs to be a valid item
|
||||
@@ -376,37 +413,54 @@ public final class GiveCommand implements CommandHandler {
|
||||
|
||||
switch (param.data.getItemType()) {
|
||||
case ITEM_WEAPON:
|
||||
targetPlayer.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());
|
||||
targetPlayer
|
||||
.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;
|
||||
case ITEM_RELIQUARY:
|
||||
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;
|
||||
default:
|
||||
targetPlayer.getInventory().addItem(new GameItem(param.data, param.amount), ActionReason.SubfieldDrop);
|
||||
CommandHandler.sendTranslatedMessage(sender, "commands.give.given", param.amount, param.id, targetPlayer.getUid());
|
||||
targetPlayer
|
||||
.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) {
|
||||
}
|
||||
}
|
||||
|
||||
private enum GiveAllType {
|
||||
NONE, ALL, WEAPONS, MATS, AVATARS
|
||||
NONE,
|
||||
ALL,
|
||||
WEAPONS,
|
||||
MATS,
|
||||
AVATARS
|
||||
}
|
||||
|
||||
private static class GiveItemParameters {
|
||||
public int id;
|
||||
@Setter
|
||||
public int lvl = 0;
|
||||
@Setter
|
||||
public int amount = 1;
|
||||
@Setter
|
||||
public int refinement = 1;
|
||||
@Setter
|
||||
public int constellation = -1;
|
||||
@Setter
|
||||
public int skillLevel = 1;
|
||||
@Setter public int lvl = 0;
|
||||
@Setter public int amount = 1;
|
||||
@Setter public int refinement = 1;
|
||||
@Setter public int constellation = -1;
|
||||
@Setter public int skillLevel = 1;
|
||||
public int mainPropId = -1;
|
||||
public List<Integer> appendPropIdList;
|
||||
public ItemData data;
|
||||
|
||||
@@ -24,8 +24,7 @@ public final class SendMailCommand implements CommandHandler {
|
||||
// the command system (again). For now this will do
|
||||
|
||||
// Key = User that is constructing the mail.
|
||||
private static final HashMap<Integer, MailBuilder> mailBeingConstructed =
|
||||
new HashMap<>();
|
||||
private static final HashMap<Integer, MailBuilder> mailBeingConstructed = new HashMap<>();
|
||||
|
||||
// Yes this is awful and I hate it.
|
||||
@Override
|
||||
|
||||
@@ -95,7 +95,8 @@ public final class SetSceneTagCommand implements CommandHandler {
|
||||
// Only remove for big world as some other scenes only have defaults
|
||||
.filter(sceneTag -> sceneTag.getSceneId() == 3)
|
||||
.forEach(
|
||||
sceneTag -> targetPlayer.getSceneTags().get(sceneTag.getSceneId()).remove(sceneTag.getId()));
|
||||
sceneTag ->
|
||||
targetPlayer.getSceneTags().get(sceneTag.getSceneId()).remove(sceneTag.getId()));
|
||||
|
||||
this.setSceneTags(targetPlayer);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user