#Using the CitizensAPI

1 messages · Page 1 of 1 (latest)

fallow dove
#

Let's chat here

round crescent
#

Ok

#

pom.xml

<repository>
            <id>everything</id>
            <url>https://repo.citizensnpcs.co/</url>
</repository>
<dependency>
            <groupId>net.citizensnpcs</groupId>
            <artifactId>citizensapi</artifactId>
            <version>2.0.29-SNAPSHOT</version>
            <type>jar</type>
            <scope>compile</scope>
</dependency>
#

plugin.yml

name: Mobarobot
version: '${project.version}'
main: ttomek.mobarobot.Mobarobot
api-version: 1.18
authors: [ ttomek ]
description: a
website: cyber-man.pl
fallow dove
#

You need to depend on Citizens in your plugin.yml

#

Depending on it will make sure it loads before your plugin so there won't be any issues

round crescent
#

pretty sure it's loading before. I have plugin manager and im reloading my plugin and citizens stay loaded

#

but will add anyway

fallow dove
#

Don't do that

#

Always restart

#

No reloads and no plugin managers if you don't know what they are and how they work

round crescent
#
name: Mobarobot
version: '${project.version}'
main: ttomek.mobarobot.Mobarobot
api-version: 1.18
authors: [ ttomek ]
description: a
website: cyber-man.pl
depend:
  - Citizens
#

like this?

fallow dove
#

Yeah

round crescent
#

Ok and now resetting server

#

whole

#

not via pluginamanager

round crescent
fallow dove
#

Doubt it

round crescent
#

well, i restart as u said

#

pluginmanager unload and load is performing natual loading lpugin and reload in this case is doing just unload then load

#

Lol

#

when i added the depend

#

now in the console my plugin logs appear much before Citizens [Citizens] Loaded 0 NPCs.

#

However it fixed Citizens 2.0 not found or not enabled

fallow dove
round crescent
#

but still java.lang.IllegalStateException: no implementation set at net.citizensnpcs.api.CitizensAPI.getImplementation(CitizensAPI.java:79)

round crescent
fallow dove
#

Anyways classloading and internals of how Spigot work isn't important here

fallow dove
#

Now where are you using Citizens in your code

round crescent
fallow dove
#

Could you send the entire error

#

?paste

#

Ow not working here

#

Anyways full error in a paste

round crescent
fallow dove
#

Do you need a trait or are you just copy pasting stuff

#

What do you want your NPC to do

round crescent
#

If trait is npc with coded by me behavior then yes

fallow dove
#

What is the goal of your plugin

#

What do you need the NPC to do

round crescent
#

I'm trying to spawn a custom npc at first

#

then the npc talks to nearby players

#

via chat

#

while playing villager sounds

#

wanders around

#

and do some actions

#

like take random item from chest

#

run towards creepers

fallow dove
#

Ah good that you're using Citizens and not your own NPCs then

#

Because that would have been real hard for you

round crescent
#

yes i jumped for deep water kinda

#

however i understand the code

fallow dove
#

Spawning an NPC is one thing. Having it move and interact is much harder

round crescent
#

etc

#

yeah but when i can't manage to even spawn it

#

u know

fallow dove
#

All right now let's get your NPC moving

round crescent
#

but

fallow dove
#

First remove that trait registration

#

You don't need it

round crescent
#

i have no npc

#

ok removed

fallow dove
#

We'll get to that later

round crescent
#

XD

fallow dove
#

Now create a way for your NPC to be spawned

#

This can be an event listener or a command. Use something simple for testing

round crescent
#

i have function

#

here

#

with location

#

etc

fallow dove
#

Okay that works

#

Now spawn your npc with;

NPC npc = CitizensAPI.getNPCRegistry().createNPC(EntityType.PLAYER, "name");

Then use npc.spawn(location)

#

This will spawn a new NPC where you want it

#

You can customize that a bit more later for now let's focus on the main behaviour

round crescent
#
Location loc = e.getBlock().getLocation();
        World world = e.getBlock().getWorld();
        System.out.println("spawn npc");
        NPC npc = CitizensAPI.getNPCRegistry().createNPC(EntityType.PLAYER, "mobara01");
        npc.spawn(loc);
#
[16:47:23 INFO]: [Mobarobot] [STDOUT] spawn npc
[16:47:23 ERROR]: Could not pass event BlockPlaceEvent to Mobarobot v1.0
java.lang.IllegalStateException: no implementation set
fallow dove
#

Uh

#

What version of Citizens are you using

round crescent
#

Citizens-2.0.29-b2446.jar

#

i read on spigot that 2.0.29 is for 1.18.1

fallow dove
#

Yeah that should work

#

How are you running your server

round crescent
#

from here

round crescent
fallow dove
#

How are you starting your server

round crescent
#

-Xmx3750M only XD

fallow dove
#

With the Paperclip jar correct?

round crescent
#
Starting org.bukkit.craftbukkit.Main
System Info: Java 17 (OpenJDK 64-Bit Server VM 17+35-2724) Host: Linux 3.10.0-1062.1.1.el7.x86_64 (amd64)
Loading libraries, please wait...
2022-01-07 16:24:50,979 ServerMain WARN Advanced terminal features are not available in this environment
[16:25:04 INFO]: Environment: authHost='https://authserver.mojang.com', accountsHost='https://api.mojang.com', sessionHost='https://sessionserver.mojang.com', servicesHost='https://api.minecraftservices.com', name='PROD'
[16:25:04 INFO]: Reloading ResourceManager: Default, bukkit
[16:25:05 INFO]: Loaded 7 recipes
[16:25:06 INFO]: Starting minecraft server version 1.18.1
[16:25:06 INFO]: Loading properties
[16:25:06 INFO]: This server is running Paper version git-Paper-117 (MC: 1.18.1) (Implementing API version 1.18.1-R0.1-SNAPSHOT) (Git: 64f9225)
[16:25:06 INFO]: Server Ping Player Sample Count: 12
[16:25:06 INFO]: Using 4 threads for Netty based IO
[16:25:06 INFO]: Default game type: SURVIVAL
[16:25:06 INFO]: Generating keypair
[16:25:06 INFO]: Starting Minecraft server on REDACTED:40205
[16:25:07 INFO]: Using epoll channel type
[16:25:07 INFO]: Paper: Using libdeflate (Linux x86_64) compression from Velocity.
[16:25:07 INFO]: Paper: Using OpenSSL 1.1.x (Linux x86_64) cipher from Velocity.
[16:25:08 ERROR]: [STDERR] [org.bukkit.craftbukkit.v1_18_R1.legacy.CraftLegacy] Initializing Legacy Material Support. Unless you have legacy plugins and/or data this is a bug!
[16:25:13 WARN]: Legacy plugin LoginSecurity v3.1 does not specify an api-version.
round crescent
#

i think

fallow dove
#

Ah okay

#

Try using Spigot instead of Paper and see if that fixes it

round crescent
#

aight

fallow dove
#

Don't use that

#

Also delete link

#

To get a spigot jar you need to use BuildTools

round crescent
#

oh ok

#

i have this

fallow dove
round crescent
#

i built it tonight

#

to use nms

fallow dove
#

Ah then upload that jar

round crescent
#

why delete it tho?

fallow dove
#

To stop people from using illeagally distributed jars

#

There is a reason spigot does not have direct downloads

round crescent
#

i don't quite get why.

fallow dove
#

The whole craftbukkit project got DMCAd

#

That's why

#

This way we can avoid sharing mojangs code

#

So we don't get taken down

round crescent
#

ok

#

ok running the server with spigot now

fallow dove
#

Did it fix the problem

round crescent
#

one sec it's loading

#

it didn't

#

same error

fallow dove
#

Hm odd

#

Try an older version of Citizens

round crescent
#

3 commits older OK?

fallow dove
#

Maybe

#

I haven't used Citizens on 1.18.1 yet

round crescent
#

same error

fallow dove
#

Guess it's just broken atm

#

You could keep trying older build or report the issue

#

I don't have access to a pc until tomorrow so can't help more until then

round crescent
#

when it's trying to getNPCRegistry it asks the implementation which can be set via CitizensAPI.setImplementation( -> https://imgur.com/a/2e7Rm4J . i'm trying to get the plugin from server.pluginmanager but it returns Just plugin not CitizensPlugin

fallow dove
#

You're not supposed to do that manually

#

Sure you can fix it like that but don't

round crescent
#

maybe i will ask on the main chat

#

I have Citizens-2.0.29-b2446.jar on my spigot 1.18.1 server with all libs. Loading just fine.
I have added depend: [ Citizens ] to my plugin.yml HOWEVER
this: ```java
NPC npc = CitizensAPI.getNPCRegistry().createNPC(EntityType.PLAYER, "mobara01");

Produces error:

Caused by: java.lang.IllegalStateException: no implementation set
at net.citizensnpcs.api.CitizensAPI.getImplementation(CitizensAPI.java:79) ~[?:?]
at net.citizensnpcs.api.CitizensAPI.getNPCRegistry(CitizensAPI.java:111) ~[?:?]

Like citizens didn't load. (commands from citizens works etc)
i tried changing citizens version
fallow dove
#

You could try asking in the Citizens discord

round crescent
#

i already did

fallow dove
#

Ah what did they say

round crescent
#

nothing

fallow dove
#

Ah just wait then

#

We can continue tomorrow

round crescent
#

Thank you for all the help

fallow dove
#

You can work on other stuff while you wait

#

Such as a system for determening where it should walk

round crescent
#

OLIVO

#

I FIXED IT

#

DON'T KNOW HOW

#

NPC SPAWNED

fallow dove
#

Uh okay

#

Ah you got an awnser in the Citizens discord

round crescent
#

it didn't solve problem

#

in fact i didn't even notice the message there

#

and didn't add it

fallow dove
#

You should use it

#

It will ensure things work everytime instead of randomly

round crescent
#

Ok thanks

#

ok so we back to walking or sth?

fallow dove
#

Yeah

#

Okay so now you need to write pathfinding for your npc

fallow dove