forked from SteamWar/SteamWar
Merge pull request 'TNTLeague/BiggerCoins' (#12) from TNTLeague/BiggerCoins into main
Reviewed-on: SteamWar/SteamWar#12 Reviewed-by: Chaoscaot <max@chaoscaot.de>
This commit is contained in:
@@ -35,6 +35,8 @@ import org.bukkit.event.player.PlayerAttemptPickupItemEvent
|
|||||||
import org.bukkit.event.player.PlayerInteractEntityEvent
|
import org.bukkit.event.player.PlayerInteractEntityEvent
|
||||||
import org.bukkit.event.player.PlayerJoinEvent
|
import org.bukkit.event.player.PlayerJoinEvent
|
||||||
import org.bukkit.event.player.PlayerMoveEvent
|
import org.bukkit.event.player.PlayerMoveEvent
|
||||||
|
import org.bukkit.event.player.*
|
||||||
|
import org.bukkit.persistence.PersistentDataType
|
||||||
|
|
||||||
object IngameListener : Listener {
|
object IngameListener : Listener {
|
||||||
|
|
||||||
@@ -75,9 +77,9 @@ object IngameListener : Listener {
|
|||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
fun onPickupCoins(e: PlayerAttemptPickupItemEvent) {
|
fun onPickupCoins(e: PlayerAttemptPickupItemEvent) {
|
||||||
if (e.item.itemStack.isSimilar(DealerInventory.coins)) {
|
if (e.item.itemStack.persistentDataContainer.has(DealerInventory.coinKey)) {
|
||||||
TNTLeagueGame.getTeam(e.player)?.coins =
|
val numberOfCoins = e.item.itemStack.persistentDataContainer[DealerInventory.coinKey, PersistentDataType.INTEGER] ?: 0
|
||||||
e.item.itemStack.amount + (TNTLeagueGame.getTeam(e.player)?.coins ?: 0)
|
TNTLeagueGame.getTeam(e.player)?.coins = (e.item.itemStack.amount * numberOfCoins) + (TNTLeagueGame.getTeam(e.player)?.coins ?: 0)
|
||||||
|
|
||||||
e.item.itemStack.amount = 0
|
e.item.itemStack.amount = 0
|
||||||
e.isCancelled = true
|
e.isCancelled = true
|
||||||
|
|||||||
@@ -24,8 +24,6 @@ import de.steamwar.message.SubMessage
|
|||||||
import de.steamwar.network.NetworkSender
|
import de.steamwar.network.NetworkSender
|
||||||
import de.steamwar.network.packets.common.FightInfoPacket
|
import de.steamwar.network.packets.common.FightInfoPacket
|
||||||
import de.steamwar.scoreboard.SWScoreboard
|
import de.steamwar.scoreboard.SWScoreboard
|
||||||
import de.steamwar.sql.Fight
|
|
||||||
import de.steamwar.sql.FightPlayer
|
|
||||||
import de.steamwar.sql.SteamwarUser
|
import de.steamwar.sql.SteamwarUser
|
||||||
import de.steamwar.tntleague.colorByTeam
|
import de.steamwar.tntleague.colorByTeam
|
||||||
import de.steamwar.tntleague.config.TNTLeagueConfig
|
import de.steamwar.tntleague.config.TNTLeagueConfig
|
||||||
@@ -37,10 +35,9 @@ import de.steamwar.tntleague.events.LobbyListener
|
|||||||
import de.steamwar.tntleague.inventory.DealerInventory
|
import de.steamwar.tntleague.inventory.DealerInventory
|
||||||
import de.steamwar.tntleague.message
|
import de.steamwar.tntleague.message
|
||||||
import de.steamwar.tntleague.plugin
|
import de.steamwar.tntleague.plugin
|
||||||
import de.steamwar.tntleague.util.*
|
import de.steamwar.tntleague.util.TNTLeagueScoreboard
|
||||||
import org.bukkit.GameMode
|
import org.bukkit.GameMode
|
||||||
import org.bukkit.Location
|
import org.bukkit.Location
|
||||||
import org.bukkit.Material
|
|
||||||
import org.bukkit.Sound
|
import org.bukkit.Sound
|
||||||
import org.bukkit.entity.Item
|
import org.bukkit.entity.Item
|
||||||
import org.bukkit.entity.Player
|
import org.bukkit.entity.Player
|
||||||
@@ -51,6 +48,7 @@ import org.bukkit.inventory.ItemStack
|
|||||||
import org.bukkit.scheduler.BukkitTask
|
import org.bukkit.scheduler.BukkitTask
|
||||||
import java.sql.Timestamp
|
import java.sql.Timestamp
|
||||||
import java.time.Instant
|
import java.time.Instant
|
||||||
|
import kotlin.random.Random
|
||||||
|
|
||||||
object TNTLeagueGame {
|
object TNTLeagueGame {
|
||||||
var state: GameState = GameState.LOBBY
|
var state: GameState = GameState.LOBBY
|
||||||
@@ -87,18 +85,24 @@ object TNTLeagueGame {
|
|||||||
|
|
||||||
message.broadcast("GAME_STARTED")
|
message.broadcast("GAME_STARTED")
|
||||||
|
|
||||||
val tnt = ItemStack(Material.TNT)
|
|
||||||
|
|
||||||
start = Timestamp.from(Instant.now())
|
start = Timestamp.from(Instant.now())
|
||||||
|
|
||||||
|
var spawnCount = 0
|
||||||
spawnerTask = plugin.server.scheduler.runTaskTimer(plugin, bukkit {
|
spawnerTask = plugin.server.scheduler.runTaskTimer(plugin, bukkit {
|
||||||
|
val coinsToSpawn = if (spawnCount % 28 == 0) {
|
||||||
|
DealerInventory.huge_coins
|
||||||
|
} else if (spawnCount % 7 == 0) {
|
||||||
|
DealerInventory.big_coins
|
||||||
|
} else {
|
||||||
|
DealerInventory.coins
|
||||||
|
}
|
||||||
|
spawnCount++
|
||||||
|
|
||||||
if (world.getNearbyEntitiesByType(Item::class.java, TNTLeagueWorldConfig.blueTeam.itemSpawn, 3.0).sumOf { it.itemStack.amount } <= 256) {
|
if (world.getNearbyEntitiesByType(Item::class.java, TNTLeagueWorldConfig.blueTeam.itemSpawn, 3.0).sumOf { it.itemStack.amount } <= 256) {
|
||||||
spawnItems(TNTLeagueWorldConfig.blueTeam.itemSpawn, tnt)
|
spawnItems(TNTLeagueWorldConfig.blueTeam.itemSpawn, coinsToSpawn)
|
||||||
spawnItems(TNTLeagueWorldConfig.blueTeam.itemSpawn, DealerInventory.coins)
|
|
||||||
}
|
}
|
||||||
if (world.getNearbyEntitiesByType(Item::class.java, TNTLeagueWorldConfig.redTeam.itemSpawn, 3.0).sumOf { it.itemStack.amount } <= 256) {
|
if (world.getNearbyEntitiesByType(Item::class.java, TNTLeagueWorldConfig.redTeam.itemSpawn, 3.0).sumOf { it.itemStack.amount } <= 256) {
|
||||||
spawnItems(TNTLeagueWorldConfig.redTeam.itemSpawn, tnt)
|
spawnItems(TNTLeagueWorldConfig.redTeam.itemSpawn, coinsToSpawn)
|
||||||
spawnItems(TNTLeagueWorldConfig.redTeam.itemSpawn, DealerInventory.coins)
|
|
||||||
}
|
}
|
||||||
}, 5, 10)
|
}, 5, 10)
|
||||||
|
|
||||||
|
|||||||
@@ -59,13 +59,31 @@ class DealerInventory(player: Player): KotlinInventory(player) {
|
|||||||
companion object {
|
companion object {
|
||||||
private val priceKey = NamespacedKey(plugin, "price")
|
private val priceKey = NamespacedKey(plugin, "price")
|
||||||
private val amountKey = NamespacedKey(plugin, "amount")
|
private val amountKey = NamespacedKey(plugin, "amount")
|
||||||
private val coinKey = NamespacedKey(plugin, "coin")
|
val coinKey = NamespacedKey(plugin, "coin")
|
||||||
|
|
||||||
val coins = ItemStack(Material.RAW_GOLD).apply {
|
val coins = ItemStack(Material.RAW_GOLD).apply {
|
||||||
itemMeta = itemMeta.apply {
|
itemMeta = itemMeta.apply {
|
||||||
displayName(Component.text("Coins").color(NamedTextColor.GOLD))
|
displayName(Component.text("Coins").color(NamedTextColor.GOLD))
|
||||||
persistentDataContainer.apply {
|
persistentDataContainer.apply {
|
||||||
set(coinKey, PersistentDataType.BOOLEAN, true)
|
set(coinKey, PersistentDataType.INTEGER, 1)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
val big_coins = ItemStack(Material.GOLD_INGOT).apply {
|
||||||
|
itemMeta = itemMeta.apply {
|
||||||
|
displayName(Component.text("Big Coins").color(NamedTextColor.GOLD))
|
||||||
|
persistentDataContainer.apply {
|
||||||
|
set(coinKey, PersistentDataType.INTEGER, 3)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
val huge_coins = ItemStack(Material.GOLD_BLOCK).apply {
|
||||||
|
itemMeta = itemMeta.apply {
|
||||||
|
displayName(Component.text("Huge Coins").color(NamedTextColor.GOLD))
|
||||||
|
persistentDataContainer.apply {
|
||||||
|
set(coinKey, PersistentDataType.INTEGER, 9)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user