-
-
Notifications
You must be signed in to change notification settings - Fork 0
Move from kotlin to java to reduce package size #6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 6 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
667e8f8
Replace kotlin with java
TheMeinerLP 7923804
Replace kotlin with java
TheMeinerLP 252b7fe
Replace kotlin with java
TheMeinerLP 51b9d63
Cleanup and add some javadocs
TheMeinerLP 84570eb
Add a working example for debugpaste
TheMeinerLP 744943f
Improve working example
TheMeinerLP 7f32eac
Rename method
TheMeinerLP 28edcbc
Add docs
TheMeinerLP 468e7ec
Make field final
TheMeinerLP 137ad26
Update readme
TheMeinerLP File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
101 changes: 101 additions & 0 deletions
101
bukkit-extension/src/main/java/dev/themeinerlp/plugindebug/BukkitDebugBuilder.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
package dev.themeinerlp.plugindebug; | ||
|
||
import io.papermc.lib.PaperLib; | ||
import io.papermc.paper.datapack.Datapack; | ||
import org.bukkit.Bukkit; | ||
import org.bukkit.configuration.file.YamlConfiguration; | ||
import org.bukkit.plugin.Plugin; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
import java.io.IOException; | ||
import java.lang.management.ManagementFactory; | ||
import java.nio.file.Files; | ||
import java.nio.file.Path; | ||
import java.util.Arrays; | ||
import java.util.regex.Pattern; | ||
|
||
public final class BukkitDebugBuilder extends DebugBuilder<BukkitDebugBuilder> { | ||
|
||
private Pattern privacyRegex = Pattern.compile("\\b(1?[0-9]{1,2}|2[0-4][0-9]|25[0-5])\\.(1?[0-9]{1,2}|2[0-4][0-9]|25[0-5])\\.(1?[0-9]{1,2}|2[0-4][0-9]|25[0-5])\\.(1?[0-9]{1,2}|2[0-4][0-9]|25[0-5])\\b"); | ||
private BukkitDebugBuilder(String uploadServer) { | ||
super(uploadServer); | ||
} | ||
|
||
/** | ||
* Collects the latest log file from bukkit | ||
* @return the builder | ||
* @throws IOException if the file empty/null | ||
*/ | ||
public BukkitDebugBuilder collectLatestSpigotLog() throws IOException { | ||
var latestLogFile = Path.of("logs", "latest.log"); | ||
if (Files.size(latestLogFile) >= maxZipFileSize) throw new IllegalStateException( | ||
String.format("Latest log file is to big only %d bytes allowed", maxZipFileSize) | ||
); | ||
var tempLogFile = Files.createTempFile(tempFile, ".log"); | ||
var cleanedList = Files.readAllLines(latestLogFile).stream().map(s -> s.replaceAll(privacyRegex.pattern(), "*")).toList(); | ||
Files.write(tempLogFile, cleanedList); | ||
addFile(tempLogFile, FileType.LOG, "Latest Log"); | ||
return this; | ||
} | ||
|
||
/** | ||
* Collects default paper debug information | ||
* @return the bukkit builder | ||
* @throws IOException if the file empty/null | ||
*/ | ||
|
||
public BukkitDebugBuilder defaultPaperDebugInformation() throws IOException { | ||
var tempLogFile = Files.createTempFile(tempFile, ".yaml"); | ||
var plugins = Arrays.asList(Bukkit.getServer().getPluginManager().getPlugins()); | ||
plugins.sort(this::sortPluginABC); | ||
var debugInformation = new YamlConfiguration(); | ||
debugInformation.set("server.version", Bukkit.getVersion()); | ||
debugInformation.set("server.plugins", plugins.size()); | ||
for (Plugin plugin : plugins) { | ||
var name = plugin.getName(); | ||
debugInformation.set(String.format("server.plugin.%s.version", name), plugin.getDescription().getVersion()); | ||
debugInformation.set(String.format("server.plugin.%s.main", name), plugin.getDescription().getMain()); | ||
debugInformation.set(String.format("server.plugin.%s.authors", name), plugin.getDescription().getAuthors()); | ||
debugInformation.set(String.format("server.plugin.%s.load-before", name), plugin.getDescription().getLoadBefore()); | ||
debugInformation.set(String.format("server.plugin.%s.dependencies", name), plugin.getDescription().getDepend()); | ||
debugInformation.set(String.format("server.plugin.%s.soft-dependencies", name), plugin.getDescription().getSoftDepend()); | ||
debugInformation.set(String.format("server.plugin.%s.provides", name), plugin.getDescription().getProvides()); | ||
debugInformation.set(String.format("server.plugin.%s.enabled", name), plugin.isEnabled()); | ||
} | ||
if (PaperLib.isPaper()) { | ||
var dataPacks = Bukkit.getServer().getDatapackManager().getEnabledPacks(); | ||
debugInformation.set("server.datapacks.count", dataPacks.size()); | ||
debugInformation.set("server.datapacks.packs", dataPacks.stream().map(Datapack::getName).toList()); | ||
} | ||
var runtime = Runtime.getRuntime(); | ||
var rb = ManagementFactory.getRuntimeMXBean(); | ||
debugInformation.set("uptime", rb.getUptime()); | ||
debugInformation.set("jvm-flags", rb.getInputArguments()); | ||
debugInformation.set("free-memory", runtime.freeMemory()); | ||
debugInformation.set("max-memory", runtime.maxMemory()); | ||
debugInformation.set("total-memory", runtime.totalMemory()); | ||
debugInformation.set("available-processors", runtime.availableProcessors()); | ||
debugInformation.set("java-name", rb.getVmName()); | ||
debugInformation.set("java-version", System.getProperty("java.version")); | ||
debugInformation.set("java-vendor", System.getProperty("java.vendor")); | ||
debugInformation.set("operating-system", System.getProperty("os.name")); | ||
debugInformation.set("os-version", System.getProperty("os.version")); | ||
debugInformation.set("os-arch", System.getProperty("os.arch")); | ||
addYAML(debugInformation.saveToString(), "Default Paper Debug Information"); | ||
return this; | ||
} | ||
|
||
private int sortPluginABC(@NotNull Plugin A, @NotNull Plugin B) { | ||
return A.getName().compareTo(B.getName()); | ||
} | ||
|
||
/** | ||
* Creates a bukkit builder instance with the given bytebin server | ||
* | ||
* @param uploadServer bytebin server base url | ||
*/ | ||
public static BukkitDebugBuilder builder(String uploadServer) { | ||
return new BukkitDebugBuilder(uploadServer); | ||
} | ||
|
||
} |
77 changes: 0 additions & 77 deletions
77
bukkit-extension/src/main/kotlin/dev/themeinerlp/plugindebug/bukkitExtension.kt
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.