From 99749ee92cad2d7deff3dbdf79586359540ffa52 Mon Sep 17 00:00:00 2001 From: Julius de Jeu Date: Sun, 25 Aug 2019 01:19:27 +0200 Subject: [PATCH] Add Admin, Bank and Utils, Fix Teleport and Base --- VoidAdmin/build.gradle | 39 +++ .../nl/voidcorp/adminplugin/AdminConfig.kt | 3 + .../nl/voidcorp/adminplugin/VoidAdmin.kt | 38 +++ .../nl/voidcorp/adminplugin/VoidEvents.kt | 17 + .../adminplugin}/commands/HealCommand.kt | 3 +- .../adminplugin/commands/NotifyBarCommand.kt | 44 +++ VoidBank/build.gradle | 24 ++ .../nl/voidcorp/bankplugin/BankConfig.kt | 3 + .../nl/voidcorp/bankplugin/BuyCommand.kt | 19 ++ .../nl/voidcorp/bankplugin/Collector.kt | 118 +++++++ .../kotlin/nl/voidcorp/bankplugin/IconMenu.kt | 89 ++++++ .../nl/voidcorp/bankplugin/ProjectEBorrow.kt | 9 + .../kotlin/nl/voidcorp/bankplugin/VoidBank.kt | 182 +++++++++++ .../voidcorp/bankplugin/WoodStripCommand.kt | 31 ++ VoidBank/src/main/resources/default.json | 293 ++++++++++++++++++ VoidPlugin/build.gradle | 24 +- .../nl/voidcorp/mainplugin/VoidEvents.kt | 24 -- .../nl/voidcorp/mainplugin/VoidPlugin.kt | 16 +- .../voidcorp/teleportplugin/VoidTeleport.kt | 4 + .../teleportplugin/commands/tpx/TpaCommand.kt | 16 +- .../teleportplugin/models/TpRequests.kt | 2 +- VoidUtils/build.gradle | 24 ++ .../kotlin/nl/voidcorp/utilsplugin/Events.kt | 46 +++ .../nl/voidcorp/utilsplugin}/PlayerTable.kt | 2 +- .../nl/voidcorp/utilsplugin/UtilsConfig.kt | 3 + .../nl/voidcorp/utilsplugin/VoidUtils.kt | 40 +++ .../utilsplugin}/commands/MemeCommand.kt | 3 +- .../utilsplugin}/commands/NickCommand.kt | 7 +- build.gradle | 2 +- settings.gradle | 5 +- 30 files changed, 1054 insertions(+), 76 deletions(-) create mode 100644 VoidAdmin/build.gradle create mode 100644 VoidAdmin/src/main/kotlin/nl/voidcorp/adminplugin/AdminConfig.kt create mode 100644 VoidAdmin/src/main/kotlin/nl/voidcorp/adminplugin/VoidAdmin.kt create mode 100644 VoidAdmin/src/main/kotlin/nl/voidcorp/adminplugin/VoidEvents.kt rename {VoidPlugin/src/main/kotlin/nl/voidcorp/mainplugin => VoidAdmin/src/main/kotlin/nl/voidcorp/adminplugin}/commands/HealCommand.kt (87%) create mode 100644 VoidAdmin/src/main/kotlin/nl/voidcorp/adminplugin/commands/NotifyBarCommand.kt create mode 100644 VoidBank/build.gradle create mode 100644 VoidBank/src/main/kotlin/nl/voidcorp/bankplugin/BankConfig.kt create mode 100644 VoidBank/src/main/kotlin/nl/voidcorp/bankplugin/BuyCommand.kt create mode 100644 VoidBank/src/main/kotlin/nl/voidcorp/bankplugin/Collector.kt create mode 100644 VoidBank/src/main/kotlin/nl/voidcorp/bankplugin/IconMenu.kt create mode 100644 VoidBank/src/main/kotlin/nl/voidcorp/bankplugin/ProjectEBorrow.kt create mode 100644 VoidBank/src/main/kotlin/nl/voidcorp/bankplugin/VoidBank.kt create mode 100644 VoidBank/src/main/kotlin/nl/voidcorp/bankplugin/WoodStripCommand.kt create mode 100644 VoidBank/src/main/resources/default.json delete mode 100644 VoidPlugin/src/main/kotlin/nl/voidcorp/mainplugin/VoidEvents.kt create mode 100644 VoidUtils/build.gradle create mode 100644 VoidUtils/src/main/kotlin/nl/voidcorp/utilsplugin/Events.kt rename {VoidPlugin/src/main/kotlin/nl/voidcorp/mainplugin => VoidUtils/src/main/kotlin/nl/voidcorp/utilsplugin}/PlayerTable.kt (93%) create mode 100644 VoidUtils/src/main/kotlin/nl/voidcorp/utilsplugin/UtilsConfig.kt create mode 100644 VoidUtils/src/main/kotlin/nl/voidcorp/utilsplugin/VoidUtils.kt rename {VoidPlugin/src/main/kotlin/nl/voidcorp/mainplugin => VoidUtils/src/main/kotlin/nl/voidcorp/utilsplugin}/commands/MemeCommand.kt (86%) rename {VoidPlugin/src/main/kotlin/nl/voidcorp/mainplugin => VoidUtils/src/main/kotlin/nl/voidcorp/utilsplugin}/commands/NickCommand.kt (87%) diff --git a/VoidAdmin/build.gradle b/VoidAdmin/build.gradle new file mode 100644 index 0000000..d376a7a --- /dev/null +++ b/VoidAdmin/build.gradle @@ -0,0 +1,39 @@ +plugins { + id 'java' + id 'org.jetbrains.kotlin.jvm' + id 'com.github.johnrengelman.shadow' + id 'net.minecrell.plugin-yml.bukkit' +} + +dependencies { + compileOnly project(":VoidPlugin") +} + +bukkit { + main = "nl.voidcorp.adminplugin.VoidAdmin" + apiVersion = '1.13' + author = 'J00LZ' + depend = ['VoidPlugin'] + commands { + heal { + description = "Heal yourself (if you have the permissions to do so)" + permission = 'voidplugin.heal' + permissionMessage = 'You are not allowed to heal yourself!' + } + notifybar { + description = "Show a notificationbar to all users" + } + } + + permissions { + 'voidplugin.*' { + children = ['voidplugin.heal'] + } + 'voidplugin.heal' { + description = 'Allows you to heal' + setDefault('OP') // 'TRUE', 'FALSE', 'OP' or 'NOT_OP' + } + + } + +} \ No newline at end of file diff --git a/VoidAdmin/src/main/kotlin/nl/voidcorp/adminplugin/AdminConfig.kt b/VoidAdmin/src/main/kotlin/nl/voidcorp/adminplugin/AdminConfig.kt new file mode 100644 index 0000000..2d77a61 --- /dev/null +++ b/VoidAdmin/src/main/kotlin/nl/voidcorp/adminplugin/AdminConfig.kt @@ -0,0 +1,3 @@ +package nl.voidcorp.adminplugin + +data class AdminConfig(val serverName: String = "My Server") \ No newline at end of file diff --git a/VoidAdmin/src/main/kotlin/nl/voidcorp/adminplugin/VoidAdmin.kt b/VoidAdmin/src/main/kotlin/nl/voidcorp/adminplugin/VoidAdmin.kt new file mode 100644 index 0000000..7201366 --- /dev/null +++ b/VoidAdmin/src/main/kotlin/nl/voidcorp/adminplugin/VoidAdmin.kt @@ -0,0 +1,38 @@ +package nl.voidcorp.adminplugin + +import nl.voidcorp.adminplugin.commands.HealCommand +import nl.voidcorp.adminplugin.commands.NotifyBarCommand +import nl.voidcorp.mainplugin.CommandHandler +import nl.voidcorp.mainplugin.VoidPluginBase +import nl.voidcorp.mainplugin.adapter +import nl.voidcorp.mainplugin.messaging.Message +import nl.voidcorp.mainplugin.messaging.MessageType +import nl.voidcorp.mainplugin.moshi + +class VoidAdmin(override val comment: String = "Make admins even more overpowered...") : VoidPluginBase() { + lateinit var config: AdminConfig + override fun enable() { + send("VoidPlugin", MessageType.GET_CONFIG) + send("VoidPlugin", MessageType.POST_CONFIG, moshi.adapter().toJson(config)) + + server.pluginManager.registerEvents(VoidEvents(config), this) + + CommandHandler(this) + .registerCommand("heal", HealCommand()) + .registerCommand("notifybar", NotifyBarCommand(this)) + + } + + override fun disable() { + send("VoidPlugin", MessageType.POST_CONFIG, moshi.adapter().toJson(config)) + } + + override fun recieve(message: Message) { + when (message.messageType) { + MessageType.GET_CONFIG -> { + config = moshi.adapter().fromJson(message.content)!! + } + else->{} + } + } +} \ No newline at end of file diff --git a/VoidAdmin/src/main/kotlin/nl/voidcorp/adminplugin/VoidEvents.kt b/VoidAdmin/src/main/kotlin/nl/voidcorp/adminplugin/VoidEvents.kt new file mode 100644 index 0000000..e76bbc8 --- /dev/null +++ b/VoidAdmin/src/main/kotlin/nl/voidcorp/adminplugin/VoidEvents.kt @@ -0,0 +1,17 @@ +package nl.voidcorp.adminplugin + +import org.bukkit.ChatColor +import org.bukkit.event.EventHandler +import org.bukkit.event.Listener +import org.bukkit.event.player.PlayerJoinEvent + + +class VoidEvents(private val config: AdminConfig) : Listener { + + @EventHandler + fun onJoin(evt: PlayerJoinEvent) { + evt.joinMessage = + "Hello ${ChatColor.BLUE}${evt.player.displayName}${ChatColor.RESET}, and welcome to ${ChatColor.BOLD}${config.serverName}${ChatColor.RESET}!" + } + +} \ No newline at end of file diff --git a/VoidPlugin/src/main/kotlin/nl/voidcorp/mainplugin/commands/HealCommand.kt b/VoidAdmin/src/main/kotlin/nl/voidcorp/adminplugin/commands/HealCommand.kt similarity index 87% rename from VoidPlugin/src/main/kotlin/nl/voidcorp/mainplugin/commands/HealCommand.kt rename to VoidAdmin/src/main/kotlin/nl/voidcorp/adminplugin/commands/HealCommand.kt index 420c4d6..fb6dd7e 100644 --- a/VoidPlugin/src/main/kotlin/nl/voidcorp/mainplugin/commands/HealCommand.kt +++ b/VoidAdmin/src/main/kotlin/nl/voidcorp/adminplugin/commands/HealCommand.kt @@ -1,5 +1,6 @@ -package nl.voidcorp.mainplugin.commands +package nl.voidcorp.adminplugin.commands +import nl.voidcorp.mainplugin.commands.VoidCommand import org.bukkit.attribute.Attribute import org.bukkit.command.Command import org.bukkit.command.CommandSender diff --git a/VoidAdmin/src/main/kotlin/nl/voidcorp/adminplugin/commands/NotifyBarCommand.kt b/VoidAdmin/src/main/kotlin/nl/voidcorp/adminplugin/commands/NotifyBarCommand.kt new file mode 100644 index 0000000..a353c54 --- /dev/null +++ b/VoidAdmin/src/main/kotlin/nl/voidcorp/adminplugin/commands/NotifyBarCommand.kt @@ -0,0 +1,44 @@ +package nl.voidcorp.adminplugin.commands + +import nl.voidcorp.mainplugin.VoidPluginBase +import nl.voidcorp.mainplugin.commands.VoidCommand +import org.bukkit.Bukkit +import org.bukkit.NamespacedKey +import org.bukkit.boss.BarColor +import org.bukkit.boss.BarFlag +import org.bukkit.boss.BarStyle +import org.bukkit.command.Command +import org.bukkit.command.CommandSender +import org.bukkit.entity.Player +import kotlin.concurrent.fixedRateTimer + +class NotifyBarCommand(plugin: VoidPluginBase) : VoidCommand() { + private val ns = NamespacedKey(plugin, "NotifyBar") + override fun onCommand(sender: CommandSender, command: Command, label: String, args: Array): Boolean { + if (sender is Player) { + if (args.isEmpty()) { + sender.sendMessage("You need to supply a message!") + } + Bukkit.createBossBar( + ns, + args.joinToString(" "), + BarColor.RED, + BarStyle.SOLID, + BarFlag.DARKEN_SKY + ).apply { + Bukkit.getServer().onlinePlayers.forEach { addPlayer(it) } + progress = 1.0 + } + fixedRateTimer(period = 100) { + val bar = Bukkit.getBossBar(ns)!! + try { + bar.progress -= 0.01 + } catch (ex: IllegalArgumentException) { + bar.removeAll() + this.cancel() + } + } + } + return true + } +} \ No newline at end of file diff --git a/VoidBank/build.gradle b/VoidBank/build.gradle new file mode 100644 index 0000000..75626fd --- /dev/null +++ b/VoidBank/build.gradle @@ -0,0 +1,24 @@ +plugins { + id 'java' + id 'org.jetbrains.kotlin.jvm' + id 'com.github.johnrengelman.shadow' + id 'net.minecrell.plugin-yml.bukkit' +} + +dependencies { + compileOnly project(":VoidPlugin") +} +bukkit { + main = "nl.voidcorp.bankplugin.VoidBank" + apiVersion = '1.13' + author = 'J00LZ' + depend = ['VoidPlugin'] + commands { + buymenu { + description = "Help me" + } + woodstrip{ + description = "Use this to transform stripped wood back into it's normal form" + } + } +} \ No newline at end of file diff --git a/VoidBank/src/main/kotlin/nl/voidcorp/bankplugin/BankConfig.kt b/VoidBank/src/main/kotlin/nl/voidcorp/bankplugin/BankConfig.kt new file mode 100644 index 0000000..d7cf42d --- /dev/null +++ b/VoidBank/src/main/kotlin/nl/voidcorp/bankplugin/BankConfig.kt @@ -0,0 +1,3 @@ +package nl.voidcorp.bankplugin + +data class BankConfig(var rerun: Boolean = true, var bankMap: MutableMap = mutableMapOf()) \ 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 new file mode 100644 index 0000000..b2b2d42 --- /dev/null +++ b/VoidBank/src/main/kotlin/nl/voidcorp/bankplugin/BuyCommand.kt @@ -0,0 +1,19 @@ +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 new file mode 100644 index 0000000..374707c --- /dev/null +++ b/VoidBank/src/main/kotlin/nl/voidcorp/bankplugin/Collector.kt @@ -0,0 +1,118 @@ +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 new file mode 100644 index 0000000..12f70fa --- /dev/null +++ b/VoidBank/src/main/kotlin/nl/voidcorp/bankplugin/IconMenu.kt @@ -0,0 +1,89 @@ +package nl.voidcorp.bankplugin + +import org.bukkit.Bukkit +import org.bukkit.entity.Player +import org.bukkit.event.EventHandler +import org.bukkit.event.Listener +import org.bukkit.event.inventory.InventoryClickEvent +import org.bukkit.event.inventory.InventoryCloseEvent +import org.bukkit.inventory.Inventory +import org.bukkit.inventory.ItemStack +import java.util.* + + +class IconMenu( + private val name: String = "Buy/Sell", + size: Int, + private val click: (clicker: Player, menu: IconMenu, rowNum: Int, slot: Int, item: ItemStack?, event: InventoryClickEvent) -> Boolean +) : Listener { + private val size: Int = size * 9 + private val viewing: MutableList = mutableListOf() + + private val items: MutableList = MutableList(this.size) { null } + + fun open(p: Player): IconMenu { + p.openInventory(getInventory(p)) + viewing.add(p.uniqueId) + return this + } + + private fun getInventory(p: Player): Inventory { + val inv = Bukkit.createInventory(p, size, name) + for (i in items.indices) + inv.setItem(i, items[i]) + return inv + } + + fun close(p: Player): IconMenu { + if (p.openInventory.title == name) + p.closeInventory() + return this + } + + @EventHandler + 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) + } + } + + @EventHandler + fun onInventoryClose(event: InventoryCloseEvent) { + if (viewing.contains(event.player.uniqueId)) + viewing.remove(event.player.uniqueId) + } + + fun addButton( + row: Int, + position: Int, + item: ItemStack, + name: String = "", + vararg lore: String = arrayOf() + ): IconMenu { + items[row * 9 + position] = getItem(item, name, *lore) + return this + } + + fun getRowFromSlot(slot: Int): Int { + return slot / 9 + } + + fun getRow(row: Int): MutableList { + return items.subList(row * 9, row * 9 + 9) + } + + private fun getItem(item: ItemStack, name: String, vararg lore: String): ItemStack { + val im = item.itemMeta + if (name.isNotBlank()) + im.setDisplayName(name) + if (lore.isNotEmpty()) + im.lore = listOf(*lore) + item.itemMeta = im + return item + } + +} \ No newline at end of file diff --git a/VoidBank/src/main/kotlin/nl/voidcorp/bankplugin/ProjectEBorrow.kt b/VoidBank/src/main/kotlin/nl/voidcorp/bankplugin/ProjectEBorrow.kt new file mode 100644 index 0000000..0d6b816 --- /dev/null +++ b/VoidBank/src/main/kotlin/nl/voidcorp/bankplugin/ProjectEBorrow.kt @@ -0,0 +1,9 @@ +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 new file mode 100644 index 0000000..267b708 --- /dev/null +++ b/VoidBank/src/main/kotlin/nl/voidcorp/bankplugin/VoidBank.kt @@ -0,0 +1,182 @@ +package nl.voidcorp.bankplugin + +import nl.voidcorp.mainplugin.CommandHandler +import nl.voidcorp.mainplugin.VoidPluginBase +import nl.voidcorp.mainplugin.adapter +import nl.voidcorp.mainplugin.messaging.Message +import nl.voidcorp.mainplugin.messaging.MessageType +import nl.voidcorp.mainplugin.moshi +import org.bukkit.Bukkit +import org.bukkit.Material +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 java.util.logging.Logger +import kotlin.math.min + +class VoidBank(override val comment: String = "Sell all the diamonds!") : VoidPluginBase() { + private val title = "Exchange" + override fun enable() { + + VoidBank.logger = logger + send("VoidPlugin", MessageType.GET_CONFIG) + send("VoidPlugin", MessageType.POST_CONFIG, moshi.adapter().toJson(VoidBank.config)) + Collector.rangeTo(0) + send("VoidPlugin", MessageType.POST_CONFIG, moshi.adapter().toJson(VoidBank.config)) + val buy = BuyCommand(this) + CommandHandler(this).registerCommand("woodstrip", WoodStripCommand()) + .registerCommand("buymenu", buy) + 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) { + when (message.messageType) { + MessageType.GET_CONFIG -> { + VoidBank.config = moshi.adapter().fromJson(message.content)!! + } + else -> Unit + } + } + + + 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 (rowNum == 5) { + if (slot != 4) { + 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) + } + } + } + } 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 + } + } + ClickType.RIGHT -> { + + if (clicker.inventory.contains(item.type)) { + val cl = clicker.inventory.removeItem(ItemStack(item.type)) + if (cl.isEmpty()) + map[clicker.uniqueId] = cash + 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 + } + } + else -> { + clicker.sendMessage("hmm?") + } + } + clicker.sendMessage("You have ${map[clicker.uniqueId] ?: 0} EC's left!") + } + } + true + } + + val iconMenus = mutableListOf() + + fun iconMenu() { + val mats = Material.values() + .filter { !it.name.startsWith("LEGACY") and !it.isEmpty and it.isItem and !it.name.contains("SPAWN") } + .filter { Collector[it] > 0 } + .chunked(45) + val needed = mats.size + repeat(needed) { + iconMenus += IconMenu(title, 6, iconfun) + } + logger.info("There are $needed pages needed to show all sales") + for ((key, v) in mats.withIndex()) { + for ((index, material) in v.withIndex()) { + val x = index % 9 + val y = index / 9 + val cost = Collector[material] + iconMenus[key].addButton(y, x, ItemStack(material), "", cost.toString()) + } + val prev = key - 1 + val next = key + 1 + if (prev >= 0) + iconMenus[key].addButton( + 5, + 0, + ItemStack(Material.FILLED_MAP), + "Page $prev", + prev.toString() + ) + if (next < mats.size) + iconMenus[key].addButton( + 5, + 8, + ItemStack(Material.FILLED_MAP), + "Page $next", + next.toString() + ) + iconMenus[key].addButton( + 5, + 4, + ItemStack(Material.MAP), + "Page $key" + ) + + } + + } + + companion object { + lateinit var logger: Logger + lateinit var config: BankConfig + } + +} \ No newline at end of file diff --git a/VoidBank/src/main/kotlin/nl/voidcorp/bankplugin/WoodStripCommand.kt b/VoidBank/src/main/kotlin/nl/voidcorp/bankplugin/WoodStripCommand.kt new file mode 100644 index 0000000..9196f9d --- /dev/null +++ b/VoidBank/src/main/kotlin/nl/voidcorp/bankplugin/WoodStripCommand.kt @@ -0,0 +1,31 @@ +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/VoidBank/src/main/resources/default.json b/VoidBank/src/main/resources/default.json new file mode 100644 index 0000000..a2c3395 --- /dev/null +++ b/VoidBank/src/main/resources/default.json @@ -0,0 +1,293 @@ +{ + "comment": "Default values for non-OreDictionary vanilla items", + "groups": { + "default": { + "comment": "Default conversion group", + "conversions": [ + { + "output": "minecraft:grass_block", + "ingredients": { + "minecraft:dirt": 2 + } + }, + { + "output": "minecraft:podzol", + "ingredients": { + "minecraft:dirt": 2 + } + }, + { + "output": "minecraft:mycelium", + "ingredients": { + "minecraft:dirt": 2 + } + }, + { + "output": "minecraft:grass_path", + "ingredients": [ "minecraft:grass" ] + }, + { + "output": "minecraft:iron_horse_armor", + "ingredients": { + "minecraft:iron_ingot": 8 + } + }, + { + "output": "minecraft:golden_horse_armor", + "ingredients": { + "minecraft:gold_ingot": 8 + } + }, + { + "output": "minecraft:diamond_horse_armor", + "ingredients": { + "minecraft:diamond": 8 + } + }, + { + "output": "minecraft:carved_pumpkin", + "ingredients": [ "minecraft:pumpkin" ] + }, + { + "output": "minecraft:enchanted_golden_apple", + "ingredients": { + "minecraft:apple": 1, + "minecraft:gold_block": 8 + } + }, + { + "output": "minecraft:wet_sponge", + "ingredients": [ "minecraft:sponge" ] + } + ] + }, + "concrete_powder_to_block": { + "comment": "Propagate concrete powder values to concrete blocks", + "conversions": [ + { + "output": "minecraft:white_concrete", + "ingredients": [ "minecraft:white_concrete_powder" ] + }, + { + "output": "minecraft:orange_concrete", + "ingredients": [ "minecraft:orange_concrete_powder" ] + }, + { + "output": "minecraft:magenta_concrete", + "ingredients": [ "minecraft:magenta_concrete_powder" ] + }, + { + "output": "minecraft:light_blue_concrete", + "ingredients": [ "minecraft:light_blue_concrete_powder" ] + }, + { + "output": "minecraft:yellow_concrete", + "ingredients": [ "minecraft:yellow_concrete_powder" ] + }, + { + "output": "minecraft:lime_concrete", + "ingredients": [ "minecraft:lime_concrete_powder" ] + }, + { + "output": "minecraft:pink_concrete", + "ingredients": [ "minecraft:pink_concrete_powder" ] + }, + { + "output": "minecraft:gray_concrete", + "ingredients": [ "minecraft:gray_concrete_powder" ] + }, + { + "output": "minecraft:light_gray_concrete", + "ingredients": [ "minecraft:light_gray_concrete_powder" ] + }, + { + "output": "minecraft:cyan_concrete", + "ingredients": [ "minecraft:cyan_concrete_powder" ] + }, + { + "output": "minecraft:purple_concrete", + "ingredients": [ "minecraft:purple_concrete_powder" ] + }, + { + "output": "minecraft:blue_concrete", + "ingredients": [ "minecraft:blue_concrete_powder" ] + }, + { + "output": "minecraft:brown_concrete", + "ingredients": [ "minecraft:brown_concrete_powder" ] + }, + { + "output": "minecraft:green_concrete", + "ingredients": [ "minecraft:green_concrete_powder" ] + }, + { + "output": "minecraft:red_concrete", + "ingredients": [ "minecraft:red_concrete_powder" ] + }, + { + "output": "minecraft:black_concrete", + "ingredients": [ "minecraft:black_concrete_powder" ] + } + ] + } + }, + "values": { + "before": { + "minecraft:cobblestone": 1, + "minecraft:stone": 1, + "minecraft:granite": 16, + "minecraft:diorite": 16, + "minecraft:andesite": 16, + "minecraft:cracked_stone_bricks": 1, + "minecraft:chiseled_stone_bricks": 1, + "minecraft:end_stone": 1, + "minecraft:netherrack": 1, + "minecraft:dirt": 1, + "minecraft:sand": 1, + "minecraft:red_sand": 1, + "minecraft:snow": 1, + "minecraft:ice": 1, + "minecraft:dead_bush": 1, + "minecraft:gravel": 4, + "minecraft:cactus": 8, + "minecraft:vine": 8, + "minecraft:cobweb": 12, + "minecraft:lily_pad": 16, + "minecraft:poppy": 16, + "minecraft:blue_orchid": 16, + "minecraft:allium": 16, + "minecraft:azure_bluet": 16, + "minecraft:red_tulip": 16, + "minecraft:orange_tulip": 16, + "minecraft:white_tulip": 16, + "minecraft:pink_tulip": 16, + "minecraft:oxeye_daisy": 16, + "minecraft:sunflower": 32, + "minecraft:lilac": 32, + "minecraft:rose_bush": 32, + "minecraft:peony": 32, + "minecraft:dandelion": 16, + "minecraft:red_mushroom": 32, + "minecraft:brown_mushroom": 32, + "minecraft:sugar_cane": 32, + "minecraft:soul_sand": 49, + "minecraft:obsidian": 64, + "minecraft:white_terracotta": 64, + "minecraft:orange_terracotta": 64, + "minecraft:magenta_terracotta": 64, + "minecraft:light_blue_terracotta": 64, + "minecraft:yellow_terracotta": 64, + "minecraft:lime_terracotta": 64, + "minecraft:pink_terracotta": 64, + "minecraft:gray_terracotta": 64, + "minecraft:light_gray_terracotta": 64, + "minecraft:cyan_terracotta": 64, + "minecraft:purple_terracotta": 64, + "minecraft:blue_terracotta": 64, + "minecraft:brown_terracotta": 64, + "minecraft:green_terracotta": 64, + "minecraft:red_terracotta": 64, + "minecraft:black_terracotta": 64, + "minecraft:sponge": 128, + "minecraft:grass": 1, + "minecraft:seagrass": 1, + "minecraft:kelp": 1, + "minecraft:sea_pickle": 16, + "minecraft:tall_grass": 1, + "minecraft:fern": 1, + "minecraft:large_fern": 1, + "minecraft:packed_ice": 4, + "minecraft:magma_block": 128, + + "minecraft:tube_coral_block": 64, + "minecraft:brain_coral_block": 64, + "minecraft:bubble_coral_block": 64, + "minecraft:fire_coral_block": 64, + "minecraft:horn_coral_block": 64, + "minecraft:dead_tube_coral_block": 1, + "minecraft:dead_brain_coral_block": 1, + "minecraft:dead_bubble_coral_block": 1, + "minecraft:dead_fire_coral_block": 1, + "minecraft:dead_horn_coral_block": 1, + "minecraft:tube_coral": 16, + "minecraft:brain_coral": 16, + "minecraft:bubble_coral": 16, + "minecraft:fire_coral": 16, + "minecraft:horn_coral": 16, + "minecraft:tube_coral_fan": 16, + "minecraft:brain_coral_fan": 16, + "minecraft:bubble_coral_fan": 16, + "minecraft:fire_coral_fan": 16, + "minecraft:horn_coral_fan": 16, + "minecraft:dead_tube_coral_fan": 1, + "minecraft:dead_brain_coral_fan": 1, + "minecraft:dead_bubble_coral_fan": 1, + "minecraft:dead_fire_coral_fan": 1, + "minecraft:dead_horn_coral_fan": 1, + + + "minecraft:chorus_plant": 64, + "minecraft:chorus_flower": 96, + "minecraft:wheat_seeds": 16, + "minecraft:beetroot_seeds": 16, + "minecraft:melon": 16, + "minecraft:wheat": 24, + "minecraft:nether_wart": 24, + "minecraft:apple": 128, + "minecraft:pumpkin": 144, + "minecraft:porkchop": 64, + "minecraft:beef": 64, + "minecraft:chicken": 64, + "minecraft:rabbit": 64, + "minecraft:mutton": 64, + "minecraft:cod": 64, + "minecraft:salmon": 64, + "minecraft:tropical_fish": 64, + "minecraft:pufferfish": 64, + "minecraft:carrot": 64, + "minecraft:beetroot": 64, + "minecraft:potato": 64, + "minecraft:poisonous_potato": 64, + "minecraft:chorus_fruit": 192, + + "minecraft:string": 12, + "minecraft:rotten_flesh": 32, + "minecraft:slime_ball": 32, + "minecraft:egg": 32, + "minecraft:scute": 96, + "minecraft:feather": 48, + "minecraft:rabbit_hide": 16, + "minecraft:rabbit_foot": 128, + "minecraft:spider_eye": 128, + "minecraft:phantom_membrane": 192, + "minecraft:gunpowder": 192, + "minecraft:ender_pearl": 1024, + "minecraft:nautilus_shell": 1024, + "minecraft:blaze_rod": 1536, + "minecraft:shulker_shell": 2048, + "minecraft:ghast_tear": 4096, + "minecraft:dragon_egg": 262144, + "minecraft:potion": 0, + + "minecraft:saddle": 192, + "minecraft:name_tag": 192, + "#forge:music_discs": 2048, + + "minecraft:flint": 4, + "minecraft:coal": 128, + "minecraft:quartz": 256, + "minecraft:prismarine_shard": 256, + "minecraft:prismarine_crystals": 512, + "minecraft:ink_sac": 16, + "minecraft:cocoa_beans": 128, + "minecraft:lapis_lazuli": 864, + "minecraft:enchanted_book": 2048, + "minecraft:emerald": 16384, + "minecraft:nether_star": 139264, + "minecraft:clay_ball": 16, + "minecraft:bone": 144, + "minecraft:snowball": 1, + "minecraft:filled_map": 1472 + } + } +} diff --git a/VoidPlugin/build.gradle b/VoidPlugin/build.gradle index 51ee33d..d97ac8f 100644 --- a/VoidPlugin/build.gradle +++ b/VoidPlugin/build.gradle @@ -9,7 +9,7 @@ plugins { dependencies { api "org.jetbrains.kotlin:kotlin-stdlib-jdk8" api 'org.jetbrains.exposed:exposed:0.17.1' - implementation "com.squareup.moshi:moshi-kotlin:1.8.0" + api "com.squareup.moshi:moshi-kotlin:1.8.0" implementation group: 'org.xerial', name: 'sqlite-jdbc', version: '3.28.0' } @@ -17,26 +17,4 @@ bukkit { main = "nl.voidcorp.mainplugin.VoidPlugin" apiVersion = '1.13' author = 'J00LZ' - commands { - memes { - description = "Memes" - } - nick { - description = "Set a nickname (prolly broken if im honest)" - } - heal { - description = "Heal yourself (if you have the permissions to do so)" - permission = 'voidplugin.heal' - permissionMessage = 'You are not allowed to heal yourself!' - } - } - permissions { - 'voidplugin.*' { - children = ['voidplugin.heal'] - } - 'voidplugin.heal' { - description = 'Allows you to heal' - setDefault('OP') // 'TRUE', 'FALSE', 'OP' or 'NOT_OP' - } - } } \ No newline at end of file diff --git a/VoidPlugin/src/main/kotlin/nl/voidcorp/mainplugin/VoidEvents.kt b/VoidPlugin/src/main/kotlin/nl/voidcorp/mainplugin/VoidEvents.kt deleted file mode 100644 index 3f0ee53..0000000 --- a/VoidPlugin/src/main/kotlin/nl/voidcorp/mainplugin/VoidEvents.kt +++ /dev/null @@ -1,24 +0,0 @@ -package nl.voidcorp.mainplugin - -import org.bukkit.ChatColor -import org.bukkit.event.EventHandler -import org.bukkit.event.Listener -import org.bukkit.event.player.PlayerJoinEvent -import org.jetbrains.exposed.sql.transactions.transaction - - -object VoidEvents : Listener { - - @EventHandler - fun onJoin(evt: PlayerJoinEvent) { - transaction { - val nick = Nick.find { NickTable.userid eq evt.player.uniqueId }.firstOrNull()?.nickname - if (nick != null) { - evt.player.setDisplayName(nick) - } - } - evt.joinMessage = - "Hello ${ChatColor.BLUE}${evt.player.displayName}${ChatColor.RESET}, and welcome to ${ChatColor.BOLD}Xirion.net${ChatColor.RESET}!" - } - -} \ No newline at end of file diff --git a/VoidPlugin/src/main/kotlin/nl/voidcorp/mainplugin/VoidPlugin.kt b/VoidPlugin/src/main/kotlin/nl/voidcorp/mainplugin/VoidPlugin.kt index 00da03e..af5c70c 100644 --- a/VoidPlugin/src/main/kotlin/nl/voidcorp/mainplugin/VoidPlugin.kt +++ b/VoidPlugin/src/main/kotlin/nl/voidcorp/mainplugin/VoidPlugin.kt @@ -1,8 +1,5 @@ package nl.voidcorp.mainplugin -import nl.voidcorp.mainplugin.commands.HealCommand -import nl.voidcorp.mainplugin.commands.MemeCommand -import nl.voidcorp.mainplugin.commands.NickCommand import nl.voidcorp.mainplugin.messaging.Message import nl.voidcorp.mainplugin.messaging.MessageType import org.jetbrains.exposed.sql.Database @@ -17,11 +14,6 @@ class VoidPlugin( var db: Database? = null override fun enable() { - server.pluginManager.registerEvents(VoidEvents, this) - CommandHandler(this) - .registerCommand("memes", MemeCommand()) - .registerCommand("nick", NickCommand()) - .registerCommand("heal", HealCommand()) send(name, MessageType.GET_CONFIG) send(name, MessageType.POST_CONFIG, moshi.adapter().toJson(conf)) @@ -30,9 +22,6 @@ class VoidPlugin( conf.databaseUrl, driver = conf.driver ) - transaction { - SchemaUtils.createMissingTablesAndColumns(NickTable) - } } override fun disable() { @@ -57,6 +46,7 @@ class VoidPlugin( private fun readConfig(filename: String): String { val config = File(dataFolder.apply { mkdirs() }, "$filename.json") + logger.info(config.path) if (!config.exists()) { config.createNewFile() return "{}" @@ -66,6 +56,8 @@ class VoidPlugin( private fun writeConfig(filename: String, configString: String) { val config = File(dataFolder.apply { mkdirs() }, "$filename.json") - config.writeText(configString) + val wr = config.bufferedWriter() + wr.write(configString) + wr.close() } } \ No newline at end of file diff --git a/VoidTeleport/src/main/kotlin/nl/voidcorp/teleportplugin/VoidTeleport.kt b/VoidTeleport/src/main/kotlin/nl/voidcorp/teleportplugin/VoidTeleport.kt index 170a95b..3e0d7d0 100644 --- a/VoidTeleport/src/main/kotlin/nl/voidcorp/teleportplugin/VoidTeleport.kt +++ b/VoidTeleport/src/main/kotlin/nl/voidcorp/teleportplugin/VoidTeleport.kt @@ -19,7 +19,10 @@ import nl.voidcorp.teleportplugin.models.TeleportLocations import nl.voidcorp.teleportplugin.models.TpRequests import nl.voidcorp.teleportplugin.models.Warps import org.jetbrains.exposed.sql.SchemaUtils +import org.jetbrains.exposed.sql.SqlExpressionBuilder.lessEq +import org.jetbrains.exposed.sql.deleteWhere import org.jetbrains.exposed.sql.transactions.transaction +import org.joda.time.DateTime class VoidTeleport(override val comment: String = "Teleport around :D") : VoidPluginBase() { @@ -42,6 +45,7 @@ class VoidTeleport(override val comment: String = "Teleport around :D") : server.pluginManager.registerEvents(TpEvents, this) transaction { SchemaUtils.createMissingTablesAndColumns(Homes, Warps, TpRequests, TeleportLocations) + TpRequests.deleteWhere { TpRequests.timeout lessEq DateTime.now() } } } } \ No newline at end of file diff --git a/VoidTeleport/src/main/kotlin/nl/voidcorp/teleportplugin/commands/tpx/TpaCommand.kt b/VoidTeleport/src/main/kotlin/nl/voidcorp/teleportplugin/commands/tpx/TpaCommand.kt index f626f63..8697daa 100644 --- a/VoidTeleport/src/main/kotlin/nl/voidcorp/teleportplugin/commands/tpx/TpaCommand.kt +++ b/VoidTeleport/src/main/kotlin/nl/voidcorp/teleportplugin/commands/tpx/TpaCommand.kt @@ -11,7 +11,9 @@ import org.bukkit.command.Command import org.bukkit.command.CommandSender import org.bukkit.entity.Player import org.jetbrains.exposed.sql.and +import org.jetbrains.exposed.sql.deleteWhere import org.jetbrains.exposed.sql.transactions.transaction +import org.joda.time.DateTime class TpaCommand : VoidCommand() { override fun onTabComplete( @@ -41,15 +43,13 @@ class TpaCommand : VoidCommand() { return true } transaction { - val open = - TpRequest.find { (TpRequests.from eq sender.uniqueId) and (TpRequests.to eq pl.uniqueId) }.toList() - open.forEach { - if (it.timeout.isAfterNow) { - it.delete() + TpRequests.deleteWhere { TpRequests.timeout lessEq DateTime.now() } + + if (TpRequest.find { TpRequests.to eq pl.uniqueId }.toList().isNotEmpty()) { + sender.sendMessage("${pl.displayName} already has a request open...") + if (TpRequest.find { (TpRequests.from eq sender.uniqueId) and (TpRequests.to eq pl.uniqueId) }.toList().isNotEmpty()) { + sender.sendMessage("Actually, you sent that request...") } - } - if (TpRequest.find { (TpRequests.from eq sender.uniqueId) and (TpRequests.to eq pl.uniqueId) }.toList().isNotEmpty()) { - sender.sendMessage("You already have a request open for ${pl.displayName}") } else { TpRequest.new { from = sender.uniqueId diff --git a/VoidTeleport/src/main/kotlin/nl/voidcorp/teleportplugin/models/TpRequests.kt b/VoidTeleport/src/main/kotlin/nl/voidcorp/teleportplugin/models/TpRequests.kt index f46c773..058f487 100644 --- a/VoidTeleport/src/main/kotlin/nl/voidcorp/teleportplugin/models/TpRequests.kt +++ b/VoidTeleport/src/main/kotlin/nl/voidcorp/teleportplugin/models/TpRequests.kt @@ -5,6 +5,6 @@ import org.joda.time.DateTime object TpRequests : IntIdTable() { val from = uuid("from") - val to = uuid("to").uniqueIndex() + val to = uuid("to") val timeout = datetime("timeout").clientDefault { DateTime.now().plusSeconds(30) } } \ No newline at end of file diff --git a/VoidUtils/build.gradle b/VoidUtils/build.gradle new file mode 100644 index 0000000..cf5e09e --- /dev/null +++ b/VoidUtils/build.gradle @@ -0,0 +1,24 @@ +plugins { + id 'java' + id 'org.jetbrains.kotlin.jvm' + id 'com.github.johnrengelman.shadow' + id 'net.minecrell.plugin-yml.bukkit' +} + +dependencies { + compileOnly project(":VoidPlugin") +} +bukkit { + main = "nl.voidcorp.utilsplugin.VoidUtils" + apiVersion = '1.13' + author = 'J00LZ' + depend = ['VoidPlugin'] + commands { + memes { + description = "Memes" + } + nick { + description = "Set a nickname (prolly broken if im honest)" + } + } +} \ 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 new file mode 100644 index 0000000..287a17d --- /dev/null +++ b/VoidUtils/src/main/kotlin/nl/voidcorp/utilsplugin/Events.kt @@ -0,0 +1,46 @@ +package nl.voidcorp.utilsplugin + +import org.bukkit.ChatColor +import org.bukkit.event.EventHandler +import org.bukkit.event.Listener +import org.bukkit.event.player.PlayerBedEnterEvent +import org.bukkit.event.player.PlayerBedLeaveEvent +import org.bukkit.event.player.PlayerJoinEvent +import org.jetbrains.exposed.sql.transactions.transaction +import java.util.* +import kotlin.math.roundToInt + +class Events(private val utils: VoidUtils) : Listener { + @EventHandler + fun onJoin(evt: PlayerJoinEvent) { + transaction { + val nick = Nick.find { NickTable.userid eq evt.player.uniqueId }.firstOrNull()?.nickname + if (nick != null) { + evt.player.setDisplayName(nick) + } + } + } + + private val bedList = mutableSetOf() + + @EventHandler + fun onBedEnter(evt: PlayerBedEnterEvent) { + if (evt.bedEnterResult != PlayerBedEnterEvent.BedEnterResult.OK) return + val id = evt.player.uniqueId + bedList.add(id) + 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 + 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!") + } + + @EventHandler + fun onBedLeave(evt: PlayerBedLeaveEvent) { + val id = evt.player.uniqueId + bedList.remove(id) + } + +} \ No newline at end of file diff --git a/VoidPlugin/src/main/kotlin/nl/voidcorp/mainplugin/PlayerTable.kt b/VoidUtils/src/main/kotlin/nl/voidcorp/utilsplugin/PlayerTable.kt similarity index 93% rename from VoidPlugin/src/main/kotlin/nl/voidcorp/mainplugin/PlayerTable.kt rename to VoidUtils/src/main/kotlin/nl/voidcorp/utilsplugin/PlayerTable.kt index f57848b..d918d37 100644 --- a/VoidPlugin/src/main/kotlin/nl/voidcorp/mainplugin/PlayerTable.kt +++ b/VoidUtils/src/main/kotlin/nl/voidcorp/utilsplugin/PlayerTable.kt @@ -1,4 +1,4 @@ -package nl.voidcorp.mainplugin +package nl.voidcorp.utilsplugin import org.jetbrains.exposed.dao.EntityID import org.jetbrains.exposed.dao.IntEntity diff --git a/VoidUtils/src/main/kotlin/nl/voidcorp/utilsplugin/UtilsConfig.kt b/VoidUtils/src/main/kotlin/nl/voidcorp/utilsplugin/UtilsConfig.kt new file mode 100644 index 0000000..e1da791 --- /dev/null +++ b/VoidUtils/src/main/kotlin/nl/voidcorp/utilsplugin/UtilsConfig.kt @@ -0,0 +1,3 @@ +package nl.voidcorp.utilsplugin + +data class UtilsConfig(val neededPlayers: Double = 0.3) \ No newline at end of file diff --git a/VoidUtils/src/main/kotlin/nl/voidcorp/utilsplugin/VoidUtils.kt b/VoidUtils/src/main/kotlin/nl/voidcorp/utilsplugin/VoidUtils.kt new file mode 100644 index 0000000..45effde --- /dev/null +++ b/VoidUtils/src/main/kotlin/nl/voidcorp/utilsplugin/VoidUtils.kt @@ -0,0 +1,40 @@ +package nl.voidcorp.utilsplugin + +import nl.voidcorp.mainplugin.CommandHandler +import nl.voidcorp.mainplugin.VoidPluginBase +import nl.voidcorp.mainplugin.adapter +import nl.voidcorp.mainplugin.messaging.Message +import nl.voidcorp.mainplugin.messaging.MessageType +import nl.voidcorp.mainplugin.moshi +import nl.voidcorp.utilsplugin.commands.MemeCommand +import nl.voidcorp.utilsplugin.commands.NickCommand +import org.jetbrains.exposed.sql.SchemaUtils +import org.jetbrains.exposed.sql.transactions.transaction + +class VoidUtils(override val comment: String = "Add some useful utilities!") : VoidPluginBase() { + lateinit var conf: UtilsConfig + override fun enable() { + transaction { + SchemaUtils.createMissingTablesAndColumns(NickTable) + } + + send("VoidPlugin", MessageType.GET_CONFIG) + send("VoidPlugin", MessageType.POST_CONFIG, moshi.adapter().toJson(conf)) + + CommandHandler(this) + .registerCommand("memes", MemeCommand()) + .registerCommand("nick", NickCommand()) + + server.pluginManager.registerEvents(Events(this), this) + + } + + override fun recieve(message: Message) { + when (message.messageType) { + MessageType.GET_CONFIG -> { + conf = moshi.adapter().fromJson(message.content)!! + } + else -> Unit + } + } +} \ No newline at end of file diff --git a/VoidPlugin/src/main/kotlin/nl/voidcorp/mainplugin/commands/MemeCommand.kt b/VoidUtils/src/main/kotlin/nl/voidcorp/utilsplugin/commands/MemeCommand.kt similarity index 86% rename from VoidPlugin/src/main/kotlin/nl/voidcorp/mainplugin/commands/MemeCommand.kt rename to VoidUtils/src/main/kotlin/nl/voidcorp/utilsplugin/commands/MemeCommand.kt index 4158969..23dfbef 100644 --- a/VoidPlugin/src/main/kotlin/nl/voidcorp/mainplugin/commands/MemeCommand.kt +++ b/VoidUtils/src/main/kotlin/nl/voidcorp/utilsplugin/commands/MemeCommand.kt @@ -1,5 +1,6 @@ -package nl.voidcorp.mainplugin.commands +package nl.voidcorp.utilsplugin.commands +import nl.voidcorp.mainplugin.commands.VoidCommand import org.bukkit.Sound import org.bukkit.SoundCategory import org.bukkit.command.Command diff --git a/VoidPlugin/src/main/kotlin/nl/voidcorp/mainplugin/commands/NickCommand.kt b/VoidUtils/src/main/kotlin/nl/voidcorp/utilsplugin/commands/NickCommand.kt similarity index 87% rename from VoidPlugin/src/main/kotlin/nl/voidcorp/mainplugin/commands/NickCommand.kt rename to VoidUtils/src/main/kotlin/nl/voidcorp/utilsplugin/commands/NickCommand.kt index 632fef3..26a19bc 100644 --- a/VoidPlugin/src/main/kotlin/nl/voidcorp/mainplugin/commands/NickCommand.kt +++ b/VoidUtils/src/main/kotlin/nl/voidcorp/utilsplugin/commands/NickCommand.kt @@ -1,7 +1,8 @@ -package nl.voidcorp.mainplugin.commands +package nl.voidcorp.utilsplugin.commands -import nl.voidcorp.mainplugin.Nick -import nl.voidcorp.mainplugin.NickTable +import nl.voidcorp.mainplugin.commands.VoidCommand +import nl.voidcorp.utilsplugin.Nick +import nl.voidcorp.utilsplugin.NickTable import org.bukkit.ChatColor import org.bukkit.command.Command import org.bukkit.command.CommandSender diff --git a/build.gradle b/build.gradle index af36628..8e32ff8 100644 --- a/build.gradle +++ b/build.gradle @@ -22,7 +22,7 @@ subprojects { dependencies { testCompile group: 'junit', name: 'junit', version: '4.12' - compileOnly 'com.destroystokyo.paper:paper-api:1.13.2-R0.1-SNAPSHOT' + compileOnly 'com.destroystokyo.paper:paper-api:1.14.2-R0.1-SNAPSHOT' } compileKotlin { diff --git a/settings.gradle b/settings.gradle index 0429e7c..c38ee22 100644 --- a/settings.gradle +++ b/settings.gradle @@ -1,4 +1,7 @@ rootProject.name = 'VoidPluginBase' include 'VoidTeleport' -include 'VoidPlugin' \ No newline at end of file +include 'VoidPlugin' +include 'VoidAdmin' +include 'VoidUtils' +include 'VoidBank' \ No newline at end of file