use of com.loohp.interactionvisualizer.entityholders.ItemFrame in project InteractionVisualizer by LOOHP.
the class CartographyTableDisplay method onCloseCartographyTable.
@EventHandler
public void onCloseCartographyTable(InventoryCloseEvent event) {
if (!playermap.containsKey((Player) event.getPlayer())) {
return;
}
Block block = playermap.get((Player) event.getPlayer());
if (!openedCTable.containsKey(block)) {
return;
}
Map<String, Object> map = openedCTable.get(block);
if (!map.get("Player").equals(event.getPlayer())) {
return;
}
if (map.get("Item") instanceof ItemFrame) {
ItemFrame entity = (ItemFrame) map.get("Item");
PacketManager.removeItemFrame(InteractionVisualizerAPI.getPlayers(), entity);
}
openedCTable.remove(block);
playermap.remove((Player) event.getPlayer());
}
use of com.loohp.interactionvisualizer.entityholders.ItemFrame 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.ItemFrame in project InteractionVisualizer by LOOHP.
the class PacketManager method removeAll.
public static void removeAll(Player theplayer) {
playerStatus.put(theplayer, Collections.newSetFromMap(new ConcurrentHashMap<>()));
if (!plugin.isEnabled()) {
return;
}
InteractionVisualizer.asyncExecutorManager.runTaskAsynchronously(() -> {
Collection<Player> player = new HashSet<>();
player.add(theplayer);
int count = 0;
int delay = 1;
for (Entry<VisualizerEntity, Collection<Player>> entry : active.entrySet()) {
count++;
if (count > 5) {
delay++;
count = 0;
}
VisualizerEntity entity = entry.getKey();
if (entity instanceof ArmorStand) {
Bukkit.getScheduler().runTaskLater(plugin, () -> removeArmorStand(player, (ArmorStand) entity, false, false), delay);
}
if (entity instanceof Item) {
Bukkit.getScheduler().runTaskLater(plugin, () -> removeItem(player, (Item) entity, false, false), delay);
}
if (entity instanceof ItemFrame) {
Bukkit.getScheduler().runTaskLater(plugin, () -> removeItemFrame(player, (ItemFrame) entity, false, false), delay);
}
}
});
}
use of com.loohp.interactionvisualizer.entityholders.ItemFrame in project InteractionVisualizer by LOOHP.
the class PacketManager method sendPlayerPackets.
public static void sendPlayerPackets(Player theplayer) {
playerStatus.put(theplayer, Collections.newSetFromMap(new ConcurrentHashMap<VisualizerEntity, Boolean>()));
if (!plugin.isEnabled()) {
return;
}
InteractionVisualizer.asyncExecutorManager.runTaskAsynchronously(() -> {
Collection<Player> player = new HashSet<>();
player.add(theplayer);
int count = 0;
int delay = 1;
for (Entry<VisualizerEntity, Collection<Player>> entry : active.entrySet()) {
VisualizerEntity entity = entry.getKey();
if (entry.getValue().contains(theplayer)) {
Boolean isLoaded = loaded.get(entity);
if (isLoaded != null && isLoaded) {
count++;
if (count > 5) {
delay++;
count = 0;
}
if (entity instanceof ArmorStand) {
Bukkit.getScheduler().runTaskLater(plugin, () -> {
sendArmorStandSpawn(player, (ArmorStand) entity);
updateArmorStand(player, (ArmorStand) entity, true);
}, delay);
}
if (entity instanceof Item) {
Bukkit.getScheduler().runTaskLater(plugin, () -> {
sendItemSpawn(player, (Item) entity);
updateItem(player, (Item) entity, true);
}, delay);
}
if (entity instanceof ItemFrame) {
Bukkit.getScheduler().runTaskLater(plugin, () -> {
sendItemFrameSpawn(player, (ItemFrame) entity);
updateItemFrame(player, (ItemFrame) entity, true);
}, delay);
}
}
}
}
});
}
use of com.loohp.interactionvisualizer.entityholders.ItemFrame in project InteractionVisualizer by LOOHP.
the class PacketManager method run.
public static void run() {
if (!plugin.isEnabled()) {
return;
}
InteractionVisualizer.asyncExecutorManager.runTaskAsynchronously(() -> {
for (Entry<VisualizerEntity, Boolean> entry : loaded.entrySet()) {
VisualizerEntity entity = entry.getKey();
if (entity instanceof ArmorStand) {
ArmorStand stand = (ArmorStand) entity;
if (PlayerLocationManager.hasPlayerNearby(stand.getLocation())) {
if (entry.getValue()) {
Collection<Player> players = active.get(entity);
if (players != null) {
SyncUtils.runAsyncWithSyncCondition(() -> LocationUtils.isLoaded(stand.getLocation()) && isOccluding(stand.getLocation().getBlock().getType()), 200, () -> {
if (active.containsKey(entity)) {
removeArmorStand(InteractionVisualizerAPI.getPlayers(), stand, false, false);
loaded.put(entity, false);
}
});
}
} else {
Collection<Player> players = active.get(entity);
if (players != null) {
SyncUtils.runAsyncWithSyncCondition(() -> LocationUtils.isLoaded(stand.getLocation()) && !isOccluding(stand.getLocation().getBlock().getType()), 200, () -> {
if (active.containsKey(entity)) {
sendArmorStandSpawn(players, stand);
updateArmorStand(stand);
loaded.put(entity, true);
}
});
}
}
}
} else if (entity instanceof Item) {
Item item = (Item) entity;
if (PlayerLocationManager.hasPlayerNearby(item.getLocation())) {
if (entry.getValue()) {
Collection<Player> players = active.get(entity);
if (players != null) {
if (item.getVelocity().equals(VECTOR_ZERO) && !item.hasGravity()) {
updateItemAsync(item, true);
}
SyncUtils.runAsyncWithSyncCondition(() -> LocationUtils.isLoaded(item.getLocation()) && isOccluding(item.getLocation().getBlock().getType()), 200, () -> {
if (active.containsKey(entity)) {
removeItem(InteractionVisualizerAPI.getPlayers(), item, false, false);
loaded.put(entity, false);
}
});
}
} else {
Collection<Player> players = active.get(entity);
if (players != null) {
SyncUtils.runAsyncWithSyncCondition(() -> LocationUtils.isLoaded(item.getLocation()) && !isOccluding(item.getLocation().getBlock().getType()), 200, () -> {
if (active.containsKey(entity)) {
sendItemSpawn(players, item);
updateItem(item);
loaded.put(entity, true);
}
});
}
}
}
} else if (entity instanceof ItemFrame) {
ItemFrame frame = (ItemFrame) entity;
if (PlayerLocationManager.hasPlayerNearby(frame.getLocation())) {
if (entry.getValue()) {
Collection<Player> players = active.get(entity);
if (players != null) {
SyncUtils.runAsyncWithSyncCondition(() -> LocationUtils.isLoaded(frame.getLocation()) && isOccluding(frame.getLocation().getBlock().getType()), 200, () -> {
if (active.containsKey(entity)) {
removeItemFrame(InteractionVisualizerAPI.getPlayers(), frame, false, false);
loaded.put(entity, false);
}
});
}
} else {
Collection<Player> players = active.get(entity);
if (players != null) {
SyncUtils.runAsyncWithSyncCondition(() -> LocationUtils.isLoaded(frame.getLocation()) && !isOccluding(frame.getLocation().getBlock().getType()), 200, () -> {
if (active.containsKey(entity)) {
sendItemFrameSpawn(players, frame);
updateItemFrame(frame);
loaded.put(entity, true);
}
});
}
}
}
}
}
try {
TimeUnit.MILLISECONDS.sleep(5);
} catch (InterruptedException e) {
}
run();
});
}
Aggregations