diff --git a/blockball-api/src/main/java/com/github/shynixn/blockball/api/business/proxy/PluginProxy.kt b/blockball-api/src/main/java/com/github/shynixn/blockball/api/business/proxy/PluginProxy.kt index d3fa5118a..391041309 100644 --- a/blockball-api/src/main/java/com/github/shynixn/blockball/api/business/proxy/PluginProxy.kt +++ b/blockball-api/src/main/java/com/github/shynixn/blockball/api/business/proxy/PluginProxy.kt @@ -43,11 +43,6 @@ interface PluginProxy { */ fun sendConsoleMessage(message: String) - /** - * Sets the motd of the server. - */ - fun setMotd(message: String) - /** * Shutdowns the server. */ diff --git a/blockball-api/src/main/java/com/github/shynixn/blockball/api/persistence/entity/BungeeCordGame.kt b/blockball-api/src/main/java/com/github/shynixn/blockball/api/persistence/entity/BungeeCordGame.kt index d165e66d8..e0b17ccba 100644 --- a/blockball-api/src/main/java/com/github/shynixn/blockball/api/persistence/entity/BungeeCordGame.kt +++ b/blockball-api/src/main/java/com/github/shynixn/blockball/api/persistence/entity/BungeeCordGame.kt @@ -27,4 +27,6 @@ package com.github.shynixn.blockball.api.persistence.entity * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ -interface BungeeCordGame : MiniGame \ No newline at end of file +interface BungeeCordGame : MiniGame { + var modt: String +} diff --git a/blockball-bukkit-plugin/build.gradle.kts b/blockball-bukkit-plugin/build.gradle.kts index be777a4b4..fcaeba302 100644 --- a/blockball-bukkit-plugin/build.gradle.kts +++ b/blockball-bukkit-plugin/build.gradle.kts @@ -87,7 +87,7 @@ tasks.register("pluginJarLatest", ShadowJar::class.java) { dependsOn("relocatePluginJar") from(zipTree(File("./build/libs/" + (tasks.getByName("relocatePluginJar") as Jar).archiveName))) archiveName = "${baseName}-${version}-latest.${extension}" - // destinationDir = File("C:\\temp\\plugins") + // destinationDir = File("C:\\temp\\plugins") exclude("com/github/shynixn/mcutils/**") exclude("org/**") @@ -110,8 +110,8 @@ dependencies { implementation(project(":blockball-bukkit-api")) implementation(project(":blockball-core")) - implementation("com.github.shynixn.mcutils:common:1.0.37") - implementation("com.github.shynixn.mcutils:packet:1.0.52") + implementation("com.github.shynixn.mcutils:common:1.0.40") + implementation("com.github.shynixn.mcutils:packet:1.0.61") implementation("com.github.shynixn.org.bstats:bstats-bukkit:1.7") implementation("org.slf4j:slf4j-jdk14:1.7.25") diff --git a/blockball-bukkit-plugin/src/main/java/com/github/shynixn/blockball/bukkit/BlockBallPlugin.kt b/blockball-bukkit-plugin/src/main/java/com/github/shynixn/blockball/bukkit/BlockBallPlugin.kt index 97415e5ee..ef856d42f 100644 --- a/blockball-bukkit-plugin/src/main/java/com/github/shynixn/blockball/bukkit/BlockBallPlugin.kt +++ b/blockball-bukkit-plugin/src/main/java/com/github/shynixn/blockball/bukkit/BlockBallPlugin.kt @@ -273,29 +273,6 @@ class BlockBallPlugin : JavaPlugin(), PluginProxy { return this.serverVersion!! } - /** - * Sets the motd of the server. - */ - override fun setMotd(message: String) { - val builder = java.lang.StringBuilder("[") - builder.append((message.replace("[", "").replace("]", ""))) - builder.append(ChatColor.RESET.toString()) - builder.append("]") - - val minecraftServerClazz = try { - findClazz("net.minecraft.server.MinecraftServer") - } catch (e: Exception) { - findClazz("net.minecraft.server.VERSION.MinecraftServer") - } - - val craftServerClazz = findClazz("org.bukkit.craftbukkit.VERSION.CraftServer") - val setModtMethod = minecraftServerClazz.getDeclaredMethod("setMotd", String::class.java) - val getServerConsoleMethod = craftServerClazz.getDeclaredMethod("getServer") - - val console = getServerConsoleMethod.invoke(Bukkit.getServer()) - setModtMethod.invoke(console, builder.toString().translateChatColors()) - } - /** * Shutdowns the server. */ diff --git a/blockball-bukkit-plugin/src/main/java/com/github/shynixn/blockball/bukkit/logic/business/listener/BungeeCordgameListener.kt b/blockball-bukkit-plugin/src/main/java/com/github/shynixn/blockball/bukkit/logic/business/listener/BungeeCordgameListener.kt index bb8a4133c..ecb2586c0 100644 --- a/blockball-bukkit-plugin/src/main/java/com/github/shynixn/blockball/bukkit/logic/business/listener/BungeeCordgameListener.kt +++ b/blockball-bukkit-plugin/src/main/java/com/github/shynixn/blockball/bukkit/logic/business/listener/BungeeCordgameListener.kt @@ -2,6 +2,7 @@ package com.github.shynixn.blockball.bukkit.logic.business.listener import com.github.shynixn.blockball.api.business.enumeration.GameType import com.github.shynixn.blockball.api.business.service.* +import com.github.shynixn.blockball.api.persistence.entity.BungeeCordGame import com.github.shynixn.blockball.bukkit.logic.business.extension.toPosition import com.github.shynixn.blockball.core.logic.business.extension.sync import com.google.inject.Inject @@ -11,6 +12,7 @@ import org.bukkit.event.Listener import org.bukkit.event.block.Action import org.bukkit.event.player.PlayerInteractEvent import org.bukkit.event.player.PlayerJoinEvent +import org.bukkit.event.server.ServerListPingEvent /** * Created by Shynixn 2018. @@ -67,6 +69,17 @@ class BungeeCordgameListener @Inject constructor( } } + @EventHandler + fun onPingServerEven(event: ServerListPingEvent) { + val game = gameService.getAllGames().find { p -> p.arena.gameType == GameType.BUNGEE } + + if (game != null && game is BungeeCordGame) { + if (game.modt.isNotBlank()) { + event.motd = game.modt + } + } + } + /** * Handles click on signs to create new server signs or to connect players to the server * written on the sign. @@ -94,4 +107,4 @@ class BungeeCordgameListener @Inject constructor( rightClickManageService.executeWatchers(event.player, event.clickedBlock!!.location) } -} \ No newline at end of file +} diff --git a/blockball-core/src/main/java/com/github/shynixn/blockball/core/logic/business/service/GameBungeeCordGameActionServiceImpl.kt b/blockball-core/src/main/java/com/github/shynixn/blockball/core/logic/business/service/GameBungeeCordGameActionServiceImpl.kt index 0f235e839..0e6bde997 100644 --- a/blockball-core/src/main/java/com/github/shynixn/blockball/core/logic/business/service/GameBungeeCordGameActionServiceImpl.kt +++ b/blockball-core/src/main/java/com/github/shynixn/blockball/core/logic/business/service/GameBungeeCordGameActionServiceImpl.kt @@ -1,5 +1,6 @@ package com.github.shynixn.blockball.core.logic.business.service +import com.github.shynixn.blockball.api.business.enumeration.ChatColor import com.github.shynixn.blockball.api.business.proxy.PluginProxy import com.github.shynixn.blockball.api.business.service.BungeeCordService import com.github.shynixn.blockball.api.business.service.ConcurrencyService @@ -7,6 +8,7 @@ import com.github.shynixn.blockball.api.business.service.GameBungeeCordGameActio import com.github.shynixn.blockball.api.business.service.ProxyService import com.github.shynixn.blockball.api.persistence.entity.BungeeCordGame import com.github.shynixn.blockball.core.logic.business.extension.sync +import com.github.shynixn.blockball.core.logic.business.extension.translateChatColors import com.google.inject.Inject /** @@ -47,7 +49,7 @@ class GameBungeeCordGameActionServiceImpl @Inject constructor( * Closes the given game and all underlying resources. */ override fun closeGame(game: BungeeCordGame) { - plugin.setMotd(bungeeCordService.bungeeCordConfiguration.restartingMotd) + setMotd(game, bungeeCordService.bungeeCordConfiguration.restartingMotd) if (!plugin.isEnabled()) { return @@ -80,9 +82,17 @@ class GameBungeeCordGameActionServiceImpl @Inject constructor( } if (game.playing) { - plugin.setMotd(bungeeCordService.bungeeCordConfiguration.inGameMotd) + setMotd(game, bungeeCordService.bungeeCordConfiguration.inGameMotd) } else { - plugin.setMotd(bungeeCordService.bungeeCordConfiguration.waitingForPlayersMotd) + setMotd(game, bungeeCordService.bungeeCordConfiguration.waitingForPlayersMotd) } } -} \ No newline at end of file + + private fun setMotd(game: BungeeCordGame, message: String) { + val builder = java.lang.StringBuilder("[") + builder.append((message.replace("[", "").replace("]", ""))) + builder.append(ChatColor.RESET.toString()) + builder.append("]") + game.modt = builder.toString().translateChatColors() + } +} diff --git a/blockball-core/src/main/java/com/github/shynixn/blockball/core/logic/persistence/entity/BungeeCordGameEntity.kt b/blockball-core/src/main/java/com/github/shynixn/blockball/core/logic/persistence/entity/BungeeCordGameEntity.kt index c8fd4df17..f100b1d22 100644 --- a/blockball-core/src/main/java/com/github/shynixn/blockball/core/logic/persistence/entity/BungeeCordGameEntity.kt +++ b/blockball-core/src/main/java/com/github/shynixn/blockball/core/logic/persistence/entity/BungeeCordGameEntity.kt @@ -31,7 +31,10 @@ import com.github.shynixn.blockball.api.persistence.entity.BungeeCordGame * SOFTWARE. */ class BungeeCordGameEntity( - /** - * Arena of the game. - */ - override val arena: Arena) : MiniGameEntity(arena), BungeeCordGame + /** + * Arena of the game. + */ + override val arena: Arena +) : MiniGameEntity(arena), BungeeCordGame { + override var modt: String = "" +} diff --git a/blockball-core/src/test/java/unittest/ArenaFileRepositoryTest.kt b/blockball-core/src/test/java/unittest/ArenaFileRepositoryTest.kt index df2d9c21e..1e3086bce 100644 --- a/blockball-core/src/test/java/unittest/ArenaFileRepositoryTest.kt +++ b/blockball-core/src/test/java/unittest/ArenaFileRepositoryTest.kt @@ -82,29 +82,6 @@ class ArenaFileRepositoryTest { Assertions.assertEquals("10", arenas[2].name) } - /** - * Given - * a new arena - * When - * save is called - * Then - * an file with the correct amount of bytes should be created. - */ - @Test - fun save_NewArenaEntity_ShouldBeCorrectlySaved() { - // Arrange - val arena = ArenaEntity() - arena.name = "1" - val classUnderTest = createWithDependencies() - - // Act - classUnderTest.save(arena) - val actualDataLength = FileUtils.readFileToString(File("build/repository-test/arena/arena_1.yml"), "UTF-8") - - // Assert - Assertions.assertEquals(9598, actualDataLength.length) - } - /** * Given * an existing arena file