Search in sources :

Example 26 with ArmorStand

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

the class GrindstoneDisplay method onGrindstone.

@EventHandler(priority = EventPriority.MONITOR)
public void onGrindstone(InventoryClickEvent event) {
    if (VanishUtils.isVanished((Player) event.getWhoClicked())) {
        return;
    }
    if (event.isCancelled()) {
        return;
    }
    if (event.getRawSlot() != 2) {
        return;
    }
    if (event.getCurrentItem() == null) {
        return;
    }
    if (event.getCurrentItem().getType().equals(Material.AIR)) {
        return;
    }
    if (event.getCursor() != null) {
        if (!event.getCursor().getType().equals(Material.AIR)) {
            if (event.getCursor().getAmount() >= event.getCursor().getType().getMaxStackSize()) {
                return;
            }
        }
    }
    if (event.isShiftClick()) {
        if (!InventoryUtils.stillHaveSpace(event.getWhoClicked().getInventory(), event.getView().getItem(2).getType())) {
            return;
        }
    }
    if (event.getAction().equals(InventoryAction.HOTBAR_MOVE_AND_READD)) {
        if (event.getWhoClicked().getInventory().getItem(event.getHotbarButton()) != null && !event.getWhoClicked().getInventory().getItem(event.getHotbarButton()).getType().equals(Material.AIR)) {
            return;
        }
    }
    if (event.getView().getTopInventory() == null) {
        return;
    }
    try {
        if (event.getView().getTopInventory().getLocation() == null) {
            return;
        }
    } catch (Exception | AbstractMethodError e) {
        return;
    }
    if (event.getView().getTopInventory().getLocation().getBlock() == null) {
        return;
    }
    if (!event.getView().getTopInventory().getLocation().getBlock().getType().equals(Material.GRINDSTONE)) {
        return;
    }
    Block block = event.getView().getTopInventory().getLocation().getBlock();
    if (!openedGrindstone.containsKey(block)) {
        return;
    }
    Map<String, Object> map = openedGrindstone.get(block);
    if (!map.get("Player").equals(event.getWhoClicked())) {
        return;
    }
    ItemStack itemstack = event.getCurrentItem().clone();
    Location loc = block.getLocation();
    Player player = (Player) event.getWhoClicked();
    ArmorStand slot0 = (ArmorStand) map.get("0");
    ArmorStand slot1 = (ArmorStand) map.get("1");
    if (map.get("2") instanceof String) {
        map.put("2", new Item(block.getLocation().clone().add(0.5, 1.2, 0.5)));
    }
    Item item = (Item) map.get("2");
    Inventory before = Bukkit.createInventory(null, 9);
    before.setItem(0, player.getOpenInventory().getItem(0).clone());
    before.setItem(1, player.getOpenInventory().getItem(1).clone());
    Bukkit.getScheduler().runTaskLater(InteractionVisualizer.plugin, () -> {
        Inventory after = Bukkit.createInventory(null, 9);
        after.setItem(0, player.getOpenInventory().getItem(0).clone());
        after.setItem(1, player.getOpenInventory().getItem(1).clone());
        if (InventoryUtils.compareContents(before, after)) {
            return;
        }
        slot0.setLocked(true);
        slot1.setLocked(true);
        item.setLocked(true);
        openedGrindstone.remove(block);
        float yaw = getCardinalDirection(player);
        Vector vector = new Location(slot0.getWorld(), slot0.getLocation().getX(), slot0.getLocation().getY(), slot0.getLocation().getZ(), yaw, 0).getDirection().normalize();
        slot0.teleport(slot0.getLocation().add(rotateVectorAroundY(vector.clone(), 90).multiply(0.1)));
        slot1.teleport(slot1.getLocation().add(rotateVectorAroundY(vector.clone(), -90).multiply(0.1)));
        PacketManager.updateArmorStand(slot0);
        PacketManager.updateArmorStand(slot1);
        Bukkit.getScheduler().runTaskLater(InteractionVisualizer.plugin, () -> {
            for (Player each : InteractionVisualizerAPI.getPlayerModuleList(Modules.ITEMDROP, KEY)) {
                each.spawnParticle(Particle.CLOUD, loc.clone().add(0.5, 1.1, 0.5), 10, 0.05, 0.05, 0.05, 0.05);
            }
        }, 6);
        Bukkit.getScheduler().runTaskLater(InteractionVisualizer.plugin, () -> {
            Vector lift = new Vector(0.0, 0.15, 0.0);
            Vector pickup = player.getEyeLocation().add(0.0, -0.5, 0.0).add(0.0, InteractionVisualizer.playerPickupYOffset, 0.0).toVector().subtract(loc.clone().add(0.5, 1.2, 0.5).toVector()).multiply(0.15).add(lift);
            item.setItemStack(itemstack);
            item.setVelocity(pickup);
            item.setGravity(true);
            item.setPickupDelay(32767);
            PacketManager.updateItem(item);
            Bukkit.getScheduler().runTaskLater(InteractionVisualizer.plugin, () -> {
                SoundManager.playItemPickup(item.getLocation(), InteractionVisualizerAPI.getPlayerModuleList(Modules.ITEMDROP, KEY));
                PacketManager.removeArmorStand(InteractionVisualizerAPI.getPlayers(), slot0);
                PacketManager.removeArmorStand(InteractionVisualizerAPI.getPlayers(), slot1);
                PacketManager.removeItem(InteractionVisualizerAPI.getPlayers(), item);
            }, 8);
        }, 10);
    }, 1);
}
Also used : Player(org.bukkit.entity.Player) Item(com.loohp.interactionvisualizer.entityholders.Item) ArmorStand(com.loohp.interactionvisualizer.entityholders.ArmorStand) Block(org.bukkit.block.Block) ItemStack(org.bukkit.inventory.ItemStack) Vector(org.bukkit.util.Vector) Inventory(org.bukkit.inventory.Inventory) Location(org.bukkit.Location) EventHandler(org.bukkit.event.EventHandler)

Example 27 with ArmorStand

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

the class LecternDisplay method onBreakLectern.

@EventHandler(priority = EventPriority.MONITOR)
public void onBreakLectern(TileEntityRemovedEvent event) {
    Block block = event.getBlock();
    if (!lecternMap.containsKey(block)) {
        return;
    }
    Map<String, Object> map = lecternMap.get(block);
    if (map.get("1") instanceof ArmorStand) {
        ArmorStand stand = (ArmorStand) map.get("1");
        PacketManager.removeArmorStand(InteractionVisualizerAPI.getPlayers(), stand);
    }
    if (map.get("2") instanceof ArmorStand) {
        ArmorStand stand = (ArmorStand) map.get("2");
        PacketManager.removeArmorStand(InteractionVisualizerAPI.getPlayers(), stand);
    }
    lecternMap.remove(block);
}
Also used : ArmorStand(com.loohp.interactionvisualizer.entityholders.ArmorStand) Block(org.bukkit.block.Block) EventHandler(org.bukkit.event.EventHandler)

Example 28 with ArmorStand

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

the class LecternDisplay method spawnArmorStands.

public Map<String, ArmorStand> spawnArmorStands(Block block) {
    Map<String, ArmorStand> map = new HashMap<>();
    Location origin = block.getLocation();
    BlockData blockData = block.getState().getBlockData();
    BlockFace facing = ((Directional) blockData).getFacing();
    Location target = block.getRelative(facing).getLocation();
    Vector direction = target.toVector().subtract(origin.toVector()).multiply(0.2);
    Location loc = origin.clone().add(direction).add(0.5, 1.301, 0.5);
    ArmorStand slot1 = new ArmorStand(loc.clone());
    setStand(slot1);
    ArmorStand slot2 = new ArmorStand(loc.clone().add(0, -0.3, 0));
    setStand(slot2);
    map.put("1", slot1);
    map.put("2", slot2);
    PacketManager.sendArmorStandSpawn(InteractionVisualizerAPI.getPlayerModuleList(Modules.HOLOGRAM, KEY), slot1);
    PacketManager.sendArmorStandSpawn(InteractionVisualizerAPI.getPlayerModuleList(Modules.HOLOGRAM, KEY), slot2);
    return map;
}
Also used : ArmorStand(com.loohp.interactionvisualizer.entityholders.ArmorStand) HashMap(java.util.HashMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) BlockFace(org.bukkit.block.BlockFace) BlockData(org.bukkit.block.data.BlockData) Vector(org.bukkit.util.Vector) Location(org.bukkit.Location) Directional(org.bukkit.block.data.Directional)

Example 29 with ArmorStand

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

the class LoomDisplay method run.

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

        public void run() {
            Iterator<Block> itr = openedLooms.keySet().iterator();
            int count = 0;
            int maxper = (int) Math.ceil((double) openedLooms.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 (!openedLooms.containsKey(block)) {
                            return;
                        }
                        Map<String, Object> map = openedLooms.get(block);
                        if (block.getType().equals(Material.LOOM)) {
                            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().getLocation().getBlock().getType().equals(Material.LOOM)) {
                                            return;
                                        }
                                    }
                                }
                            }
                        }
                        if (map.get("Banner") instanceof ArmorStand) {
                            ArmorStand entity = (ArmorStand) map.get("Banner");
                            InteractionVisualizer.lightManager.deleteLight(entity.getLocation());
                            PacketManager.removeArmorStand(InteractionVisualizerAPI.getPlayers(), entity);
                        }
                        openedLooms.remove(block);
                    }
                }.runTaskLater(InteractionVisualizer.plugin, delay);
            }
        }
    }.runTaskTimer(InteractionVisualizer.plugin, 0, 5).getTaskId();
}
Also used : Player(org.bukkit.entity.Player) ArmorStand(com.loohp.interactionvisualizer.entityholders.ArmorStand) BukkitRunnable(org.bukkit.scheduler.BukkitRunnable) Block(org.bukkit.block.Block) HashMap(java.util.HashMap) Map(java.util.Map)

Example 30 with ArmorStand

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

the class LoomDisplay method onCloseLoom.

@EventHandler
public void onCloseLoom(InventoryCloseEvent event) {
    if (event.getView().getTopInventory() == null) {
        return;
    }
    try {
        if (event.getView().getTopInventory().getLocation() == null) {
            return;
        }
    } catch (Exception | AbstractMethodError e) {
        return;
    }
    if (event.getView().getTopInventory().getLocation().getBlock() == null) {
        return;
    }
    Block block = event.getView().getTopInventory().getLocation().getBlock();
    if (!openedLooms.containsKey(block)) {
        return;
    }
    Map<String, Object> map = openedLooms.get(block);
    if (!map.get("Player").equals(event.getPlayer())) {
        return;
    }
    if (event.getView().getItem(0) != null) {
        if (!event.getView().getItem(0).getType().equals(Material.AIR)) {
            Player player = (Player) event.getPlayer();
            Item item = new Item(block.getLocation().clone().add(0.5, 1.5, 0.5));
            item.setItemStack(event.getView().getItem(0));
            item.setLocked(true);
            item.setGravity(true);
            Vector lift = new Vector(0.0, 0.15, 0.0);
            Vector pickup = player.getEyeLocation().add(0.0, -0.5, 0.0).add(0.0, InteractionVisualizer.playerPickupYOffset, 0.0).toVector().subtract(block.getLocation().clone().add(0.5, 1.2, 0.5).toVector()).multiply(0.15).add(lift);
            item.setVelocity(pickup);
            item.setPickupDelay(32767);
            PacketManager.sendItemSpawn(InteractionVisualizerAPI.getPlayerModuleList(Modules.ITEMDROP, KEY), item);
            PacketManager.updateItem(item);
            new BukkitRunnable() {

                public void run() {
                    PacketManager.removeItem(InteractionVisualizerAPI.getPlayers(), item);
                }
            }.runTaskLater(InteractionVisualizer.plugin, 8);
        }
    }
    if (map.get("Banner") instanceof ArmorStand) {
        ArmorStand entity = (ArmorStand) map.get("Banner");
        InteractionVisualizer.lightManager.deleteLight(entity.getLocation());
        PacketManager.removeArmorStand(InteractionVisualizerAPI.getPlayers(), entity);
    }
    openedLooms.remove(block);
}
Also used : Item(com.loohp.interactionvisualizer.entityholders.Item) Player(org.bukkit.entity.Player) ArmorStand(com.loohp.interactionvisualizer.entityholders.ArmorStand) Block(org.bukkit.block.Block) BukkitRunnable(org.bukkit.scheduler.BukkitRunnable) Vector(org.bukkit.util.Vector) EventHandler(org.bukkit.event.EventHandler)

Aggregations

ArmorStand (com.loohp.interactionvisualizer.entityholders.ArmorStand)56 Location (org.bukkit.Location)30 Block (org.bukkit.block.Block)30 HashMap (java.util.HashMap)25 Vector (org.bukkit.util.Vector)24 Item (com.loohp.interactionvisualizer.entityholders.Item)23 EventHandler (org.bukkit.event.EventHandler)23 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)16 Player (org.bukkit.entity.Player)14 BlockFace (org.bukkit.block.BlockFace)9 ItemStack (org.bukkit.inventory.ItemStack)9 BlockData (org.bukkit.block.data.BlockData)8 Directional (org.bukkit.block.data.Directional)7 SurroundingPlaneArmorStand (com.loohp.interactionvisualizer.entityholders.SurroundingPlaneArmorStand)6 InventoryView (org.bukkit.inventory.InventoryView)5 DynamicVisualizerEntity (com.loohp.interactionvisualizer.entityholders.DynamicVisualizerEntity)4 ItemFrame (com.loohp.interactionvisualizer.entityholders.ItemFrame)4 VisualizerEntity (com.loohp.interactionvisualizer.entityholders.VisualizerEntity)4 Collection (java.util.Collection)4 Inventory (org.bukkit.inventory.Inventory)4