Skip to content

Commit 1fb0fe7

Browse files
vLuckyyyRollczi
andauthored
GH-90 Drop Spigot Support, move to one jar, fix compatibility with other plugins. (#95)
* Remove spigot support. * Remove eternalcombat, fix plugin.yml * Improve shadowAll task, setup working `runServer` task * Update CI * Correct CI path. * Correct CI path. * Remove unnecessary type. * Move shadowAll to main gradle plugin. * Revert to "default" * Fix component serializing to message content. --------- Co-authored-by: Rollczi <[email protected]>
1 parent dbbaef8 commit 1fb0fe7

File tree

60 files changed

+392
-1032
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

60 files changed

+392
-1032
lines changed

.github/workflows/gradle.yml

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,9 @@ jobs:
3434
- name: Build with Gradle
3535
uses: gradle/gradle-build-action@62cce3c597efd445cd71ee868887b8b1117703a7
3636
with:
37-
arguments: core:shadowJar paper-support:shadowJar
37+
arguments: shadowAll
3838
- name: Upload a ChatFormatter Artifact
3939
uses: actions/[email protected]
4040
with:
4141
name: 'Successfully build ChatFormatter'
42-
path: core/build/libs/*.jar
43-
- name: Upload a PaperSupport Artifact
44-
uses: actions/[email protected]
45-
with:
46-
name: 'Successfully build PaperSupport'
47-
path: paper-support/build/libs/*.jar
42+
path: build/libs/ChatFormatter v*.jar

build.gradle.kts

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
import java.io.FileOutputStream
2+
import java.io.IOException
3+
import java.util.jar.JarEntry
4+
import java.util.jar.JarFile
5+
import java.util.jar.JarOutputStream
6+
7+
plugins{
8+
id("eternalcode.java")
9+
id("com.github.johnrengelman.shadow")
10+
id("xyz.jpenilla.run-paper") version "2.2.0"
11+
}
12+
13+
tasks.create("shadowAll") {
14+
group = "shadow"
15+
16+
val projects = listOf(
17+
project(":chatformatter-core"),
18+
project(":chatformatter-paper-plugin")
19+
)
20+
21+
for (project in projects) {
22+
dependsOn(project.name + ":shadowJar")
23+
}
24+
25+
doLast {
26+
merge("ChatFormatter v${project.version}.jar", projects)
27+
}
28+
}
29+
30+
fun merge(archiveFileName: String, projects: List<Project>) {
31+
val outputFile = File(project.layout.buildDirectory.asFile.get(), "libs/${archiveFileName}")
32+
val outputDir = outputFile.parentFile ?: throw RuntimeException("Could not get output directory")
33+
34+
if (!outputDir.exists() && !outputDir.mkdirs()) {
35+
throw RuntimeException("Could not create output directory")
36+
}
37+
38+
if (outputFile.exists()) {
39+
outputFile.delete()
40+
}
41+
42+
if (!outputFile.createNewFile()) {
43+
throw RuntimeException("Could not find output file to merge")
44+
}
45+
46+
JarOutputStream(FileOutputStream(outputFile)).use { outputJar ->
47+
for (project in projects) {
48+
val shadowJar = project.tasks.shadowJar.get()
49+
50+
for (file in shadowJar.outputs.files.files) {
51+
JarFile(file).use { jarFile ->
52+
for (entry in jarFile.entries()) {
53+
if (entry.isDirectory) {
54+
continue
55+
}
56+
57+
val bytes = jarFile.getInputStream(entry).readBytes()
58+
val newEntry = JarEntry(entry.name)
59+
60+
newEntry.setTime(System.currentTimeMillis())
61+
newEntry.setSize(bytes.size.toLong())
62+
63+
try {
64+
outputJar.putNextEntry(newEntry)
65+
outputJar.write(bytes)
66+
outputJar.closeEntry()
67+
}
68+
catch (exception: IOException) {
69+
if (exception.message?.contains("duplicate entry: ") == true) {
70+
continue
71+
}
72+
73+
exception.printStackTrace()
74+
}
75+
}
76+
}
77+
}
78+
}
79+
}
80+
81+
}
82+
83+
runPaper {
84+
disablePluginJarDetection()
85+
}
86+
87+
tasks.runServer {
88+
minecraftVersion("1.20.1")
89+
dependsOn("shadowAll")
90+
pluginJars = files("/build/libs/ChatFormatter v${project.version}.jar")
91+
}

buildSrc/src/main/kotlin/eternalcode.java.gradle.kts

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,10 @@
11
plugins {
22
`java-library`
3-
checkstyle
43
}
54

65
group = "com.eternalcode"
76
version = "1.0.7"
87

9-
checkstyle {
10-
toolVersion = "10.12.3"
11-
12-
configFile = file("${rootDir}/config/checkstyle/checkstyle.xml")
13-
14-
maxErrors = 0
15-
maxWarnings = 0
16-
}
17-
188
repositories {
199
mavenCentral()
2010
maven { url = uri("https://hub.spigotmc.org/nexus/content/repositories/snapshots/") }

core/build.gradle.kts renamed to chatformatter-core/build.gradle.kts

Lines changed: 3 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,6 @@
1-
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
2-
31
plugins {
42
id("eternalcode.java")
5-
63
id("com.github.johnrengelman.shadow")
7-
id("net.minecrell.plugin-yml.bukkit")
8-
id("xyz.jpenilla.run-paper") version "2.2.0"
9-
}
10-
11-
bukkit {
12-
main = "com.eternalcode.formatter.ChatFormatterPlugin"
13-
apiVersion = "1.19"
14-
prefix = "ChatFormatter"
15-
author = "EternalCodeTeam"
16-
name = "ChatFormatter"
17-
version = "${project.version}"
18-
depend = listOf("PlaceholderAPI", "Vault")
194
}
205

216
dependencies {
@@ -56,16 +41,12 @@ dependencies {
5641
}
5742

5843
tasks {
59-
runServer {
60-
minecraftVersion("1.19.3")
61-
}
62-
6344
withType<Test> {
6445
useJUnitPlatform()
6546
}
6647

67-
withType<ShadowJar> {
68-
archiveFileName.set("ChatFormatter v${project.version}.jar")
48+
shadowJar {
49+
archiveFileName.set("chatformatter-core-${version}.jar")
6950

7051
exclude(
7152
"org/intellij/lang/annotations/**",
@@ -78,6 +59,7 @@ tasks {
7859

7960
val prefix = "com.eternalcode.formatter.libs"
8061
listOf(
62+
"com.eternalcode.gitcheck",
8163
"net.dzikoysk",
8264
"dev.rollczi",
8365
"panda",
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
package com.eternalcode.formatter;
22

3+
import com.eternalcode.formatter.rank.ChatRankProvider;
34
import com.eternalcode.formatter.template.TemplateService;
45
import com.eternalcode.formatter.placeholder.PlaceholderRegistry;
5-
import com.eternalcode.formatter.preparatory.ChatPreparatoryService;
66

7-
public interface ChatFormatter {
7+
public interface ChatFormatterApi {
88

99
PlaceholderRegistry getPlaceholderRegistry();
1010

1111
TemplateService getTemplateService();
1212

1313
ChatRankProvider getRankProvider();
1414

15-
ChatPreparatoryService getChatPreparatoryService();
15+
ChatHandler getChatHandler();
1616

1717
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package com.eternalcode.formatter;
2+
3+
public final class ChatFormatterApiProvider {
4+
5+
private static ChatFormatterApi chatFormatterAPI;
6+
7+
static void enable(ChatFormatterApi chatFormatterAPI) {
8+
ChatFormatterApiProvider.chatFormatterAPI = chatFormatterAPI;
9+
}
10+
11+
static void disable() {
12+
ChatFormatterApiProvider.chatFormatterAPI = null;
13+
}
14+
15+
public static ChatFormatterApi get() {
16+
if (chatFormatterAPI == null) {
17+
throw new IllegalStateException();
18+
}
19+
20+
return chatFormatterAPI;
21+
}
22+
23+
}
Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
package com.eternalcode.formatter;
2+
3+
import com.eternalcode.formatter.config.ConfigManager;
4+
import com.eternalcode.formatter.config.PluginConfig;
5+
import com.eternalcode.formatter.legacy.LegacyPostProcessor;
6+
import com.eternalcode.formatter.legacy.LegacyPreProcessor;
7+
import com.eternalcode.formatter.placeholder.PlaceholderAPIStack;
8+
import com.eternalcode.formatter.rank.VaultRankProvider;
9+
import com.eternalcode.formatter.rank.ChatRankProvider;
10+
import com.eternalcode.formatter.template.TemplateService;
11+
import com.eternalcode.formatter.placeholder.PlaceholderRegistry;
12+
import com.eternalcode.formatter.updater.UpdaterController;
13+
import com.eternalcode.formatter.updater.UpdaterService;
14+
import com.google.common.base.Stopwatch;
15+
import dev.rollczi.litecommands.LiteCommands;
16+
import dev.rollczi.litecommands.bukkit.LiteBukkitFactory;
17+
import net.kyori.adventure.platform.AudienceProvider;
18+
import net.kyori.adventure.platform.bukkit.BukkitAudiences;
19+
import net.kyori.adventure.text.minimessage.MiniMessage;
20+
import org.bstats.bukkit.Metrics;
21+
import org.bukkit.Server;
22+
import org.bukkit.command.CommandSender;
23+
import org.bukkit.plugin.Plugin;
24+
import org.bukkit.plugin.java.JavaPlugin;
25+
26+
import java.util.List;
27+
import java.util.concurrent.TimeUnit;
28+
29+
public class ChatFormatterPlugin implements ChatFormatterApi {
30+
31+
private final PlaceholderRegistry placeholderRegistry;
32+
private final TemplateService templateService;
33+
private final ChatRankProvider rankProvider;
34+
private final ChatHandler chatHandler;
35+
36+
private final LiteCommands<CommandSender> liteCommands;
37+
38+
public ChatFormatterPlugin(Plugin plugin) {
39+
Server server = plugin.getServer();
40+
Stopwatch stopwatch = Stopwatch.createStarted();
41+
42+
ConfigManager configManager = new ConfigManager(plugin.getDataFolder());
43+
configManager.loadAndRenderConfigs();
44+
45+
PluginConfig pluginConfig = configManager.getPluginConfig();
46+
47+
this.placeholderRegistry = new PlaceholderRegistry();
48+
this.placeholderRegistry.stack(pluginConfig);
49+
this.placeholderRegistry.playerStack(new PlaceholderAPIStack());
50+
this.templateService = new TemplateService(pluginConfig);
51+
this.rankProvider = new VaultRankProvider(server);
52+
UpdaterService updaterService = new UpdaterService(plugin.getDescription());
53+
54+
AudienceProvider audienceProvider = BukkitAudiences.create(plugin);
55+
MiniMessage miniMessage = MiniMessage.builder()
56+
.preProcessor(new LegacyPreProcessor())
57+
.postProcessor(new LegacyPostProcessor())
58+
.build();
59+
60+
this.liteCommands = LiteBukkitFactory.builder(server, "chat-formatter")
61+
.commandInstance(new ChatFormatterCommand(configManager, audienceProvider, miniMessage))
62+
.register();
63+
64+
// bStats metrics
65+
new Metrics((JavaPlugin) plugin, 15199);
66+
67+
this.chatHandler = new ChatHandlerImpl(miniMessage, pluginConfig, this.rankProvider, this.placeholderRegistry, this.templateService);
68+
69+
List.of(
70+
new UpdaterController(updaterService, pluginConfig, audienceProvider, miniMessage)
71+
).forEach(listener -> server.getPluginManager().registerEvents(listener, plugin));
72+
73+
ChatFormatterApiProvider.enable(this);
74+
75+
plugin.getLogger().info("Plugin enabled in " + stopwatch.elapsed(TimeUnit.MILLISECONDS) + "ms");
76+
}
77+
78+
public void close() {
79+
ChatFormatterApiProvider.disable();
80+
81+
if (this.liteCommands != null) {
82+
this.liteCommands.getPlatform().unregisterAll();
83+
}
84+
}
85+
86+
@Override
87+
public PlaceholderRegistry getPlaceholderRegistry() {
88+
return this.placeholderRegistry;
89+
}
90+
91+
@Override
92+
public TemplateService getTemplateService() {
93+
return this.templateService;
94+
}
95+
96+
@Override
97+
public ChatRankProvider getRankProvider() {
98+
return this.rankProvider;
99+
}
100+
101+
@Override
102+
public ChatHandler getChatHandler() {
103+
return this.chatHandler;
104+
}
105+
106+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package com.eternalcode.formatter;
2+
3+
import org.bukkit.event.Listener;
4+
5+
public interface ChatHandler extends Listener {
6+
7+
ChatRenderedMessage process(ChatMessage message);
8+
9+
}

0 commit comments

Comments
 (0)