Skip to content

Commit

Permalink
🎨 removed forgotten commented out code, implemented playtime reset
Browse files Browse the repository at this point in the history
Took 12 minutes
  • Loading branch information
itsTyrion committed Oct 12, 2023
1 parent e6c2a8e commit d1d9e4d
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 93 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ class OnlineTimeCommand(private val plugin: BungeeOnlineTimePlugin, cmd: String,
if (checkPermission(sender, "onlinetime.reset")) {
val name = args[1]
base.sendReset(name) { msg, placeholders -> send(sender, msg, placeholders) }
val player = plugin.proxy.getPlayer(name)
if (player != null)
plugin.onlineTimePlayers[player.uniqueId]!!.setSavedOnlineTime(0L)
}

} else if (args.size == 1 && arg0 == "resetall") {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ class OnlineTimeCommandBase(
var rank = (page - 1) * topOnlineTimePageLimit + 1
val headerPlaceholders = mapOf("%PAGE%" to page)
sendMessage.accept(config.language.topTimeAbove, headerPlaceholders)
// sendMessage(player, config.language.topTimeAbove, headerPlaceholders)

for (onlineTime in response) {
val sessionTime = onlineTimePlayers.get()[onlineTime.uuid]?.getSessionOnlineTime() ?: 0
Expand All @@ -68,21 +67,18 @@ class OnlineTimeCommandBase(
"%MINUTES%" to total.toMinutes() % 60
)
sendMessage.accept(config.language.topTime, placeholders)
// sendMessage(player, config.language.topTime, placeholders)
rank++
}
sendMessage.accept(config.language.topTimeBelow, headerPlaceholders)
// sendMessage(player, config.language.topTimeBelow, headerPlaceholders)
}, onError = { e ->
sendMessage.accept(config.language.error, null)
// sendMessage(player, config.language.error)
logger.error("Error while loading top online times.", e)
})
}

fun sendReset(targetPlayerName: String, sendMessage: BiConsumer<String, Map<String, Any>?>) {
asyncTask(doTask = {
null
database.resetOnlineTime(targetPlayerName)
}, onSuccess = {
sendMessage.accept(config.language.resetPlayer, mapOf("%PLAYER%" to targetPlayerName))
}, onError = { e ->
Expand All @@ -94,6 +90,7 @@ class OnlineTimeCommandBase(
fun sendResetAll(sendMessage: BiConsumer<String, Map<String, Any>?>) {
asyncTask(doTask = {
database.resetAllOnlineTimes()
onlineTimePlayers.get().forEach { (_, value) -> value.setSavedOnlineTime(0L) }
}, onSuccess = {
sendMessage.accept(config.language.resetAll, emptyMap())
}, onError = { e ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,127 +33,42 @@ class OnlineTimeCommand(private val plugin: VelocityOnlineTimePlugin) : SimpleCo
if (size == 0) {
if (checkPermission(sender, "onlinetime.own")) {
val name = sender.username
// sendOnlineTime(sender, name)
base.sendOnlineTime(name) { msg, placeholders -> sendMessage(sender, msg, placeholders) }
}

} else if (size == 2 && arg0 == "get") {

if (checkPermission(sender, "onlinetime.others")) {
val name = args[1]
// sendOnlineTime(sender, name)
base.sendOnlineTime(name) { msg, placeholders -> sendMessage(sender, msg, placeholders) }
}

} else if ((size == 1 || size == 2) && arg0 == "top") {

if (checkPermission(sender, "onlinetime.top")) {
val page = max(args[1].toIntOrNull() ?: 1, 1)
// sendTopOnlineTimes(sender, page)
base.sendTopOnlineTimes(page) { msg, placeholders -> sendMessage(sender, msg, placeholders) }
}

} else if (args.size == 2 && arg0 == "reset") {

if (checkPermission(sender, "onlinetime.reset")) {
val name = args[1]
// sendReset(sender, name)
base.sendReset(name) { msg, placeholders -> sendMessage(sender, msg, placeholders) }
plugin.proxy.getPlayer(name)
.ifPresent { plugin.onlineTimePlayers[it.uniqueId]!!.setSavedOnlineTime(0L) }
}

} else if (args.size == 1 && arg0 == "resetall") {

if (checkPermission(sender, "onlinetime.resetall"))
// sendResetAll(sender)
base.sendResetAll { msg, placeholders -> sendMessage(sender, msg, placeholders) }

} else {
sendMessage(sender, config.language.help)
}
}

/*private fun sendOnlineTime(player: Player, targetPlayerName: String) {
asyncTask(doTask = {
plugin.database.getOnlineTime(targetPlayerName)
}, onSuccess@{ response ->
if (response.isEmpty()) {
val placeholders = mapOf("%PLAYER%" to targetPlayerName)
sendMessage(player, config.language.playerNotFound, placeholders)
return@onSuccess
}
for (onlineTime in response) {
val sessionTime = plugin.onlineTimePlayers[onlineTime.uuid]?.getSessionOnlineTime() ?: 0
val total = Duration.ofMillis(onlineTime.time + sessionTime)
val placeholders = mapOf(
"%PLAYER%" to onlineTime.name,
"%HOURS%" to total.toHours() % 24,
"%MINUTES%" to total.toMinutes() % 60
)
sendMessage(player, config.language.onlineTime, placeholders)
}
}, onError = { e ->
sendMessage(player, config.language.error)
logger.error("Error while loading online time for player $targetPlayerName.", e)
})
}*/

/*private fun sendTopOnlineTimes(player: Player, page: Int) {
val topOnlineTimePageLimit = config.plugin.topOnlineTimePageLimit
AsyncTask().exec(doTask = {
plugin.database.getTopOnlineTimes(page, topOnlineTimePageLimit)
}, onSuccess = { response ->
var rank = (page - 1) * topOnlineTimePageLimit + 1
val headerPlaceholders = mapOf("%PAGE%" to page)
sendMessage(player, config.language.topTimeAbove, headerPlaceholders)
for (onlineTime in response) {
val sessionTime = plugin.onlineTimePlayers[onlineTime.uuid]?.getSessionOnlineTime() ?: 0
val total = Duration.ofMillis(onlineTime.time + sessionTime)
val placeholders = mapOf(
"%RANK%" to rank,
"%PLAYER%" to onlineTime.name,
"%HOURS%" to total.toHours() % 24,
"%MINUTES%" to total.toMinutes() % 60
)
sendMessage(player, config.language.topTime, placeholders)
rank++
}
sendMessage(player, config.language.topTimeBelow, headerPlaceholders)
}, onError = { e ->
sendMessage(player, config.language.error)
logger.error("Error while loading top online times.", e)
})
}*/

/*private fun sendReset(player: Player, targetPlayerName: String) {
AsyncTask().exec(doTask = {
null
}, onSuccess = {
sendMessage(player, config.language.resetPlayer, mapOf("%PLAYER%" to targetPlayerName))
}, onError = { e ->
sendMessage(player, config.language.error)
logger.error("Error while resetting online time for player $targetPlayerName.", e)
})
}*/

/*private fun sendResetAll(player: Player) {
AsyncTask().exec(doTask = {
plugin.database.resetAllOnlineTimes()
}, onSuccess = {
sendMessage(player, config.language.resetAll)
}, onError = { e ->
sendMessage(player, config.language.error)
logger.error("Error while resetting online time database.", e)
})
}*/

private fun sendMessage(sender: CommandSource, messageId: String, placeholders: Map<String, Any>? = emptyMap()) {
var message = messageId
if (placeholders != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import java.util.concurrent.TimeUnit

@Plugin(id = "onlinetime", name = "OnlineTime")
class VelocityOnlineTimePlugin @Inject constructor(
private val proxy: ProxyServer,
val proxy: ProxyServer,
val logger: Logger,
@DataDirectory val dataFolder: Path
) {
Expand Down

0 comments on commit d1d9e4d

Please sign in to comment.