Skip to content

Commit afa01fc

Browse files
Updated bStats to comply with the Ore guidelines
1 parent 5b5d085 commit afa01fc

File tree

5 files changed

+69
-7
lines changed

5 files changed

+69
-7
lines changed

build.gradle

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

3939
dependencies {
4040
shadow "org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.3.11"
41-
kapt "org.spongepowered:spongeapi:7.0.0"
41+
kapt "org.spongepowered:spongeapi:7.1.0"
4242
shadow("com.github.randombyte-developer.kosp:kosp:v2.2.3") { transitive = false }
4343
shadow "org.bstats:bstats-sponge:1.4"
4444
}

src/main/kotlin/de/randombyte/commandutils/CommandUtils.kt

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,21 +19,29 @@ import de.randombyte.commandutils.execute.whenonline.PlayerJoinListener
1919
import de.randombyte.commandutils.executeonserverstartup.ServerStartupListener
2020
import de.randombyte.commandutils.service.CommandUtilsService
2121
import de.randombyte.commandutils.service.CommandUtilsServiceImpl
22+
import de.randombyte.kosp.extensions.getPlayer
23+
import de.randombyte.kosp.extensions.sendTo
2224
import de.randombyte.kosp.extensions.toText
25+
import org.apache.commons.lang3.RandomUtils
2326
import org.bstats.sponge.Metrics2
2427
import org.slf4j.Logger
2528
import org.spongepowered.api.Sponge
2629
import org.spongepowered.api.command.args.GenericArguments.*
2730
import org.spongepowered.api.command.spec.CommandSpec
2831
import org.spongepowered.api.config.ConfigDir
2932
import org.spongepowered.api.data.type.HandTypes
33+
import org.spongepowered.api.entity.living.player.Player
3034
import org.spongepowered.api.event.Listener
3135
import org.spongepowered.api.event.game.GameReloadEvent
3236
import org.spongepowered.api.event.game.state.GameInitializationEvent
3337
import org.spongepowered.api.event.game.state.GamePostInitializationEvent
38+
import org.spongepowered.api.event.network.ClientConnectionEvent
3439
import org.spongepowered.api.plugin.Dependency
3540
import org.spongepowered.api.plugin.Plugin
41+
import org.spongepowered.api.scheduler.Task
3642
import java.nio.file.Path
43+
import java.util.*
44+
import java.util.concurrent.TimeUnit
3745

3846
@Plugin(id = ID,
3947
name = NAME,
@@ -82,6 +90,13 @@ class CommandUtils @Inject constructor(
8290
ConfigUpdater.from1_8(configAccessor, logger)
8391
configAccessor.reloadAll()
8492
registerCommands()
93+
94+
if (needsMotivationalSpeech()) {
95+
Task.builder()
96+
.delay(RandomUtils.nextLong(80, 130), TimeUnit.SECONDS)
97+
.execute { -> Messages.motivationalSpeech.forEach { it.sendTo(Sponge.getServer().console) } }
98+
.submit(this)
99+
}
85100
}
86101

87102
@Listener
@@ -252,4 +267,25 @@ class CommandUtils @Inject constructor(
252267

253268
.build(), "commandutils", "cmdutils", "cu")
254269
}
270+
271+
val metricsNoteSent = mutableSetOf<UUID>()
272+
273+
@Listener
274+
fun onPlayerJoin(event: ClientConnectionEvent.Join) {
275+
val uuid = event.targetEntity.uniqueId
276+
if (needsMotivationalSpeech(event.targetEntity)) {
277+
Task.builder()
278+
.delay(RandomUtils.nextLong(10, 50), TimeUnit.SECONDS)
279+
.execute { ->
280+
val player = uuid.getPlayer() ?: return@execute
281+
metricsNoteSent += uuid
282+
Messages.motivationalSpeech.forEach { it.sendTo(player) }
283+
}
284+
.submit(this)
285+
}
286+
}
287+
288+
private fun needsMotivationalSpeech(player: Player? = null) = configAccessor.general.get().enableMetricsMessages &&
289+
!Sponge.getMetricsConfigManager().areMetricsEnabled(this) &&
290+
((player == null) || player.uniqueId !in metricsNoteSent && player.hasPermission("nucleus.mute.base")) // also passes OPs without Nucleus
255291
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package de.randombyte.commandutils
2+
3+
import de.randombyte.kosp.extensions.*
4+
5+
object Messages {
6+
val motivationalSpeech = listOf(
7+
"[${CommandUtils.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+
}
Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
package de.randombyte.commandutils.config
22

33
import de.randombyte.kosp.config.ConfigAccessor
4-
import de.randombyte.kosp.config.ConfigHolder
54
import java.nio.file.Path
65

76
class ConfigAccessor(configPath: Path) : ConfigAccessor(configPath) {
87

9-
val aliases: ConfigHolder<AliasConfig> = getConfigHolder("aliases.conf")
10-
val executeWhenOnline: ConfigHolder<ExecuteWhenOnlineConfig> = getConfigHolder("execute-when-online.conf")
11-
val executeOnServerStartup: ConfigHolder<ExecuteOnServerStartupConfig> = getConfigHolder("execute-on-server-startup.conf")
12-
val lastAliasExecutions: ConfigHolder<LastAliasExecutionsConfig> = getConfigHolder("last-alias-executions.conf")
8+
val general = getConfigHolder<GeneralConfig>("general.conf")
9+
val aliases = getConfigHolder<AliasConfig>("aliases.conf")
10+
val executeWhenOnline = getConfigHolder<ExecuteWhenOnlineConfig>("execute-when-online.conf")
11+
val executeOnServerStartup = getConfigHolder<ExecuteOnServerStartupConfig>("execute-on-server-startup.conf")
12+
val lastAliasExecutions = getConfigHolder<LastAliasExecutionsConfig>("last-alias-executions.conf")
1313

14-
override val holders = listOf(aliases, executeWhenOnline, executeOnServerStartup, lastAliasExecutions)
14+
override val holders = listOf(general, aliases, executeWhenOnline, executeOnServerStartup, lastAliasExecutions)
1515
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package de.randombyte.commandutils.config
2+
3+
import ninja.leaping.configurate.objectmapping.Setting
4+
import ninja.leaping.configurate.objectmapping.serialize.ConfigSerializable
5+
6+
@ConfigSerializable
7+
class GeneralConfig (
8+
@Setting("enable-metrics-messages", comment =
9+
"Since you are already editing configs, how about enabling metrics for at least this plugin? ;)\n" +
10+
"Go to the 'config/sponge/global.conf', scroll to the 'metrics' section and enable metrics.\n" +
11+
"Anonymous metrics data collection enables the developer to see how many people and servers are using this plugin.\n" +
12+
"Seeing that my plugin is being used is a big factor in motivating me to provide future support and updates.\n" +
13+
"If you really don't want to enable metrics and don't want to receive any messages anymore, you can disable this config option ;("
14+
) val enableMetricsMessages: Boolean = true
15+
)

0 commit comments

Comments
 (0)