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);
}
}
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;
}
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);
}
}
}
}
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);
}
Aggregations