Add new Schem GUI and some Util Stuff
Signed-off-by: Chaoscaot <chaoscaot444@gmail.com>
Dieser Commit ist enthalten in:
Ursprung
0d10aedd81
Commit
1918c96816
@ -19,12 +19,15 @@
|
||||
|
||||
package de.steamwar.schematicsystem.commands;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import de.steamwar.inventory.SWAnvilInv;
|
||||
import de.steamwar.inventory.SWInventory;
|
||||
import de.steamwar.inventory.SWItem;
|
||||
import de.steamwar.inventory.SWListInv;
|
||||
import de.steamwar.schematicsystem.SchematicSystem;
|
||||
import de.steamwar.schematicsystem.util.SchematicSelector;
|
||||
import de.steamwar.schematicsystem.util.SchematicSelectorInjectable;
|
||||
import de.steamwar.schematicsystem.util.SchematicSelectorInjectableAdapter;
|
||||
import de.steamwar.schematicsystem.util.UtilGui;
|
||||
import de.steamwar.sql.*;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
@ -38,46 +41,26 @@ import static de.steamwar.schematicsystem.commands.SchematicCommandUtils.invalid
|
||||
public class GUI {
|
||||
|
||||
public static void open(Player player) {
|
||||
list(player, SchematicNode.getSchematicsAccessibleByUser(getUser(player).getId(), null), false, "/");
|
||||
list(player);
|
||||
}
|
||||
|
||||
private static void list(Player player, List<SchematicNode> schems, boolean publics, String path) {
|
||||
List<SWListInv.SWListEntry<SchematicNode>> schemList = new ArrayList<>();
|
||||
|
||||
for(SchematicNode schem : schems) {
|
||||
Material m;
|
||||
if (schem.getItem().isEmpty())
|
||||
m = schem.isDir()?SWItem.getMaterial("CHEST"):SWItem.getMaterial("CAULDRON_ITEM");
|
||||
else
|
||||
m = SWItem.getMaterial(schem.getItem());
|
||||
|
||||
SWItem item = new SWItem(m, "§e" + schem.getName(), Collections.singletonList(schem.isDir() ? "§9Ordner" : "§7" + schem.getSchemtype().name()), !schem.isDir() && !schem.getSchemtype().writeable(), click -> {
|
||||
});
|
||||
if(!schem.isDir()) {
|
||||
if(schem.getRank() > 0)
|
||||
item.setLore(Lists.newArrayList("§7" + schem.getSchemtype().name(), "§8Rang " + schem.getRank()));
|
||||
}
|
||||
schemList.add(new SWListInv.SWListEntry<>(item, schem));
|
||||
}
|
||||
|
||||
SWListInv<SchematicNode> inv = new SWListInv<>(player, "§eSchematicliste §8- §r" + path, false, schemList, (clickType, schem) -> {
|
||||
if(schem.isDir()) {
|
||||
SteamwarUser user = SteamwarUser.get(player.getUniqueId());
|
||||
list(player, SchematicNode.getSchematicNodeInNode(schem), schem.getOwner() == 0, schem.generateBreadcrumbs(user));
|
||||
private static void list(Player player) {
|
||||
SchematicSelector selector = new SchematicSelector(player, SchematicSelector.selectSchematic(), new SchematicSelectorInjectableAdapter() {
|
||||
@Override
|
||||
public void onListRender(SWListInv<SchematicNode> inv, SchematicNode parent) {
|
||||
if(parent == null) {
|
||||
inv.setItem(49, Material.AIR, "", clickType -> {});
|
||||
} else {
|
||||
info(player, schem);
|
||||
}
|
||||
inv.setItem(49, Material.ANVIL, "§7Ordner Eigenschaften", clickType -> {
|
||||
info(player, parent);
|
||||
});
|
||||
if(publics) {
|
||||
inv.setItem(48, Material.BUCKET, "§7Eigene Schematics", clickType -> open(player));
|
||||
} else {
|
||||
inv.setItem(48, Material.GLASS, "§7Public Schematics", clickType -> list(player, SchematicNode.getSchematicsAccessibleByUser(0, null), true, "/"));
|
||||
}
|
||||
if(!publics && !path.equals("/")) {
|
||||
inv.setItem(49, Material.ANVIL, "§7Ordner-Info", clickType -> info(player, SchematicSystem.SCHEMATIC_COMMAND.nodeTypeMapper().map(player, new String[0], path)));
|
||||
}
|
||||
inv.setItem(50, Material.NAME_TAG, "§7Suche", clickType -> search(player, publics));
|
||||
inv.open();
|
||||
}, node -> {
|
||||
info(player, node);
|
||||
});
|
||||
selector.setTitle("Schematic GUI");
|
||||
selector.open();
|
||||
}
|
||||
|
||||
private static void info(Player player, SchematicNode node) {
|
||||
@ -111,11 +94,11 @@ public class GUI {
|
||||
changeItem(player, node);
|
||||
});
|
||||
if(!node.isDir()) {
|
||||
inv.setItem(4, SWItem.getMaterial("CAULDRON_ITEM"), "§e" + node.getSchemtype().name(), Arrays.asList("§7Zum Ändern", "§7anklicken"), false, click -> {
|
||||
inv.setItem(3, SWItem.getMaterial("CAULDRON_ITEM"), "§e" + node.getSchemtype().name(), Arrays.asList("§7Zum Ändern", "§7anklicken"), false, click -> {
|
||||
player.closeInventory();
|
||||
changeType(player, node);
|
||||
});
|
||||
inv.setItem(5, SWItem.getMaterial("MAGENTA_GLAZED_TERRACOTTA"), "§eDownload", click -> {
|
||||
inv.setItem(4, SWItem.getMaterial("MAGENTA_GLAZED_TERRACOTTA"), "§eDownload", click -> {
|
||||
player.closeInventory();
|
||||
SchematicSystem.SCHEMATIC_COMMAND.download(player, node);
|
||||
});
|
||||
@ -126,10 +109,17 @@ public class GUI {
|
||||
delmembers(player, node);
|
||||
});
|
||||
skull.setName("§eMitglieder");
|
||||
inv.setItem(6, skull);
|
||||
inv.setItem(5, skull);
|
||||
inv.setItem(6, Material.ARROW, "§eVerschieben", clickType -> {
|
||||
SchematicSelector selector = new SchematicSelector(player, SchematicSelector.selectDirectory(), npar -> {
|
||||
node.setParent(npar==null?null:npar.getId());
|
||||
info(player, SchematicNode.getSchematicNode(node.getId()));
|
||||
});
|
||||
selector.open();
|
||||
});
|
||||
Material finalMat = mat;
|
||||
inv.setItem(7, Material.NAME_TAG, "§eUmbenennen", clickType -> {
|
||||
SWAnvilInv anvilInv = new SWAnvilInv(player, node.getName() + " umbenennen");
|
||||
SWAnvilInv anvilInv = new SWAnvilInv(player, node.getName() + " umbenennen", node.getName());
|
||||
anvilInv.setItem(finalMat);
|
||||
anvilInv.setCallback(s -> {
|
||||
if (!invalidSchemName(player, new String[]{s})) {
|
||||
@ -237,29 +227,10 @@ public class GUI {
|
||||
}
|
||||
|
||||
private static void changeItem(Player p, SchematicNode schem){
|
||||
List<SWListInv.SWListEntry<Material>> materials = new LinkedList<>();
|
||||
for(Material material : Material.values()){
|
||||
SWItem item = new SWItem(material, "§7" + material.name());
|
||||
if(item.getItemMeta() != null && material.isItem())
|
||||
materials.add(new SWListInv.SWListEntry<>(item, material));
|
||||
}
|
||||
|
||||
SWListInv<Material> inv = new SWListInv<>(p, "Item ändern", materials, (clickType, material) -> {
|
||||
UtilGui.openMaterialSelector(p, "Item ändern", material -> {
|
||||
schem.setItem(material.name());
|
||||
p.closeInventory();
|
||||
info(p, schem);
|
||||
});
|
||||
inv.setCallback(-999, (ClickType click) -> p.closeInventory());
|
||||
inv.open();
|
||||
}
|
||||
|
||||
private static void search(Player player, boolean publics) {
|
||||
SWAnvilInv inv = new SWAnvilInv(player, "Schematics suchen");
|
||||
inv.setItem(SWItem.getMaterial("CAULDRON_ITEM"));
|
||||
inv.setCallback(s -> {
|
||||
SteamwarUser user = getUser(player);
|
||||
list(player, SchematicNode.filterSchems(publics?0:user.getId(), node -> node.getName().contains(s)), publics, "/");
|
||||
});
|
||||
inv.open();
|
||||
}
|
||||
}
|
||||
|
@ -249,16 +249,23 @@ public class SchematicCommand extends SWCommand {
|
||||
return;
|
||||
}
|
||||
|
||||
member.delete();
|
||||
SteamwarUser target = SteamwarUser.get(member.getMember());
|
||||
|
||||
List<SchematicNode> nodes = SchematicNode.deepGet(node.getId(), node1 -> node1.getOwner() != user.getId());
|
||||
if (!nodes.isEmpty()) {
|
||||
SteamwarUser target = SteamwarUser.get(member.getMember());
|
||||
for (SchematicNode schematicNode : nodes) {
|
||||
SchematicNode newNode = mkdirs(schematicNode.generateBreadcrumbs(user).split("/"), target, 1);
|
||||
schematicNode.setParent(newNode == null ? 0 : newNode.getId());
|
||||
}
|
||||
}
|
||||
|
||||
member.delete();
|
||||
player.sendMessage(SchematicSystem.PREFIX + "Der Spieler §e" + target.getUserName() + " §7hat nun keinen zugriff mehr auf die Schematic §e" + node.generateBreadcrumbs(user));
|
||||
|
||||
Player t = Bukkit.getPlayer(target.getUUID());
|
||||
if (t != null) {
|
||||
t.sendMessage(SchematicSystem.PREFIX + "Du hast nun keinen zugriff mehr auf die Schematic §e" + node.getName() + " §7von §e" + player.getName());
|
||||
}
|
||||
}
|
||||
|
||||
@Register("search")
|
||||
|
@ -0,0 +1,381 @@
|
||||
package de.steamwar.schematicsystem.util;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import de.steamwar.inventory.*;
|
||||
import de.steamwar.sql.SchematicNode;
|
||||
import de.steamwar.sql.SchematicType;
|
||||
import de.steamwar.sql.SteamwarUser;
|
||||
import lombok.*;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.text.MessageFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
public class SchematicSelector {
|
||||
|
||||
private final Player player;
|
||||
private final SteamwarUser user;
|
||||
private final Consumer<SchematicNode> callback;
|
||||
private final SelectorTarget target;
|
||||
private final SelectorFilter filter = new SelectorFilter();
|
||||
private SchematicSelectorInjectable injectable;
|
||||
private boolean useHooks;
|
||||
@Setter
|
||||
@Getter
|
||||
private boolean allowPublics = true;
|
||||
@Setter
|
||||
private String title = "{0} auswahl";
|
||||
|
||||
public SchematicSelector(Player player, SelectorTarget target, Consumer<SchematicNode> callback) {
|
||||
this.player = player;
|
||||
this.user = SteamwarUser.get(player.getUniqueId());
|
||||
this.target = target;
|
||||
this.callback = callback;
|
||||
}
|
||||
|
||||
public SchematicSelector(Player player, SelectorTarget target, SchematicSelectorInjectable injectable, Consumer<SchematicNode> callback) {
|
||||
this(player, target, callback);
|
||||
this.useHooks = true;
|
||||
this.injectable = injectable;
|
||||
}
|
||||
|
||||
public void open() {
|
||||
if(useHooks) {
|
||||
injectable.onSelectorCreate(player);
|
||||
}
|
||||
openList(null, false);
|
||||
}
|
||||
|
||||
private void openList(SchematicNode parent, boolean publics) {
|
||||
List<SWListInv.SWListEntry<SchematicNode>> list = new ArrayList<>();
|
||||
|
||||
if(parent != null) {
|
||||
list.add(new SWListInv.SWListEntry<>(new SWItem(Material.ARROW, "§eZurück", clickType -> {}), null));
|
||||
}
|
||||
|
||||
List<SchematicNode> nodes = new ArrayList<>();
|
||||
|
||||
if(filter.isFilter()) {
|
||||
nodes.addAll(SchematicNode.getAllSchematicsAccessibleByUser(publics?0:user.getId()));
|
||||
nodes.removeIf(node -> {
|
||||
if(useHooks) {
|
||||
injectable.onNodeFilter(node);
|
||||
}
|
||||
return !filter.matches(node);
|
||||
});
|
||||
if(target.target == SelectorTarget.Target.DIRECTORY) {
|
||||
nodes.removeIf(node -> !node.isDir());
|
||||
}
|
||||
} else {
|
||||
switch (target.target) {
|
||||
case DIRECTORY:
|
||||
if(parent == null) {
|
||||
nodes.addAll(SchematicNode.getSchematicsAccessibleByUser(publics?0:user.getId(), null));
|
||||
nodes.removeIf(node -> !node.isDir());
|
||||
} else {
|
||||
nodes.addAll(SchematicNode.getSchematicDirectoryInNode(parent.getId()));
|
||||
}
|
||||
break;
|
||||
case SCHEMATIC_TYPE:
|
||||
nodes.addAll(SchematicNode.getAccessibleSchematicsOfTypeInParent(publics?0:user.getId(), target.type.toDB(), parent==null?0:parent.getId()));
|
||||
break;
|
||||
default:
|
||||
nodes.addAll(SchematicNode.getSchematicsAccessibleByUser(publics?0:user.getId(), parent == null?0:parent.getId()));
|
||||
}
|
||||
}
|
||||
|
||||
for (SchematicNode node : nodes) {
|
||||
Material m;
|
||||
if (node.getItem().isEmpty())
|
||||
m = node.isDir()?SWItem.getMaterial("CHEST"):SWItem.getMaterial("CAULDRON_ITEM");
|
||||
else
|
||||
m = SWItem.getMaterial(node.getItem());
|
||||
|
||||
String name = "§" + (filter.getName().isEmpty()?"e":"7") + node.getName();
|
||||
|
||||
if(!filter.getName().isEmpty()) {
|
||||
name = name.replace(filter.getName(), "§e" + filter.getName() + "§7");
|
||||
}
|
||||
|
||||
SWItem item = new SWItem(m, name, Collections.singletonList(node.isDir() ? "§9Ordner" : "§7" + node.getSchemtype().name()), !node.isDir() && !node.getSchemtype().writeable(), click -> {
|
||||
});
|
||||
if(!node.isDir()) {
|
||||
if(node.getRank() > 0)
|
||||
item.setLore(Lists.newArrayList("§7" + node.getSchemtype().name(), "§8Rang " + node.getRank()));
|
||||
}
|
||||
list.add(new SWListInv.SWListEntry<>(item, node));
|
||||
}
|
||||
|
||||
SWListInv<SchematicNode> inv = new SWListInv<>(player, MessageFormat.format(title, target.target.getName()), false, list, (clickType, node) -> {
|
||||
if(node == null) {
|
||||
openList(getParent(parent), publics);
|
||||
return;
|
||||
}
|
||||
if(node.isDir()) {
|
||||
if(filter.isFilter() && target.target.isDirs()) {
|
||||
player.closeInventory();
|
||||
callback.accept(node);
|
||||
return;
|
||||
}
|
||||
filter.reset();
|
||||
openList(node, publics);
|
||||
return;
|
||||
}
|
||||
player.closeInventory();
|
||||
callback.accept(node);
|
||||
});
|
||||
if(allowPublics) {
|
||||
if(publics) {
|
||||
inv.setItem(48, Material.BUCKET, "§7Eigene Schematics", clickType -> openList(null, false));
|
||||
} else {
|
||||
inv.setItem(48, Material.GLASS, "§7Public Schematics", clickType -> openList(null, true));
|
||||
}
|
||||
}
|
||||
if(target.target.isDirs()) {
|
||||
inv.setItem(49, SWItem.getDye(10), "§7Ordner auswählen", clickType -> {
|
||||
player.closeInventory();
|
||||
callback.accept(parent);
|
||||
});
|
||||
}
|
||||
if(!publics) {
|
||||
inv.setItem(50, Material.CHEST, "§7Neuer Ordner", clickType -> createFolderIn(parent));
|
||||
}
|
||||
inv.setItem(51, Material.NAME_TAG, "§7Filter", clickType -> openFilter(publics));
|
||||
|
||||
if(useHooks) {
|
||||
injectable.onListRender(inv, parent);
|
||||
}
|
||||
inv.open();
|
||||
}
|
||||
|
||||
private void createFolderIn(SchematicNode parent) {
|
||||
SWAnvilInv inv = new SWAnvilInv(player, "Ordner Erstellen");
|
||||
inv.setItem(Material.CHEST);
|
||||
inv.setCallback(s -> {
|
||||
if(useHooks) {
|
||||
if(injectable.onFolderCreate(s)) {
|
||||
SchematicNode.createSchematicDirectory(user.getId(), s, parent==null?0:parent.getId());
|
||||
openList(parent, false);
|
||||
}
|
||||
} else {
|
||||
SchematicNode.createSchematicDirectory(user.getId(), s, parent==null?0:parent.getId());
|
||||
openList(parent, false);
|
||||
}
|
||||
});
|
||||
inv.open();
|
||||
}
|
||||
|
||||
private void openFilter(boolean publics) {
|
||||
SWInventory inv = new SWInventory(player, 9, "Filter");
|
||||
InvCallback nameCallback = clickType -> {
|
||||
if(clickType.isRightClick()) {
|
||||
filter.setName("");
|
||||
openFilter(publics);
|
||||
} else {
|
||||
SWAnvilInv swAnvilInv = new SWAnvilInv(player, "Name eingeben");
|
||||
swAnvilInv.setItem(Material.NAME_TAG);
|
||||
swAnvilInv.setCallback(s -> {
|
||||
filter.setName(s);
|
||||
openFilter(publics);
|
||||
});
|
||||
swAnvilInv.open();
|
||||
}
|
||||
};
|
||||
if(filter.getName().isEmpty()) {
|
||||
inv.setItem(0, Material.NAME_TAG, "§7Nach namen suchen...", nameCallback);
|
||||
} else {
|
||||
inv.setItem(0, Material.NAME_TAG, "§7Nach namen suchen...", Collections.singletonList("§7Suchwort: §e" + filter.getName()), true, nameCallback);
|
||||
}
|
||||
|
||||
InvCallback ownerCallback = clickType -> {
|
||||
if(clickType.isRightClick()) {
|
||||
filter.setOwner(null);
|
||||
openFilter(publics);
|
||||
} else {
|
||||
SWAnvilInv swAnvilInv = new SWAnvilInv(player, "Besitzer eingeben");
|
||||
swAnvilInv.setItem(Material.PLAYER_HEAD);
|
||||
swAnvilInv.setCallback(s -> {
|
||||
filter.setOwner(SteamwarUser.get(s).getId());
|
||||
openFilter(publics);
|
||||
});
|
||||
swAnvilInv.open();
|
||||
}
|
||||
};
|
||||
if(filter.getOwner() == null) {
|
||||
inv.setItem(1, Material.PLAYER_HEAD, "§7Nach Besitzer suchen...", ownerCallback);
|
||||
} else {
|
||||
SteamwarUser user = SteamwarUser.get(filter.getOwner());
|
||||
SWItem item = SWItem.getPlayerSkull(user.getUserName());
|
||||
item.setName("§7Nach Besitzer suchen...");
|
||||
item.setEnchanted(true);
|
||||
item.setLore(Collections.singletonList("§7Besitzer: §e" + user.getUserName()));
|
||||
item.setCallback(ownerCallback);
|
||||
inv.setItem(1, item);
|
||||
}
|
||||
|
||||
InvCallback schemTypeCallback = clickType -> {
|
||||
if(clickType.isRightClick()) {
|
||||
filter.setType(null);
|
||||
openFilter(publics);
|
||||
} else {
|
||||
List<SWListInv.SWListEntry<SchematicType>> types = new ArrayList<>();
|
||||
SchematicType.values().forEach(schematicType -> {
|
||||
types.add(new SWListInv.SWListEntry<>(new SWItem(SWItem.getMaterial("STONE_BUTTON"), "§e" + schematicType.name(), Collections.emptyList(), schematicType.fightType(), n -> {}), schematicType));
|
||||
});
|
||||
SWListInv<SchematicType> listInv = new SWListInv<>(player, "Typ wählen...", types, (clickType1, schematicType) -> {
|
||||
filter.setType(schematicType);
|
||||
openFilter(publics);
|
||||
});
|
||||
listInv.open();
|
||||
}
|
||||
};
|
||||
|
||||
if(filter.getType() == null) {
|
||||
inv.setItem(2, SWItem.getMaterial("STONE_BUTTON"), "§7Nach Typ Filtern...", schemTypeCallback);
|
||||
} else {
|
||||
inv.setItem(2, SWItem.getMaterial("STONE_BUTTON"), "§7Nach Typ Filtern...", Collections.singletonList("§7Typ: §e" + filter.getType().name()), true, schemTypeCallback);
|
||||
}
|
||||
|
||||
InvCallback materialCallback = clickType -> {
|
||||
if(clickType.isRightClick()) {
|
||||
filter.setItem(null);
|
||||
openFilter(publics);
|
||||
} else {
|
||||
UtilGui.openMaterialSelector(player, material -> {
|
||||
filter.setItem(material);
|
||||
openFilter(publics);
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
if(filter.getItem() == null) {
|
||||
inv.setItem(3, Material.STONE, "§7Nach Item Filtern...", materialCallback);
|
||||
} else {
|
||||
inv.setItem(3, filter.getItem(), "§7Nach Item Filtern...", Collections.singletonList("§7Item: §e" + filter.getItem().name()), true, materialCallback);
|
||||
}
|
||||
|
||||
inv.setItem(7, SWItem.getDye(1), "§eAbbrechen", clickType -> {
|
||||
filter.reset();
|
||||
openList(null, publics);
|
||||
});
|
||||
inv.setItem(8, SWItem.getDye(10), "§eSuchen...", clickType -> {
|
||||
filter.setFilter(true);
|
||||
if(useHooks) {
|
||||
injectable.onFilterApply(filter);
|
||||
}
|
||||
openList(null, publics);
|
||||
});
|
||||
|
||||
if(useHooks) {
|
||||
injectable.onFilterRender(inv);
|
||||
}
|
||||
|
||||
inv.open();
|
||||
}
|
||||
|
||||
private static SchematicNode getParent(SchematicNode node) {
|
||||
if(node.getParent() == null) {
|
||||
return null;
|
||||
}
|
||||
return node.getParentNode();
|
||||
}
|
||||
|
||||
public static SelectorTarget selectSchematic() {
|
||||
return new SelectorTarget(SelectorTarget.Target.SCHEMATIC, null);
|
||||
}
|
||||
|
||||
public static SelectorTarget selectDirectory() {
|
||||
return new SelectorTarget(SelectorTarget.Target.DIRECTORY, null);
|
||||
}
|
||||
|
||||
public static SelectorTarget selectSchematicNode() {
|
||||
return new SelectorTarget(SelectorTarget.Target.SCHEMATIC_NODE, null);
|
||||
}
|
||||
|
||||
public static SelectorTarget selectSchematicType(SchematicType type) {
|
||||
return new SelectorTarget(SelectorTarget.Target.SCHEMATIC_TYPE, type);
|
||||
}
|
||||
|
||||
private static class SelectorTarget {
|
||||
|
||||
private final Target target;
|
||||
private final SchematicType type;
|
||||
|
||||
private SelectorTarget(Target target, SchematicType type) {
|
||||
this.target = target;
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
@AllArgsConstructor
|
||||
private enum Target {
|
||||
SCHEMATIC("Schematic", false),
|
||||
DIRECTORY("Ordner", true),
|
||||
SCHEMATIC_NODE("Schematic/Ordner", true),
|
||||
SCHEMATIC_TYPE("Schematic", false);
|
||||
|
||||
@Getter
|
||||
private String name;
|
||||
@Getter
|
||||
private boolean dirs;
|
||||
}
|
||||
}
|
||||
|
||||
@NoArgsConstructor
|
||||
@Getter
|
||||
@Setter
|
||||
public static class SelectorFilter {
|
||||
|
||||
private boolean filter;
|
||||
|
||||
private String name = "";
|
||||
private Integer owner = null;
|
||||
private SchematicType type = null;
|
||||
private Material item = null;
|
||||
|
||||
public void reset() {
|
||||
name = "";
|
||||
owner = null;
|
||||
type = null;
|
||||
item = null;
|
||||
filter = false;
|
||||
}
|
||||
|
||||
public boolean matches(SchematicNode node) {
|
||||
boolean matches = true;
|
||||
if(!name.isEmpty()) {
|
||||
if(!node.getName().contains(name)) {
|
||||
matches = false;
|
||||
}
|
||||
}
|
||||
|
||||
if(owner != null) {
|
||||
if(node.getOwner() != owner) {
|
||||
matches = false;
|
||||
}
|
||||
}
|
||||
|
||||
if(type != null) {
|
||||
if(node.isDir() || !node.getType().equals(type.toDB())) {
|
||||
matches = false;
|
||||
}
|
||||
}
|
||||
|
||||
if(item != null) {
|
||||
String i;
|
||||
if(node.getItem().isEmpty()) {
|
||||
i = node.isDir()?"CHEST":"CAULDRON";
|
||||
} else {
|
||||
i = node.getItem();
|
||||
}
|
||||
if(!item.name().equals(i)) {
|
||||
matches = false;
|
||||
}
|
||||
}
|
||||
return matches;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,21 @@
|
||||
package de.steamwar.schematicsystem.util;
|
||||
|
||||
import de.steamwar.inventory.SWInventory;
|
||||
import de.steamwar.inventory.SWListInv;
|
||||
import de.steamwar.sql.SchematicNode;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public interface SchematicSelectorInjectable {
|
||||
|
||||
void onSelectorCreate(Player player);
|
||||
|
||||
void onListRender(SWListInv<SchematicNode> inv, SchematicNode parent);
|
||||
|
||||
void onFilterRender(SWInventory inventory);
|
||||
|
||||
void onFilterApply(SchematicSelector.SelectorFilter filter);
|
||||
|
||||
boolean onFolderCreate(String name);
|
||||
|
||||
void onNodeFilter(SchematicNode node);
|
||||
}
|
@ -0,0 +1,33 @@
|
||||
package de.steamwar.schematicsystem.util;
|
||||
|
||||
import de.steamwar.inventory.SWInventory;
|
||||
import de.steamwar.inventory.SWListInv;
|
||||
import de.steamwar.sql.SchematicNode;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public abstract class SchematicSelectorInjectableAdapter implements SchematicSelectorInjectable {
|
||||
|
||||
private Player player;
|
||||
|
||||
@Override
|
||||
public void onSelectorCreate(Player player) {
|
||||
this.player = player;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onListRender(SWListInv<SchematicNode> inv, SchematicNode parent) {}
|
||||
|
||||
@Override
|
||||
public void onFilterRender(SWInventory inventory) {}
|
||||
|
||||
@Override
|
||||
public void onFilterApply(SchematicSelector.SelectorFilter filter) {}
|
||||
|
||||
@Override
|
||||
public boolean onFolderCreate(String name) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNodeFilter(SchematicNode node) {}
|
||||
}
|
@ -0,0 +1,34 @@
|
||||
package de.steamwar.schematicsystem.util;
|
||||
|
||||
import de.steamwar.inventory.SWItem;
|
||||
import de.steamwar.inventory.SWListInv;
|
||||
import lombok.experimental.UtilityClass;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
@UtilityClass
|
||||
public class UtilGui {
|
||||
|
||||
public static void openMaterialSelector(Player player, Consumer<Material> callback) {
|
||||
openMaterialSelector(player, "Material auswählen", callback);
|
||||
}
|
||||
|
||||
public static void openMaterialSelector(Player player, String title, Consumer<Material> callback) {
|
||||
List<SWListInv.SWListEntry<Material>> materials = new LinkedList<>();
|
||||
for(Material material : Material.values()){
|
||||
if(material.name().startsWith(Material.LEGACY_PREFIX))
|
||||
continue;
|
||||
SWItem item = new SWItem(material, "§7" + material.name());
|
||||
if(item.getItemMeta() != null && material.isItem()) {
|
||||
materials.add(new SWListInv.SWListEntry<>(item, material));
|
||||
}
|
||||
}
|
||||
|
||||
SWListInv<Material> swListInv = new SWListInv<>(player, title, materials, (clickType3, material) -> callback.accept(material));
|
||||
swListInv.open();
|
||||
}
|
||||
}
|
6
pom.xml
6
pom.xml
@ -44,5 +44,11 @@
|
||||
<scope>system</scope>
|
||||
<systemPath>${main.basedir}/lib/SpigotCore.jar</systemPath>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
<version>1.18.22</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
In neuem Issue referenzieren
Einen Benutzer sperren