Finish it up
Dieser Commit ist enthalten in:
Ursprung
e728483e5f
Commit
a6dbf41feb
@ -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.Message;
|
||||||
import de.steamwar.bungeecore.Node;
|
import de.steamwar.bungeecore.Node;
|
||||||
|
import de.steamwar.bungeecore.util.SchematicSearch;
|
||||||
import de.steamwar.command.SWCommand;
|
import de.steamwar.command.SWCommand;
|
||||||
import net.md_5.bungee.api.CommandSender;
|
import net.md_5.bungee.api.CommandSender;
|
||||||
|
|
||||||
@ -37,6 +38,7 @@ public class StatCommand extends SWCommand {
|
|||||||
|
|
||||||
@Register
|
@Register
|
||||||
public void genericCommand(CommandSender sender) {
|
public void genericCommand(CommandSender sender) {
|
||||||
|
Message.send("STAT_SEARCH_QUEUE", sender, SchematicSearch.getQueueSize());
|
||||||
Map<String, Integer> serverCount = new HashMap<>();
|
Map<String, Integer> serverCount = new HashMap<>();
|
||||||
try {
|
try {
|
||||||
Process process = new ProcessBuilder("ps", "x").start();
|
Process process = new ProcessBuilder("ps", "x").start();
|
||||||
|
@ -31,5 +31,6 @@ public class BungeeNetworkHandler {
|
|||||||
new ImALobbyHandler().register();
|
new ImALobbyHandler().register();
|
||||||
new InventoryCallbackHandler().register();
|
new InventoryCallbackHandler().register();
|
||||||
new PrepareSchemHandler().register();
|
new PrepareSchemHandler().register();
|
||||||
|
new SchematicSearchRequestHandler().register();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,28 @@
|
|||||||
|
package de.steamwar.bungeecore.network.handlers;
|
||||||
|
|
||||||
|
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.SchematicNode;
|
||||||
import de.steamwar.sql.SteamwarUser;
|
import de.steamwar.sql.SteamwarUser;
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.Getter;
|
||||||
import net.md_5.bungee.api.ChatMessageType;
|
import net.md_5.bungee.api.ChatMessageType;
|
||||||
import net.md_5.bungee.api.chat.ClickEvent;
|
import net.md_5.bungee.api.chat.ClickEvent;
|
||||||
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
||||||
@ -50,13 +52,13 @@ public class SchematicSearch {
|
|||||||
}, 0, 1, TimeUnit.SECONDS);
|
}, 0, 1, TimeUnit.SECONDS);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void queueSearch(ProxiedPlayer player, SchematicNode node ) {
|
public static void queueSearch(ProxiedPlayer player, SchematicNode node, SchematicSearchBehavior behavior) {
|
||||||
SteamwarUser user = SteamwarUser.get(player.getUniqueId());
|
SteamwarUser user = SteamwarUser.get(player.getUniqueId());
|
||||||
synchronized (searchQueue) {
|
synchronized (searchQueue) {
|
||||||
if(user.getUserGroup().isAdminGroup()) {
|
if(user.getUserGroup().isAdminGroup()) {
|
||||||
searchQueue.add(0, new SchematicSearch(player, node));
|
searchQueue.add(0, new SchematicSearch(player, node, behavior));
|
||||||
} else {
|
} else {
|
||||||
searchQueue.add(new SchematicSearch(player, node));
|
searchQueue.add(new SchematicSearch(player, node, behavior));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(watchdog == null) {
|
if(watchdog == null) {
|
||||||
@ -79,8 +81,25 @@ public class SchematicSearch {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static List<String> constructArguments(SteamwarUser user, File pattern) {
|
public static int getQueueSize() {
|
||||||
return Arrays.asList(searchBinary, "-T", "2", "-s", "-u", String.valueOf(user.getId()), "-o", "json:std", "-m", "50", pattern.getAbsolutePath());
|
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) {
|
public static boolean removeFromQueue(ProxiedPlayer player) {
|
||||||
@ -120,13 +139,15 @@ public class SchematicSearch {
|
|||||||
|
|
||||||
private final ProxiedPlayer player;
|
private final ProxiedPlayer player;
|
||||||
private final SchematicNode node;
|
private final SchematicNode node;
|
||||||
|
private final SchematicSearchBehavior behavior;
|
||||||
private File pattern;
|
private File pattern;
|
||||||
private ScheduledTask task;
|
private ScheduledTask task;
|
||||||
private Process process;
|
private Process process;
|
||||||
|
|
||||||
private SchematicSearch(ProxiedPlayer player, SchematicNode node) {
|
private SchematicSearch(ProxiedPlayer player, SchematicNode node, SchematicSearchBehavior behavior) {
|
||||||
this.player = player;
|
this.player = player;
|
||||||
this.node = node;
|
this.node = node;
|
||||||
|
this.behavior = behavior;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static String readInputStream(InputStream is) throws IOException {
|
private static String readInputStream(InputStream is) throws IOException {
|
||||||
@ -157,7 +178,7 @@ public class SchematicSearch {
|
|||||||
}
|
}
|
||||||
Message.send("SCHEMATIC_SEARCH_STARTED", player, node.getName());
|
Message.send("SCHEMATIC_SEARCH_STARTED", player, node.getName());
|
||||||
pattern = schematicNodeToTempFile(data);
|
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();
|
process = builder.start();
|
||||||
InputStream stdout = process.getInputStream();
|
InputStream stdout = process.getInputStream();
|
||||||
InputStream stderr = process.getErrorStream();
|
InputStream stderr = process.getErrorStream();
|
||||||
@ -268,4 +289,15 @@ public class SchematicSearch {
|
|||||||
float percent;
|
float percent;
|
||||||
String name;
|
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
|
#Various commands
|
||||||
ALERT=§f{0}
|
ALERT=§f{0}
|
||||||
STAT_SERVER=§7Server §e{0}§8: §7Below limit §e{1} §7Server count §e{2}
|
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
|
#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]
|
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