13
0

Schemnodes Schematic System #93

Zusammengeführt
Lixfel hat 30 Commits von nodes nach master 2021-12-27 16:30:26 +01:00 zusammengeführt
5 geänderte Dateien mit 4 neuen und 557 gelöschten Zeilen
Nur Änderungen aus Commit 441bc4ee6c werden angezeigt - Alle Commits anzeigen

Datei anzeigen

@ -24,11 +24,10 @@ import de.steamwar.inventory.SWInventory;
import de.steamwar.inventory.SWItem; import de.steamwar.inventory.SWItem;
import de.steamwar.inventory.SWListInv; import de.steamwar.inventory.SWListInv;
import de.steamwar.schematicsystem.SchematicSystem; 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 de.steamwar.sql.*;
import de.steamwar.util.SchematicSelector;
import de.steamwar.util.SchematicSelectorInjectableAdapter;
import de.steamwar.util.UtilGui;
import org.bukkit.Material; 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;
@ -59,7 +58,7 @@ public class GUI {
}, node -> { }, node -> {
info(player, node); info(player, node);
}); });
selector.setTitle("Schematic GUI"); selector.setTitle("Schematic GUI: {1}");
selector.open(); selector.open();
} }

Datei anzeigen

@ -1,413 +0,0 @@
/*
This file is a part of the SteamWar software.
Copyright (C) 2021 SteamWar.de-Serverteam
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
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 {
@Getter
private final Player player;
@Getter
private final SteamwarUser user;
@Getter
private final Consumer<SchematicNode> callback;
@Getter
private final SelectorTarget target;
@Getter
private final SelectorFilter filter = new SelectorFilter();
private SchematicSelectorInjectable injectable;
private boolean useHooks;
@Setter
@Getter
private boolean allowPublics = true;
@Setter
@Getter
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(this);
}
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(this, node);
}
return !filter.matches(node);
});
if(target.target == SelectorTarget.Target.DIRECTORY) {
nodes.removeIf(node -> !node.isDir());
}
if(target.target == SelectorTarget.Target.SCHEMATIC_TYPE) {
nodes.removeIf(node -> node.isDir() || !node.getType().equals(target.type.toDB()));
}
} 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(this, 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(this, 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);
}
if(target.target == SelectorTarget.Target.SCHEMATIC_TYPE) {
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);
});
}
};
final int iSlot = target.target== SelectorTarget.Target.SCHEMATIC_TYPE?2:3;
if(filter.getItem() == null) {
inv.setItem(iSlot, Material.STONE, "§7Nach Item Filtern...", materialCallback);
} else {
inv.setItem(iSlot, 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(this);
}
openList(null, publics);
});
if(useHooks) {
injectable.onFilterRender(this, 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;
}
}
}

Datei anzeigen

@ -1,39 +0,0 @@
/*
This file is a part of the SteamWar software.
Copyright (C) 2021 SteamWar.de-Serverteam
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package de.steamwar.schematicsystem.util;
import de.steamwar.inventory.SWInventory;
import de.steamwar.inventory.SWListInv;
import de.steamwar.sql.SchematicNode;
public interface SchematicSelectorInjectable {
void onSelectorCreate(SchematicSelector selector);
void onListRender(SchematicSelector selector, SWListInv<SchematicNode> inv, SchematicNode parent);
void onFilterRender(SchematicSelector selector, SWInventory inventory);
void onFilterApply(SchematicSelector selector);
boolean onFolderCreate(SchematicSelector selector, String name);
void onNodeFilter(SchematicSelector selector, SchematicNode node);
}

Datei anzeigen

@ -1,47 +0,0 @@
/*
This file is a part of the SteamWar software.
Copyright (C) 2021 SteamWar.de-Serverteam
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
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 {
@Override
public void onSelectorCreate(SchematicSelector selector) {}
@Override
public void onListRender(SchematicSelector selector, SWListInv<SchematicNode> inv, SchematicNode parent) {}
@Override
public void onFilterRender(SchematicSelector selector, SWInventory inventory) {}
@Override
public void onFilterApply(SchematicSelector selector) {}
@Override
public boolean onFolderCreate(SchematicSelector selector, String name) {
return true;
}
@Override
public void onNodeFilter(SchematicSelector selector, SchematicNode node) {}
}

Datei anzeigen

@ -1,53 +0,0 @@
/*
This file is a part of the SteamWar software.
Copyright (C) 2020 SteamWar.de-Serverteam
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
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();
}
}