Eggs

Discussion in 'Plugin Development' started by brord, Nov 8, 2013.

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

    brord

    Haj, im having trouble with eggs :/
    I want my eggs to not hatch.

    Code:
    egg = p.launchProjectile(Egg.class);
     
    PlayerEggThrowEvent event = new PlayerEggThrowEvent(p, e, false, (byte)o, EntiityType.CHICKEN);
    Infortunatel, it still hatches ;/
    Could anyone explain to me how to properly do this?
     
  2. Offline

    sd5

    brord Adding this event should work:
    Code:java
    1. @EventHandler
    2. public void onEggThrow(PlayerEggThrowEvent event) {
    3. event.setHatching(false);
    4. }


    However, this blocks all eggs from hatching, if you want only the ones you've manually launched you have to add some if checks to the event.
     
  3. Offline

    vtg_the_kid

    brord
    or you could do
    Code:java
    1. @EventHandler
    2. public void onCreatureSpawn(CreatureSpawnEvent event){
    3. if (event.getSpawnReason() == SpawnReason.EGG){
    4. event.setCancelled(true);
    5. }
    6. }
     
  4. Offline

    brord

    I want to cancel jsut the eggs i shoot from a certain player. (he is holdign a gun)
    But i allready call the eggtrowevent, so who would i need to listen to it again, and set hatching to false?
    The false argument in the new PlayerEggThrowEvent allready sets nno hatching
     
  5. Offline

    MunchMallow

    You could do this
    Code:
    @EventHandler
        public void onCreatureSpawn(CreatureSpawnEvent event){
            Player p = event.getPlayer();
            if (p.getItemInHand().getType() == Material.GUN HERE){
            if (event.getSpawnReason() == SpawnReason.EGG){
                event.setCancelled(true);
            }
        }
     
  6. Offline

    brord



    Well the item in hand could change in the time from shooting and hatching the egg.
    He could even loose the gun in that time, so this wont work either :/ Thanks for the input though!
     
  7. Offline

    xize

  8. Offline

    brord

Thread Status:
Not open for further replies.

Share This Page