use of org.bukkit.inventory.CartographyInventory in project InteractionVisualizer by LOOHP.
the class CartographyTableDisplay method run.
@Override
public int run() {
return new BukkitRunnable() {
public void run() {
Iterator<Block> itr = openedCTable.keySet().iterator();
int count = 0;
int maxper = (int) Math.ceil((double) openedCTable.size() / (double) 5);
int delay = 1;
while (itr.hasNext()) {
count++;
if (count > maxper) {
count = 0;
delay++;
}
Block block = itr.next();
new BukkitRunnable() {
public void run() {
if (!openedCTable.containsKey(block)) {
return;
}
Map<String, Object> map = openedCTable.get(block);
if (block.getType().equals(Material.CARTOGRAPHY_TABLE)) {
Player player = (Player) map.get("Player");
if (!player.getGameMode().equals(GameMode.SPECTATOR)) {
if (player.getOpenInventory() != null) {
if (player.getOpenInventory().getTopInventory() != null) {
if (player.getOpenInventory().getTopInventory() instanceof CartographyInventory) {
return;
}
}
}
}
}
if (map.get("Item") instanceof ItemFrame) {
Entity entity = (Entity) map.get("Item");
PacketManager.removeItemFrame(InteractionVisualizerAPI.getPlayers(), (ItemFrame) entity);
}
openedCTable.remove(block);
}
}.runTaskLater(InteractionVisualizer.plugin, delay);
}
}
}.runTaskTimer(InteractionVisualizer.plugin, 0, 6).getTaskId();
}
use of org.bukkit.inventory.CartographyInventory in project InteractionVisualizer by LOOHP.
the class CartographyTableDisplay 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() instanceof CartographyInventory)) {
return;
}
Block block = player.getTargetBlockExact(7, FluidCollisionMode.NEVER);
if (block == null || !block.getType().equals(Material.CARTOGRAPHY_TABLE)) {
return;
}
playermap.put(player, block);
}
InventoryView view = player.getOpenInventory();
Block block = playermap.get(player);
if (!openedCTable.containsKey(block)) {
Map<String, Object> map = new HashMap<>();
map.put("Player", player);
map.put("Item", "N/A");
openedCTable.put(block, map);
}
Map<String, Object> map = openedCTable.get(block);
if (!map.get("Player").equals(player)) {
return;
}
ItemStack input = view.getItem(0);
if (input != null) {
if (input.getType().equals(Material.AIR)) {
input = null;
}
}
ItemStack output = view.getItem(2);
if (output != null) {
if (output.getType().equals(Material.AIR)) {
output = null;
}
}
ItemStack itemstack = null;
if (output == null) {
if (input != null) {
itemstack = input;
}
} else {
itemstack = output;
}
ItemFrame item = null;
if (!block.getRelative(BlockFace.UP).getType().isSolid()) {
if (map.get("Item") instanceof String) {
if (itemstack != null) {
item = new ItemFrame(block.getRelative(BlockFace.UP).getLocation());
item.setItem(itemstack);
item.setFacingDirection(BlockFace.UP);
item.setSilent(true);
map.put("Item", item);
PacketManager.sendItemFrameSpawn(InteractionVisualizerAPI.getPlayerModuleList(Modules.ITEMSTAND, KEY), item);
PacketManager.updateItemFrame(item);
} else {
map.put("Item", "N/A");
}
} else {
item = (ItemFrame) map.get("Item");
if (itemstack != null) {
if (!item.getItem().equals(itemstack)) {
item.setItem(itemstack);
PacketManager.updateItemFrame(item);
}
} else {
map.put("Item", "N/A");
PacketManager.removeItemFrame(InteractionVisualizerAPI.getPlayers(), item);
}
}
}
}
Aggregations