PlayerCommands.java 25.4 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
import emu.grasscutter.server.packet.send.PacketEntityFightPropUpdateNotify;
23
import emu.grasscutter.server.packet.send.PacketGetPlayerTokenRsp;
Melledy's avatar
Melledy committed
24
import emu.grasscutter.server.packet.send.PacketItemAddHintNotify;
25
import emu.grasscutter.server.packet.send.PacketPlayerLoginRsp;
Melledy's avatar
Melledy committed
26
27
import emu.grasscutter.utils.Position;

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

/**
 * A container for player-related commands.
 */
public final class PlayerCommands {
memetrollsXD's avatar
memetrollsXD committed
35
36
    @Command(label = "give", aliases = {"g", "item", "giveitem"}, 
            usage = "give [player] <itemId|itemName> [amount]", description = "Gives an item to you or the specified player", permission = "player.give")
KingRainbow44's avatar
KingRainbow44 committed
37
38
39
40
41
42
    public static class GiveCommand implements CommandHandler {

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

43
            switch (args.size()) {
KingRainbow44's avatar
KingRainbow44 committed
44
45
46
47
48
49
                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
50
                        target = player.getAccount().getPlayerId();
KingRainbow44's avatar
KingRainbow44 committed
51
52
53
54
55
56
57
58
59
                    } 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
60

61
62
63
                        if (Grasscutter.getGameServer().getPlayerByUid(target) == null) {
                            target = player.getUid();
                            amount = Integer.parseInt(args.get(1));
KingRainbow44's avatar
KingRainbow44 committed
64
65
66
67
68
69
70
71
72
73
74
75
76
                            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));
77
78
79
80

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

                        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;
            }

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

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

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

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

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

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

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

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

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

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

KingRainbow44's avatar
KingRainbow44 committed
145
146
        private void item(GenshinPlayer player, ItemData itemData, int amount) {
            GenshinItem genshinItem = new GenshinItem(itemData);
147
            if (itemData.isEquip()) {
KingRainbow44's avatar
KingRainbow44 committed
148
                List<GenshinItem> items = new LinkedList<>();
149
                for (int i = 0; i < amount; i++) {
KingRainbow44's avatar
KingRainbow44 committed
150
                    items.add(genshinItem);
151
152
                }
                player.getInventory().addItems(items);
KingRainbow44's avatar
KingRainbow44 committed
153
154
155
156
157
158
159
160
                player.sendPacket(new PacketItemAddHintNotify(items, ActionReason.SubfieldDrop));
            } else {
                genshinItem.setCount(amount);
                player.getInventory().addItem(genshinItem);
                player.sendPacket(new PacketItemAddHintNotify(genshinItem, ActionReason.SubfieldDrop));
            }
        }
    }
memetrollsXD's avatar
memetrollsXD committed
161
162
163
    @Command(label = "drop", aliases = {"d", "dropitem"}, 
            usage = "drop <itemId|itemName> [amount]",
            execution = Command.Execution.PLAYER, description = "Drops an item near you", permission = "server.drop")
KingRainbow44's avatar
KingRainbow44 committed
164
    public static class DropCommand implements CommandHandler {
165

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

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

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

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

memetrollsXD's avatar
memetrollsXD committed
204
205
    @Command(label = "givechar", aliases = { "givec" }, usage = "givechar <playerId> <avatarId> [level]",
            description = "Gives the player a specified character", permission = "player.givechar")
SpikeHD's avatar
SpikeHD committed
206
    public static class GiveCharCommand implements CommandHandler {
207
208
        @Override
        public void execute(GenshinPlayer player, List<String> args) {
KingRainbow44's avatar
KingRainbow44 committed
209
            int target, avatarId, level = 1, ascension = 1;
SpikeHD's avatar
SpikeHD committed
210

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

            switch (args.size()) {
217
                default:
218
                    CommandHandler.sendMessage(player, "Usage: givechar <player> <avatarId> [level]");
219
220
221
222
                    return;
                case 2:
                    try {
                        target = Integer.parseInt(args.get(0));
223
224
                        if (Grasscutter.getGameServer().getPlayerByUid(target) == null) {
                            target = player.getUid();
KingRainbow44's avatar
KingRainbow44 committed
225
                            level = Integer.parseInt(args.get(1));
KingRainbow44's avatar
KingRainbow44 committed
226
                            avatarId = Integer.parseInt(args.get(0));
227
                        } else {
KingRainbow44's avatar
KingRainbow44 committed
228
                            avatarId = Integer.parseInt(args.get(1));
229
230
231
232
233
234
235
236
237
238
                        }
                    } 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));
239
240
241
                        if (Grasscutter.getGameServer().getPlayerByUid(target) == null) {
                            CommandHandler.sendMessage(player, "Invalid player ID.");
                            return;
242
243
                        }

KingRainbow44's avatar
KingRainbow44 committed
244
                        avatarId = Integer.parseInt(args.get(1));
245
246
247
248
249
250
251
252
                        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
253

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

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

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

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

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

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

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

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

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

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

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

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

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

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

memetrollsXD's avatar
memetrollsXD committed
331
332
    @Command(label = "spawn", execution = Command.Execution.PLAYER, 
            usage = "spawn <entityId|entityName> [level] [amount]", description = "Spawns an entity near you", permission = "server.spawn")
KingRainbow44's avatar
KingRainbow44 committed
333
    public static class SpawnCommand implements CommandHandler {
334

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

KingRainbow44's avatar
KingRainbow44 committed
342
343
            try {
                int entity = Integer.parseInt(args.get(0));
344
345
346
347
348
349
                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));
350

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

KingRainbow44's avatar
KingRainbow44 committed
357
358
                float range = (5f + (.1f * amount));
                for (int i = 0; i < amount; i++) {
359
360
                    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
361
362
                    EntityMonster monster = new EntityMonster(player.getScene(), entityData, pos, level);
                    player.getScene().addEntity(monster);
KingRainbow44's avatar
KingRainbow44 committed
363
364
365
366
367
368
                }
            } catch (NumberFormatException ignored) {
                CommandHandler.sendMessage(null, "Invalid item or player ID.");
            }
        }
    }
memetrollsXD's avatar
memetrollsXD committed
369
370
371
    
    @Command(label = "killall", 
            usage = "killall [playerUid] [sceneId]", description = "Kill all entities", permission = "server.killall")
KingRainbow44's avatar
KingRainbow44 committed
372
    public static class KillAllCommand implements CommandHandler {
373

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

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

KingRainbow44's avatar
KingRainbow44 committed
390
            try {
391
                int playerUid = Integer.parseInt(args.get(0));
Melledy's avatar
Melledy committed
392
                int sceneId = Integer.parseInt(args.get(1));
393

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

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

Melledy's avatar
Melledy committed
406
407
408
409
                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
410
            } catch (NumberFormatException ignored) {
Melledy's avatar
Melledy committed
411
                CommandHandler.sendMessage(null, "Invalid arguments.");
KingRainbow44's avatar
KingRainbow44 committed
412
413
414
            }
        }
    }
415

memetrollsXD's avatar
memetrollsXD committed
416
417
418
    @Command(label = "resetconst", aliases = {"resetconstellation"}, 
            usage = "resetconst [all]", execution = Command.Execution.PLAYER, permission = "player.resetconstellation",
            description = "Resets the constellation level on your current active character, will need to relog after using the command to see any changes.")
KingRainbow44's avatar
KingRainbow44 committed
419
    public static class ResetConstellationCommand implements CommandHandler {
420

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

KingRainbow44's avatar
KingRainbow44 committed
431
432
                GenshinAvatar avatar = entity.getAvatar();
                this.resetConstellation(avatar);
433

434
435
                player.dropMessage("Constellations for " + avatar.getAvatarData().getName()
                        + " have been reset. Please relog to see changes.");
KingRainbow44's avatar
KingRainbow44 committed
436
437
            }
        }
438

KingRainbow44's avatar
KingRainbow44 committed
439
440
441
442
443
444
445
        private void resetConstellation(GenshinAvatar avatar) {
            avatar.getTalentIdList().clear();
            avatar.setCoreProudSkillLevel(0);
            avatar.recalcStats();
            avatar.save();
        }
    }
memetrollsXD's avatar
memetrollsXD committed
446
447
448
  
    @Command(label = "godmode",
            usage = "godmode", execution = Command.Execution.PLAYER, description = "Prevents you from taking damage", permission = "player.godmode")
KingRainbow44's avatar
KingRainbow44 committed
449
    public static class GodModeCommand implements CommandHandler {
450

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

memetrollsXD's avatar
memetrollsXD committed
458
459
460
    @Command(label = "sethealth", aliases = {"sethp"}, 
            usage = "sethealth <hp>", execution = Command.Execution.PLAYER, description = "Sets your health to the specified value",
            permission = "player.sethealth")
KingRainbow44's avatar
KingRainbow44 committed
461
    public static class SetHealthCommand implements CommandHandler {
462

KingRainbow44's avatar
KingRainbow44 committed
463
464
        @Override
        public void execute(GenshinPlayer player, List<String> args) {
465
466
467
            if (args.size() < 1) {
                CommandHandler.sendMessage(null, "Usage: sethealth <hp>");
                return;
KingRainbow44's avatar
KingRainbow44 committed
468
            }
469

KingRainbow44's avatar
KingRainbow44 committed
470
471
472
            try {
                int health = Integer.parseInt(args.get(0));
                EntityAvatar entity = player.getTeamManager().getCurrentAvatarEntity();
473
                if (entity == null)
KingRainbow44's avatar
KingRainbow44 committed
474
                    return;
475

KingRainbow44's avatar
KingRainbow44 committed
476
                entity.setFightProperty(FightProperty.FIGHT_PROP_CUR_HP, health);
477
478
                entity.getWorld().broadcastPacket(
                        new PacketEntityFightPropUpdateNotify(entity, FightProperty.FIGHT_PROP_CUR_HP));
KingRainbow44's avatar
KingRainbow44 committed
479
480
481
482
483
484
                player.dropMessage("Health set to " + health + ".");
            } catch (NumberFormatException ignored) {
                CommandHandler.sendMessage(null, "Invalid health value.");
            }
        }
    }
SpikeHD's avatar
SpikeHD committed
485

memetrollsXD's avatar
memetrollsXD committed
486
487
488
    @Command(label = "setworldlevel", aliases = {"setworldlvl"}, usage = "setworldlevel <level>",
            description = "Sets your world level (Relog to see proper effects)", permission = "player.setworldlevel",
            execution = Command.Execution.PLAYER)
SpikeHD's avatar
SpikeHD committed
489
490
491
    public static class SetWorldLevelCommand implements CommandHandler {
        @Override
        public void execute(GenshinPlayer player, List<String> args) {
492
493
494
            if (args.size() < 1) {
                CommandHandler.sendMessage(player, "Usage: setworldlevel <level>");
                return;
SpikeHD's avatar
SpikeHD committed
495
            }
496

SpikeHD's avatar
SpikeHD committed
497
498
499
500
501
502
503
504
505
506
507
508
509
            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.");
            }
        }
    }
memetrollsXD's avatar
memetrollsXD committed
510
511
512
513
  
    @Command(label = "clearartifacts", aliases = {"clearart"}, 
            usage = "clearartifacts", execution = Command.Execution.PLAYER, permission = "player.clearartifacts",
            description = "Deletes all unequipped and unlocked level 0 artifacts, including yellow rarity ones from your inventory")
KingRainbow44's avatar
KingRainbow44 committed
514
515
516
517
518
519
520
521
522
523
524
    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()));
        }
    }
525

memetrollsXD's avatar
memetrollsXD committed
526
527
    @Command(label = "changescene", aliases = {"scene"}, 
            usage = "changescene <scene id>", description = "Changes your scene", permission = "player.changescene", execution = Command.Execution.PLAYER)
Melledy's avatar
Melledy committed
528
529
530
    public static class ChangeSceneCommand implements CommandHandler {
        @Override
        public void execute(GenshinPlayer player, List<String> args) {
531
532
533
            if (args.size() < 1) {
                CommandHandler.sendMessage(player, "Usage: changescene <scene id>");
                return;
Melledy's avatar
Melledy committed
534
            }
535

Melledy's avatar
Melledy committed
536
            try {
KingRainbow44's avatar
KingRainbow44 committed
537
538
539
540
541
542
                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
543
            } catch (Exception e) {
544
545
                CommandHandler.sendMessage(player, "Usage: changescene <scene id>");
                return;
Melledy's avatar
Melledy committed
546
547
548
            }
        }
    }
549

memetrollsXD's avatar
memetrollsXD committed
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
    @Command(label = "sendservermessage", aliases = {"sendservmsg"},
            usage = "sendservermessage <player> <message>", description = "Sends a message to a player as the server",
            execution = Command.Execution.PLAYER, permission = "server.sendmessage")
    public static class SendServerMessageCommand implements CommandHandler {
        @Override
        public void execute(GenshinPlayer player, List<String> args) {
            if(args.size() < 2) {
                CommandHandler.sendMessage(null, "Usage: sendmessage <player> <message>"); return;
            }

            try {
                int target = Integer.parseInt(args.get(0));
                String message = String.join(" ", args.subList(1, args.size()));

                GenshinPlayer targetPlayer = Grasscutter.getGameServer().getPlayerByUid(target);
                if(targetPlayer == null) {
                    CommandHandler.sendMessage(null, "Player not found."); return;
                }

                targetPlayer.dropMessage(message);
                CommandHandler.sendMessage(null, "Message sent.");
            } catch (NumberFormatException ignored) {
                CommandHandler.sendMessage(null, "Invalid player ID.");
            }
        }
    }
alt3ri's avatar
alt3ri committed
576
577
578
579
580
581
582
583
584
585
586
    
    @Command(label = "pos",
            usage = "Usage: pos", description = "Get coordinates.",
            execution = Command.Execution.PLAYER)
    public static class CordCommand implements CommandHandler {
        
        @Override
        public void execute(GenshinPlayer player, List<String> args) {
            player.dropMessage(String.format("Coord: %.3f, %.3f, %.3f", player.getPos().getX(), player.getPos().getY(), player.getPos().getZ()));
        }
    }
587

memetrollsXD's avatar
memetrollsXD committed
588
589
    @Command(label = "restart", usage = "Usage: restart", description = "Restarts the current session", execution = Command.Execution.PLAYER, permission = "player.restart")
    public static class RestartCommand implements CommandHandler {
590
591
        @Override
        public void execute(GenshinPlayer player, List<String> args) {
592
            player.getSession().close();
593
594
        }
    }
Melledy's avatar
Melledy committed
595
}