mirror of
https://github.com/darksaid98/Carbon.git
synced 2026-12-03 06:28:54 +00:00
temporary display names part 1
This commit is contained in:
1 parent
9b876e2e00
commit
73c1f53e1b
7 files changed
+100
-84
No files matched your search
-37
@@ -1,24 +1,15 @@
|
||||
package net.draycia.carbon.bukkit.listeners;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import java.util.Objects;
|
||||
import net.draycia.carbon.api.CarbonChat;
|
||||
import net.draycia.carbon.api.users.CarbonPlayer;
|
||||
import net.draycia.carbon.api.users.ComponentPlayerResult;
|
||||
import net.draycia.carbon.bukkit.util.BukkitCapabilities;
|
||||
import net.draycia.carbon.common.config.PrimaryConfig;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||
import net.kyori.adventure.text.minimessage.Template;
|
||||
import net.milkbowl.vault.chat.Chat;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
import org.bukkit.event.player.PlayerQuitEvent;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
|
||||
public class BukkitPlayerJoinListener implements Listener {
|
||||
|
||||
@@ -44,17 +35,6 @@ public class BukkitPlayerJoinListener implements Listener {
|
||||
|
||||
final CarbonPlayer player = result.player();
|
||||
|
||||
// Apply temporary and non temporary display names
|
||||
if (player.hasCustomDisplayName()) {
|
||||
player.displayName(player.displayName());
|
||||
} else {
|
||||
final @Nullable Component nickname = this.createDefaultNickname(player);
|
||||
|
||||
if (nickname != null) {
|
||||
player.temporaryDisplayName(nickname);
|
||||
}
|
||||
}
|
||||
|
||||
// Don't show join messages when muted
|
||||
if (this.primaryConfig.hideMutedJoinLeaveQuit() && player.muted()) {
|
||||
event.joinMessage(null);
|
||||
@@ -82,21 +62,4 @@ public class BukkitPlayerJoinListener implements Listener {
|
||||
}
|
||||
}
|
||||
|
||||
private @Nullable Component createDefaultNickname(final CarbonPlayer player) {
|
||||
// TODO: command to re-calculate and apply default nicknames
|
||||
if (BukkitCapabilities.vaultEnabled()) {
|
||||
final Chat vaultChat = Objects.requireNonNull(BukkitCapabilities.chat());
|
||||
final Player bukkitPlayer = Bukkit.getPlayer(player.uuid());
|
||||
|
||||
final @Nullable String format =
|
||||
vaultChat.getPlayerInfoString(bukkitPlayer, "autonick", null);
|
||||
|
||||
if (format != null) {
|
||||
return MiniMessage.get().parse(format, Template.of("username", player.username()));
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -17,8 +17,6 @@ import net.milkbowl.vault.permission.Permission;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.scoreboard.Scoreboard;
|
||||
import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
import org.checkerframework.framework.qual.DefaultQualifier;
|
||||
@@ -28,20 +26,11 @@ import org.jetbrains.annotations.NotNull;
|
||||
public final class CarbonPlayerBukkit extends CarbonPlayerCommon implements ForwardingAudience.Single {
|
||||
|
||||
private final CarbonPlayer carbonPlayer;
|
||||
private @MonotonicNonNull Scoreboard scoreboard = null;
|
||||
|
||||
public CarbonPlayerBukkit(final CarbonPlayer carbonPlayer) {
|
||||
this.carbonPlayer = carbonPlayer;
|
||||
}
|
||||
|
||||
private @NonNull Scoreboard scoreboard() {
|
||||
if (this.scoreboard == null) {
|
||||
this.scoreboard = Bukkit.getScoreboardManager().getNewScoreboard();
|
||||
}
|
||||
|
||||
return this.scoreboard;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void displayName(final @Nullable Component displayName) {
|
||||
this.carbonPlayer.displayName(displayName);
|
||||
@@ -49,6 +38,7 @@ public final class CarbonPlayerBukkit extends CarbonPlayerCommon implements Forw
|
||||
final @Nullable Player player = this.player();
|
||||
|
||||
if (player != null) {
|
||||
// TODO: don't run this block when the player has a temporary display name already set
|
||||
// Update player's name in chat
|
||||
player.displayName(displayName);
|
||||
|
||||
@@ -58,8 +48,8 @@ public final class CarbonPlayerBukkit extends CarbonPlayerCommon implements Forw
|
||||
}
|
||||
|
||||
@Override
|
||||
public void temporaryDisplayName(final @Nullable Component displayName) {
|
||||
this.carbonPlayer.temporaryDisplayName(displayName);
|
||||
public void temporaryDisplayName(final @Nullable Component displayName, final long expirationEpoch) {
|
||||
this.carbonPlayer.temporaryDisplayName(displayName, expirationEpoch);
|
||||
|
||||
final @Nullable Player player = this.player();
|
||||
|
||||
@@ -69,6 +59,8 @@ public final class CarbonPlayerBukkit extends CarbonPlayerCommon implements Forw
|
||||
|
||||
// Update player's name in the tab player list
|
||||
player.playerListName(displayName);
|
||||
|
||||
// TODO: schedule task to unset temporary display name when it expires
|
||||
}
|
||||
}
|
||||
|
||||
@@ -84,17 +76,6 @@ public final class CarbonPlayerBukkit extends CarbonPlayerCommon implements Forw
|
||||
|
||||
@Override
|
||||
public @Nullable Component displayName() {
|
||||
// if (this.carbonPlayer.displayName() != null) {
|
||||
// return this.carbonPlayer.displayName();
|
||||
// }
|
||||
|
||||
// final @Nullable Player player = this.player();
|
||||
//
|
||||
// if (player != null) {
|
||||
// return player.displayName();
|
||||
// }
|
||||
|
||||
// return null;
|
||||
return this.carbonPlayer.displayName();
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user