mirror of
https://github.com/darksaid98/Carbon.git
synced 2026-12-02 14:38:49 +00:00
Add basic player abstractions
This commit is contained in:
1 parent
28ffa3d3e9
commit
0b3245ef0c
4 files changed
+150
-2
No files matched your search
@@ -0,0 +1,39 @@
|
||||
package net.draycia.carbon.sponge.users;
|
||||
|
||||
import net.draycia.carbon.common.users.CarbonPlayerCommon;
|
||||
import net.kyori.adventure.audience.Audience;
|
||||
import net.kyori.adventure.identity.Identity;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
import org.spongepowered.api.Sponge;
|
||||
import org.spongepowered.api.entity.living.player.server.ServerPlayer;
|
||||
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
|
||||
public class CarbonPlayerSponge extends CarbonPlayerCommon {
|
||||
|
||||
public CarbonPlayerSponge(
|
||||
final @NonNull String username,
|
||||
final @NonNull Component displayName,
|
||||
final @NonNull UUID uuid
|
||||
) {
|
||||
super(username, displayName, uuid, Identity.identity(uuid));
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NonNull Audience audience() {
|
||||
final Optional<ServerPlayer> player = this.player();
|
||||
|
||||
if (player.isEmpty()) {
|
||||
return Audience.empty();
|
||||
}
|
||||
|
||||
return player.get();
|
||||
}
|
||||
|
||||
private @NonNull Optional<ServerPlayer> player() {
|
||||
return Sponge.server().player(this.uuid);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user