SteamWar/SpigotCore
Archiviert
13
0

First GUI Prototype

Dieser Commit ist enthalten in:
Lixfel 2019-06-04 14:08:07 +02:00
Ursprung 56875f4146
Commit b205cb2216
2 geänderte Dateien mit 249 neuen und 0 gelöschten Zeilen

Datei anzeigen

@ -0,0 +1,6 @@
package de.steamwar.inventory;
public interface InvCallback {
public void clicked();
}

Datei anzeigen

@ -0,0 +1,243 @@
package de.steamwar.inventory;
import de.warking.hunjy.Core;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.HumanEntity;
import org.bukkit.entity.Player;
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;
import org.bukkit.inventory.InventoryHolder;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import java.util.*;
public class SWInventory implements Listener, Inventory {
private Player player;
private Map<Integer, InvCallback> callbacks;
private int inventorySize;
private ItemStack[] contents;
private String title;
public SWInventory(Player p, int size, String t){
title = t;
callbacks = new HashMap<>();
player = p;
inventorySize = size;
contents = new ItemStack[inventorySize];
Bukkit.getPluginManager().registerEvents(this, Core.getInstance());
}
public void addCloseCallback(InvCallback c){
callbacks.put(-1, c);
}
public void setItem(int pos, Material m, String name, InvCallback c){
setItem(pos, m, name, null, false, c);
}
public void setItem(int pos, Material m, String name, List<String> lore, boolean e, InvCallback c){
contents[pos] = new ItemStack(m, 1, (short)0);
ItemMeta im = contents[pos].getItemMeta();
im.setDisplayName(name);
im.setLore(lore);
if(e)
im.addEnchant(Enchantment.DURABILITY , 10, true);
contents[pos].setItemMeta(im);
callbacks.put(pos, c);
}
public void open(){
player.openInventory(this);
}
@EventHandler
public void onInventoryClick(InventoryClickEvent e){
System.out.println("Click");
e.setCancelled(true);
if(callbacks.containsKey(e.getRawSlot()))
callbacks.get(e.getSlot()).clicked();
}
@EventHandler
public void onInventoryClose(InventoryCloseEvent e){
System.out.println("Close");
InventoryClickEvent.getHandlerList().unregister(this);
InventoryCloseEvent.getHandlerList().unregister(this);
if(callbacks.containsKey(-1))
callbacks.get(-1).clicked();
}
@Override
public int getSize() {return inventorySize;}
@Override
public int getMaxStackSize() {return 999;}
@Override
public void setMaxStackSize(int size) {}
@Override
public String getName() {
return title;
}
@Override
public ItemStack getItem(int index) {
return contents[index];
}
@Override
public void setItem(int index, ItemStack item) {}
@Override
public HashMap<Integer, ItemStack> addItem(ItemStack... items) throws IllegalArgumentException {return null;}
@Override
public HashMap<Integer, ItemStack> removeItem(ItemStack... items) throws IllegalArgumentException {return null;}
@Override
public ItemStack[] getContents() {return contents;}
@Override
public void setContents(ItemStack[] items) throws IllegalArgumentException {}
@Override
public ItemStack[] getStorageContents() {return contents;}
@Override
public void setStorageContents(ItemStack[] items) throws IllegalArgumentException {}
@Override
public boolean contains(int materialId) {
return false;
}
@Override
public boolean contains(Material material) throws IllegalArgumentException {
return false;
}
@Override
public boolean contains(ItemStack item) {
return false;
}
@Override
public boolean contains(int materialId, int amount) {
return false;
}
@Override
public boolean contains(Material material, int amount) throws IllegalArgumentException {
return false;
}
@Override
public boolean contains(ItemStack item, int amount) {
return false;
}
@Override
public boolean containsAtLeast(ItemStack item, int amount) {
return false;
}
@Override
public HashMap<Integer, ? extends ItemStack> all(int materialId) {
return null;
}
@Override
public HashMap<Integer, ? extends ItemStack> all(Material material) throws IllegalArgumentException {
return null;
}
@Override
public HashMap<Integer, ? extends ItemStack> all(ItemStack item) {
return null;
}
@Override
public int first(int materialId) {
return 0;
}
@Override
public int first(Material material) throws IllegalArgumentException {
return 0;
}
@Override
public int first(ItemStack item) {
return 0;
}
@Override
public int firstEmpty() {
return 0;
}
@Override
public void remove(int materialId) {
}
@Override
public void remove(Material material) throws IllegalArgumentException {
}
@Override
public void remove(ItemStack item) {
}
@Override
public void clear(int index) {
}
@Override
public void clear() {
}
@Override
public List<HumanEntity> getViewers() {
List<HumanEntity> l = new ArrayList<>();
l.add(player);
return l;
}
@Override
public String getTitle() {
return title;
}
@Override
public InventoryType getType() {
return InventoryType.CHEST;
}
@Override
public InventoryHolder getHolder() {
return player;
}
@Override
public ListIterator<ItemStack> iterator() {
return null;
}
@Override
public ListIterator<ItemStack> iterator(int index) {
return null;
}
@Override
public Location getLocation() {
return null;
}
}