Commit ae2d1fe4 authored by github-actions's avatar github-actions Committed by Melledy
Browse files

Fix whitespace [skip actions]

parent 510d564b
...@@ -6,29 +6,29 @@ import emu.grasscutter.utils.Position; ...@@ -6,29 +6,29 @@ import emu.grasscutter.utils.Position;
import emu.grasscutter.utils.Utils; import emu.grasscutter.utils.Utils;
public final class GameConstants { public final class GameConstants {
public static String VERSION = "2.8.0"; public static String VERSION = "2.8.0";
public static final int MAX_TEAMS = 4; public static final int MAX_TEAMS = 4;
public static final int MAIN_CHARACTER_MALE = 10000005; public static final int MAIN_CHARACTER_MALE = 10000005;
public static final int MAIN_CHARACTER_FEMALE = 10000007; public static final int MAIN_CHARACTER_FEMALE = 10000007;
public static final Position START_POSITION = new Position(2747, 194, -1719); public static final Position START_POSITION = new Position(2747, 194, -1719);
public static final int MAX_FRIENDS = 45; public static final int MAX_FRIENDS = 45;
public static final int MAX_FRIEND_REQUESTS = 50; public static final int MAX_FRIEND_REQUESTS = 50;
public static final int SERVER_CONSOLE_UID = 99; // The UID of the server console's "player". public static final int SERVER_CONSOLE_UID = 99; // The UID of the server console's "player".
public static final int BATTLE_PASS_MAX_LEVEL = 50; public static final int BATTLE_PASS_MAX_LEVEL = 50;
public static final int BATTLE_PASS_POINT_PER_LEVEL = 1000; public static final int BATTLE_PASS_POINT_PER_LEVEL = 1000;
public static final int BATTLE_PASS_POINT_PER_WEEK = 10000; public static final int BATTLE_PASS_POINT_PER_WEEK = 10000;
public static final int BATTLE_PASS_LEVEL_PRICE = 150; public static final int BATTLE_PASS_LEVEL_PRICE = 150;
public static final int BATTLE_PASS_CURRENT_INDEX = 2; public static final int BATTLE_PASS_CURRENT_INDEX = 2;
// Default entity ability hashes. // Default entity ability hashes.
public static final String[] DEFAULT_ABILITY_STRINGS = { public static final String[] DEFAULT_ABILITY_STRINGS = {
"Avatar_DefaultAbility_VisionReplaceDieInvincible", "Avatar_DefaultAbility_AvartarInShaderChange", "Avatar_SprintBS_Invincible", "Avatar_DefaultAbility_VisionReplaceDieInvincible", "Avatar_DefaultAbility_AvartarInShaderChange", "Avatar_SprintBS_Invincible",
"Avatar_Freeze_Duration_Reducer", "Avatar_Attack_ReviveEnergy", "Avatar_Component_Initializer", "Avatar_FallAnthem_Achievement_Listener" "Avatar_Freeze_Duration_Reducer", "Avatar_Attack_ReviveEnergy", "Avatar_Component_Initializer", "Avatar_FallAnthem_Achievement_Listener"
}; };
public static final int[] DEFAULT_ABILITY_HASHES = Arrays.stream(DEFAULT_ABILITY_STRINGS).mapToInt(Utils::abilityHash).toArray(); public static final int[] DEFAULT_ABILITY_HASHES = Arrays.stream(DEFAULT_ABILITY_STRINGS).mapToInt(Utils::abilityHash).toArray();
public static final int DEFAULT_ABILITY_NAME = Utils.abilityHash("Default"); public static final int DEFAULT_ABILITY_NAME = Utils.abilityHash("Default");
} }
...@@ -217,7 +217,7 @@ public final class Grasscutter { ...@@ -217,7 +217,7 @@ public final class Grasscutter {
*/ */
private static void onShutdown() { private static void onShutdown() {
// Disable all plugins. // Disable all plugins.
if(pluginManager != null) if (pluginManager != null)
pluginManager.disablePlugins(); pluginManager.disablePlugins();
} }
......
...@@ -21,7 +21,7 @@ public final class DefaultAuthentication implements AuthenticationSystem { ...@@ -21,7 +21,7 @@ public final class DefaultAuthentication implements AuthenticationSystem {
private OAuthAuthenticator oAuthAuthenticator = new OAuthAuthentication(); private OAuthAuthenticator oAuthAuthenticator = new OAuthAuthentication();
public DefaultAuthentication() { public DefaultAuthentication() {
if(ACCOUNT.EXPERIMENTAL_RealPassword) { if (ACCOUNT.EXPERIMENTAL_RealPassword) {
passwordAuthenticator = new ExperimentalPasswordAuthenticator(); passwordAuthenticator = new ExperimentalPasswordAuthenticator();
} else { } else {
passwordAuthenticator = new PasswordAuthenticator(); passwordAuthenticator = new PasswordAuthenticator();
......
...@@ -167,7 +167,7 @@ public final class CommandMap { ...@@ -167,7 +167,7 @@ public final class CommandMap {
CommandHandler.sendTranslatedMessage(player, "commands.execution.clear_target"); CommandHandler.sendTranslatedMessage(player, "commands.execution.clear_target");
return true; return true;
} }
// Sets default targetPlayer to the UID provided. // Sets default targetPlayer to the UID provided.
try { try {
int uid = Integer.parseInt(targetUid); int uid = Integer.parseInt(targetUid);
...@@ -237,7 +237,7 @@ public final class CommandMap { ...@@ -237,7 +237,7 @@ public final class CommandMap {
Command annotation = this.annotations.get(label); Command annotation = this.annotations.get(label);
// Resolve targetPlayer // Resolve targetPlayer
try{ try {
targetPlayer = getTargetPlayer(playerId, player, targetPlayer, args); targetPlayer = getTargetPlayer(playerId, player, targetPlayer, args);
} catch (IllegalArgumentException e) { } catch (IllegalArgumentException e) {
return; return;
......
...@@ -39,8 +39,8 @@ public final class AccountCommand implements CommandHandler { ...@@ -39,8 +39,8 @@ public final class AccountCommand implements CommandHandler {
int uid = 0; int uid = 0;
String password = ""; String password = "";
if(Configuration.ACCOUNT.EXPERIMENTAL_RealPassword == true) { if (Configuration.ACCOUNT.EXPERIMENTAL_RealPassword == true) {
if(args.size() < 3) { if (args.size() < 3) {
CommandHandler.sendMessage(null, "EXPERIMENTAL_RealPassword requires a password argument"); CommandHandler.sendMessage(null, "EXPERIMENTAL_RealPassword requires a password argument");
CommandHandler.sendMessage(null, "Usage: account create <username> <password> [uid]"); CommandHandler.sendMessage(null, "Usage: account create <username> <password> [uid]");
...@@ -53,7 +53,7 @@ public final class AccountCommand implements CommandHandler { ...@@ -53,7 +53,7 @@ public final class AccountCommand implements CommandHandler {
uid = Integer.parseInt(args.get(3)); uid = Integer.parseInt(args.get(3));
} catch (NumberFormatException ignored) { } catch (NumberFormatException ignored) {
CommandHandler.sendMessage(null, translate(sender, "commands.account.invalid")); CommandHandler.sendMessage(null, translate(sender, "commands.account.invalid"));
if(Configuration.ACCOUNT.EXPERIMENTAL_RealPassword == true) { if (Configuration.ACCOUNT.EXPERIMENTAL_RealPassword == true) {
CommandHandler.sendMessage(null, "EXPERIMENTAL_RealPassword requires argument 2 to be a password, not a uid"); CommandHandler.sendMessage(null, "EXPERIMENTAL_RealPassword requires argument 2 to be a password, not a uid");
CommandHandler.sendMessage(null, "Usage: account create <username> <password> [uid]"); CommandHandler.sendMessage(null, "Usage: account create <username> <password> [uid]");
} }
...@@ -76,7 +76,7 @@ public final class AccountCommand implements CommandHandler { ...@@ -76,7 +76,7 @@ public final class AccountCommand implements CommandHandler {
CommandHandler.sendMessage(null, translate(sender, "commands.account.exists")); CommandHandler.sendMessage(null, translate(sender, "commands.account.exists"));
return; return;
} else { } else {
if(Configuration.ACCOUNT.EXPERIMENTAL_RealPassword == true) { if (Configuration.ACCOUNT.EXPERIMENTAL_RealPassword == true) {
account.setPassword(BCrypt.withDefaults().hashToString(12, password.toCharArray())); account.setPassword(BCrypt.withDefaults().hashToString(12, password.toCharArray()));
} }
account.addPermission("*"); account.addPermission("*");
...@@ -93,7 +93,7 @@ public final class AccountCommand implements CommandHandler { ...@@ -93,7 +93,7 @@ public final class AccountCommand implements CommandHandler {
CommandHandler.sendMessage(null, translate(sender, "commands.account.no_account")); CommandHandler.sendMessage(null, translate(sender, "commands.account.no_account"));
return; return;
} }
// Get the player for the account. // Get the player for the account.
// If that player is currently online, we kick them before proceeding with the deletion. // If that player is currently online, we kick them before proceeding with the deletion.
Player player = Grasscutter.getGameServer().getPlayerByAccountId(toDelete.getId()); Player player = Grasscutter.getGameServer().getPlayerByAccountId(toDelete.getId());
...@@ -106,12 +106,12 @@ public final class AccountCommand implements CommandHandler { ...@@ -106,12 +106,12 @@ public final class AccountCommand implements CommandHandler {
CommandHandler.sendMessage(null, translate(sender, "commands.account.delete")); CommandHandler.sendMessage(null, translate(sender, "commands.account.delete"));
return; return;
case "resetpass": case "resetpass":
if(Configuration.ACCOUNT.EXPERIMENTAL_RealPassword != true) { if (Configuration.ACCOUNT.EXPERIMENTAL_RealPassword != true) {
CommandHandler.sendMessage(null, "resetpass requires EXPERIMENTAL_RealPassword to be true."); CommandHandler.sendMessage(null, "resetpass requires EXPERIMENTAL_RealPassword to be true.");
return; return;
} }
if(args.size() != 3) { if (args.size() != 3) {
CommandHandler.sendMessage(null, "Invalid Args"); CommandHandler.sendMessage(null, "Invalid Args");
CommandHandler.sendMessage(null, "Usage: account resetpass <username> <password>"); CommandHandler.sendMessage(null, "Usage: account resetpass <username> <password>");
return; return;
......
...@@ -28,7 +28,7 @@ public final class AnnounceCommand implements CommandHandler { ...@@ -28,7 +28,7 @@ public final class AnnounceCommand implements CommandHandler {
return; return;
} }
switch (args.get(0)){ switch (args.get(0)) {
case "tpl": case "tpl":
if (args.size() < 2) { if (args.size() < 2) {
CommandHandler.sendTranslatedMessage(sender, "commands.announce.command_usage"); CommandHandler.sendTranslatedMessage(sender, "commands.announce.command_usage");
...@@ -37,7 +37,7 @@ public final class AnnounceCommand implements CommandHandler { ...@@ -37,7 +37,7 @@ public final class AnnounceCommand implements CommandHandler {
var templateId = Integer.parseInt(args.get(1)); var templateId = Integer.parseInt(args.get(1));
var tpl = manager.getAnnounceConfigItemMap().get(templateId); var tpl = manager.getAnnounceConfigItemMap().get(templateId);
if(tpl == null){ if (tpl == null) {
CommandHandler.sendMessage(sender, translate(sender, "commands.announce.not_found", templateId)); CommandHandler.sendMessage(sender, translate(sender, "commands.announce.not_found", templateId));
return; return;
} }
......
...@@ -38,7 +38,7 @@ public final class CoopCommand implements CommandHandler { ...@@ -38,7 +38,7 @@ public final class CoopCommand implements CommandHandler {
CommandHandler.sendMessage(sender, translate(sender, "commands.coop.usage")); CommandHandler.sendMessage(sender, translate(sender, "commands.coop.usage"));
return; return;
} }
// There's no target==host check but this just places them in multiplayer in their own world which seems fine. // There's no target==host check but this just places them in multiplayer in their own world which seems fine.
if (targetPlayer.isInMultiplayer()) { if (targetPlayer.isInMultiplayer()) {
targetPlayer.getServer().getMultiplayerSystem().leaveCoop(targetPlayer); targetPlayer.getServer().getMultiplayerSystem().leaveCoop(targetPlayer);
......
...@@ -21,10 +21,10 @@ public final class EnterDungeonCommand implements CommandHandler { ...@@ -21,10 +21,10 @@ public final class EnterDungeonCommand implements CommandHandler {
try { try {
int dungeonId = Integer.parseInt(args.get(0)); int dungeonId = Integer.parseInt(args.get(0));
if (dungeonId == targetPlayer.getSceneId()) { if (dungeonId == targetPlayer.getSceneId()) {
CommandHandler.sendMessage(sender, translate(sender, "commands.enter_dungeon.in_dungeon_error")); CommandHandler.sendMessage(sender, translate(sender, "commands.enter_dungeon.in_dungeon_error"));
return; return;
} }
boolean result = targetPlayer.getServer().getDungeonSystem().enterDungeon(targetPlayer.getSession().getPlayer(), 0, dungeonId); boolean result = targetPlayer.getServer().getDungeonSystem().enterDungeon(targetPlayer.getSession().getPlayer(), 0, dungeonId);
if (!result) { if (!result) {
......
...@@ -257,7 +257,7 @@ public final class GiveCommand implements CommandHandler { ...@@ -257,7 +257,7 @@ public final class GiveCommand implements CommandHandler {
if (avatar.getAvatarId() == GameConstants.MAIN_CHARACTER_MALE) { if (avatar.getAvatarId() == GameConstants.MAIN_CHARACTER_MALE) {
avatar.setSkillDepotData(GameData.getAvatarSkillDepotDataMap().get(504)); avatar.setSkillDepotData(GameData.getAvatarSkillDepotDataMap().get(504));
} }
else if(avatar.getAvatarId() == GameConstants.MAIN_CHARACTER_FEMALE) { else if (avatar.getAvatarId() == GameConstants.MAIN_CHARACTER_FEMALE) {
avatar.setSkillDepotData(GameData.getAvatarSkillDepotDataMap().get(704)); avatar.setSkillDepotData(GameData.getAvatarSkillDepotDataMap().get(704));
} }
...@@ -352,11 +352,11 @@ public final class GiveCommand implements CommandHandler { ...@@ -352,11 +352,11 @@ 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);
} catch (NumberFormatException ignored) { } catch (NumberFormatException ignored) {
// If the argument was not an integer, we try to determine // If the argument was not an integer, we try to determine
// the append prop ID from the given text + artifact information. // the append prop ID from the given text + artifact information.
// A substat string has the format `substat_tier`, with the // A substat string has the format `substat_tier`, with the
...@@ -378,8 +378,8 @@ public final class GiveCommand implements CommandHandler { ...@@ -378,8 +378,8 @@ public final class GiveCommand implements CommandHandler {
substatTier -= 1; // 1-indexed to 0-indexed substatTier -= 1; // 1-indexed to 0-indexed
substatTier = Math.min(Math.max(0, substatTier), substats.size() - 1); substatTier = Math.min(Math.max(0, substatTier), substats.size() - 1);
return substats.get(substatTier); return substats.get(substatTier);
} }
} }
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.
...@@ -476,11 +476,11 @@ public final class GiveCommand implements CommandHandler { ...@@ -476,11 +476,11 @@ public final class GiveCommand implements CommandHandler {
10000-10008, 11411, 11506-11508, 12505, 12506, 12508, 12509, 10000-10008, 11411, 11506-11508, 12505, 12506, 12508, 12509,
13503, 13506, 14411, 14503, 14505, 14508, 15504-15506 13503, 13506, 14411, 14503, 14505, 14508, 15504-15506
"""); """);
private static final SparseSet illegalRelicIds = new SparseSet(""" private static final SparseSet illegalRelicIds = new SparseSet("""
20001, 23300-23340, 23383-23385, 78310-78554, 99310-99554 20001, 23300-23340, 23383-23385, 78310-78554, 99310-99554
"""); """);
private static final SparseSet illegalItemIds = new SparseSet(""" private static final SparseSet illegalItemIds = new SparseSet("""
100086, 100087, 100100-101000, 101106-101110, 101306, 101500-104000, 100086, 100087, 100100-101000, 101106-101110, 101306, 101500-104000,
105001, 105004, 106000-107000, 107011, 108000, 109000-110000, 105001, 105004, 106000-107000, 107011, 108000, 109000-110000,
......
...@@ -22,13 +22,13 @@ public final class HelpCommand implements CommandHandler { ...@@ -22,13 +22,13 @@ public final class HelpCommand implements CommandHandler {
} }
} }
builder.append("\n\t").append(translate(player, "commands.help.tip_need_permission")); builder.append("\n\t").append(translate(player, "commands.help.tip_need_permission"));
if(annotation.permission().isEmpty() || annotation.permission().isBlank()) { if (annotation.permission().isEmpty() || annotation.permission().isBlank()) {
builder.append(translate(player, "commands.help.tip_need_no_permission")); builder.append(translate(player, "commands.help.tip_need_no_permission"));
} else { } else {
builder.append(annotation.permission()); builder.append(annotation.permission());
} }
if(!annotation.permissionTargeted().isEmpty() && !annotation.permissionTargeted().isBlank()) { if (!annotation.permissionTargeted().isEmpty() && !annotation.permissionTargeted().isBlank()) {
String permissionTargeted = annotation.permissionTargeted(); String permissionTargeted = annotation.permissionTargeted();
builder.append(" ").append(translate(player, "commands.help.tip_permission_targeted", permissionTargeted)); builder.append(" ").append(translate(player, "commands.help.tip_permission_targeted", permissionTargeted));
} }
......
...@@ -15,13 +15,13 @@ public final class ReloadCommand implements CommandHandler { ...@@ -15,13 +15,13 @@ public final class ReloadCommand implements CommandHandler {
@Override @Override
public void execute(Player sender, Player targetPlayer, List<String> args) { public void execute(Player sender, Player targetPlayer, List<String> args) {
CommandHandler.sendMessage(sender, translate(sender, "commands.reload.reload_start")); CommandHandler.sendMessage(sender, translate(sender, "commands.reload.reload_start"));
Grasscutter.loadConfig(); Grasscutter.loadConfig();
Grasscutter.loadLanguage(); Grasscutter.loadLanguage();
Grasscutter.getGameServer().getGachaSystem().load(); Grasscutter.getGameServer().getGachaSystem().load();
Grasscutter.getGameServer().getDropSystem().load(); Grasscutter.getGameServer().getDropSystem().load();
Grasscutter.getGameServer().getShopSystem().load(); Grasscutter.getGameServer().getShopSystem().load();
CommandHandler.sendMessage(sender, translate(sender, "commands.reload.reload_done")); CommandHandler.sendMessage(sender, translate(sender, "commands.reload.reload_done"));
} }
} }
...@@ -27,7 +27,7 @@ public final class SendMailCommand implements CommandHandler { ...@@ -27,7 +27,7 @@ public final class SendMailCommand implements CommandHandler {
@Override @Override
public void execute(Player sender, Player targetPlayer, List<String> args) { public void execute(Player sender, Player targetPlayer, List<String> args) {
int senderId; int senderId;
if(sender != null) { if (sender != null) {
senderId = sender.getUid(); senderId = sender.getUid();
} else { } else {
senderId = -1; senderId = -1;
...@@ -162,7 +162,7 @@ public final class SendMailCommand implements CommandHandler { ...@@ -162,7 +162,7 @@ public final class SendMailCommand implements CommandHandler {
} }
private String getConstructionArgs(int stage, Player sender) { private String getConstructionArgs(int stage, Player sender) {
return switch(stage) { return switch (stage) {
case 0 -> translate(sender, "commands.sendMail.title"); case 0 -> translate(sender, "commands.sendMail.title");
case 1 -> translate(sender, "commands.sendMail.message"); case 1 -> translate(sender, "commands.sendMail.message");
case 2 -> translate(sender, "commands.sendMail.sender"); case 2 -> translate(sender, "commands.sendMail.sender");
......
package emu.grasscutter.command.commands; package emu.grasscutter.command.commands;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import emu.grasscutter.command.Command; import emu.grasscutter.command.Command;
import emu.grasscutter.command.CommandHandler; import emu.grasscutter.command.CommandHandler;
import emu.grasscutter.game.player.Player; import emu.grasscutter.game.player.Player;
import emu.grasscutter.game.props.PlayerProperty; import emu.grasscutter.game.props.PlayerProperty;
import emu.grasscutter.game.tower.TowerLevelRecord; import emu.grasscutter.game.tower.TowerLevelRecord;
@Command(label = "setprop", usage = "setprop|prop <prop> <value>", aliases = {"prop"}, permission = "player.setprop", permissionTargeted = "player.setprop.others", description = "commands.setProp.description") @Command(label = "setprop", usage = "setprop|prop <prop> <value>", aliases = {"prop"}, permission = "player.setprop", permissionTargeted = "player.setprop.others", description = "commands.setProp.description")
public final class SetPropCommand implements CommandHandler { public final class SetPropCommand implements CommandHandler {
static enum PseudoProp { static enum PseudoProp {
NONE, NONE,
WORLD_LEVEL, WORLD_LEVEL,
TOWER_LEVEL, TOWER_LEVEL,
BP_LEVEL, BP_LEVEL,
GOD_MODE, GOD_MODE,
NO_STAMINA, NO_STAMINA,
UNLIMITED_ENERGY UNLIMITED_ENERGY
} }
static class Prop { static class Prop {
String name; String name;
PlayerProperty prop; PlayerProperty prop;
PseudoProp pseudoProp; PseudoProp pseudoProp;
public Prop(PlayerProperty prop) { public Prop(PlayerProperty prop) {
this(prop.toString(), prop, PseudoProp.NONE); this(prop.toString(), prop, PseudoProp.NONE);
} }
public Prop(String name) { public Prop(String name) {
this(name, PlayerProperty.PROP_NONE, PseudoProp.NONE); this(name, PlayerProperty.PROP_NONE, PseudoProp.NONE);
} }
public Prop(String name, PseudoProp pseudoProp) { public Prop(String name, PseudoProp pseudoProp) {
this(name, PlayerProperty.PROP_NONE, pseudoProp); this(name, PlayerProperty.PROP_NONE, pseudoProp);
} }
public Prop(String name, PlayerProperty prop) { public Prop(String name, PlayerProperty prop) {
this(name, prop, PseudoProp.NONE); this(name, prop, PseudoProp.NONE);
} }
public Prop(String name, PlayerProperty prop, PseudoProp pseudoProp) { public Prop(String name, PlayerProperty prop, PseudoProp pseudoProp) {
this.name = name; this.name = name;
this.prop = prop; this.prop = prop;
this.pseudoProp = pseudoProp; this.pseudoProp = pseudoProp;
} }
} }
Map<String, Prop> props; Map<String, Prop> props;
public SetPropCommand() { public SetPropCommand() {
this.props = new HashMap<>(); this.props = new HashMap<>();
// Full PlayerProperty enum that won't be advertised but can be used by devs // Full PlayerProperty enum that won't be advertised but can be used by devs
for (PlayerProperty prop : PlayerProperty.values()) { for (PlayerProperty prop : PlayerProperty.values()) {
String name = prop.toString().substring(5); // PROP_EXP -> EXP String name = prop.toString().substring(5); // PROP_EXP -> EXP
String key = name.toLowerCase(); // EXP -> exp String key = name.toLowerCase(); // EXP -> exp
this.props.put(key, new Prop(name, prop)); this.props.put(key, new Prop(name, prop));
} }
// Add special props // Add special props
Prop worldlevel = new Prop("World Level", PlayerProperty.PROP_PLAYER_WORLD_LEVEL, PseudoProp.WORLD_LEVEL); Prop worldlevel = new Prop("World Level", PlayerProperty.PROP_PLAYER_WORLD_LEVEL, PseudoProp.WORLD_LEVEL);
this.props.put("worldlevel", worldlevel); this.props.put("worldlevel", worldlevel);
this.props.put("wl", worldlevel); this.props.put("wl", worldlevel);
Prop abyss = new Prop("Tower Level", PseudoProp.TOWER_LEVEL); Prop abyss = new Prop("Tower Level", PseudoProp.TOWER_LEVEL);
this.props.put("abyss", abyss); this.props.put("abyss", abyss);
this.props.put("abyssfloor", abyss); this.props.put("abyssfloor", abyss);
this.props.put("ut", abyss); this.props.put("ut", abyss);
this.props.put("tower", abyss); this.props.put("tower", abyss);
this.props.put("towerlevel", abyss); this.props.put("towerlevel", abyss);
this.props.put("unlocktower", abyss); this.props.put("unlocktower", abyss);
Prop bplevel = new Prop("BP Level", PseudoProp.BP_LEVEL); Prop bplevel = new Prop("BP Level", PseudoProp.BP_LEVEL);
this.props.put("bplevel", bplevel); this.props.put("bplevel", bplevel);
this.props.put("bp", bplevel); this.props.put("bp", bplevel);
this.props.put("battlepass", bplevel); this.props.put("battlepass", bplevel);
Prop godmode = new Prop("godmode", PseudoProp.GOD_MODE); Prop godmode = new Prop("godmode", PseudoProp.GOD_MODE);
this.props.put("godmode", godmode); this.props.put("godmode", godmode);
this.props.put("god", godmode); this.props.put("god", godmode);
Prop nostamina = new Prop("nostamina", PseudoProp.NO_STAMINA); Prop nostamina = new Prop("nostamina", PseudoProp.NO_STAMINA);
this.props.put("nostamina", nostamina); this.props.put("nostamina", nostamina);
this.props.put("nostam", nostamina); this.props.put("nostam", nostamina);
this.props.put("ns", nostamina); this.props.put("ns", nostamina);
Prop unlimitedenergy = new Prop("unlimitedenergy", PseudoProp.UNLIMITED_ENERGY); Prop unlimitedenergy = new Prop("unlimitedenergy", PseudoProp.UNLIMITED_ENERGY);
this.props.put("unlimitedenergy", unlimitedenergy); this.props.put("unlimitedenergy", unlimitedenergy);
this.props.put("ue", unlimitedenergy); this.props.put("ue", unlimitedenergy);
} }
@Override @Override
public void execute(Player sender, Player targetPlayer, List<String> args) { public void execute(Player sender, Player targetPlayer, List<String> args) {
if (args.size() != 2) { if (args.size() != 2) {
CommandHandler.sendTranslatedMessage(sender, "commands.setProp.usage"); CommandHandler.sendTranslatedMessage(sender, "commands.setProp.usage");
return; return;
} }
String propStr = args.get(0).toLowerCase(); String propStr = args.get(0).toLowerCase();
String valueStr = args.get(1).toLowerCase(); String valueStr = args.get(1).toLowerCase();
int value; int value;
if (!props.containsKey(propStr)) { if (!props.containsKey(propStr)) {
CommandHandler.sendTranslatedMessage(sender, "commands.setProp.usage"); CommandHandler.sendTranslatedMessage(sender, "commands.setProp.usage");
return; return;
} }
try { try {
value = switch(valueStr.toLowerCase()) { value = switch (valueStr.toLowerCase()) {
case "on", "true" -> 1; case "on", "true" -> 1;
case "off", "false" -> 0; case "off", "false" -> 0;
case "toggle" -> -1; case "toggle" -> -1;
default -> Integer.parseInt(valueStr); default -> Integer.parseInt(valueStr);
}; };
} catch (NumberFormatException ignored) { } catch (NumberFormatException ignored) {
CommandHandler.sendTranslatedMessage(sender, "commands.execution.argument_error"); CommandHandler.sendTranslatedMessage(sender, "commands.execution.argument_error");
return; return;
} }
boolean success = false; boolean success = false;
Prop prop = props.get(propStr); Prop prop = props.get(propStr);
success = switch (prop.pseudoProp) { success = switch (prop.pseudoProp) {
case WORLD_LEVEL -> targetPlayer.setWorldLevel(value); case WORLD_LEVEL -> targetPlayer.setWorldLevel(value);
case BP_LEVEL -> targetPlayer.getBattlePassManager().setLevel(value); case BP_LEVEL -> targetPlayer.getBattlePassManager().setLevel(value);
case TOWER_LEVEL -> this.setTowerLevel(sender, targetPlayer, value); case TOWER_LEVEL -> this.setTowerLevel(sender, targetPlayer, value);
case GOD_MODE, NO_STAMINA, UNLIMITED_ENERGY -> this.setBool(sender, targetPlayer, prop.pseudoProp, value); case GOD_MODE, NO_STAMINA, UNLIMITED_ENERGY -> this.setBool(sender, targetPlayer, prop.pseudoProp, value);
default -> targetPlayer.setProperty(prop.prop, value); default -> targetPlayer.setProperty(prop.prop, value);
}; };
if (success) { if (success) {
if (targetPlayer == sender) { if (targetPlayer == sender) {
CommandHandler.sendTranslatedMessage(sender, "commands.generic.set_to", prop.name, valueStr); CommandHandler.sendTranslatedMessage(sender, "commands.generic.set_to", prop.name, valueStr);
} else { } else {
String uidStr = targetPlayer.getAccount().getId(); String uidStr = targetPlayer.getAccount().getId();
CommandHandler.sendTranslatedMessage(sender, "commands.generic.set_for_to", prop.name, uidStr, valueStr); CommandHandler.sendTranslatedMessage(sender, "commands.generic.set_for_to", prop.name, uidStr, valueStr);
} }
} else { } else {
if (prop.prop != PlayerProperty.PROP_NONE) { // PseudoProps need to do their own error messages if (prop.prop != PlayerProperty.PROP_NONE) { // PseudoProps need to do their own error messages
String min = Integer.toString(targetPlayer.getPropertyMin(prop.prop)); String min = Integer.toString(targetPlayer.getPropertyMin(prop.prop));
String max = Integer.toString(targetPlayer.getPropertyMax(prop.prop)); String max = Integer.toString(targetPlayer.getPropertyMax(prop.prop));
CommandHandler.sendTranslatedMessage(sender, "commands.generic.invalid.value_between", prop.name, min, max); CommandHandler.sendTranslatedMessage(sender, "commands.generic.invalid.value_between", prop.name, min, max);
} }
} }
} }
private boolean setTowerLevel(Player sender, Player targetPlayer, int topFloor) { private boolean setTowerLevel(Player sender, Player targetPlayer, int topFloor) {
List<Integer> floorIds = targetPlayer.getServer().getTowerSystem().getAllFloors(); List<Integer> floorIds = targetPlayer.getServer().getTowerSystem().getAllFloors();
if (topFloor < 0 || topFloor > floorIds.size()) { if (topFloor < 0 || topFloor > floorIds.size()) {
String min = Integer.toString(0); String min = Integer.toString(0);
String max = Integer.toString(floorIds.size()); String max = Integer.toString(floorIds.size());
CommandHandler.sendTranslatedMessage(sender, "commands.generic.invalid.value_between", "Tower Level", min, max); CommandHandler.sendTranslatedMessage(sender, "commands.generic.invalid.value_between", "Tower Level", min, max);
return false; return false;
} }
Map<Integer, TowerLevelRecord> recordMap = targetPlayer.getTowerManager().getRecordMap(); Map<Integer, TowerLevelRecord> recordMap = targetPlayer.getTowerManager().getRecordMap();
// Add records for each unlocked floor // Add records for each unlocked floor
for (int floor : floorIds.subList(0, topFloor)) { for (int floor : floorIds.subList(0, topFloor)) {
if (!recordMap.containsKey(floor)) { if (!recordMap.containsKey(floor)) {
recordMap.put(floor, new TowerLevelRecord(floor)); recordMap.put(floor, new TowerLevelRecord(floor));
} }
} }
// Remove records for each floor past our target // Remove records for each floor past our target
for (int floor : floorIds.subList(topFloor, floorIds.size())) { for (int floor : floorIds.subList(topFloor, floorIds.size())) {
if (recordMap.containsKey(floor)) { if (recordMap.containsKey(floor)) {
recordMap.remove(floor); recordMap.remove(floor);
} }
} }
// Six stars required on Floor 8 to unlock Floor 9+ // Six stars required on Floor 8 to unlock Floor 9+
if (topFloor > 8) { if (topFloor > 8) {
recordMap.get(floorIds.get(7)).setLevelStars(0, 6); // levelIds seem to start at 1 for Floor 1 Chamber 1, so this doesn't get shown at all recordMap.get(floorIds.get(7)).setLevelStars(0, 6); // levelIds seem to start at 1 for Floor 1 Chamber 1, so this doesn't get shown at all
} }
return true; return true;
} }
private boolean setBool(Player sender, Player targetPlayer, PseudoProp pseudoProp, int value) { private boolean setBool(Player sender, Player targetPlayer, PseudoProp pseudoProp, int value) {
boolean enabled = switch (pseudoProp) { boolean enabled = switch (pseudoProp) {
case GOD_MODE -> targetPlayer.inGodmode(); case GOD_MODE -> targetPlayer.inGodmode();
case NO_STAMINA -> targetPlayer.getUnlimitedStamina(); case NO_STAMINA -> targetPlayer.getUnlimitedStamina();
case UNLIMITED_ENERGY -> !targetPlayer.getEnergyManager().getEnergyUsage(); case UNLIMITED_ENERGY -> !targetPlayer.getEnergyManager().getEnergyUsage();
default -> false; default -> false;
}; };
enabled = switch (value) { enabled = switch (value) {
case -1 -> !enabled; case -1 -> !enabled;
case 0 -> false; case 0 -> false;
default -> true; default -> true;
}; };
switch (pseudoProp) { switch (pseudoProp) {
case GOD_MODE: case GOD_MODE:
targetPlayer.setGodmode(enabled); targetPlayer.setGodmode(enabled);
break; break;
case NO_STAMINA: case NO_STAMINA:
targetPlayer.setUnlimitedStamina(enabled); targetPlayer.setUnlimitedStamina(enabled);
break; break;
case UNLIMITED_ENERGY: case UNLIMITED_ENERGY:
targetPlayer.getEnergyManager().setEnergyUsage(!enabled); targetPlayer.getEnergyManager().setEnergyUsage(!enabled);
break; break;
default: default:
return false; return false;
} }
return true; return true;
} }
} }
...@@ -31,7 +31,7 @@ public final class SpawnCommand implements CommandHandler { ...@@ -31,7 +31,7 @@ public final class SpawnCommand implements CommandHandler {
int id = 0; // This is just to shut up the linter, it's not a real default int id = 0; // This is just to shut up the linter, it's not a real default
int amount = 1; int amount = 1;
int level = 1; int level = 1;
float x = 0, y = 0, z = 0; float x = 0, y = 0, z = 0;
switch (args.size()) { switch (args.size()) {
case 6: case 6:
try { try {
...@@ -64,7 +64,7 @@ public final class SpawnCommand implements CommandHandler { ...@@ -64,7 +64,7 @@ public final class SpawnCommand implements CommandHandler {
CommandHandler.sendMessage(sender, translate(sender, "commands.spawn.usage")); CommandHandler.sendMessage(sender, translate(sender, "commands.spawn.usage"));
return; return;
} }
MonsterData monsterData = GameData.getMonsterDataMap().get(id); MonsterData monsterData = GameData.getMonsterDataMap().get(id);
GadgetData gadgetData = GameData.getGadgetDataMap().get(id); GadgetData gadgetData = GameData.getGadgetDataMap().get(id);
ItemData itemData = GameData.getItemDataMap().get(id); ItemData itemData = GameData.getItemDataMap().get(id);
...@@ -72,21 +72,21 @@ public final class SpawnCommand implements CommandHandler { ...@@ -72,21 +72,21 @@ public final class SpawnCommand implements CommandHandler {
CommandHandler.sendMessage(sender, translate(sender, "commands.generic.invalid.entityId")); CommandHandler.sendMessage(sender, translate(sender, "commands.generic.invalid.entityId"));
return; return;
} }
Scene scene = targetPlayer.getScene(); Scene scene = targetPlayer.getScene();
if (scene.getEntities().size() + amount > GAME_OPTIONS.sceneEntityLimit) { if (scene.getEntities().size() + amount > GAME_OPTIONS.sceneEntityLimit) {
amount = Math.max(Math.min(GAME_OPTIONS.sceneEntityLimit - scene.getEntities().size(), amount), 0); amount = Math.max(Math.min(GAME_OPTIONS.sceneEntityLimit - scene.getEntities().size(), amount), 0);
CommandHandler.sendMessage(sender, translate(sender, "commands.spawn.limit_reached", amount)); CommandHandler.sendMessage(sender, translate(sender, "commands.spawn.limit_reached", amount));
if (amount <= 0) { if (amount <= 0) {
return; return;
} }
} }
double maxRadius = Math.sqrt(amount * 0.2 / Math.PI); double maxRadius = Math.sqrt(amount * 0.2 / Math.PI);
for (int i = 0; i < amount; i++) { for (int i = 0; i < amount; i++) {
Position pos = GetRandomPositionInCircle(targetPlayer.getPosition(), maxRadius).addY(3); Position pos = GetRandomPositionInCircle(targetPlayer.getPosition(), maxRadius).addY(3);
if(x != 0 && y != 0 && z != 0) { if (x != 0 && y != 0 && z != 0) {
pos = GetRandomPositionInCircle(new Position(x, y, z), maxRadius).addY(3); pos = GetRandomPositionInCircle(new Position(x, y, z), maxRadius).addY(3);
} }
GameEntity entity = null; GameEntity entity = null;
...@@ -120,7 +120,7 @@ public final class SpawnCommand implements CommandHandler { ...@@ -120,7 +120,7 @@ public final class SpawnCommand implements CommandHandler {
CommandHandler.sendMessage(sender, translate(sender, "commands.spawn.success", Integer.toString(amount), Integer.toString(id))); CommandHandler.sendMessage(sender, translate(sender, "commands.spawn.success", Integer.toString(amount), Integer.toString(id)));
} }
private Position GetRandomPositionInCircle(Position origin, double radius){ private Position GetRandomPositionInCircle(Position origin, double radius) {
Position target = origin.clone(); Position target = origin.clone();
double angle = Math.random() * 360; double angle = Math.random() * 360;
double r = Math.sqrt(Math.random() * radius * radius); double r = Math.sqrt(Math.random() * radius * radius);
......
package emu.grasscutter.command.commands; package emu.grasscutter.command.commands;
import emu.grasscutter.command.Command; import emu.grasscutter.command.Command;
import emu.grasscutter.command.CommandHandler; import emu.grasscutter.command.CommandHandler;
import emu.grasscutter.game.player.Player; import emu.grasscutter.game.player.Player;
import emu.grasscutter.server.packet.send.PacketChangeMpTeamAvatarRsp; import emu.grasscutter.server.packet.send.PacketChangeMpTeamAvatarRsp;
import java.util.List; import java.util.List;
import static emu.grasscutter.config.Configuration.*; import static emu.grasscutter.config.Configuration.*;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashSet; import java.util.HashSet;
@Command(label = "team", usage = "team <add|remove|set> [avatarId,...] [index|first|last|index-index,...]", @Command(label = "team", usage = "team <add|remove|set> [avatarId,...] [index|first|last|index-index,...]",
permission = "player.team", permissionTargeted = "player.team.others", description = "commands.team.description") permission = "player.team", permissionTargeted = "player.team.others", description = "commands.team.description")
public final class TeamCommand implements CommandHandler { public final class TeamCommand implements CommandHandler {
private static final int BASE_AVATARID = 10000000; private static final int BASE_AVATARID = 10000000;
@Override @Override
public void execute(Player sender, Player targetPlayer, List<String> args) { public void execute(Player sender, Player targetPlayer, List<String> args) {
if (args.isEmpty()) { if (args.isEmpty()) {
CommandHandler.sendTranslatedMessage(sender, "commands.team.usage"); CommandHandler.sendTranslatedMessage(sender, "commands.team.usage");
return; return;
} }
switch (args.get(0)) { switch (args.get(0)) {
case "add": case "add":
if (!addCommand(sender, targetPlayer, args)) return; if (!addCommand(sender, targetPlayer, args)) return;
break; break;
case "remove": case "remove":
if (!removeCommand(sender, targetPlayer, args)) return; if (!removeCommand(sender, targetPlayer, args)) return;
break; break;
case "set": case "set":
if (!setCommand(sender, targetPlayer, args)) return; if (!setCommand(sender, targetPlayer, args)) return;
break; break;
default: default:
CommandHandler.sendTranslatedMessage(sender, "commands.team.invalid_usage"); CommandHandler.sendTranslatedMessage(sender, "commands.team.invalid_usage");
CommandHandler.sendTranslatedMessage(sender, "commands.team.usage"); CommandHandler.sendTranslatedMessage(sender, "commands.team.usage");
return; return;
} }
targetPlayer.getTeamManager().updateTeamEntities( targetPlayer.getTeamManager().updateTeamEntities(
new PacketChangeMpTeamAvatarRsp(targetPlayer, targetPlayer.getTeamManager().getCurrentTeamInfo())); new PacketChangeMpTeamAvatarRsp(targetPlayer, targetPlayer.getTeamManager().getCurrentTeamInfo()));
} }
private boolean addCommand(Player sender, Player targetPlayer, List<String> args) { private boolean addCommand(Player sender, Player targetPlayer, List<String> args) {
if (args.size() < 2) { if (args.size() < 2) {
CommandHandler.sendTranslatedMessage(sender, "commands.team.invalid_usage"); CommandHandler.sendTranslatedMessage(sender, "commands.team.invalid_usage");
CommandHandler.sendTranslatedMessage(sender, "commands.team.add_usage"); CommandHandler.sendTranslatedMessage(sender, "commands.team.add_usage");
return false; return false;
} }
int index = -1; int index = -1;
if (args.size() > 2) { if (args.size() > 2) {
try { try {
index = Integer.parseInt(args.get(2)) - 1; index = Integer.parseInt(args.get(2)) - 1;
if (index < 0) index = 0; if (index < 0) index = 0;
} catch (Exception e) { } catch (Exception e) {
CommandHandler.sendTranslatedMessage(sender, "commands.team.invalid_index"); CommandHandler.sendTranslatedMessage(sender, "commands.team.invalid_index");
return false; return false;
} }
} }
var avatarIds = args.get(1).split(","); var avatarIds = args.get(1).split(",");
var currentTeamAvatars = targetPlayer.getTeamManager().getCurrentTeamInfo().getAvatars(); var currentTeamAvatars = targetPlayer.getTeamManager().getCurrentTeamInfo().getAvatars();
if (currentTeamAvatars.size() + avatarIds.length > GAME_OPTIONS.avatarLimits.singlePlayerTeam) { if (currentTeamAvatars.size() + avatarIds.length > GAME_OPTIONS.avatarLimits.singlePlayerTeam) {
CommandHandler.sendTranslatedMessage(sender, "commands.team.add_too_much", GAME_OPTIONS.avatarLimits.singlePlayerTeam); CommandHandler.sendTranslatedMessage(sender, "commands.team.add_too_much", GAME_OPTIONS.avatarLimits.singlePlayerTeam);
return false; return false;
} }
for (var avatarId: avatarIds) { for (var avatarId: avatarIds) {
int id = Integer.parseInt(avatarId); int id = Integer.parseInt(avatarId);
var success = addAvatar(sender, targetPlayer, id, index); var success = addAvatar(sender, targetPlayer, id, index);
if (index > 0) ++index; if (index > 0) ++index;
} }
return true; return true;
} }
private boolean removeCommand(Player sender, Player targetPlayer, List<String> args) { private boolean removeCommand(Player sender, Player targetPlayer, List<String> args) {
if (args.size() < 2) { if (args.size() < 2) {
CommandHandler.sendTranslatedMessage(sender, "commands.team.invalid_usage"); CommandHandler.sendTranslatedMessage(sender, "commands.team.invalid_usage");
CommandHandler.sendTranslatedMessage(sender, "commands.team.remove_usage"); CommandHandler.sendTranslatedMessage(sender, "commands.team.remove_usage");
return false; return false;
} }
var currentTeamAvatars = targetPlayer.getTeamManager().getCurrentTeamInfo().getAvatars(); var currentTeamAvatars = targetPlayer.getTeamManager().getCurrentTeamInfo().getAvatars();
var avatarCount = currentTeamAvatars.size(); var avatarCount = currentTeamAvatars.size();
var metaIndexList = args.get(1).split(","); var metaIndexList = args.get(1).split(",");
var indexes = new HashSet<Integer>(); var indexes = new HashSet<Integer>();
var ignoreList = new ArrayList<Integer>(); var ignoreList = new ArrayList<Integer>();
for (var metaIndex: metaIndexList) { for (var metaIndex: metaIndexList) {
// step 1: parse metaIndex to indexes // step 1: parse metaIndex to indexes
var subIndexes = transformToIndexes(metaIndex, avatarCount); var subIndexes = transformToIndexes(metaIndex, avatarCount);
if (subIndexes == null) { if (subIndexes == null) {
CommandHandler.sendTranslatedMessage(sender, "commands.team.failed_to_parse_index", metaIndex); CommandHandler.sendTranslatedMessage(sender, "commands.team.failed_to_parse_index", metaIndex);
continue; continue;
} }
// step 2: get all of the avatar id through indexes // step 2: get all of the avatar id through indexes
for (var avatarIndex: subIndexes) { for (var avatarIndex: subIndexes) {
try { try {
indexes.add(currentTeamAvatars.get(avatarIndex - 1)); indexes.add(currentTeamAvatars.get(avatarIndex - 1));
} catch (Exception e) { } catch (Exception e) {
ignoreList.add(avatarIndex); ignoreList.add(avatarIndex);
continue; continue;
} }
} }
} }
// step 3: check if user remove all of the avatar // step 3: check if user remove all of the avatar
if (indexes.size() >= avatarCount) { if (indexes.size() >= avatarCount) {
CommandHandler.sendTranslatedMessage(sender, "commands.team.remove_too_much"); CommandHandler.sendTranslatedMessage(sender, "commands.team.remove_too_much");
return false; return false;
} }
// step 4: hint user for ignore index // step 4: hint user for ignore index
if (!ignoreList.isEmpty()) { if (!ignoreList.isEmpty()) {
CommandHandler.sendTranslatedMessage(sender, "commands.team.ignore_index", ignoreList); CommandHandler.sendTranslatedMessage(sender, "commands.team.ignore_index", ignoreList);
} }
// step 5: remove // step 5: remove
currentTeamAvatars.removeAll(indexes); currentTeamAvatars.removeAll(indexes);
return true; return true;
} }
private boolean setCommand(Player sender, Player targetPlayer, List<String> args) { private boolean setCommand(Player sender, Player targetPlayer, List<String> args) {
if (args.size() < 3) { if (args.size() < 3) {
CommandHandler.sendTranslatedMessage(sender, "commands.team.invalid_usage"); CommandHandler.sendTranslatedMessage(sender, "commands.team.invalid_usage");
CommandHandler.sendTranslatedMessage(sender, "commands.team.set_usage"); CommandHandler.sendTranslatedMessage(sender, "commands.team.set_usage");
return false; return false;
} }
var currentTeamAvatars = targetPlayer.getTeamManager().getCurrentTeamInfo().getAvatars(); var currentTeamAvatars = targetPlayer.getTeamManager().getCurrentTeamInfo().getAvatars();
int index; int index;
try { try {
index = Integer.parseInt(args.get(1)) - 1; index = Integer.parseInt(args.get(1)) - 1;
if (index < 0) index = 0; if (index < 0) index = 0;
} catch(Exception e) { } catch (Exception e) {
CommandHandler.sendTranslatedMessage(sender, "commands.team.failed_to_parse_index", args.get(1)); CommandHandler.sendTranslatedMessage(sender, "commands.team.failed_to_parse_index", args.get(1));
return false; return false;
} }
if (index + 1 > currentTeamAvatars.size()) { if (index + 1 > currentTeamAvatars.size()) {
CommandHandler.sendTranslatedMessage(sender, "commands.team.index_out_of_range"); CommandHandler.sendTranslatedMessage(sender, "commands.team.index_out_of_range");
return false; return false;
} }
int avatarId; int avatarId;
try { try {
avatarId = Integer.parseInt(args.get(2)); avatarId = Integer.parseInt(args.get(2));
} catch(Exception e) { } catch (Exception e) {
CommandHandler.sendTranslatedMessage(sender, "commands.team.failed_parse_avatar_id", args.get(2)); CommandHandler.sendTranslatedMessage(sender, "commands.team.failed_parse_avatar_id", args.get(2));
return false; return false;
} }
if (avatarId < BASE_AVATARID) { if (avatarId < BASE_AVATARID) {
avatarId += BASE_AVATARID; avatarId += BASE_AVATARID;
} }
if (currentTeamAvatars.contains(avatarId)) { if (currentTeamAvatars.contains(avatarId)) {
CommandHandler.sendTranslatedMessage(sender, "commands.team.avatar_already_in_team", avatarId); CommandHandler.sendTranslatedMessage(sender, "commands.team.avatar_already_in_team", avatarId);
return false; return false;
} }
if (!targetPlayer.getAvatars().hasAvatar(avatarId)) { if (!targetPlayer.getAvatars().hasAvatar(avatarId)) {
CommandHandler.sendTranslatedMessage(sender, "commands.team.avatar_not_found", avatarId); CommandHandler.sendTranslatedMessage(sender, "commands.team.avatar_not_found", avatarId);
return false; return false;
} }
currentTeamAvatars.set(index, avatarId); currentTeamAvatars.set(index, avatarId);
return true; return true;
} }
private boolean addAvatar(Player sender, Player targetPlayer, int avatarId, int index) { private boolean addAvatar(Player sender, Player targetPlayer, int avatarId, int index) {
if (avatarId < BASE_AVATARID) { if (avatarId < BASE_AVATARID) {
avatarId += BASE_AVATARID; avatarId += BASE_AVATARID;
} }
var currentTeamAvatars = targetPlayer.getTeamManager().getCurrentTeamInfo().getAvatars(); var currentTeamAvatars = targetPlayer.getTeamManager().getCurrentTeamInfo().getAvatars();
if (currentTeamAvatars.contains(avatarId)) { if (currentTeamAvatars.contains(avatarId)) {
CommandHandler.sendTranslatedMessage(sender, "commands.team.avatar_already_in_team", avatarId); CommandHandler.sendTranslatedMessage(sender, "commands.team.avatar_already_in_team", avatarId);
return false; return false;
} }
if (!targetPlayer.getAvatars().hasAvatar(avatarId)) { if (!targetPlayer.getAvatars().hasAvatar(avatarId)) {
CommandHandler.sendTranslatedMessage(sender, "commands.team.avatar_not_found", avatarId); CommandHandler.sendTranslatedMessage(sender, "commands.team.avatar_not_found", avatarId);
return false; return false;
} }
if (index < 0) { if (index < 0) {
currentTeamAvatars.add(avatarId); currentTeamAvatars.add(avatarId);
} else { } else {
currentTeamAvatars.add(index, avatarId); currentTeamAvatars.add(index, avatarId);
} }
return true; return true;
} }
private List<Integer> transformToIndexes(String metaIndexes, int listLength) { private List<Integer> transformToIndexes(String metaIndexes, int listLength) {
// step 1: check if metaIndexes is a special constants // step 1: check if metaIndexes is a special constants
if (metaIndexes.equals("first")) { if (metaIndexes.equals("first")) {
return List.of(1); return List.of(1);
} else if (metaIndexes.equals("last")) { } else if (metaIndexes.equals("last")) {
return List.of(listLength); return List.of(listLength);
} }
// step 2: check if metaIndexes is a range // step 2: check if metaIndexes is a range
if (metaIndexes.contains("-")) { if (metaIndexes.contains("-")) {
var range = metaIndexes.split("-"); var range = metaIndexes.split("-");
if (range.length < 2) { if (range.length < 2) {
return null; return null;
} }
int min, max; int min, max;
try { try {
min = switch (range[0]) { min = switch (range[0]) {
case "first" -> 1; case "first" -> 1;
case "last" -> listLength; case "last" -> listLength;
default -> Integer.parseInt(range[0]); default -> Integer.parseInt(range[0]);
}; };
max = switch (range[1]) { max = switch (range[1]) {
case "first" -> 1; case "first" -> 1;
case "last" -> listLength; case "last" -> listLength;
default -> Integer.parseInt(range[1]); default -> Integer.parseInt(range[1]);
}; };
} catch (Exception e) { } catch (Exception e) {
return null; return null;
} }
if (min > max) { if (min > max) {
min ^= max; min ^= max;
max ^= min; max ^= min;
min ^= max; min ^= max;
} }
var indexes = new ArrayList<Integer>(); var indexes = new ArrayList<Integer>();
for (int i = min; i <= max; ++i) { for (int i = min; i <= max; ++i) {
indexes.add(i); indexes.add(i);
} }
return indexes; return indexes;
} }
// step 3: index is a value, simply return // step 3: index is a value, simply return
try { try {
int index = Integer.parseInt(metaIndexes); int index = Integer.parseInt(metaIndexes);
return List.of(index); return List.of(index);
} catch (Exception e) { } catch (Exception e) {
return null; return null;
} }
} }
} }
...@@ -19,7 +19,7 @@ public final class TeleportAllCommand implements CommandHandler { ...@@ -19,7 +19,7 @@ public final class TeleportAllCommand implements CommandHandler {
CommandHandler.sendMessage(sender, translate(sender, "commands.teleportAll.error")); CommandHandler.sendMessage(sender, translate(sender, "commands.teleportAll.error"));
return; return;
} }
for (Player player : targetPlayer.getWorld().getPlayers()) { for (Player player : targetPlayer.getWorld().getPlayers()) {
if (player.equals(targetPlayer)) if (player.equals(targetPlayer))
continue; continue;
...@@ -27,7 +27,7 @@ public final class TeleportAllCommand implements CommandHandler { ...@@ -27,7 +27,7 @@ public final class TeleportAllCommand implements CommandHandler {
player.getWorld().transferPlayerToScene(player, targetPlayer.getSceneId(), pos); player.getWorld().transferPlayerToScene(player, targetPlayer.getSceneId(), pos);
} }
CommandHandler.sendMessage(sender, translate(sender, "commands.teleportAll.success")); CommandHandler.sendMessage(sender, translate(sender, "commands.teleportAll.success"));
} }
} }
...@@ -58,8 +58,8 @@ public final class TeleportCommand implements CommandHandler { ...@@ -58,8 +58,8 @@ public final class TeleportCommand implements CommandHandler {
if (!result) { if (!result) {
CommandHandler.sendMessage(sender, translate(sender, "commands.teleport.exists_error")); CommandHandler.sendMessage(sender, translate(sender, "commands.teleport.exists_error"));
} else { } else {
CommandHandler.sendMessage(sender, translate(sender, "commands.teleport.success", CommandHandler.sendMessage(sender, translate(sender, "commands.teleport.success",
targetPlayer.getNickname(), Float.toString(x), Float.toString(y), targetPlayer.getNickname(), Float.toString(x), Float.toString(y),
Float.toString(z), Integer.toString(sceneId)) Float.toString(z), Integer.toString(sceneId))
); );
} }
......
...@@ -28,7 +28,7 @@ public class ConfigContainer { ...@@ -28,7 +28,7 @@ public class ConfigContainer {
try { // Check if the server is using a legacy config. try { // Check if the server is using a legacy config.
JsonObject configObject = Grasscutter.getGsonFactory() JsonObject configObject = Grasscutter.getGsonFactory()
.fromJson(new FileReader(Grasscutter.configFile), JsonObject.class); .fromJson(new FileReader(Grasscutter.configFile), JsonObject.class);
if(!configObject.has("version")) { if (!configObject.has("version")) {
Grasscutter.getLogger().info("Updating legacy .."); Grasscutter.getLogger().info("Updating legacy ..");
Grasscutter.saveConfig(null); Grasscutter.saveConfig(null);
} }
...@@ -37,7 +37,7 @@ public class ConfigContainer { ...@@ -37,7 +37,7 @@ public class ConfigContainer {
var existing = config.version; var existing = config.version;
var latest = version(); var latest = version();
if(existing == latest) if (existing == latest)
return; return;
// Create a new configuration instance. // Create a new configuration instance.
...@@ -135,20 +135,20 @@ public class ConfigContainer { ...@@ -135,20 +135,20 @@ public class ConfigContainer {
public static class Game { public static class Game {
public String bindAddress = "0.0.0.0"; public String bindAddress = "0.0.0.0";
public int bindPort = 22102; public int bindPort = 22102;
/* This is the address used in the default region. */ /* This is the address used in the default region. */
public String accessAddress = "127.0.0.1"; public String accessAddress = "127.0.0.1";
/* This is the port used in the default region. */ /* This is the port used in the default region. */
public int accessPort = 0; public int accessPort = 0;
/* Entities within a certain range will be loaded for the player */ /* Entities within a certain range will be loaded for the player */
public int loadEntitiesForPlayerRange = 100; public int loadEntitiesForPlayerRange = 100;
public boolean enableScriptInBigWorld = false; public boolean enableScriptInBigWorld = false;
public boolean enableConsole = true; public boolean enableConsole = true;
/* Controls whether packets should be logged in console or not */ /* Controls whether packets should be logged in console or not */
public ServerDebugMode logPackets = ServerDebugMode.NONE; public ServerDebugMode logPackets = ServerDebugMode.NONE;
public GameOptions gameOptions = new GameOptions(); public GameOptions gameOptions = new GameOptions();
public JoinOptions joinOptions = new JoinOptions(); public JoinOptions joinOptions = new JoinOptions();
public ConsoleAccount serverAccount = new ConsoleAccount(); public ConsoleAccount serverAccount = new ConsoleAccount();
...@@ -160,7 +160,7 @@ public class ConfigContainer { ...@@ -160,7 +160,7 @@ public class ConfigContainer {
public Region[] regions = {}; public Region[] regions = {};
public String defaultName = "Grasscutter"; public String defaultName = "Grasscutter";
public ServerDebugMode logRequests = ServerDebugMode.NONE; public ServerDebugMode logRequests = ServerDebugMode.NONE;
} }
...@@ -276,4 +276,4 @@ public class ConfigContainer { ...@@ -276,4 +276,4 @@ public class ConfigContainer {
public String Ip = "127.0.0.1"; public String Ip = "127.0.0.1";
public int Port = 22102; public int Port = 22102;
} }
} }
\ No newline at end of file
...@@ -9,19 +9,19 @@ import static emu.grasscutter.Grasscutter.config; ...@@ -9,19 +9,19 @@ import static emu.grasscutter.Grasscutter.config;
/** /**
* A data container for the server's configuration. * A data container for the server's configuration.
* *
* Use `import static emu.grasscutter.Configuration.*;` * Use `import static emu.grasscutter.Configuration.*;`
* to import all configuration constants. * to import all configuration constants.
*/ */
public final class Configuration extends ConfigContainer { public final class Configuration extends ConfigContainer {
/* /*
* Constants * Constants
*/ */
// 'c' is short for 'config' and makes code look 'cleaner'. // 'c' is short for 'config' and makes code look 'cleaner'.
public static final ConfigContainer c = config; public static final ConfigContainer c = config;
public static final Locale LANGUAGE = config.language.language; public static final Locale LANGUAGE = config.language.language;
public static final Locale FALLBACK_LANGUAGE = config.language.fallback; public static final Locale FALLBACK_LANGUAGE = config.language.fallback;
public static final String DOCUMENT_LANGUAGE = config.language.document; public static final String DOCUMENT_LANGUAGE = config.language.document;
...@@ -30,22 +30,22 @@ public final class Configuration extends ConfigContainer { ...@@ -30,22 +30,22 @@ public final class Configuration extends ConfigContainer {
private static final String PLUGINS_FOLDER = config.folderStructure.plugins; private static final String PLUGINS_FOLDER = config.folderStructure.plugins;
private static final String SCRIPTS_FOLDER = config.folderStructure.scripts; private static final String SCRIPTS_FOLDER = config.folderStructure.scripts;
private static final String PACKETS_FOLDER = config.folderStructure.packets; private static final String PACKETS_FOLDER = config.folderStructure.packets;
public static final Server SERVER = config.server; public static final Server SERVER = config.server;
public static final Database DATABASE = config.databaseInfo; public static final Database DATABASE = config.databaseInfo;
public static final Account ACCOUNT = config.account; public static final Account ACCOUNT = config.account;
public static final HTTP HTTP_INFO = config.server.http; public static final HTTP HTTP_INFO = config.server.http;
public static final Game GAME_INFO = config.server.game; public static final Game GAME_INFO = config.server.game;
public static final Dispatch DISPATCH_INFO = config.server.dispatch; public static final Dispatch DISPATCH_INFO = config.server.dispatch;
public static final Encryption HTTP_ENCRYPTION = config.server.http.encryption; public static final Encryption HTTP_ENCRYPTION = config.server.http.encryption;
public static final Policies HTTP_POLICIES = config.server.http.policies; public static final Policies HTTP_POLICIES = config.server.http.policies;
public static final Files HTTP_STATIC_FILES = config.server.http.files; public static final Files HTTP_STATIC_FILES = config.server.http.files;
public static final GameOptions GAME_OPTIONS = config.server.game.gameOptions; public static final GameOptions GAME_OPTIONS = config.server.game.gameOptions;
public static final GameOptions.InventoryLimits INVENTORY_LIMITS = config.server.game.gameOptions.inventoryLimits; public static final GameOptions.InventoryLimits INVENTORY_LIMITS = config.server.game.gameOptions.inventoryLimits;
/* /*
* Utilities * Utilities
*/ */
...@@ -56,11 +56,11 @@ public final class Configuration extends ConfigContainer { ...@@ -56,11 +56,11 @@ public final class Configuration extends ConfigContainer {
public static String DATA(String path) { public static String DATA(String path) {
return Paths.get(DATA_FOLDER, path).toString(); return Paths.get(DATA_FOLDER, path).toString();
} }
public static String RESOURCE(String path) { public static String RESOURCE(String path) {
return Paths.get(RESOURCES_FOLDER, path).toString(); return Paths.get(RESOURCES_FOLDER, path).toString();
} }
public static String PLUGIN() { public static String PLUGIN() {
return PLUGINS_FOLDER; return PLUGINS_FOLDER;
} }
......
...@@ -29,7 +29,7 @@ public class DataLoader { ...@@ -29,7 +29,7 @@ public class DataLoader {
public static InputStream load(String resourcePath) throws FileNotFoundException { public static InputStream load(String resourcePath) throws FileNotFoundException {
return load(resourcePath, true); return load(resourcePath, true);
} }
/** /**
* Creates an input stream reader for a data file. If the file isn't found within the /data directory then it will fallback to the default within the jar resources * Creates an input stream reader for a data file. If the file isn't found within the /data directory then it will fallback to the default within the jar resources
* *
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment