Adding functions for working without pair
Dieser Commit ist enthalten in:
Ursprung
2e27fac7c7
Commit
2231a5d6e8
@ -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<T> extends SWInventory {
|
||||
|
||||
private ListCallback<T> callback;
|
||||
private List<Pair<SWItem, T>> elements;
|
||||
private List<SWListEntry<T>> elements;
|
||||
private int page;
|
||||
|
||||
@Deprecated
|
||||
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;
|
||||
//Only here for backwards compatibility
|
||||
elements = new LinkedList<>();
|
||||
for(Pair<SWItem, T> pair : l)
|
||||
elements.add(new SWListEntry<>(pair.getKey(), pair.getValue()));
|
||||
page = 0;
|
||||
}
|
||||
|
||||
public SWListInv(Player p, String t, List<SWListEntry<T>> l, ListCallback<T> 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<T> 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<T> extends SWInventory {
|
||||
void clicked(ClickType click, T element);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public static List<Pair<SWItem, UUID>> createPlayerList(Player without){
|
||||
List<Pair<SWItem, UUID>> onlinePlayers = new ArrayList<>();
|
||||
for(Player player : Bukkit.getOnlinePlayers()){
|
||||
@ -81,6 +91,18 @@ public class SWListInv<T> extends SWInventory {
|
||||
return onlinePlayers;
|
||||
}
|
||||
|
||||
public static List<SWListEntry<UUID>> createPlayerList(UUID without){
|
||||
List<SWListEntry<UUID>> 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<Pair<SWItem, Schematic>> getSchemList(int warkingUserId, SchematicType type){
|
||||
List<Pair<SWItem, Schematic>> schemList = new ArrayList<>();
|
||||
|
||||
@ -101,4 +123,43 @@ public class SWListInv<T> extends SWInventory {
|
||||
}
|
||||
return schemList;
|
||||
}
|
||||
|
||||
public static List<SWListEntry<Schematic>> getSchemList(SchematicType type, int steamwarUserId){
|
||||
List<SWListEntry<Schematic>> schemList = new ArrayList<>();
|
||||
|
||||
List<Schematic> 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<T>{
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
In neuem Issue referenzieren
Einen Benutzer sperren