Commit a8293102 authored by Melledy's avatar Melledy Committed by GitHub
Browse files

Merge branch 'development' into stable

parents 304b9cb8 ecf7a81a
...@@ -12,17 +12,11 @@ import java.util.List; ...@@ -12,17 +12,11 @@ import java.util.List;
import static emu.grasscutter.utils.Language.translate; import static emu.grasscutter.utils.Language.translate;
@Command(label = "killall", usage = "killall [sceneId]", @Command(label = "killall", usage = "killall [sceneId]", permission = "server.killall", permissionTargeted = "server.killall.others", description = "commands.killall.description")
description = "Kill all entities", permission = "server.killall")
public final class KillAllCommand implements CommandHandler { public final class KillAllCommand implements CommandHandler {
@Override @Override
public void execute(Player sender, Player targetPlayer, List<String> args) { public void execute(Player sender, Player targetPlayer, List<String> args) {
if (targetPlayer == null) {
CommandHandler.sendMessage(sender, translate("commands.execution.need_target"));
return;
}
Scene scene = targetPlayer.getScene(); Scene scene = targetPlayer.getScene();
try { try {
switch (args.size()) { switch (args.size()) {
...@@ -32,14 +26,14 @@ public final class KillAllCommand implements CommandHandler { ...@@ -32,14 +26,14 @@ public final class KillAllCommand implements CommandHandler {
scene = targetPlayer.getWorld().getSceneById(Integer.parseInt(args.get(0))); scene = targetPlayer.getWorld().getSceneById(Integer.parseInt(args.get(0)));
break; break;
default: default:
CommandHandler.sendMessage(sender, translate("commands.kill.usage")); CommandHandler.sendMessage(sender, translate(sender, "commands.killall.usage"));
return; return;
} }
} catch (NumberFormatException ignored) { } catch (NumberFormatException ignored) {
CommandHandler.sendMessage(sender, translate("commands.execution.argument_error")); CommandHandler.sendMessage(sender, translate(sender, "commands.execution.argument_error"));
} }
if (scene == null) { if (scene == null) {
CommandHandler.sendMessage(sender, translate("commands.kill.scene_not_found_in_player_world")); CommandHandler.sendMessage(sender, translate(sender, "commands.killall.scene_not_found_in_player_world"));
return; return;
} }
...@@ -49,6 +43,6 @@ public final class KillAllCommand implements CommandHandler { ...@@ -49,6 +43,6 @@ public final class KillAllCommand implements CommandHandler {
.filter(entity -> entity instanceof EntityMonster) .filter(entity -> entity instanceof EntityMonster)
.toList(); .toList();
toKill.forEach(entity -> sceneF.killEntity(entity, 0)); toKill.forEach(entity -> sceneF.killEntity(entity, 0));
CommandHandler.sendMessage(sender, translate("commands.kill.kill_monsters_in_scene", Integer.toString(toKill.size()), Integer.toString(scene.getId()))); CommandHandler.sendMessage(sender, translate(sender, "commands.killall.kill_monsters_in_scene", Integer.toString(toKill.size()), Integer.toString(scene.getId())));
} }
} }
...@@ -13,14 +13,13 @@ import java.util.List; ...@@ -13,14 +13,13 @@ import java.util.List;
import static emu.grasscutter.utils.Language.translate; import static emu.grasscutter.utils.Language.translate;
@Command(label = "killcharacter", usage = "killcharacter", aliases = {"suicide", "kill"}, @Command(label = "killcharacter", usage = "killcharacter", aliases = {"suicide", "kill"}, permission = "player.killcharacter", permissionTargeted = "player.killcharacter.others", description = "commands.killCharacter.description")
description = "Kills the players current character", permission = "player.killcharacter")
public final class KillCharacterCommand implements CommandHandler { public final class KillCharacterCommand implements CommandHandler {
@Override @Override
public void execute(Player sender, Player targetPlayer, List<String> args) { public void execute(Player sender, Player targetPlayer, List<String> args) {
if (targetPlayer == null) { if (args.isEmpty()) {
CommandHandler.sendMessage(sender, translate("commands.execution.need_target")); CommandHandler.sendMessage(sender, translate(sender, "commands.killCharacter.usage"));
return; return;
} }
...@@ -33,6 +32,6 @@ public final class KillCharacterCommand implements CommandHandler { ...@@ -33,6 +32,6 @@ public final class KillCharacterCommand implements CommandHandler {
targetPlayer.getScene().removeEntity(entity); targetPlayer.getScene().removeEntity(entity);
entity.onDeath(0); entity.onDeath(0);
CommandHandler.sendMessage(sender, translate("commands.killCharacter.success", targetPlayer.getNickname())); CommandHandler.sendMessage(sender, translate(sender, "commands.killCharacter.success", targetPlayer.getNickname()));
} }
} }
package emu.grasscutter.command.commands;
import emu.grasscutter.Grasscutter;
import emu.grasscutter.command.Command;
import emu.grasscutter.command.CommandHandler;
import emu.grasscutter.database.DatabaseHelper;
import emu.grasscutter.game.Account;
import emu.grasscutter.game.player.Player;
import emu.grasscutter.utils.Utils;
import java.util.List;
import java.util.Locale;
import static emu.grasscutter.utils.Language.translate;
@Command(label = "language", usage = "language [language code]", description = "commands.language.description", aliases = {"lang"}, targetRequirement = Command.TargetRequirement.NONE)
public final class LanguageCommand implements CommandHandler {
@Override
public void execute(Player sender, Player targetPlayer, List<String> args) {
if (args.isEmpty()) {
String curLangCode = null;
if (sender != null) {
curLangCode = Utils.getLanguageCode(sender.getAccount().getLocale());
}
else {
curLangCode = Grasscutter.getLanguage().getLanguageCode();
}
CommandHandler.sendMessage(sender, translate(sender, "commands.language.current_language", curLangCode));
return;
}
String langCode = args.get(0);
var languageInst = Grasscutter.getLanguage(langCode);
var actualLangCode = languageInst.getLanguageCode();
var locale = Locale.forLanguageTag(actualLangCode);
if (sender != null) {
var account = sender.getAccount();
account.setLocale(locale);
account.save();
}
else {
Grasscutter.setLanguage(languageInst);
var config = Grasscutter.getConfig();
config.language.language = locale;
Grasscutter.saveConfig(config);
}
if (!langCode.equals(actualLangCode)) {
CommandHandler.sendMessage(sender, translate(sender, "commands.language.language_not_found", langCode));
}
CommandHandler.sendMessage(sender, translate(sender, "commands.language.language_changed", actualLangCode));
}
}
...@@ -10,8 +10,7 @@ import java.util.Map; ...@@ -10,8 +10,7 @@ import java.util.Map;
import static emu.grasscutter.utils.Language.translate; import static emu.grasscutter.utils.Language.translate;
@Command(label = "list", usage = "list [uid]", @Command(label = "list", usage = "list [uid]", aliases = {"players"}, description = "commands.list.description", targetRequirement = Command.TargetRequirement.NONE)
description = "List online players", aliases = {"players"})
public final class ListCommand implements CommandHandler { public final class ListCommand implements CommandHandler {
@Override @Override
...@@ -23,7 +22,7 @@ public final class ListCommand implements CommandHandler { ...@@ -23,7 +22,7 @@ public final class ListCommand implements CommandHandler {
needUID = args.get(0).equals("uid"); needUID = args.get(0).equals("uid");
} }
CommandHandler.sendMessage(sender, translate("commands.list.success", Integer.toString(playersMap.size()))); CommandHandler.sendMessage(sender, translate(sender, "commands.list.success", Integer.toString(playersMap.size())));
if (playersMap.size() != 0) { if (playersMap.size() != 0) {
StringBuilder playerSet = new StringBuilder(); StringBuilder playerSet = new StringBuilder();
......
package emu.grasscutter.command.commands;
import emu.grasscutter.command.Command;
import emu.grasscutter.command.CommandHandler;
import emu.grasscutter.game.player.Player;
import java.util.List;
import static emu.grasscutter.utils.Language.translate;
@Command(label = "nostamina", usage = "nostamina [on|off|toggle]", aliases = {"ns"}, permission = "player.nostamina", permissionTargeted = "player.nostamina.others", description = "commands.nostamina.description")
public final class NoStaminaCommand implements CommandHandler {
@Override
public void execute(Player sender, Player targetPlayer, List<String> args) {
boolean stamina = !targetPlayer.getStamina();
if (args.size() == 1) {
switch (args.get(0).toLowerCase()) {
case "on":
stamina = true;
break;
case "off":
stamina = false;
break;
default:
// toggled
break;
}
}
targetPlayer.setStamina(stamina); //Set
CommandHandler.sendMessage(sender, translate(sender, "commands.nostamina.success", (stamina ? translate(sender, "commands.status.enabled") : translate(sender, "commands.status.disabled")), targetPlayer.getNickname()));
}
}
...@@ -10,19 +10,13 @@ import java.util.List; ...@@ -10,19 +10,13 @@ import java.util.List;
import static emu.grasscutter.utils.Language.translate; import static emu.grasscutter.utils.Language.translate;
@Command(label = "permission", usage = "permission <add|remove> <permission>", @Command(label = "permission", usage = "permission <add|remove> <permission>", permission = "permission", description = "commands.permission.description")
description = "Grants or removes a permission for a user", permission = "*")
public final class PermissionCommand implements CommandHandler { public final class PermissionCommand implements CommandHandler {
@Override @Override
public void execute(Player sender, Player targetPlayer, List<String> args) { public void execute(Player sender, Player targetPlayer, List<String> args) {
if (targetPlayer == null) {
CommandHandler.sendMessage(sender, translate("commands.execution.need_target"));
return;
}
if (args.size() != 2) { if (args.size() != 2) {
CommandHandler.sendMessage(sender, translate("commands.permission.usage")); CommandHandler.sendMessage(sender, translate(sender, "commands.permission.usage"));
return; return;
} }
...@@ -31,26 +25,26 @@ public final class PermissionCommand implements CommandHandler { ...@@ -31,26 +25,26 @@ public final class PermissionCommand implements CommandHandler {
Account account = targetPlayer.getAccount(); Account account = targetPlayer.getAccount();
if (account == null) { if (account == null) {
CommandHandler.sendMessage(sender, translate("commands.permission.account_error")); CommandHandler.sendMessage(sender, translate(sender, "commands.permission.account_error"));
return; return;
} }
switch (action) { switch (action) {
default: default:
CommandHandler.sendMessage(sender, translate("commands.permission.usage")); CommandHandler.sendMessage(sender, translate(sender, "commands.permission.usage"));
break; break;
case "add": case "add":
if (account.addPermission(permission)) { if (account.addPermission(permission)) {
CommandHandler.sendMessage(sender, translate("commands.permission.add")); CommandHandler.sendMessage(sender, translate(sender, "commands.permission.add"));
} else CommandHandler.sendMessage(sender, translate("commands.permission.has_error")); } else CommandHandler.sendMessage(sender, translate(sender, "commands.permission.has_error"));
break; break;
case "remove": case "remove":
if (account.removePermission(permission)) { if (account.removePermission(permission)) {
CommandHandler.sendMessage(sender, translate("commands.permission.remove")); CommandHandler.sendMessage(sender, translate(sender, "commands.permission.remove"));
} else CommandHandler.sendMessage(sender, translate("commands.permission.not_have_error")); } else CommandHandler.sendMessage(sender, translate(sender, "commands.permission.not_have_error"));
break; break;
} }
account.save(); account.save();
} }
} }
\ No newline at end of file
...@@ -9,19 +9,13 @@ import java.util.List; ...@@ -9,19 +9,13 @@ import java.util.List;
import static emu.grasscutter.utils.Language.translate; import static emu.grasscutter.utils.Language.translate;
@Command(label = "position", usage = "position", aliases = {"pos"}, @Command(label = "position", usage = "position", aliases = {"pos"}, description = "commands.position.description")
description = "Get coordinates.")
public final class PositionCommand implements CommandHandler { public final class PositionCommand implements CommandHandler {
@Override @Override
public void execute(Player sender, Player targetPlayer, List<String> args) { public void execute(Player sender, Player targetPlayer, List<String> args) {
if (targetPlayer == null) {
CommandHandler.sendMessage(sender, translate("commands.execution.need_target"));
return;
}
Position pos = targetPlayer.getPos(); Position pos = targetPlayer.getPos();
CommandHandler.sendMessage(sender, translate("commands.position.success", CommandHandler.sendMessage(sender, translate(sender, "commands.position.success",
Float.toString(pos.getX()), Float.toString(pos.getY()), Float.toString(pos.getZ()), Float.toString(pos.getX()), Float.toString(pos.getY()), Float.toString(pos.getZ()),
Integer.toString(targetPlayer.getSceneId()))); Integer.toString(targetPlayer.getSceneId())));
} }
......
package emu.grasscutter.command.commands;
import emu.grasscutter.Grasscutter;
import emu.grasscutter.command.Command;
import emu.grasscutter.command.CommandHandler;
import emu.grasscutter.game.player.Player;
import emu.grasscutter.game.quest.GameQuest;
import java.util.List;
import static emu.grasscutter.utils.Language.translate;
@Command(label = "quest", usage = "quest <add|finish> [questId]", permission = "player.quest", permissionTargeted = "player.quest.others", description = "commands.quest.description")
public final class QuestCommand implements CommandHandler {
@Override
public void execute(Player sender, Player targetPlayer, List<String> args) {
if (args.size() != 2) {
CommandHandler.sendMessage(sender, translate(sender, "commands.quest.usage"));
return;
}
String cmd = args.get(0).toLowerCase();
int questId;
try {
questId = Integer.parseInt(args.get(1));
} catch (Exception e) {
CommandHandler.sendMessage(sender, translate(sender, "commands.quest.invalid_id"));
return;
}
switch (cmd) {
case "add" -> {
GameQuest quest = targetPlayer.getQuestManager().addQuest(questId);
if (quest != null) {
CommandHandler.sendMessage(sender, translate(sender, "commands.quest.added", questId));
return;
}
CommandHandler.sendMessage(sender, translate(sender, "commands.quest.not_found"));
}
case "finish" -> {
GameQuest quest = targetPlayer.getQuestManager().getQuestById(questId);
if (quest == null) {
CommandHandler.sendMessage(sender, translate(sender, "commands.quest.not_found"));
return;
}
quest.finish();
CommandHandler.sendMessage(sender, translate(sender, "commands.quest.finished", questId));
}
default -> {
CommandHandler.sendMessage(sender, translate(sender, "commands.quest.usage"));
}
}
}
}
...@@ -9,21 +9,19 @@ import java.util.List; ...@@ -9,21 +9,19 @@ import java.util.List;
import static emu.grasscutter.utils.Language.translate; import static emu.grasscutter.utils.Language.translate;
@Command(label = "reload", usage = "reload", @Command(label = "reload", usage = "reload", permission = "server.reload", description = "commands.reload.description", targetRequirement = Command.TargetRequirement.NONE)
description = "Reload server config", permission = "server.reload")
public final class ReloadCommand implements CommandHandler { 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("commands.reload.reload_start")); CommandHandler.sendMessage(sender, translate(sender, "commands.reload.reload_start"));
Grasscutter.loadConfig(); Grasscutter.loadConfig();
Grasscutter.loadLanguage(); Grasscutter.loadLanguage();
Grasscutter.getGameServer().getGachaManager().load(); Grasscutter.getGameServer().getGachaManager().load();
Grasscutter.getGameServer().getDropManager().load(); Grasscutter.getGameServer().getDropManager().load();
Grasscutter.getGameServer().getShopManager().load(); Grasscutter.getGameServer().getShopManager().load();
Grasscutter.getDispatchServer().loadQueries();
CommandHandler.sendMessage(sender, translate("commands.reload.reload_done")); CommandHandler.sendMessage(sender, translate(sender, "commands.reload.reload_done"));
} }
} }
...@@ -11,20 +11,14 @@ import java.util.List; ...@@ -11,20 +11,14 @@ import java.util.List;
import static emu.grasscutter.utils.Language.translate; import static emu.grasscutter.utils.Language.translate;
@Command(label = "resetconst", usage = "resetconst [all]", @Command(label = "resetconst", usage = "resetconst [all]",
description = "Resets the constellation level on your current active character, will need to relog after using the command to see any changes.", aliases = {"resetconstellation"}, permission = "player.resetconstellation", permissionTargeted = "player.resetconstellation.others", description = "commands.resetConst.description")
aliases = {"resetconstellation"}, permission = "player.resetconstellation")
public final class ResetConstCommand implements CommandHandler { public final class ResetConstCommand implements CommandHandler {
@Override @Override
public void execute(Player sender, Player targetPlayer, List<String> args) { public void execute(Player sender, Player targetPlayer, List<String> args) {
if (targetPlayer == null) {
CommandHandler.sendMessage(sender, translate("commands.execution.need_target"));
return;
}
if (args.size() > 0 && args.get(0).equalsIgnoreCase("all")) { if (args.size() > 0 && args.get(0).equalsIgnoreCase("all")) {
targetPlayer.getAvatars().forEach(this::resetConstellation); targetPlayer.getAvatars().forEach(this::resetConstellation);
CommandHandler.sendMessage(sender, translate("commands.resetConst.reset_all")); CommandHandler.sendMessage(sender, translate(sender, "commands.resetConst.reset_all"));
} else { } else {
EntityAvatar entity = targetPlayer.getTeamManager().getCurrentAvatarEntity(); EntityAvatar entity = targetPlayer.getTeamManager().getCurrentAvatarEntity();
if (entity == null) { if (entity == null) {
...@@ -34,7 +28,7 @@ public final class ResetConstCommand implements CommandHandler { ...@@ -34,7 +28,7 @@ public final class ResetConstCommand implements CommandHandler {
Avatar avatar = entity.getAvatar(); Avatar avatar = entity.getAvatar();
this.resetConstellation(avatar); this.resetConstellation(avatar);
CommandHandler.sendMessage(sender, translate("commands.resetConst.success", avatar.getAvatarData().getName())); CommandHandler.sendMessage(sender, translate(sender, "commands.resetConst.success", avatar.getAvatarData().getName()));
} }
} }
...@@ -44,4 +38,4 @@ public final class ResetConstCommand implements CommandHandler { ...@@ -44,4 +38,4 @@ public final class ResetConstCommand implements CommandHandler {
avatar.recalcStats(); avatar.recalcStats();
avatar.save(); avatar.save();
} }
} }
\ No newline at end of file
...@@ -9,18 +9,18 @@ import java.util.List; ...@@ -9,18 +9,18 @@ import java.util.List;
import static emu.grasscutter.utils.Language.translate; import static emu.grasscutter.utils.Language.translate;
@Command(label = "resetshop", usage = "resetshop", @Command(label = "resetshop", usage = "resetshop", permission = "server.resetshop", permissionTargeted = "server.resetshop.others", description = "commands.resetShopLimit.description")
description = "Reset target player's shop refresh time.", permission = "server.resetshop")
public final class ResetShopLimitCommand implements CommandHandler { public final class ResetShopLimitCommand implements CommandHandler {
@Override @Override
public void execute(Player sender, Player targetPlayer, List<String> args) { public void execute(Player sender, Player targetPlayer, List<String> args) {
if (targetPlayer == null) { if (args.isEmpty()) {
CommandHandler.sendMessage(sender, translate("commands.execution.need_target")); CommandHandler.sendMessage(sender, translate(sender, "commands.resetShopLimit.usage"));
return; return;
} }
targetPlayer.getShopLimit().forEach(x -> x.setNextRefreshTime(0)); targetPlayer.getShopLimit().forEach(x -> x.setNextRefreshTime(0));
targetPlayer.save(); targetPlayer.save();
CommandHandler.sendMessage(sender, translate("commands.status.success")); CommandHandler.sendMessage(sender, translate(sender, "commands.resetShopLimit.success"));
} }
} }
...@@ -6,7 +6,9 @@ import emu.grasscutter.game.player.Player; ...@@ -6,7 +6,9 @@ import emu.grasscutter.game.player.Player;
import java.util.List; import java.util.List;
@Command(label = "restart", usage = "restart - Restarts the current session") import static emu.grasscutter.utils.Language.translate;
@Command(label = "restart", usage = "restart", description = "commands.restart.description", targetRequirement = Command.TargetRequirement.NONE)
public final class RestartCommand implements CommandHandler { public final class RestartCommand implements CommandHandler {
@Override @Override
......
...@@ -13,8 +13,7 @@ import java.util.List; ...@@ -13,8 +13,7 @@ import java.util.List;
import static emu.grasscutter.utils.Language.translate; import static emu.grasscutter.utils.Language.translate;
@SuppressWarnings("ConstantConditions") @SuppressWarnings("ConstantConditions")
@Command(label = "sendmail", usage = "sendmail <userId|all|help> [templateId]", @Command(label = "sendmail", usage = "sendmail <userId|all|help> [templateId]", permission = "server.sendmail", description = "commands.sendMail.description", targetRequirement = Command.TargetRequirement.NONE)
description = "Sends mail to the specified user. The usage of this command changes based on it's composition state.", permission = "server.sendmail")
public final class SendMailCommand implements CommandHandler { public final class SendMailCommand implements CommandHandler {
// TODO: You should be able to do /sendmail and then just send subsequent messages until you finish // TODO: You should be able to do /sendmail and then just send subsequent messages until you finish
...@@ -40,24 +39,24 @@ public final class SendMailCommand implements CommandHandler { ...@@ -40,24 +39,24 @@ public final class SendMailCommand implements CommandHandler {
MailBuilder mailBuilder; MailBuilder mailBuilder;
switch (args.get(0).toLowerCase()) { switch (args.get(0).toLowerCase()) {
case "help" -> { case "help" -> {
CommandHandler.sendMessage(sender, this.getClass().getAnnotation(Command.class).description() + "\nUsage: " + this.getClass().getAnnotation(Command.class).usage()); CommandHandler.sendMessage(sender, translate(sender, "commands.sendMail.usage"));
return; return;
} }
case "all" -> mailBuilder = new MailBuilder(true, new Mail()); case "all" -> mailBuilder = new MailBuilder(true, new Mail());
default -> { default -> {
if (DatabaseHelper.getPlayerById(Integer.parseInt(args.get(0))) != null) { if (DatabaseHelper.getPlayerByUid(Integer.parseInt(args.get(0))) != null) {
mailBuilder = new MailBuilder(Integer.parseInt(args.get(0)), new Mail()); mailBuilder = new MailBuilder(Integer.parseInt(args.get(0)), new Mail());
} else { } else {
CommandHandler.sendMessage(sender, translate("commands.sendMail.user_not_exist", args.get(0))); CommandHandler.sendMessage(sender, translate(sender, "commands.sendMail.user_not_exist", args.get(0)));
return; return;
} }
} }
} }
mailBeingConstructed.put(senderId, mailBuilder); mailBeingConstructed.put(senderId, mailBuilder);
CommandHandler.sendMessage(sender, translate("commands.sendMail.start_composition")); CommandHandler.sendMessage(sender, translate(sender, "commands.sendMail.start_composition"));
} }
case 2 -> CommandHandler.sendMessage(sender, translate("commands.sendMail.templates")); case 2 -> CommandHandler.sendMessage(sender, translate(sender, "commands.sendMail.templates"));
default -> CommandHandler.sendMessage(sender, translate("commands.sendMail.invalid_arguments")); default -> CommandHandler.sendMessage(sender, translate(sender, "commands.sendMail.invalid_arguments"));
} }
} else { } else {
MailBuilder mailBuilder = mailBeingConstructed.get(senderId); MailBuilder mailBuilder = mailBeingConstructed.get(senderId);
...@@ -66,28 +65,28 @@ public final class SendMailCommand implements CommandHandler { ...@@ -66,28 +65,28 @@ public final class SendMailCommand implements CommandHandler {
switch (args.get(0).toLowerCase()) { switch (args.get(0).toLowerCase()) {
case "stop" -> { case "stop" -> {
mailBeingConstructed.remove(senderId); mailBeingConstructed.remove(senderId);
CommandHandler.sendMessage(sender, translate("commands.sendMail.sendCancel")); CommandHandler.sendMessage(sender, translate(sender, "commands.sendMail.sendCancel"));
return; return;
} }
case "finish" -> { case "finish" -> {
if (mailBuilder.constructionStage == 3) { if (mailBuilder.constructionStage == 3) {
if (!mailBuilder.sendToAll) { if (!mailBuilder.sendToAll) {
Grasscutter.getGameServer().getPlayerByUid(mailBuilder.recipient, true).sendMail(mailBuilder.mail); Grasscutter.getGameServer().getPlayerByUid(mailBuilder.recipient, true).sendMail(mailBuilder.mail);
CommandHandler.sendMessage(sender, translate("commands.sendMail.send_done", Integer.toString(mailBuilder.recipient))); CommandHandler.sendMessage(sender, translate(sender, "commands.sendMail.send_done", Integer.toString(mailBuilder.recipient)));
} else { } else {
for (Player player : DatabaseHelper.getAllPlayers()) { for (Player player : DatabaseHelper.getAllPlayers()) {
Grasscutter.getGameServer().getPlayerByUid(player.getUid(), true).sendMail(mailBuilder.mail); Grasscutter.getGameServer().getPlayerByUid(player.getUid(), true).sendMail(mailBuilder.mail);
} }
CommandHandler.sendMessage(sender, translate("commands.sendMail.send_all_done")); CommandHandler.sendMessage(sender, translate(sender, "commands.sendMail.send_all_done"));
} }
mailBeingConstructed.remove(senderId); mailBeingConstructed.remove(senderId);
} else { } else {
CommandHandler.sendMessage(sender, translate("commands.sendMail.not_composition_end", getConstructionArgs(mailBuilder.constructionStage))); CommandHandler.sendMessage(sender, translate(sender, "commands.sendMail.not_composition_end", getConstructionArgs(mailBuilder.constructionStage, sender)));
} }
return; return;
} }
case "help" -> { case "help" -> {
CommandHandler.sendMessage(sender, translate("commands.sendMail.please_use", getConstructionArgs(mailBuilder.constructionStage))); CommandHandler.sendMessage(sender, translate(sender, "commands.sendMail.please_use", getConstructionArgs(mailBuilder.constructionStage, sender)));
return; return;
} }
default -> { default -> {
...@@ -95,19 +94,19 @@ public final class SendMailCommand implements CommandHandler { ...@@ -95,19 +94,19 @@ public final class SendMailCommand implements CommandHandler {
case 0 -> { case 0 -> {
String title = String.join(" ", args.subList(0, args.size())); String title = String.join(" ", args.subList(0, args.size()));
mailBuilder.mail.mailContent.title = title; mailBuilder.mail.mailContent.title = title;
CommandHandler.sendMessage(sender, translate("commands.sendMail.set_title", title)); CommandHandler.sendMessage(sender, translate(sender, "commands.sendMail.set_title", title));
mailBuilder.constructionStage++; mailBuilder.constructionStage++;
} }
case 1 -> { case 1 -> {
String contents = String.join(" ", args.subList(0, args.size())); String contents = String.join(" ", args.subList(0, args.size()));
mailBuilder.mail.mailContent.content = contents; mailBuilder.mail.mailContent.content = contents;
CommandHandler.sendMessage(sender, translate("commands.sendMail.set_contents", contents)); CommandHandler.sendMessage(sender, translate(sender, "commands.sendMail.set_contents", contents));
mailBuilder.constructionStage++; mailBuilder.constructionStage++;
} }
case 2 -> { case 2 -> {
String msgSender = String.join(" ", args.subList(0, args.size())); String msgSender = String.join(" ", args.subList(0, args.size()));
mailBuilder.mail.mailContent.sender = msgSender; mailBuilder.mail.mailContent.sender = msgSender;
CommandHandler.sendMessage(sender, translate("commands.sendMail.set_message_sender", msgSender)); CommandHandler.sendMessage(sender, translate(sender, "commands.sendMail.set_message_sender", msgSender));
mailBuilder.constructionStage++; mailBuilder.constructionStage++;
} }
case 3 -> { case 3 -> {
...@@ -120,21 +119,21 @@ public final class SendMailCommand implements CommandHandler { ...@@ -120,21 +119,21 @@ public final class SendMailCommand implements CommandHandler {
try { try {
refinement = Integer.parseInt(args.get(3)); refinement = Integer.parseInt(args.get(3));
} catch (NumberFormatException ignored) { } catch (NumberFormatException ignored) {
CommandHandler.sendMessage(sender, translate("commands.generic.invalid.itemRefinement")); CommandHandler.sendMessage(sender, translate(sender, "commands.generic.invalid.itemRefinement"));
return; return;
} // Fallthrough } // Fallthrough
case 3: // <itemId|itemName> [amount] [level] case 3: // <itemId|itemName> [amount] [level]
try { try {
lvl = Integer.parseInt(args.get(2)); lvl = Integer.parseInt(args.get(2));
} catch (NumberFormatException ignored) { } catch (NumberFormatException ignored) {
CommandHandler.sendMessage(sender, translate("commands.generic.invalid.itemLevel")); CommandHandler.sendMessage(sender, translate(sender, "commands.generic.invalid.itemLevel"));
return; return;
} // Fallthrough } // Fallthrough
case 2: // <itemId|itemName> [amount] case 2: // <itemId|itemName> [amount]
try { try {
amount = Integer.parseInt(args.get(1)); amount = Integer.parseInt(args.get(1));
} catch (NumberFormatException ignored) { } catch (NumberFormatException ignored) {
CommandHandler.sendMessage(sender, translate("commands.generic.invalid.amount")); CommandHandler.sendMessage(sender, translate(sender, "commands.generic.invalid.amount"));
return; return;
} // Fallthrough } // Fallthrough
case 1: // <itemId|itemName> case 1: // <itemId|itemName>
...@@ -142,33 +141,33 @@ public final class SendMailCommand implements CommandHandler { ...@@ -142,33 +141,33 @@ public final class SendMailCommand implements CommandHandler {
item = Integer.parseInt(args.get(0)); item = Integer.parseInt(args.get(0));
} catch (NumberFormatException ignored) { } catch (NumberFormatException ignored) {
// TODO: Parse from item name using GM Handbook. // TODO: Parse from item name using GM Handbook.
CommandHandler.sendMessage(sender, translate("commands.generic.invalid.itemId")); CommandHandler.sendMessage(sender, translate(sender, "commands.generic.invalid.itemId"));
return; return;
} }
break; break;
default: // *No args* default: // *No args*
CommandHandler.sendMessage(sender, translate("commands.give.usage")); CommandHandler.sendMessage(sender, translate(sender, "commands.give.usage"));
return; return;
} }
mailBuilder.mail.itemList.add(new Mail.MailItem(item, amount, lvl)); mailBuilder.mail.itemList.add(new Mail.MailItem(item, amount, lvl));
CommandHandler.sendMessage(sender, translate("commands.sendMail.send", Integer.toString(amount), Integer.toString(item), Integer.toString(lvl))); CommandHandler.sendMessage(sender, translate(sender, "commands.sendMail.send", Integer.toString(amount), Integer.toString(item), Integer.toString(lvl)));
} }
} }
} }
} }
} else { } else {
CommandHandler.sendMessage(sender, translate("commands.sendMail.invalid_arguments_please_use", getConstructionArgs(mailBuilder.constructionStage))); CommandHandler.sendMessage(sender, translate(sender, "commands.sendMail.invalid_arguments_please_use", getConstructionArgs(mailBuilder.constructionStage, sender)));
} }
} }
} }
private String getConstructionArgs(int stage) { private String getConstructionArgs(int stage, Player sender) {
return switch(stage) { return switch(stage) {
case 0 -> translate("commands.sendMail.title"); case 0 -> translate(sender, "commands.sendMail.title");
case 1 -> translate("commands.sendMail.message"); case 1 -> translate(sender, "commands.sendMail.message");
case 2 -> translate("commands.sendMail.sender"); case 2 -> translate(sender, "commands.sendMail.sender");
case 3 -> translate("commands.sendMail.arguments"); case 3 -> translate(sender, "commands.sendMail.arguments");
default -> translate("commands.sendMail.error", Integer.toString(stage)); default -> translate(sender, "commands.sendMail.error", Integer.toString(stage));
}; };
} }
......
...@@ -8,23 +8,19 @@ import java.util.List; ...@@ -8,23 +8,19 @@ import java.util.List;
import static emu.grasscutter.utils.Language.translate; import static emu.grasscutter.utils.Language.translate;
@Command(label = "say", usage = "say <message>", description = "Sends a message to a player as the server", @Command(label = "sendmessage", usage = "sendmessage <message>",
aliases = {"sendservmsg", "sendservermessage", "sendmessage"}, permission = "server.sendmessage") aliases = {"say", "sendservmsg", "sendservermessage"}, permission = "server.sendmessage", permissionTargeted = "server.sendmessage.others", description = "commands.sendMessage.description")
public final class SendMessageCommand implements CommandHandler { public final class SendMessageCommand implements CommandHandler {
@Override @Override
public void execute(Player sender, Player targetPlayer, List<String> args) { public void execute(Player sender, Player targetPlayer, List<String> args) {
if (targetPlayer == null) {
CommandHandler.sendMessage(sender, translate("commands.execution.need_target"));
return;
}
if (args.size() == 0) { if (args.size() == 0) {
CommandHandler.sendMessage(null, translate("commands.sendMessage.usage")); CommandHandler.sendMessage(sender, translate(sender, "commands.sendMessage.usage"));
return; return;
} }
String message = String.join(" ", args); String message = String.join(" ", args);
CommandHandler.sendMessage(targetPlayer, message); CommandHandler.sendMessage(targetPlayer, message);
CommandHandler.sendMessage(sender, translate("commands.sendMessage.success")); CommandHandler.sendMessage(sender, translate(sender, "commands.sendMessage.success"));
} }
} }
\ No newline at end of file
...@@ -12,26 +12,20 @@ import emu.grasscutter.server.packet.send.PacketAvatarFetterDataNotify; ...@@ -12,26 +12,20 @@ import emu.grasscutter.server.packet.send.PacketAvatarFetterDataNotify;
import static emu.grasscutter.utils.Language.translate; import static emu.grasscutter.utils.Language.translate;
@Command(label = "setfetterlevel", usage = "setfetterlevel <level>", @Command(label = "setfetterlevel", usage = "setfetterlevel <level>",
description = "Sets your fetter level for your current active character", aliases = {"setfetterlvl", "setfriendship"}, permission = "player.setfetterlevel", permissionTargeted = "player.setfetterlevel.others", description = "commands.setFetterLevel.description")
aliases = {"setfetterlvl", "setfriendship"}, permission = "player.setfetterlevel")
public final class SetFetterLevelCommand implements CommandHandler { public final class SetFetterLevelCommand implements CommandHandler {
@Override @Override
public void execute(Player sender, Player targetPlayer, List<String> args) { public void execute(Player sender, Player targetPlayer, List<String> args) {
if (targetPlayer == null) {
CommandHandler.sendMessage(sender, translate("commands.execution.need_target"));
return;
}
if (args.size() != 1) { if (args.size() != 1) {
CommandHandler.sendMessage(sender, translate("commands.setFetterLevel.usage")); CommandHandler.sendMessage(sender, translate(sender, "commands.setFetterLevel.usage"));
return; return;
} }
try { try {
int fetterLevel = Integer.parseInt(args.get(0)); int fetterLevel = Integer.parseInt(args.get(0));
if (fetterLevel < 0 || fetterLevel > 10) { if (fetterLevel < 0 || fetterLevel > 10) {
CommandHandler.sendMessage(sender, translate("commands.setFetterLevel.range_error")); CommandHandler.sendMessage(sender, translate(sender, "commands.setFetterLevel.range_error"));
return; return;
} }
Avatar avatar = targetPlayer.getTeamManager().getCurrentAvatarEntity().getAvatar(); Avatar avatar = targetPlayer.getTeamManager().getCurrentAvatarEntity().getAvatar();
...@@ -43,9 +37,9 @@ public final class SetFetterLevelCommand implements CommandHandler { ...@@ -43,9 +37,9 @@ public final class SetFetterLevelCommand implements CommandHandler {
avatar.save(); avatar.save();
targetPlayer.sendPacket(new PacketAvatarFetterDataNotify(avatar)); targetPlayer.sendPacket(new PacketAvatarFetterDataNotify(avatar));
CommandHandler.sendMessage(sender, translate("commands.setFetterLevel.success", fetterLevel)); CommandHandler.sendMessage(sender, translate(sender, "commands.setFetterLevel.success", fetterLevel));
} catch (NumberFormatException ignored) { } catch (NumberFormatException ignored) {
CommandHandler.sendMessage(sender, translate("commands.setFetterLevel.level_error")); CommandHandler.sendMessage(sender, translate(sender, "commands.setFetterLevel.level_error"));
} }
} }
......
...@@ -15,8 +15,7 @@ import emu.grasscutter.utils.Language; ...@@ -15,8 +15,7 @@ import emu.grasscutter.utils.Language;
import static emu.grasscutter.utils.Language.translate; import static emu.grasscutter.utils.Language.translate;
@Command(label = "setstats", usage = "setstats|stats <stat> <value>", @Command(label = "setstats", usage = "setstats|stats <stat> <value>", aliases = {"stats"}, permission = "player.setstats", permissionTargeted = "player.setstats.others", description = "commands.setStats.description")
description = "Set fight property for your current active character", aliases = {"stats"}, permission = "player.setstats")
public final class SetStatsCommand implements CommandHandler { public final class SetStatsCommand implements CommandHandler {
static class Stat { static class Stat {
String name; String name;
...@@ -176,16 +175,11 @@ public final class SetStatsCommand implements CommandHandler { ...@@ -176,16 +175,11 @@ public final class SetStatsCommand implements CommandHandler {
@Override @Override
public void execute(Player sender, Player targetPlayer, List<String> args) { public void execute(Player sender, Player targetPlayer, List<String> args) {
String syntax = sender == null ? translate("commands.setStats.usage_console") : translate("commands.setStats.ingame"); String syntax = sender == null ? translate(sender, "commands.setStats.usage_console") : translate(sender, "commands.setStats.usage_ingame");
String usage = syntax + translate("commands.setStats.help_message"); String usage = syntax + translate(sender, "commands.setStats.help_message");
String statStr; String statStr;
String valueStr; String valueStr;
if (targetPlayer == null) {
CommandHandler.sendMessage(sender, translate("commands.execution.need_target"));
return;
}
if (args.size() == 2) { if (args.size() == 2) {
statStr = args.get(0).toLowerCase(); statStr = args.get(0).toLowerCase();
valueStr = args.get(1); valueStr = args.get(1);
...@@ -204,7 +198,7 @@ public final class SetStatsCommand implements CommandHandler { ...@@ -204,7 +198,7 @@ public final class SetStatsCommand implements CommandHandler {
value = Float.parseFloat(valueStr); value = Float.parseFloat(valueStr);
} }
} catch (NumberFormatException ignored) { } catch (NumberFormatException ignored) {
CommandHandler.sendMessage(sender, translate("commands.setStats.value_error")); CommandHandler.sendMessage(sender, translate(sender, "commands.setStats.value_error"));
return; return;
} }
...@@ -218,10 +212,10 @@ public final class SetStatsCommand implements CommandHandler { ...@@ -218,10 +212,10 @@ public final class SetStatsCommand implements CommandHandler {
valueStr = String.format("%.0f", value); valueStr = String.format("%.0f", value);
} }
if (targetPlayer == sender) { if (targetPlayer == sender) {
CommandHandler.sendMessage(sender, translate("commands.setStats.set_self", stat.name, valueStr)); CommandHandler.sendMessage(sender, translate(sender, "commands.setStats.set_self", stat.name, valueStr));
} else { } else {
String uidStr = targetPlayer.getAccount().getId(); String uidStr = targetPlayer.getAccount().getId();
CommandHandler.sendMessage(sender, translate("commands.setStats.set_self", stat.name, uidStr, valueStr)); CommandHandler.sendMessage(sender, translate(sender, "commands.setStats.set_for_uid", stat.name, uidStr, valueStr));
} }
} else { } else {
CommandHandler.sendMessage(sender, usage); CommandHandler.sendMessage(sender, usage);
......
...@@ -10,26 +10,20 @@ import java.util.List; ...@@ -10,26 +10,20 @@ import java.util.List;
import static emu.grasscutter.utils.Language.translate; import static emu.grasscutter.utils.Language.translate;
@Command(label = "setworldlevel", usage = "setworldlevel <level>", @Command(label = "setworldlevel", usage = "setworldlevel <level>",
description = "Sets your world level (Relog to see proper effects)", aliases = {"setworldlvl"}, permission = "player.setworldlevel", permissionTargeted = "player.setworldlevel.others", description = "commands.setWorldLevel.description")
aliases = {"setworldlvl"}, permission = "player.setworldlevel")
public final class SetWorldLevelCommand implements CommandHandler { public final class SetWorldLevelCommand implements CommandHandler {
@Override @Override
public void execute(Player sender, Player targetPlayer, List<String> args) { public void execute(Player sender, Player targetPlayer, List<String> args) {
if (targetPlayer == null) {
CommandHandler.sendMessage(sender, translate("commands.execution.need_target"));
return;
}
if (args.size() < 1) { if (args.size() < 1) {
CommandHandler.sendMessage(sender, translate("commands.setWorldLevel.usage")); CommandHandler.sendMessage(sender, translate(sender, "commands.setWorldLevel.usage"));
return; return;
} }
try { try {
int level = Integer.parseInt(args.get(0)); int level = Integer.parseInt(args.get(0));
if (level > 8 || level < 0) { if (level > 8 || level < 0) {
CommandHandler.sendMessage(sender, translate("commands.setWorldLevel.value_error")); CommandHandler.sendMessage(sender, translate(sender, "commands.setWorldLevel.value_error"));
return; return;
} }
...@@ -37,9 +31,9 @@ public final class SetWorldLevelCommand implements CommandHandler { ...@@ -37,9 +31,9 @@ public final class SetWorldLevelCommand implements CommandHandler {
targetPlayer.getWorld().setWorldLevel(level); targetPlayer.getWorld().setWorldLevel(level);
targetPlayer.setWorldLevel(level); targetPlayer.setWorldLevel(level);
CommandHandler.sendMessage(sender, translate("commands.setWorldLevel.success", Integer.toString(level))); CommandHandler.sendMessage(sender, translate(sender, "commands.setWorldLevel.success", Integer.toString(level)));
} catch (NumberFormatException ignored) { } catch (NumberFormatException ignored) {
CommandHandler.sendMessage(null, translate("commands.setWorldLevel.invalid_world_level")); CommandHandler.sendMessage(null, translate(sender, "commands.setWorldLevel.invalid_world_level"));
} }
} }
} }
...@@ -4,10 +4,10 @@ import emu.grasscutter.Grasscutter; ...@@ -4,10 +4,10 @@ import emu.grasscutter.Grasscutter;
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.def.AvatarData; import emu.grasscutter.data.excels.AvatarData;
import emu.grasscutter.data.def.GadgetData; import emu.grasscutter.data.excels.GadgetData;
import emu.grasscutter.data.def.ItemData; import emu.grasscutter.data.excels.ItemData;
import emu.grasscutter.data.def.MonsterData; import emu.grasscutter.data.excels.MonsterData;
import emu.grasscutter.game.avatar.Avatar; import emu.grasscutter.game.avatar.Avatar;
import emu.grasscutter.game.entity.*; import emu.grasscutter.game.entity.*;
import emu.grasscutter.game.player.Player; import emu.grasscutter.game.player.Player;
...@@ -20,59 +20,75 @@ import javax.swing.text.html.parser.Entity; ...@@ -20,59 +20,75 @@ import javax.swing.text.html.parser.Entity;
import java.util.List; import java.util.List;
import java.util.Random; import java.util.Random;
import static emu.grasscutter.Configuration.*;
import static emu.grasscutter.utils.Language.translate; import static emu.grasscutter.utils.Language.translate;
@Command(label = "spawn", usage = "spawn <entityId> [amount] [level(monster only)]", @Command(label = "spawn", usage = "spawn <entityId> [amount] [level(monster only)] [<x> <y> <z>(monster only, optional)]", permission = "server.spawn", permissionTargeted = "server.spawn.others", description = "commands.spawn.description")
description = "Spawns an entity near you", permission = "server.spawn")
public final class SpawnCommand implements CommandHandler { public final class SpawnCommand implements CommandHandler {
@Override @Override
public void execute(Player sender, Player targetPlayer, List<String> args) { public void execute(Player sender, Player targetPlayer, List<String> args) {
if (targetPlayer == null) {
CommandHandler.sendMessage(sender, translate("commands.execution.need_target"));
return;
}
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;
switch (args.size()) { switch (args.size()) {
case 6:
try {
x = Float.parseFloat(args.get(3));
y = Float.parseFloat(args.get(4));
z = Float.parseFloat(args.get(5));
} catch (NumberFormatException ignored) {
CommandHandler.sendMessage(sender, translate(sender, "commands.execution.argument_error"));
} // Fallthrough
case 3: case 3:
try { try {
level = Integer.parseInt(args.get(2)); level = Integer.parseInt(args.get(2));
} catch (NumberFormatException ignored) { } catch (NumberFormatException ignored) {
CommandHandler.sendMessage(sender, translate("commands.execution.argument_error")); CommandHandler.sendMessage(sender, translate(sender, "commands.execution.argument_error"));
} // Fallthrough } // Fallthrough
case 2: case 2:
try { try {
amount = Integer.parseInt(args.get(1)); amount = Integer.parseInt(args.get(1));
} catch (NumberFormatException ignored) { } catch (NumberFormatException ignored) {
CommandHandler.sendMessage(sender, translate("commands.generic.error.amount")); CommandHandler.sendMessage(sender, translate(sender, "commands.generic.invalid.amount"));
} // Fallthrough } // Fallthrough
case 1: case 1:
try { try {
id = Integer.parseInt(args.get(0)); id = Integer.parseInt(args.get(0));
} catch (NumberFormatException ignored) { } catch (NumberFormatException ignored) {
CommandHandler.sendMessage(sender, translate("commands.generic.error.entityId")); CommandHandler.sendMessage(sender, translate(sender, "commands.generic.invalid.entityId"));
} }
break; break;
default: default:
CommandHandler.sendMessage(sender, translate("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);
if (monsterData == null && gadgetData == null && itemData == null) { if (monsterData == null && gadgetData == null && itemData == null) {
CommandHandler.sendMessage(sender, translate("commands.generic.error.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) {
amount = Math.max(Math.min(GAME_OPTIONS.sceneEntityLimit - scene.getEntities().size(), amount), 0);
CommandHandler.sendMessage(sender, translate(sender, "commands.spawn.limit_reached", amount));
if (amount <= 0) {
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.getPos(), maxRadius).addY(3); Position pos = GetRandomPositionInCircle(targetPlayer.getPos(), maxRadius).addY(3);
if(x != 0 && y != 0 && z != 0) {
pos = GetRandomPositionInCircle(new Position(x, y, z), maxRadius).addY(3);
}
GameEntity entity = null; GameEntity entity = null;
if (itemData != null) { if (itemData != null) {
entity = new EntityItem(scene, null, itemData, pos, 1, true); entity = new EntityItem(scene, null, itemData, pos, 1, true);
...@@ -101,7 +117,7 @@ public final class SpawnCommand implements CommandHandler { ...@@ -101,7 +117,7 @@ public final class SpawnCommand implements CommandHandler {
scene.addEntity(entity); scene.addEntity(entity);
} }
CommandHandler.sendMessage(sender, translate("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){
......
...@@ -9,15 +9,14 @@ import java.util.List; ...@@ -9,15 +9,14 @@ import java.util.List;
import static emu.grasscutter.utils.Language.translate; import static emu.grasscutter.utils.Language.translate;
@Command(label = "stop", usage = "stop", @Command(label = "stop", usage = "stop", permission = "server.stop", description = "commands.stop.description", targetRequirement = Command.TargetRequirement.NONE)
description = "Stops the server", permission = "server.stop")
public final class StopCommand implements CommandHandler { public final class StopCommand 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(null, translate("commands.stop.success")); CommandHandler.sendMessage(null, translate("commands.stop.success"));
for (Player p : Grasscutter.getGameServer().getPlayers().values()) { for (Player p : Grasscutter.getGameServer().getPlayers().values()) {
CommandHandler.sendMessage(p, translate("commands.stop.success")); CommandHandler.sendMessage(p, translate(p, "commands.stop.success"));
} }
System.exit(1000); System.exit(1000);
......
...@@ -3,7 +3,7 @@ package emu.grasscutter.command.commands; ...@@ -3,7 +3,7 @@ package emu.grasscutter.command.commands;
import emu.grasscutter.Grasscutter; import emu.grasscutter.Grasscutter;
import emu.grasscutter.command.Command; import emu.grasscutter.command.Command;
import emu.grasscutter.command.CommandHandler; import emu.grasscutter.command.CommandHandler;
import emu.grasscutter.data.def.AvatarSkillDepotData; import emu.grasscutter.data.excels.AvatarSkillDepotData;
import emu.grasscutter.game.avatar.Avatar; import emu.grasscutter.game.avatar.Avatar;
import emu.grasscutter.game.entity.EntityAvatar; import emu.grasscutter.game.entity.EntityAvatar;
import emu.grasscutter.game.player.Player; import emu.grasscutter.game.player.Player;
...@@ -14,18 +14,17 @@ import java.util.List; ...@@ -14,18 +14,17 @@ import java.util.List;
import static emu.grasscutter.utils.Language.translate; import static emu.grasscutter.utils.Language.translate;
@Command(label = "talent", usage = "talent <talentID> <value>", @Command(label = "talent", usage = "talent <talentId> <value>", permission = "player.settalent", permissionTargeted = "player.settalent.others", description = "commands.talent.description")
description = "Set talent level for your current active character", permission = "player.settalent")
public final class TalentCommand implements CommandHandler { public final class TalentCommand implements CommandHandler {
private void setTalentLevel(Player sender, Player player, Avatar avatar, int talentId, int talentLevel) { private void setTalentLevel(Player sender, Player player, Avatar avatar, int talentId, int talentLevel) {
int oldLevel = avatar.getSkillLevelMap().get(talentId); int oldLevel = avatar.getSkillLevelMap().get(talentId);
if (talentLevel < 0 || talentLevel > 15) { if (talentLevel < 0 || talentLevel > 15) {
CommandHandler.sendMessage(sender, translate("commands.talent.lower_16")); CommandHandler.sendMessage(sender, translate(sender, "commands.talent.lower_16"));
return; return;
} }
// Upgrade skill // Upgrade skill
avatar.getSkillLevelMap().put(talentLevel, talentLevel); avatar.getSkillLevelMap().put(talentId, talentLevel);
avatar.save(); avatar.save();
// Packet // Packet
...@@ -41,20 +40,15 @@ public final class TalentCommand implements CommandHandler { ...@@ -41,20 +40,15 @@ public final class TalentCommand implements CommandHandler {
} else if (talentId == depot.getEnergySkill()) { } else if (talentId == depot.getEnergySkill()) {
successMessage = "commands.talent.set_q"; successMessage = "commands.talent.set_q";
} }
CommandHandler.sendMessage(sender, translate(successMessage, talentLevel)); CommandHandler.sendMessage(sender, translate(sender, successMessage, talentLevel));
} }
@Override @Override
public void execute(Player sender, Player targetPlayer, List<String> args) { public void execute(Player sender, Player targetPlayer, List<String> args) {
if (targetPlayer == null) {
CommandHandler.sendMessage(sender, translate("commands.execution.need_target"));
return;
}
if (args.size() < 1){ if (args.size() < 1){
CommandHandler.sendMessage(sender, translate("commands.talent.usage_1")); CommandHandler.sendMessage(sender, translate(sender, "commands.talent.usage_1"));
CommandHandler.sendMessage(sender, translate("commands.talent.usage_2")); CommandHandler.sendMessage(sender, translate(sender, "commands.talent.usage_2"));
CommandHandler.sendMessage(sender, translate("commands.talent.usage_3")); CommandHandler.sendMessage(sender, translate(sender, "commands.talent.usage_3"));
return; return;
} }
...@@ -63,15 +57,15 @@ public final class TalentCommand implements CommandHandler { ...@@ -63,15 +57,15 @@ public final class TalentCommand implements CommandHandler {
String cmdSwitch = args.get(0); String cmdSwitch = args.get(0);
switch (cmdSwitch) { switch (cmdSwitch) {
default -> { default -> {
CommandHandler.sendMessage(sender, translate("commands.talent.usage_1")); CommandHandler.sendMessage(sender, translate(sender, "commands.talent.usage_1"));
CommandHandler.sendMessage(sender, translate("commands.talent.usage_2")); CommandHandler.sendMessage(sender, translate(sender, "commands.talent.usage_2"));
CommandHandler.sendMessage(sender, translate("commands.talent.usage_3")); CommandHandler.sendMessage(sender, translate(sender, "commands.talent.usage_3"));
return; return;
} }
case "set" -> { case "set" -> {
if (args.size() < 3) { if (args.size() < 3) {
CommandHandler.sendMessage(sender, translate("commands.talent.usage_1")); CommandHandler.sendMessage(sender, translate(sender, "commands.talent.usage_1"));
CommandHandler.sendMessage(sender, translate("commands.talent.usage_3")); CommandHandler.sendMessage(sender, translate(sender, "commands.talent.usage_3"));
return; return;
} }
try { try {
...@@ -79,13 +73,13 @@ public final class TalentCommand implements CommandHandler { ...@@ -79,13 +73,13 @@ public final class TalentCommand implements CommandHandler {
int newLevel = Integer.parseInt(args.get(2)); int newLevel = Integer.parseInt(args.get(2));
setTalentLevel(sender, targetPlayer, avatar, skillId, newLevel); setTalentLevel(sender, targetPlayer, avatar, skillId, newLevel);
} catch (NumberFormatException ignored) { } catch (NumberFormatException ignored) {
CommandHandler.sendMessage(sender, translate("commands.talent.invalid_skill_id")); CommandHandler.sendMessage(sender, translate(sender, "commands.talent.invalid_skill_id"));
return; return;
} }
} }
case "n", "e", "q" -> { case "n", "e", "q" -> {
if (args.size() < 2) { if (args.size() < 2) {
CommandHandler.sendMessage(sender, translate("commands.talent.usage_2")); CommandHandler.sendMessage(sender, translate(sender, "commands.talent.usage_2"));
return; return;
} }
AvatarSkillDepotData SkillDepot = avatar.getData().getSkillDepot(); AvatarSkillDepotData SkillDepot = avatar.getData().getSkillDepot();
...@@ -98,7 +92,7 @@ public final class TalentCommand implements CommandHandler { ...@@ -98,7 +92,7 @@ public final class TalentCommand implements CommandHandler {
int newLevel = Integer.parseInt(args.get(1)); int newLevel = Integer.parseInt(args.get(1));
setTalentLevel(sender, targetPlayer, avatar, skillId, newLevel); setTalentLevel(sender, targetPlayer, avatar, skillId, newLevel);
} catch (NumberFormatException ignored) { } catch (NumberFormatException ignored) {
CommandHandler.sendMessage(sender, translate("commands.talent.invalid_level")); CommandHandler.sendMessage(sender, translate(sender, "commands.talent.invalid_level"));
return; return;
} }
} }
...@@ -106,9 +100,9 @@ public final class TalentCommand implements CommandHandler { ...@@ -106,9 +100,9 @@ public final class TalentCommand implements CommandHandler {
int skillIdNorAtk = avatar.getData().getSkillDepot().getSkills().get(0); int skillIdNorAtk = avatar.getData().getSkillDepot().getSkills().get(0);
int skillIdE = avatar.getData().getSkillDepot().getSkills().get(1); int skillIdE = avatar.getData().getSkillDepot().getSkills().get(1);
int skillIdQ = avatar.getData().getSkillDepot().getEnergySkill(); int skillIdQ = avatar.getData().getSkillDepot().getEnergySkill();
CommandHandler.sendMessage(sender, translate("commands.talent.normal_attack_id", Integer.toString(skillIdNorAtk))); CommandHandler.sendMessage(sender, translate(sender, "commands.talent.normal_attack_id", Integer.toString(skillIdNorAtk)));
CommandHandler.sendMessage(sender, translate("commands.talent.e_skill_id", Integer.toString(skillIdE))); CommandHandler.sendMessage(sender, translate(sender, "commands.talent.e_skill_id", Integer.toString(skillIdE)));
CommandHandler.sendMessage(sender, translate("commands.talent.q_skill_id", Integer.toString(skillIdQ))); CommandHandler.sendMessage(sender, translate(sender, "commands.talent.q_skill_id", Integer.toString(skillIdQ)));
} }
} }
} }
......
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