-
Notifications
You must be signed in to change notification settings - Fork 0
Feat/player hiding api #41
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
8326d93
feat: update publish.yml for microservice branch handling and release…
TheBjoRedCraft a27c562
feat: remove SNAPSHOT dependency for Redis in build configuration
TheBjoRedCraft 9faacde
feat: implement player access control for viewing and argument handling
TheBjoRedCraft 4fbda6f
Merge branch 'version/1.21.11' into feat/player-hiding-api
TheBjoRedCraft d1c66a4
Update gradle.properties
TheBjoRedCraft 3efcba1
feat: update publish.yml to remove microservice branch handling and a…
TheBjoRedCraft e3c7c01
Merge remote-tracking branch 'origin/feat/player-hiding-api' into fea…
TheBjoRedCraft File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| kotlin.code.style=official | ||
| kotlin.stdlib.default.dependency=false | ||
| org.gradle.parallel=true | ||
| version=1.21.11-2.0.0-SNAPSHOT | ||
| version=1.21.11-2.1.0-SNAPSHOT |
20 changes: 20 additions & 0 deletions
20
...urf-core-api-paper/src/main/kotlin/dev/slne/surf/core/api/paper/CorePlayerStatusAccess.kt
This file contains hidden or 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,20 @@ | ||
| package dev.slne.surf.core.api.paper | ||
|
|
||
| import dev.slne.surf.core.api.common.player.SurfPlayer | ||
| import dev.slne.surf.surfapi.core.api.util.requiredService | ||
| import org.bukkit.command.CommandSender | ||
| import org.bukkit.entity.Player | ||
|
|
||
| private val access = requiredService<CorePlayerStatusAccess>() | ||
| typealias PlayerAccessHandler = (viewer: SurfPlayer, player: SurfPlayer) -> Boolean | ||
|
|
||
| interface CorePlayerStatusAccess { | ||
| fun registerHandler(handler: PlayerAccessHandler) | ||
| fun hasAccess(viewer: Player, player: Player): Boolean | ||
| fun hasAccess(viewer: CommandSender, player: SurfPlayer): Boolean | ||
| fun hasAccess(viewer: SurfPlayer, player: SurfPlayer): Boolean | ||
|
|
||
| companion object : CorePlayerStatusAccess by access { | ||
| val INSTANCE get() = access | ||
| } | ||
| } |
This file contains hidden or 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 hidden or 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
45 changes: 45 additions & 0 deletions
45
...e-paper/src/main/kotlin/dev/slne/surf/core/paper/api/access/CorePlayerStatusAccessImpl.kt
This file contains hidden or 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,45 @@ | ||
| package dev.slne.surf.core.paper.api.access | ||
|
|
||
| import com.google.auto.service.AutoService | ||
| import dev.slne.surf.core.api.common.SurfCoreApi | ||
| import dev.slne.surf.core.api.common.player.SurfPlayer | ||
| import dev.slne.surf.core.api.paper.CorePlayerStatusAccess | ||
| import dev.slne.surf.core.api.paper.PlayerAccessHandler | ||
| import net.kyori.adventure.util.Services | ||
| import org.bukkit.command.CommandSender | ||
| import org.bukkit.entity.Player | ||
| import java.util.concurrent.ConcurrentHashMap | ||
|
|
||
| @AutoService(CorePlayerStatusAccess::class) | ||
| class CorePlayerStatusAccessImpl : CorePlayerStatusAccess, Services.Fallback { | ||
| private val _handlers = ConcurrentHashMap.newKeySet<PlayerAccessHandler>() | ||
|
|
||
| override fun registerHandler(handler: PlayerAccessHandler) { | ||
| _handlers += handler | ||
| } | ||
|
|
||
| override fun hasAccess( | ||
| viewer: Player, | ||
| player: Player | ||
| ): Boolean { | ||
| val surfViewer = SurfCoreApi.getPlayer(viewer.uniqueId) ?: return false | ||
| val surfPlayer = SurfCoreApi.getPlayer(player.uniqueId) ?: return false | ||
|
|
||
| return hasAccess(surfViewer, surfPlayer) | ||
| } | ||
|
|
||
| override fun hasAccess( | ||
| viewer: CommandSender, | ||
| player: SurfPlayer | ||
| ): Boolean { | ||
| if (viewer !is Player) return true | ||
| val surfViewer = SurfCoreApi.getPlayer(viewer.uniqueId) ?: return false | ||
|
|
||
| return hasAccess(surfViewer, player) | ||
| } | ||
|
|
||
| override fun hasAccess( | ||
| viewer: SurfPlayer, | ||
| player: SurfPlayer | ||
| ): Boolean = _handlers.all { it(viewer, player) } | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.