broken-arrow

Untitled

Sep 28th, 2021 (edited)
182
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.95 KB | None | 0 0
  1. import org.broken.cheststorage.ChestStorage;
  2. import org.broken.cheststorage.ClassInstance;
  3. import org.broken.cheststorage.cache.ContainerRegistry;
  4. import org.broken.cheststorage.containerholders.InventoryHolder;
  5. import org.broken.cheststorage.util.MetadataEnumsForGui;
  6. import org.bukkit.Location;
  7. import org.bukkit.entity.Player;
  8. import org.bukkit.event.EventHandler;
  9. import org.bukkit.event.EventPriority;
  10. import org.bukkit.event.Listener;
  11. import org.bukkit.event.inventory.InventoryClickEvent;
  12. import org.bukkit.inventory.Inventory;
  13. import org.mineacademy.fo.SerializeUtil;
  14. import org.mineacademy.fo.remain.CompMetadata;
  15.  
  16. import java.util.Objects;
  17.  
  18. public class AddItemsToContainerListener implements Listener {
  19.  
  20.     private final ClassInstance classinstans = ChestStorage.getInstance().getClassinstans();
  21.  
  22.     @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
  23.     public void onChestInteract(InventoryClickEvent event) {
  24.         Inventory clickedInventory = event.getView().getTopInventory();
  25.         Player player = (Player) event.getWhoClicked();
  26.         MetadataEnumsForGui metadataChest = MetadataEnumsForGui.CHEST_METADATA;
  27.         ContainerRegistry registry = ContainerRegistry.getInstance();
  28.  
  29.         Location location = SerializeUtil.deserializeLocation(CompMetadata.getMetadata(player, metadataChest.toString()));
  30.        
  31.         if (!Objects.equals(registry.getTypeofContainer(location), ContainerRegistry.TypeOfContainer.STORAGEUNIT) || !registry.isRegistered(location))
  32.             return;
  33.  
  34.         InventoryHolder holder = classinstans.createObjektInventoryHolder(location, player);
  35.  
  36.         if (holder != null && holder.isInventoryExist(location) && clickedInventory.equals(holder.getPage(location, 0)) && registry.isRegistered(location) && registry.getTypeofContainer(location) != null
  37.                 && Objects.equals(registry.getTypeofContainer(location), ContainerRegistry.TypeOfContainer.STORAGEUNIT)) {
  38.             holder.onClickingInsideGui(registry, null, location, event, null);
  39.         }
  40.  
  41.  
  42.     }
  43.  
  44.  
  45. }
Add Comment
Please, Sign In to add comment