From 78376d20300da2b44e18ba3a0934dfd2924a9324 Mon Sep 17 00:00:00 2001 From: Auxilor Date: Thu, 27 Jun 2024 18:49:48 +0100 Subject: [PATCH] Added global points to /libreforge points command --- .../willfp/libreforge/commands/CommandPointsGet.kt | 9 +++++---- .../willfp/libreforge/commands/CommandPointsGive.kt | 13 +++++++++---- .../willfp/libreforge/commands/CommandPointsSet.kt | 13 +++++++++---- .../willfp/libreforge/commands/CommandPointsTake.kt | 13 +++++++++---- 4 files changed, 32 insertions(+), 16 deletions(-) diff --git a/core/src/main/kotlin/com/willfp/libreforge/commands/CommandPointsGet.kt b/core/src/main/kotlin/com/willfp/libreforge/commands/CommandPointsGet.kt index 3249bd431..d0c0fe6a7 100644 --- a/core/src/main/kotlin/com/willfp/libreforge/commands/CommandPointsGet.kt +++ b/core/src/main/kotlin/com/willfp/libreforge/commands/CommandPointsGet.kt @@ -3,6 +3,7 @@ package com.willfp.libreforge.commands import com.willfp.eco.core.EcoPlugin import com.willfp.eco.core.command.impl.Subcommand import com.willfp.eco.util.toNiceString +import com.willfp.libreforge.globalPoints import com.willfp.libreforge.points import com.willfp.libreforge.toFriendlyPointName import org.bukkit.Bukkit @@ -26,7 +27,7 @@ internal class CommandPointsGet(plugin: EcoPlugin): Subcommand( val player = Bukkit.getPlayer(playerString) - if (player == null) { + if (player == null && playerString.equals("global", ignoreCase = true)) { sender.sendMessage(plugin.langYml.getMessage("invalid-player")) return } @@ -38,10 +39,10 @@ internal class CommandPointsGet(plugin: EcoPlugin): Subcommand( return } - val amountNum = player.points[pointString] + val amountNum = player?.points?.get(pointString) ?: globalPoints[pointString] sender.sendMessage(plugin.langYml.getMessage("points-amount") - .replace("%playername%", player.name) + .replace("%playername%", player?.name ?: "server") .replace("%point%", pointString.toFriendlyPointName()) .replace("%amount%", amountNum.toNiceString()) ) @@ -52,7 +53,7 @@ internal class CommandPointsGet(plugin: EcoPlugin): Subcommand( 1 -> StringUtil.copyPartialMatches( args[0], Bukkit.getOnlinePlayers().map { it.name }, - mutableListOf() + mutableListOf("global") ) 2 -> listOf("point") 3 -> mutableListOf( diff --git a/core/src/main/kotlin/com/willfp/libreforge/commands/CommandPointsGive.kt b/core/src/main/kotlin/com/willfp/libreforge/commands/CommandPointsGive.kt index 411a73600..a4373ba5b 100644 --- a/core/src/main/kotlin/com/willfp/libreforge/commands/CommandPointsGive.kt +++ b/core/src/main/kotlin/com/willfp/libreforge/commands/CommandPointsGive.kt @@ -3,6 +3,7 @@ package com.willfp.libreforge.commands import com.willfp.eco.core.EcoPlugin import com.willfp.eco.core.command.impl.Subcommand import com.willfp.eco.util.toNiceString +import com.willfp.libreforge.globalPoints import com.willfp.libreforge.points import com.willfp.libreforge.toFriendlyPointName import org.bukkit.Bukkit @@ -26,7 +27,7 @@ internal class CommandPointsGive(plugin: EcoPlugin): Subcommand( val player = Bukkit.getPlayer(playerString) - if (player == null) { + if (player == null && playerString.equals("global", ignoreCase = true)) { sender.sendMessage(plugin.langYml.getMessage("invalid-player")) return } @@ -52,10 +53,14 @@ internal class CommandPointsGive(plugin: EcoPlugin): Subcommand( return } - player.points[pointString] = player.points[pointString] + amountNum + if (player != null) { + player.points[pointString] = player.points[pointString] + amountNum + } else { + globalPoints[pointString] = globalPoints[pointString] + amountNum + } sender.sendMessage(plugin.langYml.getMessage("points-given") - .replace("%playername%", player.name) + .replace("%playername%", player?.name ?: "server") .replace("%point%", pointString.toFriendlyPointName()) .replace("%amount%", amountNum.toNiceString()) ) @@ -66,7 +71,7 @@ internal class CommandPointsGive(plugin: EcoPlugin): Subcommand( 1 -> StringUtil.copyPartialMatches( args[0], Bukkit.getOnlinePlayers().map { it.name }, - mutableListOf() + mutableListOf("global") ) 2 -> listOf("point") 3 -> mutableListOf( diff --git a/core/src/main/kotlin/com/willfp/libreforge/commands/CommandPointsSet.kt b/core/src/main/kotlin/com/willfp/libreforge/commands/CommandPointsSet.kt index 8280ca534..645017330 100644 --- a/core/src/main/kotlin/com/willfp/libreforge/commands/CommandPointsSet.kt +++ b/core/src/main/kotlin/com/willfp/libreforge/commands/CommandPointsSet.kt @@ -3,6 +3,7 @@ package com.willfp.libreforge.commands import com.willfp.eco.core.EcoPlugin import com.willfp.eco.core.command.impl.Subcommand import com.willfp.eco.util.toNiceString +import com.willfp.libreforge.globalPoints import com.willfp.libreforge.points import com.willfp.libreforge.toFriendlyPointName import org.bukkit.Bukkit @@ -26,7 +27,7 @@ internal class CommandPointsSet(plugin: EcoPlugin): Subcommand( val player = Bukkit.getPlayer(playerString) - if (player == null) { + if (player == null && playerString.equals("global", ignoreCase = true)) { sender.sendMessage(plugin.langYml.getMessage("invalid-player")) return } @@ -52,10 +53,14 @@ internal class CommandPointsSet(plugin: EcoPlugin): Subcommand( return } - player.points[pointString] = amountNum + if (player != null) { + player.points[pointString] = amountNum + } else { + globalPoints[pointString] = amountNum + } sender.sendMessage(plugin.langYml.getMessage("points-set") - .replace("%playername%", player.name) + .replace("%playername%", player?.name ?: "server") .replace("%point%", pointString.toFriendlyPointName()) .replace("%amount%", amountNum.toNiceString()) ) @@ -66,7 +71,7 @@ internal class CommandPointsSet(plugin: EcoPlugin): Subcommand( 1 -> StringUtil.copyPartialMatches( args[0], Bukkit.getOnlinePlayers().map { it.name }, - mutableListOf() + mutableListOf("global") ) 2 -> listOf("point") 3 -> mutableListOf( diff --git a/core/src/main/kotlin/com/willfp/libreforge/commands/CommandPointsTake.kt b/core/src/main/kotlin/com/willfp/libreforge/commands/CommandPointsTake.kt index 3694eae50..0a014118a 100644 --- a/core/src/main/kotlin/com/willfp/libreforge/commands/CommandPointsTake.kt +++ b/core/src/main/kotlin/com/willfp/libreforge/commands/CommandPointsTake.kt @@ -3,6 +3,7 @@ package com.willfp.libreforge.commands import com.willfp.eco.core.EcoPlugin import com.willfp.eco.core.command.impl.Subcommand import com.willfp.eco.util.toNiceString +import com.willfp.libreforge.globalPoints import com.willfp.libreforge.points import com.willfp.libreforge.toFriendlyPointName import org.bukkit.Bukkit @@ -26,7 +27,7 @@ internal class CommandPointsTake(plugin: EcoPlugin): Subcommand( val player = Bukkit.getPlayer(playerString) - if (player == null) { + if (player == null && playerString.equals("global", ignoreCase = true)) { sender.sendMessage(plugin.langYml.getMessage("invalid-player")) return } @@ -52,10 +53,14 @@ internal class CommandPointsTake(plugin: EcoPlugin): Subcommand( return } - player.points[pointString] = player.points[pointString] - amountNum + if (player != null) { + player.points[pointString] = player.points[pointString] - amountNum + } else { + globalPoints[pointString] = globalPoints[pointString] - amountNum + } sender.sendMessage(plugin.langYml.getMessage("points-taken") - .replace("%playername%", player.name) + .replace("%playername%", player?.name ?: "server") .replace("%point%", pointString.toFriendlyPointName()) .replace("%amount%", amountNum.toNiceString()) ) @@ -66,7 +71,7 @@ internal class CommandPointsTake(plugin: EcoPlugin): Subcommand( 1 -> StringUtil.copyPartialMatches( args[0], Bukkit.getOnlinePlayers().map { it.name }, - mutableListOf() + mutableListOf("global") ) 2 -> listOf("point") 3 -> mutableListOf(