Add listener for BlockFormEvent
This commit is contained in:
@@ -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.
|
||||||
*/
|
*/
|
||||||
|
|||||||
Reference in New Issue
Block a user