mirror of
https://github.com/Grasscutters/Grasscutter.git
synced 2025-01-25 17:22:55 +08:00
[WIP] Command Targeting overhaul
This commit is contained in:
parent
4e0ebe56a6
commit
82ec63c4e4
@ -221,7 +221,7 @@ public final class Grasscutter {
|
||||
|
||||
isLastInterrupted = false;
|
||||
try {
|
||||
CommandMap.getInstance().invoke(null, input);
|
||||
CommandMap.getInstance().invoke(null, null, input);
|
||||
} catch (Exception e) {
|
||||
Grasscutter.getLogger().error(language.Command_error, e);
|
||||
}
|
||||
|
@ -14,6 +14,8 @@ public @interface Command {
|
||||
String[] aliases() default {};
|
||||
|
||||
String permission() default "";
|
||||
|
||||
String permissionTargeted() default "";
|
||||
|
||||
boolean threading() default false;
|
||||
}
|
||||
|
@ -25,6 +25,6 @@ public interface CommandHandler {
|
||||
* @param sender The player/console that invoked the command.
|
||||
* @param args The arguments to the command.
|
||||
*/
|
||||
default void execute(Player sender, List<String> args) {
|
||||
default void execute(Player sender, Player targetPlayer, List<String> args) {
|
||||
}
|
||||
}
|
||||
|
@ -12,6 +12,8 @@ import java.util.*;
|
||||
public final class CommandMap {
|
||||
private final Map<String, CommandHandler> commands = new HashMap<>();
|
||||
private final Map<String, Command> annotations = new HashMap<>();
|
||||
private final Map<String, Player> targetPlayers = new HashMap<>();
|
||||
private static final String consoleId = "console";
|
||||
public CommandMap() {
|
||||
this(false);
|
||||
}
|
||||
@ -104,7 +106,7 @@ public final class CommandMap {
|
||||
* @param player The player invoking the command or null for the server console.
|
||||
* @param rawMessage The messaged used to invoke the command.
|
||||
*/
|
||||
public void invoke(Player player, String rawMessage) {
|
||||
public void invoke(Player player, Player targetPlayer, String rawMessage) {
|
||||
rawMessage = rawMessage.trim();
|
||||
if (rawMessage.length() == 0) {
|
||||
CommandHandler.sendMessage(player, Grasscutter.getLanguage().No_command_specified);
|
||||
@ -119,6 +121,29 @@ public final class CommandMap {
|
||||
String[] split = rawMessage.split(" ");
|
||||
List<String> args = new LinkedList<>(Arrays.asList(split));
|
||||
String label = args.remove(0);
|
||||
// Check for special case
|
||||
String playerId = (player == null) ? consoleId : player.getAccount().getId();
|
||||
if (label == "target") { // Sets or clears default targetPlayer
|
||||
if (args.size() < 1) {
|
||||
targetPlayers.remove(playerId);
|
||||
CommandHandler.sendMessage(player, Grasscutter.getLanguage().Target_cleared);
|
||||
} else {
|
||||
try {
|
||||
String sUid = args.get(0);
|
||||
int uid = Integer.parseInt(sUid);
|
||||
targetPlayer = Grasscutter.getGameServer().getPlayerByUid(uid);
|
||||
if (targetPlayer == null) {
|
||||
CommandHandler.sendMessage(player, Grasscutter.getLanguage().Player_not_found_or_offline);
|
||||
} else {
|
||||
targetPlayers.put(playerId, targetPlayer);
|
||||
CommandHandler.sendMessage(player, Grasscutter.getLanguage().Target_set.replace("{uid}", sUid));
|
||||
}
|
||||
} catch (NumberFormatException e) {
|
||||
CommandHandler.sendMessage(player, Grasscutter.getLanguage().Invalid_UID);
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
// Get command handler.
|
||||
CommandHandler handler = this.commands.get(label);
|
||||
if (handler == null) {
|
||||
@ -126,10 +151,43 @@ public final class CommandMap {
|
||||
return;
|
||||
}
|
||||
|
||||
// If any @UID argument is present, override targetPlayer with it
|
||||
for (int i = 0; i < args.size(); i++) {
|
||||
String arg = args.get(i);
|
||||
if (!arg.startsWith("@")) {
|
||||
continue;
|
||||
} else {
|
||||
arg = args.remove(i).substring(1);
|
||||
try {
|
||||
int uid = Integer.parseInt(arg);
|
||||
targetPlayer = Grasscutter.getGameServer().getPlayerByUid(uid);
|
||||
if (targetPlayer == null) {
|
||||
CommandHandler.sendMessage(player, Grasscutter.getLanguage().Player_not_found_or_offline);
|
||||
return;
|
||||
}
|
||||
break;
|
||||
} catch (NumberFormatException e) {
|
||||
CommandHandler.sendMessage(player, Grasscutter.getLanguage().Invalid_UID);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
// If there's still no targetPlayer at this point, use previously-set target
|
||||
if (targetPlayer == null) {
|
||||
targetPlayer = targetPlayers.getOrDefault(playerId, null);
|
||||
}
|
||||
|
||||
// Check for permission.
|
||||
if (player != null) {
|
||||
String permissionNode = this.annotations.get(label).permission();
|
||||
String permissionNodeTargeted = this.annotations.get(label).permissionTargeted();
|
||||
Account account = player.getAccount();
|
||||
if (player != targetPlayer) { // Additional permission required for targeting another player
|
||||
if (!permissionNodeTargeted.isEmpty() && !account.hasPermission(permissionNodeTargeted)) {
|
||||
CommandHandler.sendMessage(player, Grasscutter.getLanguage().You_not_permission_run_command);
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (!permissionNode.isEmpty() && !account.hasPermission(permissionNode)) {
|
||||
CommandHandler.sendMessage(player, Grasscutter.getLanguage().You_not_permission_run_command);
|
||||
return;
|
||||
@ -138,7 +196,8 @@ public final class CommandMap {
|
||||
|
||||
// Invoke execute method for handler.
|
||||
boolean threading = this.annotations.get(label).threading();
|
||||
Runnable runnable = () -> handler.execute(player, args);
|
||||
final Player targetPlayerF = targetPlayer; // Is there a better way to do this?
|
||||
Runnable runnable = () -> handler.execute(player, targetPlayerF, args);
|
||||
if(threading) {
|
||||
Thread command = new Thread(runnable);
|
||||
command.start();
|
||||
|
@ -12,7 +12,7 @@ import java.util.List;
|
||||
public final class AccountCommand implements CommandHandler {
|
||||
|
||||
@Override
|
||||
public void execute(Player sender, List<String> args) {
|
||||
public void execute(Player sender, Player targetPlayer, List<String> args) {
|
||||
if (sender != null) {
|
||||
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().This_command_can_only_run_from_console);
|
||||
return;
|
||||
|
@ -12,7 +12,7 @@ import java.util.List;
|
||||
public final class BroadcastCommand implements CommandHandler {
|
||||
|
||||
@Override
|
||||
public void execute(Player sender, List<String> args) {
|
||||
public void execute(Player sender, Player targetPlayer, List<String> args) {
|
||||
if (args.size() < 1) {
|
||||
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Broadcast_command_usage);
|
||||
return;
|
||||
|
@ -12,7 +12,7 @@ import java.util.List;
|
||||
description = "Changes your scene", aliases = {"scene"}, permission = "player.changescene")
|
||||
public final class ChangeSceneCommand implements CommandHandler {
|
||||
@Override
|
||||
public void execute(Player sender, List<String> args) {
|
||||
public void execute(Player sender, Player targetPlayer, List<String> args) {
|
||||
if (sender == null) {
|
||||
CommandHandler.sendMessage(null, Grasscutter.getLanguage().Run_this_command_in_game);
|
||||
return;
|
||||
|
@ -16,7 +16,7 @@ import java.util.List;
|
||||
public final class ClearCommand implements CommandHandler {
|
||||
|
||||
@Override
|
||||
public void execute(Player sender, List<String> args) {
|
||||
public void execute(Player sender, Player targetPlayer, List<String> args) {
|
||||
int target;
|
||||
String cmdSwitch = "";
|
||||
if (sender == null) {
|
||||
@ -32,7 +32,6 @@ public final class ClearCommand implements CommandHandler {
|
||||
cmdSwitch = args.get(1);
|
||||
target = Integer.parseInt(args.get(0));
|
||||
}
|
||||
Player targetPlayer = Grasscutter.getGameServer().getPlayerByUid(target);
|
||||
switch (cmdSwitch) {
|
||||
case "wp" -> {
|
||||
playerInventory.getItems().values().stream()
|
||||
@ -99,7 +98,6 @@ public final class ClearCommand implements CommandHandler {
|
||||
return;
|
||||
}
|
||||
|
||||
Player targetPlayer = Grasscutter.getGameServer().getPlayerByUid(target);
|
||||
if (targetPlayer == null) {
|
||||
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Player_not_found);
|
||||
return;
|
||||
|
@ -11,7 +11,7 @@ import java.util.List;
|
||||
description = "Forces someone to join the world of others", permission = "server.coop")
|
||||
public final class CoopCommand implements CommandHandler {
|
||||
@Override
|
||||
public void execute(Player sender, List<String> args) {
|
||||
public void execute(Player sender, Player targetPlayer, List<String> args) {
|
||||
if (args.size() < 2) {
|
||||
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Coop_usage);
|
||||
return;
|
||||
|
@ -16,7 +16,7 @@ import java.util.List;
|
||||
public final class DropCommand implements CommandHandler {
|
||||
|
||||
@Override
|
||||
public void execute(Player sender, List<String> args) {
|
||||
public void execute(Player sender, Player targetPlayer, List<String> args) {
|
||||
if (sender == null) {
|
||||
CommandHandler.sendMessage(null, Grasscutter.getLanguage().Run_this_command_in_game);
|
||||
return;
|
||||
|
@ -11,7 +11,7 @@ import java.util.List;
|
||||
description = "Enter a dungeon", aliases = {"dungeon"}, permission = "player.enterdungeon")
|
||||
public final class EnterDungeonCommand implements CommandHandler {
|
||||
@Override
|
||||
public void execute(Player sender, List<String> args) {
|
||||
public void execute(Player sender, Player targetPlayer, List<String> args) {
|
||||
if (sender == null) {
|
||||
CommandHandler.sendMessage(null, Grasscutter.getLanguage().Run_this_command_in_game);
|
||||
return;
|
||||
|
@ -18,7 +18,7 @@ import java.util.*;
|
||||
public final class GiveAllCommand implements CommandHandler {
|
||||
|
||||
@Override
|
||||
public void execute(Player sender, List<String> args) {
|
||||
public void execute(Player sender, Player targetPlayer, List<String> args) {
|
||||
int target, amount = 99999;
|
||||
|
||||
switch (args.size()) {
|
||||
@ -63,7 +63,6 @@ public final class GiveAllCommand implements CommandHandler {
|
||||
return;
|
||||
}
|
||||
|
||||
Player targetPlayer = Grasscutter.getGameServer().getPlayerByUid(target);
|
||||
if (targetPlayer == null) {
|
||||
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Player_not_found);
|
||||
return;
|
||||
|
@ -17,7 +17,7 @@ import java.util.List;
|
||||
@Command(label = "giveart", usage = "giveart [player] <artifactId> <mainPropId> [<appendPropId>[,<times>]]... [level]", description = "Gives the player a specified artifact", aliases = {"gart"}, permission = "player.giveart")
|
||||
public final class GiveArtifactCommand implements CommandHandler {
|
||||
@Override
|
||||
public void execute(Player sender, List<String> args) {
|
||||
public void execute(Player sender, Player targetPlayer, List<String> args) {
|
||||
int size = args.size(), target, itemId, mainPropId, level = 1;
|
||||
ArrayList<Integer> appendPropIdList = new ArrayList<>();
|
||||
String msg = Grasscutter.getLanguage().GiveArtifact_usage;
|
||||
@ -71,7 +71,6 @@ public final class GiveArtifactCommand implements CommandHandler {
|
||||
return;
|
||||
}
|
||||
|
||||
Player targetPlayer = Grasscutter.getGameServer().getPlayerByUid(target);
|
||||
if (targetPlayer == null) {
|
||||
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Player_not_found);
|
||||
return;
|
||||
|
@ -15,7 +15,7 @@ import java.util.List;
|
||||
public final class GiveCharCommand implements CommandHandler {
|
||||
|
||||
@Override
|
||||
public void execute(Player sender, List<String> args) {
|
||||
public void execute(Player sender, Player targetPlayer, List<String> args) {
|
||||
int target, avatarId, level = 1, ascension;
|
||||
|
||||
if (sender == null && args.size() < 2) {
|
||||
@ -61,7 +61,6 @@ public final class GiveCharCommand implements CommandHandler {
|
||||
break;
|
||||
}
|
||||
|
||||
Player targetPlayer = Grasscutter.getGameServer().getPlayerByUid(target);
|
||||
if (targetPlayer == null) {
|
||||
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Player_not_found);
|
||||
return;
|
||||
|
@ -18,7 +18,7 @@ import java.util.List;
|
||||
public final class GiveCommand implements CommandHandler {
|
||||
|
||||
@Override
|
||||
public void execute(Player sender, List<String> args) {
|
||||
public void execute(Player sender, Player targetPlayer, List<String> args) {
|
||||
int target, item, lvl, amount = 1, refinement = 0;
|
||||
if (sender == null && args.size() < 2) {
|
||||
CommandHandler.sendMessage(null, Grasscutter.getLanguage().Give_usage);
|
||||
@ -121,7 +121,6 @@ public final class GiveCommand implements CommandHandler {
|
||||
break;
|
||||
}
|
||||
|
||||
Player targetPlayer = Grasscutter.getGameServer().getPlayerByUid(target);
|
||||
|
||||
if (targetPlayer == null) {
|
||||
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Player_not_found);
|
||||
|
@ -12,7 +12,7 @@ import java.util.List;
|
||||
public final class GodModeCommand implements CommandHandler {
|
||||
|
||||
@Override
|
||||
public void execute(Player sender, List<String> args) {
|
||||
public void execute(Player sender, Player targetPlayer, List<String> args) {
|
||||
if (sender == null) {
|
||||
CommandHandler.sendMessage(null, Grasscutter.getLanguage().Run_this_command_in_game);
|
||||
return; // TODO: toggle player's godmode statue from console or other players
|
||||
@ -32,7 +32,6 @@ public final class GodModeCommand implements CommandHandler {
|
||||
} else {
|
||||
target = sender.getUid();
|
||||
}
|
||||
Player targetPlayer = Grasscutter.getGameServer().getPlayerByUid(target);
|
||||
if (targetPlayer == null) {
|
||||
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Player_not_found);
|
||||
return;
|
||||
|
@ -14,7 +14,7 @@ import java.util.List;
|
||||
description = "Heal all characters in your current team.", permission = "player.heal")
|
||||
public final class HealCommand implements CommandHandler {
|
||||
@Override
|
||||
public void execute(Player sender, List<String> args) {
|
||||
public void execute(Player sender, Player targetPlayer, List<String> args) {
|
||||
if (sender == null) {
|
||||
CommandHandler.sendMessage(null, Grasscutter.getLanguage().Run_this_command_in_game);
|
||||
return;
|
||||
|
@ -13,7 +13,7 @@ import java.util.*;
|
||||
public final class HelpCommand implements CommandHandler {
|
||||
|
||||
@Override
|
||||
public void execute(Player player, List<String> args) {
|
||||
public void execute(Player player, Player targetPlayer, List<String> args) {
|
||||
if (args.size() < 1) {
|
||||
HashMap<String, CommandHandler> handlers = CommandMap.getInstance().getHandlers();
|
||||
List<Command> annotations = new ArrayList<>();
|
||||
|
@ -12,10 +12,9 @@ import java.util.List;
|
||||
public final class KickCommand implements CommandHandler {
|
||||
|
||||
@Override
|
||||
public void execute(Player sender, List<String> args) {
|
||||
public void execute(Player sender, Player targetPlayer, List<String> args) {
|
||||
int target = Integer.parseInt(args.get(0));
|
||||
|
||||
Player targetPlayer = Grasscutter.getGameServer().getPlayerByUid(target);
|
||||
if (targetPlayer == null) {
|
||||
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Player_not_found);
|
||||
return;
|
||||
|
@ -15,9 +15,8 @@ import java.util.List;
|
||||
public final class KillAllCommand implements CommandHandler {
|
||||
|
||||
@Override
|
||||
public void execute(Player sender, List<String> args) {
|
||||
public void execute(Player sender, Player targetPlayer, List<String> args) {
|
||||
Scene mainScene;
|
||||
Player targetPlayer;
|
||||
|
||||
try {
|
||||
switch (args.size()) {
|
||||
|
@ -17,7 +17,7 @@ import java.util.List;
|
||||
public final class KillCharacterCommand implements CommandHandler {
|
||||
|
||||
@Override
|
||||
public void execute(Player sender, List<String> args) {
|
||||
public void execute(Player sender, Player targetPlayer, List<String> args) {
|
||||
int target;
|
||||
if (sender == null) {
|
||||
// from console
|
||||
@ -48,7 +48,6 @@ public final class KillCharacterCommand implements CommandHandler {
|
||||
}
|
||||
}
|
||||
|
||||
Player targetPlayer = Grasscutter.getGameServer().getPlayerByUid(target);
|
||||
if (targetPlayer == null) {
|
||||
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Player_not_found_or_offline);
|
||||
return;
|
||||
|
@ -13,7 +13,7 @@ import java.util.Map;
|
||||
public final class ListCommand implements CommandHandler {
|
||||
|
||||
@Override
|
||||
public void execute(Player sender, List<String> args) {
|
||||
public void execute(Player sender, Player targetPlayer, List<String> args) {
|
||||
Map<Integer, Player> playersMap = Grasscutter.getGameServer().getPlayers();
|
||||
boolean needUID = false;
|
||||
|
||||
|
@ -13,7 +13,7 @@ import java.util.List;
|
||||
public final class PermissionCommand implements CommandHandler {
|
||||
|
||||
@Override
|
||||
public void execute(Player sender, List<String> args) {
|
||||
public void execute(Player sender, Player targetPlayer, List<String> args) {
|
||||
if (args.size() < 3) {
|
||||
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Permission_usage);
|
||||
return;
|
||||
|
@ -12,7 +12,7 @@ import java.util.List;
|
||||
public final class PositionCommand implements CommandHandler {
|
||||
|
||||
@Override
|
||||
public void execute(Player sender, List<String> args) {
|
||||
public void execute(Player sender, Player targetPlayer, List<String> args) {
|
||||
if (sender == null) {
|
||||
CommandHandler.sendMessage(null, Grasscutter.getLanguage().Run_this_command_in_game);
|
||||
return;
|
||||
|
@ -12,7 +12,7 @@ import java.util.List;
|
||||
public final class ReloadCommand implements CommandHandler {
|
||||
|
||||
@Override
|
||||
public void execute(Player sender, List<String> args) {
|
||||
public void execute(Player sender, Player targetPlayer, List<String> args) {
|
||||
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Reload_reload_start);
|
||||
Grasscutter.loadConfig();
|
||||
Grasscutter.loadLanguage();
|
||||
|
@ -15,7 +15,7 @@ import java.util.List;
|
||||
public final class ResetConstCommand implements CommandHandler {
|
||||
|
||||
@Override
|
||||
public void execute(Player sender, List<String> args) {
|
||||
public void execute(Player sender, Player targetPlayer, List<String> args) {
|
||||
if (sender == null) {
|
||||
CommandHandler.sendMessage(null, Grasscutter.getLanguage().Run_this_command_in_game);
|
||||
return;
|
||||
|
@ -11,14 +11,13 @@ import java.util.List;
|
||||
description = "Reset target player's shop refresh time.", permission = "server.resetshop")
|
||||
public final class ResetShopLimitCommand implements CommandHandler {
|
||||
@Override
|
||||
public void execute(Player sender, List<String> args) {
|
||||
public void execute(Player sender, Player targetPlayer, List<String> args) {
|
||||
if (args.size() < 1) {
|
||||
CommandHandler.sendMessage(sender,Grasscutter.getLanguage().ResetShopLimit_usage);
|
||||
return;
|
||||
}
|
||||
|
||||
int target = Integer.parseInt(args.get(0));
|
||||
Player targetPlayer = Grasscutter.getGameServer().getPlayerByUid(target);
|
||||
if (targetPlayer == null) {
|
||||
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Player_not_found);
|
||||
return;
|
||||
|
@ -10,7 +10,7 @@ import java.util.List;
|
||||
public final class RestartCommand implements CommandHandler {
|
||||
|
||||
@Override
|
||||
public void execute(Player sender, List<String> args) {
|
||||
public void execute(Player sender, Player targetPlayer, List<String> args) {
|
||||
sender.getSession().close();
|
||||
}
|
||||
}
|
||||
|
@ -23,7 +23,7 @@ public final class SendMailCommand implements CommandHandler {
|
||||
|
||||
// Yes this is awful and I hate it.
|
||||
@Override
|
||||
public void execute(Player sender, List<String> args) {
|
||||
public void execute(Player sender, Player targetPlayer, List<String> args) {
|
||||
int senderId;
|
||||
if(sender != null) {
|
||||
senderId = sender.getUid();
|
||||
|
@ -12,7 +12,7 @@ import java.util.List;
|
||||
public final class SendMessageCommand implements CommandHandler {
|
||||
|
||||
@Override
|
||||
public void execute(Player sender, List<String> args) {
|
||||
public void execute(Player sender, Player targetPlayer, List<String> args) {
|
||||
if (args.size() < 2) {
|
||||
CommandHandler.sendMessage(null, Grasscutter.getLanguage().SendMessage_usage);
|
||||
return;
|
||||
@ -22,7 +22,6 @@ public final class SendMessageCommand implements CommandHandler {
|
||||
int target = Integer.parseInt(args.get(0));
|
||||
String message = String.join(" ", args.subList(1, args.size()));
|
||||
|
||||
Player targetPlayer = Grasscutter.getGameServer().getPlayerByUid(target);
|
||||
if (targetPlayer == null) {
|
||||
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Player_not_found);
|
||||
return;
|
||||
|
@ -16,7 +16,7 @@ import emu.grasscutter.server.packet.send.PacketAvatarFetterDataNotify;
|
||||
public final class SetFetterLevelCommand implements CommandHandler {
|
||||
|
||||
@Override
|
||||
public void execute(Player sender, List<String> args) {
|
||||
public void execute(Player sender, Player targetPlayer, List<String> args) {
|
||||
if (sender == null) {
|
||||
CommandHandler.sendMessage(null, Grasscutter.getLanguage().Run_this_command_in_game);
|
||||
return;
|
||||
|
@ -174,50 +174,26 @@ public final class SetStatsCommand implements CommandHandler {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(Player sender, List<String> args) {
|
||||
public void execute(Player sender, Player targetPlayer, List<String> args) {
|
||||
Language lang = Grasscutter.getLanguage();
|
||||
String syntax = sender == null ? lang.SetStats_usage_console : lang.SetStats_usage_console;
|
||||
String usage = syntax + lang.SetStats_help_message;
|
||||
Player targetPlayer = sender;
|
||||
String uidStr = "";
|
||||
String statStr;
|
||||
String valueStr;
|
||||
|
||||
if (targetPlayer == null) {
|
||||
CommandHandler.sendMessage(sender, usage);
|
||||
return;
|
||||
}
|
||||
|
||||
switch (args.size()) {
|
||||
default:
|
||||
CommandHandler.sendMessage(sender, usage);
|
||||
return;
|
||||
case 2:
|
||||
if (sender == null) {
|
||||
// When run by the server, first parameter is not optional
|
||||
CommandHandler.sendMessage(sender, usage);
|
||||
return;
|
||||
}
|
||||
statStr = args.get(0).toLowerCase();
|
||||
valueStr = args.get(1);
|
||||
break;
|
||||
case 3:
|
||||
uidStr = args.get(0);
|
||||
if (uidStr.startsWith("@")) {
|
||||
uidStr = uidStr.substring(1);
|
||||
} else {
|
||||
CommandHandler.sendMessage(sender, usage);
|
||||
return;
|
||||
}
|
||||
try {
|
||||
int uid = Integer.parseInt(uidStr);
|
||||
targetPlayer = Grasscutter.getGameServer().getPlayerByUid(uid);
|
||||
if (targetPlayer == null) {
|
||||
CommandHandler.sendMessage(sender, lang.SetStats_player_error);
|
||||
return;
|
||||
}
|
||||
} catch (NumberFormatException e) {
|
||||
CommandHandler.sendMessage(sender, lang.SetStats_uid_error);
|
||||
return;
|
||||
}
|
||||
statStr = args.get(1).toLowerCase();
|
||||
valueStr = args.get(2);
|
||||
break;
|
||||
};
|
||||
|
||||
EntityAvatar entity = targetPlayer.getTeamManager().getCurrentAvatarEntity();
|
||||
@ -248,6 +224,7 @@ public final class SetStatsCommand implements CommandHandler {
|
||||
if (targetPlayer == sender) {
|
||||
CommandHandler.sendMessage(sender, lang.SetStats_set_self.replace("{name}", stat.name).replace("{value}", valueStr));
|
||||
} else {
|
||||
String uidStr = targetPlayer.getAccount().getId();
|
||||
CommandHandler.sendMessage(sender, lang.SetStats_set_for_uid.replace("{name}", stat.name).replace("{uid}", uidStr).replace("{value}", valueStr));
|
||||
}
|
||||
return;
|
||||
|
@ -13,7 +13,7 @@ import java.util.List;
|
||||
public final class SetWorldLevelCommand implements CommandHandler {
|
||||
|
||||
@Override
|
||||
public void execute(Player sender, List<String> args) {
|
||||
public void execute(Player sender, Player targetPlayer, List<String> args) {
|
||||
if (sender == null) {
|
||||
CommandHandler.sendMessage(null, Grasscutter.getLanguage().Run_this_command_in_game);
|
||||
return; // TODO: set player's world level from console or other players
|
||||
|
@ -24,7 +24,7 @@ import java.util.Random;
|
||||
public final class SpawnCommand implements CommandHandler {
|
||||
|
||||
@Override
|
||||
public void execute(Player sender, List<String> args) {
|
||||
public void execute(Player sender, Player targetPlayer, List<String> args) {
|
||||
if (sender == null) {
|
||||
CommandHandler.sendMessage(null, Grasscutter.getLanguage().Run_this_command_in_game);
|
||||
return;
|
||||
|
@ -12,7 +12,7 @@ import java.util.List;
|
||||
public final class StopCommand implements CommandHandler {
|
||||
|
||||
@Override
|
||||
public void execute(Player sender, List<String> args) {
|
||||
public void execute(Player sender, Player targetPlayer, List<String> args) {
|
||||
CommandHandler.sendMessage(null, Grasscutter.getLanguage().Stop_message);
|
||||
for (Player p : Grasscutter.getGameServer().getPlayers().values()) {
|
||||
CommandHandler.sendMessage(p, Grasscutter.getLanguage().Stop_message);
|
||||
|
@ -17,7 +17,7 @@ import java.util.List;
|
||||
public final class TalentCommand implements CommandHandler {
|
||||
|
||||
@Override
|
||||
public void execute(Player sender, List<String> args) {
|
||||
public void execute(Player sender, Player targetPlayer, List<String> args) {
|
||||
if (sender == null) {
|
||||
CommandHandler.sendMessage(null, Grasscutter.getLanguage().Run_this_command_in_game);
|
||||
return;
|
||||
|
@ -12,7 +12,7 @@ import java.util.List;
|
||||
description = "Teleports all players in your world to your position", permission = "player.tpall")
|
||||
public final class TeleportAllCommand implements CommandHandler {
|
||||
@Override
|
||||
public void execute(Player sender, List<String> args) {
|
||||
public void execute(Player sender, Player targetPlayer, List<String> args) {
|
||||
if (sender == null) {
|
||||
CommandHandler.sendMessage(null, Grasscutter.getLanguage().Run_this_command_in_game);
|
||||
return;
|
||||
|
@ -13,7 +13,7 @@ import java.util.List;
|
||||
public final class TeleportCommand implements CommandHandler {
|
||||
|
||||
@Override
|
||||
public void execute(Player sender, List<String> args) {
|
||||
public void execute(Player sender, Player targetPlayer, List<String> args) {
|
||||
int target;
|
||||
if (args.size() < (sender == null ? 4 : 3)) {
|
||||
CommandHandler.sendMessage(sender, sender == null ? Grasscutter.getLanguage().Teleport_usage_server :
|
||||
@ -35,7 +35,6 @@ public final class TeleportCommand implements CommandHandler {
|
||||
target = sender.getUid();
|
||||
}
|
||||
|
||||
Player targetPlayer = Grasscutter.getGameServer().getPlayerByUid(target);
|
||||
if (targetPlayer == null) {
|
||||
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Player_not_found_or_offline);
|
||||
return;
|
||||
|
@ -14,7 +14,7 @@ import java.util.List;
|
||||
public final class WeatherCommand implements CommandHandler {
|
||||
|
||||
@Override
|
||||
public void execute(Player sender, List<String> args) {
|
||||
public void execute(Player sender, Player targetPlayer, List<String> args) {
|
||||
if (sender == null) {
|
||||
CommandHandler.sendMessage(null, Grasscutter.getLanguage().Run_this_command_in_game);
|
||||
return;
|
||||
|
@ -28,15 +28,15 @@ public class ChatManager {
|
||||
if (message == null || message.length() == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Check if command
|
||||
if (PREFIXES.contains(message.charAt(0))) {
|
||||
CommandMap.getInstance().invoke(player, message);
|
||||
return;
|
||||
}
|
||||
|
||||
// Get target
|
||||
Player target = getServer().getPlayerByUid(targetUid);
|
||||
|
||||
// Check if command
|
||||
if (PREFIXES.contains(message.charAt(0))) {
|
||||
CommandMap.getInstance().invoke(player, target, message);
|
||||
return;
|
||||
}
|
||||
|
||||
if (target == null) {
|
||||
return;
|
||||
@ -72,7 +72,7 @@ public class ChatManager {
|
||||
|
||||
// Check if command
|
||||
if (PREFIXES.contains(message.charAt(0))) {
|
||||
CommandMap.getInstance().invoke(player, message);
|
||||
CommandMap.getInstance().invoke(player, null, message);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -58,6 +58,8 @@ public final class Language {
|
||||
public String Invalid_arguments = "Invalid arguments.";
|
||||
public String Success = "Success";
|
||||
public String Invalid_entity_id = "Invalid entity id.";
|
||||
public String Target_cleared = "Target cleared.";
|
||||
public String Target_set = "Subsequent commands will target @{uid} by default.";
|
||||
|
||||
// Help
|
||||
public String Help_usage = " Usage: ";
|
||||
@ -215,8 +217,6 @@ public final class Language {
|
||||
\t(cont.) Elemental RES: respyro | rescryo | reshydro | resgeo | resdendro | reselectro | resphys
|
||||
""";
|
||||
public String SetStats_value_error = "Invalid stat value.";
|
||||
public String SetStats_uid_error = "Invalid UID.";
|
||||
public String SetStats_player_error = "Player not found or offline.";
|
||||
public String SetStats_set_self = "{name} set to {value}.";
|
||||
public String SetStats_set_for_uid = "{name} for {uid} set to {value}.";
|
||||
public String Stats_FIGHT_PROP_MAX_HP = "Max HP";
|
||||
|
Loading…
Reference in New Issue
Block a user