Archived
0

Add listener for BlockFormEvent

This commit is contained in:
Dico Karssiens
2018-07-30 16:02:23 +01:00
parent 72482a3547
commit 195b8db225
3 changed files with 39 additions and 1 deletions

View File

@@ -34,6 +34,8 @@ class Options {
data class WorldOptions(var gameMode: GameMode? = GameMode.CREATIVE,
var dayTime: Boolean = true,
var noWeather: Boolean = true,
var preventWeatherBlockChanges: Boolean = true,
var preventBlockSpread: Boolean = true, // TODO
var dropEntityItems: Boolean = true,
var doTileDrops: Boolean = false,
var disableExplosions: Boolean = true,

View File

@@ -77,13 +77,15 @@ class ParcelsPlugin : JavaPlugin() {
if (optionsFile.exists()) {
yamlObjectMapper.readerForUpdating(options).readValue<Options>(optionsFile)
} else if (optionsFile.tryCreate()) {
options.addWorld("plotworld", WorldOptions())
options.addWorld("parcels", WorldOptions())
try {
yamlObjectMapper.writeValue(optionsFile, options)
} catch (ex: Throwable) {
optionsFile.delete()
throw ex
}
plogger.warn("Created options file with a world template. Please review it before next start.")
return false
} else {
plogger.error("Failed to save options file ${optionsFile.canonicalPath}")
return false

View File

@@ -376,6 +376,40 @@ class ParcelListeners(val worlds: Worlds, val entityTracker: ParcelEntityTracker
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.
*/