Issues with Faction/Citizens 2 integration

Discussion in 'Spigot Plugin Development' started by TheRedCrafter344, May 28, 2018.

  1. Ok, I don't even know where to start.
    When I start the server I get a null pointer exception.
    Here is the log:
    Code (Text):
    [19:32:26] [Server thread/WARN]: [Citizens] Task #67 for Citizens v2.0.22-SNAPSHOT (build 1487) generated an exception
    java.lang.NullPointerException
        at redcrafter.factioncontrol.FactionTrait.onAttach(FactionTrait.java:45) ~[?:?]
        at net.citizensnpcs.api.trait.Trait.linkToNPC(Trait.java:46) ~[?:?]
        at net.citizensnpcs.api.npc.AbstractNPC.addTrait(AbstractNPC.java:100) ~[?:?]
        at net.citizensnpcs.api.npc.AbstractNPC.load(AbstractNPC.java:300) ~[?:?]
        at net.citizensnpcs.npc.CitizensNPC.load(CitizensNPC.java:134) ~[?:?]
        at net.citizensnpcs.api.npc.SimpleNPCDataStore.loadInto(SimpleNPCDataStore.java:59) ~[?:?]
        at net.citizensnpcs.Citizens$2.run(Citizens.java:305) ~[?:?]
        at org.bukkit.craftbukkit.v1_10_R1.scheduler.CraftTask.run(CraftTask.java:71) ~[minecraft_server.jar:git-Spigot-de459a2-51263e9]
        at org.bukkit.craftbukkit.v1_10_R1.scheduler.CraftScheduler.mainThreadHeartbeat(CraftScheduler.java:353) [minecraft_server.jar:git-Spigot-de459a2-51263e9]
        at net.minecraft.server.v1_10_R1.MinecraftServer.D(MinecraftServer.java:723) [minecraft_server.jar:git-Spigot-de459a2-51263e9]
        at net.minecraft.server.v1_10_R1.DedicatedServer.D(DedicatedServer.java:400) [minecraft_server.jar:git-Spigot-de459a2-51263e9]
        at net.minecraft.server.v1_10_R1.MinecraftServer.C(MinecraftServer.java:668) [minecraft_server.jar:git-Spigot-de459a2-51263e9]
        at net.minecraft.server.v1_10_R1.MinecraftServer.run(MinecraftServer.java:567) [minecraft_server.jar:git-Spigot-de459a2-51263e9]
        at java.lang.Thread.run(Thread.java:748) [?:1.8.0_171]
    Here is my code:
    Code (Java):
    public void onAttach() {
            originalOwner = getNPC().getTrait(Owner.class).getOwnerId().toString();
            faction = FactionColl.get().getNone().getId();
        }
    This is the first problem. Apart from that, when I rightclick an NPC, i get this:
    Code (Text):
    [19:35:28] [Server thread/ERROR]: Could not pass event NPCRightClickEvent to Citizens v2.0.22-SNAPSHOT (build 1487)
    org.bukkit.event.EventException
        at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:306) ~[minecraft_server.jar:git-Spigot-de459a2-51263e9]
        at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:62) ~[minecraft_server.jar:git-Spigot-de459a2-51263e9]
        at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.java:502) [minecraft_server.jar:git-Spigot-de459a2-51263e9]
        at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:487) [minecraft_server.jar:git-Spigot-de459a2-51263e9]
        at net.citizensnpcs.EventListen.onPlayerInteractEntity(EventListen.java:414) [Citizens(4).jar:?]
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_171]
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:1.8.0_171]
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0_171]
        at java.lang.reflect.Method.invoke(Method.java:498) ~[?:1.8.0_171]
        at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:302) [minecraft_server.jar:git-Spigot-de459a2-51263e9]
        at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:62) [minecraft_server.jar:git-Spigot-de459a2-51263e9]
        at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.java:502) [minecraft_server.jar:git-Spigot-de459a2-51263e9]
        at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:487) [minecraft_server.jar:git-Spigot-de459a2-51263e9]
        at net.minecraft.server.v1_10_R1.PlayerConnection.a(PlayerConnection.java:1540) [minecraft_server.jar:git-Spigot-de459a2-51263e9]
        at net.minecraft.server.v1_10_R1.PacketPlayInUseEntity.a(SourceFile:68) [minecraft_server.jar:git-Spigot-de459a2-51263e9]
        at net.minecraft.server.v1_10_R1.PacketPlayInUseEntity.a(SourceFile:12) [minecraft_server.jar:git-Spigot-de459a2-51263e9]
        at net.minecraft.server.v1_10_R1.PlayerConnectionUtils$1.run(SourceFile:13) [minecraft_server.jar:git-Spigot-de459a2-51263e9]
        at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) [?:1.8.0_171]
        at java.util.concurrent.FutureTask.run(FutureTask.java:266) [?:1.8.0_171]
        at net.minecraft.server.v1_10_R1.SystemUtils.a(SourceFile:45) [minecraft_server.jar:git-Spigot-de459a2-51263e9]
        at net.minecraft.server.v1_10_R1.MinecraftServer.D(MinecraftServer.java:732) [minecraft_server.jar:git-Spigot-de459a2-51263e9]
        at net.minecraft.server.v1_10_R1.DedicatedServer.D(DedicatedServer.java:400) [minecraft_server.jar:git-Spigot-de459a2-51263e9]
        at net.minecraft.server.v1_10_R1.MinecraftServer.C(MinecraftServer.java:668) [minecraft_server.jar:git-Spigot-de459a2-51263e9]
        at net.minecraft.server.v1_10_R1.MinecraftServer.run(MinecraftServer.java:567) [minecraft_server.jar:git-Spigot-de459a2-51263e9]
        at java.lang.Thread.run(Thread.java:748) [?:1.8.0_171]
    Caused by: java.lang.NoSuchMethodError: com.massivecraft.factions.entity.FactionColl.get(Ljava/lang/Object;)Lcom/massivecraft/factions/entity/Faction;
        at redcrafter.factioncontrol.FactionTrait.getFaction(FactionTrait.java:54) ~[?:?]
        at redcrafter.factioncontrol.FactionTrait.onClick(FactionTrait.java:37) ~[?:?]
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_171]
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:1.8.0_171]
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0_171]
        at java.lang.reflect.Method.invoke(Method.java:498) ~[?:1.8.0_171]
        at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:302) ~[minecraft_server.jar:git-Spigot-de459a2-51263e9]
        ... 24 more
    Actually, here is my whole trait code:
    Code (Java):
    package redcrafter.factioncontrol;

    import java.util.UUID;

    import org.bukkit.Bukkit;
    import org.bukkit.OfflinePlayer;
    import org.bukkit.event.EventHandler;

    import com.massivecraft.factions.Rel;
    import com.massivecraft.factions.entity.Faction;
    import com.massivecraft.factions.entity.FactionColl;
    import com.massivecraft.factions.entity.MPlayer;

    import net.citizensnpcs.api.event.NPCRightClickEvent;
    import net.citizensnpcs.api.persistence.Persist;
    import net.citizensnpcs.api.trait.Trait;
    import net.citizensnpcs.api.trait.TraitName;
    import net.citizensnpcs.api.trait.trait.Owner;

    @TraitName("faction")
    public class FactionTrait extends Trait {

        @Persist
        private String originalOwner;
       
        @Persist
        private String faction;
       
        public FactionTrait() {
            super("faction");
        }
       
        @EventHandler
        public void onClick(NPCRightClickEvent e) {
            if(e.getNPC() != getNPC()) return;
            Faction f = MPlayer.get(e.getClicker()).getFaction();
            if((f.getId().equals(getFaction().getId()) && (MPlayer.get(e.getClicker()).getRelationTo(f) == Rel.OFFICER || MPlayer.get(e.getClicker()).getRelationTo(f) == Rel.LEADER))
            || e.getClicker().getUniqueId().toString().equals(originalOwner)) {
                getNPC().getTrait(Owner.class).setOwner(e.getClicker());
                e.getClicker().sendMessage("Revokable ownership of the NPC transferred to you!");
            }
        }
       
        public void onAttach() {
            originalOwner = getNPC().getTrait(Owner.class).getOwnerId().toString();
            faction = FactionColl.get().getNone().getId();
        }
       
        public void setFaction(Faction f) {
            faction = f.getId();
        }
       
        public Faction getFaction() {
            if(FactionColl.get().containsId(faction)) return FactionColl.get().get(faction);
            setFaction(FactionColl.get().getNone());
            return FactionColl.get().getNone();
        }
       
        public OfflinePlayer getOriginalOwner() {
            return Bukkit.getOfflinePlayer(UUID.fromString(originalOwner));
        }
       
        public void setOriginalOwner(OfflinePlayer p) {
            originalOwner = p.getUniqueId().toString();
        }
    }
    have fun trying to find the problem because i have no idea what's happening.