Added IOffPlayer#getPlayerStatus() + added warning color in Chat class
This commit is contained in:
parent
54ffb4eddd
commit
e50bf0ee39
@ -103,6 +103,7 @@ public abstract sealed class Chat extends ChatStatic implements HoverEventSource
|
||||
|
||||
public Chat thenText(Object plainText) { return then(text(plainText)); }
|
||||
public Chat thenInfo(Object plainText) { return then(infoText(plainText)); }
|
||||
public Chat thenWarning(Object plainText) { return then(warningText(plainText)); }
|
||||
public Chat thenSuccess(Object plainText) { return then(successText(plainText)); }
|
||||
public Chat thenFailure(Object plainText) { return then(failureText(plainText)); }
|
||||
public Chat thenData(Object plainText) { return then(dataText(plainText)); }
|
||||
@ -242,6 +243,7 @@ public abstract sealed class Chat extends ChatStatic implements HoverEventSource
|
||||
public FormatableChat successColor() { return color(config.successColor); }
|
||||
public FormatableChat failureColor() { return color(config.failureColor); }
|
||||
public FormatableChat infoColor() { return color(config.infoColor); }
|
||||
public FormatableChat warningColor() { return color(config.warningColor); }
|
||||
public FormatableChat dataColor() { return color(config.dataColor); }
|
||||
public FormatableChat decorationColor() { return color(config.decorationColor); }
|
||||
public FormatableChat urlColor() { return color(config.urlColor); }
|
||||
@ -450,6 +452,7 @@ public abstract sealed class Chat extends ChatStatic implements HoverEventSource
|
||||
public TextColor successColor = NamedTextColor.GREEN;
|
||||
public TextColor failureColor = NamedTextColor.RED;
|
||||
public TextColor infoColor = NamedTextColor.GOLD;
|
||||
public TextColor warningColor = NamedTextColor.GOLD;
|
||||
public TextColor dataColor = NamedTextColor.GRAY;
|
||||
public TextColor urlColor = NamedTextColor.GREEN;
|
||||
public TextColor commandColor = NamedTextColor.GRAY;
|
||||
|
@ -61,6 +61,10 @@ public abstract class ChatStatic {
|
||||
return text(plainText).infoColor();
|
||||
}
|
||||
|
||||
public static FormatableChat warningText(Object plainText) {
|
||||
return text(plainText).warningColor();
|
||||
}
|
||||
|
||||
public static FormatableChat dataText(Object plainText) {
|
||||
return text(plainText).dataColor();
|
||||
}
|
||||
|
@ -1,10 +1,16 @@
|
||||
package fr.pandacube.lib.core.players;
|
||||
|
||||
import static fr.pandacube.lib.core.chat.ChatStatic.dataText;
|
||||
import static fr.pandacube.lib.core.chat.ChatStatic.successText;
|
||||
import static fr.pandacube.lib.core.chat.ChatStatic.text;
|
||||
import static fr.pandacube.lib.core.chat.ChatStatic.warningText;
|
||||
|
||||
import java.util.Calendar;
|
||||
import java.util.OptionalLong;
|
||||
import java.util.UUID;
|
||||
import java.util.stream.LongStream;
|
||||
|
||||
import fr.pandacube.lib.core.chat.Chat;
|
||||
import fr.pandacube.lib.core.chat.ChatColorUtil;
|
||||
import fr.pandacube.lib.core.db.DBException;
|
||||
import fr.pandacube.lib.core.permissions.PermPlayer;
|
||||
@ -12,6 +18,9 @@ import fr.pandacube.lib.core.permissions.Permissions;
|
||||
import fr.pandacube.lib.core.util.Log;
|
||||
|
||||
public interface IOffPlayer {
|
||||
|
||||
/** From how long the last web activity should be before considering the user offline (in ms)? */
|
||||
public static final long TIMEOUT_WEB_SESSION = 10000; // msec
|
||||
|
||||
|
||||
|
||||
@ -63,6 +72,59 @@ public interface IOffPlayer {
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Provides informations of the online status of the player:
|
||||
* online in game, online on the website, or offline.
|
||||
* If the player is online in game, it provides the current server they are
|
||||
* connected.
|
||||
*/
|
||||
public default PlayerStatusOnServer getPlayerStatus() {
|
||||
|
||||
IOnlinePlayer op = getOnlineInstance();
|
||||
if (op != null && !op.isVanished())
|
||||
return new PlayerStatusOnServer(PlayerStatusOnServer.PlayerStatus.ONLINE_IG, op.getServerName());
|
||||
|
||||
try {
|
||||
SQLPlayer webSession = getDbPlayer();
|
||||
|
||||
if (webSession != null) {
|
||||
long lastWebActivity = webSession.get(SQLPlayer.lastWebActivity);
|
||||
|
||||
if (System.currentTimeMillis() - lastWebActivity < TIMEOUT_WEB_SESSION)
|
||||
return new PlayerStatusOnServer(PlayerStatusOnServer.PlayerStatus.ONLINE_WEB, null);
|
||||
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
Log.severe(e);
|
||||
}
|
||||
return new PlayerStatusOnServer(PlayerStatusOnServer.PlayerStatus.OFFLINE, null);
|
||||
}
|
||||
|
||||
public record PlayerStatusOnServer(PlayerStatus status, String server) {
|
||||
public Chat toComponent() {
|
||||
if (status == PlayerStatus.ONLINE_IG)
|
||||
return successText("En ligne, " + server);
|
||||
if (status == PlayerStatus.ONLINE_WEB)
|
||||
return warningText("En ligne, web");
|
||||
if (status == PlayerStatus.OFFLINE)
|
||||
return dataText("Hors ligne");
|
||||
return text("N/A");
|
||||
}
|
||||
|
||||
public enum PlayerStatus {
|
||||
ONLINE_IG, ONLINE_WEB, OFFLINE
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* Floodgate related stuff
|
||||
|
Loading…
Reference in New Issue
Block a user