forked from jeremylvln/Shulker
-
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.
feat(shulker-proxy-agent): add glist, gtp and gfind commands
- Loading branch information
1 parent
c29eac1
commit 850af26
Showing
12 changed files
with
284 additions
and
32 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
32 changes: 32 additions & 0 deletions
32
...nt/src/bungeecord/kotlin/io/shulkermc/proxyagent/bungeecord/commands/GlobalFindCommand.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,32 @@ | ||
package io.shulkermc.proxyagent.bungeecord.commands | ||
|
||
import io.shulkermc.proxyagent.ShulkerProxyAgentCommon | ||
import net.md_5.bungee.api.ChatColor | ||
import net.md_5.bungee.api.CommandSender | ||
import net.md_5.bungee.api.chat.ComponentBuilder | ||
import net.md_5.bungee.api.plugin.Command | ||
|
||
class GlobalFindCommand(private val agent: ShulkerProxyAgentCommon) : Command("gfind", "shulker.command.gfind") { | ||
override fun execute(sender: CommandSender, args: Array<out String>) { | ||
if (!this.hasPermission(sender)) { | ||
sender.sendMessage(*ComponentBuilder("You don't have permission to execute this command.").color(ChatColor.RED).create()) | ||
return | ||
} | ||
|
||
if (args.size != 1) { | ||
sender.sendMessage(*ComponentBuilder("Usage: /gfind <player>").color(ChatColor.RED).create()) | ||
return | ||
} | ||
|
||
val player = args[0] | ||
val playerPosition = this.agent.cache.getPlayerIdFromName(player) | ||
.flatMap { playerId -> this.agent.cache.getPlayerPosition(playerId) } | ||
|
||
if (playerPosition.isEmpty) { | ||
sender.sendMessage(*ComponentBuilder("Player $player not found.").color(ChatColor.RED).create()) | ||
return | ||
} | ||
|
||
sender.sendMessage(*ComponentBuilder("Player $player is connected on proxy ${playerPosition.get().proxyName} and located on server ${playerPosition.get().serverName}.").color(ChatColor.GREEN).create()) | ||
} | ||
} |
48 changes: 48 additions & 0 deletions
48
...nt/src/bungeecord/kotlin/io/shulkermc/proxyagent/bungeecord/commands/GlobalListCommand.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,48 @@ | ||
package io.shulkermc.proxyagent.bungeecord.commands | ||
|
||
import io.shulkermc.proxyagent.ShulkerProxyAgentCommon | ||
import net.md_5.bungee.api.ChatColor | ||
import net.md_5.bungee.api.CommandSender | ||
import net.md_5.bungee.api.ProxyServer | ||
import net.md_5.bungee.api.chat.BaseComponent | ||
import net.md_5.bungee.api.chat.ComponentBuilder | ||
import net.md_5.bungee.api.chat.TextComponent | ||
import net.md_5.bungee.api.plugin.Command | ||
|
||
class GlobalListCommand(private val agent: ShulkerProxyAgentCommon, private val proxyServer: ProxyServer) : Command("glist", "shulker.command.glist") { | ||
override fun execute(sender: CommandSender, args: Array<out String>) { | ||
if (!this.hasPermission(sender)) { | ||
sender.sendMessage(*ComponentBuilder("You don't have permission to execute this command.").color(ChatColor.RED).create()) | ||
return | ||
} | ||
|
||
if (args.size != 1) { | ||
this.showPlayerListInServers(sender, this.proxyServer.servers.keys) | ||
return | ||
} | ||
|
||
val server = args[0] | ||
this.showPlayerListInServers(sender, setOf(server)) | ||
} | ||
|
||
private fun showPlayerListInServers(sender: CommandSender, serverNames: Set<String>) { | ||
sender.sendMessage(*ComponentBuilder("⎯".repeat(63)).color(ChatColor.DARK_GRAY).strikethrough(true).create()) | ||
sender.sendMessage(TextComponent("")) | ||
serverNames.map { serverName -> | ||
sender.sendMessage(*this.createServerListMessage(serverName)) | ||
sender.sendMessage(TextComponent("")) | ||
} | ||
sender.sendMessage(*ComponentBuilder("⎯".repeat(63)).color(ChatColor.DARK_GRAY).strikethrough(true).create()) | ||
} | ||
|
||
private fun createServerListMessage(serverName: String): Array<BaseComponent> { | ||
val playerNames = this.agent.cache.getPlayerNamesFromIds(this.agent.cache.listPlayersInServer(serverName)).values | ||
.sortedBy { it.lowercase() } | ||
.joinToString(", ") { it } | ||
|
||
return ComponentBuilder("$serverName:\n") | ||
.color(ChatColor.WHITE) | ||
.append(ComponentBuilder(playerNames).color(ChatColor.GRAY).currentComponent) | ||
.create() | ||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
...rc/bungeecord/kotlin/io/shulkermc/proxyagent/bungeecord/commands/GlobalTeleportCommand.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,40 @@ | ||
package io.shulkermc.proxyagent.bungeecord.commands | ||
|
||
import io.shulkermc.proxyagent.ShulkerProxyAgentCommon | ||
import net.md_5.bungee.api.ChatColor | ||
import net.md_5.bungee.api.CommandSender | ||
import net.md_5.bungee.api.chat.ComponentBuilder | ||
import net.md_5.bungee.api.plugin.Command | ||
|
||
class GlobalTeleportCommand(private val agent: ShulkerProxyAgentCommon) : Command("gtp", "shulker.command.gtp") { | ||
override fun execute(sender: CommandSender, args: Array<out String>) { | ||
if (!this.hasPermission(sender)) { | ||
sender.sendMessage(*ComponentBuilder("You don't have permission to execute this command.").color(ChatColor.RED).create()) | ||
return | ||
} | ||
|
||
if (args.isEmpty() || args.size > 2) { | ||
sender.sendMessage(*ComponentBuilder("Usage: /gtp <player> [server]").color(ChatColor.RED).create()) | ||
return | ||
} | ||
|
||
val player = args[0] | ||
val playerPosition = this.agent.cache.getPlayerIdFromName(player) | ||
.flatMap { playerId -> this.agent.cache.getPlayerPosition(playerId) } | ||
|
||
if (playerPosition.isEmpty) { | ||
sender.sendMessage(*ComponentBuilder("Player $player not found.").color(ChatColor.RED).create()) | ||
return | ||
} | ||
|
||
if (args.size == 1) { | ||
val server = playerPosition.get().serverName | ||
this.agent.pubSub.teleportPlayerOnServer(player, server) | ||
sender.sendMessage(*ComponentBuilder("Teleported to server $server.").color(ChatColor.GREEN).create()) | ||
} else { | ||
val server = args[1] | ||
this.agent.pubSub.teleportPlayerOnServer(player, server) | ||
sender.sendMessage(*ComponentBuilder("Teleported $player to server $server.").color(ChatColor.GREEN).create()) | ||
} | ||
} | ||
} |
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
6 changes: 6 additions & 0 deletions
6
...er-proxy-agent/src/common/kotlin/io/shulkermc/proxyagent/adapters/pubsub/PubSubAdapter.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,6 @@ | ||
package io.shulkermc.proxyagent.adapters.pubsub | ||
|
||
interface PubSubAdapter { | ||
fun teleportPlayerOnServer(playerId: String, serverName: String) | ||
fun onTeleportPlayerOnServer(callback: (playerId: String, serverName: String) -> Unit) | ||
} |
23 changes: 23 additions & 0 deletions
23
...oxy-agent/src/common/kotlin/io/shulkermc/proxyagent/adapters/pubsub/RedisPubSubAdapter.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,23 @@ | ||
package io.shulkermc.proxyagent.adapters.pubsub | ||
|
||
import redis.clients.jedis.JedisPool | ||
import redis.clients.jedis.JedisPubSub | ||
|
||
class RedisPubSubAdapter(private val jedisPool: JedisPool) : PubSubAdapter { | ||
override fun teleportPlayerOnServer(playerId: String, serverName: String) { | ||
this.jedisPool.resource.use { jedis -> | ||
jedis.publish("shulker:teleport", "$playerId:$serverName") | ||
} | ||
} | ||
|
||
override fun onTeleportPlayerOnServer(callback: (playerId: String, serverName: String) -> Unit) { | ||
this.jedisPool.resource.use { jedis -> | ||
jedis.subscribe(object : JedisPubSub() { | ||
override fun onMessage(channel: String, message: String) { | ||
val (playerId, serverName) = message.split(":") | ||
callback(playerId, serverName) | ||
} | ||
}, "shulker:teleport") | ||
} | ||
} | ||
} |
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
37 changes: 37 additions & 0 deletions
37
...-agent/src/velocity/kotlin/io/shulkermc/proxyagent/velocity/commands/GlobalFindCommand.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,37 @@ | ||
package io.shulkermc.proxyagent.velocity.commands | ||
|
||
import com.mojang.brigadier.Command | ||
import com.mojang.brigadier.arguments.StringArgumentType | ||
import com.mojang.brigadier.builder.LiteralArgumentBuilder | ||
import com.mojang.brigadier.builder.RequiredArgumentBuilder | ||
import com.velocitypowered.api.command.BrigadierCommand | ||
import com.velocitypowered.api.command.CommandSource | ||
import io.shulkermc.proxyagent.ShulkerProxyAgentCommon | ||
import net.kyori.adventure.text.Component | ||
import net.kyori.adventure.text.format.NamedTextColor | ||
|
||
object GlobalFindCommand { | ||
fun create(agent: ShulkerProxyAgentCommon): BrigadierCommand { | ||
val rootNode = LiteralArgumentBuilder.literal<CommandSource>("gfind") | ||
.requires { it.hasPermission("shulker.command.gfind") } | ||
.then(RequiredArgumentBuilder.argument<CommandSource, String>("player", StringArgumentType.word()) | ||
.executes { context -> | ||
val source = context.source | ||
val player = context.getArgument("player", String::class.java) | ||
val playerPosition = agent.cache.getPlayerIdFromName(player) | ||
.flatMap { playerId -> agent.cache.getPlayerPosition(playerId) } | ||
|
||
if (playerPosition.isEmpty) { | ||
source.sendMessage(Component.text("Player $player not found.", NamedTextColor.RED)) | ||
return@executes Command.SINGLE_SUCCESS | ||
} | ||
|
||
source.sendMessage(Component.text("Player $player is connected on proxy ${playerPosition.get().proxyName} and located on server ${playerPosition.get().serverName}.", NamedTextColor.GREEN)) | ||
return@executes Command.SINGLE_SUCCESS | ||
} | ||
) | ||
.build() | ||
|
||
return BrigadierCommand(rootNode) | ||
} | ||
} |
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
Oops, something went wrong.