#help-development
1 messages · Page 1097 of 1
odd
try it in git bash
never used git bash
just click this arrow and open one
can u think of an example when it would happen?
when getTo returns null
try to execute buildtools from there
right i will do that but I just am wondering when getTo would ever return null and why
this command
it is NotNull in Paper so I don't know honestly
probably an annotation forgotten in an upgrade
interesting note
if they move and teleport at the same time is an example
IE, standing in a nether portal and you move at the time you teleport, getTo would be null
there is other scenarios where getTo can be null
that would be for the teleport event maybe but not for move event
right but what happens if both packets come in?
because packets don't just stop once sent
so if the client says, hey they moved lets let the server know, and then rightt after the client goes oh times up time to teleport lol
delete the stuff that was generated and try again, it is complaining that you did it first on powershell and now you are doing it in git bash
doesnt the server tell the client when it time to teleport or no
ok trying again
speaikng from laggy experiences
packets are handled by a queue so I doubt it'd be a problem, though I haven't checked exactly how Spigot handles them
I doubt it'd be all too different from Paper
at most, a desync in information can happen and the getTo would just outright be wrong, but for it to be null? I don't know about that
some edge cases
its nullable for a reason
make sure you check for it
There are cases where it can be nullable again
I think they gotta go back
check java docs
I saw machine maker say something the other day about making it nullable again
ah its because of teleports
I'm speaking of why paper is returing to nullable
idk what every edge case for spigot is tbh
but by the sound of it, it looks like more of an API conflict more than an actual behavior issue
it worked now
thank you
even if this was the case you still end up in a scenario where both happens
so if they teleport, and a move packet comes in, the getTo couldn't be set because they are in a different world
and getTo would refer to an invalid location
therefore its best its null
like technically you could say its accurate but it wouldn't be if getFrom is one world and getTo was another lol
I think having it null is valid, but some people believe nothing ever should be null lol
personally I rather have data absent then be given incorrect data
simply because someone hated nulls
data shouldn't be incorrect to begin with, the data having to be null is a symptom not the solution
it is a solution
you thinking otherwise is your opinion sure
but the problem arising with wrong data is that now you have to check the data that it is correct
no, if the server can't properly process the packets sent by the player, then it is a server issue
no
in a multi-threaded environment you simply can not avoid clashes when two things can happen
that is just not true, and what part of the packet processing in the server is multithreaded anyway?
when two things happen at once and you don't handle it, that's called a race condition
well you are advocating that data should be stuffed into it, when it potentionally could be incorrect data that no longer applies. Which sure it works but it doesn't remove the need for checks which is what null would require anyways, just it is easier to detect no data vs incorrect data or data that no longer applies
it isn't that it is not handled, just one is dropped in favor of the other
is spigot single threaded
not entirely
mostly?
almost everything related to the world is handled in a single thread
isnt spigot made relatively recently? like 10 years ago?
only chat and login proccess isn't
not sure I would call that recent
paper is newer then spigot is
recent enough for multi core cpus to exist innit
yes
im just curious as to why they went with single threaded instead of multi threaded
but spigot doesn't drastatically change the way the game works or the code of it
because the vanilla server works that way
spigot is an abstraction over bukkit right?
spigot is bukkit now pretty much
spigot is the continuation of bukkit
and paper is continuation of spigot?
at this point in time you can consider bukkit and spigot one in the same
or parallel?
Paper is a fork of spigot
paper is a fork of spigot, they work in parallel to each other yes
paper is like bleeding edge software built on top of spigot
Spigot = Bukkit at this point
so is paper multithreaded?
it isn't, folia is though
I don't know about Minestorm, never used it
ye same
Minestom will never be as viable as bukkit derivatives
ive seen people use it
sure but you won't get a good solid survival server out of it
minestom is just an API to build your own server innit?
way more control
unless you're literally insane
if you want survival just use minecrafts own server innit
one of these days I will release my own implementation
the so called "nms" is bukkit or actual minecraft server?
vanilla server
nms -> net.minecraft.server
is bukkit an abstraction over the actual vanilla server?
yes
and spigot even over that
not anymore
i see, java in real life
number of spigot patches decreases every year pretty much
so spigot is dying basically?
no lol
ah I see
craftbukkit is the server modifications to make the bukkit abstractions work
I was just curious since im making my own server framework, and dont want to make the same mistakes as bukkit or others
if you want to make a server platform from scratch, I'd recommend talking to the Sponge guys
i dont think itll ever compete with spigot in terms of plugins shit
since entirely different langs
not sure what goals you have, however my implementation if I ever get around to making it won't contain the majority of mojang code 🙂
maybe provide a scripting language like lua or some shit
yeah same, mine is a clean-room implementation as well
just looking at wiki.vg
also, I am going to turn it into a proper server setup
I mean, it doesn't matter even if it is the same language, look at fabric, minestorm, sponge. They barely get any adoption
clean room implementations won't ever really be viable unfortunately
IE separate some components into their own processes
mine isn't going to be entirely clean room
🤔
and you simply can't anyways due to login stuff
login stuff? encryption?
what do you mean by that
he means you eventually have to delegate to mojangs servers for auth
the whole protocol is very well documented, so clean room is possible
tampering with player login functionality is considered removing DRM
ah but I mean, that's entirely different
yeah that
yea thats just using an external API provided by mojang to authenticate users
could go nuts like the fosscord guys and implement the whole mojang backend like they did for discord lol
anyways, the reason I am not going with a complete clean room implementation is because there is some things I am too lazy to do myself
such as pathfinding etc
or entity logic
I ain't going through and making all that myself lmao
that's the easier parts, what hurts is world and chunk gen
pathfinding is easy innit
those are easy
chunk gen, if done in proper steps shouldnt be that hard
would still take time though
a proper, efficient implementation is no walk in the park
Yes
well the thing about making your own implementation in regards to those things is that you don't have to follow how mojang does it
you can choose whatever method you want
yeah thats true
the downside of doing that is that seeds online won't work the same lmao
for world gen you can start with perlin noise and come up with something
otherwise you can use whatever randomization method you want
some are more optimal then others depending on what you are making
have you worked on your impl? @wet breach or do you have to start?
kind of a bit of both. The first thing I need to work on is separating the components
cuz if u gonna start why not work together
my implementation will require 3-4 processes
processes as in server processes running
I did an impl of the server myself, not clean room tho and for 1.8
I am going to have a login server, chat server, world server and some others
splitting the logic in processes sounds like a bad idea
because splitting it like this means I can dedicate the resources to the things that really need it
a chat server doesn't require much and same with a login server
you can easily have a slim VM for that
then you have your world server which you can spread out over many VM's and delegate resources as needed
you could have green threads innit
for every task
right now every conection for me is handled on a different thread
every system (keep alive, connection receiver etc)
they are looking for an arch which will allow for horizontal scaling
and the upside of all this is I can reboot the world servers without players getting kicked
fair
I mean, you can do all of that without splitting into processes
the only upside of process splitting a server impl is horizontal scaling, but at the cost of IPC latency
not sure what you are going on about
there won't be latency issues
chat is not dependent on the world
also, the way I intend to scale the world server is by doing something along the lines of sharding
that's what horizontal scaling is
ok, I don't really care not sure what issue you have
sharding would allow both vertical and horizontal scaling
vertical scaling just has to do with adding more resources or power vs using more nodes
but given technology today such as VM's becoming a whole lot better your horizontal scaling can also be vertical at the same time
nothing says VM's have to be on different hosts
anyways, the reason for sharding is because it would be more efficient to have a separate node for an area of a map. Since I like survival that is what my implementation is geared to
each node is assigned a piece of the world, and if a node goes down another node can easily take over if need be, or you can add more nodes if a shard starts becoming overwhelmed.
one of the main reasons I want the chat server to be its own thing
is because I am fan of allowing people to connect with just a chat client
other then we don't need the main server processes handling that stuff, as well as if something happens in the world chat won't freeze either
I also intend at some point in creating a custom client as well
I do not like the vanilla client
is there any way to completely disable the cobblestone generator?
cancel the event just makes liquid not flow together, i don't want that.
lol
nah 50% he starts, 0.01% its finished
I'd say the odds are more reversed for frost
I've had one of those 'holy shit this bug was so easy to fix' moments
my computeIfAbsent lambda was modifying the map, not returning the value NotLikeThis
Yep 0.2
love that
who wrote that
The people had some fun
easter eggs
does LivingEntity#damage(double damage, Entity source) modify damage based on source GENERIC_ATTACK_DAMAGE attribute or does it deal the direct value, and does it take into consideration the entity being hit's armor protection attribute?
im just having this really weird issue where its dealing correct? damage to all other mobs except Zombies
ie.
Player player = getPlayerSomehow();
Mob mob = (Mob) getVictimSomehow();
mob.damage(mob.getHealth(), player);
and with nothing in my hand, this will not insta kill the Zombie, however if mob is anything other than Zombie, it will
try doing negative health
I added reflections to rust
what are we rating this
frfr
its compile time too
instead of run time
unlike java
How would compile time reflection work lol
derive macros
its in rust
so when compiling code, its basically a macro to loop through each file and look for specific type of structs
the system is pretty clean tbh, the serialization
doesn't serde do that
serde is slow
the overhead
i compared with 3 other libs and mine is still faster, for no reason
i didnt even do stupid simd shit
i do love me some rust macros
this sorta just ended up doing nothing to... everything
like now nothing takes damage lol
kinda funny
extension trait?
pub TraitA: TraitB?
literally what they are called
traits that extend structs/other traits
would be the equivalent of extension functions in kotlin
trait StringExt {
fn push_newline(&mut self);
}
impl StringExt for String {
...
}
let mut string = "Hello, world".to_string();
string.push_newline();
it's just syntax sugar for a wrapper. Maybe a static method that takes the object is a better description
ah yeah
doesn't zig do that by default
like it has that builtin
lmao
they are talking about comptime
comptime is weird
ic ic
a camera as well
aww man you cant name nbt compounds as crabs
isnt it utf8
what is
now do that for dfu 
dfu?
its not rust
yea
how would I bench it
You could rewrite it in rust
theres that
jni
create a jar that uses it and run it in rust 
minecraft's is most likely more efficient given the scale
fr?
not sure since it's mojang code
tf does it even do
its so big
mine is barely 2-3 files
code size barely matters in terms of performance
well it has pretty much all the serialisation from minecraft

because without args it has unlimited capacity?
yes
cuz this is a relatively small struct
a chunk maybe a thousand times bigger
bro getting excited with the network handler
stop trying to get nanosecond optimisations and build shit
i agree
so real
sadly they withdrew the string templates JEP, see https://youtu.be/c6L4Ef9owuQ?si=CuyKyG83f694ikp2
String templates proposed a way to readably and safely mix strings with run-time values and were a preview feature in JDKs 21 and 22. Then, to everybody's surprise, they were dropped in JDK 23! What where the reasons, what could a new proposal look like, when may we see it, and what does all this mean for the OpenJDK development process? Let's d...
i got an idea on what plugin I need but idk how to code.. anti lava and water from forming cobble/obby flags, need worldguard for dependencies,
What tool are you using? Perf?
criterion
I mean, that kind of benchmark isn't even measuring real performance of anything, it is just playing around with the benchmarking crate
what have you done
make my code slow on purpose cuz its too fast, duhhh
sleep(Duration::from_millis(10));
premature optimization is the root of all evil people, remember
I'd just sleep on it if I were you
otherwise you'll get burned out and never finish the project
when I am doing dumb shit inside a project, I know it is time to get away from the keyboard
yes
nothing to do
¯_(ツ)_/¯
or its time to check on your cat
i dont have pets
I can't recommend having one with a good concience, I love animals too much but I am too broke to have them
I love my cat
and they are basically babies that never grow up
XD
i dont want additional responsibilities
i already have too much shit to do
mine is sleeping right above me right now
Wasn’t mainly just put on ice since they didn’t know how to redesign it?
how many lookups are you doing per tick?
Do NOT do db access on the main thread
Yes
26 seconds, jeez
Likely will
you also may wanna check your queries, that's too long for any connection
is your db hosted locally?
well, then you won't ever notice latency issues that way
Well @blissful crow dont be scared, string interpolation is likely to come back in the distant future
or “string templates”
if you now will
kinda, yeah
very so
hey I do that and it's fine! Ignore that it is lazily loading db files under 10kb
Java 8 has long not been industry standard
You’re on thin ice saying that
I will pasta la vista you
I mean, it isn't fine, but like everything done in a single minecraft tick, it'll work out
yeah it's done once mostly at startup
or on the first occurrence of something
then everything else is done async
did you do it to avoid the context switch penalty or just found it easier to not care about it
I did it because the data can't be loaded later than exactly when requested
so it has to run on the same thread
plus it loads in <5ms
"yet we should not pass up our opportunities in that critical 3%" is the part people tend to forget
that just means your design isn't designed around the idea of being non-blocking, normally you deal with that by using completion handlers everywhere
yes but that would be slower
not necessarily, just a lot more tedious than what it's worth
var tag = tags().get("tag");
tag.has(UUID)
...
vs
tags().get("tag").then(tag -> {
tag.has(UUID);
...
});
I like the first one better
laughs in STR."hello \{name}"
😔
hopefully these fancy concurrency features such as scoped values and structured concurrency APIs get out of preview soon™️ so it becomes a whole lot easier
tbf i saw them being used in minestom
scoped values are a bit funky imho
Lol really now?
for things like minimessage, mightve been a personal lib
I mean, it exists in JDK 21 as a preview, so I wouldn't be surprised
I mean both the struc conc apis are in their third preview, hopefully for the sake of love and god we get those fully delivered in j24
nah, they are going to wait till 25 if I remember what I read in the mailing lists correctly, which is next LTS
java is getting some W updates
ah, that’s interesting
but honestly the one I'm most excited about is List<int>
Well at least its on lts then
because of some safety thing that was outlined in the JEP
it's apparently safer
🤨
it was something about performance, but they later discovered it wasn't necessary and thus the JEP fell apart
valhalla is gonna be great
well good enough
valhalla is going to be a W
Yup
we are 1 month away of Java 23 too
holy shit
kotlin when vibes
can you shut the fuck up about kotlin
yeah I am aware, a fuck ton of languages have this
maybe java is just updating and adding modern features?
shocker
Its also interesting gen zgc by default is just shipped fully w little preview or anything, in j23
I mean I suppose its been tested enough to outperform normal zgc
I can't wait for java 100 🔥
are we using zgc by default already
gen zgc
^^
https://openjdk.org/jeps/473 is one I've been waiting to get out of preview for a while too
Yeah
A lot of my optimizing code will need to be updated for all of these JEPs
but they just end up giving me more data to optimize better so W
with this I can stop doing dumb shit like calling map twice and abuse the hell out of method references kek
Its not been out for too little long, doubt that’s the last preview but we can hope
it is going to be ready for 25 most likely, it isn't a big one
https://openjdk.org/jeps/469 however, I hope it can just get out of incubator lol
thing's going through so many phases
Yea as long as things can be fully delivered on the lts version its pretty accepted
Eighth incubator
lmao
more simd intrinsics?
Yea, although fully makes sense why it went through a lot of stages
yeah
it's just waiting on valhalla now
yep, with this you can do a lot of fun stuff
Doubt valhalla will be fully delivered by 25 tho
Java has a lot of auto-vectorization code but it didn't have many utilities for manual vectorization until that API arrived
extremely doubtful
It is so fucking fast
and it's super easy
the same reason you need simd anywhere else, to make things faster
it's like huge speed boosts for very little
working with __m128 is also super easy 👉👈
DoubleSpecies.MAX_DOUBLE or smt and you can make instances of these ones and just sum n values together in one op
the good thing about it being in the JDK is that it's going to eventually be fully cross-platform, so you would be able to write very performant SIMD code that works on various architectures, not like now where you have to be very mindful of it with lower level languages
and the JDK devs are very competent so they'll make something that works well out of the box, anything else will come from library makers
tbh why write in other langs than Java when you aren't in embedded envs
if done right esp with the releases that are coming it is just a productivity boost
love it when ike reacts to his own message
you gotta commit to the reaction
hmm
the jep has been withdrawn
they are incorporating some changes
W
might be of interest to you
it isn't talked about a lot, but people are using Java a bunch in the enterprise side of things
rate my IDE
rust 🗿
RustRover huh
is there like a reason to use rr over vscode or smth
not really
rust-analyzer (the lsp), is really good
to the point you could use notepad for what is worth as long as it supported LSPs
just learn vim
cuz its way better and literally meant for rust?
better than what
you can enable it in rustrover as well
vscode
the vscode extension is also literally meant for rust
i just dont like vscode
simple
i have all jetbrain ides for everything i do
they do best what they're meant to do
vscode seems too basic
vscode is too basic
but you don't need anything fancy for rust
I don't think jetbrains can offer anything of actual value to me as a dev in RR that I wouldn't be able to achieve in my neovim setup
same
its free
¯_(ツ)_/¯
i would rather use (neo)vim than vscode
zed looks fairly limited
how small is ur monitor
just looks crammed idk
i have big font
i mean
it has all you need
what more do you need than terminal, lsp, editor and files
Zed is written in rust 🗣️
isnt that.. .the resolution
meanwhile all other fast langs:
its just llvm
being comfortable
huh?
the screenshot is 1920x1080
also i had to compile it myself
binaries exist
not for windows innit
windows 🤡
anyone good w java generics please dm
?ask
If you have a question, please just ask it. Don't look for staff or topic experts. Don't ask to ask or ask if people are awake or available. Just ask the question to the channel straight out, and wait patiently for a reply. Make sure you use the right channel regarding the topic of your question. Create a thread in case the channel is already in use!
i cant send images
?img
Can't send images? That's because you're not verified! Use !verify to complete verification.
Alternatively, you can upload screenshots to any image hosting site and share the link.
Here's some screenshot utilities that you can use to upload images.
Lightshot: https://prnt.sc
Imgur: https://imgur.com/upload
Flameshot: https://flameshot.org
!verify
Usage: !verify <forums username>
field is not typed
you will have to do TicketField<T> then cast it as that again
unless getInput takes a class to implicit cast
which is a downside
rust is just an automatic downside
its readable
joke of the year award goes to:
you're a downside
FourteenBush! With their joke "Rust is readable"!
lol
anyone can recomend good discord api for bot integration
jda
I got shop plugin which I want to hook in to discord
You LITERALLY use kotlin and rust unironically
d4j 
java.net.URL
never heard of
jda or d4j ?
jda
which one is better and easier?
just use jda, more popular one
thanks
field type isn’t always = data type, hence the second if check comparing the classes so i cant just cast it
unless i just put in a try catch
probs the best option
You wont be able to catch an unsafe cast
wdym, doesnt it throw?
or you can do two TicketField variables
one type ?, other type T
check type then if applicable, cast
There is probably a way to make this kinda type safe. But i have no idea what this is.
public <T> boolean addInputData(String type, T data){
TicketField<?> field = this.category.getInput(type);
if(!data.getClass().isInstance(field.getType())){
return false
}
TicketField<T> castField = (TicketField<T>)field;
//do stuff
}
If you keep the type checking encapsulated with an implicit relation, you can use unsafe casts but be technically type safe.
not semantically type safe, but techincally type safe
Pretty much
This prob work tbh i’m not on pc rn will check later
Eg if you have a Map<Class<?>, SomeObj> and stricly limit access to this map, you can safely cast later.
Hm, i cant point my finger at it, but i feel like isAssignableFrom should be used here somehow
nvm, ignore me, i just got up
that would work i think
I feel like there is a better solution. The TicketField<T> could have a Class<T> getFieldType() method.
What even is String type ???
That doesnt look right
Ye key is the name of the field, a string, value is well, object
like am just messing with input fields similar to what discord has with like NumberInputField, StringInputField etcetc that provides a universal interface for all field types
but generics / that might be the wrong approach even idk
If in inventoryclick the player clicks on the topInventory inv, will topinventory.getcontents return the updated items?
@EventHandler(priority = EventPriority.HIGH)
public void onInventoryClick(InventoryClickEvent event) {
Player player = (Player) event.getWhoClicked();
Inventory inventory = player.getOpenInventory().getTopInventory();
System.out.println("antes");
if (!inventory.getName().equals("Backpack")) {
System.out.println("TOMAA" + inventory.getName());
return;
}
System.out.println("depois");
Backpack backpack = plugin.getBackpackService().get(player.getName());
updateBackpack(backpack, inventory);
}```
The event is fired before any changes where made to either the cursor or the inventories
then what can i do?
Hmm, i would recommend having a coupling to actual classes.
public <T> boolean addInputData(Class<T> type, T data) {
And if you need them deserialized from Strings, you could call Class.forName()
But i would need a bigger picture
First of all, you should never use the name of your inventories as identifiers.
People can just rename a chest, place them and then basically spoof all of your guis.
What are you trying to do in the first place?
not have nametags
backpack
basically if a person put a item on backpack inventory, the backpack#getContents() will update and update on database too
Backpacks should be straight forward.
- When the player opens a backpack -> Load the content and put them in an inventory
- When the player closes the backpack -> Go over the inventory and save everything
There is no need to sync/save the backpack on every click. Just open a plain old inventory and let the players
throw their stuff in there.
Then save it on close and load it on open.
the reason for the string type is because of the input field’s configurable name, it’s not related to T or classes
Like I could have a IntField with the name Salary, and addInputData parameters would then be addInputData(”Salary”, 24000)
if the server closes and the player is editing the backpack?
Do you recommend comparing the arrays in inventoryclose before saving to the database?
Then you need a Registry mapping Strings to classes. But at some point you need to convert Strings to something more type safe.
No, just save the entire inventory and override whatever is in the database before
Bad idea having a string name as key yeah?
User input always results in Strings
Honestly i have no idea how your system works and who can register new types.
Could you tell me why? What if the server restarts with the backpack open?
Make sure to close all open inventories when the server stops.
if server crashes -.-
Then its gone
But how do I close all inventories when the server closes? Doesn't this happen anymore? Do I have to go through all the players and close the inv in the ondisable?
Validators are predefined (URL, Number) etc.
Fields are configurable. The validators should simply serve as a universal standard for adding new fields of a specific type, e.g. a Url Input Field, because it’ll validate the user’s string input later submitted and check if it’s a url for instance
Pretty much
Bukkit.getScheduler().cancelTasks(this); i need make this on disable?
then?
Sadly, for some reason, spigot doesnt kick all players before stopping.
no, happens implicitly
Should I kick all players or close the inventory?
Really depends on what plugins are loaded at this point. If its a single plugin server, then kick them.
This will result in the PlayerQuitEvent being fired for all of them. Alternatively you can manually save all of your Managers live data in onDisable.
In this case, the only thing I have to save is just that, the rest is all synchronized.
and it is a unique plugin
I'll choose to kick anyway
Btw, this has a tricky implication.
You should never run IO operations on the main thread. (Accessing Files, Databases, Web endpoints, etc)
unless you are in your onEnable/onDisable. This means you need a flag that you can set, to switch between sync/async access.
The inventory should be saved in the InventoryCloseEvent, but this should happen async, unless it is fired as a result of your onDisable kicks.
Just keep that in mind. Running IO in events or other parts of the main thread will result in lags.
Oh, I disagree with you.
Which part
Don't be a fool
First of all, why would I use an asynchronous database if I have to use the CompletableFuture's .join method? It will even use more resources and stop the main thread for the same amount of time!
You don;t understand Futures
you do not call .get on a future
it defeats the whole purpose
whats the event for sapling changing its stage?
You should not .join() your futures. Ill write you an example which lets you load the data async, and open the inventory sync afterwards.
The main drawback is that you might need to wait 1 or 2 ticks. brb
Imagine, if I use .thenAccept or something like that, let's consider that it takes 5 minutes for the response to be returned. A get is used that returns the player's coins and it takes 5 minutes to return the response that will return 1 million coins. However, the player has 0 coins and sells an item in the store for 100 million. The player will receive the 100 million in the cache and will set it in the database, then after 5 minutes the database will overwrite the cache and the player will only have 1 million.
So in most cases I'm forced to use .join, which makes it completely useless and just wastes more resources.
It uses more resources because several tasks that will be executed in another thread are rewritten, and it will end up overloading the system as well.
your imaginary scenario is flawed
public ItemStack[] loadItemsFromDatabase(UUID playerId) {
// Load items from database
}
public CompletableFuture<ItemStack[]> loadItemsFromDatabaseAsync(UUID playerId) {
return CompletableFuture.supplyAsync(() -> loadItemsFromDatabase(playerId));
}
public void openBackpack(Player player) {
BukkitScheduler scheduler = Bukkit.getScheduler();
JavaPlugin plugin = ...;
UUID playerId = player.getUniqueId();
Inventory backpack = Bukkit.createInventory(null, 27, "Backpack");
// Load items async
CompletableFuture<ItemStack[]> futureItems = loadItemsFromDatabaseAsync(playerId);
// With thenAccept you can define some code that should run after the future is completed
futureItems.thenAccept(items -> {
// This code is used to get back to the main thread
scheduler.runTask(plugin, () -> {
backpack.setContents(items);
player.openInventory(backpack);
});
});
}
If you call .join() on a 5 minute query, then your server simply crashes on the spot.
when you have a cache system in place, you should storing data in the DB right away before it goes to cache since cache can be lost at any moment. If you follow this, there shouldn't be a scenario where your coins get overwritten
**Imagine, if I use .thenAccept **
And thenaccept will prevent server crash
even if it is in the db before the cache, the problem I mentioned will continue
Look at the example ive sent. Lets not deviate from backpacks, because currency is an entirely different topic.
no it won't unless you are just completely ignoring the DB
What do backpacks have to do with this? You said that queries etc. in the database have to be asynchronous and I said that 99% of the cases do not
brother, I just sent you an example that asynchronous db will result in data inconsistency
the reason they should be async is because you can encounter a long query for whatever reason and it will hault the main thread
In 100% of cases they absolutely need to be async during playtime. There is no exception because you cant risk your server crashing because your DB has a hickup.
but if you use .join it will be worse LOL
will stop the main thread anyway and still use more resources
Yeap. Do not use .join() on the main thread.
And lets keep caching out of this discussion for now.
because the DB having connection errors is not important at all, right? All the server data will simply not be saved from then on.
and even because nothing is important for the player to keep his data in the database because the guy decided to make the DB asynchronous in 100% of the systems 🤡
you dont wanna crash the server due to freezing atleast
and even because a get in mysql is very expensive 🤡
the player is impacted by the server not responding for several minutes afaik
connection recovery strategies have nothing to do with this. If you have actual connection problems to your database during playtime, then this should not be handled by crashing the server on the spot.
alright I see we have an inexperienced person and I am just not going to bother. DB tables can be locked while performing operations where you don't want overwriting to occur like in your scenario. If the table is structured properly you will know that the data you are about to insert is now stale and you can implement code around this in how you want to handle the exception that occurs.
no it most definitely is not
ola, you are making the argument that simply crashing the server is a proper strategy to handle connection problems...
mysql can handle millions of queries a second easily with not a whole lot of resources being needed for it
Now let's go to the real context that a query will never take 5 minutes, will milliseconds on main thread affect?
ANY delay on teh main thread is detrimental
and if the player can do what I said in 5 minutes, in milliseconds. any player is subject to having rollback at any time Do you think this is good?
you should always program for the exception, not the rule
you can never guarantee a query will always be quick
no but it cant be prevented
someone shaking with the harddrives hehe
if the connection from server to DB dies for whatever reason, your query will hang for 30 seconds since that is the TCP timeout
Yes. Even 1ms is already 2% of the servers tick. And DB queries can take several hundred millis, which could be several ticks. And if a lot of players query something in parallel, then you are
running into massive, unrecoverable lags. Each millisecond counts
Thats why i dont even query redis (which is right in memory) sync.
So the solution would be to have rollback at any time?
roll back what
I had 100 players with my db sync, do you want me to send you the tps? 20.0
Really weird
with how many queries a second?
Imagine, if I use .thenAccept or something like that, let's consider that it takes 5 minutes for the response to be returned. A get is used that returns the player's coins and it takes 5 minutes to return the response that will return 1 million coins. However, the player has 0 coins and sells an item in the store for 100 million. The player will receive the 100 million in the cache and will set it in the database, then after 5 minutes the database will overwrite the cache and the player will only have 1 million.
So in most cases I'm forced to use .join, which makes it completely useless and just wastes more resources.
a moment
a moment?
Completely irrelevant. Dont try to come with anecdotal evidence.
that is not a number
ola you are arguing pointlessly. Not a single person here will agree with you doing sync db access on the main game thread.
that doesn't answer what I asked. How many queries a second?
the whole server is in my plugin. and it's everything, insertions/reading when entering, whenever they modify a backpack, whenever they type /gang create, EVERYTHING
i think thats the wrong image
stay calm, I hadn't sent the message yet
ok?
Basically it's a rust server (more similar to factions if you don't know) with a synchronized DB and all the data synchronized, anything the player does (setting up a base, evolving it, will be synchronized)
showing a list of packages helps with nothing lmfao
also TPS is a bad measurement
I can assure you that we have quite a few devs on here who worked on actually scaled servers. And i can tell you from my personal experience (if we already throw anecdotes in) that you would
be laughed out of any dev interview, if you even so much as mentioned running database queries on the main thread.
but yes, the solution will be to have data inconsistency with the DB, and all players will lose their things at any time.
when did we say that
what is bro making up
done correctly (async) you will never have data inconsistencies or data loss
only way I can see them sucessfully running DB queries on main thread with little issue is most likely because the amount of queries per second, is like 1 every so many seconds.
the solution is certainly not to crash your server on a blue monday because the database wasnt feeling it
Just 1 player enters and there is already a query
this is why I was curious with their statement, how many queries were they performing
No, there will be no data inconsistency in your Database. You simply dont understand how to work with data. Thats literally it.
Get you head out of your a** and learn from what we provided you. Show some humility. You will not improve with this attitude.
db host slow: server just dies
so in actuality you have no idea let alone don't even know how measure it or where to find this information
again proving my point you don't know anything about DB's
that there is a design flaw
So tell me how you would solve the problem I mentioned with asynchronous DB
I already told you that you can lock tables
get the data in the Async pre join so it is available in the Join
ever heard of AsyncPlayerPreJoinEvent or whatever it's called
you also delay the pre join until the data has been fetched so you 100% guarantee it is ready
No need to lock. For currencies you simply run queries like INC and DEC, with field constraints. You can define a DB number collumn to always stay above 0.
Then you run your DEC query, and it will either be successful or not.
You can do it that way too
100% consistency in your values as the DB ensures consecutive calls
load data in your pre join and then put it in a concurrent hash map and then do your shit on join
So there you go. You got two solutions. Locking and field constraints.
anyways, @rough hinge I recommend doing more research or learning in regards to DB's. They are very powerful tools on their own and can facilate many things for you if you just knew what it had and in some cases remove code you didn't even need.
concurrency with DB's dates probably before you were born(guessing you are young from your example arguments)
yall 👉 👈
i tried, when i cancel it the stage still changes
just it never finishes growing
lol
are you able to get the stage it was at?
because you could just reset the stage back
only one I know of is structuregrowevent
yea im cancelling it and stage changes
so reset the stage back of the sapling
all you really need the event for is just so you know the stage changed
but doesnt structuregrowevent only trigger when last stage turns into a structure?
not each stage
xS
I'd suggest informed is the right word there
Does anyone here know how exactly the custom crop plugins work, from what ive gathered they use blockentities but from what i can see i wouldnt be able to display the crop properly
Can transient be used like this private transient final JavaPlugin plugin in classes with multiple instances to free up ram/memory usage?
if i need to reference the main class a lot
when dependency injecting
no, ther is only ever one instance of JavaPlugin
transient is about serialization not about GC
yeah it would store references to the plugin class object, not the actual object
ah so like if I have multiple Profiles stored in a List and every Profile has a JavaPlugin field, transient isn’t anything to add
It is if you're yeeting profile POJO's in the database
(because you can't really encode JavaPlugins)
But otherwise no
yeah well do you ever store such an object in whole as it is
Got it
it’s not a too common keyword eh?
dont think i’ve ever used it in plugin or even seen it for that matter
In the minecraft context, no
For methods like this where findone is called if there is nothing in the cache, would you make it async as well? https://paste.md-5.net/miwaheqake.cs
Either that yeah or making my T data parameter just an Object?
In the addInputData method
Acc no that wouldn’t work
But don’t know if the ticket type generic is T since it gets from the name of the ticket type, not the validator class
I could cast it to TicketType<T> after first if check?
Yes
For example, the player types /money, would you run async that returns a completablefuture and then you would use thenaccept? And how would you send the message to the player with the amount of money inside the thenaccept? Would you run a task to just send a message?
You can just sendMessage in the thenAccept
sendmessage is sync?
The way we do it at work (we're a pretty big bedrock studio) is that everything that needs to be done in order is blocking
Our economy service is blocking and every request goes through the database
this tells me you haven't got a single clue about how minecraft works
sigh this will take a while to get across
I didn't understand. Did you say to sync this?
There are a few keywords that are tossed around and they can often get confused
Mostly we need to know the difference between sync vs async vs multi-threaded vs thread-safe vs blocking
because labelling everything "sync" is just a huge meme
sync - be executed in a single thread
multi-threaded - many threads to execute
thread-safe something that may have coherence issues if executed outside the thread
async - could it just be load distribution and not imply a different thread?
Nope
A blocking method is a method that takes a while to execute regardless of what thread you're on
For example, an IO operation
.join on CF?
Not exactly
then
and stop jumping to conclusions so fast ffs
you're here to learn not to 1-up me
Thread-safe means that a method is "alright" to be ran on another thread, or multiple threads at once
So for example, sending a packet is thread-safe. You can queue up multiple packets on multiple threads at once, and the server doesn't care
Then you have the term "sync", which doesn't necessarily mean "main thread" but it means that a method runs in a synchronized operation to the thread that calls it
It might run on another thread but eventually join back the main thread
In minecraft terms we just refer to it as "running on the main thread"
And "async" doesn't necessarily mean "running off the main thread", it just means that "it runs.. eventually.. somewhere"
It's parallel to what your operation is doing
is it a common practice if I make my plugin use reflection and compile it with the java version that is run by lowest supported minecraft version my plugin uses. Then I can make a single jar that is supporting versions 1.8-1.21
I mean, you can also use MRJ \s
Yeah, the definition of async is often most misunderstood
Which is a shame, because it undermines the beauty of lockless concurrent datastructures and algorithms
(it basically just means don't expect immediate results)
Now, what we do at work is that we have a "blocking" bunch of services for our database operations
So for example economy is blocking, where any get / set might run through a cache but usually takes a while to execute
me?
So you're encouraged to execute transactions off the main thread (because blocking it is stupid)
yeah
And if you care about constant updates (let's say a scoreboard or something) you can store a snapshot of the last let's say 5 seconds
tbh I never heard for that
And update the snapshot if any payment data is received on the same server within those 5 seconds
That's one example, there are a lot more complex structures
Multi-release-jars. They are more often more pain than worth it, but sometimes can be quite neato - especially once you dip your toes in sub-J8 compatibility
I didn't know that even exists so I tought I could write my own tool that does that. But then I remembered that I can make a single jar for every version. But the problem comes that basically I need to refactor every existing nms code to reflection and then add new reflection for newer versions and etc....
I'm still thinking. That's what I said right
hum ok
I mean, you're probably better off using MethodHandles instead of Reflection unless you want to support really old Java versions.
And ideally you find workarounds that don't involve NMS code but I can understand that that isn't always possible
Yes, I already understood. But I don't even know if sending a message is a packet sent or not.
I wanted to know how in my case I would use ./money <...> and use the findone method being async (async on this case, outside the minecraft thread) in the db
I would like to know how, after the response returned from the DB, I can send a message outside the Minecraft thread and from what I understand, can I do that?
You can yeah
I would like to know everything about Minecraft that is thread safe. Sending messages, particles in the world is threadsafe. updating an armorstand for example is not thread safe, right?
I understand and good points. But the plugin's base is already in 1.8 and it was meant to be like that. But I want the plugin to work in modern versions, like the latest ones. And my plugin is forced into using NMS on multiple parts, because on some things I didn't use APIs because there is no guarantee that they will work later and upgrading that would be harder than upgrading NMS.
upgrading that would be harder than upgrading NMS.
Uh what
like third party APIs***, for example book api or smth
because as u know in 1.8.8 book support isn't as good as in 1.21
I have a vehicle plugin that whenever a player presses W in the packetreceiveevent (I used packetevents as the lib) updates the location of an armorstand. But, I update the location of the armorstand outside the game thread, which I believe is not thread-safe, what can I do about this? I tried to execute a task but the server thread stopped because there must be like 1000 threads in a single second. The thread stopped with only one player, which in this case was me using the vehicle.
so I tought I could maybe get bukkit package name and extract NMS version from it automatically and with that make it support all versions
jump back sync to apply world changes
Is it possible to block coal from being consumed in a furnace using spigot java
nms
I thought just getting the entity location and getting the yaw would do it but seemingly no
no way really
API is lacking in that it applies the yaw to the body and adds Eye height for eye location
I think I need just 1 single NMS rewrite from 1.8. 1.13 was released together with mojang mappings, so this is the only version that I need to refactor NMS and then 1.13+ versions will all work? correct me if I am wrong. All NMS I am currently using is for packets.
it would be a breaking change to fix it
can't get get an entity.getBodyLoc
from nms you can
any idea what the remapped way of getting it is
I'll have to open my ide
is it just getBukkitYaw?
I think I can confirm this one for myself.
I can confirm.
can i use player#sendMessage if player is offline but player != null?
Probably?
I think you can but why
It just won’t do anything
I guess
nothing happens but it works
Just chexk
You can but its a stale object so will do nothing
Yeah just put an if statement
you May get a connection error in console but it should not crash the server
It will happen, I just want to know which one has more performance, check if the player is online or simply send the message
sending the message probably
send a message is equals send a packet
right
player.isonline check if player is a map or list idk
but the player object should already know if its online
no
the code inside thenaccept can be executed after the player has exited
I always just do player!=null
but player is != null lol
the code inside thenaccept can be executed after the player has exited
yes
but then at that point it will either be online or not
like the player object will know if its online
or atleast should
Plus this is in an async task, so it matters even less
player#isOnline check in a list, it's not a simple boolean
What would you do? Would you do the verification or just send a message?
look, if the player object is valid, you can do whatever you want, or you can just store UUIDs and get player by uuid
but idk the implementation so sendMessage might not even send if no player is online
yes but 99% of the cases the check in the list will be redundant because thenaccept is supposed to return 1 ms after the player is still online
brother, you are still talking about worse alternatives 😂
Just do the check
Then you don’t have to worry about something changing in the future
Better. STOP holding Player references and fetch from UUID
exactly
your plugin is not gonna break because you missed a 1 ns increase optimization
In 99% of cases the check will be redundant, so I think it has more performance in 1% of cases to send the message to a player who is not even online, but I don't know if it returns an error.
well seems like yrot is body and yrot0 might be head
does that mean it's not even exposed?
Why do you care about performance
it depends on the case lol
This is a single Boolean check that isn’t even on the main thread
if you already made up your mind then just go for it, maybe add a comment or whatever
the idea behind programming is that you are aware of the consequences
If the player types /money pay <name> you will call a method with his uuid, then to get the name to get from the database you will get the name by uuid (go through the list once) and then in thenaccept check again if the player is online (go through the list once more)
If you want to use Player you can use weak references
data shoudl be stored against teh UUID as names can be changed
^^
generally yes, but this is such a non issue in this instance
always prefer uuids for any real systems
not in my case because my server is not premium
what?
So like I said, don't generalize
well, I'll check if the player is online because it should return an error
lol
hey does the client do some kind of client-side logic for body rotations because this only "works"
it works when they start moving but now when they're standing still

