#help-development

1 messages · Page 967 of 1

tepid turret
#

💀

charred blaze
#

thanks anyway

#

i forgot to change value in test server

#

and changed it in editor instead

valid burrow
#

thats how problem solving works

#

smart ass

tepid turret
#

You said not really then asked for more information

#

^^

valid burrow
#

no? i asked if he made sure it gets retrieved propperly

tepid turret
#

yes and thats more information

valid burrow
#

thats vague

tepid turret
#

anyways

#

I have the serialization just need help deserializing

#
public static String serializeEntity(Entity entity) {
        net.minecraft.world.entity.Entity nmsEntity = ((CraftEntity) entity).getHandle();
        NBTTagCompound tag = new NBTTagCompound();
        nmsEntity.saveWithoutId(tag, true);
        return tag.toString();
    }
#

(All conversions from mfnalex's nms code)

#
public static Entity deserializeEntity(Class<? extends Entity> type, String json, Location loc) {
        return loc.getWorld().spawn(loc, type, entity -> {
            net.minecraft.world.entity.Entity nmsEntity = ((CraftEntity) entity).getHandle();
            NBTTagCompound tag = null;
            try {
                tag = TagParser.parseTag(json);
            } catch (CommandSyntaxException e) {
                throw new RuntimeException(e);
            }
            nmsEntity.load(tag);
        });
    }```

Red lines under TagParser and load
#

Tag Parser cannot resolve symbol

#

Then

#

Can not resolve method 'load' in 'Entity'

#

Hey sorry for the ping after a LONG time from making this. Any chance you could make an update to this?

echo basalt
#

Looks like you need mappings

cinder abyss
#

Hello, is there a way to make the execution of a command async?

lost matrix
rigid shoal
#

hello how do "hide" commands if the player dont meet the permissions for it?

cinder abyss
#

or a function async

lost matrix
#

What does 'running' mean in this context?

lost matrix
lost matrix
cinder abyss
#

thinking of it, not really spigot related

#

maybe I shouldn't try running the function from my plugin

full cargo
#

how do i get a material/items user friendly name like "Grass Block"?

rigid shoal
tepid turret
tender shard
#

yeah ?switchmappings for that

tepid turret
#

Yea I couldnt find TagParser or nmsEntity.save

lost matrix
lost matrix
rough drift
#

which means, you have to hardcode em all in!

rough drift
#

Ah it's new

rigid shoal
clear briar
#

Hey guys i want to code with nms and installed the needed Jar with the recompield mappings from Mojang with the Buildtools

#

i get promted by intellij that i have to decompile the jars is this normal?

full cargo
#

im trying to use translation keys but not sure how to use them with inventories/itemstacks

lost matrix
full cargo
#

actually nvm i realized i dont need to get the item name

clear briar
lost matrix
#

In your IDE

#

Maven tab

lost matrix
# rigid shoal ...

Kindof. You can iterate all plugins, get their description file and call getPermissions().

#

Which kinda works, but many plugins randomly use permissions without registering them

cinder abyss
rigid shoal
lost matrix
clear briar
summer scroll
#

How can you get all chests in a world?

sullen marlin
#

load every chunk -> get every tile in chunk -> get every chest

#

?xy

undone axleBOT
lilac dagger
summer scroll
lilac dagger
#

then what i said should help you

sullen marlin
#

and why do you need to get all chests in the world to do that, as opposed to getting each chest as each chunk loads

#

ChunkLoadEvent -> getTileEntities -> get every chest

lilac dagger
#

or md's way should work too

sullen marlin
#

yeah either one works

summer scroll
#

I think that would be the solution yes, I just realize I came add different check for the item

#

Thanks!

sullen marlin
#

mine accounts for hoppers 😉

tepid turret
#

This serialization fails

#

give second

#

nevermind

twin venture
#

all commands implment Icommand

#

but they are not been registering

tepid turret
#

serializaton doesnt work for entities... pain

twin venture
tepid turret
twin venture
#

when i do /lootbox for example , it say unkown commands

#

seems like the command are registering

lilac dagger
twin venture
#

how i can fix it?

twin venture
lilac dagger
#

i do it via the map

#

wait no

#

your problem is that you create a new command map

#

you need to get the map from the server

twin venture
#

oky

lilac dagger
#

Server server = Bukkit.getServer();
commandMap = (CommandMap) server.getClass().getMethod("getCommandMap").invoke(server);

#

this is how you can get the command map

twin venture
#

Thanks

twin venture
#

like for 1.8 , and to latest?

lilac dagger
#

yeah

twin venture
#

ok great 🙂

lilac dagger
#

nobody messed with the command map thankfully

twin venture
#

hhahah that's great to hear

#

i have a problem with mongodb , when i restart the server the sky user is null and it create new data?

#

it does not load the data that are inserted

#

not sure if iam doing anything wrong :

tender shard
tepid turret
tender shard
#

?nms

tender shard
#

you need to use mojang mappings

twin venture
#

commands working now thanks 🙂

tender shard
sullen canyon
twin venture
#

using the sh

#

how i can use it and see?

#

and why i was able to conncet directly how i can set a password?

#

and why does it say null ?

#

does that mean connection failure?

tender shard
twin venture
#

its connected right?

twin venture
twin venture
#

how i can fix that?

#

is it possible to make my plugin create a datbase in mongo server?

#

without the need of me to make one? manaully?

tender shard
#

the server needs to have authorization enabled

tender shard
tepid turret
#

Hey if i hid something from intellij's alt+enter keybind

#

how would i get that back

tender shard
#

Editor > General > Intentions.

twin venture
twin venture
#

this file is empty

tepid turret
twin venture
#

not sure if its correct

dawn flower
#

how do i check if an entity is a passenger?

tepid turret
#

Thank you

#

that worked

tender shard
young knoll
#

Iirc it’ll be null if they aren’t a passenger

dawn flower
#

wait vehicle is the entity theyre riding or the entity riding them

tender shard
#

a vehicle is the opposite of a passenger

#

if your mum rides your dad, your dad is the vehicle and your mom is the passenger /scnr

twin venture
kind hatch
#

lol

tender shard
#

if a player rides a horse, then the horse is the player's vehicle and the player's the horse's passenger

dawn flower
#

alr

twin venture
#

this is how i should save it correct?

cinder abyss
#

Hello, how can I edit the cost for an item repair?

young knoll
#

PrepareItemAnvilEvent

tender shard
cinder abyss
cinder abyss
tender shard
#

PrepareAnvilEvent

tepid turret
#

Ended up getting this working but any chance I can see an example because its still confusing me

young knoll
#

My bad it’s just PrepareAnvilEvent

twin venture
cinder abyss
twin venture
#

and this is how i load it :

tender shard
tepid turret
#

I am now using mojang maps

young knoll
#

You should load it directly rather than from a document

#

Make a codec for your object

tepid turret
#

fuck nvm got it i think

tender shard
#
String serializedZombie = serializeEntity(someRandomZombie);

// spawn it again

Zombie zombieSpanwedAgain = (Zombie) deserializeEntity(Zombie.class, serializedZombie, someLocation);

the deserializeEntity could probably better return T instead of Entity, but whatever

tepid turret
#

ah for some reason earlier Zombie.class wasn't working but now it is

#

:)

#

thanks

tender shard
tepid turret
#

ahh probs lol

twin venture
#

i didn't work with mongo long enought

young knoll
#

Codec is an interface you implement

twin venture
#

something like this right?

#

or should i codec the UserPortal class?

tepid turret
#

I get this error

#

weird

young knoll
#

Which are you storing

tender shard
#

Are you using maven or gradle?

tepid turret
tender shard
#

?paste your pom.xml

undone axleBOT
tepid turret
twin venture
tender shard
young knoll
#

You should make a codec for each object you store

#

Then you can read it directly

tepid turret
tender shard
#

maven tab -> lifecycle -> double click on package

#

your .jar will be at projectFolder/target/YourProject-1.0.jar (or whatever)

tepid turret
#

can i remap that location?

tender shard
#

yes

#

If you’re using maven for your Spigot plugins (which you should do), it’s easy to make maven automatically save your plugin’s .jar in your plugins folder. There’s two ways of doing this: 1. The lazy way (not recommended) If you only work alone on one computer, you can just directly declare the output location in...

young knoll
#

You add a class to your getCollection call

#

Like so
database.getCollection("profiles", UserProfile.class)

tepid turret
#

rightt

#

i was manually editing that section every time :p

twin venture
#

that what it tells me

tepid turret
#

so it runs package when i press f10

tender shard
tepid turret
#

alright ill just double click then

young knoll
tender shard
#

Try run > edit run configurations or sth like that

twin venture
#

like so i have it

tender shard
young knoll
#

That’s not the usersCollection field

twin venture
#

you mean like so?

young knoll
#

Yes

twin venture
young knoll
#

You can now get and set SkyUser objects directly to that collection

twin venture
#

how?

tepid turret
tender shard
tepid turret
#

if i want to support 1.20 1.20.1 1.20.2 1.20.3 ?

#

I know NMS has a way of doing all of the versions similar to it

tender shard
# tepid turret if i want to support 1.20 1.20.1 1.20.2 1.20.3 ?

Hi there! Today I’m going to explain how to setup a multi-module project using maven to support different NMS versions. Important notes about this tutorial: Every step will have detailled screenshots using IntelliJ. I explicitly chose not to include everything as copy/pastable source code, but normal screenshots (you can click on them to show th...

tender shard
tender shard
young knoll
#

As long as you have the codec registered

tepid turret
tender shard
#

it is. however nobody uses 1.20 anymore anyway. check bstats for which versions are actually used

twin venture
#

yeah i see

twin venture
tender shard
#

1.20.4, 1.20.2 and 1.20.1 - ignore the rest

tepid turret
twin venture
#

my fav version :-:

tender shard
slender elbow
#

4.8 too many

twin venture
#

xD

tender shard
#

1.8 should have completely died the minute 1.9 was released

young knoll
#

But muh PvP

tepid turret
tender shard
#

because it's not API :p

tender shard
# young knoll But muh PvP

people who are too bad to time their attacks properly, and instead favor spam-clicking should just not play pvp then lol

twin venture
#

there are some oldCombatPvP Plugin you can install on the 1.20 server

#

it will bring back old pvp

tender shard
# tepid turret ew 💀 why is nms so cringe

the reason why NMS is cringe is because mojang wrote it and they obfuscate their code and so it breaks on every update. that's why ou need to "remap" your code so e.g. saveEntity(...) gets renamed to aX(...) or however it's called in the specific version that you're using the mappings for. It might be aX in 1.20.4 but bC() in 1.20.3 etc

tepid turret
#

but i'm assuming the remapping is automatic?

tender shard
#

alternatively, you could pull request a serializeEntity method to spigot, then it wouldn't break on every change 🥲

tender shard
young knoll
#

Let me find my save code

twin venture
#

so like this?

young knoll
#

Bson filter = Filters.eq(object.getId());
this.collection.replaceOne(filter, object);

#

Yeah

twin venture
#

what if i had values in SkyUser or other Users , that i don't want to be saved

#

what i can do ?

young knoll
#

Don’t save them

#

In the codec

tender shard
#

doesnt bson/mongodb have sth similar to gson that "automatically" tries to serialize/deserialize objects?

tepid turret
#

Serializer.deserializeEntity(Boat.class, plugin.getAdvancedBoatsDatabase().getPlayerBoat(player, Integer.parseInt(args[1])), front);

#

functions but it just disapears

tender shard
tepid turret
tepid turret
#

so maybe for 1 tick but it just doesn't exist on my screen

young knoll
#

But I try to avoid it because ehhhh

tender shard
tepid turret
#

nope

tender shard
#

I knew that it worked fine when I wrote that stuff. print out the serialized string and check what it says

tepid turret
#

wait weird

tender shard
tepid turret
#

it allows spawning in water

#

but not on land?

tender shard
#

is your entity a water based entity?

tepid turret
#

its a boat

#

is there a way I let it spawn not on water?

twin venture
#

oh i see

young knoll
#

In your codec

tepid turret
#
Location loc = player.getEyeLocation();
                            Vector direction = player.getLocation().getDirection();
                            Location front = loc.add(direction);
                            

                            Serializer.deserializeEntity(Boat.class, plugin.getAdvancedBoatsDatabase().getPlayerBoat(player, Integer.parseInt(args[1])), front);
                            plugin.getAdvancedBoatsDatabase().updatePlayerBoat(player, Integer.valueOf(args[1]), null);
twin venture
#

got it

tepid turret
tender shard
#

does it even return a valid entity? inside the consumer (the { part after entity -> {), print out entity.toString().

#

also is there a reason why you never save the result of deserializeEntity ?

twin venture
#

in my main SkyUser , i have a UserStats
if i want to codec the SkyUser how would i do that for the field of the UserStats?

young knoll
#

Make a codec for that too

#

And then use that codec in the other codec

twin venture
#

that's weird

tender shard
# tepid turret is there a way I let it spawn not on water?

tbf it simply uses the bukkit method to spawn the entity (then after that, it loads the serialized stuff) - try to simply call world.spawnEntity(...) without my serializing thing at all - are you now able to spawn it outside of water?

young knoll
#

Bukkit entity serialization when

tender shard
smoky anchor
#

Let me save a pig in a bottle item 🙏

tender shard
young knoll
#

Yeah but that’s not readable

#

So idk

tender shard
#

not readable?

smoky anchor
#

Did you call nbt not readable ?
Am I missing something

young knoll
#

Well not the way Bukkit likes it

tepid turret
tender shard
# tender shard not readable?

CompoundTag -> getAsString() should return readable SNBT, and MojangsonParser turns that back into a normal CompoundTag

young knoll
#

When you serialize an itemstack to config it gets split up

#

But yeah I’d like an snbt system too

shadow night
tender shard
young knoll
#

Would go well with EntitySnapshot

shadow night
#

I wanna personally meet them

young knoll
#

Tbf I kinda want to do this pr now

#

Hm

young knoll
#

Bukkit.getEntityFactory incoming

#

Kek

tepid turret
#

don't please

#

i've spent years doing this code

#

tryna get nms to work cuz i cant read

#

and then u make it default feature

#

😭

twin venture
tender shard
tepid turret
#

(My english is slowly lessening)

twin venture
young knoll
twin venture
#

also i do have this for UserStats class

tender shard
# tepid turret wdym?

instead of calling save (...) to apply the CompoundTag to the new entity, do that 20 ticks later

tepid turret
#
entity -> {
            net.minecraft.world.entity.Entity nmsEntity = ((CraftEntity) entity).getHandle();
            CompoundTag tag = null;
            try {
                tag = TagParser.parseTag(json);
            } catch (CommandSyntaxException e) {
                throw new RuntimeException(e);
            }
            nmsEntity.load(tag);
        });
#

?

#

u mean move that?

young knoll
#

Having a static instance for it is fine

twin venture
#

oky

tender shard
# tepid turret ```java entity -> { net.minecraft.world.entity.Entity nmsEntity = ((...

yes.

Boat entity = world.spawnEntity(Boat.class, location);

Bukkit.getScheduler().runTaskLater(myPlugin, () -> {
              net.minecraft.world.entity.Entity nmsEntity = ((CraftEntity) entity).getHandle();
            CompoundTag tag = null;
            try {
                tag = TagParser.parseTag(json);
            } catch (CommandSyntaxException e) {
                throw new RuntimeException(e);
            }
            nmsEntity.load(tag);
}, 20);

sth like that

#

also, as said, print out the "json" part and see what it says

twin venture
young knoll
#

Yeah

tender shard
young knoll
#

Use encode/decode respectively

tender shard
#

if so you'd have to get rid of that part in the TagCompound

twin venture
#

decode is for loading , and encode is for saving?

tender shard
twin venture
#

so final code looks like this?

young knoll
#

Wait does spigot not have a getAsString for ItemStack?

tepid turret
#
public static Entity deserializeEntity(Class<? extends Entity> type, String json, Location loc) {
        Boat entity = (Boat) loc.getWorld().spawn(loc, type);
        Bukkit.getScheduler().runTaskLater(plugin, () -> {
            net.minecraft.world.entity.Entity nmsEntity = ((CraftEntity) entity).getHandle();
            CompoundTag tag = null;
            try {
                tag = TagParser.parseTag(json);
                Bukkit.getLogger().info(json);
            } catch (CommandSyntaxException e) {
                throw new RuntimeException(e);
            }
            nmsEntity.load(tag);
        }, 20);
        return null;
    }
tender shard
young knoll
#

why is it on the meta

tepid turret
#

🤷‍♂️

tender shard
#

probably because it doesnt include the material

young knoll
river oracle
dawn flower
#

how do i listen for when non living entities die like text display

twin venture
# young knoll yeah

sorry for the to many questions , i still have one more questions how i can use it here?

twin venture
tepid turret
#
{Air:300s,Bukkit.updateLevel:2,FallDistance:1.0E-6f,Fire:-1s,Invulnerable:0b,Motion:[0.0d,0.0d,0.0d],OnGround:0b,Paper.Origin:[-250.2959523107364d,62.88888889551163d,81.93140875581388d],Paper.OriginWorld:[I;205279836,914311098,-2136146469,1756123852],Paper.SpawnReason:"DEFAULT",PortalCooldown:0,Pos:[-250.33628236504336d,62.52266269475798d,81.91386996645853d],Rotation:[132.1875f,0.0f],Spigot.ticksLived:407,Type:"spruce",UUID:[I;1260725656,-1162133028,-1880877821,647595504],WorldUUIDLeast:-9174679222064753972L,WorldUUIDMost:881670183062554554L,id:"minecraft:boat"}
#

Json print

tender shard
# tepid turret Works

hm weird. in that case, you should be able to do with with no delay at all - just don't use the consumer

young knoll
tender shard
#
Boat entity = world.spawnEntity(Boat.class, location);
// Now the code to load the NBT stuff again, without scheduler
#

funny that it's not working inside the consumer - it used to work fine when I wrote that shit

tepid turret
tender shard
twin venture
tepid turret
#

Now im permanently thinking of the -> { } as a face

#

-> { }
-> {}

tender shard
#

Consumer = Take sth in, give nothing
Function = Take sth in, return another thing
BiConsumer = Take 2 things in, give nothing
BiFunction = Take 2 things in, return another thing
Supplier = Take nothing in, return something

icy beacon
#

Kotlin makes this a bit easier

dawn flower
#

Predicate = returns true or false

tender shard
icy beacon
#

Take nothing return nothing

smoky anchor
icy beacon
#

Just do thing then stop

tender shard
twin venture
#

i think this way

river oracle
#

UniaryOperator

dawn flower
#

u can have unlimited parameters

#

by creating an interface

slender elbow
#

BooleanSupplier

tepid turret
slender elbow
#

IntToLongFunction

dawn flower
slender elbow
#

ObjIntConsumer

river oracle
#

Kekw

slender elbow
#

ToDoubleBiFunction

dawn flower
#

i always see that but i never understand what it does

tender shard
tepid turret
#

how do i fix this?

dawn flower
#

generic array to java when

tepid turret
#

just teleport it after nbt data again?

dawn flower
#

Function<T...> fr

young knoll
#

Drop the location part from the NBT data

tender shard
icy beacon
#
typealias Runnable = () -> Unit
typealias Consumer<T> = (T) -> Unit
typealias Function<T, R> = (T) -> R
typealias BiConsumer<T, K> = (T, K) -> Unit
typealias BiFunction<T, K, R> = (T, K) -> R
typealias Supplier<R> = () -> R
#

kotlin makes things fun

tepid turret
#

EW

dawn flower
#

kotlin = python + javascript

#

u cant change my mind

tepid turret
tender shard
#

bb gotta buy a huge pot for cooking chilli lol

dawn flower
#

kotlin = python + javascript if they were compiled

icy beacon
#

Kotlin = python + javascript if they were actually fun to use

inner mulch
#

kotlin < java

tepid turret
#

Ok wait. So with commands we have ^1 to place something 1 block infront of where the player is looking on that access

icy beacon
#

Eh subjective

tepid turret
#

so if i want to spawn something 2 blocks infront of where the player is looking?

young knoll
#

Vectors

tepid turret
#

or just at the block the player is looking at

#
Location loc = player.getEyeLocation();
Vector direction = player.getLocation().getDirection();
Location front = loc.add(direction);
twin venture
#

Mongodb help loading saving data

young knoll
#

Player#getEyeLocation#getDirection#normalize#multiply(2)

dawn flower
young knoll
tepid turret
#
                            Location loc = player.getEyeLocation();
                            Vector direction = player.getEyeLocation().getDirection().normalize().multiply(2);
                            Location front = loc.add(direction);
young knoll
#

Should do

tepid turret
tender shard
#

oh I didnt realize. For that do what coll said

dawn flower
tardy delta
dawn flower
slender elbow
#

lolno

tardy delta
#

thats already better

slender elbow
#

ruby is far worse

dawn flower
#

kotlin = binary

young knoll
#

Okay time to figure out how to work with SNBT

#

:p

slender elbow
#

ruby is like anti logic

dawn flower
#

that aint cancellable doe

smoky anchor
#

That was not specified in your request

dawn flower
#

do i seriously have to listen for packets

#

for something so simple

slender elbow
#

i mean

#

the event is there

smoky anchor
#

how do you want to listen to packets when you remove an entity server-side ?
What if it's at spawn and no player is near to even recieve the packet

slender elbow
#

listening to packets isn't gonna be any better

dawn flower
#

u can cancel packets

#

any packet

slender elbow
#

asterisk

smoky anchor
#

and no player will recieve them, doesn't mean it will not remove an entity
(I believe)

slender elbow
#

but the entity will still be removed on the server

dawn flower
#

hm

#

good point

smoky anchor
#

You severly misunderstand packets I think

dawn flower
#

so im screwed?

smoky anchor
#

just respawn the entity

dawn flower
smoky anchor
#

just respawn the entity and give it the NBT, if you scroll up you can see how to do it :D

dawn flower
#

nbt = nms

#

u cant modify actual nbt without nms pretty sure

smoky anchor
#

if it's only a display entity, and no "some entity" then just hardcode the values

dawn flower
#

i want all display entities

#

ill have like 20

#

if not more

smoky anchor
#

So there's 3 entity types, not that bad

slender elbow
#

how do you even get a display entity to die, what lmao

young knoll
#

There are methods to copy an entity now

#

btw

dawn flower
#

how?

slender elbow
#

oh yeah that's a thing

smoky anchor
young knoll
#

It's an older api

tender shard
young knoll
#

You can snapshot the entity and spawn that

young knoll
dawn flower
#

is there a spawn method that takes an entity object

young knoll
#

Only works with virtual entities

dawn flower
#

rip, so what will copying the entity really do

young knoll
#

Like I said

#

snapshot it and then spawn that

dawn flower
#

tfdym snapshot it

tepid turret
#

Entity#createSnapshot

slender elbow
#

you take a snapshot of the entity

young knoll
#

Entity#createSnapshot

slender elbow
#

that you can then reinstate

young knoll
#

EntitySnapshot#createEntity

tepid turret
#

ZipFile invalid LOC header (bad signature)?

tepid turret
#

💀

dawn flower
#

does createEntity just return the entity or spawn it

tepid turret
young knoll
#

Depends on which method you use

dawn flower
#

entity.createSnapshot().createEntity(entity.getLocation());

young knoll
#

The location one or world one

young knoll
#

That will spawn it

tepid turret
#

ew

#

but that is functional

#

I guess thats the only way you can do it

dawn flower
#

better than 1000 nms lines to copy the nbt

tepid turret
#

real

young knoll
#

It's closer to like

#

10

#

:p

tepid turret
#

(I've been using it for the past 2 hours straight)

young knoll
#

Can you even easily recreate the item when using ItemMeta#getAsString

tepid turret
#

?

#

where did that come from

young knoll
#

It doesn't include the type so I don't think ItemFactory#createItemStack would work

young knoll
#

kek

river oracle
#

I'm not touching ItemStack until 1.20.5 mojang is murdering them

#

I'm just going to sit back and watch my NMS break

young knoll
#

I mean

#

There is already a 1.20.5 pre 1 spigot

river oracle
#

I wonder if MD actually changed ItemMeta much

#

outside of redirecting the NBT to Components

slender elbow
#

pre 3 is already out

young knoll
#

hush

river oracle
#

Paper is going to take 10 years to update

tepid turret
#

shush

river oracle
#

NMS isn't hard

#

I find it fun tbh

tepid turret
#

for some reason even with NMS saving a boat-chest boat doesn't work

river oracle
#

some of the NMS level stuff is actually easier

#

until we improve API!

tepid turret
#

when removing boats used by my plugin this comes up

#

[EntityLookup] Failed to remove entity EntityBoat['Spruce Boat'/739, uuid='75bed1e4-b7fc-406a-b21e-2b9d59183d38', l='ServerLevel[world]', x=-293.82, y=61.00, z=44.18, cpos=[-19, 2], tl=122, v=true, removed=DISCARDED] by uuid, current entity mapped: null

#
[EntityLookup] Failed to remove entity EntityBoat['Spruce Boat'/739, uuid='75bed1e4-b7fc-406a-b21e-2b9d59183d38', l='ServerLevel[world]', x=-293.82, y=61.00, z=44.18, cpos=[-19, 2], tl=122, v=true, removed=DISCARDED] by uuid, current entity mapped: null
#

it still removes them

#

just says that?

#

ew why tf does it show my spigot name

lost matrix
tepid turret
#

they are being hit by me

#

then that msg shows up

hardy minnow
#

Check to make sure the event you are following does not actually trigger twice.

lost matrix
tepid turret
#

then a new copy gets spawned later

#

Ok basicall

#

y

#
Command Run While In Boat.

Boat Gets Saved As String (Serialized)

Boat gets removed
#

Then later

#
Command Runs

Boat gets deserialized

Boat gets spawned
hardy minnow
#

So which part is failing then?

tepid turret
#

No part

#

just after the boat gets spawned

#

if it gets punched and killed

#

it outputs that msg

lost matrix
#

In that case your serialization method fails to link your nms entity to a bukkit entity

tepid turret
#
public static String serializeEntity(Entity entity) {
        net.minecraft.world.entity.Entity nmsEntity = ((CraftEntity) entity).getHandle();
        CompoundTag tag = new CompoundTag();
        nmsEntity.save(tag);
        return tag.getAsString();
    }

    public static Entity deserializeEntity(Class<? extends Entity> type, String json, Location loc) {
        Boat entity = (Boat) loc.getWorld().spawn(loc, type);
        net.minecraft.world.entity.Entity nmsEntity = ((CraftEntity) entity).getHandle();
        CompoundTag tag = null;
        try {
            tag = TagParser.parseTag(json);
        } catch (CommandSyntaxException e) {
                throw new RuntimeException(e);
        }
        nmsEntity.load(tag);
        entity.teleport(loc);
        return entity;
    }
lost matrix
#

World#spawnEntity will create an unrelated UUID to your entity. That could lead to desync if load(tag) assigns the stored UUID to the entity.

#

Try to not use any spigot methods when deserializing entities.

young knoll
#

Gotta yeet that UUID

tepid turret
quaint mantle
#

i am so bad with nms cant get it without errors to run smh

#

such a stupid thing

young knoll
#

You get used to it eventually :p

tepid turret
#

As in

#

oh wait

tepid turret
#

tag.remove("")

#

what in the ""?

lost matrix
#

Just dont use spigot methods for spawning...

#

Spawn it like nms would

young knoll
#

I don't think NMS would approve either

#

Could be wrong tho

tepid turret
young knoll
#

EntityType.create(world, tag) should work

#

or EntityType.loadEntityRecursive

tepid turret
#

net.minecraft.world.entity.vehicle.Boat ???

#

from there?

#

or?

young knoll
#

EntityType is a class

shadow night
young knoll
#

The method is static, idk why I used a #

shadow night
#

But wtf is loadEntityRecursive

young knoll
#

It recursivly loads entities from an NBT tag

shadow night
shadow night
young knoll
#

# is usually used used to indicate instance methods

slender elbow
#

lol

shadow night
#

What is used for non-instance methods? ::?

#

StaticClass::pierdole()?

slender elbow
#

just .

tepid turret
# young knoll \# is usually used used to indicate instance methods

Sorry my brain is fried

Boat entity = (Boat) loc.getWorld().spawn(loc, type);
        net.minecraft.world.entity.Entity nmsEntity = ((CraftEntity) entity).getHandle();
        CompoundTag tag = null;
        try {
            tag = TagParser.parseTag(json);
        } catch (CommandSyntaxException e) {
            throw new RuntimeException(e);
        }
        nmsEntity.load(tag);
        entity.teleport(loc);
        return entity;
#

where and what???

quaint mantle
#

Probably not so I stick without nms and cry over that I can not user hex colors in the tablist as for the player name itself 🤡

slender elbow
#

does setPlayerListName not work?

quaint mantle
#

And since im avoiding § colors and using the format <red> of the adventure api it's quite a pain to do so

slender elbow
#

xd

tepid turret
#

anyone have any idea how to NMS spawn entity???

slender elbow
#

wat

#

i don't see how using minimessage makes any difference?

#

setPlayerListName takes a string with section symbols

quaint mantle
quaint mantle
slender elbow
#

but you don't put the <red> etc in that method

quaint mantle
#

no i would not

slender elbow
#

you need to convert it to legacy codes

quaint mantle
#

Yeaaaa still it will cut names with more than 10 characters or something

tepid turret
# quaint mantle Just spawn it the casual way

Spawning it the non NMS way causes this to show up when the boat is punched and killed:

[EntityLookup] Failed to remove entity EntityBoat['Spruce Boat'/509, uuid='f6bc539b-79c0-4a78-b244-7caa8de832bd', l='ServerLevel[world]', x=-296.10, y=62.52, z=40.09, cpos=[-19, 2], tl=628, v=true, removed=DISCARDED] by uuid, current entity mapped: null
quaint mantle
#

its pain

quaint mantle
tepid turret
#

:o how

quaint mantle
#

it works the same as with villagers or self spawned armorstands

#

let me check

#

if im right*

tepid turret
#

Also remove y from vector?

quaint mantle
#

ouh

#

i guess you have to manually do that

tepid turret
#
Location loc = player.getEyeLocation();
Vector direction = player.getEyeLocation().getDirection().normalize().multiply(5);
Location front = loc.add(direction);
#

can i just set the y?

quaint mantle
#

You should be able to set the y location yea

tepid turret
#

cool

tepid turret
#

how do i remove the msg?

quaint mantle
#

Ill try to figure it out

#

its just when spawning it ?

#

or when it get killed

tepid turret
#

just when it gets killed

quaint mantle
#

alright so either try

tepid turret
#
Command Run While In Boat.

Boat Gets Saved As String (Serialized)

Boat gets removed
quaint mantle
#

Spigot.yml set the option below on False.

Toggles whether or not to log information about the death of entities with custom names.

Code (Text):
settings:
log-named-deaths: false

If you still want player death messages, make a simple plugin

#

if thats still up to date

tepid turret
#

Them

Command Runs

Boat gets deserialized

Boat gets spawned
quaint mantle
#

or else run the entitydeathevent and cancel the message or

tepid turret
#

I'll do that one

quaint mantle
#

okay I see

#

i dont know if its up to date, thats just what i have found

tepid turret
#

so entitydeathevent if entity is boat with custom data then shut it up?

quaint mantle
#

Yea

#

You can try that one

tepid turret
#

Anyone know how using maven configurations i can have it run a .bat file (only when a maven profile is selected) after the plugin is compiled

tranquil glen
hardy minnow
#

Not completely finished, but if I need to change course, hoping to do it early on

remote swallow
slender elbow
#

yeah

#

thread

hardy minnow
#

Thank you ❤️

fringe yew
#

how do i make a plugin datafolder and put my config.yml i wrote in the resources folder in it?

icy beacon
#

JavaPlugin#saveResource

tranquil glen
#

actually lemme see how i did it before

#

i'll get back to you with a screenshot

icy beacon
fringe yew
# fringe yew how do i make a plugin datafolder and put my config.yml i wrote in the resources...

this is how i have it right now, i have two files, config.yml and messages.yml
i want to save them both in the data folder. When i launch the server it just errors saying config.yml doesn't exist as it wasn't bundled in the jar

if (!getDataFolder().exists()) {
    getLogger().info("Detected first time launch! Creating configuration files...");
    getDataFolder().mkdir();
}

saveDefaultConfig();
saveResource("messages.yml", false);
tranquil glen
#

Did you create the file in your project?

fringe yew
#

yeah, both yml files are in the resources folder

icy beacon
#

show the error

fringe yew
#

alr hold up

#
java.lang.IllegalArgumentException: The embedded resource 'config.yml' cannot be found in plugins\pv2-2.0.0a.jar
        at org.bukkit.plugin.java.JavaPlugin.saveResource(JavaPlugin.java:252) ~[server.jar:git-Spigot-550ebace-7019900e2]
        at org.bukkit.plugin.java.JavaPlugin.saveDefaultConfig(JavaPlugin.java:239) ~[server.jar:git-Spigot-550ebace-7019900e2]
        at co.uk.robuxtrex.pv2.Main.onEnable(Main.java:36) ~[?:?]
        at org.bukkit.plugin.java.JavaPlugin.setEnabled(JavaPlugin.java:321) ~[server.jar:git-Spigot-550ebace-7019900e2]
        at org.bukkit.plugin.java.JavaPluginLoader.enablePlugin(JavaPluginLoader.java:335) [server.jar:git-Spigot-550ebace-7019900e2]
        at org.bukkit.plugin.SimplePluginManager.enablePlugin(SimplePluginManager.java:405) [server.jar:git-Spigot-550ebace-7019900e2]
        at org.bukkit.craftbukkit.v1_8_R1.CraftServer.loadPlugin(CraftServer.java:356) [server.jar:git-Spigot-550ebace-7019900e2]
        at org.bukkit.craftbukkit.v1_8_R1.CraftServer.enablePlugins(CraftServer.java:316) [server.jar:git-Spigot-550ebace-7019900e2]
        at net.minecraft.server.v1_8_R1.MinecraftServer.q(MinecraftServer.java:402) [server.jar:git-Spigot-550ebace-7019900e2]
        at net.minecraft.server.v1_8_R1.MinecraftServer.k(MinecraftServer.java:370) [server.jar:git-Spigot-550ebace-7019900e2]
        at net.minecraft.server.v1_8_R1.MinecraftServer.a(MinecraftServer.java:325) [server.jar:git-Spigot-550ebace-7019900e2]
        at net.minecraft.server.v1_8_R1.DedicatedServer.init(DedicatedServer.java:211) [server.jar:git-Spigot-550ebace-7019900e2]
        at net.minecraft.server.v1_8_R1.MinecraftServer.run(MinecraftServer.java:505) [server.jar:git-Spigot-550ebace-7019900e2]
        at java.base/java.lang.Thread.run(Thread.java:840) [?:?]
#

line 36 is savedefaultresource

icy beacon
#

can you send a screenie of your resources folder just to verify that everything's intact

fringe yew
#

ignore lang btw

glad prawn
#

lang

tranquil glen
#

i don't think the lang matters

icy beacon
#

try commenting out saveDefaultConfig and see if saveResource will also throw an error

#

if so then your resourcesfolder may be in the wrong place or something

tranquil glen
#

If that doesn't work, send a screenie of your onEnable method

fringe yew
#

it's in the main folder

hazy parrot
#

your file is just isn't present at runtime, so its definetly something wrong with your resources. Screenshot whole project structure

fringe yew
glad prawn
#

messages file is fine, try recreate your config file

tranquil glen
#

It's in the right spot

fringe yew
#

plugin.yml is fine btw

icy beacon
#

Open your jar with 7zip or anything else and see if the files are bundled properly

fringe yew
slender elbow
#

how are you compiling the plugin

tranquil glen
#

Send a screenshot of your onEnable method

icy beacon
#

I am not talking about plugin yml

fringe yew
#

same error this time with messages file

icy beacon
#

I am talking about your other files

#

Are they present?

tranquil glen
#

Maybe it's not including them when you compile for some reason

fringe yew
#

i'm saying that plugin.yml is present and the other config files aren't.

slender elbow
#

how are you compiling the plugin into a jar file?

tranquil glen
#

ohhhhh

fringe yew
#

mvn clean package

slender elbow
#

and you're taking the jar from the target folder i presume

fringe yew
#

yes

slender elbow
#

?paste your pom

undone axleBOT
fringe yew
slender elbow
#
    <directory>${project.basedir}/src/main/resources</directory>
    <includes>
      <include>plugin.yml</include>
    </includes>
tranquil glen
#

Should include the other yml's too

fringe yew
#

i'm so bad with maven it's crazy lol

tranquil glen
#

It only includes plugin.yml

slender elbow
#

you shouldn't need to explicitly include things

icy beacon
#

Is that thing even necessary at all

slender elbow
#

^ yeah

icy beacon
#

I don't remember having to write this ever

slender elbow
#

it isn't at all

fringe yew
#

can i mention

#

i copied the code from my working plugin into this

tranquil glen
#

I've never written a pom.xml tbf.

icy beacon
#

Isn't there like a maven resources plugin or something

#

Or maybe package does it for you

fringe yew
#

yes

slender elbow
#
    <sourceDirectory>${project.basedir}/src/main/java</sourceDirectory>
    <resources>
      <resource>
        <directory>${project.basedir}/src/main/resources</directory>
        <includes>
          <include>plugin.yml</include>
        </includes>
      </resource>
    </resources>

none of this is necessary

fringe yew
#

i used the spigot guide

tranquil glen
#

Try deleting what Emily sent

#

and see if it compiles with it

fringe yew
#

alright

icy beacon
#
<resources>
            <resource>
                <directory>src/main/resources</directory>
                <filtering>true</filtering>
            </resource>
        </resources>

I have this in one of my working poms

slender elbow
#

that's useful if you wanna have placeholders to expand on build, like ${project.version} in your plugin.yml or whatever

#

but explicitly defining the directory is not needed

icy beacon
#

What exactly embeds resources though, i never thought of it

#

Does maven just do it?

fringe yew
#
java.lang.NullPointerException
        at java.base/java.io.Reader.<init>(Reader.java:168) ~[?:?]
        at java.base/java.io.InputStreamReader.<init>(InputStreamReader.java:76) ~[?:?]
        at co.uk.robuxtrex.pv2.Modules.GetLangConfig(Modules.java:26) ~[?:?]
        at co.uk.robuxtrex.pv2.listeners.PlayerJoin.<init>(PlayerJoin.java:16) ~[?:?]
        at co.uk.robuxtrex.pv2.Main.onEnable(Main.java:45) ~[?:?]
        at org.bukkit.plugin.java.JavaPlugin.setEnabled(JavaPlugin.java:321) ~[server.jar:git-Spigot-550ebace-7019900e2]
        at org.bukkit.plugin.java.JavaPluginLoader.enablePlugin(JavaPluginLoader.java:335) [server.jar:git-Spigot-550ebace-7019900e2]
        at org.bukkit.plugin.SimplePluginManager.enablePlugin(SimplePluginManager.java:405) [server.jar:git-Spigot-550ebace-7019900e2]
        at org.bukkit.craftbukkit.v1_8_R1.CraftServer.loadPlugin(CraftServer.java:356) [server.jar:git-Spigot-550ebace-7019900e2]
        at org.bukkit.craftbukkit.v1_8_R1.CraftServer.enablePlugins(CraftServer.java:316) [server.jar:git-Spigot-550ebace-7019900e2]
        at net.minecraft.server.v1_8_R1.MinecraftServer.q(MinecraftServer.java:402) [server.jar:git-Spigot-550ebace-7019900e2]
        at net.minecraft.server.v1_8_R1.MinecraftServer.k(MinecraftServer.java:370) [server.jar:git-Spigot-550ebace-7019900e2]
        at net.minecraft.server.v1_8_R1.MinecraftServer.a(MinecraftServer.java:325) [server.jar:git-Spigot-550ebace-7019900e2]
        at net.minecraft.server.v1_8_R1.DedicatedServer.init(DedicatedServer.java:211) [server.jar:git-Spigot-550ebace-7019900e2]
        at net.minecraft.server.v1_8_R1.MinecraftServer.run(MinecraftServer.java:505) [server.jar:git-Spigot-550ebace-7019900e2]
        at java.base/java.lang.Thread.run(Thread.java:840) [?:?]
slender elbow
#

good, that's a different error this time

twin venture
slender elbow
#

you are passing some null value into InputStreamReader constructor in GetLangConfig

proud badge
#

What is the method to load the config.yml from file to ram?

fringe yew
#

entire onenable

@Override
    public void onEnable() {
        // BStats Metrics
        int PluginID = 18706;
        new Metrics(this, PluginID);

        // Configuration
        if (!getDataFolder().exists()) {
            getLogger().info("Detected first time launch! Creating configuration files...");
            getDataFolder().mkdir();
        }

        //saveDefaultConfig();
        saveResource("messages.yml", false);
        FileConfiguration config = this.getConfig();

        if (!config.getBoolean("enabled")) {
            modules.SendConsoleMessage("PermaVision has been disabled in the configuration file. You must re-enable it for the plugin to function as intended.", Level.WARNING);
        }

        // Registering Events
        getServer().getPluginManager().registerEvents(new PlayerJoin(), this);
    }
icy beacon
#

Look at what we're doing rn

#

Wait nvm

#

Not exactly lol mb

slender elbow
#

this is the crucial part in your code

fringe yew
#

playerjoin

#

maybe it's just a problem with me now

#

hold up

slender elbow
#

whatever GetLangConfig is passing to the inputstreamreader constructor is null

fringe yew
#

the jar file is 1kb larger

#

omg

tranquil glen
fringe yew
#

yep it's there

proud badge
#

k thx

tranquil glen
#

yup yup

#

Not sure if there's a better way to do it

#

but that's how I did it

fringe yew
# slender elbow whatever GetLangConfig is passing to the inputstreamreader constructor is null
public FileConfiguration GetConfig() {
        return Main.getInstance().getConfig();
    }

public FileConfiguration GetLangConfig() {
    YamlConfiguration configReader = YamlConfiguration.loadConfiguration(new InputStreamReader(Main.getInstance().getResource("lang/" + GetConfig().getString("language") + ".yml")));
    
    YamlConfiguration endResult;

    if (configReader != null) {
        endResult = configReader;
    } else {
        endResult = YamlConfiguration.loadConfiguration(new InputStreamReader(Main.getInstance().getResource("messages.yml")));
    }

    return endResult;
}
#

ignore the terrible formatting

tranquil glen
#
endResult = YamlConfiguration.loadConfiguration(new InputStreamReader(Main.getInstance().getResource("messages.yml")));```
#

Possibly an error with this line

#

messages.yml is null?

slender elbow
tranquil glen
#
YamlConfiguration configReader = YamlConfiguration.loadConfiguration(new InputStreamReader(Main.getInstance().getResource("lang/" + GetConfig().getString("language") + ".yml")));
#

or this

fringe yew
#

^

#

that's line 26

#

ik why

#

i just realised

slender elbow
#

cool

fringe yew
#

that's because i forgot to put the actual file in the lang folder

#

so it's empty lol

tranquil glen
#

lolll

#

yep that'll do it

fringe yew
#

lemme do that hold up

twin venture
tranquil glen
#

What's the problem?

twin venture
#

it say Caused by: org.bson.codecs.configuration.CodecConfigurationException: Can't find a codec for class me.advancedskypvp.data.users.SkyUser.

#

how i can fix it please?

#

this is how i have my UserStatsCodec class :

fringe yew
#

no way it didn't error

#

it's a miracle

tranquil glen
#

Awesome

twin venture
#

this is my other class :

slender elbow
#
        MongoDatabase mongoClientDatabase = mongoClient.getDatabase(database);
        this.mongoDatabase = mongoClient.getDatabase(database).withCodecRegistry(codecRegistry);
        this.usersCollection = mongoClientDatabase.getCollection("sky_users", SkyUser.class);
        this.statsUserCollection = mongoClientDatabase.getCollection("sky_stats", UserStats.class);

you are using mongoClientDatabase which you are not creating with the codec registry, you are creating this.mongoDatabase with it tho, you'd have to use that instead

tranquil glen
#

Since you're creating the MongoDatabase instance (mongoDatabase) with the codec registry applied, you should use that instance (mongoDatabase) instead of mongoClientDatabase when accessing collections

#

Try this for line 20:

#
this.usersCollection = mongoDatabase.getCollection("sky_users", SkyUser.class);```
#

And this for line 21:

#
this.statsUserCollection = mongoDatabase.getCollection("sky_stats", UserStats.class);```
twin venture
#

alr

fringe yew
#

erm so i just looked at the data folder the plugin generated and it loaded messages.yml into it but not config.yml

twin venture
#

this right?

slender elbow
#

looks good

tranquil glen
#

let us know if it worked

twin venture
#

and i use this version

#

should i update or is it good?

slender elbow
twin venture
#

works 🙂

tranquil glen
quaint mantle
#

And also have the config file in your resource folder

fringe yew
#

do i save resource config.yml too?

tranquil glen
#

yes

#

or just "saveDefaultConfig();"

fringe yew
#

i assumed savedefaultconfig would do that for me?

quaint mantle
#

You need to have the config.yml file within your resource folder

fringe yew
#

OH NVM

quaint mantle
#

Otherwise it won't work

tranquil glen
#

where do you have that

fringe yew
#

I STILL HAVE IT COMMENTED FROM EARLIER

#

BRUHH

tranquil glen
#

yeah lol

quaint mantle
#

💀

tranquil glen
#

I was gonna say I dont see it

slender elbow
#

that will have a fair number of breaking changes you'd have to change your code for, you don't have to update ig

tepid turret
#

So wait if i want to edit the NMS of an existing entity how?

slender elbow
#

but i'd stay updated ¯_(ツ)_/¯

tranquil glen
slender elbow
tender shard
hybrid quartz
#

Why bullet don't launches on changed location?

                Location shootBullet = player.getEyeLocation().subtract(0, 1.25, 0);
                ShulkerBullet bullet = player.launchProjectile(ShulkerBullet.class, shootBullet.getDirection().multiply(-0.4));
young knoll
#

Because that argument just controls the velocity

#

Not the spawn location

hybrid quartz
young knoll
#

world#spawn

quaint mantle
#

mongo db 5.0 isnt cool

#

I can tell you that

hybrid quartz
#

or?

young knoll
#

Pretty sure you can setShooter

hybrid quartz
tender shard
young knoll
#

yeah

#

I don't think shulker bullets really work with velocity anyway

tender shard
#

tbf i dont even know what a shulker bullet is lmao

tranquil glen
#

the projectile that makes u levitate when it hits u

tender shard
#

aaaah those fuckers

#

I hate them

tepid turret
#

gotta love when u write a line of code wrong and suddenly u have a quadrillion chest boats

young knoll
#

Sounds like a feature to me

tender shard
#

new cmarco plugin just dropped?

tepid turret
tranquil glen
#

no

#

someone else needed help with them

#

i was just saying what a shulker bullet is

twin venture
#

Hi i found a bug with mongodb , so when i kill someone, it will increaese the kills and it does do that :

but when i leave and join , it set it back to 0 ?

tepid turret
#

love when my internet restarts

twin venture
#

This is my code rn :

tepid turret
#

is it when you leave and join or when the server restarts?

twin venture
#

when user leave and join

#

it does send the message

cursive loom
#

For a server it's better to replace a crop every 30s after a player break it or it's better to add all breaked crops into a list and replace all every 5m ?

tepid turret
#

because then you only have one runtasktimer

cursive loom
young knoll
#

You can only have one regardless

tepid turret
#

:o what?

young knoll
#

And just use timestamps and a priority queue

twin venture
#

i have 2 modes , mysql and mongodb , mysql works just fine , i want to add fully support to mongodb 🙂

tepid turret
twin venture
#

when leave it get the correct data, but when join it does not 🙂

tepid turret
#
public static Entity deserializeBoatEntity(Class<? extends Entity> type, String json, Location loc) {
        Entity entity = (Entity) loc.getWorld().spawn(loc, type);
        net.minecraft.world.entity.Entity nmsEntity = ((CraftEntity) entity).getHandle();
        CompoundTag tag = null;
        try {
            tag = TagParser.parseTag(json);
        } catch (CommandSyntaxException e) {
            throw new RuntimeException(e);
        }
        nmsEntity.load(tag);
        entity.teleport(loc);
        return entity;
    }
#

wondering if anyone knows how to make this function work for boats and chestboats?

#

I don't know whether or not its gonna be a boat or chestboat when calling this function

#

(Though there is persistent data container key that can tell us. but i don't know how to find that from the json?)

fringe yew
#

how do i share the main class to other files again

sharp heart
#

Hello is there a way to disable guardian from jumping ?

undone axleBOT
fringe yew
#

thanks

tepid turret
remote swallow
#

prefer di

tranquil glen
#

FYI, learning object-oriented programming concepts helps a lot with spigot development

fringe yew
#

i've been using static getter but it just aint working

shadow night
tranquil glen
#

What about it isnt working?

tepid turret
tepid turret
#

or forums

#

where thats meant to be

remote swallow
#

here is fine

fringe yew
#

wait there

remote swallow
#

you just need to wait for someone that actually knows mongo

shadow night
tepid turret
tranquil glen
#

Mongodb discord will probably be able to help

#

A lot better than we can

remote swallow
#

mongos discord can help a lot better

#

but directing people to forums isnt the best as its not very active

tepid turret
tranquil glen
#

Yeah so either go there or just check back here like once every 30 minutes/1 hour and ask again until someone knows mongodb

twin venture
#

where is the offical discord for mongos?

tranquil glen
#

probably on their website

#

I don't know if they have an official one

#

Just google "mongodb discord"

remote swallow
fringe yew
# tranquil glen What about it isnt working?

basically i have my getter here

private static Main instance; {
    instance = this;
}

public static Main getInstance() {
    return instance;
}

and when i try .getInstance().getLogger() it just errors saying this.Main doesn't exist

remote swallow
#

that instance = this wont get called when it should

#

do instance = this in onEnable and dont do anything requiring plugin instance till after its enabled

tranquil glen
#

You can treat onEnable as your constructor

slender elbow
tranquil glen
#

@fringe yew Try just making getInstance() return this instead of instance

fringe yew
#

so just return this?

shadow night
#

That isn't possible?

shadow night
#

Also, please never name your main class 'Main'

fringe yew
#

why not

shadow night
#

Sec

tepid turret
#

Its bad coding practice

tranquil glen
#

Yeah, when using APIs

shadow night
#

?main I think

hybrid quartz
#

I have created command /fart, which shoots shulker_bullet projectile. And now I need to send player message if he was shooted by this projectile. Don't understand why this don't work. What have I done wrong?

public class FartHitEvent implements Listener {
    @EventHandler
    public void onFartHitEvent(ProjectileHitEvent e) {
        if (e.getEntityType() != EntityType.SHULKER_BULLET) return;

        ProjectileSource shooter = e.getEntity().getShooter();

        if (shooter instanceof Player) {

            Entity hitEntity = e.getHitEntity();
            System.out.println("test");

            if (hitEntity == null) return;
            if (hitEntity.getType() != EntityType.PLAYER) return;

            Player hitPlayer = (Player) hitEntity;
            Player playerShooter = (Player) shooter;

            hitPlayer.sendMessage(Utils.color("&aВ вас попал игрок " + playerShooter.getName()));
            playerShooter.sendMessage(Utils.color("&aВы попали в игрока " + hitPlayer.getName()));
        }
    }
}
tranquil glen
# fringe yew why not

Since your plugin runs on top of libraries/APIs, there is likely going to be a case where there is already a "Main" class. It makes it hard to differentiate

fringe yew
#

time to rename to app

tranquil glen
#

Or just rename it to your plugin's name

#

or you could just call it <plugin name>Main

#

It's mainly just a readablity thing

shadow night
tranquil glen
#

yeah exactly

#

Main class is usually reserved for the actual main java class that the JVM looks for

hasty hamlet
#

Where to learn java?

fringe yew
#

anyway back to my original problem, what modifications should I make?

tepid turret
tranquil glen
#

Try that?

shadow night
shadow night
#

Throws an exception

tranquil glen
#

Oh okay, didn't know that

#

He's getting an error that it doesnt exist

shadow night
#

You could try return JavaPlugin.getPlugin(Main.class) or something like that

tepid turret
#

{Air:300s,Bukkit.updateLevel:2,BukkitValues:{"phytorboats:phytorboats.claimed":"77e27de9-5c36-40b7-b793-013e2f2312ea","phytorboats:phytorboats.instance":"chestboat","phytorboats:phytorboats.name":"2","phytorboats:phytorboats.owner":"Assailent"},FallDistance:0.0f,Fire:0s,Invulnerable:0b,Items:[],Motion:[0.0d,0.0d,0.0d],OnGround:0b,Paper.Origin:[-41.8062490577733d,62.88888889551163d,-37.90250601474626d],Paper.OriginWorld:[I;205279836,914311098,-2136146469,1756123852],Paper.SpawnReason:"DEFAULT",PortalCooldown:0,Pos:[-39.98733468585121d,62.52326914115938d,-38.72699575066581d],Rotation:[-114.388596f,0.0f],Spigot.ticksLived:80,Type:"oak",UUID:[I;-34477562,-1488436226,-2070525519,-892086393],WorldUUIDLeast:-9174679222064753972L,WorldUUIDMost:881670183062554554L,id:"minecraft:chest_boat"}

#

How do i search through this is it just treated as a dict?

tranquil glen
#

I believe

shadow night
#

If it's shot by a shulker then it'll be a shulker, but otherwise it'll be null or something it was set to

hybrid quartz
tranquil glen
#

ohhh okay

hybrid quartz
#

Don't understand how can I parse it

shadow night
tranquil glen
#

yeah

shadow night
#

Set the shooter to the shooting player in the consumer when spawning the projectile entity

tranquil glen
#

Maybe some debug comments too

#
public void onFartHitEvent(ProjectileHitEvent e) {
        if (e.getEntityType() != EntityType.SHULKER_BULLET) return;

        ProjectileSource shooter = e.getEntity().getShooter();

        if (!(shooter instanceof Player)) {
            // Log or debug message to ensure it's a player shooting
            System.out.println("Shooter is not a player.");
            return;
        }

        Player playerShooter = (Player) shooter;
        Entity hitEntity = e.getHitEntity();

        if (hitEntity == null || hitEntity.getType() != EntityType.PLAYER) return;

        Player hitPlayer = (Player) hitEntity;

        // Debug message to ensure the event is firing and the logic reaches this point
        System.out.println("Fart hit event triggered.");

        hitPlayer.sendMessage(Utils.color("&aВ вас попал игрок " + playerShooter.getName()));
        playerShooter.sendMessage(Utils.color("&aВы попали в игрока " + hitPlayer.getName()));
    }
}```
hybrid quartz
#

I just set shooter to player and now all works

tranquil glen
#

awesome

tepid turret
#

code*

tranquil glen
#

Just to debug

tepid turret
#

no i mean the hitPlayer.sendMessage() unless thats also just to debug

tranquil glen
#

Oh those are his messages

tepid turret
#

and its not ur code is it...

tranquil glen
#

No

#

lol

tepid turret
#

yea i realised

shadow night
#

I usually have an utility class for messages

tranquil glen
#

Yeah it's good to have modular stuff like that

shadow night
#

Gimme a sec

tranquil glen
#

So you don't have to go to like 20 different classes to change a message

#

Keep it all in one spot

shadow night
tepid turret
#

i had one for my last plugin but the one im currently deving i was too lazy too

tranquil glen
#

It's a necessity if you plan on developing that plugin for a while

#

if it's just a quick thrown together plugin to solve a task, then no need

tepid turret
#

its pretty simple

hushed relic
#

i have a question

tepid turret
#

plus if i need to make a utility for messages then i will probably end up having to refactor the whole thing anyways so i'll just start a new (I once restarted 6 times in one day)