-
-
Notifications
You must be signed in to change notification settings - Fork 6
GH-90 Drop Spigot Support, move to one jar, fix compatibility with other plugins. #95
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 all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
e8b21db
Remove spigot support.
Rollczi 8293cf4
Remove eternalcombat, fix plugin.yml
vLuckyyy 2bd624f
Improve shadowAll task, setup working `runServer` task
vLuckyyy 5c50283
Update CI
vLuckyyy 5f8e88c
Correct CI path.
vLuckyyy 1dc1733
Correct CI path.
vLuckyyy 1fb2a41
Remove unnecessary type.
vLuckyyy 69e7eee
Move shadowAll to main gradle plugin.
Rollczi 43d4c82
Revert to "default"
vLuckyyy 710aec2
Fix component serializing to message content.
Rollczi 2219a1f
Merge remote-tracking branch 'origin/drop-spiggoten-support' into dro…
Rollczi 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
| 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 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
6 changes: 3 additions & 3 deletions
6
.../eternalcode/formatter/ChatFormatter.java → ...ernalcode/formatter/ChatFormatterApi.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 |
|---|---|---|
| @@ -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 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,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 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,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 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,9 @@ | ||
| package com.eternalcode.formatter; | ||
|
|
||
| import org.bukkit.event.Listener; | ||
|
|
||
| public interface ChatHandler extends Listener { | ||
|
|
||
| ChatRenderedMessage process(ChatMessage message); | ||
|
|
||
| } |
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.