SteamWar/SpigotCore
Archiviert
13
0

Last Filters in SchematicSelector
Alle Prüfungen waren erfolgreich
SteamWarCI Build successful

Dieser Commit ist enthalten in:
Chaoscaot 2023-10-23 19:17:53 +02:00
Ursprung 97461b198d
Commit 5558d9ccf7
3 geänderte Dateien mit 123 neuen und 42 gelöschten Zeilen

Datei anzeigen

@ -69,6 +69,11 @@ SCHEM_SELECTOR_SCHEMATIC=Schematic
SCHEM_SELECTOR_DIRECTORY=Directory
SCHEM_SELECTOR_SCHEMATIC_NODE=Schematic/Directory
SCHEM_SELECTOR_FILTER_TITLE_SINGLE=§eSingle Filter
SCHEM_SELECTOR_FILTER_TITLE_MULTI=§e{0} Filters
SCHEM_SELECTOR_FILTER_TITLE_EMPTY=§eNo Filters
SCHEM_SELECTOR_FILTER_EMPTY=§7Empty
MATERIAL_SELECTOR_TITLE=Select material
BAN_TEAM={0} §e{1} §7was §e§lbanned§7 by §e{2} {3}§8: §f{4}

Datei anzeigen

@ -64,6 +64,11 @@ SCHEM_SELECTOR_SCHEMATIC=Schematic
SCHEM_SELECTOR_DIRECTORY=Ordner
SCHEM_SELECTOR_SCHEMATIC_NODE=Schematic/Ordner
SCHEM_SELECTOR_FILTER_TITLE_SINGLE=§eEinzelfilter
SCHEM_SELECTOR_FILTER_TITLE_MULTI=§e{0} §e§lMehrfachfilter
SCHEM_SELECTOR_FILTER_TITLE_EMPTY=§eKeine Filter
SCHEM_SELECTOR_FILTER_EMPTY=§7Leer
MATERIAL_SELECTOR_TITLE=Material auswählen
BAN_TEAM={0} §e{1} §7wurde von §e{2} {3} §e§lgebannt§8: §f{4}

Datei anzeigen

@ -34,6 +34,7 @@ import java.util.function.Consumer;
public class SchematicSelector {
private static final Sorting[] all_sortings = Sorting.values();
private static final Map<Player, SelectorFilter[]> filterCache = new HashMap<>();
@Getter
private final Player player;
@ -44,7 +45,7 @@ public class SchematicSelector {
private Consumer<SchematicNode> callback;
private final SelectorTarget target;
@Getter
private final SelectorFilter filter = new SelectorFilter();
private SelectorFilter filter;
private SchematicSelectorInjectable injectable = SchematicSelectorInjectable.DEFAULT;
@Setter
@Getter
@ -96,7 +97,7 @@ public class SchematicSelector {
private void openList(SchematicNode parent) {
lastParent = parent;
List<SchematicNode> nodes = applySorting(filter.isFilter()?getFilteredSchematics():getSchematicList(parent));
List<SchematicNode> nodes = applySorting(filter != null?getFilteredSchematics():getSchematicList(parent));
if(sdoTrigger) {
sdoTrigger = false;
@ -115,7 +116,7 @@ public class SchematicSelector {
list.add(renderItem(node));
}
SWListInv<SchematicNode> inv = new SWListInv<>(player, MessageFormat.format(injectable.createTitle(player), target.target.getName(player), filter.getName() == null?(parent == null?"/":parent.generateBreadcrumbs()):filter.getName()), false, list, (clickType, node) -> handleClick(node, parent));
SWListInv<SchematicNode> inv = new SWListInv<>(player, MessageFormat.format(injectable.createTitle(player), target.target.getName(player), (filter == null || filter.getName() == null)?(parent == null?"/":parent.generateBreadcrumbs()):filter.getName()), false, list, (clickType, node) -> handleClick(node, parent));
if(publicMode == PublicMode.ALL) {
if(user.getId() == 0) {
inv.setItem(48, Material.BUCKET, Core.MESSAGE.parse("SCHEM_SELECTOR_OWN", player), clickType -> {
@ -188,12 +189,12 @@ public class SchematicSelector {
return;
}
if(node.isDir()) {
if(filter.isFilter() && target.target.dirs) {
if(filter != null && target.target.dirs) {
player.closeInventory();
callback.accept(node);
return;
}
filter.reset();
filter = null;
depth++;
openList(node);
return;
@ -227,9 +228,9 @@ public class SchematicSelector {
private SWListInv.SWListEntry<SchematicNode> renderItem(SchematicNode node) {
Material m = SWItem.getMaterial(node.getItem());
String name = Core.MESSAGE.parse(filter.name == null?"SCHEM_SELECTOR_ITEM_NAME":"SCHEM_SELECTOR_ITEM_NAME_FILTER", player, node.getName());
String name = Core.MESSAGE.parse((filter != null && filter.name == null)?"SCHEM_SELECTOR_ITEM_NAME":"SCHEM_SELECTOR_ITEM_NAME_FILTER", player, node.getName());
if(filter.getName() != null) {
if(filter != null && filter.getName() != null) {
name = name.replace(filter.getName(), Core.MESSAGE.parse("SCHEM_SELECTOR_ITEM_REPLACE", player, filter.getName()));
}
@ -273,16 +274,20 @@ public class SchematicSelector {
}
private void openFilter() {
SWInventory inv = new SWInventory(player, 9, Core.MESSAGE.parse("SCHEM_SELECTOR_FILTER_TITLE", player));
if (filter == null) {
filter = new SelectorFilter(null, null, null, null);
}
SWInventory inv = new SWInventory(player, 9 * 2, Core.MESSAGE.parse("SCHEM_SELECTOR_FILTER_TITLE", player));
InvCallback nameCallback = clickType -> {
if(clickType.isRightClick()) {
filter.setName(null);
filter = filter.withName(null);
openFilter();
} else {
SWAnvilInv swAnvilInv = new SWAnvilInv(player, Core.MESSAGE.parse("SCHEM_SELECTOR_FILTER_ENTER_NAME", player));
swAnvilInv.setItem(Material.NAME_TAG, Collections.singletonList(Core.MESSAGE.parse("SCHEM_SELECTOR_CLICK_BACK", player)), false);
swAnvilInv.setCallback(s -> {
filter.setName(s);
filter = filter.withName(s);
openFilter();
});
addLeftCloseAction(swAnvilInv, this::openFilter);
@ -297,14 +302,14 @@ public class SchematicSelector {
InvCallback ownerCallback = clickType -> {
if(clickType.isRightClick()) {
filter.setOwner(null);
filter = filter.withOwner(null);
openFilter();
} else {
SWAnvilInv swAnvilInv = new SWAnvilInv(player, Core.MESSAGE.parse("SCHEM_SELECTOR_FILTER_ENTER_OWNER", player));
swAnvilInv.setItem(SWItem.getMaterial("SKULL_ITEM"), (byte) 3, Collections.singletonList(Core.MESSAGE.parse("SCHEM_SELECTOR_CLICK_BACK", player)), false);
swAnvilInv.setCallback(s -> {
if(SteamwarUser.get(s) != null) {
filter.setOwner(SteamwarUser.get(s).getId());
filter = filter.withOwner(SteamwarUser.get(s).getId());
}
openFilter();
});
@ -327,15 +332,13 @@ public class SchematicSelector {
if(target.target != Target.SCHEMATIC_TYPE) {
InvCallback schemTypeCallback = clickType -> {
if(clickType.isRightClick()) {
filter.setType(null);
filter = filter.withType(null);
openFilter();
} else {
List<SWListInv.SWListEntry<SchematicType>> types = new ArrayList<>();
SchematicType.values().forEach(schematicType -> {
types.add(new SWListInv.SWListEntry<>(new SWItem(SWItem.getMaterial(schematicType.getMaterial()), "§e" + schematicType.name(), Collections.emptyList(), schematicType.fightType(), n -> {}), schematicType));
});
SchematicType.values().forEach(schematicType -> types.add(new SWListInv.SWListEntry<>(new SWItem(SWItem.getMaterial(schematicType.getMaterial()), "§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);
filter = filter.withType(schematicType);
openFilter();
});
listInv.open();
@ -351,11 +354,11 @@ public class SchematicSelector {
InvCallback materialCallback = clickType -> {
if(clickType.isRightClick()) {
filter.setItem(null);
filter = filter.withItem(null);
openFilter();
} else {
UtilGui.openMaterialSelector(player, material -> {
filter.setItem(material);
filter = filter.withItem(material);
openFilter();
});
}
@ -369,13 +372,49 @@ public class SchematicSelector {
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);
}
if (!filterCache.containsKey(player)) {
filterCache.put(player, new SelectorFilter[9]);
}
SelectorFilter[] filters = filterCache.get(player);
for (int i = 0; i < filters.length; i++) {
SelectorFilter filterCached = filters[i];
if (filterCached == null) {
inv.setItem(i + 9, new SWItem(Material.BARRIER, "SCHEM_SELECTOR_FILTER_EMPTY", click -> {}));
} else {
SWItem item = filterCached.toItemStack(player);
item.setEnchanted(filterCached.equals(filter));
inv.setItem(i + 9, item.getItemStack(), click -> {
filter = filterCached;
openFilter();
});
}
}
inv.setItem(7, SWItem.getDye(1), Core.MESSAGE.parse("SCHEM_SELECTOR_CANCEL", player), clickType -> {
filter.reset();
filter = null;
depth = 0;
openList(null);
});
inv.setItem(8, SWItem.getDye(10), Core.MESSAGE.parse("SCHEM_SELECTOR_GO", player), clickType -> {
filter.setFilter(true);
if (!filter.equals(filters[0])) {
for (int i = filters.length - 1; i > 0; i--) {
filters[i] = filters[i-1];
if (filter.equals(filters[i])) {
filters[i] = null;
for (int j = i; j < filters.length - 1; j++) {
filters[j] = filters[j+1];
}
filters[filters.length - 1] = null;
}
}
filters[0] = filter;
filterCache.put(player, filters);
}
injectable.onFilterApply(this);
depth = 0;
openList(null);
@ -454,7 +493,7 @@ public class SchematicSelector {
}
@AllArgsConstructor
static class SelectorTarget {
public static class SelectorTarget {
private final Target target;
private final SchematicType type;
@ -476,31 +515,19 @@ public class SchematicSelector {
}
}
@NoArgsConstructor
@Getter
@Setter
@AllArgsConstructor
@With
@EqualsAndHashCode
public static class SelectorFilter {
private boolean filter;
private String name = null;
private Integer owner = null;
private SchematicType type = null;
private Material item = null;
public void reset() {
name = null;
owner = null;
type = null;
item = null;
filter = false;
}
private final String name;
private final Integer owner;
private final SchematicType type;
private final Material item;
public boolean matches(SchematicNode node) {
boolean matches = true;
if(name != null && !node.getName().contains(name)) {
matches = false;
}
boolean matches = name == null || node.getName().contains(name);
if(owner != null && node.getOwner() != owner) {
matches = false;
@ -523,6 +550,50 @@ public class SchematicSelector {
}
return matches;
}
public long getCount() {
return Arrays.stream(new Object[]{name, owner, type, item}).filter(Objects::nonNull).count();
}
public List<String> getItemLore(Player player) {
List<String> lore = new ArrayList<>(4);
if(name != null) {
lore.add(Core.MESSAGE.parse("SCHEM_SELECTOR_FILTER_NAME_SEARCH", player, name));
}
if(owner != null) {
lore.add(Core.MESSAGE.parse("SCHEM_SELECTOR_FILTER_OWNER_SEARCH", player, SteamwarUser.get(owner).getUserName()));
}
if(type != null) {
lore.add(Core.MESSAGE.parse("SCHEM_SELECTOR_FILTER_TYPE_SEARCH", player, type.name()));
}
if(item != null) {
lore.add(Core.MESSAGE.parse("SCHEM_SELECTOR_FILTER_MAT_SEARCH", player, item.name()));
}
return lore;
}
public SWItem toItemStack(Player player) {
long count = getCount();
String itemName = count != 1 ? Core.MESSAGE.parse("SCHEM_SELECTOR_FILTER_TITLE_MULTI", player, count) : Core.MESSAGE.parse("SCHEM_SELECTOR_FILTER_TITLE_SINGLE", player);
List<String> lore = getItemLore(player);
if (name != null) {
return new SWItem(Material.NAME_TAG, itemName, lore, false, click -> {});
} else if (owner != null) {
SWItem playerSkull = SWItem.getPlayerSkull(SteamwarUser.get(owner).getUserName());
playerSkull.setName(itemName);
playerSkull.setLore(lore);
return playerSkull;
} else if (type != null) {
return new SWItem(SWItem.getMaterial(type.getMaterial()), itemName, lore, false, n -> {});
} else if (item != null) {
return new SWItem(item, itemName, lore, false, click -> {});
} else {
return new SWItem(Material.BARRIER, Core.MESSAGE.parse("SCHEM_SELECTOR_FILTER_TITLE_EMPTY", player), Collections.emptyList(), false, click -> {});
}
}
}
public enum PublicMode {