use of org.bukkit.entity.Phantom in project kit-api by HGLabor.
the class FalcoKit method onPlayerRightClickKitItem.
@KitEvent
@Override
public void onPlayerRightClickKitItem(PlayerInteractEvent event, KitPlayer kitPlayer) {
kitPlayer.getBukkitPlayer().ifPresent(it -> {
Phantom phantom = it.getWorld().spawn(it.getLocation(), Phantom.class);
phantom.setShouldBurnInDay(false);
phantom.addPotionEffect(new PotionEffect(PotionEffectType.FIRE_RESISTANCE, Integer.MAX_VALUE, 25, false, false));
phantom.setVelocity(it.getLocation().getDirection().multiply(2));
AtomicInteger tick = new AtomicInteger();
Bukkit.getScheduler().runTaskLater(KitApi.getInstance().getPlugin(), () -> {
phantom.getWorld().playSound(phantom.getLocation(), Sound.ENTITY_GENERIC_EXPLODE, 1f, 10f);
}, 40);
Bukkit.getScheduler().runTaskTimer(KitApi.getInstance().getPlugin(), task -> {
tick.getAndIncrement();
if (tick.get() == flashDuration) {
task.cancel();
phantom.remove();
} else {
for (Entity nearby : phantom.getNearbyEntities(flashRadius, flashRadius, flashRadius)) {
nearby.getWorld().spawnParticle(Particle.FLASH, nearby.getLocation().clone().add(0, 1, 0), 0);
}
}
}, 40, 1);
});
kitPlayer.activateKitCooldown(this);
}
use of org.bukkit.entity.Phantom in project Citizens2 by CitizensDev.
the class PhantomTrait method run.
@Override
public void run() {
if (npc.isSpawned() && npc.getEntity() instanceof Phantom) {
Phantom phantom = (Phantom) npc.getEntity();
phantom.setSize(size);
}
}
use of org.bukkit.entity.Phantom in project RoseStacker by Rosewood-Development.
the class PhantomStackSettings method canStackWithInternal.
@Override
protected EntityStackComparisonResult canStackWithInternal(StackedEntity stack1, StackedEntity stack2) {
Phantom phantom1 = (Phantom) stack1.getEntity();
Phantom phantom2 = (Phantom) stack2.getEntity();
if (this.dontStackIfDifferentSize && phantom1.getSize() != phantom2.getSize())
return EntityStackComparisonResult.DIFFERENT_SIZES;
return EntityStackComparisonResult.CAN_STACK;
}
use of org.bukkit.entity.Phantom in project CoreProtect by PlayPro.
the class EntityUtil method spawnEntity.
public static void spawnEntity(final BlockState block, final EntityType type, final List<Object> list) {
if (type == null) {
return;
}
Bukkit.getServer().getScheduler().runTask(CoreProtect.getInstance(), () -> {
try {
Location location = block.getLocation();
location.setX(location.getX() + 0.50);
location.setZ(location.getZ() + 0.50);
Entity entity = block.getLocation().getWorld().spawnEntity(location, type);
if (list.isEmpty()) {
return;
}
@SuppressWarnings("unchecked") List<Object> age = (List<Object>) list.get(0);
@SuppressWarnings("unchecked") List<Object> tame = (List<Object>) list.get(1);
@SuppressWarnings("unchecked") List<Object> data = (List<Object>) list.get(2);
if (list.size() >= 5) {
entity.setCustomNameVisible((Boolean) list.get(3));
entity.setCustomName((String) list.get(4));
}
int unixtimestamp = (int) (System.currentTimeMillis() / 1000L);
int wid = Util.getWorldId(block.getWorld().getName());
String token = "" + block.getX() + "." + block.getY() + "." + block.getZ() + "." + wid + "." + type.name() + "";
CacheHandler.entityCache.put(token, new Object[] { unixtimestamp, entity.getEntityId() });
if (entity instanceof Ageable) {
int count = 0;
Ageable ageable = (Ageable) entity;
for (Object value : age) {
if (count == 0) {
int set = (Integer) value;
ageable.setAge(set);
} else if (count == 1) {
boolean set = (Boolean) value;
ageable.setAgeLock(set);
} else if (count == 2) {
boolean set = (Boolean) value;
if (set) {
ageable.setAdult();
} else {
ageable.setBaby();
}
} else if (count == 3) {
boolean set = (Boolean) value;
ageable.setBreed(set);
} else if (count == 4 && value != null) {
// deprecated
double set = (Double) value;
ageable.setMaxHealth(set);
}
count++;
}
}
if (entity instanceof Tameable) {
int count = 0;
Tameable tameable = (Tameable) entity;
for (Object value : tame) {
if (count == 0) {
boolean set = (Boolean) value;
tameable.setTamed(set);
} else if (count == 1) {
String set = (String) value;
if (set.length() > 0) {
Player owner = Bukkit.getServer().getPlayer(set);
if (owner == null) {
OfflinePlayer offlinePlayer = Bukkit.getServer().getOfflinePlayer(set);
if (offlinePlayer != null) {
tameable.setOwner(offlinePlayer);
}
} else {
tameable.setOwner(owner);
}
}
}
count++;
}
}
if (entity instanceof Attributable && list.size() >= 6) {
Attributable attributable = (Attributable) entity;
@SuppressWarnings("unchecked") List<Object> attributes = (List<Object>) list.get(5);
for (Object value : attributes) {
@SuppressWarnings("unchecked") List<Object> attributeData = (List<Object>) value;
Attribute attribute = (Attribute) attributeData.get(0);
Double baseValue = (Double) attributeData.get(1);
@SuppressWarnings("unchecked") List<Object> attributeModifiers = (List<Object>) attributeData.get(2);
AttributeInstance entityAttribute = attributable.getAttribute(attribute);
if (entityAttribute != null) {
entityAttribute.setBaseValue(baseValue);
for (AttributeModifier modifier : entityAttribute.getModifiers()) {
entityAttribute.removeModifier(modifier);
}
for (Object modifier : attributeModifiers) {
@SuppressWarnings("unchecked") Map<String, Object> serializedModifier = (Map<String, Object>) modifier;
entityAttribute.addModifier(AttributeModifier.deserialize(serializedModifier));
}
}
}
}
if (entity instanceof LivingEntity && list.size() >= 7) {
LivingEntity livingEntity = (LivingEntity) entity;
@SuppressWarnings("unchecked") List<Object> details = (List<Object>) list.get(6);
int count = 0;
for (Object value : details) {
if (count == 0) {
boolean set = (Boolean) value;
livingEntity.setRemoveWhenFarAway(set);
} else if (count == 1) {
boolean set = (Boolean) value;
livingEntity.setCanPickupItems(set);
}
count++;
}
}
int count = 0;
for (Object value : data) {
if (entity instanceof Creeper) {
Creeper creeper = (Creeper) entity;
if (count == 0) {
boolean set = (Boolean) value;
creeper.setPowered(set);
}
} else if (entity instanceof Enderman) {
Enderman enderman = (Enderman) entity;
if (count == 1) {
String blockDataString = (String) value;
BlockData blockData = Bukkit.getServer().createBlockData(blockDataString);
enderman.setCarriedBlock(blockData);
}
} else if (entity instanceof IronGolem) {
IronGolem irongolem = (IronGolem) entity;
if (count == 0) {
boolean set = (Boolean) value;
irongolem.setPlayerCreated(set);
}
} else if (entity instanceof Cat) {
Cat cat = (Cat) entity;
if (count == 0) {
Cat.Type set = (Cat.Type) value;
cat.setCatType(set);
} else if (count == 1) {
DyeColor set = (DyeColor) value;
cat.setCollarColor(set);
}
} else if (entity instanceof Fox) {
Fox fox = (Fox) entity;
if (count == 0) {
Fox.Type set = (Fox.Type) value;
fox.setFoxType(set);
} else if (count == 1) {
boolean set = (Boolean) value;
fox.setSitting(set);
}
} else if (entity instanceof Panda) {
Panda panda = (Panda) entity;
if (count == 0) {
Gene set = (Gene) value;
panda.setMainGene(set);
} else if (count == 1) {
Gene set = (Gene) value;
panda.setHiddenGene(set);
}
} else if (entity instanceof Pig) {
Pig pig = (Pig) entity;
if (count == 0) {
boolean set = (Boolean) value;
pig.setSaddle(set);
}
} else if (entity instanceof Sheep) {
Sheep sheep = (Sheep) entity;
if (count == 0) {
boolean set = (Boolean) value;
sheep.setSheared(set);
} else if (count == 1) {
DyeColor set = (DyeColor) value;
sheep.setColor(set);
}
} else if (entity instanceof MushroomCow) {
MushroomCow mushroomCow = (MushroomCow) entity;
if (count == 0) {
MushroomCow.Variant set = (MushroomCow.Variant) value;
mushroomCow.setVariant(set);
}
} else if (entity instanceof Slime) {
Slime slime = (Slime) entity;
if (count == 0) {
int set = (Integer) value;
slime.setSize(set);
}
} else if (entity instanceof Parrot) {
Parrot parrot = (Parrot) entity;
if (count == 0) {
Variant set = (Variant) value;
parrot.setVariant(set);
}
} else if (entity instanceof TropicalFish) {
TropicalFish tropicalFish = (TropicalFish) entity;
if (count == 0) {
DyeColor set = (DyeColor) value;
tropicalFish.setBodyColor(set);
} else if (count == 1) {
TropicalFish.Pattern set = (TropicalFish.Pattern) value;
tropicalFish.setPattern(set);
} else if (count == 2) {
DyeColor set = (DyeColor) value;
tropicalFish.setPatternColor(set);
}
} else if (entity instanceof Phantom) {
Phantom phantom = (Phantom) entity;
if (count == 0) {
int set = (Integer) value;
phantom.setSize(set);
}
} else if (entity instanceof AbstractVillager) {
AbstractVillager abstractVillager = (AbstractVillager) entity;
if (count == 0) {
if (abstractVillager instanceof Villager) {
Villager villager = (Villager) abstractVillager;
Profession set = (Profession) value;
villager.setProfession(set);
}
} else if (count == 1) {
if (abstractVillager instanceof Villager && value instanceof Villager.Type) {
Villager villager = (Villager) abstractVillager;
Villager.Type set = (Villager.Type) value;
villager.setVillagerType(set);
}
} else if (count == 2) {
List<MerchantRecipe> merchantRecipes = new ArrayList<>();
@SuppressWarnings("unchecked") List<Object> set = (List<Object>) value;
for (Object recipes : set) {
@SuppressWarnings("unchecked") List<Object> recipe = (List<Object>) recipes;
@SuppressWarnings("unchecked") List<Object> itemMap = (List<Object>) recipe.get(0);
@SuppressWarnings("unchecked") ItemStack result = ItemStack.deserialize((Map<String, Object>) itemMap.get(0));
@SuppressWarnings("unchecked") List<List<Map<String, Object>>> metadata = (List<List<Map<String, Object>>>) itemMap.get(1);
Object[] populatedStack = Rollback.populateItemStack(result, metadata);
result = (ItemStack) populatedStack[2];
int uses = (int) recipe.get(1);
int maxUses = (int) recipe.get(2);
boolean experienceReward = (boolean) recipe.get(3);
List<ItemStack> merchantIngredients = new ArrayList<>();
@SuppressWarnings("unchecked") List<Object> ingredients = (List<Object>) recipe.get(4);
for (Object ingredient : ingredients) {
@SuppressWarnings("unchecked") List<Object> ingredientMap = (List<Object>) ingredient;
@SuppressWarnings("unchecked") ItemStack item = ItemStack.deserialize((Map<String, Object>) ingredientMap.get(0));
@SuppressWarnings("unchecked") List<List<Map<String, Object>>> itemMetaData = (List<List<Map<String, Object>>>) ingredientMap.get(1);
populatedStack = Rollback.populateItemStack(item, itemMetaData);
item = (ItemStack) populatedStack[2];
merchantIngredients.add(item);
}
MerchantRecipe merchantRecipe = new MerchantRecipe(result, uses, maxUses, experienceReward);
if (recipe.size() > 6) {
int villagerExperience = (int) recipe.get(5);
float priceMultiplier = (float) recipe.get(6);
merchantRecipe = new MerchantRecipe(result, uses, maxUses, experienceReward, villagerExperience, priceMultiplier);
}
merchantRecipe.setIngredients(merchantIngredients);
merchantRecipes.add(merchantRecipe);
}
if (!merchantRecipes.isEmpty()) {
abstractVillager.setRecipes(merchantRecipes);
}
} else {
Villager villager = (Villager) abstractVillager;
if (count == 3) {
int set = (int) value;
villager.setVillagerLevel(set);
} else if (count == 4) {
int set = (int) value;
villager.setVillagerExperience(set);
}
}
} else if (entity instanceof Raider) {
Raider raider = (Raider) entity;
if (count == 0) {
boolean set = (Boolean) value;
raider.setPatrolLeader(set);
}
if (entity instanceof Spellcaster && count == 1) {
Spellcaster spellcaster = (Spellcaster) entity;
Spell set = (Spell) value;
spellcaster.setSpell(set);
}
} else if (entity instanceof Wolf) {
Wolf wolf = (Wolf) entity;
if (count == 0) {
boolean set = (Boolean) value;
wolf.setSitting(set);
} else if (count == 1) {
DyeColor set = (DyeColor) value;
wolf.setCollarColor(set);
}
} else if (entity instanceof ZombieVillager) {
ZombieVillager zombieVillager = (ZombieVillager) entity;
if (count == 0) {
boolean set = (Boolean) value;
zombieVillager.setBaby(set);
} else if (count == 1) {
Profession set = (Profession) value;
zombieVillager.setVillagerProfession(set);
}
} else if (entity instanceof Zombie) {
Zombie zombie = (Zombie) entity;
if (count == 0) {
boolean set = (Boolean) value;
zombie.setBaby(set);
}
} else if (entity instanceof AbstractHorse) {
AbstractHorse abstractHorse = (AbstractHorse) entity;
if (count == 0 && value != null) {
// deprecated
boolean set = (Boolean) value;
if (entity instanceof ChestedHorse) {
ChestedHorse chestedHorse = (ChestedHorse) entity;
chestedHorse.setCarryingChest(set);
}
} else if (count == 1 && value != null) {
// deprecated
org.bukkit.entity.Horse.Color set = (org.bukkit.entity.Horse.Color) value;
if (entity instanceof Horse) {
Horse horse = (Horse) entity;
horse.setColor(set);
}
} else if (count == 2) {
int set = (Integer) value;
abstractHorse.setDomestication(set);
} else if (count == 3) {
double set = (Double) value;
abstractHorse.setJumpStrength(set);
} else if (count == 4) {
int set = (Integer) value;
abstractHorse.setMaxDomestication(set);
} else if (count == 5 && value != null) {
// deprecated
Style set = (Style) value;
Horse horse = (Horse) entity;
horse.setStyle(set);
}
if (entity instanceof Horse) {
Horse horse = (Horse) entity;
if (count == 8) {
if (value != null) {
@SuppressWarnings("unchecked") ItemStack set = ItemStack.deserialize((Map<String, Object>) value);
horse.getInventory().setSaddle(set);
}
} else if (count == 9) {
org.bukkit.entity.Horse.Color set = (org.bukkit.entity.Horse.Color) value;
horse.setColor(set);
} else if (count == 10) {
Style set = (Style) value;
horse.setStyle(set);
} else if (count == 11) {
if (value != null) {
@SuppressWarnings("unchecked") ItemStack set = ItemStack.deserialize((Map<String, Object>) value);
horse.getInventory().setArmor(set);
}
} else if (count == 12 && value != null) {
@SuppressWarnings("unchecked") org.bukkit.Color set = org.bukkit.Color.deserialize((Map<String, Object>) value);
ItemStack armor = horse.getInventory().getArmor();
if (armor != null) {
ItemMeta itemMeta = armor.getItemMeta();
if (itemMeta instanceof LeatherArmorMeta) {
LeatherArmorMeta leatherArmorMeta = (LeatherArmorMeta) itemMeta;
leatherArmorMeta.setColor(set);
armor.setItemMeta(leatherArmorMeta);
}
}
}
} else if (entity instanceof ChestedHorse) {
if (count == 7) {
ChestedHorse chestedHorse = (ChestedHorse) entity;
boolean set = (Boolean) value;
chestedHorse.setCarryingChest(set);
}
if (entity instanceof Llama) {
Llama llama = (Llama) entity;
if (count == 8) {
if (value != null) {
@SuppressWarnings("unchecked") ItemStack set = ItemStack.deserialize((Map<String, Object>) value);
llama.getInventory().setDecor(set);
}
} else if (count == 9) {
Llama.Color set = (Llama.Color) value;
llama.setColor(set);
}
}
}
} else {
BukkitAdapter.ADAPTER.setEntityMeta(entity, value, count);
}
count++;
}
} catch (Exception e) {
e.printStackTrace();
}
});
}
use of org.bukkit.entity.Phantom in project TARDIS by eccentricdevotion.
the class TARDISForceField method run.
@Override
public void run() {
for (Map.Entry<UUID, Location> map : plugin.getTrackerKeeper().getActiveForceFields().entrySet()) {
Player player = plugin.getServer().getPlayer(map.getKey());
if (player == null || !player.isOnline()) {
continue;
}
Location location = map.getValue().clone().add(0.5, 0.5, 0.5);
new TARDISForceFieldVisualiser(plugin).showBorder(location.clone(), dust);
for (Entity other : location.getWorld().getNearbyEntities(location, doubleRange, doubleRange, doubleRange)) {
if (!(other instanceof LivingEntity)) {
continue;
}
if (other instanceof Player) {
if (player.equals(other)) {
continue;
}
if (((Player) other).getGameMode() == GameMode.SPECTATOR) {
continue;
}
if (other.hasPermission("tardis.admin")) {
continue;
}
if (isCompanion((Player) other, player)) {
continue;
}
}
if (offset(other, map.getValue()) > range) {
continue;
}
while (other.getVehicle() != null) {
other = other.getVehicle();
}
// velocity(other, getTrajectory2d(map.getValue(), other), 0.5d);
velocity(other, getTrajectory3d(map.getValue(), other), (other instanceof Phantom) ? 1.5d : 0.5d);
other.getWorld().playSound(other.getLocation(), "tardis_force_field", 0.5f, 1.0f);
}
dust++;
if (dust > 11) {
dust = 0;
}
}
}
Aggregations