remove shulker
This commit is contained in:
@@ -2,7 +2,6 @@ package io.github.itzispyder.ogredupealias.events;
|
||||
|
||||
import io.github.itzispyder.ogredupealias.data.PlacedStructures;
|
||||
import io.github.itzispyder.ogredupealias.plugin.InventoryPresets;
|
||||
import io.github.itzispyder.ogredupealias.utils.ShulkerUtils;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
@@ -22,10 +21,6 @@ public class InteractionListener implements Listener {
|
||||
final Block b = e.getClickedBlock();
|
||||
final ItemStack item = e.getItem();
|
||||
|
||||
if (a == Action.RIGHT_CLICK_AIR || a == Action.RIGHT_CLICK_BLOCK) {
|
||||
ShulkerUtils.onShulkerInteraction(e);
|
||||
}
|
||||
|
||||
if (PlacedStructures.isCustomTable(b)) {
|
||||
e.setCancelled(true);
|
||||
p.openInventory(InventoryPresets.createCustomTable());
|
||||
|
||||
@@ -1,13 +1,11 @@
|
||||
package io.github.itzispyder.ogredupealias.events;
|
||||
|
||||
import io.github.itzispyder.ogredupealias.plugin.custom.forging.CustomTable;
|
||||
import io.github.itzispyder.ogredupealias.utils.ShulkerUtils;
|
||||
import io.github.itzispyder.ogredupealias.utils.Text;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
import org.bukkit.event.inventory.InventoryCloseEvent;
|
||||
import org.bukkit.event.inventory.InventoryType;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
|
||||
public class InventoryActionListener implements Listener {
|
||||
@@ -19,10 +17,8 @@ public class InventoryActionListener implements Listener {
|
||||
|
||||
try {
|
||||
if (inv == null) return;
|
||||
if (inv.getType() == InventoryType.PLAYER) return;
|
||||
|
||||
if (title.equals(Text.color("&eForging Table"))) CustomTable.onInventoryAction(e);
|
||||
else if (title.contains(Text.color("&7Viewing "))) ShulkerUtils.onInventoryClick(e);
|
||||
}
|
||||
catch (Exception ignore) {}
|
||||
}
|
||||
@@ -33,7 +29,6 @@ public class InventoryActionListener implements Listener {
|
||||
|
||||
try {
|
||||
if (title.equals(Text.color("&eForging Table"))) CustomTable.onInventoryClose(e);
|
||||
else if (title.contains(Text.color("&7Viewing "))) ShulkerUtils.onInventoryClose(e);
|
||||
}
|
||||
catch (Exception ignore) {}
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ import org.bukkit.Sound;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
import org.bukkit.event.inventory.InventoryCloseEvent;
|
||||
import org.bukkit.event.inventory.InventoryType;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
@@ -96,6 +97,9 @@ public class CustomTable {
|
||||
final int slot = e.getSlot();
|
||||
final CustomTable table = new CustomTable(inv);
|
||||
|
||||
if (inv == null) return;
|
||||
if (inv.getType() == InventoryType.PLAYER) return;
|
||||
|
||||
if (table.isUnresponsiveSlot(slot)) {
|
||||
e.setCancelled(true);
|
||||
return;
|
||||
|
||||
@@ -1,77 +0,0 @@
|
||||
package io.github.itzispyder.ogredupealias.utils;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.block.ShulkerBox;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.block.Action;
|
||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
import org.bukkit.event.inventory.InventoryCloseEvent;
|
||||
import org.bukkit.event.player.PlayerInteractEvent;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.BlockStateMeta;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
public abstract class ShulkerUtils {
|
||||
|
||||
private static final Map<UUID,ItemStack> lastOpenedBox = new HashMap<>();
|
||||
|
||||
public static Inventory getOf(ItemStack item, ShulkerBox box) {
|
||||
final String display = ItemUtils.getDisplay(item);
|
||||
final Inventory inv = Bukkit.createInventory(null, box.getInventory().getSize(), Text.color("&7Viewing&r " + display));
|
||||
|
||||
inv.setContents(box.getInventory().getContents());
|
||||
return inv;
|
||||
}
|
||||
|
||||
public static void onShulkerInteraction(PlayerInteractEvent e) {
|
||||
final Player p = e.getPlayer();
|
||||
final ItemStack item = e.getItem();
|
||||
final Action a = e.getAction();
|
||||
|
||||
if (!e.isCancelled() && a == Action.RIGHT_CLICK_BLOCK) return;
|
||||
if (item == null || item.getType().isAir()) return;
|
||||
if (a != Action.RIGHT_CLICK_BLOCK && a != Action.RIGHT_CLICK_AIR) return;
|
||||
if (!item.getType().name().contains("SHULKER_BOX")) return;
|
||||
|
||||
final BlockStateMeta meta = (BlockStateMeta) item.getItemMeta();
|
||||
final ShulkerBox box = (ShulkerBox) meta.getBlockState();
|
||||
|
||||
p.openInventory(getOf(item, box));
|
||||
lastOpenedBox.put(p.getUniqueId(),item);
|
||||
}
|
||||
|
||||
public static void onInventoryClick(InventoryClickEvent e) {
|
||||
final Inventory inv = e.getClickedInventory();
|
||||
final Player p = (Player) e.getWhoClicked();
|
||||
|
||||
final ItemStack item = lastOpenedBox.get(p.getUniqueId());
|
||||
if (item == null || !item.getType().name().contains("SHULKER_BOX")) return;
|
||||
final BlockStateMeta meta = (BlockStateMeta) item.getItemMeta();
|
||||
final ShulkerBox box = (ShulkerBox) meta.getBlockState();
|
||||
|
||||
box.getInventory().setContents(inv.getContents());
|
||||
box.update();
|
||||
meta.setBlockState(box);
|
||||
item.setItemMeta(meta);
|
||||
}
|
||||
|
||||
public static void onInventoryClose(InventoryCloseEvent e) {
|
||||
final Inventory inv = e.getInventory();
|
||||
final Player p = (Player) e.getPlayer();
|
||||
|
||||
final ItemStack item = lastOpenedBox.get(p.getUniqueId());
|
||||
if (item == null || !item.getType().name().contains("SHULKER_BOX")) return;
|
||||
final BlockStateMeta meta = (BlockStateMeta) item.getItemMeta();
|
||||
final ShulkerBox box = (ShulkerBox) meta.getBlockState();
|
||||
|
||||
box.getInventory().setContents(inv.getContents());
|
||||
box.update();
|
||||
meta.setBlockState(box);
|
||||
item.setItemMeta(meta);
|
||||
lastOpenedBox.remove(p.getUniqueId());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user