PlayerCommands.java 22.6 KB
Newer Older
Melledy's avatar
Melledy committed
1
2
package emu.grasscutter.commands;

KingRainbow44's avatar
KingRainbow44 committed
3
import emu.grasscutter.Grasscutter;
Melledy's avatar
Melledy committed
4
5
import emu.grasscutter.data.GenshinData;
import emu.grasscutter.data.def.ItemData;
6
import emu.grasscutter.data.def.AvatarData;
7
import emu.grasscutter.data.def.AvatarSkillDepotData;
Melledy's avatar
Melledy committed
8
9
import emu.grasscutter.data.def.MonsterData;
import emu.grasscutter.game.GenshinPlayer;
Melledy's avatar
Melledy committed
10
import emu.grasscutter.game.GenshinScene;
KingRainbow44's avatar
KingRainbow44 committed
11
import emu.grasscutter.game.World;
Melledy's avatar
Melledy committed
12
13
14
15
16
import emu.grasscutter.game.avatar.GenshinAvatar;
import emu.grasscutter.game.entity.EntityAvatar;
import emu.grasscutter.game.entity.EntityItem;
import emu.grasscutter.game.entity.EntityMonster;
import emu.grasscutter.game.inventory.GenshinItem;
KingRainbow44's avatar
KingRainbow44 committed
17
import emu.grasscutter.game.inventory.Inventory;
Melledy's avatar
Melledy committed
18
19
20
import emu.grasscutter.game.inventory.ItemType;
import emu.grasscutter.game.props.ActionReason;
import emu.grasscutter.game.props.FightProperty;
SpikeHD's avatar
SpikeHD committed
21
import emu.grasscutter.game.props.PlayerProperty;
Melledy's avatar
Melledy committed
22
23
import emu.grasscutter.server.packet.send.PacketEntityFightPropUpdateNotify;
import emu.grasscutter.server.packet.send.PacketItemAddHintNotify;
24
import emu.grasscutter.server.packet.send.PacketPlayerLoginRsp;
Melledy's avatar
Melledy committed
25
26
import emu.grasscutter.utils.Position;

KingRainbow44's avatar
KingRainbow44 committed
27
28
29
30
31
32
33
import java.util.LinkedList;
import java.util.List;

/**
 * A container for player-related commands.
 */
public final class PlayerCommands {
34
35
    @Command(label = "give", aliases = { "g", "item",
            "giveitem" }, usage = "Usage: give [player] <itemId|itemName> [amount]")
KingRainbow44's avatar
KingRainbow44 committed
36
37
38
39
40
41
    public static class GiveCommand implements CommandHandler {

        @Override
        public void execute(GenshinPlayer player, List<String> args) {
            int target, item, amount = 1;

42
            switch (args.size()) {
KingRainbow44's avatar
KingRainbow44 committed
43
44
45
46
47
48
                default:
                    CommandHandler.sendMessage(player, "Usage: give <player> <itemId|itemName> [amount]");
                    return;
                case 1:
                    try {
                        item = Integer.parseInt(args.get(0));
KingRainbow44's avatar
KingRainbow44 committed
49
                        target = player.getAccount().getPlayerId();
KingRainbow44's avatar
KingRainbow44 committed
50
51
52
53
54
55
56
57
58
                    } catch (NumberFormatException ignored) {
                        // TODO: Parse from item name using GM Handbook.
                        CommandHandler.sendMessage(player, "Invalid item id.");
                        return;
                    }
                    break;
                case 2:
                    try {
                        target = Integer.parseInt(args.get(0));
Melledy's avatar
Melledy committed
59

60
61
62
                        if (Grasscutter.getGameServer().getPlayerByUid(target) == null) {
                            target = player.getUid();
                            amount = Integer.parseInt(args.get(1));
KingRainbow44's avatar
KingRainbow44 committed
63
64
65
66
67
68
69
70
71
72
73
74
75
                            item = Integer.parseInt(args.get(0));
                        } else {
                            item = Integer.parseInt(args.get(1));
                        }
                    } catch (NumberFormatException ignored) {
                        // TODO: Parse from item name using GM Handbook.
                        CommandHandler.sendMessage(player, "Invalid item or player ID.");
                        return;
                    }
                    break;
                case 3:
                    try {
                        target = Integer.parseInt(args.get(0));
76
77
78
79

                        if (Grasscutter.getGameServer().getPlayerByUid(target) == null) {
                            CommandHandler.sendMessage(player, "Invalid player ID.");
                            return;
KingRainbow44's avatar
KingRainbow44 committed
80
81
82
83
84
85
86
87
88
89
90
91
                        }

                        item = Integer.parseInt(args.get(1));
                        amount = Integer.parseInt(args.get(2));
                    } catch (NumberFormatException ignored) {
                        // TODO: Parse from item name using GM Handbook.
                        CommandHandler.sendMessage(player, "Invalid item or player ID.");
                        return;
                    }
                    break;
            }

92
            GenshinPlayer targetPlayer = Grasscutter.getGameServer().getPlayerByUid(target);
Melledy's avatar
Melledy committed
93

94
95
96
            if (targetPlayer == null) {
                CommandHandler.sendMessage(player, "Player not found.");
                return;
KingRainbow44's avatar
KingRainbow44 committed
97
98
99
            }

            ItemData itemData = GenshinData.getItemDataMap().get(item);
100
101
102
            if (itemData == null) {
                CommandHandler.sendMessage(player, "Invalid item id.");
                return;
KingRainbow44's avatar
KingRainbow44 committed
103
            }
104

KingRainbow44's avatar
KingRainbow44 committed
105
106
107
108
109
110
            this.item(targetPlayer, itemData, amount);
        }

        /**
         * give [player] [itemId|itemName] [amount]
         */
111
112
113
        @Override
        public void execute(List<String> args) {
            if (args.size() < 2) {
KingRainbow44's avatar
KingRainbow44 committed
114
115
116
                CommandHandler.sendMessage(null, "Usage: give <player> <itemId|itemName> [amount]");
                return;
            }
117

KingRainbow44's avatar
KingRainbow44 committed
118
119
120
            try {
                int target = Integer.parseInt(args.get(0));
                int item = Integer.parseInt(args.get(1));
121
122
123
124
                int amount = 1;
                if (args.size() > 2)
                    amount = Integer.parseInt(args.get(2));

125
                GenshinPlayer targetPlayer = Grasscutter.getGameServer().getPlayerByUid(target);
Melledy's avatar
Melledy committed
126

127
128
129
                if (targetPlayer == null) {
                    CommandHandler.sendMessage(null, "Player not found.");
                    return;
KingRainbow44's avatar
KingRainbow44 committed
130
                }
131

KingRainbow44's avatar
KingRainbow44 committed
132
                ItemData itemData = GenshinData.getItemDataMap().get(item);
133
134
135
                if (itemData == null) {
                    CommandHandler.sendMessage(null, "Invalid item id.");
                    return;
KingRainbow44's avatar
KingRainbow44 committed
136
                }
137

KingRainbow44's avatar
KingRainbow44 committed
138
139
140
141
142
                this.item(targetPlayer, itemData, amount);
            } catch (NumberFormatException ignored) {
                CommandHandler.sendMessage(null, "Invalid item or player ID.");
            }
        }
143

KingRainbow44's avatar
KingRainbow44 committed
144
145
        private void item(GenshinPlayer player, ItemData itemData, int amount) {
            GenshinItem genshinItem = new GenshinItem(itemData);
146
            if (itemData.isEquip()) {
KingRainbow44's avatar
KingRainbow44 committed
147
                List<GenshinItem> items = new LinkedList<>();
148
                for (int i = 0; i < amount; i++) {
KingRainbow44's avatar
KingRainbow44 committed
149
                    items.add(genshinItem);
150
151
                }
                player.getInventory().addItems(items);
KingRainbow44's avatar
KingRainbow44 committed
152
153
154
155
156
157
158
159
                player.sendPacket(new PacketItemAddHintNotify(items, ActionReason.SubfieldDrop));
            } else {
                genshinItem.setCount(amount);
                player.getInventory().addItem(genshinItem);
                player.sendPacket(new PacketItemAddHintNotify(genshinItem, ActionReason.SubfieldDrop));
            }
        }
    }
160
161
162

    @Command(label = "drop", aliases = { "d",
            "dropitem" }, usage = "Usage: drop <itemId|itemName> [amount]", execution = Command.Execution.PLAYER)
KingRainbow44's avatar
KingRainbow44 committed
163
    public static class DropCommand implements CommandHandler {
164

KingRainbow44's avatar
KingRainbow44 committed
165
166
        @Override
        public void execute(GenshinPlayer player, List<String> args) {
167
            if (args.size() < 1) {
KingRainbow44's avatar
KingRainbow44 committed
168
                CommandHandler.sendMessage(player, "Usage: drop <itemId|itemName> [amount]");
KingRainbow44's avatar
KingRainbow44 committed
169
170
                return;
            }
171

KingRainbow44's avatar
KingRainbow44 committed
172
173
            try {
                int item = Integer.parseInt(args.get(0));
174
175
176
                int amount = 1;
                if (args.size() > 1)
                    amount = Integer.parseInt(args.get(1));
Melledy's avatar
Melledy committed
177

KingRainbow44's avatar
KingRainbow44 committed
178
                ItemData itemData = GenshinData.getItemDataMap().get(item);
179
180
181
                if (itemData == null) {
                    CommandHandler.sendMessage(player, "Invalid item id.");
                    return;
KingRainbow44's avatar
KingRainbow44 committed
182
                }
183

KingRainbow44's avatar
KingRainbow44 committed
184
185
186
                if (itemData.isEquip()) {
                    float range = (5f + (.1f * amount));
                    for (int i = 0; i < amount; i++) {
187
188
                        Position pos = player.getPos().clone().addX((float) (Math.random() * range) - (range / 2))
                                .addY(3f).addZ((float) (Math.random() * range) - (range / 2));
Melledy's avatar
Melledy committed
189
190
                        EntityItem entity = new EntityItem(player.getScene(), player, itemData, pos, 1);
                        player.getScene().addEntity(entity);
KingRainbow44's avatar
KingRainbow44 committed
191
192
                    }
                } else {
193
194
                    EntityItem entity = new EntityItem(player.getScene(), player, itemData,
                            player.getPos().clone().addY(3f), amount);
Melledy's avatar
Melledy committed
195
                    player.getScene().addEntity(entity);
KingRainbow44's avatar
KingRainbow44 committed
196
197
                }
            } catch (NumberFormatException ignored) {
KingRainbow44's avatar
KingRainbow44 committed
198
                CommandHandler.sendMessage(player, "Invalid item or player ID.");
KingRainbow44's avatar
KingRainbow44 committed
199
200
201
            }
        }
    }
SpikeHD's avatar
SpikeHD committed
202

203
204
    @Command(label = "givechar", aliases = {
            "givec" }, usage = "Usage: givechar <player|avatarId> [level|avatarId] [level]")
SpikeHD's avatar
SpikeHD committed
205
    public static class GiveCharCommand implements CommandHandler {
206
207
        @Override
        public void execute(GenshinPlayer player, List<String> args) {
KingRainbow44's avatar
KingRainbow44 committed
208
            int target, avatarId, level = 1, ascension = 1;
SpikeHD's avatar
SpikeHD committed
209

210
            if (args.size() < 1) {
KingRainbow44's avatar
KingRainbow44 committed
211
                CommandHandler.sendMessage(player, "Usage: givechar <player> <avatarId> [level]");
212
213
                return;
            }
214
215

            switch (args.size()) {
216
                default:
217
                    CommandHandler.sendMessage(player, "Usage: givechar <player> <avatarId> [level]");
218
219
220
221
                    return;
                case 2:
                    try {
                        target = Integer.parseInt(args.get(0));
222
223
                        if (Grasscutter.getGameServer().getPlayerByUid(target) == null) {
                            target = player.getUid();
KingRainbow44's avatar
KingRainbow44 committed
224
                            level = Integer.parseInt(args.get(1));
KingRainbow44's avatar
KingRainbow44 committed
225
                            avatarId = Integer.parseInt(args.get(0));
226
                        } else {
KingRainbow44's avatar
KingRainbow44 committed
227
                            avatarId = Integer.parseInt(args.get(1));
228
229
230
231
232
233
234
235
236
237
                        }
                    } catch (NumberFormatException ignored) {
                        // TODO: Parse from avatar name using GM Handbook.
                        CommandHandler.sendMessage(player, "Invalid avatar or player ID.");
                        return;
                    }
                    break;
                case 3:
                    try {
                        target = Integer.parseInt(args.get(0));
238
239
240
                        if (Grasscutter.getGameServer().getPlayerByUid(target) == null) {
                            CommandHandler.sendMessage(player, "Invalid player ID.");
                            return;
241
242
                        }

KingRainbow44's avatar
KingRainbow44 committed
243
                        avatarId = Integer.parseInt(args.get(1));
244
245
246
247
248
249
250
251
                        level = Integer.parseInt(args.get(2));
                    } catch (NumberFormatException ignored) {
                        // TODO: Parse from avatar name using GM Handbook.
                        CommandHandler.sendMessage(player, "Invalid avatar or player ID.");
                        return;
                    }
                    break;
            }
SpikeHD's avatar
SpikeHD committed
252

Melledy's avatar
Melledy committed
253
            GenshinPlayer targetPlayer = Grasscutter.getGameServer().getPlayerByUid(target);
254
255
256
            if (targetPlayer == null) {
                CommandHandler.sendMessage(player, "Player not found.");
                return;
SpikeHD's avatar
SpikeHD committed
257
            }
258

KingRainbow44's avatar
KingRainbow44 committed
259
            AvatarData avatarData = GenshinData.getAvatarDataMap().get(avatarId);
260
261
262
            if (avatarData == null) {
                CommandHandler.sendMessage(player, "Invalid avatar id.");
                return;
SpikeHD's avatar
SpikeHD committed
263
264
            }

265
266
            // Calculate ascension level.
            if (level <= 40) {
KingRainbow44's avatar
KingRainbow44 committed
267
268
269
                ascension = (int) Math.ceil(level / 20f);
            } else {
                ascension = (int) Math.ceil(level / 10f) - 3;
270
271
            }

KingRainbow44's avatar
KingRainbow44 committed
272
            GenshinAvatar avatar = new GenshinAvatar(avatarId);
SpikeHD's avatar
SpikeHD committed
273
            avatar.setLevel(level);
274
            avatar.setPromoteLevel(ascension);
275

276
277
            // This will handle stats and talents
            avatar.recalcStats();
278

279
280
            targetPlayer.addAvatar(avatar);
        }
SpikeHD's avatar
SpikeHD committed
281

282
283
        @Override
        public void execute(List<String> args) {
284
            if (args.size() < 2) {
SpikeHD's avatar
SpikeHD committed
285
                CommandHandler.sendMessage(null, "Usage: givechar <player> <itemId|itemName> [amount]");
286
287
288
289
290
291
                return;
            }

            try {
                int target = Integer.parseInt(args.get(0));
                int avatarID = Integer.parseInt(args.get(1));
292
293
294
                int level = 1;
                if (args.size() > 2)
                    level = Integer.parseInt(args.get(2));
KingRainbow44's avatar
KingRainbow44 committed
295
                int ascension;
296

Melledy's avatar
Melledy committed
297
                GenshinPlayer targetPlayer = Grasscutter.getGameServer().getPlayerByUid(target);
298
299
300
                if (targetPlayer == null) {
                    CommandHandler.sendMessage(null, "Player not found.");
                    return;
301
                }
302

303
                AvatarData avatarData = GenshinData.getAvatarDataMap().get(avatarID);
304
305
306
                if (avatarData == null) {
                    CommandHandler.sendMessage(null, "Invalid avatar id.");
                    return;
307
                }
308

309
310
                // Calculate ascension level.
                if (level <= 40) {
KingRainbow44's avatar
KingRainbow44 committed
311
312
313
                    ascension = (int) Math.ceil(level / 20f);
                } else {
                    ascension = (int) Math.ceil(level / 10f) - 3;
314
                }
315

316
317
                GenshinAvatar avatar = new GenshinAvatar(avatarID);
                avatar.setLevel(level);
318
                avatar.setPromoteLevel(ascension);
319
320
321

                // This will handle stats and talents
                avatar.recalcStats();
322

323
324
325
326
                targetPlayer.addAvatar(avatar);
            } catch (NumberFormatException ignored) {
                CommandHandler.sendMessage(null, "Invalid item or player ID.");
            }
SpikeHD's avatar
SpikeHD committed
327
328
        }
    }
Melledy's avatar
Melledy committed
329

330
    @Command(label = "spawn", execution = Command.Execution.PLAYER, usage = "Usage: spawn <entityId|entityName> [level] [amount]")
KingRainbow44's avatar
KingRainbow44 committed
331
    public static class SpawnCommand implements CommandHandler {
332

KingRainbow44's avatar
KingRainbow44 committed
333
334
        @Override
        public void execute(GenshinPlayer player, List<String> args) {
335
            if (args.size() < 1) {
KingRainbow44's avatar
KingRainbow44 committed
336
337
338
                CommandHandler.sendMessage(null, "Usage: spawn <entityId|entityName> [amount]");
                return;
            }
339

KingRainbow44's avatar
KingRainbow44 committed
340
341
            try {
                int entity = Integer.parseInt(args.get(0));
342
343
344
345
346
347
                int level = 1;
                if (args.size() > 1)
                    level = Integer.parseInt(args.get(1));
                int amount = 1;
                if (args.size() > 2)
                    amount = Integer.parseInt(args.get(2));
348

KingRainbow44's avatar
KingRainbow44 committed
349
                MonsterData entityData = GenshinData.getMonsterDataMap().get(entity);
350
351
352
                if (entityData == null) {
                    CommandHandler.sendMessage(null, "Invalid entity id.");
                    return;
KingRainbow44's avatar
KingRainbow44 committed
353
                }
354

KingRainbow44's avatar
KingRainbow44 committed
355
356
                float range = (5f + (.1f * amount));
                for (int i = 0; i < amount; i++) {
357
358
                    Position pos = player.getPos().clone().addX((float) (Math.random() * range) - (range / 2)).addY(3f)
                            .addZ((float) (Math.random() * range) - (range / 2));
Melledy's avatar
Melledy committed
359
360
                    EntityMonster monster = new EntityMonster(player.getScene(), entityData, pos, level);
                    player.getScene().addEntity(monster);
KingRainbow44's avatar
KingRainbow44 committed
361
362
363
364
365
366
                }
            } catch (NumberFormatException ignored) {
                CommandHandler.sendMessage(null, "Invalid item or player ID.");
            }
        }
    }
367
368

    @Command(label = "killall", usage = "Usage: killall [playerUid] [sceneId]")
KingRainbow44's avatar
KingRainbow44 committed
369
    public static class KillAllCommand implements CommandHandler {
370

KingRainbow44's avatar
KingRainbow44 committed
371
372
        @Override
        public void execute(GenshinPlayer player, List<String> args) {
Melledy's avatar
Melledy committed
373
374
            GenshinScene scene = player.getScene();
            scene.getEntities().values().stream()
KingRainbow44's avatar
KingRainbow44 committed
375
                    .filter(entity -> entity instanceof EntityMonster)
Melledy's avatar
Melledy committed
376
377
                    .forEach(entity -> scene.killEntity(entity, 0));
            CommandHandler.sendMessage(null, "Killing all monsters in scene " + scene.getId());
KingRainbow44's avatar
KingRainbow44 committed
378
        }
379

KingRainbow44's avatar
KingRainbow44 committed
380
381
        @Override
        public void execute(List<String> args) {
382
383
384
            if (args.size() < 2) {
                CommandHandler.sendMessage(null, "Usage: killall [playerUid] [sceneId]");
                return;
KingRainbow44's avatar
KingRainbow44 committed
385
            }
386

KingRainbow44's avatar
KingRainbow44 committed
387
            try {
388
                int playerUid = Integer.parseInt(args.get(0));
Melledy's avatar
Melledy committed
389
                int sceneId = Integer.parseInt(args.get(1));
390

391
                GenshinPlayer player = Grasscutter.getGameServer().getPlayerByUid(playerUid);
Melledy's avatar
Melledy committed
392
                if (player == null) {
393
394
                    CommandHandler.sendMessage(null, "Player not found or offline.");
                    return;
Melledy's avatar
Melledy committed
395
                }
396

Melledy's avatar
Melledy committed
397
398
                GenshinScene scene = player.getWorld().getSceneById(sceneId);
                if (scene == null) {
399
400
                    CommandHandler.sendMessage(null, "Scene not found in player world");
                    return;
Melledy's avatar
Melledy committed
401
                }
402

Melledy's avatar
Melledy committed
403
404
405
406
                scene.getEntities().values().stream()
                        .filter(entity -> entity instanceof EntityMonster)
                        .forEach(entity -> scene.killEntity(entity, 0));
                CommandHandler.sendMessage(null, "Killing all monsters in scene " + scene.getId());
KingRainbow44's avatar
KingRainbow44 committed
407
            } catch (NumberFormatException ignored) {
Melledy's avatar
Melledy committed
408
                CommandHandler.sendMessage(null, "Invalid arguments.");
KingRainbow44's avatar
KingRainbow44 committed
409
410
411
            }
        }
    }
412
413
414

    @Command(label = "resetconst", aliases = {
            "resetconstellation" }, usage = "Usage: resetconst [all]", execution = Command.Execution.PLAYER)
KingRainbow44's avatar
KingRainbow44 committed
415
    public static class ResetConstellationCommand implements CommandHandler {
416

KingRainbow44's avatar
KingRainbow44 committed
417
418
        @Override
        public void execute(GenshinPlayer player, List<String> args) {
419
            if (args.size() > 0 && args.get(0).equalsIgnoreCase("all")) {
KingRainbow44's avatar
KingRainbow44 committed
420
421
422
                player.getAvatars().forEach(this::resetConstellation);
                player.dropMessage("Reset all avatars' constellations.");
            } else {
423
424
                EntityAvatar entity = player.getTeamManager().getCurrentAvatarEntity();
                if (entity == null)
KingRainbow44's avatar
KingRainbow44 committed
425
                    return;
426

KingRainbow44's avatar
KingRainbow44 committed
427
428
                GenshinAvatar avatar = entity.getAvatar();
                this.resetConstellation(avatar);
429

430
431
                player.dropMessage("Constellations for " + avatar.getAvatarData().getName()
                        + " have been reset. Please relog to see changes.");
KingRainbow44's avatar
KingRainbow44 committed
432
433
            }
        }
434

KingRainbow44's avatar
KingRainbow44 committed
435
436
437
438
439
440
441
        private void resetConstellation(GenshinAvatar avatar) {
            avatar.getTalentIdList().clear();
            avatar.setCoreProudSkillLevel(0);
            avatar.recalcStats();
            avatar.save();
        }
    }
442
443

    @Command(label = "godmode", usage = "Usage: godmode", execution = Command.Execution.PLAYER)
KingRainbow44's avatar
KingRainbow44 committed
444
    public static class GodModeCommand implements CommandHandler {
445

KingRainbow44's avatar
KingRainbow44 committed
446
447
448
449
450
451
        @Override
        public void execute(GenshinPlayer player, List<String> args) {
            player.setGodmode(!player.inGodmode());
            player.dropMessage("Godmode is now " + (player.inGodmode() ? "enabled" : "disabled") + ".");
        }
    }
452
453
454

    @Command(label = "sethealth", aliases = {
            "sethp" }, usage = "Usage: sethealth <hp>", execution = Command.Execution.PLAYER)
KingRainbow44's avatar
KingRainbow44 committed
455
    public static class SetHealthCommand implements CommandHandler {
456

KingRainbow44's avatar
KingRainbow44 committed
457
458
        @Override
        public void execute(GenshinPlayer player, List<String> args) {
459
460
461
            if (args.size() < 1) {
                CommandHandler.sendMessage(null, "Usage: sethealth <hp>");
                return;
KingRainbow44's avatar
KingRainbow44 committed
462
            }
463

KingRainbow44's avatar
KingRainbow44 committed
464
465
466
            try {
                int health = Integer.parseInt(args.get(0));
                EntityAvatar entity = player.getTeamManager().getCurrentAvatarEntity();
467
                if (entity == null)
KingRainbow44's avatar
KingRainbow44 committed
468
                    return;
469

KingRainbow44's avatar
KingRainbow44 committed
470
                entity.setFightProperty(FightProperty.FIGHT_PROP_CUR_HP, health);
471
472
                entity.getWorld().broadcastPacket(
                        new PacketEntityFightPropUpdateNotify(entity, FightProperty.FIGHT_PROP_CUR_HP));
KingRainbow44's avatar
KingRainbow44 committed
473
474
475
476
477
478
                player.dropMessage("Health set to " + health + ".");
            } catch (NumberFormatException ignored) {
                CommandHandler.sendMessage(null, "Invalid health value.");
            }
        }
    }
SpikeHD's avatar
SpikeHD committed
479

480
481
    @Command(label = "setworldlevel", aliases = {
            "setworldlvl" }, usage = "Usage: setworldlevel <level>", execution = Command.Execution.PLAYER)
SpikeHD's avatar
SpikeHD committed
482
483
484
    public static class SetWorldLevelCommand implements CommandHandler {
        @Override
        public void execute(GenshinPlayer player, List<String> args) {
485
486
487
            if (args.size() < 1) {
                CommandHandler.sendMessage(player, "Usage: setworldlevel <level>");
                return;
SpikeHD's avatar
SpikeHD committed
488
            }
489

SpikeHD's avatar
SpikeHD committed
490
491
492
493
494
495
496
497
498
499
500
501
502
            try {
                int level = Integer.parseInt(args.get(0));

                // Set in both world and player props
                player.getWorld().setWorldLevel(level);
                player.setProperty(PlayerProperty.PROP_PLAYER_WORLD_LEVEL, level);

                player.dropMessage("World level set to " + level + ".");
            } catch (NumberFormatException ignored) {
                CommandHandler.sendMessage(null, "Invalid world level.");
            }
        }
    }
503
504
505

    @Command(label = "clearartifacts", aliases = {
            "clearart" }, usage = "Usage: clearartifacts", execution = Command.Execution.PLAYER)
KingRainbow44's avatar
KingRainbow44 committed
506
507
508
509
510
511
512
513
514
515
516
    public static class ClearArtifactsCommand implements CommandHandler {
        @Override
        public void execute(GenshinPlayer player, List<String> args) {
            Inventory playerInventory = player.getInventory();
            playerInventory.getItems().values().stream()
                    .filter(item -> item.getItemType() == ItemType.ITEM_RELIQUARY)
                    .filter(item -> item.getLevel() == 1 && item.getExp() == 0)
                    .filter(item -> !item.isLocked() && !item.isEquipped())
                    .forEach(item -> playerInventory.removeItem(item, item.getCount()));
        }
    }
517

518
519
    @Command(label = "changescene", aliases = {
            "scene" }, usage = "Usage: changescene <scene id>", execution = Command.Execution.PLAYER)
Melledy's avatar
Melledy committed
520
521
522
    public static class ChangeSceneCommand implements CommandHandler {
        @Override
        public void execute(GenshinPlayer player, List<String> args) {
523
524
525
            if (args.size() < 1) {
                CommandHandler.sendMessage(player, "Usage: changescene <scene id>");
                return;
Melledy's avatar
Melledy committed
526
            }
527

Melledy's avatar
Melledy committed
528
            try {
KingRainbow44's avatar
KingRainbow44 committed
529
530
531
532
533
534
                int sceneId = Integer.parseInt(args.get(0));
                boolean result = player.getWorld().transferPlayerToScene(player, sceneId, player.getPos());

                if (!result) {
                    CommandHandler.sendMessage(null, "Scene does not exist or you are already in it");
                }
Melledy's avatar
Melledy committed
535
            } catch (Exception e) {
536
537
                CommandHandler.sendMessage(player, "Usage: changescene <scene id>");
                return;
Melledy's avatar
Melledy committed
538
539
540
            }
        }
    }
541
542
543
544
545
546
547
548
549

    @Command(label = "restart", usage = "Usage: restart - Restarts the current session", execution = Command.Execution.PLAYER)
    public static class RestartCommand implements CommandHandler {

        @Override
        public void execute(GenshinPlayer player, List<String> args) {
            player.getSession().close();
        }
    }
Melledy's avatar
Melledy committed
550
}