So i wanted to edit what a mob drops upon death using(event.getDrops().add(). I know how to setup everything, and i am using an integer list, so a user can set values in of items. Everything works, but i noticed you cant enter items with colons like 5:2 5:3...etc. Is there any workaround for this? r any specific way this is done?
Store a string list instead. Check if the string contains ":". If it does, use String [] newString = string.split(":"); then do something with newString[0] and newString[1]
Here is some code i tried, and it is same as normal. It drops the items on death, but will not spawn the items such as 5:2 and such. I added some messages to show whats happening, but it seems as if the If Statement that checks for the contains doesnt even execute. Code:java event.getDrops().clear();List<String> setdrops = plugin.getConfig().getStringList("General_Zombie_Modifications.Zombie_Drops");for(String drops : setdrops){if(drops.contains(":")){String[] string = drops.split(":");Bukkit.broadcastMessage("--"+drops);Bukkit.broadcastMessage("--"+string[0]+" "+string[1]);}ItemStack test = new ItemStack(Integer.parseInt(drops));event.getDrops().add(test);//Add Specific drops mode}
Don't store it as string, you would need to calculate it every time. Create new class for it or use ItemStack.
I hav't done much stuff with splitting strings and stuff, so how would i go about doing it? Making a class out of it? Or saving it directly to an itemstack? But the first problem is it seems like the If statement checking for the .contains) doesnt even execute.
Code: public class ItemAndData { public int id = 0; public short data = 0; public ItemAndData(int id, short data) { this.id = id; this.data = data; } } then Code: List<ItemAndData> items = new ArrayList<ItemAndData>(); items.add(new ItemAndData(5, (short) 2)); items.get(0).id; items.get(0).data;
@raGan I was messing around with some of that code, but i went back to my default way, and i found a way that works. What was wrong was whenever there was like 5:2 in the config it would come out as 302 in the actual code. For some reason it multiplied the first number by 6 and added 2 at the end, Which i found weird. But i found a way that works, so in the config they would just enter 5,2 and it would give a birch plank. Here is the code: Code: event.getDrops().clear(); List<String> setdrops = plugin.getConfig().getStringList("General_Zombie_Modifications.Zombie_Drops"); for(String drops : setdrops){ if(drops.contains(",")){ String[] string = drops.split(","); ItemStack items = new ItemStack(Integer.parseInt(string[0]), 1, (byte)Integer.parseInt(string[1])); event.getDrops().add(items); }else{ ItemStack test = new ItemStack(Integer.parseInt(drops)); event.getDrops().add(test); } } I used RealDope 's way kind of. But the only thing i cannot get to work is Mob Heads. Whenever i try to drop one on death, it gives this weird looking block, and when i place it it just places a skeleton head. Same with when i want it to drop a zombie head, it gives the same weird looking block that only places a skeleton head. Even when i just put 144 the same thing happens. I even tried dropping the block naturally but nothing. Thanks for all your help too!
Major_Derp Both ways should work, but string solution performs much worse, since it has to be processed every single time a mob dies. It sounds reasonable to store numbers as actual numbers and just use those. Heads use NBT tags to determine head type, so you won't be able to do it with just damage value.
Thanks for the help! And i might try the way you suggested once i figure out how to set it up with the config values stuff. Thanks!
By the way, here you can find item metas to handle various special items. http://jd.bukkit.org/doxygen/d0/d60/namespaceorg_1_1bukkit_1_1inventory_1_1meta.html