This commit is contained in:
Marc Baloup 2023-02-22 16:40:08 +01:00
parent 6f310de32e
commit a6bde9e191
5 changed files with 87 additions and 15 deletions

View File

@ -90,44 +90,65 @@ public class ChatConfig {
} }
/**
* A set of predefined colors.
*/
public static class PandaTheme { public static class PandaTheme {
/** Green 1 color. */
public static final TextColor CHAT_GREEN_1_NORMAL = TextColor.fromHexString("#3db849"); // h=126 s=50 l=48 public static final TextColor CHAT_GREEN_1_NORMAL = TextColor.fromHexString("#3db849"); // h=126 s=50 l=48
/** Green 2 color. */
public static final TextColor CHAT_GREEN_2 = TextColor.fromHexString("#5ec969"); // h=126 s=50 l=58 public static final TextColor CHAT_GREEN_2 = TextColor.fromHexString("#5ec969"); // h=126 s=50 l=58
/** Green 3 color. */
public static final TextColor CHAT_GREEN_3 = TextColor.fromHexString("#85d68d"); // h=126 s=50 l=68 public static final TextColor CHAT_GREEN_3 = TextColor.fromHexString("#85d68d"); // h=126 s=50 l=68
/** Green 4 color. */
public static final TextColor CHAT_GREEN_4 = TextColor.fromHexString("#abe3b0"); // h=126 s=50 l=78 public static final TextColor CHAT_GREEN_4 = TextColor.fromHexString("#abe3b0"); // h=126 s=50 l=78
/** Green max saturation color. */
public static final TextColor CHAT_GREEN_SATMAX = TextColor.fromHexString("#00ff19"); // h=126 s=100 l=50 public static final TextColor CHAT_GREEN_SATMAX = TextColor.fromHexString("#00ff19"); // h=126 s=100 l=50
/** Green 1 saturated color. */
public static final TextColor CHAT_GREEN_1_SAT = TextColor.fromHexString("#20d532"); // h=126 s=50 l=48 public static final TextColor CHAT_GREEN_1_SAT = TextColor.fromHexString("#20d532"); // h=126 s=50 l=48
/** Green 2 saturated color. */
public static final TextColor CHAT_GREEN_2_SAT = TextColor.fromHexString("#45e354"); // h=126 s=50 l=58 public static final TextColor CHAT_GREEN_2_SAT = TextColor.fromHexString("#45e354"); // h=126 s=50 l=58
/** Green 3 saturated color. */
public static final TextColor CHAT_GREEN_3_SAT = TextColor.fromHexString("#71ea7d"); // h=126 s=50 l=68 public static final TextColor CHAT_GREEN_3_SAT = TextColor.fromHexString("#71ea7d"); // h=126 s=50 l=68
/** Green 4 saturated color. */
public static final TextColor CHAT_GREEN_4_SAT = TextColor.fromHexString("#9df0a6"); // h=126 s=50 l=78 public static final TextColor CHAT_GREEN_4_SAT = TextColor.fromHexString("#9df0a6"); // h=126 s=50 l=78
/** Brown 1 color. */
public static final TextColor CHAT_BROWN_1 = TextColor.fromHexString("#b26d3a"); // h=26 s=51 l=46 public static final TextColor CHAT_BROWN_1 = TextColor.fromHexString("#b26d3a"); // h=26 s=51 l=46
/** Brown 2 color. */
public static final TextColor CHAT_BROWN_2 = TextColor.fromHexString("#cd9265"); // h=26 s=51 l=60 public static final TextColor CHAT_BROWN_2 = TextColor.fromHexString("#cd9265"); // h=26 s=51 l=60
/** Brown 3 color. */
public static final TextColor CHAT_BROWN_3 = TextColor.fromHexString("#e0bb9f"); // h=26 s=51 l=75 public static final TextColor CHAT_BROWN_3 = TextColor.fromHexString("#e0bb9f"); // h=26 s=51 l=75
/** Brown 1 saturated color. */
public static final TextColor CHAT_BROWN_1_SAT = TextColor.fromHexString("#b35c19"); // h=26 s=75 l=40 public static final TextColor CHAT_BROWN_1_SAT = TextColor.fromHexString("#b35c19"); // h=26 s=75 l=40
/** Brown 2 saturated color. */
public static final TextColor CHAT_BROWN_2_SAT = TextColor.fromHexString("#e28136"); // h=26 s=51 l=55 public static final TextColor CHAT_BROWN_2_SAT = TextColor.fromHexString("#e28136"); // h=26 s=51 l=55
/** Brown 3 saturated color. */
public static final TextColor CHAT_BROWN_3_SAT = TextColor.fromHexString("#ecab79"); // h=26 s=51 l=70 public static final TextColor CHAT_BROWN_3_SAT = TextColor.fromHexString("#ecab79"); // h=26 s=51 l=70
/** Gray medium color. */
public static final TextColor CHAT_GRAY_MID = TextColor.fromHexString("#888888"); public static final TextColor CHAT_GRAY_MID = TextColor.fromHexString("#888888");
/** Red failure color. */
public static final TextColor CHAT_RED_FAILURE = TextColor.fromHexString("#ff3333"); public static final TextColor CHAT_RED_FAILURE = TextColor.fromHexString("#ff3333");
/** Color used for private message prefix decoration. */
public static final TextColor CHAT_PM_PREFIX_DECORATION = CHAT_BROWN_2_SAT; public static final TextColor CHAT_PM_PREFIX_DECORATION = CHAT_BROWN_2_SAT;
/** Color used for sent message text. */
public static final TextColor CHAT_PM_SELF_MESSAGE = CHAT_GREEN_2; public static final TextColor CHAT_PM_SELF_MESSAGE = CHAT_GREEN_2;
/** Color used for received message text. */
public static final TextColor CHAT_PM_OTHER_MESSAGE = CHAT_GREEN_4; public static final TextColor CHAT_PM_OTHER_MESSAGE = CHAT_GREEN_4;
/** Discord color. */
public static final TextColor CHAT_DISCORD_LINK_COLOR = TextColor.fromHexString("#00aff4"); public static final TextColor CHAT_DISCORD_LINK_COLOR = TextColor.fromHexString("#00aff4");
/**
* Generate a prefix for broadcast message.
* @return a prefix for broadcast message.
*/
public static Chat CHAT_MESSAGE_PREFIX() { public static Chat CHAT_MESSAGE_PREFIX() {
return Chat.text("[") return Chat.text("[")
.broadcastColor() .broadcastColor()

View File

@ -83,11 +83,20 @@ public class Persist {
save(); save();
} }
/**
* Tells if the backup process with the provided id is dirty.
* @param id the id of the backup process.
* @return true if the process is marked as dirty, false otherwise.
*/
public synchronized boolean isDirty(String id) { public synchronized boolean isDirty(String id) {
return isDirtySince(id) != -1; return isDirtySince(id) != -1;
} }
/**
* Tells since when the backup process with the provided id is dirty.
* @param id the id of the backup process.
* @return the millis-timestamp of when the backup process has been marked dirty.
*/
public synchronized long isDirtySince(String id) { public synchronized long isDirtySince(String id) {
if (!dirtySince.containsKey(id)) if (!dirtySince.containsKey(id))
setDirtySinceNow(id); setDirtySinceNow(id);

View File

@ -6,17 +6,26 @@ import net.md_5.bungee.api.ChatColor;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.text.DateFormat;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Date;
import java.util.List; import java.util.List;
import java.util.function.BiPredicate; import java.util.function.BiPredicate;
/**
* A special backup process that handle the backup of rotated log files.
*/
public class RotatedLogsBackupProcess extends BackupProcess { public class RotatedLogsBackupProcess extends BackupProcess {
final String logFileRegexPattern; final String logFileRegexPattern;
final File sourceLogDirectory; final File sourceLogDirectory;
final boolean inNewThread; final boolean inNewThread;
/**
* Create a new instance of this backup process.
* @param bm the backup manager.
* @param inNewThread tells if this process should be run in a separate thread (true) or in the same thread handling
* the backup manager (false).
* @param sourceLogDir the directory where the rotated log files are stored, usually {@code ./logs/}.
* @param logFileRegexPattern the pattern to match the rotated log files (usually dated log files, excuding the current log file).
*/
public RotatedLogsBackupProcess(BackupManager bm, boolean inNewThread, File sourceLogDir, String logFileRegexPattern) { public RotatedLogsBackupProcess(BackupManager bm, boolean inNewThread, File sourceLogDir, String logFileRegexPattern) {
super(bm, "logs"); super(bm, "logs");
this.logFileRegexPattern = logFileRegexPattern; this.logFileRegexPattern = logFileRegexPattern;
@ -84,7 +93,7 @@ public class RotatedLogsBackupProcess extends BackupProcess {
public List<File> getFilesToMove() { private List<File> getFilesToMove() {
List<File> ret = new ArrayList<>(); List<File> ret = new ArrayList<>();
for (File f : getSourceDir().listFiles()) { for (File f : getSourceDir().listFiles()) {
if (f.getName().matches(logFileRegexPattern)) if (f.getName().matches(logFileRegexPattern))

View File

@ -74,14 +74,46 @@ public interface AbstractOffPlayer {
* Player config * Player config
*/ */
/**
* Gets the value of the provided configuration key of this player.
* @param key the configuration key.
* @return the value of the configuration, or null if the configuration is not set.
* @throws Exception if an error occurs fetching the configuration value.
*/
String getConfig(String key) throws Exception; String getConfig(String key) throws Exception;
/**
* Gets the value of the provided configuration key of this player.
* @param key the configuration key.
* @param deflt the default value if the configuration is not set.
* @return the value of the configuration, or {@code deflt} if the configuration is not set.
* @throws Exception if an error occurs fetching the configuration value.
*/
String getConfig(String key, String deflt) throws Exception; String getConfig(String key, String deflt) throws Exception;
/**
* Sets the value of the provided configuration key for this player.
* @param key the configuration key to set.
* @param value the new value.
* @throws Exception if an error occurs updating the configuration value.
*/
void setConfig(String key, String value) throws Exception; void setConfig(String key, String value) throws Exception;
/**
* Updates the value of the provided configuration key for this player, using the provided updater.
* @param key the configuration key to update.
* @param deflt the default value to use if the configuration is not already set.
* @param updater the unary operator to use to update th value. The old value is used as the parameter of the updater,
* and it returns the new value of the configuration.
* @throws Exception if an error occurs updating the configuration value.
*/
void updateConfig(String key, String deflt, UnaryOperator<String> updater) throws Exception; void updateConfig(String key, String deflt, UnaryOperator<String> updater) throws Exception;
/**
* Unsets the value of the provided configuration key for this player.
* @param key the configuration key to update.
* @throws Exception if an error occurs deleting the configuration value.
*/
void unsetConfig(String key) throws Exception; void unsetConfig(String key) throws Exception;

View File

@ -122,6 +122,7 @@ public abstract class AbstractPlayerManager<OP extends AbstractOnlinePlayer, OF
* The default implementation returns all the players. * The default implementation returns all the players.
* Concrete subclasses should override this method, especially * Concrete subclasses should override this method, especially
* on Paper server, using the {@code Player.canSee(Player)} API. * on Paper server, using the {@code Player.canSee(Player)} API.
* @param viewer the player to test visibility on.
* @return the players that the provided player can see. * @return the players that the provided player can see.
*/ */
public List<OP> getOnlyVisibleFor(OF viewer) { public List<OP> getOnlyVisibleFor(OF viewer) {
@ -130,10 +131,10 @@ public abstract class AbstractPlayerManager<OP extends AbstractOnlinePlayer, OF
/** /**
* Get all the players that the provided player can see. * Get all the players that the provided player can see.
* The default implementation returns all the players. * Uses {@link #getOnlyVisibleFor(AbstractOffPlayer)}.
* Concrete subclasses should override this method, especially * @param viewer the player to test visibility on.
* on Paper server, using the {@code Player.canSee(Player)} API.
* @return the players that the provided player can see. * @return the players that the provided player can see.
* @see #getOnlyVisibleFor(AbstractOffPlayer)
*/ */
public List<String> getNamesOnlyVisible(OF viewer) { public List<String> getNamesOnlyVisible(OF viewer) {
return getOnlyVisibleFor(viewer).stream() return getOnlyVisibleFor(viewer).stream()