Add WIP TabListHandler class

This commit is contained in:
JeremyStar™ 2024-10-09 02:33:06 +02:00
parent 2eddb833d4
commit ec86f75619
Signed by: JeremyStarTM
GPG key ID: E366BAEF67E4704D
6 changed files with 144 additions and 0 deletions

View file

@ -51,6 +51,9 @@ dependencies {
// Plugins
compileOnly("net.luckperms:api:${dependencyLuckPerms}")
// Bukkit libraries
implementation("fr.mrmicky:fastboard:${dependencyFastboard}")
}
// Set Java version

View file

@ -89,6 +89,7 @@ public final class Extension extends JavaPlugin {
ExtensionInformation.update();
TranslationManager.loadTranslations();
TranslationManager.processTranslations();
//TabListHandler.initialize();
PlayerDataFactory.initialize();
logger.info("Bootstrapped in " + Miscellaneous.measureExecutionTime(() -> {}) + "ms");

View file

@ -51,6 +51,7 @@ public enum LanguageString {
// Connection errors
CONNECTION_ERROR_REGISTRATION,
CONNECTION_ERROR_TABLISTHANDLER,
// Command /psse
EXTENSIONCMD_GREETER,

View file

@ -0,0 +1,137 @@
/*
* PICKSHADOW SERVER KIT SOURCE FILE
* Copyright (c) 2024 The PickShadow Server Kit authors
* Licensed under the GNU Affero General Public License v3
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package de.jeremystartm.pickshadow.misc;
import de.jeremystartm.pickshadow.Extension;
import de.jeremystartm.pickshadow.api.entity.player.PlayerData;
import de.staropensource.sosengine.base.logging.LoggerInstance;
import fr.mrmicky.fastboard.adventure.FastBoard;
import net.kyori.adventure.text.minimessage.MiniMessage;
import lombok.Getter;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.NotNull;
import java.util.List;
/**
* Handles and manages scoreboards
* and the player tab list.
* <p>
* Doesn't work at all and
* should not be used.
*
* @since v1-release0
*/
@ApiStatus.Experimental
@SuppressWarnings({ "JavadocDeclaration" })
public final class TabListHandler {
/**
* Contains the global instance of this class.
*
* @since v1-release0
* -- GETTER --
* Returns the global instance of this class.
*
* @return global instance
* @since v1-release0
*/
@Getter
private static TabListHandler instance = null;
/**
* Contains the logger instance for this class.
*
* @since v1-release0
*/
private final LoggerInstance logger = new LoggerInstance.Builder().setClazz(getClass()).setOrigin("PSSE").build();
/**
* Contains the content of the tab list.
* Each entry represents one line.
*
* @since v1-release0
*/
private final @NotNull List<@NotNull String> content = List.of(
"Line 1",
"Line 2",
"Line DREI",
"Line 4",
"Line 5"
);
/**
* Creates and initializes an instance of this class.
*
* @since v1-release0
*/
private TabListHandler() {}
/**
* Initializes the scoreboard handler,
* if it hasn't been already.
*
* @since v1-release0
*/
public static void initialize() {
if (instance == null)
instance = new TabListHandler();
}
/**
* Initializes the tab list for
* some {@link PlayerData} instance.
*
* @since v1-release0
*/
public void initializeTabList(@NotNull PlayerData playerData) {
logger.verb("Initializing player list for player " + playerData.getPlayer().getName() + " (" + playerData.getPlayer().getUniqueId() + ")");
// Initialize FastBoard
FastBoard board = new FastBoard(playerData.getPlayer());
playerData.setPlayerListScoreboard(board);
// Configure FastBoard
board.updateTitle(MiniMessage.miniMessage().deserialize("<red>TabList <italic>yay</italic></red>"));
// Schedule update
updateTabList(playerData, true);
}
/**
* Updates the tab list.
*
* @since v1-release0
*/
public void updateTabList(@NotNull PlayerData playerData, boolean justSchedule) {
// Schedule next update
playerData.getPlayer().getScheduler().execute(Extension.getInstance(), () -> updateTabList(playerData, false), null, 20);
// Stop further execution if 'justSchedule' is true
if (justSchedule)
return;
logger.verb("Updating player list for player " + playerData.getPlayer().getName() + " (" + playerData.getPlayer().getUniqueId() + ")");
for (int line = 0; line < content.size(); line++) {
logger.verb("Processing line " + line + " for player " + playerData.getPlayer().getName() + " (" + playerData.getPlayer().getUniqueId() + ")");
playerData.getPlayerListScoreboard().updateLine(line, MiniMessage.miniMessage().deserialize(content.get(line)));
}
}
}

View file

@ -20,6 +20,7 @@
"ERROR_PLAYER_NOT_FOUND": "<error>The player <mention>%player%</mention> could not be found.</error>",
"CONNECTION_ERROR_REGISTRATION": "<error>Unable to process log in",
"CONNECTION_ERROR_TABLISTHANDLER": "<error>TabListHandler failed unexpectedly",
"EXTENSIONCMD_GREETER": "<generic>This subserver is running <#d60532><bold>PSSE</bold> \"<italic>%codename%</italic>\" <italic>@ %version% (%commit%, dirty %dirty%)</italic></generic>\n<generic>To view additional information, invoke some subcommands.",
"EXTENSIONCMD_KILLJVM": "<generic>Bye bye!",

View file

@ -37,6 +37,7 @@ dependencyGson=2.11.0
dependencyPaper=R0.1
dependencyAdventure=4.17.0
dependencyLuckPerms=5.4
dependencyFastboard=2.1.3
# Plugins
pluginLombok=8.6