use of com.loohp.interactionvisualizer.entityholders.ArmorStand in project InteractionVisualizer by LOOHP.
the class SpawnerDisplay method spawnArmorStands.
public Map<String, ArmorStand> spawnArmorStands(Block block) {
Map<String, ArmorStand> map = new HashMap<>();
Location origin = block.getLocation();
Location loc = origin.clone().add(0.5, 0.2, 0.5);
SurroundingPlaneArmorStand slot1 = new SurroundingPlaneArmorStand(loc.clone(), 0.7, pathType);
setStand(slot1);
map.put("1", slot1);
PacketManager.sendArmorStandSpawn(InteractionVisualizerAPI.getPlayerModuleList(Modules.HOLOGRAM, KEY), slot1);
return map;
}
use of com.loohp.interactionvisualizer.entityholders.ArmorStand in project InteractionVisualizer by LOOHP.
the class SpawnerDisplay method onBreakSpawner.
@EventHandler(priority = EventPriority.MONITOR)
public void onBreakSpawner(TileEntityRemovedEvent event) {
Block block = event.getBlock();
if (!spawnerMap.containsKey(block)) {
return;
}
Map<String, Object> map = spawnerMap.get(block);
if (map.get("1") instanceof ArmorStand) {
ArmorStand stand = (ArmorStand) map.get("1");
PacketManager.removeArmorStand(InteractionVisualizerAPI.getPlayers(), stand);
}
spawnerMap.remove(block);
}
use of com.loohp.interactionvisualizer.entityholders.ArmorStand in project InteractionVisualizer by LOOHP.
the class PacketManager method update.
public static void update() {
if (!plugin.isEnabled()) {
return;
}
InteractionVisualizer.asyncExecutorManager.runTaskAsynchronously(() -> {
for (Player player : Bukkit.getOnlinePlayers()) {
try {
Set<VisualizerEntity> activeList = playerStatus.get(player);
if (activeList != null) {
Collection<Player> playerList = new HashSet<>();
playerList.add(player);
Location playerLocation = PlayerLocationManager.getPlayerLocation(player);
Location playerEyeLocation = PlayerLocationManager.getPlayerEyeLocation(player);
for (Entry<VisualizerEntity, Collection<Player>> entry : active.entrySet()) {
VisualizerEntity entity = entry.getKey();
int range = InteractionVisualizer.playerTrackingRange.getOrDefault(entity.getWorld(), 64);
range *= range;
boolean playerActive = activeList.contains(entity);
boolean sameWorld = entity.getWorld().equals(playerLocation.getWorld());
boolean inRange = sameWorld && (entity.getLocation().distanceSquared(playerLocation) <= range);
Boolean hasLineOfSight = InteractionVisualizer.hideIfObstructed ? null : true;
boolean isLoaded = loaded.getOrDefault(entity, false);
Location entityCenter = entity.getLocation();
entityCenter.setY(entityCenter.getY() + (entity instanceof Item ? (entity.getHeight() * 1.7) : (entity.getHeight() * 0.7)));
if (playerActive && (!sameWorld || !inRange || !(hasLineOfSight != null ? hasLineOfSight : (hasLineOfSight = LineOfSightUtils.hasLineOfSight(playerEyeLocation, entityCenter))))) {
if (entity instanceof ArmorStand) {
ArmorStand stand = (ArmorStand) entity;
removeArmorStand(playerList, stand, false, true);
} else if (entity instanceof Item) {
Item item = (Item) entity;
removeItem(playerList, item, false, true);
} else if (entity instanceof ItemFrame) {
ItemFrame frame = (ItemFrame) entity;
removeItemFrame(playerList, frame, false, true);
}
} else if (!playerActive && entry.getValue().contains(player) && isLoaded && sameWorld && inRange && (hasLineOfSight != null ? hasLineOfSight : (hasLineOfSight = LineOfSightUtils.hasLineOfSight(playerEyeLocation, entityCenter)))) {
if (entity instanceof ArmorStand) {
ArmorStand stand = (ArmorStand) entity;
sendArmorStandSpawn(playerList, stand);
updateArmorStand(playerList, stand);
} else if (entity instanceof Item) {
Item item = (Item) entity;
sendItemSpawn(playerList, item);
updateItem(playerList, item);
} else if (entity instanceof ItemFrame) {
ItemFrame frame = (ItemFrame) entity;
sendItemFrameSpawn(playerList, frame);
updateItemFrame(playerList, frame);
}
}
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
try {
TimeUnit.MILLISECONDS.sleep(5);
} catch (InterruptedException e) {
}
update();
});
}
use of com.loohp.interactionvisualizer.entityholders.ArmorStand in project InteractionVisualizer by LOOHP.
the class EnchantmentTableAnimation method playEnchantAnimation.
@SuppressWarnings("deprecation")
private CompletableFuture<Integer> playEnchantAnimation(Map<Enchantment, Integer> enchantsToAdd, Integer expCost, ItemStack itemstack) {
CompletableFuture<Integer> future = new CompletableFuture<>();
if (item.isPresent() && item.get().isLocked()) {
future.complete(PLAY_ENCHANTMENT);
return future;
}
this.enchanting.set(true);
if (!this.item.isPresent()) {
this.item = Optional.of(new Item(location.clone().add(0.5, 1.3, 0.5)));
PacketManager.sendItemSpawn(InteractionVisualizerAPI.getPlayerModuleList(Modules.ITEMDROP, KEY), item.get());
}
Item item = this.item.get();
item.setItemStack(itemstack);
item.setGravity(false);
item.setLocked(true);
item.setVelocity(new Vector(0.0, 0.05, 0.0));
PacketManager.updateItem(item);
for (Player each : InteractionVisualizerAPI.getPlayerModuleList(Modules.ITEMDROP, KEY)) {
each.spawnParticle(Particle.PORTAL, location.clone().add(0.5, 2.6, 0.5), 200);
}
Bukkit.getScheduler().runTaskLater(plugin, () -> {
item.teleport(location.clone().add(0.5, 2.3, 0.5));
item.setVelocity(new Vector(0, 0, 0));
PacketManager.updateItem(item);
}, 20);
List<ArmorStand> stands = new LinkedList<>();
Bukkit.getScheduler().runTaskLater(plugin, () -> {
Location standloc = item.getLocation().add(0.0, 0.5, 0.0);
for (Entry<Enchantment, Integer> entry : enchantsToAdd.entrySet()) {
Enchantment ench = entry.getKey();
int level = entry.getValue();
String str = TranslationUtils.getEnchantment(ench);
if (!EnchantmentTableDisplay.getTranslatableEnchantments().contains(str)) {
str = null;
}
Component enchantmentName = (str == null || str.equals("")) ? ComponentFont.parseFont(LegacyComponentSerializer.legacySection().deserialize(CustomStringUtils.capitalize(ench.getName().toLowerCase().replace("_", " ")))) : Component.translatable(str);
ArmorStand stand = new ArmorStand(standloc);
if (ench.getMaxLevel() != 1 || level != 1) {
enchantmentName = enchantmentName.append(ComponentFont.parseFont(LegacyComponentSerializer.legacySection().deserialize(" " + ChatColor.AQUA + RomanNumberUtils.toRoman(entry.getValue()))));
}
if (ench.isCursed()) {
enchantmentName = enchantmentName.color(NamedTextColor.RED);
} else {
enchantmentName = enchantmentName.color(NamedTextColor.AQUA);
}
stand.setCustomName(enchantmentName);
stand.setCustomNameVisible(true);
setStand(stand);
PacketManager.sendArmorStandSpawn(InteractionVisualizerAPI.getPlayerModuleList(Modules.HOLOGRAM, KEY), stand);
stands.add(stand);
standloc.add(0.0, 0.3, 0.0);
}
ArmorStand stand = new ArmorStand(standloc);
TranslatableComponent levelTrans = Component.translatable(TranslationUtils.getLevel(expCost));
if (expCost != 1) {
levelTrans = levelTrans.args(Component.text(expCost));
}
levelTrans = levelTrans.color(NamedTextColor.GREEN);
stand.setCustomName(levelTrans);
stand.setCustomNameVisible(true);
setStand(stand);
PacketManager.sendArmorStandSpawn(InteractionVisualizerAPI.getPlayerModuleList(Modules.HOLOGRAM, KEY), stand);
stands.add(stand);
PacketManager.updateItem(item);
}, 50);
Bukkit.getScheduler().runTaskLater(plugin, () -> {
while (!stands.isEmpty()) {
ArmorStand stand = stands.remove(0);
PacketManager.removeArmorStand(InteractionVisualizerAPI.getPlayers(), stand);
}
item.setGravity(true);
PacketManager.updateItem(item);
}, 90);
Bukkit.getScheduler().runTaskLater(plugin, () -> {
item.teleport(location.clone().add(0.5, 1.3, 0.5));
item.setGravity(false);
PacketManager.updateItem(item);
item.setLocked(false);
future.complete(PLAY_ENCHANTMENT);
this.enchanting.set(false);
}, 98);
return future;
}
use of com.loohp.interactionvisualizer.entityholders.ArmorStand in project InteractionVisualizer by LOOHP.
the class FurnaceDisplay method spawnArmorStands.
public Map<String, ArmorStand> spawnArmorStands(Block block) {
Map<String, ArmorStand> map = new HashMap<>();
Location origin = block.getLocation();
BlockFace facing = null;
if (!InteractionVisualizer.version.isLegacy()) {
BlockData blockData = block.getState().getBlockData();
facing = ((Directional) blockData).getFacing();
} else {
facing = LegacyFacingUtils.getFacing(block);
}
Location target = block.getRelative(facing).getLocation();
Vector direction = target.toVector().subtract(origin.toVector()).multiply(0.7);
Location loc = block.getLocation().clone().add(direction).add(0.5, 0.2, 0.5);
ArmorStand slot1 = new ArmorStand(loc.clone());
setStand(slot1);
map.put("Stand", slot1);
PacketManager.sendArmorStandSpawn(InteractionVisualizerAPI.getPlayerModuleList(Modules.HOLOGRAM, KEY), slot1);
return map;
}
Aggregations