#help-development
1 messages ยท Page 248 of 1
like i guess when a player joins it will send out a message requesting the player data?
Wdym?
idk tbh. i just need to figure out how to make the server communicate so it always makes sure data is not lost
Tcp?
use the migrate command
migrate can move keys from one instance to another
so if you use redis and have separate DB's
you could just migrate the key and thus now the other server has access to it ๐
right i think using redis to cache the data is best but would need to do some research on how that works exactly
like how would you se the amount of time it keeps it cached
& how would i commit back to db on expiry
personally you should use replace instead of migrate
because replace will check to see if it exists already, and if it does deletes it and then migrates the key
seems redis doesn't do this, thought it did but it appears you would have to make a function yourself to commit back to DB
For player data, when a player logs out, you can set a boolean toRemove to true and push the data to redis
And when they log in another server, you set it to false
In the server they logged out of, you can run a task 10 seconds after to see if toRemove is true and of it is, remove data frm redis
Also on logout, you should still put whatever is cached into mongo
the better way is to see if they changed servers via the command, if so just move the key
yea that would be a good idea too
Sometimes they don't change servers via command
sometimes not, but it really depends on ones setup
ah well thanks for the advice. i will go and try some stuff out and see if i can make it work nicely
sounds like nms incoming. Context for this question is that i want to check for certain blocks, but only under certain conditions will the chunk be loaded. I'm aware theres a chunk class that iirc is in the api, so let me rephrase a bit.
Can i somehow read chunk data in without '''activating''' the chunk - speak, without loading it?
no
server isn't aware of the chunk unless it has been loaded even if partially because region file gets memory mapped even if a single chunk in said region is accessed
So the only way you could access chunk data without it being loaded is if you accessed the region file yourself
but, I mean it isn't an expensive operation to load a chunk and then unload it when done with it
invalid syntax
depend or softdepend
no idea, rename the file to something no called config.yml then regen the file
how do i print a debug message?
... is just syntax sugar for a variable sized array
String [] and String ... are both internally arrays
one takes a vararg parameter the other doesn't
not sure why that is so hard to understand, if you don't believe me go look at the implementation
System.out.println("debugmessage") or Bukkit.broadcastMessage("debugmessage")
fuck logger
unnessecary di
if all you need to do is print debug messages, the logger isn't necessary for it
Or you could be a baller and use kotlin's println() function
For debug, logger if possible, otherwise sysout is not going to kill you
It's all going to the same place and you know where the messages are coming from
love it when the server complains about me using sysout
paper
im running paper yes
stfu
should be working on my parser but my head hurts when i think about the debugging
i always dev again spigot api but i have always ran paper severs for some reason
only thing i could think of
Flashback to when a logging library had RCE
i always run paper cuz their reload command is faster
for the rest i dont give a fuck
ew
plug woman? kek
I never reload unless testing reload itself
only on jda ive found
usually my plugin was breaking when using reload but i fixed it
nah, hes just really bad
fuck copilot cant even write correct tests for me
lol
lol
u have the money for copilot?
gh student lol
too lazy to write a few thousand cases in a file lol
only effective way to test
uuum
why not be me and write this abonimation
?paste
wha
smh
just generate your tests with more buggy code
one is cs and one is math
Guys whats this?Why i got this?
https://paste.md-5.net/agizaxurav.sql
copilot sayin A: A function is a relation in which each element of the domain is paired with exactly one element of the range. A relation is a set of ordered pairs.
an instance of that plugin already exists
when i spawn in particles such as CLOUD, it makes them fly all over... how would i fix that
oh right if both are math. functions have to fulfill certain conditions so that u dont get three outputs for one input
uh thank you
could the islandData be returning name
the only other option is tab is adding the player name in
where does it actually get added
before or after the money
on a method that can be triggered try printing the return of any player to console or something and see if its added there
yeah
the Helper.colorize
ye
if that returns a player name it would have to come from one of your methods, if not its tab being stupid
ig you could try and change the placeholder and see if that fixes it
try the placeholder change and see if its them trying to hook into player for it
instead of %player-something% change the player to anything else
lets say I have a hashmap of hex codes, given a hex code that is not in the hashmap, how would I go about finding the colour nearest to an existing key in the hashmap
google java colour distance
else might wanna use a tree map
alr so iterate thru all keys and use the one that has the lowest value right
best I've seen (ignoring it uses sqrt) ```java
double colorDistance(final double r1, final double g1, final double b1, final double r2, final double g2, final double b2)
Return the "distance" between two colors.
double a = r2 - r1;
double b = g2 - g1;
double c = b2 - b1;
return Math.sqrt(a * a + b * b + c * c);
yes, lowest comparison is closest
ight thanks
how severe would the performance impact be of always loading designated "farm chunks" 24/7 to make farms always work
Thx, i solved this
How i can convert String to Material?
if (player.getInventory().contains(getConfig().getString("BuyBlock"))) {}
Thx
I cant find GameProfile at all in my external libraries and cant get a custom skull.
Its as if GameProfile doesnt even exist in the first place, even though I used it in the past.
?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
๐ฅฒ
https://paste.md-5.net/mamujacixi.bash
Line 45:if (api.utils.checkItem(player, Material.matchMaterial(getConfig().getString("Clans.BuyBlock")), getConfig().getInt("Clans.BuyAmount")))
checkItem method in API: public boolean checkItem (Player user, Material id, int amount) { if (user.getInventory().contains(new ItemStack(id, amount))) { return true; } return false; } }
so basically just changed my -SNAPSHOT to -SNAPSHOP-shaded
Config FIle: ```Clans:
BuyBlock: STONE
BuyAmount: 1
Update; Didnt work. I shaded it and it refuses to show gameprofile.
<repositories>
<repository>
<id>spigotmc-repo</id>
<url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId>
<version>1.19.2-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
</dependencies>
Im building it as package shade:shade
Why wont it show GameProfile?
im running on minecraft 1.19.2
lmc my pom
Wait.. do I need to run buildtools?
well
yes
it uses ur local .m2
so for every new version ur gonna need to run bt for that or somehow get the shaded jar file
when printing the 1d slot it calculated its 0, how the fuck does that make sense
if you fill it in it should be 0 * 9 + 5 = 5 right
ah ok
i assume i place the file inside of External Libraries
or
no
you dont do anything after running buildtools apart from rebooting ur computer
maven ONLY works correctly if u touch neither the m2 folder nor ur import folder
nvm am stupid
@smoky oak so as soon as its done just restart my pc right
there are like 2 ways to do it
like
there are multiple ways to compare colors
there's the euclidean distance, but some algorithms cater to the human eye
well u could convert it to color wheel and calc the angle
but i recon thatd take more cycles to do since its sinus math
I mean like
there are multiple ways to determine how "close they are"
one is based on pure rgb values
but that might not always be "accurate" among a population because we have more red? receptors
so there's this secondary comparator
bah
i write the library to use color
not the library to adjust it
I use this in my imageboard system
this weighted euclidean check tends to boost yellows more
well its not like im a graphic designer. the stuff i work with is usually much lower or much higher in abstraction tbf
same
id probably just subtract the values and add up the differences
I just happen to have obsessed over maps & itemframes
ah
and couldn't go to sleep without making this extremely performant
worked tirelessly for like 3 days straight
and even setup graphs for it
@smoky oak Didnt work: I installed it into my downloads, restarted my PC and nothing happened
um 1 sec
the default rendering system that minecraft uses is incredibly slow
so is the traditional raytracing route
but then you start going into advanced routes and have to account for stuff like lens distortion
wells its openGL which isn't exactly known to be better then using drivers
I had 0 clue why my gameprofile wont work lol
I mean the map rendering
not the client part itself
oh
can u ?paste ur pom
it was taking like 60ms to draw an image
1.3 ticks isn't all that bad
for 1 frame
now, go render a 1000x1000 image into a grid made from frames that can only render 128x128
so 64 frames
sure you can multithread it
that's still more than 0.1ms :)
well I mean you are not going to get lower then 50ms in mc
well considerimg mc runs at 20 internal fps anyways couldnt u do that frame smearing they use in vr
they get put into the queue
my brain hurts
tldr: we likely all have, or are working on, cs degrees
I'm finishing up my associate's in programming
theres a reason i only ever poke opengl with a 10 foot pole
also ofc its implementation in javas crap so im sitting here staring at c++ pointers and wondering why tf its not working
I don't go to college or possess any degrees. Mostly self taught with a side of military teaching me satellite communications ๐
and then i learn that for some dumb reason it put my massive array onto the STACK
like
think 3000000 values
I've been making plugins for 6 years :)
yea i did then i did it properly @wet breach
am i doing something wrong?
ive shaded my jar
ive installed buildtools on my pc
now what
ie without fucking over my computer
lol
${user.home}/.m2/repository/
you??
oh whats it doing there lmao
like the .m2 folder was buried into appdata for a long while for me
and now its in home
wtf
aaanyways, @quaint mantle, do you have a $home/.m2/repository/org/spigotmc folder
whats $home
yes
i have that
inside it is minecraft-server
spigot
spigot-api
spigot-parent
do u have a spigot/1.19.2.... folder
yep
i have the 1.19.2-R0.1-SNAPSHOT
im using spigot-api and not spigot however
i changed that a while ago
how would i turn a legacy string into a minecraft chat component
try this
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId>
<version>1.19.2-R0.1-SNAPSHOT</version>
<type>jar</type>
<scope>provided</scope>
</dependency>
it also might be ur repo
try spigot-repo instead of spigotmc-repo as identifier
first thing didnt work
trying spigot-repo
building
@smoky oak Nope
none of those worked
?paste
what error are you getting?
no error; just that gameprofile doesnt exist
using intelliJ?
tried clearing caches?
how do I do that?
https://paste.md-5.net/hasowejuti.xml
sanitized version of my xml, excluding build name. Copy ur group/artifact/version into it and check if it works, if not, its not a problem with ur pom cuz i can build with it
it might help to reload maven too
and for the love of god make a copy of it first
may or may not need to restart IDE after that don't remember
o.O
whats ur build args
ah I should have read closer
on ur maven build button
is it a nms thing?
o
for GameProfile yes
mojang authlib
you can be happy to know you are not going crazy yet
that imports nms
?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
idk it works for me
depends on the version
Okay so then how do I create a PlayerProfile
starting from 1.17 you need to use the method described in the post above
with a random UUID
it works for me in 1.19
wait ill send my code
public static ItemStack getCustomSkull(String url) {
ItemStack head = new ItemStack(Material.PLAYER_HEAD, 1);
if (url.isEmpty()) return head;
SkullMeta skullMeta = (SkullMeta) head.getItemMeta();
GameProfile profile = new GameProfile(UUID.randomUUID(), null);
profile.getProperties().put("textures", new Property("textures", url));
try {
Method mtd = skullMeta.getClass().getDeclaredMethod("setProfile", GameProfile.class);
mtd.setAccessible(true);
mtd.invoke(skullMeta, profile);
} catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException ex) {
ex.printStackTrace();
}
head.setItemMeta(skullMeta);
return head;
}
I was attempting to create a skull
this is some code I made ~ a year ago
So im unsure if it still works correctly
just use the SkullMeta
declaration: package: org.bukkit.inventory.meta, interface: SkullMeta
oh wait that is for items, not a skull block
wasnt there something new for 1.18 skull skins
no i mean the skull block itself
declaration: package: org.bukkit.block, interface: Skull
i wanna create a skull w/ a texture inside of a gui
anyways the skull api has setOwner()
and setOwnerProfile()
no longer do you have to do it that old way ๐
^^^
if its inside the inventory, the skull isn't a block, it is an item
ah
im a dumbass
i thought u wanted a create skull texture gui
all g
@wet breach so i can create the skull using setowner and setownerprofile
using these strings
SkullOwner:{Id:[I;384364079,607340060,-1248642982,2089600727],Properties:{textures:[{Value:"eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvNmZhZmUwNmZlMzI4YTI1YjViZGM3ZjA3OGJmOTM1OGViYWQyNWQ5MTQ5NTkxMTM4MmZjNDMyNWVkODg0MjhkMiJ9fX0="}]}
yea sound about right
idk the syntax here tho
someone posted an example here like 4 months ago but i aint being bothered to find it
you would need the playerprofile, from there you can get the PlayerTexture
That string is just a url to the skin encoded in base64
it should be the encoded texture
PlayerTexture lets you set a url to the texture to be used
Almost it's a piece of json containing the url
found it
Oh wow
see, told you your code is now outdated and there is better ways ๐
lol
tysm
i didnt think it was THAT outdated lol
i have a very broad pool of shallow knowledge in a lot of areas, so i remembered that one, just not where it was
for this:
PlayerProfile profile = Bukkit.getServer().createPlayerProfile(id, name);
s
should I just make it a random id and a blank name
as custom skulls dont use them
same thing as Bukkit.createPlayerProfile tho
oh on that topic
who am i kidding this is a logic leap but
does anyone know if different worlds run on different threads?
they all run on the same thread
They do not afaik. Since some things have to be in sync (like time and teleportation)
Well but what about plugins?
They would need their own instance for each thread/world
how do I check if something doesnt exist in a hashmap?
do i just compair it to null or
contains
ty
containsKey()
to be specific
if you want to check for a key
containsValue() if you want to check values
If you want to grab it as a set
ah lol
okay yay my stuff works

technically O(n) (1<n)
since yk, given a really bad hashCode
but thats rarely the case
well isnt it scaled so that it's considered o(1) by saying that extra cost is part of some other part of that
a bit
why
yea
yes?
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!
all I see you doing is initializing the size of the array + 1
This line of code is creating a NPE -> item1_meta.setDisplayName(config.getString("GUIItems.item1.name"));, I have NO IDEA why it would do this. ```logFreezes: true
logReFreezes: true
GUIItems:
item1:
type: !!org.bukkit.Material 'PAPER'
name: You have been frozen by staff, please look at your discord!
amount: 1
Heya!
I keep getting this issue, and I've done a lot to try and fix it, to no avail. It also doesn't seem to have been encountered much, so no luck googling... Have you guys ever encountered it? If so, how'd you fix it?
[21:35:47 WARN]: Entity ChestBoat['x2 ยงiChestBoat'/491, uuid='cb7d6a7f-684d-4eba-be46-41bd09ed97a0', l='ServerLevel[world]', x=-36.22, y=176.00, z=-99.36, cpos=[-3, -7], tl=128, v=false, removed=DISCARDED] is currently prevented from being added/removed to world since it is processing section status updates```
maybe config / item1_meta are at fault of being null?
Also I'm not sure if you can set the display for a name that long
I might be wrong, I'm really not sure
It works
The name does
ah mb
Ok, so I was using an int in the ItemStack which is depreciated, but I am unsure if that would make it null? I am unsure on that. However I am unsure how I would go about making it not that and just having the material
But also making it readable
?paste the stack trace
whats line 18 of FreezeFunc and line 27 of FeezeCommand
Line 18 of FreezeFunc is the one I sent and line 27 in the command is just Freeze.Freeze(p, true, false); (Calling FreezeFunc)
Donโt unless ur using legacy support.
Yeah I figured it would cause issues, I am unsure on how I would get a material from the config.yml tho
Or how I could take a string and use it in a material name
Material.valueOf(configString)
Oh thanks
sorry?
Do I need to change what I have already put there? Or just change what is after Material.?
Also, this is my plugin.yml -> ```logFreezes: true
logReFreezes: true
GUIItems:
item1:
type: Paper
name: You have been frozen by staff, please look at your discord!
amount: 1
Cheers
I just want to know if it passes an array
Ok, will that return an array?
hm ok
Anyone knows how to do a "loading screen" like that?
i'm currently using bossbars to do that but this would look way better
i know how to send the titles but idk how to make the loading thing
it is
Action bar
its a title
Looks like Actionbar tbr
it is mid screen
i know difference between title and actionbar
don't worry, i know how to send them but i don't know how to make the plugin know where to start coloring green
Wait so I put this in ConfigurationSection GUIItemsSection = config.getConfigurationSection("GUIItems");, do I just use something like GUIItemsSection.getKeys()?
Well depends on what you load of course
i already have a percentage integer that goes from 0 to 1, it already works well for bossbars
But you would just do a for clause to loop it
kk thanks
could you be more specific?
GUIItemsKeys = GUIItemsSection.getKeys(); what should I put before this
Like String?
It wanted me to use a Set so it wrapped it into a String List List<String> GUIItemsKeys = (List<String>) GUIItemsSection.getKeys(false);
Well lets say you have 10 characters. If the progress value is 0.5, you draw the first 5 characters green
E element = list.get(i);
}``` Would something like this work for iterating through the list and then using the element to get the values ofc
i'll try do smth like that
Nicec
What would I use in the config.getString? -> for (String guiItemsKey : GUIItemsKeys) { config.getString() } Would I just add GUIItemsKeys +"path to value" or something?
Nice
This error is occuring when it is called
ItemStack item1 = new ItemStack((Material.matchMaterial(((config.getString(GUIItemsKeys+".type").toUpperCase())))), (config.getInt(GUIItemsKeys+".amount")));
ItemMeta item1_meta = item1.getItemMeta();
item1_meta.setDisplayName(config.getString(GUIItemsKeys+".name"));
item1.setItemMeta(item1_meta);
GUI.setItem(Integer.parseInt((GUIItemsKeys+".placeInGUI")), item1);
}``` That is the loop
oh ok
kk
With that you can calculate how many chars to fill, then you gotta iterate through them with a for() loop probably
Oh
Nvm
Sry
Use the method morice said, forget mine
You gotta String#repeat the amount of green chars, then subtract the green chars from the total chars to get how many gray chars you gotta repeat after that
If you know what I mean
people need to move away from java 8
tell that to Oracle, java 8 is still default Jre..
you should use ConfigurationSections for this
final ConfigurationSection guiItemSection = config.getConfigurationSection("GUIItems");
for (String key : guiItemSection.getKeys(false)) {
final ConfigurationSection currentSection = guiItemSection.getConfigurationSection(key);
final String name = currentSection.getString("name"); // equivalent to GUIItems.<key>.name
}
example
that's why i'm used to work with it
no it isn't
Java 17 is the latest LTS
yes but it isn't an LTS
not sure what link you clicked
in the official java site, 8 is the first thing that comes out
Well use the right Java Version depending on your mc version
its literally https://www.java.com/it/download/
If you are developing a minecraft 1.12.2 plugin, do not use Java 17
?paste
i'm developing a 1.12-1.18 plugin so yeah i use java 8
Yeah then you cannot use repeat
still that link you gave me gives a dev kit
i'll just copy the code and paste it in my project
it uses java 8 compatible code
You gotta use my complicated method then I guess
Or maybe there is a method for repeat user-made online
frostalf that does not change the fact that he needs to use J8
i'm importing the code in my project
https://paste.md-5.net/olosolasup.cpp can anyone help me with this?
the code used by the repeat method
It works in java 8
its just that wasn't included
Tysm
I mean there's nothing wrong with using Java 17 if his server works well with Java 17
If you compile your plugin for 17 and the server isn't running 17 then it's not going to work.
or Java 19
The Server Just Needs to have a Higher or Same Java Version as the Plugin
Java is Backwards Compatible
I have a class that acts as a middleman between my database and my plugin and also caches stuff from the database, what should i call that class?
Does anybody know how one would add a delay to a command?
?scheduler
fuck
?scheduling
uh i looked at that but i ment more like
like cant move for 10 seconds when you execute it
and if you do it cancels
well, then you would have to keep track of the player and the timestamp and check for it
i guess i can try that
i got it, thanks
one more thing though how would i kill someone while bypassing their titem
totem
calling kill on something should kill it even with totem
whenever i remotely interact with the class "Material" my entire ide just freezes...
any1 know why that could be happening?
never had that issue before
that started happening to me a while back while using eclipse
I don't think I was able to fix it
Im using intellij. But like my pc is pretty strong it normally handles it fine
I also have plenty ram allocated to intellij so i dont rlly understand
Exactly, but it's wrong to say that you should use Java 8 for a 1.12 server
In fact, I'd never use Java 8 for any personal project nowadays
There is just no reason
My point would be that if someone downloaded a plugin built for 17 and their server used 8 it would error resulting in the plugin being removed usually.
That's true, if he's developing it for the public then it can make sense
But my only reason in doing that would be to have some calm from people who contact you because the plugin isn't working on their relic server
Metrics metrics = new Metrics(this, pluginId);``` bstats isnt recording the data from my plugin
can take up to 30min
I was wandering if anyone had any YouTube tutorials for velocity?
Velocity not maintained by Spigot.
I know I was just seeing if anyone knew of any tutorials
Afaik config is almost the same. Althouhg. Testing and self-taughting is a thing as well. But any seaches also should give a good result.
Last time I check bStats was down.
Oh, it's already up now.
can someone walk me through creating a multi module project with maven?
i always mess it up and end up throwing all the files in 1 module
currently this is my layout
iirc intellij has module creating built in
yeah but the project structure looks weird sometimes
from what ive seen and that, its
FolderMain
pom.xml
module
--pom.xml
--src
otherwise this might help https://www.jetbrains.com/idea/guide/tutorials/marco-codes-maven/multi-module-projects/
delete the src folder not in API
that contains all my current code
if you want that kind of module's people normally just put it in a separate folder after me.name.something or something like that, so you would have src.main.java.me.epic.epicplugin.api.APISTUFF and src.main.java.me.epic.epicplugin.core.MAINPLUGIN
main class only existing in core
that looks correct to me
just create one
right click server core and new file
but the .gitignore should most likely be in server core too
no idea, its probably on here somewhere
The POM for me.saif:API:jar:1.0-SNAPSHOT is missing, no dependency information available
<dependency>
<groupId>me.saif</groupId>
<artifactId>API</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
i have that in my Spigot module since it depends on the api
ohhh
wait ik
i dont have a build config for API
works ๐
now time to make this a template
does anyone know about import MagicSpell lib to maven project?
I couldn't find dependency of MagicSpell ๐ฆ
do you have their repo
do you mean repository?
repo is short for repository
I thx ๐ I wanna this!
is there any way to do something like this so i dont need to go to each pom to change the version?
you can, I do not remember how to off the top of my head
most good IDEs have the ability to find all in a program
I mark up my versions with a comment
this is my current project
multi-moduled
try it
?paste
?tas
Anyone have an idea why all of my files in the submodule say "X.java is not on classpath"
https://paste.md-5.net/epeberihid.xml
https://paste.md-5.net/adegewokab.xml
I swear to god I have my pom setup correctly
nvm I see I'm not getting specific errors reported for some odd reason
which still doesn't make sense
I forgor /java ๐
Exception in thread "main" java.lang.IllegalArgumentException
at java.base/jdk.internal.misc.Unsafe.objectFieldOffset0(Native Method)
at java.base/jdk.internal.misc.Unsafe.objectFieldOffset(Unknown Source)
at jdk.unsupported/sun.misc.Unsafe.objectFieldOffset(Unknown Source)
at sh.miles.test.Test.main(Test.java:12)
does anyone have an idea why this is causing an error?
private static final String TEST = "test";
public static void main(String[] args) throws NoSuchFieldException, SecurityException {
final sun.misc.Unsafe unsafe = getUnsafe();
Field field = Test.class.getDeclaredField("TEST");
unsafe.putObject(null, unsafe.objectFieldOffset(field), "Changed"); // line 12
System.out.println(TEST);
}
public static sun.misc.Unsafe getUnsafe() {
try {
java.lang.reflect.Field f = sun.misc.Unsafe.class.getDeclaredField("theUnsafe");
f.setAccessible(true);
return (sun.misc.Unsafe) f.get(null);
} catch (Exception e) {
return null;
}
}``` I'm pretty sure I invoked it correctly
i'm making a system plugin that manage 90% of my server.
but the bungee messaging must have atleast one player in the spigot instance
and i wanna make it with websockets, i have a websocket server in nodejs.
and the websocket is secure (https).
but what should i put the uri the websocket client in java?
i tried a lot ..
Shouldn't it be unsafe.putObject(TEST, unsafe.objectFieldOffset(field), "Changed"); ?
test isn't an object
it works, i hate java.
I figured it is unsafe.staticFieldOffset
though I get a jvm dump for doing that lol
first time running unsafe and It crashes how fitting
that's why it's called Unsafe lol
ughm what are you trying to do?
why do you need unsafe to change a field?
why can't you just do field.set(...)
private static final
๐ข
blame mojang
and openjdk for patching a bug that allowed you to change private static final with reflection
you can change the modifiers to make it non-final
you do not need Unsafe
you do post JDK 17
the standard method for doing so prior was removed post JDK12
the ability itself was removed all together in JDK18
to ensure platform compatability unsafe is a better option
you may ask? How do you know are you sure? I've dumped too many hours into this in research
unless you have a way to parse JDK version then I'd run different code per JDK version and only use unsafe post JDK17
you can probably get it from the system properties
String version = System.getProperty("java.version");
aparently it was never intended to beable to do that
returns sth like "1.6.0_30"
like the reflection thing
it wasn't intended, but it definitely was possible anyway ๐
fuck the security manager, I hate this thing
fuck security Unsafe time ๐
So I was attempting to create a lottery system for my server...
And it doesnt work with more than 1 person.
Ill paste my code, I have 0 idea why its not working correctly
?notworking
"Does not working" is a useless statement. Please describe what exactly is not working, what you expect it to do, and what actually happens. If you get any console errors, also ?paste the entire stacktrace.
Ah, sorry
It refuses to run EventHandlers (and yes I tested them they are active)
?paste
Here is the code, can anybody identify why it wont run the events properly? and if you guys see any way to improve it lmk
Better question: Is inventory holder a better way to run this
hm well I would add a ton of debug statements, e.g. like this
@EventHandler
public void onInventoryClick(final InventoryDragEvent e) {
System.out.println("InventoryDragEvent");
final Player p = (Player) e.getWhoClicked();
System.out.println("Player == " + p.getName());
if(inv == null || !(inv.getHolder() instanceof Player) || !p.equals(inv.getHolder())) {
System.out.println("inv is null or the holder is not the player");
return;
}
...
}
then see where it stops executing
I did this, it states that inv is null
For 0 reason
are you creating 1 shared inventory or is each one per player?
ooh inv is a field
1 each player
I didnt see that
you should not just save one "inv" field, but rather use a Map<UUID,Inventory>
so you can store one inventory per player
do you know how maps work?
I see, but my better question is if it may be better to move this over to as a InventoryHolder, from what I can tell, your supposed to use inventoryholder for this stuff
no. actually, you are not even allowed to create a custom inventoryholder
Samee
while you can technically do that, it's disallowed as stated in the javadocs
Ah ok
(creating a custom inv holder)
so its better to do it the way I am them technically
Yes
you should just use a Map<UUID, Inventory>
Yeah
alr lettme try that
Am I the only one that is always parsing UUIDs to Strings to store them? Lol
i keep them as UUIDs normally
not as strings
How are you storing them? Like in a file or a db?
idk about others tho
both actually lol
I always either use JSON or MariaDB to store data
I would use null. Using the player suggests that it's actually their inventory instead of a GUI
import java.net.io.*;
trynna make a damn http request but it says Cannot resolve symbol 'java'
java?
ic
You do know that MySQL can store the UUID data type right? You can just pass it in directly.
Files are one thing, but you can reduce some parsing with a db.
cant import anything from java.*
what would be the best way to store a location in a database
what IDE do you use? do you use maven/gradle? what JDK version did you set both to?
Yes I know but I hate doing the extra step because I almost never need actual UUID objects
But Strings
the breast way you mean
Separate columns for world id x y z yaw and pitch
yeah I'd also do it like this
i was thinking that, but wanted to check there wasnt a better way
I use IntelliJ. also on the top of my screen it says Project JDK is misconfigured
ill use that, thanks
although I mean... it already implements ConfigurationSerializalbe
File > Project Structure > set the Java SDK
o k
but using that would be a bit wasteful lol
(#FuckJson)
No
then click on "Fix" or however it's called
Json is good
you should set your JDK to either 8 if you wanna support ancient mc versions, or 17 if you are using a proper version
Its set to JDK 19
what jvm does 1.16 use
im using maven btw
java 8 - java 16 is supported
Java 8
it's compiled for java 8
uhm J16 or something probably
wiat i needa use jdk 8?
no, you should use JDK 17
oh oka
what MC are you looking to support
lemme install it rq
latest
smh i was planning on support 1.16 too
^
I shud use jdk 17 for latest relaeses of mc?
Yes
hm IIRC intelliJ can do that automatically
Since it is LTS
now we drop the support of 1.16
K
should look like this
I began switching to new minecraft versions, and I gotta admit it really sucks in some ways
1.16 is so old, i wasn't even gay when it was released
its downloading correto 17
I still was together with a girl haha
i wonder if mc will swap to 20/21 the one thats lts next
For modding with forge new versions are just absolute garbage, for servers it is fine
Still wont function. Am I doing something wrong?
Whats going on: Just doesnt detect the events.
are you registering them
probably they will always switch to the newest LTS available. took them long enough to go fro 8 to 16, then 17 came
aight imma just use the default
registering the events
File -> Invalidate Caches -> Check every box and click "Invalidate & Restart"
Hmm
Wait a minute.
you're using the same key for all the inventories?
OH WAIT I SEE WHATS WRONG A
ktysm
lol
you still haven't added any useful debug information. the events DO get called, your check whether the list contains "key" is simply always false
because you only store one key, that makes absolutely no sense
les go I think tghat worked
Okay so, the events get called.
The list key returns as nil for an unknown reason.
Upon the openInventory event being called, it creates the inventory and puts the data in the hashmap. Unsure why it wont work further.
https://paste.md-5.net/wagovetatu.java
To access the list: invList.get(p.getUniqueId())
List contents: invList.put(p.getUniqueId(), new HashMap<String, Object>(){{ put("ClicksR", 3); put("Inv", in); put("AllowC", false); }});
yessir that worked
tysm
Use a map of instead of creating your own hashmap class
Why
Doesnt that do the same thing
Anyone have an idea of the issue
wdm
wdym*
oh you are talking about the code block they sent
I only looked at the link
is something wrong with that codeblock
it's fine but a bit unusual
you do new HashMap() { ... }
usually you do not use the { ... } part
usually you do it like this;
Map<String,Integer> myMap = new HashMap<>();
myMap.put("mfnalex", 27);
oh i do this for organization and beautification purposes
if it works, it's okay lol
thats my philosophy lol
anyways: did you detect the issue?
Also: the ui is initialized like so:
new LotteryGui().openInventory(p);
as I already mentioned twice . add a ton of debug System.out.println()'s and you'll find the issue
print out the result of every if(...) check you do
I have no clue what's wrong, I am too tired to check your code line by line
but printing everything out will tell you what's wrong
"it" creates "what"?
It creates thhe new userid hashmap
and after the createinventory function gets to the end
it just ceases to exist
the hashmap gets set to null, you mean?
yea
05.12 06:54:25 [Server] Server thread/INFO {193ff4d4-68cd-4f4b-8877-a31f41f88aa2={Inv=org.bukkit.craftbukkit.v1_19_R1.inventory.CraftInventoryCustom@1db9732, ClicksR=3, AllowC=false}}
05.12 06:54:26 [Server] Server thread/INFO {}
the first one is on opening the ui
the second one is an event
it's not null, it's just empty
why
idk but first of all, I would suggest you to use descriptive variable names, that helps everyone else who looks at your code to debug it
please do not use variable names like "in", "bg", "bg_x" etc
rather call them "inventory", "itemstack", etc
e.g. I have no clue what "bg_x" is
alr lettme rework the names
I think it's control+shift+F6 in intellij
then it automatically renames it everywhere
it's just Shift+F6
just put the "text marker" on the var name, then press Shift+F6, then enter a new name
ale ty
I have just observed very weird behavior and I'm curious for an explanation
Gson before = ReflectionUtils.getStaticField(ClientboundStatusResponsePacket.class, "a");
new StatusApplier().injectJson();
public void injectJson() {
UnsafeUtils.changeStaticFinalField(ClientboundStatusResponsePacket.class, "a", GSON);
}
I am working with Gson formatting in NMS, I am injection my custom GSON formatting, but to start I'm just copying impl nms to make sure the fields replacing. Oddly enough if I observe the before value than inject my GSON the code errors out
[00:58:27] [Netty Epoll Server IO #1/ERROR]: Packet encoding of packet ID 0 threw (skippable? false)
java.lang.StackOverflowError: null
``` with an overflow as well
however if I remove the observation no error occurs, but no changes occur when I switch over to my custom system as intended. The only think of is some weird optimizations by the jvm have caused the field to not actually be changed properly or something along those lines
player.setAllowFlight(true);
player.setFlying(true);
``` is not working! why?
i'm using imanity spigot but is not the issue
?notworking ๐คท๐ฝโโ๏ธ
"Does not working" is a useless statement. Please describe what exactly is not working, what you expect it to do, and what actually happens. If you get any console errors, also ?paste the entire stacktrace.
hmm
public static void playerJoin(Player player) {
playerClear(player);
LocationUtils.safeTeleport(player, Major.spawn);
if(topOnline != null) {
try {
topOnline.display(player);
} catch (Exception ignored) {}
}
if(topClans != null) {
try {
topClans.display(player);
} catch (Exception ignored) {}
}
player.getInventory().setItem(1, generateItemStack(
Material.BLAZE_ROD,
Major.C("&6Fun&eGun"),
Major.C("&8"),
Major.C("&7Wooho")
));
player.getInventory().setItem(0, generateItemStack(
Material.COMPASS,
Major.C("&9Game Menu"),
Major.C("&8"),
Major.C("&9Browse our games")
));
player.getInventory().setItem(8, generateItemStack(
Material.ENCHANTED_BOOK,
Major.C("&eShop"),
Major.C("&8"),
Major.C("&eOur store"),
Major.C("&cWe are no longer selling on the site")
));
boolean has = hasPerm(player, "pgxpo.fly");
player.setAllowFlight(has);
player.setFlying(has);
ScoreBoard.toPlayer(player);
}
``` is that good for you? and the `has` var is true i'm checked that
and this function executed from the join event
and for no reason the player cannot fly
player.getInventory() returns their actual inventory, not the inventory their currently have open
idk if that helps
the issue is the player cannot fly, the inventory is good
are you calling that method on a player join event
okay yea i cant figure out the issue
@EventHandler(ignoreCancelled = true)
public void _join(PlayerJoinEvent e) {
e.setJoinMessage(null);
System.out.println(e.getPlayer().getName() + " Joined2.");
Major.playerJoin(e.getPlayer());
}
``` is thats okay for you?
do you have any other plugins installed?
sure
those conventions tho lol, but I'm not sure tbh\
e.g. Essentials automatically removes fly if they don't have essentials.fly perm IIRC
yep, custom perms plugin, this plugin, multiverse core, spark
try to remove all other plugins
then see if it now works
Do hashmaps clear after calling get on them
if yes, it's another plugin causing this
no, it stays
Im like 99% sure they dont
it definitely stays
why would they clear that seems so random
100%
Okay then there is 0 reason for it to be blank afterwards then
My hashmap clears after running a function
For 0 reason
hmm ima try to remove some plugins
you have a List<UUID, HashMap>
Is that supposed to be a list?
and in createInventory, you call invList.put(..., new HashMap)
ima bump since alex might be smart enough to know random jvm shit
I don't even know what your hashmap is supposed to contain, your variable names are really a bit weird
lmfao
Mine is a HashMap<UUID, HashMap<String, Object>>
the issue from the multiverse core! wow
sry but I have no clue about Gson, I always use SimpleJson or however it's called
put("ClicksR", 3);
put("Inv", inv);
put("AllowC", false);
ClicksR is how many lottery tickets before its allowed to autoclose
Inv is inventory
AllowC is if its allowed to close or not
its moreso a JVM question tbh because I copied mojangs mapped code
is simpleJson easier to use than gson
imho yes
link it
simplejson basically always just turns a json doc into a Map<String,Object>
it is?
it just confuses me since the GSON i injected only causes errors when the old GSON is observed prior to injection, but if its not observed nothing occurs. this is like some quantum physics hsit
I might be mistaken, it's 8 am and I am still awake
im gunna go to the store to see if maybe my brain is just fuzzy
ill brb
Object authenticatedUsers = getAuthenticatedUsers();
``` getAuthenticatedUsers() returns a JSONParser. this json/object/thing is a list. how do I loop over it???
first of all, you should literally never use a Map<String,Object>. you should just have three different hashmaps, or create your own class to hold those three values
how do I even get a element from dis
what json lib do you use?
import org.json.simple.parser.JSONParser; lmao
so what create 1 hashmap for the inventory, one for clicks and one for closing
my favorite json library org.json.simple.JSONParser lmao
found it online
then you can do sth like this:
JSONParser parser = ...;
while(parser.hasNext()) {
Event next = parser.next();
// Do sth
}
wat
but when I do JSONParser.parse(mystring) it returns a Object
java is weird bro
you have made a cardinal sin
spotted the JavaScript dev
I am python enjoyer
oh I see, I checked the wrong javadocs
oh lord
Object is superclass of every class in java, it probably means that it can return any "object", not sure why they are not using generics but yeah
troll
you can usually cast your "Object" to JSONObject or JSONArray, or String, or Number, or Boolean
how does your json string look like?
then it's a JSONArray
how is the method supposed to know whether it's a JSONElement, or a JSONArray, or a String, Number or Boolean though
imo, gson is better than this
of course it's better, but it's also more complicated
Gson has TypeAdaptors and stuff. that's only useful if you have complicated data
the same ig, but the primitive is confused not gonna lie
i have simple data
if you just have a simple array, then you just cast your stuff to JsonArray and that's it
yas
nope, you can do it the same as this btw
did you just call me a monkey indirectly LOL
I know, but gson is still more complicated
ha? what? xd
he's talking about primates, not primitives, lol
thats true, but for a good performance.
what the hell are primitives
?learnjava
Here are some links to get you started on learning Java:
- https://www.codecademy.com/learn/learn-java
- https://www.sololearn.com/learning/1068
- https://www.learnjavaonline.org/
- https://programmingbydoing.com/
- https://docs.oracle.com/javase/tutorial/java/index.html
The last one is the only official one, however some of those concepts assume that you already know a bit about programming.
int, string .. etc
is it a weird java thing
String are NOT primitives
lol
mb i just drop every data type
n o
byte and chars is primitive too
i refuse to commit cardinal sin ๐
well
if you mean char[] by using the word "chars", then they are arrays, which indeed are objects lol
it's a bit confusing
if you talk about a single char, then you are right
dude its not 100% as i'm say xd
mb
java indeed is weird, I never understood why primitives even exist
javascript > java
everything should be an object, like in lua or in python
HELL NO
lol
no
that doesn't change anything
it could be final, but its just a small optimization
yeah but it won't fix their problem
I misunderstood method, trough its deserializing object for some reason