use of com.loohp.interactionvisualizer.entityholders.Item in project InteractionVisualizer by LOOHP.
the class DropperDisplay method onUseDropper.
@EventHandler(priority = EventPriority.MONITOR)
public void onUseDropper(InventoryClickEvent event) {
Player player = (Player) event.getWhoClicked();
if (event.isCancelled()) {
return;
}
if (VanishUtils.isVanished(player)) {
return;
}
if (OpenInvUtils.isSlientChest(player)) {
return;
}
if (event.getWhoClicked().getGameMode().equals(GameMode.SPECTATOR)) {
return;
}
if (event.getView().getTopInventory() == null) {
return;
}
if (!event.getView().getTopInventory().getType().equals(InventoryType.DROPPER)) {
return;
}
try {
if (event.getView().getTopInventory().getLocation() == null) {
return;
}
} catch (Exception | AbstractMethodError e) {
return;
}
if (!LocationUtils.isLoaded(event.getView().getTopInventory().getLocation())) {
return;
}
if (event.getView().getTopInventory().getLocation().getBlock() == null) {
return;
}
if (!event.getView().getTopInventory().getLocation().getBlock().getType().equals(Material.DROPPER)) {
return;
}
if (event.getClick().equals(ClickType.MIDDLE) && !event.getWhoClicked().getGameMode().equals(GameMode.CREATIVE)) {
return;
}
Inventory topInventory = event.getView().getTopInventory();
Block block = topInventory.getLocation().getBlock();
Location loc = block.getLocation();
boolean isIn = true;
boolean isMove = false;
ItemStack itemstack = null;
if (event.getRawSlot() >= 0 && event.getRawSlot() < topInventory.getSize()) {
itemstack = event.getCurrentItem();
if (itemstack != null) {
if (itemstack.getType().equals(Material.AIR)) {
itemstack = null;
} else {
isIn = false;
isMove = true;
}
}
if (itemstack == null) {
itemstack = event.getCursor();
if (itemstack != null) {
if (itemstack.getType().equals(Material.AIR)) {
itemstack = null;
} else {
isMove = true;
}
}
} else {
if (event.getCursor() != null) {
if (event.getCursor().getType().equals(itemstack.getType())) {
isIn = true;
}
}
}
if (itemstack == null) {
if (event.getAction().equals(InventoryAction.HOTBAR_MOVE_AND_READD) || event.getAction().equals(InventoryAction.HOTBAR_SWAP)) {
itemstack = event.getWhoClicked().getInventory().getItem(event.getHotbarButton());
if (itemstack != null) {
if (itemstack.getType().equals(Material.AIR)) {
itemstack = null;
} else {
isMove = true;
}
}
}
}
}
if (itemstack == null) {
if (event.getAction().equals(InventoryAction.MOVE_TO_OTHER_INVENTORY)) {
itemstack = event.getCurrentItem();
if (itemstack != null) {
if (itemstack.getType().equals(Material.AIR)) {
itemstack = null;
} else {
isMove = true;
}
}
}
}
if (event.isShiftClick() && event.getView().getItem(event.getRawSlot()) != null) {
if (isIn) {
if (!InventoryUtils.stillHaveSpace(event.getView().getTopInventory(), event.getView().getItem(event.getRawSlot()).getType())) {
return;
}
} else {
if (!InventoryUtils.stillHaveSpace(event.getWhoClicked().getInventory(), event.getView().getItem(event.getRawSlot()).getType())) {
return;
}
}
}
if (event.getCursor() != null) {
if (!event.getCursor().getType().equals(Material.AIR)) {
if (event.getCurrentItem() != null) {
if (!event.getCurrentItem().getType().equals(Material.AIR)) {
if (event.getCurrentItem().getType().equals(event.getCursor().getType())) {
if (event.getCurrentItem().getAmount() >= event.getCurrentItem().getType().getMaxStackSize()) {
return;
}
}
}
}
}
}
if (isMove) {
PacketManager.sendHandMovement(InteractionVisualizerAPI.getPlayers(), player);
if (itemstack != null) {
Item item = new Item(loc.clone().add(0.5, 0.5, 0.5).add(event.getWhoClicked().getLocation().getDirection().multiply(-0.8)));
Vector offset = new Vector(0.0, 0.15, 0.0);
Vector vector = loc.clone().add(0.5, 0.5, 0.5).toVector().subtract(event.getWhoClicked().getEyeLocation().clone().add(0.0, InteractionVisualizer.playerPickupYOffset, 0.0).add(0.0, -0.5, 0.0).toVector()).multiply(-0.13).add(offset);
item.setVelocity(vector);
if (isIn) {
item.teleport(event.getWhoClicked().getEyeLocation().add(0.0, InteractionVisualizer.playerPickupYOffset, 0.0));
vector = loc.clone().add(0.5, 0.5, 0.5).toVector().subtract(event.getWhoClicked().getEyeLocation().clone().add(0.0, InteractionVisualizer.playerPickupYOffset, 0.0).toVector()).multiply(0.13).add(offset);
item.setVelocity(vector);
}
PacketManager.sendItemSpawn(InteractionVisualizerAPI.getPlayerModuleList(Modules.ITEMDROP, KEY), item);
item.setItemStack(itemstack);
item.setPickupDelay(32767);
item.setGravity(true);
PacketManager.updateItem(item);
if (!link.containsKey(player)) {
link.put(player, new ArrayList<Item>());
}
List<Item> list = link.get(player);
list.add(item);
boolean finalIsIn = isIn;
Bukkit.getScheduler().runTaskLater(InteractionVisualizer.plugin, () -> {
if (finalIsIn) {
item.teleport(loc.clone().add(0.5, 0.5, 0.5));
} else {
item.teleport(event.getWhoClicked().getEyeLocation().add(0.0, -0.5, 0.0).add(0.0, InteractionVisualizer.playerPickupYOffset, 0.0));
}
item.setVelocity(new Vector(0.0, 0.0, 0.0));
item.setGravity(false);
PacketManager.updateItem(item);
}, 8);
Bukkit.getScheduler().runTaskLater(InteractionVisualizer.plugin, () -> {
PacketManager.removeItem(InteractionVisualizerAPI.getPlayers(), item);
list.remove(item);
}, 20);
}
}
}
use of com.loohp.interactionvisualizer.entityholders.Item in project InteractionVisualizer by LOOHP.
the class DropperDisplay method onCloseDropper.
@EventHandler
public void onCloseDropper(InventoryCloseEvent event) {
if (event.getView().getTopInventory() == null) {
return;
}
try {
if (event.getView().getTopInventory().getLocation() == null) {
return;
}
} catch (Exception | AbstractMethodError e) {
return;
}
if (!LocationUtils.isLoaded(event.getView().getTopInventory().getLocation())) {
return;
}
if (event.getView().getTopInventory().getLocation().getBlock() == null) {
return;
}
if (!link.containsKey((Player) event.getPlayer())) {
return;
}
List<Item> list = link.get((Player) event.getPlayer());
for (Item item : list) {
PacketManager.removeItem(InteractionVisualizerAPI.getPlayers(), item);
}
link.remove((Player) event.getPlayer());
}
use of com.loohp.interactionvisualizer.entityholders.Item 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.Item in project InteractionVisualizer by LOOHP.
the class BarrelDisplay method onUseBarrel.
@EventHandler(priority = EventPriority.MONITOR)
public void onUseBarrel(InventoryClickEvent event) {
Player player = (Player) event.getWhoClicked();
if (event.isCancelled()) {
return;
}
if (VanishUtils.isVanished(player)) {
return;
}
if (OpenInvUtils.isSlientChest(player)) {
return;
}
if (event.getWhoClicked().getGameMode().equals(GameMode.SPECTATOR)) {
return;
}
if (event.getView().getTopInventory() == null) {
return;
}
if (!event.getView().getTopInventory().getType().equals(InventoryType.BARREL)) {
return;
}
try {
if (event.getView().getTopInventory().getLocation() == null) {
return;
}
} catch (Exception | AbstractMethodError e) {
return;
}
if (!LocationUtils.isLoaded(event.getView().getTopInventory().getLocation())) {
return;
}
if (event.getView().getTopInventory().getLocation().getBlock() == null) {
return;
}
if (!event.getView().getTopInventory().getLocation().getBlock().getType().equals(Material.BARREL)) {
return;
}
if (event.getClick().equals(ClickType.MIDDLE) && !event.getWhoClicked().getGameMode().equals(GameMode.CREATIVE)) {
return;
}
Inventory topInventory = event.getView().getTopInventory();
Block block = topInventory.getLocation().getBlock();
Location loc = block.getLocation();
boolean isIn = true;
boolean isMove = false;
ItemStack itemstack = null;
if (event.getRawSlot() >= 0 && event.getRawSlot() < topInventory.getSize()) {
itemstack = event.getCurrentItem();
if (itemstack != null) {
if (itemstack.getType().equals(Material.AIR)) {
itemstack = null;
} else {
isIn = false;
isMove = true;
}
}
if (itemstack == null) {
itemstack = event.getCursor();
if (itemstack != null) {
if (itemstack.getType().equals(Material.AIR)) {
itemstack = null;
} else {
isMove = true;
}
}
} else {
if (event.getCursor() != null) {
if (event.getCursor().getType().equals(itemstack.getType())) {
isIn = true;
}
}
}
if (itemstack == null) {
if (event.getAction().equals(InventoryAction.HOTBAR_MOVE_AND_READD) || event.getAction().equals(InventoryAction.HOTBAR_SWAP)) {
itemstack = event.getWhoClicked().getInventory().getItem(event.getHotbarButton());
if (itemstack != null) {
if (itemstack.getType().equals(Material.AIR)) {
itemstack = null;
} else {
isMove = true;
}
}
}
}
}
if (itemstack == null) {
if (event.getAction().equals(InventoryAction.MOVE_TO_OTHER_INVENTORY)) {
itemstack = event.getCurrentItem();
if (itemstack != null) {
if (itemstack.getType().equals(Material.AIR)) {
itemstack = null;
} else {
isMove = true;
}
}
}
}
if (event.isShiftClick() && event.getView().getItem(event.getRawSlot()) != null) {
if (isIn) {
if (!InventoryUtils.stillHaveSpace(event.getView().getTopInventory(), event.getView().getItem(event.getRawSlot()).getType())) {
return;
}
} else {
if (!InventoryUtils.stillHaveSpace(event.getWhoClicked().getInventory(), event.getView().getItem(event.getRawSlot()).getType())) {
return;
}
}
}
if (event.getCursor() != null) {
if (!event.getCursor().getType().equals(Material.AIR)) {
if (event.getCurrentItem() != null) {
if (!event.getCurrentItem().getType().equals(Material.AIR)) {
if (event.getCurrentItem().getType().equals(event.getCursor().getType())) {
if (event.getCurrentItem().getAmount() >= event.getCurrentItem().getType().getMaxStackSize()) {
return;
}
}
}
}
}
}
if (isMove) {
PacketManager.sendHandMovement(InteractionVisualizerAPI.getPlayers(), player);
if (itemstack != null) {
Item item = new Item(loc.clone().add(0.5, 0.5, 0.5).add(event.getWhoClicked().getLocation().getDirection().multiply(-0.8)));
Vector offset = new Vector(0.0, 0.15, 0.0);
Vector vector = loc.clone().add(0.5, 0.5, 0.5).toVector().subtract(event.getWhoClicked().getEyeLocation().clone().add(0.0, InteractionVisualizer.playerPickupYOffset, 0.0).add(0.0, -0.5, 0.0).toVector()).multiply(-0.13).add(offset);
item.setVelocity(vector);
if (isIn) {
item.teleport(event.getWhoClicked().getEyeLocation().add(0.0, InteractionVisualizer.playerPickupYOffset, 0.0));
vector = loc.clone().add(0.5, 0.5, 0.5).toVector().subtract(event.getWhoClicked().getEyeLocation().clone().add(0.0, InteractionVisualizer.playerPickupYOffset, 0.0).toVector()).multiply(0.13).add(offset);
item.setVelocity(vector);
}
PacketManager.sendItemSpawn(InteractionVisualizerAPI.getPlayerModuleList(Modules.ITEMDROP, KEY), item);
item.setItemStack(itemstack);
item.setPickupDelay(32767);
item.setGravity(true);
PacketManager.updateItem(item);
if (!link.containsKey(player)) {
link.put(player, new ArrayList<Item>());
}
List<Item> list = link.get(player);
list.add(item);
boolean finalIsIn = isIn;
Bukkit.getScheduler().runTaskLater(InteractionVisualizer.plugin, () -> {
if (finalIsIn) {
item.teleport(loc.clone().add(0.5, 0.5, 0.5));
} else {
item.teleport(event.getWhoClicked().getEyeLocation().add(0.0, -0.5, 0.0).add(0.0, InteractionVisualizer.playerPickupYOffset, 0.0));
}
item.setVelocity(new Vector(0.0, 0.0, 0.0));
item.setGravity(false);
PacketManager.updateItem(item);
}, 8);
Bukkit.getScheduler().runTaskLater(InteractionVisualizer.plugin, () -> {
PacketManager.removeItem(InteractionVisualizerAPI.getPlayers(), item);
list.remove(item);
}, 20);
}
}
}
use of com.loohp.interactionvisualizer.entityholders.Item in project InteractionVisualizer by LOOHP.
the class BlastFurnaceDisplay method onBreakBlastFurnace.
@EventHandler(priority = EventPriority.MONITOR)
public void onBreakBlastFurnace(TileEntityRemovedEvent event) {
Block block = event.getBlock();
if (!blastfurnaceMap.containsKey(block)) {
return;
}
Map<String, Object> map = blastfurnaceMap.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);
}
blastfurnaceMap.remove(block);
}
Aggregations