Players will now be launched away from physical crates if they don't have a key
This commit is contained in:
@@ -43,7 +43,7 @@ class CommandGive(plugin: EcoPlugin) : Subcommand(
|
||||
|
||||
val amount = args.getOrNull(2)?.toIntOrNull() ?: 1
|
||||
|
||||
crate.giveKeys(player, amount)
|
||||
crate.adjustKeys(player, amount)
|
||||
sender.sendMessage(
|
||||
plugin.langYml.getMessage("gave-keys")
|
||||
.replace("%amount%", amount.toString())
|
||||
|
||||
@@ -164,15 +164,27 @@ class Crate(
|
||||
return (0..amount).map { getRandomReward(displayWeight) }
|
||||
}
|
||||
|
||||
fun openWithKey(player: Player, location: Location? = null) {
|
||||
val keys = player.profile.read(keysKey)
|
||||
fun openPhysical(player: Player, location: Location) {
|
||||
if (!testKeys(player)) {
|
||||
val vector = player.location.clone().subtract(location.toVector())
|
||||
.toVector()
|
||||
.normalize()
|
||||
.multiply(plugin.configYml.getDouble("no-key-velocity"))
|
||||
|
||||
player.velocity = vector
|
||||
|
||||
if (keys == 0) {
|
||||
player.sendMessage(plugin.langYml.getMessage("not-enough-keys").replace("%crate%", this.name))
|
||||
return
|
||||
}
|
||||
|
||||
player.profile.write(keysKey, keys - 1)
|
||||
openWithKey(player, location)
|
||||
}
|
||||
|
||||
fun openWithKey(player: Player, location: Location? = null) {
|
||||
if (!testKeys(player)) {
|
||||
return
|
||||
}
|
||||
|
||||
adjustKeys(player, -1)
|
||||
open(player, location)
|
||||
}
|
||||
|
||||
@@ -190,11 +202,20 @@ class Crate(
|
||||
finishFireworks.forEach { it.launch(location) }
|
||||
}
|
||||
|
||||
fun giveKeys(player: OfflinePlayer, amount: Int) {
|
||||
fun adjustKeys(player: OfflinePlayer, amount: Int) {
|
||||
player.profile.write(keysKey, player.profile.read(keysKey) + amount)
|
||||
}
|
||||
|
||||
fun getKeys(player: OfflinePlayer): Int {
|
||||
return player.profile.read(keysKey)
|
||||
}
|
||||
|
||||
fun testKeys(player: Player): Boolean {
|
||||
if (getKeys(player) == 0) {
|
||||
player.sendMessage(plugin.langYml.getMessage("not-enough-keys").replace("%crate%", this.name))
|
||||
return false
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,7 +32,7 @@ class PlacedCrateListener(
|
||||
|
||||
when (event.action) {
|
||||
Action.LEFT_CLICK_BLOCK -> crate.previewForPlayer(player)
|
||||
Action.RIGHT_CLICK_BLOCK -> crate.openWithKey(player, block.location)
|
||||
Action.RIGHT_CLICK_BLOCK -> crate.openPhysical(player, block.location)
|
||||
else -> return
|
||||
}
|
||||
|
||||
|
||||
@@ -3,6 +3,8 @@
|
||||
# by Auxilor
|
||||
#
|
||||
|
||||
no-key-velocity: 1.5 # The speed at which a player should be launched away from a crate if they try to open it without a key. Set to 0 to disable.
|
||||
|
||||
keygui:
|
||||
rows: 3
|
||||
mask:
|
||||
|
||||
Reference in New Issue
Block a user