-
Notifications
You must be signed in to change notification settings - Fork 100
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #435 from FxRayHughes/master
[player-database]
- Loading branch information
Showing
7 changed files
with
161 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
...ion/expansion-player-database/src/main/kotlin/taboolib/expansion/ReadOnlyDataContainer.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package taboolib.expansion | ||
|
||
import taboolib.common.Inject | ||
import taboolib.common.LifeCycle | ||
import taboolib.common.platform.Awake | ||
import taboolib.common.platform.function.submitAsync | ||
|
||
// 只读数据容器 | ||
class ReadOnlyDataContainer(val user: String, val database: Database) { | ||
|
||
var source = database[user] | ||
|
||
operator fun get(key: String): String? { | ||
return source[key] | ||
} | ||
|
||
fun keys(): Set<String> { | ||
return source.keys | ||
} | ||
|
||
fun values(): Map<String, String> { | ||
return source | ||
} | ||
|
||
fun size(): Int { | ||
return source.size | ||
} | ||
|
||
override fun toString(): String { | ||
return "ReadOnlyDataContainer(user='$user', source=$source)" | ||
} | ||
|
||
fun update() { | ||
source = database[user] | ||
} | ||
|
||
|
||
@Inject | ||
internal companion object { | ||
|
||
// 延迟更新时间 | ||
var syncTick = 80L | ||
|
||
@Awake(LifeCycle.ACTIVE) | ||
private fun update() { | ||
submitAsync(period = syncTick) { | ||
playerReadOnlyDataContainer.values.forEach { | ||
runCatching { it.update() } | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters