Search in sources :

Example 1 with Egg

use of org.bukkit.entity.Egg in project Minigames by AddstarMC.

the class Events method playerShoot.

@EventHandler(ignoreCancelled = true)
private void playerShoot(ProjectileLaunchEvent event) {
    if (event.getEntityType() == EntityType.SNOWBALL) {
        Snowball snowball = (Snowball) event.getEntity();
        if (snowball.getShooter() != null && snowball.getShooter() instanceof Player) {
            MinigamePlayer ply = pdata.getMinigamePlayer((Player) snowball.getShooter());
            if (ply == null)
                return;
            if (ply.isInMinigame() && ply.getMinigame().hasUnlimitedAmmo()) {
                ItemStack mainhand = ply.getPlayer().getInventory().getItemInMainHand();
                if (mainhand.getType() == Material.SNOW_BALL) {
                    mainhand.setAmount(16);
                    ply.getPlayer().updateInventory();
                } else {
                    ply.getPlayer().getInventory().addItem(new ItemStack(Material.SNOW_BALL, 1));
                }
            }
        }
    } else if (event.getEntityType() == EntityType.EGG) {
        Egg egg = (Egg) event.getEntity();
        if (egg.getShooter() != null && egg.getShooter() instanceof Player) {
            MinigamePlayer ply = pdata.getMinigamePlayer((Player) egg.getShooter());
            if (ply == null)
                return;
            if (ply.isInMinigame() && ply.getMinigame().hasUnlimitedAmmo()) {
                ply.getPlayer().getInventory().addItem(new ItemStack(Material.EGG));
            }
        }
    }
}
Also used : Snowball(org.bukkit.entity.Snowball) Player(org.bukkit.entity.Player) Egg(org.bukkit.entity.Egg) ItemStack(org.bukkit.inventory.ItemStack) EventHandler(org.bukkit.event.EventHandler)

Aggregations

Egg (org.bukkit.entity.Egg)1 Player (org.bukkit.entity.Player)1 Snowball (org.bukkit.entity.Snowball)1 EventHandler (org.bukkit.event.EventHandler)1 ItemStack (org.bukkit.inventory.ItemStack)1