Adding GUI-Lists + modifying API + Added Schems by SchemsByType
Dieser Commit ist enthalten in:
Ursprung
3efacade25
Commit
42e2dbcfac
@ -1,6 +1,8 @@
|
|||||||
package de.steamwar.inventory;
|
package de.steamwar.inventory;
|
||||||
|
|
||||||
|
import org.bukkit.event.inventory.ClickType;
|
||||||
|
|
||||||
public interface InvCallback {
|
public interface InvCallback {
|
||||||
|
|
||||||
public void clicked();
|
public void clicked(ClickType click);
|
||||||
}
|
}
|
||||||
|
@ -19,7 +19,7 @@ import java.util.*;
|
|||||||
|
|
||||||
public class SWInventory implements Listener, Inventory {
|
public class SWInventory implements Listener, Inventory {
|
||||||
|
|
||||||
private Player player;
|
protected Player player;
|
||||||
private Map<Integer, InvCallback> callbacks;
|
private Map<Integer, InvCallback> callbacks;
|
||||||
private int inventorySize;
|
private int inventorySize;
|
||||||
private ItemStack[] contents;
|
private ItemStack[] contents;
|
||||||
@ -31,7 +31,6 @@ public class SWInventory implements Listener, Inventory {
|
|||||||
player = p;
|
player = p;
|
||||||
inventorySize = size;
|
inventorySize = size;
|
||||||
contents = new ItemStack[inventorySize];
|
contents = new ItemStack[inventorySize];
|
||||||
Bukkit.getPluginManager().registerEvents(this, Core.getInstance());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public SWInventory(Player p, int size, String t, Map<Integer, SWItem> items){
|
public SWInventory(Player p, int size, String t, Map<Integer, SWItem> items){
|
||||||
@ -72,21 +71,28 @@ public class SWInventory implements Listener, Inventory {
|
|||||||
|
|
||||||
public void open(){
|
public void open(){
|
||||||
player.openInventory(this);
|
player.openInventory(this);
|
||||||
|
Bukkit.getPluginManager().registerEvents(this, Core.getInstance());
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onInventoryClick(InventoryClickEvent e){
|
public void onInventoryClick(InventoryClickEvent e){
|
||||||
|
if(!player.equals(e.getWhoClicked()))
|
||||||
|
return;
|
||||||
|
|
||||||
e.setCancelled(true);
|
e.setCancelled(true);
|
||||||
if(callbacks.containsKey(e.getRawSlot()))
|
if(callbacks.containsKey(e.getRawSlot()))
|
||||||
callbacks.get(e.getSlot()).clicked();
|
callbacks.get(e.getSlot()).clicked(e.getClick());
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onInventoryClose(InventoryCloseEvent e){
|
public void onInventoryClose(InventoryCloseEvent e){
|
||||||
|
if(!player.equals(e.getPlayer()))
|
||||||
|
return;
|
||||||
|
|
||||||
InventoryClickEvent.getHandlerList().unregister(this);
|
InventoryClickEvent.getHandlerList().unregister(this);
|
||||||
InventoryCloseEvent.getHandlerList().unregister(this);
|
InventoryCloseEvent.getHandlerList().unregister(this);
|
||||||
if(callbacks.containsKey(-1))
|
if(callbacks.containsKey(-1))
|
||||||
callbacks.get(-1).clicked();
|
callbacks.get(-1).clicked(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -209,12 +215,14 @@ public class SWInventory implements Listener, Inventory {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void clear(int index) {
|
public void clear(int index) {
|
||||||
|
contents[index] = null;
|
||||||
|
callbacks.remove(index);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void clear() {
|
public void clear() {
|
||||||
|
contents = new ItemStack[contents.length];
|
||||||
|
callbacks.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -5,6 +5,7 @@ import org.bukkit.enchantments.Enchantment;
|
|||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
import org.bukkit.inventory.meta.ItemMeta;
|
import org.bukkit.inventory.meta.ItemMeta;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class SWItem {
|
public class SWItem {
|
||||||
@ -18,6 +19,10 @@ public class SWItem {
|
|||||||
itemMeta = itemStack.getItemMeta();
|
itemMeta = itemStack.getItemMeta();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public SWItem(Material material, String name){
|
||||||
|
this(material, (byte)0, name, new ArrayList<>(), false, null);
|
||||||
|
}
|
||||||
|
|
||||||
public SWItem(Material material, String name, List<String> lore, boolean enchanted, InvCallback c){
|
public SWItem(Material material, String name, List<String> lore, boolean enchanted, InvCallback c){
|
||||||
this(material, (byte)0, name, lore, enchanted, c);
|
this(material, (byte)0, name, lore, enchanted, c);
|
||||||
}
|
}
|
||||||
|
115
src/de/steamwar/inventory/SWListInv.java
Normale Datei
115
src/de/steamwar/inventory/SWListInv.java
Normale Datei
@ -0,0 +1,115 @@
|
|||||||
|
package de.steamwar.inventory;
|
||||||
|
|
||||||
|
import de.warking.hunjy.MySQL.Schematic;
|
||||||
|
import de.warking.hunjy.MySQL.SchematicType;
|
||||||
|
import javafx.util.Pair;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.event.inventory.ClickType;
|
||||||
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
import org.bukkit.inventory.meta.SkullMeta;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
public class SWListInv<T> extends SWInventory {
|
||||||
|
|
||||||
|
private ListCallback<T> callback;
|
||||||
|
private List<Pair<SWItem, T>> elements;
|
||||||
|
private int page;
|
||||||
|
|
||||||
|
public SWListInv(Player p, String t, ListCallback<T> c, List<Pair<SWItem, T>> l) {
|
||||||
|
super(p, (l.size()>45) ? 54 : (l.size() + 9-l.size()%9), t);
|
||||||
|
callback = c;
|
||||||
|
elements = l;
|
||||||
|
page = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void open(){
|
||||||
|
clear();
|
||||||
|
setCallback(-999, (ClickType click) -> player.closeInventory());
|
||||||
|
if(elements.size() > 54){
|
||||||
|
//TODO: Shift & Right-Click-Features
|
||||||
|
if(page != 0)
|
||||||
|
setItem(45, Material.INK_SACK, (byte)10, "§eSeite zurück", (ClickType click) -> {
|
||||||
|
page--;
|
||||||
|
open();
|
||||||
|
});
|
||||||
|
else
|
||||||
|
setItem(45, Material.INK_SACK, (byte)8, "§7Seite zurück", (ClickType click) -> {});
|
||||||
|
if(page < elements.size()%45)
|
||||||
|
setItem(53, Material.INK_SACK, (byte)10, "§eSeite vor", (ClickType click) -> {
|
||||||
|
page++;
|
||||||
|
open();
|
||||||
|
});
|
||||||
|
else
|
||||||
|
setItem(53, Material.INK_SACK, (byte)8, "§7Seite vor", (ClickType click) -> {});
|
||||||
|
}
|
||||||
|
|
||||||
|
int ipageLimit = elements.size() - page*45;
|
||||||
|
if(ipageLimit > 45 && elements.size() > 54){
|
||||||
|
ipageLimit = 45;
|
||||||
|
}
|
||||||
|
int i = page*45;
|
||||||
|
for(int ipage=0; ipage < ipageLimit; ipage++ ){
|
||||||
|
SWItem e = elements.get(i).getKey();
|
||||||
|
|
||||||
|
final int pos = i;
|
||||||
|
setItem(ipage, e);
|
||||||
|
setCallback(ipage, (ClickType click) -> callback.clicked(click, elements.get(pos).getValue()));
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
super.open();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCallback(ListCallback<T> c){
|
||||||
|
callback = c;
|
||||||
|
}
|
||||||
|
|
||||||
|
public interface ListCallback<T>{
|
||||||
|
public void clicked(ClickType click, T element);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static List<Pair<SWItem, UUID>> createPlayerList(Player without){
|
||||||
|
List<Pair<SWItem, UUID>> onlinePlayers = new ArrayList<>();
|
||||||
|
for(Player player : Bukkit.getOnlinePlayers()){
|
||||||
|
if(without != null && player.getUniqueId().equals(without.getUniqueId()))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
SWItem p = new SWItem();
|
||||||
|
ItemStack head = new ItemStack(Material.SKULL_ITEM, 1, (short) 3);
|
||||||
|
|
||||||
|
SkullMeta headmeta = (SkullMeta) head.getItemMeta();
|
||||||
|
headmeta.setOwningPlayer(player);
|
||||||
|
headmeta.setDisplayName(player.getName());
|
||||||
|
head.setItemMeta(headmeta);
|
||||||
|
p.setItemStack(head);
|
||||||
|
onlinePlayers.add(new Pair<>(p, player.getUniqueId()));
|
||||||
|
}
|
||||||
|
return onlinePlayers;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static List<Pair<SWItem, Schematic>> getSchemList(Player p, SchematicType type){
|
||||||
|
List<Pair<SWItem, Schematic>> schemList = new ArrayList<>();
|
||||||
|
|
||||||
|
List<Schematic> schems;
|
||||||
|
if(type == null)
|
||||||
|
schems = Schematic.getSchemsAccessibleByUser(p.getUniqueId());
|
||||||
|
else
|
||||||
|
schems = Schematic.getSchemsOfType(p.getUniqueId(), type);
|
||||||
|
|
||||||
|
for(Schematic s : schems){
|
||||||
|
Material m;
|
||||||
|
if(s.getItem().isEmpty())
|
||||||
|
m = Material.CAULDRON_ITEM;
|
||||||
|
else
|
||||||
|
m = Material.valueOf(s.getItem());
|
||||||
|
SWItem item = new SWItem(m,"§e" + s.getSchemName());
|
||||||
|
schemList.add(new Pair<>(item, s));
|
||||||
|
}
|
||||||
|
return schemList;
|
||||||
|
}
|
||||||
|
}
|
@ -95,19 +95,13 @@ public class Schematic {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static List<Schematic> getSchemsOfType(int schemOwner, SchematicType schemType){
|
public static List<Schematic> getSchemsOfType(int schemOwner, SchematicType schemType){
|
||||||
try{
|
//Unsauber, dafür auch geaddede Schematics dabei
|
||||||
ResultSet schematic = sql.select("SELECT * FROM Schematic WHERE SchemOwner = '" + schemOwner + "' AND SchemType = '" + schemType.name() + "'");
|
List<Schematic> schems = getSchemsAccessibleByUser(schemOwner);
|
||||||
List<Schematic> schematics = new ArrayList<>();
|
if(schems != null)
|
||||||
while(schematic.next()){
|
for(int i = schems.size()-1; i >= 0; i--)
|
||||||
String schemName = schematic.getString("SchemName");
|
if(!schems.get(i).getSchemType().equals(schemType))
|
||||||
String item = schematic.getString("Item");
|
schems.remove(i);
|
||||||
schematics.add(new Schematic(schemName, schemOwner, item, schemType, false));
|
return schems;
|
||||||
}
|
|
||||||
return schematics;
|
|
||||||
}catch(SQLException e){
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static List<Schematic> getAllSchemsOfType(SchematicType schemType){
|
public static List<Schematic> getAllSchemsOfType(SchematicType schemType){
|
||||||
|
In neuem Issue referenzieren
Einen Benutzer sperren