Skip to content

Commit 7923804

Browse files
committed
Replace kotlin with java
1 parent 667e8f8 commit 7923804

3 files changed

Lines changed: 103 additions & 126 deletions

File tree

bukkit-extension/build.gradle.kts

Lines changed: 6 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,14 @@ import org.ajoberstar.grgit.Grgit
22
import java.util.*
33

44
plugins {
5-
kotlin("jvm") version "1.8.21"
5+
java
66
`java-library`
77
`maven-publish`
88
signing
9-
id("org.jetbrains.dokka") version "1.8.10"
109
}
1110

1211
group = "dev.themeinerlp"
13-
var baseVersion by extra("1.0.0")
12+
var baseVersion by extra("1.1.0")
1413
var extension by extra("")
1514
var snapshot by extra("-SNAPSHOT")
1615

@@ -34,58 +33,19 @@ dependencies {
3433
compileOnly(rootProject)
3534
compileOnly("io.papermc.paper:paper-api:1.19.4-R0.1-SNAPSHOT")
3635
implementation("io.papermc:paperlib:1.0.8")
37-
testImplementation(platform("org.junit:junit-bom:5.9.3"))
38-
testImplementation("org.junit.jupiter:junit-jupiter")
3936
}
4037

4138
tasks {
4239
test {
4340
useJUnitPlatform()
4441
}
4542

46-
dokkaHtml {
47-
dokkaSourceSets {
48-
named("main") {
49-
moduleName.set("Plugin Debug Bukkit Extension")
50-
description = "Extends the main api with some nice features for bukkit"
51-
version = "%s%s".format(Locale.ROOT, baseVersion, snapshot)
52-
}
53-
}
54-
}
55-
dokkaJavadoc {
56-
dokkaSourceSets {
57-
named("main") {
58-
moduleName.set("Plugin Debug Bukkit Extension")
59-
description = "Extends the main api with some nice features for bukkit"
60-
version = "%s%s".format(Locale.ROOT, baseVersion, snapshot)
61-
}
62-
}
63-
}
64-
}
6543

66-
kotlin {
67-
jvmToolchain(17)
68-
sourceSets.all {
69-
languageSettings {
70-
languageVersion = "2.0"
71-
}
72-
}
73-
}
74-
75-
val sourceJar by tasks.register<Jar>("kotlinJar") {
76-
from(sourceSets.main.get().allSource)
77-
archiveClassifier.set("sources")
7844
}
79-
val dokkaJavadocJar by tasks.register<Jar>("dokkaHtmlJar") {
80-
dependsOn(rootProject.tasks.dokkaHtml)
81-
from(rootProject.tasks.dokkaHtml.flatMap { it.outputDirectory })
82-
archiveClassifier.set("html-docs")
83-
}
84-
85-
val dokkaHtmlJar by tasks.register<Jar>("dokkaJavadocJar") {
86-
dependsOn(rootProject.tasks.dokkaJavadoc)
87-
from(rootProject.tasks.dokkaJavadoc.flatMap { it.outputDirectory })
88-
archiveClassifier.set("javadoc")
45+
java {
46+
toolchain {
47+
languageVersion.set(JavaLanguageVersion.of(17))
48+
}
8949
}
9050

9151
publishing {
@@ -95,9 +55,6 @@ publishing {
9555
groupId = "dev.themeinerlp.plugin-debug"
9656
artifactId = "bukkit-extension"
9757
version = "%s%s".format(Locale.ROOT, baseVersion, snapshot)
98-
artifact(dokkaJavadocJar)
99-
artifact(dokkaHtmlJar)
100-
artifact(sourceJar)
10158
pom {
10259
name.set("Bukkit Extension")
10360
description.set("The extension for bukkit/paper/spigot for plugin debug")
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
package dev.themeinerlp.plugindebug;
2+
3+
import io.papermc.lib.PaperLib;
4+
import io.papermc.paper.datapack.Datapack;
5+
import org.bukkit.Bukkit;
6+
import org.bukkit.configuration.file.YamlConfiguration;
7+
import org.bukkit.plugin.Plugin;
8+
import org.bukkit.plugin.java.JavaPlugin;
9+
import org.jetbrains.annotations.NotNull;
10+
11+
import java.io.IOException;
12+
import java.lang.management.ManagementFactory;
13+
import java.nio.file.Files;
14+
import java.nio.file.Path;
15+
import java.util.Arrays;
16+
import java.util.regex.Pattern;
17+
import java.util.stream.Collectors;
18+
19+
public final class BukkitDebugBuilder extends DebugBuilder<BukkitDebugBuilder> {
20+
21+
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");
22+
private BukkitDebugBuilder(String uploadServer) {
23+
super(uploadServer);
24+
}
25+
26+
/**
27+
* Collects the latest log file from bukkit
28+
* @return the builder
29+
* @throws IOException if the file empty/null
30+
*/
31+
public BukkitDebugBuilder collectLatestSpigotLog() throws IOException {
32+
var latestLogFile = Path.of("logs", "latest.log");
33+
if (Files.size(latestLogFile) >= maxZipFileSize) throw new IllegalStateException(
34+
String.format("Latest log file is to big only %d bytes allowed", maxZipFileSize)
35+
);
36+
var tempLogFile = Files.createTempFile(tempFile, ".log");
37+
var cleanedList = Files.readAllLines(latestLogFile).stream().map(s -> s.replaceAll(privacyRegex.pattern(), "*")).toList();
38+
Files.write(tempLogFile, cleanedList);
39+
addFile(tempLogFile, FileType.LOG, "Latest Log");
40+
return this;
41+
}
42+
43+
public BukkitDebugBuilder defaultPaperDebugInformation() throws IOException {
44+
var tempLogFile = Files.createTempFile(tempFile, ".yaml");
45+
var plugins = Arrays.asList(Bukkit.getServer().getPluginManager().getPlugins());
46+
plugins.sort(this::sortPluginABC);
47+
var debugInformation = new YamlConfiguration();
48+
debugInformation.set("server.version", Bukkit.getVersion());
49+
debugInformation.set("server.plugins", plugins.size());
50+
for (Plugin plugin : plugins) {
51+
var name = plugin.getName();
52+
debugInformation.set(String.format("server.plugin.%s.version", name), plugin.getDescription().getVersion());
53+
debugInformation.set(String.format("server.plugin.%s.main", name), plugin.getDescription().getMain());
54+
debugInformation.set(String.format("server.plugin.%s.authors", name), plugin.getDescription().getAuthors());
55+
debugInformation.set(String.format("server.plugin.%s.load-before", name), plugin.getDescription().getLoadBefore());
56+
debugInformation.set(String.format("server.plugin.%s.dependencies", name), plugin.getDescription().getDepend());
57+
debugInformation.set(String.format("server.plugin.%s.soft-dependencies", name), plugin.getDescription().getSoftDepend());
58+
debugInformation.set(String.format("server.plugin.%s.provides", name), plugin.getDescription().getProvides());
59+
debugInformation.set(String.format("server.plugin.%s.enabled", name), plugin.isEnabled());
60+
}
61+
if (PaperLib.isPaper()) {
62+
var dataPacks = Bukkit.getServer().getDatapackManager().getEnabledPacks();
63+
debugInformation.set("server.datapacks.count", dataPacks.size());
64+
debugInformation.set("server.datapacks.packs", dataPacks.stream().map(Datapack::getName).toList());
65+
}
66+
var runtime = Runtime.getRuntime();
67+
var rb = ManagementFactory.getRuntimeMXBean();
68+
debugInformation.set("uptime", rb.getUptime());
69+
debugInformation.set("jvm-flags", rb.getInputArguments());
70+
debugInformation.set("free-memory", runtime.freeMemory());
71+
debugInformation.set("max-memory", runtime.maxMemory());
72+
debugInformation.set("total-memory", runtime.totalMemory());
73+
debugInformation.set("available-processors", runtime.availableProcessors());
74+
debugInformation.set("java-name", rb.getVmName());
75+
debugInformation.set("java-version", System.getProperty("java.version"));
76+
debugInformation.set("java-vendor", System.getProperty("java.vendor"));
77+
debugInformation.set("operating-system", System.getProperty("os.name"));
78+
debugInformation.set("os-version", System.getProperty("os.version"));
79+
debugInformation.set("os-arch", System.getProperty("os.arch"));
80+
addYAML(debugInformation.saveToString(), "Default Paper Debug Information");
81+
return this;
82+
}
83+
84+
private int sortPluginABC(@NotNull Plugin A, @NotNull Plugin B) {
85+
return A.getName().compareTo(B.getName());
86+
}
87+
88+
/**
89+
* Creates a bukkit builder instance with the given bytebin server
90+
*
91+
* @param uploadServer bytebin server base url
92+
*/
93+
public static BukkitDebugBuilder builder(String uploadServer) {
94+
return new BukkitDebugBuilder(uploadServer);
95+
}
96+
97+
}

bukkit-extension/src/main/kotlin/dev/themeinerlp/plugindebug/bukkitExtension.kt

Lines changed: 0 additions & 77 deletions
This file was deleted.

0 commit comments

Comments
 (0)