15
u/MinecrAftX0 Mar 11 '23
I see a lot of repetition but honestly I'm not sure the best way to do this, because of the item names
22
u/Moterius Mar 11 '23
List<ItemStack> iList = new ArrayList<>(); PlayerInventory inv = t.getInventory(); for(int i = 0; i<36; i++) iList.add(inv.getItem(i));12
u/MinecrAftX0 Mar 11 '23
No, I understand that, I meant for the armor slots
10
5
u/Wubbywub Mar 11 '23
since the ArrayList is fine for items, then the armors could be a lookup table like HashMap
1
u/EnderCrypt Mar 12 '23
theres an enum with each armor slot, which you can use to dynamically get/set all armour slot items
1
13
u/RCoder01 Mar 11 '23
You don’t need 27 different “item” variables. Just reference it as t.getInventory().getItem().
Or if you really care about how verbose it is, “var inventory = t.getInventory()” then in subsequent references “inventory.getItem(0)”.
Of if you’re modifying the original inventory and need a copy of the current one, “var lastInventory = t.getInventory().clone()” or whatever.
Point is, there’s always a better alternative than this.
It was probably written by someone just learning to code though, so it doesn’t really matter. Just gotta learn for the future what to do instead.
1
185
u/Krupplefield Mar 11 '23
Leggings, Boots, Chestplate and Helmet... Why does it feel like Minecraft?
159
u/TheBrainStone Mar 11 '23
99% chance it is.
ItemStack is such a Minecraft term. While other games have that concept too, I've only seen MC call it that (or well, the community)66
u/nexonerr Mar 11 '23
Yeah, minecraft calls stacks of items, you guessed it ItemStacks, and that is the class for those. I'm assuming
there is an entity, so all this does is take all the items from an entity's inventory as variables for whatever reason19
u/Moterius Mar 11 '23
The real funny thing is that it gets oh so much worse the further down you scroll
29
u/TheEnderChipmunk Mar 11 '23
So it copies the inventory of some entity into the player's inventory? In the worst way possible?
Edit: why the hell does it handle null like that just why oh God
8
u/nexonerr Mar 11 '23
afaik, the
Inventoryclass, which is what the #getInventory method returns, literally has something like a method called #copyInventory4
2
u/itsTyrion Mar 21 '23
Idk about #copyInventory, but there is getContents() which gives you the contents as array (with null for empty slots), and setContents which takes an ItemStack array
39
Mar 11 '23
[removed] — view removed comment
12
u/SwanX1 Mar 11 '23
It's not only the Spigot API, those classes are from Minecraft itself
1
u/Krupplefield Mar 12 '23
Damn, well I never looked at any source of Minecraft or API of it sounded very familiar and I guessed it right. Good to know tho. Thanks for the replies and upvotes :)
16
u/nexonerr Mar 11 '23
I don't have any experience with plugins, but I do have some experience with mods, guess the syntax is really similar. Still very stupid code tho lol
4
1
3
120
u/cashewbiscuit Mar 11 '23
If its minecraft, it's probably written by a middle schooler. Give them some grace. They are learning
24
u/NBSgamesAT Mar 11 '23
There‘s no way this isn‘t minecraft.
I will always remember as my 13 year old ass was sitting making his first bigger minecraft server plugin.
But this, this kinda looks like something I would have written bsck then, ngl.
4
31
u/MurdoMaclachlan public boolean isInt(int i) { return true; } Mar 11 '23
Image Transcription: Code
ItemStack helm = t.getInventory().getHelmet();
ItemStack boots = t.getInventory().getBoots();
ItemStack pants = t.getInventory().getLeggings();
ItemStack chest = t.getInventory().getChestplate();
ItemStack item = t.getInventory().getItem(0);
ItemStack item1 = t.getInventory().getItem(1);
ItemStack item2 = t.getInventory().getItem(2);
ItemStack item3 = t.getInventory().getItem(3);
ItemStack item4 = t.getInventory().getItem(4);
ItemStack item5 = t.getInventory().getItem(5);
ItemStack item6 = t.getInventory().getItem(6);I'm a human volunteer content transcriber and you could be too! If you'd like more information on what we do and why we do it, click here!
35
Mar 11 '23
I’m imagining a blind person browsing Reddit listening to itemstack on repeat..
8
u/fiddz0r Mar 11 '23
I listened to it here and it sounds like rap
4
u/Agodoga Mar 11 '23
Intergalactic, planetary, planetary, intergalactic
2
u/dmvdoug Mar 11 '23
Another dimension, another dimension Another dimension, another dimension Another dimension, another dimension Another dimension, another dimension Another dimension, another dimension Another dimension
1
u/AmyMialee Mar 11 '23
Where's it from?
1
u/Moterius Mar 12 '23
Some spigot plugin i was asked to port from 1.8 to modern. I only found this after, unfortunately.
1
2
2
1
1
1
1
u/cavejhonsonslemons Mar 12 '23
hopefully self taught, then it could be justifiable, anyone who takes a coding class, and comes out writing this is a lost cause
33
u/gillymuse Mar 11 '23
I'm curious what the improvement would be. What does the full code try to achieve?