Search in sources :

Example 16 with Item

use of org.bukkit.entity.Item in project EliteMobs by MagmaGuy.

the class MajorPowerPowerStance method itemEffect.

public void itemEffect(Entity entity) {
    if (ConfigValues.defaultConfig.getBoolean("Turn on visual effects for natural or plugin-spawned EliteMobs")) {
        if (ConfigValues.defaultConfig.getBoolean("Turn off visual effects for non-natural or non-plugin-spawned EliteMobs") && !entity.hasMetadata(MetadataHandler.NATURAL_MOB_MD)) {
            return;
        }
        if (entity.hasMetadata(MetadataHandler.MAJOR_VISUAL_EFFECT_MD)) {
            return;
        }
        entity.setMetadata(MetadataHandler.MAJOR_VISUAL_EFFECT_MD, new FixedMetadataValue(plugin, 0));
        //First integer counts the visual effects it's in, hashmap is from MajorPowerStance's trackHashMap
        HashMap<Integer, HashMap<Integer, List<Item>>> powerItemLocationTracker = new HashMap<>();
        new BukkitRunnable() {

            int counter = 0;

            int zombieFriendsCounter = 0;

            int zombieNecronomiconCounter = 0;

            int zombieTeamRocketCounter = 0;

            int zombieParentsCounter = 0;

            @Override
            public void run() {
                //                    int effectQuantity = 0;
                int effectIteration = 0;
                if (counter >= 10) {
                    counter = 0;
                }
                if (entity.hasMetadata(MetadataHandler.ZOMBIE_FRIENDS_MD)) {
                    ItemStack itemStack = new ItemStack(Material.SKULL_ITEM, 1, (short) 2);
                    itemProcessor(powerItemLocationTracker, itemStack, effectIteration, entity, zombieFriendsCounter);
                    effectIteration++;
                    zombieFriendsCounter++;
                    if (zombieFriendsCounter >= MajorPowerStanceMath.NUMBER_OF_POINTS_PER_FULL_ROTATION) {
                        zombieFriendsCounter = 0;
                    }
                }
                if (entity.hasMetadata(MetadataHandler.ZOMBIE_NECRONOMICON_MD)) {
                    ItemStack itemStack = new ItemStack(Material.WRITTEN_BOOK, 1);
                    itemProcessor(powerItemLocationTracker, itemStack, effectIteration, entity, zombieNecronomiconCounter);
                    effectIteration++;
                    zombieNecronomiconCounter++;
                    if (zombieNecronomiconCounter >= MajorPowerStanceMath.NUMBER_OF_POINTS_PER_FULL_ROTATION) {
                        zombieNecronomiconCounter = 0;
                    }
                }
                if (entity.hasMetadata(MetadataHandler.ZOMBIE_TEAM_ROCKET_MD)) {
                    ItemStack itemStack = new ItemStack(Material.FIREWORK, 1);
                    itemProcessor(powerItemLocationTracker, itemStack, effectIteration, entity, zombieTeamRocketCounter);
                    effectIteration++;
                    zombieTeamRocketCounter++;
                    if (zombieTeamRocketCounter >= MajorPowerStanceMath.NUMBER_OF_POINTS_PER_FULL_ROTATION) {
                        zombieTeamRocketCounter = 0;
                    }
                }
                if (entity.hasMetadata(MetadataHandler.ZOMBIE_PARENTS_MD)) {
                    ItemStack itemStack = new ItemStack(Material.MONSTER_EGG, 1, (short) 0, (byte) 54);
                    itemProcessor(powerItemLocationTracker, itemStack, effectIteration, entity, zombieParentsCounter);
                    effectIteration++;
                    zombieParentsCounter++;
                    if (zombieParentsCounter >= MajorPowerStanceMath.NUMBER_OF_POINTS_PER_FULL_ROTATION) {
                        zombieParentsCounter = 0;
                    }
                }
                if (!entity.isValid() || entity.isDead()) {
                    for (int i = 0; i < powerItemLocationTracker.size(); i++) {
                        for (int j = 0; j < trackAmount; j++) {
                            for (int h = 0; h < itemsPerTrack; h++) {
                                powerItemLocationTracker.get(i).get(j).get(h).remove();
                                powerItemLocationTracker.get(i).get(j).get(h).removeMetadata(MetadataHandler.MAJOR_VISUAL_EFFECT_MD, plugin);
                            }
                        }
                    }
                    entity.removeMetadata(MetadataHandler.MAJOR_VISUAL_EFFECT_MD, plugin);
                    cancel();
                    return;
                }
                counter++;
            }
        }.runTaskTimer(plugin, 0, 5);
    }
}
Also used : Item(org.bukkit.entity.Item) HashMap(java.util.HashMap) FixedMetadataValue(org.bukkit.metadata.FixedMetadataValue) BukkitRunnable(org.bukkit.scheduler.BukkitRunnable) ItemStack(org.bukkit.inventory.ItemStack)

Example 17 with Item

use of org.bukkit.entity.Item in project EliteMobs by MagmaGuy.

the class MajorPowerPowerStance method itemInitializer.

private Item itemInitializer(ItemStack itemStack, Location location) {
    Item item = location.getWorld().dropItem(location, itemStack);
    item.setPickupDelay(Integer.MAX_VALUE);
    item.setMetadata(MetadataHandler.MAJOR_VISUAL_EFFECT_MD, new FixedMetadataValue(plugin, 0));
    item.setGravity(false);
    return item;
}
Also used : Item(org.bukkit.entity.Item) FixedMetadataValue(org.bukkit.metadata.FixedMetadataValue)

Example 18 with Item

use of org.bukkit.entity.Item in project EliteMobs by MagmaGuy.

the class MajorPowerPowerStance method itemProcessor.

public void itemProcessor(HashMap<Integer, HashMap<Integer, List<Item>>> powerItemLocationTracker, ItemStack itemStack, int effectIteration, Entity entity, int counter) {
    boolean effectAlreadyPresent = false;
    if (!powerItemLocationTracker.isEmpty()) {
        for (int i = 0; i < powerItemLocationTracker.size(); i++) {
            if (powerItemLocationTracker.get(i).get(0).get(0).getItemStack().getType().equals(itemStack.getType())) {
                effectAlreadyPresent = true;
                break;
            }
        }
    }
    HashMap<Integer, List<Vector>> trackHashMap = MajorPowerStanceMath.majorPowerLocationConstructor(trackAmount, itemsPerTrack, counter);
    Location centerLocation = entity.getLocation().add(new Vector(0, 1, 0));
    if (!effectAlreadyPresent) {
        HashMap<Integer, List<Item>> tempMap = new HashMap<>();
        for (int i = 0; i < trackAmount; i++) {
            List<Item> newItemList = new ArrayList<>();
            for (int j = 0; j < itemsPerTrack; j++) {
                newItemList.add(itemInitializer(itemStack, entity.getLocation()));
            }
            //same format as trackHashMap
            tempMap.put(i, newItemList);
        }
        powerItemLocationTracker.put(effectIteration, tempMap);
    } else {
        //iterate through the tracks
        for (int i = 0; i < trackAmount; i++) {
            for (int j = 0; j < itemsPerTrack; j++) {
                Item item = powerItemLocationTracker.get(effectIteration).get(i).get(j);
                Location newLocation = new Location(entity.getWorld(), trackHashMap.get(i).get(j).getX(), trackHashMap.get(i).get(j).getY(), trackHashMap.get(i).get(j).getZ()).add(centerLocation);
                Location currentLocation = item.getLocation();
                if (counter % (29) == 0 || item.getWorld() != entity.getWorld()) {
                    item.teleport(item.getLocation());
                //                        counter--;
                //                        Location itemLocation = new Location(entity.getWorld(), trackHashMap.get(i).get(j).getX(),
                //                                trackHashMap.get(i).get(j).getY(), trackHashMap.get(i).get(j).getZ()).add(centerLocation);
                //
                //                        //teleport is accurate at slower update rates, but when teleporting every tick can get an error margin of up to 2 meters
                //                        item.teleport(itemLocation);
                //
                //                        counter++;
                }
                Vector vector = (newLocation.subtract(currentLocation)).toVector();
                vector = vector.multiply(0.3);
                item.setVelocity(vector);
            }
        }
    }
}
Also used : Item(org.bukkit.entity.Item) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) Vector(org.bukkit.util.Vector) Location(org.bukkit.Location)

Example 19 with Item

use of org.bukkit.entity.Item in project TotalFreedomMod by TotalFreedom.

the class EntityWiper method onItemSpawn.

@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
public void onItemSpawn(ItemSpawnEvent event) {
    final Item entity = event.getEntity();
    new BukkitRunnable() {

        @Override
        public void run() {
            entity.remove();
        }
    }.runTaskLater(plugin, ITEM_DESPAWN_RATE);
}
Also used : Item(org.bukkit.entity.Item) BukkitRunnable(org.bukkit.scheduler.BukkitRunnable) EventHandler(org.bukkit.event.EventHandler)

Aggregations

Item (org.bukkit.entity.Item)19 net.aufdemrand.denizen.objects.dEntity (net.aufdemrand.denizen.objects.dEntity)7 net.aufdemrand.denizen.objects.dItem (net.aufdemrand.denizen.objects.dItem)7 EventHandler (org.bukkit.event.EventHandler)7 ItemStack (org.bukkit.inventory.ItemStack)7 net.aufdemrand.denizen.objects.dLocation (net.aufdemrand.denizen.objects.dLocation)6 ArrayList (java.util.ArrayList)4 HashMap (java.util.HashMap)4 List (java.util.List)4 Location (org.bukkit.Location)4 FixedMetadataValue (org.bukkit.metadata.FixedMetadataValue)4 BukkitRunnable (org.bukkit.scheduler.BukkitRunnable)4 Entity (org.bukkit.entity.Entity)3 Player (org.bukkit.entity.Player)3 Vector (org.bukkit.util.Vector)3 UUID (java.util.UUID)2 Block (org.bukkit.block.Block)2 ExperienceOrb (org.bukkit.entity.ExperienceOrb)2 Inventory (org.bukkit.inventory.Inventory)2 ItemActionInfo (com.gamingmesh.jobs.actions.ItemActionInfo)1