Signed-off-by: Chaoscaot <chaoscaot444@gmail.com>
Dieser Commit ist enthalten in:
Ursprung
83d7a4c988
Commit
bf796ebce3
51
SpigotCore_Main/src/SpigotCore.properties
Normale Datei
51
SpigotCore_Main/src/SpigotCore.properties
Normale Datei
@ -0,0 +1,51 @@
|
||||
#
|
||||
# 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/>.
|
||||
#
|
||||
|
||||
SCHEM_SELECTOR_TITLE={0} auswählen: {1}
|
||||
SCHEM_SELECTOR_BACK=§eZurück
|
||||
SCHEM_SELECTOR_DIR=Ordner
|
||||
SCHEM_SELECTOR_RANK=§8Rang {0}
|
||||
SCHEM_SELECTOR_OWN=§7Eigene Schematics
|
||||
SCHEM_SELECTOR_PUB=§7Public Schematics
|
||||
SCHEM_SELECTOR_SEL_DIR=§7Ordner auswählen
|
||||
SCHEM_SELECTOR_NEW_DIR=§7Neuer Ordner
|
||||
SCHEM_SELECTOR_FILTER=§7Filter
|
||||
|
||||
SCHEM_SELECTOR_CREATE_DIR_TITLE=Ordner Erstellen
|
||||
|
||||
SCHEM_SELECTOR_FILTER_TITLE=Filter
|
||||
SCHEM_SELECTOR_FILTER_ENTER_NAME=Name eingeben
|
||||
SCHEM_SELECTOR_FILTER_NAME=§7Nach Namen suchen...
|
||||
SCHEM_SELECTOR_FILTER_NAME_SEARCH=§7Suchwort: §e{0}
|
||||
SCHEM_SELECTOR_FILTER_ENTER_OWNER=Besitzer eingeben
|
||||
SCHEM_SELECTOR_FILTER_OWNER=§7Nach Besitzer suchen...
|
||||
SCHEM_SELECTOR_FILTER_OWNER_SEARCH=§7Besitzer: §e{0}
|
||||
SCHEM_SELECTOR_FILTER_SEL_TYPE=Typ wählen...
|
||||
SCHEM_SELECTOR_FILTER_TYPE=§7Nach Typ Filtern...
|
||||
SCHEM_SELECTOR_FILTER_TYPE_SEARCH=§7Typ: §e{0}
|
||||
SCHEM_SELECTOR_FILTER_MAT=§7Nach Item Filtern...
|
||||
SCHEM_SELECTOR_FILTER_MAT_SEARCH=§7Item: §e{0}
|
||||
SCHEM_SELECTOR_CANCEL=§eAbbrechen
|
||||
SCHEM_SELECTOR_GO=§eSuchen...
|
||||
|
||||
SCHEM_SELECTOR_SCHEMATIC=Schematic
|
||||
SCHEM_SELECTOR_DIRECTORY=Ordner
|
||||
SCHEM_SELECTOR_SCHEMATIC_NODE=Schematic/Ordner
|
||||
|
||||
MATERIAL_SELECTOR_TITLE=Material auswählen
|
0
SpigotCore_Main/src/SpigotCore_en.properties
Normale Datei
0
SpigotCore_Main/src/SpigotCore_en.properties
Normale Datei
@ -25,6 +25,7 @@ import de.steamwar.core.events.ChattingEvent;
|
||||
import de.steamwar.core.events.ChunkListener;
|
||||
import de.steamwar.core.events.PlayerJoinedEvent;
|
||||
import de.steamwar.core.events.WorldLoadEvent;
|
||||
import de.steamwar.message.Message;
|
||||
import de.steamwar.sql.SQL;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
@ -39,6 +40,7 @@ public class Core extends JavaPlugin{
|
||||
|
||||
private static Core instance;
|
||||
private static final int version;
|
||||
public static Message MESSAGE;
|
||||
|
||||
static{
|
||||
String packageName = Bukkit.getServer().getClass().getPackage().getName();
|
||||
@ -79,6 +81,8 @@ public class Core extends JavaPlugin{
|
||||
} catch (IOException e) {
|
||||
throw new SecurityException("Could not load Hostname", e);
|
||||
}
|
||||
|
||||
MESSAGE = new Message("SpigotCore", getClassLoader());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -19,10 +19,12 @@
|
||||
|
||||
package de.steamwar.util;
|
||||
|
||||
import de.steamwar.core.Core;
|
||||
import de.steamwar.inventory.*;
|
||||
import de.steamwar.sql.SchematicNode;
|
||||
import de.steamwar.sql.SchematicType;
|
||||
import de.steamwar.sql.SteamwarUser;
|
||||
import jdk.nashorn.internal.runtime.doubleconv.CachedPowers;
|
||||
import lombok.*;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
@ -33,9 +35,12 @@ import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.Function;
|
||||
|
||||
public class SchematicSelector {
|
||||
|
||||
public static final String DEFAULT_TITLE = "SCHEM_SELECTOR_TITLE";
|
||||
|
||||
@Getter
|
||||
private final Player player;
|
||||
@Getter
|
||||
@ -53,10 +58,11 @@ public class SchematicSelector {
|
||||
private PublicMode publicMode = PublicMode.ALL;
|
||||
@Setter
|
||||
@Getter
|
||||
private String title = "{0} auswahl: {1}";
|
||||
private boolean singleDirOpen;
|
||||
@Setter
|
||||
@Getter
|
||||
private boolean singleDirOpen;
|
||||
private Function<Player, String> title;
|
||||
private boolean sdoTrigger = false;
|
||||
|
||||
public SchematicSelector(Player player, SelectorTarget target, Consumer<SchematicNode> callback) {
|
||||
this.player = player;
|
||||
@ -80,112 +86,42 @@ public class SchematicSelector {
|
||||
}
|
||||
|
||||
private void openList(SchematicNode parent, boolean publics) {
|
||||
List<SchematicNode> nodes = new ArrayList<>();
|
||||
List<SchematicNode> nodes = filter.isFilter()?getFilteredSchematics(publics):getSchematicList(publics, parent);
|
||||
|
||||
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()));
|
||||
if(target.rank >= 0) {
|
||||
nodes.removeIf(node -> node.getRank() > target.rank);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
nodes.addAll(SchematicNode.getSchematicsAccessibleByUser(publics?0:user.getId(), parent == null?0:parent.getId()));
|
||||
}
|
||||
|
||||
if(singleDirOpen && nodes.size() == 1 && nodes.get(0).isDir()) {
|
||||
openList(nodes.get(0), publics);
|
||||
return;
|
||||
}
|
||||
if(sdoTrigger) {
|
||||
sdoTrigger = false;
|
||||
return;
|
||||
}
|
||||
|
||||
List<SWListInv.SWListEntry<SchematicNode>> list = new ArrayList<>();
|
||||
|
||||
if(parent != null) {
|
||||
list.add(new SWListInv.SWListEntry<>(new SWItem(Material.ARROW, "§eZurück", clickType -> {}), null));
|
||||
list.add(new SWListInv.SWListEntry<>(new SWItem(Material.ARROW, Core.MESSAGE.parse("SCHEM_SELECTOR_BACK", player), clickType -> {}), null));
|
||||
}
|
||||
|
||||
for (SchematicNode node : nodes) {
|
||||
if(node.getName().equals("//copy")) continue;
|
||||
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(Arrays.asList("§7" + node.getSchemtype().name(), "§8Rang " + node.getRank()));
|
||||
}
|
||||
list.add(new SWListInv.SWListEntry<>(item, node));
|
||||
list.add(renderItem(node));
|
||||
}
|
||||
|
||||
SWListInv<SchematicNode> inv = new SWListInv<>(player, MessageFormat.format(title, target.target.getName(), filter.getName().isEmpty()?(parent == null?"/":parent.generateBreadcrumbs(user)):filter.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);
|
||||
});
|
||||
SWListInv<SchematicNode> inv = new SWListInv<>(player, MessageFormat.format(title==null?DEFAULT_TITLE:title.apply(player), target.target.getName(player), filter.getName().isEmpty()?(parent == null?"/":parent.generateBreadcrumbs(user)):filter.getName()), false, list, (clickType, node) -> handleClick(publics, node, parent));
|
||||
if(publicMode == PublicMode.ALL) {
|
||||
if(publics) {
|
||||
inv.setItem(48, Material.BUCKET, "§7Eigene Schematics", clickType -> openList(null, false));
|
||||
inv.setItem(48, Material.BUCKET, Core.MESSAGE.parse("SCHEM_SELECTOR_OWN", player), clickType -> openList(null, false));
|
||||
} else {
|
||||
inv.setItem(48, Material.GLASS, "§7Public Schematics", clickType -> openList(null, true));
|
||||
inv.setItem(48, Material.GLASS, Core.MESSAGE.parse("SCHEM_SELECTOR_PUB", player), clickType -> openList(null, true));
|
||||
}
|
||||
}
|
||||
if(target.target.isDirs()) {
|
||||
inv.setItem(49, SWItem.getDye(10), "§7Ordner auswählen", clickType -> {
|
||||
inv.setItem(49, SWItem.getDye(10), Core.MESSAGE.parse("SCHEM_SELECTOR_SEL_DIR", player), clickType -> {
|
||||
player.closeInventory();
|
||||
callback.accept(parent);
|
||||
});
|
||||
}
|
||||
if(!publics) {
|
||||
inv.setItem(50, Material.CHEST, "§7Neuer Ordner", clickType -> createFolderIn(parent));
|
||||
inv.setItem(50, Material.CHEST, Core.MESSAGE.parse("SCHEM_SELECTOR_NEW_DIR", player), clickType -> createFolderIn(parent));
|
||||
}
|
||||
inv.setItem(51, Material.NAME_TAG, "§7Filter", clickType -> openFilter(publics));
|
||||
inv.setItem(51, Material.NAME_TAG, Core.MESSAGE.parse("SCHEM_SELECTOR_FILTER", player), clickType -> openFilter(publics));
|
||||
|
||||
if(useHooks) {
|
||||
injectable.onListRender(this, inv, parent);
|
||||
@ -193,8 +129,48 @@ public class SchematicSelector {
|
||||
inv.open();
|
||||
}
|
||||
|
||||
private void handleClick(boolean publics, SchematicNode node, SchematicNode parent) {
|
||||
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);
|
||||
}
|
||||
|
||||
private SWListInv.SWListEntry<SchematicNode> renderItem(SchematicNode node) {
|
||||
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() ? ("§9" + Core.MESSAGE.parse("SCHEM_SELECTOR_DIR", player)) : "§7" + node.getSchemtype().name()), !node.isDir() && !node.getSchemtype().writeable(), click -> {
|
||||
});
|
||||
if(!node.isDir() && node.getRank() > 0) {
|
||||
item.setLore(Arrays.asList("§7" + node.getSchemtype().name(), Core.MESSAGE.parse("SCHEM_SELECTOR_RANK", player)));
|
||||
}
|
||||
return new SWListInv.SWListEntry<>(item, node);
|
||||
}
|
||||
|
||||
private void createFolderIn(SchematicNode parent) {
|
||||
SWAnvilInv inv = new SWAnvilInv(player, "Ordner Erstellen");
|
||||
SWAnvilInv inv = new SWAnvilInv(player, Core.MESSAGE.parse("SCHEM_SELECTOR_CREATE_DIR_TITLE", player));
|
||||
inv.setItem(Material.CHEST);
|
||||
inv.setCallback(s -> {
|
||||
if(useHooks) {
|
||||
@ -211,13 +187,13 @@ public class SchematicSelector {
|
||||
}
|
||||
|
||||
private void openFilter(boolean publics) {
|
||||
SWInventory inv = new SWInventory(player, 9, "Filter");
|
||||
SWInventory inv = new SWInventory(player, 9, Core.MESSAGE.parse("SCHEM_SELECTOR_FILTER_TITLE", player));
|
||||
InvCallback nameCallback = clickType -> {
|
||||
if(clickType.isRightClick()) {
|
||||
filter.setName("");
|
||||
openFilter(publics);
|
||||
} else {
|
||||
SWAnvilInv swAnvilInv = new SWAnvilInv(player, "Name eingeben");
|
||||
SWAnvilInv swAnvilInv = new SWAnvilInv(player, Core.MESSAGE.parse("SCHEM_SELECTOR_FILTER_ENTER_NAME", player));
|
||||
swAnvilInv.setItem(Material.NAME_TAG);
|
||||
swAnvilInv.setCallback(s -> {
|
||||
filter.setName(s);
|
||||
@ -227,9 +203,9 @@ public class SchematicSelector {
|
||||
}
|
||||
};
|
||||
if(filter.getName().isEmpty()) {
|
||||
inv.setItem(0, Material.NAME_TAG, "§7Nach namen suchen...", nameCallback);
|
||||
inv.setItem(0, Material.NAME_TAG, Core.MESSAGE.parse("SCHEM_SELECTOR_FILTER_NAME", player), nameCallback);
|
||||
} else {
|
||||
inv.setItem(0, Material.NAME_TAG, "§7Nach namen suchen...", Collections.singletonList("§7Suchwort: §e" + filter.getName()), true, nameCallback);
|
||||
inv.setItem(0, Material.NAME_TAG, Core.MESSAGE.parse("SCHEM_SELECTOR_FILTER_NAME", player), Collections.singletonList(Core.MESSAGE.parse("SCHEM_SELECTOR_FILTER_NAME_SEARCH", player, filter.getName())), true, nameCallback);
|
||||
}
|
||||
|
||||
InvCallback ownerCallback = clickType -> {
|
||||
@ -237,7 +213,7 @@ public class SchematicSelector {
|
||||
filter.setOwner(null);
|
||||
openFilter(publics);
|
||||
} else {
|
||||
SWAnvilInv swAnvilInv = new SWAnvilInv(player, "Besitzer eingeben");
|
||||
SWAnvilInv swAnvilInv = new SWAnvilInv(player, Core.MESSAGE.parse("SCHEM_SELECTOR_FILTER_ENTER_OWNER", player));
|
||||
swAnvilInv.setItem(Material.PLAYER_HEAD);
|
||||
swAnvilInv.setCallback(s -> {
|
||||
filter.setOwner(SteamwarUser.get(s).getId());
|
||||
@ -247,13 +223,13 @@ public class SchematicSelector {
|
||||
}
|
||||
};
|
||||
if(filter.getOwner() == null) {
|
||||
inv.setItem(1, Material.PLAYER_HEAD, "§7Nach Besitzer suchen...", ownerCallback);
|
||||
inv.setItem(1, Material.PLAYER_HEAD, Core.MESSAGE.parse("SCHEM_SELECTOR_FILTER_OWNER", player), ownerCallback);
|
||||
} else {
|
||||
SteamwarUser user = SteamwarUser.get(filter.getOwner());
|
||||
SteamwarUser tUser = SteamwarUser.get(filter.getOwner());
|
||||
SWItem item = SWItem.getPlayerSkull(user.getUserName());
|
||||
item.setName("§7Nach Besitzer suchen...");
|
||||
item.setName(Core.MESSAGE.parse("SCHEM_SELECTOR_FILTER_OWNER", player));
|
||||
item.setEnchanted(true);
|
||||
item.setLore(Collections.singletonList("§7Besitzer: §e" + user.getUserName()));
|
||||
item.setLore(Collections.singletonList(Core.MESSAGE.parse("SCHEM_SELECTOR_FILTER_OWNER_SEARCH", player, tUser.getUserName())));
|
||||
item.setCallback(ownerCallback);
|
||||
inv.setItem(1, item);
|
||||
}
|
||||
@ -268,7 +244,7 @@ public class SchematicSelector {
|
||||
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) -> {
|
||||
SWListInv<SchematicType> listInv = new SWListInv<>(player, Core.MESSAGE.parse("SCHEM_SELECTOR_FILTER_SEL_TYPE", player), types, (clickType1, schematicType) -> {
|
||||
filter.setType(schematicType);
|
||||
openFilter(publics);
|
||||
});
|
||||
@ -277,9 +253,9 @@ public class SchematicSelector {
|
||||
};
|
||||
|
||||
if(filter.getType() == null) {
|
||||
inv.setItem(2, SWItem.getMaterial("STONE_BUTTON"), "§7Nach Typ Filtern...", schemTypeCallback);
|
||||
inv.setItem(2, SWItem.getMaterial("STONE_BUTTON"), Core.MESSAGE.parse("SCHEM_SELECTOR_FILTER_TYPE", player), schemTypeCallback);
|
||||
} else {
|
||||
inv.setItem(2, SWItem.getMaterial("STONE_BUTTON"), "§7Nach Typ Filtern...", Collections.singletonList("§7Typ: §e" + filter.getType().name()), true, schemTypeCallback);
|
||||
inv.setItem(2, SWItem.getMaterial("STONE_BUTTON"), Core.MESSAGE.parse("SCHEM_SELECTOR_FILTER_TYPE", player), Collections.singletonList(Core.MESSAGE.parse("SCHEM_SELECTOR_FILTER_TYPE_SEARCH", player, filter.getType().name())), true, schemTypeCallback);
|
||||
}
|
||||
}
|
||||
|
||||
@ -298,16 +274,16 @@ public class SchematicSelector {
|
||||
final int iSlot = target.target== SelectorTarget.Target.SCHEMATIC_TYPE?2:3;
|
||||
|
||||
if(filter.getItem() == null) {
|
||||
inv.setItem(iSlot, Material.STONE, "§7Nach Item Filtern...", materialCallback);
|
||||
inv.setItem(iSlot, Material.STONE, Core.MESSAGE.parse("SCHEM_SELECTOR_FILTER_MAT", player), materialCallback);
|
||||
} else {
|
||||
inv.setItem(iSlot, filter.getItem(), "§7Nach Item Filtern...", Collections.singletonList("§7Item: §e" + filter.getItem().name()), true, materialCallback);
|
||||
inv.setItem(iSlot, filter.getItem(), Core.MESSAGE.parse("SCHEM_SELECTOR_FILTER_MAT", player), Collections.singletonList(Core.MESSAGE.parse("SCHEM_SELECTOR_FILTER_MAT_SEARCH", player, filter.getItem().name())), true, materialCallback);
|
||||
}
|
||||
|
||||
inv.setItem(7, SWItem.getDye(1), "§eAbbrechen", clickType -> {
|
||||
inv.setItem(7, SWItem.getDye(1), Core.MESSAGE.parse("SCHEM_SELECTOR_CANCEL", player), clickType -> {
|
||||
filter.reset();
|
||||
openList(null, publics);
|
||||
});
|
||||
inv.setItem(8, SWItem.getDye(10), "§eSuchen...", clickType -> {
|
||||
inv.setItem(8, SWItem.getDye(10), Core.MESSAGE.parse("SCHEM_SELECTOR_GO", player), clickType -> {
|
||||
filter.setFilter(true);
|
||||
if(useHooks) {
|
||||
injectable.onFilterApply(this);
|
||||
@ -322,6 +298,51 @@ public class SchematicSelector {
|
||||
inv.open();
|
||||
}
|
||||
|
||||
private List<SchematicNode> getFilteredSchematics(boolean publics) {
|
||||
List<SchematicNode> nodes = new ArrayList<>(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()));
|
||||
}
|
||||
return nodes;
|
||||
}
|
||||
|
||||
private List<SchematicNode> getSchematicList(boolean publics, SchematicNode parent) {
|
||||
List<SchematicNode> nodes = new ArrayList<>();
|
||||
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()));
|
||||
if(target.rank >= 0) {
|
||||
nodes.removeIf(node -> node.getRank() > target.rank);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
nodes.addAll(SchematicNode.getSchematicsAccessibleByUser(publics?0:user.getId(), parent == null?0:parent.getId()));
|
||||
}
|
||||
|
||||
if(singleDirOpen && nodes.size() == 1 && nodes.get(0).isDir()) {
|
||||
openList(nodes.get(0), publics);
|
||||
sdoTrigger = true;
|
||||
}
|
||||
return nodes;
|
||||
}
|
||||
|
||||
private static SchematicNode getParent(SchematicNode node) {
|
||||
if(node.getParent() == null) {
|
||||
return null;
|
||||
@ -363,15 +384,19 @@ public class SchematicSelector {
|
||||
|
||||
@AllArgsConstructor
|
||||
private enum Target {
|
||||
SCHEMATIC("Schematic", false),
|
||||
DIRECTORY("Ordner", true),
|
||||
SCHEMATIC_NODE("Schematic/Ordner", true),
|
||||
SCHEMATIC_TYPE("Schematic", false);
|
||||
SCHEMATIC("SCHEM_SELECTOR_SCHEMATIC", false),
|
||||
DIRECTORY("SCHEM_SELECTOR_DIRECTORY", true),
|
||||
SCHEMATIC_NODE("SCHEM_SELECTOR_SCHEMATIC_NODE", true),
|
||||
SCHEMATIC_TYPE("SCHEM_SELECTOR_SCHEMATIC", false);
|
||||
|
||||
@Getter
|
||||
private String name;
|
||||
private String rawName;
|
||||
@Getter
|
||||
private boolean dirs;
|
||||
|
||||
public String getName(Player player) {
|
||||
return Core.MESSAGE.parse(rawName, player);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -25,15 +25,15 @@ import de.steamwar.sql.SchematicNode;
|
||||
|
||||
public interface SchematicSelectorInjectable {
|
||||
|
||||
void onSelectorCreate(SchematicSelector selector);
|
||||
default void onSelectorCreate(SchematicSelector selector) {}
|
||||
|
||||
void onListRender(SchematicSelector selector, SWListInv<SchematicNode> inv, SchematicNode parent);
|
||||
default void onListRender(SchematicSelector selector, SWListInv<SchematicNode> inv, SchematicNode parent) {}
|
||||
|
||||
void onFilterRender(SchematicSelector selector, SWInventory inventory);
|
||||
default void onFilterRender(SchematicSelector selector, SWInventory inventory) {}
|
||||
|
||||
void onFilterApply(SchematicSelector selector);
|
||||
default void onFilterApply(SchematicSelector selector) {}
|
||||
|
||||
boolean onFolderCreate(SchematicSelector selector, String name);
|
||||
default boolean onFolderCreate(SchematicSelector selector, String name) {return true;}
|
||||
|
||||
void onNodeFilter(SchematicSelector selector, SchematicNode node);
|
||||
default void onNodeFilter(SchematicSelector selector, SchematicNode node) {}
|
||||
}
|
||||
|
@ -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.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) {}
|
||||
}
|
@ -19,6 +19,7 @@
|
||||
|
||||
package de.steamwar.util;
|
||||
|
||||
import de.steamwar.core.Core;
|
||||
import de.steamwar.inventory.SWItem;
|
||||
import de.steamwar.inventory.SWListInv;
|
||||
import lombok.experimental.UtilityClass;
|
||||
@ -33,7 +34,7 @@ import java.util.function.Consumer;
|
||||
public class UtilGui {
|
||||
|
||||
public static void openMaterialSelector(Player player, Consumer<Material> callback) {
|
||||
openMaterialSelector(player, "Material auswählen", callback);
|
||||
openMaterialSelector(player, Core.MESSAGE.parse("MATERIAL_SELECTOR_TITLE", player), callback);
|
||||
}
|
||||
|
||||
public static void openMaterialSelector(Player player, String title, Consumer<Material> callback) {
|
||||
|
In neuem Issue referenzieren
Einen Benutzer sperren