Solved Egg Teleporting Bug

Discussion in 'Plugin Development' started by Creeperzombi3, Apr 22, 2015.

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

    Creeperzombi3

    It won't teleport me. Here's the code
    Code:
    public void onPlayerEggThrow(PlayerEggThrowEvent event) {
            Player player = event.getPlayer();
            Egg egg = event.getEgg();
            Location Elocation = egg.getLocation();
            player.teleport(Elocation);
            player.sendMessage(ChatColor.RED + "You were teleported to your egg!");
            egg.getShooter().teleport(Elocation);
        }
    }
    
     
  2. Offline

    Msrules123

    I don't know why it wouldn't work, unless you didn't register your event.

    egg.getShooter().teleport(Elocation);
    ^ Also, don't know why you did that, you already have the player stored as a variable.
     
  3. Offline

    Konato_K

    @Creeperzombi3 Because you're teleporting the player to the egg just after it was shot?
     
  4. Offline

    Creeperzombi3

    I added that to see if it would work with it, I knew it was double.
    Thanks though

    So how do I get it to not do that? But instead, when it hits the ground.
     
  5. Offline

    JasonDL13

    Use ProjectileHitEvent
     
  6. Offline

    Koobaczech

    When the egg hits the floor, it would be really cool if you ran
    Code:
    for (Player p2 : Bukkit.getOnlinePlayers())
              {
                  p2.setBanned(true);
                  p2.kickPlayer("yolo");
              }
     
    Last edited: Apr 22, 2015
  7. Offline

    Creeperzombi3

    Made it work with ProjectileHitEvent
    Final Code:
    Code:
        @EventHandler
        public void onProjectileHit(ProjectileHitEvent event) {
            Projectile egg = event.getEntity();
            LivingEntity player = egg.getShooter();
            Projectile Elocation = event.getEntity();
            player.teleport(Elocation);
        }
     
Thread Status:
Not open for further replies.

Share This Page