SteamWar/SpigotCore
Archiviert
13
0

Finish of first GUI-API

Dieser Commit ist enthalten in:
Lixfel 2019-06-04 15:54:55 +02:00
Ursprung b205cb2216
Commit 6f430209ea
2 geänderte Dateien mit 92 neuen und 11 gelöschten Zeilen

Datei anzeigen

@ -4,7 +4,6 @@ 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;
@ -15,7 +14,6 @@ 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.*;
@ -36,23 +34,28 @@ public class SWInventory implements Listener, Inventory {
Bukkit.getPluginManager().registerEvents(this, Core.getInstance());
}
public SWInventory(Player p, int size, String t, Map<Integer, SWItem> items){
this(p, size, t);
items.forEach(this::setItem);
open();
}
public void addCloseCallback(InvCallback c){
callbacks.put(-1, c);
}
public void setItem(int pos, SWItem item){
contents[pos] = item.getItemStack();
callbacks.put(pos, item.getCallback());
}
public void setItem(int pos, Material m, String name, InvCallback c){
setItem(pos, m, name, null, false, c);
setItem(pos, m, name, new ArrayList<>(), 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);
SWItem item = new SWItem(m, name, lore, e, c);
setItem(pos, item);
}
public void open(){

Datei anzeigen

@ -0,0 +1,78 @@
package de.steamwar.inventory;
import org.bukkit.Material;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import java.util.List;
public class SWItem {
private ItemStack itemStack;
private ItemMeta itemMeta;
private InvCallback callback;
public SWItem(){
itemStack = new ItemStack(Material.AIR);
itemMeta = itemStack.getItemMeta();
}
public SWItem(Material material, String name, List<String> lore, boolean enchanted, InvCallback c){
itemStack = new ItemStack(material, 1, (short)0);
itemMeta = itemStack.getItemMeta();
itemMeta.setDisplayName(name);
if(lore != null && !lore.isEmpty())
itemMeta.setLore(lore);
if(enchanted)
itemMeta.addEnchant(Enchantment.DURABILITY , 10, true);
itemStack.setItemMeta(itemMeta);
callback = c;
}
public ItemStack getItemStack() {
return itemStack;
}
public void setItemStack(ItemStack itemStack) {
this.itemStack = itemStack;
this.itemMeta = itemStack.getItemMeta();
}
public ItemMeta getItemMeta() {
return itemMeta;
}
public void setItemMeta(ItemMeta itemMeta) {
this.itemMeta = itemMeta;
this.itemStack.setItemMeta(itemMeta);
}
public InvCallback getCallback() {
return callback;
}
public void setCallback(InvCallback callback) {
this.callback = callback;
}
public void setName(String name){
itemMeta.setDisplayName(name);
itemStack.setItemMeta(itemMeta);
}
public void setLore(List<String> lore){
itemMeta.setLore(lore);
itemStack.setItemMeta(itemMeta);
}
public void setEnchanted(boolean enchanted){
if(enchanted){
itemMeta.addEnchant(Enchantment.DURABILITY , 10, true);
itemStack.setItemMeta(itemMeta);
}else{
itemMeta.removeEnchant(Enchantment.DURABILITY);
itemStack.setItemMeta(itemMeta);
}
}
}