mirror of
https://github.com/Melledy/Grasscutter.git
synced 2024-11-23 03:37:38 +00:00
Command Targeting overhaul fixes
This commit is contained in:
parent
d8b2e787e5
commit
37c2ee5e2c
@ -12,7 +12,7 @@ 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 final Map<String, Integer> targetPlayerIds = new HashMap<>();
|
||||
private static final String consoleId = "console";
|
||||
public CommandMap() {
|
||||
this(false);
|
||||
@ -122,24 +122,29 @@ public final class CommandMap {
|
||||
String targetUidStr = null;
|
||||
if (label.startsWith("@")) { // @[UID]
|
||||
targetUidStr = label.substring(1);
|
||||
} else if (label == "target") { // target [[@]UID]
|
||||
} else if (label.equalsIgnoreCase("target")) { // target [[@]UID]
|
||||
if (args.size() > 0) {
|
||||
targetUidStr = args.get(0);
|
||||
if (targetUidStr.startsWith("@")) {
|
||||
targetUidStr = targetUidStr.substring(1);
|
||||
}
|
||||
} else {
|
||||
targetUidStr = "";
|
||||
}
|
||||
if (targetUidStr == "") { // Clears default targetPlayer
|
||||
targetPlayers.remove(playerId);
|
||||
}
|
||||
if (targetUidStr != null) {
|
||||
if (targetUidStr.equals("")) { // Clears default targetPlayer
|
||||
targetPlayerIds.remove(playerId);
|
||||
CommandHandler.sendMessage(player, Grasscutter.getLanguage().Target_cleared);
|
||||
return;
|
||||
} else if (targetUidStr != null) { // Sets default targetPlayer to the UID given
|
||||
} else { // Sets default targetPlayer to the UID given
|
||||
try {
|
||||
int uid = Integer.parseInt(targetUidStr);
|
||||
targetPlayer = Grasscutter.getGameServer().getPlayerByUid(uid);
|
||||
if (targetPlayer == null) {
|
||||
CommandHandler.sendMessage(player, Grasscutter.getLanguage().Player_not_found_or_offline);
|
||||
} else {
|
||||
targetPlayers.put(playerId, targetPlayer);
|
||||
targetPlayerIds.put(playerId, uid);
|
||||
CommandHandler.sendMessage(player, Grasscutter.getLanguage().Target_set.replace("{uid}", targetUidStr));
|
||||
}
|
||||
} catch (NumberFormatException e) {
|
||||
@ -147,6 +152,7 @@ public final class CommandMap {
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// Get command handler.
|
||||
CommandHandler handler = this.commands.get(label);
|
||||
@ -178,7 +184,18 @@ public final class CommandMap {
|
||||
}
|
||||
// If there's still no targetPlayer at this point, use previously-set target
|
||||
if (targetPlayer == null) {
|
||||
targetPlayer = targetPlayers.getOrDefault(playerId, null);
|
||||
if (targetPlayerIds.containsKey(playerId)) {
|
||||
targetPlayer = Grasscutter.getGameServer().getPlayerByUid(targetPlayerIds.get(playerId)); // We check every time in case the target goes offline after being targeted
|
||||
if (targetPlayer == null) {
|
||||
CommandHandler.sendMessage(player, Grasscutter.getLanguage().Player_not_found_or_offline);
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
// If there's still no targetPlayer at this point, use local player
|
||||
if (targetPlayer == null) {
|
||||
targetPlayer = player;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Check for permission.
|
||||
|
@ -32,7 +32,7 @@ public final class ClearCommand implements CommandHandler {
|
||||
.filter(item -> item.getItemType() == ItemType.ITEM_WEAPON)
|
||||
.filter(item -> !item.isLocked() && !item.isEquipped())
|
||||
.forEach(item -> playerInventory.removeItem(item, item.getCount()));
|
||||
sender.dropMessage(Grasscutter.getLanguage().Clear_weapons.replace("{name}", targetPlayer.getNickname()));
|
||||
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Clear_weapons.replace("{name}", targetPlayer.getNickname()));
|
||||
}
|
||||
case "art" -> {
|
||||
playerInventory.getItems().values().stream()
|
||||
@ -40,7 +40,7 @@ public final class ClearCommand implements CommandHandler {
|
||||
.filter(item -> item.getLevel() == 1 && item.getExp() == 0)
|
||||
.filter(item -> !item.isLocked() && !item.isEquipped())
|
||||
.forEach(item -> playerInventory.removeItem(item, item.getCount()));
|
||||
sender.dropMessage(Grasscutter.getLanguage().Clear_artifacts.replace("{name}", targetPlayer.getNickname()));
|
||||
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Clear_artifacts.replace("{name}", targetPlayer.getNickname()));
|
||||
}
|
||||
case "mat" -> {
|
||||
playerInventory.getItems().values().stream()
|
||||
@ -48,7 +48,7 @@ public final class ClearCommand implements CommandHandler {
|
||||
.filter(item -> item.getLevel() == 1 && item.getExp() == 0)
|
||||
.filter(item -> !item.isLocked() && !item.isEquipped())
|
||||
.forEach(item -> playerInventory.removeItem(item, item.getCount()));
|
||||
sender.dropMessage(Grasscutter.getLanguage().Clear_artifacts.replace("{name}", targetPlayer.getNickname()));
|
||||
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Clear_artifacts.replace("{name}", targetPlayer.getNickname()));
|
||||
}
|
||||
case "all" -> {
|
||||
playerInventory.getItems().values().stream()
|
||||
@ -56,34 +56,34 @@ public final class ClearCommand implements CommandHandler {
|
||||
.filter(item1 -> item1.getLevel() == 1 && item1.getExp() == 0)
|
||||
.filter(item1 -> !item1.isLocked() && !item1.isEquipped())
|
||||
.forEach(item1 -> playerInventory.removeItem(item1, item1.getCount()));
|
||||
sender.dropMessage(Grasscutter.getLanguage().Clear_artifacts.replace("{name}", targetPlayer.getNickname()));
|
||||
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Clear_artifacts.replace("{name}", targetPlayer.getNickname()));
|
||||
playerInventory.getItems().values().stream()
|
||||
.filter(item2 -> item2.getItemType() == ItemType.ITEM_MATERIAL)
|
||||
.filter(item2 -> !item2.isLocked() && !item2.isEquipped())
|
||||
.forEach(item2 -> playerInventory.removeItem(item2, item2.getCount()));
|
||||
sender.dropMessage(Grasscutter.getLanguage().Clear_artifacts.replace("{name}", targetPlayer.getNickname()));
|
||||
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Clear_artifacts.replace("{name}", targetPlayer.getNickname()));
|
||||
playerInventory.getItems().values().stream()
|
||||
.filter(item3 -> item3.getItemType() == ItemType.ITEM_WEAPON)
|
||||
.filter(item3 -> item3.getLevel() == 1 && item3.getExp() == 0)
|
||||
.filter(item3 -> !item3.isLocked() && !item3.isEquipped())
|
||||
.forEach(item3 -> playerInventory.removeItem(item3, item3.getCount()));
|
||||
sender.dropMessage(Grasscutter.getLanguage().Clear_artifacts.replace("{name}", targetPlayer.getNickname()));
|
||||
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Clear_artifacts.replace("{name}", targetPlayer.getNickname()));
|
||||
playerInventory.getItems().values().stream()
|
||||
.filter(item4 -> item4.getItemType() == ItemType.ITEM_FURNITURE)
|
||||
.filter(item4 -> !item4.isLocked() && !item4.isEquipped())
|
||||
.forEach(item4 -> playerInventory.removeItem(item4, item4.getCount()));
|
||||
sender.dropMessage(Grasscutter.getLanguage().Clear_furniture.replace("{name}", targetPlayer.getNickname()));
|
||||
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Clear_furniture.replace("{name}", targetPlayer.getNickname()));
|
||||
playerInventory.getItems().values().stream()
|
||||
.filter(item5 -> item5.getItemType() == ItemType.ITEM_DISPLAY)
|
||||
.filter(item5 -> !item5.isLocked() && !item5.isEquipped())
|
||||
.forEach(item5 -> playerInventory.removeItem(item5, item5.getCount()));
|
||||
sender.dropMessage(Grasscutter.getLanguage().Clear_displays.replace("{name}", targetPlayer.getNickname()));
|
||||
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Clear_displays.replace("{name}", targetPlayer.getNickname()));
|
||||
playerInventory.getItems().values().stream()
|
||||
.filter(item6 -> item6.getItemType() == ItemType.ITEM_VIRTUAL)
|
||||
.filter(item6 -> !item6.isLocked() && !item6.isEquipped())
|
||||
.forEach(item6 -> playerInventory.removeItem(item6, item6.getCount()));
|
||||
sender.dropMessage(Grasscutter.getLanguage().Clear_virtuals.replace("{name}", targetPlayer.getNickname()));
|
||||
sender.dropMessage(Grasscutter.getLanguage().Clear_everything.replace("{name}", targetPlayer.getNickname()));
|
||||
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Clear_virtuals.replace("{name}", targetPlayer.getNickname()));
|
||||
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Clear_everything.replace("{name}", targetPlayer.getNickname()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -20,17 +20,21 @@ public final class CoopCommand implements CommandHandler {
|
||||
Player host = sender;
|
||||
switch (args.size()) {
|
||||
case 0: // Summon target to self
|
||||
if (sender == null) { // Console doesn't have a self to summon to
|
||||
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Coop_usage);
|
||||
return;
|
||||
}
|
||||
break;
|
||||
case 1: // Summon target to argument
|
||||
try {
|
||||
int hostId = Integer.parseInt(args.get(1));
|
||||
host = sender.getServer().getPlayerByUid(hostId);
|
||||
int hostId = Integer.parseInt(args.get(0));
|
||||
host = Grasscutter.getGameServer().getPlayerByUid(hostId);
|
||||
if (host == null) {
|
||||
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Player_is_offline);
|
||||
return;
|
||||
}
|
||||
break;
|
||||
} catch (Exception e) {
|
||||
} catch (NumberFormatException ignored) {
|
||||
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Invalid_playerId);
|
||||
return;
|
||||
}
|
||||
@ -39,12 +43,12 @@ public final class CoopCommand implements CommandHandler {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
// There's no target==host check but this just places them in multiplayer in their own world which seems fine.
|
||||
if (targetPlayer.isInMultiplayer()) {
|
||||
sender.getServer().getMultiplayerManager().leaveCoop(targetPlayer);
|
||||
targetPlayer.getServer().getMultiplayerManager().leaveCoop(targetPlayer);
|
||||
}
|
||||
sender.getServer().getMultiplayerManager().applyEnterMp(targetPlayer, host.getUid());
|
||||
sender.getServer().getMultiplayerManager().applyEnterMpReply(host, targetPlayer.getUid(), true);
|
||||
host.getServer().getMultiplayerManager().applyEnterMp(targetPlayer, host.getUid());
|
||||
targetPlayer.getServer().getMultiplayerManager().applyEnterMpReply(host, targetPlayer.getUid(), true);
|
||||
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Coop_success.replace("{host}", host.getNickname()).replace("{target}", targetPlayer.getNickname()));
|
||||
}
|
||||
}
|
||||
|
@ -37,7 +37,7 @@ public final class GiveAllCommand implements CommandHandler {
|
||||
}
|
||||
break;
|
||||
default: // invalid
|
||||
CommandHandler.sendMessage(null, Grasscutter.getLanguage().GiveAll_usage);
|
||||
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().GiveAll_usage);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -52,7 +52,7 @@ public final class GiveArtifactCommand implements CommandHandler {
|
||||
int level = 1;
|
||||
try {
|
||||
int last = Integer.parseInt(args.get(args.size()-1));
|
||||
if (last > 0 && last < 21) { // Luckily appendPropIds aren't in the range of [1,20]
|
||||
if (last > 0 && last < 22) { // Luckily appendPropIds aren't in the range of [1,21]
|
||||
level = last;
|
||||
args.remove(args.size()-1);
|
||||
}
|
||||
|
@ -35,6 +35,6 @@ public final class GodModeCommand implements CommandHandler {
|
||||
}
|
||||
|
||||
targetPlayer.setGodmode(enabled);
|
||||
sender.dropMessage(Grasscutter.getLanguage().Godmode_status.replace("{status}", (enabled ? Grasscutter.getLanguage().Enabled : Grasscutter.getLanguage().Disabled)).replace("{name}", targetPlayer.getNickname()));
|
||||
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Godmode_status.replace("{status}", (enabled ? Grasscutter.getLanguage().Enabled : Grasscutter.getLanguage().Disabled)).replace("{name}", targetPlayer.getNickname()));
|
||||
}
|
||||
}
|
||||
|
@ -20,6 +20,6 @@ public final class PositionCommand implements CommandHandler {
|
||||
}
|
||||
|
||||
Position pos = targetPlayer.getPos();
|
||||
sender.dropMessage(Grasscutter.getLanguage().Position_message.replace("{x}", Float.toString(pos.getX())).replace("{y}", Float.toString(pos.getY())).replace("{z}", Float.toString(pos.getZ())).replace("{id}", Integer.toString(sender.getSceneId())));
|
||||
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Position_message.replace("{x}", Float.toString(pos.getX())).replace("{y}", Float.toString(pos.getY())).replace("{z}", Float.toString(pos.getZ())).replace("{id}", Integer.toString(targetPlayer.getSceneId())));
|
||||
}
|
||||
}
|
||||
|
@ -23,7 +23,7 @@ public final class ResetConstCommand implements CommandHandler {
|
||||
|
||||
if (args.size() > 0 && args.get(0).equalsIgnoreCase("all")) {
|
||||
targetPlayer.getAvatars().forEach(this::resetConstellation);
|
||||
targetPlayer.dropMessage(Grasscutter.getLanguage().ResetConst_reset_all);
|
||||
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().ResetConst_reset_all);
|
||||
} else {
|
||||
EntityAvatar entity = targetPlayer.getTeamManager().getCurrentAvatarEntity();
|
||||
if (entity == null) {
|
||||
@ -33,7 +33,7 @@ public final class ResetConstCommand implements CommandHandler {
|
||||
Avatar avatar = entity.getAvatar();
|
||||
this.resetConstellation(avatar);
|
||||
|
||||
sender.dropMessage(Grasscutter.getLanguage().ResetConst_reset_all_done.replace("{name}", avatar.getAvatarData().getName()));
|
||||
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().ResetConst_reset_all_done.replace("{name}", avatar.getAvatarData().getName()));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -11,6 +11,9 @@ public final class RestartCommand implements CommandHandler {
|
||||
|
||||
@Override
|
||||
public void execute(Player sender, Player targetPlayer, List<String> args) {
|
||||
if (sender == null) {
|
||||
return;
|
||||
}
|
||||
sender.getSession().close();
|
||||
}
|
||||
}
|
||||
|
@ -27,7 +27,7 @@ public final class SetWorldLevelCommand implements CommandHandler {
|
||||
try {
|
||||
int level = Integer.parseInt(args.get(0));
|
||||
if (level > 8 || level < 0) {
|
||||
sender.dropMessage(Grasscutter.getLanguage().SetWorldLevel_world_level_must_between_0_and_8);
|
||||
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().SetWorldLevel_world_level_must_between_0_and_8);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -35,7 +35,7 @@ public final class SetWorldLevelCommand implements CommandHandler {
|
||||
targetPlayer.getWorld().setWorldLevel(level);
|
||||
targetPlayer.setWorldLevel(level);
|
||||
|
||||
sender.dropMessage(Grasscutter.getLanguage().SetWorldLevel_set_world_level.replace("{level}", Integer.toString(level)));
|
||||
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().SetWorldLevel_set_world_level.replace("{level}", Integer.toString(level)));
|
||||
} catch (NumberFormatException ignored) {
|
||||
CommandHandler.sendMessage(null, Grasscutter.getLanguage().SetWorldLevel_invalid_world_level);
|
||||
}
|
||||
|
@ -56,7 +56,7 @@ public final class TalentCommand implements CommandHandler {
|
||||
return;
|
||||
}
|
||||
|
||||
EntityAvatar entity = sender.getTeamManager().getCurrentAvatarEntity();
|
||||
EntityAvatar entity = targetPlayer.getTeamManager().getCurrentAvatarEntity();
|
||||
Avatar avatar = entity.getAvatar();
|
||||
String cmdSwitch = args.get(0);
|
||||
switch (cmdSwitch) {
|
||||
|
@ -46,8 +46,8 @@ public final class TeleportCommand implements CommandHandler {
|
||||
case 3:
|
||||
try {
|
||||
x = parseRelative(args.get(0), x);
|
||||
y = parseRelative(args.get(0), y);
|
||||
z = parseRelative(args.get(0), z);
|
||||
y = parseRelative(args.get(1), y);
|
||||
z = parseRelative(args.get(2), z);
|
||||
} catch (NumberFormatException ignored) {
|
||||
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Teleport_invalid_position);
|
||||
}
|
||||
|
@ -43,9 +43,9 @@ public final class WeatherCommand implements CommandHandler {
|
||||
|
||||
ClimateType climate = ClimateType.getTypeByValue(climateId);
|
||||
|
||||
sender.getScene().setWeather(weatherId);
|
||||
sender.getScene().setClimate(climate);
|
||||
sender.getScene().broadcastPacket(new PacketSceneAreaWeatherNotify(sender));
|
||||
targetPlayer.getScene().setWeather(weatherId);
|
||||
targetPlayer.getScene().setClimate(climate);
|
||||
targetPlayer.getScene().broadcastPacket(new PacketSceneAreaWeatherNotify(targetPlayer));
|
||||
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Weather_message.replace("{weatherId}", Integer.toString(weatherId)).replace("{climateId}", Integer.toString(climateId)));
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user