@@ -16,6 +16,7 @@ import de.randombyte.unity.config.ConfigAccessor
1616import io.github.nucleuspowered.nucleus.api.service.NucleusMessageTokenService
1717import ninja.leaping.configurate.commented.CommentedConfigurationNode
1818import ninja.leaping.configurate.loader.ConfigurationLoader
19+ import org.apache.commons.lang3.RandomUtils
1920import org.bstats.sponge.Metrics2
2021import org.slf4j.Logger
2122import org.spongepowered.api.Sponge
@@ -34,13 +35,16 @@ import org.spongepowered.api.event.filter.cause.Root
3435import org.spongepowered.api.event.game.GameReloadEvent
3536import org.spongepowered.api.event.game.state.GameInitializationEvent
3637import org.spongepowered.api.event.game.state.GameStartingServerEvent
38+ import org.spongepowered.api.event.network.ClientConnectionEvent
3739import org.spongepowered.api.event.service.ChangeServiceProviderEvent
3840import org.spongepowered.api.plugin.Dependency
3941import org.spongepowered.api.plugin.Plugin
4042import org.spongepowered.api.plugin.PluginContainer
43+ import org.spongepowered.api.scheduler.Task
4144import org.spongepowered.api.text.action.TextActions
4245import java.text.SimpleDateFormat
4346import java.util.*
47+ import java.util.concurrent.TimeUnit
4448
4549@Plugin(id = ID ,
4650 name = NAME ,
@@ -110,6 +114,13 @@ class Unity @Inject constructor(
110114 // do this here to ensure all worlds are loaded for location deserialization
111115 loadConfig()
112116 saveConfig()
117+
118+ if (needsMotivationalSpeech()) {
119+ Task .builder()
120+ .delay(RandomUtils .nextLong(80 , 130 ), TimeUnit .SECONDS )
121+ .execute { -> Messages .motivationalSpeech.forEach { it.sendTo(Sponge .getServer().console) } }
122+ .submit(this )
123+ }
113124 }
114125
115126 @Listener
@@ -221,4 +232,26 @@ class Unity @Inject constructor(
221232 private fun saveConfig () {
222233 configManager.save(config)
223234 }
235+
236+
237+ val metricsNoteSent = mutableSetOf<UUID >()
238+
239+ @Listener
240+ fun onPlayerJoin (event : ClientConnectionEvent .Join ) {
241+ val uuid = event.targetEntity.uniqueId
242+ if (needsMotivationalSpeech(event.targetEntity)) {
243+ Task .builder()
244+ .delay(RandomUtils .nextLong(10 , 50 ), TimeUnit .SECONDS )
245+ .execute { ->
246+ val player = uuid.getPlayer() ? : return @execute
247+ metricsNoteSent + = uuid
248+ Messages .motivationalSpeech.forEach { it.sendTo(player) }
249+ }
250+ .submit(this )
251+ }
252+ }
253+
254+ private fun needsMotivationalSpeech (player : Player ? = null) = config.enableMetricsMessages &&
255+ ! Sponge .getMetricsConfigManager().areMetricsEnabled(this ) &&
256+ ((player == null ) || player.uniqueId !in metricsNoteSent && player.hasPermission(" nucleus.mute.base" )) // also passes OPs without Nucleus
224257}
0 commit comments