CitizensDev / Citizens2

Citizens - the premier plugin and API for creating server-side NPCs in Minecraft.
https://citizensnpcs.co
Open Software License 3.0
590 stars 313 forks source link

Persist API not working across extended classes. #2091

Closed Xemorr closed 4 years ago

Xemorr commented 4 years ago

My issue is: I have an abstract class called NPC with some persist fields. `public abstract class NPC extends Trait {

protected NPC(String name) {
    super(name);
}

@Persist
public String name = "Default";

@Persist
public String rank = "&8&l[&7Human&8&l]";

public void sendMessage(Player player, String string) {
    player.sendMessage(ChatColor.translateAlternateColorCodes('&', rank + " &7" + name +  " &8&l>> &7" + string));
}

} and a trait that extends this NPC public class Talker extends NPC {

public Talker() {
    super("Talker");
    if (messages.isEmpty()) {
        messages.add("Hello! This is the default message");
    }
}

@Persist
List<String> messages = new ArrayList<>();

@EventHandler
public void onRightClick(NPCRightClickEvent event) {
    if (this.getNPC() == event.getNPC()) {
        for (int i = 0; i < messages.size(); i++) {
            String message = messages.get(i);
            new BukkitRunnable() {
                @Override
                public void run() {
                    sendMessage(event.getClicker(), message);
                }
            }.runTaskLater(JavaPlugin.getPlugin(SkyblockNPCs.class), i * 10);

        }
    }
}

} `

The issue is, only the traits inside of Talker are actually saved to the config. talker: messages: '0': Hello! This is the default message '1': 'Hi hi hih ih ih ih i '

The output of command /version on my server is: This server is running Paper version git-Paper-655 (MC: 1.13.2) (Implementing API version 1.13.2-R0.1-SNAPSHOT) The output of command /version citizens on my server is: Citizens version 2.0.25-SNAPSHOT (build 1709)

mcmonkey4eva commented 4 years ago
Xemorr commented 4 years ago

I'm using 2.0.25-SNAPSHOT in my pom.xml, but I'll update to 2.0.26 and see if it fixes it. I'll rename NPC to BaseTrait as well.

Xemorr commented 4 years ago

I updated to 2.0.26-SNAPSHOT in my pom and I'm using the latest build as you linked to and it has exactly the same behavior. I created a new NPC and applied my talker trait, and it was the same.

fullwall commented 4 years ago

This is a feature request, because PersistenceLoader doesn't support superclasses yet.

Xemorr commented 4 years ago

Thanks fullwall, Any ETA on when this will be fixed, or should I just build in the @Persist attributes into each of my classes :(

fullwall commented 4 years ago

I'll need to work out a strategy for doing it properly - might take a few days. In the meantime, just build it into your classes.

fullwall commented 4 years ago

Just pushed a simple implementation that pulls in superclasses - no namespacing as yet.