Skip to content

Commit a0424dc

Browse files
author
BuildTools
committed
Added new lunar api. fixed jtp, online staff and lookup not using redis server status cheking and l
1 parent caed06e commit a0424dc

File tree

8 files changed

+185
-123
lines changed

8 files changed

+185
-123
lines changed

spigot/build.gradle

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ repositories {
1616
name = "gravemc-repo"
1717
url = "https://repo.gravemc.net/releases/"
1818
}
19+
maven {
20+
name = 'lunarclient'
21+
url = 'https://repo.lunarclient.dev'
22+
}
1923
}
2024

2125
dependencies {
@@ -33,6 +37,7 @@ dependencies {
3337
compileOnly "com.github.MilkBowl:VaultAPI:1.7"
3438
implementation "club.minnced:discord-webhooks:0.8.2"
3539
compileOnly 'net.luckperms:api:5.4'
40+
compileOnly 'com.lunarclient:apollo-api:1.1.8'
3641
compileOnly 'net.md-5:bungeecord-api:1.19-R0.1-SNAPSHOT'
3742
compileOnly 'com.mojang:authlib:1.5.21' //1.5.21
3843

spigot/src/main/kotlin/ltd/matrixstudios/alchemist/client/commands/LunarClientCommands.kt

Lines changed: 108 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -4,49 +4,135 @@ import co.aikar.commands.BaseCommand
44
import co.aikar.commands.CommandHelp
55
import co.aikar.commands.annotation.*
66
import co.aikar.commands.bukkit.contexts.OnlinePlayer
7-
import com.lunarclient.bukkitapi.LunarClientAPI
7+
import com.lunarclient.apollo.Apollo
8+
import com.lunarclient.apollo.module.notification.Notification
9+
import com.lunarclient.apollo.module.notification.NotificationModule
10+
import com.lunarclient.apollo.module.staffmod.StaffMod
11+
import com.lunarclient.apollo.module.staffmod.StaffModModule
12+
import com.lunarclient.apollo.player.ApolloPlayer
813
import ltd.matrixstudios.alchemist.api.AlchemistAPI
914
import ltd.matrixstudios.alchemist.util.Chat
15+
import net.kyori.adventure.text.Component
16+
import net.kyori.adventure.text.format.NamedTextColor
1017
import org.bukkit.Bukkit
1118
import org.bukkit.command.CommandSender
19+
import java.time.Duration
20+
21+
object LunarClientNotifier {
22+
23+
/**
24+
*
25+
*
26+
* @param apolloPlayer The Apollo player to send the notification to.
27+
* @param title The title component
28+
* @param description The description component
29+
* @param icon Optional resource icon path (default: "icons/golden_apple.png").
30+
* @param duration Duration to display the notification (default: 5 seconds).
31+
*/
32+
fun sendNotification(
33+
apolloPlayer: ApolloPlayer,
34+
title: Component,
35+
description: Component,
36+
icon: String = "icons/golden_apple.png",
37+
duration: Duration = Duration.ofSeconds(5)
38+
) {
39+
val notificationModule = Apollo.getModuleManager()
40+
.getModule(NotificationModule::class.java) ?: return
41+
42+
try {
43+
// Build the notification via reflection kinda scuff need to unrelocate adventure api
44+
val builder = Notification::class.java.getDeclaredMethod("builder").invoke(null)
45+
46+
val titleMethod = builder.javaClass.getMethod("titleComponent", Any::class.java)
47+
val descriptionMethod = builder.javaClass.getMethod("descriptionComponent", Any::class.java)
48+
val resourceMethod = builder.javaClass.getMethod("resourceLocation", String::class.java)
49+
val displayTimeMethod = builder.javaClass.getMethod("displayTime", Duration::class.java)
50+
val buildMethod = builder.javaClass.getMethod("build")
51+
52+
titleMethod.invoke(builder, title)
53+
descriptionMethod.invoke(builder, description)
54+
resourceMethod.invoke(builder, icon)
55+
displayTimeMethod.invoke(builder, duration)
56+
57+
val notification = buildMethod.invoke(builder)
58+
val displayMethod = notificationModule.javaClass.getMethod("displayNotification", ApolloPlayer::class.java, Notification::class.java)
59+
displayMethod.invoke(notificationModule, apolloPlayer, notification)
60+
61+
} catch (e: Exception) {
62+
e.printStackTrace()
63+
}
64+
}
65+
}
1266

13-
/**
14-
* Class created on 9/13/2023
1567

16-
* @author 98ping
17-
* @project Alchemist
18-
* @website https://solo.to/redis
19-
*/
2068
@CommandAlias("lunarclient|lc")
2169
@CommandPermission("alchemist.clients.lunar")
22-
object LunarClientCommands : BaseCommand()
23-
{
70+
object LunarClientCommands : BaseCommand() {
2471

2572
@HelpCommand
26-
fun help(help: CommandHelp)
27-
{
73+
fun help(help: CommandHelp) {
2874
help.showHelp()
2975
}
3076

77+
78+
fun enableStaffModules(apolloPlayer: ApolloPlayer) {
79+
val staffModModule = Apollo.getModuleManager().getModule(StaffModModule::class.java)
80+
staffModModule?.enableStaffMods(apolloPlayer, listOf(StaffMod.XRAY))
81+
}
82+
fun disableStaffModules(apolloPlayer: ApolloPlayer) {
83+
val staffModModule = Apollo.getModuleManager().getModule(StaffModModule::class.java)
84+
staffModModule?.disableStaffMods(apolloPlayer, listOf(StaffMod.XRAY))
85+
}
86+
87+
88+
3189
@Subcommand("players")
32-
fun players(player: CommandSender)
33-
{
90+
fun players(sender: CommandSender) {
3491
val start = System.currentTimeMillis()
3592
val count = Bukkit.getOnlinePlayers().count {
36-
LunarClientAPI.getInstance().isRunningLunarClient(it)
93+
Apollo.getPlayerManager().hasSupport(it.uniqueId)
3794
}
3895

39-
player.sendMessage(Chat.format("&eThis server has a total of &a${count} &eplayers that run &bLunar Client&e."))
40-
player.sendMessage(Chat.format("&7To check a specific user's status, execute /lc check <player>"))
41-
player.sendMessage(Chat.format("&8(This lookup took ${System.currentTimeMillis().minus(start)} milliseconds)"))
96+
sender.sendMessage(Chat.format("&eThere are &a$count &eplayers running &bLunar Client&e."))
97+
sender.sendMessage(Chat.format("&7To check a specific user's status: /lc check <player>"))
98+
sender.sendMessage(Chat.format("&8(This lookup took ${System.currentTimeMillis() - start} ms)"))
4299
}
43100

44101
@Subcommand("check")
45102
@CommandCompletion("@players")
46-
fun check(player: CommandSender, @Name("target") target: OnlinePlayer)
47-
{
48-
val isUsing = LunarClientAPI.getInstance().isRunningLunarClient(target.player)
103+
fun check(sender: CommandSender, @Name("target") target: OnlinePlayer) {
104+
val isUsing = Apollo.getPlayerManager().hasSupport(target.player.uniqueId)
105+
sender.sendMessage(
106+
Chat.format(
107+
"&r${AlchemistAPI.getRankDisplay(target.player.uniqueId)} &eis " +
108+
"${if (isUsing) "&acurrently" else "&cnot currently"} &eusing &bLunar Client&e."
109+
)
110+
)
111+
}
112+
113+
@Subcommand("staffmodules")
114+
@CommandCompletion("@players")
115+
fun staffModules(sender: CommandSender, @Name("target") target: OnlinePlayer) {
116+
val uuid = target.player.uniqueId
117+
val apolloOpt = Apollo.getPlayerManager().getPlayer(uuid)
118+
119+
if (!apolloOpt.isPresent) {
120+
sender.sendMessage(Chat.format("&cThat player is not running Lunar Client."))
121+
return
122+
}
123+
124+
val apolloPlayer = apolloOpt.get()
125+
126+
enableStaffModules(apolloPlayer)
127+
128+
// LunarClientNotifier.sendNotification(
129+
// apolloPlayer,
130+
// Component.text("Staff Modules Enabled", NamedTextColor.GREEN),
131+
// Component.text("XRAY staff mod has been enabled.", NamedTextColor.WHITE)
132+
//Need to un relocate adventure api )
49133

50-
player.sendMessage(Chat.format("&r${AlchemistAPI.getRankDisplay(target.player.uniqueId)} &eis ${if (isUsing) "&acurrently" else "&cnot currently"} &eusing &bLunar Client&e."))
134+
sender.sendMessage(
135+
Chat.format("&r${AlchemistAPI.getRankDisplay(uuid)} &ehas been given &bLunar Client &eStaff Modules.")
136+
)
51137
}
52-
}
138+
}

spigot/src/main/kotlin/ltd/matrixstudios/alchemist/client/feature/NameTagFeature.kt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ object NameTagFeature
2727
),
2828
viewer
2929
)
30-
LunarClientAPI.getInstance().giveAllStaffModules(target)
3130
}
3231

3332
fun startNametagUpdateTask()
@@ -58,7 +57,6 @@ object NameTagFeature
5857
{
5958
Bukkit.getServer().onlinePlayers.forEach { staff ->
6059
LunarClientAPI.getInstance().resetNametag(player, staff)
61-
LunarClientAPI.getInstance().disableAllStaffModules(player)
6260
}
6361
}
6462
}

spigot/src/main/kotlin/ltd/matrixstudios/alchemist/profiles/commands/player/LookupCommand.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,12 @@ class LookupCommand : BaseCommand()
3030
{
3131
override fun run()
3232
{
33-
val serverFromProfile = gameProfile.metadata.get("server")
33+
//val serverFromProfile = gameProfile.metadata.get("server")
3434
val serverFromRedis = RedisOnlineStatusService.getOnlineServer(gameProfile.uuid) //is stored as string
3535

36-
if (serverFromProfile != null && !serverFromProfile.asString.equals("None", ignoreCase = true))
36+
if (serverFromRedis != null && !serverFromRedis.equals("None", ignoreCase = true))
3737
{
38-
player.sendMessage(Chat.format(AlchemistAPI.getRankDisplay(gameProfile.uuid) + " &ewas found on &f${serverFromRedis} &fMongo: ${serverFromProfile.asString}"))
38+
player.sendMessage(Chat.format(AlchemistAPI.getRankDisplay(gameProfile.uuid) + " &ewas found on &f${serverFromRedis}"))
3939
} else
4040
{
4141
player.sendMessage(

spigot/src/main/kotlin/ltd/matrixstudios/alchemist/staff/commands/JumpToPlayerCommand.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import ltd.matrixstudios.alchemist.api.AlchemistAPI
99
import ltd.matrixstudios.alchemist.models.profile.GameProfile
1010
import ltd.matrixstudios.alchemist.packets.StaffGeneralMessagePacket
1111
import ltd.matrixstudios.alchemist.redis.AsynchronousRedisSender
12+
import ltd.matrixstudios.alchemist.redis.RedisOnlineStatusService
1213
import ltd.matrixstudios.alchemist.service.server.UniqueServerService
1314
import ltd.matrixstudios.alchemist.util.Chat
1415
import ltd.matrixstudios.alchemist.util.NetworkUtil
@@ -31,7 +32,7 @@ class JumpToPlayerCommand : BaseCommand()
3132
fun jumpTo(player: Player, @Name("target") target: GameProfile)
3233
{
3334
val globalServer = Alchemist.globalServer
34-
val onlineServer = target.metadata.get("server").asString
35+
val onlineServer = RedisOnlineStatusService.getOnlineServer(target.uuid) ?: "None"
3536
val uniqueServer = UniqueServerService.byId(onlineServer.lowercase(Locale.getDefault()))
3637

3738
if (uniqueServer == null || onlineServer.lowercase(Locale.getDefault()).equals("None", ignoreCase = true))
Lines changed: 24 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,64 +1,47 @@
11
package ltd.matrixstudios.alchemist.staff.commands
22

33
import co.aikar.commands.BaseCommand
4-
import co.aikar.commands.annotation.*
4+
import co.aikar.commands.annotation.CommandAlias
5+
import co.aikar.commands.annotation.CommandPermission
56
import ltd.matrixstudios.alchemist.api.AlchemistAPI
7+
import ltd.matrixstudios.alchemist.redis.RedisOnlineStatusService
68
import ltd.matrixstudios.alchemist.redis.RedisVanishStatusService
7-
import ltd.matrixstudios.alchemist.servers.*
89
import ltd.matrixstudios.alchemist.service.server.UniqueServerService
910
import ltd.matrixstudios.alchemist.util.Chat
1011
import org.bukkit.entity.Player
1112
import java.util.*
1213

13-
/**
14-
* Class created on 5/14/2023
15-
16-
* @author 98ping, AB987
17-
* @project Alchemist
18-
* @website https://solo.to/redis
19-
*/
20-
class OnlineStaffCommand : BaseCommand()
21-
{
14+
class OnlineStaffCommand : BaseCommand() {
2215

2316
@CommandAlias("onlinestaff|globalstaff|stafflist")
2417
@CommandPermission("alchemist.staff.list")
25-
fun onlineStaff(player: Player)
26-
{
27-
val allPlayers = mutableListOf<UUID>()
28-
val servers = UniqueServerService.getValues()
18+
fun onlineStaff(player: Player) {
19+
val allPlayers = mutableSetOf<UUID>()
2920
val msgs = mutableListOf<String>()
3021

31-
for (server in servers)
32-
{
33-
for (player1 in server.players)
34-
{
35-
if (!allPlayers.contains(player1))
36-
{
37-
allPlayers.add(player1)
38-
}
39-
}
22+
for (server in UniqueServerService.getValues()) {
23+
allPlayers.addAll(server.players)
4024
}
4125

42-
for (player2 in allPlayers)
43-
{
44-
val profile = AlchemistAPI.syncFindProfile(player2) ?: continue
45-
val serverName = UniqueServerService.byId(profile.metadata.get("server").asString.lowercase())?.displayName
46-
?: "&cUnknown"
26+
for (uuid in allPlayers) {
27+
val profile = AlchemistAPI.syncFindProfile(uuid) ?: continue
28+
if (!profile.getCurrentRank().staff) continue
4729

48-
if (profile.getCurrentRank().staff)
49-
{
50-
val isVanished = RedisVanishStatusService.isVanished(profile.uuid)
51-
val vanishPrefix = if (isVanished) "&7[V] " else ""
52-
53-
msgs.add(Chat.format("&7- " + vanishPrefix + AlchemistAPI.getRankDisplay(profile.uuid) + " &eis currently &aonline &eat &f" + serverName))
30+
val redisServer = RedisOnlineStatusService.getOnlineServer(uuid)
31+
val serverName = if (redisServer != null) {
32+
UniqueServerService.byId(redisServer.lowercase(Locale.getDefault()))?.displayName
33+
?: "&cUnknown"
34+
} else {
35+
"&cUnknown"
5436
}
5537

38+
val isVanished = RedisVanishStatusService.isVanished(uuid)
39+
val vanishPrefix = if (isVanished) "&7[V] " else ""
40+
41+
msgs.add("&7- $vanishPrefix${AlchemistAPI.getRankDisplay(uuid)} &eis currently &aonline &eat &f$serverName")
5642
}
43+
5744
player.sendMessage(Chat.format("&e&lOnline Staff Members&7:"))
58-
for (msg in msgs)
59-
{
60-
player.sendMessage(Chat.format(msg))
61-
}
45+
msgs.forEach { player.sendMessage(Chat.format(it)) }
6246
}
63-
64-
}
47+
}

spigot/src/main/kotlin/ltd/matrixstudios/alchemist/staff/mode/StaffSuiteManager.kt

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
package ltd.matrixstudios.alchemist.staff.mode
22

3+
import com.lunarclient.apollo.Apollo
4+
import com.lunarclient.bukkitapi.LunarClientAPI
5+
import com.lunarclient.bukkitapi.`object`.StaffModule
36
import ltd.matrixstudios.alchemist.AlchemistSpigotPlugin
47
import ltd.matrixstudios.alchemist.client.LunarClientExtension
8+
import ltd.matrixstudios.alchemist.client.commands.LunarClientCommands
59
import ltd.matrixstudios.alchemist.client.feature.NameTagFeature
610
import ltd.matrixstudios.alchemist.client.feature.TeamViewFeature
711
import ltd.matrixstudios.alchemist.service.profiles.ProfileGameService
@@ -58,6 +62,11 @@ object StaffSuiteManager
5862
{
5963
TeamViewFeature.clearTeamView(player)
6064
NameTagFeature.removeNameTag(player)
65+
LunarClientAPI.getInstance().disableAllStaffModules(player)
66+
LunarClientAPI.getInstance().setStaffModuleState(player, StaffModule.XRAY, false)
67+
Apollo.getPlayerManager().getPlayer(player.uniqueId).ifPresent { apolloPlayer ->
68+
LunarClientCommands.disableStaffModules(apolloPlayer)
69+
}
6170
}
6271

6372
player.removeMetadata("modmode", AlchemistSpigotPlugin.instance)
@@ -92,6 +101,11 @@ object StaffSuiteManager
92101
player.inventory.armorContents = null
93102

94103
StaffItems.equip(player)
104+
//LunarClientAPI.getInstance().giveAllStaffModules(player)
105+
//LunarClientAPI.getInstance().setStaffModuleState(player, StaffModule.XRAY, true)
106+
Apollo.getPlayerManager().getPlayer(player.uniqueId).ifPresent { apolloPlayer ->
107+
LunarClientCommands.enableStaffModules(apolloPlayer)
108+
}
95109

96110
player.updateInventory()
97111

0 commit comments

Comments
 (0)