mirror of
https://github.com/Grasscutters/Grasscutter.git
synced 2026-02-07 10:36:41 +01:00
Continue merging quests (pt. 2)
This commit is contained in:
@@ -1,57 +1,59 @@
|
||||
package emu.grasscutter.command;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.function.BiConsumer;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
public class CommandHelpers {
|
||||
public static final Pattern lvlRegex =
|
||||
Pattern.compile("(?<!\\w)l(?:vl?)?(\\d+)"); // Java doesn't have raw string literals :(
|
||||
public static final Pattern amountRegex =
|
||||
Pattern.compile("((?<=(?<!\\w)x)\\d+|\\d+(?=x)(?!x\\d))");
|
||||
public static final Pattern refineRegex = Pattern.compile("(?<!\\w)r(\\d+)");
|
||||
public static final Pattern rankRegex = Pattern.compile("(\\d+)\\*");
|
||||
public static final Pattern constellationRegex = Pattern.compile("(?<!\\w)c(\\d+)");
|
||||
public static final Pattern skillLevelRegex = Pattern.compile("sl(\\d+)");
|
||||
public static final Pattern stateRegex = Pattern.compile("state(\\d+)");
|
||||
public static final Pattern blockRegex = Pattern.compile("blk(\\d+)");
|
||||
public static final Pattern groupRegex = Pattern.compile("grp(\\d+)");
|
||||
public static final Pattern configRegex = Pattern.compile("cfg(\\d+)");
|
||||
public static final Pattern hpRegex = Pattern.compile("(?<!\\w)hp(\\d+)");
|
||||
public static final Pattern maxHPRegex = Pattern.compile("maxhp(\\d+)");
|
||||
public static final Pattern atkRegex = Pattern.compile("atk(\\d+)");
|
||||
public static final Pattern defRegex = Pattern.compile("def(\\d+)");
|
||||
public static final Pattern aiRegex = Pattern.compile("ai(\\d+)");
|
||||
|
||||
public static int matchIntOrNeg(Pattern pattern, String arg) {
|
||||
Matcher match = pattern.matcher(arg);
|
||||
if (match.find()) {
|
||||
return Integer.parseInt(
|
||||
match.group(
|
||||
1)); // This should be exception-safe as only \d+ can be passed to it (i.e. non-empty
|
||||
// string of pure digits)
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
public static <T> List<String> parseIntParameters(
|
||||
List<String> args, @Nonnull T params, Map<Pattern, BiConsumer<T, Integer>> map) {
|
||||
args.removeIf(
|
||||
arg -> {
|
||||
var argL = arg.toLowerCase();
|
||||
boolean deleteArg = false;
|
||||
for (var entry : map.entrySet()) {
|
||||
int argNum = matchIntOrNeg(entry.getKey(), argL);
|
||||
if (argNum != -1) {
|
||||
entry.getValue().accept(params, argNum);
|
||||
deleteArg = true;
|
||||
}
|
||||
}
|
||||
return deleteArg;
|
||||
});
|
||||
return args;
|
||||
}
|
||||
}
|
||||
package emu.grasscutter.command;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.function.BiConsumer;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
public class CommandHelpers {
|
||||
public static final Pattern lvlRegex =
|
||||
Pattern.compile("(?<!\\w)l(?:vl?)?(\\d+)"); // Java doesn't have raw string literals :(
|
||||
public static final Pattern amountRegex =
|
||||
Pattern.compile("((?<=(?<!\\w)x)\\d+|\\d+(?=x)(?!x\\d))");
|
||||
public static final Pattern refineRegex = Pattern.compile("(?<!\\w)r(\\d+)");
|
||||
public static final Pattern rankRegex = Pattern.compile("(\\d+)\\*");
|
||||
public static final Pattern constellationRegex = Pattern.compile("(?<!\\w)c(\\d+)");
|
||||
public static final Pattern skillLevelRegex = Pattern.compile("sl(\\d+)");
|
||||
public static final Pattern stateRegex = Pattern.compile("state(\\d+)");
|
||||
public static final Pattern blockRegex = Pattern.compile("blk(\\d+)");
|
||||
public static final Pattern groupRegex = Pattern.compile("grp(\\d+)");
|
||||
public static final Pattern configRegex = Pattern.compile("cfg(\\d+)");
|
||||
public static final Pattern hpRegex = Pattern.compile("(?<!\\w)hp(\\d+)");
|
||||
public static final Pattern maxHPRegex = Pattern.compile("maxhp(\\d+)");
|
||||
public static final Pattern atkRegex = Pattern.compile("atk(\\d+)");
|
||||
public static final Pattern defRegex = Pattern.compile("def(\\d+)");
|
||||
public static final Pattern aiRegex = Pattern.compile("ai(\\d+)");
|
||||
public static final Pattern sceneRegex = Pattern.compile("scene(\\d+)");
|
||||
public static final Pattern suiteRegex = Pattern.compile("suite(\\d+)");
|
||||
|
||||
public static int matchIntOrNeg(Pattern pattern, String arg) {
|
||||
Matcher match = pattern.matcher(arg);
|
||||
if (match.find()) {
|
||||
return Integer.parseInt(
|
||||
match.group(
|
||||
1)); // This should be exception-safe as only \d+ can be passed to it (i.e. non-empty
|
||||
// string of pure digits)
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
public static <T> List<String> parseIntParameters(
|
||||
List<String> args, @Nonnull T params, Map<Pattern, BiConsumer<T, Integer>> map) {
|
||||
args.removeIf(
|
||||
arg -> {
|
||||
var argL = arg.toLowerCase();
|
||||
boolean deleteArg = false;
|
||||
for (var entry : map.entrySet()) {
|
||||
int argNum = matchIntOrNeg(entry.getKey(), argL);
|
||||
if (argNum != -1) {
|
||||
entry.getValue().accept(params, argNum);
|
||||
deleteArg = true;
|
||||
}
|
||||
}
|
||||
return deleteArg;
|
||||
});
|
||||
return args;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
package emu.grasscutter.command.commands;
|
||||
|
||||
import emu.grasscutter.command.Command;
|
||||
import emu.grasscutter.command.CommandHandler;
|
||||
import emu.grasscutter.game.player.Player;
|
||||
import emu.grasscutter.server.packet.send.PacketCutsceneBeginNotify;
|
||||
import java.util.List;
|
||||
import lombok.val;
|
||||
|
||||
@Command(
|
||||
label = "cutscene",
|
||||
aliases = {"c"},
|
||||
usage = {"[<cutsceneId>]"},
|
||||
permission = "player.group",
|
||||
permissionTargeted = "player.group.others")
|
||||
public final class CutsceneCommand implements CommandHandler {
|
||||
|
||||
@Override
|
||||
public void execute(Player sender, Player targetPlayer, List<String> args) {
|
||||
if (args.isEmpty()) {
|
||||
sendUsageMessage(sender);
|
||||
return;
|
||||
}
|
||||
val cutSceneId = Integer.parseInt(args.get(0));
|
||||
targetPlayer.sendPacket(new PacketCutsceneBeginNotify(cutSceneId));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
package emu.grasscutter.command.commands;
|
||||
|
||||
import static emu.grasscutter.utils.Language.translate;
|
||||
|
||||
import emu.grasscutter.command.Command;
|
||||
import emu.grasscutter.command.CommandHandler;
|
||||
import emu.grasscutter.game.player.Player;
|
||||
import emu.grasscutter.server.packet.send.PacketScenePlayerSoundNotify;
|
||||
import emu.grasscutter.utils.Position;
|
||||
import java.util.List;
|
||||
import lombok.val;
|
||||
|
||||
@Command(
|
||||
label = "sound",
|
||||
aliases = {"s", "audio"},
|
||||
usage = {"[<audioname>] [<x><y><z>]"},
|
||||
permission = "player.group",
|
||||
permissionTargeted = "player.group.others")
|
||||
public final class SoundCommand implements CommandHandler {
|
||||
|
||||
@Override
|
||||
public void execute(Player sender, Player targetPlayer, List<String> args) {
|
||||
if (args.isEmpty()) {
|
||||
sendUsageMessage(sender);
|
||||
return;
|
||||
}
|
||||
val soundName = args.get(0);
|
||||
var playPosition = targetPlayer.getPosition();
|
||||
if (args.size() == 4) {
|
||||
try {
|
||||
float x, y, z;
|
||||
x = Float.parseFloat(args.get(1));
|
||||
y = Float.parseFloat(args.get(2));
|
||||
z = Float.parseFloat(args.get(3));
|
||||
playPosition = new Position(x, y, z);
|
||||
} catch (NumberFormatException ignored) {
|
||||
CommandHandler.sendMessage(sender, translate(sender, "commands.execution.argument_error"));
|
||||
return;
|
||||
}
|
||||
} else if (args.size() > 1) {
|
||||
sendUsageMessage(sender);
|
||||
return;
|
||||
}
|
||||
targetPlayer
|
||||
.getScene()
|
||||
.broadcastPacket(new PacketScenePlayerSoundNotify(playPosition, soundName, 1));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user