java.lang.Object
net.citizensnpcs.api.trait.Trait
rocks.gravili.notquests.paper.managers.integrations.citizens.QuestGiverNPCTrait
All Implemented Interfaces:
Runnable, org.bukkit.event.Listener

public class QuestGiverNPCTrait extends net.citizensnpcs.api.trait.Trait
This handles the QuestGiver NPC Trait which is given directly to Citizens NPCs via their API. A lot of things from this ugly class have been copy-and-pasted from their wiki.

Only NPCs which have quests attached to them should have this trait. There are several methods in the plugin which remove the trait from NPCs which do not have Quests stored on them - for example that cleanup runs when the plugin restarts.

Note: TODO: The available Quests are not stored in the NPC directly. Instead, each quest object stores the NPC. Because of this, it has to loop through. This should be improved in the future for better performance.

  • Field Summary

    Fields inherited from class net.citizensnpcs.api.trait.Trait

    npc
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    click(net.citizensnpcs.api.event.NPCRightClickEvent event)
    Called when a player clicks on the NPC.
    void
    load(net.citizensnpcs.api.util.DataKey key)
     
    void
    Run code when your trait is attached to a NPC.
    void
     
    void
    Run code when the NPC is removed.
    void
     
    void
    run()
    Called every tick.
    void
    save(net.citizensnpcs.api.util.DataKey key)
     

    Methods inherited from class net.citizensnpcs.api.trait.Trait

    getName, getNPC, isRunImplemented, linkToNPC, onCopy, onPreSpawn

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • QuestGiverNPCTrait

      public QuestGiverNPCTrait()
  • Method Details

    • load

      public void load(net.citizensnpcs.api.util.DataKey key)
      Overrides:
      load in class net.citizensnpcs.api.trait.Trait
    • save

      public void save(net.citizensnpcs.api.util.DataKey key)
      Overrides:
      save in class net.citizensnpcs.api.trait.Trait
    • click

      public void click(net.citizensnpcs.api.event.NPCRightClickEvent event)
      Called when a player clicks on the NPC. This will send the quest preview GUI / Text to the player, which lists all available Quests for this NPC.

      The available Quests are not stored in the NPC directly. Instead, each quest object stores the NPC. Because of this, it has to loop through. This should be improved in the future for better performance.

    • run

      public void run()
      Called every tick. This spawns a particle above an NPCs head which has this Trait, showcasing to the player that they have Quests and can be clicked.
      Specified by:
      run in interface Runnable
      Overrides:
      run in class net.citizensnpcs.api.trait.Trait
    • onAttach

      public void onAttach()
      Run code when your trait is attached to a NPC. This is called BEFORE onSpawn, so npc.getEntity() will return null This will just splurt out a debug message, so we know when the trait has been attached to the NPC.
      Overrides:
      onAttach in class net.citizensnpcs.api.trait.Trait
    • onDespawn

      public void onDespawn()
      Overrides:
      onDespawn in class net.citizensnpcs.api.trait.Trait
    • onSpawn

      public void onSpawn()
      Overrides:
      onSpawn in class net.citizensnpcs.api.trait.Trait
    • onRemove

      public void onRemove()
      Run code when the NPC is removed. This will also remove from the Quest object that the NPC is attached to it - since the NPC does not exist anymore. Otherwise, the plugin would try giving a non-existent NPC the NPC trait.

      This method is not called when the NPC is just despawned, but when it's completely removed and thus won't exist anymore.

      Overrides:
      onRemove in class net.citizensnpcs.api.trait.Trait