Skip to content

Commit

Permalink
GH-90 Drop Spigot Support, move to one jar, fix compatibility with ot…
Browse files Browse the repository at this point in the history
…her 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]>
  • Loading branch information
vLuckyyy and Rollczi authored Nov 13, 2023
1 parent dbbaef8 commit 1fb0fe7
Show file tree
Hide file tree
Showing 60 changed files with 392 additions and 1,032 deletions.
9 changes: 2 additions & 7 deletions .github/workflows/gradle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,9 @@ jobs:
- name: Build with Gradle
uses: gradle/gradle-build-action@62cce3c597efd445cd71ee868887b8b1117703a7
with:
arguments: core:shadowJar paper-support:shadowJar
arguments: shadowAll
- name: Upload a ChatFormatter Artifact
uses: actions/[email protected]
with:
name: 'Successfully build ChatFormatter'
path: core/build/libs/*.jar
- name: Upload a PaperSupport Artifact
uses: actions/[email protected]
with:
name: 'Successfully build PaperSupport'
path: paper-support/build/libs/*.jar
path: build/libs/ChatFormatter v*.jar
91 changes: 91 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
import java.io.FileOutputStream
import java.io.IOException
import java.util.jar.JarEntry
import java.util.jar.JarFile
import java.util.jar.JarOutputStream

plugins{
id("eternalcode.java")
id("com.github.johnrengelman.shadow")
id("xyz.jpenilla.run-paper") version "2.2.0"
}

tasks.create("shadowAll") {
group = "shadow"

val projects = listOf(
project(":chatformatter-core"),
project(":chatformatter-paper-plugin")
)

for (project in projects) {
dependsOn(project.name + ":shadowJar")
}

doLast {
merge("ChatFormatter v${project.version}.jar", projects)
}
}

fun merge(archiveFileName: String, projects: List<Project>) {
val outputFile = File(project.layout.buildDirectory.asFile.get(), "libs/${archiveFileName}")
val outputDir = outputFile.parentFile ?: throw RuntimeException("Could not get output directory")

if (!outputDir.exists() && !outputDir.mkdirs()) {
throw RuntimeException("Could not create output directory")
}

if (outputFile.exists()) {
outputFile.delete()
}

if (!outputFile.createNewFile()) {
throw RuntimeException("Could not find output file to merge")
}

JarOutputStream(FileOutputStream(outputFile)).use { outputJar ->
for (project in projects) {
val shadowJar = project.tasks.shadowJar.get()

for (file in shadowJar.outputs.files.files) {
JarFile(file).use { jarFile ->
for (entry in jarFile.entries()) {
if (entry.isDirectory) {
continue
}

val bytes = jarFile.getInputStream(entry).readBytes()
val newEntry = JarEntry(entry.name)

newEntry.setTime(System.currentTimeMillis())
newEntry.setSize(bytes.size.toLong())

try {
outputJar.putNextEntry(newEntry)
outputJar.write(bytes)
outputJar.closeEntry()
}
catch (exception: IOException) {
if (exception.message?.contains("duplicate entry: ") == true) {
continue
}

exception.printStackTrace()
}
}
}
}
}
}

}

runPaper {
disablePluginJarDetection()
}

tasks.runServer {
minecraftVersion("1.20.1")
dependsOn("shadowAll")
pluginJars = files("/build/libs/ChatFormatter v${project.version}.jar")
}
10 changes: 0 additions & 10 deletions buildSrc/src/main/kotlin/eternalcode.java.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,20 +1,10 @@
plugins {
`java-library`
checkstyle
}

group = "com.eternalcode"
version = "1.0.7"

checkstyle {
toolVersion = "10.12.3"

configFile = file("${rootDir}/config/checkstyle/checkstyle.xml")

maxErrors = 0
maxWarnings = 0
}

repositories {
mavenCentral()
maven { url = uri("https://hub.spigotmc.org/nexus/content/repositories/snapshots/") }
Expand Down
24 changes: 3 additions & 21 deletions core/build.gradle.kts → chatformatter-core/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,21 +1,6 @@
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar

plugins {
id("eternalcode.java")

id("com.github.johnrengelman.shadow")
id("net.minecrell.plugin-yml.bukkit")
id("xyz.jpenilla.run-paper") version "2.2.0"
}

bukkit {
main = "com.eternalcode.formatter.ChatFormatterPlugin"
apiVersion = "1.19"
prefix = "ChatFormatter"
author = "EternalCodeTeam"
name = "ChatFormatter"
version = "${project.version}"
depend = listOf("PlaceholderAPI", "Vault")
}

dependencies {
Expand Down Expand Up @@ -56,16 +41,12 @@ dependencies {
}

tasks {
runServer {
minecraftVersion("1.19.3")
}

withType<Test> {
useJUnitPlatform()
}

withType<ShadowJar> {
archiveFileName.set("ChatFormatter v${project.version}.jar")
shadowJar {
archiveFileName.set("chatformatter-core-${version}.jar")

exclude(
"org/intellij/lang/annotations/**",
Expand All @@ -78,6 +59,7 @@ tasks {

val prefix = "com.eternalcode.formatter.libs"
listOf(
"com.eternalcode.gitcheck",
"net.dzikoysk",
"dev.rollczi",
"panda",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
package com.eternalcode.formatter;

import com.eternalcode.formatter.rank.ChatRankProvider;
import com.eternalcode.formatter.template.TemplateService;
import com.eternalcode.formatter.placeholder.PlaceholderRegistry;
import com.eternalcode.formatter.preparatory.ChatPreparatoryService;

public interface ChatFormatter {
public interface ChatFormatterApi {

PlaceholderRegistry getPlaceholderRegistry();

TemplateService getTemplateService();

ChatRankProvider getRankProvider();

ChatPreparatoryService getChatPreparatoryService();
ChatHandler getChatHandler();

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.eternalcode.formatter;

public final class ChatFormatterApiProvider {

private static ChatFormatterApi chatFormatterAPI;

static void enable(ChatFormatterApi chatFormatterAPI) {
ChatFormatterApiProvider.chatFormatterAPI = chatFormatterAPI;
}

static void disable() {
ChatFormatterApiProvider.chatFormatterAPI = null;
}

public static ChatFormatterApi get() {
if (chatFormatterAPI == null) {
throw new IllegalStateException();
}

return chatFormatterAPI;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
package com.eternalcode.formatter;

import com.eternalcode.formatter.config.ConfigManager;
import com.eternalcode.formatter.config.PluginConfig;
import com.eternalcode.formatter.legacy.LegacyPostProcessor;
import com.eternalcode.formatter.legacy.LegacyPreProcessor;
import com.eternalcode.formatter.placeholder.PlaceholderAPIStack;
import com.eternalcode.formatter.rank.VaultRankProvider;
import com.eternalcode.formatter.rank.ChatRankProvider;
import com.eternalcode.formatter.template.TemplateService;
import com.eternalcode.formatter.placeholder.PlaceholderRegistry;
import com.eternalcode.formatter.updater.UpdaterController;
import com.eternalcode.formatter.updater.UpdaterService;
import com.google.common.base.Stopwatch;
import dev.rollczi.litecommands.LiteCommands;
import dev.rollczi.litecommands.bukkit.LiteBukkitFactory;
import net.kyori.adventure.platform.AudienceProvider;
import net.kyori.adventure.platform.bukkit.BukkitAudiences;
import net.kyori.adventure.text.minimessage.MiniMessage;
import org.bstats.bukkit.Metrics;
import org.bukkit.Server;
import org.bukkit.command.CommandSender;
import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.java.JavaPlugin;

import java.util.List;
import java.util.concurrent.TimeUnit;

public class ChatFormatterPlugin implements ChatFormatterApi {

private final PlaceholderRegistry placeholderRegistry;
private final TemplateService templateService;
private final ChatRankProvider rankProvider;
private final ChatHandler chatHandler;

private final LiteCommands<CommandSender> liteCommands;

public ChatFormatterPlugin(Plugin plugin) {
Server server = plugin.getServer();
Stopwatch stopwatch = Stopwatch.createStarted();

ConfigManager configManager = new ConfigManager(plugin.getDataFolder());
configManager.loadAndRenderConfigs();

PluginConfig pluginConfig = configManager.getPluginConfig();

this.placeholderRegistry = new PlaceholderRegistry();
this.placeholderRegistry.stack(pluginConfig);
this.placeholderRegistry.playerStack(new PlaceholderAPIStack());
this.templateService = new TemplateService(pluginConfig);
this.rankProvider = new VaultRankProvider(server);
UpdaterService updaterService = new UpdaterService(plugin.getDescription());

AudienceProvider audienceProvider = BukkitAudiences.create(plugin);
MiniMessage miniMessage = MiniMessage.builder()
.preProcessor(new LegacyPreProcessor())
.postProcessor(new LegacyPostProcessor())
.build();

this.liteCommands = LiteBukkitFactory.builder(server, "chat-formatter")
.commandInstance(new ChatFormatterCommand(configManager, audienceProvider, miniMessage))
.register();

// bStats metrics
new Metrics((JavaPlugin) plugin, 15199);

this.chatHandler = new ChatHandlerImpl(miniMessage, pluginConfig, this.rankProvider, this.placeholderRegistry, this.templateService);

List.of(
new UpdaterController(updaterService, pluginConfig, audienceProvider, miniMessage)
).forEach(listener -> server.getPluginManager().registerEvents(listener, plugin));

ChatFormatterApiProvider.enable(this);

plugin.getLogger().info("Plugin enabled in " + stopwatch.elapsed(TimeUnit.MILLISECONDS) + "ms");
}

public void close() {
ChatFormatterApiProvider.disable();

if (this.liteCommands != null) {
this.liteCommands.getPlatform().unregisterAll();
}
}

@Override
public PlaceholderRegistry getPlaceholderRegistry() {
return this.placeholderRegistry;
}

@Override
public TemplateService getTemplateService() {
return this.templateService;
}

@Override
public ChatRankProvider getRankProvider() {
return this.rankProvider;
}

@Override
public ChatHandler getChatHandler() {
return this.chatHandler;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.eternalcode.formatter;

import org.bukkit.event.Listener;

public interface ChatHandler extends Listener {

ChatRenderedMessage process(ChatMessage message);

}
Loading

0 comments on commit 1fb0fe7

Please sign in to comment.