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;
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;
......
......@@ -29,15 +29,15 @@ public class ChatManager {
return;
}
// Get target
Player target = getServer().getPlayerByUid(targetUid);
// Check if command
if (PREFIXES.contains(message.charAt(0))) {
CommandMap.getInstance().invoke(player, message);
CommandMap.getInstance().invoke(player, target, message);
return;
}
// Get target
Player target = getServer().getPlayerByUid(targetUid);
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;
}
......
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