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.ChunkListener;
|
||||||
import de.steamwar.core.events.PlayerJoinedEvent;
|
import de.steamwar.core.events.PlayerJoinedEvent;
|
||||||
import de.steamwar.core.events.WorldLoadEvent;
|
import de.steamwar.core.events.WorldLoadEvent;
|
||||||
|
import de.steamwar.message.Message;
|
||||||
import de.steamwar.sql.SQL;
|
import de.steamwar.sql.SQL;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
@ -39,6 +40,7 @@ public class Core extends JavaPlugin{
|
|||||||
|
|
||||||
private static Core instance;
|
private static Core instance;
|
||||||
private static final int version;
|
private static final int version;
|
||||||
|
public static Message MESSAGE;
|
||||||
|
|
||||||
static{
|
static{
|
||||||
String packageName = Bukkit.getServer().getClass().getPackage().getName();
|
String packageName = Bukkit.getServer().getClass().getPackage().getName();
|
||||||
@ -79,6 +81,8 @@ public class Core extends JavaPlugin{
|
|||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
throw new SecurityException("Could not load Hostname", e);
|
throw new SecurityException("Could not load Hostname", e);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
MESSAGE = new Message("SpigotCore", getClassLoader());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -19,10 +19,12 @@
|
|||||||
|
|
||||||
package de.steamwar.util;
|
package de.steamwar.util;
|
||||||
|
|
||||||
|
import de.steamwar.core.Core;
|
||||||
import de.steamwar.inventory.*;
|
import de.steamwar.inventory.*;
|
||||||
import de.steamwar.sql.SchematicNode;
|
import de.steamwar.sql.SchematicNode;
|
||||||
import de.steamwar.sql.SchematicType;
|
import de.steamwar.sql.SchematicType;
|
||||||
import de.steamwar.sql.SteamwarUser;
|
import de.steamwar.sql.SteamwarUser;
|
||||||
|
import jdk.nashorn.internal.runtime.doubleconv.CachedPowers;
|
||||||
import lombok.*;
|
import lombok.*;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
@ -33,9 +35,12 @@ import java.util.Arrays;
|
|||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
|
import java.util.function.Function;
|
||||||
|
|
||||||
public class SchematicSelector {
|
public class SchematicSelector {
|
||||||
|
|
||||||
|
public static final String DEFAULT_TITLE = "SCHEM_SELECTOR_TITLE";
|
||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
private final Player player;
|
private final Player player;
|
||||||
@Getter
|
@Getter
|
||||||
@ -53,10 +58,11 @@ public class SchematicSelector {
|
|||||||
private PublicMode publicMode = PublicMode.ALL;
|
private PublicMode publicMode = PublicMode.ALL;
|
||||||
@Setter
|
@Setter
|
||||||
@Getter
|
@Getter
|
||||||
private String title = "{0} auswahl: {1}";
|
private boolean singleDirOpen;
|
||||||
@Setter
|
@Setter
|
||||||
@Getter
|
@Getter
|
||||||
private boolean singleDirOpen;
|
private Function<Player, String> title;
|
||||||
|
private boolean sdoTrigger = false;
|
||||||
|
|
||||||
public SchematicSelector(Player player, SelectorTarget target, Consumer<SchematicNode> callback) {
|
public SchematicSelector(Player player, SelectorTarget target, Consumer<SchematicNode> callback) {
|
||||||
this.player = player;
|
this.player = player;
|
||||||
@ -80,10 +86,220 @@ public class SchematicSelector {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void openList(SchematicNode parent, boolean publics) {
|
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()) {
|
if(sdoTrigger) {
|
||||||
nodes.addAll(SchematicNode.getAllSchematicsAccessibleByUser(publics?0:user.getId()));
|
sdoTrigger = false;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
List<SWListInv.SWListEntry<SchematicNode>> list = new ArrayList<>();
|
||||||
|
|
||||||
|
if(parent != 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;
|
||||||
|
list.add(renderItem(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, Core.MESSAGE.parse("SCHEM_SELECTOR_OWN", player), clickType -> openList(null, false));
|
||||||
|
} else {
|
||||||
|
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), Core.MESSAGE.parse("SCHEM_SELECTOR_SEL_DIR", player), clickType -> {
|
||||||
|
player.closeInventory();
|
||||||
|
callback.accept(parent);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
if(!publics) {
|
||||||
|
inv.setItem(50, Material.CHEST, Core.MESSAGE.parse("SCHEM_SELECTOR_NEW_DIR", player), clickType -> createFolderIn(parent));
|
||||||
|
}
|
||||||
|
inv.setItem(51, Material.NAME_TAG, Core.MESSAGE.parse("SCHEM_SELECTOR_FILTER", player), clickType -> openFilter(publics));
|
||||||
|
|
||||||
|
if(useHooks) {
|
||||||
|
injectable.onListRender(this, inv, parent);
|
||||||
|
}
|
||||||
|
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, Core.MESSAGE.parse("SCHEM_SELECTOR_CREATE_DIR_TITLE", player));
|
||||||
|
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, Core.MESSAGE.parse("SCHEM_SELECTOR_FILTER_TITLE", player));
|
||||||
|
InvCallback nameCallback = clickType -> {
|
||||||
|
if(clickType.isRightClick()) {
|
||||||
|
filter.setName("");
|
||||||
|
openFilter(publics);
|
||||||
|
} else {
|
||||||
|
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);
|
||||||
|
openFilter(publics);
|
||||||
|
});
|
||||||
|
swAnvilInv.open();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
if(filter.getName().isEmpty()) {
|
||||||
|
inv.setItem(0, Material.NAME_TAG, Core.MESSAGE.parse("SCHEM_SELECTOR_FILTER_NAME", player), nameCallback);
|
||||||
|
} else {
|
||||||
|
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 -> {
|
||||||
|
if(clickType.isRightClick()) {
|
||||||
|
filter.setOwner(null);
|
||||||
|
openFilter(publics);
|
||||||
|
} else {
|
||||||
|
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());
|
||||||
|
openFilter(publics);
|
||||||
|
});
|
||||||
|
swAnvilInv.open();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
if(filter.getOwner() == null) {
|
||||||
|
inv.setItem(1, Material.PLAYER_HEAD, Core.MESSAGE.parse("SCHEM_SELECTOR_FILTER_OWNER", player), ownerCallback);
|
||||||
|
} else {
|
||||||
|
SteamwarUser tUser = SteamwarUser.get(filter.getOwner());
|
||||||
|
SWItem item = SWItem.getPlayerSkull(user.getUserName());
|
||||||
|
item.setName(Core.MESSAGE.parse("SCHEM_SELECTOR_FILTER_OWNER", player));
|
||||||
|
item.setEnchanted(true);
|
||||||
|
item.setLore(Collections.singletonList(Core.MESSAGE.parse("SCHEM_SELECTOR_FILTER_OWNER_SEARCH", player, tUser.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, Core.MESSAGE.parse("SCHEM_SELECTOR_FILTER_SEL_TYPE", player), types, (clickType1, schematicType) -> {
|
||||||
|
filter.setType(schematicType);
|
||||||
|
openFilter(publics);
|
||||||
|
});
|
||||||
|
listInv.open();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
if(filter.getType() == null) {
|
||||||
|
inv.setItem(2, SWItem.getMaterial("STONE_BUTTON"), Core.MESSAGE.parse("SCHEM_SELECTOR_FILTER_TYPE", player), schemTypeCallback);
|
||||||
|
} else {
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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, Core.MESSAGE.parse("SCHEM_SELECTOR_FILTER_MAT", player), materialCallback);
|
||||||
|
} else {
|
||||||
|
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), Core.MESSAGE.parse("SCHEM_SELECTOR_CANCEL", player), clickType -> {
|
||||||
|
filter.reset();
|
||||||
|
openList(null, publics);
|
||||||
|
});
|
||||||
|
inv.setItem(8, SWItem.getDye(10), Core.MESSAGE.parse("SCHEM_SELECTOR_GO", player), clickType -> {
|
||||||
|
filter.setFilter(true);
|
||||||
|
if(useHooks) {
|
||||||
|
injectable.onFilterApply(this);
|
||||||
|
}
|
||||||
|
openList(null, publics);
|
||||||
|
});
|
||||||
|
|
||||||
|
if(useHooks) {
|
||||||
|
injectable.onFilterRender(this, inv);
|
||||||
|
}
|
||||||
|
|
||||||
|
inv.open();
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<SchematicNode> getFilteredSchematics(boolean publics) {
|
||||||
|
List<SchematicNode> nodes = new ArrayList<>(SchematicNode.getAllSchematicsAccessibleByUser(publics ? 0 : user.getId()));
|
||||||
nodes.removeIf(node -> {
|
nodes.removeIf(node -> {
|
||||||
if(useHooks) {
|
if(useHooks) {
|
||||||
injectable.onNodeFilter(this, node);
|
injectable.onNodeFilter(this, node);
|
||||||
@ -96,7 +312,11 @@ public class SchematicSelector {
|
|||||||
if(target.target == SelectorTarget.Target.SCHEMATIC_TYPE) {
|
if(target.target == SelectorTarget.Target.SCHEMATIC_TYPE) {
|
||||||
nodes.removeIf(node -> node.isDir() || !node.getType().equals(target.type.toDB()));
|
nodes.removeIf(node -> node.isDir() || !node.getType().equals(target.type.toDB()));
|
||||||
}
|
}
|
||||||
} else {
|
return nodes;
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<SchematicNode> getSchematicList(boolean publics, SchematicNode parent) {
|
||||||
|
List<SchematicNode> nodes = new ArrayList<>();
|
||||||
switch (target.target) {
|
switch (target.target) {
|
||||||
case DIRECTORY:
|
case DIRECTORY:
|
||||||
if(parent == null) {
|
if(parent == null) {
|
||||||
@ -118,208 +338,9 @@ public class SchematicSelector {
|
|||||||
|
|
||||||
if(singleDirOpen && nodes.size() == 1 && nodes.get(0).isDir()) {
|
if(singleDirOpen && nodes.size() == 1 && nodes.get(0).isDir()) {
|
||||||
openList(nodes.get(0), publics);
|
openList(nodes.get(0), publics);
|
||||||
return;
|
sdoTrigger = true;
|
||||||
}
|
}
|
||||||
}
|
return nodes;
|
||||||
|
|
||||||
List<SWListInv.SWListEntry<SchematicNode>> list = new ArrayList<>();
|
|
||||||
|
|
||||||
if(parent != null) {
|
|
||||||
list.add(new SWListInv.SWListEntry<>(new SWItem(Material.ARROW, "§eZurück", 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));
|
|
||||||
}
|
|
||||||
|
|
||||||
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);
|
|
||||||
});
|
|
||||||
if(publicMode == PublicMode.ALL) {
|
|
||||||
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) {
|
private static SchematicNode getParent(SchematicNode node) {
|
||||||
@ -363,15 +384,19 @@ public class SchematicSelector {
|
|||||||
|
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
private enum Target {
|
private enum Target {
|
||||||
SCHEMATIC("Schematic", false),
|
SCHEMATIC("SCHEM_SELECTOR_SCHEMATIC", false),
|
||||||
DIRECTORY("Ordner", true),
|
DIRECTORY("SCHEM_SELECTOR_DIRECTORY", true),
|
||||||
SCHEMATIC_NODE("Schematic/Ordner", true),
|
SCHEMATIC_NODE("SCHEM_SELECTOR_SCHEMATIC_NODE", true),
|
||||||
SCHEMATIC_TYPE("Schematic", false);
|
SCHEMATIC_TYPE("SCHEM_SELECTOR_SCHEMATIC", false);
|
||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
private String name;
|
private String rawName;
|
||||||
@Getter
|
@Getter
|
||||||
private boolean dirs;
|
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 {
|
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;
|
package de.steamwar.util;
|
||||||
|
|
||||||
|
import de.steamwar.core.Core;
|
||||||
import de.steamwar.inventory.SWItem;
|
import de.steamwar.inventory.SWItem;
|
||||||
import de.steamwar.inventory.SWListInv;
|
import de.steamwar.inventory.SWListInv;
|
||||||
import lombok.experimental.UtilityClass;
|
import lombok.experimental.UtilityClass;
|
||||||
@ -33,7 +34,7 @@ import java.util.function.Consumer;
|
|||||||
public class UtilGui {
|
public class UtilGui {
|
||||||
|
|
||||||
public static void openMaterialSelector(Player player, Consumer<Material> callback) {
|
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) {
|
public static void openMaterialSelector(Player player, String title, Consumer<Material> callback) {
|
||||||
|
In neuem Issue referenzieren
Einen Benutzer sperren