mirror of
https://github.com/Grasscutters/Grasscutter.git
synced 2025-01-25 02:12:52 +08:00
Fix commands in party chat, re-add optional positional item quantity to give command, error out and print usage if excess arguments given to give command
This commit is contained in:
parent
13a7f08665
commit
a80302cdcd
@ -114,18 +114,27 @@ public final class GiveCommand implements CommandHandler {
|
|||||||
default:
|
default:
|
||||||
try {
|
try {
|
||||||
param.id = Integer.parseInt(id);
|
param.id = Integer.parseInt(id);
|
||||||
|
} catch (NumberFormatException e) {
|
||||||
|
// TODO: Parse from item name using GM Handbook.
|
||||||
|
CommandHandler.sendTranslatedMessage(sender, "commands.generic.invalid.itemId");
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
param.data = GameData.getItemDataMap().get(param.id);
|
param.data = GameData.getItemDataMap().get(param.id);
|
||||||
if ((param.id > 10_000_000) && (param.id < 12_000_000))
|
if ((param.id > 10_000_000) && (param.id < 12_000_000))
|
||||||
param.avatarData = GameData.getAvatarDataMap().get(param.id);
|
param.avatarData = GameData.getAvatarDataMap().get(param.id);
|
||||||
else if ((param.id > 1000) && (param.id < 1100))
|
else if ((param.id > 1000) && (param.id < 1100))
|
||||||
param.avatarData = GameData.getAvatarDataMap().get(param.id - 1000 + 10_000_000);
|
param.avatarData = GameData.getAvatarDataMap().get(param.id - 1000 + 10_000_000);
|
||||||
isRelic = ((param.data != null) && (param.data.getItemType() == ItemType.ITEM_RELIQUARY));
|
isRelic = ((param.data != null) && (param.data.getItemType() == ItemType.ITEM_RELIQUARY));
|
||||||
|
|
||||||
|
if (!isRelic && !args.isEmpty() && (param.amount == 1)) { // A concession for the people that truly hate [x<amount>].
|
||||||
|
try {
|
||||||
|
param.amount = Integer.parseInt(args.remove(0));
|
||||||
} catch (NumberFormatException e) {
|
} catch (NumberFormatException e) {
|
||||||
// TODO: Parse from item name using GM Handbook.
|
CommandHandler.sendTranslatedMessage(sender, "commands.generic.invalid.amount");
|
||||||
CommandHandler.sendTranslatedMessage(sender, "commands.generic.invalid.itemId");
|
|
||||||
throw e;
|
throw e;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (param.amount < 1) param.amount = 1;
|
if (param.amount < 1) param.amount = 1;
|
||||||
if (param.refinement < 1) param.refinement = 1;
|
if (param.refinement < 1) param.refinement = 1;
|
||||||
@ -143,7 +152,8 @@ public final class GiveCommand implements CommandHandler {
|
|||||||
if (param.lvl > 90) param.lvl = 90;
|
if (param.lvl > 90) param.lvl = 90;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isRelic && !args.isEmpty()) {
|
if (!args.isEmpty()) {
|
||||||
|
if (isRelic) {
|
||||||
try {
|
try {
|
||||||
parseRelicArgs(param, args);
|
parseRelicArgs(param, args);
|
||||||
} catch (IllegalArgumentException e) {
|
} catch (IllegalArgumentException e) {
|
||||||
@ -151,6 +161,10 @@ public final class GiveCommand implements CommandHandler {
|
|||||||
CommandHandler.sendTranslatedMessage(sender, "commands.give.usage_relic");
|
CommandHandler.sendTranslatedMessage(sender, "commands.give.usage_relic");
|
||||||
throw e;
|
throw e;
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
CommandHandler.sendTranslatedMessage(sender, "commands.give.usage");
|
||||||
|
throw new IllegalArgumentException();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return param;
|
return param;
|
||||||
|
@ -7,11 +7,12 @@ import emu.grasscutter.server.game.GameServer;
|
|||||||
import emu.grasscutter.server.packet.send.PacketPlayerChatNotify;
|
import emu.grasscutter.server.packet.send.PacketPlayerChatNotify;
|
||||||
import emu.grasscutter.server.packet.send.PacketPrivateChatNotify;
|
import emu.grasscutter.server.packet.send.PacketPrivateChatNotify;
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.regex.Pattern;
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public class ChatManager implements ChatManagerHandler {
|
public class ChatManager implements ChatManagerHandler {
|
||||||
static final List<Character> PREFIXES = Arrays.asList('/', '!');
|
static final String PREFIXES = "[/!]";
|
||||||
|
static final Pattern RE_PREFIXES = Pattern.compile(PREFIXES);
|
||||||
|
static final Pattern RE_COMMANDS = Pattern.compile("\n" + PREFIXES);
|
||||||
|
|
||||||
private final GameServer server;
|
private final GameServer server;
|
||||||
|
|
||||||
@ -23,6 +24,14 @@ public class ChatManager implements ChatManagerHandler {
|
|||||||
return server;
|
return server;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private boolean tryInvokeCommand(Player sender, Player target, String rawMessage) {
|
||||||
|
if (!RE_PREFIXES.matcher(rawMessage.substring(0, 1)).matches())
|
||||||
|
return false;
|
||||||
|
for (String line : rawMessage.substring(1).split("\n[/!]"))
|
||||||
|
CommandMap.getInstance().invoke(sender, target, line);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
public void sendPrivateMessage(Player player, int targetUid, String message) {
|
public void sendPrivateMessage(Player player, int targetUid, String message) {
|
||||||
// Sanity checks
|
// Sanity checks
|
||||||
if (message == null || message.length() == 0) {
|
if (message == null || message.length() == 0) {
|
||||||
@ -33,8 +42,7 @@ public class ChatManager implements ChatManagerHandler {
|
|||||||
Player target = getServer().getPlayerByUid(targetUid);
|
Player target = getServer().getPlayerByUid(targetUid);
|
||||||
|
|
||||||
// Check if command
|
// Check if command
|
||||||
if (PREFIXES.contains(message.charAt(0))) {
|
if (tryInvokeCommand(player, target, message)) {
|
||||||
CommandMap.getInstance().invoke(player, target, message.substring(1));
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -71,8 +79,7 @@ public class ChatManager implements ChatManagerHandler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Check if command
|
// Check if command
|
||||||
if (PREFIXES.contains(message.charAt(0))) {
|
if (tryInvokeCommand(player, null, message)) {
|
||||||
CommandMap.getInstance().invoke(player, null, message);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user