-
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
GH-90 Drop Spigot Support, move to one jar, fix compatibility with ot…
…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
Showing
60 changed files
with
392 additions
and
1,032 deletions.
There are no files selected for viewing
This file contains 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 |
---|---|---|
|
@@ -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 |
This file contains 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,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") | ||
} |
This file contains 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 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
6 changes: 3 additions & 3 deletions
6
.../eternalcode/formatter/ChatFormatter.java → ...ernalcode/formatter/ChatFormatterApi.java
This file contains 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 |
---|---|---|
@@ -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(); | ||
|
||
} |
23 changes: 23 additions & 0 deletions
23
chatformatter-core/src/main/java/com/eternalcode/formatter/ChatFormatterApiProvider.java
This file contains 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,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; | ||
} | ||
|
||
} |
File renamed without changes.
106 changes: 106 additions & 0 deletions
106
chatformatter-core/src/main/java/com/eternalcode/formatter/ChatFormatterPlugin.java
This file contains 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,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; | ||
} | ||
|
||
} |
9 changes: 9 additions & 0 deletions
9
chatformatter-core/src/main/java/com/eternalcode/formatter/ChatHandler.java
This file contains 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,9 @@ | ||
package com.eternalcode.formatter; | ||
|
||
import org.bukkit.event.Listener; | ||
|
||
public interface ChatHandler extends Listener { | ||
|
||
ChatRenderedMessage process(ChatMessage message); | ||
|
||
} |
Oops, something went wrong.