-
-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Add OfflinePlayer#ifOnline #10197
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
Closed
Closed
Add OfflinePlayer#ifOnline #10197
Changes from all commits
Commits
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 | ||
| From: leguan <longboard.noah@gmail.com> | ||
| Date: Sun, 28 Jan 2024 19:05:33 +0100 | ||
| Subject: [PATCH] Add OfflinePlayer#ifOnline | ||
|
|
||
|
|
||
| diff --git a/src/main/java/org/bukkit/OfflinePlayer.java b/src/main/java/org/bukkit/OfflinePlayer.java | ||
| index abb5109ed08a3a651c2c27d4d17a3d49eb06da1e..2b7a49e595bf42a0bf80e0715f3912467b2d3eb6 100644 | ||
| --- a/src/main/java/org/bukkit/OfflinePlayer.java | ||
| +++ b/src/main/java/org/bukkit/OfflinePlayer.java | ||
| @@ -545,4 +545,12 @@ public interface OfflinePlayer extends ServerOperator, AnimalTamer, Configuratio | ||
| */ | ||
| @Nullable | ||
| public Location getLocation(); | ||
| + | ||
| + // Paper start - Add OfflinePlayer#ifOnline | ||
| + /** | ||
| + * Runs the provided consumer if the player is online. | ||
| + * @param consumer the consumer that has to be run. | ||
| + */ | ||
| + void ifOnline(java.util.function.@NotNull Consumer<Player> consumer); | ||
| + // Paper end - Add OfflinePlayer#ifOnline | ||
| } |
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,46 @@ | ||
| From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 | ||
| From: leguan <longboard.noah@gmail.com> | ||
| Date: Sun, 28 Jan 2024 19:39:01 +0100 | ||
| Subject: [PATCH] Add OfflinePlayer#ifOnline | ||
|
|
||
|
|
||
| diff --git a/src/main/java/org/bukkit/craftbukkit/CraftOfflinePlayer.java b/src/main/java/org/bukkit/craftbukkit/CraftOfflinePlayer.java | ||
| index 4a875bce9563f3b9351ebecde9b0eb1287beb50e..a5ce3a727271b6808fefa4c61989c6e949ecdd5f 100644 | ||
| --- a/src/main/java/org/bukkit/craftbukkit/CraftOfflinePlayer.java | ||
| +++ b/src/main/java/org/bukkit/craftbukkit/CraftOfflinePlayer.java | ||
| @@ -358,6 +358,15 @@ public class CraftOfflinePlayer implements OfflinePlayer, ConfigurationSerializa | ||
| return null; | ||
| } | ||
|
|
||
| + // Paper start - Add OfflinePlayer#ifOnline | ||
| + @Override | ||
| + public void ifOnline(final java.util.function.@org.jetbrains.annotations.NotNull Consumer<Player> consumer) { | ||
| + if (this.isOnline()) { | ||
| + consumer.accept(this.getPlayer()); | ||
| + } | ||
| + } | ||
| + // Paper end - Add OfflinePlayer#ifOnline | ||
| + | ||
| @Override | ||
| public Location getBedSpawnLocation() { | ||
| return this.getRespawnLocation(); | ||
| diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java | ||
| index 39b25c2478eadd373383a3445a7f27ea30d18550..79e6e82fa0c56189f578ba7fd320e056bde481e3 100644 | ||
| --- a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java | ||
| +++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java | ||
| @@ -1576,6 +1576,15 @@ public class CraftPlayer extends CraftHumanEntity implements Player { | ||
| CraftStatistic.setStatistic(this.getHandle().getStats(), statistic, entityType, newValue, this.getHandle()); | ||
| } | ||
|
|
||
| + // Paper start - Add OfflinePlayer#ifOnline | ||
| + @Override | ||
| + public void ifOnline(final java.util.function.@org.jetbrains.annotations.NotNull Consumer<Player> consumer) { | ||
| + if (this.isOnline()) { | ||
| + consumer.accept(this.getPlayer()); | ||
| + } | ||
| + } | ||
| + // Paper end - Add OfflinePlayer#ifOnline | ||
| + | ||
| @Override | ||
| public void setPlayerTime(long time, boolean relative) { | ||
| this.getHandle().timeOffset = time; | ||
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could save some resource by caching
getPlayerinto a variable asisOnlineinvokesgetPlayerand performs a not-null condition.and do the same in
CraftPlayerThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good point.