Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,13 @@
import java.util.Set;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import me.lucko.fabric.api.permissions.v0.Permissions;
import net.minecraft.server.command.ServerCommandSource;
import net.minecraft.text.ClickEvent;
import net.minecraft.text.HoverEvent;
import net.minecraft.text.MutableText;
import net.minecraft.text.Text;
import net.minecraft.util.Formatting;

public class HandleAltsCommand {

Expand Down Expand Up @@ -67,7 +70,7 @@ public static int execute(CommandContext<ServerCommandSource> context, File logF
// Query is a username
Set<String> ips = playerToIps.get(query);
if (ips != null) {
StringBuilder response = new StringBuilder();
MutableText response = Text.literal("");
if (Permissions.check(source, "altx.viewips", 4)) {
response
.append("§bPlayer §3")
Expand All @@ -82,13 +85,13 @@ public static int execute(CommandContext<ServerCommandSource> context, File logF

response.append("\n");
if (Permissions.check(source, "altx.viewips", 4)) {
response.append("§3- (§b").append(ip).append("§3): §f");
response.append("§3- (§b").append(getIpText(ip)).append("§3): §f");
} else {
response.append("§3- §f");
}
response.append(String.join(", ", players));
}
context.getSource().sendFeedback(() -> Text.literal(response.toString()), false);
context.getSource().sendFeedback(() -> response, false);
} else {
context
.getSource()
Expand All @@ -97,6 +100,16 @@ public static int execute(CommandContext<ServerCommandSource> context, File logF
return 1;
}

private static MutableText getIpText(String ip) {
return Text.literal(ip)
.styled(
style ->
style
.withColor(Formatting.AQUA) // §b
.withClickEvent(new ClickEvent.CopyToClipboard(ip))
.withHoverEvent(new HoverEvent.ShowText(Text.literal("Copy"))));
}

private static void readLogFile(
Map<String, Set<String>> ipToPlayers, Map<String, Set<String>> playerToIps, File logFile)
throws IOException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,11 @@
import java.util.Set;
import me.lucko.fabric.api.permissions.v0.Permissions;
import net.minecraft.server.command.ServerCommandSource;
import net.minecraft.text.ClickEvent;
import net.minecraft.text.HoverEvent;
import net.minecraft.text.MutableText;
import net.minecraft.text.Text;
import net.minecraft.util.Formatting;

public class ListIpsWithMultiplePlayers {
public static int execute(CommandContext<ServerCommandSource> context, File logFile) {
Expand All @@ -28,15 +32,15 @@ public static int execute(CommandContext<ServerCommandSource> context, File logF
}

// Filter and build the result
StringBuilder response = new StringBuilder("§bIPs with two or more users:");
MutableText response = Text.literal("§bIPs with two or more users:");
boolean found = false;

for (Map.Entry<String, Set<String>> entry : ipToPlayers.entrySet()) {
if (entry.getValue().size() >= 2) {
found = true;
response.append("\n");
if (Permissions.check(source, "altx.viewips", 4)) {
response.append("§3- (§b").append(entry.getKey()).append("§3): §f");
response.append("§3- (§b").append(getIpText(entry.getKey())).append("§3): §f");
} else {
response.append("§3- §f");
}
Expand All @@ -49,11 +53,21 @@ public static int execute(CommandContext<ServerCommandSource> context, File logF
}

// Send the response
context.getSource().sendFeedback(() -> Text.literal(response.toString()), false);
context.getSource().sendFeedback(() -> response, false);

return 1;
}

private static MutableText getIpText(String ip) {
return Text.literal(ip)
.styled(
style ->
style
.withColor(Formatting.AQUA) // §b
.withClickEvent(new ClickEvent.CopyToClipboard(ip))
.withHoverEvent(new HoverEvent.ShowText(Text.literal("Copy"))));
}

private static void readLogFile(File logFile, Map<String, Set<String>> ipToPlayers)
throws IOException {
// Load the IP-to-players map from the log file
Expand Down