Shopkeepers

Shopkeepers

2M Downloads

Copy shopkeeper data (eg. trades, etc.) when the associated Citizens NPC is copied (/npc copy)

Aknotl opened this issue ยท 4 comments

commented

Preliminaries:

  • Shopkeepers version: 2.12.0
  • Spigot version: Paper version git-Paper-345 (MC: 1.16.4) (Implementing API version 1.16.4-R0.1-SNAPSHOT)

  • I have checked that my issue/question does not get answered by:
  • I have checked all open and closed issues, but none seems to fit my issue/question.

Reproduction on a fresh and up-to-date Spigot server:

I was not able to reproduce my issue on a freshly setup and up-to-date Spigot server (currently Paper version git-Paper-345 (MC: 1.16.4) (Implementing API version 1.16.4-R0.1-SNAPSHOT)) with the latest version of Shopkeepers (currently 2.12.0), with no other plugins and with no kinds of other server or client mods.
Note : i can only tested on my public server, with other plugins, and on client optifine installed.

Issue :

  • Create citizens shopkeepers with the command /npc create test and /trait add shopkeeper
  • Fill it with one trade (I put 1 dirt for 1 cobble)
  • Execute /npc copy

Observed behavior :
The citizens npc is copied, there is a shopkeeper interface when right-clicked, but there is no trade.

Expected behavior :
The citizens npc should be copied with all trades.

When I wrote this issue I realized that I did citizens commands. However, I think that giving a way to copy shopkeeper could be very useful for this plugin. My players appreciate the vanilla style of the interface, in my opinion it only lacks a way to automate it.
I suppose that this issue is related to that : #480

Thanks a lot for taking time to read this.

commented

Yeah, this will not work, and I am not sure if this is even expected to work this way. The shopkeeper data is not stored with the Citizens NPC, but the other way around: The shopkeeper exists independently and the Citizens NPC is linked to the shopkeeper and used as its representation in the world (just like other forms of shopkeeper representations, such as the various kinds of mobs, or signs for sign shops).
When you copy the citizen NPC, you are not really copying the shopkeeper associated with it. What happens is that the Citizens plugin will copy the trait and attach it to that new NPC. The Shopkeepers plugin handles this just like when you manually add the shopkeeper trait to a new NPC: It creates a new shopkeeper for it and links the NPC to it.

There is currently no way yet to copy a shopkeeper and all of its associated data (see the ticket you linked). Once there is a way to copy shopkeepers, I can look into whether or not I can detect the copying of a Citizens NPC with the shopkeeper trait and automatically trigger a copy of the associated shopkeeper and link it to the new Citizens NPC.

However, there are several things to do first before I can even start looking into this.

in my opinion it only lacks a way to automate it

I am not exactly sure what you mean by 'automate it'. However, even though there are no commands to copy shopkeepers or add trades to them via commands, there is an API with which you can programmatically create new shopkeepers and add trades to them. You could even use it to implement your own copy command that copies over the trades. I even did something like this in the past as a separate plugin as a proof of concept, but that might be outdated by now (not sure): https://github.com/blablubbabc/ShopkeeperCopy
However, this only covers (copies) the explicitly hard-coded aspects of shopkeeper data, which is why there is still the need to support a general copy of shopkeepers data in the Shopkeepers plugin itself (and which is why that linked ticket is still open).

I will keep this ticket open as a reminder for this use case to look into once there is a way to copy shopkeepers. But don't expect any progress in that direction any time soon (there are other, more important things too look into first; which is why that linked ticket already exists for that long). The 'workaround' is to write your own little addon plugin (or use the one I linked, if that still works and suffices your needs) and implement your own copy command that covers your automation needs for the time being.

commented

You can find the contents of the shopkeeper API here: https://github.com/Shopkeepers/Shopkeepers/tree/master/src/api/java/com/nisovin/shopkeepers/api

You can of course also hook into more-internal aspects of the Shopkeepers plugin (since not all aspects of the plugin have been exposed via the API yet), however, these are generally less stable across updates. However, even the API itself is not considered stable yet (which is why there is no real documentation for it yet).
Typically you can access the various aspects of the Shopkeeper API via the class ShopkeepersAPI (https://github.com/Shopkeepers/Shopkeepers/blob/master/src/api/java/com/nisovin/shopkeepers/api/ShopkeepersAPI.java).
For example, there are methods to create shopkeepers:

You can hook into the plugin or the API portion of the plugin by importing it via Maven. See the Readme for the available Maven repositories that host Shopkeeper artifacts: https://github.com/Shopkeepers/Shopkeepers

Import example:

<dependency>
  <groupId>com.nisovin.shopkeepers</groupId>
  <artifactId>ShopkeepersAPI</artifactId>
  <version>2.12.0</version>
</dependency>
commented

Ok! Thanks a lot for the documentation, I will try to progress with that :)

commented

Quick response, thank you very much, it helps me a lot !

I will explore these ways for doing what I want. However, do you have a link about the API ? I'm not sure what is the Shopkeepers API, and I can't find any information on the web.