use of com.loohp.interactionvisualizer.entityholders.Item 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);
}
use of com.loohp.interactionvisualizer.entityholders.Item in project InteractionVisualizer by LOOHP.
the class HopperDisplay method onUseHopper.
@EventHandler(priority = EventPriority.MONITOR)
public void onUseHopper(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.HOPPER)) {
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.HOPPER)) {
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.65, 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 LoomDisplay method onLoom.
@EventHandler(priority = EventPriority.MONITOR)
public void onLoom(InventoryClickEvent event) {
if (VanishUtils.isVanished((Player) event.getWhoClicked())) {
return;
}
if (event.isCancelled()) {
return;
}
if (event.getRawSlot() != 0 && event.getRawSlot() != 3) {
return;
}
if (event.getCurrentItem() == null) {
return;
}
if (event.getCurrentItem().getType().equals(Material.AIR)) {
return;
}
if (event.getRawSlot() == 3) {
if (event.getCursor() != null) {
if (!event.getCursor().getType().equals(Material.AIR)) {
if (event.getCursor().getAmount() >= event.getCursor().getType().getMaxStackSize()) {
return;
}
}
}
} else {
if (event.getCursor() != null) {
if (event.getCursor().getType().equals(event.getCurrentItem().getType())) {
return;
}
}
}
if (event.isShiftClick()) {
if (!InventoryUtils.stillHaveSpace(event.getWhoClicked().getInventory(), event.getView().getItem(event.getRawSlot()).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.LOOM)) {
return;
}
Block block = event.getView().getTopInventory().getLocation().getBlock();
if (!openedLooms.containsKey(block)) {
return;
}
ItemStack itemstack = event.getCurrentItem().clone();
Location loc = block.getLocation();
Player player = (Player) event.getWhoClicked();
Inventory before = Bukkit.createInventory(null, 9);
before.setItem(0, player.getOpenInventory().getItem(0).clone());
before.setItem(1, player.getOpenInventory().getItem(1).clone());
before.setItem(2, player.getOpenInventory().getItem(2).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());
after.setItem(2, player.getOpenInventory().getItem(2).clone());
if (InventoryUtils.compareContents(before, after)) {
return;
}
Map<String, Object> map = openedLooms.get(block);
if (!map.get("Player").equals(event.getWhoClicked())) {
return;
}
Item item = new Item(block.getLocation().clone().add(0.5, 1.5, 0.5));
item.setItemStack(itemstack);
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(loc.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);
Bukkit.getScheduler().runTaskLater(InteractionVisualizer.plugin, () -> {
SoundManager.playItemPickup(item.getLocation(), InteractionVisualizerAPI.getPlayerModuleList(Modules.ITEMDROP, KEY));
PacketManager.removeItem(InteractionVisualizerAPI.getPlayers(), item);
}, 8);
}, 1);
}
use of com.loohp.interactionvisualizer.entityholders.Item 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);
}
use of com.loohp.interactionvisualizer.entityholders.Item in project InteractionVisualizer by LOOHP.
the class ShulkerBoxDisplay method onDragShulkerbox.
@EventHandler(priority = EventPriority.MONITOR)
public void onDragShulkerbox(InventoryDragEvent event) {
Player player = (Player) event.getWhoClicked();
if (event.isCancelled()) {
return;
}
if (event.getWhoClicked().getGameMode().equals(GameMode.SPECTATOR)) {
return;
}
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 (!event.getView().getTopInventory().getLocation().getBlock().getType().toString().toUpperCase().contains("SHULKER_BOX")) {
return;
}
boolean ok = false;
for (Entry<Integer, ItemStack> entry : event.getNewItems().entrySet()) {
ItemStack item = event.getView().getItem(entry.getKey());
if (item == null) {
ok = true;
break;
}
if (item.getType().equals(Material.AIR)) {
ok = true;
break;
}
if (!item.getType().equals(entry.getValue().getType())) {
continue;
}
if (item.getAmount() < item.getType().getMaxStackSize()) {
ok = true;
break;
}
}
if (!ok) {
return;
}
Inventory topInventory = event.getView().getTopInventory();
Block block = topInventory.getLocation().getBlock();
Location loc = block.getLocation();
for (int slot : event.getRawSlots()) {
if (slot >= 0 && slot < topInventory.getSize()) {
PacketManager.sendHandMovement(InteractionVisualizerAPI.getPlayers(), player);
ItemStack itemstack = event.getOldCursor();
if (itemstack != null) {
if (itemstack.getType().equals(Material.AIR)) {
itemstack = null;
}
}
if (itemstack != null) {
Item item = new Item(event.getWhoClicked().getEyeLocation().add(0.0, InteractionVisualizer.playerPickupYOffset, 0.0));
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).toVector()).multiply(0.13).add(offset);
item.setVelocity(vector);
PacketManager.sendItemSpawn(InteractionVisualizerAPI.getPlayerModuleList(Modules.ITEMDROP, KEY), item);
item.setItemStack(itemstack);
item.setCustomName(System.currentTimeMillis() + "");
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);
Bukkit.getScheduler().runTaskLater(InteractionVisualizer.plugin, () -> {
item.teleport(loc.clone().add(0.5, 0.5, 0.5));
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);
}
break;
}
}
}
Aggregations