Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions modules/basics-ping/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
| Command | Permission |
|------------------|--------------------|
| `/ping` | basics.ping |
| `/ping <player>` | basics.ping.others |
3 changes: 3 additions & 0 deletions modules/basics-ping/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
plugins {
id("basics.module")
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package com.github.spigotbasics.modules.basicsping

import com.github.spigotbasics.core.command.parsed.CommandContextExecutor
import com.github.spigotbasics.core.command.parsed.arguments.SelectorSinglePlayerArg
import com.github.spigotbasics.core.command.parsed.context.MapContext
import com.github.spigotbasics.core.module.AbstractBasicsModule
import com.github.spigotbasics.core.module.loader.ModuleInstantiationContext
import org.bukkit.command.CommandSender
import org.bukkit.entity.Player

class BasicsPingModule(context: ModuleInstantiationContext) : AbstractBasicsModule(context) {
private val permission =
permissionManager.createSimplePermission(
"basics.ping",
"Allows the player to see their own ping",
)
private val permissionOthers =
permissionManager.createSimplePermission(
"basics.ping.others",
"Allows the player to see the ping of other players",
)

private fun msgPing(ping: Int) = messages.getMessage("ping").tagParsed("ping", ping.toString())

private fun msgPingOthers(
player: Player,
ping: Int,
) = messages.getMessage("ping-others").tagParsed("ping", ping.toString()).concerns(player)

override fun onEnable() {
commandFactory.parsedCommandBuilder("ping", permission).mapContext {
usage = "[player]"
description("Shows the ping of a player")

path {
playerOnly()
}

path {
permissions(permissionOthers)
arguments {
named("player", SelectorSinglePlayerArg("player"))
}
}
}.executor(
object : CommandContextExecutor<MapContext> {
override fun execute(
sender: CommandSender,
context: MapContext,
) {
val target = context["player"] as Player? ?: sender as Player
val message = if (sender == target) msgPing(target.ping) else msgPingOthers(target, target.ping)
message.sendToSender(sender)
}
},
).register()
}
}
3 changes: 3 additions & 0 deletions modules/basics-ping/src/main/resources/basics-module.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
main-class: com.github.spigotbasics.modules.basicsping.BasicsPingModule
name: basics-ping
version: ${moduleVersion}
3 changes: 3 additions & 0 deletions modules/basics-ping/src/main/resources/messages.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Tags: <#ping>
ping: "<def_text>Pong! Your ping is <lite_text><#ping>ms</lite_text>.</def_text>"
ping-others: "<def_text><player-dm><#player-name-genitive-suffix> ping is <lite_text><#ping>ms</lite_text>.</def_text>"
Loading