#help-development
1 messages · Page 665 of 1
are you on 1.16 or sth?
nope
which version is that?
1.19.4
just too lazy to use mapping
but using the mappings is the lazy way
I'm fine with the dictionary 😄
you are doing it the more complicated way
yeah well but nobody else knows what b() is or i()
or AdvancementProgress#a
and without the full stacktrace, we also cannot help
What line?
the MinecraftKey minecraftKey = craftAdvancement.getHandle().i()
it keep telling me that it is null while It cannot be null
Also
As im starting to learn what you guys think is the best tutorial foe learning mc development
intellij
technically its up to opinion
your best to try the most popular ones
intellij, eclipse, netbeans, visual studio
I use it
if you know java well enough, you have all the resources you could possibly need to build the most complex plugin that ever existed
But tutoiral
so learn lava
?learnjava
Here are some links to get you started on learning Java:
- https://www.codecademy.com/learn/learn-java
- https://www.sololearn.com/learning/1068
- https://www.learnjavaonline.org/
- https://programmingbydoing.com/
- https://docs.oracle.com/javase/tutorial/java/index.html
The last one is the only official one, however some of those concepts assume that you already know a bit about programming.
theres the wiki
Ik docs but ok ill see
The home of Spigot a high performance, no lag customized CraftBukkit Minecraft server API, and BungeeCord, the cloud server proxy.
Here are some links to get you started on learning Java:
- https://www.codecademy.com/learn/learn-java
- https://www.sololearn.com/learning/1068
- https://www.learnjavaonline.org/
- https://programmingbydoing.com/
- https://docs.oracle.com/javase/tutorial/java/index.html
The last one is the only official one, however some of those concepts assume that you already know a bit about programming.
Oki
If you "perfectly" understand java you should take a look at the wiki and some plugin on github.
Should get you pretty far
Obviously you want to look at smaller plugins so you learn more about the basics of the api instead of being overwhelmed by huge projects
public static final enum Type {
}
why this didnt work?
oh god
that's not how enums work
uhm why do you need static and final on an enum
still dont works when i removed static
remove final too
why
an enum is already final
Because an enum is a compile-time constant
^ that's final in more words
Except for finals that get their values by a constructor since those can obviously be dynamic as in can be read from a file
But maybe we should start with the question why you thought an enum should be static final in the first place?
i doubt you're getting an answer to that
Will probably write an api full of final classes at some point💀
i suggest java gets removed from the face of earth so people don't have the issue of not knowing java
(since it won't exist anymore)
And then we all use kotlin?
no
we all learn assembly
why bother with a programming language when u can just not need one
Does anyone know how the uid.dat file in a world is created?
It has 128bits, so it's UUID; But it doesn't match the value that's safed in the playerdata.dat files.
what do you mean by how it is crated
Yeah "created" might have been a bad word for it, whoops.
What I meant was, how do you convert those 128 bits to the WorldUUIDMost and WorldUUIDLeast?
It seems that each player safes 3 things about the dim they are in:
Dimension(an int like 0, -1 or 1)WorldUUIDMost; I assume the first 64bits of the 128WorldUUIDLeast; I assume the last 64 bits
But when I ran the code I got following result:
128bits: [2, -128, -46, 100, -101, -121, 66, -87, -77, -24, 93, 121, 20, -9, 57, 29] (Shortened to a byte array here)
First 64bits: 180375314642715305
WorldUUIDMost however is 180375314642715300; I'm off by a value of 5?!
Last 64bits: -5483029771699406563
WorldUUIDLeast however is -5483029771699407000; Here's a greater margin of error and idk why
there is a way to create an inventory with a title that has a custom font?
BaseComponent component = new TextComponent("123");
component.setFont("custom:font");
Inventory inventory = Bukkit.createInventory(null, 27, component.toString());
this method doesn't work 🥸
No exception
which is the best way to generate sha1 for resource pack?
why are you trying to do this though?
trying to use DigestUtils.sha1Hex(), but is not working
i'm not sure the uid.dat file is used for actually identifying the world
Cause I want to TP an offline player; And therefore I need to change their playerdata.
No, chaching that they SHOULD be teleported is not an option.
iirc u can even delete the uid.dat file and it will be regenerated
why is that not an option?
Changing their position isn't hard, however teleporting them through dimensions is
why is teleporting through dimensions difficult wtf
Cause the whole point of the plugin is to teleport players, who got their chunks corrupted, out of them.
The player's position is not stored in uid.dat
Cause I can't get an instance of Player, I always have OfflinePlayer
if you really wanna do that u can probably have to take a look into editing playerdata
You just need to read their .dat files and yeet them into another position
Ik, that's not the issue.
But it seems that the UUID (WorldUUIDMost / WorldUUIDLeast) is. That's my question, how do I get those 2 values
I can't; I tried, it won't accept it if I just change the "Dimension" value
wait, how did you get that? It looks like you opened the .dat file in intelij
magic
Hm, cause I always have to use VScode or now my own editor
explain wizard
yes
Anyways, does one of you know?
so
128 bits is.. 16 bytes
The format is split into 2 segments
of 8 bytes each
Pure coincidence that a UUID's constructor takes 2 longs and a long is 8 bytes huh
That's exactly what I did in the msg I wrote, yet the values aren't correct
I wonder where I've seen this before
I'm not using UUID, I just called it that cause of the naming they used
Yeah but they are
Only reason why it's saved into 2 segments is because it uses less overhead than writing a string
But it won't do anything if I converted the bytes to a UUID and then get the bytes again
No clue what you're on about
Maybe start by providing a method and some test cases
And describing your expected output and what you're getting
Ok, so I get the 128bits, no problem; Then I spit them into 2x 64bits, did that; Then I get the values from them, aka msb and lsb. But they are still different to the values that they should be, but just by a slight margin.
That's what I did in the msg I pinned:
#help-development message
how can i generate sha1 for resourcepack?
Here's the uid file and here's the code I used to get the data I mentioned:
final File file = new File(path + "\\uid.dat");
final byte[] a = Files.readAllBytes(file.toPath());
System.out.println(Arrays.toString(a));
final String s = toBinary(a);
private String toBinary(byte... bytes ) {
StringBuilder sb = new StringBuilder(bytes.length * Byte.SIZE);
for( int i = 0; i < Byte.SIZE * bytes.length; i++ )
sb.append((bytes[i / Byte.SIZE] << i % Byte.SIZE & 0x80) == 0 ? '0' : '1');
return sb.toString();
}
is ItemMeta.setLore outdated?
No you're just using paper
Oh, so how to do this using spigot? How to get "Component" & "Component list"?
that's paper only
this your expected result?
Spigot doesn't have support for adventure natively. And doesn't yet have compoennts on ItemStacks
oh
how do components work on itemstacks?
the same they do elsewhere internally in NMS
That's the issue; the MSB should be 180375314642715300, but it's 180375314642715305 for some reason. That's the same result I got aswell.
Same with the LSB, it's also wrong for some reason
you can't hover over the text as far as i know
just click events won't work and hover events
but ItemMeta.lore().add() is working
ah
ask paper
we don't support those methods here
well, they are just fancy texts then
Something tells me your "should be" result is skewed
oh ok sorry
But is spigot supporting changing lore?
I'm reading it out of the player.dat file directly
corrupt player dat file maybe? Send that over
oh i got it
It would be quite the coincidence if 2 players were corrupted and had the exact same value
got no clue
but sure.
Thanks for looking at it though
but still good to double-check
You want both .dat files for me and my alt?
WTF
took me a bit because I accidentally assigned intellij to not open .dat files
I'm gonna hit someone AHHHHHHHHHHHH
Thanks alot <3
Also, please mister Wizard, tell me your secret of opening these files in intelij
ide plugin 
Great; Now I have to find the bug in my parsing code... yey
❤️
What's regionised multithreading and how could it affect a minecraft server?
It has nothing to be with spigot, just saw Folia thing (a papermc fork) which sais that's using that regionised multithreading
||Don't wherami me 😔||
So I made a plugin that gives you a temporary inventory (for a duel).
In the event that a player disconnects during a duel, should I save their inventory to a file and restore it when they rejoin or just revert their player.dat file to before they started the duel?
Revert their inventory when they disconnect
so save their inventory and apply it when they join?
Likely, why don't you just revert their original inventory when they disconnect?
Instead of doing it when they join back
Will I have access to their player object to do that before the server removes it?
if so that makes this much easier
Wdym?
PlayerQuitEvent has a getPlayer method, the event gets fired before the player actually disconnects the server
Or are you modifying directly .dat files?
If so, you shouldn't
no the duel inventory is in RAM
how to use interpolations with block displays?
Then I would recommend you to use PlayerQuitEvent and restore their inventory when they leave the server, instead of when they join back
okay thanks
You could store their inventory, in case the plugin gets shutdown while duels active (in which case player inventories won't be restored), so when the plugin starts again, its able to restore "saved" inventories
And in that case, you will need to use the PlayerJoinEvent instead
ok
Set the transformation I believe
Folia's concept is that instead of ticking all worlds at once
It's split into regions
And those regions have their own scheduler
So if someone's base is laggy, the rest of the server doesn't get affected
Yeah, I've been reading how it works, I kinda like it
Even though they say it breaks almost everything
folia's concept is amazing
but how do plugins work with it, i assume entities events will be called from another thread
They don't
As of now
But basically yes
Apparently, for example, EntityDamageByEntityEvent, each entity could have its own "region", which means performing the same action on both entities could happen at different times?
What I really like about Folia is that there's not a main thread as it is
A good part of it, is that they will allow to schedule a task for the next "tick" or something like that
public void onUserIsTeleporting(PlayerMoveEvent event) {
Player player = event.getPlayer();
Location to = event.getTo(), from = event.getFrom();
if(to.getX() != from.getX() || to.getY() != from.getY() || to.getZ() != from.getZ()) {
if(player.isTeleporting()) {
player
.cancelTeleport();
}
}
}```
I am trying to make it so the player can look around while teleporting but if they move x,y,z it cancels
But this cancels if the player moves their mouse which isn't making sense
use epsilon to check if it's not the same location
there might be small corrections that triggers it
What do you mean by epilson
or just compare block locations if it's fine for you if they move on the same block
(Math.abs(x1 - x2) < epsilon)
basically your tolerance
it allows for small double errors to go unchecked
you can go with 0.1
not sure what epsilon tolerance is exactly
if(Math.abs(x1 - x2) > Math.E || Math.abs(y1 - y2) > Math.E || Math.abs(z1 - z2) > Math.E)
Like this?
Sorry i havent dug into much math stuff lol
What event happens when a block changes itself? For example coral dries up
if(Math.abs(x1 - x2) > tolerance || Math.abs(y1 - y2) > tolerance || Math.abs(z1 - z2) > tolerance) {```
That enables a hack client to move 0.15*20 blocks per tick
hmm
Either compare the original location (and store it) or go for 0.00001
can also test with more digits obviously
I thought this would be simple lol
declaration: package: org.bukkit.event.block, class: BlockFadeEvent
Yea the tolerance lets me walk more than i'd like it to before cancelling it
just lower it until you're happy
If I do 0.015 would that be good
how long is your teleport cooldown?
3 seconds
that's 0.9 blocks of possible movement (with a hack client)
hmm
My code use to work back a couple years ago lol
can also go for 0.0015 which makes it 0.09 blocks (which is minimal)
All the sudden correction movements mesed it up
Didn't work
I moved my mouse around and it triggered
private boolean hasMoved(Location before, Location after) {
return before.distance(after) >= 1;
}```
Are you sure you are actually running the correct code?
I never had a problem with X Y and Z exact comparisons either
yeah, it's something odd
it's not like minecraft keep changing the x, y z of player for yaw/ piatch movement
public void onUserIsTeleporting(PlayerMoveEvent event) {
Player player = event.getPlayer();
Location to = event.getTo(), from = event.getFrom();
double x1 = to.getX(), y1 = to.getY(), z1 = to.getZ();
double x2 = from.getX(), y2 = from.getY(), z2 = from.getZ();
double tolerance = 0.0015;
if(Math.abs(x1 - x2) > tolerance || Math.abs(y1 - y2) > tolerance || Math.abs(z1 - z2) > tolerance) {
player.sendMessage("You moved!");
}
}```
Thx
remove this pls
remove
What do you mean?
its the shittest code I have ever seen
use this man
can't be here for long then
lmao bro literally got 3 replies saying "remove"
that doesn't work tho lol
should use distanceSquared though
🥹
im sure it does
assuming you put to and from
Are you referring to the entire code or just using the PlayerMoveEvent?
Comparing blocks allows movement on the same block tho
but if you want precision use tolerance
public void onUserIsTeleporting(PlayerMoveEvent event) {
Player player = event.getPlayer();
Location to = event.getTo(), from = event.getFrom();
if(hasMoved(to, from)) {
player.sendMessage("You moved!");
}
}```
Better?
The hasMoved allows too much movement
why would i use PlayerTeleportEvent.TeleportCause
what did i do so wrong in tolerance everyone wants me to remove it
they are bots i think
if you look on their spigot profile they are friends
or something
they just go at it together
https://www.spigotmc.org/resources/authors/defuuu1337.1155253/ and https://www.spigotmc.org/resources/authors/fertiz.1826727/
Hi
?
Forgive me for writing here, it's somehow easier for me here, who can tell me. I want to ban the use of elites on the roof of hell.
are you dumb or something
maybe stop complaining about code you don't understand
and also don't give bad code in playermoveevent
Yeah I thought the same, they are bots
I don't get why it is always so hostile to ask for help here
what is Vector.distanceSquared?
Who’s a bot?
to.getX != from.getX,
Omg bro really??
!=
not work 😦
but this doesn't work because it seems camera movement also prevent movement, maybe read the guy's problem first before
public void onUserIsTeleporting(PlayerMoveEvent event) {
Player player = event.getPlayer();
Location to = event.getTo(), from = event.getFrom();
double x1 = to.getX(), y1 = to.getY(), z1 = to.getZ();
double x2 = from.getX(), y2 = from.getY(), z2 = from.getZ();
double tolerance = 0.015;
if(Math.abs(x1 - x2) > tolerance || Math.abs(y1 - y2) > tolerance || Math.abs(z1 - z2) > tolerance) {
player.sendMessage("You moved!");
}
}```
Can I use this or is it really that bad
use it
it is really bad
dont use it please
On my server, everyone uses this, I would still like to prohibit the full use of elytra on the roof of hell
How would you do it then
you can help me ?
just use distance method or do it yourself, compare old location with new one
You have to make some kind of map holding the from location, check the X, y, z delta by that stored (from location), whenever you find out to call that by tolerance, replace it with the new (from location)
Each time you call event.getFrom, it gives you a new (from location)
what if he put them on before he got on the roof?
Which you found out not working as expected
\
You can also use distance squared, that one doesn't cost much of CPU since it's not doing the square root thing
Do you want me to just pick up the elites? It is necessary to somehow prohibit so that they remain
hey, i have an abstract class like this that takes T extends Event
but when i extend this class and set generic to in this case EntityDamageByEntityEvent i still get an error when registering the listener saying i cannot register a listener for Event class
help me pls
use brain and you will solve it
i don't think bukkit allows dynamic events
plus how would they work?
they all become whatever T extends in compiled code
the information will be lost
ahh i see
i need to prevent that somehow
to be the class that extends
unless theres a different way to register a listener manually
Take a look at this example:
https://paste.md-5.net/ufipelijim.cs
??? you both overengineer it
Can you explain me what "over engineering" is?
Are there any better solutions, so come up with it
players as map keys
fuck no
Welcome to java
Yea sure tho, I'll mostly use strings with player names, but yea, that's an example
UUID ???
use uuids
Where does everybody usually store additional information about players, and things for the plugin?
🙏 @echo basalt do u know how 2 make the cumpiler not break it
made an interface for teleporting a player 
That's what registerEvent is for
writing useless code
simply
🤔
please tell me if you know how to solve this problem
onFart(SpawnerSpawnEvent event)
I have already told you so many times
compare event.getTo() and event.getFrom()
Ive read the documentatiuon for player interact events and I am still a bit confused.
Im wanting to check when a player right clicks, with nothing in their hand
and ?
client doesn't send a packet
and do rest of code
So either use a resourcepack and make an invisible item
or have some sort of invisible entity 5 blocks into their cursor
Can you please explain in more detail ?
How do you get the comparation between event.getFrom and event.getTo? How do you know the time complexity between each move packet that has been sent to the server? How can you get their difference?
sometimes reading docs really helps
read docs
Location from = event.getFrom();
Location to = event.getTo();
if (from.getX() == to.getX() && from.getZ() == to.getZ()) {
return;
}
even this is better
you can also use distanceSquared
Sorry, going to sleep rn
bruh I ordered burger king and this shit ain't showing up
family's gonna get mad if someone rings the bell at fuckin 2am
I would be very grateful to you if someone would help me solve my problem. I'm a newbie
For sure tho, thanks
THEN CHECK ALSO FOR Y?
be more worried the BK was open still at 2am
if he couldnt move camera then he modifies player yaw or pitch
what about camera being affected?
its not the check error
Are you kidding me?!
so
what about you start thinking
Is it you asking the question?
Or I'm getting wrong
Represents an event that is called when a player interacts with an object or air, potentially fired once for each hand. The hand can be determined using getHand().
To be clear i believe you, but the documentation seems to be worded oddly
This is what was causing the errors
It fires if:
- The player interacts with an item, looking at air
- The player interacts with a block
yes
There's also the interact entity events for when the player clicks on an entity
no?
The code triggers when a player moves their mouse
yes, thats why you check if he has moved
That won't work
Well sometimes it does
if you dont want to cancel event you can teleport player to old location
You don't want to compare decimal values directly like that, but do an epsilon check
the amount of misinformation that's spreading
whats the matter tho? if you want to check if player has moved from block then use code I have sent
this is what distanceSquared does: NumberConversions.square(this.x - o.x) + NumberConversions.square(this.y - o.y) + NumberConversions.square(this.z - o.z)
if no, then use distanceSquared
I want to ban the use of elites on the roof of hell.
answered
can you just take off the elytra?
It'd work if you did getBlockX, but comparing doubles rarely works with == due to floating point inprecision
@quick beacon I'm sure tho, this is not going to work with lower speeds, you have to track their (from location), that's the simplest solution I can suggest, maybe ask other ppl they may know better than me.
You can also use distance squared instead of tolerance.
https://paste.md-5.net/ufipelijim.cs
its int my friend 🙂
its block location
not double location
I don't want to take away from the players
Location#getX returns a double
I didnt use getX
are you blind
but still
Look at this for detecting an elytra use. https://www.spigotmc.org/threads/event-called-when-player-glides-with-elytra.127237/ If the player is above a certain Y level, stop it…
you can use block location
he didn't want block changes as that's too much
That also doesn't work with higher distance and lower speeds
wdym
can i use spring with spigot?
That was why I made that map, just put loggers in move listener as see what it does
Just make a separate spring service and do some communication
Easier to test and won't blow up your server
do communication using websockets or java sockets
Introduces security vulnerabilities
wdym
Just stick to a database or some messaging system like rabbitmq
java sockets and websockets are encrypted
if someone has ip and port, yes
the same goes for database 🤣
With a well configured firewall sure
with simple configured
Databases at least try doing authenthication
also you can block other ip connections
you check socket ip
you can choose which ip can connect
That's what I'm doing, in fact
I adjusted a settings on my Eclipse now when I click a file it opens in my Project Explorer window how do i undo that
just take off elytra from player
I'm not taking elytra away from him
so do it
String clientIP = clientSocket.getInetAddress().getHostAddress();
if (isBlockedIP(clientIP)) {
System.out.println("Blocked connection attempt from: " + clientIP);
clientSocket.close();
} else {
System.out.println("Accepted connection from: " + clientIP);
}
I want to forbid using on the roof of hell
you can probably just take it away and put it right back a tick later to force fly mode off
not sure why cancelling that event woulnt work tho
If I spam enough requests I can crash the server by spamming sysout
YES IF YOU HAVE IP
It's a real vulnerability
ips are public domain you idiot
I can just try every single ip out there
u are idiot xd
do you realise how easy that is to get of a minecraft server
just use brain
depends
sudo ufw
and move on
you can block ports and use shields
jesus relax dude
i cant read this shit
I have a degree in systems management and programming, I know enough about network security jfc
yes, if server is not protected well ofcourse
yes use python's firewall
i bet the network handler would crash it before sysout does
because it has bandwidth limits?
I'm not joking, ufw is written with python
yo illusion sorry to report this to you man but u have no brain
thanks
appereantly
if you have no idea about servers then please don't talk
lmfao
fuck it i'm too ooga booga for this
the network handler would probably crash the server before the sysout spam does tho
you are the one who is trolling
Relax, you literally compared two doubles with =! Rn
and you are troll about forming a proper english sentence
aint no way
yikes
., You both did
Quit trying to sound almighty because you have a plugin with 400k downloads
Alt account vibes
but illusion where did you see empty interfaces in my bytecode analyzer im curious
And more worse, you two comparing from and to locations, no one did this before in Minecraft history, since it failes with higher tolerance and lower speeds
lets go
then use Double.compare
Still
bam
Doesn't get what I mean
???
thats just so you dont have to implement literally everything
when you override it
Just as a small update, i found out that Mythic Craft have actually got something in their in house library that can detect / "register" this sorta thing from what I can tell.
Trying to get the deets
its like an abstract class minus the class
Sending me WorldGaurd's listener ^^
tf is wrong with != or am i missing context
double != double often fails
because floating point stuff
They compare ints here so it's ok
You are removing camera from affection
isnt that unfixable
So
you two comparing from and to locations, no one did this before in Minecraft history, since it failes with higher tolerance and lower speeds
because it cant store more precise values
That comparation is just meant to disable camera and does nothing
I wasn't the one saying that shit so quit attacking me
he's comparing ints lol
not doubles
then be more precisie
ok wait how tf else are you comparing doubles
If you want to see if 2 doubles are "equal" you define an epsilon (-1E6), subtract the values and see if they're within that epsilon
why not just compare the bits
Floating point innacuracies ;)
._.
If the bits were the same then == would work directly
:|||
shouldn't those be the same across all doubles though
No
:|
Doubles are generally represented as a fraction or exponent of a weird number
ik how theyre represented
Yeah so if you have 2 numbers from different "sources" (4/2 and 1+1) they might not match
just dont see why you couldnt compare the bits, but i dont know the algorithms cpus use for arithmetic
ah
ok
so how would you do a more precise comparison
floor
Floor doubles, and compare them
epsilon
as I said like 5 times
shouldn't that be the standard algorithm in cpus then
Or idk, approximately (if that's not wrong in english
3.14159 -> 3.14000
theres no way comparisons are that unprecise
That also not needed in this situation
for such small numbers
floating point innacuracies my beloved
This is totally not spigot but is totally development
has anybody ever programmed a amx touch screen av controller
isn’t that the literal point of normalised formats
ie normalised floating point
so all values have a specific way to represent them
?nms
Hey so im sure this has been asked alot before so im sorry for repeating it but ive been looking online and i cant really find one definitive answer
When is it okay to use the keyword static? like when is it not considered static abuse
Because some stuff like constants, utility methods, and trying to replicate singleton patterns make sense
But what about other scenerios?
this might answer your question
Where do people usually store information for plugins, like additional information of players or something like that? In json files?
that entirely depends on the application, but yes thats an option
databases are also often used
What options are there too?
Configs, databases, json files?
any type of database that works good for you
i dont recommend storing data in configs like yml
json is fine imo
I usually just make an interface and impls at will
yea
Ok, then json
Kindof
But if i have multiple instances that should be sharing a variable is it valid to make it an static or should the variable be moved to another class then be accessed via DI?
Also what are the limits of constants? Like if i have a inventory with a set amount of Items in it (like a gui Menu)
Is it wrong for that to be a static/constant, since it never changes?
But the data is going to the database?
It just seems to me there is alot of, what ifs
and im not exactly sure what to do in what case 😅
Constants are immutable "simple" values whose logic won't change
I'd say an inventory would be static abuse as it's mutable and can be changed at any time
Constants are things like how many ticks in a second
Collections shouldn't be kept as static
But in short just keep asking yourself "Does this belong to the object or to the class itself"
If your collection is immutable (let's say a map for time units, or a list of all the iron tools) then it might be fine to have it as static
Basically a permanent read-only thing
?paste
just curious, would you call this static abuse @echo basalt ? https://paste.md-5.net/rituqixabe.java
That makes sense ty
Does that also apply to the first thing? Multiple instances of a class that should be sharing a variable
That's what DI is for
Unless that variable is read-only immutable type deal
Okie I thought so
this is how i used to do cooldown back when i just started, but ive never been completely sure if doing it like this was ok
Like if you don't have any context for that variable (let's say a list of iron tools) then static is fine, but if it's something a bit more specific like your main instance
Yeah it is
yeaa i thought so xd
like it uses a static map to save itself as data xD
at the time i thought it was quite smart
whyy does the static key word even exisstt
It seems so easy to abuse lmao
oh my
the static keyword is absolutely needed
well it has very good applications as well for which it must exist
Uh oh i fear i have said something
for what purposes exactly may i ask?
coding without static would be hell honestly
Your entry point
Singletons, entry points, registries, utility methods etc etc
Constants
new UtilityClass().getTicksPerSecond
Imagine the dependency injection hell
it would be kind of horrible (yet fun) to see an entire project without static
Pov: my code
bro doesn't write utils
Easy refactor
no singletons even?
that's crazy I love my singletons to death
I don't
i also never user singletons
I DI everywhere
me too, but i do write utils
Fairr
Also i was thinking about things like constants on small scale
5000 object each storing a variable that is the same will be more resource intensive than 5000 objects all accessing one variable
Unless im being dumb, which is very possible
I think I use singletons for stuff like mongodb codecs
no ur right i think
since its just a reference to the same var
might just be the same tho
I use singletons for data classes and registries mostly
Ew
data classes just make sense, you're using the data everywhere why should I pass it around to every class instead of just use the data where its needed with my singleton I (a.) know will be initialized and (b.) will always ever be one instance of it.
at that point the DI pattern becomes a burden more than anything ofc I need my data class in this class the project is working with my data
No justification you're just lazy
proper use of singletons isn't lazy
what about translations too?, it gets to the point where you're passing in things that could just be a singleton. Translations you'll only ever need one instance they'll never change
Hmm so heres a question
Is it acceptable to use a static method to get an inventory that will always be the same
Cause all the method is doing is creating a new inventory, putting items into it, then returning that inventory
And it is the same every time
That would be a form of utility, no?
Unless im mistaken, which again, i very well might be
Nah inventories are mutable
Damn really?
They're still populated in a method with context so no
static usually won't pair well with inventories mostly because of just their nature. You usally want to take a DI approach with them seeing as they are well ever changing, though 7smile7 has a good article on a good modern approach to inventories that uses a clean approach https://www.spigotmc.org/threads/a-modern-approach-to-inventory-guis.594005/
everything has context that's a moot point
certain things should just be a singleton, Databases, Translations, registries, some data classes (depending on their function)
Well damn i just got instantly called out in the first few lines of the article
Tysm for supplying this though, will definitley read
another use of static is builder and factory pattern (sometimes) though I'd argue builder pattern without static is the ugliest thing imagineable
for example my wrapper of BungeeChat component builder only has static access points so Component#of vs new ComponentBuilder
What about new ComponentBuilder().of
My mind is vaguelyy understanding this
Which is a pleasant surprise that i understand it at all
that just adds an extra step :P
I prefer my static access to Builders think it lokos better
just try it out, try to get ur mind arround it and its going to make ur life to much better then you get it 🙂
granted its kinda all preference with the builders as you don't "need" the static constructors
I mean saying this, having the handler be a singleton wouldn't be the worst idea in the world 0_0
*no
*the manager
mb mistype
oh yeah the manager definitely should be imho
There are worse approaches
but the rest of the stuff probably should stay away from it
100%
Clues in the name singleton
ANything with more than 1
you'd be hard pressed to justify a singleton gui
shouldnt be static
can't really see a use case for that even
It'd be stupid tbh
Whats the point of a manager
if your gonna fill it with singletons lmao
silly shenanigans right there
working with BungeeChat without arrays has been a pleasent experience
I removed them all 😆
real
no more arrays
rewrite Inventory's for me so we can have AnvilInventories in API thx
What should I name my NMS handle class NMS looks bad and Nms looks horrid
nMs
perfection
I think I might just do MinecraftServer or like NativeCode though I think the latter is too ambiguous
VersionHandler
smart
i ussualy just do like 1_8_R2
😄
I use reflection cause i hate those annoying names
I use reflection too :P
and I usually have multiple handler classes that all do different things like ItemHandler, InventoryHandler etc
i just do it because its startup logic so who cares
Yeah VersionItemHandler etc.
yea thats fair enough
Just takes a bit, but when everything is working it’s great
My name is usually NMSAdapter and NMSAdapterImpl
so I want to add a blocking mechanic for pvp where once you do a certain action it either greatly decreases or negates damage. Any ideas for good ways to do this, shifting seems to easy
Make them right click with good timing
I was thinking that too but fighting with fists is a big part and I don't think you can detect right clicking with an empty hand
You can if they are looking at a block or entity
But yeah not if they are clicking the air
health.setDisplayName(ChatColor.DARK_RED + "❤");```
I created a health scoreboard but it begins at 0 until the entity takes damage, how can I have it begin at player health?
@young knoll I noticed you never acknowledged the fact that I'm forcing you to redo the inventory system so we can have AnvilInventories
anvils don't have tiles
I deflect responsibility to choco
ik which is why the craftbukkit system would have to be redone to support such behaviors because rn it only supports tiles and the default case
which just reconstructs an IInventory
make a pr then
too lazy I'm shoving responsability onto coll
I'm stuck on the SignChangeEvent PR :P
like I could do Inventories
might give it another crack tonight
Crack is wack
you're wack
If I get mad I can always PR simple performance stuff :P
True this is spigot I think we should do performance detrimentz
BRO
I just found the stupidest code issue
Apparently this works
But the moment I change it to this, it loads the class prematurely and issues a noclassdeffound
yes
go figure
i mean
for the lambda expression above, it creates a separate method in your class file that has the code you have in there
for the bottom one it points directly to the class' ctor
so it needs to exist, as it is tried to be fetched eagerly
okay but what about a factory factory builder?
lgtm
my favorite FactoryFactoryBuilder
for (Team team : this.gameData.getTeams()){
// first we can check if the team already exists.
if (this.teams.containsKey(team)){
// this means the team exists.
int teamSize = this.teams.get(team).size() + 1;
if (teamSize < this.gameMode.getPlayersPerTeam()) {
// this means the team's size is still less than the gameMode's players per team.
// add them to the existing team.
this.teams.get(team).add(player.getUniqueId());
this.players.put(player.getUniqueId(), team);
Bukkit.getLogger().info(player.getName() + " got assigned to an existing team " + team.getColor());
break;
} else if (teamSize == this.gameMode.getPlayersPerTeam()) {
// this means the team's size is equal to the gameMode's players per team.
// create a new team.
this.teams.put(team, new HashSet<>());
this.teams.get(team).add(player.getUniqueId());
this.players.put(player.getUniqueId(), team);
Bukkit.getLogger().info(player.getName() + " got assigned to new team because of existing team being full " + team.getColor());
break;
}
} else {
// create a new team because one doesn't exist yet.
this.teams.put(team, new HashSet<>());
this.teams.get(team).add(player.getUniqueId());
this.players.put(player.getUniqueId(), team);
Bukkit.getLogger().info(player.getName() + " got assigned to a new team " + team.getColor());
break;
}
}
can anyone help me fix this?
everything works fine when its 1 playerPerTeam
or solo
but if team game mode
it doesnt work
ok
Bukkit.getLogger().info(player.getName() + " got assigned to a new team " + team.getColor()); prints out fine
Bukkit.getLogger().info(player.getName() + " got assigned to an existing team " + team.getColor());
this prints out fine aswell
the problem is
when creating a new team when an existing team is full
icky
fixed
Is there anyway to stop players from shift clicking items into an inventory?
i cant seem to find an event for it
InventoryClickEvent
is this a good way? (im not using the api cuz wanna learn dis)
- too lazy to setup all the modules
🙂
Look at how nms does it
They have some listener you might beable to realistically mix into
I feel like mixing best way to go here
obviously
just use remapped nms
He forgot the api existed
wait wont this not workm
wtf
ur getting nobuscated classes?
unobuscated
Can anyone help with my scoreboard please?
you just need to make a custom event and then fire it whenever a player takes fall damage
or if you just want to detect then just use the damage event
what does PacketPlayOutAdvancements consume?
I read wiki.vg and figure out that there are 3 of this
but have no idea what to put in
do you want to actually make a new event
or just detect the fall damage
then register a entitydamageevent listener
make sure its a player
and if so and the damage cause is fall damage
do whatever
well yeah it could
you could check for any damagable entities
thats why its entitydamageevent
yeah just add a new event handler
listen to entity damage event
check if its a sheep or whatever
and if its fall damage do ___
Whats the event fired when i place a block above a DIRT_PATH turning it into a DIRT?
how tf do you know how to listen to entitydamagebyentity event
but not just simply a different event
what event
never used what event
ur listening to an event
how tf you know how to listen to one event
but have dementia of how to listen to one
okay so just change what event it is
Anyone knows?
@EventHandler
public void entityDamage(EntityDamageEvent event) {
}
spoonfeed of shame
fym then
you asked me how to listen
event.getCause()
oh my lord
u ever heard of javadocs
what
so right there ur setting getting the entity
doing nothing
then returning
after doing a check
what are you . ing
what are you actually trying to do with this
im so confused
why do you just say .
im sorry but most . messages is because they are trying to reply to a message
and you doing that and not replying confounds me
faction.getEnemies().stream().map(StringUtils.capitalise(Faction::getName)).collect(Collectors.joining(", ")
How can I do this correctly
It doesnt like the StringUtils.capitalise
what are you doing
well its because StringUtils.capatalize isn't a function
StringUtils.capatalaize != Function<A, B>
compeltely different things
you can't just throw a function call inside the method to makeup for it either
How can I do this
please try javadocs next time though getCause is literally the first method thay shows up in entity damage event javadocs
yes
You can change it to map(Faction::getName).map(StringUtils::capitalize)
you need to learn how types work
why map twice that's such a waste
do it in one function
How do I do it within 1 function
It looks nicer and it’s easier to type on mobile
:P fair about hte mobile part
istg im going to stab you next . you send without replying to a message
im going to just combust now
Imma use map(Faction::getName).map(StringUtils::capitalize)
You should learn more about lambdas before using them
Do you know why your original code didn’t work?
Not really tbh
The map method takes a function like this ^
that code is inefficent and it should be obvious why
Because it’s a lambda that has an input, it require you to specify the input such as faction -> someCode
What you did didn’t provide an input for the function parameter of the map method
You tried using a method reference inside the method call
But that doesn’t work because the StringUtils::capitalize would have to be what you used
Or you can change it to faction -> StringUtils.capitalize(faction.getName())
Idk if I explained that well, let me know if you have any questions
could someone help me with this
PacketPlayOutAdvancements
I have no idea to create that packet without bugs
I have some other bad code - I want to know how to do it more efficent
int index = 0, length = results.size(), resultsPerPage = (28 - 1);
int start = index + ((page - 1) * resultsPerPage);
List<Integer> resultsForPage = new ArrayList<>();
for(int i = start; i < resultsPerPage; i++) {
resultsForPage.add(results.get(i));
}
return resultsForPage;```
whatever ur germanic heart desires
How can I iterate though an interface tho?
also lmao
never used those before lol
I'd recommend making it a Set though, if you are planning on using an "array". Or an Enum.
Cause Sets have some nice methods to work with
off-topic, but oh shit a swiftie on a development server :o
i tried to get tickets for her world tour in germany but well. getting tickets for a big concert :/
nooo
so just an array?
a few of my friends went to eras n im soo jealous lol
i feel
i don't get enums in java lmao
but well idk if a set is necessary here
it's just strings for languages. and i doubt that i will translate this into more than 3 lmao
probably german, english and french xd
They are really cool.
Basically they are just a list of predefined names, which you can then use innyour code too ensure that you don't pass a wrong/nonexistent value.
How about annotations:l?
ic, but it's about a user input in the config.yml
and enums are kinda their own type, no?
That's the good part, cause then you don't have to pass around Strings, but rather enums. Ehich means in method parameters can be set as an enum and you know what values are allowed. If a method would just take a string as an argument, then you'd probably forget which strings would be valid
And you can convert strings to enums, for example if you use the players input and then you can use the enum in your code instead of a string.
how does the conversion work?
Welp, I'm heading off now, but I really recommend reading up on enums, they are very useful in my opinion.
you really dont want to use an interface for that
an enum is the best you can go for
Either you make your own function for that, or enums have a predefined function called valueOf, I think.
Though you have to make sure that the string is the exact same to the name of the enum or it will throw an exception
second best a list, array, general collections
Set?
case sensetive?
Yes
well .toUpperCase ig
general collections, but a set doesnt give any advantage to a list or anything in this context
That's why you might have to make your own function for converting them.
ic
Fair, though it would enusure that the language can only be in there once and using HashSet you have quicker calls to "contains", but even if it's only 3 elements, that'll be negligible.
exactly. if you sort in a language twice you have other problems. and to discuss about big o notation for a <200 elements collection then have fun with a monologue
I don't, idk, a Set just "fells" right there, if a collection were to be used.
not wrong but yet redundant. i would intuitive probably also stick to a set when i somehow whyever should not use an enum
when using a command in the console, is that an instance of ConsoleCommandSender?
yeah ig i can test it once i get home. but not that necessary anyway tbh. (would be used for a safety check, but my plugin disables the execute command (by default) anyway so whatever)
You can check if the "sender" arg is an instance of "Player", if not, it was the console or a command block.
what about /execute?
Can you do shenanigans with that like using an entity or smth?
you can't use bukkit commands with /execute in any way iirc
config.yml is updated onReload right?
u sure? can't you use pluginname:command ?
I am not, hence the "iirc"
I don't think it gets registrated to Brigadier so vanilla commands don't know about it
hey, what jdk should i download to make plugins? i am using intellij
the one that supports the version your plugin will be running on
so lets say for 1.20, would i download the latest java jdk?
okay
Java 17 I think
than kyou
oh right. prettier. i wanna include prettier in the project. how do i do that?
Hello. For a multiple server communication what is the best solution (without pluginmessages). Socket or redis ? Or other ?
how do i download a sdk?
doesn't intellij have an option for that ?
its not working, keeps saying no sdk specified
no, I am sure it can download one
i think i got it to work
yeah i do download it but it still says no sdk specified its weird
it let me create a new project tho so i think it worked
If a player is hit by a player, ONLY the EntityDamageByEntityEvent is called, correct?
EntityDamageEvent is JUST non-Entity damage causes, right?
EntityDamageEvent is called, but its the same event
so its not called twice, but it is called
am I blind? where'd the git push/pull/etc buttons go in the "new" IJ GUI?
You can listen to EntityDamageEvent and then check instanceof to see which child event type it is
left side bar at the commit window
where?
I can't find the push button (except in the drop down menu)
commit and commit and push is on the bottom here
yeah but I want to push without committing anything new
ctrl + shift + k
so they jut removed that button? smh
I've always been using the dropdown
I hate the new UI, all the useful buttons are now hidden in an extra menu
nope
i love it lol
i don't mind the new menu
a lot cleaner and you still have shortcuts
not like you push every few mins
I hate change


