diff --git a/src/main/java/emu/grasscutter/command/commands/Account.java b/src/main/java/emu/grasscutter/command/commands/AccountCommand.java similarity index 95% rename from src/main/java/emu/grasscutter/command/commands/Account.java rename to src/main/java/emu/grasscutter/command/commands/AccountCommand.java index cd2978feb..2c21cba79 100644 --- a/src/main/java/emu/grasscutter/command/commands/Account.java +++ b/src/main/java/emu/grasscutter/command/commands/AccountCommand.java @@ -1,62 +1,62 @@ -package emu.grasscutter.command.commands; - -import emu.grasscutter.command.Command; -import emu.grasscutter.command.CommandHandler; -import emu.grasscutter.database.DatabaseHelper; -import emu.grasscutter.game.GenshinPlayer; - -import java.util.List; - -@Command(label = "account", usage = "account [uid]", - description = "Modify user accounts") -public class Account implements CommandHandler { - - @Override - public void execute(GenshinPlayer sender, List args) { - if (sender != null) { - CommandHandler.sendMessage(sender, "This command can only be run from the console."); - return; - } - - if (args.size() < 2) { - CommandHandler.sendMessage(null, "Usage: account [uid]"); - return; - } - - String action = args.get(0); - String username = args.get(1); - - switch (action) { - default: - CommandHandler.sendMessage(null, "Usage: account [uid]"); - return; - case "create": - int uid = 0; - if (args.size() > 2) { - try { - uid = Integer.parseInt(args.get(2)); - } catch (NumberFormatException ignored) { - CommandHandler.sendMessage(null, "Invalid UID."); - return; - } - } - - emu.grasscutter.game.Account account = DatabaseHelper.createAccountWithId(username, uid); - if (account == null) { - CommandHandler.sendMessage(null, "Account already exists."); - return; - } else { - CommandHandler.sendMessage(null, "Account created with UID " + account.getPlayerId() + "."); - account.addPermission("*"); // Grant the player superuser permissions. - account.save(); // Save account to database. - } - return; - case "delete": - if (DatabaseHelper.deleteAccount(username)) { - CommandHandler.sendMessage(null, "Account deleted."); - } else { - CommandHandler.sendMessage(null, "Account not found."); - } - } - } -} +package emu.grasscutter.command.commands; + +import emu.grasscutter.command.Command; +import emu.grasscutter.command.CommandHandler; +import emu.grasscutter.database.DatabaseHelper; +import emu.grasscutter.game.GenshinPlayer; + +import java.util.List; + +@Command(label = "account", usage = "account [uid]", + description = "Modify user accounts") +public final class AccountCommand implements CommandHandler { + + @Override + public void execute(GenshinPlayer sender, List args) { + if (sender != null) { + CommandHandler.sendMessage(sender, "This command can only be run from the console."); + return; + } + + if (args.size() < 2) { + CommandHandler.sendMessage(null, "Usage: account [uid]"); + return; + } + + String action = args.get(0); + String username = args.get(1); + + switch (action) { + default: + CommandHandler.sendMessage(null, "Usage: account [uid]"); + return; + case "create": + int uid = 0; + if (args.size() > 2) { + try { + uid = Integer.parseInt(args.get(2)); + } catch (NumberFormatException ignored) { + CommandHandler.sendMessage(null, "Invalid UID."); + return; + } + } + + emu.grasscutter.game.Account account = DatabaseHelper.createAccountWithId(username, uid); + if (account == null) { + CommandHandler.sendMessage(null, "Account already exists."); + return; + } else { + CommandHandler.sendMessage(null, "Account created with UID " + account.getPlayerId() + "."); + account.addPermission("*"); // Grant the player superuser permissions. + account.save(); // Save account to database. + } + return; + case "delete": + if (DatabaseHelper.deleteAccount(username)) { + CommandHandler.sendMessage(null, "Account deleted."); + } else { + CommandHandler.sendMessage(null, "Account not found."); + } + } + } +} diff --git a/src/main/java/emu/grasscutter/command/commands/Broadcast.java b/src/main/java/emu/grasscutter/command/commands/BroadcastCommand.java similarity index 91% rename from src/main/java/emu/grasscutter/command/commands/Broadcast.java rename to src/main/java/emu/grasscutter/command/commands/BroadcastCommand.java index 7659fed9e..4922f16f8 100644 --- a/src/main/java/emu/grasscutter/command/commands/Broadcast.java +++ b/src/main/java/emu/grasscutter/command/commands/BroadcastCommand.java @@ -1,29 +1,29 @@ -package emu.grasscutter.command.commands; - -import emu.grasscutter.Grasscutter; -import emu.grasscutter.command.Command; -import emu.grasscutter.command.CommandHandler; -import emu.grasscutter.game.GenshinPlayer; - -import java.util.List; - -@Command(label = "broadcast", usage = "broadcast ", - description = "Sends a message to all the players", aliases = {"b"}, permission = "server.broadcast") -public class Broadcast implements CommandHandler { - - @Override - public void execute(GenshinPlayer sender, List args) { - if (args.size() < 1) { - CommandHandler.sendMessage(sender, "Usage: broadcast "); - return; - } - - String message = String.join(" ", args.subList(0, args.size())); - - for (GenshinPlayer p : Grasscutter.getGameServer().getPlayers().values()) { - CommandHandler.sendMessage(p, message); - } - - CommandHandler.sendMessage(sender, "Message sent."); - } -} +package emu.grasscutter.command.commands; + +import emu.grasscutter.Grasscutter; +import emu.grasscutter.command.Command; +import emu.grasscutter.command.CommandHandler; +import emu.grasscutter.game.GenshinPlayer; + +import java.util.List; + +@Command(label = "broadcast", usage = "broadcast ", + description = "Sends a message to all the players", aliases = {"b"}, permission = "server.broadcast") +public final class BroadcastCommand implements CommandHandler { + + @Override + public void execute(GenshinPlayer sender, List args) { + if (args.size() < 1) { + CommandHandler.sendMessage(sender, "Usage: broadcast "); + return; + } + + String message = String.join(" ", args.subList(0, args.size())); + + for (GenshinPlayer p : Grasscutter.getGameServer().getPlayers().values()) { + CommandHandler.sendMessage(p, message); + } + + CommandHandler.sendMessage(sender, "Message sent."); + } +} diff --git a/src/main/java/emu/grasscutter/command/commands/ChangeScene.java b/src/main/java/emu/grasscutter/command/commands/ChangeSceneCommand.java similarity index 93% rename from src/main/java/emu/grasscutter/command/commands/ChangeScene.java rename to src/main/java/emu/grasscutter/command/commands/ChangeSceneCommand.java index 196c7fea7..a5afe7bf7 100644 --- a/src/main/java/emu/grasscutter/command/commands/ChangeScene.java +++ b/src/main/java/emu/grasscutter/command/commands/ChangeSceneCommand.java @@ -1,36 +1,36 @@ -package emu.grasscutter.command.commands; - -import emu.grasscutter.command.Command; -import emu.grasscutter.command.CommandHandler; -import emu.grasscutter.game.GenshinPlayer; - -import java.util.List; - -@Command(label = "changescene", usage = "changescene ", - description = "Changes your scene", aliases = {"scene"}, permission = "player.changescene") -public class ChangeScene implements CommandHandler { - @Override - public void execute(GenshinPlayer sender, List args) { - if (sender == null) { - CommandHandler.sendMessage(null, "Run this command in-game."); - return; - } - - if (args.size() < 1) { - CommandHandler.sendMessage(sender, "Usage: changescene "); - return; - } - - try { - int sceneId = Integer.parseInt(args.get(0)); - boolean result = sender.getWorld().transferPlayerToScene(sender, sceneId, sender.getPos()); - - CommandHandler.sendMessage(sender, "Changed to scene " + sceneId); - if (!result) { - CommandHandler.sendMessage(sender, "Scene does not exist or you are already in it"); - } - } catch (Exception e) { - CommandHandler.sendMessage(sender, "Usage: changescene "); - } - } -} +package emu.grasscutter.command.commands; + +import emu.grasscutter.command.Command; +import emu.grasscutter.command.CommandHandler; +import emu.grasscutter.game.GenshinPlayer; + +import java.util.List; + +@Command(label = "changescene", usage = "changescene ", + description = "Changes your scene", aliases = {"scene"}, permission = "player.changescene") +public final class ChangeSceneCommand implements CommandHandler { + @Override + public void execute(GenshinPlayer sender, List args) { + if (sender == null) { + CommandHandler.sendMessage(null, "Run this command in-game."); + return; + } + + if (args.size() < 1) { + CommandHandler.sendMessage(sender, "Usage: changescene "); + return; + } + + try { + int sceneId = Integer.parseInt(args.get(0)); + boolean result = sender.getWorld().transferPlayerToScene(sender, sceneId, sender.getPos()); + + CommandHandler.sendMessage(sender, "Changed to scene " + sceneId); + if (!result) { + CommandHandler.sendMessage(sender, "Scene does not exist or you are already in it"); + } + } catch (Exception e) { + CommandHandler.sendMessage(sender, "Usage: changescene "); + } + } +} diff --git a/src/main/java/emu/grasscutter/command/commands/ClearArtifacts.java b/src/main/java/emu/grasscutter/command/commands/ClearArtifactsCommand.java similarity index 93% rename from src/main/java/emu/grasscutter/command/commands/ClearArtifacts.java rename to src/main/java/emu/grasscutter/command/commands/ClearArtifactsCommand.java index 8a46760dd..258e1e1d5 100644 --- a/src/main/java/emu/grasscutter/command/commands/ClearArtifacts.java +++ b/src/main/java/emu/grasscutter/command/commands/ClearArtifactsCommand.java @@ -1,30 +1,30 @@ -package emu.grasscutter.command.commands; - -import emu.grasscutter.command.Command; -import emu.grasscutter.command.CommandHandler; -import emu.grasscutter.game.GenshinPlayer; -import emu.grasscutter.game.inventory.Inventory; -import emu.grasscutter.game.inventory.ItemType; - -import java.util.List; - -@Command(label = "clearartifacts", usage = "clearartifacts", - description = "Deletes all unequipped and unlocked level 0 artifacts, including yellow rarity ones from your inventory", - aliases = {"clearart"}, permission = "player.clearartifacts") -public class ClearArtifacts implements CommandHandler { - - @Override - public void execute(GenshinPlayer sender, List args) { - if (sender == null) { - CommandHandler.sendMessage(null, "Run this command in-game."); - return; // TODO: clear player's artifacts from console or other players - } - - Inventory playerInventory = sender.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())); - } -} +package emu.grasscutter.command.commands; + +import emu.grasscutter.command.Command; +import emu.grasscutter.command.CommandHandler; +import emu.grasscutter.game.GenshinPlayer; +import emu.grasscutter.game.inventory.Inventory; +import emu.grasscutter.game.inventory.ItemType; + +import java.util.List; + +@Command(label = "clearartifacts", usage = "clearartifacts", + description = "Deletes all unequipped and unlocked level 0 artifacts, including yellow rarity ones from your inventory", + aliases = {"clearart"}, permission = "player.clearartifacts") +public final class ClearArtifactsCommand implements CommandHandler { + + @Override + public void execute(GenshinPlayer sender, List args) { + if (sender == null) { + CommandHandler.sendMessage(null, "Run this command in-game."); + return; // TODO: clear player's artifacts from console or other players + } + + Inventory playerInventory = sender.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())); + } +} diff --git a/src/main/java/emu/grasscutter/command/commands/Drop.java b/src/main/java/emu/grasscutter/command/commands/DropCommand.java similarity index 95% rename from src/main/java/emu/grasscutter/command/commands/Drop.java rename to src/main/java/emu/grasscutter/command/commands/DropCommand.java index 21db96881..e2d7644a0 100644 --- a/src/main/java/emu/grasscutter/command/commands/Drop.java +++ b/src/main/java/emu/grasscutter/command/commands/DropCommand.java @@ -1,56 +1,56 @@ -package emu.grasscutter.command.commands; - -import emu.grasscutter.command.Command; -import emu.grasscutter.command.CommandHandler; -import emu.grasscutter.data.GenshinData; -import emu.grasscutter.data.def.ItemData; -import emu.grasscutter.game.GenshinPlayer; -import emu.grasscutter.game.entity.EntityItem; -import emu.grasscutter.utils.Position; - -import java.util.List; - -@Command(label = "drop", usage = "drop [amount]", - description = "Drops an item near you", aliases = {"d", "dropitem"}, permission = "server.drop") -public class Drop implements CommandHandler { - - @Override - public void execute(GenshinPlayer sender, List args) { - if (sender == null) { - CommandHandler.sendMessage(null, "Run this command in-game."); - return; - } - - if (args.size() < 1) { - CommandHandler.sendMessage(sender, "Usage: drop [amount]"); - return; - } - - try { - int item = Integer.parseInt(args.get(0)); - int amount = 1; - if (args.size() > 1) amount = Integer.parseInt(args.get(1)); - - ItemData itemData = GenshinData.getItemDataMap().get(item); - if (itemData == null) { - CommandHandler.sendMessage(sender, "Invalid item id."); - return; - } - - if (itemData.isEquip()) { - float range = (5f + (.1f * amount)); - for (int i = 0; i < amount; i++) { - Position pos = sender.getPos().clone().addX((float) (Math.random() * range) - (range / 2)).addY(3f).addZ((float) (Math.random() * range) - (range / 2)); - EntityItem entity = new EntityItem(sender.getScene(), sender, itemData, pos, 1); - sender.getScene().addEntity(entity); - } - } else { - EntityItem entity = new EntityItem(sender.getScene(), sender, itemData, sender.getPos().clone().addY(3f), amount); - sender.getScene().addEntity(entity); - } - CommandHandler.sendMessage(sender, String.format("Dropped %s of %s.", amount, item)); - } catch (NumberFormatException ignored) { - CommandHandler.sendMessage(sender, "Invalid item or player ID."); - } - } +package emu.grasscutter.command.commands; + +import emu.grasscutter.command.Command; +import emu.grasscutter.command.CommandHandler; +import emu.grasscutter.data.GenshinData; +import emu.grasscutter.data.def.ItemData; +import emu.grasscutter.game.GenshinPlayer; +import emu.grasscutter.game.entity.EntityItem; +import emu.grasscutter.utils.Position; + +import java.util.List; + +@Command(label = "drop", usage = "drop [amount]", + description = "Drops an item near you", aliases = {"d", "dropitem"}, permission = "server.drop") +public final class DropCommand implements CommandHandler { + + @Override + public void execute(GenshinPlayer sender, List args) { + if (sender == null) { + CommandHandler.sendMessage(null, "Run this command in-game."); + return; + } + + if (args.size() < 1) { + CommandHandler.sendMessage(sender, "Usage: drop [amount]"); + return; + } + + try { + int item = Integer.parseInt(args.get(0)); + int amount = 1; + if (args.size() > 1) amount = Integer.parseInt(args.get(1)); + + ItemData itemData = GenshinData.getItemDataMap().get(item); + if (itemData == null) { + CommandHandler.sendMessage(sender, "Invalid item id."); + return; + } + + if (itemData.isEquip()) { + float range = (5f + (.1f * amount)); + for (int i = 0; i < amount; i++) { + Position pos = sender.getPos().clone().addX((float) (Math.random() * range) - (range / 2)).addY(3f).addZ((float) (Math.random() * range) - (range / 2)); + EntityItem entity = new EntityItem(sender.getScene(), sender, itemData, pos, 1); + sender.getScene().addEntity(entity); + } + } else { + EntityItem entity = new EntityItem(sender.getScene(), sender, itemData, sender.getPos().clone().addY(3f), amount); + sender.getScene().addEntity(entity); + } + CommandHandler.sendMessage(sender, String.format("Dropped %s of %s.", amount, item)); + } catch (NumberFormatException ignored) { + CommandHandler.sendMessage(sender, "Invalid item or player ID."); + } + } } \ No newline at end of file diff --git a/src/main/java/emu/grasscutter/command/commands/GiveChar.java b/src/main/java/emu/grasscutter/command/commands/GiveCharCommand.java similarity index 96% rename from src/main/java/emu/grasscutter/command/commands/GiveChar.java rename to src/main/java/emu/grasscutter/command/commands/GiveCharCommand.java index 9c9d87fb5..bfe0f51c0 100644 --- a/src/main/java/emu/grasscutter/command/commands/GiveChar.java +++ b/src/main/java/emu/grasscutter/command/commands/GiveCharCommand.java @@ -1,93 +1,93 @@ -package emu.grasscutter.command.commands; - -import emu.grasscutter.Grasscutter; -import emu.grasscutter.command.Command; -import emu.grasscutter.command.CommandHandler; -import emu.grasscutter.data.GenshinData; -import emu.grasscutter.data.def.AvatarData; -import emu.grasscutter.game.GenshinPlayer; -import emu.grasscutter.game.avatar.GenshinAvatar; - -import java.util.List; - -@Command(label = "givechar", usage = "givechar [level]", - description = "Gives the player a specified character", aliases = {"givec"}, permission = "player.givechar") -public class GiveChar implements CommandHandler { - - @Override - public void execute(GenshinPlayer sender, List args) { - int target, avatarId, level = 1, ascension; - - if (sender == null && args.size() < 2) { - CommandHandler.sendMessage(null, "Usage: givechar [amount]"); - return; - } - - switch (args.size()) { - default: - CommandHandler.sendMessage(sender, "Usage: givechar [level]"); - return; - case 2: - try { - target = Integer.parseInt(args.get(0)); - if (Grasscutter.getGameServer().getPlayerByUid(target) == null && sender != null) { - target = sender.getUid(); - level = Integer.parseInt(args.get(1)); - avatarId = Integer.parseInt(args.get(0)); - } else { - avatarId = Integer.parseInt(args.get(1)); - } - } catch (NumberFormatException ignored) { - // TODO: Parse from avatar name using GM Handbook. - CommandHandler.sendMessage(sender, "Invalid avatar or player ID."); - return; - } - break; - case 3: - try { - target = Integer.parseInt(args.get(0)); - if (Grasscutter.getGameServer().getPlayerByUid(target) == null) { - CommandHandler.sendMessage(sender, "Invalid player ID."); - return; - } - - avatarId = Integer.parseInt(args.get(1)); - level = Integer.parseInt(args.get(2)); - } catch (NumberFormatException ignored) { - // TODO: Parse from avatar name using GM Handbook. - CommandHandler.sendMessage(sender, "Invalid avatar or player ID."); - return; - } - break; - } - - GenshinPlayer targetPlayer = Grasscutter.getGameServer().getPlayerByUid(target); - if (targetPlayer == null) { - CommandHandler.sendMessage(sender, "Player not found."); - return; - } - - AvatarData avatarData = GenshinData.getAvatarDataMap().get(avatarId); - if (avatarData == null) { - CommandHandler.sendMessage(sender, "Invalid avatar id."); - return; - } - - // Calculate ascension level. - if (level <= 40) { - ascension = (int) Math.ceil(level / 20f); - } else { - ascension = (int) Math.ceil(level / 10f) - 3; - } - - GenshinAvatar avatar = new GenshinAvatar(avatarId); - avatar.setLevel(level); - avatar.setPromoteLevel(ascension); - - // This will handle stats and talents - avatar.recalcStats(); - - targetPlayer.addAvatar(avatar); - CommandHandler.sendMessage(sender, String.format("Given %s to %s.", avatarId, target)); - } -} +package emu.grasscutter.command.commands; + +import emu.grasscutter.Grasscutter; +import emu.grasscutter.command.Command; +import emu.grasscutter.command.CommandHandler; +import emu.grasscutter.data.GenshinData; +import emu.grasscutter.data.def.AvatarData; +import emu.grasscutter.game.GenshinPlayer; +import emu.grasscutter.game.avatar.GenshinAvatar; + +import java.util.List; + +@Command(label = "givechar", usage = "givechar [level]", + description = "Gives the player a specified character", aliases = {"givec"}, permission = "player.givechar") +public final class GiveCharCommand implements CommandHandler { + + @Override + public void execute(GenshinPlayer sender, List args) { + int target, avatarId, level = 1, ascension; + + if (sender == null && args.size() < 2) { + CommandHandler.sendMessage(null, "Usage: givechar [amount]"); + return; + } + + switch (args.size()) { + default: + CommandHandler.sendMessage(sender, "Usage: givechar [level]"); + return; + case 2: + try { + target = Integer.parseInt(args.get(0)); + if (Grasscutter.getGameServer().getPlayerByUid(target) == null && sender != null) { + target = sender.getUid(); + level = Integer.parseInt(args.get(1)); + avatarId = Integer.parseInt(args.get(0)); + } else { + avatarId = Integer.parseInt(args.get(1)); + } + } catch (NumberFormatException ignored) { + // TODO: Parse from avatar name using GM Handbook. + CommandHandler.sendMessage(sender, "Invalid avatar or player ID."); + return; + } + break; + case 3: + try { + target = Integer.parseInt(args.get(0)); + if (Grasscutter.getGameServer().getPlayerByUid(target) == null) { + CommandHandler.sendMessage(sender, "Invalid player ID."); + return; + } + + avatarId = Integer.parseInt(args.get(1)); + level = Integer.parseInt(args.get(2)); + } catch (NumberFormatException ignored) { + // TODO: Parse from avatar name using GM Handbook. + CommandHandler.sendMessage(sender, "Invalid avatar or player ID."); + return; + } + break; + } + + GenshinPlayer targetPlayer = Grasscutter.getGameServer().getPlayerByUid(target); + if (targetPlayer == null) { + CommandHandler.sendMessage(sender, "Player not found."); + return; + } + + AvatarData avatarData = GenshinData.getAvatarDataMap().get(avatarId); + if (avatarData == null) { + CommandHandler.sendMessage(sender, "Invalid avatar id."); + return; + } + + // Calculate ascension level. + if (level <= 40) { + ascension = (int) Math.ceil(level / 20f); + } else { + ascension = (int) Math.ceil(level / 10f) - 3; + } + + GenshinAvatar avatar = new GenshinAvatar(avatarId); + avatar.setLevel(level); + avatar.setPromoteLevel(ascension); + + // This will handle stats and talents + avatar.recalcStats(); + + targetPlayer.addAvatar(avatar); + CommandHandler.sendMessage(sender, String.format("Given %s to %s.", avatarId, target)); + } +} diff --git a/src/main/java/emu/grasscutter/command/commands/Give.java b/src/main/java/emu/grasscutter/command/commands/GiveCommand.java similarity index 96% rename from src/main/java/emu/grasscutter/command/commands/Give.java rename to src/main/java/emu/grasscutter/command/commands/GiveCommand.java index 47c015cf0..7d15a4759 100644 --- a/src/main/java/emu/grasscutter/command/commands/Give.java +++ b/src/main/java/emu/grasscutter/command/commands/GiveCommand.java @@ -1,112 +1,112 @@ -package emu.grasscutter.command.commands; - -import emu.grasscutter.Grasscutter; -import emu.grasscutter.command.Command; -import emu.grasscutter.command.CommandHandler; -import emu.grasscutter.data.GenshinData; -import emu.grasscutter.data.def.ItemData; -import emu.grasscutter.game.GenshinPlayer; -import emu.grasscutter.game.inventory.GenshinItem; -import emu.grasscutter.game.props.ActionReason; -import emu.grasscutter.server.packet.send.PacketItemAddHintNotify; - -import java.util.LinkedList; -import java.util.List; - -@Command(label = "give", usage = "give [player] [amount]", - description = "Gives an item to you or the specified player", aliases = {"g", "item", "giveitem"}, permission = "player.give") -public class Give implements CommandHandler { - - @Override - public void execute(GenshinPlayer sender, List args) { - int target, item, amount = 1; - - if (sender == null && args.size() < 2) { - CommandHandler.sendMessage(null, "Usage: give [amount]"); - return; - } - - switch (args.size()) { - default: // *No args* - CommandHandler.sendMessage(sender, "Usage: give [player] [amount]"); - return; - case 1: // - try { - item = Integer.parseInt(args.get(0)); - target = sender.getUid(); - } catch (NumberFormatException ignored) { - // TODO: Parse from item name using GM Handbook. - CommandHandler.sendMessage(sender, "Invalid item id."); - return; - } - break; - case 2: // [amount] | [player] - try { - target = Integer.parseInt(args.get(0)); - - if (Grasscutter.getGameServer().getPlayerByUid(target) == null && sender != null) { - target = sender.getUid(); - item = Integer.parseInt(args.get(0)); - amount = Integer.parseInt(args.get(1)); - } else { - item = Integer.parseInt(args.get(1)); - } - } catch (NumberFormatException ignored) { - // TODO: Parse from item name using GM Handbook. - CommandHandler.sendMessage(sender, "Invalid item or player ID."); - return; - } - break; - case 3: // [player] [amount] - try { - target = Integer.parseInt(args.get(0)); - - if (Grasscutter.getGameServer().getPlayerByUid(target) == null) { - CommandHandler.sendMessage(sender, "Invalid player ID."); - return; - } - - 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(sender, "Invalid item or player ID."); - return; - } - break; - } - - GenshinPlayer targetPlayer = Grasscutter.getGameServer().getPlayerByUid(target); - - if (targetPlayer == null) { - CommandHandler.sendMessage(sender, "Player not found."); - return; - } - - ItemData itemData = GenshinData.getItemDataMap().get(item); - if (itemData == null) { - CommandHandler.sendMessage(sender, "Invalid item id."); - return; - } - - this.item(targetPlayer, itemData, amount); - - CommandHandler.sendMessage(sender, String.format("Given %s of %s to %s.", amount, item, target)); - } - - private void item(GenshinPlayer player, ItemData itemData, int amount) { - GenshinItem genshinItem = new GenshinItem(itemData); - if (itemData.isEquip()) { - List items = new LinkedList<>(); - for (int i = 0; i < amount; i++) { - items.add(genshinItem); - } - player.getInventory().addItems(items); - player.sendPacket(new PacketItemAddHintNotify(items, ActionReason.SubfieldDrop)); - } else { - genshinItem.setCount(amount); - player.getInventory().addItem(genshinItem); - player.sendPacket(new PacketItemAddHintNotify(genshinItem, ActionReason.SubfieldDrop)); - } - } -} +package emu.grasscutter.command.commands; + +import emu.grasscutter.Grasscutter; +import emu.grasscutter.command.Command; +import emu.grasscutter.command.CommandHandler; +import emu.grasscutter.data.GenshinData; +import emu.grasscutter.data.def.ItemData; +import emu.grasscutter.game.GenshinPlayer; +import emu.grasscutter.game.inventory.GenshinItem; +import emu.grasscutter.game.props.ActionReason; +import emu.grasscutter.server.packet.send.PacketItemAddHintNotify; + +import java.util.LinkedList; +import java.util.List; + +@Command(label = "give", usage = "give [player] [amount]", + description = "Gives an item to you or the specified player", aliases = {"g", "item", "giveitem"}, permission = "player.give") +public final class GiveCommand implements CommandHandler { + + @Override + public void execute(GenshinPlayer sender, List args) { + int target, item, amount = 1; + + if (sender == null && args.size() < 2) { + CommandHandler.sendMessage(null, "Usage: give [amount]"); + return; + } + + switch (args.size()) { + default: // *No args* + CommandHandler.sendMessage(sender, "Usage: give [player] [amount]"); + return; + case 1: // + try { + item = Integer.parseInt(args.get(0)); + target = sender.getUid(); + } catch (NumberFormatException ignored) { + // TODO: Parse from item name using GM Handbook. + CommandHandler.sendMessage(sender, "Invalid item id."); + return; + } + break; + case 2: // [amount] | [player] + try { + target = Integer.parseInt(args.get(0)); + + if (Grasscutter.getGameServer().getPlayerByUid(target) == null && sender != null) { + target = sender.getUid(); + item = Integer.parseInt(args.get(0)); + amount = Integer.parseInt(args.get(1)); + } else { + item = Integer.parseInt(args.get(1)); + } + } catch (NumberFormatException ignored) { + // TODO: Parse from item name using GM Handbook. + CommandHandler.sendMessage(sender, "Invalid item or player ID."); + return; + } + break; + case 3: // [player] [amount] + try { + target = Integer.parseInt(args.get(0)); + + if (Grasscutter.getGameServer().getPlayerByUid(target) == null) { + CommandHandler.sendMessage(sender, "Invalid player ID."); + return; + } + + 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(sender, "Invalid item or player ID."); + return; + } + break; + } + + GenshinPlayer targetPlayer = Grasscutter.getGameServer().getPlayerByUid(target); + + if (targetPlayer == null) { + CommandHandler.sendMessage(sender, "Player not found."); + return; + } + + ItemData itemData = GenshinData.getItemDataMap().get(item); + if (itemData == null) { + CommandHandler.sendMessage(sender, "Invalid item id."); + return; + } + + this.item(targetPlayer, itemData, amount); + + CommandHandler.sendMessage(sender, String.format("Given %s of %s to %s.", amount, item, target)); + } + + private void item(GenshinPlayer player, ItemData itemData, int amount) { + GenshinItem genshinItem = new GenshinItem(itemData); + if (itemData.isEquip()) { + List items = new LinkedList<>(); + for (int i = 0; i < amount; i++) { + items.add(genshinItem); + } + player.getInventory().addItems(items); + player.sendPacket(new PacketItemAddHintNotify(items, ActionReason.SubfieldDrop)); + } else { + genshinItem.setCount(amount); + player.getInventory().addItem(genshinItem); + player.sendPacket(new PacketItemAddHintNotify(genshinItem, ActionReason.SubfieldDrop)); + } + } +} diff --git a/src/main/java/emu/grasscutter/command/commands/GodMode.java b/src/main/java/emu/grasscutter/command/commands/GodModeCommand.java similarity index 91% rename from src/main/java/emu/grasscutter/command/commands/GodMode.java rename to src/main/java/emu/grasscutter/command/commands/GodModeCommand.java index a84085d4d..e5635dc9f 100644 --- a/src/main/java/emu/grasscutter/command/commands/GodMode.java +++ b/src/main/java/emu/grasscutter/command/commands/GodModeCommand.java @@ -1,22 +1,22 @@ -package emu.grasscutter.command.commands; - -import emu.grasscutter.command.Command; -import emu.grasscutter.command.CommandHandler; -import emu.grasscutter.game.GenshinPlayer; - -import java.util.List; - -@Command(label = "godmode", usage = "godmode [playerId]", - description = "Prevents you from taking damage", permission = "player.godmode") -public class GodMode implements CommandHandler { - - @Override - public void execute(GenshinPlayer sender, List args) { - if (sender == null) { - CommandHandler.sendMessage(null, "Run this command in-game."); - return; // TODO: toggle player's godmode statue from console or other players - } - sender.setGodmode(!sender.inGodmode()); - sender.dropMessage("Godmode is now " + (sender.inGodmode() ? "enabled" : "disabled") + "."); - } -} +package emu.grasscutter.command.commands; + +import emu.grasscutter.command.Command; +import emu.grasscutter.command.CommandHandler; +import emu.grasscutter.game.GenshinPlayer; + +import java.util.List; + +@Command(label = "godmode", usage = "godmode [playerId]", + description = "Prevents you from taking damage", permission = "player.godmode") +public final class GodModeCommand implements CommandHandler { + + @Override + public void execute(GenshinPlayer sender, List args) { + if (sender == null) { + CommandHandler.sendMessage(null, "Run this command in-game."); + return; // TODO: toggle player's godmode statue from console or other players + } + sender.setGodmode(!sender.inGodmode()); + sender.dropMessage("Godmode is now " + (sender.inGodmode() ? "enabled" : "disabled") + "."); + } +} diff --git a/src/main/java/emu/grasscutter/command/commands/Help.java b/src/main/java/emu/grasscutter/command/commands/HelpCommand.java similarity index 96% rename from src/main/java/emu/grasscutter/command/commands/Help.java rename to src/main/java/emu/grasscutter/command/commands/HelpCommand.java index 376bb8cbf..abe78e7d3 100644 --- a/src/main/java/emu/grasscutter/command/commands/Help.java +++ b/src/main/java/emu/grasscutter/command/commands/HelpCommand.java @@ -1,91 +1,91 @@ -package emu.grasscutter.command.commands; - -import emu.grasscutter.command.Command; -import emu.grasscutter.command.CommandHandler; -import emu.grasscutter.command.CommandMap; -import emu.grasscutter.game.GenshinPlayer; - -import java.util.*; - -@Command(label = "help", usage = "help [command]", - description = "Sends the help message or shows information about a specified command") -public class Help implements CommandHandler { - - @Override - public void execute(GenshinPlayer player, List args) { - if (args.size() < 1) { - HashMap handlers = CommandMap.getInstance().getHandlers(); - List annotations = new ArrayList<>(); - for (String key : handlers.keySet()) { - Command annotation = handlers.get(key).getClass().getAnnotation(Command.class); - - if (!Arrays.asList(annotation.aliases()).contains(key)) { - if (player != null && !Objects.equals(annotation.permission(), "") && !player.getAccount().hasPermission(annotation.permission())) - continue; - annotations.add(annotation); - } - } - - SendAllHelpMessage(player, annotations); - } else { - String command = args.get(0); - CommandHandler handler = CommandMap.getInstance().getHandler(command); - StringBuilder builder = new StringBuilder(player == null ? "\nHelp - " : "Help - ").append(command).append(": \n"); - if (handler == null) { - builder.append("No command found."); - } else { - Command annotation = handler.getClass().getAnnotation(Command.class); - - builder.append(" ").append(annotation.description()).append("\n"); - builder.append(" Usage: ").append(annotation.usage()); - if (annotation.aliases().length >= 1) { - builder.append("\n").append(" Aliases: "); - for (String alias : annotation.aliases()) { - builder.append(alias).append(" "); - } - } - if (player != null && !Objects.equals(annotation.permission(), "") && !player.getAccount().hasPermission(annotation.permission())) { - builder.append("\n Warning: You do not have permission to run this command."); - } - } - - CommandHandler.sendMessage(player, builder.toString()); - } - } - - void SendAllHelpMessage(GenshinPlayer player, List annotations) { - if (player == null) { - StringBuilder builder = new StringBuilder("\nAvailable commands:\n"); - annotations.forEach(annotation -> { - builder.append(annotation.label()).append("\n"); - builder.append(" ").append(annotation.description()).append("\n"); - builder.append(" Usage: ").append(annotation.usage()); - if (annotation.aliases().length >= 1) { - builder.append("\n").append(" Aliases: "); - for (String alias : annotation.aliases()) { - builder.append(alias).append(" "); - } - } - - builder.append("\n"); - }); - - CommandHandler.sendMessage(null, builder.toString()); - } else { - CommandHandler.sendMessage(player, "Available commands:"); - annotations.forEach(annotation -> { - StringBuilder builder = new StringBuilder(annotation.label()).append("\n"); - builder.append(" ").append(annotation.description()).append("\n"); - builder.append(" Usage: ").append(annotation.usage()); - if (annotation.aliases().length >= 1) { - builder.append("\n").append(" Aliases: "); - for (String alias : annotation.aliases()) { - builder.append(alias).append(" "); - } - } - - CommandHandler.sendMessage(player, builder.toString()); - }); - } - } -} +package emu.grasscutter.command.commands; + +import emu.grasscutter.command.Command; +import emu.grasscutter.command.CommandHandler; +import emu.grasscutter.command.CommandMap; +import emu.grasscutter.game.GenshinPlayer; + +import java.util.*; + +@Command(label = "help", usage = "help [command]", + description = "Sends the help message or shows information about a specified command") +public final class HelpCommand implements CommandHandler { + + @Override + public void execute(GenshinPlayer player, List args) { + if (args.size() < 1) { + HashMap handlers = CommandMap.getInstance().getHandlers(); + List annotations = new ArrayList<>(); + for (String key : handlers.keySet()) { + Command annotation = handlers.get(key).getClass().getAnnotation(Command.class); + + if (!Arrays.asList(annotation.aliases()).contains(key)) { + if (player != null && !Objects.equals(annotation.permission(), "") && !player.getAccount().hasPermission(annotation.permission())) + continue; + annotations.add(annotation); + } + } + + SendAllHelpMessage(player, annotations); + } else { + String command = args.get(0); + CommandHandler handler = CommandMap.getInstance().getHandler(command); + StringBuilder builder = new StringBuilder(player == null ? "\nHelp - " : "Help - ").append(command).append(": \n"); + if (handler == null) { + builder.append("No command found."); + } else { + Command annotation = handler.getClass().getAnnotation(Command.class); + + builder.append(" ").append(annotation.description()).append("\n"); + builder.append(" Usage: ").append(annotation.usage()); + if (annotation.aliases().length >= 1) { + builder.append("\n").append(" Aliases: "); + for (String alias : annotation.aliases()) { + builder.append(alias).append(" "); + } + } + if (player != null && !Objects.equals(annotation.permission(), "") && !player.getAccount().hasPermission(annotation.permission())) { + builder.append("\n Warning: You do not have permission to run this command."); + } + } + + CommandHandler.sendMessage(player, builder.toString()); + } + } + + void SendAllHelpMessage(GenshinPlayer player, List annotations) { + if (player == null) { + StringBuilder builder = new StringBuilder("\nAvailable commands:\n"); + annotations.forEach(annotation -> { + builder.append(annotation.label()).append("\n"); + builder.append(" ").append(annotation.description()).append("\n"); + builder.append(" Usage: ").append(annotation.usage()); + if (annotation.aliases().length >= 1) { + builder.append("\n").append(" Aliases: "); + for (String alias : annotation.aliases()) { + builder.append(alias).append(" "); + } + } + + builder.append("\n"); + }); + + CommandHandler.sendMessage(null, builder.toString()); + } else { + CommandHandler.sendMessage(player, "Available commands:"); + annotations.forEach(annotation -> { + StringBuilder builder = new StringBuilder(annotation.label()).append("\n"); + builder.append(" ").append(annotation.description()).append("\n"); + builder.append(" Usage: ").append(annotation.usage()); + if (annotation.aliases().length >= 1) { + builder.append("\n").append(" Aliases: "); + for (String alias : annotation.aliases()) { + builder.append(alias).append(" "); + } + } + + CommandHandler.sendMessage(player, builder.toString()); + }); + } + } +} diff --git a/src/main/java/emu/grasscutter/command/commands/Kick.java b/src/main/java/emu/grasscutter/command/commands/KickCommand.java similarity index 93% rename from src/main/java/emu/grasscutter/command/commands/Kick.java rename to src/main/java/emu/grasscutter/command/commands/KickCommand.java index 9a9c19f86..188ce1877 100644 --- a/src/main/java/emu/grasscutter/command/commands/Kick.java +++ b/src/main/java/emu/grasscutter/command/commands/KickCommand.java @@ -1,31 +1,31 @@ -package emu.grasscutter.command.commands; - -import emu.grasscutter.Grasscutter; -import emu.grasscutter.command.Command; -import emu.grasscutter.command.CommandHandler; -import emu.grasscutter.game.GenshinPlayer; - -import java.util.List; - -@Command(label = "kick", usage = "kick ", - description = "Kicks the specified player from the server (WIP)", permission = "server.kick") -public class Kick implements CommandHandler { - - @Override - public void execute(GenshinPlayer sender, List args) { - int target = Integer.parseInt(args.get(0)); - - GenshinPlayer targetPlayer = Grasscutter.getGameServer().getPlayerByUid(target); - if (targetPlayer == null) { - CommandHandler.sendMessage(sender, "Player not found."); - return; - } - - if (sender != null) { - CommandHandler.sendMessage(sender, String.format("Player [%s:%s] has kicked player [%s:%s]", sender.getAccount().getPlayerId(), sender.getAccount().getUsername(), target, targetPlayer.getAccount().getUsername())); - } - CommandHandler.sendMessage(sender, String.format("Kicking player [%s:%s]", target, targetPlayer.getAccount().getUsername())); - - targetPlayer.getSession().close(); - } -} +package emu.grasscutter.command.commands; + +import emu.grasscutter.Grasscutter; +import emu.grasscutter.command.Command; +import emu.grasscutter.command.CommandHandler; +import emu.grasscutter.game.GenshinPlayer; + +import java.util.List; + +@Command(label = "kick", usage = "kick ", + description = "Kicks the specified player from the server (WIP)", permission = "server.kick") +public final class KickCommand implements CommandHandler { + + @Override + public void execute(GenshinPlayer sender, List args) { + int target = Integer.parseInt(args.get(0)); + + GenshinPlayer targetPlayer = Grasscutter.getGameServer().getPlayerByUid(target); + if (targetPlayer == null) { + CommandHandler.sendMessage(sender, "Player not found."); + return; + } + + if (sender != null) { + CommandHandler.sendMessage(sender, String.format("Player [%s:%s] has kicked player [%s:%s]", sender.getAccount().getPlayerId(), sender.getAccount().getUsername(), target, targetPlayer.getAccount().getUsername())); + } + CommandHandler.sendMessage(sender, String.format("Kicking player [%s:%s]", target, targetPlayer.getAccount().getUsername())); + + targetPlayer.getSession().close(); + } +} diff --git a/src/main/java/emu/grasscutter/command/commands/KillAll.java b/src/main/java/emu/grasscutter/command/commands/KillAllCommand.java similarity index 96% rename from src/main/java/emu/grasscutter/command/commands/KillAll.java rename to src/main/java/emu/grasscutter/command/commands/KillAllCommand.java index ba434aa89..436691b57 100644 --- a/src/main/java/emu/grasscutter/command/commands/KillAll.java +++ b/src/main/java/emu/grasscutter/command/commands/KillAllCommand.java @@ -1,64 +1,64 @@ -package emu.grasscutter.command.commands; - -import emu.grasscutter.Grasscutter; -import emu.grasscutter.command.Command; -import emu.grasscutter.command.CommandHandler; -import emu.grasscutter.game.GenshinPlayer; -import emu.grasscutter.game.GenshinScene; -import emu.grasscutter.game.entity.EntityMonster; - -import java.util.List; - -@Command(label = "killall", usage = "killall [playerUid] [sceneId]", - description = "Kill all entities", permission = "server.killall") -public class KillAll implements CommandHandler { - - @Override - public void execute(GenshinPlayer sender, List args) { - GenshinScene scene; - GenshinPlayer genshinPlayer; - - try { - switch (args.size()) { - case 0: // *No args* - if (sender == null) { - CommandHandler.sendMessage(null, "Usage: killall [playerUid] [sceneId]"); - return; - } - scene = sender.getScene(); - break; - case 1: // [playerUid] - genshinPlayer = Grasscutter.getGameServer().getPlayerByUid(Integer.parseInt(args.get(0))); - if (genshinPlayer == null) { - CommandHandler.sendMessage(sender, "Player not found or offline."); - return; - } - scene = genshinPlayer.getScene(); - break; - case 2: // [playerUid] [sceneId] - genshinPlayer = Grasscutter.getGameServer().getPlayerByUid(Integer.parseInt(args.get(0))); - if (genshinPlayer == null) { - CommandHandler.sendMessage(sender, "Player not found or offline."); - return; - } - GenshinScene genshinScene = sender.getWorld().getSceneById(Integer.parseInt(args.get(1))); - if (genshinScene == null) { - CommandHandler.sendMessage(sender, "Scene not found in player world"); - return; - } - scene = genshinScene; - break; - default: - CommandHandler.sendMessage(sender, "Usage: killall [playerUid] [sceneId]"); - return; - } - - scene.getEntities().values().stream() - .filter(entity -> entity instanceof EntityMonster) - .forEach(entity -> scene.killEntity(entity, 0)); - CommandHandler.sendMessage(sender, "Killing all monsters in scene " + scene.getId()); - } catch (NumberFormatException ignored) { - CommandHandler.sendMessage(sender, "Invalid arguments."); - } - } -} +package emu.grasscutter.command.commands; + +import emu.grasscutter.Grasscutter; +import emu.grasscutter.command.Command; +import emu.grasscutter.command.CommandHandler; +import emu.grasscutter.game.GenshinPlayer; +import emu.grasscutter.game.GenshinScene; +import emu.grasscutter.game.entity.EntityMonster; + +import java.util.List; + +@Command(label = "killall", usage = "killall [playerUid] [sceneId]", + description = "Kill all entities", permission = "server.killall") +public final class KillAllCommand implements CommandHandler { + + @Override + public void execute(GenshinPlayer sender, List args) { + GenshinScene scene; + GenshinPlayer genshinPlayer; + + try { + switch (args.size()) { + case 0: // *No args* + if (sender == null) { + CommandHandler.sendMessage(null, "Usage: killall [playerUid] [sceneId]"); + return; + } + scene = sender.getScene(); + break; + case 1: // [playerUid] + genshinPlayer = Grasscutter.getGameServer().getPlayerByUid(Integer.parseInt(args.get(0))); + if (genshinPlayer == null) { + CommandHandler.sendMessage(sender, "Player not found or offline."); + return; + } + scene = genshinPlayer.getScene(); + break; + case 2: // [playerUid] [sceneId] + genshinPlayer = Grasscutter.getGameServer().getPlayerByUid(Integer.parseInt(args.get(0))); + if (genshinPlayer == null) { + CommandHandler.sendMessage(sender, "Player not found or offline."); + return; + } + GenshinScene genshinScene = sender.getWorld().getSceneById(Integer.parseInt(args.get(1))); + if (genshinScene == null) { + CommandHandler.sendMessage(sender, "Scene not found in player world"); + return; + } + scene = genshinScene; + break; + default: + CommandHandler.sendMessage(sender, "Usage: killall [playerUid] [sceneId]"); + return; + } + + scene.getEntities().values().stream() + .filter(entity -> entity instanceof EntityMonster) + .forEach(entity -> scene.killEntity(entity, 0)); + CommandHandler.sendMessage(sender, "Killing all monsters in scene " + scene.getId()); + } catch (NumberFormatException ignored) { + CommandHandler.sendMessage(sender, "Invalid arguments."); + } + } +} diff --git a/src/main/java/emu/grasscutter/command/commands/Permission.java b/src/main/java/emu/grasscutter/command/commands/PermissionCommand.java similarity index 94% rename from src/main/java/emu/grasscutter/command/commands/Permission.java rename to src/main/java/emu/grasscutter/command/commands/PermissionCommand.java index 353ba81c8..7218bf2cd 100644 --- a/src/main/java/emu/grasscutter/command/commands/Permission.java +++ b/src/main/java/emu/grasscutter/command/commands/PermissionCommand.java @@ -1,50 +1,50 @@ -package emu.grasscutter.command.commands; - -import emu.grasscutter.Grasscutter; -import emu.grasscutter.command.Command; -import emu.grasscutter.command.CommandHandler; -import emu.grasscutter.game.Account; -import emu.grasscutter.game.GenshinPlayer; - -import java.util.List; - -@Command(label = "permission", usage = "permission ", - description = "Grants or removes a permission for a user", permission = "*") -public class Permission implements CommandHandler { - - @Override - public void execute(GenshinPlayer sender, List args) { - if (args.size() < 3) { - CommandHandler.sendMessage(sender, "Usage: permission "); - return; - } - - String action = args.get(0); - String username = args.get(1); - String permission = args.get(2); - - Account account = Grasscutter.getGameServer().getAccountByName(username); - if (account == null) { - CommandHandler.sendMessage(sender, "Account not found."); - return; - } - - switch (action) { - default: - CommandHandler.sendMessage(sender, "Usage: permission "); - break; - case "add": - if (account.addPermission(permission)) { - CommandHandler.sendMessage(sender, "Permission added."); - } else CommandHandler.sendMessage(sender, "They already have this permission!"); - break; - case "remove": - if (account.removePermission(permission)) { - CommandHandler.sendMessage(sender, "Permission removed."); - } else CommandHandler.sendMessage(sender, "They don't have this permission!"); - break; - } - - account.save(); - } +package emu.grasscutter.command.commands; + +import emu.grasscutter.Grasscutter; +import emu.grasscutter.command.Command; +import emu.grasscutter.command.CommandHandler; +import emu.grasscutter.game.Account; +import emu.grasscutter.game.GenshinPlayer; + +import java.util.List; + +@Command(label = "permission", usage = "permission ", + description = "Grants or removes a permission for a user", permission = "*") +public final class PermissionCommand implements CommandHandler { + + @Override + public void execute(GenshinPlayer sender, List args) { + if (args.size() < 3) { + CommandHandler.sendMessage(sender, "Usage: permission "); + return; + } + + String action = args.get(0); + String username = args.get(1); + String permission = args.get(2); + + Account account = Grasscutter.getGameServer().getAccountByName(username); + if (account == null) { + CommandHandler.sendMessage(sender, "Account not found."); + return; + } + + switch (action) { + default: + CommandHandler.sendMessage(sender, "Usage: permission "); + break; + case "add": + if (account.addPermission(permission)) { + CommandHandler.sendMessage(sender, "Permission added."); + } else CommandHandler.sendMessage(sender, "They already have this permission!"); + break; + case "remove": + if (account.removePermission(permission)) { + CommandHandler.sendMessage(sender, "Permission removed."); + } else CommandHandler.sendMessage(sender, "They don't have this permission!"); + break; + } + + account.save(); + } } \ No newline at end of file diff --git a/src/main/java/emu/grasscutter/command/commands/Pos.java b/src/main/java/emu/grasscutter/command/commands/PositionCommand.java similarity index 82% rename from src/main/java/emu/grasscutter/command/commands/Pos.java rename to src/main/java/emu/grasscutter/command/commands/PositionCommand.java index 3f1d40c9d..639301c7f 100644 --- a/src/main/java/emu/grasscutter/command/commands/Pos.java +++ b/src/main/java/emu/grasscutter/command/commands/PositionCommand.java @@ -1,22 +1,22 @@ -package emu.grasscutter.command.commands; - -import emu.grasscutter.command.Command; -import emu.grasscutter.command.CommandHandler; -import emu.grasscutter.game.GenshinPlayer; - -import java.util.List; - -@Command(label = "pos", usage = "pos", - description = "Get coordinates.") -public class Pos implements CommandHandler { - - @Override - public void execute(GenshinPlayer sender, List args) { - if (sender == null) { - CommandHandler.sendMessage(null, "Run this command in-game."); - return; - } - - sender.dropMessage(String.format("Coord: %.3f, %.3f, %.3f", sender.getPos().getX(), sender.getPos().getY(), sender.getPos().getZ())); - } -} +package emu.grasscutter.command.commands; + +import emu.grasscutter.command.Command; +import emu.grasscutter.command.CommandHandler; +import emu.grasscutter.game.GenshinPlayer; + +import java.util.List; + +@Command(label = "position", usage = "position", aliases = {"pos"}, + description = "Get coordinates.") +public final class PositionCommand implements CommandHandler { + + @Override + public void execute(GenshinPlayer sender, List args) { + if (sender == null) { + CommandHandler.sendMessage(null, "Run this command in-game."); + return; + } + + sender.dropMessage(String.format("Coord: %.3f, %.3f, %.3f", sender.getPos().getX(), sender.getPos().getY(), sender.getPos().getZ())); + } +} diff --git a/src/main/java/emu/grasscutter/command/commands/Reload.java b/src/main/java/emu/grasscutter/command/commands/ReloadCommand.java similarity index 91% rename from src/main/java/emu/grasscutter/command/commands/Reload.java rename to src/main/java/emu/grasscutter/command/commands/ReloadCommand.java index cf2bae2b1..b145aaf94 100644 --- a/src/main/java/emu/grasscutter/command/commands/Reload.java +++ b/src/main/java/emu/grasscutter/command/commands/ReloadCommand.java @@ -1,22 +1,22 @@ -package emu.grasscutter.command.commands; - -import emu.grasscutter.Grasscutter; -import emu.grasscutter.command.Command; -import emu.grasscutter.command.CommandHandler; -import emu.grasscutter.game.GenshinPlayer; - -import java.util.List; - -@Command(label = "reload", usage = "reload", - description = "Reload server config", permission = "server.reload") -public class Reload implements CommandHandler { - - @Override - public void execute(GenshinPlayer sender, List args) { - CommandHandler.sendMessage(sender, "Reloading config."); - Grasscutter.loadConfig(); - Grasscutter.getGameServer().getGachaManager().load(); - Grasscutter.getDispatchServer().loadQueries(); - CommandHandler.sendMessage(sender, "Reload complete."); - } -} +package emu.grasscutter.command.commands; + +import emu.grasscutter.Grasscutter; +import emu.grasscutter.command.Command; +import emu.grasscutter.command.CommandHandler; +import emu.grasscutter.game.GenshinPlayer; + +import java.util.List; + +@Command(label = "reload", usage = "reload", + description = "Reload server config", permission = "server.reload") +public final class ReloadCommand implements CommandHandler { + + @Override + public void execute(GenshinPlayer sender, List args) { + CommandHandler.sendMessage(sender, "Reloading config."); + Grasscutter.loadConfig(); + Grasscutter.getGameServer().getGachaManager().load(); + Grasscutter.getDispatchServer().loadQueries(); + CommandHandler.sendMessage(sender, "Reload complete."); + } +} diff --git a/src/main/java/emu/grasscutter/command/commands/ResetConst.java b/src/main/java/emu/grasscutter/command/commands/ResetConstCommand.java similarity index 94% rename from src/main/java/emu/grasscutter/command/commands/ResetConst.java rename to src/main/java/emu/grasscutter/command/commands/ResetConstCommand.java index 027e6addd..77f16f9b8 100644 --- a/src/main/java/emu/grasscutter/command/commands/ResetConst.java +++ b/src/main/java/emu/grasscutter/command/commands/ResetConstCommand.java @@ -1,45 +1,45 @@ -package emu.grasscutter.command.commands; - -import emu.grasscutter.command.Command; -import emu.grasscutter.command.CommandHandler; -import emu.grasscutter.game.GenshinPlayer; -import emu.grasscutter.game.avatar.GenshinAvatar; -import emu.grasscutter.game.entity.EntityAvatar; - -import java.util.List; - -@Command(label = "resetconst", usage = "resetconst [all]", - description = "Resets the constellation level on your current active character, will need to relog after using the command to see any changes.", - aliases = {"resetconstellation"}, permission = "player.resetconstellation") -public class ResetConst implements CommandHandler { - - @Override - public void execute(GenshinPlayer sender, List args) { - if (sender == null) { - CommandHandler.sendMessage(null, "Run this command in-game."); - return; - } - - if (args.size() > 0 && args.get(0).equalsIgnoreCase("all")) { - sender.getAvatars().forEach(this::resetConstellation); - sender.dropMessage("Reset all avatars' constellations."); - } else { - EntityAvatar entity = sender.getTeamManager().getCurrentAvatarEntity(); - if (entity == null) { - return; - } - - GenshinAvatar avatar = entity.getAvatar(); - this.resetConstellation(avatar); - - sender.dropMessage("Constellations for " + avatar.getAvatarData().getName() + " have been reset. Please relog to see changes."); - } - } - - private void resetConstellation(GenshinAvatar avatar) { - avatar.getTalentIdList().clear(); - avatar.setCoreProudSkillLevel(0); - avatar.recalcStats(); - avatar.save(); - } +package emu.grasscutter.command.commands; + +import emu.grasscutter.command.Command; +import emu.grasscutter.command.CommandHandler; +import emu.grasscutter.game.GenshinPlayer; +import emu.grasscutter.game.avatar.GenshinAvatar; +import emu.grasscutter.game.entity.EntityAvatar; + +import java.util.List; + +@Command(label = "resetconst", usage = "resetconst [all]", + description = "Resets the constellation level on your current active character, will need to relog after using the command to see any changes.", + aliases = {"resetconstellation"}, permission = "player.resetconstellation") +public final class ResetConstCommand implements CommandHandler { + + @Override + public void execute(GenshinPlayer sender, List args) { + if (sender == null) { + CommandHandler.sendMessage(null, "Run this command in-game."); + return; + } + + if (args.size() > 0 && args.get(0).equalsIgnoreCase("all")) { + sender.getAvatars().forEach(this::resetConstellation); + sender.dropMessage("Reset all avatars' constellations."); + } else { + EntityAvatar entity = sender.getTeamManager().getCurrentAvatarEntity(); + if (entity == null) { + return; + } + + GenshinAvatar avatar = entity.getAvatar(); + this.resetConstellation(avatar); + + sender.dropMessage("Constellations for " + avatar.getAvatarData().getName() + " have been reset. Please relog to see changes."); + } + } + + private void resetConstellation(GenshinAvatar avatar) { + avatar.getTalentIdList().clear(); + avatar.setCoreProudSkillLevel(0); + avatar.recalcStats(); + avatar.save(); + } } \ No newline at end of file diff --git a/src/main/java/emu/grasscutter/command/commands/Restart.java b/src/main/java/emu/grasscutter/command/commands/RestartCommand.java similarity index 86% rename from src/main/java/emu/grasscutter/command/commands/Restart.java rename to src/main/java/emu/grasscutter/command/commands/RestartCommand.java index a00e8af67..cf40fa9bd 100644 --- a/src/main/java/emu/grasscutter/command/commands/Restart.java +++ b/src/main/java/emu/grasscutter/command/commands/RestartCommand.java @@ -1,16 +1,16 @@ -package emu.grasscutter.command.commands; - -import emu.grasscutter.command.Command; -import emu.grasscutter.command.CommandHandler; -import emu.grasscutter.game.GenshinPlayer; - -import java.util.List; - -@Command(label = "restart", usage = "restart - Restarts the current session") -public class Restart implements CommandHandler { - - @Override - public void execute(GenshinPlayer sender, List args) { - sender.getSession().close(); - } -} +package emu.grasscutter.command.commands; + +import emu.grasscutter.command.Command; +import emu.grasscutter.command.CommandHandler; +import emu.grasscutter.game.GenshinPlayer; + +import java.util.List; + +@Command(label = "restart", usage = "restart - Restarts the current session") +public final class RestartCommand implements CommandHandler { + + @Override + public void execute(GenshinPlayer sender, List args) { + sender.getSession().close(); + } +} diff --git a/src/main/java/emu/grasscutter/command/commands/SendMessage.java b/src/main/java/emu/grasscutter/command/commands/SendMessageCommand.java similarity index 93% rename from src/main/java/emu/grasscutter/command/commands/SendMessage.java rename to src/main/java/emu/grasscutter/command/commands/SendMessageCommand.java index 9da80ef91..061009c19 100644 --- a/src/main/java/emu/grasscutter/command/commands/SendMessage.java +++ b/src/main/java/emu/grasscutter/command/commands/SendMessageCommand.java @@ -1,37 +1,37 @@ -package emu.grasscutter.command.commands; - -import emu.grasscutter.Grasscutter; -import emu.grasscutter.command.Command; -import emu.grasscutter.command.CommandHandler; -import emu.grasscutter.game.GenshinPlayer; - -import java.util.List; - -@Command(label = "say", usage = "say ", description = "Sends a message to a player as the server", - aliases = {"sendservmsg", "sendservermessage", "sendmessage"}, permission = "server.sendmessage") -public class SendMessage implements CommandHandler { - - @Override - public void execute(GenshinPlayer sender, List args) { - if (args.size() < 2) { - CommandHandler.sendMessage(null, "Usage: sendmessage "); - 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(sender, "Player not found."); - return; - } - - CommandHandler.sendMessage(targetPlayer, message); - CommandHandler.sendMessage(sender, "Message sent."); - } catch (NumberFormatException ignored) { - CommandHandler.sendMessage(sender, "Invalid player ID."); - } - } +package emu.grasscutter.command.commands; + +import emu.grasscutter.Grasscutter; +import emu.grasscutter.command.Command; +import emu.grasscutter.command.CommandHandler; +import emu.grasscutter.game.GenshinPlayer; + +import java.util.List; + +@Command(label = "say", usage = "say ", description = "Sends a message to a player as the server", + aliases = {"sendservmsg", "sendservermessage", "sendmessage"}, permission = "server.sendmessage") +public final class SendMessageCommand implements CommandHandler { + + @Override + public void execute(GenshinPlayer sender, List args) { + if (args.size() < 2) { + CommandHandler.sendMessage(null, "Usage: sendmessage "); + 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(sender, "Player not found."); + return; + } + + CommandHandler.sendMessage(targetPlayer, message); + CommandHandler.sendMessage(sender, "Message sent."); + } catch (NumberFormatException ignored) { + CommandHandler.sendMessage(sender, "Invalid player ID."); + } + } } \ No newline at end of file diff --git a/src/main/java/emu/grasscutter/command/commands/SetStats.java b/src/main/java/emu/grasscutter/command/commands/SetStatsCommand.java similarity index 97% rename from src/main/java/emu/grasscutter/command/commands/SetStats.java rename to src/main/java/emu/grasscutter/command/commands/SetStatsCommand.java index f8cac4bf4..30e8c9f12 100644 --- a/src/main/java/emu/grasscutter/command/commands/SetStats.java +++ b/src/main/java/emu/grasscutter/command/commands/SetStatsCommand.java @@ -1,120 +1,120 @@ -package emu.grasscutter.command.commands; - -import emu.grasscutter.command.Command; -import emu.grasscutter.command.CommandHandler; -import emu.grasscutter.game.GenshinPlayer; -import emu.grasscutter.game.entity.EntityAvatar; -import emu.grasscutter.game.props.FightProperty; -import emu.grasscutter.server.packet.send.PacketEntityFightPropUpdateNotify; - -import java.util.List; - -@Command(label = "setstats", usage = "setstats ", - aliases = {"stats"}) -public class SetStats implements CommandHandler { - - @Override - public void execute(GenshinPlayer sender, List args) { - if (sender == null) { - CommandHandler.sendMessage(null, "Run this command in-game."); - return; - } - - String stat = args.get(0); - switch (stat) { - default: - CommandHandler.sendMessage(sender, "Usage: setstats|stats "); - return; - case "hp": - try { - int health = Integer.parseInt(args.get(1)); - EntityAvatar entity = sender.getTeamManager().getCurrentAvatarEntity(); - entity.setFightProperty(FightProperty.FIGHT_PROP_CUR_HP, health); - entity.getWorld().broadcastPacket(new PacketEntityFightPropUpdateNotify(entity, FightProperty.FIGHT_PROP_CUR_HP)); - CommandHandler.sendMessage(sender, "HP set to " + health + "."); - } catch (NumberFormatException ignored) { - CommandHandler.sendMessage(sender, "Invalid HP value."); - return; - } - break; - case "def": - try { - int def = Integer.parseInt(args.get(1)); - EntityAvatar entity = sender.getTeamManager().getCurrentAvatarEntity(); - entity.setFightProperty(FightProperty.FIGHT_PROP_CUR_DEFENSE, def); - entity.getWorld().broadcastPacket(new PacketEntityFightPropUpdateNotify(entity, FightProperty.FIGHT_PROP_CUR_DEFENSE)); - CommandHandler.sendMessage(sender, "DEF set to " + def + "."); - } catch (NumberFormatException ignored) { - CommandHandler.sendMessage(sender, "Invalid DEF value."); - return; - } - break; - case "atk": - try { - int atk = Integer.parseInt(args.get(1)); - EntityAvatar entity = sender.getTeamManager().getCurrentAvatarEntity(); - entity.setFightProperty(FightProperty.FIGHT_PROP_CUR_ATTACK, atk); - entity.getWorld().broadcastPacket(new PacketEntityFightPropUpdateNotify(entity, FightProperty.FIGHT_PROP_CUR_ATTACK)); - CommandHandler.sendMessage(sender, "ATK set to " + atk + "."); - } catch (NumberFormatException ignored) { - CommandHandler.sendMessage(sender, "Invalid ATK value."); - return; - } - break; - case "em": - try { - int em = Integer.parseInt(args.get(1)); - EntityAvatar entity = sender.getTeamManager().getCurrentAvatarEntity(); - entity.setFightProperty(FightProperty.FIGHT_PROP_ELEMENT_MASTERY, em); - entity.getWorld().broadcastPacket(new PacketEntityFightPropUpdateNotify(entity, FightProperty.FIGHT_PROP_ELEMENT_MASTERY)); - CommandHandler.sendMessage(sender, "Elemental Mastery set to " + em + "."); - } catch (NumberFormatException ignored) { - CommandHandler.sendMessage(sender, "Invalid EM value."); - return; - } - break; - case "er": - try { - float er = Integer.parseInt(args.get(1)); - EntityAvatar entity = sender.getTeamManager().getCurrentAvatarEntity(); - float erecharge = er / 10000; - entity.setFightProperty(FightProperty.FIGHT_PROP_CHARGE_EFFICIENCY, erecharge); - entity.getWorld().broadcastPacket(new PacketEntityFightPropUpdateNotify(entity, FightProperty.FIGHT_PROP_CHARGE_EFFICIENCY)); - float iger = erecharge * 100; - CommandHandler.sendMessage(sender, "Energy recharge set to " + iger + "%."); - } catch (NumberFormatException ignored) { - CommandHandler.sendMessage(sender, "Invalid ER value."); - return; - } - break; - case "crate": - try { - float cr = Integer.parseInt(args.get(1)); - EntityAvatar entity = sender.getTeamManager().getCurrentAvatarEntity(); - float crate = cr / 10000; - entity.setFightProperty(FightProperty.FIGHT_PROP_CRITICAL, crate); - entity.getWorld().broadcastPacket(new PacketEntityFightPropUpdateNotify(entity, FightProperty.FIGHT_PROP_CRITICAL)); - float igcrate = crate * 100; - CommandHandler.sendMessage(sender, "Crit Rate set to " + igcrate + "%."); - } catch (NumberFormatException ignored) { - CommandHandler.sendMessage(sender, "Invalid Crit Rate value."); - return; - } - break; - case "cdmg": - try { - float cdmg = Integer.parseInt(args.get(1)); - EntityAvatar entity = sender.getTeamManager().getCurrentAvatarEntity(); - float cdamage = cdmg / 10000; - entity.setFightProperty(FightProperty.FIGHT_PROP_CRITICAL_HURT, cdamage); - entity.getWorld().broadcastPacket(new PacketEntityFightPropUpdateNotify(entity, FightProperty.FIGHT_PROP_CRITICAL_HURT)); - float igcdmg = cdamage * 100; - CommandHandler.sendMessage(sender, "Crit DMG set to " + igcdmg + "%"); - } catch (NumberFormatException ignored) { - CommandHandler.sendMessage(sender, "Invalid Crit DMG value."); - return; - } - break; - } - } -} +package emu.grasscutter.command.commands; + +import emu.grasscutter.command.Command; +import emu.grasscutter.command.CommandHandler; +import emu.grasscutter.game.GenshinPlayer; +import emu.grasscutter.game.entity.EntityAvatar; +import emu.grasscutter.game.props.FightProperty; +import emu.grasscutter.server.packet.send.PacketEntityFightPropUpdateNotify; + +import java.util.List; + +@Command(label = "setstats", usage = "setstats ", + aliases = {"stats"}) +public final class SetStatsCommand implements CommandHandler { + + @Override + public void execute(GenshinPlayer sender, List args) { + if (sender == null) { + CommandHandler.sendMessage(null, "Run this command in-game."); + return; + } + + String stat = args.get(0); + switch (stat) { + default: + CommandHandler.sendMessage(sender, "Usage: setstats|stats "); + return; + case "hp": + try { + int health = Integer.parseInt(args.get(1)); + EntityAvatar entity = sender.getTeamManager().getCurrentAvatarEntity(); + entity.setFightProperty(FightProperty.FIGHT_PROP_CUR_HP, health); + entity.getWorld().broadcastPacket(new PacketEntityFightPropUpdateNotify(entity, FightProperty.FIGHT_PROP_CUR_HP)); + CommandHandler.sendMessage(sender, "HP set to " + health + "."); + } catch (NumberFormatException ignored) { + CommandHandler.sendMessage(sender, "Invalid HP value."); + return; + } + break; + case "def": + try { + int def = Integer.parseInt(args.get(1)); + EntityAvatar entity = sender.getTeamManager().getCurrentAvatarEntity(); + entity.setFightProperty(FightProperty.FIGHT_PROP_CUR_DEFENSE, def); + entity.getWorld().broadcastPacket(new PacketEntityFightPropUpdateNotify(entity, FightProperty.FIGHT_PROP_CUR_DEFENSE)); + CommandHandler.sendMessage(sender, "DEF set to " + def + "."); + } catch (NumberFormatException ignored) { + CommandHandler.sendMessage(sender, "Invalid DEF value."); + return; + } + break; + case "atk": + try { + int atk = Integer.parseInt(args.get(1)); + EntityAvatar entity = sender.getTeamManager().getCurrentAvatarEntity(); + entity.setFightProperty(FightProperty.FIGHT_PROP_CUR_ATTACK, atk); + entity.getWorld().broadcastPacket(new PacketEntityFightPropUpdateNotify(entity, FightProperty.FIGHT_PROP_CUR_ATTACK)); + CommandHandler.sendMessage(sender, "ATK set to " + atk + "."); + } catch (NumberFormatException ignored) { + CommandHandler.sendMessage(sender, "Invalid ATK value."); + return; + } + break; + case "em": + try { + int em = Integer.parseInt(args.get(1)); + EntityAvatar entity = sender.getTeamManager().getCurrentAvatarEntity(); + entity.setFightProperty(FightProperty.FIGHT_PROP_ELEMENT_MASTERY, em); + entity.getWorld().broadcastPacket(new PacketEntityFightPropUpdateNotify(entity, FightProperty.FIGHT_PROP_ELEMENT_MASTERY)); + CommandHandler.sendMessage(sender, "Elemental Mastery set to " + em + "."); + } catch (NumberFormatException ignored) { + CommandHandler.sendMessage(sender, "Invalid EM value."); + return; + } + break; + case "er": + try { + float er = Integer.parseInt(args.get(1)); + EntityAvatar entity = sender.getTeamManager().getCurrentAvatarEntity(); + float erecharge = er / 10000; + entity.setFightProperty(FightProperty.FIGHT_PROP_CHARGE_EFFICIENCY, erecharge); + entity.getWorld().broadcastPacket(new PacketEntityFightPropUpdateNotify(entity, FightProperty.FIGHT_PROP_CHARGE_EFFICIENCY)); + float iger = erecharge * 100; + CommandHandler.sendMessage(sender, "Energy recharge set to " + iger + "%."); + } catch (NumberFormatException ignored) { + CommandHandler.sendMessage(sender, "Invalid ER value."); + return; + } + break; + case "crate": + try { + float cr = Integer.parseInt(args.get(1)); + EntityAvatar entity = sender.getTeamManager().getCurrentAvatarEntity(); + float crate = cr / 10000; + entity.setFightProperty(FightProperty.FIGHT_PROP_CRITICAL, crate); + entity.getWorld().broadcastPacket(new PacketEntityFightPropUpdateNotify(entity, FightProperty.FIGHT_PROP_CRITICAL)); + float igcrate = crate * 100; + CommandHandler.sendMessage(sender, "Crit Rate set to " + igcrate + "%."); + } catch (NumberFormatException ignored) { + CommandHandler.sendMessage(sender, "Invalid Crit Rate value."); + return; + } + break; + case "cdmg": + try { + float cdmg = Integer.parseInt(args.get(1)); + EntityAvatar entity = sender.getTeamManager().getCurrentAvatarEntity(); + float cdamage = cdmg / 10000; + entity.setFightProperty(FightProperty.FIGHT_PROP_CRITICAL_HURT, cdamage); + entity.getWorld().broadcastPacket(new PacketEntityFightPropUpdateNotify(entity, FightProperty.FIGHT_PROP_CRITICAL_HURT)); + float igcdmg = cdamage * 100; + CommandHandler.sendMessage(sender, "Crit DMG set to " + igcdmg + "%"); + } catch (NumberFormatException ignored) { + CommandHandler.sendMessage(sender, "Invalid Crit DMG value."); + return; + } + break; + } + } +} diff --git a/src/main/java/emu/grasscutter/command/commands/SetWorldLevel.java b/src/main/java/emu/grasscutter/command/commands/SetWorldLevelCommand.java similarity index 93% rename from src/main/java/emu/grasscutter/command/commands/SetWorldLevel.java rename to src/main/java/emu/grasscutter/command/commands/SetWorldLevelCommand.java index 2619ee3b6..146837523 100644 --- a/src/main/java/emu/grasscutter/command/commands/SetWorldLevel.java +++ b/src/main/java/emu/grasscutter/command/commands/SetWorldLevelCommand.java @@ -1,39 +1,39 @@ -package emu.grasscutter.command.commands; - -import emu.grasscutter.command.Command; -import emu.grasscutter.command.CommandHandler; -import emu.grasscutter.game.GenshinPlayer; -import emu.grasscutter.game.props.PlayerProperty; - -import java.util.List; - -@Command(label = "setworldlevel", usage = "setworldlevel ", - description = "Sets your world level (Relog to see proper effects)", - aliases = {"setworldlvl"}, permission = "player.setworldlevel") -public class SetWorldLevel implements CommandHandler { - - @Override - public void execute(GenshinPlayer sender, List args) { - if (sender == null) { - CommandHandler.sendMessage(null, "Run this command in-game."); - return; // TODO: set player's world level from console or other players - } - - if (args.size() < 1) { - CommandHandler.sendMessage(sender, "Usage: setworldlevel "); - return; - } - - try { - int level = Integer.parseInt(args.get(0)); - - // Set in both world and player props - sender.getWorld().setWorldLevel(level); - sender.setProperty(PlayerProperty.PROP_PLAYER_WORLD_LEVEL, level); - - sender.dropMessage("World level set to " + level + "."); - } catch (NumberFormatException ignored) { - CommandHandler.sendMessage(null, "Invalid world level."); - } - } -} +package emu.grasscutter.command.commands; + +import emu.grasscutter.command.Command; +import emu.grasscutter.command.CommandHandler; +import emu.grasscutter.game.GenshinPlayer; +import emu.grasscutter.game.props.PlayerProperty; + +import java.util.List; + +@Command(label = "setworldlevel", usage = "setworldlevel ", + description = "Sets your world level (Relog to see proper effects)", + aliases = {"setworldlvl"}, permission = "player.setworldlevel") +public final class SetWorldLevelCommand implements CommandHandler { + + @Override + public void execute(GenshinPlayer sender, List args) { + if (sender == null) { + CommandHandler.sendMessage(null, "Run this command in-game."); + return; // TODO: set player's world level from console or other players + } + + if (args.size() < 1) { + CommandHandler.sendMessage(sender, "Usage: setworldlevel "); + return; + } + + try { + int level = Integer.parseInt(args.get(0)); + + // Set in both world and player props + sender.getWorld().setWorldLevel(level); + sender.setProperty(PlayerProperty.PROP_PLAYER_WORLD_LEVEL, level); + + sender.dropMessage("World level set to " + level + "."); + } catch (NumberFormatException ignored) { + CommandHandler.sendMessage(null, "Invalid world level."); + } + } +} diff --git a/src/main/java/emu/grasscutter/command/commands/Spawn.java b/src/main/java/emu/grasscutter/command/commands/SpawnCommand.java similarity index 95% rename from src/main/java/emu/grasscutter/command/commands/Spawn.java rename to src/main/java/emu/grasscutter/command/commands/SpawnCommand.java index 5a3fc2b9c..969872119 100644 --- a/src/main/java/emu/grasscutter/command/commands/Spawn.java +++ b/src/main/java/emu/grasscutter/command/commands/SpawnCommand.java @@ -1,51 +1,51 @@ -package emu.grasscutter.command.commands; - -import emu.grasscutter.command.Command; -import emu.grasscutter.command.CommandHandler; -import emu.grasscutter.data.GenshinData; -import emu.grasscutter.data.def.MonsterData; -import emu.grasscutter.game.GenshinPlayer; -import emu.grasscutter.game.entity.EntityMonster; -import emu.grasscutter.utils.Position; - -import java.util.List; - -@Command(label = "spawn", usage = "spawn [level] [amount]", - description = "Spawns an entity near you", permission = "server.spawn") -public class Spawn implements CommandHandler { - - @Override - public void execute(GenshinPlayer sender, List args) { - if (sender == null) { - CommandHandler.sendMessage(null, "Run this command in-game."); - return; - } - - if (args.size() < 1) { - CommandHandler.sendMessage(sender, "Usage: spawn [amount]"); - return; - } - - try { - int entity = Integer.parseInt(args.get(0)); - int level = args.size() > 1 ? Integer.parseInt(args.get(1)) : 1; - int amount = args.size() > 2 ? Integer.parseInt(args.get(2)) : 1; - - MonsterData entityData = GenshinData.getMonsterDataMap().get(entity); - if (entityData == null) { - CommandHandler.sendMessage(sender, "Invalid entity id."); - return; - } - - float range = (5f + (.1f * amount)); - for (int i = 0; i < amount; i++) { - Position pos = sender.getPos().clone().addX((float) (Math.random() * range) - (range / 2)).addY(3f).addZ((float) (Math.random() * range) - (range / 2)); - EntityMonster monster = new EntityMonster(sender.getScene(), entityData, pos, level); - sender.getScene().addEntity(monster); - } - CommandHandler.sendMessage(sender, String.format("Spawned %s of %s.", amount, entity)); - } catch (NumberFormatException ignored) { - CommandHandler.sendMessage(sender, "Invalid item or player ID."); - } - } -} +package emu.grasscutter.command.commands; + +import emu.grasscutter.command.Command; +import emu.grasscutter.command.CommandHandler; +import emu.grasscutter.data.GenshinData; +import emu.grasscutter.data.def.MonsterData; +import emu.grasscutter.game.GenshinPlayer; +import emu.grasscutter.game.entity.EntityMonster; +import emu.grasscutter.utils.Position; + +import java.util.List; + +@Command(label = "spawn", usage = "spawn [level] [amount]", + description = "Spawns an entity near you", permission = "server.spawn") +public final class SpawnCommand implements CommandHandler { + + @Override + public void execute(GenshinPlayer sender, List args) { + if (sender == null) { + CommandHandler.sendMessage(null, "Run this command in-game."); + return; + } + + if (args.size() < 1) { + CommandHandler.sendMessage(sender, "Usage: spawn [amount]"); + return; + } + + try { + int entity = Integer.parseInt(args.get(0)); + int level = args.size() > 1 ? Integer.parseInt(args.get(1)) : 1; + int amount = args.size() > 2 ? Integer.parseInt(args.get(2)) : 1; + + MonsterData entityData = GenshinData.getMonsterDataMap().get(entity); + if (entityData == null) { + CommandHandler.sendMessage(sender, "Invalid entity id."); + return; + } + + float range = (5f + (.1f * amount)); + for (int i = 0; i < amount; i++) { + Position pos = sender.getPos().clone().addX((float) (Math.random() * range) - (range / 2)).addY(3f).addZ((float) (Math.random() * range) - (range / 2)); + EntityMonster monster = new EntityMonster(sender.getScene(), entityData, pos, level); + sender.getScene().addEntity(monster); + } + CommandHandler.sendMessage(sender, String.format("Spawned %s of %s.", amount, entity)); + } catch (NumberFormatException ignored) { + CommandHandler.sendMessage(sender, "Invalid item or player ID."); + } + } +} diff --git a/src/main/java/emu/grasscutter/command/commands/Stop.java b/src/main/java/emu/grasscutter/command/commands/StopCommand.java similarity index 90% rename from src/main/java/emu/grasscutter/command/commands/Stop.java rename to src/main/java/emu/grasscutter/command/commands/StopCommand.java index a76e33435..4b63cd44e 100644 --- a/src/main/java/emu/grasscutter/command/commands/Stop.java +++ b/src/main/java/emu/grasscutter/command/commands/StopCommand.java @@ -1,23 +1,23 @@ -package emu.grasscutter.command.commands; - -import emu.grasscutter.Grasscutter; -import emu.grasscutter.command.Command; -import emu.grasscutter.command.CommandHandler; -import emu.grasscutter.game.GenshinPlayer; - -import java.util.List; - -@Command(label = "stop", usage = "stop", - description = "Stops the server", permission = "server.stop") -public class Stop implements CommandHandler { - - @Override - public void execute(GenshinPlayer sender, List args) { - CommandHandler.sendMessage(null, "Server shutting down..."); - for (GenshinPlayer p : Grasscutter.getGameServer().getPlayers().values()) { - CommandHandler.sendMessage(p, "Server shutting down..."); - } - - System.exit(1); - } -} +package emu.grasscutter.command.commands; + +import emu.grasscutter.Grasscutter; +import emu.grasscutter.command.Command; +import emu.grasscutter.command.CommandHandler; +import emu.grasscutter.game.GenshinPlayer; + +import java.util.List; + +@Command(label = "stop", usage = "stop", + description = "Stops the server", permission = "server.stop") +public final class StopCommand implements CommandHandler { + + @Override + public void execute(GenshinPlayer sender, List args) { + CommandHandler.sendMessage(null, "Server shutting down..."); + for (GenshinPlayer p : Grasscutter.getGameServer().getPlayers().values()) { + CommandHandler.sendMessage(p, "Server shutting down..."); + } + + System.exit(1); + } +} diff --git a/src/main/java/emu/grasscutter/command/commands/Weather.java b/src/main/java/emu/grasscutter/command/commands/WeatherCommand.java similarity index 93% rename from src/main/java/emu/grasscutter/command/commands/Weather.java rename to src/main/java/emu/grasscutter/command/commands/WeatherCommand.java index ff3c77044..919432ed1 100644 --- a/src/main/java/emu/grasscutter/command/commands/Weather.java +++ b/src/main/java/emu/grasscutter/command/commands/WeatherCommand.java @@ -1,39 +1,39 @@ -package emu.grasscutter.command.commands; - -import emu.grasscutter.command.Command; -import emu.grasscutter.command.CommandHandler; -import emu.grasscutter.game.GenshinPlayer; -import emu.grasscutter.game.props.ClimateType; -import emu.grasscutter.server.packet.send.PacketSceneAreaWeatherNotify; - -import java.util.List; - -@Command(label = "weather", usage = "weather ", - description = "Changes the weather.", aliases = {"w"}, permission = "player.weather") -public class Weather implements CommandHandler { - - @Override - public void execute(GenshinPlayer sender, List args) { - if (sender == null) { - CommandHandler.sendMessage(null, "Run this command in-game."); - return; - } - - if (args.size() < 1) { - CommandHandler.sendMessage(sender, "Usage: weather "); - return; - } - - try { - int weatherId = Integer.parseInt(args.get(0)); - - ClimateType climate = ClimateType.getTypeByValue(weatherId); - - sender.getScene().setClimate(climate); - sender.getScene().broadcastPacket(new PacketSceneAreaWeatherNotify(sender)); - CommandHandler.sendMessage(sender, "Changed weather to " + weatherId); - } catch (NumberFormatException ignored) { - CommandHandler.sendMessage(sender, "Invalid weather ID."); - } - } -} +package emu.grasscutter.command.commands; + +import emu.grasscutter.command.Command; +import emu.grasscutter.command.CommandHandler; +import emu.grasscutter.game.GenshinPlayer; +import emu.grasscutter.game.props.ClimateType; +import emu.grasscutter.server.packet.send.PacketSceneAreaWeatherNotify; + +import java.util.List; + +@Command(label = "weather", usage = "weather ", + description = "Changes the weather.", aliases = {"w"}, permission = "player.weather") +public final class WeatherCommand implements CommandHandler { + + @Override + public void execute(GenshinPlayer sender, List args) { + if (sender == null) { + CommandHandler.sendMessage(null, "Run this command in-game."); + return; + } + + if (args.size() < 1) { + CommandHandler.sendMessage(sender, "Usage: weather "); + return; + } + + try { + int weatherId = Integer.parseInt(args.get(0)); + + ClimateType climate = ClimateType.getTypeByValue(weatherId); + + sender.getScene().setClimate(climate); + sender.getScene().broadcastPacket(new PacketSceneAreaWeatherNotify(sender)); + CommandHandler.sendMessage(sender, "Changed weather to " + weatherId); + } catch (NumberFormatException ignored) { + CommandHandler.sendMessage(sender, "Invalid weather ID."); + } + } +}