parent
2ae528fc98
commit
8dbd61c1ef
@ -1,7 +1,3 @@ |
||||
* teleport from one to the other a set time after entering a teleportation chamber and closing the door |
||||
* automatically open the door after effects wear off |
||||
* teleport everyone inside the portal, not just the person who closed the door |
||||
* interrupt teleportation if portal is destroyed mid-teleportation, or if a new portal is constructed during teleportation, changing the destination |
||||
* cancel teleportation if someone moves out of the teleporter during teleportation (maybe prevent them from starting?) |
||||
* save any effects that would be overwritten by teleportation (including to disk!), and put them back when the player opens the door or arrives |
||||
* add portal particles and ambient sounds to the teleporter when portals are paired |
||||
* fix facing and location when teleporting in different directions |
@ -0,0 +1,118 @@ |
||||
package net.deliciousreya.minecraftportal.model |
||||
|
||||
import net.deliciousreya.minecraftportal.proto.PortalSaveDataProtos |
||||
import org.bukkit.Location |
||||
import org.bukkit.entity.Entity |
||||
import org.bukkit.entity.LivingEntity |
||||
import org.bukkit.plugin.Plugin |
||||
import org.bukkit.potion.PotionEffect |
||||
import org.bukkit.potion.PotionEffectType |
||||
import org.bukkit.scheduler.BukkitRunnable |
||||
|
||||
class Teleportation(val portalType: PortalType, val plugin: Plugin) { |
||||
val leftEntities = LinkedHashSet<Entity>() |
||||
val rightEntities = LinkedHashSet<Entity>() |
||||
val allEntities = LinkedHashSet<Entity>() |
||||
var currentTask: BukkitRunnable? = null |
||||
var sparklesTask: DoSparkles? = null |
||||
val leftPortal = portalType.newestActivePortal!! |
||||
val rightPortal = portalType.oldestActivePortal!! |
||||
|
||||
fun cancelFor(entity: Entity) { |
||||
leftEntities.remove(entity) |
||||
rightEntities.remove(entity) |
||||
allEntities.remove(entity) |
||||
if (allEntities.isEmpty()) { |
||||
cancelTeleportation() |
||||
} |
||||
} |
||||
|
||||
fun cancelEffectsOn(entity: Entity) { |
||||
if (entity is LivingEntity) { |
||||
entity.removePotionEffect(PotionEffectType.BLINDNESS) |
||||
entity.removePotionEffect(PotionEffectType.CONFUSION) |
||||
} |
||||
} |
||||
|
||||
fun cancelTeleportation() { |
||||
leftPortal.frame.open() |
||||
rightPortal.frame.open() |
||||
leftPortal.frame.playTeleportCanceledEffect() |
||||
rightPortal.frame.playTeleportCanceledEffect() |
||||
cancelEffectsOnAll() |
||||
leftEntities.clear() |
||||
rightEntities.clear() |
||||
allEntities.clear() |
||||
currentTask?.cancel() |
||||
currentTask = null |
||||
sparklesTask?.cancel() |
||||
sparklesTask = null |
||||
} |
||||
|
||||
fun cancelEffectsOnAll() { |
||||
for (entity in allEntities) { |
||||
cancelEffectsOn(entity) |
||||
} |
||||
} |
||||
|
||||
fun start() { |
||||
leftEntities.addAll(leftPortal.frame.getEntities()) |
||||
rightEntities.addAll(rightPortal.frame.getEntities()) |
||||
allEntities.addAll(leftEntities) |
||||
allEntities.addAll(rightEntities) |
||||
for (entity in allEntities) { |
||||
if (entity is LivingEntity) { |
||||
entity.addPotionEffect(PotionEffect(PotionEffectType.CONFUSION, 200, 1, false, false, false)) |
||||
entity.addPotionEffect(PotionEffect(PotionEffectType.BLINDNESS, 200, 1, false, false, false)) |
||||
} |
||||
} |
||||
leftPortal.frame.close() |
||||
rightPortal.frame.close() |
||||
leftPortal.frame.playTeleporterActivatedEffect() |
||||
rightPortal.frame.playTeleporterActivatedEffect() |
||||
val task = DoTeleport() |
||||
task.runTaskLater(plugin, 100) |
||||
currentTask = task |
||||
val sparkles = DoSparkles() |
||||
sparkles.runTaskTimer(plugin, 10, 15) |
||||
sparklesTask = sparkles |
||||
} |
||||
|
||||
inner class DoSparkles : BukkitRunnable() { |
||||
override fun run() { |
||||
leftPortal.frame.playTeleporterActiveEffect() |
||||
rightPortal.frame.playTeleporterActiveEffect() |
||||
} |
||||
} |
||||
|
||||
inner class DoTeleport : BukkitRunnable() { |
||||
override fun run() { |
||||
for(leftEntity in leftEntities) { |
||||
val relativeLocation = leftPortal.frame.getRelativeLocationFromAbsoluteLocation(leftEntity.location) |
||||
val destination = rightPortal.frame.getAbsoluteLocationFromRelativeLocation(relativeLocation) |
||||
leftEntity.teleport(destination) |
||||
} |
||||
for(rightEntity in rightEntities) { |
||||
val relativeLocation = rightPortal.frame.getRelativeLocationFromAbsoluteLocation(rightEntity.location) |
||||
val destination = leftPortal.frame.getAbsoluteLocationFromRelativeLocation(relativeLocation) |
||||
rightEntity.teleport(destination) |
||||
} |
||||
leftPortal.frame.playTeleportTravelEffect() |
||||
rightPortal.frame.playTeleportTravelEffect() |
||||
val task = OpenDoors() |
||||
task.runTaskLater(plugin, 100) |
||||
currentTask = task |
||||
} |
||||
} |
||||
|
||||
inner class OpenDoors: BukkitRunnable() { |
||||
override fun run() { |
||||
leftPortal.frame.open() |
||||
rightPortal.frame.open() |
||||
cancelEffectsOnAll() |
||||
currentTask = null |
||||
sparklesTask?.cancel() |
||||
sparklesTask = null |
||||
} |
||||
} |
||||
} |
Loading…
Reference in new issue