#help-development
1 messages · Page 222 of 1
ok
what was the problem anyways lol
I dont know how to send the packet back
change the while in the keepAlive() to if
With what error
App console no error, and neither server
then send it once built
oh ok, how i was doing with packet up?
yes
looks good
instantly or after a time?
um exit code 0 means your process finished
yeah ik
It ended itself
did you forget to loop in your main?
I removed thw while tho
But that's how keepalive works. It needs to be constantly sent on a frequent basis.
you have to loop to keep reading new packets
I need to compact tha tinto the lib
Not doing it on program main class which uses the library
[20:43:04 INFO]: FakeClient lost connection: Internal Exception: io.netty.handler.codec.DecoderException: Badly compressed packet - size of 20 is below server threshold of 256
Still having that shity error
😂
Boost the size to 256 then
Hmnn
I dont even understand the shity exceptions
Because the protocol is so well designed
😡
You compressed the packet into a size of 20
But the server wants a size of 256
im not compressing it?
Check for every class that sends packets
Wtf
There 3 methods only on tha class, Handshake, Login and keepAlive()
It must because im not sending correctly the packet
Then handshake and login?
They are okay
It just the fkng keepAlive()
Its really diff, because there is no fkc example about sending packets
Just tell what ** to use in the packet itself, but not how do to send it🤡
It's just like last time I tried discord websocket
Sent a keepalive but they boot me off instead
But the same problem here
You got kicked for compressed size
I got kicked by false keepalive
Sometimes it's hard to use something without libs
Find a mc protocol lib
And build on it
hmn ok
https://paste.md-5.net/megalijaxo.cs
cant figure out why this is happening
Does your plugin have 2 classes extending javaPlugin?
public final class Kingdoms extends JavaPlugin implements Listener is where it says its at
no
Its saying that your pluign is already initialized
You're reiniting your plugin somewhere
yeah
FakeClient lost connection: Internal Exception: io.netty.handler.codec.DecoderException: Badly compressed packet - size of 32 is below server threshold of 256
Loving shity mc prtcol
🤣
I'm going to guess you are in offline mode
change the min packet size in server.properties to 32
Im testing it in offline mode
Is that the problem
That?
LMAo too much problems
you could change it to 0 for no compression
ok
[21:08:09 INFO]: FakeClient lost connection: Internal Exception: io.netty.handler.codec.DecoderException: java.util.zip.DataFormatException: inflate data is bad
Hahaha
Errors, erros and more erros, shity protocol that doesn thav a lib
maybe the mc version?
Sever runs spigot 1.19.2
No bruh
I will send code
Because im really stressed with this
[21:10:02 INFO]: FakeClient lost connection: Internal Exception: io.netty.handler.codec.DecoderException: java.lang.IndexOutOfBoundsException: readerIndex(2) + length(1) exceeds writerIndex(2): PooledUnsafeDirectByteBuf(ridx: 2, widx: 2, cap: 256)
shity protocols
😡 😡 😡 😡 😡
🤡
Yeah
Why dont the fuck just make a library
Instead of making us devs to have headaches trying to figure how their shit works
hello
could anyone help me?
Utils.getConfig().getInt("Elves.player-avoid-distance"),
Utils.getConfig().getDouble("Elves.player-avoid-speed"),
Utils.getConfig().getDouble("Elves.player-avoid-speed")));```
but my mob isnt running away from player, can anyone tell me what i am doing wrong?
why the fuck do they use a, b, c, d, e, f, g etc. instead of using normal variables names
obfuscation
wdym
protocol is quite well documented for the most part
oh ye, that makes sense
also of note, obfuscation can make the overall binary smaller too
but they are making things so difficult 😭
thats the point im pretty sure
anyway, anyone?
ye maybe
The point is both to make reverse-engineering harder and to make the binary smaller. Removing long variable/method names helps reduce the binary size by quite a lot.
thats makes sense
*that
but i am dying inside
and i can't find a way to fix my problem 😫
I try but i dont udnerstand how to format the packet
What version of MC
Me?
Not you
I thought it was a reply 
oh haha
well you not understanding how packets and networking works isn't the fault of other devs or other devs making it too difficult.
Yeah i dont understand how they serialize
as a bytearray ig
😬
the only serializing that happens is if compression is used or not, otherwise the network card handles serializing the data into binary
Really thanks mate for recommending a library instead of doing it myself
I mean i would not use the full library i will definitly try take from it the things i need
Because its like 8mb library
how do i get all files within a directory
Files.listfiles or soemthgin close
does anyone know if Path#getFileName() returns the file extension bc the jdoc just says
Returns the name of the file or directory denoted by this path as a Path object. The file name is the farthest element fromthe root in the directory hierarchy.
Returns: a path representing the name of the file or directory, or null if this path has zero elements
extension is part of the file name
alright don't listen to me then
It does include the extension
extension is part of the filename, and the OS only makes that distinction for viewing purposes, but from a programming perspective it isn't separate
i knew what you were saying but i was just saying it doesnt really make sense
That is correct
But to answer their question: yes, this method does include giving you the extension
For sure you basicly answered, but just to make it clear
it is why I provided that last bit before you said I was correct 😛
Ok
File#listFiles()
File dir = new File("path/to/dir");
File[] files = dir.listFiles();
Any idea how can I exclude sqlite jdbc dep natives (am I even able ? ) because its like 23mb
wft
Isn't it a provided library?
SQLite lib is not 23mb
it is
Then just set the scope to provided?
Im not using it with spigot, just general question
Sqlite is already bundled with Spigot
natives take more then 20mb
Ah
why tf is it 23 here then
<dependency>
<groupId>org.xerial</groupId>
<artifactId>sqlite-jdbc</artifactId>
<version>3.39.3.0</version>
</dependency>
using this
🤦♂️
does anyone know a good plugin for random kit pvp servers?
Wrong channel
#help-server for none programming
Ask in #help-server
Please use the correct channels - Thanks
np
OfflinePlayer p = Bukkit.getOfflinePlayer(name);
ItemStack is = new ItemStack(Material.PLAYER_HEAD);
SkullMeta m = (SkullMeta) is.getItemMeta();
m.setOwningPlayer(p);
is.setItemMeta(m);
why with this code i got a steve head ?
but when i place it, it work
(and also i saw the data of the head is by value and when i place it, it's by skull owner)
have you tried picking the head up after you place it
yes and it work
when i give it i have a value and when i pickup it i have skull owner (in nbt with data command)
i mean skin on the head
when you place it and break it and pick it up
it has the skin you want
but when you give it with command it doesn't(until you place)
hmm
huh i inverted
when i give it i dont have texture property and when i place it i have
what you could do is use maven to strip out what you are not using
however sometimes this breaks libs especially ones that are also plugins, but proper libs like sqlite however it generally doesn't cause issues
just add <minimizeJar>true</minimizeJar> to maven shade configuration
as I said, sometimes breaks libs so do some testing first with the final jar to see if it still works lol
// COMMAND CLASS
public class Msg implements CommandExecutor {
@Override
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
System.out.println("works");
return false;
}
}
// also added it into the onEnable and in the plugin.yml```
Is there a new way to override the /msg command ?
also you must be getting confused between the difference of size and size on disk
the size you see, is the size on disk and the reason this may be different is because it is dependent on block sector size for the disk
for example, lets say the block sector size is set to 5mb per block, the size on disk will be 15mb because it will use 3, 5mb block sectors to store 12mb
Thanks, will try that 👍
Yeah I understand, thanks
You'd need to use PlayerCommandPreProcessEvent for that
Ohh okay.
@quaint mantle alternatively you can unregister the vanilla command from the command map
Does anyone know a way to make a player completely blind? I'm creating a gamemode that requires flashes (like in FPS games)
I need a way to make someone completely blind, not with effects tho
Because they're not completely blind
They can still see the player if he comes close
You could do that and hide all players in their radius closely than unhide them once it wears off
Otherwise ull need packet fuckery
or maybe spawn particles per player
with packets yea
that covers his vision completely
You don't necessarily need packets to hide players.
yea doesn't spigot have that in API now
If above 1.14, just make a resource pack with a white image
You can then color it with rgb n such
What is the default reason is none is provided in the inventory#closeInventory method?
Where are you seeing a reason for closeInventory?
InventoryClickEvent.closeInventory(Reason)
Sigh, Paper moment
?paperdev
Make sure to ask in the appropriate server concerning development towards different JAR types such as PaperMC. (Tip: Google them!)
fwiw, if you're compiling against the Paper API, you should probably be asking your question in the Paper Discord/forums anyways
Easy way to find out is to read the docs 
player.closeInventory()
no "reason" provided, but it's an alternative anyways
With paper the reason is probably 'unknown' by default
is it possible to save Objects into ItemStack’s NBT Data? Objects like: List and HashMap
Big question is: why
?pdc
If you serialize the data into base64 pretty sure you could easily store it into pdc
Possible? Yes. Do you want to? Probably not.
Yeah considering items can sometimes magically disappear
If that happens well there goes your data lol
I was thinking about that
well my idea is just to make Inventories from the Item’s NBT Data
and continue with sub inventories
You are better off using something similar to schematic files except with inventories. Items are subject to just being removed.
If the item drops, you will lose all the data with it
the items will be in a GUI so they are not gonna be droppable
but I’m thinking for other possible ways too
like what’s the best way to make a GUI which will list some folders and then you can open each one close it create new folders
Since you are already going to have a custom inventory you might as well just use file storage or db storage for the data.
like windows file explorer
file storage can be a good solution
idk how to call it maybe Recursive GUI
@kind hatch Did you test this yet?
How do I spawn a vanilla mob in a different biome
Ive got some nms code setup but it's not working
I ended up just creating dirty by sometimes replacing animals with the mob I want on chunk load
i think you can change spawning rules with datapacks
is there any good website for learning java
i tried w3 but dont understand methods
?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.
Another one that isn't on the list is Udemy. It has really good java courses, but they aren't free
Tim Buchalka Is a really good instructor for it
All the basics would be a good start. As well as things like inheritance, try and catch, abstract
That's just a java course lol
thanks
?di
Guide to dependency injection: https://www.spigotmc.org/wiki/using-dependency-injection/
That's also good info to have @cerulean lynx
this. tells Java that you are setting one of the class's properties rather than a property in the current scope
so since you have two variables both named plugin (on in the class, one as a parameter) you use this. to set the one in the class
public class Test {
private final Plugin plugin; // <- This is indicated by this.plugin
public Test(Plugin plugin) {
this.plugin = plugin; // "plugin" is the variable in the constructor
}
}
alright thank you
methods are the equivalent of functions in other languages if you know any
ServerConnectEvent is called before the connection is even being made. What is called if that cinnection fails?
Eg. Player does /server test1
Test1 is down however so bungee tells them that it's down
What even is called when a connection isn't made?
FREE JAVA LESSONS
What
ClickEvent.Action.RUN_COMMAND executes a command from the player, can it execute command from cmd?
No
The client just sends the command to the server
It's executed as if the player typed that command into the chat and sent it
if you want to execute a command from the console, use Bukkit.dispatchCommand(Bukkit.getServer().getConsoleSender(), "command here without splashes");
Why do u want it to execute a xommand frm the console?
could be many reasons
i cant do it in BaseComponent event
If they click it twice itll run the console command twice
then make a command that executes the correct command from the console
This is possible
But if you wanna be more secure
You can make the command something like /<uuid here>
like /playercommand, which will make console execute your required command
And check the command pre process event
HashMap
I did it, but maybe there is any better method to do it
And use uuid to match up the commands
mmmmmm probably but I dunno
So let say you'd like to use the command /eco give steve 200
But you don't want them spamming it
Assign a random uuid to the command and put it in a map
instead of UUID, do a HashMap. .-.
More easier and can be set whatever they want to. Just make sure not to make it spam any errors after the execution of the command
Yes, and use a runnable that runs every x amount of ticks to hide players in sight of the player
both should work, but HashMap is probably better
Personally I'd use the uuid method
well, depends on everyone's mind
Uuid with a hashmap
they either execute one, or both 😹
You'll need a new hashmap for every new command you'd like to excute
What’s the correct way to check if a player clicked in a specific inventory
Comparing the InventoryHolder
Could you give me an example of that?
and creating your Inventory with a specific one
Let me find the project I used this in 😅
Yea I checked if the player that triggered the oninventoryclick event clicked in an inventory with the name equal to the name of the inventory I created
I think by using getWhoClicked() but I did it last night at like 3am so that’s probably not the right method call
Anvils can be renamed which also renames the inventory iirc. So that's not the most secure way
If you rename an anvil inside an anvil (or might also work for chests) and you place it. I think it keeps the name
Maybe I can make an inventory class and j check if it’s in an instance of that class
But that seems super complicated for a simple task so they’re definitely a better way at going about this
yeah you check the inventory holders instance usually
Bukkit.createInventory(new MyOwnHolder(), size, name)
...
}
And in the InventoryClickEvent you just check
if (!(inv.getHolder() instanceof MyOwnHolder)) return;
how is that not easy? o.o
Why would implementing InventoryHolder be a problem?
So you'd rather implement or extend your own Inventory class?
But then you have to keep track of each inventory that you open for a player. This way the holder (which is stored inside the inventory) is used to keep track of it
It just seems overkill if you can use the holder. Especially since it would be null if you don't use it for that
How would u do it w maps
You can use InventoryView right?
That’s what I did
I see, alright. I'll keep it in mind
You mean a custom Anvil inventory?
yeah that would make sense. So far I only did normal inventories
Wait but would you set Anvil as the InventoryHolder for a custom anvil inventory?
Oh so it's done in createInventory I suppose
Is there an easy way (or any way) to listen for a shrieker shrieking? I thought that I might find a ShriekerShriekingEvent or something similar, but I wasn't able to find anything?
where can i report bugs?
As usual. What seems to be the problem?
Well then you are in a static context. That's not the schedulers fault tho.
Can I give the player an item with which he can click on e.g. an iron door to lock it and then give him a key to open said door?
you can
ooo
Welcome to the world of coding 👋
i have searched for a while now and i figured i'd ask :D
Thats probably something you would have to make yourself via a plugin
or have someone make for you
yk, i've been developing a large server-system (currently on 1.16.4 but i'm planning on migrating to 1.19.2 once i figure out how easy that is) and this is just a thing that popped into my mind a while ago but i haven't found a solution
ofc
hopefully you arent paid
wdym by that?
:D
lmao
am i not getting jokes rn? sorry lmao
my brain has been dead for the last couple days
Couldn't find anything either :/ You could check spigots code on how they figure it out and use the same code / use reflection. But that's certainly not easy
What are you planning to do?
I guess, check spigot api, maybe there's an event
or did you try that already?
maybe you should try that
I thought that I might find a ShriekerShriekingEvent or something similar, but I wasn't able to find anything?
thats what developers do
Constantly check the warning level 5head
https://hub.spigotmc.org/javadocs/bukkit/org/bukkit/block/SculkShrieker.html
declaration: package: org.bukkit.block, interface: SculkShrieker
not even in the api anything at all?
hm
mb
💀💀💀💀💀
There even is "isShrieking" but then he would have to find all sculk shriekers before
or just the ones within range of a player
Try blockphysicsevent or similar
Since nobody seems to like phantoms, I had the idea to rework them. My idea was to have the 2nd shrieker shriek summon in a few phantoms, since they seem to be a good fit for the deep dark area/dungeon thing.
This would have phantoms be a thing that is caused directly by something the player does rather than just something that happens to the player randomly for not sleeping
i was just gonna say that
Yes you don't want static unless it actually makes sense
I think the warning level is stored to the player. So you could check that every few ticks
i hate static so much lmao
Good idea, Ill give this a shot and see what I can work out
You could also listen for when a sound is played to the player
I imagine there is a way to get the block source of the sound
and only then do you have to check whether its a skulk sensor
plays on mute I hate phantoms /s
We're probably not seeing smth very obvious for the shrieker lol
Must be some interact / change event or something
That's still a lot of iterations depending on how fast the player is travelling
I don't know whether the shrieking is handled client side though
no iteration needed?
Prior to posting here, my best idea was to try and catch when the shrieker particles are sent to the player, so not far off of my line of thinking
So how do you find shriekers around the player without checking close blocks?
I'm thinking purely off the playsound command here but don't sounds that are played to the player have a source?
you'd just have to check the sound source block
Oh you wrote that before you started the sound thing. So I didn't take that into consideration, sorry :D
You remove static and use either DI or an actual object?
https://wiki.vg/Protocol#Sound_Effect
The effect position is inside this packet so could work
I assume the shrieker isn't client side since the warden spawns after x number of shrieks
Then do it
GenericGameEvent - GameEvent.SHRIEK
That's a lot simpler 😆
public void onUseKeyInteractable(PlayerInteractAtEntityEvent e) {
Player p = e.getPlayer();
ItemStack item = e.getPlayer().getItemInHand();
if (item.getType() == Material.NAME_TAG && item.containsEnchantment(Enchantment.LUCK)) {
e.setCancelled(true);
}
}```
Can someone explain why tf this code won't work? I don't get it (yes, the if-statement is reached)
"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.
<player>.inventory.getItemInMainHand
@white root btw ^
Ah, lemme look into that
not?
that's definitely the proper way of doing it. No idea that event existed
i found it by searching for shriek on the papermc discord xd
Uh, another thing, how do you listen to a/the GenericGameEvent?
i think it's the new event system mojang added
just like any other event
Im compiling against org.spigotmc:spigot-api:1.9.2-R0.1-SNAPSHOT but intellij doesnt seem to know what that is
https://uploadi.ng/🔮👔📻🤾
1.9.2?
yeah, typo in my build.gradle lol
💀 howd you get it lol
A bit like a unicorn am I?
been a while since I've seen another in the wild
kotlin user when
didn't even clock in the screenshot, it took me till you said you were using gradle
I thought this doesn't sound like a java developer
I use kotlin at work but code java outside of work so I don't forget everything :D
We still use maven with kotlin tho 💀
💀
Hi is there any good tutorial on how to use packets to spawn , and munplate entites?
makes sense since kotlin compiles to java bytecode
once you use gradle there's no going back to maven
Can confirm
Not much of a wonder considering how painful maven multi module builds are
and there's no need to rely on plugins for everything. If you want something to happen during your build you just code it rather than getting a plugin that does it
just makes sense
Maven is highly customizable
there really isn't anything maven can't do
majority of people who see or complain of maven going slow is due to the fact they haven't learnt maven or bothered to configure it properly
People forget you can just make custom maven plugins
making a custom maven plugin is no more difficult then making a plugin for spigot
you can even have maven execute build scripts too if you really dislike maven that much or you can combine maven with ant as well
not sure why this is painful for you
in either case which you want to use is mostly preference. The majority here will most likely never see any differences between the two because you really need super large projects to really see the difference.
maven by default is configured to be conservative with resources
you need to modify the maven config or add it to your pom to allow maven to use more resources. As well as concurrent building
Yeah totally it’s preference
I don’t really have any massive projects, but the small things that I do utilise are much easier to make in gradle than maven from my experience
And not sure if this is just a kotlin thing, but by default gradle is definitely slower than maven
well ease of use is mostly down to what makes sense to you. For some gradle makes sense, for others maven does. I prefer maven because literally there isn't a problem I can't solve with it build wise. I can either find a plugin to resolve whatever issue or provide some functionality or I can make one.
this is probably due to the fact that on small stuff you can't really take advantage of where gradle performs
Bro is a class a jester
Got me giggling n shit
Oh yeah I definitely don’t use gradle to it’s full potential
well at least you know you are 😛
But I was definitely worse with maven
I would do so much manually
And maven is a joke for kotlin development
I don't use kotlin so I can't really say
I’ve never had a problem with maven using Java
Does anyone use gradle to its full potential? Seems like its so jam packed with stuff that'd be near impossible
gradle is complicated
Well unless you are using a kotlin JVM, kotlin compiles to java bytecode
gradle is designed to be optimal for long running builds
like builds that can take hours or even a day or so
oh hell nah 
gradle's onl advantage for me is for big ass projects
other than that it only causes problems
I get impatient when my build takes 30 seconds
For example, compiling something like Firefox
Of course, but telling maven to ‘compile’ kotlin and customise as you need it a lot more difficult in maven
Firefox literally can take you half a day or more to compile XD
I used to use brave-git from the arch AUR and rather than use their binaries it recompiled the browser
Every
Fucking
Update
lol
Took forever
Of course that wasn’t using a JVM language but gives you an idea of how long a build actually can take
in a more professionel environment you just commit to the branch and it gets automatically built every 3 hours or so. you only notice if you get an unfriendly mail that you broke the build
when I had a dual core it took me something like 18-20 hours to compile firefox I think it was
That’s why you don’t push to main
Makes sense
yeah getting mails from the git blame
svn 🤡
They knew what they were doing when they made that command
svn is alright until someone messes up the history
Blame
Reminds me of OBS change logs where they blame the person for bugs directly
Haven’t ever used a source control other than git and don’t plan to
it really sucks. git would be 10000 times better
might be more of inside joke more then anything lmao
Still pretty funny
well git has its downsides where svn is better
Probably, but I haven’t had issues
svn is really easy to use and doesn't take much to set up, where it becomes a hassle is when you want to rollback something
If it ain’t broke don’t fix it
git push -f
ah yeah, just force the commit because you don't want to actually fix the problem 😂
but even some people do what you would do on SVN to fix problems with git
for example, on svn instead of trying to rollback a change, you would just commit again with the changes reverted
and you just pretend the history is all fine and dandy XD
people who use git kind of do the same thing and don't bother with the rollback features
the other advantage of git is that everyone has a local copy, where as in svn you don't and thus you can't have multiple people checkout the same thing so file locking can be an issue sometimes
especially if someone forgets to checked in what they checkouted
no, you are all on the same branch most of the time. But with SVN there is a server that maintains file locks
so if someone checks out a file
someone else can't check it out
so you have to wait for that person to make their changes, so you can make yours
i guess that stops conflicts but that just doesn't sound very productive
it is, and it does work with large projects because it prevents a single file from being edited by multiple people who most likely are not even talking with each other
git does alright with this, but even git has its limitations when it comes to merging
does it follow the same general workflow of new feature -> new branch?
for large projects I guess that's followed more closely
ironically git was created in 2005
yes but it works slightly different
every branch is a directory inside of the repo
also svn is more performant when it comes to large files as well or super large projects
also when it comes to permissions, git is very limiting. SVN allows you to set permissions all the way down to per file permissions and per directory
yeah I've had to deal with incompetent developers before me pushing gigabytes of data to a repo and of course when you clone or create a new branch the entire history goes with it
that does sound quite handy
so svn is still used, just its has its strenghts and weaknesses like git has its strengths and weaknesses
as everything will
for small to medium projects git is probably the best especially if you don't have too many people working on it
medium to large projects with quite a lot of people probably best to use svn
another handy thing is, that unlike with git not just anyone can change the history with svn
you need access to the central server itself to change the history
with git, all it takes is someone to push the history to mess it all up for everyone else
wait so uh if i do smth like HashMap<String, int>
would i need to have that identical string object to be able to match it
cuz like
yk how you cant use ==
no
because if my issue aint that i dont know what it is
String keys are not compared by instance
okayyyy um.. how about a string array
are string arrays compared by instance
No clue, but probably
fuck..
it simple to test
You have IdentityHashMap at your disposal if you need identity based keys where it uses System::identityHashCode
i might just be a lil stupid but wdym by identity based?
For any a and b, a and b are considered to be the same key if and only if a == b
ah
yeah no thats not what i need
i have like a custom recipe system where I have a String[] of keys for items and a Recipe object for recipes in a hashmap so like Hashmap<String[], Recipe> and I need to make it so that String[] matches with any identical string array
HashMap<String[], Integer> map = new HashMap();
String[] str1 = new String[] {"a", "b", "c"};
map.put(str1, 5);
System.out.println(map.get(new String[] {"a", "b", "c"})); // so like this should also return 5 instead of null
System.out.println(map.get(str1)); // returns 5
You might just make a record around that arr
so instead of a string array i'd have a record that has 9 variables for each key?
do these recipes have names?
not really?
because you can totally use a hashmap inside of a hashmap
but i dont see how that would help?
how do I delete a World? Like if I want to delete the world's file on the server disabling what method do I use to delete it?
the file delete method
well the way you are going about it, seems very inefficient if it were me I would make a custom object to hold your string array and recipe in
yeah but then how would i find the recipe?
this hashmap is to like uh find the recipe from the items in the gui
so i get the item id of each item in the gui
make an array
and then look up in the hashmap to find if there is a recipe for that specific combination of items
it wouldn't be that hard....
what method is that, and how would I get my world folder that I want to delete?
thanks btw
i might be overcomplicating it
there is a reason why I mentioned using two hashmaps
HashMap<String, CustomObject> CustomObjectMap inside of customObject is another HashMap<ItemStack, Recipe> RecipeMap. Now all you have to do is just do this
CustomObjectMap.get(String).RecipeMap.get(ItemStack) or something to that effect anyways
you could even do it without a custom object
ah nvm I figured it out
HashMap<String, HashMap<ItemStack, Recipe>>
okayy
and um, how am i suppose to figure out what that is from 9 items in an inventory
because you can decide on the names or make it use the names of the items
okay so arent we doing the same thing?
who cares how many recipes or combinations you have, just toss them all into the hashmap....not like the hashmap is going to break
i am so confused right now im so sorry
but the way I am suggesting is instead of trying to group them all together just keep it all separate
no need to really worry about if item a is the same recipe as item b if they are both in the hashmap anyways
anyways I am tired so I am going to bed, you are making it harder then it needs to be
or more like over thinking it
Hello guys c; hope you're all fine
I'm compiling this code but when I run this command in the server, the console says "Null pointer exception"
it would be useful to send that null pointer error
Ok, gimme a sec
I assume the map or array aren't initialized
Or be a rebel and call it plugout
private static final Main main
Called it
This is what happens :c
Did you initialize the array you're adding it to?
Main line 36
This is my main
Homes and homes ahh
lul
Ugh I'm still writing my State Manager tutorial. Guess my next one is going to be a "how to read an error"
private final Map<UUID, List<Home>> homes = new HashMap<>(); 🥺
this is immensely important
Most beginners definitely don't try to understand the error
purely because theres so much text that they won't understand
Pls
You're right
Does anyone know how I could make a region and get the center block of that region?
ive been stuck on this for a couple hours
ty
just a select portion of blocks
final String[] args = getCondition().split(" ");
final String[] arguments = new String[args.length - 1];
System.arraycopy(args, 1, arguments, 0, arguments.length);
Any way to simplify this? Basically want to create an array that is a split string, but pop the first argument
how can i get the location to the right of the player depending on the perspective?
the location object contains a vector that gives the sight direction. Grab that, flatten it to the xz plane, rotate it 90° to the right
Figured it out!
final String[] args0 = getCondition().split(" ");
final String[] args = Arrays.copyOfRange(args0, 1, args0.length);
how can i "flatten" it to the xz plane?
should be part of javas math packages
i recall doing some vector math
i can check the package
ah
i substituted my math with doing it directly oops
just check the vector3d class
it should have functions to flatten to a plane
Ok guys, this seems to be working nicely, the only thing I see is that it's listing all the homes for all the players and not the ones a specific user creates
Should I add an UUID to the home class and check if that home has the sender UUID?
do you have a Map<UUID, List<Home>> in your main?
Yes
you should not compare strings with == use #equals
theres no need to keep two collections, you can just use the values() of the map
well youre iterating over some kind of collection that is not a map
in an inventoryclickevent do i need to just wait a tick to have the updated inventory
or is there anyway to force update it
Sorry could you tell me where I compared the strings using ==
or you ensure youre the latest one that applied changes
I mean I'm not sure if I used it or not
res += obj.getName() + " ";
== checks for the memory location of a variable, ::equals compares the actual content of an object and can be self defined
Oh, but it's because I want a user to be able to have many homes
we learnt loops in college today 💀
Hmmm I'm not comparing
well i cant find the proper method so heres the stupid version: set the y value to 0, then use the (0,1,0) norm vector as rotation axis
I'm just adding to the same variablew
no i meant like if the player placed an item in it
right but why is the = there
its not needed to add
do i need to wait for that change to affect the inventory in e.getInventory
you can get the changes with the appropriate event method?
=+
what is obj.getname ?
+= fuck
yea was bout to say that
atleast add a comma smh
works fine for me
the issue with this is that you're not checking if a player owns that home. youre checking if a player has a home at all, then you concatrinate all home names and return them. you need a check in the loop, or better yet, iterate over the homes of that player only.
If you're using configuration, if you try to get a configuration section it returns an empty configsection if the player has no home
so you wont get a NPE when iterating thta
Well, that's not the same thing I'm doing there...
There's so much wrong with it.
in a loop u should use a Stringbuilder
like intellij suggests you
There shouldn't even be a loop or an arraylist
true
i did string weirdness before and never got that recommendation
exposing collections go brr
hm
foo = ""
bar
shut
sorry reflex
shut
always wondering what foobar even meant
wait wtf since when is "yield" an operator in java
since the fancy switch
java 9 then
idk i use the new switch not the new operator
my copilot
return switch (state) {
case BRRR -> {
System.out.println("I'm outta here");
yield -1;
}
default -> 2;
}```
bleh
so basically in the return switch i had this multi-line expression, and apparently you need yield to return values in those
somehow that looks wrong
isnt that just the same as return -1 ?
and cant you just do -> to give a return value from a switch
return is in the return switch
ye
you can if it's a one-liner
ffs
unless you call a function exactly for that returning the value but that sounds like a bad idea
mines blue and white at least lol
long time since i did updates lol
sudo apt-get update && sudo apt-get upgrade && sudo reboot now
ill probably start dualbooting again
this is SO fancy omg
switch in a case 💀
i feel like i am coding in not java
xD
y'al should update if youre running any sort of SSH cuz there's been a massive vulnerability that's been fixed in newer updates but is about to be disclosed
or downpatch to 1.x
programmers: Math.PI
nah make a constant
Mojang moment
wtf
for what would you need that
Math.pow(5, Math.PI)
how can i do an if statment where i have a bool true or false and in the if statment if the bool is true then i pass a condition in the if statmnet
probably doesnt accept a double as 2nd param
do shit
}```
can i nest that in an existing if statment tho
You'll have to elaborate
if bool false then have
if (blockData.getMaterial() != Material.AIR && blockData.getMaterial() != block.getLocation().getBlock().getBlockData().getMaterial()) {
else if true have
if (blockData.getMaterial() != block.getLocation().getBlock().getBlockData().getMaterial()) {
like a double if statment in one
idk im in a sleep wreck trying to do this
it probably doesnt make much sense its hard to explain
You can probably find your answer in ?learnjava
Huh guess that didnt work
?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.
how do u check if a player doesnt have a shulker box with a dragon egg inside (shulker box yes, but not with egg)
Probably by fetching any shulkers they have in their inventory and checking if they contain dragon eggs?
how can i count all stone blocks in a players inventory just to have the number
then remove all of them
but thats for single itemstack no?
i need how many they have in whole inventory
or should i iterate through each slot
ohoh
itemmeta or smth
i know how to check if they have, but idk how to do the opposite
you can use getcontent and it should return everything in the inventroy
instead of == use !=
ye but how can i count like say cobblestone in someones inventory
should i iterate through all contents
or is there a better function
that will give how many cobblestones they have in inventory
oh yea probably
i couldnt find in docs
found one called getMaxStack or smthng
but idk if it returns largest stack
declaration: package: org.bukkit.inventory, interface: Inventory
does onDisable() run when the server closes, or how could I run something on the server closing?
Yeah your plugin gets disabled when the server is closed
for some reason the thing I'm doing isn't running
public void onDisable() {
getServer().getWorld("CustomCoolWorld").getWorldFolder().delete();
super.onDisable();
}``` I'm trying to delete my world file when the server closes
is there another way to do this?
The world probably isn't unloaded yet
ah
how do I unload it?
I'll google it ig
I tried unloading the world but it didn't work
the world still didn't delete
yes, but that triggers also if u have 2 shulkers with one of them containing an egg and the other empty
(so it triggers for the first shulker which doesnt have anything and then doesnt triggers the shulker with the egg)
How can I check if the attacked entity is dead in the EntityDamageByEntityEvent event?
check if the victim's health - the final damage is lower than 0
Like this? if (e.getDamage() > ((Zombie) e.getEntity()).getHealth()) {}
not really
Because it doesn't let me do the e#getEntity()#getHealth() if it's not casted. And I already did Zombie check earlier
firstly. you need to use the final damage. not this one. final damage is with armor/modifier calculations this one is without
and i would do it exactly as i said victimHealth - final damage <= 0
ait, thanks
change ur if then
This is because not all entities have health btw (arrows, experience orbs). An entity with health is a LivingEntity
int entityId = player.getEntityId();
PacketPlayOutEntityDestroy destroyPacket = new PacketPlayOutEntityDestroy(entityId);
EntityCreature creature = null;
WorldServer ws = ((CraftWorld) player.getWorld()).getHandle();
String kitName = kit.name().toLowerCase();
switch (kitName) {
case "creeper" -> creature = new EntityCreeper(EntityTypes.q, ws);
case "enderman" -> creature = new EntityEnderman(EntityTypes.y, ws);
case "snowgolem" -> creature = new EntitySnowman(EntityTypes.aI, ws);
case "chicken" -> creature = new EntityChicken(EntityTypes.n, ws);
}
player.setMetadata("spleef-kit", new FixedMetadataValue(spleef, kitName));
assert creature != null;
PacketPlayOutSpawnEntity spawnPacket = new PacketPlayOutSpawnEntity(creature);
try {
// c field
Field entityIdField = spawnPacket.getClass().getDeclaredField("c");
entityIdField.setAccessible(true);
entityIdField.set(spawnPacket, entityId);
} catch (NoSuchFieldException | IllegalAccessException e) {
e.printStackTrace();
}
Bukkit.getLogger().info("A little bit of magic for these dumb ass packets!");
Bukkit.getLogger().info("Player Entity Id = " + entityId);
Bukkit.getLogger().info("Spawn Packet Entity Id = " + spawnPacket.b());
for(Player onlinePlayer : Bukkit.getOnlinePlayers()) {
CraftPlayer craftPlayer = (CraftPlayer) onlinePlayer;
EntityPlayer entityPlayer = craftPlayer.getHandle();
entityPlayer.b.a(destroyPacket);
entityPlayer.b.a(spawnPacket);
}
Could someone shine some insight on why this isn't working. (Isn't working by I cannot see my own skin, and can't move after these packets are sent)
?paste
Hey im trying to create a chest after a players death it spawns the chest but It throws me an error
Error: https://paste.md-5.net/vetiqadute.bash
Code: https://paste.md-5.net/jacegexiwi.java
let me try
you can only read data async
generally thats the rule with spigot api
writing is not really going to possible on 99% of the api asynchronously
works thanks
You tested that pretty fast ngl
I just replaced runTaskLaterAsynchronously with runTaskLater compiled put on server reload /debug (start the game) get some items 2nd account killed me looked in chest and done
1min job
💀 you are just productive
well gota get the plugin finish someday
How
Do
You
Fix
Null Pointer Exception
???
Im sooo tired of searching the web for answers of how i can fix this problem, and i guess you guys fix it in your sleep (or just doesnt do it)
I have a List which i want accessible from another class, but im getting a null pointer exception.
"Code:"
public List<String> onCooldown = new ArrayList<>();
Why?
How do you access it in another class
are you getting it with just doing YourClass yourClass = new YourClass or are you doing it with an instance of the class in the main?
Pass it somewhere.
?di
Guide to dependency injection: https://www.spigotmc.org/wiki/using-dependency-injection/
probably want to have an object wrapping that collection with appropriate methods for crud operations tho
Why
because passing mutable collections around goes brr
youll ever fuck it up
?paste
He’ll most likely access it singlethreaded either way. Mutable != evil.
wrapping logic with your object would be much cleaner
Depends on his usage of said object.
this can be refactored to if plugin.collection.remove()
if it will remove it and return true if it was able too
Like so
you were using t as param before
if (plugin.selectedPlayers.contains(t)) {
plugin.selectedPlayers.remove(t);```
=>
if (plugin.selectedPlayers.remove(t)) {}```
That why getter and setter exists!
selectedPlayers must be used only for field or variables declarations
That its speciifed on Chapter 6, article 1 of Java programming book, "Conventions"
He’s talking about getters and setters for variables. Encapsulation
getters exist for a reason yes
Yeah, you should be using encapsulation instead of working directly over the things
I dont really care if my code is messy. It will probably only be used once, so idc how it looks like :P
Must care about it
Code messy == hard understand when needing to fix up issues, not even talking it about scalability terms
Yea, but i understand it better the way it is, plus that wasnt even the thing i had a problem with
One thing i learned about spigot is it’s pointless to point anything out.
I don’t see you using your field in your code @stone dust so please point to where the error occurs
With a stacktrace and the updated code.
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!
Learn how to ask about code
Not wondering to sound rude, but doesnt make sense asking for help without explaning the problem itself "just sayin doesnt work" and not sending any code/code "not working" ho you call it
He did send code and said his problem
So what are u talking about?
If you wont help dont do it
Its simply
Dont disturb on the channel saying not necessary things
🤔🤪
Stop being weird.
I literally asked him for further information so i could help him properly.
M
Dude Verano chill
M
Yeah sorry i really having diff days and stress with fkg obligatory exams 😬
Please provide the stacktrace and the code in which you use the variable. @stone dust just ignore the others.
The error occurs where it searches if selectedPlayers has p (Line 32 in the pastebin)
And here is the stacktrace: Caused by: java.lang.NullPointerException: Cannot invoke "java.util.List.contains(Object)" because "this.plugin.selectedPlayers" is null at live.supeer.twitchplugin.TwitchCommands.onCommand(TwitchCommands.java:31) ~[twitchplugin-1.0-SNAPSHOT.jar:?] at org.bukkit.command.PluginCommand.execute(PluginCommand.java:45) ~[paper-api-1.19.2-R0.1-SNAPSHOT.jar:?] ... 23 more
that list is null
Please follow ?conventions
?conventions
You should use a getter
I mean it is part of Chapter 6, Article 1 "Conventions" of the book of basic fundamentals and advanced programming for Java
noone knows what book youre talking about 💀
💀
The variable should not be null. @stone dust
Just follow the 4 principles of OOP + java naming conventions
Are you setting it somewhere?
and proper design patterns like Dependency Injection & Dependency Inversion
Might as well apply SOLID principles
bro verano in this case it really doesnt matter, its not professional production code
and while you're at it, use JNI to achieve better performance by writing your code in c++
Yeah what i was trying to tell him, basing on the book i bought
never heard of dependency inversion lol
jni calls are slower right
And actually you should start writing in Assembly after your first plugin
By setting, do you mean the value, or the List?
actually bytecode
make it with something more native to minecraft - redsotne
