Skip to content

Commit 642a772

Browse files
Updated Sponge
1 parent 9e2f70f commit 642a772

File tree

4 files changed

+54
-2
lines changed

4 files changed

+54
-2
lines changed

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ configurations {
2626

2727
dependencies {
2828
shadow "org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.3.11"
29-
kapt "org.spongepowered:spongeapi:7.0.0"
29+
kapt "org.spongepowered:spongeapi:7.1.0"
3030
shadow("com.github.randombyte-developer.kosp:kosp:v1.9.1") { transitive = false }
3131
shadow "org.bstats:bstats-sponge:1.4"
3232
compile "io.github.nucleuspowered:nucleus-api:1.2.2-S7.0"
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package de.randombyte.unity
2+
3+
import de.randombyte.kosp.extensions.*
4+
5+
object Messages {
6+
val motivationalSpeech = listOf(
7+
"[${Unity.NAME}] ".yellow() + "Metrics are disabled for this plugin or globally! Please consider enabling metrics.".aqua(),
8+
"Metrics are anonymous usage data (how many players are on the server, which minecraft version the server is on, etc.)".green(),
9+
"With that data the developer can check how many servers use the plugin. Plugins with many users motivate me more to release new updates. :)".gold(),
10+
"To disable this message, go to the Sponge global config, and enable metrics collection for at least this plugin, thanks! ;)".lightPurple())
11+
12+
const val configComment = "Since you are already editing configs, how about enabling metrics for at least this plugin? ;)\n" +
13+
"Go to the 'config/sponge/global.conf', scroll to the 'metrics' section and enable metrics.\n" +
14+
"Anonymous metrics data collection enables the developer to see how many people and servers are using this plugin.\n" +
15+
"Seeing that my plugin is being used is a big factor in motivating me to provide future support and updates.\n" +
16+
"If you really don't want to enable metrics and don't want to receive any messages anymore, you can disable this config option ;("
17+
}

src/main/kotlin/de/randombyte/unity/Unity.kt

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import de.randombyte.unity.config.ConfigAccessor
1616
import io.github.nucleuspowered.nucleus.api.service.NucleusMessageTokenService
1717
import ninja.leaping.configurate.commented.CommentedConfigurationNode
1818
import ninja.leaping.configurate.loader.ConfigurationLoader
19+
import org.apache.commons.lang3.RandomUtils
1920
import org.bstats.sponge.Metrics2
2021
import org.slf4j.Logger
2122
import org.spongepowered.api.Sponge
@@ -34,13 +35,16 @@ import org.spongepowered.api.event.filter.cause.Root
3435
import org.spongepowered.api.event.game.GameReloadEvent
3536
import org.spongepowered.api.event.game.state.GameInitializationEvent
3637
import org.spongepowered.api.event.game.state.GameStartingServerEvent
38+
import org.spongepowered.api.event.network.ClientConnectionEvent
3739
import org.spongepowered.api.event.service.ChangeServiceProviderEvent
3840
import org.spongepowered.api.plugin.Dependency
3941
import org.spongepowered.api.plugin.Plugin
4042
import org.spongepowered.api.plugin.PluginContainer
43+
import org.spongepowered.api.scheduler.Task
4144
import org.spongepowered.api.text.action.TextActions
4245
import java.text.SimpleDateFormat
4346
import 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
}

src/main/kotlin/de/randombyte/unity/config/Config.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package de.randombyte.unity.config
22

33
import de.randombyte.kosp.extensions.*
44
import de.randombyte.kosp.fixedTextTemplateOf
5+
import de.randombyte.unity.Messages
56
import de.randombyte.unity.commands.sendMessageIfNotEmpty
67
import de.randombyte.unity.config.Config.Unity.HomeLocation.*
78
import de.randombyte.unity.config.Config.Unity.HomeLocation.Set
@@ -22,7 +23,8 @@ data class Config(
2223
@Setting("texts") val texts: Texts = Texts(),
2324
@Setting("divorce-cooldown") val divorceCooldown: Duration = Duration.ofDays(1),
2425
@Setting("married-prefix") val marriedPrefix: Text = "[".red() + "".darkRed() + "]".red(),
25-
@Setting("kissing-enabled", comment = "Shift-right-click your partner to spawn heart particles.") val kissingEnabled: Boolean = true
26+
@Setting("kissing-enabled", comment = "Shift-right-click your partner to spawn heart particles.") val kissingEnabled: Boolean = true,
27+
@Setting("enable-metrics-messages", comment = Messages.configComment) val enableMetricsMessages: Boolean = true
2628
) {
2729
@ConfigSerializable
2830
data class Unity(

0 commit comments

Comments
 (0)