mirror of
https://github.com/amalthea-mc/ShopChest.git
synced 2024-11-22 10:22:29 +00:00
Show and hide holograms asynchronously
This commit is contained in:
parent
bae02c910a
commit
8b8c7d4d73
@ -5,6 +5,7 @@ import de.epiceric.shopchest.utils.Utils;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.ArmorStand;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
@ -124,7 +125,10 @@ public class Hologram {
|
||||
/**
|
||||
* @param p Player to which the hologram should be shown
|
||||
*/
|
||||
public void showPlayer(Player p) {
|
||||
public void showPlayer(final Player p) {
|
||||
new BukkitRunnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
for (Object o : entityList) {
|
||||
try {
|
||||
Object entityLiving = entityLivingClass.cast(o);
|
||||
@ -137,13 +141,19 @@ public class Hologram {
|
||||
plugin.debug(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}.runTaskAsynchronously(plugin);
|
||||
|
||||
visible.add(p);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param p Player from which the hologram should be hidden
|
||||
*/
|
||||
public void hidePlayer(Player p) {
|
||||
public void hidePlayer(final Player p) {
|
||||
new BukkitRunnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
for (Object o : entityList) {
|
||||
try {
|
||||
int id = (int) entityArmorStandClass.getMethod("getId").invoke(o);
|
||||
@ -157,6 +167,9 @@ public class Hologram {
|
||||
plugin.debug(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}.runTaskAsynchronously(plugin);
|
||||
|
||||
visible.remove(p);
|
||||
}
|
||||
|
||||
@ -185,7 +198,7 @@ public class Hologram {
|
||||
|
||||
/**
|
||||
* Removes the hologram. <br>
|
||||
* IHologram will be hidden from all players and will be killed
|
||||
* Hologram will be hidden from all players and will be killed
|
||||
*/
|
||||
public void remove() {
|
||||
for (Object o : entityList) {
|
||||
|
@ -247,19 +247,20 @@ public class ShopUtils {
|
||||
|
||||
if (distSqr <= holoDistSqr) {
|
||||
if (shop.getHologram() != null) {
|
||||
Block b = shop.getLocation().getBlock();
|
||||
Material type = shop.getLocation().getBlock().getType();
|
||||
|
||||
if (b.getType() != Material.CHEST && b.getType() != Material.TRAPPED_CHEST) {
|
||||
if (type != Material.CHEST && type != Material.TRAPPED_CHEST) {
|
||||
plugin.getShopUtils().removeShop(shop, plugin.getShopChestConfig().remove_shop_on_error);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!shop.getHologram().isVisible(player)) {
|
||||
shop.getHologram().showPlayer(player);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (shop.getHologram() != null) shop.getHologram().hidePlayer(player);
|
||||
if (shop.getHologram() != null) {
|
||||
shop.getHologram().hidePlayer(player);
|
||||
}
|
||||
}
|
||||
|
||||
if (distSqr <= itemDistSqr) {
|
||||
|
Loading…
Reference in New Issue
Block a user