-
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
1 parent
134bd8b
commit d5fe29d
Showing
5 changed files
with
132 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
47 changes: 47 additions & 0 deletions
47
src/main/kotlin/net/blockventuremc/modules/general/commands/OnlinetimeCommand.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,47 @@ | ||
package net.blockventuremc.modules.general.commands | ||
|
||
import net.blockventuremc.annotations.BlockCommand | ||
import net.blockventuremc.extensions.getLogger | ||
import net.blockventuremc.extensions.sendMessagePrefixed | ||
import net.blockventuremc.extensions.toDatabaseUser | ||
import net.blockventuremc.extensions.translate | ||
import org.bukkit.command.Command | ||
import org.bukkit.command.CommandExecutor | ||
import org.bukkit.command.CommandSender | ||
import org.bukkit.entity.Player | ||
import org.bukkit.permissions.PermissionDefault | ||
import kotlin.time.Duration.Companion.milliseconds | ||
|
||
|
||
@BlockCommand( | ||
name = "onlinetime", | ||
description = "Check your onlinetime", | ||
permission = "blockventure.onlinetime", | ||
permissionDefault = PermissionDefault.TRUE, | ||
usage = "/onlinetime", | ||
aliases = ["ot"] | ||
) | ||
class OnlinetimeCommand : CommandExecutor { | ||
|
||
|
||
override fun onCommand( | ||
sender: CommandSender, | ||
command: Command, | ||
label: String, | ||
args: Array<out String> | ||
): Boolean { | ||
if (sender !is Player) { | ||
val jreRunningSince = System.currentTimeMillis() - java.lang.management.ManagementFactory.getRuntimeMXBean().startTime | ||
val runTimeDuration = jreRunningSince.milliseconds | ||
getLogger().info("The server is running for $runTimeDuration") | ||
return true | ||
} | ||
|
||
val player = sender | ||
val onlinetime = player.toDatabaseUser().onlineTime | ||
|
||
player.sendMessagePrefixed(player.translate("onlinetime", mapOf("onlinetime" to onlinetime.toString()))?.message ?: "You have been online for $onlinetime") | ||
return true | ||
} | ||
|
||
} |
42 changes: 42 additions & 0 deletions
42
src/main/kotlin/net/blockventuremc/modules/general/events/PlayerLoadSaveListener.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,42 @@ | ||
package net.blockventuremc.modules.general.events | ||
|
||
import dev.fruxz.ascend.tool.time.calendar.Calendar | ||
import dev.fruxz.stacked.text | ||
import net.blockventuremc.BlockVenture | ||
import net.blockventuremc.cache.PlayerCache | ||
import org.bukkit.Bukkit | ||
import org.bukkit.event.EventHandler | ||
import org.bukkit.event.EventPriority | ||
import org.bukkit.event.Listener | ||
import org.bukkit.event.player.PlayerJoinEvent | ||
import org.bukkit.event.player.PlayerQuitEvent | ||
|
||
class PlayerLoadSaveListener : Listener { | ||
|
||
|
||
@EventHandler(priority = EventPriority.LOWEST) | ||
fun onJoin(event: PlayerJoinEvent): Unit = with(event) { | ||
player.sendActionBar(text("<green>" + "Loading userdata...")) | ||
Bukkit.getScheduler().runTaskLater(BlockVenture.instance, Runnable { | ||
val pixelPlayer = PlayerCache.reloadPlayer(player.uniqueId).copy( | ||
username = player.name, | ||
lastTimeJoined = Calendar.now() | ||
) | ||
PlayerCache.updateCached( | ||
pixelPlayer | ||
) | ||
player.sendActionBar(text("<green>" + "Loaded userdata...")) | ||
}, 10L) | ||
} | ||
|
||
@EventHandler(priority = EventPriority.HIGHEST) | ||
fun onQuit(event: PlayerQuitEvent): Unit = with(event) { | ||
val databaseUser = PlayerCache.get(player.uniqueId) | ||
PlayerCache.saveToDB( | ||
databaseUser.copy( | ||
username = player.name | ||
) | ||
) | ||
PlayerCache.remove(player.uniqueId) | ||
} | ||
} |
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 |
---|---|---|
@@ -1,3 +1,4 @@ | ||
{ | ||
"build_mode_toggled": "Build mode is now %enabled%." | ||
"build_mode_toggled": "Build mode is now %enabled%.", | ||
"onlinetime": "Your online time is %onlinetime%." | ||
} |