diff --git a/build.gradle b/build.gradle index 1a92d3c..7343e74 100644 --- a/build.gradle +++ b/build.gradle @@ -19,7 +19,7 @@ static def determineVersion(String defaultVersion) { } group = 'dev.mikchan.mcnp' -version = determineVersion('2.1.1') +version = determineVersion('2.1.4') repositories { mavenCentral() diff --git a/src/main/java/dev/mikchan/mcnp/chat/FactorySelector.kt b/src/main/java/dev/mikchan/mcnp/chat/FactorySelector.kt index 0008b52..e115f4d 100644 --- a/src/main/java/dev/mikchan/mcnp/chat/FactorySelector.kt +++ b/src/main/java/dev/mikchan/mcnp/chat/FactorySelector.kt @@ -1,8 +1,17 @@ package dev.mikchan.mcnp.chat import dev.mikchan.mcnp.chat.contract.IChatPluginFactory -import dev.mikchan.mcnp.chat.implementation.pre19spigot.Pre19SpigotChatPluginFactory -import dev.mikchan.mcnp.chat.implementation.spigot.SpigotChatPluginFactory +import dev.mikchan.mcnp.chat.implementation.spigot.latest.SpigotLatestChatPluginFactory +import dev.mikchan.mcnp.chat.implementation.spigot.v1_16_5.SpigotV1m16p5ChatPluginFactory +import dev.mikchan.mcnp.chat.implementation.spigot.v1_17.SpigotV1m17ChatPluginFactory +import dev.mikchan.mcnp.chat.implementation.spigot.v1_17_1.SpigotV1m17p1ChatPluginFactory +import dev.mikchan.mcnp.chat.implementation.spigot.v1_18.SpigotV1m18ChatPluginFactory +import dev.mikchan.mcnp.chat.implementation.spigot.v1_18_1.SpigotV1m18p1ChatPluginFactory +import dev.mikchan.mcnp.chat.implementation.spigot.v1_18_2.SpigotV1m18p2ChatPluginFactory +import dev.mikchan.mcnp.chat.implementation.spigot.v1_19.SpigotV1m19ChatPluginFactory +import dev.mikchan.mcnp.chat.implementation.spigot.v1_19_1.SpigotV1m19p1ChatPluginFactory +import dev.mikchan.mcnp.chat.implementation.spigot.v1_19_2.SpigotV1m19p2ChatPluginFactory +import dev.mikchan.mcnp.chat.implementation.spigot.v1_19_3.SpigotV1m19p3ChatPluginFactory internal object FactorySelector { @@ -10,24 +19,52 @@ internal object FactorySelector { private class Version(val major: Int, val minor: Int, val patch: Int) private fun getVersion(plugin: ChatPlugin): Version? { - val versionRegex = Regex("""(\d+)\.(\d+)\.(\d+)""") + val versionRegex = Regex("""(\d+)\.(\d+)(?:\.(\d+))?""") val match = versionRegex.find(plugin.server.bukkitVersion) ?: return null val (sMajor, sMinor, sPatch) = match.destructured val major = sMajor.toIntOrNull() ?: return null val minor = sMinor.toIntOrNull() ?: return null - val patch = sPatch.toIntOrNull() ?: return null + val patch = sPatch.toIntOrNull() ?: 0 return Version(major, minor, patch) } fun selectFactory(plugin: ChatPlugin): IChatPluginFactory { - val version = getVersion(plugin) ?: return SpigotChatPluginFactory(plugin) + val version = getVersion(plugin) ?: return SpigotLatestChatPluginFactory(plugin) - if (version.major == 1 && version.minor < 19) { - return Pre19SpigotChatPluginFactory(plugin) - } + return when (version.major) { + 1 -> when (version.minor) { + 16 -> when (version.patch) { + 5 -> SpigotV1m16p5ChatPluginFactory(plugin) + else -> SpigotV1m16p5ChatPluginFactory(plugin) + } + + 17 -> when (version.patch) { + 0 -> SpigotV1m17ChatPluginFactory(plugin) + 1 -> SpigotV1m17p1ChatPluginFactory(plugin) + else -> SpigotV1m17p1ChatPluginFactory(plugin) + } + + 18 -> when (version.patch) { + 0 -> SpigotV1m18ChatPluginFactory(plugin) + 1 -> SpigotV1m18p1ChatPluginFactory(plugin) + 2 -> SpigotV1m18p2ChatPluginFactory(plugin) + else -> SpigotV1m18p2ChatPluginFactory(plugin) + } - return SpigotChatPluginFactory(plugin) + 19 -> when (version.patch) { + 0 -> SpigotV1m19ChatPluginFactory(plugin) + 1 -> SpigotV1m19p1ChatPluginFactory(plugin) + 2 -> SpigotV1m19p2ChatPluginFactory(plugin) + else -> SpigotV1m19p3ChatPluginFactory(plugin) + } + + else -> SpigotLatestChatPluginFactory(plugin) + } + + // Minecraft 2? + else -> SpigotLatestChatPluginFactory(plugin) + } } } diff --git a/src/main/java/dev/mikchan/mcnp/chat/contract/config/IConfig.kt b/src/main/java/dev/mikchan/mcnp/chat/contract/config/IConfig.kt index 0ebe2d0..376664f 100644 --- a/src/main/java/dev/mikchan/mcnp/chat/contract/config/IConfig.kt +++ b/src/main/java/dev/mikchan/mcnp/chat/contract/config/IConfig.kt @@ -71,13 +71,21 @@ interface IConfig { var privateTemplate: String /** - * The console private message template. + * The console to player private message template. * * This is the template which is used for private messages that were sent from the console. * Any `:player_to` will be replaced with [toTemplate], and `:message:` with the message text. */ var consoleTemplate: String + /** + * The player to console private message template. + * + * This is the template which is used for private messages that were sent from the console. + * Any `:player_from` will be replaced with [fromTemplate], and `:message:` with the message text. + */ + var fromConsoleTemplate: String + /** * The player name template. * diff --git a/src/main/java/dev/mikchan/mcnp/chat/contract/formatting/IFormatter.kt b/src/main/java/dev/mikchan/mcnp/chat/contract/formatting/IFormatter.kt index b4a33b1..653458f 100644 --- a/src/main/java/dev/mikchan/mcnp/chat/contract/formatting/IFormatter.kt +++ b/src/main/java/dev/mikchan/mcnp/chat/contract/formatting/IFormatter.kt @@ -18,7 +18,7 @@ interface IFormatter { fun formatPrivate(from: Player, to: Player, message: String): String /** - * Formats a private message sent from the console. + * Formats a private message sent from the console to player. * * @param to The player that receives the message. * @param message The text of the message. @@ -27,6 +27,16 @@ interface IFormatter { */ fun formatConsole(to: Player, message: String): String + /** + * Formats a private message sent from the console to player. + * + * @param from The player that sends the message. + * @param message The text of the message. + * + * @return The formatted message. + */ + fun formatToConsole(from: Player, message: String): String + /** * Formats a global message. * diff --git a/src/main/java/dev/mikchan/mcnp/chat/implementation/spigot/commands/SpigotCommandManager.kt b/src/main/java/dev/mikchan/mcnp/chat/implementation/base/commands/BaseCommandManager.kt similarity index 52% rename from src/main/java/dev/mikchan/mcnp/chat/implementation/spigot/commands/SpigotCommandManager.kt rename to src/main/java/dev/mikchan/mcnp/chat/implementation/base/commands/BaseCommandManager.kt index 92f40d2..f9f95fd 100644 --- a/src/main/java/dev/mikchan/mcnp/chat/implementation/spigot/commands/SpigotCommandManager.kt +++ b/src/main/java/dev/mikchan/mcnp/chat/implementation/base/commands/BaseCommandManager.kt @@ -1,18 +1,18 @@ -package dev.mikchan.mcnp.chat.implementation.spigot.commands +package dev.mikchan.mcnp.chat.implementation.base.commands import dev.mikchan.mcnp.chat.ChatPlugin -import dev.mikchan.mcnp.chat.implementation.spigot.commands.command.* import dev.mikchan.mcnp.chat.contract.commands.ICommandManager -internal class SpigotCommandManager(private val plugin: ChatPlugin) : ICommandManager { - private val messageHistory: MutableMap = mutableMapOf() +internal typealias MessageHistory = MutableMap +internal typealias CommandExecutors = Map - private val executors: Map = mapOf( - "mcn_chat" to ReloadCommand(plugin), - "msg" to MsgCommand(plugin, messageHistory), - "reply" to ReplyCommand(plugin, messageHistory), - "spy" to SpyCommand(plugin), - ) +internal open class BaseCommandManager( + private val plugin: ChatPlugin, + commandsBuilder: (plugin: ChatPlugin, messageHistory: MessageHistory) -> CommandExecutors, +) : ICommandManager { + private val messageHistory: MessageHistory = mutableMapOf() + + private val executors: CommandExecutors = commandsBuilder(plugin, messageHistory) override fun enableAll() { disableAll() diff --git a/src/main/java/dev/mikchan/mcnp/chat/implementation/spigot/commands/command/ICommand.kt b/src/main/java/dev/mikchan/mcnp/chat/implementation/base/commands/ICommand.kt similarity index 67% rename from src/main/java/dev/mikchan/mcnp/chat/implementation/spigot/commands/command/ICommand.kt rename to src/main/java/dev/mikchan/mcnp/chat/implementation/base/commands/ICommand.kt index d1a2bf9..dd413be 100644 --- a/src/main/java/dev/mikchan/mcnp/chat/implementation/spigot/commands/command/ICommand.kt +++ b/src/main/java/dev/mikchan/mcnp/chat/implementation/base/commands/ICommand.kt @@ -1,4 +1,4 @@ -package dev.mikchan.mcnp.chat.implementation.spigot.commands.command +package dev.mikchan.mcnp.chat.implementation.base.commands import org.bukkit.command.CommandExecutor import org.bukkit.command.TabCompleter diff --git a/src/main/java/dev/mikchan/mcnp/chat/implementation/spigot/events/SpigotEventManager.kt b/src/main/java/dev/mikchan/mcnp/chat/implementation/base/event/BaseEventManager.kt similarity index 55% rename from src/main/java/dev/mikchan/mcnp/chat/implementation/spigot/events/SpigotEventManager.kt rename to src/main/java/dev/mikchan/mcnp/chat/implementation/base/event/BaseEventManager.kt index d2dde97..51c033c 100644 --- a/src/main/java/dev/mikchan/mcnp/chat/implementation/spigot/events/SpigotEventManager.kt +++ b/src/main/java/dev/mikchan/mcnp/chat/implementation/base/event/BaseEventManager.kt @@ -1,17 +1,16 @@ -package dev.mikchan.mcnp.chat.implementation.spigot.events +package dev.mikchan.mcnp.chat.implementation.base.event import dev.mikchan.mcnp.chat.ChatPlugin import dev.mikchan.mcnp.chat.contract.events.IEventManager -import dev.mikchan.mcnp.chat.implementation.spigot.events.listeners.ChatListener -import dev.mikchan.mcnp.chat.implementation.spigot.events.listeners.MCNCListener import org.bukkit.event.HandlerList import org.bukkit.event.Listener -internal class SpigotEventManager(private val plugin: ChatPlugin) : IEventManager { - private val listeners: List = listOf( - ChatListener(plugin), - MCNCListener(plugin), - ) + +internal open class BaseEventManager( + private val plugin: ChatPlugin, + listenerBuilder: (plugin: ChatPlugin) -> List, +) : IEventManager { + private val listeners: List = listenerBuilder(plugin) override fun unregister() { HandlerList.unregisterAll(plugin) diff --git a/src/main/java/dev/mikchan/mcnp/chat/implementation/base/event/listeners/BaseChatListener.kt b/src/main/java/dev/mikchan/mcnp/chat/implementation/base/event/listeners/BaseChatListener.kt index 01c155f..cb6456b 100644 --- a/src/main/java/dev/mikchan/mcnp/chat/implementation/base/event/listeners/BaseChatListener.kt +++ b/src/main/java/dev/mikchan/mcnp/chat/implementation/base/event/listeners/BaseChatListener.kt @@ -14,7 +14,7 @@ internal open class BaseChatListener(private val plugin: ChatPlugin) { if (!event.player.hasPermission("mcn.chat.global") && !isPreview) throw NoPermissionException() val recipients = plugin.server.onlinePlayers.toSet() - val formattedMessage = plugin.formatter.formatGlobal(event.player, "%2\$s") + val formattedMessage = plugin.formatter.formatGlobal(event.player, msg) return MCNChatEvent(event.player, recipients, true, msg, formattedMessage, isPreview, event.isAsynchronous) } @@ -27,7 +27,7 @@ internal open class BaseChatListener(private val plugin: ChatPlugin) { val recipients = plugin.server.onlinePlayers.toList().filter { player -> player.world == event.player.world } .filter { player -> player.location.distance(event.player.location) < localRadius }.toSet() - val formattedMessage = plugin.formatter.formatLocal(event.player, "%2\$s") + val formattedMessage = plugin.formatter.formatLocal(event.player, msg) return MCNChatEvent(event.player, recipients, false, msg, formattedMessage, isPreview, event.isAsynchronous) } @@ -54,18 +54,16 @@ internal open class BaseChatListener(private val plugin: ChatPlugin) { if (plugin.config.substituteEvents) { if (!isPreview) { plugin.server.scheduler.scheduleSyncDelayedTask(plugin) { - val fMsg = String.format(mcncEvent.formattedMessage, mcncEvent.sender, mcncEvent.message) - plugin.server.consoleSender.sendMessage(fMsg) + plugin.server.consoleSender.sendMessage(mcncEvent.formattedMessage) for (recipient in mcncEvent.recipients) { - recipient.sendMessage(mcncEvent.sender.uniqueId, fMsg) + recipient.sendMessage(mcncEvent.sender.uniqueId, mcncEvent.formattedMessage) } } } return false } else { - event.message = mcncEvent.message - event.format = mcncEvent.formattedMessage + event.format = mcncEvent.formattedMessage.replace("%", "%%") event.recipients.clear() event.recipients.addAll(mcncEvent.recipients) diff --git a/src/main/java/dev/mikchan/mcnp/chat/implementation/base/formatting/BaseFormatter.kt b/src/main/java/dev/mikchan/mcnp/chat/implementation/base/formatting/BaseFormatter.kt index f43eaea..3b6eb6b 100644 --- a/src/main/java/dev/mikchan/mcnp/chat/implementation/base/formatting/BaseFormatter.kt +++ b/src/main/java/dev/mikchan/mcnp/chat/implementation/base/formatting/BaseFormatter.kt @@ -13,13 +13,10 @@ internal abstract class BaseFormatter(private val plugin: ChatPlugin) : IFormatt globalPlayer: () -> String?, localPlayer: () -> String?, spyPlayer: () -> String?, - preProcess: (s: String) -> String?, - postProcess: (s: String) -> String?, message: () -> String? ): String { var res = template - res = preProcess(res) ?: res res = ChatColor.translateAlternateColorCodes('&', res) if (res.contains(":player_from:")) { @@ -52,7 +49,6 @@ internal abstract class BaseFormatter(private val plugin: ChatPlugin) : IFormatt res = res.replace(":spy_player:", defPlayer) } - res = postProcess(res) ?: res if (res.contains(":message:")) { val msg = message() diff --git a/src/main/java/dev/mikchan/mcnp/chat/implementation/spigot/config/BoostedYamlConfig.kt b/src/main/java/dev/mikchan/mcnp/chat/implementation/boosted/config/BoostedYamlConfig.kt similarity index 93% rename from src/main/java/dev/mikchan/mcnp/chat/implementation/spigot/config/BoostedYamlConfig.kt rename to src/main/java/dev/mikchan/mcnp/chat/implementation/boosted/config/BoostedYamlConfig.kt index 960ba57..0262d24 100644 --- a/src/main/java/dev/mikchan/mcnp/chat/implementation/spigot/config/BoostedYamlConfig.kt +++ b/src/main/java/dev/mikchan/mcnp/chat/implementation/boosted/config/BoostedYamlConfig.kt @@ -1,4 +1,4 @@ -package dev.mikchan.mcnp.chat.implementation.spigot.config +package dev.mikchan.mcnp.chat.implementation.boosted.config import dev.dejvokep.boostedyaml.YamlDocument import dev.dejvokep.boostedyaml.dvs.versioning.BasicVersioning @@ -88,6 +88,13 @@ internal class BoostedYamlConfig(document: File, resource: InputStream) : IConfi config.save() } + override var fromConsoleTemplate: String + get() = config.getString("fromConsoleTemplate", "<:player_from: to CONSOLE> :message:") + set(value) { + config.set("fromConsoleTemplate", value) + config.save() + } + override var playerTemplate: String get() = config.getString("playerTemplate", "%player_name%") set(value) { diff --git a/src/main/java/dev/mikchan/mcnp/chat/implementation/fallback/config/FallbackConfig.kt b/src/main/java/dev/mikchan/mcnp/chat/implementation/fallback/config/FallbackConfig.kt index f32d762..cca36b9 100644 --- a/src/main/java/dev/mikchan/mcnp/chat/implementation/fallback/config/FallbackConfig.kt +++ b/src/main/java/dev/mikchan/mcnp/chat/implementation/fallback/config/FallbackConfig.kt @@ -66,6 +66,10 @@ internal class FallbackConfig : IConfig { override var consoleTemplate: String get() = " :message:" set(_) {} + + override var fromConsoleTemplate: String + get() = "<:player_from: to CONSOLE> :message:" + set(_) {} override var substituteEvents: Boolean get() = false diff --git a/src/main/java/dev/mikchan/mcnp/chat/implementation/fallback/formatting/FallbackFormatter.kt b/src/main/java/dev/mikchan/mcnp/chat/implementation/fallback/formatting/FallbackFormatter.kt index 9a05052..c046af4 100644 --- a/src/main/java/dev/mikchan/mcnp/chat/implementation/fallback/formatting/FallbackFormatter.kt +++ b/src/main/java/dev/mikchan/mcnp/chat/implementation/fallback/formatting/FallbackFormatter.kt @@ -6,88 +6,48 @@ import org.bukkit.ChatColor import org.bukkit.entity.Player internal class FallbackFormatter(private val plugin: ChatPlugin) : BaseFormatter(plugin) { - override fun formatPrivate(from: Player, to: Player, message: String): String { - return prepareTemplate(plugin.config.privateTemplate, - { "%1\$s" }, - { to.displayName }, - { "%1\$s" }, - { "%1\$s" }, - { "%1\$s" }, - { "%1\$s" }, - { it.replace("%", "%%") }, - { null }, - { - if (from.hasPermission("mcn.chat.colors")) ChatColor.translateAlternateColorCodes( + private fun format( + player: Player, + template: String, + message: String, + alwaysTranslateColors: Boolean = false, + to: (() -> String?)? = null + ): String { + val name = { player.displayName } + return prepareTemplate(template, name, to ?: name, name, name, name, name) { + if (alwaysTranslateColors || player.hasPermission("mcn.chat.colors")) { + ChatColor.translateAlternateColorCodes( '&', message - ) else ChatColor.stripColor(message) - }) + ) + } else { + ChatColor.stripColor(message) + } + } + } + + override fun formatPrivate(from: Player, to: Player, message: String): String { + return format(from, plugin.config.fromTemplate, message, to = { + to.displayName + }) } override fun formatConsole(to: Player, message: String): String { - return prepareTemplate(plugin.config.consoleTemplate, - { to.displayName }, - { to.displayName }, - { to.displayName }, - { to.displayName }, - { to.displayName }, - { to.displayName }, - { it.replace("%", "%%") }, - { null }, - { - ChatColor.translateAlternateColorCodes( - '&', message - ) - }) + return format(to, plugin.config.consoleTemplate, message, alwaysTranslateColors = true) + } + + override fun formatToConsole(from: Player, message: String): String { + return format(from, plugin.config.fromConsoleTemplate, message) } override fun formatGlobal(from: Player, message: String): String { - return prepareTemplate(plugin.config.globalTemplate, - { "%1\$s" }, - { "%1\$s" }, - { "%1\$s" }, - { "%1\$s" }, - { "%1\$s" }, - { "%1\$s" }, - { it.replace("%", "%%") }, - { null }, - { - if (from.hasPermission("mcn.chat.colors")) ChatColor.translateAlternateColorCodes( - '&', message - ) else ChatColor.stripColor(message) - }) + return format(from, plugin.config.globalTemplate, message) } override fun formatLocal(from: Player, message: String): String { - return prepareTemplate(plugin.config.localTemplate, - { "%1\$s" }, - { "%1\$s" }, - { "%1\$s" }, - { "%1\$s" }, - { "%1\$s" }, - { "%1\$s" }, - { it.replace("%", "%%") }, - { null }, - { - if (from.hasPermission("mcn.chat.colors")) ChatColor.translateAlternateColorCodes( - '&', message - ) else ChatColor.stripColor(message) - }) + return format(from, plugin.config.localTemplate, message) } override fun formatSpy(from: Player, message: String): String { - return prepareTemplate(plugin.config.spyTemplate, - { "%1\$s" }, - { "%1\$s" }, - { "%1\$s" }, - { "%1\$s" }, - { "%1\$s" }, - { "%1\$s" }, - { it.replace("%", "%%") }, - { null }, - { - if (from.hasPermission("mcn.chat.colors")) ChatColor.translateAlternateColorCodes( - '&', message - ) else ChatColor.stripColor(message) - }) + return format(from, plugin.config.spyTemplate, message) } } diff --git a/src/main/java/dev/mikchan/mcnp/chat/implementation/spigot/log/FileChatLogger.kt b/src/main/java/dev/mikchan/mcnp/chat/implementation/file/log/FileChatLogger.kt similarity index 97% rename from src/main/java/dev/mikchan/mcnp/chat/implementation/spigot/log/FileChatLogger.kt rename to src/main/java/dev/mikchan/mcnp/chat/implementation/file/log/FileChatLogger.kt index 30c4134..dc14ecc 100644 --- a/src/main/java/dev/mikchan/mcnp/chat/implementation/spigot/log/FileChatLogger.kt +++ b/src/main/java/dev/mikchan/mcnp/chat/implementation/file/log/FileChatLogger.kt @@ -1,4 +1,4 @@ -package dev.mikchan.mcnp.chat.implementation.spigot.log +package dev.mikchan.mcnp.chat.implementation.file.log import dev.mikchan.mcnp.chat.ChatPlugin import dev.mikchan.mcnp.chat.contract.log.IChatLogger diff --git a/src/main/java/dev/mikchan/mcnp/chat/implementation/papi/formatting/PAPIFormatter.kt b/src/main/java/dev/mikchan/mcnp/chat/implementation/papi/formatting/PAPIFormatter.kt new file mode 100644 index 0000000..a5a7aaa --- /dev/null +++ b/src/main/java/dev/mikchan/mcnp/chat/implementation/papi/formatting/PAPIFormatter.kt @@ -0,0 +1,67 @@ +package dev.mikchan.mcnp.chat.implementation.papi.formatting + +import dev.mikchan.mcnp.chat.ChatPlugin +import dev.mikchan.mcnp.chat.implementation.base.formatting.BaseFormatter +import me.clip.placeholderapi.PlaceholderAPI +import org.bukkit.ChatColor +import org.bukkit.entity.Player + +internal class PAPIFormatter(private val plugin: ChatPlugin) : BaseFormatter(plugin) { + private fun prepareColors(player: Player, template: String): String { + return ChatColor.translateAlternateColorCodes('&', PlaceholderAPI.setPlaceholders(player, template)) + } + + private fun format( + player: Player, + template: String, + message: String, + alwaysTranslateColors: Boolean = false, + to: (() -> String?)? = null, + ): String { + val colorize = { fieldTemplate: String -> { prepareColors(player, fieldTemplate) } } + + return prepareTemplate( + template, + colorize(plugin.config.fromTemplate), + to ?: colorize(plugin.config.toTemplate), + colorize(plugin.config.playerTemplate), + colorize(plugin.config.globalPlayerTemplate), + colorize(plugin.config.localPlayerTemplate), + colorize(plugin.config.spyPlayerTemplate) + ) { + if (alwaysTranslateColors || player.hasPermission("mcn.chat.colors")) { + ChatColor.translateAlternateColorCodes( + '&', message + ) + } else { + ChatColor.stripColor(message) + } + } + } + + override fun formatPrivate(from: Player, to: Player, message: String): String { + return format(from, plugin.config.privateTemplate, message, to = { + prepareColors(to, plugin.config.toTemplate) + }) + } + + override fun formatConsole(to: Player, message: String): String { + return format(to, plugin.config.consoleTemplate, message, alwaysTranslateColors = true) + } + + override fun formatToConsole(from: Player, message: String): String { + return format(from, plugin.config.fromConsoleTemplate, message) + } + + override fun formatGlobal(from: Player, message: String): String { + return format(from, plugin.config.globalTemplate, message) + } + + override fun formatLocal(from: Player, message: String): String { + return format(from, plugin.config.localTemplate, message) + } + + override fun formatSpy(from: Player, message: String): String { + return format(from, plugin.config.spyTemplate, message) + } +} diff --git a/src/main/java/dev/mikchan/mcnp/chat/implementation/pre19spigot/Pre19SpigotChatPluginFactory.kt b/src/main/java/dev/mikchan/mcnp/chat/implementation/pre19spigot/Pre19SpigotChatPluginFactory.kt deleted file mode 100644 index f9d5a8b..0000000 --- a/src/main/java/dev/mikchan/mcnp/chat/implementation/pre19spigot/Pre19SpigotChatPluginFactory.kt +++ /dev/null @@ -1,12 +0,0 @@ -package dev.mikchan.mcnp.chat.implementation.pre19spigot - -import dev.mikchan.mcnp.chat.ChatPlugin -import dev.mikchan.mcnp.chat.contract.events.IEventManager -import dev.mikchan.mcnp.chat.implementation.pre19spigot.events.Pre19SpigotEventManager -import dev.mikchan.mcnp.chat.implementation.spigot.SpigotChatPluginFactory - -internal class Pre19SpigotChatPluginFactory(val plugin: ChatPlugin) : SpigotChatPluginFactory(plugin) { - override fun createEventManager(): IEventManager { - return Pre19SpigotEventManager(plugin) - } -} diff --git a/src/main/java/dev/mikchan/mcnp/chat/implementation/pre19spigot/events/Pre19SpigotEventManager.kt b/src/main/java/dev/mikchan/mcnp/chat/implementation/pre19spigot/events/Pre19SpigotEventManager.kt deleted file mode 100644 index a6d327d..0000000 --- a/src/main/java/dev/mikchan/mcnp/chat/implementation/pre19spigot/events/Pre19SpigotEventManager.kt +++ /dev/null @@ -1,28 +0,0 @@ -package dev.mikchan.mcnp.chat.implementation.pre19spigot.events - -import dev.mikchan.mcnp.chat.ChatPlugin -import dev.mikchan.mcnp.chat.contract.events.IEventManager -import dev.mikchan.mcnp.chat.implementation.pre19spigot.events.listeners.Pre19SpigotChatListener -import dev.mikchan.mcnp.chat.implementation.spigot.events.listeners.MCNCListener -import org.bukkit.event.HandlerList -import org.bukkit.event.Listener - -internal class Pre19SpigotEventManager(private val plugin: ChatPlugin) : IEventManager { - private val listeners: List = listOf( - Pre19SpigotChatListener(plugin), - MCNCListener(plugin), - ) - - override fun unregister() { - HandlerList.unregisterAll(plugin) - } - - override fun register() { - unregister() - - val pluginManager = plugin.server.pluginManager - for (listener in listeners) { - pluginManager.registerEvents(listener, plugin) - } - } -} diff --git a/src/main/java/dev/mikchan/mcnp/chat/implementation/spigot/formatting/PAPIFormatter.kt b/src/main/java/dev/mikchan/mcnp/chat/implementation/spigot/formatting/PAPIFormatter.kt deleted file mode 100644 index 7f7e6ae..0000000 --- a/src/main/java/dev/mikchan/mcnp/chat/implementation/spigot/formatting/PAPIFormatter.kt +++ /dev/null @@ -1,130 +0,0 @@ -package dev.mikchan.mcnp.chat.implementation.spigot.formatting - -import dev.mikchan.mcnp.chat.ChatPlugin -import dev.mikchan.mcnp.chat.implementation.base.formatting.BaseFormatter -import me.clip.placeholderapi.PlaceholderAPI -import org.bukkit.ChatColor -import org.bukkit.entity.Player - -internal class PAPIFormatter(private val plugin: ChatPlugin) : BaseFormatter(plugin) { - private fun prepareFromPlayer(player: Player): String { - return ChatColor.translateAlternateColorCodes( - '&', PlaceholderAPI.setPlaceholders(player, plugin.config.fromTemplate) - ) - } - - private fun prepareToPlayer(player: Player): String { - return ChatColor.translateAlternateColorCodes( - '&', PlaceholderAPI.setPlaceholders(player, plugin.config.toTemplate) - ) - } - - private fun preparePlayer(player: Player): String { - return ChatColor.translateAlternateColorCodes( - '&', PlaceholderAPI.setPlaceholders(player, plugin.config.playerTemplate) - ) - } - - private fun prepareGlobalPlayer(player: Player): String { - return ChatColor.translateAlternateColorCodes( - '&', PlaceholderAPI.setPlaceholders(player, plugin.config.globalPlayerTemplate) - ) - } - - private fun prepareLocalPlayer(player: Player): String { - return ChatColor.translateAlternateColorCodes( - '&', PlaceholderAPI.setPlaceholders(player, plugin.config.localPlayerTemplate) - ) - } - - private fun prepareSpyPlayer(player: Player): String { - return ChatColor.translateAlternateColorCodes( - '&', PlaceholderAPI.setPlaceholders(player, plugin.config.spyPlayerTemplate) - ) - } - - override fun formatPrivate(from: Player, to: Player, message: String): String { - return prepareTemplate(plugin.config.privateTemplate, - { prepareFromPlayer(from) }, - { prepareToPlayer(to) }, - { preparePlayer(from) }, - { prepareGlobalPlayer(from) }, - { prepareLocalPlayer(from) }, - { prepareSpyPlayer(from) }, - { null }, - { it.replace("%", "%%") }, - { - if (from.hasPermission("mcn.chat.colors")) ChatColor.translateAlternateColorCodes( - '&', message - ) else ChatColor.stripColor(message) - }) - } - - override fun formatConsole(to: Player, message: String): String { - return prepareTemplate(plugin.config.consoleTemplate, - { prepareFromPlayer(to) }, - { prepareToPlayer(to) }, - { preparePlayer(to) }, - { prepareGlobalPlayer(to) }, - { prepareLocalPlayer(to) }, - { prepareSpyPlayer(to) }, - { null }, - { it.replace("%", "%%") }, - { - ChatColor.translateAlternateColorCodes( - '&', message - ) - }) - } - - override fun formatGlobal(from: Player, message: String): String { - return prepareTemplate(plugin.config.globalTemplate, - { prepareFromPlayer(from) }, - { prepareToPlayer(from) }, - { preparePlayer(from) }, - { prepareGlobalPlayer(from) }, - { prepareLocalPlayer(from) }, - { prepareSpyPlayer(from) }, - { null }, - { it.replace("%", "%%") }, - { - if (from.hasPermission("mcn.chat.colors")) ChatColor.translateAlternateColorCodes( - '&', message - ) else ChatColor.stripColor(message) - }) - } - - override fun formatLocal(from: Player, message: String): String { - return prepareTemplate(plugin.config.localTemplate, - { prepareFromPlayer(from) }, - { prepareToPlayer(from) }, - { preparePlayer(from) }, - { prepareGlobalPlayer(from) }, - { prepareLocalPlayer(from) }, - { prepareSpyPlayer(from) }, - { null }, - { it.replace("%", "%%") }, - { - if (from.hasPermission("mcn.chat.colors")) ChatColor.translateAlternateColorCodes( - '&', message - ) else ChatColor.stripColor(message) - }) - } - - override fun formatSpy(from: Player, message: String): String { - return prepareTemplate(plugin.config.spyTemplate, - { prepareFromPlayer(from) }, - { prepareToPlayer(from) }, - { preparePlayer(from) }, - { prepareGlobalPlayer(from) }, - { prepareLocalPlayer(from) }, - { prepareSpyPlayer(from) }, - { null }, - { it.replace("%", "%%") }, - { - if (from.hasPermission("mcn.chat.colors")) ChatColor.translateAlternateColorCodes( - '&', message - ) else ChatColor.stripColor(message) - }) - } -} diff --git a/src/main/java/dev/mikchan/mcnp/chat/implementation/spigot/keys/SpigotKeys.kt b/src/main/java/dev/mikchan/mcnp/chat/implementation/spigot/keys/SpigotKeys.kt deleted file mode 100644 index 535334d..0000000 --- a/src/main/java/dev/mikchan/mcnp/chat/implementation/spigot/keys/SpigotKeys.kt +++ /dev/null @@ -1,9 +0,0 @@ -package dev.mikchan.mcnp.chat.implementation.spigot.keys - -import dev.mikchan.mcnp.chat.ChatPlugin -import dev.mikchan.mcnp.chat.contract.keys.IKeys -import org.bukkit.persistence.PersistentDataType - -internal class SpigotKeys(plugin: ChatPlugin) : IKeys { - override val spy = SpigotKey(plugin, "spy", PersistentDataType.BYTE) -} diff --git a/src/main/java/dev/mikchan/mcnp/chat/implementation/spigot/latest/SpigotLatestChatPluginFactory.kt b/src/main/java/dev/mikchan/mcnp/chat/implementation/spigot/latest/SpigotLatestChatPluginFactory.kt new file mode 100644 index 0000000..225c6ad --- /dev/null +++ b/src/main/java/dev/mikchan/mcnp/chat/implementation/spigot/latest/SpigotLatestChatPluginFactory.kt @@ -0,0 +1,6 @@ +package dev.mikchan.mcnp.chat.implementation.spigot.latest + +import dev.mikchan.mcnp.chat.ChatPlugin +import dev.mikchan.mcnp.chat.implementation.spigot.v1_19_3.SpigotV1m19p3ChatPluginFactory + +internal class SpigotLatestChatPluginFactory(plugin: ChatPlugin) : SpigotV1m19p3ChatPluginFactory(plugin) diff --git a/src/main/java/dev/mikchan/mcnp/chat/implementation/spigot/SpigotChatPluginFactory.kt b/src/main/java/dev/mikchan/mcnp/chat/implementation/spigot/v1_16_5/SpigotV1m16p5ChatPluginFactory.kt similarity index 64% rename from src/main/java/dev/mikchan/mcnp/chat/implementation/spigot/SpigotChatPluginFactory.kt rename to src/main/java/dev/mikchan/mcnp/chat/implementation/spigot/v1_16_5/SpigotV1m16p5ChatPluginFactory.kt index 21595c9..b9fb081 100644 --- a/src/main/java/dev/mikchan/mcnp/chat/implementation/spigot/SpigotChatPluginFactory.kt +++ b/src/main/java/dev/mikchan/mcnp/chat/implementation/spigot/v1_16_5/SpigotV1m16p5ChatPluginFactory.kt @@ -1,4 +1,4 @@ -package dev.mikchan.mcnp.chat.implementation.spigot +package dev.mikchan.mcnp.chat.implementation.spigot.v1_16_5 import dev.mikchan.mcnp.chat.ChatPlugin import dev.mikchan.mcnp.chat.contract.IChatPluginFactory @@ -9,19 +9,19 @@ import dev.mikchan.mcnp.chat.contract.formatting.IFormatter import dev.mikchan.mcnp.chat.contract.keys.IKeys import dev.mikchan.mcnp.chat.contract.log.IChatLogger import dev.mikchan.mcnp.chat.contract.users.IUserManager +import dev.mikchan.mcnp.chat.implementation.boosted.config.BoostedYamlConfig import dev.mikchan.mcnp.chat.implementation.fallback.config.FallbackConfig import dev.mikchan.mcnp.chat.implementation.fallback.formatting.FallbackFormatter -import dev.mikchan.mcnp.chat.implementation.spigot.commands.SpigotCommandManager -import dev.mikchan.mcnp.chat.implementation.spigot.config.BoostedYamlConfig -import dev.mikchan.mcnp.chat.implementation.spigot.events.SpigotEventManager -import dev.mikchan.mcnp.chat.implementation.spigot.formatting.PAPIFormatter -import dev.mikchan.mcnp.chat.implementation.spigot.keys.SpigotKeys -import dev.mikchan.mcnp.chat.implementation.spigot.log.FileChatLogger -import dev.mikchan.mcnp.chat.implementation.spigot.users.SpigotUserManager +import dev.mikchan.mcnp.chat.implementation.file.log.FileChatLogger +import dev.mikchan.mcnp.chat.implementation.papi.formatting.PAPIFormatter +import dev.mikchan.mcnp.chat.implementation.spigot.v1_16_5.commands.SpigotV1m16p5CommandManager +import dev.mikchan.mcnp.chat.implementation.spigot.v1_16_5.events.SpigotV1m16p5EventManager +import dev.mikchan.mcnp.chat.implementation.spigot.v1_16_5.keys.SpigotV1m16p5Keys +import dev.mikchan.mcnp.chat.implementation.spigot.v1_16_5.users.SpigotV1m16p5UserManager import me.clip.placeholderapi.PlaceholderAPIPlugin import java.io.File -internal open class SpigotChatPluginFactory(private val plugin: ChatPlugin) : IChatPluginFactory { +internal open class SpigotV1m16p5ChatPluginFactory(private val plugin: ChatPlugin) : IChatPluginFactory { override fun createConfig(): IConfig { val resource = plugin.getResource("config.yml") @@ -33,11 +33,11 @@ internal open class SpigotChatPluginFactory(private val plugin: ChatPlugin) : IC } override fun createCommandManager(): ICommandManager { - return SpigotCommandManager(plugin) + return SpigotV1m16p5CommandManager(plugin) } override fun createEventManager(): IEventManager { - return SpigotEventManager(plugin) + return SpigotV1m16p5EventManager(plugin) } override fun createFormatter(): IFormatter { @@ -53,11 +53,11 @@ internal open class SpigotChatPluginFactory(private val plugin: ChatPlugin) : IC } override fun createKeys(): IKeys { - return SpigotKeys(plugin) + return SpigotV1m16p5Keys(plugin) } override fun createUserManager(): IUserManager { - return SpigotUserManager(plugin) + return SpigotV1m16p5UserManager(plugin) } override fun createChatLogger(): IChatLogger { diff --git a/src/main/java/dev/mikchan/mcnp/chat/implementation/spigot/v1_16_5/commands/SpigotV1m16p5CommandManager.kt b/src/main/java/dev/mikchan/mcnp/chat/implementation/spigot/v1_16_5/commands/SpigotV1m16p5CommandManager.kt new file mode 100644 index 0000000..8eea7d2 --- /dev/null +++ b/src/main/java/dev/mikchan/mcnp/chat/implementation/spigot/v1_16_5/commands/SpigotV1m16p5CommandManager.kt @@ -0,0 +1,20 @@ +package dev.mikchan.mcnp.chat.implementation.spigot.v1_16_5.commands + +import dev.mikchan.mcnp.chat.ChatPlugin +import dev.mikchan.mcnp.chat.implementation.base.commands.BaseCommandManager +import dev.mikchan.mcnp.chat.implementation.spigot.v1_16_5.commands.command.MsgCommand +import dev.mikchan.mcnp.chat.implementation.spigot.v1_16_5.commands.command.ReloadCommand +import dev.mikchan.mcnp.chat.implementation.spigot.v1_16_5.commands.command.ReplyCommand +import dev.mikchan.mcnp.chat.implementation.spigot.v1_16_5.commands.command.SpyCommand + +internal class SpigotV1m16p5CommandManager(chatPlugin: ChatPlugin) : BaseCommandManager( + chatPlugin, + { plugin, messageHistory -> + mapOf( + "mcn_chat" to ReloadCommand(plugin), + "msg" to MsgCommand(plugin, messageHistory), + "reply" to ReplyCommand(plugin, messageHistory), + "spy" to SpyCommand(plugin), + ) + }, +) diff --git a/src/main/java/dev/mikchan/mcnp/chat/implementation/spigot/commands/command/MsgCommand.kt b/src/main/java/dev/mikchan/mcnp/chat/implementation/spigot/v1_16_5/commands/command/MsgCommand.kt similarity index 93% rename from src/main/java/dev/mikchan/mcnp/chat/implementation/spigot/commands/command/MsgCommand.kt rename to src/main/java/dev/mikchan/mcnp/chat/implementation/spigot/v1_16_5/commands/command/MsgCommand.kt index a3f9a36..3931040 100644 --- a/src/main/java/dev/mikchan/mcnp/chat/implementation/spigot/commands/command/MsgCommand.kt +++ b/src/main/java/dev/mikchan/mcnp/chat/implementation/spigot/v1_16_5/commands/command/MsgCommand.kt @@ -1,6 +1,7 @@ -package dev.mikchan.mcnp.chat.implementation.spigot.commands.command +package dev.mikchan.mcnp.chat.implementation.spigot.v1_16_5.commands.command import dev.mikchan.mcnp.chat.ChatPlugin +import dev.mikchan.mcnp.chat.implementation.base.commands.ICommand import org.bukkit.ChatColor import org.bukkit.command.Command import org.bukkit.command.CommandSender diff --git a/src/main/java/dev/mikchan/mcnp/chat/implementation/spigot/commands/command/ReloadCommand.kt b/src/main/java/dev/mikchan/mcnp/chat/implementation/spigot/v1_16_5/commands/command/ReloadCommand.kt similarity index 89% rename from src/main/java/dev/mikchan/mcnp/chat/implementation/spigot/commands/command/ReloadCommand.kt rename to src/main/java/dev/mikchan/mcnp/chat/implementation/spigot/v1_16_5/commands/command/ReloadCommand.kt index 1d8ca4f..9701b6f 100644 --- a/src/main/java/dev/mikchan/mcnp/chat/implementation/spigot/commands/command/ReloadCommand.kt +++ b/src/main/java/dev/mikchan/mcnp/chat/implementation/spigot/v1_16_5/commands/command/ReloadCommand.kt @@ -1,6 +1,7 @@ -package dev.mikchan.mcnp.chat.implementation.spigot.commands.command +package dev.mikchan.mcnp.chat.implementation.spigot.v1_16_5.commands.command import dev.mikchan.mcnp.chat.ChatPlugin +import dev.mikchan.mcnp.chat.implementation.base.commands.ICommand import net.md_5.bungee.api.ChatColor import org.bukkit.command.Command import org.bukkit.command.CommandSender diff --git a/src/main/java/dev/mikchan/mcnp/chat/implementation/spigot/commands/command/ReplyCommand.kt b/src/main/java/dev/mikchan/mcnp/chat/implementation/spigot/v1_16_5/commands/command/ReplyCommand.kt similarity index 92% rename from src/main/java/dev/mikchan/mcnp/chat/implementation/spigot/commands/command/ReplyCommand.kt rename to src/main/java/dev/mikchan/mcnp/chat/implementation/spigot/v1_16_5/commands/command/ReplyCommand.kt index 1739995..2eafb34 100644 --- a/src/main/java/dev/mikchan/mcnp/chat/implementation/spigot/commands/command/ReplyCommand.kt +++ b/src/main/java/dev/mikchan/mcnp/chat/implementation/spigot/v1_16_5/commands/command/ReplyCommand.kt @@ -1,6 +1,7 @@ -package dev.mikchan.mcnp.chat.implementation.spigot.commands.command +package dev.mikchan.mcnp.chat.implementation.spigot.v1_16_5.commands.command import dev.mikchan.mcnp.chat.ChatPlugin +import dev.mikchan.mcnp.chat.implementation.base.commands.ICommand import org.bukkit.ChatColor import org.bukkit.command.Command import org.bukkit.command.CommandSender @@ -35,8 +36,7 @@ internal class ReplyCommand(private val plugin: ChatPlugin, private val history: } else if (recipient is Player && sender !is Player) { plugin.formatter.formatConsole(recipient, msg) } else if (sender is Player) { - // TODO: Add formatFromConsole - plugin.formatter.formatGlobal(sender, msg) + plugin.formatter.formatToConsole(sender, msg) } else { return false } diff --git a/src/main/java/dev/mikchan/mcnp/chat/implementation/spigot/commands/command/SpyCommand.kt b/src/main/java/dev/mikchan/mcnp/chat/implementation/spigot/v1_16_5/commands/command/SpyCommand.kt similarity index 88% rename from src/main/java/dev/mikchan/mcnp/chat/implementation/spigot/commands/command/SpyCommand.kt rename to src/main/java/dev/mikchan/mcnp/chat/implementation/spigot/v1_16_5/commands/command/SpyCommand.kt index ec524a4..7e7ff8e 100644 --- a/src/main/java/dev/mikchan/mcnp/chat/implementation/spigot/commands/command/SpyCommand.kt +++ b/src/main/java/dev/mikchan/mcnp/chat/implementation/spigot/v1_16_5/commands/command/SpyCommand.kt @@ -1,12 +1,13 @@ -package dev.mikchan.mcnp.chat.implementation.spigot.commands.command +package dev.mikchan.mcnp.chat.implementation.spigot.v1_16_5.commands.command import dev.mikchan.mcnp.chat.ChatPlugin +import dev.mikchan.mcnp.chat.implementation.base.commands.ICommand import org.bukkit.ChatColor import org.bukkit.command.Command import org.bukkit.command.CommandSender import org.bukkit.entity.Player -class SpyCommand(private val plugin: ChatPlugin) : ICommand { +internal class SpyCommand(private val plugin: ChatPlugin) : ICommand { override fun onCommand(sender: CommandSender, command: Command, label: String, args: Array): Boolean { val player = sender as? Player diff --git a/src/main/java/dev/mikchan/mcnp/chat/implementation/spigot/v1_16_5/events/SpigotV1m16p5EventManager.kt b/src/main/java/dev/mikchan/mcnp/chat/implementation/spigot/v1_16_5/events/SpigotV1m16p5EventManager.kt new file mode 100644 index 0000000..d022baf --- /dev/null +++ b/src/main/java/dev/mikchan/mcnp/chat/implementation/spigot/v1_16_5/events/SpigotV1m16p5EventManager.kt @@ -0,0 +1,16 @@ +package dev.mikchan.mcnp.chat.implementation.spigot.v1_16_5.events + +import dev.mikchan.mcnp.chat.ChatPlugin +import dev.mikchan.mcnp.chat.implementation.base.event.BaseEventManager +import dev.mikchan.mcnp.chat.implementation.spigot.v1_16_5.events.listeners.SpigotV1m16p5ChatListener +import dev.mikchan.mcnp.chat.implementation.spigot.v1_16_5.events.listeners.SpigotV1m16p5MCNCListener + +internal class SpigotV1m16p5EventManager(chatPlugin: ChatPlugin) : BaseEventManager( + chatPlugin, + { plugin -> + listOf( + SpigotV1m16p5ChatListener(plugin), + SpigotV1m16p5MCNCListener(plugin), + ) + }, +) diff --git a/src/main/java/dev/mikchan/mcnp/chat/implementation/pre19spigot/events/listeners/Pre19SpigotChatListener.kt b/src/main/java/dev/mikchan/mcnp/chat/implementation/spigot/v1_16_5/events/listeners/SpigotV1m16p5ChatListener.kt similarity index 73% rename from src/main/java/dev/mikchan/mcnp/chat/implementation/pre19spigot/events/listeners/Pre19SpigotChatListener.kt rename to src/main/java/dev/mikchan/mcnp/chat/implementation/spigot/v1_16_5/events/listeners/SpigotV1m16p5ChatListener.kt index 3d0ec2e..fb1e01f 100644 --- a/src/main/java/dev/mikchan/mcnp/chat/implementation/pre19spigot/events/listeners/Pre19SpigotChatListener.kt +++ b/src/main/java/dev/mikchan/mcnp/chat/implementation/spigot/v1_16_5/events/listeners/SpigotV1m16p5ChatListener.kt @@ -1,4 +1,4 @@ -package dev.mikchan.mcnp.chat.implementation.pre19spigot.events.listeners +package dev.mikchan.mcnp.chat.implementation.spigot.v1_16_5.events.listeners import dev.mikchan.mcnp.chat.ChatPlugin import dev.mikchan.mcnp.chat.implementation.base.event.listeners.BaseChatListener @@ -7,7 +7,7 @@ import org.bukkit.event.EventPriority import org.bukkit.event.Listener import org.bukkit.event.player.AsyncPlayerChatEvent -internal class Pre19SpigotChatListener(plugin: ChatPlugin) : BaseChatListener(plugin), Listener { +internal class SpigotV1m16p5ChatListener(plugin: ChatPlugin) : BaseChatListener(plugin), Listener { @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) fun onAsyncMessage(event: AsyncPlayerChatEvent) { if (!handleChatEvent(event, false)) event.isCancelled = true diff --git a/src/main/java/dev/mikchan/mcnp/chat/implementation/spigot/events/listeners/MCNCListener.kt b/src/main/java/dev/mikchan/mcnp/chat/implementation/spigot/v1_16_5/events/listeners/SpigotV1m16p5MCNCListener.kt similarity index 91% rename from src/main/java/dev/mikchan/mcnp/chat/implementation/spigot/events/listeners/MCNCListener.kt rename to src/main/java/dev/mikchan/mcnp/chat/implementation/spigot/v1_16_5/events/listeners/SpigotV1m16p5MCNCListener.kt index 4d1fb30..0b028c2 100644 --- a/src/main/java/dev/mikchan/mcnp/chat/implementation/spigot/events/listeners/MCNCListener.kt +++ b/src/main/java/dev/mikchan/mcnp/chat/implementation/spigot/v1_16_5/events/listeners/SpigotV1m16p5MCNCListener.kt @@ -1,4 +1,4 @@ -package dev.mikchan.mcnp.chat.implementation.spigot.events.listeners +package dev.mikchan.mcnp.chat.implementation.spigot.v1_16_5.events.listeners import dev.mikchan.mcnp.chat.ChatPlugin import dev.mikchan.mcnp.chat.contract.events.MCNChatEvent @@ -7,7 +7,7 @@ import org.bukkit.event.EventHandler import org.bukkit.event.EventPriority import org.bukkit.event.Listener -internal class MCNCListener(private val plugin: ChatPlugin) : Listener { +internal class SpigotV1m16p5MCNCListener(private val plugin: ChatPlugin) : Listener { private fun checkSpy(player: Player): Boolean { return try { player.persistentDataContainer.getOrDefault( diff --git a/src/main/java/dev/mikchan/mcnp/chat/implementation/spigot/keys/SpigotKey.kt b/src/main/java/dev/mikchan/mcnp/chat/implementation/spigot/v1_16_5/keys/SpigotV1m16p5Key.kt similarity index 77% rename from src/main/java/dev/mikchan/mcnp/chat/implementation/spigot/keys/SpigotKey.kt rename to src/main/java/dev/mikchan/mcnp/chat/implementation/spigot/v1_16_5/keys/SpigotV1m16p5Key.kt index 439881a..f286b1f 100644 --- a/src/main/java/dev/mikchan/mcnp/chat/implementation/spigot/keys/SpigotKey.kt +++ b/src/main/java/dev/mikchan/mcnp/chat/implementation/spigot/v1_16_5/keys/SpigotV1m16p5Key.kt @@ -1,11 +1,11 @@ -package dev.mikchan.mcnp.chat.implementation.spigot.keys +package dev.mikchan.mcnp.chat.implementation.spigot.v1_16_5.keys import dev.mikchan.mcnp.chat.ChatPlugin import dev.mikchan.mcnp.chat.contract.keys.IKey import org.bukkit.NamespacedKey import org.bukkit.persistence.PersistentDataType -internal class SpigotKey( +internal class SpigotV1m16p5Key( plugin: ChatPlugin, key: String, override val type: PersistentDataType diff --git a/src/main/java/dev/mikchan/mcnp/chat/implementation/spigot/v1_16_5/keys/SpigotV1m16p5Keys.kt b/src/main/java/dev/mikchan/mcnp/chat/implementation/spigot/v1_16_5/keys/SpigotV1m16p5Keys.kt new file mode 100644 index 0000000..6b4aeb9 --- /dev/null +++ b/src/main/java/dev/mikchan/mcnp/chat/implementation/spigot/v1_16_5/keys/SpigotV1m16p5Keys.kt @@ -0,0 +1,9 @@ +package dev.mikchan.mcnp.chat.implementation.spigot.v1_16_5.keys + +import dev.mikchan.mcnp.chat.ChatPlugin +import dev.mikchan.mcnp.chat.contract.keys.IKeys +import org.bukkit.persistence.PersistentDataType + +internal class SpigotV1m16p5Keys(plugin: ChatPlugin) : IKeys { + override val spy = SpigotV1m16p5Key(plugin, "spy", PersistentDataType.BYTE) +} diff --git a/src/main/java/dev/mikchan/mcnp/chat/implementation/spigot/users/SpigotUserManager.kt b/src/main/java/dev/mikchan/mcnp/chat/implementation/spigot/v1_16_5/users/SpigotV1m16p5UserManager.kt similarity index 87% rename from src/main/java/dev/mikchan/mcnp/chat/implementation/spigot/users/SpigotUserManager.kt rename to src/main/java/dev/mikchan/mcnp/chat/implementation/spigot/v1_16_5/users/SpigotV1m16p5UserManager.kt index 8e1a702..02a797a 100644 --- a/src/main/java/dev/mikchan/mcnp/chat/implementation/spigot/users/SpigotUserManager.kt +++ b/src/main/java/dev/mikchan/mcnp/chat/implementation/spigot/v1_16_5/users/SpigotV1m16p5UserManager.kt @@ -1,11 +1,11 @@ -package dev.mikchan.mcnp.chat.implementation.spigot.users +package dev.mikchan.mcnp.chat.implementation.spigot.v1_16_5.users import dev.mikchan.mcnp.chat.ChatPlugin import dev.mikchan.mcnp.chat.contract.users.IUserManager import org.bukkit.entity.Player import java.util.* -internal open class SpigotUserManager(private val plugin: ChatPlugin) : IUserManager { +internal class SpigotV1m16p5UserManager(private val plugin: ChatPlugin) : IUserManager { override fun findSimilar(search: String, playerContext: Player?): List { @Suppress("UnnecessaryVariable") val res = plugin.server.onlinePlayers.filter { player -> player.displayName.startsWith(search, true) } diff --git a/src/main/java/dev/mikchan/mcnp/chat/implementation/spigot/v1_17/SpigotV1m17ChatPluginFactory.kt b/src/main/java/dev/mikchan/mcnp/chat/implementation/spigot/v1_17/SpigotV1m17ChatPluginFactory.kt new file mode 100644 index 0000000..af79faa --- /dev/null +++ b/src/main/java/dev/mikchan/mcnp/chat/implementation/spigot/v1_17/SpigotV1m17ChatPluginFactory.kt @@ -0,0 +1,6 @@ +package dev.mikchan.mcnp.chat.implementation.spigot.v1_17 + +import dev.mikchan.mcnp.chat.ChatPlugin +import dev.mikchan.mcnp.chat.implementation.spigot.v1_16_5.SpigotV1m16p5ChatPluginFactory + +internal open class SpigotV1m17ChatPluginFactory(plugin: ChatPlugin) : SpigotV1m16p5ChatPluginFactory(plugin) diff --git a/src/main/java/dev/mikchan/mcnp/chat/implementation/spigot/v1_17_1/SpigotV1m17p1ChatPluginFactory.kt b/src/main/java/dev/mikchan/mcnp/chat/implementation/spigot/v1_17_1/SpigotV1m17p1ChatPluginFactory.kt new file mode 100644 index 0000000..4278d1c --- /dev/null +++ b/src/main/java/dev/mikchan/mcnp/chat/implementation/spigot/v1_17_1/SpigotV1m17p1ChatPluginFactory.kt @@ -0,0 +1,6 @@ +package dev.mikchan.mcnp.chat.implementation.spigot.v1_17_1 + +import dev.mikchan.mcnp.chat.ChatPlugin +import dev.mikchan.mcnp.chat.implementation.spigot.v1_17.SpigotV1m17ChatPluginFactory + +internal open class SpigotV1m17p1ChatPluginFactory(plugin: ChatPlugin) : SpigotV1m17ChatPluginFactory(plugin) diff --git a/src/main/java/dev/mikchan/mcnp/chat/implementation/spigot/v1_18/SpigotV1m18ChatPluginFactory.kt b/src/main/java/dev/mikchan/mcnp/chat/implementation/spigot/v1_18/SpigotV1m18ChatPluginFactory.kt new file mode 100644 index 0000000..dc483b8 --- /dev/null +++ b/src/main/java/dev/mikchan/mcnp/chat/implementation/spigot/v1_18/SpigotV1m18ChatPluginFactory.kt @@ -0,0 +1,6 @@ +package dev.mikchan.mcnp.chat.implementation.spigot.v1_18 + +import dev.mikchan.mcnp.chat.ChatPlugin +import dev.mikchan.mcnp.chat.implementation.spigot.v1_17_1.SpigotV1m17p1ChatPluginFactory + +internal open class SpigotV1m18ChatPluginFactory(plugin: ChatPlugin) : SpigotV1m17p1ChatPluginFactory(plugin) diff --git a/src/main/java/dev/mikchan/mcnp/chat/implementation/spigot/v1_18_1/SpigotV1m18p1ChatPluginFactory.kt b/src/main/java/dev/mikchan/mcnp/chat/implementation/spigot/v1_18_1/SpigotV1m18p1ChatPluginFactory.kt new file mode 100644 index 0000000..9bcb57f --- /dev/null +++ b/src/main/java/dev/mikchan/mcnp/chat/implementation/spigot/v1_18_1/SpigotV1m18p1ChatPluginFactory.kt @@ -0,0 +1,6 @@ +package dev.mikchan.mcnp.chat.implementation.spigot.v1_18_1 + +import dev.mikchan.mcnp.chat.ChatPlugin +import dev.mikchan.mcnp.chat.implementation.spigot.v1_18.SpigotV1m18ChatPluginFactory + +internal open class SpigotV1m18p1ChatPluginFactory(plugin: ChatPlugin) : SpigotV1m18ChatPluginFactory(plugin) diff --git a/src/main/java/dev/mikchan/mcnp/chat/implementation/spigot/v1_18_2/SpigotV1m18p2ChatPluginFactory.kt b/src/main/java/dev/mikchan/mcnp/chat/implementation/spigot/v1_18_2/SpigotV1m18p2ChatPluginFactory.kt new file mode 100644 index 0000000..b14fa38 --- /dev/null +++ b/src/main/java/dev/mikchan/mcnp/chat/implementation/spigot/v1_18_2/SpigotV1m18p2ChatPluginFactory.kt @@ -0,0 +1,6 @@ +package dev.mikchan.mcnp.chat.implementation.spigot.v1_18_2 + +import dev.mikchan.mcnp.chat.ChatPlugin +import dev.mikchan.mcnp.chat.implementation.spigot.v1_18_1.SpigotV1m18p1ChatPluginFactory + +internal open class SpigotV1m18p2ChatPluginFactory(plugin: ChatPlugin) : SpigotV1m18p1ChatPluginFactory(plugin) diff --git a/src/main/java/dev/mikchan/mcnp/chat/implementation/spigot/v1_19/SpigotV1m19ChatPluginFactory.kt b/src/main/java/dev/mikchan/mcnp/chat/implementation/spigot/v1_19/SpigotV1m19ChatPluginFactory.kt new file mode 100644 index 0000000..b64a9c1 --- /dev/null +++ b/src/main/java/dev/mikchan/mcnp/chat/implementation/spigot/v1_19/SpigotV1m19ChatPluginFactory.kt @@ -0,0 +1,6 @@ +package dev.mikchan.mcnp.chat.implementation.spigot.v1_19 + +import dev.mikchan.mcnp.chat.ChatPlugin +import dev.mikchan.mcnp.chat.implementation.spigot.v1_18_2.SpigotV1m18p2ChatPluginFactory + +internal open class SpigotV1m19ChatPluginFactory(plugin: ChatPlugin) : SpigotV1m18p2ChatPluginFactory(plugin) diff --git a/src/main/java/dev/mikchan/mcnp/chat/implementation/spigot/v1_19_1/SpigotV1m19p1ChatPluginFactory.kt b/src/main/java/dev/mikchan/mcnp/chat/implementation/spigot/v1_19_1/SpigotV1m19p1ChatPluginFactory.kt new file mode 100644 index 0000000..bc3bcb8 --- /dev/null +++ b/src/main/java/dev/mikchan/mcnp/chat/implementation/spigot/v1_19_1/SpigotV1m19p1ChatPluginFactory.kt @@ -0,0 +1,13 @@ +package dev.mikchan.mcnp.chat.implementation.spigot.v1_19_1 + +import dev.mikchan.mcnp.chat.ChatPlugin +import dev.mikchan.mcnp.chat.contract.events.IEventManager +import dev.mikchan.mcnp.chat.implementation.spigot.v1_19.SpigotV1m19ChatPluginFactory +import dev.mikchan.mcnp.chat.implementation.spigot.v1_19_1.events.SpigotV1m19p1EventManager + +internal open class SpigotV1m19p1ChatPluginFactory(private val plugin: ChatPlugin) : + SpigotV1m19ChatPluginFactory(plugin) { + override fun createEventManager(): IEventManager { + return SpigotV1m19p1EventManager(plugin) + } +} diff --git a/src/main/java/dev/mikchan/mcnp/chat/implementation/spigot/v1_19_1/events/SpigotV1m19p1EventManager.kt b/src/main/java/dev/mikchan/mcnp/chat/implementation/spigot/v1_19_1/events/SpigotV1m19p1EventManager.kt new file mode 100644 index 0000000..68161b4 --- /dev/null +++ b/src/main/java/dev/mikchan/mcnp/chat/implementation/spigot/v1_19_1/events/SpigotV1m19p1EventManager.kt @@ -0,0 +1,16 @@ +package dev.mikchan.mcnp.chat.implementation.spigot.v1_19_1.events + +import dev.mikchan.mcnp.chat.ChatPlugin +import dev.mikchan.mcnp.chat.implementation.base.event.BaseEventManager +import dev.mikchan.mcnp.chat.implementation.spigot.v1_16_5.events.listeners.SpigotV1m16p5MCNCListener +import dev.mikchan.mcnp.chat.implementation.spigot.v1_19_1.events.listeners.SpigotV1m19p1ChatListener + +internal class SpigotV1m19p1EventManager(chatPlugin: ChatPlugin) : BaseEventManager( + chatPlugin, + { plugin -> + listOf( + SpigotV1m19p1ChatListener(plugin), + SpigotV1m16p5MCNCListener(plugin), + ) + }, +) diff --git a/src/main/java/dev/mikchan/mcnp/chat/implementation/spigot/events/listeners/ChatListener.kt b/src/main/java/dev/mikchan/mcnp/chat/implementation/spigot/v1_19_1/events/listeners/SpigotV1m19p1ChatListener.kt similarity index 78% rename from src/main/java/dev/mikchan/mcnp/chat/implementation/spigot/events/listeners/ChatListener.kt rename to src/main/java/dev/mikchan/mcnp/chat/implementation/spigot/v1_19_1/events/listeners/SpigotV1m19p1ChatListener.kt index 6fb139e..40dc417 100644 --- a/src/main/java/dev/mikchan/mcnp/chat/implementation/spigot/events/listeners/ChatListener.kt +++ b/src/main/java/dev/mikchan/mcnp/chat/implementation/spigot/v1_19_1/events/listeners/SpigotV1m19p1ChatListener.kt @@ -1,4 +1,6 @@ -package dev.mikchan.mcnp.chat.implementation.spigot.events.listeners +@file:Suppress("DEPRECATION") + +package dev.mikchan.mcnp.chat.implementation.spigot.v1_19_1.events.listeners import dev.mikchan.mcnp.chat.ChatPlugin import dev.mikchan.mcnp.chat.implementation.base.event.listeners.BaseChatListener @@ -8,7 +10,7 @@ import org.bukkit.event.Listener import org.bukkit.event.player.AsyncPlayerChatEvent import org.bukkit.event.player.AsyncPlayerChatPreviewEvent -internal class ChatListener(plugin: ChatPlugin) : BaseChatListener(plugin), Listener { +internal class SpigotV1m19p1ChatListener(plugin: ChatPlugin) : BaseChatListener(plugin), Listener { @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) fun onAsyncMessage(event: AsyncPlayerChatEvent) { if (!handleChatEvent(event, false)) event.isCancelled = true diff --git a/src/main/java/dev/mikchan/mcnp/chat/implementation/spigot/v1_19_2/SpigotV1m19p2ChatPluginFactory.kt b/src/main/java/dev/mikchan/mcnp/chat/implementation/spigot/v1_19_2/SpigotV1m19p2ChatPluginFactory.kt new file mode 100644 index 0000000..8c76362 --- /dev/null +++ b/src/main/java/dev/mikchan/mcnp/chat/implementation/spigot/v1_19_2/SpigotV1m19p2ChatPluginFactory.kt @@ -0,0 +1,6 @@ +package dev.mikchan.mcnp.chat.implementation.spigot.v1_19_2 + +import dev.mikchan.mcnp.chat.ChatPlugin +import dev.mikchan.mcnp.chat.implementation.spigot.v1_19_1.SpigotV1m19p1ChatPluginFactory + +internal open class SpigotV1m19p2ChatPluginFactory(plugin: ChatPlugin) : SpigotV1m19p1ChatPluginFactory(plugin) diff --git a/src/main/java/dev/mikchan/mcnp/chat/implementation/spigot/v1_19_3/SpigotV1m19p3ChatPluginFactory.kt b/src/main/java/dev/mikchan/mcnp/chat/implementation/spigot/v1_19_3/SpigotV1m19p3ChatPluginFactory.kt new file mode 100644 index 0000000..2ad4266 --- /dev/null +++ b/src/main/java/dev/mikchan/mcnp/chat/implementation/spigot/v1_19_3/SpigotV1m19p3ChatPluginFactory.kt @@ -0,0 +1,6 @@ +package dev.mikchan.mcnp.chat.implementation.spigot.v1_19_3 + +import dev.mikchan.mcnp.chat.ChatPlugin +import dev.mikchan.mcnp.chat.implementation.spigot.v1_19_2.SpigotV1m19p2ChatPluginFactory + +internal open class SpigotV1m19p3ChatPluginFactory(plugin: ChatPlugin) : SpigotV1m19p2ChatPluginFactory(plugin) diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index 14c7935..f76faa7 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -1,5 +1,5 @@ # This is an automatic property, do not change! -configVersion: 4 +configVersion: 5 # Should enable logging messages? enableLog: false @@ -40,6 +40,7 @@ spyTemplate: '<:player:> :message:' # :message: - the message itself privateTemplate: '<:player_from: to :player_to:> :message:' consoleTemplate: ' :message:' +fromConsoleTemplate: '<:player_from: to CONSOLE> :message:' # If PAPI is present, this field will be used to replace :player: playerTemplate: '%player_name%'