Super Simple Spawners

Discussion in 'Plugin Development' started by KaiBB, May 16, 2012.

Thread Status:
Not open for further replies.
  1. Offline

    KaiBB

    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));
            }
        }
        }   
    }
    
     
    1. No @EventHandler notations above the event methods
    2. it'll give you a NPE because 'plugin' will be null
    3. Is the listener even registered?
     
  2. Offline

    KaiBB

    Okay, I need to find away to have my Eclipse window's title say "DON'T FORGET EVENTHANDLER".
    I always forget it. Thanks :D

    kumpelblase2
    ClassCastException at
    Code:
    egg.getClass().cast(mob);
    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 25, 2016
  3. Offline

    ZeusAllMighty11

    There's already a plugin called Super Simple Spawners.
     
  4. You can't cast an egg to a enum.
     
  5. Offline

    KaiBB

    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.
     
    Last edited by a moderator: May 25, 2016
  6. Code:
    itemstack.setData(new SpawnEgg(mob));
    that should probably work.
     
  7. Offline

    KaiBB

    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.
     
    Last edited by a moderator: May 25, 2016
  8. Offline

    Iron_Crystal

  9. Offline

    mushroomhostage

    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 .
     
    justcool393 likes this.
  10. Offline

    KaiBB

    Ugh... I've gotten to the point where I must decompile other plugins. Great. :'(
     
  11. Offline

    mushroomhostage

    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).
     
  12. Offline

    KaiBB

    And source is posted, thanks! :D

    You made it :eek:
    Nice!

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 25, 2016
  13. Offline

    dumptruckman

  14. Offline

    Compressions

Thread Status:
Not open for further replies.

Share This Page