forked from SteamWar/SteamWar
Add bigger coins and remove TNT from spawning
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.PlayerJoinEvent
|
||||
import org.bukkit.event.player.PlayerMoveEvent
|
||||
import org.bukkit.event.player.*
|
||||
import org.bukkit.persistence.PersistentDataType
|
||||
|
||||
object IngameListener : Listener {
|
||||
|
||||
@@ -75,9 +77,9 @@ object IngameListener : Listener {
|
||||
|
||||
@EventHandler
|
||||
fun onPickupCoins(e: PlayerAttemptPickupItemEvent) {
|
||||
if (e.item.itemStack.isSimilar(DealerInventory.coins)) {
|
||||
TNTLeagueGame.getTeam(e.player)?.coins =
|
||||
e.item.itemStack.amount + (TNTLeagueGame.getTeam(e.player)?.coins ?: 0)
|
||||
if (e.item.itemStack.persistentDataContainer.has(DealerInventory.coinKey)) {
|
||||
val numberOfCoins = e.item.itemStack.persistentDataContainer[DealerInventory.coinKey, PersistentDataType.INTEGER] ?: 0
|
||||
TNTLeagueGame.getTeam(e.player)?.coins = (e.item.itemStack.amount * numberOfCoins) + (TNTLeagueGame.getTeam(e.player)?.coins ?: 0)
|
||||
|
||||
e.item.itemStack.amount = 0
|
||||
e.isCancelled = true
|
||||
|
||||
@@ -24,8 +24,6 @@ import de.steamwar.message.SubMessage
|
||||
import de.steamwar.network.NetworkSender
|
||||
import de.steamwar.network.packets.common.FightInfoPacket
|
||||
import de.steamwar.scoreboard.SWScoreboard
|
||||
import de.steamwar.sql.Fight
|
||||
import de.steamwar.sql.FightPlayer
|
||||
import de.steamwar.sql.SteamwarUser
|
||||
import de.steamwar.tntleague.colorByTeam
|
||||
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.message
|
||||
import de.steamwar.tntleague.plugin
|
||||
import de.steamwar.tntleague.util.*
|
||||
import de.steamwar.tntleague.util.TNTLeagueScoreboard
|
||||
import org.bukkit.GameMode
|
||||
import org.bukkit.Location
|
||||
import org.bukkit.Material
|
||||
import org.bukkit.Sound
|
||||
import org.bukkit.entity.Item
|
||||
import org.bukkit.entity.Player
|
||||
@@ -51,6 +48,7 @@ import org.bukkit.inventory.ItemStack
|
||||
import org.bukkit.scheduler.BukkitTask
|
||||
import java.sql.Timestamp
|
||||
import java.time.Instant
|
||||
import kotlin.random.Random
|
||||
|
||||
object TNTLeagueGame {
|
||||
var state: GameState = GameState.LOBBY
|
||||
@@ -87,18 +85,23 @@ object TNTLeagueGame {
|
||||
|
||||
message.broadcast("GAME_STARTED")
|
||||
|
||||
val tnt = ItemStack(Material.TNT)
|
||||
|
||||
start = Timestamp.from(Instant.now())
|
||||
|
||||
val random = Random(System.currentTimeMillis())
|
||||
|
||||
spawnerTask = plugin.server.scheduler.runTaskTimer(plugin, bukkit {
|
||||
var coinsToSpawn = DealerInventory.coins
|
||||
if (random.nextDouble() < 0.33) {
|
||||
coinsToSpawn = DealerInventory.big_coins
|
||||
} else if (random.nextDouble() < 0.11) {
|
||||
coinsToSpawn = DealerInventory.huge_coins
|
||||
}
|
||||
|
||||
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, DealerInventory.coins)
|
||||
spawnItems(TNTLeagueWorldConfig.blueTeam.itemSpawn, coinsToSpawn)
|
||||
}
|
||||
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, DealerInventory.coins)
|
||||
spawnItems(TNTLeagueWorldConfig.redTeam.itemSpawn, coinsToSpawn)
|
||||
}
|
||||
}, 5, 10)
|
||||
|
||||
|
||||
@@ -59,13 +59,31 @@ class DealerInventory(player: Player): KotlinInventory(player) {
|
||||
companion object {
|
||||
private val priceKey = NamespacedKey(plugin, "price")
|
||||
private val amountKey = NamespacedKey(plugin, "amount")
|
||||
private val coinKey = NamespacedKey(plugin, "coin")
|
||||
val coinKey = NamespacedKey(plugin, "coin")
|
||||
|
||||
val coins = ItemStack(Material.RAW_GOLD).apply {
|
||||
itemMeta = itemMeta.apply {
|
||||
displayName(Component.text("Coins").color(NamedTextColor.GOLD))
|
||||
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