mirror of
https://github.com/MightyPirates/OpenComputers.git
synced 2025-09-16 10:51:55 -04:00
Might fix a memory leak.
This commit is contained in:
parent
f498deba26
commit
d39ce433ed
@ -21,6 +21,7 @@ import li.cil.oc.common.tileentity.Robot
|
|||||||
import li.cil.oc.common.tileentity.traits.power
|
import li.cil.oc.common.tileentity.traits.power
|
||||||
import li.cil.oc.integration.Mods
|
import li.cil.oc.integration.Mods
|
||||||
import li.cil.oc.integration.util
|
import li.cil.oc.integration.util
|
||||||
|
import li.cil.oc.server.component.Keyboard
|
||||||
import li.cil.oc.server.{PacketSender => ServerPacketSender}
|
import li.cil.oc.server.{PacketSender => ServerPacketSender}
|
||||||
import li.cil.oc.util._
|
import li.cil.oc.util._
|
||||||
import net.minecraft.client.Minecraft
|
import net.minecraft.client.Minecraft
|
||||||
@ -34,6 +35,7 @@ import net.minecraftforge.common.util.ForgeDirection
|
|||||||
import net.minecraftforge.event.world.BlockEvent
|
import net.minecraftforge.event.world.BlockEvent
|
||||||
import net.minecraftforge.event.world.WorldEvent
|
import net.minecraftforge.event.world.WorldEvent
|
||||||
|
|
||||||
|
import scala.collection.convert.WrapAsScala._
|
||||||
import scala.collection.mutable
|
import scala.collection.mutable
|
||||||
import scala.concurrent.ExecutionContext.Implicits.global
|
import scala.concurrent.ExecutionContext.Implicits.global
|
||||||
import scala.concurrent.Future
|
import scala.concurrent.Future
|
||||||
@ -45,10 +47,14 @@ object EventHandler {
|
|||||||
|
|
||||||
private val runningRobots = mutable.Set.empty[Robot]
|
private val runningRobots = mutable.Set.empty[Robot]
|
||||||
|
|
||||||
|
private val keyboards = java.util.Collections.newSetFromMap[Keyboard](new java.util.WeakHashMap[Keyboard, java.lang.Boolean])
|
||||||
|
|
||||||
def onRobotStart(robot: Robot): Unit = runningRobots += robot
|
def onRobotStart(robot: Robot): Unit = runningRobots += robot
|
||||||
|
|
||||||
def onRobotStopped(robot: Robot): Unit = runningRobots -= robot
|
def onRobotStopped(robot: Robot): Unit = runningRobots -= robot
|
||||||
|
|
||||||
|
def addKeyboard(keyboard: Keyboard): Unit = keyboards += keyboard
|
||||||
|
|
||||||
def schedule(tileEntity: TileEntity) {
|
def schedule(tileEntity: TileEntity) {
|
||||||
if (SideTracker.isServer) pending.synchronized {
|
if (SideTracker.isServer) pending.synchronized {
|
||||||
pending += (() => Network.joinOrCreateNetwork(tileEntity))
|
pending += (() => Network.joinOrCreateNetwork(tileEntity))
|
||||||
@ -186,6 +192,21 @@ object EventHandler {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SubscribeEvent
|
||||||
|
def onPlayerRespawn(e: PlayerRespawnEvent) {
|
||||||
|
keyboards.foreach(_.releasePressedKeys(e.player))
|
||||||
|
}
|
||||||
|
|
||||||
|
@SubscribeEvent
|
||||||
|
def onPlayerChangedDimension(e: PlayerChangedDimensionEvent) {
|
||||||
|
keyboards.foreach(_.releasePressedKeys(e.player))
|
||||||
|
}
|
||||||
|
|
||||||
|
@SubscribeEvent
|
||||||
|
def onPlayerLogout(e: PlayerLoggedOutEvent) {
|
||||||
|
keyboards.foreach(_.releasePressedKeys(e.player))
|
||||||
|
}
|
||||||
|
|
||||||
lazy val drone = api.Items.get("drone")
|
lazy val drone = api.Items.get("drone")
|
||||||
lazy val eeprom = api.Items.get("eeprom")
|
lazy val eeprom = api.Items.get("eeprom")
|
||||||
lazy val mcu = api.Items.get("microcontroller")
|
lazy val mcu = api.Items.get("microcontroller")
|
||||||
|
@ -1,21 +1,14 @@
|
|||||||
package li.cil.oc.server.component
|
package li.cil.oc.server.component
|
||||||
|
|
||||||
import cpw.mods.fml.common.FMLCommonHandler
|
|
||||||
import cpw.mods.fml.common.eventhandler.SubscribeEvent
|
|
||||||
import cpw.mods.fml.common.gameevent.PlayerEvent.PlayerChangedDimensionEvent
|
|
||||||
import cpw.mods.fml.common.gameevent.PlayerEvent.PlayerLoggedOutEvent
|
|
||||||
import cpw.mods.fml.common.gameevent.PlayerEvent.PlayerRespawnEvent
|
|
||||||
import li.cil.oc.Settings
|
import li.cil.oc.Settings
|
||||||
import li.cil.oc.api
|
import li.cil.oc.api
|
||||||
import li.cil.oc.api.Network
|
import li.cil.oc.api.Network
|
||||||
import li.cil.oc.api.component.Keyboard.UsabilityChecker
|
import li.cil.oc.api.component.Keyboard.UsabilityChecker
|
||||||
import li.cil.oc.api.driver.EnvironmentHost
|
import li.cil.oc.api.driver.EnvironmentHost
|
||||||
import li.cil.oc.api.network.Message
|
import li.cil.oc.api.network.Message
|
||||||
import li.cil.oc.api.network.Node
|
|
||||||
import li.cil.oc.api.network.Visibility
|
import li.cil.oc.api.network.Visibility
|
||||||
import li.cil.oc.api.prefab
|
import li.cil.oc.api.prefab
|
||||||
import net.minecraft.entity.player.EntityPlayer
|
import net.minecraft.entity.player.EntityPlayer
|
||||||
import net.minecraftforge.event.world.WorldEvent
|
|
||||||
|
|
||||||
import scala.collection.mutable
|
import scala.collection.mutable
|
||||||
|
|
||||||
@ -35,21 +28,6 @@ class Keyboard(val host: EnvironmentHost) extends prefab.ManagedEnvironment with
|
|||||||
|
|
||||||
// ----------------------------------------------------------------------- //
|
// ----------------------------------------------------------------------- //
|
||||||
|
|
||||||
@SubscribeEvent
|
|
||||||
def onPlayerRespawn(e: PlayerRespawnEvent) {
|
|
||||||
releasePressedKeys(e.player)
|
|
||||||
}
|
|
||||||
|
|
||||||
@SubscribeEvent
|
|
||||||
def onPlayerChangedDimension(e: PlayerChangedDimensionEvent) {
|
|
||||||
releasePressedKeys(e.player)
|
|
||||||
}
|
|
||||||
|
|
||||||
@SubscribeEvent
|
|
||||||
def onPlayerLogout(e: PlayerLoggedOutEvent) {
|
|
||||||
releasePressedKeys(e.player)
|
|
||||||
}
|
|
||||||
|
|
||||||
def releasePressedKeys(player: EntityPlayer) {
|
def releasePressedKeys(player: EntityPlayer) {
|
||||||
pressedKeys.get(player) match {
|
pressedKeys.get(player) match {
|
||||||
case Some(keys) => for ((code, char) <- keys) {
|
case Some(keys) => for ((code, char) <- keys) {
|
||||||
@ -65,29 +43,8 @@ class Keyboard(val host: EnvironmentHost) extends prefab.ManagedEnvironment with
|
|||||||
pressedKeys.remove(player)
|
pressedKeys.remove(player)
|
||||||
}
|
}
|
||||||
|
|
||||||
@SubscribeEvent
|
|
||||||
def onWorldUnload(e: WorldEvent.Unload) {
|
|
||||||
try FMLCommonHandler.instance.bus.unregister(this) catch {
|
|
||||||
case ignore: Throwable =>
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// ----------------------------------------------------------------------- //
|
// ----------------------------------------------------------------------- //
|
||||||
|
|
||||||
override def onConnect(node: Node) {
|
|
||||||
if (node == this.node) {
|
|
||||||
FMLCommonHandler.instance.bus.register(this)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
override def onDisconnect(node: Node) {
|
|
||||||
if (node == this.node) {
|
|
||||||
try FMLCommonHandler.instance.bus.unregister(this) catch {
|
|
||||||
case ignore: Throwable =>
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
override def onMessage(message: Message) = {
|
override def onMessage(message: Message) = {
|
||||||
message.data match {
|
message.data match {
|
||||||
case Array(p: EntityPlayer, char: Character, code: Integer) if message.name == "keyboard.keyDown" =>
|
case Array(p: EntityPlayer, char: Character, code: Integer) if message.name == "keyboard.keyDown" =>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user