Search in sources :

Example 11 with ItemStack

use of org.bukkit.inventory.ItemStack in project GameCore by Warvale.

the class TeamSelect method onPlayerInteract.

@EventHandler
public void onPlayerInteract(PlayerInteractEvent event) {
    Action a = event.getAction();
    ItemStack is = event.getItem();
    if (a == Action.PHYSICAL || is == null || is.getType() == Material.AIR)
        return;
    if (is.getType() == Material.ENCHANTED_BOOK)
        tsGUI(event.getPlayer());
    if (Main.getTeams().getSpectatorTeam().getEntries().contains(event.getPlayer().getName())) {
        event.getPlayer().playSound(event.getPlayer().getLocation(), Sound.BLOCK_ENDERCHEST_OPEN, 1, 1);
    }
}
Also used : Action(org.bukkit.event.block.Action) ItemStack(org.bukkit.inventory.ItemStack) EventHandler(org.bukkit.event.EventHandler)

Example 12 with ItemStack

use of org.bukkit.inventory.ItemStack in project GameCore by Warvale.

the class GlobalEvent method onBlockBreak.

@EventHandler
public void onBlockBreak(BlockBreakEvent event) {
    if (event.getBlock().getType().equals(Material.IRON_ORE)) {
        event.getPlayer().giveExp(10);
        for (int i = 0; i < NumberUtils.random(3, 1); i++) {
            event.getPlayer().getInventory().addItem(new ItemStack(Material.IRON_INGOT));
        }
        event.setCancelled(true);
        Location blockLoc = event.getBlock().getLocation();
        event.getBlock().setType(Material.STONE);
        List<Entity> entityList = new ArrayList<>();
        for (int i = 0; i < NumberUtils.random(5, 2) + 1; i++) {
            ItemStack stack = new ItemStack(Material.IRON_NUGGET);
            stack.addUnsafeEnchantment(Enchantment.DAMAGE_ALL, NumberUtils.random(100, 1));
            entityList.add(event.getPlayer().getWorld().dropItemNaturally(event.getBlock().getLocation().setDirection(Vector.getRandom()).add(Vector.getRandom()), stack));
        }
        new BukkitRunnable() {

            @Override
            public void run() {
                entityList.forEach(Entity::remove);
            }
        }.runTaskLater(Main.get(), 60L);
        new BukkitRunnable() {

            @Override
            public void run() {
                event.getPlayer().getWorld().getBlockAt(blockLoc).setType(Material.IRON_ORE);
                event.getPlayer().getWorld().playSound(blockLoc, Sound.ENTITY_EXPERIENCE_ORB_PICKUP, 5, 1);
            }
        }.runTaskLater(Main.get(), 400L);
    }
    if (event.getBlock().getType().equals(Material.GOLD_ORE)) {
        event.getPlayer().giveExp(30);
        for (int i = 0; i < NumberUtils.random(2, 0); i++) {
            event.getPlayer().getInventory().addItem(new ItemStack(Material.GOLD_INGOT));
        }
        event.setCancelled(true);
        Location blockLoc = event.getBlock().getLocation();
        event.getBlock().setType(Material.STONE);
        List<Entity> entityList = new ArrayList<>();
        for (int i = 0; i < NumberUtils.random(5, 2) + 1; i++) {
            ItemStack stack = new ItemStack(Material.GOLD_NUGGET);
            stack.addUnsafeEnchantment(Enchantment.DAMAGE_ALL, NumberUtils.random(100, 1));
            entityList.add(event.getPlayer().getWorld().dropItemNaturally(event.getBlock().getLocation().setDirection(Vector.getRandom()).add(Vector.getRandom()), stack));
        }
        new BukkitRunnable() {

            @Override
            public void run() {
                entityList.stream().forEach(entity -> entity.remove());
            }
        }.runTaskLater(Main.get(), 60L);
        new BukkitRunnable() {

            @Override
            public void run() {
                event.getPlayer().getWorld().getBlockAt(blockLoc).setType(Material.GOLD_ORE);
                event.getPlayer().getWorld().playSound(blockLoc, Sound.ENTITY_EXPERIENCE_ORB_PICKUP, 10, 1);
            }
        }.runTaskLater(Main.get(), 400L);
    }
    if (event.getBlock().getType().equals(Material.DIAMOND_ORE)) {
        event.getPlayer().giveExp(50);
        for (int i = 0; i < NumberUtils.random(1, 0); i++) {
            event.getPlayer().getInventory().addItem(new ItemStack(Material.DIAMOND));
        }
        event.setCancelled(true);
        Location blockLoc = event.getBlock().getLocation();
        event.getBlock().setType(Material.STONE);
        List<Entity> entityList = new ArrayList<>();
        for (int i = 0; i < NumberUtils.random(5, 2) + 1; i++) {
            ItemStack stack = new ItemStack(Material.PRISMARINE_CRYSTALS);
            stack.addUnsafeEnchantment(Enchantment.DAMAGE_ALL, NumberUtils.random(100, 1));
            entityList.add(event.getPlayer().getWorld().dropItemNaturally(event.getBlock().getLocation().setDirection(Vector.getRandom()).add(Vector.getRandom()), stack));
        }
        new BukkitRunnable() {

            @Override
            public void run() {
                entityList.stream().forEach(entity -> entity.remove());
            }
        }.runTaskLater(Main.get(), 60L);
        new BukkitRunnable() {

            @Override
            public void run() {
                event.getPlayer().getWorld().getBlockAt(blockLoc).setType(Material.DIAMOND_ORE);
                event.getPlayer().getWorld().playSound(blockLoc, Sound.ENTITY_EXPERIENCE_ORB_PICKUP, 25, 1);
            }
        }.runTaskLater(Main.get(), 400L);
    }
    if (event.getBlock().getType().equals(Material.LAPIS_ORE)) {
        event.getPlayer().giveExp(50);
        for (int i = 0; i < NumberUtils.random(1, 0); i++) {
            event.getPlayer().getInventory().addItem(new ItemStack(Material.LAPIS_BLOCK));
        }
        event.setCancelled(true);
        Location blockLoc = event.getBlock().getLocation();
        event.getBlock().setType(Material.STONE);
        List<Entity> entityList = new ArrayList<>();
        for (int i = 0; i < NumberUtils.random(5, 2) + 1; i++) {
            ItemStack stack = new ItemStack(Material.EYE_OF_ENDER);
            stack.addUnsafeEnchantment(Enchantment.DAMAGE_ALL, NumberUtils.random(100, 1));
            entityList.add(event.getPlayer().getWorld().dropItemNaturally(event.getBlock().getLocation().setDirection(Vector.getRandom()).add(Vector.getRandom()), stack));
        }
        new BukkitRunnable() {

            @Override
            public void run() {
                entityList.stream().forEach(entity -> entity.remove());
            }
        }.runTaskLater(Main.get(), 60L);
        new BukkitRunnable() {

            @Override
            public void run() {
                event.getPlayer().getWorld().getBlockAt(blockLoc).setType(Material.LAPIS_ORE);
                event.getPlayer().getWorld().playSound(blockLoc, Sound.ENTITY_EXPERIENCE_ORB_PICKUP, 15, 1);
            }
        }.runTaskLater(Main.get(), 400L);
    }
}
Also used : Arrays(java.util.Arrays) Entity(org.bukkit.entity.Entity) Enchantment(org.bukkit.enchantments.Enchantment) BukkitRunnable(org.bukkit.scheduler.BukkitRunnable) BlockBreakEvent(org.bukkit.event.block.BlockBreakEvent) NumberUtils(net.warvale.core.utils.NumberUtils) Sound(org.bukkit.Sound) Player(org.bukkit.entity.Player) PlayerPickupItemEvent(org.bukkit.event.player.PlayerPickupItemEvent) ItemStack(org.bukkit.inventory.ItemStack) ArrayList(java.util.ArrayList) TeamManager(net.warvale.core.game.logic.TeamManager) EventHandler(org.bukkit.event.EventHandler) Vector(org.bukkit.util.Vector) PlayerDeathEvent(org.bukkit.event.entity.PlayerDeathEvent) List(java.util.List) ChatUtils(net.warvale.core.utils.chat.ChatUtils) Location(org.bukkit.Location) ChatColor(org.bukkit.ChatColor) Material(org.bukkit.Material) Listener(org.bukkit.event.Listener) Entity(org.bukkit.entity.Entity) ArrayList(java.util.ArrayList) BukkitRunnable(org.bukkit.scheduler.BukkitRunnable) ItemStack(org.bukkit.inventory.ItemStack) Location(org.bukkit.Location) EventHandler(org.bukkit.event.EventHandler)

Example 13 with ItemStack

use of org.bukkit.inventory.ItemStack in project GameCore by Warvale.

the class Bosses method BossWizard.

private void BossWizard(Location bossLocation) {
    Skeleton Wizard = (Skeleton) bossLocation.getWorld().spawnEntity(bossLocation, EntityType.SKELETON);
    Wizard.addPotionEffect(new PotionEffect(PotionEffectType.DAMAGE_RESISTANCE, 200, 100));
    Wizard.setCustomName(ChatColor.translateAlternateColorCodes('&', "&eWizard"));
    Wizard.setCustomNameVisible(true);
    Wizard.setCanPickupItems(true);
    ItemStack chestplate = new ItemStack(Material.IRON_CHESTPLATE);
    chestplate.addEnchantment(Enchantment.PROTECTION_ENVIRONMENTAL, 2);
    Wizard.getEquipment().setChestplate(chestplate);
    Wizard.getAttribute(Attribute.GENERIC_MAX_HEALTH).setBaseValue(30);
    Wizard.addPotionEffect(new PotionEffect(PotionEffectType.GLOWING, 1000000, 1, false, false, Color.RED));
}
Also used : PotionEffect(org.bukkit.potion.PotionEffect) ItemStack(org.bukkit.inventory.ItemStack)

Example 14 with ItemStack

use of org.bukkit.inventory.ItemStack in project GameCore by Warvale.

the class Bosses method BossCruitionator.

private void BossCruitionator(Location bossLocation) {
    Spider Cruitionator = (Spider) bossLocation.getWorld().spawnEntity(bossLocation, EntityType.SPIDER);
    Cruitionator.setCustomNameVisible(true);
    Cruitionator.setCustomName(ChatColor.translateAlternateColorCodes('&', "&eCruitionator"));
    Cruitionator.getAttribute(Attribute.GENERIC_MAX_HEALTH).setBaseValue(20);
    Cruitionator.getAttribute(Attribute.GENERIC_MOVEMENT_SPEED).setBaseValue(0.5);
    Cruitionator.addPotionEffect(new PotionEffect(PotionEffectType.GLOWING, 1000000, 1, false, false, Color.RED));
    Cruitionator.getEquipment().setItemInMainHand(new ItemStack(Material.WOOD_SWORD));
    Cruitionator.getEquipment().setItemInOffHandDropChance(0);
}
Also used : PotionEffect(org.bukkit.potion.PotionEffect) ItemStack(org.bukkit.inventory.ItemStack)

Example 15 with ItemStack

use of org.bukkit.inventory.ItemStack in project Minigames by AddstarMC.

the class MinigamePlayer method storePlayerData.

public void storePlayerData() {
    ItemStack[] storedItems = player.getInventory().getContents();
    ItemStack[] storedArmour = player.getInventory().getArmorContents();
    int food = player.getFoodLevel();
    double health = player.getHealth();
    float saturation = player.getSaturation();
    lastScoreboard = player.getScoreboard();
    GameMode lastGM = player.getGameMode();
    float exp = player.getExp();
    int level = player.getLevel();
    player.setSaturation(15);
    player.setFoodLevel(20);
    player.setHealth(player.getMaxHealth());
    player.getInventory().clear();
    player.getInventory().setArmorContents(null);
    player.setLevel(0);
    player.setExp(0);
    oply = new OfflineMinigamePlayer(getPlayer().getUniqueId().toString(), storedItems, storedArmour, food, health, saturation, lastGM, exp, level, null);
    player.updateInventory();
}
Also used : GameMode(org.bukkit.GameMode) ItemStack(org.bukkit.inventory.ItemStack)

Aggregations

ItemStack (org.bukkit.inventory.ItemStack)1282 Player (org.bukkit.entity.Player)262 EventHandler (org.bukkit.event.EventHandler)183 ItemMeta (org.bukkit.inventory.meta.ItemMeta)167 ArrayList (java.util.ArrayList)130 Inventory (org.bukkit.inventory.Inventory)115 Location (org.bukkit.Location)88 Material (org.bukkit.Material)87 PlayerInventory (org.bukkit.inventory.PlayerInventory)84 Entity (org.bukkit.entity.Entity)63 Block (org.bukkit.block.Block)52 TagCompound (de.keyle.knbt.TagCompound)47 Map (java.util.Map)44 LivingEntity (org.bukkit.entity.LivingEntity)44 HashMap (java.util.HashMap)40 Mage (com.elmakers.mine.bukkit.api.magic.Mage)39 Enchantment (org.bukkit.enchantments.Enchantment)38 SkullMeta (org.bukkit.inventory.meta.SkullMeta)38 Vector (org.bukkit.util.Vector)35 Test (org.junit.Test)32