Add Admin, Bank and Utils, Fix Teleport and Base

This commit is contained in:
Julius 2019-08-25 01:19:27 +02:00
parent d6bc214a94
commit 99749ee92c
30 changed files with 1054 additions and 76 deletions

39
VoidAdmin/build.gradle Normal file
View file

@ -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'
}
}
}

View file

@ -0,0 +1,3 @@
package nl.voidcorp.adminplugin
data class AdminConfig(val serverName: String = "My Server")

View file

@ -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<AdminConfig>().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<AdminConfig>().toJson(config))
}
override fun recieve(message: Message) {
when (message.messageType) {
MessageType.GET_CONFIG -> {
config = moshi.adapter<AdminConfig>().fromJson(message.content)!!
}
else->{}
}
}
}

View file

@ -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}!"
}
}

View file

@ -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.attribute.Attribute
import org.bukkit.command.Command import org.bukkit.command.Command
import org.bukkit.command.CommandSender import org.bukkit.command.CommandSender

View file

@ -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<out String>): 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
}
}

24
VoidBank/build.gradle Normal file
View file

@ -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"
}
}
}

View file

@ -0,0 +1,3 @@
package nl.voidcorp.bankplugin
data class BankConfig(var rerun: Boolean = true, var bankMap: MutableMap<String, Int> = mutableMapOf())

View file

@ -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<out String>): 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
}
}

View file

@ -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<ProjectEBorrow>()
.fromJson(Collector::class.java.getResourceAsStream("/default.json").bufferedReader().readText())
if (borrow != null) {
prices.putAll(borrow.values.asMaterialList)
}
// let the pain commence
val simple = mutableListOf<SimpleRecipe>()
val recipes = Bukkit.recipeIterator().asSequence().filter { it.result.type !in prices.keys }.toMutableList()
val shapeless = recipes.filterIsInstance<ShapelessRecipe>()
val shaped = recipes.filterIsInstance<ShapedRecipe>()
val furnace = recipes.filterIsInstance<FurnaceRecipe>()
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<Material, Int>()
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<Material, Int>) {
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<Material, Int>, val output: Material, val count: Int)
class meme(val recipes: List<SimpleRecipe>)
}

View file

@ -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<UUID> = mutableListOf()
private val items: MutableList<ItemStack?> = 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<ItemStack?> {
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
}
}

View file

@ -0,0 +1,9 @@
package nl.voidcorp.bankplugin
import org.bukkit.Material
data class ProjectEBorrow(val comment: String, val groups: Map<String, Any>, val values: Values)
data class Values(val before: Map<String, Int>) {
val asMaterialList: Map<Material, Int>
get() = before.filterKeys { Material.matchMaterial(it) != null }.map { Material.matchMaterial(it.key)!! to it.value }.toMap()
}

View file

@ -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<BankConfig>().toJson(VoidBank.config))
Collector.rangeTo(0)
send("VoidPlugin", MessageType.POST_CONFIG, moshi.adapter<BankConfig>().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<BankConfig>().fromJson(message.content)!!
}
else -> Unit
}
}
val map = mutableMapOf<UUID, Int>()
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<IconMenu>()
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
}
}

View file

@ -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<out String>): 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
}
}

View file

@ -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
}
}
}

View file

@ -9,7 +9,7 @@ plugins {
dependencies { dependencies {
api "org.jetbrains.kotlin:kotlin-stdlib-jdk8" api "org.jetbrains.kotlin:kotlin-stdlib-jdk8"
api 'org.jetbrains.exposed:exposed:0.17.1' 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' implementation group: 'org.xerial', name: 'sqlite-jdbc', version: '3.28.0'
} }
@ -17,26 +17,4 @@ bukkit {
main = "nl.voidcorp.mainplugin.VoidPlugin" main = "nl.voidcorp.mainplugin.VoidPlugin"
apiVersion = '1.13' apiVersion = '1.13'
author = 'J00LZ' 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'
}
}
} }

View file

@ -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}!"
}
}

View file

@ -1,8 +1,5 @@
package nl.voidcorp.mainplugin 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.Message
import nl.voidcorp.mainplugin.messaging.MessageType import nl.voidcorp.mainplugin.messaging.MessageType
import org.jetbrains.exposed.sql.Database import org.jetbrains.exposed.sql.Database
@ -17,11 +14,6 @@ class VoidPlugin(
var db: Database? = null var db: Database? = null
override fun enable() { 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.GET_CONFIG)
send(name, MessageType.POST_CONFIG, moshi.adapter<Config>().toJson(conf)) send(name, MessageType.POST_CONFIG, moshi.adapter<Config>().toJson(conf))
@ -30,9 +22,6 @@ class VoidPlugin(
conf.databaseUrl, conf.databaseUrl,
driver = conf.driver driver = conf.driver
) )
transaction {
SchemaUtils.createMissingTablesAndColumns(NickTable)
}
} }
override fun disable() { override fun disable() {
@ -57,6 +46,7 @@ class VoidPlugin(
private fun readConfig(filename: String): String { private fun readConfig(filename: String): String {
val config = File(dataFolder.apply { mkdirs() }, "$filename.json") val config = File(dataFolder.apply { mkdirs() }, "$filename.json")
logger.info(config.path)
if (!config.exists()) { if (!config.exists()) {
config.createNewFile() config.createNewFile()
return "{}" return "{}"
@ -66,6 +56,8 @@ class VoidPlugin(
private fun writeConfig(filename: String, configString: String) { private fun writeConfig(filename: String, configString: String) {
val config = File(dataFolder.apply { mkdirs() }, "$filename.json") val config = File(dataFolder.apply { mkdirs() }, "$filename.json")
config.writeText(configString) val wr = config.bufferedWriter()
wr.write(configString)
wr.close()
} }
} }

View file

@ -19,7 +19,10 @@ import nl.voidcorp.teleportplugin.models.TeleportLocations
import nl.voidcorp.teleportplugin.models.TpRequests import nl.voidcorp.teleportplugin.models.TpRequests
import nl.voidcorp.teleportplugin.models.Warps import nl.voidcorp.teleportplugin.models.Warps
import org.jetbrains.exposed.sql.SchemaUtils 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.jetbrains.exposed.sql.transactions.transaction
import org.joda.time.DateTime
class VoidTeleport(override val comment: String = "Teleport around :D") : class VoidTeleport(override val comment: String = "Teleport around :D") :
VoidPluginBase() { VoidPluginBase() {
@ -42,6 +45,7 @@ class VoidTeleport(override val comment: String = "Teleport around :D") :
server.pluginManager.registerEvents(TpEvents, this) server.pluginManager.registerEvents(TpEvents, this)
transaction { transaction {
SchemaUtils.createMissingTablesAndColumns(Homes, Warps, TpRequests, TeleportLocations) SchemaUtils.createMissingTablesAndColumns(Homes, Warps, TpRequests, TeleportLocations)
TpRequests.deleteWhere { TpRequests.timeout lessEq DateTime.now() }
} }
} }
} }

View file

@ -11,7 +11,9 @@ import org.bukkit.command.Command
import org.bukkit.command.CommandSender import org.bukkit.command.CommandSender
import org.bukkit.entity.Player import org.bukkit.entity.Player
import org.jetbrains.exposed.sql.and import org.jetbrains.exposed.sql.and
import org.jetbrains.exposed.sql.deleteWhere
import org.jetbrains.exposed.sql.transactions.transaction import org.jetbrains.exposed.sql.transactions.transaction
import org.joda.time.DateTime
class TpaCommand : VoidCommand() { class TpaCommand : VoidCommand() {
override fun onTabComplete( override fun onTabComplete(
@ -41,15 +43,13 @@ class TpaCommand : VoidCommand() {
return true return true
} }
transaction { transaction {
val open = TpRequests.deleteWhere { TpRequests.timeout lessEq DateTime.now() }
TpRequest.find { (TpRequests.from eq sender.uniqueId) and (TpRequests.to eq pl.uniqueId) }.toList()
open.forEach { if (TpRequest.find { TpRequests.to eq pl.uniqueId }.toList().isNotEmpty()) {
if (it.timeout.isAfterNow) { sender.sendMessage("${pl.displayName} already has a request open...")
it.delete() 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 { } else {
TpRequest.new { TpRequest.new {
from = sender.uniqueId from = sender.uniqueId

View file

@ -5,6 +5,6 @@ import org.joda.time.DateTime
object TpRequests : IntIdTable() { object TpRequests : IntIdTable() {
val from = uuid("from") val from = uuid("from")
val to = uuid("to").uniqueIndex() val to = uuid("to")
val timeout = datetime("timeout").clientDefault { DateTime.now().plusSeconds(30) } val timeout = datetime("timeout").clientDefault { DateTime.now().plusSeconds(30) }
} }

24
VoidUtils/build.gradle Normal file
View file

@ -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)"
}
}
}

View file

@ -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<UUID>()
@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)
}
}

View file

@ -1,4 +1,4 @@
package nl.voidcorp.mainplugin package nl.voidcorp.utilsplugin
import org.jetbrains.exposed.dao.EntityID import org.jetbrains.exposed.dao.EntityID
import org.jetbrains.exposed.dao.IntEntity import org.jetbrains.exposed.dao.IntEntity

View file

@ -0,0 +1,3 @@
package nl.voidcorp.utilsplugin
data class UtilsConfig(val neededPlayers: Double = 0.3)

View file

@ -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<UtilsConfig>().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<UtilsConfig>().fromJson(message.content)!!
}
else -> Unit
}
}
}

View file

@ -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.Sound
import org.bukkit.SoundCategory import org.bukkit.SoundCategory
import org.bukkit.command.Command import org.bukkit.command.Command

View file

@ -1,7 +1,8 @@
package nl.voidcorp.mainplugin.commands package nl.voidcorp.utilsplugin.commands
import nl.voidcorp.mainplugin.Nick import nl.voidcorp.mainplugin.commands.VoidCommand
import nl.voidcorp.mainplugin.NickTable import nl.voidcorp.utilsplugin.Nick
import nl.voidcorp.utilsplugin.NickTable
import org.bukkit.ChatColor import org.bukkit.ChatColor
import org.bukkit.command.Command import org.bukkit.command.Command
import org.bukkit.command.CommandSender import org.bukkit.command.CommandSender

View file

@ -22,7 +22,7 @@ subprojects {
dependencies { dependencies {
testCompile group: 'junit', name: 'junit', version: '4.12' 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 { compileKotlin {

View file

@ -1,4 +1,7 @@
rootProject.name = 'VoidPluginBase' rootProject.name = 'VoidPluginBase'
include 'VoidTeleport' include 'VoidTeleport'
include 'VoidPlugin' include 'VoidPlugin'
include 'VoidAdmin'
include 'VoidUtils'
include 'VoidBank'