Merge pull request #1 from Dico200/master
Update with outstanding commits from Dico200/Parcels2
This commit is contained in:
@@ -5,6 +5,7 @@ import org.jetbrains.kotlin.gradle.dsl.Coroutines.ENABLE
|
|||||||
import org.jetbrains.kotlin.gradle.plugin.KotlinPlatformJvmPlugin
|
import org.jetbrains.kotlin.gradle.plugin.KotlinPlatformJvmPlugin
|
||||||
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
|
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
|
||||||
import java.io.PrintWriter
|
import java.io.PrintWriter
|
||||||
|
import java.net.URL
|
||||||
|
|
||||||
val stdout = PrintWriter("gradle-output.txt")
|
val stdout = PrintWriter("gradle-output.txt")
|
||||||
|
|
||||||
@@ -124,6 +125,17 @@ tasks {
|
|||||||
manifest.attributes["Class-Path"] = "../lib/kotlin-stdlib.jar"
|
manifest.attributes["Class-Path"] = "../lib/kotlin-stdlib.jar"
|
||||||
dependsOn(kotlinStdlibJar)
|
dependsOn(kotlinStdlibJar)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
val createDebugServer by creating {
|
||||||
|
|
||||||
|
val jarUrl = URL("https://yivesmirror.com/files/spigot/spigot-latest.jar")
|
||||||
|
val serverJarFile = file("$serverDir/lib/spigot.jar")
|
||||||
|
|
||||||
|
|
||||||
|
doFirst {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
stdout.flush()
|
stdout.flush()
|
||||||
|
|||||||
@@ -34,6 +34,8 @@ class Options {
|
|||||||
data class WorldOptions(var gameMode: GameMode? = GameMode.CREATIVE,
|
data class WorldOptions(var gameMode: GameMode? = GameMode.CREATIVE,
|
||||||
var dayTime: Boolean = true,
|
var dayTime: Boolean = true,
|
||||||
var noWeather: Boolean = true,
|
var noWeather: Boolean = true,
|
||||||
|
var preventWeatherBlockChanges: Boolean = true,
|
||||||
|
var preventBlockSpread: Boolean = true, // TODO
|
||||||
var dropEntityItems: Boolean = true,
|
var dropEntityItems: Boolean = true,
|
||||||
var doTileDrops: Boolean = false,
|
var doTileDrops: Boolean = false,
|
||||||
var disableExplosions: Boolean = true,
|
var disableExplosions: Boolean = true,
|
||||||
|
|||||||
@@ -77,13 +77,15 @@ class ParcelsPlugin : JavaPlugin() {
|
|||||||
if (optionsFile.exists()) {
|
if (optionsFile.exists()) {
|
||||||
yamlObjectMapper.readerForUpdating(options).readValue<Options>(optionsFile)
|
yamlObjectMapper.readerForUpdating(options).readValue<Options>(optionsFile)
|
||||||
} else if (optionsFile.tryCreate()) {
|
} else if (optionsFile.tryCreate()) {
|
||||||
options.addWorld("plotworld", WorldOptions())
|
options.addWorld("parcels", WorldOptions())
|
||||||
try {
|
try {
|
||||||
yamlObjectMapper.writeValue(optionsFile, options)
|
yamlObjectMapper.writeValue(optionsFile, options)
|
||||||
} catch (ex: Throwable) {
|
} catch (ex: Throwable) {
|
||||||
optionsFile.delete()
|
optionsFile.delete()
|
||||||
throw ex
|
throw ex
|
||||||
}
|
}
|
||||||
|
plogger.warn("Created options file with a world template. Please review it before next start.")
|
||||||
|
return false
|
||||||
} else {
|
} else {
|
||||||
plogger.error("Failed to save options file ${optionsFile.canonicalPath}")
|
plogger.error("Failed to save options file ${optionsFile.canonicalPath}")
|
||||||
return false
|
return false
|
||||||
|
|||||||
@@ -376,6 +376,40 @@ class ParcelListeners(val worlds: Worlds, val entityTracker: ParcelEntityTracker
|
|||||||
w.setGameRuleValue("doTileDrops", world.options.doTileDrops.toString())
|
w.setGameRuleValue("doTileDrops", world.options.doTileDrops.toString())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: BlockFormEvent, BlockSpreadEvent, BlockFadeEvent
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Prevents natural blocks forming
|
||||||
|
*/
|
||||||
|
@ListenerMarker(priority = NORMAL)
|
||||||
|
val onBlockFormEvent = RegistratorListener<BlockFormEvent> l@{ event ->
|
||||||
|
val block = event.block
|
||||||
|
val (wo, ppa) = getWoAndPPa(block) ?: return@l
|
||||||
|
|
||||||
|
// prevent any generation whatsoever on paths
|
||||||
|
if (ppa == null) {
|
||||||
|
event.isCancelled = true; return@l
|
||||||
|
}
|
||||||
|
|
||||||
|
val hasEntity = event is EntityBlockFormEvent
|
||||||
|
val player = (event as? EntityBlockFormEvent)?.entity as? Player
|
||||||
|
|
||||||
|
val cancel: Boolean = when (block.type) {
|
||||||
|
|
||||||
|
// prevent ice generation from Frost Walkers enchantment
|
||||||
|
ICE -> player != null && !ppa.canBuild(player)
|
||||||
|
|
||||||
|
// prevent snow generation from weather
|
||||||
|
SNOW -> !hasEntity && wo.options.preventWeatherBlockChanges
|
||||||
|
|
||||||
|
else -> false
|
||||||
|
}
|
||||||
|
|
||||||
|
if (cancel) {
|
||||||
|
event.isCancelled = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Prevents mobs (living entities) from spawning if that is disabled for that world in the config.
|
* Prevents mobs (living entities) from spawning if that is disabled for that world in the config.
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import kotlinx.coroutines.experimental.channels.ProducerScope
|
|||||||
import org.jetbrains.exposed.sql.*
|
import org.jetbrains.exposed.sql.*
|
||||||
import org.jetbrains.exposed.sql.SchemaUtils.create
|
import org.jetbrains.exposed.sql.SchemaUtils.create
|
||||||
import org.jetbrains.exposed.sql.transactions.transaction
|
import org.jetbrains.exposed.sql.transactions.transaction
|
||||||
|
import org.jetbrains.exposed.sql.vendors.DatabaseDialect
|
||||||
import org.joda.time.DateTime
|
import org.joda.time.DateTime
|
||||||
import java.util.*
|
import java.util.*
|
||||||
import javax.sql.DataSource
|
import javax.sql.DataSource
|
||||||
@@ -62,6 +63,14 @@ class ExposedBacking(private val dataSourceFactory: () -> DataSource) : Backing
|
|||||||
|
|
||||||
override val isConnected get() = database != null
|
override val isConnected get() = database != null
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
init {
|
||||||
|
Database.registerDialect("mariadb") {
|
||||||
|
Class.forName("org.jetbrains.exposed.sql.vendors.MysqlDialect").newInstance() as DatabaseDialect
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
override suspend fun init() {
|
override suspend fun init() {
|
||||||
if (isShutdown) throw IllegalStateException()
|
if (isShutdown) throw IllegalStateException()
|
||||||
dataSource = dataSourceFactory()
|
dataSource = dataSourceFactory()
|
||||||
|
|||||||
@@ -1,8 +1,10 @@
|
|||||||
package io.dico.parcels2.storage
|
package io.dico.parcels2.storage
|
||||||
|
|
||||||
import org.jetbrains.exposed.sql.*
|
import org.jetbrains.exposed.sql.Column
|
||||||
|
import org.jetbrains.exposed.sql.Index
|
||||||
|
import org.jetbrains.exposed.sql.Table
|
||||||
|
import org.jetbrains.exposed.sql.Transaction
|
||||||
import org.jetbrains.exposed.sql.statements.InsertStatement
|
import org.jetbrains.exposed.sql.statements.InsertStatement
|
||||||
import org.jetbrains.exposed.sql.statements.UpdateStatement
|
|
||||||
import org.jetbrains.exposed.sql.transactions.TransactionManager
|
import org.jetbrains.exposed.sql.transactions.TransactionManager
|
||||||
|
|
||||||
class UpsertStatement<Key : Any>(table: Table, conflictColumn: Column<*>? = null, conflictIndex: Index? = null)
|
class UpsertStatement<Key : Any>(table: Table, conflictColumn: Column<*>? = null, conflictIndex: Index? = null)
|
||||||
@@ -26,12 +28,23 @@ class UpsertStatement<Key : Any>(table: Table, conflictColumn: Column<*>? = null
|
|||||||
|
|
||||||
override fun prepareSQL(transaction: Transaction) = buildString {
|
override fun prepareSQL(transaction: Transaction) = buildString {
|
||||||
append(super.prepareSQL(transaction))
|
append(super.prepareSQL(transaction))
|
||||||
append(" ON CONFLICT(")
|
|
||||||
append(indexName)
|
|
||||||
append(") DO UPDATE SET ")
|
|
||||||
|
|
||||||
values.keys.filter { it !in indexColumns}.joinTo(this) { "${transaction.identity(it)}=EXCLUDED.${transaction.identity(it)}" }
|
val dialect = transaction.db.vendor
|
||||||
}.also { println(it) }
|
if (dialect == "postgresql") {
|
||||||
|
|
||||||
|
append(" ON CONFLICT(")
|
||||||
|
append(indexName)
|
||||||
|
append(") DO UPDATE SET ")
|
||||||
|
|
||||||
|
values.keys.filter { it !in indexColumns }.joinTo(this) { "${transaction.identity(it)}=EXCLUDED.${transaction.identity(it)}" }
|
||||||
|
|
||||||
|
} else {
|
||||||
|
|
||||||
|
append (" ON DUPLICATE KEY UPDATE ")
|
||||||
|
values.keys.filter { it !in indexColumns }.joinTo(this) { "${transaction.identity(it)}=VALUES(${transaction.identity(it)})" }
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -15,6 +15,15 @@ fun getHikariConfig(dialectName: String,
|
|||||||
dataSourceProperties["portNumber"] = port.toString()
|
dataSourceProperties["portNumber"] = port.toString()
|
||||||
dataSourceProperties["databaseName"] = dco.database
|
dataSourceProperties["databaseName"] = dco.database
|
||||||
}
|
}
|
||||||
|
|
||||||
|
"mariadb" -> run {
|
||||||
|
dataSourceClassName = "org.mariadb.jdbc.MariaDbDataSource"
|
||||||
|
dataSourceProperties["serverName"] = address
|
||||||
|
dataSourceProperties["port"] = port.toString()
|
||||||
|
dataSourceProperties["databaseName"] = dco.database
|
||||||
|
dataSourceProperties["properties"] = "useUnicode=true;characterEncoding=utf8"
|
||||||
|
}
|
||||||
|
|
||||||
else -> throw IllegalArgumentException("Unsupported dialect: $dialectName")
|
else -> throw IllegalArgumentException("Unsupported dialect: $dialectName")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ interface StorageFactory {
|
|||||||
|
|
||||||
class ConnectionStorageFactory : StorageFactory {
|
class ConnectionStorageFactory : StorageFactory {
|
||||||
override val optionsClass = DataConnectionOptions::class
|
override val optionsClass = DataConnectionOptions::class
|
||||||
private val types: List<String> = listOf("postgresql")
|
private val types: List<String> = listOf("postgresql", "mariadb")
|
||||||
|
|
||||||
fun register(companion: StorageFactory.StorageFactories) {
|
fun register(companion: StorageFactory.StorageFactories) {
|
||||||
types.forEach { companion.registerFactory(it, this) }
|
types.forEach { companion.registerFactory(it, this) }
|
||||||
|
|||||||
Reference in New Issue
Block a user