Search in sources :

Example 1 with ArmorStand

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

the class InteractionVisualizerAPI method createArmorStandItemHoldingObject.

/**
 * Create a fake armorstand for holding mini items at the given location.
 * DOES NOT SPAWN THE ARMORSTAND.
 *
 * @return The InteractionVisualizer ArmorStand object created.
 */
public static ArmorStand createArmorStandItemHoldingObject(Location location) {
    Vector vector = rotateVectorAroundY(location.clone().getDirection().normalize().multiply(0.19), -100).add(location.clone().getDirection().normalize().multiply(-0.11));
    ArmorStand stand = new ArmorStand(location.add(vector));
    setStand(stand, location.getYaw());
    return stand;
}
Also used : ArmorStand(com.loohp.interactionvisualizer.entityholders.ArmorStand) Vector(org.bukkit.util.Vector)

Example 2 with ArmorStand

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

the class FurnaceDisplay method onBreakFurnace.

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

Example 3 with ArmorStand

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

the class GrindstoneDisplay method spawnArmorStands.

public Map<String, ArmorStand> spawnArmorStands(Player player, Block block) {
    // .add(0.68, 0.600781, 0.35)
    Map<String, ArmorStand> map = new HashMap<>();
    Location loc = block.getLocation().clone().add(0.5, 0.600781, 0.5);
    ArmorStand center = new ArmorStand(loc);
    float yaw = getCardinalDirection(player);
    center.setRotation(yaw, center.getLocation().getPitch());
    setStand(center);
    center.setCustomName("IV.Grindstone.Center");
    Vector vector = rotateVectorAroundY(center.getLocation().clone().getDirection().normalize().multiply(0.19), -100).add(center.getLocation().clone().getDirection().normalize().multiply(-0.11));
    ArmorStand middle = new ArmorStand(loc.clone().add(vector));
    setStand(middle, yaw);
    ArmorStand slot0 = new ArmorStand(middle.getLocation().clone().add(rotateVectorAroundY(center.getLocation().clone().getDirection().normalize().multiply(0.2), -90)));
    setStand(slot0, yaw + 20);
    ArmorStand slot1 = new ArmorStand(middle.getLocation().clone().add(rotateVectorAroundY(center.getLocation().clone().getDirection().normalize().multiply(0.2), 90)));
    setStand(slot1, yaw - 20);
    map.put("0", slot0);
    map.put("1", slot1);
    PacketManager.sendArmorStandSpawn(InteractionVisualizerAPI.getPlayerModuleList(Modules.ITEMSTAND, KEY), slot0);
    PacketManager.sendArmorStandSpawn(InteractionVisualizerAPI.getPlayerModuleList(Modules.ITEMSTAND, KEY), slot1);
    return map;
}
Also used : ArmorStand(com.loohp.interactionvisualizer.entityholders.ArmorStand) HashMap(java.util.HashMap) Vector(org.bukkit.util.Vector) Location(org.bukkit.Location)

Example 4 with ArmorStand

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

the class GrindstoneDisplay method onCloseGrindstone.

@EventHandler
public void onCloseGrindstone(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 (!openedGrindstone.containsKey(block)) {
        return;
    }
    Map<String, Object> map = openedGrindstone.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);
            }
        }
    }
    openedGrindstone.remove(block);
}
Also used : Item(com.loohp.interactionvisualizer.entityholders.Item) ArmorStand(com.loohp.interactionvisualizer.entityholders.ArmorStand) Block(org.bukkit.block.Block) EventHandler(org.bukkit.event.EventHandler)

Example 5 with ArmorStand

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

the class GrindstoneDisplay method process.

@Override
public void process(Player player) {
    if (VanishUtils.isVanished(player)) {
        return;
    }
    if (player.getGameMode().equals(GameMode.SPECTATOR)) {
        return;
    }
    if (player.getOpenInventory().getTopInventory().getLocation() == null) {
        return;
    }
    if (!LocationUtils.isLoaded(player.getOpenInventory().getTopInventory().getLocation())) {
        return;
    }
    if (player.getOpenInventory().getTopInventory().getLocation().getBlock() == null) {
        return;
    }
    if (!player.getOpenInventory().getTopInventory().getLocation().getBlock().getType().equals(Material.GRINDSTONE)) {
        return;
    }
    InventoryView view = player.getOpenInventory();
    Block block = view.getTopInventory().getLocation().getBlock();
    Location loc = block.getLocation();
    if (!openedGrindstone.containsKey(block)) {
        Map<String, Object> map = new HashMap<>();
        map.put("Player", player);
        map.put("2", "N/A");
        map.putAll(spawnArmorStands(player, block));
        openedGrindstone.put(block, map);
    }
    Map<String, Object> map = openedGrindstone.get(block);
    if (!map.get("Player").equals(player)) {
        return;
    }
    ItemStack[] items = new ItemStack[] { view.getItem(0), view.getItem(1) };
    if (view.getItem(2) != null) {
        ItemStack itemstack = view.getItem(2);
        if (itemstack == null || itemstack.getType().equals(Material.AIR)) {
            itemstack = null;
        }
        Item item = null;
        if (map.get("2") instanceof String) {
            if (itemstack != null) {
                item = new Item(loc.clone().add(0.5, 1.2, 0.5));
                item.setItemStack(itemstack);
                item.setVelocity(new Vector(0, 0, 0));
                item.setPickupDelay(32767);
                item.setGravity(false);
                map.put("2", item);
                PacketManager.sendItemSpawn(InteractionVisualizerAPI.getPlayerModuleList(Modules.ITEMDROP, KEY), item);
                PacketManager.updateItem(item);
            } else {
                map.put("2", "N/A");
            }
        } else {
            item = (Item) map.get("2");
            if (itemstack != null) {
                if (!item.getItemStack().equals(itemstack)) {
                    item.setItemStack(itemstack);
                    PacketManager.updateItem(item);
                }
            } else {
                map.put("2", "N/A");
                PacketManager.removeItem(InteractionVisualizerAPI.getPlayers(), item);
            }
        }
    }
    for (int i = 0; i < 2; i++) {
        ArmorStand stand = (ArmorStand) map.get(String.valueOf(i));
        ItemStack item = items[i];
        if (item == null || item.getType().equals(Material.AIR)) {
            item = null;
        }
        if (item != null) {
            boolean changed = true;
            if (MaterialUtils.getMaterialType(item.getType()).equals(MaterialMode.BLOCK) && !standMode(stand).equals(MaterialMode.BLOCK)) {
                toggleStandMode(stand, "Block");
            } else if (MaterialUtils.getMaterialType(item.getType()).equals(MaterialMode.TOOL) && !standMode(stand).equals(MaterialMode.TOOL)) {
                toggleStandMode(stand, "Tool");
            } else if (MaterialUtils.getMaterialType(item.getType()).equals(MaterialMode.ITEM) && !standMode(stand).equals(MaterialMode.ITEM)) {
                toggleStandMode(stand, "Item");
            } else if (MaterialUtils.getMaterialType(item.getType()).equals(MaterialMode.STANDING) && !standMode(stand).equals(MaterialMode.STANDING)) {
                toggleStandMode(stand, "Standing");
            } else if (MaterialUtils.getMaterialType(item.getType()).equals(MaterialMode.LOWBLOCK) && !standMode(stand).equals(MaterialMode.LOWBLOCK)) {
                toggleStandMode(stand, "LowBlock");
            } else {
                changed = false;
            }
            if (!item.getType().equals(stand.getItemInMainHand().getType())) {
                changed = true;
                stand.setItemInMainHand(item);
            }
            if (changed) {
                PacketManager.updateArmorStand(stand);
            }
        } else {
            if (!stand.getItemInMainHand().getType().equals(Material.AIR)) {
                stand.setItemInMainHand(new ItemStack(Material.AIR));
                PacketManager.updateArmorStand(stand);
            }
        }
    }
}
Also used : HashMap(java.util.HashMap) Item(com.loohp.interactionvisualizer.entityholders.Item) InventoryView(org.bukkit.inventory.InventoryView) ArmorStand(com.loohp.interactionvisualizer.entityholders.ArmorStand) Block(org.bukkit.block.Block) ItemStack(org.bukkit.inventory.ItemStack) Vector(org.bukkit.util.Vector) Location(org.bukkit.Location)

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