From 1d0204a6487925f8364930ceaeb9383ba9743efd Mon Sep 17 00:00:00 2001 From: Julius de Jeu Date: Sun, 25 Aug 2019 16:00:36 +0200 Subject: [PATCH] Update VoidUtils: Fix weather skip to only run if thunder --- VoidBank/build.gradle | 22 +++- .../nl/voidcorp/bankplugin/BuyCommand.kt | 19 --- .../nl/voidcorp/bankplugin/Collector.kt | 118 ------------------ .../kotlin/nl/voidcorp/bankplugin/IconMenu.kt | 18 ++- .../nl/voidcorp/bankplugin/ProjectEBorrow.kt | 9 -- .../kotlin/nl/voidcorp/bankplugin/VoidBank.kt | 118 +++++++++--------- .../voidcorp/bankplugin/WoodStripCommand.kt | 31 ----- .../kotlin/nl/voidcorp/utilsplugin/Events.kt | 4 +- 8 files changed, 96 insertions(+), 243 deletions(-) delete mode 100644 VoidBank/src/main/kotlin/nl/voidcorp/bankplugin/BuyCommand.kt delete mode 100644 VoidBank/src/main/kotlin/nl/voidcorp/bankplugin/Collector.kt delete mode 100644 VoidBank/src/main/kotlin/nl/voidcorp/bankplugin/ProjectEBorrow.kt delete mode 100644 VoidBank/src/main/kotlin/nl/voidcorp/bankplugin/WoodStripCommand.kt diff --git a/VoidBank/build.gradle b/VoidBank/build.gradle index 75626fd..c5f5093 100644 --- a/VoidBank/build.gradle +++ b/VoidBank/build.gradle @@ -15,10 +15,28 @@ bukkit { depend = ['VoidPlugin'] commands { buymenu { - description = "Help me" + description = "Buy or sell stuff!" } - woodstrip{ + woodstrip { description = "Use this to transform stripped wood back into it's normal form" } + checkcash { + description = "Check how many ECs you have in you account" + } + transfer { + description = "Send cash to another player" + } + reload { + description = "Reloads the fileconfig" + permission = "bank.reload" + permissionMessage = "You are not allowed to reload the config..." + } + } + + permissions { + 'bank.reload' { + setDefault("OP") + description = "Allows reloading the config" + } } } \ No newline at end of file diff --git a/VoidBank/src/main/kotlin/nl/voidcorp/bankplugin/BuyCommand.kt b/VoidBank/src/main/kotlin/nl/voidcorp/bankplugin/BuyCommand.kt deleted file mode 100644 index b2b2d42..0000000 --- a/VoidBank/src/main/kotlin/nl/voidcorp/bankplugin/BuyCommand.kt +++ /dev/null @@ -1,19 +0,0 @@ -package nl.voidcorp.bankplugin - -import nl.voidcorp.mainplugin.commands.VoidCommand -import org.bukkit.command.Command -import org.bukkit.command.CommandSender -import org.bukkit.entity.Player - -class BuyCommand(private val plugin: VoidBank) : VoidCommand() { - private val title = "Exchange" - - override fun onCommand(sender: CommandSender, command: Command, label: String, args: Array): Boolean { - if (sender is Player) { - val page = args.toList().getOrNull(0)?.toInt() ?: 0 - plugin.iconMenus[page.coerceIn(0 until plugin.iconMenus.size)].open(sender) - } - return true - } - -} \ No newline at end of file diff --git a/VoidBank/src/main/kotlin/nl/voidcorp/bankplugin/Collector.kt b/VoidBank/src/main/kotlin/nl/voidcorp/bankplugin/Collector.kt deleted file mode 100644 index 374707c..0000000 --- a/VoidBank/src/main/kotlin/nl/voidcorp/bankplugin/Collector.kt +++ /dev/null @@ -1,118 +0,0 @@ -package nl.voidcorp.bankplugin - -import nl.voidcorp.mainplugin.adapter -import nl.voidcorp.mainplugin.messaging.MessageType -import nl.voidcorp.mainplugin.moshi -import org.bukkit.Bukkit -import org.bukkit.Material -import org.bukkit.Tag -import org.bukkit.inventory.FurnaceRecipe -import org.bukkit.inventory.ShapedRecipe -import org.bukkit.inventory.ShapelessRecipe -import kotlin.math.max - -object Collector { - private val prices = mutableMapOf(Material.IRON_INGOT to 256) - - init { - val config = VoidBank.config.bankMap - if (config.isNotEmpty() && !VoidBank.config.rerun) { - prices.putAll(config.map { Material.getMaterial(it.key)!! to it.value }.toMap()) - } - if (VoidBank.config.rerun) { - prices.putAll(Tag.LOGS.values.map { it to 32 }) - prices.putAll(Tag.PLANKS.values.map { it to 8 }) - prices.putAll(Tag.SAPLINGS.values.map { it to 32 }) - prices.putAll(Tag.LEAVES.values.map { it to 1 }) - prices.putAll(Tag.WOOL.values.map { it to 48 }) - this += Material.DIAMOND to 8192 - this += Material.STICK to 4 - this += Material.REDSTONE to 64 - this += Material.GLOWSTONE_DUST to 384 - this += Material.GOLD_INGOT to prices[Material.IRON_INGOT]!! * 8 - val borrow = moshi.adapter() - .fromJson(Collector::class.java.getResourceAsStream("/default.json").bufferedReader().readText()) - if (borrow != null) { - prices.putAll(borrow.values.asMaterialList) - } - - // let the pain commence - val simple = mutableListOf() - val recipes = Bukkit.recipeIterator().asSequence().filter { it.result.type !in prices.keys }.toMutableList() - val shapeless = recipes.filterIsInstance() - val shaped = recipes.filterIsInstance() - val furnace = recipes.filterIsInstance() - for (r in shapeless) { - - simple += SimpleRecipe( - r.ingredientList.groupingBy { it.type }.eachCount(), - r.result.type, - r.result.amount - ) - } - for (r in shaped) { - val ingredients = r.ingredientMap - val shape = r.shape.joinToString("").toList() - val m = mutableMapOf() - for (c in shape) { - val i = ingredients[c] - if (i != null) { - val curr = m.getOrDefault(i.type, 0) + 1 - m[i.type] = curr - } - } - simple += SimpleRecipe(m, r.result.type, r.result.amount) - } - for (r in furnace) { - val sticks = r.cookingTime / 100 - val inp = r.input - val outp = r.result - val m = mutableMapOf(inp.type to inp.amount, Material.STICK to sticks) - simple += SimpleRecipe(m, outp.type, outp.amount) - } - - simple += SimpleRecipe(mapOf(Material.BUCKET to 1), Material.MILK_BUCKET, 1) - simple += SimpleRecipe( - mapOf(Material.GOLD_BLOCK to 8, Material.APPLE to 1), - Material.ENCHANTED_GOLDEN_APPLE, - 1 - ) - simple += SimpleRecipe(mapOf(Material.IRON_INGOT to 4), Material.CREEPER_HEAD, 1) - simple += SimpleRecipe(mapOf(Material.WITHER_SKELETON_SKULL to 4), Material.CREEPER_HEAD, 1) - simple += SimpleRecipe(mapOf(Material.COBBLESTONE to 16384 / 12), Material.MELON_SLICE, 9) - simple += SimpleRecipe(mapOf(Material.PUMPKIN to 1), Material.CARVED_PUMPKIN, 1) - simple += SimpleRecipe(mapOf(Material.COBBLESTONE to 2), Material.BAMBOO, 1) - - repeat(5) { - simple.removeIf { (it.output in prices.keys) or (it.input.keys.any { it.name.contains("ORE") }) } - VoidBank.logger.info("Count: ${simple.size}, step $it") - val rs = simple.filter { it.input.keys.all { it in prices.keys } } - for (r in rs) { - val cost = r.input.map { it.value * prices.getOrDefault(it.key, 0) }.sum() / r.count - prices[r.output] = max(cost, prices.getOrDefault(r.output, 0)) - } - } - simple.removeIf { (it.output in prices.keys) or (it.input.keys.any { it.name.contains("ORE") }) } - VoidBank.logger.info("Count: ${simple.size}, step end") -// VoidBank.logger.info(moshi.adapter(meme::class.java).toJson(meme(simple))) - prices.remove(Material.ENCHANTED_BOOK) - prices.remove(Material.FILLED_MAP) - prices.remove(Material.WRITTEN_BOOK) - VoidBank.config.bankMap = prices.mapKeys { it.key.name }.toMutableMap() - VoidBank.config.rerun = false - - } - - } - - operator fun plusAssign(p: Pair) { - prices += p - } - - operator fun get(m: Material) = prices.getOrDefault(m, 0) - - operator fun rangeTo(max: Int) = prices.filterValues { it <= max } - - data class SimpleRecipe(val input: Map, val output: Material, val count: Int) - class meme(val recipes: List) -} \ No newline at end of file diff --git a/VoidBank/src/main/kotlin/nl/voidcorp/bankplugin/IconMenu.kt b/VoidBank/src/main/kotlin/nl/voidcorp/bankplugin/IconMenu.kt index 12f70fa..a96aa3b 100644 --- a/VoidBank/src/main/kotlin/nl/voidcorp/bankplugin/IconMenu.kt +++ b/VoidBank/src/main/kotlin/nl/voidcorp/bankplugin/IconMenu.kt @@ -35,8 +35,7 @@ class IconMenu( } fun close(p: Player): IconMenu { - if (p.openInventory.title == name) - p.closeInventory() + viewing.remove(p.uniqueId) return this } @@ -44,10 +43,17 @@ class IconMenu( fun onInventoryClick(event: InventoryClickEvent) { val p = event.whoClicked as Player if (p.uniqueId in viewing) { - event.isCancelled = true - val row = getRowFromSlot(event.slot) - if (!click(p, this, row, event.slot % 9, event.currentItem, event)) - close(p) + if (event.clickedInventory == event.whoClicked.inventory) { + if (event.isShiftClick) { + event.isCancelled = true + } + + } else { + event.isCancelled = true + val row = getRowFromSlot(event.slot) + if (!click(p, this, row, event.slot % 9, event.currentItem, event)) + close(p) + } } } diff --git a/VoidBank/src/main/kotlin/nl/voidcorp/bankplugin/ProjectEBorrow.kt b/VoidBank/src/main/kotlin/nl/voidcorp/bankplugin/ProjectEBorrow.kt deleted file mode 100644 index 0d6b816..0000000 --- a/VoidBank/src/main/kotlin/nl/voidcorp/bankplugin/ProjectEBorrow.kt +++ /dev/null @@ -1,9 +0,0 @@ -package nl.voidcorp.bankplugin - -import org.bukkit.Material - -data class ProjectEBorrow(val comment: String, val groups: Map, val values: Values) -data class Values(val before: Map) { - val asMaterialList: Map - get() = before.filterKeys { Material.matchMaterial(it) != null }.map { Material.matchMaterial(it.key)!! to it.value }.toMap() -} \ No newline at end of file diff --git a/VoidBank/src/main/kotlin/nl/voidcorp/bankplugin/VoidBank.kt b/VoidBank/src/main/kotlin/nl/voidcorp/bankplugin/VoidBank.kt index 267b708..4c73055 100644 --- a/VoidBank/src/main/kotlin/nl/voidcorp/bankplugin/VoidBank.kt +++ b/VoidBank/src/main/kotlin/nl/voidcorp/bankplugin/VoidBank.kt @@ -1,5 +1,9 @@ package nl.voidcorp.bankplugin +import nl.voidcorp.bankplugin.commands.* +import nl.voidcorp.bankplugin.costcalc.Collector +import nl.voidcorp.bankplugin.models.Bank +import nl.voidcorp.bankplugin.models.Banks import nl.voidcorp.mainplugin.CommandHandler import nl.voidcorp.mainplugin.VoidPluginBase import nl.voidcorp.mainplugin.adapter @@ -12,9 +16,8 @@ import org.bukkit.entity.Player import org.bukkit.event.inventory.ClickType import org.bukkit.event.inventory.InventoryClickEvent import org.bukkit.inventory.ItemStack -import org.bukkit.inventory.ShapedRecipe -import org.bukkit.inventory.ShapelessRecipe -import java.util.* +import org.jetbrains.exposed.sql.SchemaUtils +import org.jetbrains.exposed.sql.transactions.transaction import java.util.logging.Logger import kotlin.math.min @@ -27,23 +30,23 @@ class VoidBank(override val comment: String = "Sell all the diamonds!") : VoidPl send("VoidPlugin", MessageType.POST_CONFIG, moshi.adapter().toJson(VoidBank.config)) Collector.rangeTo(0) send("VoidPlugin", MessageType.POST_CONFIG, moshi.adapter().toJson(VoidBank.config)) + + transaction { + SchemaUtils.createMissingTablesAndColumns(Banks) + } + val buy = BuyCommand(this) CommandHandler(this).registerCommand("woodstrip", WoodStripCommand()) .registerCommand("buymenu", buy) + .registerCommand("checkcash", CheckCashCommand()) + .registerCommand("transfer", TransferCashCommand()) + .registerCommand("reload", ReloadCommand(this)) + + iconMenu() for (iconMenu in iconMenus) { server.pluginManager.registerEvents(iconMenu, this) } - val recipes = server.recipeIterator().asSequence().toList() - recipes.forEach { - if (it is ShapedRecipe) { - - } - if (it is ShapelessRecipe) { - it.ingredientList - } - - } } override fun recieve(message: Message) { @@ -56,71 +59,69 @@ class VoidBank(override val comment: String = "Sell all the diamonds!") : VoidPl } - val map = mutableMapOf() - val iconfun = { clicker: Player, menu: IconMenu, rowNum: Int, slot: Int, item: ItemStack?, event: InventoryClickEvent -> - if (event.clickedInventory == event.whoClicked.inventory) { - if (event.isShiftClick) { - event.isCancelled = true - } - - } else if (item != null) { + if (item != null) { if (rowNum == 5) { - if (slot != 4) { + if (slot == 0 || slot == 8) { val s = item.itemMeta.lore?.get(0)?.toInt() ?: 0 val next = iconMenus[s] if (next != menu) { Bukkit.getScheduler().runTask(this) { _ -> - menu.close(clicker) next.open(clicker) + menu.close(clicker) } } } } else { - val price = item.itemMeta.lore?.get(0)?.toInt() ?: 0 - val cash = map.getOrDefault(clicker.uniqueId, 0) - when (event.click) { - ClickType.LEFT -> { - if (cash >= price) { - clicker.inventory.addItem(ItemStack(item.type)) - map[clicker.uniqueId] = cash - price - } + transaction { + val bank = Bank.find { Banks.player eq clicker.uniqueId }.firstOrNull() ?: Bank.new { + player = clicker.uniqueId } - ClickType.RIGHT -> { + val price = item.itemMeta.lore?.get(0)?.toInt() ?: 0 + val cash = bank.money + when (event.click) { + ClickType.LEFT -> { + if (cash >= price) { + clicker.inventory.addItem(ItemStack(item.type)) + bank.money = cash - price + } + } + ClickType.RIGHT -> { - if (clicker.inventory.contains(item.type)) { - val cl = clicker.inventory.removeItem(ItemStack(item.type)) - if (cl.isEmpty()) - map[clicker.uniqueId] = cash + price + if (clicker.inventory.contains(item.type)) { + val cl = clicker.inventory.removeItem(ItemStack(item.type)) + if (cl.isEmpty()) + bank.money = cash + price + + } } + ClickType.SHIFT_LEFT -> { + // max (0/1536, 64 + val amt = min((cash / price).toInt(), item.type.maxStackSize) + clicker.inventory.addItem(ItemStack(item.type, amt)) + bank.money = cash - amt * price - } - ClickType.SHIFT_LEFT -> { - // max (0/1536, 64 - val amt = min(cash / price, item.type.maxStackSize) - clicker.inventory.addItem(ItemStack(item.type, amt)) - map[clicker.uniqueId] = cash - amt * price - - } - ClickType.SHIFT_RIGHT -> { - if (clicker.inventory.contains(item.type)) { - val amt = - min(clicker.inventory.contents.filterNotNull().filter { it.type == item.type }.map { it.amount }.sum(), - item.type.maxStackSize - ) - val rm = ItemStack(item.type, amt) - clicker.inventory.removeItem(rm) - map[clicker.uniqueId] = cash + price * amt + } + ClickType.SHIFT_RIGHT -> { + if (clicker.inventory.contains(item.type)) { + val amt = + min(clicker.inventory.contents.filterNotNull().filter { it.type == item.type }.map { it.amount }.sum(), + item.type.maxStackSize + ) + val rm = ItemStack(item.type, amt) + clicker.inventory.removeItem(rm) + bank.money = cash + price * amt + } + } + else -> { + Unit } } - else -> { - clicker.sendMessage("hmm?") - } + clicker.sendMessage("You have ${bank.money} ECs left!") } - clicker.sendMessage("You have ${map[clicker.uniqueId] ?: 0} EC's left!") } } true @@ -147,6 +148,9 @@ class VoidBank(override val comment: String = "Sell all the diamonds!") : VoidPl } val prev = key - 1 val next = key + 1 + for (z in 0..8) { + iconMenus[key].addButton(5, z, ItemStack(Material.BARRIER), "Bad, don't click here!") + } if (prev >= 0) iconMenus[key].addButton( 5, diff --git a/VoidBank/src/main/kotlin/nl/voidcorp/bankplugin/WoodStripCommand.kt b/VoidBank/src/main/kotlin/nl/voidcorp/bankplugin/WoodStripCommand.kt deleted file mode 100644 index 9196f9d..0000000 --- a/VoidBank/src/main/kotlin/nl/voidcorp/bankplugin/WoodStripCommand.kt +++ /dev/null @@ -1,31 +0,0 @@ -package nl.voidcorp.bankplugin - -import nl.voidcorp.mainplugin.commands.VoidCommand -import org.bukkit.Bukkit -import org.bukkit.Material -import org.bukkit.command.Command -import org.bukkit.command.CommandSender -import org.bukkit.entity.Player -import org.bukkit.inventory.ItemStack -import org.bukkit.inventory.MerchantRecipe - -class WoodStripCommand : VoidCommand() { - override fun onCommand(sender: CommandSender, command: Command, label: String, args: Array): Boolean { - if (sender is Player) { - val merchant = Bukkit.createMerchant("Wood Stripper") - - val cursed = "STRIPPED_(.*)_LOG".toRegex() - val logs = Material.values().toList().filter { it.name.matches(cursed) } - .map { cursed.matchEntire(it.name)!!.groupValues[1] } - val recipes = - logs.map { - MerchantRecipe(ItemStack(Material.getMaterial("${it}_LOG")!!), Int.MAX_VALUE).apply { - addIngredient(ItemStack(Material.getMaterial("STRIPPED_${it}_LOG")!!)) - } - }.toMutableList() - merchant.recipes = recipes - sender.openMerchant(merchant, true) - } - return true - } -} \ No newline at end of file diff --git a/VoidUtils/src/main/kotlin/nl/voidcorp/utilsplugin/Events.kt b/VoidUtils/src/main/kotlin/nl/voidcorp/utilsplugin/Events.kt index 287a17d..3b826b2 100644 --- a/VoidUtils/src/main/kotlin/nl/voidcorp/utilsplugin/Events.kt +++ b/VoidUtils/src/main/kotlin/nl/voidcorp/utilsplugin/Events.kt @@ -31,7 +31,9 @@ class Events(private val utils: VoidUtils) : Listener { val req = (utils.conf.neededPlayers * evt.player.server.onlinePlayers.size).roundToInt() if (bedList.size >= req) { utils.server.worlds.forEach { it.time = 0 } - evt.player.world.weatherDuration = 1 + if (evt.player.world.isThundering) { + evt.player.world.weatherDuration = 1 + } utils.server.broadcastMessage("Enough players were sleeping, skipping the night!") } else utils.server.broadcastMessage("There are now ${ChatColor.GOLD}${bedList.size}/$req${ChatColor.RESET} players sleeping to skip the night!")