From 2231a5d6e85576e8da72b0ffa0f8f0cb109f4955 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Tue, 7 Jan 2020 06:59:19 +0100 Subject: [PATCH] Adding functions for working without pair --- .../src/de/steamwar/inventory/SWListInv.java | 73 +++++++++++++++++-- 1 file changed, 67 insertions(+), 6 deletions(-) diff --git a/SpigotCore_Main/src/de/steamwar/inventory/SWListInv.java b/SpigotCore_Main/src/de/steamwar/inventory/SWListInv.java index 72f6e8e..42b708b 100644 --- a/SpigotCore_Main/src/de/steamwar/inventory/SWListInv.java +++ b/SpigotCore_Main/src/de/steamwar/inventory/SWListInv.java @@ -8,17 +8,26 @@ import org.bukkit.Material; import org.bukkit.entity.Player; import org.bukkit.event.inventory.ClickType; -import java.util.ArrayList; -import java.util.List; -import java.util.UUID; +import java.util.*; public class SWListInv extends SWInventory { private ListCallback callback; - private List> elements; + private List> elements; private int page; + @Deprecated public SWListInv(Player p, String t, ListCallback c, List> l) { + super(p, (l.size()>45) ? 54 : (l.size() + 9-l.size()%9), t); + callback = c; + //Only here for backwards compatibility + elements = new LinkedList<>(); + for(Pair pair : l) + elements.add(new SWListEntry<>(pair.getKey(), pair.getValue())); + page = 0; + } + + public SWListInv(Player p, String t, List> l, ListCallback c){ super(p, (l.size()>45) ? 54 : (l.size() + 9-l.size()%9), t); callback = c; elements = l; @@ -52,11 +61,11 @@ public class SWListInv extends SWInventory { } int i = page*45; for(int ipage=0; ipage < ipageLimit; ipage++ ){ - SWItem e = elements.get(i).getKey(); + SWItem e = elements.get(i).getItem(); final int pos = i; setItem(ipage, e); - setCallback(ipage, (ClickType click) -> callback.clicked(click, elements.get(pos).getValue())); + setCallback(ipage, (ClickType click) -> callback.clicked(click, elements.get(pos).getObject())); i++; } super.open(); @@ -70,6 +79,7 @@ public class SWListInv extends SWInventory { void clicked(ClickType click, T element); } + @Deprecated public static List> createPlayerList(Player without){ List> onlinePlayers = new ArrayList<>(); for(Player player : Bukkit.getOnlinePlayers()){ @@ -81,6 +91,18 @@ public class SWListInv extends SWInventory { return onlinePlayers; } + public static List> createPlayerList(UUID without){ + List> onlinePlayers = new ArrayList<>(); + for(Player player : Bukkit.getOnlinePlayers()){ + if(without != null && player.getUniqueId().equals(without)) + continue; + + onlinePlayers.add(new SWListEntry<>(SWItem.getPlayerSkull(player), player.getUniqueId())); + } + return onlinePlayers; + } + + @Deprecated public static List> getSchemList(int warkingUserId, SchematicType type){ List> schemList = new ArrayList<>(); @@ -101,4 +123,43 @@ public class SWListInv extends SWInventory { } return schemList; } + + public static List> getSchemList(SchematicType type, int steamwarUserId){ + List> schemList = new ArrayList<>(); + + List schems; + if(type == null) + schems = Schematic.getSchemsAccessibleByUser(steamwarUserId); + else + schems = Schematic.getSchemsOfType(steamwarUserId, type); + + for(Schematic s : schems){ + Material m; + if(s.getItem().isEmpty()) + m = SWItem.getMaterial("CAULDRON_ITEM"); + else + m = SWItem.getMaterial(s.getItem()); + SWItem item = new SWItem(m,"§e" + s.getSchemName()); + schemList.add(new SWListEntry<>(item, s)); + } + return schemList; + } + + public static class SWListEntry{ + final SWItem item; + final T object; + + public SWListEntry(SWItem item, T object){ + this.item = item; + this.object = object; + } + + public SWItem getItem(){ + return item; + } + + public T getObject(){ + return object; + } + } } -- 2.39.2