DAO Extensions
DAO is a really cool part of the Exposed and KotlinBukkitKIT can't let this without any extensions :D .
Making plugins we have commum types that we want to store, in file, in a database. Exposed make easy to work with database, but, it can get a little boilerplate in a point that you think "there is no better way to do that?".
Let's get the Location example for a minute, we usually store the world, x, y, z, yaw, pitch in different columns and convert it to Location and set a location to the Exposed DAO can be a little boilerplate. For that, we have delegate extensions to work with Bukkit Plugin commum types.
These are the following supported types:
Block
BlockPos (Just the position without trying to get the World from the Server)
Chunk
ChunkPos (Just the chunk position without trying to get the World from the Server)
Location
LocationPos (Just the position without trying to get the World from the Server)
OfflinePlayer
World
Item (NOTE: This does not save NBT and could break version to version, you can build your own copying and changing the serialization/deserialization logic)
Using it at your DAO
object MarketTable : IntIdTable() {
...
val seller = uuid("seller")
val item = blob("item")
val customer = uuid("customer").nullable()
// location
val world = varchar("world", 50)
val x = double("x")
val y = double("y")
val z = double("z")
val yaw = float("yaw")
val pitch = float("pitch")
...
}
class MarketItem(id: EntityID<Int>) : IntEntity(id) {
...
var seller by offlinePlayer(MarketTable.seller)
var item by itemStack(MarketTable.item)
var customer by nullableOfflinePlayer(MarketTable.customer)
var location by location(MarketTable.world, MarketTable.x, MarketTable.y, MarketTable.z, MarketTable.yaw, MarketTable.pitch)
...
}Last updated