Search in sources :

Example 6 with ArmorStand

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

the class LoomDisplay method spawnArmorStands.

public Map<String, ArmorStand> spawnArmorStands(Player player, Block block) {
    Map<String, ArmorStand> map = new HashMap<>();
    Location loc = block.getLocation().clone().add(0.5, 0.01, 0.5);
    Location temploc = new Location(loc.getWorld(), loc.getX(), loc.getY(), loc.getZ()).setDirection(player.getLocation().getDirection().normalize().multiply(-1));
    float yaw = temploc.getYaw();
    ArmorStand banner = new ArmorStand(loc.clone());
    setStand(banner, yaw);
    map.put("Banner", banner);
    PacketManager.sendArmorStandSpawn(InteractionVisualizerAPI.getPlayerModuleList(Modules.ITEMSTAND, KEY), banner);
    return map;
}
Also used : ArmorStand(com.loohp.interactionvisualizer.entityholders.ArmorStand) HashMap(java.util.HashMap) Location(org.bukkit.Location)

Example 7 with ArmorStand

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

the class SmithingTableDisplay method onSmithingTable.

@EventHandler(priority = EventPriority.MONITOR)
public void onSmithingTable(InventoryClickEvent event) {
    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 (!playermap.containsKey((Player) event.getWhoClicked())) {
        return;
    }
    Block block = event.getWhoClicked().getTargetBlockExact(7, FluidCollisionMode.NEVER);
    if (!openedSTables.containsKey(block)) {
        return;
    }
    Map<String, Object> map = openedSTables.get(block);
    if (!map.get("Player").equals(event.getWhoClicked())) {
        return;
    }
    ItemStack itemstack = event.getCurrentItem();
    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);
        openedSTables.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 : Item(com.loohp.interactionvisualizer.entityholders.Item) Player(org.bukkit.entity.Player) ArmorStand(com.loohp.interactionvisualizer.entityholders.ArmorStand) Block(org.bukkit.block.Block) ItemStack(org.bukkit.inventory.ItemStack) Vector(org.bukkit.util.Vector) SmithingInventory(org.bukkit.inventory.SmithingInventory) Inventory(org.bukkit.inventory.Inventory) Location(org.bukkit.Location) EventHandler(org.bukkit.event.EventHandler)

Example 8 with ArmorStand

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

the class SmithingTableDisplay method onCloseSmithingTable.

@EventHandler
public void onCloseSmithingTable(InventoryCloseEvent event) {
    if (!playermap.containsKey((Player) event.getPlayer())) {
        return;
    }
    Block block = playermap.get((Player) event.getPlayer());
    if (!openedSTables.containsKey(block)) {
        return;
    }
    Map<String, Object> map = openedSTables.get(block);
    if (!map.get("Player").equals(event.getPlayer())) {
        return;
    }
    for (int i = 0; i <= 2; i++) {
        if (!(map.get(String.valueOf(i)) instanceof String)) {
            Object entity = map.get(String.valueOf(i));
            if (entity instanceof Item) {
                PacketManager.removeItem(InteractionVisualizerAPI.getPlayers(), (Item) entity);
            } else if (entity instanceof ArmorStand) {
                PacketManager.removeArmorStand(InteractionVisualizerAPI.getPlayers(), (ArmorStand) entity);
            }
        }
    }
    if (map.get("0") instanceof ArmorStand) {
        ArmorStand entity = (ArmorStand) map.get("0");
        InteractionVisualizer.lightManager.deleteLight(entity.getLocation());
        PacketManager.removeArmorStand(InteractionVisualizerAPI.getPlayers(), entity);
    }
    openedSTables.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) EventHandler(org.bukkit.event.EventHandler)

Example 9 with ArmorStand

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

the class SmokerDisplay 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.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;
}
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 10 with ArmorStand

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

the class CampfireDisplay method onBreakCampfire.

@EventHandler(priority = EventPriority.MONITOR)
public void onBreakCampfire(TileEntityRemovedEvent event) {
    Block block = event.getBlock();
    if (!campfireMap.containsKey(block)) {
        return;
    }
    Map<String, Object> map = campfireMap.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);
    }
    if (map.get("3") instanceof ArmorStand) {
        ArmorStand stand = (ArmorStand) map.get("3");
        PacketManager.removeArmorStand(InteractionVisualizerAPI.getPlayers(), stand);
    }
    if (map.get("4") instanceof ArmorStand) {
        ArmorStand stand = (ArmorStand) map.get("4");
        PacketManager.removeArmorStand(InteractionVisualizerAPI.getPlayers(), stand);
    }
    campfireMap.remove(block);
}
Also used : ArmorStand(com.loohp.interactionvisualizer.entityholders.ArmorStand) Block(org.bukkit.block.Block) 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