-
-
Notifications
You must be signed in to change notification settings - Fork 39
feat: player abilities APIs #843
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 2 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
70ad58b
feat: player abilities APIs
zernix2077 a86bc3b
feat: remove PlayerAbility.OPERATOR_COMMAND and PlayerAbility.TELEPOR…
zernix2077 fa18f93
feat: better Player ability methods naming
zernix2077 e8493da
feat: PlayerAbility.NO_BLOCK_CONSUMPTION
zernix2077 60d9f05
feat: remove ability setters
zernix2077 6a6ce08
feat: rename NO_BLOCK_CONSUMPTION to INFINITE_BLOCK
zernix2077 671a96e
fix: ensure flying state sync on abilities update
zernix2077 1c9ae04
Merge remote-tracking branch 'origin/master' into ability-refactor
zernix2077 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
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
35 changes: 35 additions & 0 deletions
35
api/src/main/java/org/allaymc/api/eventbus/event/server/PlayerAbilitiesUpdateEvent.java
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,35 @@ | ||
| package org.allaymc.api.eventbus.event.server; | ||
|
|
||
| import lombok.Getter; | ||
| import org.allaymc.api.annotation.CallerThread; | ||
| import org.allaymc.api.annotation.ThreadType; | ||
| import org.allaymc.api.player.Player; | ||
| import org.allaymc.api.player.PlayerAbility; | ||
|
|
||
| import java.util.Collections; | ||
| import java.util.EnumSet; | ||
| import java.util.Set; | ||
|
|
||
| /** | ||
| * Called after a player's abilities are changed. | ||
| * | ||
| * @author zernix2077 | ||
| */ | ||
| @Getter | ||
| @CallerThread(ThreadType.WORLD) | ||
| public class PlayerAbilitiesUpdateEvent extends ServerPlayerEvent { | ||
| protected final Set<PlayerAbility> previous; | ||
| protected final Set<PlayerAbility> current; | ||
|
|
||
| public PlayerAbilitiesUpdateEvent(Player player, Set<PlayerAbility> previous, Set<PlayerAbility> current) { | ||
| super(player); | ||
| this.previous = copyAbilities(previous); | ||
| this.current = copyAbilities(current); | ||
| } | ||
|
|
||
| protected static Set<PlayerAbility> copyAbilities(Set<PlayerAbility> abilities) { | ||
| return abilities.isEmpty() | ||
| ? Collections.unmodifiableSet(EnumSet.noneOf(PlayerAbility.class)) | ||
| : Collections.unmodifiableSet(EnumSet.copyOf(abilities)); | ||
| } | ||
| } |
32 changes: 32 additions & 0 deletions
32
...rc/main/java/org/allaymc/api/eventbus/event/server/PlayerAbilitiesUpdateRequestEvent.java
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,32 @@ | ||
| package org.allaymc.api.eventbus.event.server; | ||
|
|
||
| import lombok.Getter; | ||
| import org.allaymc.api.annotation.CallerThread; | ||
| import org.allaymc.api.annotation.ThreadType; | ||
| import org.allaymc.api.eventbus.event.CancellableEvent; | ||
| import org.allaymc.api.player.Player; | ||
| import org.allaymc.api.player.PlayerAbility; | ||
|
|
||
| import java.util.Collections; | ||
| import java.util.EnumSet; | ||
| import java.util.Set; | ||
|
|
||
| /** | ||
| * Called before an operator's requested ability update is applied to another player. | ||
| * | ||
| * @author zernix2077 | ||
| */ | ||
| @Getter | ||
| @CallerThread(ThreadType.WORLD) | ||
| public class PlayerAbilitiesUpdateRequestEvent extends ServerPlayerEvent implements CancellableEvent { | ||
| protected final Player target; | ||
| protected final Set<PlayerAbility> abilities; | ||
|
|
||
| public PlayerAbilitiesUpdateRequestEvent(Player player, Player target, Set<PlayerAbility> abilities) { | ||
| super(player); | ||
| this.target = target; | ||
| this.abilities = abilities.isEmpty() | ||
| ? Collections.unmodifiableSet(EnumSet.noneOf(PlayerAbility.class)) | ||
| : Collections.unmodifiableSet(EnumSet.copyOf(abilities)); | ||
| } | ||
| } |
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
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
Oops, something went wrong.
Oops, something went wrong.
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.