#help-development
1 messages · Page 389 of 1
@green prism I don't see the point of this
you're creating a copy and iterating over the copy
bro wants to make a mc rust server by asking others to make the plugins for him for free lolz u should quit its a waste of time
akex06
https://gist.github.com/clarence112/9a3e971283d7f4052a0c33f11de9b7c5 I think I can do it with this
Anyone know why I'm getting a class cast exception here?
ClassCastException: java.lang.Integer cannot be cast to java.lang.Long
Code:
if (((Integer) location.getBlockX()).longValue() != ((Long) locationJson.get("x"))) return false;?
And the locationJson.get("x") returns a long, checked that.
You can't cast Integer to long
I can't do so directly, that's why I'm using the inbuilt version of the java.lan.Integer class
They are completely different wrapper classes not related
If I create a sync bukkitrunnable in an async task in order to resynchronize some information, will that cause the async thread to hang until the first tick of that bukkitrunnable has been run?
no
how do i type that on command "hub" it switches server to lobby
my code: https://paste.md-5.net/eyadamevav.coffeescript
The home of Spigot a high performance, no lag customized CraftBukkit Minecraft server API, and BungeeCord, the cloud server proxy.
Is there a method to center text using player#sendMessage, so whatever the player Chat Options are, it will be always centered?
Centering depends on which font a player has and how his chat settings look like.
is there a better way than making 1000 bufferedreaders to read a bunch of mojang recipe files with gson? im already using a dir stream
Well yeah...
if theres no better way, ok then
Not really lol
does a remapped mojang dependency exist for 1.8.8?
since im getting this error:
org.spigotmc:spigot:jar:remapped-mojang:1.8.8-R0.1-SNAPSHOT was not found in https://oss.sonatype.org/content/groups/public/ during a previous attempt. This failure was cached in the local repository and resolution is not reattempted until the update interval of sonatype has elapsed or updates are forced
?paste
! lmao !
?1.8
Too old! (Click the link to get the exact time)
i still wanna use it tho idrc that its old
Nobody uses 1.8 anymore besides a hand full of pvp kiddies.
Support for this version was dropped years ago.
No
he's right, but to answer your question, no
Mappings were released in like 1.16 iirc
Remapped came in 1.17 iirc
^^
i dont wanna make anything pvp but i dont like the system for pve either, so is there anyway i can work around it?
You can use online libre mappings
Forge, Fabric, the like. I actually don't know if Fabric mappings were available
Did it exist 8 years ago? lol
It didn't
Then yeah, Forge/MCP mappings are your only chance
CraftBukkit mappings are incomplete
Less incomplete than CB
well i dont really NEED to use `1.8 if theres a way to work around the combat sytstem?
I honestly dont like the take where you rely on either 1.8 or 1.9+ combat.
You can be very innovative and create a fast paced combat system in the latest
version if you just think creatively.
thinking is too hard
Plugins like OldCombatMechanics and ViaBackwards exist
yea im using viabackwards but last time i used smt for old combat mechanics it messed up everything but maybe thats cus i was using the wrong plugin
also ive realised that enemies get stunned when they get hit so u cant hit them for a while, any way to change this too?
That has existed for quite a while
You can make your own plugin to remove it, if ocm can't
ocm also has a feature for that?

I want to add to my plugin that you dont have to type /"itemName" but /"pluginName" "itemName"
how do i do that?
Create a command /pluginName itemName ?
Register a conmand called pluginName and then create arguments
yes, right now i have a list of commands that you can type to get different items, but i'd like to sum it up to "undercommands"
sub commands
That what args parameter is used inside onCommand method
Hey guys
To get each NMS class for each version I need to run buildtools with --remapped for each version I need?
Yes
Write a quick script
ChatGPT does have a specialt in doing that
But it's fine
Now last questions, Do the R1, R2 mean .1 .2?
not always
iirc the number changes when theres internal changes or protocol changes, no idea what versions change and dont. Best bet to just check what https://github.com/JEFF-Media-GbR/JeffLib uses
Fair, ty
What event is left click event?
i dont think its working
did you register the event
yes
?paste the code
what happened to Entity.setLocation(loc);
https://hub.spigotmc.org/javadocs/spigot/org/bukkit/entity/Entity.html#teleport(org.bukkit.Location)
declaration: package: org.bukkit.entity, interface: Entity
In nms?
yea
What version
1.19.3
add debug stuff
i have a similar thing with right click and thats working
https://paste.md-5.net/oxebohutag.py
it's setPos I believe
Then teleport them
Just add all versions you need to this list:
@ECHO OFF
set versions=1.19 1.19.1 1.19.2
for %%x in (%versions%) do java -jar ./BuildTools.jar --remapped --rev %%x
@PAUSE
im trying to teleport an armor stand with a name above an entity but when i do so the tag is just at the bottom of the entity
Don't teleport that it will look bad
You need to make the nametag an entity riding the player
yea i did that but when u go in the water it will kick off the armorstand
So I have to constantly switch
and also the name tag will be inside the head of the entity so it has to be located higher
Packets?
i honestly have no idea how
combine with 7Smile&'s code ```bat
@echo off
mkdir BuildTools
cd BuildTools
SET JAVA_CURRENT="C:\Program Files\Eclipse Adoptium\jdk-19.0.1.10-hotspot\bin\java.exe"
SET JAVA_8="C:\Program Files\AdoptOpenJDK\jdk-8.0.252.09-hotspot\bin\java.exe"
SET BUILDTOOLS_URL="https://hub.spigotmc.org/jenkins/job/BuildTools/lastSuccessfulBuild/artifact/target/BuildTools.jar"
curl -z BuildTools.jar -o BuildTools.jar %BUILDTOOLS_URL%
SET /p Input=Enter the version: || set Input=latest
for /f "tokens=1,2,3 delims=." %%a in ("%input%") do set major=%%a& set minor=%%b& set revision=%%c
IF "%major%"=="latest" (
SET cmd=%JAVA_CURRENT%
GOTO execute
)
IF "%major%"=="1" (
IF %minor% GEQ 17 SET cmd=%JAVA_CURRENT%
IF %minor% LEQ 16 SET cmd=%JAVA_8%
)
:execute
%cmd% -jar BuildTools.jar --generate-source --generate-docs --remapped --output-dir .. --rev %Input%
cd ..
pause```
Cant you just use 17 and build every version with that? It should be able to build older versions as well
I see
Nah it can't
There it i. seems to work
above code will select the correct java version
Well Elgarl just gave you a gem there
Which ones do I install?
you combine both
you need two java 8 and whatever current build
Ok
how could i do that with packets?
Man I still hate GEQ and LEQ
Why can't they be normal and just use >= and <=?
Almost done. I just need to write some generator machines and then i can ship it 
nice
Im thinking solar pannel and furnace generator for now...
For any1 else so its easier to know what the issue is:
How can i prevent a passenger (armor stand) to get off when the entity goes in water.
slimefun 4 now
Holy... Slimefun is still actively developed.
its so badly coded
I made sure to make this plugin scalable and pretty efficient
does it have an api or have a way to determine its own blocks/items/etc
can some one help me with this?
Yes it has a way of registering external machines with only 2 classes.
I plan on writing different modules for this plugin so that i can add
a batch of machines with a theme (eg nuclear generators will be an addon)
new slimefun confirmed
im guessing it adds metadata? or pdc to what possible so other plugins could interact with those blocks knowing its urs
It uses TileStates as machine bases so most of it is stored in the PDC of the base block.
And there is a simple method to get from Block to IMachine
fun
🥲
Unloading and loading a world is done sync. I have had the same issue while writing a SkyBlock server which used multiple worlds
for multiple islands. I ended up actually forking the server because the world loading is hard coded on the main thread.
so what i supposed to do?
I whish there was a Bukkit.createWorldAsync() method which returns a Future<World> but thats sadly not a thing
Get an NVMe SSD for your server XD
Let me take a look at your code again. Maybe there is something you can improve on still.
engrish
when the server stopped i can remove the world folder, and load it when the player s votes to the selected map, is this will fix the issue?
Ok im seeing a lot of IO on the main thread from your side. That def does not help and will lag out the server.
this code just check the socket if not connected to reconnect again
thats the code
public void checkSocket() {
if (socket == null || !socket.isActive() || !socket.connected()) {
socketConnect(null);
}
}
ohhh
All of this should not be done there
i can make new thread and put the code on it, or this will destroy the server?
You cant run any bukkit api from another thread. So for example loading the chunk will break.
omg, so what i should to do? i'm confused tbh xd
@lost matrix i have a socket server, if i can let the socket server delete the files that will be ok ?
Run your IO on a different thread and you bukkit code on the main thread...
hmm
if i did this?
public synchronized boolean cloneUWU() {
try {
new Thread(() -> {
try {
FileUtils.copyDirectory(new File("/minecraft/servers/SurvivalGames/maps/" + this.getMapName()), new File(this.getMapName()));
} catch (Exception e) {}
}).run();
World world = Bukkit.createWorld(new WorldCreator(this.getMapName()));
if(world != null) {
world.getSpawnLocation().getChunk().load();
}
return world != null;
} catch (Exception e) {
return false;
}
}
I dont know what that is supposed to mean but it sounds alarming
This will break everything. You need to wait until the world is deleted before you create a new one.
sure, the world reload and copy the folder after the players vote (after 4 minutes)
Also: You are hiding your exceptions. Never do that.
error handling:
i'm gonna try to let the socket do the files things
and send a socket message to the server to load the world, i guess this will be smooth
cuz java sucks
if i can't did this, i will try to make the files things in other thread as you said
Those two things run in parallel (so at the same time)
This is a horrible idea
i know, this is an example
wait why? 😦
What does that even mean the socket does "the file things"
A socket is used for communication. I dont see why it should
touch any Files at all.
them making it in thread, load the world files when the vote finished, when the game will be started before like some seconds load the world. i guess this will be smooth as it will be 1 map loaded only
Calling run on a thread :(
lol i even missed that
It's not in parallel
don't say its a bad thing 🥲
there's a start method instead of run should i use it?
copying the world folder in it will be a good idea? cuz java works like sh**
Not sure if you need to await the result
Go program your plugins in python then or whatever
smh
lol
You're recreating the map ig so don't you need to wait for the current map to get deleted?
Reading this on a phone goes brr
there's a 4 minutes delay to recreating the map
so there's no way the world not deleted
i'm gonna try a scheduler then the thread, but i have to learn some java first 🥲
but yeah thanks you guys *flower*
I want cookies not flowers
then here you go 🍪
Challenge accepted, xDD
There is actually already a framework for that
I'm not experienced at all in this, but are there ways of adding "fake" players with custom AI (just attacking, jumping/following around other players, simple stuff) ?
I think it's possible, but I can't find anything online about how to do this. Could someone refer me to something please?
Oh, who would've guessed...
EntityPlayer
This is very hard to achieve
I'm not trying to do something overly complex, just have some "bots" that jump around and attack you if you're near them
Thats very complex
Simplest approach:
Write custom AI entities and disguise them using LibsDisguises
I have problems remapping my nms. I ran the buildtools with java -jar BuildTools.jar --rev 1.19.2 --remapped and this is my pom.xml https://paste.md-5.net/irojajemoy.xml as soon as I added the classifier and the plugin in my pom.xml some of the nms classes like WorldServer just vanished. Any ideas why?
is there a way to get the latest 1.version.patch number
im guessing world server is spigot mappings
Sorry, I don't know what you mean by that
with just org.spigot:spigot:version you use the obsfucated minecraft server code, class names are renamed so you dont have stuff like new rkab(...), using remapped its the class, field, etc names that are used unobsfucated in mojang code
?nms
Sorry, I sent the wrong pom.xml
You are also building a spigot 1.19.2 plugin against java 8, it requires 16? or 17 I forget which
what i said still applies
without the classifer its spigot mappings and obsfucated stuff
I do have the classifier though
wrong java version
Since with mojang mappings EntityPlayer doesnt exist anymore,
how do i create an npc?
yeah
thats why the field changes
because you are now using the real class names, not spigot mappings
I just updated that
EntityPlayer is now ServerPlayer or somethign like that
Ah ok, is there some sort of translöation on the internet?
yes but it's really easy to find the new classes,
whats the easiest way?
Most IDE's will auto suggest
its a bit laggy but this https://nms.screamingsandals.org/comparison/mojang-to-obfuscated-to-spigot.html
most stuff on 1.18.2 or higher stays the same iirc
yep, just a few packet name changes
ohh okay thanks
i can just ctrl + f and look it up
got it thx
x/z
How do I create a FakePlayer using nms? Every resource or thread I see uses
new EntityPlayer(server, world, new GameProfile(target.getUniqueId(), target.getName()), new PlayerInteractManager(world));
But if I try to do that
ServerPlayer npc = new ServerPlayer(server, world, new GameProfile(p.getUniqueId(), p.getName()), null);
It says that the last arg needs to be a ProfilePublicKey
never heard of the class FakePlayer
Oh no.... I did rm -rf * in the wrong ssh terminal
Did it in the home directory aswell
You can pass null for ProfilePublicKey Unless it's an actual player, then you need their actual key
I've done that, but it doesn't spawn a player
for an NPC you need to extend ServerPlayer in your own class so you can override the connection
if you don;t block outgoing packets to the NPC you will crash yoru server
So I would have to create my own NPC class that extends ServerPlayer
yes
a good resource to get started, BUT read it carefully https://www.spigotmc.org/threads/nms-serverplayer-entityplayer-for-the-1-17-1-18-mojang-mappings-with-fall-damage-and-knockback.551281/
ok, thank you very much
I've got 3 jars, 1.8 1,7 1.16 since i depend on all 3 the only issue is when I call Bukkit.getOnlinePlayers() I get this
I’ve asked this before, but I’m asking again because I’d like to hear more opinions. If I’m writing a custom system for a server, should I divide the different parts of the server such as rank management, custom NPCs, etc, into different plugins, then make them communicate with each other? I’m new
No idea if this is the right place to ask but, I'm trying to take the behavior of foxes and apply them to tamed and named cats. How do I do this?
I mean like, so that they roam around and stuff
if its for nms you should be have modules for each version, and depend on the lowest version you support for the core
and dont use thread.sleep
Use NMS to create a custom cat and add the AI goals to achieve what you're trying to do. You can look at the Fox class to see what you need to add.
it doesnt error for him
if you do it wrong you will just lag the server
Thank you!
Honestly it's really up to you, whichever is easiest for you to understand would be the way to go. I don't really think there's a right or wrong way to do that.
Thanks for the response. I’d probably make it all one plugin then, as the different parts are all very interconnected
how can I display Objective in PLAYER_LIST and BELOW_NAME at same time?
<html>Overload resolution ambiguity:<br/>public open fun getOnlinePlayers(): Array<(out) Player!>! defined in org.bukkit.Bukkit<br/>public open fun getOnlinePlayers(): (MutableCollection<out Player!>..Collection<Player!>?) defined in org.bukkit.Bukkit
kotlin 🤡
follow up on this, it works. Withh skins, except the second layer... how do i render this too?
i tried using this as it said in the comments of a video
npc.getEntityData().set(new EntityDataAccessor<>(16, EntityDataSerializers.BYTE), (byte)127);
but when i do it gives me an error
java.lang.ClassCastException: class java.lang.Byte cannot be cast to class java.lang.Integer (java.lang.Byte and java.lang.Integer are in module java.base of loader 'bootstrap')
what is an effective and efficient way to store player data for a lot of players
would it be best to use one big config file, or lots of per-player config files, or a database, or what (and why)
A database, because databases are built for storing data it's in the name
Ofcourse I'd cache as well to make data fetch times much faster if the data is being constantly used
yaml config stored on players pdc with more pdc 
Serialize a json file in player PDC instead
🔥🔥🔥🔥
json is confusing imho
Your confusing
DB if you need decentralized storage. Eg if the data needs to be accessed by multiple servers.
If you have a file setup then use one file per player in the format <UUID>.json or <UUID>.yml
wait untill you end up with that 1 server with 25953 players all saving data
I'll hedge bets that'll never happen 😂
can we access players pdc async?
I doubt it, but who knows
No
Unless you are reading directly from the players file
I dont need decentralized storage.
Will there be a significant performance difference between using per-player config files and using databases?
Only if you exceed thousands of players. Which less than 0.1% of servers do. So dont worry about that for now.
Does this look cool or what
Alright. So per-player config files should be fine since im not expecting to exceed thousands of players anytime soon, though I imagine that per-player configs should be fine for a few hundred players (I currently get up to 200 players though increasing)
That. Looks. Cool.
Yeah you should be fine
Wtf bruh that's dope
thats insane
are the nametags and heads just invisable armor stands or what?
Yeah
I am excited for those new fucking entities coming in 1.20
Omfg you know ima rave for that shit
Yeah those entities look pretty useful
Should see some stuff already done with them with just command blocks
theyre definately pretty cool
though i still dont use new versions in servers because the performance is horrible (in comparason to older game versions)
That's a given more stuff more hardware requirements
No.
Don't message me out of the blue about plugin ideas out of the blue, unless you are rather certain that I'm the only one really suitable for the task (however I am quite certain that you don't know my strong suits and thus it is almost certain that I am not the only one capable of doing it).
yeah ofcourse. though for some servers the performance difference isnt worth it for the features, while for stuff like survival based servers its of course worth
ofc its opinion
https://youtu.be/Y4FnAFdry2Q example use
Hey everyone! I wasn't too invested in the recent Minecraft snapshots that had been releasing until I saw these new entities. The possibilities are endless with the interactions and block display :D That being said, the first thing I decided to make with them was a piano.
Sorry the video is very short, I wanted to get this out before the update...
Even though this is basic asf
They've been messaging every frequent member here to make free plugins for them
They also pinged almost every booster
oh ive seen that vid on minestom dc
Yeah - honestly at some point there should be a voteban command
minecraft:interaction huh
Where's the democracy when you need it?
You are not the only one that gets DM spammed...
This is why I have my dms off 
They are always too lazy to friend request
Those who actually want business will care enough to friend you
I have never seen people that really want buisness
The bots have started to friend first :c
i only get friend requests from people that dont respond after that \💀
Same ngl
Perhaps back in my bukkit plugin development hayday - but these days there is noone DMing me directly for reasons that are justifyable
Wait you can warp them? Ok this changes everything. I thought you could only change the scale (which was insane already)
:P they are a creators dream
Looks like inmersive engeeniering, i pretty love that mod its fucking amazing
org.yaml.snakeyaml.error.YAMLException: The incoming YAML document exceeds the limit: 3145728 code points.
:(
Uhm... F?
Top 10 reasons of not using yaml as storage!!!
🤣
Can you help me please?
StackTrace
Caused by: java.lang.NullPointerException: Cannot invoke "it.mikeslab.labutil.inventories.annotations.ClickEvent.action()" because the return value of "java.lang.reflect.Method.getAnnotation(java.lang.Class)" is null
Library Class Involved:
https://paste.md-5.net/hucosoqoru.php
Class using that library and that class:
https://paste.md-5.net/cawecamida.java
Context:
Using my CustomGUI API. I've got an error from using that Annotation-Action click association.
Where is the InventoryClickEvent Event?:
https://paste.md-5.net/yoqejokaga.cs
?npe
The NullPointerException, (commonly referred to as NPE), is thrown in the following cases, but not sealed to: 1. null is passed into a method or constructor which does not allow it; 2. When trying to access a field on an object pointing to null; 3. Casting null to a primitive. See https://stackoverflow.com/a/3988794/17047120 for information on how to debug NPEs.
I didn't feel like the headache SQLite is going to bring with itself and thought that YAML would do just fine for a dump to disk. Seems like it doesn't.
I asked that because I don't know where I have been wrong
Something is trying to reflect an annotation that is not present on runtime.
That why:
Yaml -> Meant only for configurations
Json -> Meant for data structuring and storaging
But ofc you can then switch between Json, SQLite, H2
Also something i ask too much, is why the fuck they ddint create something like SQlite meant for Json storage 🤔
No sense, the annotation is real
@ClickEvent(action = "BUY")
public void buyClick(InventoryClickEvent event) {
ShopUtils sellUtils = plugin.getShopUtils();
Player player = (Player) event.getWhoClicked();
Component result = sellUtils.buyItem(player, Buyable.ARMOR, 1, event.getSlot());
plugin.getAudience().player(player).sendMessage(result);
}
@ClickEvent(action = "CLOSE")
public void closeClick(InventoryClickEvent event) {
ShopUtils sellUtils = plugin.getShopUtils();
}
Please, help me... I'm going crazy
The only reason it cannot handle big files is because it's stupid spec makes the parser end up as such a complicated state machine that it would probably take forever to parse big files and they want to sweep that under the rug.
Talking about what format?
Yaml
yeah, as i said Yaml must not be used for storage
Its not designed for that, that why Json exists
Did you made own observer?
That's a very, very weak reason.
saw that yesterday
Bruh. Observer is pattern wich mean game events.
No, look online its has an exaplanation
Its not his library
Oh
Wdym? LabUtil is mine
Makes sense
I seen that but didnt want to say it
I have seen that guy doing the same things for some people 💀
But idk so far its not my problem so i just blocked him on the momment i was told hahaha
Which line throws your exception?
Here i suppose
public Consumer<InventoryClickEvent> loadClickEvent() {
return (e) -> {
if(objectContent.isEmpty()) return;
if(inventory.getItems().get(e.getSlot()) == null) return;
if(inventory.getItems().get(e.getSlot()).getValue() == null) return;
String elementAction = inventory.getItems().get(e.getSlot()).getValue();
objectContent.keySet().stream()
.filter(obj -> objectContent.get(obj).getKey().equals(name))
.forEach(obj -> objectContent.get(obj).getValue().stream()
.filter(method -> method.getAnnotation(ClickEvent.class).action().equals(elementAction)) //This line
.forEach(method -> {
try {
method.invoke(obj, e);
} catch (Exception exception) {
exception.printStackTrace();
}
}));
};
}
}
```java
Are you talking of me?
👌
What happened to your previous filter?
So far, why dont you use Spigot events-driven system?
It looked more robust
Spigot already has implemented an EventBus, which allow you to create custom event and listening
It gives me no stack trace
At least this line gives me a giant error:
.filter(method -> method.getAnnotation(ClickEvent.class).action().equals(elementAction)) //This line
Sorry, I forgot to say that
https://paste.gg/p/anonymous/f69075fb207c41549ba4a4254b8b8a77
My plugin is making this error. Line 38 is ```java
task.cancel();
```java
for (BukkitTask task : playerAndTasks.get(player.getUniqueId())) {
task.cancel();
}
There are justifiable reasons why one might use their own
ik, also spigot event bus is really weird coded, it can be reduced to few classes
Well your first filter was correct. If you dont see any method invocations afterwards then it means
that your reflective scraping did not fetch any methods with the right annotations.
Try getDeclaredMethods() instead of getMethods()
PS: You approach will have a horrible performance.
Idk
oh i hate that you have to put try catch in a lambda instead of giving the exception to the outer method signature
Sneaky throws
lombok 🤡
💀
Trying to render the second layer of a skin on an NPC with this code
npc.getEntityData().set(new EntityDataAccessor<>(16, EntityDataSerializers.BYTE), (byte)127);
but when i try to im getting this error:
java.lang.ClassCastException: class java.lang.Byte cannot be cast to class java.lang.Integer (java.lang.Byte and java.lang.Integer are in module java.base of loader 'bootstrap')
When i try use
EntityDataSerializers.INT), 127
it just doesnt work
You need to use the wrapper class
oh i hate that crap
Byte
What yo have against json simple apart from that its ancient and sucks?
i mean that sounds like a good reason to not use it
idk the moment i start using gson, its for using the reflection part, not (de)serializing manually
but i switched now anywyas
i should learn json
Ye i was trying to be a bit sarcastic :>
always fun when gson doesnt know how to deserialize smth
Agree with you, why dont they already make a SneakyThrow internally
trying to write a recipe loader that loads the clients recipes into their java object 💀
If I were to start that library from scratch, what would you recommend I do to optimize things?
The idea was to register listeners (one for each inventory registered) and then work with annotations to associate events with a method.
Also, instead of working with slots, work with actions: associate an action to each CustomItem obtained from the config, which will then be checked on click and invoke the relative method.
going kinda brr, i need 1000 bufferedreaders for that

how does mc even has 1000 recipes
Lol
Well, sneaky throw is heavily avoided because it just does that; sneaky throws
Use MethodHandles instead of relfect.Method. On that note: A Benchmark i did yesterday for measuring how expensive each
method call is:
Benchmark Mode Cnt Score Error Units
ReflectionBenchmark.callMethodPublic avgt 5 0,987 ± 0,003 ns/op
ReflectionBenchmark.handleMethodPrivate avgt 5 3,851 ± 0,006 ns/op
ReflectionBenchmark.handleMethodPublic avgt 5 3,908 ± 0,210 ns/op
ReflectionBenchmark.reflectMethodPrivate avgt 5 16,220 ± 1,851 ns/op
ReflectionBenchmark.reflectMethodPublic avgt 5 15,788 ± 0,993 ns/op
lowest score is best right
how would i do that?
me and jmh are no good friends
In that case they uses that they must know that all method handles aren’t necessarily more performant
16ms!?!?!?
Byte.valueOf() for example
lol, no
Like if you unreflect a reflective object to a method handle that object iirc will invoke slower as it delegates to reflective invocation
They cane make something like this:
getExecutor().execute(() -> {}).catch(ex -> logger.severe(ex.getMessage()));
that takes in either a bye or a string as argument tho
thats js my man
If it is less than 16ms... Where is the problem?
I mean yeah, but thats really good, Java should implement it
cuz it adds up
Generally, you will want to deal with common errors a bit more elegantly
But ye works
Do you even Java?
honestly ive never worked with bytes
gtg walk my doggo
show
a byte is just a smaller and more annoying int
Him scared on new years eve so i got him some mufflers
LOL
🥲
man listenin' spotify
whats he listening to
if you want to access the main class instance from a different class, is there any difference between making a static method which returns the instance and making a variable from that in other classes, and making a static variable and setting that to the instance in onEnable()
?di
Guide to dependency injection: https://www.spigotmc.org/wiki/using-dependency-injection/
di where you can
yeah in every class
and about 5 less in the main class
does
Integer.byteValue() == (byte) int
I would hope so
if thats an issue lomboks @graceful fractalquiredArgsConstructor m ight help you
my bow aint shooting
https://paste.md-5.net/zefedumawu.cs
nah fr skyblock,
Did you register the class?
yes
its more like why isnt a static accessor for your plugin not good
debug statements
Static cringe
wdym
Agree
any1 else that can help me with that is not walking their dog?
its literally one variable for something that you know can only be one of
The best practice is to pass the instance, but a nooby singleton is fine also
I do not advice exposing a public variable in any sort of weird way, that’ll make ur code hard to maintain rather rapidly
if you wanna use a static variable or function I would say it makes the most sense for a plugin instance
what makes something a "best practice"
is there a difference in litterally anything when using it?
what people think is better combined with what the language says is better
Well there turns out to that singletons are evil in excessive usage
ugh int count = Optional.ofNullable(obj.get("count")).map(JsonElement::getAsInt).orElse(0);
yes thats why the reccomendation is to just not use it at all if it can be prevented
I most used service manager instead.
but like, to a certain point I think its fine
I dont understand why this is an error. Can someone help?
im missing let count = obj.get("count")?.getAsInt() || 0
are you missing a constructor
hover over it
Singletons can be fine, but you have to really consider the scope in which the singleton is going to be contained within to avoid problems later
^^
also how am i even getting this error??? nowhere am i casting a byte to an integer?
Then you saying that my method looks like JS!!
smh
forgot a listener
sorry, could you explain this further?
Its a viable option, but for just passing an instance of your own to one of your own components, services manager may be a bit much
That i wanted to say😂
could also do it like this but that looks awful
Totally agreeed
Omg ‘tis the mighty Conclure 😱
No
we are choosing to ignore the fact its a matching pfp at this time
You have to consider concurrency, and how your abstraction hierarchy is going to look like.
he says with the emo anime pfp
mfs Exception in thread "main" java.lang.RuntimeException: Failed to invoke constructor 'net.minestom.server.network.packet.server.play.DeclareRecipesPacket$DeclaredShapedCraftingRecipe(String, int, int, String, List, ItemStack)' with args [null, 0, 0, boat, null, ItemStackImpl[material=minecraft:air, amount=1, meta={}]]
null
🥲
conclure
yes I agree, and with a plugin instance I would argue that the scope would be the whole plugin so then it would be fine to just use a static thing
whos it matching with
blob, so from my perspective I choose singleton if I want to lazily get something
Else it doesn’t make sense to choose a singleton
who else has no clue what they aare doing
i guess thats another way of putting it
My “emo” gf suppose lol
smh
cool, new error:
[19:17:22] [Netty Server IO #2/ERROR]: Error receiving packet 78
java.lang.NullPointerException: Cannot invoke "java.util.List.iterator()" because "var0" is null
what is a real dev
And if the singleton is lazy (which it likely is going to be) then you have to care about there only being one instance, which becomes a bit more crucial to properly think about when this singleton is used in multiple threads
Else singletons are bad because they hide the fact they components depend on them, they become tightly coupled to components that depend on them
someone that doesnt go outside, no significant other etc etc
Since you for instance never pass a singleton to a constructor, we all can agree that it wouldn’t make much sense, thus normal dependency injection should be used rather
then I know no fake devs
just use kotlin smh val count = obj.get("count")?.getAsInt()
class Singleton{
//with methods and stuff
}
record Dependence(Singleton singleton){}
//you never (almost) see this
new Dependence(Singleton.getInstance());
for example, this is what i did in a previous plugin i made
public final class FastLegacyCrystals extends JavaPlugin {
public static Plugin plugin;
@Override
public void onLoad() {
plugin = this;
would something like that work fine (i mean it worked fine)
exactly cuz tehre is reason to
That public there is a bit meh
It goes against the principle of that you should write your code defensively to avoid future misinputs that may be written by either you, or other contributors
Stop abusing static shity getInstance() and start using Di 🤣
this is a 100% lazy way to do it but i never saw an issue with it because it worked
other than principles and shit
its literally not abusing
It scales badly with a software system?
its literally one static function for the central object of the whole plugin, i.e. the plugin instance
Bruh giving main plugin class is bad practice.
Anyone who has worked on a software infrastructure with more than a million lines of code knows how it feels like when those getInstances are insinuated everywhere.
Yes, you should give a proper name, most the time <namePlugin>
I mean the only danger is you need to watch out that it doesnt grow out of control and use it in places where it isnt supposed to be used
would you mind to elaborate
how does it scales badly
Your software system becomes a spaghetti and a mess if let’s say you decide to use a singleton for every middle layered level component
and besides, the result is already from a singleton thanks to bukkit
For instance, the lowest level components are going to end up hiding their dependence on those middle leveled components
using singleton for class which is and can only be singleton scales to spaghetti code ?
yes I agree with you conclure, but like I said I think its an acceptable use in this case
Well, in either case, you shouldn’t ever have to depend on your main plugin instance
Its the top level class of your system
That is a violation of abstraction technically
having abstraction on places it doesn't have to exist >>
then di just hides that fact by making it seem like its supposed to belong in your lower classes
lets just use hungarian notations
Use a CDI framework which figures out in which order to inject the dependencies 😄
Mye
is there a difference between
public static Plugin getinstanceorsomethingidk(){
return this;
and
private Plugin plugin;
@Override
public void onEnableOrOnLoadidkthedifference(){
plugin = this;
public static Plugin getinstanceorsomethingidk(){
return plugin;
and
public static Plugin plugin;
@Override
public void onEnableOrOnLoadidkthedifference(){
plugin = this;
(refer directly to the static plugin variable in other classes)
Guice and dagger are still fine I suppose
Use instance injection.
Never static
y
But yes its incredibly annoying finding out dependencies if you have the singleton pattern everywhere
*But you can battle a lot of problems with lazy references
what is SOLID?
some words people said some time ago
Okay, maybe if you create a little hobby project for the cause, practicing whatever principles you like may be fine then
Stupid old legacy idiom (against) deprecation
btw whats the difference between onload and onenable
onLoad is called way earlier
onLoad is before onEnable
yeah but ig you want to maintain an stable and big software, making it able to scale easly you must use DI
onLoads gets called when the plugin loads and onEnable gets called when the plugin is enabled
Like almost as soon as your plugin constructor is invoked
so in what cases would that be needed?
not many
World generation iirc
Providing services for RegisteredServiceProviders
*for example
so are you also saying that you should never use static?
Velocity be like **ProxyEnableEvent ** 🤢
Static is meant for utility methods
static and singleton are not synonymous
true
Static should be used for stateless designs ideally
okay makes sense
Was about to point that out
Factory methods, utility functions, helper methods, nested builder classes etc
If you dont combine static and final then you are probably doing something wrong
ehhhh il probably keep setting a static variable to plugin instance in onenable until it breaks something
yeah I guess the singleton is just implemented using static since thats the easiest way
Honestly this is fine
Ye, I mean the canonical pattern of singleton doesnt talk at all about static
It just says like, have one instance and make damn sure it has a global access point
guys I have this method here and I want to know if there is an app or webiste that can draw me this I am tired of opening mc everytime
for (int iteration = 0; iteration < 5; iteration++) {
double angle = 72.0D * iteration;
double nextAngle = 72.0D * (iteration + 2);
angle = Math.toRadians(angle);
nextAngle = Math.toRadians(nextAngle);
double x = Math.cos(angle) * 3.5D;
double z = Math.sin(angle) * 3.5D;
double x2 = Math.cos(nextAngle) * 3.5D;
double z2 = Math.sin(nextAngle) * 3.5D;
double deltaX = x2 - x;
double deltaZ = z2 - z;
double distance = Math.sqrt((deltaX - x) * (deltaX - x) + (deltaZ - z) * (deltaZ - z)) * 0.11D;
for (double d = 0.0D; d < distance - 0.1D; d += 0.02D) {
loc.add(x + deltaX * d, 0.0D, z + deltaZ * d);
MathParticles.spawnParticle(p.getWorld(), pe, loc, rgb1, rgb2, rgb3);
loc.subtract(x + deltaX * d, 0.0D, z + deltaZ * d);
}
}```
?codeblock
You can use the discord code block format to display code or just text in a more pleasing way:
```java
public class MyPlugin extends JavaPlugin {
@Override
public void onEnable() {
}
}```
Becomes:
public class MyPlugin extends JavaPlugin {
@Override
public void onEnable() {
}
}```
is it possible for players to join the server before onEnable? (assuming im not using reload or a plugin reload plugin or anything weird like that)
Might be drawable with desmos
I mean for my accessor I just use return getPlugin(MyPlugin.class); xD
Nah
Altho assuming you do cache that
who, me?
Ye
no, they cant, because plugins are first loaded and/or enabled, finally bind to the address and port
I guess so
thanks
well I dont want to copy paste 1000 number
np, if need smth else, just ask here
okay I cached it xD
Nice
making my plugin better 1 cache at a time

Oh oh he is gonna have a weird problem, learn about cache invalidation soon and then stop caching again.
nah
As a wise man once said, cache the cache
I just wont notice it until its too late 🤷
Java GC is kinda epic when it comes to invalidation and cleaning up tho, so dw bout it too much
Can I store inventory data inside a Custom Holder assigned to the inventory?
Ye you can
Ty
Nothing’s technically preventing you from it
CustomHolder holder = (CustomHolder) inventory.getInventoryHolder();
right?
iirc its just getHolder()
What happens if I call Runtime.getRuntime().gc() every tick?
But yes
Why can we have this but custom Predicate<ItemStack> recipe choices are "too leaky"
Nothing
Most jvms have that disabled
(Like server owners disable it with a flag)
iirc its disabled in aikars flags, so hence why
If it didn't disabled 🤔
Then you gonna tank your performance big time, thats all
How would I remove a FakePlayer from the tablist?
Its like asking “Hi GC, please for the sake of our beloved god, I hereby inquire you to collect my dirty garbage as soon as your possibly can work your ass off, thanks”
And then jvm is probably gonna invoke a sweep relatively soon
so me?
Ye you definitely should touch some grass
nah man
Send this packet:
https://wiki.vg/Protocol#Player_Info_Remove
Been working on that math expression validator for way too long I reckon
I mean it does
sorry for late af reply https://paste.md-5.net/aqujupapuw.md
heh what math expression parser?
But the jvm will take those calls into account
yeah just asks the GC
i got one push i gotta do and that basically completes my current goals
pretty ironic lol
Ye lol
someone even asked me to publish it on a projects showcase thing 💀
if they want that ig
smile are you there?
Yeah
@EventHandler
public void onClick(InventoryClickEvent event) {
if(event.getClickedInventory() == null) return;
if(event.getClickedInventory().getHolder() == null) return;
if(!(event.getClickedInventory().getHolder() instanceof Holder)) return;
Holder holder = (Holder) event.getClickedInventory().getHolder();
CustomInventory inventory = identifyInventory(holder);
if(inventory == null) return;
event.setCancelled(true);
int slot = event.getSlot();
String action = (inventory.getItems().get(slot).getValue() + "").toLowerCase();
if(action.equals("")) return;
Object listenerInstance = listeners.get(inventory.getName()).getKey();
try {
MethodAccessUtil.invokeMethod(listenerInstance, action, event);
} catch (Throwable e) {
throw new RuntimeException(e);
}
}
MethodAccessUtil:
https://paste.md-5.net/vodayitepo.java
Smth like this?
Lmao
always fun when i have an exception on a line that doesnt exist
Why hard working, when you can simply use spigot EventBus. Idk its up to you, just being curious
funniest thing i saw today was ConstructorConstructor#construct in gson
This will completely tank performance. You need to cache your MethodHandles. The actual lookup is whats expensive.
Also have you seen they shity conventions? They follow C# conventions
oh im touchin' grass tomorrow
But yes something like that
From bad to worse
what c# conventions
Make own observer.
1m
I don't understand what you're talking about.
and Im also tired af
Make own event system
lol
Ye
overwrite Bukkit's classes?
the whole point of the underscore prefix is to not call "this" but yet they do 💀
starting from packets, ending with gui custom clicks?
You should not use inventory names for anything. Especially not as a key for storage.
probably decompiled
Ppl gonna register it to your plugin
There can be two inventories open with the same name which breaks your approach.
inventory names never change their value
it's like an ID (it's not the displayName)
How does that help here? Whats wrong with using spigots event system as a backend
oh wait
What can I do about that?
Compare the inventory objects, thats the correct way
What is your "action" String representing?
title: <blue>Shop!
size: 27
filler: BLACK_STAINED_GLASS_PANE
items:
12:
material: DIAMOND_HELMET
customModelData: 10000
displayName: "<blue>Armors Shop"
action: ARMORS_SHOP
lore:
- "<gray>Click to open <blue>Armors Shop</blue>!"
13:
material: PLAYER_HEAD
texture: d831830a7bd3b1ab05beb98dc2f9fc5ea550b3cf649fd94d483da7cd39f7c063
displayName: "<blue>Exchanger Shop"
action: EXCHANGER_SHOP
lore:
- "<gray>Click to open <blue>Exchanger Shop</blue>!"
14:
material: DIAMOND_HELMET
customModelData: 10000
displayName: "<blue>Weapons Shop"
action: WEAPONS_SHOP
lore:
- "<gray>Click to open <blue>Weapons Shop</blue>!"
It's something to replace more easily the "ClickableSlot" thing
It will be easier to distinguish and only the list of objects registered on the plugin will be used.
Mh, well, I don't know
seems pretty heavy
Thats for your .equals() implementation to decide
InventoryHolder is fine in most cases but ye comparing the objects is better
Be like:
class MenuListener implements Listener {
MenuHandler handler;
onInventoryOpen(InventoryOpenEvent event) {
Player player = (Player) event.getPlayer();
Optional<Menu> menu = handler.getMenu(event.getViews().getTopInventory());
if (!menu.isPresent()) return;
MenuEvent open = new MenuOpenEvent(player, menu.get());
Bukkit.getPluginManager().callEvent(open);
event.setCancelled(open.isCancelled());
}
}
class MenuOpenEvent extends MenuEvent {
final HandlerList handlers = new HandlerList();
public MenuOpenEvent(Player player, Menu menu) {
super(player, menu);
}
// HandlerList static getter
}
Written using pseudo code
😂
Idk why you over complicating
oh okay pseudo
?eventlistener
F
I dont remember the cmd
?listener
and now they removed the ?help command, so we cant see the command list
https://paste.md-5.net/qojojelago.java someone know how to fix?
how to fix what
print out params and you will see your error
he is already printing them apparently xD
and i dont get anything
%«pluginname»_rank_name%
What does params contain if you use %rank_name%?
Did you use /papi parse me <placeholder> ?
7Sm,
Something like this?: https://paste.md-5.net/fuyomaxupu.java
Its "name", right?
And what branch do you think "name" does trigger here?
case "rank_name": return user.getGroup().getName();
case "rank_prefix": return user.getGroup().getColoredPrefix();
case "rank_icon": return user.getGroup().getColoredIcon();
case "rank_time": return TimeUtil.toText(user.getLeftGroupTime());
Thats just a plain old memory leak.
🧐
Ohhh that static HashBasedTable
Are you talking of that?
Yeah. It may contain objects which are linked to game objects.
If someone references a chunk in his GUI or a World, then those can never be unloaded.
In your opinion, what could be a solution?
You dont need to cache the object itself
ohhhh okay!! So the ListenerClass Instance Object is the problem
In MethodHandles invoke method the first object you pass will be the object you invoke your method on.
So you can have a MethodHandle without having the actual object
So it becomes permanently stored, right?
Your table should look more like this:
HashBasedTable<Type, String, MethodHandle>
or
HashBasedTable<Class<?>, String, MethodHandle>
I miss something...
If I don't need an Object anymore, why not using a Map<String, MethodHandle>?
Because two different classes can have the same method name which would simply overwrite the other one
So, I need to pass a Class<Ex: ListenerClass> instead of an Object param
okay I got it
thank you
ok, but when i log params i dont get anything in console, request is dont runed, idk why
Nope you need to still pass the Object
But you call .getClass() on the object
.
ohhh okay
okay okay okay
Or at least put the obj in your varargs and get the class of the first one
How are you testing your placeholder?
Well only if your varargs contain the same object again as first element
.invokeWithArguments(args);
in args the first object is the object you are going to use this method on.
The rest are the parameters
Wait a minute let me not confuse invoke and invokeWithArgs
papi parse command and TAB plugin
Show me your plugin.yml
name: Permissions
version: '1.0-SNAPSHOT'
main: me.xemuain.permissions.Permissions
api-version: 1.19
authors: [ Xemuain ]
description: Plugin for manager players permissions
softdepend: [PlaceholderAPI]
lookup %permissions_name% and check if you got "name" in your console then.
Did you tried %Permissions_rank_name%?
work, when you write %<<pluginname>>_rank_name% i used it as %<<Permissions>>_rank_name%
ty bro
You can return null as name to remove "Permissions_" (not sure it work)
if I want to check when a player takes damage from another player how do i get both players
I can getEntity
but that only gets one
getAttacker and getVictim?
`public class Events implements Listener {
@EventHandler
public void OnAttack(PlayerInteractEvent event){
}
}
`
but what do I put
in the public void OnAttack
PlayerInteractEvent???
EntityDamageAtEntityEvent iirc
oh thank you im stupid
EntityDamageByEntityEvent but close enough
Xd
when I do event.getDamager() I cant do .getInventory
how do I check the inventory of the attacker
oh thanks
how would I separate my plugin into 2 different versions where one is just an expanded version of the other
and still keep it maintainable reasonably well
ah yes need to abuse gson now so i know the file name of where the jsonelement comes from in a deserialize 🤔
wtf
how do i remove an NPC? the remove action doesnt exist for some reason
They changed it in the 1.19.3, i think it's something like this ClientboundPlayerInfoRemovePacket or ClientboundRemoveEntitiesPacket
does anyone knows how i would get my filename into the typeadapter? cuz i need it too to construct a valid recipe object. Could probably give it to the reader but that feels hacky
i think it's the second one and it takes an array of entity ids
https://wiki.vg/Protocol#Remove_Entities
also is there an easy way to prevent entities from burning (specific custom ones)
isnt that uh EntityCombustEvent?
something like that
or alternatively invisible (no particles) potion effect
yea ill just make a list of my custom mobs and when the combust event fires ill cancel it for all of the entities in the list
Can anyone make a rainbow text animation going to the left into a hex code for me to rename snowballs
yes
that would be glitchy as fuck wouldnt it
yea
cuz you have to update the name all the time
yea
thats a resource pack
yes
can anyone do it possibly?
yeah that server runs on paper 1.19.3 a dev told me stuff about it
well yea the name is a resourcepack or a mod tho
it doesnt have to do with a spigot plugin afaik
umm the dev said he got his emojis from twemoji-master but he didn't say much about how to do rainbow text ill check dms one second
nah he didn't say anything about rainbow text it's a resourcepack i am guessing cause when i was in server the pack glitched and the item was just plain white writing
anyone here know or have a project thats on github that uses gson in spigot stuff
Would you know how to do this?
:{
and i suck at math
Anyone else know how
why does Ai suck so much
and why is it so biased
im trying to make an npc character attack/follow the player
You could just use Citizens and Sentinels
anyone know where i can find an emoji like the dab one?
ill give it a try tomorrow
lets say i wouldnt want to use that for whatever reason,
Any good way doing it myself?
Why doesn't this code disable picking up items? In fact it doesn't even show an error message neither anything in console
ProtocolLibrary.getProtocolManager().addPacketListener(new PacketAdapter(this, PacketType.Play.Client.PICK_ITEM)
{
@Override
public void onPacketSending(PacketEvent event)
{
System.out.println("Disabled picking #1");
event.setCancelled(true);
}
@Override
public void onPacketReceiving(PacketEvent event)
{
System.out.println("Disabled picking #2");
event.setCancelled(true);
}
});
there's bukkit api method for that
how would I broadcast a message, but instead of it being in the chat, it is on the action bar?
Item#setOwner()
just set this to an UUID that is not used
and voila
or
Item#setPickupDelay(Integer.MAX_VALUE)
this wouldnt allow for players to pickup items for at least 3 years in real life
I want to do it using ProtocolLib.
im surprised that theres even a packet for that
since it could be easily handled by a server
by tracking entity and player locations
maybe you're catching server sent packet?
bruh without the packet it wouldn't be possible to use the bukkit event lol
I'm new to PL so idk but I don't think so. The only thing related to item pickup within PacketType is what I used
Pickup Item
Sent by the server when someone picks up an item lying on the ground — its sole purpose appears to be the animation of the item flying towards you.
pickup is handled by the server
server sends that packet to make the animation on the client
just use the api
and the server wont send the packet
and item wouldnt dissapear
if you cancel this packet
item would dissapear
but no animation will be invoked on the client
My friend
Nothing happens when I run the code I sent
The animation runs
No log is sent to the console
how would I broadcast a message through the action bar?
Yes ofc
sorry for dumb question
with provided scope on maven
They have an example on their wiki with chat, I ran it and it actually worked
So it's not a wrong setup or something
Something must be ignoring my listener or the packet itself
what mc version are you running
protocollib ver?
Start learning pathfinding and nms
BFS and DFS for pathfinding at least
the latest one for 1.19.3, you don't download it from spigot but from their own site
there are better algorithms though
jenkins?
Yes, I'm pretty sure
isit possible to give potion effects async using packets?
Yeah
what packet
its not spigot that its at fault
its the underlying vanilla minecraft server that is not designed for concurrency
well i have smt with spawning an invisible zombie and adding ai to that so it follows the player but the zombie just dont seem to spawn
well you kinda can do it, but forget about duration of potion effects since those are ticked by server's heartbeat
How should i check if around my block that i placed, if any liquids are in 8 block range? I guess it's not check block after block with getlocation().getX - 1 and so on.
*it spawns but its just not there, i can even print the locating and everything
if you only want to make certains people for certain entities invisible you can do that
im not sure why would you use packets
to add potion effects though
here is the underlying zombie code:
https://paste.md-5.net/qinixevava.java
and this is the NPC class:
https://paste.md-5.net/bamegasame.java
are you trying to make nopacket vanish to prevent hacked clients from seeing you even if you're invisible?
if that's so you need to send remove player or entity packet (smth like that) to do that
You're never adding the mob to the world
You can use the api for that
Spigot has hide and show player methods
even better solution, I agree with that. ^^
do i just use this?
presumably you depend on the jar ?
Yes, I want to use the SyncCompleteEvent event that this plugin has but I don't know if I need to add some code in my Main class for the event to work
no you'd just listen to it like any other event
Okay, thanks a lot!
Lets say i need to return boxed primitive type
is storing Boxed primitive type as a static field
help to prevent autoboxing?
is there any way to retrieve boxed primitive from a final field somewhere like empty immutable collections?
like boxed boolean?
or does JVM optimize that for you
@eternal night ik you know this
i guess this works
but im not sure if i should use it
instead of returning primitive type

return true would autobox everytime
for a return type of Boolean
im wondering if using static field Boolean.TRUE would be better in this case
Yea it does that for intergers too
to some degree
how large is the int cache again 
can anyone make a rainbow text animation into a hex or somehow name a snowball for example HelloThere but rainbow moving text running to the left?
I mean, I'd say if you 100% need the performance, return Boolean.TRUE
if this is specifically for booleans
Services ¿?