Stop spawneggs and water/lava from dispensers.

Discussion in 'Plugin Development' started by djmaster329, Oct 11, 2012.

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

    djmaster329

    Hello,

    Yesterday evening a random player on my server decided to abuse the spawn eggs and spawn over 200 villagers all over my creative map. He also used lava and water (I blocked bucket usage) by putting a bucket into a dispenser.

    How can I disable all spawn eggs?
    And how can I stop people from placing water/lava buckets into dispensers?

    Kind Regards,

    Djmaster329
     
  2. Offline

    llamasaylol

    Bobfan likes this.
  3. Offline

    djmaster329

    I tried this:
    Code:
    public void onDispense(BlockDispenseEvent Event){
            if(Event.getBlock().isLiquid()){
                Event.setCancelled(true);
            }
            if(Event.getBlock().getType() == Material.WATER_BUCKET){
                Event.setCancelled(true);
            }
            if(Event.getBlock().getType() == Material.LAVA_BUCKET){
                Event.setCancelled(true);
            }
            if(Event.getBlock().getType() == Material.MONSTER_EGG){
                Event.setCancelled(true);
            }
        }
    But it doesn't seem to work... :(
     
  4. Offline

    slater96

    You need @EventHandler above and need to register the event if you haven't already. Also Event is normally like event because I think there's a java util Event so you may need to put it in lower case. Read here for the new event handling.
    http://wiki.bukkit.org/Event_API_Reference
     
  5. Offline

    djmaster329

    Haha, how silly of me :p. I forgot the @EventHandler. Lets see if it fixes it :)

    EDIT:
    Nope, adding @EventHandler doesn't seem to fix it. :(

    I have found the solution.
    Code:
    @EventHandler
        public void onDispense(BlockDispenseEvent Event){
            if(Event.getItem().getType() == Material.WATER_BUCKET){
                Event.setCancelled(true);
            }
            if(Event.getItem().getType() == Material.LAVA_BUCKET){
                Event.setCancelled(true);
            }
            if(Event.getItem().getType() == Material.MONSTER_EGG){
                Event.setCancelled(true);
            }
            if(Event.getItem().getType() == Material.MONSTER_EGGS){
                Event.setCancelled(true);
            }
        }
    Now I only need to find a way to block the spawneggs when a player right clicks.

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

    sayaad

    Code:java
    1. if(event.getAction == Action.RIGHT_CLICK_AIR || event.getAction == Action.RIGHT_CLICK_BLOCK)//something like that
    2. {
    3. if(event.getPlayer().getItemInHand().getType() == Material.MONSTER_EGG){
    4.  
    5. event.setCancelled(true);
    6. }
    7. }

    That should work.
     
  7. Offline

    chenr1

    And if they right click a block? Will that still work? Havn't coded in a while so I don't really remember Also your signature is freaking hilarious.
     
  8. Offline

    sayaad

    Yea. That is what the
    Code:java
    1. Action.RIGHT_CLICK_BLOCK
    is for.


    Edit:

    Thanks ;)
    A friend who is really good at GFX made that, thought it was funny as hell.
     
  9. Offline

    chenr1

    Ok, cool. Has this been fixed since 1.2.5 because I recall that
    Code:
    Action.RIGHT_CLICK_BLOCK
    wouldn't work when trying to determine what was in your hand. I think there really needs to be an even for this.
     
  10. Offline

    Seadragon91

    To disable spawner eggs, this way is possible to:

    Code:
    @EventHandler
    public void onCreatureSpawn(CreatureSpawnEvent event) {
        if (event.getSpawnReason() == SpawnReason.SPAWNER_EGG) {
            event.setCancelled(true);
        }
    }
     
  11. Offline

    chenr1

    Hadn't seen that before. Nice.
     
Thread Status:
Not open for further replies.

Share This Page