Skip to content

Commit

Permalink
#456 Fixed bungeecord setting motd.
Browse files Browse the repository at this point in the history
  • Loading branch information
Shynixn committed Dec 8, 2023
1 parent 76589e0 commit 2a5c8b9
Show file tree
Hide file tree
Showing 8 changed files with 41 additions and 64 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,6 @@ interface PluginProxy {
*/
fun sendConsoleMessage(message: String)

/**
* Sets the motd of the server.
*/
fun setMotd(message: String)

/**
* Shutdowns the server.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
interface BungeeCordGame : MiniGame {
var modt: String
}
6 changes: 3 additions & 3 deletions blockball-bukkit-plugin/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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/**")
Expand All @@ -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")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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.
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -94,4 +107,4 @@ class BungeeCordgameListener @Inject constructor(

rightClickManageService.executeWatchers(event.player, event.clickedBlock!!.location)
}
}
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
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
import com.github.shynixn.blockball.api.business.service.GameBungeeCordGameActionService
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

/**
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
}
}
}

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()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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 = ""
}
23 changes: 0 additions & 23 deletions blockball-core/src/test/java/unittest/ArenaFileRepositoryTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 2a5c8b9

Please sign in to comment.