# Conflicts: # SpigotCore_Main/src/de/steamwar/inventory/SchematicSelector.java
Dieser Commit ist enthalten in:
Commit
4ab9e8298a
@ -26,6 +26,14 @@ SCHEM_SELECTOR_PUB=
|
|||||||
SCHEM_SELECTOR_SEL_DIR=§7Ordner auswählen
|
SCHEM_SELECTOR_SEL_DIR=§7Ordner auswählen
|
||||||
SCHEM_SELECTOR_NEW_DIR=§7Neuer Ordner
|
SCHEM_SELECTOR_NEW_DIR=§7Neuer Ordner
|
||||||
SCHEM_SELECTOR_FILTER=§7Filter
|
SCHEM_SELECTOR_FILTER=§7Filter
|
||||||
|
SCHEM_SELECTOR_SORTING=§7Sortierung
|
||||||
|
SCHEM_SELECTOR_SORTING_CURRENT=§7Aktuell: §e{0}
|
||||||
|
SCHEM_SELECTOR_SORTING_NAME=Name
|
||||||
|
SCHEM_SELECTOR_SORTING_TYPE=Schematic-Typ
|
||||||
|
SCHEM_SELECTOR_SORTING_UPDATE=Letztes Update
|
||||||
|
SCHEM_SELECTOR_SORTING_DIRECTION=§7Richtung: §e{0}
|
||||||
|
SCHEM_SELECTOR_SORTING_ASC=Aufsteigend
|
||||||
|
SCHEM_SELECTOR_SORTING_DSC=Absteigend
|
||||||
|
|
||||||
SCHEM_SELECTOR_ITEM_NAME=§e{0}
|
SCHEM_SELECTOR_ITEM_NAME=§e{0}
|
||||||
SCHEM_SELECTOR_ITEM_NAME_FILTER=§7{0}
|
SCHEM_SELECTOR_ITEM_NAME_FILTER=§7{0}
|
||||||
|
@ -332,6 +332,6 @@ public abstract class SWCommand {
|
|||||||
@Retention(RetentionPolicy.RUNTIME)
|
@Retention(RetentionPolicy.RUNTIME)
|
||||||
@Target({ElementType.PARAMETER})
|
@Target({ElementType.PARAMETER})
|
||||||
protected @interface StaticValue {
|
protected @interface StaticValue {
|
||||||
String value();
|
String[] value() default {};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -163,8 +163,9 @@ public class SWCommandUtils {
|
|||||||
GUARD_FUNCTIONS.putIfAbsent(name, guardChecker);
|
GUARD_FUNCTIONS.putIfAbsent(name, guardChecker);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static TypeMapper<String> createMapper(String value) {
|
public static TypeMapper<String> createMapper(String... values) {
|
||||||
return createMapper((s) -> value.equals(s) ? value : null, s -> Collections.singletonList(value));
|
List<String> strings = Arrays.asList(values);
|
||||||
|
return createMapper((s) -> strings.contains(s) ? s : null, s -> strings);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static <T> TypeMapper<T> createMapper(Function<String, T> mapper, Function<String, List<String>> tabCompleter) {
|
public static <T> TypeMapper<T> createMapper(Function<String, T> mapper, Function<String, List<String>> tabCompleter) {
|
||||||
|
@ -45,7 +45,7 @@ class SubCommand {
|
|||||||
GuardChecker guardChecker;
|
GuardChecker guardChecker;
|
||||||
Class<?> varArgType = null;
|
Class<?> varArgType = null;
|
||||||
private boolean help;
|
private boolean help;
|
||||||
boolean noTabComplete = false;
|
boolean noTabComplete;
|
||||||
|
|
||||||
SubCommand(SWCommand swCommand, Method method, String[] subCommand, Map<String, TypeMapper<?>> localTypeMapper, Map<String, GuardChecker> localGuardChecker, boolean help, String[] description, boolean noTabComplete) {
|
SubCommand(SWCommand swCommand, Method method, String[] subCommand, Map<String, TypeMapper<?>> localTypeMapper, Map<String, GuardChecker> localGuardChecker, boolean help, String[] description, boolean noTabComplete) {
|
||||||
this.swCommand = swCommand;
|
this.swCommand = swCommand;
|
||||||
@ -71,7 +71,8 @@ class SubCommand {
|
|||||||
}
|
}
|
||||||
|
|
||||||
SWCommand.Mapper mapper = parameter.getAnnotation(SWCommand.Mapper.class);
|
SWCommand.Mapper mapper = parameter.getAnnotation(SWCommand.Mapper.class);
|
||||||
if (clazz.isEnum() && mapper == null && !MAPPER_FUNCTIONS.containsKey(clazz.getTypeName()) && !localTypeMapper.containsKey(clazz.getTypeName())) {
|
SWCommand.ClassMapper classMapper = parameter.getAnnotation(SWCommand.ClassMapper.class);
|
||||||
|
if (clazz.isEnum() && mapper == null && classMapper == null && !MAPPER_FUNCTIONS.containsKey(clazz.getTypeName()) && !localTypeMapper.containsKey(clazz.getTypeName())) {
|
||||||
Class<Enum<?>> enumClass = (Class<Enum<?>>) clazz;
|
Class<Enum<?>> enumClass = (Class<Enum<?>>) clazz;
|
||||||
List<String> tabCompletes = new ArrayList<>();
|
List<String> tabCompletes = new ArrayList<>();
|
||||||
for (Enum<?> enumConstant : enumClass.getEnumConstants()) {
|
for (Enum<?> enumConstant : enumClass.getEnumConstants()) {
|
||||||
@ -82,7 +83,9 @@ class SubCommand {
|
|||||||
}
|
}
|
||||||
|
|
||||||
String name = clazz.getTypeName();
|
String name = clazz.getTypeName();
|
||||||
if (mapper != null) {
|
if (classMapper != null) {
|
||||||
|
name = classMapper.value().getTypeName();
|
||||||
|
} else if (mapper != null) {
|
||||||
name = mapper.value();
|
name = mapper.value();
|
||||||
} else {
|
} else {
|
||||||
SWCommand.StaticValue staticValue = parameter.getAnnotation(SWCommand.StaticValue.class);
|
SWCommand.StaticValue staticValue = parameter.getAnnotation(SWCommand.StaticValue.class);
|
||||||
@ -100,6 +103,21 @@ class SubCommand {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private GuardChecker getGuardChecker(Parameter parameter, Map<String, GuardChecker> localGuardChecker) {
|
private GuardChecker getGuardChecker(Parameter parameter, Map<String, GuardChecker> localGuardChecker) {
|
||||||
|
SWCommand.ClassGuard classGuard = parameter.getAnnotation(SWCommand.ClassGuard.class);
|
||||||
|
if (classGuard != null) {
|
||||||
|
if (classGuard.value() == null) {
|
||||||
|
String s = parameter.getType().getTypeName();
|
||||||
|
if (parameter.isVarArgs()) {
|
||||||
|
s = parameter.getType().getComponentType().getTypeName();
|
||||||
|
}
|
||||||
|
return localGuardChecker.getOrDefault(s, GUARD_FUNCTIONS.getOrDefault(s, null));
|
||||||
|
}
|
||||||
|
GuardChecker current = localGuardChecker.getOrDefault(classGuard.value().getTypeName(), GUARD_FUNCTIONS.getOrDefault(classGuard.value().getTypeName(), null));
|
||||||
|
if (current == null) {
|
||||||
|
Bukkit.getLogger().log(Level.WARNING, () -> "The guard checker with name '" + classGuard.value().getTypeName() + "' is neither a local guard checker nor a global one");
|
||||||
|
}
|
||||||
|
return current;
|
||||||
|
}
|
||||||
SWCommand.Guard guard = parameter.getAnnotation(SWCommand.Guard.class);
|
SWCommand.Guard guard = parameter.getAnnotation(SWCommand.Guard.class);
|
||||||
if (guard != null) {
|
if (guard != null) {
|
||||||
if (guard.value() == null || guard.value().isEmpty()) {
|
if (guard.value() == null || guard.value().isEmpty()) {
|
||||||
|
@ -29,14 +29,13 @@ import org.bukkit.Material;
|
|||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
import java.text.MessageFormat;
|
import java.text.MessageFormat;
|
||||||
import java.util.ArrayList;
|
import java.util.*;
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
|
|
||||||
public class SchematicSelector {
|
public class SchematicSelector {
|
||||||
|
|
||||||
|
private static final Sorting[] all_sortings = Sorting.values();
|
||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
private final Player player;
|
private final Player player;
|
||||||
@Getter
|
@Getter
|
||||||
@ -57,6 +56,8 @@ public class SchematicSelector {
|
|||||||
@Getter
|
@Getter
|
||||||
@Setter
|
@Setter
|
||||||
private int depth = 0;
|
private int depth = 0;
|
||||||
|
private Sorting sorting = Sorting.NAME;
|
||||||
|
private boolean invertSorting = 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,7 +81,7 @@ public class SchematicSelector {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void openList(SchematicNode parent) {
|
private void openList(SchematicNode parent) {
|
||||||
List<SchematicNode> nodes = filter.isFilter()?getFilteredSchematics():getSchematicList(parent);
|
List<SchematicNode> nodes = applySorting(filter.isFilter()?getFilteredSchematics():getSchematicList(parent));
|
||||||
|
|
||||||
if(sdoTrigger) {
|
if(sdoTrigger) {
|
||||||
sdoTrigger = false;
|
sdoTrigger = false;
|
||||||
@ -123,6 +124,17 @@ public class SchematicSelector {
|
|||||||
inv.setItem(50, Material.CHEST, Core.MESSAGE.parse("SCHEM_SELECTOR_NEW_DIR", player), 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, Core.MESSAGE.parse("SCHEM_SELECTOR_FILTER", player), clickType -> openFilter());
|
inv.setItem(51, Material.NAME_TAG, Core.MESSAGE.parse("SCHEM_SELECTOR_FILTER", player), clickType -> openFilter());
|
||||||
|
inv.setItem(47, sorting.mat, Core.MESSAGE.parse("SCHEM_SELECTOR_SORTING", player), List.of(
|
||||||
|
Core.MESSAGE.parse("SCHEM_SELECTOR_SORTING_CURRENT", player, sorting.parseName(player)),
|
||||||
|
Core.MESSAGE.parse("SCHEM_SELECTOR_SORTING_DIRECTION", player, Core.MESSAGE.parse(invertSorting?"SCHEM_SELECTOR_SORTING_DSC":"SCHEM_SELECTOR_SORTING_ASC", player))
|
||||||
|
), invertSorting, click -> {
|
||||||
|
if(click.isLeftClick()) {
|
||||||
|
cycleSorting();
|
||||||
|
} else {
|
||||||
|
invertSorting = !invertSorting;
|
||||||
|
}
|
||||||
|
openList(parent);
|
||||||
|
});
|
||||||
|
|
||||||
injectable.onListRender(this, inv, parent);
|
injectable.onListRender(this, inv, parent);
|
||||||
inv.open();
|
inv.open();
|
||||||
@ -173,6 +185,28 @@ public class SchematicSelector {
|
|||||||
callback.accept(node);
|
callback.accept(node);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void cycleSorting() {
|
||||||
|
int next = sorting.ordinal() + 1;
|
||||||
|
if(next >= all_sortings.length) {
|
||||||
|
next = 0;
|
||||||
|
}
|
||||||
|
sorting = all_sortings[next];
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<SchematicNode> applySorting(List<SchematicNode> nodes) {
|
||||||
|
if(sorting == Sorting.NAME && !invertSorting) {
|
||||||
|
return nodes;
|
||||||
|
}
|
||||||
|
|
||||||
|
Comparator<SchematicNode> comparator = sorting.comparator;
|
||||||
|
if(invertSorting) {
|
||||||
|
comparator = comparator.reversed();
|
||||||
|
}
|
||||||
|
|
||||||
|
nodes.sort(comparator);
|
||||||
|
return nodes;
|
||||||
|
}
|
||||||
|
|
||||||
private SWListInv.SWListEntry<SchematicNode> renderItem(SchematicNode node) {
|
private SWListInv.SWListEntry<SchematicNode> renderItem(SchematicNode node) {
|
||||||
Material m = SWItem.getMaterial(node.getItem());
|
Material m = SWItem.getMaterial(node.getItem());
|
||||||
|
|
||||||
@ -399,8 +433,8 @@ public class SchematicSelector {
|
|||||||
SCHEMATIC_NODE("SCHEM_SELECTOR_SCHEMATIC_NODE", true),
|
SCHEMATIC_NODE("SCHEM_SELECTOR_SCHEMATIC_NODE", true),
|
||||||
SCHEMATIC_TYPE("SCHEM_SELECTOR_SCHEMATIC", false);
|
SCHEMATIC_TYPE("SCHEM_SELECTOR_SCHEMATIC", false);
|
||||||
|
|
||||||
private String rawName;
|
private final String rawName;
|
||||||
private boolean dirs;
|
private final boolean dirs;
|
||||||
|
|
||||||
private String getName(Player player) {
|
private String getName(Player player) {
|
||||||
return Core.MESSAGE.parse(rawName, player);
|
return Core.MESSAGE.parse(rawName, player);
|
||||||
@ -461,4 +495,25 @@ public class SchematicSelector {
|
|||||||
PRIVATE_ONLY,
|
PRIVATE_ONLY,
|
||||||
PUBLIC_ONLY
|
PUBLIC_ONLY
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@AllArgsConstructor
|
||||||
|
private enum Sorting {
|
||||||
|
NAME(Material.PAPER, "SCHEM_SELECTOR_SORTING_NAME", Comparator.comparing(SchematicNode::getName)),
|
||||||
|
TYPE(Material.CAULDRON, "SCHEM_SELECTOR_SORTING_TYPE", (o1, o2) -> {
|
||||||
|
if(o1.isDir() || o2.isDir()) {
|
||||||
|
return Boolean.compare(o1.isDir(), o2.isDir());
|
||||||
|
} else {
|
||||||
|
return o1.getSchemtype().name().compareTo(o2.getSchemtype().name());
|
||||||
|
}
|
||||||
|
}),
|
||||||
|
LAST_UPDATED(Material.CLOCK, "SCHEM_SELECTOR_SORTING_UPDATE", Comparator.comparing(SchematicNode::getLastUpdate));
|
||||||
|
|
||||||
|
private final Material mat;
|
||||||
|
private final String name;
|
||||||
|
private final Comparator<SchematicNode> comparator;
|
||||||
|
|
||||||
|
private String parseName(Player player) {
|
||||||
|
return Core.MESSAGE.parse(name, player);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
In neuem Issue referenzieren
Einen Benutzer sperren