#help-development
1 messages · Page 967 of 1
thanks anyway
i forgot to change value in test server
and changed it in editor instead
no? i asked if he made sure it gets retrieved propperly
yes and thats more information
thats vague
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?
Hello, is there a way to make the execution of a command async?
You mean dispatching a command async or running the code within a command method async?
running the command async
hello how do "hide" commands if the player dont meet the permissions for it?
or a function async
Define the permission in the plugin.yml. The players wont receive the commands when they join.
What does 'running' mean in this context?
ok but how?
And what does a 'function' refer to? A minecraft datapack function?
With a text editor or your IDE
yeah
thinking of it, not really spigot related
maybe I shouldn't try running the function from my plugin
how do i get a material/items user friendly name like "Grass Block"?
what's the issue with it?
ik but i am confused on what permissions are there?
Nevermind I fixed it but the problem was the names were all messed up because they were old.
yeah ?switchmappings for that
Yea I couldnt find TagParser or nmsEntity.save
This depends on the language settings of the client. Players receive translatable components for item names, and their client translates them
to whatever language they selected. You might be able to do something with Material#getTranslationKey() or simply transform the toString() of
Material to something readable.
The permission to execute the command
TranslatableComponent is what you want to use to send the message, and Material has no getTranslationKey
which means, you have to hardcode em all in!
Ah it's new
i am asking if there is a list of permissions i can look at?
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?
im trying to use translation keys but not sure how to use them with inventories/itemstacks
Sounds like you didnt add the sources to your project. On the top right: "Add sources and javadocs"
actually nvm i realized i dont need to get the item name
Sorry for this dumm question but in pom file?
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
Hello, does it looks good to see if I should remove Displays or not?
https://paste.md-5.net/calorocodu.java
ok but what abt checking if the player is op in plugin.yml?
the plugin.yml is a config file. It doesnt check anything.
Ok i have clicked that but still get this popup
How can you get all chests in a world?
you might wanna consider listening to chest open event and add them in a list
I basically want to remove specific item from the server
then what i said should help you
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
or md's way should work too
yeah either one works
I think that would be the solution yes, I just realize I came add different check for the item
Thanks!
mine accounts for hoppers 😉
serializaton doesnt work for entities... pain
Just gonna ask again. I can't find the mappings for it
when i do /lootbox for example , it say unkown commands
seems like the command are registering
there's more steps to register a command
how i can fix it?
ok , can you send me link or smth?
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
oky
Server server = Bukkit.getServer();
commandMap = (CommandMap) server.getClass().getMethod("getCommandMap").invoke(server);
this is how you can get the command map
Thanks
its the same for all minecraft Versions right?
like for 1.8 , and to latest?
yeah
ok great 🙂
nobody messed with the command map thankfully
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 :
what exactly can't you find?
TabParser and nmsEntity.save
you need to use mojang mappings
commands working now thanks 🙂
or translate the class and method names back to the obfuscated/spigot mappings through that site ^
check if data is actually inserted in the database after player left with mongocompass or whaterver
i connected using mongocompass
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?
XFS being recommended? I thought XFS has been more or less dead for years and people switched to zfs or btrfs
its connected right?
what are those , i was working with only sql , never tried mongo , i try it now
read the log
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?
the server needs to have authorization enabled
yes ofc but then you'd need to have a user with perms for creating arbitrary databases. usually that's not the case
Editor > General > Intentions.
wouldn't players on my server can just connect to it and use it?
wdym?
can't find it. I accidentally removed the org.bukkit.Entity thing import so now i cant find it easily
this is the tutorial iam checking rn :
https://gist.github.com/royz/46397fe4ee25dc14418b41821ee45335
MongoDB - install, enable authentication & remote access on Ubuntu 20.04 - MongoDB.md
not sure if its correct
for auto-imports, check here
how do i check if an entity is a passenger?
check if their getVehicle() returns sth or sth like that
declaration: package: org.bukkit.entity, interface: Entity
Iirc it’ll be null if they aren’t a passenger
wait vehicle is the entity theyre riding or the entity riding them
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

good explanation
lol
if a player rides a horse, then the horse is the player's vehicle and the player's the horse's passenger
alr
this is how i should save it correct?
Hello, how can I edit the cost for an item repair?
PrepareItemAnvilEvent
if uuid is supposed to basically behave like a primary / unique key, then it looks good to me
I want to cap repair for a tool and renaming at 1 level, but adding enchantment at the basic cost, that's possible with this event?
PrepareAnvilEvent
Ended up getting this working but any chance I can see an example because its still confusing me
My bad it’s just PrepareAnvilEvent
ofc the uuid is the primary key 🙂
okay thanks
and this is how i load it :
are you now using mojang maps or not?
I am now using mojang maps
You should load it directly rather than from a document
Make a codec for your object
fuck nvm got it i think
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
you probably imported the NMS zombie class instead of the bukkit one
ahh probs lol
can you give me an example?
i didn't work with mongo long enought
Codec is an interface you implement
Which are you storing
you haven't properly followed my tutorial for mojang maps. you haven't reobfuscated your classes.
Are you using maven or gradle?
maven
?paste your pom.xml
storing the uuid , and list of Portals , and i also store the uuid , and the nickname , kitname , other data like kills , etc etc
how are you compiling?
f10 which makes an artefact in intellij
that's wrong. you need to use maven to compile
maven tab -> lifecycle -> double click on package
your .jar will be at projectFolder/target/YourProject-1.0.jar (or whatever)
can i remap that location?
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...
You add a class to your getCollection call
Like so
database.getCollection("profiles", UserProfile.class)
AHH and thats how people get the version to show up when compiling
rightt
i was manually editing that section every time :p
Can i map the maven profiles to f10 then?
so it runs package when i press f10
That‘s also possible but idk how, i just always double click package in the maven tab
alright ill just double click then
What is the field declared as
Try run > edit run configurations or sth like that
like so i have it
There should be some way somewhere there to make it run mvn package as default
That’s not the usersCollection field
you mean like so?
Yes
what will this do exactly?
You can now get and set SkyUser objects directly to that collection
how?
Ok but now my plugin will only work on 1.20.4
Correct.
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
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...
Was possible with reflection up to 1.16.5 - not anymore
You‘ll need to do sth like this
Something like SkyUser user = this.usersCollection.find().first()
As long as you have the codec registered
seems painful
it is. however nobody uses 1.20 anymore anyway. check bstats for which versions are actually used
how i can register it?
1.20.4, 1.20.2 and 1.20.1 - ignore the rest
so wait just cuz i skim read. does that mean i have to recode the plugin every version or nah it just works?
4.8% 1.8 :p
my fav version :-:
you can reuse the code everytime (in 99 % of cases) but you'll need a different pom.xml for the mappings part (the specialsource plugin part in your pom)
4.8 too many
1.8 should have completely died the minute 1.9 was released
But muh PvP
😦 why
ew 💀 why is nms so cringe
because it's not API :p
people who are too bad to time their attacks properly, and instead favor spam-clicking should just not play pvp then lol
there are some oldCombatPvP Plugin you can install on the 1.20 server
it will bring back old pvp
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
ohhh right
but i'm assuming the remapping is automatic?
alternatively, you could pull request a serializeEntity method to spigot, then it wouldn't break on every change 🥲
problem with save ?
..
yes ofc - that's what the "specialsource-maven-plugin" is for in your pom.xml
Ahh right cool 👍
Don’t make a document, just use the object
Let me find my save code
so like this?
Bson filter = Filters.eq(object.getId());
this.collection.replaceOne(filter, object);
Yeah
what if i had values in SkyUser or other Users , that i don't want to be saved
what i can do ?
doesnt bson/mongodb have sth similar to gson that "automatically" tries to serialize/deserialize objects?
One last thing. Spawning using your serializer isn't working for some reason>?
Serializer.deserializeEntity(Boat.class, plugin.getAdvancedBoatsDatabase().getPlayerBoat(player, Integer.parseInt(args[1])), front);
functions but it just disapears
so it only gets spawned like for one tick or sth?
I don't even see it
Yes
so maybe for 1 tick but it just doesn't exist on my screen
But I try to avoid it because ehhhh
any error messages?
nope
I knew that it worked fine when I wrote that stuff. print out the serialized string and check what it says
wait weird
yeah sure probably just sucks, was just wondering
is your entity a water based entity?
In your codec
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);
got it
I need to also do a range check and I am clueless rn on that
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 ?
I don't need it?
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?
that's weird
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?
Bukkit entity serialization when
would be such an easy PR tbh
Let me save a pig in a bottle item 🙏
just get the nbt as string and load it again into a new entity
not readable?
Did you call nbt not readable ?
Am I missing something
Well not the way Bukkit likes it
I am literally serializing entites rn 💀
CompoundTag -> getAsString() should return readable SNBT, and MojangsonParser turns that back into a normal CompoundTag
When you serialize an itemstack to config it gets split up
But yeah I’d like an snbt system too
"Mojangson"Parser? Lmao what
that's the spigot mapped name for TagParser
Would go well with EntitySnapshot
Who mapped that
I wanna personally meet them
yes it does
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
😭
can you explain a bit more?
then delay applying the old CompoundTag by e.g. 20 ticks, see whether it just disappears then
(My english is slowly lessening)
wdym?
Grab an instance of the child codec and use that
also i do have this for UserStats class
instead of calling save (...) to apply the CompoundTag to the new entity, do that 20 ticks later
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?
Having a static instance for it is fine
oky
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
like this?
Yeah
might contain the old location and / or duplicate entity or sth, and that might cause issues ( teleporting it back, or making it invalid because of duplicated ID)
Use encode/decode respectively
if so you'd have to get rid of that part in the TagCompound
decode is for loading , and encode is for saving?
seems so
Trying now
yes
so final code looks like this?
Wait does spigot not have a getAsString for ItemStack?
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;
}
ItemMeta
why is it on the meta
🤷♂️
probably because it doesnt include the material
yeah
That's the only part that matters
ic
how do i listen for when non living entities die like text display
sorry for the to many questions , i still have one more questions how i can use it here?
Works
changing it to 1 tick
this is inside the SkyUserCodec
{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
hm weird. in that case, you should be able to do with with no delay at all - just don't use the consumer
Grab the instance and call encode?
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
Yea. Also who tf decided to call it a "consumer" thats the goofiest name ever
it "consumes" one parameter and returns nothing
seems wrong?
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
Kotlin makes this a bit easier
surely this gets a pin
Predicate = returns true or false
a Predicate<T> is just a fancy Function<T,Boolean>
Runnable crying rn
Take nothing return nothing
I can never remember this
Any memory trick you can suggest for Consumer/Supplier ?
:D
Just do thing then stop
oh yeah Runnable is like a Consumer<Void> or Supplier<Void> kek
i think this way
UniaryOperator
BooleanSupplier
Is a bi function not just Test(int i, int w) {}
IntToLongFunction
tf is that
ObjIntConsumer
Kekw
ToDoubleBiFunction
i always see that but i never understand what it does
it's basically a Function<Integer,Long> kek
Updated code means that when it supplies the NBT data it teleports the boat to where it was when it was saved
how do i fix this?
generic array to java when
just teleport it after nbt data again?
Function<T...> fr
Drop the location part from the NBT data
you either teleport it back after applying NBT, or you remove the location part from the NBT (that will require you to check the contents of the TagCompound after deserializing it with the TagParser)
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
EW
except less slowness...
bb gotta buy a huge pot for cooking chilli lol
kotlin = python + javascript if they were compiled
Kotlin = python + javascript if they were actually fun to use
kotlin < java
Ok wait. So with commands we have ^1 to place something 1 block infront of where the player is looking on that access
Eh subjective
What is the alternative in spigot
so if i want to spawn something 2 blocks infront of where the player is looking?
Vectors
or just at the block the player is looking at
Location loc = player.getEyeLocation();
Vector direction = player.getLocation().getDirection();
Location front = loc.add(direction);
Mongodb help loading saving data
Player#getEyeLocation#getDirection#normalize#multiply(2)
anyone?
then add to eye location
just raytrace??
Location loc = player.getEyeLocation();
Vector direction = player.getEyeLocation().getDirection().normalize().multiply(2);
Location front = loc.add(direction);
Should do
here's how I rewrote the ~ ~1 ~ functionality
https://github.com/SpigotBasics/basics/blob/main/core/src/main/kotlin/com/github/spigotbasics/core/command/parsed/arguments/XYZCoordsArg.kt
https://github.com/SpigotBasics/basics/blob/main/core/src/main/kotlin/com/github/spigotbasics/core/command/parsed/arguments/TripleContextCoordinatesArg.kt
~ ~1 ~ and ^ ^1 ^ are different
oh I didnt realize. For that do what coll said
fifth time asking for help
^ Bump
dare to say that one more time
kotlin = ruby
lolno
thats already better
ruby is far worse
kotlin = binary
ruby is like anti logic
I'd expect
https://hub.spigotmc.org/javadocs/bukkit/org/bukkit/event/entity/EntityRemoveEvent.html
to work, no promises
that aint cancellable doe
That was not specified in your request
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
listening to packets isn't gonna be any better
asterisk
and no player will recieve them, doesn't mean it will not remove an entity
(I believe)
but the entity will still be removed on the server
You severly misunderstand packets I think
so im screwed?
just respawn the entity
it has nbt
just respawn the entity and give it the NBT, if you scroll up you can see how to do it :D
if it's only a display entity, and no "some entity" then just hardcode the values
So there's 3 entity types, not that bad
how do you even get a display entity to die, what lmao
how?
oh yeah that's a thing
Did you PR that in like an hour ?
Or something different
It's an older api
Just let TagParser handle it
You can snapshot the entity and spawn that
Yeah I found it
is there a spawn method that takes an entity object
Only works with virtual entities
rip, so what will copying the entity really do
tfdym snapshot it
you take a snapshot of the entity
Entity#createSnapshot
that you can then reinstate
EntitySnapshot#createEntity
ZipFile invalid LOC header (bad signature)?
Whats with you two being some weird dynamic duo
💀
does createEntity just return the entity or spawn it
Spawn it iirc
Depends on which method you use
entity.createSnapshot().createEntity(entity.getLocation());
The location one or world one
so that?
That will spawn it
better than 1000 nms lines to copy the nbt
real
still NMS is nasty
(I've been using it for the past 2 hours straight)
Can you even easily recreate the item when using ItemMeta#getAsString
It doesn't include the type so I don't think ItemFactory#createItemStack would work
kek
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
I wonder if MD actually changed ItemMeta much
outside of redirecting the NBT to Components
hush
Paper is going to take 10 years to update
Don't scare me
shush
for some reason even with NMS saving a boat-chest boat doesn't work
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
Sounds like you are trying to remove entities which are already unloaded and saved.
Well no my plugin isn't attempting to remove them ever
they are being hit by me
then that msg shows up
Check to make sure the event you are following does not actually trigger twice.
?
So you are never calling .remove() on your entity?
well ages before this but that triggers once and works
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
So which part is failing then?
No part
just after the boat gets spawned
if it gets punched and killed
it outputs that msg
In that case your serialization method fails to link your nms entity to a bukkit entity
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;
}
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.
Gotta yeet that UUID
So what would the alternative be?
You get used to it eventually :p
How do I do this?
tag.remove("")
what in the ""?
how does nms spawn it?
EntityType is a class
Wtf is that
The method is static, idk why I used a #
But wtf is loadEntityRecursive
It recursivly loads entities from an NBT tag
Why does that matter
Ahh ok
# is usually used used to indicate instance methods
lol
just .
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???
Eventually
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 🤡
does setPlayerListName not work?
Yea it does, but if you exceed the character limit of 16 it will truncate the playername...
And since im avoiding § colors and using the format <red> of the adventure api it's quite a pain to do so
xd
anyone have any idea how to NMS spawn entity???
wat
i don't see how using minimessage makes any difference?
setPlayerListName takes a string with section symbols
Just spawn it the casual way
it makes the string of playerlistname longer
but you don't put the <red> etc in that method
no i would not
you need to convert it to legacy codes
Yeaaaa still it will cut names with more than 10 characters or something
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
its pain
You can remove that message I believe
:o how
it works the same as with villagers or self spawned armorstands
let me check
if im right*
Also remove y from vector?
Location loc = player.getEyeLocation();
Vector direction = player.getEyeLocation().getDirection().normalize().multiply(5);
Location front = loc.add(direction);
can i just set the y?
You should be able to set the y location yea
cool
But back to this
how do i remove the msg?
just when it gets killed
alright so either try
Look at this chain of msgs
Command Run While In Boat.
Boat Gets Saved As String (Serialized)
Boat gets removed
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
Them
Command Runs
Boat gets deserialized
Boat gets spawned
or else run the entitydeathevent and cancel the message or
I'll do that one
so entitydeathevent if entity is boat with custom data then shut it up?
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
I'm not sure, but I think that is a perfect question for chatGPT
Not completely finished, but if I need to change course, hoping to do it early on
Thank you ❤️
how do i make a plugin datafolder and put my config.yml i wrote in the resources folder in it?
JavaPlugin#saveResource
Not sure how spigot implements that, but you could use some java trickery to do that
actually lemme see how i did it before
i'll get back to you with a screenshot
this will work just fine
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);
Did you create the file in your project?
yeah, both yml files are in the resources folder
show the error
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
can you send a screenie of your resources folder just to verify that everything's intact
ignore lang btw
lang
i don't think the lang matters
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
If that doesn't work, send a screenie of your onEnable method
it's in the main folder
your file is just isn't present at runtime, so its definetly something wrong with your resources. Screenshot whole project structure
messages file is fine, try recreate your config file
It's in the right spot
plugin.yml is fine btw
Open your jar with 7zip or anything else and see if the files are bundled properly
.
how are you compiling the plugin
it indeed did
Send a screenshot of your onEnable method
I am not talking about plugin yml
same error this time with messages file
Maybe it's not including them when you compile for some reason
i'm saying that plugin.yml is present and the other config files aren't.
how are you compiling the plugin into a jar file?
ohhhhh
mvn clean package
Peculiar
and you're taking the jar from the target folder i presume
yes
?paste your pom
<directory>${project.basedir}/src/main/resources</directory> <includes> <include>plugin.yml</include> </includes>
Should include the other yml's too
i'm so bad with maven it's crazy lol
It only includes plugin.yml
you shouldn't need to explicitly include things
Is that thing even necessary at all
^ yeah
I don't remember having to write this ever
it isn't at all
I've never written a pom.xml tbf.
Isn't there like a maven resources plugin or something
Or maybe package does it for you
yes
<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
i used the spigot guide
alright
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
I have this in one of my working poms
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
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) [?:?]
good, that's a different error this time
Anyone can help me 🙂 ?
https://discord.com/channels/690411863766466590/1229780393666940979
you are passing some null value into InputStreamReader constructor in GetLangConfig
What is the method to load the config.yml from file to ram?
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);
}
You're just on time
Look at what we're doing rn
Wait nvm
Not exactly lol mb
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) ~[?:?]
this is the crucial part in your code
whatever GetLangConfig is passing to the inputstreamreader constructor is null
saveDefaultConfig();
getConfig().options().copyDefaults();
saveConfig();```
yep it's there
k thx
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
endResult = YamlConfiguration.loadConfiguration(new InputStreamReader(Main.getInstance().getResource("messages.yml")));```
Possibly an error with this line
messages.yml is null?
which one is line 26 in your Modules.java?
YamlConfiguration configReader = YamlConfiguration.loadConfiguration(new InputStreamReader(Main.getInstance().getResource("lang/" + GetConfig().getString("language") + ".yml")));
or this
cool
lemme do that hold up
https://paste.md-5.net/qoqolezamo.java
i get a problem with this code
What's the problem?
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 :
Awesome
this is my other class :
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
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);```
alr
erm so i just looked at the data folder the plugin generated and it loaded messages.yml into it but not config.yml
looks good
let us know if it worked
make sure you're calling saveDefaultConfig/saveResource("config.yml")
works 🙂
Did you load config.yml in your onEnable
And also have the config file in your resource folder
do i save resource config.yml too?
i assumed savedefaultconfig would do that for me?
You need to have the config.yml file within your resource folder
OH NVM
Otherwise it won't work
where do you have that
yeah lol
💀
I was gonna say I dont see it
https://mongodb.github.io/mongo-java-driver/ i mean the latest version seems to be 5.0.0 but sure i guess
that will have a fair number of breaking changes you'd have to change your code for, you don't have to update ig
So wait if i want to edit the NMS of an existing entity how?
but i'd stay updated ¯_(ツ)_/¯
let us know if it works :D
"edit the nms of an existing entity"?
maybe they're using java 6 💀
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));
How can I set spawn location?
world#spawn
Pretty sure you can setShooter
ok, thanks i'll try
probably still gotta apply velocity manually ig
tbf i dont even know what a shulker bullet is lmao
the projectile that makes u levitate when it hits u
gotta love when u write a line of code wrong and suddenly u have a quadrillion chest boats
Sounds like a feature to me
new cmarco plugin just dropped?
Do you need to use them
no
someone else needed help with them
i was just saying what a shulker bullet is
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 ?
love when my internet restarts
This is my code rn :
is it when you leave and join or when the server restarts?
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 ?
almost definetely every 5m
because then you only have one runtasktimer
thx 🙂
You can only have one regardless
:o what?
And just use timestamps and a priority queue
sooo any ideas?
i have 2 modes , mysql and mongodb , mysql works just fine , i want to add fully support to mongodb 🙂
?? how would that work out of curiousity
when leave it get the correct data, but when join it does not 🙂
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?)
how do i share the main class to other files again
Hello is there a way to disable guardian from jumping ?
?di
Guide to dependency injection: https://www.spigotmc.org/wiki/using-dependency-injection/
thanks
In your main class
private static <MainClassName> plugin;
public static <MainClassName> getPlugin() { return plugin; }
In other class (File)
private static <MainClassName> plugin = <MainClassName>.getPlugin()
prefer di
Wtf is this pseudocode lmao
FYI, learning object-oriented programming concepts helps a lot with spigot development
i've been using static getter but it just aint working
Then you've done something wrong most likely
What about it isnt working?
.
Yea but i've had it be weird in situations so i dont use it always... most of the time i use it tho
here is fine
wait there
you just need to wait for someone that actually knows mongo
I sometimes have situations where I end up having statically initialized stuff which needs a plugin instance
Yea but over there would have more people that know mongo...
mongos discord can help a lot better
but directing people to forums isnt the best as its not very active
I didn't know if mongo had a discord. Also sometimes forums aren't too inactive
Yeah so either go there or just check back here like once every 30 minutes/1 hour and ask again until someone knows mongodb
where is the offical discord for mongos?
probably on their website
I don't know if they have an official one
Just google "mongodb discord"
MongoDB Unofficial Discord I have started a discord for MongoDB for quicker help. We stand at 644 members at the time of writing, and I’ve decided to put it here so it’s more accessible to those who wish to get help faster than they may do on the forums, but also an easier way of getting help with any MongoDB service. In short: Faster support,...
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
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
You can treat onEnable as your constructor
yes it will?
@fringe yew Try just making getInstance() return this instead of instance
so just return this?
That isn't possible?
done 🙂
Also, please never name your main class 'Main'
why not
Sec
Its bad coding practice
Yeah, when using APIs
?main I think
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()));
}
}
}
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
time to rename to app
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
Also, there are lots of cases where you use your main class in other classes making it unintuitive as well as the Main class usually has a public static void main method, which plugins should never have
yeah exactly
Main class is usually reserved for the actual main java class that the JVM looks for
Where to learn java?
anyway back to my original problem, what modifications should I make?
Anywhere away from sharp objects...
public static Main getInstance() {
if (instance == null) {
instance = new Main();
}
return instance;
}
Try that?
The jvm looks for the main class defined in the manifest, there isn't a specific class name it looks for. Not naming the Main class is just a convention for readability and to ensure compatibility
Never make a new instance of your plugins main class lol
Throws an exception
can someone help please
You could try return JavaPlugin.getPlugin(Main.class) or something like that
{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?
Because shooter is a shulker
I believe
Depends on what it's set to
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
The shooter isn't shulker, it just spawns from player's location
ohhh okay
Don't understand how can I parse it
Then the shooter is null
yeah
Set the shooter to the shooting player in the consumer when spawning the projectile entity
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()));
}
}```
Oh yeah thanks
...
the name
I just set shooter to player and now all works
awesome
Just to debug
no i mean the hitPlayer.sendMessage() unless thats also just to debug
Oh those are his messages
and its not ur code is it...
yea i realised
I usually have an utility class for messages
Yeah it's good to have modular stuff like that
Gimme a sec
So you don't have to go to like 20 different classes to change a message
Keep it all in one spot
https://github.com/RaydanOMGr/AMUtilLib/blob/master/src/main/java/me/andreasmelone/amutillib/i18n/I18n.java this is my util class I use for that, but it's not the greatest, I thought of improving it a bit
Yea i should start making a utility class
i had one for my last plugin but the one im currently deving i was too lazy too
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
its pretty simple
i have a question
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)