#help-development
1 messages · Page 2199 of 1
im not too sure what exactly i should be googling, whats the exact terms used yk
java.lang.NullPointerException: Cannot invoke "thunderlearn.thunderlearn.databasesql.mySQL.disconnect()" because "this.SQL" is null
wtf
when i make calls to the database and create new entrys, its all fine but i get this as soon as i start my plugin
Likely calling a constructor incorrectly
Bro with the amount of simple preventable errors you are having I can't reccomend enough doing something simple without a db
Narrow it down to just a pure Java project if possible
The best way to learn is a project but imo your in way to deep for your own good
how would i stop particles from spawnParticle flying everywhere
ik i have to turn down the speed
but how
theres no speed parameter
in any of the functions
yeah sure im in over my head here but i cant physically sit down and learn a language by forcing myself, unless i have a reason to do it, i cant lol
and it was a simple fix
thankfully
Me either but I like to sir down and figure out ideas that I know will be easy and get to the harder ideas later. When I first started I made stupid shit like summoning tnt every time you broke a block etc
im past the east stuff i wanted to do, there isnt anything left thats simple but something i want to do tbh
java -jar BuildTools.jar lastest --compile craftbukkit
Is this a valid param for buildtools
The home of Spigot a high performance, no lag customized CraftBukkit Minecraft server API, and BungeeCord, the cloud server proxy.
well i did how else do u think i got the command. they told me to add --compile craftbukkit but where in command idk
I mean, where else would you put it?
*You can find CraftBukkit (to but not including version 1.14) and Spigot in the same directory you ran the the BuildTools.jar in (craftbukkit-1.14.jar and spigot-1.14.jar). You can find Spigot-API in \Spigot\Spigot-API\target\ (spigot-api-1.14-R0.1-SNAPSHOT.jar). To compile CraftBukkit for 1.14 and beyond, you must add the --compile craftbukkit argument to the command.```
that's wat it says
will it work if i put --compile craftbukkit in the end of the whole param
:v i only used that thing only when building buildtools hehe. maybe i will learn it later
imagine compiling craftbukkit
tfw u write a whole class to get it working then to realize its inefficient af so u gotta rewrite it
https://gyazo.com/2a9f20fb97779d6f5a52474e58384de9 anyone have an idea why this value at the top is not null but the one below is full of nulls?
nevermind
apparently Bukkit#craftItem was setting the array to null
but since java is always pass by value that shouldnt have effect the itemstacks in my array right?
How can I create a system that hides players' nametag but only visually to certain players? I want to hide the nametag If the player e.g: behind a block, sneaking, etc.
how do I make my custom recipe unlock when a player obtains an item, (iron ingot in this case)?
this is how I register my recipe: ```java
Bukkit.getServer().addRecipe(new ShapedRecipe(key, result)
.shape(
"I I",
"IWI",
" R ")
.setIngredient('I', Material.IRON_INGOT)
.setIngredient('W', Material.WATER_BUCKET)
.setIngredient('R', Material.REDSTONE)
);
I don't see anything mentioning recipe book
oh shi my bad
I did find Player#unlockRecipe(NamespacedKey key), and it does unlock it, (I checked with the /recipe command), but it doesn't show up in the recipe book
run it? the guide explains how to use it very well
is there way to see when something was removed and something else added?
in javadocs
like changes per version
is it possible to "exclude" a certain event from firing? I'm trying to make it so that when a horse is spawned in, the plugin will save it to an array.
@EventHandler
public void onHorseSpawn(EntitySpawnEvent event) {
if (event.isCancelled()) {
return;
}
if (event.getEntityType() == EntityType.HORSE) {
Horse horse = (Horse) event.getEntity();
Bukkit.getServer().getScheduler().runTaskLater(plugin, () -> {
if (horse.isValid()) {
superiorHorses.add(new SuperiorHorse(horse));
}
}, 1);
}
}
(new SuperiorHorse(horse) kills the old horse and spawns in a new one)
How problem I'm having is that this turns into an infinite loop- superiorHorses.add(new SuperiorHorse(horse)); kills the old horse and spawns in a new one, which fires the event again and again
oh lol
just add the horse to a set
if its in the set, dont spawn another one
or even better
since everything is on one thread, have a boolean variable in the class
called spawning
set it to true before u spawn the new superiorhorse and set it false afterwards
if entityspawnevent is called when u spawn the horse, check if the boolean is true, if it is, you know you're spawning a custom horse so u can ignore
ive tried that already
@EventHandler
public void onHorseSpawn(EntitySpawnEvent event) {
if (event.isCancelled()) {
return;
}
if (event.getEntityType() == EntityType.HORSE) {
Horse horse = (Horse) event.getEntity();
if (getCachedHorse(horse) != null) {
return;
}
Bukkit.getServer().getScheduler().runTaskLater(plugin, () -> {
if (horse.isValid()) {
superiorHorses.add(new SuperiorHorse(horse));
}
}, 1);
}
}
why u doing it one tick later?
getCachedHorse(horse) just returns the SuperiorHorse thats already in the cache
SuperiorHorse is a wrapper for a custom horse using NMS. I need the original horse to actually spawn in first so that I can copy the color, style, custom stats, etc. from the original horse to the new NMS hose
whatversion are u using
1.18.1
wait ur unable to get it when the horse is spawned?
get what
event.getLocation??
oh well yeah that would work
but it'll kinda make my code very unclean
I've already completely isolated SuperiorHorse so that it only needs a single entity to construct
@EventHandler(ignoreCancelled = true)
private void onHorseSpawn(CreatureSpawnEvent event) {
if (!(event.getEntity() instanceof Horse) || isSpawningCustomHorse)
return;
Horse horse = ((Horse) event.getEntity());
Location spawnLoc = event.getLocation();
isSpawningCustomHorse = true;
//spawn hose
isSpawningCustomHorse = false;
}
a scheduler makes that look very messy
cancel the event and spawn ur horse in the //
whats the difference between CreatureSpawnEvent and EntitySpawnEvent
an item is an entity
but not a livingentity
so item is entityspawnevent only
horse is creaturespawnevent and entityspawnevent
oh ok
it'll be better to listen to creaturespawn but tbh there's virtually no real difference
i guess its slightly more efficient
this seemed to work thanks
but theres some weird thing going on, i dont know if it will cause issues
what is it?
when i spawn in a horse using a spawn egg, its color and style randomizes after like a millisecond after spawning in
like I can see it flash to a different type of horse
did that happen before?
no
althought i think its fine, i tried reloading the plugin and none of the horses changed
and they are all in the cache correctly
horse social stratification
👁️ 👁️
RPG-style horses you could say
each horse has a stats like hunger, friendliness, trust, etc
and you do certain actions to them to bring stats up and down
nice
interesting
and they affect how you interact with them
wait, what's this about native support for bedrock to java clients now?
I hadn't heard about it
WAT
?
it was on my launcher as news just now
where'd you see that?
try launching mc
oh wow
btw a cool trick alot of ppl dont know abt is when u want to do something right away but cant because the event is still being run, u can schedule a task with runTask (0tick delay)instead of runTaskLater(1tick delay)
the scheduled task runs after the event but before the next tick
turns out i can get the coordinates
its just that the error was so hard to read i guess because i was being spammed with an exponentially growing amount of errors every second lmao
lmao
@ornate patio can u help me out with setting up nms
i messed it up somehow and now idk how to get it working again
should i just try to rerunbuildtools?
i can try but i gotta go real soon
rebuilding with bt first
uhh
honestly i have no idea
i can send you my pom.xml if you'd like
@humble tulip
https://mystb.in/EcuadorWingsComputer.xml
or wait here
i actually found the link
I have a small question, why is it that we need to implement the Listener interface when working with events? As far as I can see, the Listener interface is just empty right?
Ah, I will take a look into that, I'm still relatively new to Java, I am coming from C / C++.
Ah I see, although Cpp has interfaces or well virtual functions
I keep getting this error: incompatible types: net.md_5.bungee.api.chat.TranslatableComponent cannot be converted to net.minecraft.network.chat.Component
Apparently TranslatableComponents don't work anymore?
Need help
Anyway the point of it is to mark that any class that implements it will most likely just have a bunch of methods annotated with @EventHandler and that you can expect something like that, we have in the jdk Serializable and RandomAccess as marker interfaces if that maybe helps enhancing the concept a bit better
https://paste.md-5.net/ehipagaguj.cs
java.lang.ClassCastException: class org.bukkit.inventory.ItemStack cannot be cast to class org.bukkit.inventory.RecipeChoice (org.bukkit.inventory.ItemStack and org.bukkit.inventory.RecipeChoice are in unnamed module of loader java.net.URLClassLoader @5fa7e7ff)
i honestlt have no idea how to fix this here
C++ was a long time ago for me haha. Mostly using C the past year.
Ah, just C and not ObjC?
entity.setCustomName(new TranslatableComponent("test"));```
Doesn't work, throw this error:
incompatible types: net.md_5.bungee.api.chat.TranslatableComponent cannot be converted to net.minecraft.network.chat.Component
@next fossil check your imports
I did its all correct
Its the new 1.19 Chat Component issue
1.18 and before works fine
No like
The TranslatableComponent is of md chat api whilst the Component is Minecraft’s component
Am I right to assume that some other classes / functions in the spigot jar go and find these classes, so it can work with them in a way that makes sense for a listener?
pretty sure either wanna use just the components from Minecraft or md5 chat, not both mixed up
I have no ObjC experience whatsoever. I did have a little peek into C#, but I like Java a lot more.
yo maybe i’m dumb asf but why is it say i have a map in class A and then class B and C both take in instances of class A through injection. then i use classes B and C to modify class A. how is it that i can use class A to modify in those classes if java is pass by value
Is there a way to add my custom crafting recipe to the knowledge book?
You can’t cast an item stack to a recipe choice
well then what should i do for what i need?
cause to me pass by value is literally that it’s just a value not like ok we have instance to class A now we can use that to modify class A data. Wouldn’t that be reference ?
anyone knows?
setIngredient('C', new ShapedRecipe.ExactChoice(itemStack)); @quaint mantle
Classes are reference types, yes
bruh
You pass the reference by value
Yes, well the concept of having a Listener.java is vague as Bukkit could have just used Object
Pass by value means something else Zlaio
A variable always passes the value of itself when passes through a function/constructor
hmm
What version?
1.18.2
yes
havent updated yet
iirc KnowledgeBookMeta
is there not a way pre 1.19?
but this was what im getting more or less
Uh that’s odd
in knowledgeBookMeta.addRecipe(); what should the key be? I dont understand
Thunderin where did you put it in your code?
do you mean the class?
A key that refers to the recipe
yes RecipeChoice does have it
it's not ShapedRecipe.ExactChoice
but wouldnt that still give me the same error?
Yeah but what is it? the name of the recipe variable? the name of the item? the variable itself?
NameSpaced key? just a guess
dont cast
if a method asks for a car, are you going to give it a tyre and call it a car?
yeah figured
I see you keep making the mistake of casting stuff
U gotta try to figure how to get a recipechoice
casting is genuinely not a concept i understand
so u can do new RecipeChoice.ExactChoice(itemstack)
?polymorphism
ah
please actaully read this
actually start here
and click next
It wont take more than 5 mins to read
I found this video mildly elaborative https://youtu.be/HpuH7n9VOYk
Learn about Upcasting and Downcasting in Java! Full tutorial with concrete examples.
In Java, upcasting and downcasting are used along with method overriding to do some really cool things. But what exactly is upcasting, what is downcasting, and how do you use them in your Java programs?
When can you upcast, and when can you downcast? What do yo...
Which explains it rather good
is upcasting ever useful?
Method overloading
ill watch the vid first
Awesome :3
yes
actually i upcasted String[] to Object when i was trying to use reflection yday lol
just for my sake, is Player player = (Player) sender; casting?
Yep
okay i think i understand casting a little better
im trying to do this public static ShapedRecipe Heart = new ShapedRecipe(new NamespacedKey(this, "Heart"),HeartEssence.heart);
and it says com.ytg667.main.Recipe.this' cannot be referenced from a static context
I tried everything and I couldn't get it to work
It says that I need to input the plugin where I put 'this' but it also says that I can't use in static context
idk what to do
how do I make the nameSpacedKey?
The keyword static controls ownership (not accessibility). A method or field that is static belongs to the class instead of an instance of a class.
the namespacedkey is fine, you just cant instantiate ShapedRecipe in a static context since that will be loaded before CB even load
and this is a keyword in Java that references the current instance of the class.
u can only use that in a non static context
If it isnt static I cant use this function
Heart.shape("NDN",
"HTH",
"EDE");
Heart.setIngredient('N', Material.NETHERITE_BLOCK);
Heart.setIngredient('T', Material.TOTEM_OF_UNDYING);
Heart.setIngredient('D', Material.DIAMOND_BLOCK);
Heart.setIngredient('H', Material.HEART_OF_THE_SEA);
Heart.setIngredient('E', Material.EMERALD_BLOCK);
Bukkit.getServer().addRecipe(Heart);
}```
oh wait a sec, i didnt looked right
its like a loop either way I cant do it
yeah you cant use this in a static context since there is no this
but the recipe is not in main so how do I get the plugin?
what is init
and call it after you set your instance
so I have this public void SetRecipe(JavaPlugin plugin){ this.Heart = new ShapedRecipe(new NamespacedKey(plugin, "Heart"),HeartEssence.heart); }
And I cant use it in main if it isnt static but I cant make it static
if its a constant value i dont see why it cant be static
Yeah but in this case, static is being used for access throughout the project instead of it being used for a class having a single instance of something
Recipe: https://paste.md-5.net/onecobuzez.cpp
Event: https://paste.md-5.net/idijuqidif.cs
Main: Recipe.getRecipe(this);
Does it work?
I get no errors but it doesn't work.
The recipe works
but I don't have the knowledge
@humble tulip nvm
It didn't show up but it's there
Don't u have to add the item to the player inv
why?
It's a heart of the sea that gives one heart upon right clicking with it
I mean
In playerjoinevent u create a recipebook itemstack
And do nothing with it
Don't you have to give that to the player?
oh wait
you're right the recipe isn't given if the player doesn't have this item
what should I do?
declaration: package: org.bukkit.entity, interface: HumanEntity
Look att his
Think it's what ur looking for
I just put this in the event and nothing happened event.getPlayer().discoverRecipe(new NamespacedKey(plugin, "Heart"));
I put it in the end
U could probably remove your entire playerjoinevent and just put this
You're right, thank you!
How would i get the server TPS?
Has anyone else experienced problems with item meta hide attributes lately?
nope
theres an attribute to hide them
i'm not sure if you can completely get rid of them though
We can
It works in every other plugin from me
public ItemStack createGuiItem(int amount, Material mat, String displayName, String... lore) {
ItemStack itemStack = new ItemStack(mat, amount);
ItemMeta itemStackMeta = itemStack.getItemMeta();
ArrayList<String> metaLore = new ArrayList<>();
metaLore.add("");
metaLore.addAll(Arrays.asList(lore));
itemStackMeta.setLore(metaLore);
itemStackMeta.getItemFlags().add(ItemFlag.HIDE_ATTRIBUTES);
itemStackMeta.getItemFlags().add(ItemFlag.HIDE_POTION_EFFECTS);
itemStackMeta.setDisplayName(displayName);
itemStack.setItemMeta(itemStackMeta);
return itemStack;
}```
that's what I always used, it works in every single one of my plugins except this one
that's... peculiar to say the least
The item is created and has the right material, display name and lore
just the attributes are still visible
I don't understand this :(
i'm sure i have at least ONE project laying around that has this
that's so weird and really annoying
because here i've used
#ItemMeta.addItemFlags(ItemFlag.HIDE_ATTRIBUTES);
instead of
#ItemMeta.getItemFlags().add(ItemFlag.HIDE_ATTRIBUTES);
pretty sure yeah
I'll try that
buildtools doesnt yell at me so i would suppose so
if that fixes it, i suppose the reasonning is that getItemFlags gives you a copy of the attributes list rather than the original, so if you alter it it has no effect
np! x)
But still weird, in older versions it worked the way I did it
i had this thing for a project where i was tired of UI items having data
probably a change that went under the radar
Haha hide everything :D
I guess so
well on that note, back to updating every one of my plugins to 1.19 TwT
There's a changelog somewhere?
probably in the post yeah
wait, per player world border??
whhhat
i would suppose its only visual but still
i just hope that one day, a pathfinding api will be implemented, because NMS is a pain and not really meant to be used
I'm praying for it
I'd love to make my custom entities look at you, but instead they just stand around
well mine does look at you, and move around to cure copper, do somethings on anvils, fight off mobs. But if you ever DARE reload the plugin or be on 1.18.2 instead of 1.18.1
breaks
but its a personal project so its fine
Mine have no AI and only way to make them still look at you is by setting a pathfindinggoal or smth like that
through nms
And that's currently not worth the struggle for me
to make them just look at you i'm pretty sure you dont need NMS
i think teleporting them with a specific yaw and pitch on the location should do the trick
rly? But wouldn't I need to teleport them like very often
every tick to be precise
is that overkill? yes, absolutely
yeah it lags behind a little bit
i was like "why dont you just use packets and make a fake one" but i remembered that its basically the same thing
and it doesnt lag that much, as long as your ping is decent
used it to make a enderslenderman look at you from afar
works nicely but having about 50 around starts to get a bit heavy
mhm
hm
Im new to Java
Why not working
}
@EventHandler
public void onPlayerJoin(PlayerJoinEvent event){
event.setJoinMessage("Just a test");
}```
||oh hell no||
you probably didnt register the class that has this code as a listener in your main class
Have you registered it?
In the main
No :/
So do it
Give you a example link?
Yes
replace BWListener by your class name
i is an instance of your plugin
you could replace it by the keyword "this"
Okay thank you
Look into how citizens does it
@EventHandler
public void onBlockPhysicsEvent(BlockPhysicsEvent e){
if(e.getBlock().getType().equals(Material.CROPS) && e.getChangedType().equals(Material.AIR)){
e.setCancelled(true);
}
}```
Im trying to grow a wheat seed on top of another block, but it just breaks every time.. this was my code for trying to prevent it but it still breaks. I did a log in console for old and new block
And i saw that it also breaks because it does crops as old and crops as new
But i cant cancel that because then it doesnt grow the seeds
So does someone know how i can fix this?
has anyone else noticed an issue with spawning mobs on chunk load in 1.19
the ghost of an old bug seems to have returned
we had the same issue I think it was in either early 1.18 or early 1.17, I think it was 1.18
simple
crop is trying to grow, so crop to crop, doesnt get cancelled, * gets updated and realises it should be here so simply breaks
and blockPhysicsEvent doesnt catch the break event for some reason
can you elaborate more?
I have code that spawns custom entities on chunk load, this code works for all versions since 1.14 but in 1.19 it does not work
So how can i only prevent the breaking part? And that it still grows?
same exact issue happened I am pretty sure it was in early 1.18 days, and was fixed
on spigot's end
i suppose cancelling the blockBreak event should do the trick?
not too sure on that one
Hmm thanks, i will try that one!
hope it works!
Me too!
Blockbreak is a player event
what's the event for "natural" block breaking then? like explosions?
@hybrid spoke guess I better hit jira up huh
I guess thats the BlockPhysicsEvent but with all the things i try with that event it doesnt break but also doesnt grow the seeds
you're actually mistaken
its a simple blockevent
wait no
i am
and cannot read
Oof haha
Lol
can you clear an NbtTagCompound?
so fix it 
i have no idea, the api suggests it IS blockPhysics eventbut that linked event dont all trigger a new event
What should I do register, can someone explain to me?
https://hub.spigotmc.org/javadocs/bukkit/org/bukkit/event/block/BlockEvent.html
https://hub.spigotmc.org/javadocs/bukkit/org/bukkit/event/block/BlockPhysicsEvent.html
declaration: package: org.bukkit.event.block, class: BlockEvent
declaration: package: org.bukkit.event.block, class: BlockPhysicsEvent
Does blockphysicseven actually get called?
Yes it gets called because i want to grow a seed on top of another block, and with blockphysicsevent it breaks
When i cancel the crop with that event then it doent break it but also doesnt grow it
^^
But how?
Oh wait
and update the satte
He won't know if it's being broken or being grown
Exactly
Cuz if he did he wouldn't be in this position rn
Seems like getChangedType returns the type of block that the source block is
That's so stupid lol
Yes i saw that sourceblock and changedblock both returned crops lmao
I did this but not working 😦
@EventHandler
public void onPlayerJoin(PlayerJoinEvent event){
event.setJoinMessage("Just a test");
getServer().getPluginManager().registerEvents(new tr(), this);
}```
i said in the main class not in the listener
o h
how would it register itself
How would your plugin register the listener on player join if the listener needs to be registered for onPlayerJoin to be called
Register your listener in your onEnable method
@Override
public void onEnable() {
getServer().getConsoleSender().sendMessage("Plugin is enabled!");
getServer().getPluginManager().registerEvents(new tr(), this);
}```
Are you talking about this?
yes
i think we should just straight out ask for the whole class
?paste all your code here pls
alright i've fallen in love with CafeBabe
I can see but not working onPlayerJoin method
replace new tr() with "this" without the ""
shouldn't it work with a new instance though?...
Oh okay
Nah
we learn new things everyday i guess
OH, i have a question
convention wise, is it better to :
1 - Have a public static instance of you plugin class for every other class to access
2 - Pass the instance in constructors
Think it throws an exception of u got more than one so idk how he didn't see the console spam
Either is fine
Doesn’t matter
2 is better
Like you usually wanna avoid passing your plugin instance anyway
hmmmmm
If possible, pass dependencies directly
Ye
That’d be the best practice here, altho its fine to do it with the singleton or just passing the plugin instance
Since you won’t gain anything significant from passing dependencies directly unless the project is growing at a noticeable pace
the project?
Yes your plugin
Yeah that’s not much
its starting to be given my usual project scale
Yea ye
first time working on an actual minigame from a to z
Sounds exciting :3
But when I meant growing noticeably I mean having 100k lines+ at least
okay i have a lot of leeway then
Lmao yep
whole project must be smth like 5k lines at most
and that's with generous rounding up
Yeah, well companies who are in the enterprise might have 1 million lines or more
i still have access to a company i did an insternhip in
or at least a version of it
🥲
:/
its in PHP tho so it tends to have more lines
yeah not that bad
still pretty bad tho xD
was enlightening tho
i now know how to organize a project with thousands of files
i just hope i'll never reach that scale for a personnal project
when i was young i wanted to optimise every bit of code i could see, then i got an internship
that was the end of that dream
alright, back to 1.19 updating everything
what did change for devs in the big lines?
i dont think i have any plugin that heavily relies on chat
oh, the encrypted one isnt a different packet?
nope
and it is basically one packet containing 2 packets (chat preview being optional)
CHAT PREVIEW
Servers can enable Chat Preview by setting previews-chat=true in server.properties
When enabled, a server-controlled preview appears above the chat edit box, showing how the message will look when sent
This can be used by servers to preview messages with styling applied, such as emojis or chat coloring
Chat Preview sends chat messages to the server as they are typed, even before they’re sent
The server then sends back the styled preview in real time
This allows servers to apply dynamic message stylings while still allowing chat to be securely signed
A warning screen is shown on the client when joining a server with Chat Preview, and it can be globally disabled in Chat Settings
Dynamic chat styling can also be controlled by the server, although this is only signed when Chat Preview is enabled
Clients can prefer to always show the original, signed message by enabling “Only Show Signed Chat” in Chat Settings
oh
thats a thing?
does that mean chat coloring is a vanilla thing now? or is it just a neat feature for devs
🤣
chat coloring always was a vanilla thing
Wasn't chat coloring always vanilla?
yea but by default u havent had access to it
i meant without plugins or anything
and without /tellraw ofc
like
&4 This message is in red!
u use the paragraph character
^
i never knew you could color stuff in chat without a plugin
the chatcolor enum merely translates colors to this pattern
Is there a way to get a list of all the hidden players from a specific player? or do I need to iterate through the online players list?
package com.connorlinfoot.actionbarapi does not exist
What is this?
I have ActionBarAPI.jar in the libraries folder
to see which players are hidden from the target?
Yes
Player.Spigot::getHiddenPlayers iirc
Oh I see, that's what I was looking for yes
Thanks !
Why is player.spigot a thing?
for text components
and other stuff
you cant edit Player directly i think
the only use i know is for sending text components
it was mainly to explicate the additions that spigot had compared to craft bukkit, but now thats no longer relevant hence why Player.Spigot scarcely gets any new methods
tho tbh the spigot reference doesnt have many members
i suppose its not being merged into player for retrocompatibility reasons?
mye
If I get an online player and put it in a 'Player' variable and they log out
Will it turn the variable to null or does it not work like that?
pretty sure the variable stays but if they relog they wont match
however you will have a bad player object
no but if u try to target that player u will get a nullptr error
you would have 2 player instances of same name and uuid, but different nevertheless
like certain things in the player object is gonna be null Shalev
Oh if they relog I will also not be able to target them?
target them?
just store the UUID instead
^
Yeah I think this is the safer option, I wondered if I could use Player though
had to do this for a antispam plugin wsith a mute feature
and it could be bypassed by relogging
which was annoying
you almost never want to use Player as the key type in a Map
or well in a Set etc
Player interface is at most an accurate context object of a player
nothing more
sometimes
or be invalid as well, or is it just unrelated
||i'm having so much fun discussing here, why didnt i join sooner||
so OfflinePlayers are weakly persistent
which means as long as any plugin holds on to them they will stay
and if not it gets destroyed and recreated when needed ?
<= doesnt know the differences between a weak hashmap and a "normal" one
lemme google it rq
yeah
yesn, you can still get their uuid and stuff but if say u wanna manipulate them set their location, get their location, kill them etc then ull get a nullptr error
ye
basically if u wanna perform anything that ACTUALLY requires the player to be online to work
huh, and will I be able to get information about them? like their hidden players?
that would fix a ram leak i had on an old project of mine
no guarantee shelev
if theyre offline? do if(player.isOnline()) check for hidden players;
else remove from list
I honestly do not understand weak references
barely at best? 🤣🤔
That's really as much is i know
sort of
Lol
can you get the cause of an EntityCombustEvent
?jd
it means as long as x is pointing to blah, blah cannot by definition be garbage collected
Ok that i do know
declaration: package: org.bukkit.event.entity, class: EntityCombustEvent
Yep
i wanna check if an entity is set on fire because of sunlight
and then some arbitrary time in the future, blah will be garbage collected and cleared from on heap memory
if I were to do:
WeakReference<?> ref = new WeakReference<>(blah);
here, any time blah can still be enqueued for garbage collection
only way to hinder it from being enqueued is if
var y = blah
is present somewhere else at the time
I'm guessing weakreference has special treatment from the jvm because how else would it store a reference and still be allowed to be garbage collected
Then is it possible to get an object that has not yet been gced back from heap memory with no references to it
yes
Wtf
you can register the weak reference to a reference queue
altho PhantomReference might be more suitable here
Imagine being smart enf to use this in your projects😂
lol ye
well you should avoid this type of pattern
since we have try with resources
a much better way of dealing with resources
Oh that's another thing
Why do statements need to be closed
If we no longer reference them
ram usage?
do plugins made on paper work in spigot servers?
Yes but shouldn't it be gced
Not all but all spigot works on paper iirc
yea that i know
most of the time yeah, as long as they don't use paper specific features it will work
otherwise the server will be like, oh you need something from paper? what's paper? and just error
xd
releasing resources
Similar to closing a stream?
most will, but no guarantee as paper has stuff spigot does not
myeah
altho you dont need to close all streams
Ah ok
only io streams must be closed
I close all cuz idk which
like a normal Stream from Stream::of or Collection::stream doesnt need to be closed
Yk there are streams that accept streams in the constructor?
ugh wym?
One sec
like Stream::flatMap?
sure :3
Is there an event called even later than the PlayerQuitEvent when a player leaves?
nope
alright then I have to run a task
x)
ahhh, the infamous
. runTaskLater(plugin, 1)
because for some reason it needs a tick to process and work
or just runTask :p
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
BukkitObjectOutputStream dataOutput = new BukkitObjectOutputStream(outputStream);
dataOutput.writeInt(obj.length);
for (int i = 0; i < obj.length; i++) {
dataOutput.writeObject(obj[i]);
}
dataOutput.close();
outputStream.close();
ikr
do i need to close both and do i even need to close them at all?
wait, that delays it by one tick by default??
yes
huh
i guess i can remove smth like 10 characters from a few plugins then
no minion
you only need to close dataOutput in principle
since dataOutput will close outputStream when close() is invoked
well it makes no sense to schedule something after 0 ticks
it does, in a sense
just use runTask ten
what does runTaskLater(plugin, 0) do then?
from CraftScheduler
anyway
public BukkitTask runTaskTimer(Plugin plugin, Object runnable, long delay, long period) {
CraftScheduler.validate(plugin, runnable);
if (delay < 0L) {
delay = 0;
}
if (period == CraftTask.ERROR) {
period = 1L;
} else if (period < CraftTask.NO_REPEATING) {
period = CraftTask.NO_REPEATING;
}
return this.handle(new CraftTask(plugin, runnable, this.nextId(), period), delay);
}
``` here
CraftTask.ERROR = 0
oh wait
ugh
yes
no?
hmm
wait let me see if I can find it
time to test
or do u know this with 100% certainty
i found that spigot-1.19 will play 2 times of the warden summoning animation.
can fix?
yeah make an issue
Bukkit.getScheduler().runTask(plugin,() -> {
System.out.println(Bukkit.getCurrentTick());
});
Bukkit.getScheduler().runTaskLater(plugin,() -> {
System.out.println(Bukkit.getCurrentTick());
},1);
Bukkit.getScheduler().runTask(plugin,() -> {
System.out.println(Bukkit.getCurrentTick());
});
@humble tulip
[11:49:07 INFO]: 105
[11:49:07 INFO]: 105
[11:49:07 INFO]: 105
output ^
ye
is there an order to how a tick functions?
like first mc world does it stuff and all events, then player packets processed and those events then scheduler?
like that
oh
idk how to explain it
well
packet interception -> queued to server thread -> world handles it -> delegates to blocks, entities etc
basically
when does the scheduler run sync tasks then?
how do u check these things so quickly lol
public void tickChildren(BooleanSupplier shouldKeepTicking) {
MinecraftTimings.bukkitSchedulerTimer.startTiming(); // Spigot // Paper
this.server.getScheduler().mainThreadHeartbeat(this.tickCount); // CraftBukkit
yep
intellij -> double shift and then I search the class basically
and I use ctrl + left click to navigate (through classes and functions)
pressing double shift while hovering the class?
oh no, just double shift, it will bring up a search window
oh
I just ctrl left click the class, method, variable or whatever needs to be navigated
yea im probably gonna use that now

Can I simply combine those 2 maven shade plugins? Cause it's causing me some trouble when building
Sure I don’t see the incompatibility here
you should move the relocations from the bottom one to the configuration of the first one
no problem
does it have an inner class?
Shouldn't be an issue in most cases
Alright, thanks. I'm still kinda new to maven
The pom kind of overwhelmed me at first
https://www.youtube.com/watch?v=37_R7ahD6A4
anyone knows how I can do this thing?
z o o o o o o o O O O O O O O O O O P
the gravity storm part
it's all vectors, pretty easy
well, the visual effects are falling blocks but that's the only other thing
can we go dms?
no
can we not go to dms?
alr
Anyone knows why TextComponents now are prefixed with a <> in 1.19 chat?
It only applies to component messages. Not normal chat messages.
no clue of how you got it like that, I use thousands of text components and I don't have it
Thats from worldedit. But also applies to other plugins.
Yes. I just builded the server jar.
the effect isnt that hard,
first you have the location, where all entities should be pushed to
then you use Location#getNearbyEntities,
then you iterate through the Entities and do stuff with them
dms pls?
prob use setVelocity
lets make a thread here
stop trying to drag people into dms
I can help you here
then get help like a normal person
^
ok ig
I just told you how to do it, what is your current problem
nothing nbm
maybe you should elaborate more on do stuff with them
since thats what he wants
he wants to push them all to a location, so I would prob. try it with setVelocity(Vector)
what vector though
but idk how to create that animation
If you have trouble focusing on a discussion start a Thread with your question clearly stated.
I am trying to add a recipe to the recipe book when the player obtains an iron ingot. this is how I register the recipe: java Bukkit.getServer().addRecipe(new ShapedRecipe(key, result) .shape( "I I", "IWI", " R ") .setIngredient('I', Material.IRON_INGOT) .setIngredient('W', Material.WATER_BUCKET) .setIngredient('R', Material.REDSTONE) ); and this event is also registered: ```java
@EventHandler
public void onEntityPickupItem(EntityPickupItemEvent event) {
if (event.getEntity() instanceof Player player && event.getItem().getItemStack().getType() == Material.IRON_INGOT) {
player.discoverRecipe(key);
}
}
the event does get called, and the player gets the recipe (I checked using the `/recipe` command) but the player doesn't get a notification and it doesn't appear in the recipe book.
Is it possible to add a block to a block tag like minecraft:logs so leaves dont dissappear around it
no, you'd have to cancel the LeavesDecayEvent or whatever manually
Thank God there's an event for that, thanks ill just check within a range and cancel it
also the tags are "per material" and not "per block" so yeah tags don'T help
I meant for a material
I was gonna add mushroom block to it
oh ok. you could probably add a tag with some very nasty reflection
Id rather override the event but thanks for help
oki
Well, could also be a chat plugin making the issues with the <> prefix. (if it's only me who has them in 1.19)
Anyway, thanks for the help.
hi alex :3
henlooo
what’s your timezone
CEST
you sen to be on when i’m on
it's 1pm here
central european summer time 😛
it's funny how it's called "eastern" time although it's on the west side of the world lol
I'm trying to get info of the item a player is holding, but it spits out "org.bukkit.entity.Player.getItemInUse()" is null
There is a fair bit of conflicting info that I've found from searching this stuff up. From what I read on the spigot api docs this should be working but clearly I am doing something wrong
declaration: package: org.bukkit.entity, interface: HumanEntity
it's nullable
that means it returns null when the humanentity doesn't have any item in use
they could simply be using their bare hands
like fists
That is the issue, there is an item in use which is what is confusing me
and what item is that?
A diamond pickaxe
what about get item in main hand
Are you doing this in an Interact event? You have two hands
Thank you
it’s out
its out
i never knew lmao
and spigot is updated
I must be out of date, I can't use getItemInMainHand apparently. Is it new?
Thank you
1.18.2, I was just not thinking the right way. It's been a while since I worked on this plugin
and java in general tbh

I should probably have realized I'd need to get the player inventory first. Thank you for your help. Code is working perfectly now.
getInventory().getItemInMainHand()
We've figured it out, thank you though
or just do it properly instead
ItemStack item = (ItemStack) PlayerInventory.class.getDeclaredMethod("getItemInMainHand",(Class<?>[]) null).invoke(player, (Object[]) null);
Looks more like a massive pain ngl
yeah it was a joke, i'm bored
It seems there is no issue when having no item in hand so I'll leave it as is
will now spigot will handle 2times about some BlockInteractEvent
I was just checking if they had Silk Touch enchant java boolean usingSilktouch = e.getPlayer().getInventory().getItemInMainHand().containsEnchantment(Enchantment.SILK_TOUCH);
it has been like this for like 8 years now
If it's null then it'll be false anyways so it's fine for my specific usecase
no, if it's null you cannot call "containsEnchantment" but get a NPE
but IIRC it's annotated as NotNull
it would return an empty itemstack of Material.AIR instead of being null
It is
and warden summoning animate will be played 2 times in spigot
Yes, my mistake. Result is the same but I should've been more clear about cause
when will this bug fix?
or fix it yourself
you have to sign some agreement to get access though
you can access anon on stash. You can;t view PR's is all
oh ok
are wolves persistent by default?
I believe so
?paste
tamed/named are for sure
god this issue is annoying me
Minecraft's forums should say
ok yeah so
something busted my spawning entities on chunk load but only for... wolves and (some) villagers
100% of the wolves, but an inconsistent % of villagers
ok so my issue now makes... less sense
I've a config for my plugin that requires a quite strict way of writing. Is there an optimal way of making sure the plugin doesn't crash when there's an error, outside of using a try catch statement?
I was spawning stuff 1 tick after the chunk load and when removing that wolves now spawn correctly
yeah so now everything spawns correctly
so my 1.18 fix now breaks 1.19
uh
use a config format that isn't as strict as yaml
I always just print a huge warning to both console and chat when the config is broken and load the default config instead
ah i let the plugin crash
again with my probably very basic questions - can someone show me how i'm supposed to setup my pom.xml to undo mojang mappings on compile? it did not work from the two tutorials i found so i tried working it out and turns out i just made it worse, lol
I always just show this msg
yeahh thats the one i tried
but it kept giving me malformed pom errors
?paste your pom.xml
thats my current one
(homemade badly from trying to make that tutorial work)
thiink the issue when i tried that one as-is, executions tag wouldnt work and gave malformed
okay so what the heck is this?
also the <build> section doesn't go into the profiles section
ah ye its even more messed up cus i tried to follow an alternative way
that included splitting it into profiles
then i just kept moving tags as errors happened
so its way more messed up now lol
pls check out my blog post again. you should have a <build> inside <project>, and that should contain <plugins>. and inside there you need to add the maven-specialsauce plugin or whats it called with all the remapping configuration
👍
you can actually remove your complete <profiles> section
Sorry for late reply but how would one go about doing this and so it only replaces air blocks?
I've tried to do it and it only places 1 block not a sphere
show your code ps
@tender shard
Updated code
final Set<Location> blocks = new HashSet<>();
final World world = location.getWorld();
final int X = location.getBlockX();
final int Y = location.getBlockY();
final int Z = location.getBlockZ();
final int radiusSquared = radius * radius;
if (hollow) {
for (int x = X - radius; x <= X + radius; x++)
for (int y = Y - radius; y <= Y + radius; y++)
for (int z = Z - radius; z <= Z + radius; z++)
if ((X - x) * (X - x) + (Y - y) * (Y - y) + (Z - z) * (Z - z) <= radiusSquared)
blocks.add(new Location(world, x, y, z));
location.getBlock().setType(material);
return makeHollow(blocks, true);
}
for (int x = X - radius; x <= X + radius; x++)
for (int y = Y - radius; y <= Y + radius; y++)
for (int z = Z - radius; z <= Z + radius; z++)
if ((X - x) * (X - x) + (Y - y) * (Y - y) + (Z - z) * (Z - z) <= radiusSquared)
blocks.add(new Location(world, x, y, z));
return blocks;
}```
I don't see you placing any blocks in that part of code
outside the for loops
I get wrong locations probably
hard to spot without formatting lol
the only block you ever place is at "location" which is the original argument
instead of doing it in this weird way, you should remove the setType in that completely and then loop over the RESULT of this method to set the type
that worked perfectly thanks, really have no idea what i did wrong before then lol
I have this function that gives items:
if (amount > 0){
is = is.clone();
is.setAmount(amount);
World world = p.getWorld();
p.getInventory().addItem(is).values().stream()
.filter(item -> !item.getType().isAir())
.forEach(item -> world.dropItemNaturally(p.getLocation(), item));
}
}```
and when I use it the dropped items are invisible for some reason. any ideas?
np 🙂
if they are indeed invisible then thats a bug
a bug in my client?
I don't know. I am doing similar stuff and it's working fine for me
I should probably have been more specific. When the plugin pulls from the config it requires things like materials to be properly typed "deepslate_diamond_ore" can't have a spelling error for example. If it does the plugin crashes. I've gotten around this by just typing properly but if I want it to be more user friendly it obviously has to let them know in a friendly way.
So that's why I ask if there's a better way than just try catch, in terms of running the code and spitting out an error if there's an issue.
it's a function that I created 2 weeks ago and it did work fine
?paste
https://paste.md-5.net/ihusukigeg.java ok my drop method is a tiny bit longer lol
@tender shard well I reloaded the plugin and now it's not invisible. idk what that was but thanks anyways
weird. maybe mc just had a hiccup for a second lol
tiny
minecraft counts 4215 dropped items as 2 ;-; wtf
it's not my plugin's problem
I jumped into that dropped items and my entire inventory was filled.
I killed every item entity after that and I got in chat "killed 2 entities"
there was actually a lot of items
isnt that because dropped items merge?