Commit 82ec63c4 authored by AnimeGitB's avatar AnimeGitB Committed by Melledy
Browse files

[WIP] Command Targeting overhaul

parent 4e0ebe56
...@@ -17,7 +17,7 @@ import java.util.List; ...@@ -17,7 +17,7 @@ import java.util.List;
public final class KillCharacterCommand implements CommandHandler { public final class KillCharacterCommand implements CommandHandler {
@Override @Override
public void execute(Player sender, List<String> args) { public void execute(Player sender, Player targetPlayer, List<String> args) {
int target; int target;
if (sender == null) { if (sender == null) {
// from console // from console
...@@ -48,7 +48,6 @@ public final class KillCharacterCommand implements CommandHandler { ...@@ -48,7 +48,6 @@ public final class KillCharacterCommand implements CommandHandler {
} }
} }
Player targetPlayer = Grasscutter.getGameServer().getPlayerByUid(target);
if (targetPlayer == null) { if (targetPlayer == null) {
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Player_not_found_or_offline); CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Player_not_found_or_offline);
return; return;
......
...@@ -13,7 +13,7 @@ import java.util.Map; ...@@ -13,7 +13,7 @@ import java.util.Map;
public final class ListCommand implements CommandHandler { public final class ListCommand implements CommandHandler {
@Override @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(); Map<Integer, Player> playersMap = Grasscutter.getGameServer().getPlayers();
boolean needUID = false; boolean needUID = false;
......
...@@ -13,7 +13,7 @@ import java.util.List; ...@@ -13,7 +13,7 @@ import java.util.List;
public final class PermissionCommand implements CommandHandler { public final class PermissionCommand implements CommandHandler {
@Override @Override
public void execute(Player sender, List<String> args) { public void execute(Player sender, Player targetPlayer, List<String> args) {
if (args.size() < 3) { if (args.size() < 3) {
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Permission_usage); CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Permission_usage);
return; return;
......
...@@ -12,7 +12,7 @@ import java.util.List; ...@@ -12,7 +12,7 @@ import java.util.List;
public final class PositionCommand implements CommandHandler { public final class PositionCommand implements CommandHandler {
@Override @Override
public void execute(Player sender, List<String> args) { public void execute(Player sender, Player targetPlayer, List<String> args) {
if (sender == null) { if (sender == null) {
CommandHandler.sendMessage(null, Grasscutter.getLanguage().Run_this_command_in_game); CommandHandler.sendMessage(null, Grasscutter.getLanguage().Run_this_command_in_game);
return; return;
......
...@@ -12,7 +12,7 @@ import java.util.List; ...@@ -12,7 +12,7 @@ import java.util.List;
public final class ReloadCommand implements CommandHandler { public final class ReloadCommand implements CommandHandler {
@Override @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); CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Reload_reload_start);
Grasscutter.loadConfig(); Grasscutter.loadConfig();
Grasscutter.loadLanguage(); Grasscutter.loadLanguage();
......
...@@ -15,7 +15,7 @@ import java.util.List; ...@@ -15,7 +15,7 @@ import java.util.List;
public final class ResetConstCommand implements CommandHandler { public final class ResetConstCommand implements CommandHandler {
@Override @Override
public void execute(Player sender, List<String> args) { public void execute(Player sender, Player targetPlayer, List<String> args) {
if (sender == null) { if (sender == null) {
CommandHandler.sendMessage(null, Grasscutter.getLanguage().Run_this_command_in_game); CommandHandler.sendMessage(null, Grasscutter.getLanguage().Run_this_command_in_game);
return; return;
......
...@@ -11,14 +11,13 @@ import java.util.List; ...@@ -11,14 +11,13 @@ import java.util.List;
description = "Reset target player's shop refresh time.", permission = "server.resetshop") 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, List<String> args) { public void execute(Player sender, Player targetPlayer, List<String> args) {
if (args.size() < 1) { if (args.size() < 1) {
CommandHandler.sendMessage(sender,Grasscutter.getLanguage().ResetShopLimit_usage); CommandHandler.sendMessage(sender,Grasscutter.getLanguage().ResetShopLimit_usage);
return; return;
} }
int target = Integer.parseInt(args.get(0)); int target = Integer.parseInt(args.get(0));
Player targetPlayer = Grasscutter.getGameServer().getPlayerByUid(target);
if (targetPlayer == null) { if (targetPlayer == null) {
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Player_not_found); CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Player_not_found);
return; return;
......
...@@ -10,7 +10,7 @@ import java.util.List; ...@@ -10,7 +10,7 @@ import java.util.List;
public final class RestartCommand implements CommandHandler { public final class RestartCommand implements CommandHandler {
@Override @Override
public void execute(Player sender, List<String> args) { public void execute(Player sender, Player targetPlayer, List<String> args) {
sender.getSession().close(); sender.getSession().close();
} }
} }
...@@ -23,7 +23,7 @@ public final class SendMailCommand implements CommandHandler { ...@@ -23,7 +23,7 @@ public final class SendMailCommand implements CommandHandler {
// Yes this is awful and I hate it. // Yes this is awful and I hate it.
@Override @Override
public void execute(Player sender, 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();
......
...@@ -12,7 +12,7 @@ import java.util.List; ...@@ -12,7 +12,7 @@ import java.util.List;
public final class SendMessageCommand implements CommandHandler { public final class SendMessageCommand implements CommandHandler {
@Override @Override
public void execute(Player sender, List<String> args) { public void execute(Player sender, Player targetPlayer, List<String> args) {
if (args.size() < 2) { if (args.size() < 2) {
CommandHandler.sendMessage(null, Grasscutter.getLanguage().SendMessage_usage); CommandHandler.sendMessage(null, Grasscutter.getLanguage().SendMessage_usage);
return; return;
...@@ -22,7 +22,6 @@ public final class SendMessageCommand implements CommandHandler { ...@@ -22,7 +22,6 @@ public final class SendMessageCommand implements CommandHandler {
int target = Integer.parseInt(args.get(0)); int target = Integer.parseInt(args.get(0));
String message = String.join(" ", args.subList(1, args.size())); String message = String.join(" ", args.subList(1, args.size()));
Player targetPlayer = Grasscutter.getGameServer().getPlayerByUid(target);
if (targetPlayer == null) { if (targetPlayer == null) {
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Player_not_found); CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Player_not_found);
return; return;
......
...@@ -16,7 +16,7 @@ import emu.grasscutter.server.packet.send.PacketAvatarFetterDataNotify; ...@@ -16,7 +16,7 @@ import emu.grasscutter.server.packet.send.PacketAvatarFetterDataNotify;
public final class SetFetterLevelCommand implements CommandHandler { public final class SetFetterLevelCommand implements CommandHandler {
@Override @Override
public void execute(Player sender, List<String> args) { public void execute(Player sender, Player targetPlayer, List<String> args) {
if (sender == null) { if (sender == null) {
CommandHandler.sendMessage(null, Grasscutter.getLanguage().Run_this_command_in_game); CommandHandler.sendMessage(null, Grasscutter.getLanguage().Run_this_command_in_game);
return; return;
......
...@@ -174,50 +174,26 @@ public final class SetStatsCommand implements CommandHandler { ...@@ -174,50 +174,26 @@ public final class SetStatsCommand implements CommandHandler {
} }
@Override @Override
public void execute(Player sender, List<String> args) { public void execute(Player sender, Player targetPlayer, List<String> args) {
Language lang = Grasscutter.getLanguage(); Language lang = Grasscutter.getLanguage();
String syntax = sender == null ? lang.SetStats_usage_console : lang.SetStats_usage_console; String syntax = sender == null ? lang.SetStats_usage_console : lang.SetStats_usage_console;
String usage = syntax + lang.SetStats_help_message; String usage = syntax + lang.SetStats_help_message;
Player targetPlayer = sender;
String uidStr = "";
String statStr; String statStr;
String valueStr; String valueStr;
if (targetPlayer == null) {
CommandHandler.sendMessage(sender, usage);
return;
}
switch (args.size()) { switch (args.size()) {
default: default:
CommandHandler.sendMessage(sender, usage); CommandHandler.sendMessage(sender, usage);
return; return;
case 2: 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(); statStr = args.get(0).toLowerCase();
valueStr = args.get(1); valueStr = args.get(1);
break; 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(); EntityAvatar entity = targetPlayer.getTeamManager().getCurrentAvatarEntity();
...@@ -248,6 +224,7 @@ public final class SetStatsCommand implements CommandHandler { ...@@ -248,6 +224,7 @@ public final class SetStatsCommand implements CommandHandler {
if (targetPlayer == sender) { if (targetPlayer == sender) {
CommandHandler.sendMessage(sender, lang.SetStats_set_self.replace("{name}", stat.name).replace("{value}", valueStr)); CommandHandler.sendMessage(sender, lang.SetStats_set_self.replace("{name}", stat.name).replace("{value}", valueStr));
} else { } else {
String uidStr = targetPlayer.getAccount().getId();
CommandHandler.sendMessage(sender, lang.SetStats_set_for_uid.replace("{name}", stat.name).replace("{uid}", uidStr).replace("{value}", valueStr)); CommandHandler.sendMessage(sender, lang.SetStats_set_for_uid.replace("{name}", stat.name).replace("{uid}", uidStr).replace("{value}", valueStr));
} }
return; return;
......
...@@ -13,7 +13,7 @@ import java.util.List; ...@@ -13,7 +13,7 @@ import java.util.List;
public final class SetWorldLevelCommand implements CommandHandler { public final class SetWorldLevelCommand implements CommandHandler {
@Override @Override
public void execute(Player sender, List<String> args) { public void execute(Player sender, Player targetPlayer, List<String> args) {
if (sender == null) { if (sender == null) {
CommandHandler.sendMessage(null, Grasscutter.getLanguage().Run_this_command_in_game); CommandHandler.sendMessage(null, Grasscutter.getLanguage().Run_this_command_in_game);
return; // TODO: set player's world level from console or other players return; // TODO: set player's world level from console or other players
......
...@@ -24,7 +24,7 @@ import java.util.Random; ...@@ -24,7 +24,7 @@ import java.util.Random;
public final class SpawnCommand implements CommandHandler { public final class SpawnCommand implements CommandHandler {
@Override @Override
public void execute(Player sender, List<String> args) { public void execute(Player sender, Player targetPlayer, List<String> args) {
if (sender == null) { if (sender == null) {
CommandHandler.sendMessage(null, Grasscutter.getLanguage().Run_this_command_in_game); CommandHandler.sendMessage(null, Grasscutter.getLanguage().Run_this_command_in_game);
return; return;
......
...@@ -12,7 +12,7 @@ import java.util.List; ...@@ -12,7 +12,7 @@ import java.util.List;
public final class StopCommand implements CommandHandler { public final class StopCommand implements CommandHandler {
@Override @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); CommandHandler.sendMessage(null, Grasscutter.getLanguage().Stop_message);
for (Player p : Grasscutter.getGameServer().getPlayers().values()) { for (Player p : Grasscutter.getGameServer().getPlayers().values()) {
CommandHandler.sendMessage(p, Grasscutter.getLanguage().Stop_message); CommandHandler.sendMessage(p, Grasscutter.getLanguage().Stop_message);
......
...@@ -17,7 +17,7 @@ import java.util.List; ...@@ -17,7 +17,7 @@ import java.util.List;
public final class TalentCommand implements CommandHandler { public final class TalentCommand implements CommandHandler {
@Override @Override
public void execute(Player sender, List<String> args) { public void execute(Player sender, Player targetPlayer, List<String> args) {
if (sender == null) { if (sender == null) {
CommandHandler.sendMessage(null, Grasscutter.getLanguage().Run_this_command_in_game); CommandHandler.sendMessage(null, Grasscutter.getLanguage().Run_this_command_in_game);
return; return;
......
...@@ -12,7 +12,7 @@ import java.util.List; ...@@ -12,7 +12,7 @@ import java.util.List;
description = "Teleports all players in your world to your position", permission = "player.tpall") description = "Teleports all players in your world to your position", permission = "player.tpall")
public final class TeleportAllCommand implements CommandHandler { public final class TeleportAllCommand implements CommandHandler {
@Override @Override
public void execute(Player sender, List<String> args) { public void execute(Player sender, Player targetPlayer, List<String> args) {
if (sender == null) { if (sender == null) {
CommandHandler.sendMessage(null, Grasscutter.getLanguage().Run_this_command_in_game); CommandHandler.sendMessage(null, Grasscutter.getLanguage().Run_this_command_in_game);
return; return;
......
...@@ -13,7 +13,7 @@ import java.util.List; ...@@ -13,7 +13,7 @@ import java.util.List;
public final class TeleportCommand implements CommandHandler { public final class TeleportCommand implements CommandHandler {
@Override @Override
public void execute(Player sender, List<String> args) { public void execute(Player sender, Player targetPlayer, List<String> args) {
int target; int target;
if (args.size() < (sender == null ? 4 : 3)) { if (args.size() < (sender == null ? 4 : 3)) {
CommandHandler.sendMessage(sender, sender == null ? Grasscutter.getLanguage().Teleport_usage_server : CommandHandler.sendMessage(sender, sender == null ? Grasscutter.getLanguage().Teleport_usage_server :
...@@ -35,7 +35,6 @@ public final class TeleportCommand implements CommandHandler { ...@@ -35,7 +35,6 @@ public final class TeleportCommand implements CommandHandler {
target = sender.getUid(); target = sender.getUid();
} }
Player targetPlayer = Grasscutter.getGameServer().getPlayerByUid(target);
if (targetPlayer == null) { if (targetPlayer == null) {
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Player_not_found_or_offline); CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Player_not_found_or_offline);
return; return;
......
...@@ -14,7 +14,7 @@ import java.util.List; ...@@ -14,7 +14,7 @@ import java.util.List;
public final class WeatherCommand implements CommandHandler { public final class WeatherCommand implements CommandHandler {
@Override @Override
public void execute(Player sender, List<String> args) { public void execute(Player sender, Player targetPlayer, List<String> args) {
if (sender == null) { if (sender == null) {
CommandHandler.sendMessage(null, Grasscutter.getLanguage().Run_this_command_in_game); CommandHandler.sendMessage(null, Grasscutter.getLanguage().Run_this_command_in_game);
return; return;
......
...@@ -29,15 +29,15 @@ public class ChatManager { ...@@ -29,15 +29,15 @@ public class ChatManager {
return; return;
} }
// Get target
Player target = getServer().getPlayerByUid(targetUid);
// Check if command // Check if command
if (PREFIXES.contains(message.charAt(0))) { if (PREFIXES.contains(message.charAt(0))) {
CommandMap.getInstance().invoke(player, message); CommandMap.getInstance().invoke(player, target, message);
return; return;
} }
// Get target
Player target = getServer().getPlayerByUid(targetUid);
if (target == null) { if (target == null) {
return; return;
} }
...@@ -72,7 +72,7 @@ public class ChatManager { ...@@ -72,7 +72,7 @@ public class ChatManager {
// Check if command // Check if command
if (PREFIXES.contains(message.charAt(0))) { if (PREFIXES.contains(message.charAt(0))) {
CommandMap.getInstance().invoke(player, message); CommandMap.getInstance().invoke(player, null, message);
return; return;
} }
......
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