mirror of
https://github.com/MightyPirates/OpenComputers.git
synced 2025-09-17 11:15:12 -04:00
Avoiding potential race condition in tablets. I think.
This commit is contained in:
parent
7464e38302
commit
82ec88fadb
@ -231,24 +231,23 @@ object Tablet extends Callable[TabletWrapper] with RemovalListener[String, Table
|
|||||||
|
|
||||||
private var currentHolder: Entity = _
|
private var currentHolder: Entity = _
|
||||||
|
|
||||||
def get(stack: ItemStack, holder: Entity) = (if (holder.worldObj.isRemote) clientCache else serverCache).synchronized {
|
def get(stack: ItemStack, holder: Entity) = {
|
||||||
currentStack = stack
|
val cache = if (holder.worldObj.isRemote) clientCache else serverCache
|
||||||
currentHolder = holder
|
cache.synchronized {
|
||||||
if (!stack.hasTagCompound) {
|
currentStack = stack
|
||||||
stack.setTagCompound(new NBTTagCompound("tag"))
|
currentHolder = holder
|
||||||
|
if (!stack.hasTagCompound) {
|
||||||
|
stack.setTagCompound(new NBTTagCompound("tag"))
|
||||||
|
}
|
||||||
|
if (!stack.getTagCompound.hasKey(Settings.namespace + "tablet")) {
|
||||||
|
stack.getTagCompound.setString(Settings.namespace + "tablet", UUID.randomUUID().toString)
|
||||||
|
}
|
||||||
|
val id = stack.getTagCompound.getString(Settings.namespace + "tablet")
|
||||||
|
val wrapper = cache.get(id, this)
|
||||||
|
wrapper.stack = stack
|
||||||
|
wrapper.holder = holder
|
||||||
|
wrapper
|
||||||
}
|
}
|
||||||
if (!stack.getTagCompound.hasKey(Settings.namespace + "tablet")) {
|
|
||||||
stack.getTagCompound.setString(Settings.namespace + "tablet", UUID.randomUUID().toString)
|
|
||||||
}
|
|
||||||
val id = stack.getTagCompound.getString(Settings.namespace + "tablet")
|
|
||||||
val wrapper =
|
|
||||||
if (holder.worldObj.isRemote)
|
|
||||||
clientCache.get(id, this)
|
|
||||||
else
|
|
||||||
serverCache.get(id, this)
|
|
||||||
wrapper.stack = stack
|
|
||||||
wrapper.holder = holder
|
|
||||||
wrapper
|
|
||||||
}
|
}
|
||||||
|
|
||||||
def call = {
|
def call = {
|
||||||
@ -267,10 +266,14 @@ object Tablet extends Callable[TabletWrapper] with RemovalListener[String, Table
|
|||||||
|
|
||||||
@ForgeSubscribe
|
@ForgeSubscribe
|
||||||
def onWorldUnload(e: WorldEvent.Unload) {
|
def onWorldUnload(e: WorldEvent.Unload) {
|
||||||
clientCache.invalidateAll()
|
clientCache.synchronized {
|
||||||
clientCache.cleanUp()
|
clientCache.invalidateAll()
|
||||||
serverCache.invalidateAll()
|
clientCache.cleanUp()
|
||||||
serverCache.cleanUp()
|
}
|
||||||
|
serverCache.synchronized {
|
||||||
|
serverCache.invalidateAll()
|
||||||
|
serverCache.cleanUp()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override def getLabel = "OpenComputers Tablet Cleanup Ticker"
|
override def getLabel = "OpenComputers Tablet Cleanup Ticker"
|
||||||
@ -278,8 +281,8 @@ object Tablet extends Callable[TabletWrapper] with RemovalListener[String, Table
|
|||||||
override def ticks = util.EnumSet.of(TickType.CLIENT, TickType.SERVER)
|
override def ticks = util.EnumSet.of(TickType.CLIENT, TickType.SERVER)
|
||||||
|
|
||||||
override def tickStart(tickType: util.EnumSet[TickType], tickData: AnyRef*) {
|
override def tickStart(tickType: util.EnumSet[TickType], tickData: AnyRef*) {
|
||||||
clientCache.cleanUp()
|
clientCache.synchronized(clientCache.cleanUp())
|
||||||
serverCache.cleanUp()
|
serverCache.synchronized(serverCache.cleanUp())
|
||||||
}
|
}
|
||||||
|
|
||||||
override def tickEnd(tickType: util.EnumSet[TickType], tickData: AnyRef*) {}
|
override def tickEnd(tickType: util.EnumSet[TickType], tickData: AnyRef*) {}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user