-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
90 additions
and
3 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
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
11 changes: 11 additions & 0 deletions
11
src/main/java/dev/mikchan/mcnp/motd/events/creator/EventManagerCreator.kt
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,11 @@ | ||
package dev.mikchan.mcnp.motd.events.creator | ||
|
||
import dev.mikchan.mcnp.motd.MOTDPlugin | ||
import dev.mikchan.mcnp.motd.events.manager.EventManager | ||
import dev.mikchan.mcnp.motd.events.manager.IEventManager | ||
|
||
internal class EventManagerCreator : IEventManagerCreator { | ||
override fun build(plugin: MOTDPlugin): IEventManager { | ||
return EventManager(plugin) | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
src/main/java/dev/mikchan/mcnp/motd/events/creator/IEventManagerCreator.kt
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,8 @@ | ||
package dev.mikchan.mcnp.motd.events.creator | ||
|
||
import dev.mikchan.mcnp.motd.MOTDPlugin | ||
import dev.mikchan.mcnp.motd.events.manager.IEventManager | ||
|
||
interface IEventManagerCreator { | ||
fun build(plugin: MOTDPlugin): IEventManager | ||
} |
32 changes: 32 additions & 0 deletions
32
src/main/java/dev/mikchan/mcnp/motd/events/listeners/MOTDListener.kt
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,32 @@ | ||
package dev.mikchan.mcnp.motd.events.listeners | ||
|
||
import dev.mikchan.mcnp.motd.MOTDPlugin | ||
import org.bukkit.event.EventHandler | ||
import org.bukkit.event.Listener | ||
import org.bukkit.event.server.ServerListPingEvent | ||
|
||
internal class MOTDListener(private val plugin: MOTDPlugin) : Listener { | ||
@EventHandler(ignoreCancelled = true) | ||
fun onServerListPingEvent(event: ServerListPingEvent) { | ||
if (!plugin.config.enabled) return | ||
val motd = plugin.motdManager.getRandom() ?: return | ||
|
||
if (motd.firstLine != null || motd.secondLine != "") { | ||
val firstLine = motd.firstLine ?: "" | ||
val secondLine = motd.secondLine ?: "" | ||
event.motd = "${firstLine}\n${secondLine}" | ||
} | ||
|
||
val image = motd.image?.let { | ||
if (plugin.config.randomImages) { | ||
plugin.imageManager.getRandom() | ||
} else { | ||
null | ||
} | ||
} | ||
|
||
if (image != null) { | ||
event.setServerIcon(image) | ||
} | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
src/main/java/dev/mikchan/mcnp/motd/events/manager/EventManager.kt
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,16 @@ | ||
package dev.mikchan.mcnp.motd.events.manager | ||
|
||
import dev.mikchan.mcnp.motd.MOTDPlugin | ||
import dev.mikchan.mcnp.motd.events.listeners.MOTDListener | ||
import org.bukkit.event.HandlerList | ||
|
||
internal class EventManager(private val plugin: MOTDPlugin) : IEventManager { | ||
override fun registerAll() { | ||
unregisterAll() | ||
plugin.server.pluginManager.registerEvents(MOTDListener(plugin), plugin) | ||
} | ||
|
||
override fun unregisterAll() { | ||
HandlerList.unregisterAll(plugin) | ||
} | ||
} |
6 changes: 6 additions & 0 deletions
6
src/main/java/dev/mikchan/mcnp/motd/events/manager/IEventManager.kt
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,6 @@ | ||
package dev.mikchan.mcnp.motd.events.manager | ||
|
||
interface IEventManager { | ||
fun registerAll() | ||
fun unregisterAll() | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,4 +8,5 @@ interface IImageManager { | |
|
||
fun preload() | ||
fun reload() | ||
fun unload() | ||
} |
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