Change around profile methods on players

This commit is contained in:
Vankka 2022-03-04 13:29:21 +02:00
parent da882301bc
commit 54db798e9a
No known key found for this signature in database
GPG Key ID: 6E50CB7A29B96AD0
6 changed files with 26 additions and 25 deletions

View File

@ -19,8 +19,8 @@
package com.discordsrv.bukkit.player; package com.discordsrv.bukkit.player;
import com.discordsrv.bukkit.BukkitDiscordSRV; import com.discordsrv.bukkit.BukkitDiscordSRV;
import com.discordsrv.common.DiscordSRV;
import com.discordsrv.common.player.IOfflinePlayer; import com.discordsrv.common.player.IOfflinePlayer;
import com.discordsrv.common.profile.Profile;
import net.kyori.adventure.identity.Identity; import net.kyori.adventure.identity.Identity;
import org.bukkit.OfflinePlayer; import org.bukkit.OfflinePlayer;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
@ -37,17 +37,17 @@ public class BukkitOfflinePlayer implements IOfflinePlayer {
this.identity = Identity.identity(offlinePlayer.getUniqueId()); this.identity = Identity.identity(offlinePlayer.getUniqueId());
} }
@Override
public DiscordSRV discordSRV() {
return discordSRV;
}
@SuppressWarnings("NullabilityProblems") @SuppressWarnings("NullabilityProblems")
@Override @Override
public String username() { public String username() {
return offlinePlayer.getName(); return offlinePlayer.getName();
} }
@Override
public Profile profile() {
return discordSRV.profileManager().getProfile(uniqueId()).orElseThrow(IllegalStateException::new);
}
@Override @Override
public @NotNull Identity identity() { public @NotNull Identity identity() {
return identity; return identity;

View File

@ -22,7 +22,6 @@ import com.discordsrv.bungee.BungeeDiscordSRV;
import com.discordsrv.bungee.component.util.BungeeComponentUtil; import com.discordsrv.bungee.component.util.BungeeComponentUtil;
import com.discordsrv.common.DiscordSRV; import com.discordsrv.common.DiscordSRV;
import com.discordsrv.common.player.IPlayer; import com.discordsrv.common.player.IPlayer;
import com.discordsrv.common.profile.Profile;
import net.kyori.adventure.audience.Audience; import net.kyori.adventure.audience.Audience;
import net.kyori.adventure.identity.Identity; import net.kyori.adventure.identity.Identity;
import net.kyori.adventure.text.Component; import net.kyori.adventure.text.Component;
@ -63,11 +62,6 @@ public class BungeePlayer implements IPlayer {
return player.getName(); return player.getName();
} }
@Override
public Profile profile() {
return discordSRV.profileManager().getProfile(uniqueId()).orElseThrow(IllegalStateException::new);
}
@Override @Override
public @NotNull Identity identity() { public @NotNull Identity identity() {
return identity; return identity;

View File

@ -19,6 +19,7 @@
package com.discordsrv.common.player; package com.discordsrv.common.player;
import com.discordsrv.api.placeholder.annotation.Placeholder; import com.discordsrv.api.placeholder.annotation.Placeholder;
import com.discordsrv.common.DiscordSRV;
import com.discordsrv.common.profile.Profile; import com.discordsrv.common.profile.Profile;
import net.kyori.adventure.identity.Identified; import net.kyori.adventure.identity.Identified;
import org.jetbrains.annotations.ApiStatus; import org.jetbrains.annotations.ApiStatus;
@ -26,9 +27,17 @@ import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
import java.util.UUID; import java.util.UUID;
import java.util.concurrent.CompletableFuture;
public interface IOfflinePlayer extends Identified { public interface IOfflinePlayer extends Identified {
DiscordSRV discordSRV();
@ApiStatus.NonExtendable
default CompletableFuture<Profile> lookupProfile() {
return discordSRV().profileManager().lookupProfile(uniqueId());
}
@Placeholder("player_name") @Placeholder("player_name")
@Nullable @Nullable
String username(); String username();
@ -39,6 +48,4 @@ public interface IOfflinePlayer extends Identified {
default UUID uniqueId() { default UUID uniqueId() {
return identity().uuid(); return identity().uuid();
} }
Profile profile();
} }

View File

@ -25,6 +25,7 @@ import com.discordsrv.common.DiscordSRV;
import com.discordsrv.common.command.game.sender.ICommandSender; import com.discordsrv.common.command.game.sender.ICommandSender;
import com.discordsrv.common.config.main.channels.base.BaseChannelConfig; import com.discordsrv.common.config.main.channels.base.BaseChannelConfig;
import com.discordsrv.common.function.OrDefault; import com.discordsrv.common.function.OrDefault;
import com.discordsrv.common.profile.Profile;
import net.kyori.adventure.text.Component; import net.kyori.adventure.text.Component;
import org.jetbrains.annotations.ApiStatus; import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
@ -36,6 +37,11 @@ public interface IPlayer extends DiscordSRVPlayer, IOfflinePlayer, ICommandSende
DiscordSRV discordSRV(); DiscordSRV discordSRV();
@ApiStatus.NonExtendable
default Profile profile() {
return discordSRV().profileManager().getProfile(uniqueId()).orElseThrow(IllegalStateException::new);
}
@NotNull @NotNull
String username(); String username();

View File

@ -18,8 +18,8 @@
package com.discordsrv.sponge.player; package com.discordsrv.sponge.player;
import com.discordsrv.common.DiscordSRV;
import com.discordsrv.common.player.IOfflinePlayer; import com.discordsrv.common.player.IOfflinePlayer;
import com.discordsrv.common.profile.Profile;
import com.discordsrv.sponge.SpongeDiscordSRV; import com.discordsrv.sponge.SpongeDiscordSRV;
import net.kyori.adventure.identity.Identity; import net.kyori.adventure.identity.Identity;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
@ -36,13 +36,13 @@ public class SpongeOfflinePlayer implements IOfflinePlayer {
} }
@Override @Override
public @NotNull String username() { public DiscordSRV discordSRV() {
return user.name(); return discordSRV;
} }
@Override @Override
public Profile profile() { public @NotNull String username() {
return discordSRV.profileManager().getProfile(uniqueId()).orElseThrow(IllegalStateException::new); return user.name();
} }
@Override @Override

View File

@ -20,7 +20,6 @@ package com.discordsrv.velocity.player;
import com.discordsrv.common.DiscordSRV; import com.discordsrv.common.DiscordSRV;
import com.discordsrv.common.player.IPlayer; import com.discordsrv.common.player.IPlayer;
import com.discordsrv.common.profile.Profile;
import com.discordsrv.velocity.VelocityDiscordSRV; import com.discordsrv.velocity.VelocityDiscordSRV;
import com.velocitypowered.api.proxy.Player; import com.velocitypowered.api.proxy.Player;
import net.kyori.adventure.audience.Audience; import net.kyori.adventure.audience.Audience;
@ -58,11 +57,6 @@ public class VelocityPlayer implements IPlayer {
return player.getUsername(); return player.getUsername();
} }
@Override
public Profile profile() {
return discordSRV.profileManager().getProfile(uniqueId()).orElseThrow(IllegalStateException::new);
}
@Override @Override
public @NotNull Identity identity() { public @NotNull Identity identity() {
return player.identity(); return player.identity();