WIP: Add SchemSearch #467
@ -1,40 +0,0 @@
|
||||
package de.steamwar.bungeecore.commands;
|
||||
|
||||
import de.steamwar.bungeecore.util.SchematicSearch;
|
||||
import de.steamwar.command.PreviousArguments;
|
||||
import de.steamwar.command.SWCommand;
|
||||
import de.steamwar.command.TypeMapper;
|
||||
import de.steamwar.sql.SchematicNode;
|
||||
import de.steamwar.sql.SteamwarUser;
|
||||
import net.md_5.bungee.api.CommandSender;
|
||||
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
public class SchemSearchTestCommand extends SWCommand {
|
||||
public SchemSearchTestCommand() {
|
||||
super("schemsearch");
|
||||
}
|
||||
|
||||
|
||||
@Register
|
||||
public void genericCommand(ProxiedPlayer player, SchematicNode node) {
|
||||
SchematicSearch.queueSearch(player, node);
|
||||
}
|
||||
|
||||
@ClassMapper(SchematicNode.class)
|
||||
public TypeMapper<SchematicNode> getSchematicNodeMapper() {
|
||||
return new TypeMapper<SchematicNode>() {
|
||||
|
||||
@Override
|
||||
public SchematicNode map(CommandSender commandSender, String[] previousArguments, String s) {
|
||||
return SchematicNode.getNodeFromPath(SteamwarUser.get(commandSender.getName()), s);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<String> tabCompletes(CommandSender sender, PreviousArguments previousArguments, String s) {
|
||||
return SchematicNode.getNodeTabcomplete(SteamwarUser.get(sender.getName()), s);
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
@ -21,6 +21,7 @@ package de.steamwar.bungeecore.commands;
|
||||
|
||||
import de.steamwar.bungeecore.Message;
|
||||
import de.steamwar.bungeecore.Node;
|
||||
import de.steamwar.bungeecore.util.SchematicSearch;
|
||||
import de.steamwar.command.SWCommand;
|
||||
import net.md_5.bungee.api.CommandSender;
|
||||
|
||||
@ -37,6 +38,7 @@ public class StatCommand extends SWCommand {
|
||||
|
||||
@Register
|
||||
public void genericCommand(CommandSender sender) {
|
||||
Message.send("STAT_SEARCH_QUEUE", sender, SchematicSearch.getQueueSize());
|
||||
Map<String, Integer> serverCount = new HashMap<>();
|
||||
try {
|
||||
Process process = new ProcessBuilder("ps", "x").start();
|
||||
|
@ -31,5 +31,6 @@ public class BungeeNetworkHandler {
|
||||
new ImALobbyHandler().register();
|
||||
new InventoryCallbackHandler().register();
|
||||
new PrepareSchemHandler().register();
|
||||
new SchematicSearchRequestHandler().register();
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,28 @@
|
||||
package de.steamwar.bungeecore.network.handlers;
|
||||
Lixfel markierte diese Unterhaltung als gelöst
Veraltet
|
||||
|
||||
import de.steamwar.bungeecore.BungeeCore;
|
||||
import de.steamwar.bungeecore.util.SchematicSearch;
|
||||
import de.steamwar.network.packets.PacketHandler;
|
||||
import de.steamwar.network.packets.client.RequestSchematicSearchPacket;
|
||||
import de.steamwar.sql.SchematicNode;
|
||||
import de.steamwar.sql.SteamwarUser;
|
||||
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
||||
|
||||
public class SchematicSearchRequestHandler extends PacketHandler {
|
||||
|
||||
@Handler
|
||||
public void handle(RequestSchematicSearchPacket packet) {
|
||||
SteamwarUser user = SteamwarUser.get(packet.getPlayerId());
|
||||
SchematicNode node = SchematicNode.getSchematicNode(packet.getSchematicId());
|
||||
ProxiedPlayer proxiedPlayer = BungeeCore.get().getProxy().getPlayer(user.getUUID());
|
||||
if(proxiedPlayer == null) {
|
||||
return;
|
||||
}
|
||||
SchematicSearch.SchematicSearchBehavior behavior = SchematicSearch.SchematicSearchBehavior.builder()
|
||||
.airAsAny(packet.isAirAsAny())
|
||||
.ignoreAir(packet.isIgnoreAir())
|
||||
.ignoreBlockData(packet.isIgnoreBlockData())
|
||||
.build();
|
||||
SchematicSearch.queueSearch(proxiedPlayer, node, behavior);
|
||||
}
|
||||
}
|
@ -10,6 +10,8 @@ import de.steamwar.sql.NodeData;
|
||||
import de.steamwar.sql.SchematicNode;
|
||||
import de.steamwar.sql.SteamwarUser;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Getter;
|
||||
import net.md_5.bungee.api.ChatMessageType;
|
||||
import net.md_5.bungee.api.chat.ClickEvent;
|
||||
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
||||
@ -50,13 +52,13 @@ public class SchematicSearch {
|
||||
}, 0, 1, TimeUnit.SECONDS);
|
||||
Lixfel
hat
Falscher Pfad. Falscher Pfad.
|
||||
}
|
||||
|
||||
public static void queueSearch(ProxiedPlayer player, SchematicNode node ) {
|
||||
public static void queueSearch(ProxiedPlayer player, SchematicNode node, SchematicSearchBehavior behavior) {
|
||||
SteamwarUser user = SteamwarUser.get(player.getUniqueId());
|
||||
synchronized (searchQueue) {
|
||||
if(user.getUserGroup().isAdminGroup()) {
|
||||
Lixfel
hat
Warum den Task ständig starten und stoppen und nicht den Thread ständig offen lassen und einfach eventbasiert auf notifyAll() warten lassen? Warum den Task ständig starten und stoppen und nicht den Thread ständig offen lassen und einfach eventbasiert auf notifyAll() warten lassen?
|
||||
searchQueue.add(0, new SchematicSearch(player, node));
|
||||
searchQueue.add(0, new SchematicSearch(player, node, behavior));
|
||||
} else {
|
||||
searchQueue.add(new SchematicSearch(player, node));
|
||||
searchQueue.add(new SchematicSearch(player, node, behavior));
|
||||
}
|
||||
}
|
||||
if(watchdog == null) {
|
||||
@ -79,8 +81,25 @@ public class SchematicSearch {
|
||||
}
|
||||
}
|
||||
|
||||
private static List<String> constructArguments(SteamwarUser user, File pattern) {
|
||||
return Arrays.asList(searchBinary, "-T", "2", "-s", "-u", String.valueOf(user.getId()), "-o", "json:std", "-m", "50", pattern.getAbsolutePath());
|
||||
public static int getQueueSize() {
|
||||
synchronized (searchQueue) {
|
||||
return searchQueue.size();
|
||||
}
|
||||
}
|
||||
|
||||
private static List<String> constructArguments(SteamwarUser user, File pattern, SchematicSearchBehavior behavior) {
|
||||
List<String> args = new ArrayList<>(Arrays.asList(searchBinary, "-T", "2", "-s", "-u", String.valueOf(user.getId()), "-o", "json:std", "-m", "50"));
|
||||
if(behavior.isAirAsAny()) {
|
||||
args.add("-A");
|
||||
}
|
||||
if(behavior.isIgnoreAir()) {
|
||||
args.add("-a");
|
||||
}
|
||||
if(behavior.isIgnoreBlockData()) {
|
||||
args.add("-d");
|
||||
}
|
||||
args.add(pattern.getAbsolutePath());
|
||||
return args;
|
||||
}
|
||||
|
||||
public static boolean removeFromQueue(ProxiedPlayer player) {
|
||||
@ -120,13 +139,15 @@ public class SchematicSearch {
|
||||
|
||||
private final ProxiedPlayer player;
|
||||
private final SchematicNode node;
|
||||
private final SchematicSearchBehavior behavior;
|
||||
private File pattern;
|
||||
private ScheduledTask task;
|
||||
private Process process;
|
||||
|
||||
private SchematicSearch(ProxiedPlayer player, SchematicNode node) {
|
||||
private SchematicSearch(ProxiedPlayer player, SchematicNode node, SchematicSearchBehavior behavior) {
|
||||
this.player = player;
|
||||
this.node = node;
|
||||
this.behavior = behavior;
|
||||
}
|
||||
|
||||
private static String readInputStream(InputStream is) throws IOException {
|
||||
@ -157,7 +178,7 @@ public class SchematicSearch {
|
||||
}
|
||||
Message.send("SCHEMATIC_SEARCH_STARTED", player, node.getName());
|
||||
pattern = schematicNodeToTempFile(data);
|
||||
ProcessBuilder builder = new ProcessBuilder(constructArguments(SteamwarUser.get(player.getUniqueId()), pattern));
|
||||
ProcessBuilder builder = new ProcessBuilder(constructArguments(SteamwarUser.get(player.getUniqueId()), pattern, behavior));
|
||||
process = builder.start();
|
||||
InputStream stdout = process.getInputStream();
|
||||
InputStream stderr = process.getErrorStream();
|
||||
@ -268,4 +289,15 @@ public class SchematicSearch {
|
||||
float percent;
|
||||
String name;
|
||||
}
|
||||
|
||||
@Builder
|
||||
@Getter
|
||||
public static class SchematicSearchBehavior {
|
||||
@Builder.Default
|
||||
boolean airAsAny = false;
|
||||
@Builder.Default
|
||||
boolean ignoreAir = false;
|
||||
@Builder.Default
|
||||
boolean ignoreBlockData = false;
|
||||
}
|
||||
}
|
||||
|
@ -121,6 +121,7 @@ MOD_USE_MODSENDER=§cPlease use the §c§lFabricModSender§c (https://steamwar.d
|
||||
#Various commands
|
||||
Lixfel markierte diese Unterhaltung als gelöst
Lixfel
hat
Deutsche Fassung fehlt noch. Deutsche Fassung fehlt noch.
|
||||
ALERT=§f{0}
|
||||
STAT_SERVER=§7Server §e{0}§8: §7Below limit §e{1} §7Server count §e{2}
|
||||
STAT_SEARCH_QUEUE=§7Schematic search queue: §e{0}
|
||||
|
||||
#Ban&Mute-Command
|
||||
PUNISHMENT_USAGE=§8/§7{0} §8[§eplayer§8] [§edd§8.§emm§8.§eyyyy §7or §edd§8.§emm§8.§eyyyy§8_§ehh§8:§emm §7or §eperma§8] [§ereason§8]
|
||||
|
In neuem Issue referenzieren
Einen Benutzer sperren
.