So, I'm trying to recreate Super Simple Spawners (won't be released, mind you) and I've come across a problem. Completely unresponsive, no errors. Plugin: http://dev.bukkit.org/server-mods/supersimplespawners/ Code: package kai.spawners; import org.bukkit.Material; import org.bukkit.block.Block; import org.bukkit.block.CreatureSpawner; import org.bukkit.entity.EntityType; import org.bukkit.entity.Player; import org.bukkit.event.Listener; import org.bukkit.event.block.BlockBreakEvent; import org.bukkit.event.player.PlayerInteractEvent; import org.bukkit.inventory.ItemStack; public class ServerListener implements Listener { Core plugin; public void onBlockBreak(BlockBreakEvent event) { Block b = event.getBlock(); Player p = event.getPlayer(); if (p.hasPermission("spawner.break")) { if (b.getState() instanceof CreatureSpawner) { CreatureSpawner cs = (CreatureSpawner) b.getState(); EntityType mob = cs.getSpawnedType(); ItemStack egg = new ItemStack(Material.MONSTER_EGG, 1); egg.getClass().cast(mob); b.getDrops().add(egg); } } } public void onPlayerInteract(PlayerInteractEvent event) { Player p = event.getPlayer(); ItemStack i = p.getItemInHand(); if (i.getClass().equals(Material.MONSTER_EGG)) { CreatureSpawner es = (CreatureSpawner) i; EntityType eggmob = es.getSpawnedType(); if (p.hasPermission("spawner.place")) { p.getTargetBlock(null, 5).getLocation().add(0, 1, 0).getBlock().setType(Material.MOB_SPAWNER.getClass().cast(eggmob)); } } } }
No @EventHandler notations above the event methods it'll give you a NPE because 'plugin' will be null Is the listener even registered?
Okay, I need to find away to have my Eclipse window's title say "DON'T FORGET EVENTHANDLER". I always forget it. Thanks kumpelblase2 ClassCastException at Code: egg.getClass().cast(mob); EDIT by Moderator: merged posts, please use the edit button instead of double posting.
Maybe you should read my post. Know how I can accomplish this? I feel like decompiling the actual plugin is cheating. EDIT by Moderator: merged posts, please use the edit button instead of double posting.
Thanks, I'll try it kumpelblase2 Used your bit of code. Still isn't working, but no errors. What's the difference between Material.MONSTER_EGG and Material.MONSTER_EGGS? Something small like that could be the problem. EDIT by Moderator: merged posts, please use the edit button instead of double posting.
Looking at the Java Docs, there is no Material.MONSTER_EGG Its just Material.MONSTER_EGGS http://jd.bukkit.org/doxygen/dc/d9b/classorg_1_1bukkit_1_1material_1_1MonsterEggs.html
There is both, which you can see here: http://jd.bukkit.org/apidocs/org/bukkit/Material.html Material.MONSTER_EGGS is (confusingly) actually the "hidden silverfish" block (97), whereas Material.MONSTER_EGG is the spawn egg item you're looking for. Personally I've often found the Material enum names misleading and non-descriptive; sometimes it's easier to just lookup the IDs from http://www.minecraftwiki.net/wiki/Data_values .
That's odd the author hasn't posted the source even though he is using the MIT License.. Anyways it's not exactly the same but you may find http://dev.bukkit.org/server-mods/silkspawners/ useful - its open source and the full code is posted on GitHub (although this plugin behaves slightly differently than SuperSimpleSpawners, it could still help with manipulating spawn eggs).
And source is posted, thanks! You made it Nice! EDIT by Moderator: merged posts, please use the edit button instead of double posting.
What... The source has always been posted on the page afaik... right at the bottom. "Github: https://github.com/dumptruckman/SuperSimpleSpawners"