This repository has been archived by the owner on Dec 21, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 32
Add PlayerProfile support to PaperLib #4
Closed
Closed
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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 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
11 changes: 11 additions & 0 deletions
11
src/main/java/io/papermc/lib/features/profilesupport/ProfileSupport.java
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,11 @@ | ||
package io.papermc.lib.features.profilesupport; | ||
|
||
import java.io.IOException; | ||
import java.util.UUID; | ||
import java.util.concurrent.CompletableFuture; | ||
|
||
public interface ProfileSupport { | ||
CompletableFuture<UUID> getPlayerUUID(String playerName) throws IOException; | ||
|
||
CompletableFuture<String> getPlayerName(UUID playerUUID) throws IOException; | ||
} |
34 changes: 34 additions & 0 deletions
34
src/main/java/io/papermc/lib/features/profilesupport/ProfileSupportPaper.java
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,34 @@ | ||
package io.papermc.lib.features.profilesupport; | ||
|
||
import com.destroystokyo.paper.profile.PlayerProfile; | ||
import org.bukkit.Bukkit; | ||
|
||
import java.io.IOException; | ||
import java.util.UUID; | ||
import java.util.concurrent.CompletableFuture; | ||
|
||
public class ProfileSupportPaper implements ProfileSupport { | ||
public CompletableFuture<UUID> getPlayerUUID(String playerName) throws IOException { | ||
PlayerProfile profile = Bukkit.createProfile(playerName); | ||
if (profile.isComplete() || profile.completeFromCache()) { | ||
return CompletableFuture.completedFuture(profile.getId()); | ||
} | ||
|
||
return CompletableFuture.supplyAsync(() -> { | ||
profile.complete(false); | ||
return profile.getId(); | ||
}); | ||
} | ||
|
||
public CompletableFuture<String> getPlayerName(UUID playerUUID) throws IOException { | ||
PlayerProfile profile = Bukkit.createProfile(playerUUID); | ||
if (profile.isComplete() || profile.completeFromCache()) { | ||
return CompletableFuture.completedFuture(profile.getName()); | ||
} | ||
|
||
return CompletableFuture.supplyAsync(() -> { | ||
profile.complete(false); | ||
return profile.getName(); | ||
}); | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
src/main/java/io/papermc/lib/features/profilesupport/ProfileSupportUnknown.java
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,17 @@ | ||
package io.papermc.lib.features.profilesupport; | ||
|
||
import org.bukkit.Bukkit; | ||
|
||
import java.io.IOException; | ||
import java.util.UUID; | ||
import java.util.concurrent.CompletableFuture; | ||
|
||
public class ProfileSupportUnknown implements ProfileSupport { | ||
public CompletableFuture<UUID> getPlayerUUID(String playerName) throws IOException { | ||
return CompletableFuture.completedFuture(Bukkit.getOfflinePlayer(playerName).getUniqueId()); | ||
} | ||
|
||
public CompletableFuture<String> getPlayerName(UUID playerUUID) throws IOException { | ||
return CompletableFuture.completedFuture(Bukkit.getOfflinePlayer(playerUUID).getName()); | ||
} | ||
} |
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.
These API's weren't added to be async. They were added to more efficiently look up a players UUID than loading the entire offline player.
Nothing would prevent you loading the offline player async too, but I'm not sure this lib needs to handle that.
Lets just drop the async and keep them sync, and plugins can call the method async themselves.
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.
Hmm, fair. I guess I was just kinda going based off the current naming scheme. Though you can totally load them async it's not necessarily a requirement.
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.
You only changed the name. Need to remove the futures themselves and the async part too.