Merge branch 'softRemovalOfPair' of SteamWar/SpigotCore into master
Dieser Commit ist enthalten in:
Commit
8608ceb738
@ -8,17 +8,26 @@ import org.bukkit.Material;
|
|||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.inventory.ClickType;
|
import org.bukkit.event.inventory.ClickType;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.*;
|
||||||
import java.util.List;
|
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
public class SWListInv<T> extends SWInventory {
|
public class SWListInv<T> extends SWInventory {
|
||||||
|
|
||||||
private ListCallback<T> callback;
|
private ListCallback<T> callback;
|
||||||
private List<Pair<SWItem, T>> elements;
|
private List<SWListEntry<T>> elements;
|
||||||
private int page;
|
private int page;
|
||||||
|
|
||||||
|
@Deprecated
|
||||||
public SWListInv(Player p, String t, ListCallback<T> c, List<Pair<SWItem, T>> l) {
|
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);
|
super(p, (l.size()>45) ? 54 : (l.size() + 9-l.size()%9), t);
|
||||||
callback = c;
|
callback = c;
|
||||||
elements = l;
|
elements = l;
|
||||||
@ -52,11 +61,11 @@ public class SWListInv<T> extends SWInventory {
|
|||||||
}
|
}
|
||||||
int i = page*45;
|
int i = page*45;
|
||||||
for(int ipage=0; ipage < ipageLimit; ipage++ ){
|
for(int ipage=0; ipage < ipageLimit; ipage++ ){
|
||||||
SWItem e = elements.get(i).getKey();
|
SWItem e = elements.get(i).getItem();
|
||||||
|
|
||||||
final int pos = i;
|
final int pos = i;
|
||||||
setItem(ipage, e);
|
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++;
|
i++;
|
||||||
}
|
}
|
||||||
super.open();
|
super.open();
|
||||||
@ -70,6 +79,7 @@ public class SWListInv<T> extends SWInventory {
|
|||||||
void clicked(ClickType click, T element);
|
void clicked(ClickType click, T element);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Deprecated
|
||||||
public static List<Pair<SWItem, UUID>> createPlayerList(Player without){
|
public static List<Pair<SWItem, UUID>> createPlayerList(Player without){
|
||||||
List<Pair<SWItem, UUID>> onlinePlayers = new ArrayList<>();
|
List<Pair<SWItem, UUID>> onlinePlayers = new ArrayList<>();
|
||||||
for(Player player : Bukkit.getOnlinePlayers()){
|
for(Player player : Bukkit.getOnlinePlayers()){
|
||||||
@ -81,6 +91,18 @@ public class SWListInv<T> extends SWInventory {
|
|||||||
return onlinePlayers;
|
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){
|
public static List<Pair<SWItem, Schematic>> getSchemList(int warkingUserId, SchematicType type){
|
||||||
List<Pair<SWItem, Schematic>> schemList = new ArrayList<>();
|
List<Pair<SWItem, Schematic>> schemList = new ArrayList<>();
|
||||||
|
|
||||||
@ -101,4 +123,43 @@ public class SWListInv<T> extends SWInventory {
|
|||||||
}
|
}
|
||||||
return schemList;
|
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