Skip to content

Add player trade command (/wp trade <playerName>)#298

Open
Copilot wants to merge 4 commits intomainfrom
copilot/add-player-trade-feature
Open

Add player trade command (/wp trade <playerName>)#298
Copilot wants to merge 4 commits intomainfrom
copilot/add-player-trade-feature

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Mar 8, 2026

  • Explore codebase and understand command structure, pet ownership, and persistence
  • Create TradeCommand.java - new command to transfer selected pet to another online player (/wp trade <playerName>)
  • Add transferPet method to PetListRepository for clean pet ownership transfer
  • Register TradeCommand in WildPets.java command initialization
  • Add wp.trade permission to plugin.yml
  • Add trade command to HelpCommand.java help text
  • Run code review and address feedback (remove old owner from access list, fix help text style)
  • Run CodeQL security check (no issues found)
  • Address PR review comments:
    • Reorder validation: check args.length before pet selection for correct error messages
    • Use Bukkit.getPlayerExact() instead of Bukkit.getPlayer() to avoid partial name matching
    • Add petLimit check in transferPet() to prevent exceeding the configured pet cap (with rollback on failure)
Original prompt

This section details on the original issue you should resolve

<issue_title>Player Trade Feature</issue_title>
<issue_description>A player option to "Trade" a pet to another player. My player's want pets that they can sell to each other. A simple Trade feature would work and then the players can use our pay features we already have to settle payment on their own. (I did see there was a type of "release" command already, but a trade option would simplify things in my opinion. At least for this purpose.)</issue_description>

Comments on the Issue (you are @copilot in this section)


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI and others added 2 commits March 8, 2026 09:26
Co-authored-by: dmccoystephenson <21204351+dmccoystephenson@users.noreply.github.com>
… consistency

Co-authored-by: dmccoystephenson <21204351+dmccoystephenson@users.noreply.github.com>
Copilot AI changed the title [WIP] Add player trade feature for pets Add player trade command (/wp trade <playerName>) Mar 8, 2026
@dmccoystephenson dmccoystephenson requested a review from Copilot March 8, 2026 09:39
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a new /wp trade <playerName> subcommand to transfer ownership of the caller’s currently selected pet to another online player, updating both in-memory pet lists and persisted pet records.

Changes:

  • Introduces TradeCommand to validate and perform pet ownership transfer, notify both players, and clear the sender’s selection.
  • Adds PetListRepository.transferPet() to move a pet between owners’ pet lists while preserving entity properties.
  • Wires the command into plugin initialization, help output, and permissions.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
src/main/resources/plugin.yml Adds wp.trade permission node.
src/main/java/dansplugins/wildpets/pet/list/PetListRepository.java Adds transferPet() for moving pets between owners.
src/main/java/dansplugins/wildpets/commands/TradeCommand.java New /wp trade command implementation.
src/main/java/dansplugins/wildpets/commands/HelpCommand.java Adds trade command line to help output.
src/main/java/dansplugins/wildpets/WildPets.java Registers TradeCommand in command initialization.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +59 to +69
PetList newList = getPetList(newOwnerUUID);
if (newList == null) {
createPetListForPlayer(newOwnerUUID);
newList = getPetList(newOwnerUUID);
}

pet.setOwnerUUID(newOwnerUUID);
pet.removeFromAccessList(oldList.getOwnerUUID());
pet.addToAccessList(newOwnerUUID);
newList.addPet(pet);
return true;
Copy link

Copilot AI Mar 8, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

transferPet allows bypassing the configured petLimit (currently only enforced during taming). A player can trade pets to someone who is already at the limit, exceeding the cap. Add a limit check against configService.getInt("petLimit") before adding to the recipient list (and return false with a meaningful failure path).

Copilot uses AI. Check for mistakes.
Comment on lines +58 to +63
String targetName = args[0];
Player targetPlayer = Bukkit.getPlayer(targetName);

if (targetPlayer == null) {
player.sendMessage(ChatColor.RED + "That player is not online.");
return false;
Copy link

Copilot AI Mar 8, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bukkit.getPlayer(String) performs partial name matching and can return the wrong player if multiple online names share a prefix. For a trade/ownership transfer, use Bukkit.getPlayerExact(targetName) (or otherwise disambiguate) to avoid transferring a pet to an unintended player.

Copilot uses AI. Check for mistakes.
Comment on lines +48 to +57
Pet pet = ephemeralData.getPetSelectionForPlayer(player.getUniqueId());
if (pet == null) {
player.sendMessage(ChatColor.RED + "No pet selected. Use /wp select first.");
return false;
}

if (args.length < 1) {
return execute(sender);
}

Copy link

Copilot AI Mar 8, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The missing-argument check happens after the selected-pet check, so /wp trade with no args can report "No pet selected" instead of showing usage. For consistency with commands like RenameCommand, validate args.length first (show usage), then validate selection/transfer prerequisites.

Suggested change
Pet pet = ephemeralData.getPetSelectionForPlayer(player.getUniqueId());
if (pet == null) {
player.sendMessage(ChatColor.RED + "No pet selected. Use /wp select first.");
return false;
}
if (args.length < 1) {
return execute(sender);
}
if (args.length < 1) {
return execute(sender);
}
Pet pet = ephemeralData.getPetSelectionForPlayer(player.getUniqueId());
if (pet == null) {
player.sendMessage(ChatColor.RED + "No pet selected. Use /wp select first.");
return false;
}

Copilot uses AI. Check for mistakes.
@dmccoystephenson
Copy link
Copy Markdown
Member

@copilot address comments

… check

Co-authored-by: dmccoystephenson <21204351+dmccoystephenson@users.noreply.github.com>
Copy link
Copy Markdown
Contributor Author

Copilot AI commented Mar 8, 2026

@copilot address comments

All three review comments addressed in 86b1d14:

  • Reordered validation so args.length is checked before pet selection (shows usage instead of "no pet selected" when args missing)
  • Switched from Bukkit.getPlayer() to Bukkit.getPlayerExact() to avoid partial name matching
  • Added petLimit check in transferPet() that prevents exceeding the configured cap and rolls back the removal if the recipient is at their limit

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +53 to +55
public boolean transferPet(Pet pet, UUID newOwnerUUID) {
PetList oldList = getPetList(pet.getOwnerUUID());
if (oldList == null || !oldList.getPets().remove(pet)) {
Copy link

Copilot AI Mar 21, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pet exposes getOwnerUUID(), but this new code calls pet.getOwnerUUID() (missing UUID). This won't compile and will prevent the plugin from building. Update the call to use the correct method name.

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Player Trade Feature

3 participants