use of com.loohp.interactionvisualizer.entityholders.ArmorStand in project InteractionVisualizer by LOOHP.
the class ConduitDisplay method onBreakConduit.
@EventHandler(priority = EventPriority.MONITOR)
public void onBreakConduit(TileEntityRemovedEvent event) {
Block block = event.getBlock();
if (!conduitMap.containsKey(block)) {
return;
}
Map<String, Object> map = conduitMap.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);
}
conduitMap.remove(block);
}
use of com.loohp.interactionvisualizer.entityholders.ArmorStand in project InteractionVisualizer by LOOHP.
the class CraftingTableDisplay 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().getLocation() == null) {
return;
}
if (player.getOpenInventory().getTopInventory().getLocation().getBlock() == null) {
return;
}
if (!InteractionVisualizer.version.isLegacy()) {
if (!InteractionVisualizer.version.equals(MCVersion.V1_13) && !InteractionVisualizer.version.equals(MCVersion.V1_13_1)) {
if (!player.getOpenInventory().getTopInventory().getLocation().getBlock().getType().toString().equalsIgnoreCase("CRAFTING_TABLE")) {
return;
}
} else {
if (!(player.getOpenInventory().getTopInventory() instanceof CraftingInventory)) {
return;
}
if (((CraftingInventory) player.getOpenInventory().getTopInventory()).getMatrix().length != 9) {
return;
}
if (!player.getTargetBlock(MaterialUtils.getNonSolidSet(), 7).getType().toString().equalsIgnoreCase("CRAFTING_TABLE")) {
return;
}
}
} else {
if (!(player.getOpenInventory().getTopInventory() instanceof CraftingInventory)) {
return;
}
if (((CraftingInventory) player.getOpenInventory().getTopInventory()).getMatrix().length != 9) {
return;
}
if (!player.getTargetBlock(MaterialUtils.getNonSolidSet(), 7).getType().toString().equalsIgnoreCase("WORKBENCH")) {
return;
}
}
Block block = null;
InventoryView view = player.getOpenInventory();
if (!InteractionVisualizer.version.isLegacy() && !InteractionVisualizer.version.equals(MCVersion.V1_13) && !InteractionVisualizer.version.equals(MCVersion.V1_13_1)) {
block = view.getTopInventory().getLocation().getBlock();
} else {
block = player.getTargetBlock(MaterialUtils.getNonSolidSet(), 7);
}
playermap.put(player, block);
}
InventoryView view = player.getOpenInventory();
Block block = playermap.get(player);
Location loc = block.getLocation();
if (!openedBenches.containsKey(block)) {
Map<String, Object> map = new HashMap<>();
map.put("Player", player);
map.put("0", "N/A");
map.putAll(spawnArmorStands(player, block));
openedBenches.put(block, map);
}
Map<String, Object> map = openedBenches.get(block);
if (!map.get("Player").equals(player)) {
return;
}
ItemStack[] items = new ItemStack[] { view.getItem(1), view.getItem(2), view.getItem(3), view.getItem(4), view.getItem(5), view.getItem(6), view.getItem(7), view.getItem(8), view.getItem(9) };
if (view.getItem(0) != null) {
ItemStack itemstack = view.getItem(0);
if (itemstack == null || itemstack.getType().equals(Material.AIR)) {
itemstack = null;
}
Item item = null;
if (map.get("0") 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("0", item);
PacketManager.sendItemSpawn(InteractionVisualizerAPI.getPlayerModuleList(Modules.ITEMDROP, KEY), item);
PacketManager.updateItem(item);
} else {
map.put("0", "N/A");
}
} else {
item = (Item) map.get("0");
if (itemstack != null) {
if (!item.getItemStack().equals(itemstack)) {
item.setItemStack(itemstack);
PacketManager.updateItem(item);
}
} else {
map.put("0", "N/A");
PacketManager.removeItem(InteractionVisualizerAPI.getPlayers(), item);
}
}
}
for (int i = 0; i < 9; i++) {
ArmorStand stand = (ArmorStand) map.get(String.valueOf(i + 1));
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);
}
}
}
Location loc1 = ((ArmorStand) map.get("5")).getLocation();
InteractionVisualizer.lightManager.deleteLight(loc1);
int skylight = loc1.getBlock().getRelative(BlockFace.UP).getLightFromSky();
int blocklight = loc1.getBlock().getRelative(BlockFace.UP).getLightFromBlocks() - 1;
blocklight = Math.max(blocklight, 0);
if (skylight > 0) {
InteractionVisualizer.lightManager.createLight(loc1, skylight, LightType.SKY);
}
if (blocklight > 0) {
InteractionVisualizer.lightManager.createLight(loc1, blocklight, LightType.BLOCK);
}
}
use of com.loohp.interactionvisualizer.entityholders.ArmorStand in project InteractionVisualizer by LOOHP.
the class AnvilDisplay 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().toString().toUpperCase().contains("ANVIL")) {
return;
}
InventoryView view = player.getOpenInventory();
Block block = view.getTopInventory().getLocation().getBlock();
Location loc = block.getLocation();
if (!openedAnvil.containsKey(block)) {
Map<String, Object> map = new HashMap<>();
map.put("Player", player);
map.put("2", "N/A");
map.putAll(spawnArmorStands(player, block));
openedAnvil.put(block, map);
}
Map<String, Object> map = openedAnvil.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);
item.setCustomName(itemstack.getItemMeta().getDisplayName());
item.setCustomNameVisible(true);
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);
item.setCustomName(itemstack.getItemMeta().getDisplayName());
item.setCustomNameVisible(true);
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);
}
}
}
}
use of com.loohp.interactionvisualizer.entityholders.ArmorStand in project InteractionVisualizer by LOOHP.
the class AnvilDisplay 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.Anvil.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;
}
use of com.loohp.interactionvisualizer.entityholders.ArmorStand in project InteractionVisualizer by LOOHP.
the class BannerDisplay method spawnArmorStands.
@SuppressWarnings("deprecation")
public Map<String, ArmorStand> spawnArmorStands(Block block) {
Map<String, ArmorStand> map = new HashMap<>();
if (isWallBanner(block.getType())) {
ArmorStand line1 = new ArmorStand(block.getLocation().add(0.5, 0.0, 0.5));
setStand(line1);
map.put("1", line1);
PacketManager.sendArmorStandSpawn(InteractionVisualizerAPI.getPlayerModuleList(Modules.HOLOGRAM, KEY), line1);
} else {
Location origin = block.getLocation().add(0.5, 1.0, 0.5);
Vector vector;
if (InteractionVisualizer.version.isLegacy()) {
org.bukkit.material.Banner banner = (org.bukkit.material.Banner) block.getState().getData();
vector = getDirection(banner.getFacing()).multiply(0.3125);
} else {
Rotatable rotate = (Rotatable) block.getBlockData();
vector = getDirection(rotate.getRotation()).multiply(0.3125);
}
ArmorStand line1 = new ArmorStand(origin.clone().add(vector));
setStand(line1);
map.put("1", line1);
PacketManager.sendArmorStandSpawn(InteractionVisualizerAPI.getPlayerModuleList(Modules.HOLOGRAM, KEY), line1);
}
return map;
}
Aggregations