Skip to content

Commit

Permalink
Added global points to /libreforge points command
Browse files Browse the repository at this point in the history
  • Loading branch information
WillFP committed Jun 27, 2024
1 parent 8c02cdf commit 78376d2
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
}
Expand All @@ -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())
)
Expand All @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
}
Expand All @@ -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())
)
Expand All @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
}
Expand All @@ -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())
)
Expand All @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
}
Expand All @@ -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())
)
Expand All @@ -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(
Expand Down

0 comments on commit 78376d2

Please sign in to comment.