SteamWar/BungeeCore
Archiviert
13
2
Dieser Commit ist enthalten in:
Chaoscaot 2023-04-12 02:05:23 +02:00
Ursprung e728483e5f
Commit a6dbf41feb
6 geänderte Dateien mit 71 neuen und 47 gelöschten Zeilen

Datei anzeigen

@ -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);
}
};
}
}

Datei anzeigen

@ -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();

Datei anzeigen

@ -31,5 +31,6 @@ public class BungeeNetworkHandler {
new ImALobbyHandler().register();
new InventoryCallbackHandler().register();
new PrepareSchemHandler().register();
new SchematicSearchRequestHandler().register();
}
}

Datei anzeigen

@ -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);
}
}

Datei anzeigen

@ -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);
}
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()) {
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;
}
}

Datei anzeigen

@ -121,6 +121,7 @@ MOD_USE_MODSENDER=§cPlease use the §c§lFabricModSender§c (https://steamwar.d
#Various commands
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]