Search in sources :

Example 6 with ItemFrame

use of com.loohp.interactionvisualizer.entityholders.ItemFrame in project InteractionVisualizer by LOOHP.

the class CartographyTableDisplay method run.

@Override
public int run() {
    return new BukkitRunnable() {

        public void run() {
            Iterator<Block> itr = openedCTable.keySet().iterator();
            int count = 0;
            int maxper = (int) Math.ceil((double) openedCTable.size() / (double) 5);
            int delay = 1;
            while (itr.hasNext()) {
                count++;
                if (count > maxper) {
                    count = 0;
                    delay++;
                }
                Block block = itr.next();
                new BukkitRunnable() {

                    public void run() {
                        if (!openedCTable.containsKey(block)) {
                            return;
                        }
                        Map<String, Object> map = openedCTable.get(block);
                        if (block.getType().equals(Material.CARTOGRAPHY_TABLE)) {
                            Player player = (Player) map.get("Player");
                            if (!player.getGameMode().equals(GameMode.SPECTATOR)) {
                                if (player.getOpenInventory() != null) {
                                    if (player.getOpenInventory().getTopInventory() != null) {
                                        if (player.getOpenInventory().getTopInventory() instanceof CartographyInventory) {
                                            return;
                                        }
                                    }
                                }
                            }
                        }
                        if (map.get("Item") instanceof ItemFrame) {
                            Entity entity = (Entity) map.get("Item");
                            PacketManager.removeItemFrame(InteractionVisualizerAPI.getPlayers(), (ItemFrame) entity);
                        }
                        openedCTable.remove(block);
                    }
                }.runTaskLater(InteractionVisualizer.plugin, delay);
            }
        }
    }.runTaskTimer(InteractionVisualizer.plugin, 0, 6).getTaskId();
}
Also used : CartographyInventory(org.bukkit.inventory.CartographyInventory) Entity(org.bukkit.entity.Entity) Player(org.bukkit.entity.Player) BukkitRunnable(org.bukkit.scheduler.BukkitRunnable) Block(org.bukkit.block.Block) ItemFrame(com.loohp.interactionvisualizer.entityholders.ItemFrame) HashMap(java.util.HashMap) Map(java.util.Map)

Example 7 with ItemFrame

use of com.loohp.interactionvisualizer.entityholders.ItemFrame in project InteractionVisualizer by LOOHP.

the class CartographyTableDisplay method process.

@Override
public void process(Player player) {
    if (VanishUtils.isVanished(player)) {
        return;
    }
    if (!playermap.containsKey(player)) {
        if (player.getGameMode().equals(GameMode.SPECTATOR)) {
            return;
        }
        if (!(player.getOpenInventory().getTopInventory() instanceof CartographyInventory)) {
            return;
        }
        Block block = player.getTargetBlockExact(7, FluidCollisionMode.NEVER);
        if (block == null || !block.getType().equals(Material.CARTOGRAPHY_TABLE)) {
            return;
        }
        playermap.put(player, block);
    }
    InventoryView view = player.getOpenInventory();
    Block block = playermap.get(player);
    if (!openedCTable.containsKey(block)) {
        Map<String, Object> map = new HashMap<>();
        map.put("Player", player);
        map.put("Item", "N/A");
        openedCTable.put(block, map);
    }
    Map<String, Object> map = openedCTable.get(block);
    if (!map.get("Player").equals(player)) {
        return;
    }
    ItemStack input = view.getItem(0);
    if (input != null) {
        if (input.getType().equals(Material.AIR)) {
            input = null;
        }
    }
    ItemStack output = view.getItem(2);
    if (output != null) {
        if (output.getType().equals(Material.AIR)) {
            output = null;
        }
    }
    ItemStack itemstack = null;
    if (output == null) {
        if (input != null) {
            itemstack = input;
        }
    } else {
        itemstack = output;
    }
    ItemFrame item = null;
    if (!block.getRelative(BlockFace.UP).getType().isSolid()) {
        if (map.get("Item") instanceof String) {
            if (itemstack != null) {
                item = new ItemFrame(block.getRelative(BlockFace.UP).getLocation());
                item.setItem(itemstack);
                item.setFacingDirection(BlockFace.UP);
                item.setSilent(true);
                map.put("Item", item);
                PacketManager.sendItemFrameSpawn(InteractionVisualizerAPI.getPlayerModuleList(Modules.ITEMSTAND, KEY), item);
                PacketManager.updateItemFrame(item);
            } else {
                map.put("Item", "N/A");
            }
        } else {
            item = (ItemFrame) map.get("Item");
            if (itemstack != null) {
                if (!item.getItem().equals(itemstack)) {
                    item.setItem(itemstack);
                    PacketManager.updateItemFrame(item);
                }
            } else {
                map.put("Item", "N/A");
                PacketManager.removeItemFrame(InteractionVisualizerAPI.getPlayers(), item);
            }
        }
    }
}
Also used : CartographyInventory(org.bukkit.inventory.CartographyInventory) InventoryView(org.bukkit.inventory.InventoryView) HashMap(java.util.HashMap) Block(org.bukkit.block.Block) ItemFrame(com.loohp.interactionvisualizer.entityholders.ItemFrame) ItemStack(org.bukkit.inventory.ItemStack)

Aggregations

ItemFrame (com.loohp.interactionvisualizer.entityholders.ItemFrame)7 Player (org.bukkit.entity.Player)6 ArmorStand (com.loohp.interactionvisualizer.entityholders.ArmorStand)4 DynamicVisualizerEntity (com.loohp.interactionvisualizer.entityholders.DynamicVisualizerEntity)4 Item (com.loohp.interactionvisualizer.entityholders.Item)4 VisualizerEntity (com.loohp.interactionvisualizer.entityholders.VisualizerEntity)4 Collection (java.util.Collection)4 HashSet (java.util.HashSet)3 Block (org.bukkit.block.Block)3 HashMap (java.util.HashMap)2 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)2 CartographyInventory (org.bukkit.inventory.CartographyInventory)2 Map (java.util.Map)1 Location (org.bukkit.Location)1 Entity (org.bukkit.entity.Entity)1 EventHandler (org.bukkit.event.EventHandler)1 InventoryView (org.bukkit.inventory.InventoryView)1 ItemStack (org.bukkit.inventory.ItemStack)1 BukkitRunnable (org.bukkit.scheduler.BukkitRunnable)1