Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
Shanwer committed Aug 4, 2024
2 parents 1a4ac2b + 61ae5de commit b582214
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -63,31 +63,31 @@ public DumpCommand(GeyserImpl geyser, String name, String description, String pe
this.geyser = geyser;
}

@Override
public void register(CommandManager<GeyserCommandSource> manager) {
manager.command(baseBuilder(manager)
.optional(ARGUMENTS, stringArrayParser(), SuggestionProvider.blockingStrings((ctx, input) -> {
// parse suggestions here
List<String> inputs = new ArrayList<>();
while (input.hasRemainingInput()) {
inputs.add(input.readStringSkipWhitespace());
}

if (inputs.size() <= 2) {
return SUGGESTIONS; // only `geyser dump` was typed (2 literals)
}

// the rest of the input after `geyser dump` is for this argument
inputs = inputs.subList(2, inputs.size());

// don't suggest any words they have already typed
List<String> suggestions = new ArrayList<>();
SUGGESTIONS.forEach(suggestions::add);
suggestions.removeAll(inputs);
return suggestions;
}))
.handler(this::execute));
}
@Override
public void register(CommandManager<GeyserCommandSource> manager) {
manager.command(baseBuilder(manager)
.optional(ARGUMENTS, stringArrayParser(), SuggestionProvider.blockingStrings((ctx, input) -> {
// parse suggestions here
List<String> inputs = new ArrayList<>();
while (input.hasRemainingInput()) {
inputs.add(input.readStringSkipWhitespace());
}

if (inputs.size() <= 2) {
return SUGGESTIONS; // only `geyser dump` was typed (2 literals)
}

// the rest of the input after `geyser dump` is for this argument
inputs = inputs.subList(2, inputs.size());

// don't suggest any words they have already typed
List<String> suggestions = new ArrayList<>();
SUGGESTIONS.forEach(suggestions::add);
suggestions.removeAll(inputs);
return suggestions;
}))
.handler(this::execute));
}

@Override
public void execute(CommandContext<GeyserCommandSource> context) {
Expand All @@ -113,13 +113,15 @@ public void execute(CommandContext<GeyserCommandSource> context) {
source.sendMessage(GeyserLocale.getPlayerLocaleString("geyser.commands.dump.collecting", source.locale()));
String dumpData;
try {
DumpInfo dump = new DumpInfo(geyser, addLog);

if (offlineDump) {
DefaultPrettyPrinter prettyPrinter = new DefaultPrettyPrinter();
// Make arrays easier to read
prettyPrinter.indentArraysWith(new DefaultIndenter(" ", "\n"));
dumpData = MAPPER.writer(prettyPrinter).writeValueAsString(new DumpInfo(addLog));
dumpData = MAPPER.writer(prettyPrinter).writeValueAsString(dump);
} else {
dumpData = MAPPER.writeValueAsString(new DumpInfo(addLog));
dumpData = MAPPER.writeValueAsString(dump);
}
} catch (IOException e) {
source.sendMessage(ChatColor.RED + GeyserLocale.getPlayerLocaleString("geyser.commands.dump.collect_error", source.locale()));
Expand Down
22 changes: 13 additions & 9 deletions core/src/main/java/org/geysermc/geyser/dump/DumpInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public class DumpInfo {
private final FlagsInfo flagsInfo;
private final List<ExtensionInfo> extensionInfo;

public DumpInfo(boolean addLog) {
public DumpInfo(GeyserImpl geyser, boolean addLog) {
this.versionInfo = new VersionInfo();

this.cpuCount = Runtime.getRuntime().availableProcessors();
Expand All @@ -91,7 +91,7 @@ public DumpInfo(boolean addLog) {

this.gitInfo = new GitInfo(GeyserImpl.BUILD_NUMBER, GeyserImpl.COMMIT.substring(0, 7), GeyserImpl.COMMIT, GeyserImpl.BRANCH, GeyserImpl.REPOSITORY);

this.config = GeyserImpl.getInstance().getConfig();
this.config = geyser.getConfig();
this.floodgate = new Floodgate();

String md5Hash = "unknown";
Expand All @@ -107,7 +107,7 @@ public DumpInfo(boolean addLog) {
//noinspection UnstableApiUsage
sha256Hash = byteSource.hash(Hashing.sha256()).toString();
} catch (Exception e) {
if (GeyserImpl.getInstance().getConfig().isDebugMode()) {
if (this.config.isDebugMode()) {
e.printStackTrace();
}
}
Expand All @@ -116,18 +116,22 @@ public DumpInfo(boolean addLog) {
this.ramInfo = new RamInfo();

if (addLog) {
this.logsInfo = new LogsInfo();
this.logsInfo = new LogsInfo(geyser);
}

this.userPlatforms = new Object2IntOpenHashMap<>();
for (GeyserSession session : GeyserImpl.getInstance().getSessionManager().getAllSessions()) {
for (GeyserSession session : geyser.getSessionManager().getAllSessions()) {
DeviceOs device = session.getClientData().getDeviceOs();
userPlatforms.put(device, userPlatforms.getOrDefault(device, 0) + 1);
}

this.connectionAttempts = GeyserImpl.getInstance().getGeyserServer().getConnectionAttempts();
if (geyser.getGeyserServer() != null) {
this.connectionAttempts = geyser.getGeyserServer().getConnectionAttempts();
} else {
this.connectionAttempts = 0; // Fallback if Geyser failed to fully startup
}

this.bootstrapInfo = GeyserImpl.getInstance().getBootstrap().getDumpInfo();
this.bootstrapInfo = geyser.getBootstrap().getDumpInfo();

this.flagsInfo = new FlagsInfo();

Expand Down Expand Up @@ -244,10 +248,10 @@ public static class Floodgate {
public static class LogsInfo {
private String link;

public LogsInfo() {
public LogsInfo(GeyserImpl geyser) {
try {
Map<String, String> fields = new HashMap<>();
fields.put("content", FileUtils.readAllLines(GeyserImpl.getInstance().getBootstrap().getLogsPath()).collect(Collectors.joining("\n")));
fields.put("content", FileUtils.readAllLines(geyser.getBootstrap().getLogsPath()).collect(Collectors.joining("\n")));

JsonNode logData = GeyserImpl.JSON_MAPPER.readTree(WebUtils.postForm("https://api.mclo.gs/1/log", fields));

Expand Down

0 comments on commit b582214

Please sign in to comment.