├── .gitignore ├── .idea ├── .gitignore ├── discord.xml ├── misc.xml └── vcs.xml ├── README.md ├── pom.xml └── src └── main ├── java └── uk │ └── haku │ └── gcequip │ ├── GcEquip.java │ └── commands │ └── EquipCommand.java └── resources └── plugin.json /.gitignore: -------------------------------------------------------------------------------- 1 | target/ 2 | !.mvn/wrapper/maven-wrapper.jar 3 | !**/src/main/**/target/ 4 | !**/src/test/**/target/ 5 | 6 | ### IntelliJ IDEA ### 7 | .idea/modules.xml 8 | .idea/jarRepositories.xml 9 | .idea/compiler.xml 10 | .idea/libraries/ 11 | *.iws 12 | *.iml 13 | *.ipr 14 | 15 | ### Eclipse ### 16 | .apt_generated 17 | .classpath 18 | .factorypath 19 | .project 20 | .settings 21 | .springBeans 22 | .sts4-cache 23 | 24 | ### NetBeans ### 25 | /nbproject/private/ 26 | /nbbuild/ 27 | /dist/ 28 | /nbdist/ 29 | /.nb-gradle/ 30 | build/ 31 | !**/src/main/**/build/ 32 | !**/src/test/**/build/ 33 | 34 | ### VS Code ### 35 | .vscode/ 36 | 37 | ### Mac OS ### 38 | .DS_Store 39 | 40 | lib -------------------------------------------------------------------------------- /.idea/.gitignore: -------------------------------------------------------------------------------- 1 | # Default ignored files 2 | /shelf/ 3 | /workspace.xml 4 | # Editor-based HTTP Client requests 5 | /httpRequests/ 6 | # Datasource local storage ignored files 7 | /dataSources/ 8 | /dataSources.local.xml 9 | -------------------------------------------------------------------------------- /.idea/discord.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 7 | -------------------------------------------------------------------------------- /.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 10 | 11 | 12 | 13 | 14 | 15 | 18 | 19 | -------------------------------------------------------------------------------- /.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Equip Weapon Plugin 2 | 3 | ## Installation 4 | 1. Download GcEquip-1.0.0.jar from Release. 5 | 2. Put it to your Grasscutter plugin folder. 6 | 7 | ## Command Usage 8 | 1. > /equip {weaponId} 9 | 2. > /eq {weaponId} 10 | 11 | ### Version 12 | The plugin template is compatible with Grasscutter version `1.4.5-dev`. 13 | -------------------------------------------------------------------------------- /pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | uk.haku 8 | GcEquip 9 | 1.0.1 10 | 11 | 12 | 17 13 | 17 14 | 15 | 16 | 17 | 18 | sonatype 19 | https://s01.oss.sonatype.org/content/groups/public/ 20 | 21 | 22 | 23 | 24 | 25 | xyz.grasscutters 26 | grasscutter 27 | 1.4.5-dev 28 | system 29 | ${project.basedir}/lib/grasscutter-1.4.5-dev.jar 30 | 31 | 32 | -------------------------------------------------------------------------------- /src/main/java/uk/haku/gcequip/GcEquip.java: -------------------------------------------------------------------------------- 1 | package uk.haku.gcequip; 2 | 3 | import emu.grasscutter.plugin.Plugin; 4 | import uk.haku.gcequip.commands.*; 5 | 6 | 7 | /** 8 | * The Grasscutter plugin template. 9 | * This is the main class for the plugin. 10 | */ 11 | public final class GcEquip extends Plugin { 12 | /* Turn the plugin into a singleton. */ 13 | private static GcEquip instance; 14 | 15 | /** 16 | * Gets the plugin instance. 17 | * @return A plugin singleton. 18 | */ 19 | public static GcEquip getInstance() { 20 | return instance; 21 | } 22 | 23 | /** 24 | * This method is called immediately after the plugin is first loaded into system memory. 25 | */ 26 | @Override public void onLoad() { 27 | // Log a plugin status message. 28 | this.getLogger().info("The GcEquip plugin has been loaded."); 29 | } 30 | 31 | /** 32 | * This method is called before the servers are started, or when the plugin enables. 33 | */ 34 | @Override public void onEnable() { 35 | // Register commands. 36 | this.getHandle().registerCommand(new EquipCommand()); 37 | 38 | // Log a plugin status message. 39 | this.getLogger().info("The GcEquip plugin has been enabled."); 40 | } 41 | 42 | /** 43 | * This method is called when the plugin is disabled. 44 | */ 45 | @Override public void onDisable() { 46 | // Log a plugin status message. 47 | this.getLogger().info("The GcEquip plugin has been disabled."); 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /src/main/java/uk/haku/gcequip/commands/EquipCommand.java: -------------------------------------------------------------------------------- 1 | package uk.haku.gcequip.commands; 2 | 3 | import emu.grasscutter.command.Command; 4 | import emu.grasscutter.command.CommandHandler; 5 | import emu.grasscutter.data.GameData; 6 | import emu.grasscutter.data.excels.ItemData; 7 | import emu.grasscutter.game.avatar.Avatar; 8 | import emu.grasscutter.game.inventory.GameItem; 9 | import emu.grasscutter.game.inventory.ItemType; 10 | import emu.grasscutter.game.player.Player; 11 | 12 | import java.util.List; 13 | 14 | @Command(label = "equip", usage = "equip ", aliases = { 15 | "eq" }, permission = "player.equip", permissionTargeted = "player.equip.others") 16 | public final class EquipCommand implements CommandHandler { 17 | @Override 18 | public void execute(Player sender, Player targetPlayer, List args) { 19 | GameItem targetItem; 20 | int itemId; 21 | Avatar activeAvatar; 22 | 23 | // Check if args is valid. 24 | if (args.size() != 1) { 25 | CommandHandler.sendMessage(sender, "Wrong args size. Usage: equip "); 26 | return; 27 | } 28 | 29 | // Get item data. 30 | itemId = Integer.parseInt(args.get(0)); 31 | ItemData itemData = GameData.getItemDataMap().get(itemId); 32 | 33 | // Check if item data is valid. 34 | if (itemData == null) { 35 | CommandHandler.sendMessage(sender, "Invalid weaponId"); 36 | return; 37 | } 38 | 39 | // Check if item is weapon. 40 | if (itemData.getItemType() != ItemType.ITEM_WEAPON) { 41 | CommandHandler.sendMessage(sender, "Invalid weaponId"); 42 | return; 43 | } 44 | 45 | // Set target player. 46 | Player player = sender; 47 | if (player == null) { 48 | CommandHandler.sendMessage(sender, "Invalid player"); 49 | return; 50 | } 51 | 52 | if (targetPlayer != null) { 53 | player = targetPlayer; 54 | } 55 | 56 | // Get weapon from inventory and it is not equiped by other character. 57 | List items = player.getInventory().getItems().values().stream() 58 | .filter(item -> item.getItemId() == itemId) 59 | .filter(item -> !item.isEquipped()) 60 | .toList(); 61 | 62 | // Check if weapon is in inventory. Create new weapon item if not. 63 | if (items.size() == 0) { 64 | targetItem = new GameItem(itemId); 65 | targetItem.setRefinement(5); 66 | targetItem.setLevel(90); 67 | targetItem.setPromoteLevel(6); 68 | } else { 69 | targetItem = items.get(0); 70 | } 71 | 72 | // Get active avatar. 73 | activeAvatar = player.getTeamManager().getCurrentAvatarEntity().getAvatar(); 74 | 75 | // Equip weapon. 76 | boolean isSuccess = activeAvatar.equipItem(targetItem, true); 77 | 78 | if (isSuccess == true) { 79 | CommandHandler.sendMessage(sender, "Succes equiping weapon " + targetItem.getItemId()); 80 | } else { 81 | CommandHandler.sendMessage(sender, "Failed to equip weapon"); 82 | } 83 | } 84 | } 85 | -------------------------------------------------------------------------------- /src/main/resources/plugin.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "GcEquip", 3 | "description": "A grasscutter plugin to equip weapon to any character regardless of the types of weapon", 4 | "version": "1.0.1", 5 | "authors": [ "Ffauzan" ], 6 | 7 | "mainClass": "uk.haku.gcequip.GcEquip", 8 | 9 | "comments": [ 10 | "This comments block doesn't need to be in your plugin.json.", 11 | "The mainClass should include the FQDN of the main plugin class.", 12 | "Required fields are: 'name', 'description', and 'mainClass'." 13 | ] 14 | } --------------------------------------------------------------------------------