You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
138 lines
5.0 KiB
138 lines
5.0 KiB
package net.deliciousreya.minecraftportal
|
|
|
|
import com.destroystokyo.paper.event.block.BlockDestroyEvent
|
|
import org.bukkit.Effect
|
|
import org.bukkit.Material
|
|
import org.bukkit.Particle
|
|
import org.bukkit.Sound
|
|
import org.bukkit.block.Block
|
|
import org.bukkit.block.data.type.Door
|
|
import org.bukkit.event.EventHandler
|
|
import org.bukkit.event.Listener
|
|
import org.bukkit.event.block.*
|
|
import org.bukkit.event.entity.CreatureSpawnEvent
|
|
import org.bukkit.event.entity.EntityChangeBlockEvent
|
|
import org.bukkit.event.entity.EntityExplodeEvent
|
|
import org.bukkit.event.player.PlayerBucketFillEvent
|
|
import org.bukkit.event.player.PlayerInteractEvent
|
|
import org.bukkit.plugin.java.JavaPlugin
|
|
import org.bukkit.potion.PotionEffect
|
|
import org.bukkit.potion.PotionEffectType
|
|
|
|
class MinecraftPortalPlugin() : JavaPlugin(), Listener
|
|
{
|
|
override fun onEnable() {
|
|
super.onEnable()
|
|
logger.info("Loaded the portal plugin!")
|
|
server.pluginManager.registerEvents(this, this)
|
|
}
|
|
|
|
@EventHandler
|
|
fun onBlockPlaced(e: BlockPlaceEvent) {
|
|
if (e.block.type in PortalFrame.State.INACTIVE.allValidBlocks) {
|
|
val portalScanResults = findPortalFrameConnectedTo(e.block, PortalFrame.State.INACTIVE)
|
|
if (portalScanResults.frame != null) {
|
|
logger.info("found portal frame, creating portal")
|
|
portalScanResults.frame.color()
|
|
e.block.world.playSound(portalScanResults.frame.portalCenter, Sound.BLOCK_BEACON_ACTIVATE, 20f, 1f)
|
|
e.block.world.spawnParticle(Particle.SPELL, portalScanResults.frame.portalCenter, 40)
|
|
} else {
|
|
logger.info("no portal frame found matching placed block, ignoring")
|
|
}
|
|
}
|
|
}
|
|
|
|
@EventHandler
|
|
fun onBlockDestroy(e:BlockDestroyEvent) {
|
|
onDestroyedBlock(e.block)
|
|
}
|
|
|
|
@EventHandler
|
|
fun onEntityExplosion(e:EntityExplodeEvent) {
|
|
e.blockList().forEach(::onDestroyedBlock)
|
|
}
|
|
|
|
@EventHandler
|
|
fun onBlockExplosion(e:BlockExplodeEvent) {
|
|
onDestroyedBlock(e.block)
|
|
e.blockList().forEach(::onDestroyedBlock)
|
|
}
|
|
|
|
@EventHandler
|
|
fun onBlockBurn(e: BlockBurnEvent) {
|
|
onDestroyedBlock(e.block)
|
|
}
|
|
|
|
@EventHandler
|
|
fun onBlockFade(e: BlockFadeEvent) {
|
|
onDestroyedBlock(e.block)
|
|
}
|
|
|
|
@EventHandler
|
|
fun onSpongeAbsorb(e: SpongeAbsorbEvent) {
|
|
e.blocks.forEach { blockstate -> onDestroyedBlock(blockstate.location.block) }
|
|
}
|
|
|
|
@EventHandler
|
|
fun onBlockBreak(e:BlockBreakEvent) {
|
|
onDestroyedBlock(e.block)
|
|
}
|
|
|
|
@EventHandler
|
|
fun onEntityChangeBlock(e: EntityChangeBlockEvent) {
|
|
onDestroyedBlock(e.block)
|
|
}
|
|
|
|
@EventHandler
|
|
fun onPlayerFillBucket(e: PlayerBucketFillEvent) {
|
|
onDestroyedBlock(e.blockClicked)
|
|
}
|
|
|
|
@EventHandler
|
|
fun onPlayerInteract(e: PlayerInteractEvent) {
|
|
if (e.clickedBlock == null || e.action != Action.RIGHT_CLICK_BLOCK) {
|
|
return
|
|
}
|
|
val block = e.clickedBlock!!
|
|
if(block.type !in DOOR_TYPES) {
|
|
return
|
|
}
|
|
val portalScanResults = findPortalFrameConnectedTo(block, PortalFrame.State.ACTIVE)
|
|
if (portalScanResults.frame == null) {
|
|
return
|
|
}
|
|
val door = block.blockData as Door
|
|
|
|
if (!portalScanResults.frame.isStandingInPortal(e.player.location)) {
|
|
e.isCancelled = true
|
|
return
|
|
}
|
|
if (door.isOpen) {
|
|
// door is about to be closed, so drug the player
|
|
e.player.playSound(e.player.location, Sound.BLOCK_PORTAL_TRIGGER, 20f, 1f)
|
|
e.player.addPotionEffect(PotionEffect(PotionEffectType.CONFUSION, 200, 10, false, false, false))
|
|
e.player.addPotionEffect(PotionEffect(PotionEffectType.BLINDNESS, 200, 1, false, false, false))
|
|
e.player.addPotionEffect(PotionEffect(PotionEffectType.INVISIBILITY, 200, 1, false, false, false))
|
|
} else {
|
|
// door is about to be opened, so undrug the player
|
|
e.player.stopSound(Sound.BLOCK_PORTAL_TRIGGER)
|
|
e.player.removePotionEffect(PotionEffectType.BLINDNESS)
|
|
e.player.removePotionEffect(PotionEffectType.CONFUSION)
|
|
e.player.removePotionEffect(PotionEffectType.INVISIBILITY)
|
|
}
|
|
}
|
|
|
|
fun onDestroyedBlock(block: Block) {
|
|
if (block.type in PortalFrame.State.ACTIVE.allValidBlocks) {
|
|
val portalScanResults = findPortalFrameConnectedTo(block, PortalFrame.State.ACTIVE)
|
|
if (portalScanResults.frame != null) {
|
|
logger.info("found portal frame matching destroyed block, deactivating")
|
|
portalScanResults.frame.uncolor()
|
|
block.world.playSound(portalScanResults.frame.portalCenter, Sound.BLOCK_BEACON_DEACTIVATE, 20f, 1f)
|
|
block.world.spawnParticle(Particle.SMOKE_NORMAL, portalScanResults.frame.portalCenter, 40)
|
|
} else {
|
|
logger.info("no portal frame found matching destroyed block, ignoring")
|
|
}
|
|
}
|
|
}
|
|
} |