Dieser Commit ist enthalten in:
Commit
ace5778fba
@ -20,6 +20,7 @@
|
|||||||
package de.steamwar.schematicsystem.commands;
|
package de.steamwar.schematicsystem.commands;
|
||||||
|
|
||||||
import de.steamwar.command.SWCommand;
|
import de.steamwar.command.SWCommand;
|
||||||
|
import de.steamwar.command.SWCommandUtils;
|
||||||
import de.steamwar.command.TypeMapper;
|
import de.steamwar.command.TypeMapper;
|
||||||
import de.steamwar.inventory.SWAnvilInv;
|
import de.steamwar.inventory.SWAnvilInv;
|
||||||
import de.steamwar.inventory.SchematicSelector;
|
import de.steamwar.inventory.SchematicSelector;
|
||||||
@ -37,6 +38,8 @@ import org.bukkit.command.CommandSender;
|
|||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
import java.util.function.Function;
|
||||||
|
import java.util.function.Predicate;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
@ -45,6 +48,16 @@ import static de.steamwar.schematicsystem.commands.SchematicCommandUtils.*;
|
|||||||
|
|
||||||
public class SchematicCommand extends SWCommand {
|
public class SchematicCommand extends SWCommand {
|
||||||
|
|
||||||
|
private static final Map<String, TypeMapper<?>> searchMapper = new HashMap<>();
|
||||||
|
|
||||||
|
static {
|
||||||
|
searchMapper.put("-type", SWCommandUtils.createMapper(SchematicType.values().stream().map(SchematicType::name).toArray(String[]::new)));
|
||||||
|
searchMapper.put("-owner", SWCommandUtils.createMapper(Function.identity(), (commandSender, s) -> Collections.singletonList(s)));
|
||||||
|
Class<?> clazz = Material.class;
|
||||||
|
searchMapper.put("-item", SWCommandUtils.createEnumMapper((Class<Enum<?>>) clazz));
|
||||||
|
searchMapper.put("-public", null);
|
||||||
|
}
|
||||||
|
|
||||||
public SchematicCommand() {
|
public SchematicCommand() {
|
||||||
super("schematic", Bukkit.getPluginManager().getPlugin("Teamserver") == null ? new String[] {"schem", "/schem", "/schematic"} : new String[]{"schem"});
|
super("schematic", Bukkit.getPluginManager().getPlugin("Teamserver") == null ? new String[] {"schem", "/schem", "/schematic"} : new String[]{"schem"});
|
||||||
}
|
}
|
||||||
@ -153,9 +166,14 @@ public class SchematicCommand extends SWCommand {
|
|||||||
SchematicNode currentNode = mkdirs(layers, user, 1);
|
SchematicNode currentNode = mkdirs(layers, user, 1);
|
||||||
|
|
||||||
SchematicNode node = SchematicNode.getNodeFromPath(user, String.join("/", layers));
|
SchematicNode node = SchematicNode.getNodeFromPath(user, String.join("/", layers));
|
||||||
if (node != null && !node.getSchemtype().writeable() && node.getOwner() != user.getId()) {
|
if (node != null) {
|
||||||
player.sendMessage(SchematicSystem.PREFIX + "§cDu darfst diese Schematic nicht überschreiben");
|
if(node.isDir()) {
|
||||||
return;
|
player.sendMessage(SchematicSystem.PREFIX + "§cDie Schematic ist ein Ordner");
|
||||||
|
return;
|
||||||
|
} else if (!node.getSchemtype().writeable() || node.getOwner() != user.getId()) {
|
||||||
|
player.sendMessage(SchematicSystem.PREFIX + "§cDu darfst diese Schematic nicht überschreiben");
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean newSchem = false;
|
boolean newSchem = false;
|
||||||
@ -265,13 +283,64 @@ public class SchematicCommand extends SWCommand {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Register("search")
|
@Register("search")
|
||||||
public void schemSearch(Player player, String query) {
|
public void schemSearch(Player player, @Mapper("searchMapper") String... query) {
|
||||||
SteamwarUser user = getUser(player);
|
SteamwarUser user = getUser(player);
|
||||||
List<SchematicNode> nodes = SchematicNode.filterSchems(user.getId(), node -> node.getName().contains(query));
|
int userId = user.getId();
|
||||||
|
List<Predicate<SchematicNode>> predicates = new ArrayList<>();
|
||||||
|
List<String> nameList = new ArrayList<>();
|
||||||
|
int i = 0;
|
||||||
|
while (i < query.length) {
|
||||||
|
String current = query[i];
|
||||||
|
if (searchMapper.containsKey(current)) {
|
||||||
|
if (searchMapper.get(current) == null) {
|
||||||
|
if (current.equals("-public")) {
|
||||||
|
userId = 0;
|
||||||
|
}
|
||||||
|
} else if (i + 1 < query.length) {
|
||||||
|
int finalI = i;
|
||||||
|
switch (current) {
|
||||||
|
case "-type":
|
||||||
|
predicates.add(node -> node.getSchemtype().name().equalsIgnoreCase(query[finalI + 1]));
|
||||||
|
break;
|
||||||
|
case "-item":
|
||||||
|
predicates.add(node -> node.getItem().equalsIgnoreCase(query[finalI + 1]));
|
||||||
|
break;
|
||||||
|
case "-owner":
|
||||||
|
SteamwarUser steamwarUser = SteamwarUser.get(query[finalI + 1]);
|
||||||
|
if (steamwarUser == null) {
|
||||||
|
player.sendMessage(SchematicSystem.PREFIX + "§cDer Spieler §e" + query[finalI + 1] + " §cexistiert nicht");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
predicates.add(node -> node.getOwner() == steamwarUser.getId());
|
||||||
|
}
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
predicates.add(node -> node.getName().contains(current));
|
||||||
|
nameList.add(current);
|
||||||
|
}
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
|
||||||
|
List<SchematicNode> nodes = SchematicNode.filterSchems(userId, node -> {
|
||||||
|
for (Predicate<SchematicNode> predicate : predicates) {
|
||||||
|
if (!predicate.test(node)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
});
|
||||||
player.sendMessage("§eSchematics §8(§e" + nodes.size() + "§8)");
|
player.sendMessage("§eSchematics §8(§e" + nodes.size() + "§8)");
|
||||||
nodes.forEach(node -> {
|
nodes.forEach(node -> {
|
||||||
String br = node.generateBreadcrumbs(user);
|
String br = node.generateBreadcrumbs(user);
|
||||||
TextComponent schematics = new TextComponent("§7" + br.replace(query, "§e§l" + query + "§7"));
|
String displayName = br;
|
||||||
|
if (!nameList.isEmpty()) {
|
||||||
|
displayName = "§8" + br;
|
||||||
|
}
|
||||||
|
for (String s : nameList) {
|
||||||
|
displayName = displayName.replace(s, "§e§l" + s + "§8");
|
||||||
|
}
|
||||||
|
TextComponent schematics = new TextComponent("§7" + displayName);
|
||||||
schematics.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ComponentBuilder("§eSchematic verwalten").create()));
|
schematics.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ComponentBuilder("§eSchematic verwalten").create()));
|
||||||
schematics.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/schem info " + br));
|
schematics.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/schem info " + br));
|
||||||
|
|
||||||
@ -606,6 +675,39 @@ public class SchematicCommand extends SWCommand {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Mapper(value = "searchMapper", local = true)
|
||||||
|
public TypeMapper<String> searchTypeMapper() {
|
||||||
|
return new TypeMapper<String>() {
|
||||||
|
@Override
|
||||||
|
public String map(CommandSender commandSender, String[] previousArguments, String s) {
|
||||||
|
return s;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<String> tabCompletes(CommandSender commandSender, String[] strings, String s) {
|
||||||
|
if (strings.length == 0) {
|
||||||
|
List<String> list = new ArrayList<>();
|
||||||
|
list.add(s);
|
||||||
|
list.addAll(searchMapper.keySet());
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
String last = strings[strings.length - 1];
|
||||||
|
if (searchMapper.containsKey(last)) {
|
||||||
|
TypeMapper<?> mapper = searchMapper.get(last);
|
||||||
|
if (mapper == null) {
|
||||||
|
List<String> list = new ArrayList<>(searchMapper.keySet());
|
||||||
|
list.add(s);
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
return mapper.tabCompletes(commandSender, strings, s);
|
||||||
|
}
|
||||||
|
List<String> list = new ArrayList<>(searchMapper.keySet());
|
||||||
|
list.add(s);
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
enum Extend {
|
enum Extend {
|
||||||
AUSFAHREN,
|
AUSFAHREN,
|
||||||
NORMAL
|
NORMAL
|
||||||
|
@ -55,6 +55,10 @@ public class SchematicCommandUtils {
|
|||||||
player.sendMessage(SchematicSystem.PREFIX + "§cDeine Ordner brauchen schon einen Namen!");
|
player.sendMessage(SchematicSystem.PREFIX + "§cDeine Ordner brauchen schon einen Namen!");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
if(layer.length() > 64) {
|
||||||
|
player.sendMessage(SchematicSystem.PREFIX + "§cDer Name der Schematic ist zu lang");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
if (layer.contains("/") ||
|
if (layer.contains("/") ||
|
||||||
layer.contains("\\") ||
|
layer.contains("\\") ||
|
||||||
layer.contains("<") ||
|
layer.contains("<") ||
|
||||||
@ -315,7 +319,7 @@ public class SchematicCommandUtils {
|
|||||||
player.sendMessage(SchematicSystem.PREFIX + "§cEs konnte keine Daten in der Schematic gefunden werden.");
|
player.sendMessage(SchematicSystem.PREFIX + "§cEs konnte keine Daten in der Schematic gefunden werden.");
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
player.sendMessage(SchematicSystem.PREFIX + "§cDie Schematic konnte nicht geladen werden.");
|
player.sendMessage(SchematicSystem.PREFIX + "§cDie Schematic konnte nicht geladen werden.");
|
||||||
throw new SecurityException(e);
|
Bukkit.getLogger().log(Level.INFO, e.getMessage(), e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
In neuem Issue referenzieren
Einen Benutzer sperren