#help-development
1 messages · Page 777 of 1
Do some math
hi , question what would be the best way to handle multi profile system for each user so for example :
- Solo , doubles , Ranked , insane , this is 4 diffrent type of the same Mode [skywars]
what would be the best way to handle the user data for each type ?
i was thinking about making a profile for each type
and just load them all
when user join , and edit it when it required
just save it all under the same user's stats in the databae
like
username
> ranked
kills
deaths
> solo
kills
deaths
how can i clear banner patterns from a shield? if i have a shield with a banner applied to it, how to get a clean shield?
I mean you can just give them a new shield with the same durability
isn't there a better way?
the Info packet on older versions InfoAction.ADD_PLAYER and on newer wersions EnumSet.of(ADD_PLAYER , UPDATE_LIST)
yeah i know how to set a pattern but i want to remove it
Just remove them instead of adding
how
?jd-s
It’s a very simple method
Did that, and im assuming that setting the PlayerInfoData is still the same, but I get an error saying cannot cast List to EnumSet. And it points to when I’m setting the PlayerInfoData
???
Whatchu asking?
like
a List is a different structure to an EnumSet
I even told you to do
so ofc you get an error
static import 
variable
Is listening to PlayerStatisticIncrementEvent for JUMP increase the best way to detect jumps? Or is there some API I don't know about?
Pretty much
Kk ty
yeah I saw that
Kk
Clientside
Do you mean the tablist?
ohhh that's why the packets are one-time
yeah
There would be little reason for it to be sent
Yeah I know, I set the EnumSet then the PlayerInfoData but it gives me an error saying cannot cast ArrayList to EnumSet. Heres what I have.
Enum
Set
Not
Set
and
not
luist
list
just
EnumSet
I have no idea how ProtocolLib works
spam 😡
😅
shut up
This has never happened before 😮
ngl feel kinda slow rn
but 100% Set is not the correct one
either input only the action or only the EnumSet
try both
Ok gotcha
so if I want to hide some players in the tab I have to send the remove packets to everyone?
I think so
mmmm
is there a way to stop the server from sending it in the first place?
except for constant ChannelDuplexHandler monitoring
so constant monitoring
yes
fine
hi guys
someone can help me with the animation?
with the plugin tab?
i want to do animation with the name too
but i do only the role
how i do with the name?
Player#setPlayerListName
or smthg like that
on a repeating task
wait
GL 👍
i give you something
what?


owner:
change-interval: 100
texts:
- '&C&LO&4&LWNER'
- '&4&LO&c&LW&4&LNER'
- '&4&LOW&c&LN&4&LER'
- '&4&LOWN&c&LE&4&LR '
- '&4&LOWNE&c&LR'
this is the owner
#help-server we’re not tab users
can you do to me with the animation?
Can anyone help me? I would like to create a command that accepts 3 args, player_name time number. I want these args to be passed in an event, and everything I write in the event is executed for a certain amount of time (I use a database). how can I do?
That’s a lot of stuff
That doesn’t really pair together
What is the outcome you want it to do?
The important thing is that I understand how to pass the args
Nope
The important thing is you properly explain your end goal. It sounds like you have everything else wrong
Explain your end goal. What is it supposed to achieve?
I want the exp to be multiplied by the value I wrote in the command and the time I said in the command
all exp?
yep
not difficult
hi
first you need some kind of database (HashMap) to hold the player multiplier data.
then in the exp gain event you read from that database for the player multiplier and do Math
but the time?
you create an object which holds the multiplier adn the time
so your Map<UUID, Data>
data can just be a simple Record
public record Data (float multiplier, long time) {}```
my problem now, it's not how to save the data. It's how to check the time, if it's done or if it's started
just use System.currentTime
mills, it's a long
using that you can compare teh stored value against the current and see which is larger
Learn about unix timestamps
and math
sw.null
null isn;t a table
i dont have a null anywhere
Show where you make your query
didn't set any null vlaues
this is where its acctully buged
the bug is from here
mySQLManager.executeUpdate(query, parameters.toArray(new Object[0]));
this line
I'm attempting to store a Multiblock structure within a chunk's PDC, I'm questioning what type of key I should use though, the issue with sometihng like a BoundingBox would be the need to reconstruct a bounding box to grab the MultiBlock, I'm hestitant to use a Location because you'd need to store many locations that conforms to the size of the multiblock
if you are storing in a Chunk you don;t need the location, only the x/y/z
How do you handle multiblocks which cross chunk borders?
good point I didn't quite think about, unfortunately I'm still trying to figure out how to store the data at all within PDC
They key would be "multi-block-structures" and the value would be a List<MultiblockStructure>
Each structure has a base block and a list of x, y and z values, pointing at Blocks, relative to the base block.
how effective would it to be to check if an interaction occurred on such a structure though wouldn't that be a fairly large operation to check every time. If i'm understanding this right it'd kind of be like a Linked type structure in which every node only knows about the nodes surrounding it and so on
i know that this isn't the place for specific api support, but the discord is somewhat inactive, so i was wondering if theres a way to create a bukkit advancement object and then when i use Bukkit.advancementIterator() it would be included
not sure if that's possible but lmk
this is exactly the place for specific API support btw
Although that's in JSON format. There's no pretty API way to do it
When the chunk loads then you load all multiblocks into memory ofc. pdc is only accessed on chunk load/unload
Some people did make APIs around it though https://github.com/Roxeez/AdvancementAPI
oh i see
this thing then
i was trying to convert a BaseAdvancement class into the bukkit Advancement
but it seems like their entire framework is custom
oh by specific API I thought you meant like bukkit API
and only accesses minecraft stuff at a lower level than im willing to look at
i saw some classes and just kinda
brain closed
I'd opt for the one I sent, personally
i'm not great with reflection, i've dabbled a bit in the simple stuff but not really this
The one I sent above at least makes use of API. Unstable API, but it uses API
ahhh okay. So even when loaded into memory though how would I obtain what multiblock has been has been interacted with etc would I use something like a Map<Location, MultiBlockStructure>? within memory seems like it'd be fairly decent to me
hmm since i've already got quite a few custom advancements already built in and working, would it be worth it to just make a converter for the plugin that is using the iterator?
like just have them as extras
so currently i have an advancement display gui
and it should just display all the advancements in the game, i could just add the custom ones on at the end
tell em to click their mouse
why i cant use znpcs on aternos
aternos servers run on outdated potatoes
why does it only flag it if I add the @NotNull in the generic spot
but it doesn't flag the other ones
because @NotNull on the list side technically means the contents could be null
but the list will never be null
however conventional wisdom will tell you that @NotNull on the list probably indicates that the contents shouldn't be null
I'm aware
that means the contents shouldn't be null
having the notnull only on the list part means the contents COULD be null, extremely stupid, but whatever
Do I just ignore it then
Those annotations are only advisories.
^ I would ignore it
What would be a good way to add websockets to a spigot plugin?
Start a new thread and open a socket on it
Any recommended library that works well with it?
client or server?
Java
I've you're familiar with it then you can just use that in a different thread
I haven't done much with threads except for small things, any things i need to watch out for?
Many things in the Spigot API are not thread safe
So you want to jump back to the main thread when doing stuff
and an easy way to do that is using the scheduler
I'd say most things aren't very few exceptions. ChunkSnapshots is the only things I can think of off the top of my head
Yeah
Most read operations are semi-safe on another thread
though under specific circumstances they most likely can cause errors
That seems difficult, any guide somewhere that talks about going back to the main thread?
?scheduling
BukkitScheduler#runTask(Runnable)
Bukkit.getScheduler().runTask(() -> System.out.println("I'm on the main thread now mom"));
So then i for example send something through the socket every one tick?
in what world would you need to send something through a Web socket every tick?
sounds extremely heavy
its like a plugin where people can race and there is a live leaderboard on a web app for it
is there a way to make it so intellij doesn't put the @NotNull here
you'll get errors most likely
is characterInformation marked as not null?
yeah
That would be why
but I want it like
@Override
@NotNull
public void ...
unless that's not the convention
they probably want the annotation on top of the method like a normal person
Different people want it in different places. You can configure it in the settings
@Override
@NotNull
public List<@NotNull String>
compared to
@Override
public @NotNull List<@NotNull String>
I think it's a bug
cause it's like this
instead of that
I don't think its a bug
^^
just need to change your format settings
Check your code style settings
I'll just keep it next to the return type
do you use the annotations on the arrays and list
I hate that which is why I just use the java 5 annotations
wdym
the @NotNull List<@NotNull Object>
I usually don't do that
I thought it was like a common inferance that a returned collection of any type shouldn't ever really be null
Yeah I always assume it's NotNull by default
If there for some reason would be a null value I would mark it as such
I tried to do this, but [21:52:13 ERROR]: Exception in thread "Thread-0" java.lang.NoClassDefFoundError: org/springframework/boot/SpringApplication
[21:52:13 ERROR]: at jcn.siteinplugin.WebServer.startServer(WebServer.java:9)
[21:52:13 ERROR]: at jcn.siteinplugin.SiteInPlugin.lambda$onProxyInitialization$0(SiteInPlugin.java:23)
[21:52:13 ERROR]: at java.base/java.lang.Thread.run(Thread.java:1623)
[21:52:13 ERROR]: Caused by: java.lang.ClassNotFoundException: org.springframework.boot.SpringApplication
[21:52:13 ERROR]: at com.velocitypowered.proxy.plugin.PluginClassLoader.loadClass0(PluginClassLoader.java:87)
[21:52:13 ERROR]: at com.velocitypowered.proxy.plugin.PluginClassLoader.loadClass(PluginClassLoader.java:64)
[21:52:13 ERROR]: at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)
[21:52:13 ERROR]: ... 3 more
U didn't compile it correctly
You need to shade spring into your plugin or else the classes wont be on the server when it starts
Sorry, I'm new to programming, could you suggest resources on which to study this topic
If you are new to programming then spring is not something you should touch to be honest.
They have a ton of concepts that make no sense if you dont know meta programming.
What is your goal with this spring server running on spigot?
I just want to run the site from a plugin
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.5.1</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<createDependencyReducedPom>false</createDependencyReducedPom>
</configuration>
</execution>
</executions>
</plugin>
... etc
This is how you setup the shade plugin in your pom.xml
Ok but why
I would like to create a plugin for the bank
don't run the entire website off the plugin, just interact with the website from a plugin
I have a websocket server through vertx in my spigot plugin. What port do i use? Can i use a custom port or does it need to go through the minecraft server port?
this can easily be done with WebSockets or some form of Rest API
you probably shouldn't use Minecrafts port or your code will error since the port will have already been bound
Okay, thank you all for your help. I'm going to try
How would you imagine running two applications through the same port should work?
Imagine if spigot gets some http packets. It would be confused as hell and just throw it away.
Yeah i got confused because my client couldn't connect but the ports were right.
I found the problem tho, its CORS
Funny question
@last temple I suppose if you hold a strong reference to the player var and they leave that might be set to null hmm
or fake players
sus
what's the IP for 👀
that's much less fun than timezones
guh no one is gonna do player based time detection based on their timezone!
Hey, quick question - does this take into account that 1.20.2's ClienboundLoginDisconect packet can be both a raw string or a component?
According to a decompiled 1.20.2 client, the client tries to read the received string leniently & deserialize accordingly to what was received (raw string, or component)
the reason field in the packet is a Component and is serialized as such
the server can only send a component
For the normal disconnect packet yeah, but isn't the login disconnect one a special case for backwards compat?
Sure, that's what it is internally, but the reason is deserialized differently with the login disconnect packet vs the normal disconnect packet - atleast affording to a decompiled jar with e.g. yarn mappings
Not sure if allowed here, ill delete if it isnt - but see here how the serialization happens
does getNearbyEntities (world class) only get entities where the center of their hitbox is within the getnearbyentities hitbox or can any part of the hitbox of the entity be within the getNearbyEntities hitbox
also, is entity.getnerabyentities more optimised than world.getnearbyentities?
iirc it creates a BoundingBox and checks for any overlapping box to its own
alr, do you know if entity.getnearbyentities is more optimised than world.getnearbyentities?
The former delegates to the same method as the latter
smile beat me too it 😦

alr thank u
i mean, i can't tell you why the client does that, but the server can only send a component and that's been the case for the better part of the last decade
Does anyone know how this protocolllib code would work in 1.19.3 and higher where you have to use the getDataValueCollectionModifier. Not sure what would be the equivalent to this setEntity of the datawatcher
WrappedDataWatcher watcher = new WrappedDataWatcher();
watcher.setEntity(player);
watcher.setObject(DW_ARROW_INDEX, WrappedDataWatcher.Registry.get(Integer.class), arrowCount);
packet.getWatchableCollectionModifier().write(0, watcher.getWatchableObjects());
Snippet from my Hologram tutorial
Okay thanks ill try that out
are the indexes equivalent to the ones specified in wiki.vg?
Number 12 would be the correct one if i want to control the number of arrows in an entity right?
I am currently hosting a websocket server through vertx in my spigot plugin. When i connect it works, but when i try to send a message from client to server, I get INVALID_STATE_ERR in vertx-eventbus. Now normally when this happens, it's because an error happened on the server side. But for some reason vertx server side isn't throwing any errors in the spigot console. How can I make it so that happens, or is vertx just not throwing any errors?
you cant add chatcolors?
or do you need to put an empty string first if you want to add multiple at the start of a string
correct
Just asking, why using your own program for sending data thru servers? You can barelly use Redis, you skip all this problems, you wont get something as fast as redis
redis requires you to have an instance of it, a (web)socket goes point to point
A websocket needs to be secured but it's slightly faster
websockets can get really messy really quick with multiple conversation participants
websockets are a mess by themselves
Websockets just transfer json?
You can also just tranfer binary data *if you have the right protocol to deserialize it on the other side
binary data is kinda ass
protobuf is alright
A <-> B is whatever
binary data is great when you have to pay for the amount of data transfered
But messaging systems are purpose built for a reason
Everyone(mostly) have unlimited internet access plan
Lets use the foreign memory api to transfer data directly through memory 
when would this have not been initialised? how else can i cancel a task inside a task or achieve the same thing
Business contracts pay by quantity of data in most cases
You cant reference this variable from the inner scope in a call stack like that.
How i can get a Chest block from a location instance?
what else can I do?
Let me write an example
World.getBlockAt(Location)
so for example :
-GameStartEvent -> get save location for the specfic Chest and just fill it when game start
new BukkitRunnable() {
@Override
public void run() {
if(player == null || !player.isValid()) {
this.cancel();
}
}
}.runTaskTimer(plugin, 0, 10);
is there any difference between using a bukkitrunnable and a runnable?
Location location = ...;
Block block = location.getBlock();
Yes. The BukkitRunnable has methods like cancel()
Runnable only has a run method and nothing else.
just wondering, why not?
Location location = ...;
Block block = location.getBlock();
Chest chest = (Chest) block.getState();
Inventory inventory = chest.getInventory();
inventory.addItem(...);
chest.update(true);
Runnable is a plain old java class. It is very commonly used outside of Spigot to simply represent an action that can be ran.
I just recommended Redis because managing multiple conversations at the same time with Sockets is a mess, even when need performance
Runnable is simply just this
lol just replace your () -> to task ->
i should have thought of that
either way, the error message that it might have not been initialised yet made no sense
I really dont like this approach because you can get caught up in confusing scopes like that
nvm that does not work
It made perfect sense to me. If the lambda would execute instantly, then your variable wouldnt be initialized
choose other name your variable name is task
Remove the variable declaration from the start
oops
in what case would it execute instantly though?
i guess it isnt gonna go though the entire bukkit source to figure out if its gonna execute instantly
didnt work either
Because this is not deterministically analyzable. Its a specification of spigot.
Show your code
ig u doesnt know how to use lambda
I really dont like the excessive use of lambdas. Creating a concrete implementation is the safest way for newer devs to get a hang of it.
yes but i talk to him
Lambdas are weird
- part of a serverside autoclicker
i mean yea i havnt tried to do something like this with a lambda before so idk what id run into
i need to save the bukkittask somewhere else though to be able to stop it from a different part of my code
it gets dumped into a hashmap
That sounds like an absolute mess.
In that case you cant use this lambda.
Im giving you a task now: Create a new class, name it appropriately after your task, and let it extend BukkitRunnable.
any reason not to just use an anonymous bukkitrunnable?
it works fine
Deprecated (in the scheduler) also not very clean
actually this is a mess im making my own class
Yes, plenty of reasons. Making you pass variables through the constructor shows you the scope in which you enslave them.
You will see that having a player reference in there is a bad idea.
Eyyy, even more bit stuff, here I go again:)
I have a mask, so I can get some data back from a long:
X_ONE_MASK = 0xFF00000000000000L
And I have a long of data: 0000110100001011000010010000000000000111000000000000010100000011
I want too get the first 8 bits of the data long, the ones that overlap with the mask. No probleme, a simple & Operator. But now I have this long as a return value:
0000110100000000000000000000000000000000000000000000000000000000 But I want that as a byte? So how can I move the bits too the right? Ik I can use >> but how would I get the amount of shift form the mask?
In the worst case, I'll just create hardcoded values.
You need to predefine the size of your masks. This also determines the amount of shiftes you need.
So hardcoding it is
kk
what is wrong with the player reference?
You shouldnt keep references to game objects like entities, worlds, chunks and players because you can easily
create memory leaks if you are not careful. Its better practice to use an indirect reference like their UUID and
request them from Bukkit. This has almost no performance impact.
how would a memory leak be caused if its constantly checking if the player is valid and killing itself if it isnt? is that not enough of a check?
i understand your point but i dont see why its valid in my specific use case
i might just do it to be safe tho
You could also do the following:
private static byte getFirstOne(final long bits) {
if (bits == 0) return 0;
return (byte) ((Math.log(Long.lowestOneBit(bits)) / Math.log(2)));
}
Returns the first occurence of a "1" in the long, so you can just shift by that amount
Its simply a good practice which i would enforce for consistency. Imagine having methods in your other classes that take a UUID
and then you have other parts which take a Player. Its just inconsistent converting them around constantly.
In this specific case it wouldnt cause a memory leak.
public static byte getFirstByte(long value) {
return (byte) ((value >> 56) & 0xFF);
}
After that you simply need to shift by 8 less every step.
*This gives you the left most byte in this long
In my case I can't really do that, I'm mixing sizes. So my long is split into 2x8 Bits, 4x4 Bits and 2x16 Bits
Hm. So the hard part is probably the 4x4 Bits...
The rest are done like the method above
should I make separate utility handling class for PDC tags?
If you feel like it makes your code simpler and reduces repetitive tasks for you, then sure
ill be using PDC tags for pretty much all custom items, enemies and such
so I thought about making a method for both entities and items
Ok so lets start slowly extracting your data from left to right. Im just gonna put everything into ints for now.
like set, read etc.
Don't worry about it, I'll just hard code it, since the masks are hard coded aswell
int firstSegment = (int) ((value >> 56) & 0xFF);
int secondSegment = (int) ((value >> 48) & 0xFF);
Ok so those are the first 2x8 bits
int fifthSegment = (int) ((value >> 32) & 0xFFFF);
int sixthSegment = (int) (value & 0xFFFF);
Those are the right most bits.
The middle can probably be extracted with a loop. Let me test something real quick
int[] segments = new int[4];
for (int i = 0; i < 4; i++) {
segments[i] = (int) ((value >> (44 - 4 * i)) & 0x0F);
}
Ok i think this should do it. So it skips the first 16 bit (bc of the 2x8 before them).
Then it shifts the long 4 times with each shift being 4 greater than the previous.
This should result in the 4x4 values after the first 16 bit.
I mean... you could also just hard code the values and not use a loop.
Thats probably easier
Just make sure to use a 0x0F mask for your 4 bits
ye
you could just split the long first into the appropriate sizes
I love how you were a "man on a mission".
Me 2 messages ago: "Yeah, I have a solution, thanks though"
You: hold my beer, I wanna show you something

A while ago i found a spigot resource where you made 2 maven profiles one build and one dev, and in the dev you put outputpath as your plugin folder, but i don't seem to find that resource back
If you’re using maven for your Spigot plugins (which you should do), it’s easy to make maven automatically save your plugin’s .jar in your plugins folder. There’s two ways of doing this: 1. The lazy way (not recommended) If you only work alone on one computer, you can just directly declare the output location in...
yes that one thanks
So, im working on cooldown and stuff, and i wanna know if using long as ticks is the best option:
and i know 20 ticks is a second
so i can make if (Long % 20) {
seconds = seconds-1
} or smth like that
I would suggest using a Long but as a unix timestamp. (ms)
Keeping track via ticks is a bad idea
You can use a tick timestamp instead if you want the cooldown to match the game time
Hello, I have a question
When I Register a command using plugin.yml. spigot register the command in the global command map is that correcte ? So the command will be registered like if we register it without plugin.yml?
How to structure a controller that is bidirectional? For example, i have a controller with function broadcast, which broadcast to my website, but the website can also broadcast to my spigot plugin. Do I make a seperate controller for that?
We can using the commandMap directly
yes you can forcefully register with reflection
make the map accessible and add your command
Spigot just add the command from plugin.yml in command map or its another system ?
idk, what you wanna do?
No I am just asking about handling of commands
Yes spigot adds them to the command map
So a command added with plugin.yml will work just as well as a command added directly in commandmap?
Or will there be a few differences?
yes
#1170412914428084375 thanks jetbrains
What are they?
it will work just as well @sterile breach
Ups srry
I've noticed that commands are added directly to the command map. If I make them a permission set for example. And low the permissions will not apply and at the time of executing the command spigot will not check if the user has permission and it will trigger the handler directly. Is this correct?
I know it isnt the right place but i dont know where else to get help
But does anyone know why i cant use keyBindForward.isPressed? (mcp 1.8.8)
if(mc.gameSettings.keyBindForward.isPressed){
Is it possible to play sound from a resource pack in a plugin?
that is, you can launch a custom sound without replacing the vanilla ones?
Yes
.?
No idea
Okay fair
mcp is ancient
String#isEmpty refers to if its null?
cause, im making a cmd where 'arg' is the first element in the array of strings on the command
no
if String is null it has no #isEmpty
== null refers to if its null
okay
thanks
still the same error
where strings is the array of subcommands in onCommand method
what should i do?
does element 0 exist?
well, no
then you can;t read it can you
of course you can;t, it doesn;t exist
thought with == null its okay
arg = string{0} is impossible
if it's 1 you have an element 0
im using Duration#toString but PT is like weird
you could use Duration#toSeconds()
if you want to format, more perfectly you'll need to make something yourself
Yeah don;t use toString https://www.baeldung.com/java-period-duration
k thanks
i tried
didnt work
thanks
well, it doesnt exist #toSeconds()
weird
there is a Duration section in the loink I gave
Hello, I have a question. When I import spigot 1.20.1, it doesn't find the JavaPlugin class ?
how do you "import" it ?
import org.bukkit.plugin.java.JavaPlugin; but it can't find the plugin folder
and how do you include api in your project...
Do not depend on this jar with IJ, use maven to manage the dependency instead
(or the other one, forgot name)
Do you know of any documentation for adding it?
?bootstrap
Bootstrap Jar
The main spigot-1.18.jar is now a bootstrap jar which contains all libraries. You cannot directly depend on this jar. You should depend on Spigot/Spigot-API/target/spigot-api-1.18-R0.1-SNAPSHOT-shaded.jar, or the entire contents of the bundler directory from your server, or use a dependency manager such as Maven or Gradle to handle this automatically.
Please read the release notes for further information: https://www.spigotmc.org/threads/9-years-of-spigotmc-spigot-bungeecord-1-18-1-18-1-release.534760/#post-4305163
it works the same way for version 1.20.1 ?
yep
okay thanks, I'll take a look at it
how can I make a zombie wear custom player head?
get their equipment and use setHelmet
oh yeah I get that part but idk how to set up custom player head
From a player name or what
is there any way to detect when a player opens their own inventory
using packets is fine, i just want to know if there is any possible way of detecing it, ive found conflicting stuff online
There is not, no. No packet is sent to the server for that because it doesn't really need to be
Server doesn't particularly care whether or not that screen is open, just if a slot in the player's inventory changes, for which there is a packet :p
What would be most convenient way to pass logged user from spring to react frontend. I don't like the idea of having separate endpoint (/user/me for example). Is passing trough thymeleaf actually alright ?
I've been using nms for a while now but all of the sudden it just breaks on me, i've tried restarting, reinstalling buildtools and more but nothing? anyone help
oh thanks
i think there was conflicting information because it was possible in older versions
I don't recall that being the case
You're calling methods that don't exist in the api on what appears to be api objects
oh
That code has nothing to do with nms as far as I can tell
I asked here earlier if its possible to make several plugins use same custom config but it's not really the best practice, what could I do to make them use same source of information such as custom enemy, weapons etc. data that was initially stored in plugin's custom configs?
since now I basically stuff everything into one plugin but that doesnt sound optimal at all
make an API
do you have any resources on that?
I have this CryptoManager class Im adding to cryptoGraphGuiPlayers map data. If I print them in class where Im adding that data, data are there, but in runnable there are there only for first run of it. Im not removing that anywhere. Can someone tell me why?
public HashMap<UUID, CryptoCoin> cryptoGraphGuiPlayers = new HashMap<>();
private BukkitTask updateRunnable;
public CryptoManager() {
this.startRunnable();
}
private void startRunnable() {
int interval = 10; //in seconds!
updateRunnable = new BukkitRunnable() {
@Override
public void run() {
updateStats();
}
}.runTaskTimer(RPComputer3.instance, 20L, interval * 20L );
}
private void updateStats() {
System.out.println("graph: " + cryptoGraphGuiPlayers );
System.out.println("graph: " + this.cryptoGraphGuiPlayers );
System.out.println("graph: " + Set.copyOf(Map.copyOf(getCryptoGraphGuiPlayers()).keySet()) );
for (Map.Entry<UUID, CryptoCoin> entry : Map.copyOf(getCryptoGraphGuiPlayers()).entrySet()) {
UUID playerUUID = entry.getKey();
Player player = Bukkit.getPlayer(playerUUID);
CryptoCoin crypto = entry.getValue();
this.getCryptoGraphGuiPlayers().remove(playerUUID);
if (player == null) continue;
System.out.println("for run");
new PCCCryptoGraph(player, crypto).show(player);
System.out.println("---");
}
}```
Other class where Im taking instance of CryptoManager :
```java
private final Plugin pluginInstance = Plugin.instance;
private final CryptoManager cryptoManager = pluginInstance.getCryptoManager();
public void initialize() {
cryptoManager.getCryptoGraphGuiPlayers().put(this.guiPlayer.getUniqueId(), this.crypto);
System.out.println("graph added: " + cryptoManager.getCryptoGraphGuiPlayers().get(this.guiPlayer.getUniqueId()));
}
?paste
display entities
You're removing every entry
yeah, but this should run the other class again new PCCCryptoGraph(player, crypto).show(player);
on screen you can see is runed again and in runnable its empty
I maybe missing something? idk... I guess Im accessing same map every time, Im kinda new in java so idk
I've got a quick question if I do Block.getType().equals(Material.OAK_SIGN) will it still work for wall signs?
Anyone here good w/ gradle? I have an issue where this is my runtimeClasspath but there is other shit included in final jar
I'm not sure if this is why but I tried to make this ocmpileOnly (this is in my gradle project allprojects block)
Can someone help me with apache http server? i got some doubts
what's up?
Guys
When it comes to SOLID principles
for the D does that mean I make an interface for everything
Even like plain old java objects
data objects
Dependency Inversion
basically you want to make interfaces for everything
and make your code rely on interfaces rather than specific implementations
Ok so yes
My ranks are being organized incorrectly on the tablist. Here is the full post > https://www.spigotmc.org/threads/tab-plugin-ranks-disorganized.625125/#post-4661082
I know, i set up the weights correctly. Its still not working properly
luckperms has a discord.
?whereami
Hello, I have a problem with the placement of my structures, I can get them from the StructureManagaer but not do the .place, I have no console error and the code which is after is executed correctly, could someone help me ?
System.out.println(Main.getInstance().getServer().getStructureManager().getStructure(new NamespacedKey(Main.getInstance(), "tir-a-arc-1")).getSize());
Main.getInstance().getServer().getStructureManager().getStructure(new NamespacedKey(Main.getInstance(), "tir-a-arc-1")).place(player.getLocation(), false, StructureRotation.NONE, Mirror.NONE, 0, 0f, new Random());
and I am also sure that the structure exists and that the rental does too
not sure on this one but i assume Main is your JavaPlugin instance. The structure would need to be registered to PluginName/StructName if i remember this correctly
yes the Main is where I extend my JavaPlugin
and my structure is indeed registered because otherwise I would not be able to get the size of it
(don't ever name your plugins main class Main, might cause issues from what I know)
In this case it is useful and does not pose any problems
It might not cause any issues right now, but it's bad practice to name your main class Main in a plugin. Just saying. It's up to you what to name your main class ¯_(ツ)_/¯
might be an idea to store the structure and check with a debugger what's stored in it
do you have ur debugger setup yet?
no
i never try this
But in fact what I did worked yesterday that's why I don't understand
Another thing, might not fix your issue, but you are making a lot of Main.getInstance() calls. Instead, you should call Main.getInstance() once and save it to a variable and then use that variable everywhere.
yes but this is for testing and it doesn't really pose a problem to call it 3/4 times
Makes sense, but saving it to a variable saves some time.
Is there a difference by using JavaPlugin with dependency injection by constructors, / using it with static methods like that from above: Main.getInstance();?
I find that using the singleton pattern (static) is more convenient
technically there's a difference
System.out.println(plugin.getServer().getStructureManager().getStructure(new NamespacedKey(plugin, "tir-a-arc-1")).getPalettes());
plugin.getServer().getStructureManager().getStructure(new NamespacedKey(plugin, "tir-a-arc-1")).place(player.getLocation(), false, StructureRotation.NONE, Mirror.NONE, 0, 0f, new Random());
but for spigot plugins i wouldn't worry abou tit
I prefer dependency injecting my instances just because yes
i dont hacve constructor on this, it's command and i juste have onCommand
you can add a constructor with no issues
getInstance can't be that performance impactive
yes, from a design point of view
If you do it only once per a class, then it's basically nothing
But that's not the question, I just came for the place() Structure at the base, can you help me with that?
I mean there are some cases where its like, let's use static instead of instances, for instance why AtomicFieldUpdater exists
sometimes I just use for example in a command / listener class something like this:
public CommandClass(Main plugin){
this.plugin = plugin;
plugin.getCommand("command").setExecutor(this);
}``` and then just call ```java
new CommandClass(this);``` in onEnable()
u should move the setExecutor part to below
but Bukkit.getPlugin(); or something like this should work too
Or you can have another class with the plugin instance injected into it to call the new class instance thingy
^
Anyway, the point of passing the instance instead is that you don't tightly couple your code to rely on specific instances. Since a singleton binds a class to a specific instance. Avoiding that may be resourceful if you care about not making your code spaghetti long term, now that doesn't mean singleton is inherently bad since it definitely has its use-cases. We get more re-usability, flexibility and testability when we avoiding design patterns that tightly couple our code, on the other hand we may have to compromise the simplicity of the code architecture or other properties at times. @desert tinsel
I hear that the function is executed but nothing has been done in the world
at the moment I pass the instance, but I used to work with static values too
yes as said, both works
but just because a design works doesn't really imply its the best one to use in that said context
sometimes not using the most suitable design is fine ofc
mr lube you never answered me
sorry, what did I miss? ,:)
.
but sometimes I just need to have a util method that needs a JavaPlugin instance once, and I need to pass the dependency through 2-3 methods
This is probably going to be a complicated topic, but I'll still ask how I can make a chunk generator that will ADD to the vanilla generator, and NOT CHANGE it.
use minecraft code?
A common mistake is to use short names for variables, such as "p" for player, or "i" for index. This is a bad practice, as it makes your code harder to read and understand. Instead, use descriptive names, such as "player" or "index".
Yeah well that's partly true, the industry convention is to name variables proportionally to the scope they're declared within. For instance a for loop that doesn't do much and isn't exposed to much doesn't need its increment variable named "index", just "i" is fine there.
Re-use variables when possible:, Avoid repeating collections calls:, Perform the most performant checks first, Don't expose mutable collections, the principles etc are all good, I suppose you could just try to use wrapped types when u want primitives with nullability else yeah good stuff, some but not all is basically effective java items 😅
i for index is a weird edge case
Maths
single letter variables make sense in context (x, y, z)
exception e is valid
Exception caughtException
I guess if you really want to you can PR improvements here -> https://github.com/IllusionTheDev/search-index-backup
yea, well there was only one subtitle I had something crucial to say about
whats this for exactly?
else its pin-worthy :>
homie about to pin my entire index
off-site copy in case some idiot griefs my stuff
I like how half the pins are messages from @echo basalt
also serves as portfolio
i just clicked the pins and im like 'tf that's a thing in java'?
like is there seriously a transient keyword in java
hi i have a stupid question
?ask lol
If you have a question, please just ask it. Don't look for staff or topic experts. Don't ask to ask or ask if people are awake or available. Just ask the question to the channel straight out, and wait patiently for a reply. Make sure you use the right channel regarding the topic of your question. Create a thread in case the channel is already in use!
im typing 😭
are animation limit to one mob
for example does the piglin dance animation work on a zombie
probably not
or is it hardcoded
mobs don't follow a generic model, animations and bounding boxes are coded per model
Probably
its worth a try tbh
aren't animations handled disjunct from the entities?
or does every entitiy have its own arm swing animation
pretty sure it's just poses
Hi guys, could you guide me on how to improve messages in my plugin to minimize redundancy? https://github.com/SzinDzeks/ChunkyPlots/
thats a pretty bad utility method
wdym
well actually, do u mind sending the utility method?
public static void openInventory(Player p, BossEvents plugin) {
Inventory voteInventory = Bukkit.createInventory(null, 27, "Buy an item");
voteInventory.setMaxStackSize(3);
for (Item item : plugin.getItemsManager().getItems()) {
ItemStack is = new ItemStack(item.getMaterial());
ItemMeta meta = is.getItemMeta();
meta.setDisplayName(item.getName());
meta.setLore(Arrays.asList("Price: " + item.getCost()));
is.setItemMeta(meta);
voteInventory.setItem(item.getSlot(), is);
}
p.openInventory(voteInventory);
}```
so well, I wouldnt call that a utility method
its more a clumsy static helper method
idk these names
well, a utility method is pure and stateless, meaning that it wont ever return void
Also added guard clauses at the top
a static helper method just does a bunch of stuff, in principle
mr lube 💀
😒
Hello everyone, I do custom enchantments, if I add Lore in English, then everything is displayed perfectly, but if I output it in Russian or Ukrainian, then random symbols appear there like at the enchantment table
How to fix is?
Make sure to have your project compile in utf-8
It is compiled using UTF-8
Files (yml) have to be created/saved as utf-8 too
For tests I changed displayName in code
Then you can't be compiling in utf-8, or your IDE is not set to utf-8
I'm trying to learn how to create custom chunk generators but I don't understand the point of these methods - https://paste.md-5.net/aqitunevul.java - for what they need??
aint utf8 default for both IDEs and file IO?
setBlock is not a method of ChunkGenerator (anymore?)
getDefaultWorldGenerator can be overridden to let your generator be used by the default world
in tutorial i was see setBlock in Impl ChunkGeneration
probably old
damn I didn't find more recent tutorials
Did I understand correctly that the successor of chunkGeneration is the chunk itself in Minecraft and all its methods are overridden to fill the chunk with their own systems?
if so can I override the vanilla generator and change it a little?
Sorry don't understand the first part
But yes you can override vanilla with the should methods
Exception ex ☝️
e is fine
Idk looks a bit ugly
I have a habit of naming Exceptions at least ex because I used to do stuff like Player p back in the day, and so exceptions would clash with entities lmao
lol
Laughs in kotlin
I do use kotlin now
Primarily
The habit has stuck though
Wasn't spigotcraft pfp yellow
Never
Shit. Solo Mandela effect
yOU ALSO THINK IT WAS YELLOW??
We gotta find some old screenshots of this server
Like year-old ones
It was gray. Welp
Ouchie
bro sending finger pics
Its6am
its 12 am
Yeah that looks about right...

this is general what are you on about
Is there an event for when a player middle clicks a block in survival?
What does that even do
Nothing, but it works in creative
in survival it'll take the same block from your inventory into your main hand if you have it, obvioulsy
is there somewhere a general method where the server sends the packets to all the channel handlers?
What
i mean u can inject each player when they join, think thats what most devs do
but to answer ur question, prob not (speculation only)
that's what I also do
what if there's a like a player list update packet it's sent to everyone equally
hmm, iirc there are some helper methods to dispatch a packet to a certain chunk or level etc, and then that level/chunk will just delegate those packets to the players contained within them
something like that at least
is the vanilla chunk generator registered in the same way as in the plugin through the abstract class chunkgeneration?
Probably not
As I understand it, you need to convert the Minecraft code to bukkit api methods?
You just described craftbukkit
What are the most common mistakes when making a plugin, in regards to server performance?
(For example (atleast I think that‘s bad): creating a scheduler for each player instead of having a single scheduler in which i loop over all players)
There’s so many
My MSPT is at ~48 and i wanna get it down a bit, so I‘d like to check my plugin for such mistakes.
Hmm, but like most common or highest impact?
Is using PlayerMoveEvent a lot bad?
dont do unnecessary shit, dont do shit twice, dont do expensive shit in high frequency events
Say i want to detect when a player is in a certain area. Should i have a 1 second repeating scheduler that checks all players, or should I just check it in the MoveEvent
not having common sense is the biggest mistake
obv the movevent as you won't toggle it for afk players.
(i believe)
Hmm yea that makes sense
But on the other hand, the moveevent is triggered like 20 times per second per moving player, whereas the loop will only run once per second
Usually you’d go with the scheduler
PlayerMoveEvent is very expensive due to it being called an absurd amount
the moveevent is triggered even more often
multiple times per tick
Generally just avoid moveevent
If you really really need it make sure it’s cheap logic
PlayerMoveEvent, the performance graveyard
do they need to be moving?
early exit unless to and from blocks are different
Hm?
to avoid evaluating jumping, movings inside the same block or crosshair movement
Oh yeah i get what he meant now
which one should I go for?
the second one executes the tasks always a tick late but there is no need for synchronization at task addition
both work
(probably)
ahaha
keep both and try around when youre done with everything switch to the other one and test the difference
I mean the second one is faster but introduces a 1 tick must-delay
but the first one is how you should properly handle multi-threading
multi threading? minecraft is entirely single threaded though isn’t it
no?
It hasn't been for a long time
Netty has threads, chat is another thread, worker threads are used for worldgen
Ages ago
damn
when they first introduced servers
the tick loop is single threaded, that's about it
i mean, chat is another thread on (craft)bukkit (+ forks), it's sync on vanilla lol
i believe yall over reddit and google but all sources i find say its still single threaded xd
Wait the chat thread is a bukkit thing?
just look at the source code
huh
again, the tick loop is single threaded
but the entirety of minecraft does not run on a single thread
that would be horrible
single-threaded is used here for the meaning that the main server logic is synced
yh but that is about 99% of the usage isnt it
I think the main benefit that could be introduced is threaded entity ticking
unlike Folia for example
Look out for my new fork
no
DeluxeAsyncEntityTickingSpigot™️
most of the information you are finding on google is outdated information that no one has bothered to update
the entire netty communication is async
look at the screenshots ut holds dates too
2023, 2021 etc
idk what those dates mean
.
/\
.
im not saying i disagree
its just that i cant find anything about it and i wanna read about it xd
Not really much to read
Communication is handled by the netty threads
Worldgen does some wacky passing between worker threads
And chat is just chat
Just imagine what would be if netty channels are synced
sounds crap
what is this code lol https://puu.sh/JTSHN/f0cb9192c2.png
New spigot fork dropping soon SyncChatSpigot
not sure if you will find some third party that has covered the changes, but you can see the changes in the source code though 🙂
How would it accept new packets?
Sync it
you don't need to
Poor chat
Lol
This plugin right https://www.spigotmc.org/resources/nest.113419/
It's such shit ahaha
Just freeze the sever until we get the next chat packet
Might be fun to try and make entity AI async tbh
Did they do that?
from tis'?
I never used it
nono
The Nest thing is just this https://puu.sh/JTSIe/11fb2b333a.png
wtf is this
Nothing
Very optimized 10/10
Placebo effect
what does this even do?
Very stronk
Nothing other than printing messages
Nah man Nest uses a custom chunk loader called Nester, which improves chunk loading by determining where players spend the most time.
Suure
I hate all these performance plugins I'm about to make AsyncMemoryLeakPremium
Kofi builds confidnece https://puu.sh/JTSIA/c923a22848.png
Make memory leaks on a whim
You can leak a certain amount of memory on a timer
Omg I'm going to be rich
I once made a ServerSabotager plugin
New server shutdown timer
Is it async?
Thank god
You could always do the opposite and randomly remove a pointer lol
You dont run it
Genius
oh my gosh
like a fuck ton
Ur a helper help us by doing the math
you mean
Threads are largely dependent on current memory in system
Okay well, how many does it try to make
Coroutines go stonks
Will probably try to make an infinite amount lol. But at 64gb of memory and the system using 2gb of it you could have like 200k threads if my math is correct
Yes, it approaches infinity
Hey, im trying to hide a player's equipment with protocolllib and im getting this exception:
This is my code:
PacketContainer packetContainer = new PacketContainer(PacketType.Play.Server.ENTITY_EQUIPMENT);
packetContainer.getIntegers().write(0, player.getEntityId());
packetContainer.getItemSlots().write(0, slot); <- error
ah okay thanks
Doesnt this have like a List<Pair<Slot, Item>> field now?
Also, yeah, for future reference, ProtocolLib operates off of fields in the packet class, not the actual protocol data
okay what would be the correct field for this then?
Not sure off memory. Probably getItemSlotPairs() or something
getSlotStackPairLists?
That's the one
You are best to use API though because it does all this for you and faster
Which translates to something like
PacketContainer container = new PacketContainer(PacketType.Play.Server.ENTITY_EQUIPMENT);
container.getIntegers().write(0, someId);
List<Pair<EnumItemSlot, ItemStack>> slotStackPairs = new ArrayList<>();
slotStackPairs.add(new Pair<>(EnumItemSlot.MAINHAND, new ItemStack(Material.DIAMOND_SWORD)));
container.getSlotStackPairLists().write(0, slotStackPairs);
Can you stop chunks from being sent to a player without using ProtocolLib/NMS
so, im trying to do a restAPI but idk if thats the right software to use
By the way, why is interacting with the chunkLoadEvent chunk more expensive than creating your own chunk generator?
Think about it
You can also use PacketEvents. Otherwise no
yes
you would have to stop the server from reading the chunk in the region file
if the server can't read that information or its incomplete, it doesn't get sent
can I also just cancel ChunkLoadEvent
sure
ohk
just not sure what you were wanting was all 😛
I was under the impression without using the api, what other ways could you stop a chunk from being sent lol
i mean you can still make the player load the chunk on the server and get it ticking normally without sending the chunk info to the client, but that does require nms or {packets library of choice}
which falls outside of the presented constraints
Thanks ya'll
Ur welcome
Hi i have a question about something iam working on so i have been working on a Default kit for Each user and it will be saved in the mysql database .
so i started by making a PlayerKit class it hold :
- PlayerData class
- String kit name
- ItemStack[] contents
- ItemStack[] armors
..
what would be the best way to serlize the itemstacks and desrlize?
playerData class hold 2 methods :
- void setPlayerKit(PlayerKit playerKit);
and a PlayerKit playerKit();
with other methods and stats ofc
Serialize them to a single String and store them as Varchar
what if a user changed kit ? how would it remove only that kit items and add the new one?
or as a blob
i do have a tag on kit items its called : Kit
You just overwrite the entry
can you give an example?
Are kits unique to players or can multiple players have the same kit?
the latter one
Where are kits loaded from?
each kit have its own .yml file
In that case, you should not store all items in your DB but only the name of your kit
ay Key
Why are KitItems addressable via an UUID?
each item have its own uuid
json sorry*
Ok but why?
so i can just do that
or other stuff
but its not important i can remove it anywhy
yeah name is enough
System.out.println(event.getAction() + " " + event.getModifiedType());
System.out.println((event.getAction() == EntityPotionEffectEvent.Action.ADDED) + " " + (event.getModifiedType() == PotionEffectType.POISON));
Why doess this comparison of potioneffecttypes not work
?jd-s
reference equality works just fine on enums
PotionEffectType is not an enum
if it is one that is
^^
yeah
not necessarily
But i feel like spigot should make sure to reuse those instances instead of creating new ones...
Agreed. Guess not?
Most enums will be replaced by constants in the future because it is needed to reflect the underlying structure mojang is going for.
Everything aims to be data driven, and enums are simply too rigid for that.
okay hopefully theyll make sure this still works then
Do it
can I show images of a minecraft item in chat or on like the scoreboard (using resourcepacks)
with resource packs you can basically show everything. but you could also use the placeholder api
so I can also show vanilla items that change texture if you apply another resource pack? like I know you can just create images but I wonder how I would use existing images
idk if what I said makes any sense but I may have solved my problem xD
I don't think minecraft would natively support this behavior. e.g. if the player changes their resource pack a server would have no clue about this
if you were to create another font, however if YOU as a server were to apply a resource pack something like this could be achieved you'd just need to change the relevant chat textures within your pack
well yeah but I meant if I can reference a vanilla texture location
well yes but you dont want to do that. placeholderapi got your back there
wait what now
Anybody experienced with programming for Android? I'm trying to set sdk level to 30 because that's what my phone is at (Android 11) but apparently Google Play requires that apps target API level 31 or higher. Does this mean that the app will not work on my phone? My minSdk is set to 26, and compileSdk & targetSdk are at 30 (presumably I'll have to set them to 31)
it will work on your phone and you can deploy it, but to have your app be in play store it requires level 31
Yeah so if I set compileSdk and targetSdk to 31, will I still be able to run it on my phone?
I'm asking primarily because my app is currently crashing on start and I'm trying to see whether that could be the reason
if you dont use newer api yes
Interesting, guess I'll have to look out for that
Tyty
its backward compatible
you dont have webserver to proccess php files
Is it possible to retrieve how high a block is somehow?
Yes
getY() ?
How?
Meaned how high the block is
:nanithefuck:
what do you mean
how high
like get what drugs its taken?
i dont think blocks have a BAC
sorry if i'm unclear you know blocks have pixels like i want to somehow be able to measure how many pixels a block has or somehow get the height of a block
It’s fairly simple he is just asking how high it is
Like a slab is 0.5 and a full block is 1