From 8ca0285aeb88f46873d43b46bb603f7591312440 Mon Sep 17 00:00:00 2001 From: 98ping <67809373+98ping@users.noreply.github.com> Date: Thu, 20 Jul 2023 20:54:38 -0700 Subject: [PATCH] chore: work on the login events and fix some modmode issues --- .../grant/scope/ScopeSelectionEditorMenu.kt | 7 +- .../menu/grant/scope/ScopeSelectionMenu.kt | 6 +- .../profiles/BukkitProfileAdaptation.kt | 112 +++--------------- .../alchemist/profiles/ProfileJoinListener.kt | 9 +- .../postlog/BukkitPostLoginConnection.kt | 14 ++- .../profiles/postlog/BukkitPostLoginTask.kt | 15 +++ .../profiles/postlog/tasks/CheckBanEvasion.kt | 34 ++++++ .../profiles/postlog/tasks/LoadPermissions.kt | 30 +++++ .../postlog/tasks/SendStaffWelcome.kt | 45 +++++++ .../prelog/BukkitPreLoginConnection.kt | 18 ++- .../profiles/prelog/BukkitPreLoginTask.kt | 18 +++ .../prelog/tasks/CalculateGrantables.kt | 36 ++++++ .../prelog/tasks/HandlePunishments.kt | 56 +++++++++ .../profiles/prelog/tasks/LoadProfile.kt | 42 +++++++ .../packets/PunishmentRemovePacket.kt | 2 +- .../GenericStaffmodePreventionListener.kt | 18 --- .../StaffmodeFunctionalityListener.kt | 25 ---- 17 files changed, 333 insertions(+), 154 deletions(-) create mode 100644 spigot/src/main/kotlin/ltd/matrixstudios/alchemist/profiles/postlog/BukkitPostLoginTask.kt create mode 100644 spigot/src/main/kotlin/ltd/matrixstudios/alchemist/profiles/postlog/tasks/CheckBanEvasion.kt create mode 100644 spigot/src/main/kotlin/ltd/matrixstudios/alchemist/profiles/postlog/tasks/LoadPermissions.kt create mode 100644 spigot/src/main/kotlin/ltd/matrixstudios/alchemist/profiles/postlog/tasks/SendStaffWelcome.kt create mode 100644 spigot/src/main/kotlin/ltd/matrixstudios/alchemist/profiles/prelog/BukkitPreLoginTask.kt create mode 100644 spigot/src/main/kotlin/ltd/matrixstudios/alchemist/profiles/prelog/tasks/CalculateGrantables.kt create mode 100644 spigot/src/main/kotlin/ltd/matrixstudios/alchemist/profiles/prelog/tasks/HandlePunishments.kt create mode 100644 spigot/src/main/kotlin/ltd/matrixstudios/alchemist/profiles/prelog/tasks/LoadProfile.kt diff --git a/spigot/src/main/kotlin/ltd/matrixstudios/alchemist/commands/grants/menu/grant/scope/ScopeSelectionEditorMenu.kt b/spigot/src/main/kotlin/ltd/matrixstudios/alchemist/commands/grants/menu/grant/scope/ScopeSelectionEditorMenu.kt index 1c2158ae9..f27b41f97 100644 --- a/spigot/src/main/kotlin/ltd/matrixstudios/alchemist/commands/grants/menu/grant/scope/ScopeSelectionEditorMenu.kt +++ b/spigot/src/main/kotlin/ltd/matrixstudios/alchemist/commands/grants/menu/grant/scope/ScopeSelectionEditorMenu.kt @@ -46,8 +46,7 @@ class ScopeSelectionEditorMenu( Chat.format("&7Making this a global grant means that"), Chat.format("&7this grant will apply on every scope."), Chat.format(" "), - Chat.format("&7Currently&7: &f" + if (global) "&aGlobal" else "&cLocal"), - Chat.format("&e&lLeft-Click &eto change the global status of this grant"), + Chat.format("&e&lLeft-Click &eto change global status to " + (if (global) "&cfalse" else "&atrue") + "&e."), Chat.format(" ") ), Chat.format("&e&lGlobal Status"), 0 ).setBody { player, i, clickType -> @@ -112,10 +111,10 @@ class ScopeSelectionEditorMenu( override fun getDescription(player: Player): MutableList? { val desc = mutableListOf() desc.add(Chat.format(" ")) - desc.add(Chat.format("&7Click to " + if (equipped.contains(uniqueServer.id)) "&aadd" else "&cremove" + " &f${uniqueServer.displayName}")) + desc.add(Chat.format("&7Click to " + (if (equipped.contains(uniqueServer.id)) "&cremove" else "&aadd") + " &7${uniqueServer.displayName}")) desc.add(Chat.format("&7to the active scope list.")) desc.add(Chat.format(" ")) - desc.add(Chat.format("&e&lLeft-Click &eto " + if (equipped.contains(uniqueServer.id)) "unselect" else "select" + " this server")) + desc.add(Chat.format("&e&lLeft-Click &eto " + (if (equipped.contains(uniqueServer.id)) "unselect" else "select") + " this server")) desc.add(Chat.format(" ")) return desc diff --git a/spigot/src/main/kotlin/ltd/matrixstudios/alchemist/commands/grants/menu/grant/scope/ScopeSelectionMenu.kt b/spigot/src/main/kotlin/ltd/matrixstudios/alchemist/commands/grants/menu/grant/scope/ScopeSelectionMenu.kt index 622f6bb27..309767b0a 100644 --- a/spigot/src/main/kotlin/ltd/matrixstudios/alchemist/commands/grants/menu/grant/scope/ScopeSelectionMenu.kt +++ b/spigot/src/main/kotlin/ltd/matrixstudios/alchemist/commands/grants/menu/grant/scope/ScopeSelectionMenu.kt @@ -53,7 +53,7 @@ class ScopeSelectionMenu( Chat.format("&7Making this a global grant means that"), Chat.format("&7this grant will apply on every scope."), Chat.format(" "), - Chat.format("&e&lLeft-Click &eto change global status to " + if (global) "&cfalse" else "&atrue" + "&e."), + Chat.format("&e&lLeft-Click &eto change global status to " + (if (global) "&cfalse" else "&atrue") + "&e."), Chat.format(" ") ), Chat.format("&e&lGlobal Status"), 0 ).setBody { player, i, clickType -> @@ -135,10 +135,10 @@ class ScopeSelectionMenu( override fun getDescription(player: Player): MutableList? { val desc = mutableListOf() desc.add(Chat.format(" ")) - desc.add(Chat.format("&7Click to " + if (equipped.contains(uniqueServer.id)) "&cremove" else "&aadd" + " &7${uniqueServer.displayName}")) + desc.add(Chat.format("&7Click to " + (if (equipped.contains(uniqueServer.id)) "&cremove" else "&aadd") + " &7${uniqueServer.displayName}")) desc.add(Chat.format("&7to the active scope list.")) desc.add(Chat.format(" ")) - desc.add(Chat.format("&e&lLeft-Click &eto " + if (equipped.contains(uniqueServer.id)) "unselect" else "select" + " this server")) + desc.add(Chat.format("&e&lLeft-Click &eto " + (if (equipped.contains(uniqueServer.id)) "unselect" else "select") + " this server")) desc.add(Chat.format(" ")) return desc diff --git a/spigot/src/main/kotlin/ltd/matrixstudios/alchemist/profiles/BukkitProfileAdaptation.kt b/spigot/src/main/kotlin/ltd/matrixstudios/alchemist/profiles/BukkitProfileAdaptation.kt index 603ae31b0..d30226b39 100644 --- a/spigot/src/main/kotlin/ltd/matrixstudios/alchemist/profiles/BukkitProfileAdaptation.kt +++ b/spigot/src/main/kotlin/ltd/matrixstudios/alchemist/profiles/BukkitProfileAdaptation.kt @@ -15,13 +15,15 @@ import ltd.matrixstudios.alchemist.redis.AsynchronousRedisSender import ltd.matrixstudios.alchemist.service.expirable.PunishmentService import ltd.matrixstudios.alchemist.service.expirable.RankGrantService import ltd.matrixstudios.alchemist.service.profiles.ProfileGameService +import ltd.matrixstudios.alchemist.staff.mode.StaffSuiteManager import ltd.matrixstudios.alchemist.util.Chat import ltd.matrixstudios.alchemist.util.SHA import ltd.matrixstudios.alchemist.util.TimeUtil import org.bukkit.Bukkit import org.bukkit.entity.Player import org.bukkit.event.player.AsyncPlayerPreLoginEvent -import java.util.UUID +import java.text.SimpleDateFormat +import java.util.* import java.util.concurrent.CompletableFuture import java.util.logging.Level @@ -32,110 +34,24 @@ import java.util.logging.Level * @project Alchemist * @website https://solo.to/redis */ -object BukkitProfileAdaptation -{ +object BukkitProfileAdaptation { fun loadAllEvents() { - BukkitPreLoginConnection.registerNewCallback { event -> - loadAndEquipProfile(event) - } - - BukkitPreLoginConnection.registerNewCallback { event -> - calculateAndPostGrantables(event.uniqueId) - } - - BukkitPreLoginConnection.registerNewLazyCallback { event -> - handlePunishmentsUsingEvent(event.uniqueId, event) - } - - BukkitPostLoginConnection.registerNewCallback { player -> - dispatchPermissionAttatchment(player) - } - - BukkitPostLoginConnection.registerNewLazyCallback { player -> - ensurePlayerIsNotBanEvading(player.uniqueId) - } - } - - fun loadAndEquipProfile(event: AsyncPlayerPreLoginEvent) { - val start = System.currentTimeMillis() - val profile = ProfileGameService.loadProfile(event.uniqueId, event.name) - - Bukkit.getLogger().log(Level.INFO, "Profile of " + event.name + " loaded in " + System.currentTimeMillis().minus(start) + "ms") - MetricService.addMetric("Profile Service", Metric("Profile Service", System.currentTimeMillis().minus(start), System.currentTimeMillis())) - - val hostAddress = event.address.hostAddress - val output = SHA.toHexString(hostAddress)!! - val currentServer = Alchemist.globalServer - - profile.lastSeenAt = System.currentTimeMillis() - profile.ip = output - profile.currentSession = profile.createNewSession(currentServer) - - ProfileGameService.save(profile) - } - - fun dispatchPermissionAttatchment(player: Player) { - val profile = ProfileGameService.byId(player.uniqueId) ?: return - val startPerms = System.currentTimeMillis() - CompletableFuture.runAsync { - AccessiblePermissionHandler.update(player, profile.getPermissions()) + for (task in BukkitPreLoginConnection.getAllTasks()) { + if (!task.shouldBeLazy()) { + BukkitPreLoginConnection.registerNewCallback { + task.run(it) + } + } else BukkitPreLoginConnection.registerNewLazyCallback { task.run(it) } } - MetricService.addMetric("Permission Handler", Metric("Permission Handler", System.currentTimeMillis().minus(startPerms), System.currentTimeMillis())) - } - - fun handlePunishmentsUsingEvent(profileId: UUID, event: AsyncPlayerPreLoginEvent) { - val profile = AlchemistAPI.syncFindProfile(profileId) ?: return - PunishmentService.recalculateUUID(profileId) - - if (profile.hasActivePunishment(PunishmentType.BAN) || profile.hasActivePunishment(PunishmentType.BLACKLIST)) { - val option = profile.hasActivePunishment(PunishmentType.BAN) - val punishment = profile.getActivePunishments(if (option) PunishmentType.BAN else PunishmentType.BLACKLIST).firstOrNull() - val msgs = AlchemistSpigotPlugin.instance.config.getStringList("${if (option) "banned" else "blacklisted"}-join") - - msgs.replaceAll { it.replace("", punishment!!.reason) } - msgs.replaceAll { it.replace("", if (punishment!!.expirable.duration == Long.MAX_VALUE) "Never" else TimeUtil.formatDuration(punishment.expirable.addedAt + punishment.expirable.duration - System.currentTimeMillis())) } - - event.loginResult = AsyncPlayerPreLoginEvent.Result.KICK_BANNED - event.kickMessage = msgs.map { Chat.format(it) }.joinToString("\n") - } else if (profile.alternateAccountHasBlacklist()) { - val detectedPunishment: Punishment = profile.getFirstBlacklistFromAlts() ?: return - - val msgs = AlchemistSpigotPlugin.instance.config.getStringList("blacklisted-join-related") - - msgs.replaceAll { it.replace("", detectedPunishment.reason) } - msgs.replaceAll { it.replace("", AlchemistAPI.syncFindProfile(detectedPunishment.target)?.username ?: "N/A") } - - msgs.replaceAll { it.replace("", if (detectedPunishment.expirable.duration == Long.MAX_VALUE) "Never" else TimeUtil.formatDuration(detectedPunishment.expirable.addedAt + detectedPunishment.expirable.duration - System.currentTimeMillis())) } - event.kickMessage = msgs.map { Chat.format(it) }.joinToString("\n") - } - } - - fun ensurePlayerIsNotBanEvading(profileId: UUID) { - val profile = AlchemistAPI.syncFindProfile(profileId) ?: return - CompletableFuture.supplyAsync { - return@supplyAsync profile.getAltAccounts() - }.thenApply { alts -> - val isBanEvading = alts.size >= 1 && alts.any { it.hasActivePunishment(PunishmentType.BAN) || it.hasActivePunishment(PunishmentType.BLACKLIST) } - - if (isBanEvading) { - AsynchronousRedisSender.send(StaffGeneralMessagePacket("&b[S] &3[${Alchemist.globalServer.displayName}] ${AlchemistAPI.getRankWithPrefix(profileId)} &3may be using an alt to evade a punishment!")) + for (task in BukkitPostLoginConnection.getAllTasks()) + { + BukkitPostLoginConnection.registerNewCallback { + task.run(it) } } } - - fun calculateAndPostGrantables(profileId: UUID) { - val profile = AlchemistAPI.syncFindProfile(profileId) ?: return - - val startGrants = System.currentTimeMillis() - RankGrantService.recalculatePlayer(profile) - MetricService.addMetric("Grants Service", Metric("Grants Service", System.currentTimeMillis().minus(startGrants), System.currentTimeMillis())) - - val startPunishments = System.currentTimeMillis() - PunishmentService.recalculatePlayer(profile) - MetricService.addMetric("Punishment Service", Metric("Punishment Service", System.currentTimeMillis().minus(startPunishments), System.currentTimeMillis())) - } } \ No newline at end of file diff --git a/spigot/src/main/kotlin/ltd/matrixstudios/alchemist/profiles/ProfileJoinListener.kt b/spigot/src/main/kotlin/ltd/matrixstudios/alchemist/profiles/ProfileJoinListener.kt index 598fed4f2..2f149b270 100644 --- a/spigot/src/main/kotlin/ltd/matrixstudios/alchemist/profiles/ProfileJoinListener.kt +++ b/spigot/src/main/kotlin/ltd/matrixstudios/alchemist/profiles/ProfileJoinListener.kt @@ -93,8 +93,9 @@ class ProfileJoinListener : Listener { it.addAll(BukkitPostLoginConnection.allCallbacks + BukkitPostLoginConnection.allLazyCallbacks) } - for (cback in allCallbacks) cback.invoke(player) - + for (cback in allCallbacks) { + cback.invoke(player) + } } @EventHandler(priority = EventPriority.LOWEST) @@ -103,7 +104,9 @@ class ProfileJoinListener : Listener { it.addAll(BukkitPreLoginConnection.allCallbacks + BukkitPreLoginConnection.allLazyCallbacks) } - for (cback in allCallbacks) cback.invoke(event) + for (cback in allCallbacks) { + cback.invoke(event) + } } @EventHandler(priority = EventPriority.LOWEST) diff --git a/spigot/src/main/kotlin/ltd/matrixstudios/alchemist/profiles/postlog/BukkitPostLoginConnection.kt b/spigot/src/main/kotlin/ltd/matrixstudios/alchemist/profiles/postlog/BukkitPostLoginConnection.kt index 262c212fe..335ddc073 100644 --- a/spigot/src/main/kotlin/ltd/matrixstudios/alchemist/profiles/postlog/BukkitPostLoginConnection.kt +++ b/spigot/src/main/kotlin/ltd/matrixstudios/alchemist/profiles/postlog/BukkitPostLoginConnection.kt @@ -1,6 +1,9 @@ package ltd.matrixstudios.alchemist.profiles.postlog import ltd.matrixstudios.alchemist.models.connection.ConnectionMethod +import ltd.matrixstudios.alchemist.profiles.postlog.tasks.CheckBanEvasion +import ltd.matrixstudios.alchemist.profiles.postlog.tasks.LoadPermissions +import ltd.matrixstudios.alchemist.profiles.postlog.tasks.SendStaffWelcome import org.bukkit.entity.Player /** @@ -10,4 +13,13 @@ import org.bukkit.entity.Player * @project Alchemist * @website https://solo.to/redis */ -object BukkitPostLoginConnection : ConnectionMethod() \ No newline at end of file +object BukkitPostLoginConnection : ConnectionMethod() { + + fun getAllTasks() : List { + return listOf( + LoadPermissions, + SendStaffWelcome, + CheckBanEvasion + ) + } +} \ No newline at end of file diff --git a/spigot/src/main/kotlin/ltd/matrixstudios/alchemist/profiles/postlog/BukkitPostLoginTask.kt b/spigot/src/main/kotlin/ltd/matrixstudios/alchemist/profiles/postlog/BukkitPostLoginTask.kt new file mode 100644 index 000000000..c78843d54 --- /dev/null +++ b/spigot/src/main/kotlin/ltd/matrixstudios/alchemist/profiles/postlog/BukkitPostLoginTask.kt @@ -0,0 +1,15 @@ +package ltd.matrixstudios.alchemist.profiles.postlog + +import org.bukkit.entity.Player + +/** + * Class created on 7/20/2023 + + * @author 98ping + * @project Alchemist + * @website https://solo.to/redis + */ +interface BukkitPostLoginTask { + + fun run(player: Player) +} \ No newline at end of file diff --git a/spigot/src/main/kotlin/ltd/matrixstudios/alchemist/profiles/postlog/tasks/CheckBanEvasion.kt b/spigot/src/main/kotlin/ltd/matrixstudios/alchemist/profiles/postlog/tasks/CheckBanEvasion.kt new file mode 100644 index 000000000..0699af7a6 --- /dev/null +++ b/spigot/src/main/kotlin/ltd/matrixstudios/alchemist/profiles/postlog/tasks/CheckBanEvasion.kt @@ -0,0 +1,34 @@ +package ltd.matrixstudios.alchemist.profiles.postlog.tasks + +import ltd.matrixstudios.alchemist.Alchemist +import ltd.matrixstudios.alchemist.api.AlchemistAPI +import ltd.matrixstudios.alchemist.packets.StaffGeneralMessagePacket +import ltd.matrixstudios.alchemist.profiles.postlog.BukkitPostLoginTask +import ltd.matrixstudios.alchemist.punishments.PunishmentType +import ltd.matrixstudios.alchemist.redis.AsynchronousRedisSender +import org.bukkit.entity.Player +import java.util.concurrent.CompletableFuture + +/** + * Class created on 7/20/2023 + + * @author 98ping + * @project Alchemist + * @website https://solo.to/redis + */ +object CheckBanEvasion : BukkitPostLoginTask { + override fun run(player: Player) { + val profileId = player.uniqueId + val profile = AlchemistAPI.syncFindProfile(profileId) ?: return + CompletableFuture.supplyAsync { + return@supplyAsync profile.getAltAccounts() + }.thenApply { alts -> + val isBanEvading = alts.size >= 1 && alts.any { it.hasActivePunishment(PunishmentType.BAN) || it.hasActivePunishment( + PunishmentType.BLACKLIST) } + + if (isBanEvading) { + AsynchronousRedisSender.send(StaffGeneralMessagePacket("&b[S] &3[${Alchemist.globalServer.displayName}] ${AlchemistAPI.getRankWithPrefix(profileId)} &3may be using an alt to evade a punishment!")) + } + } + } +} \ No newline at end of file diff --git a/spigot/src/main/kotlin/ltd/matrixstudios/alchemist/profiles/postlog/tasks/LoadPermissions.kt b/spigot/src/main/kotlin/ltd/matrixstudios/alchemist/profiles/postlog/tasks/LoadPermissions.kt new file mode 100644 index 000000000..6e3a719cc --- /dev/null +++ b/spigot/src/main/kotlin/ltd/matrixstudios/alchemist/profiles/postlog/tasks/LoadPermissions.kt @@ -0,0 +1,30 @@ +package ltd.matrixstudios.alchemist.profiles.postlog.tasks + +import ltd.matrixstudios.alchemist.metric.Metric +import ltd.matrixstudios.alchemist.metric.MetricService +import ltd.matrixstudios.alchemist.permissions.AccessiblePermissionHandler +import ltd.matrixstudios.alchemist.profiles.postlog.BukkitPostLoginTask +import ltd.matrixstudios.alchemist.service.profiles.ProfileGameService +import org.bukkit.entity.Player +import java.util.concurrent.CompletableFuture + +/** + * Class created on 7/20/2023 + + * @author 98ping + * @project Alchemist + * @website https://solo.to/redis + */ +object LoadPermissions : BukkitPostLoginTask { + + override fun run(player: Player) { + val profile = ProfileGameService.byId(player.uniqueId) ?: return + + val startPerms = System.currentTimeMillis() + CompletableFuture.runAsync { + AccessiblePermissionHandler.update(player, profile.getPermissions()) + } + + MetricService.addMetric("Permission Handler", Metric("Permission Handler", System.currentTimeMillis().minus(startPerms), System.currentTimeMillis())) + } +} \ No newline at end of file diff --git a/spigot/src/main/kotlin/ltd/matrixstudios/alchemist/profiles/postlog/tasks/SendStaffWelcome.kt b/spigot/src/main/kotlin/ltd/matrixstudios/alchemist/profiles/postlog/tasks/SendStaffWelcome.kt new file mode 100644 index 000000000..fcbc350d2 --- /dev/null +++ b/spigot/src/main/kotlin/ltd/matrixstudios/alchemist/profiles/postlog/tasks/SendStaffWelcome.kt @@ -0,0 +1,45 @@ +package ltd.matrixstudios.alchemist.profiles.postlog.tasks + +import ltd.matrixstudios.alchemist.AlchemistSpigotPlugin +import ltd.matrixstudios.alchemist.api.AlchemistAPI +import ltd.matrixstudios.alchemist.profiles.postlog.BukkitPostLoginTask +import ltd.matrixstudios.alchemist.staff.mode.StaffSuiteManager +import ltd.matrixstudios.alchemist.util.Chat +import org.bukkit.Bukkit +import org.bukkit.entity.Player +import java.text.SimpleDateFormat +import java.util.* + +/** + * Class created on 7/20/2023 + + * @author 98ping + * @project Alchemist + * @website https://solo.to/redis + */ +object SendStaffWelcome : BukkitPostLoginTask { + + override fun run(player: Player) { + Bukkit.getScheduler().runTaskLater(AlchemistSpigotPlugin.instance, { + val config = AlchemistSpigotPlugin.instance.config + val dateFormat = SimpleDateFormat("MM-dd-yyyy", Locale.getDefault()) + + if (player.hasPermission("alchemist.staff")) { + + if (config.getBoolean("staffmode.sendWelcomeMessage")) { + player.sendMessage(" ") + player.sendMessage(Chat.format("&eWelcome back, " + AlchemistAPI.getRankDisplay(player.uniqueId))) + player.sendMessage(Chat.format("&eIt is currently &d" + dateFormat.format(Date(System.currentTimeMillis())))) + player.sendMessage(Chat.format("&eEdit your mod mode with &a/editmodmode")) + player.sendMessage(" ") + } + + if (StaffSuiteManager.isModModeOnJoin(player)) + { + player.sendMessage(Chat.format("&7&oYou have been put into ModMode automatically")) + StaffSuiteManager.setStaffMode(player) + } + } + }, 10L) + } +} \ No newline at end of file diff --git a/spigot/src/main/kotlin/ltd/matrixstudios/alchemist/profiles/prelog/BukkitPreLoginConnection.kt b/spigot/src/main/kotlin/ltd/matrixstudios/alchemist/profiles/prelog/BukkitPreLoginConnection.kt index 307b166ad..3a9895aaa 100644 --- a/spigot/src/main/kotlin/ltd/matrixstudios/alchemist/profiles/prelog/BukkitPreLoginConnection.kt +++ b/spigot/src/main/kotlin/ltd/matrixstudios/alchemist/profiles/prelog/BukkitPreLoginConnection.kt @@ -1,6 +1,13 @@ package ltd.matrixstudios.alchemist.profiles.prelog import ltd.matrixstudios.alchemist.models.connection.ConnectionMethod +import ltd.matrixstudios.alchemist.profiles.postlog.BukkitPostLoginTask +import ltd.matrixstudios.alchemist.profiles.postlog.tasks.CheckBanEvasion +import ltd.matrixstudios.alchemist.profiles.postlog.tasks.LoadPermissions +import ltd.matrixstudios.alchemist.profiles.postlog.tasks.SendStaffWelcome +import ltd.matrixstudios.alchemist.profiles.prelog.tasks.CalculateGrantables +import ltd.matrixstudios.alchemist.profiles.prelog.tasks.HandlePunishments +import ltd.matrixstudios.alchemist.profiles.prelog.tasks.LoadProfile import org.bukkit.entity.Player import org.bukkit.event.player.AsyncPlayerPreLoginEvent @@ -11,4 +18,13 @@ import org.bukkit.event.player.AsyncPlayerPreLoginEvent * @project Alchemist * @website https://solo.to/redis */ -object BukkitPreLoginConnection : ConnectionMethod() \ No newline at end of file +object BukkitPreLoginConnection : ConnectionMethod() { + + fun getAllTasks() : List { + return listOf( + LoadProfile, + HandlePunishments, + CalculateGrantables + ) + } +} \ No newline at end of file diff --git a/spigot/src/main/kotlin/ltd/matrixstudios/alchemist/profiles/prelog/BukkitPreLoginTask.kt b/spigot/src/main/kotlin/ltd/matrixstudios/alchemist/profiles/prelog/BukkitPreLoginTask.kt new file mode 100644 index 000000000..7da022ac0 --- /dev/null +++ b/spigot/src/main/kotlin/ltd/matrixstudios/alchemist/profiles/prelog/BukkitPreLoginTask.kt @@ -0,0 +1,18 @@ +package ltd.matrixstudios.alchemist.profiles.prelog + +import org.bukkit.entity.Player +import org.bukkit.event.player.AsyncPlayerPreLoginEvent + +/** + * Class created on 7/20/2023 + + * @author 98ping + * @project Alchemist + * @website https://solo.to/redis + */ +interface BukkitPreLoginTask { + + fun run(event: AsyncPlayerPreLoginEvent) + + fun shouldBeLazy() : Boolean +} \ No newline at end of file diff --git a/spigot/src/main/kotlin/ltd/matrixstudios/alchemist/profiles/prelog/tasks/CalculateGrantables.kt b/spigot/src/main/kotlin/ltd/matrixstudios/alchemist/profiles/prelog/tasks/CalculateGrantables.kt new file mode 100644 index 000000000..08f2c9c9d --- /dev/null +++ b/spigot/src/main/kotlin/ltd/matrixstudios/alchemist/profiles/prelog/tasks/CalculateGrantables.kt @@ -0,0 +1,36 @@ +package ltd.matrixstudios.alchemist.profiles.prelog.tasks + +import ltd.matrixstudios.alchemist.api.AlchemistAPI +import ltd.matrixstudios.alchemist.metric.Metric +import ltd.matrixstudios.alchemist.metric.MetricService +import ltd.matrixstudios.alchemist.profiles.prelog.BukkitPreLoginTask +import ltd.matrixstudios.alchemist.service.expirable.PunishmentService +import ltd.matrixstudios.alchemist.service.expirable.RankGrantService +import org.bukkit.event.player.AsyncPlayerPreLoginEvent + +/** + * Class created on 7/20/2023 + + * @author 98ping + * @project Alchemist + * @website https://solo.to/redis + */ +object CalculateGrantables : BukkitPreLoginTask { + + override fun run(event: AsyncPlayerPreLoginEvent) { + val profileId = event.uniqueId + val profile = AlchemistAPI.syncFindProfile(profileId) ?: return + + val startGrants = System.currentTimeMillis() + RankGrantService.recalculatePlayer(profile) + MetricService.addMetric("Grants Service", Metric("Grants Service", System.currentTimeMillis().minus(startGrants), System.currentTimeMillis())) + + val startPunishments = System.currentTimeMillis() + PunishmentService.recalculatePlayer(profile) + MetricService.addMetric("Punishment Service", Metric("Punishment Service", System.currentTimeMillis().minus(startPunishments), System.currentTimeMillis())) + } + + override fun shouldBeLazy(): Boolean { + return false + } +} \ No newline at end of file diff --git a/spigot/src/main/kotlin/ltd/matrixstudios/alchemist/profiles/prelog/tasks/HandlePunishments.kt b/spigot/src/main/kotlin/ltd/matrixstudios/alchemist/profiles/prelog/tasks/HandlePunishments.kt new file mode 100644 index 000000000..7c07ccb65 --- /dev/null +++ b/spigot/src/main/kotlin/ltd/matrixstudios/alchemist/profiles/prelog/tasks/HandlePunishments.kt @@ -0,0 +1,56 @@ +package ltd.matrixstudios.alchemist.profiles.prelog.tasks + +import ltd.matrixstudios.alchemist.AlchemistSpigotPlugin +import ltd.matrixstudios.alchemist.api.AlchemistAPI +import ltd.matrixstudios.alchemist.models.grant.types.Punishment +import ltd.matrixstudios.alchemist.profiles.prelog.BukkitPreLoginTask +import ltd.matrixstudios.alchemist.punishments.PunishmentType +import ltd.matrixstudios.alchemist.service.expirable.PunishmentService +import ltd.matrixstudios.alchemist.util.Chat +import ltd.matrixstudios.alchemist.util.TimeUtil +import org.bukkit.event.player.AsyncPlayerPreLoginEvent + +/** + * Class created on 7/20/2023 + + * @author 98ping + * @project Alchemist + * @website https://solo.to/redis + */ +object HandlePunishments : BukkitPreLoginTask { + + override fun run(event: AsyncPlayerPreLoginEvent) { + val profileId = event.uniqueId + val profile = AlchemistAPI.syncFindProfile(profileId) ?: return + + if (profile.hasActivePunishment(PunishmentType.BAN) || profile.hasActivePunishment(PunishmentType.BLACKLIST)) { + val option = profile.hasActivePunishment(PunishmentType.BAN) + val punishment = profile.getActivePunishments(if (option) PunishmentType.BAN else PunishmentType.BLACKLIST).firstOrNull() + val msgs = AlchemistSpigotPlugin.instance.config.getStringList("${if (option) "banned" else "blacklisted"}-join") + + msgs.replaceAll { it.replace("", punishment!!.reason) } + msgs.replaceAll { it.replace("", if (punishment!!.expirable.duration == Long.MAX_VALUE) "Never" else TimeUtil.formatDuration(punishment.expirable.addedAt + punishment.expirable.duration - System.currentTimeMillis())) } + + event.loginResult = AsyncPlayerPreLoginEvent.Result.KICK_BANNED + event.kickMessage = msgs.map { Chat.format(it) }.joinToString("\n") + + return + } + + if (profile.alternateAccountHasBlacklist()) { + val detectedPunishment: Punishment = profile.getFirstBlacklistFromAlts() ?: return + + val msgs = AlchemistSpigotPlugin.instance.config.getStringList("blacklisted-join-related") + + msgs.replaceAll { it.replace("", detectedPunishment.reason) } + msgs.replaceAll { it.replace("", AlchemistAPI.syncFindProfile(detectedPunishment.target)?.username ?: "N/A") } + + msgs.replaceAll { it.replace("", if (detectedPunishment.expirable.duration == Long.MAX_VALUE) "Never" else TimeUtil.formatDuration(detectedPunishment.expirable.addedAt + detectedPunishment.expirable.duration - System.currentTimeMillis())) } + event.kickMessage = msgs.map { Chat.format(it) }.joinToString("\n") + } + } + + override fun shouldBeLazy(): Boolean { + return true + } +} \ No newline at end of file diff --git a/spigot/src/main/kotlin/ltd/matrixstudios/alchemist/profiles/prelog/tasks/LoadProfile.kt b/spigot/src/main/kotlin/ltd/matrixstudios/alchemist/profiles/prelog/tasks/LoadProfile.kt new file mode 100644 index 000000000..928c07fe1 --- /dev/null +++ b/spigot/src/main/kotlin/ltd/matrixstudios/alchemist/profiles/prelog/tasks/LoadProfile.kt @@ -0,0 +1,42 @@ +package ltd.matrixstudios.alchemist.profiles.prelog.tasks + +import ltd.matrixstudios.alchemist.Alchemist +import ltd.matrixstudios.alchemist.metric.Metric +import ltd.matrixstudios.alchemist.metric.MetricService +import ltd.matrixstudios.alchemist.profiles.prelog.BukkitPreLoginTask +import ltd.matrixstudios.alchemist.service.profiles.ProfileGameService +import ltd.matrixstudios.alchemist.util.SHA +import org.bukkit.Bukkit +import org.bukkit.event.player.AsyncPlayerPreLoginEvent +import java.util.logging.Level + +/** + * Class created on 7/20/2023 + + * @author 98ping + * @project Alchemist + * @website https://solo.to/redis + */ +object LoadProfile : BukkitPreLoginTask { + override fun run(event: AsyncPlayerPreLoginEvent) { + val start = System.currentTimeMillis() + val profile = ProfileGameService.loadProfile(event.uniqueId, event.name) + + Bukkit.getLogger().log(Level.INFO, "Profile of " + event.name + " loaded in " + System.currentTimeMillis().minus(start) + "ms") + MetricService.addMetric("Profile Service", Metric("Profile Service", System.currentTimeMillis().minus(start), System.currentTimeMillis())) + + val hostAddress = event.address.hostAddress + val output = SHA.toHexString(hostAddress)!! + val currentServer = Alchemist.globalServer + + profile.lastSeenAt = System.currentTimeMillis() + profile.ip = output + profile.currentSession = profile.createNewSession(currentServer) + + ProfileGameService.save(profile) + } + + override fun shouldBeLazy(): Boolean { + return false + } +} \ No newline at end of file diff --git a/spigot/src/main/kotlin/ltd/matrixstudios/alchemist/punishment/packets/PunishmentRemovePacket.kt b/spigot/src/main/kotlin/ltd/matrixstudios/alchemist/punishment/packets/PunishmentRemovePacket.kt index 0a7003958..c7736873b 100644 --- a/spigot/src/main/kotlin/ltd/matrixstudios/alchemist/punishment/packets/PunishmentRemovePacket.kt +++ b/spigot/src/main/kotlin/ltd/matrixstudios/alchemist/punishment/packets/PunishmentRemovePacket.kt @@ -38,7 +38,7 @@ class PunishmentRemovePacket( .appendNewline() .append(Component.text(Chat.format("&6&m-------------------------"))) - val component = Component.text(Chat.format((if (silent) "&7[Silent]" else "") + " &r")) + val component = Component.text(Chat.format((if (silent) "&7(Silent)" else "") + " &r")) .append(Component.text(profile?.username ?: "Console").color(Chat.findTextColorFromString(profile?.getCurrentRank()?.color ?: "&c"))) .append(Component.text(Chat.format(" &ahas " + punishmentType.removed + diff --git a/spigot/src/main/kotlin/ltd/matrixstudios/alchemist/staff/mode/listeners/GenericStaffmodePreventionListener.kt b/spigot/src/main/kotlin/ltd/matrixstudios/alchemist/staff/mode/listeners/GenericStaffmodePreventionListener.kt index f959cee88..91eebe70b 100644 --- a/spigot/src/main/kotlin/ltd/matrixstudios/alchemist/staff/mode/listeners/GenericStaffmodePreventionListener.kt +++ b/spigot/src/main/kotlin/ltd/matrixstudios/alchemist/staff/mode/listeners/GenericStaffmodePreventionListener.kt @@ -82,24 +82,6 @@ class GenericStaffmodePreventionListener : Listener { } } - @EventHandler - fun moveItem(e: InventoryClickEvent) - { - val player = e.whoClicked - - if (player is Player) - { - - if (StaffSuiteManager.isModMode(player)) - { - if (!player.hasPermission("alchemist.staffmode.edit")) - { - e.isCancelled = true - } - } - } - } - @EventHandler fun pickup(e: PlayerPickupItemEvent) { diff --git a/spigot/src/main/kotlin/ltd/matrixstudios/alchemist/staff/mode/listeners/StaffmodeFunctionalityListener.kt b/spigot/src/main/kotlin/ltd/matrixstudios/alchemist/staff/mode/listeners/StaffmodeFunctionalityListener.kt index 11d02c75c..be2cd0225 100644 --- a/spigot/src/main/kotlin/ltd/matrixstudios/alchemist/staff/mode/listeners/StaffmodeFunctionalityListener.kt +++ b/spigot/src/main/kotlin/ltd/matrixstudios/alchemist/staff/mode/listeners/StaffmodeFunctionalityListener.kt @@ -144,29 +144,4 @@ class StaffmodeFunctionalityListener : Listener { } } } - - @EventHandler(priority = EventPriority.HIGHEST) - fun join(event: PlayerJoinEvent) - { - val player = event.player - val config = AlchemistSpigotPlugin.instance.config - val dateFormat = SimpleDateFormat("MM-dd-yyyy", Locale.getDefault()) - - if (player.hasPermission("alchemist.staff")) { - - if (config.getBoolean("staffmode.sendWelcomeMessage")) { - player.sendMessage(" ") - player.sendMessage(Chat.format("&eWelcome back, " + AlchemistAPI.getRankDisplay(player.uniqueId))) - player.sendMessage(Chat.format("&eIt is currently &d" + dateFormat.format(Date(System.currentTimeMillis())))) - player.sendMessage(Chat.format("&eEdit your mod mode with &a/editmodmode")) - player.sendMessage(" ") - } - - if (StaffSuiteManager.isModModeOnJoin(player)) - { - player.sendMessage(Chat.format("&7&oYou have been put into ModMode automatically")) - StaffSuiteManager.setStaffMode(player) - } - } - } } \ No newline at end of file