Compare commits

..

2 Commits

Author SHA1 Message Date
62949948e1 Some more javadoc 2023-08-27 17:28:12 +02:00
bd3bea8381 Some refactoring in pandalib-util 2023-08-27 13:37:17 +02:00
66 changed files with 300 additions and 193 deletions

View File

@ -4,25 +4,42 @@ import fr.pandacube.lib.bungee.util.BungeeDailyLogRotateFileHandler;
import fr.pandacube.lib.bungee.util.PluginMessagePassthrough;
import net.md_5.bungee.api.plugin.Plugin;
/**
* General class used to initialize some tools of pandalib-bungee, following the bungee plugin's lifecycle.
*/
public class PandaLibBungee {
private static Plugin plugin;
/**
* Method to be called in {@link Plugin#onLoad()} method.
* @param plugin the plugin instance.
*/
public static void onLoad(Plugin plugin) {
PandaLibBungee.plugin = plugin;
}
/**
* Method to be called in {@link Plugin#onEnable()} method.
*/
public static void onEnable() {
PluginMessagePassthrough.init(plugin);
BungeeDailyLogRotateFileHandler.init(true);
}
/**
* Method to be called in {@link Plugin#onDisable()} method.
*/
public static void disable() {
}
/**
* Returns the plugin instance.
* @return the plugin instance.
*/
public static Plugin getPlugin() {
return plugin;
}

View File

@ -6,12 +6,33 @@ import java.io.File;
import java.util.ArrayList;
import java.util.List;
/**
* Class that holds the configuration varables for {@link BungeeBackupManager}.
*/
@SuppressWarnings("CanBeFinal")
public class BungeeBackupConfig {
/**
* Tells if the working directory of the current bungee instance should be backed up.
*/
public boolean workdirBackupEnabled = true;
/**
* Tells if the old logs of the current bungee instance should be backed up.
*/
public boolean logsBackupEnabled = true;
/**
* The cron scheduling of when the workdir backup occurs.
*/
public String scheduling = "0 2 * * *"; // cron format, here is every day at 2am
/**
* The destination directory for the backups.
*/
public File backupDirectory = null;
/**
* The configuration handling the cleaning of the backup directory.
*/
public BackupCleaner workdirBackupCleaner = BackupCleaner.KEEPING_1_EVERY_N_MONTH(3).merge(BackupCleaner.KEEPING_N_LAST(5));
/**
* A list of ignored files or directory in the workdir to exclude from the backup.
*/
public List<String> workdirIgnoreList = new ArrayList<>();
}

View File

@ -6,10 +6,17 @@ import fr.pandacube.lib.core.backup.RotatedLogsBackupProcess;
import java.io.File;
/**
* Handles the backup processes for a Bungeecord instance.
*/
public class BungeeBackupManager extends BackupManager {
BungeeBackupConfig config;
/**
* Instanciate a new {@link BungeeBackupManager}.
* @param config the configuration.
*/
public BungeeBackupManager(BungeeBackupConfig config) {
super(config.backupDirectory);
setConfig(config);
@ -24,12 +31,19 @@ public class BungeeBackupManager extends BackupManager {
super.addProcess(process);
}
/**
* Sets a new configuration for this backup manager.
* @param config the new configuration.
*/
public void setConfig(BungeeBackupConfig config) {
this.config = config;
backupQueue.forEach(this::updateProcessConfig);
}
/**
* Deploys the new configuration to the provided backup process.
* @param process the process on which to apply the new config.
*/
public void updateProcessConfig(BackupProcess process) {
if (process instanceof BungeeWorkdirProcess) {
process.setEnabled(config.workdirBackupEnabled);

View File

@ -5,8 +5,15 @@ import fr.pandacube.lib.core.backup.BackupProcess;
import java.io.File;
import java.util.function.BiPredicate;
/**
* The backup process responsible for the working directory of the current Bungeecord instance.
*/
public class BungeeWorkdirProcess extends BackupProcess {
/**
* Instantiates this backup process.
* @param bm the backup manager.
*/
protected BungeeWorkdirProcess(BungeeBackupManager bm) {
super(bm, "workdir");
}

View File

@ -7,7 +7,7 @@ import com.mojang.brigadier.suggestion.Suggestions;
import com.mojang.brigadier.tree.LiteralCommandNode;
import fr.pandacube.lib.commands.BrigadierCommand;
import fr.pandacube.lib.commands.SuggestionsSupplier;
import fr.pandacube.lib.util.Log;
import fr.pandacube.lib.util.log.Log;
import net.md_5.bungee.api.CommandSender;
import net.md_5.bungee.api.ProxyServer;
import net.md_5.bungee.api.connection.ProxiedPlayer;

View File

@ -1,6 +1,6 @@
package fr.pandacube.lib.bungee.util;
import fr.pandacube.lib.util.logs.DailyLogRotateFileHandler;
import fr.pandacube.lib.util.log.DailyLogRotateFileHandler;
import net.md_5.bungee.api.ProxyServer;
import net.md_5.bungee.log.ConciseFormatter;

View File

@ -199,6 +199,7 @@ public class ChatUtil {
/**
* Do like {@link String#join(CharSequence, Iterable)}, but for components.
* @param separator the separator used everywhere except between the two last components to join.
* @param elements the components to join.
* @return a new {@link Chat} instance with all the provided {@code component} joined using the separators.
*/
public static FormatableChat join(ComponentLike separator, Iterable<? extends ComponentLike> elements) {

View File

@ -8,7 +8,7 @@ import fr.pandacube.lib.cli.log.CLILogger;
import jline.console.ConsoleReader;
import org.fusesource.jansi.AnsiConsole;
import fr.pandacube.lib.util.Log;
import fr.pandacube.lib.util.log.Log;
/**
* Class to handle general standard IO operation for a CLI application. It uses Jlines {@link ConsoleReader} for the

View File

@ -2,7 +2,7 @@ package fr.pandacube.lib.cli;
import fr.pandacube.lib.cli.commands.CommandAdmin;
import fr.pandacube.lib.cli.commands.CommandStop;
import fr.pandacube.lib.util.Log;
import fr.pandacube.lib.util.log.Log;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.logging.Logger;
@ -14,17 +14,23 @@ public abstract class CLIApplication {
private static CLIApplication instance;
/**
* Returns the current application instance.
* @return the current application instance.
*/
public static CLIApplication getInstance() {
return instance;
}
/**
* The instance of {@link CLI} for this application.
*/
public final CLI cli;
/**
* Creates a new application instance.
*/
protected CLIApplication() {
instance = this;
CLI tmpCLI = null;
@ -56,6 +62,10 @@ public abstract class CLIApplication {
}
}
/**
* Returns the application's {@link Logger}.
* @return the application's {@link Logger}.
*/
public Logger getLogger() {
return cli.getLogger();
}
@ -63,6 +73,9 @@ public abstract class CLIApplication {
private final AtomicBoolean stopping = new AtomicBoolean(false);
/**
* Stops this application.
*/
@SuppressWarnings("finally")
public final void stop() {
synchronized (stopping) {
@ -75,25 +88,45 @@ public abstract class CLIApplication {
end();
} catch (Throwable t) {
Log.severe("Error stopping application " + getName() + " version " + getClass().getPackage().getImplementationVersion(), t);
System.exit(1);
} finally {
Log.info("Bye bye.");
System.exit(0);
}
}
/**
* Tells if this application is currently stopping, that is the {@link #stop()} method has been called.
* @return true if the application is stopping, false otherwise.
*/
public boolean isStopping() {
return stopping.get();
}
/**
* Gets the name of this application.
* @return the name of this application.
*/
public abstract String getName();
/**
* Method to override to initialize stuff in this application.
* This method is called on instanciation of this Application.
* @throws Exception If an exception is thrown, the application will not start.
*/
protected abstract void start() throws Exception;
/**
* Method to override to reload specific stuff in this application.
* This method is called by using the command {@code admin reload}.
*/
public abstract void reload();
/**
* Method to override to execute stuff when this application stops.
* This method is called once before this application terminates, possibly from a shutdown hook Thread.
*/
protected abstract void end();

View File

@ -1,7 +1,7 @@
package fr.pandacube.lib.cli.commands;
import fr.pandacube.lib.chat.Chat;
import fr.pandacube.lib.util.Log;
import fr.pandacube.lib.util.log.Log;
import net.kyori.adventure.audience.MessageType;
import net.kyori.adventure.identity.Identity;
import net.kyori.adventure.text.Component;

View File

@ -17,7 +17,7 @@ import fr.pandacube.lib.chat.Chat;
import fr.pandacube.lib.chat.Chat.FormatableChat;
import fr.pandacube.lib.chat.ChatTreeNode;
import fr.pandacube.lib.cli.CLIApplication;
import fr.pandacube.lib.util.Log;
import fr.pandacube.lib.util.log.Log;
import net.md_5.bungee.api.chat.BaseComponent;
import java.util.ArrayList;
@ -31,6 +31,9 @@ import static fr.pandacube.lib.chat.ChatStatic.failureText;
import static fr.pandacube.lib.chat.ChatStatic.successText;
import static fr.pandacube.lib.chat.ChatStatic.text;
/**
* The {@code admin} command for a {@link CLIApplication}.
*/
public class CommandAdmin extends CLIBrigadierCommand {
@Override

View File

@ -5,7 +5,7 @@ import com.mojang.brigadier.builder.LiteralArgumentBuilder;
import fr.pandacube.lib.cli.CLIApplication;
/**
* /stop (/end) command.
* the {@code stop} (or {@code end}) command for a {@link CLIApplication}.
*/
public class CommandStop extends CLIBrigadierCommand {

View File

@ -1,9 +1,9 @@
package fr.pandacube.lib.cli.log;
import fr.pandacube.lib.cli.CLI;
import fr.pandacube.lib.util.Log;
import fr.pandacube.lib.util.log.Log;
import fr.pandacube.lib.util.ThrowableUtil;
import fr.pandacube.lib.util.logs.DailyLogRotateFileHandler;
import fr.pandacube.lib.util.log.DailyLogRotateFileHandler;
import net.md_5.bungee.log.ColouredWriter;
import net.md_5.bungee.log.ConciseFormatter;

View File

@ -10,7 +10,7 @@ import com.mojang.brigadier.exceptions.CommandSyntaxException;
import com.mojang.brigadier.exceptions.SimpleCommandExceptionType;
import com.mojang.brigadier.suggestion.SuggestionProvider;
import com.mojang.brigadier.tree.LiteralCommandNode;
import fr.pandacube.lib.util.Log;
import fr.pandacube.lib.util.log.Log;
import java.util.Arrays;
import java.util.function.Function;

View File

@ -6,7 +6,7 @@ import com.mojang.brigadier.exceptions.CommandSyntaxException;
import com.mojang.brigadier.suggestion.Suggestions;
import com.mojang.brigadier.tree.LiteralCommandNode;
import fr.pandacube.lib.chat.Chat;
import fr.pandacube.lib.util.Log;
import fr.pandacube.lib.util.log.Log;
import net.kyori.adventure.text.ComponentLike;
import java.util.concurrent.CompletableFuture;

View File

@ -1,7 +1,7 @@
package fr.pandacube.lib.core.backup;
import fr.pandacube.lib.chat.Chat;
import fr.pandacube.lib.util.Log;
import fr.pandacube.lib.util.log.Log;
import net.md_5.bungee.api.ChatColor;
import java.io.File;

View File

@ -1,6 +1,6 @@
package fr.pandacube.lib.core.backup;
import fr.pandacube.lib.util.Log;
import fr.pandacube.lib.util.log.Log;
import java.io.File;
import java.time.ZonedDateTime;
@ -66,7 +66,10 @@ public class BackupManager extends TimerTask {
return backupDirectory;
}
/**
* Tells if a backup is currently running.
* @return true if a backup is running, false otherwise.
*/
public synchronized boolean isBackupRunning() {
return runningBackup.get() != null;
}
@ -93,6 +96,7 @@ public class BackupManager extends TimerTask {
* Disables this backup manager, canceling scheduled backups.
* It will wait for a currently running backup to finish before returning.
*/
@SuppressWarnings("BusyWait")
public synchronized void onDisable() {
schedulerTimer.cancel();

View File

@ -3,7 +3,7 @@ package fr.pandacube.lib.core.backup;
import fc.cron.CronExpression;
import fr.pandacube.lib.core.cron.CronScheduler;
import fr.pandacube.lib.util.FileUtils;
import fr.pandacube.lib.util.Log;
import fr.pandacube.lib.util.log.Log;
import net.md_5.bungee.api.ChatColor;
import java.io.File;

View File

@ -3,7 +3,7 @@ package fr.pandacube.lib.core.backup;
import com.google.gson.JsonParseException;
import com.google.gson.reflect.TypeToken;
import fr.pandacube.lib.core.json.Json;
import fr.pandacube.lib.util.Log;
import fr.pandacube.lib.util.log.Log;
import java.io.File;
import java.io.FileReader;

View File

@ -1,7 +1,7 @@
package fr.pandacube.lib.core.backup;
import com.google.common.io.Files;
import fr.pandacube.lib.util.Log;
import fr.pandacube.lib.util.log.Log;
import net.md_5.bungee.api.ChatColor;
import java.io.File;

View File

@ -1,7 +1,7 @@
package fr.pandacube.lib.core.config;
import fr.pandacube.lib.chat.ChatColorUtil;
import fr.pandacube.lib.util.Log;
import fr.pandacube.lib.util.log.Log;
import java.io.BufferedReader;
import java.io.File;

View File

@ -4,7 +4,7 @@ import com.google.gson.JsonParseException;
import com.google.gson.reflect.TypeToken;
import fc.cron.CronExpression;
import fr.pandacube.lib.core.json.Json;
import fr.pandacube.lib.util.Log;
import fr.pandacube.lib.util.log.Log;
import java.io.File;
import java.io.FileReader;

View File

@ -10,7 +10,7 @@ import com.google.gson.JsonSerializationContext;
import com.google.gson.JsonSerializer;
import com.google.gson.TypeAdapterFactory;
import com.google.gson.internal.bind.TreeTypeAdapter;
import fr.pandacube.lib.util.Log;
import fr.pandacube.lib.util.log.Log;
import fr.pandacube.lib.util.ThrowableUtil;
import java.lang.reflect.Constructor;

View File

@ -5,14 +5,27 @@ import java.util.List;
import java.util.Map;
import java.util.TreeMap;
/**
* Record holding the data for {@link ProtocolVersion}, to facilitate serializing and deserializing.
* @param protocolOfVersion mapping from a version string to the corresponding protocol version number.
* @param versionsOfProtocol mapping from a protocol version number to a list of the supported MC versions.
*/
public record MinecraftVersionList(
Map<String, Integer> protocolOfVersion,
Map<Integer, List<String>> versionsOfProtocol
) {
/**
* Creates an empty {@link MinecraftVersionList}.
*/
public MinecraftVersionList() {
this(new TreeMap<>(MinecraftVersionUtil::compareVersions), new TreeMap<>());
}
/**
* Adds a new pair of version string and protocol version number.
* @param versionId the version string (e.g. "1.19.4").
* @param protocolVersion the protocol version number.
*/
public void add(String versionId, int protocolVersion) {
protocolOfVersion.put(versionId, protocolVersion);
List<String> versions = versionsOfProtocol.computeIfAbsent(protocolVersion, p -> new ArrayList<>());

View File

@ -1,7 +1,7 @@
package fr.pandacube.lib.core.mc_version;
import fr.pandacube.lib.core.json.Json;
import fr.pandacube.lib.util.Log;
import fr.pandacube.lib.util.log.Log;
import fr.pandacube.lib.util.StringUtil;
import org.jetbrains.annotations.NotNull;
@ -156,8 +156,9 @@ public class ProtocolVersion implements Comparable<ProtocolVersion> {
* @return all the {@link ProtocolVersion} currently known by this class.
*/
public static List<ProtocolVersion> allKnownProtocolVersions() {
return versionList.get().versionsOfProtocol().keySet().stream()
.map(ProtocolVersion::ofProtocol)
return versionList.get().versionsOfProtocol().entrySet().stream()
.filter(e -> e.getValue() != null && !e.getValue().isEmpty())
.map(e -> new ProtocolVersion(e.getKey(), List.copyOf(e.getValue())))
.toList();
}

View File

@ -2,7 +2,7 @@ package fr.pandacube.lib.core.search;
import com.google.common.cache.Cache;
import com.google.common.cache.CacheBuilder;
import fr.pandacube.lib.util.Log;
import fr.pandacube.lib.util.log.Log;
import java.util.ArrayList;
import java.util.HashMap;

View File

@ -15,7 +15,7 @@ import java.util.Objects;
import java.util.function.Consumer;
import fr.pandacube.lib.reflect.Reflect;
import fr.pandacube.lib.util.Log;
import fr.pandacube.lib.util.log.Log;
/**
* Static class to handle most of the database operations.

View File

@ -26,7 +26,7 @@ import java.util.UUID;
import java.util.stream.Collectors;
import fr.pandacube.lib.util.EnumUtil;
import fr.pandacube.lib.util.Log;
import fr.pandacube.lib.util.log.Log;
/**
* Represents an entry in a SQL table. Each subclass is for a specific table.

View File

@ -1,6 +1,6 @@
package fr.pandacube.lib.db;
import fr.pandacube.lib.util.Log;
import fr.pandacube.lib.util.log.Log;
/**
* A foreign key field in a SQL table.

View File

@ -6,7 +6,7 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
import fr.pandacube.lib.util.Log;
import fr.pandacube.lib.util.log.Log;
/**
* Builder for a SQL {@code UPDATE} query.

View File

@ -4,7 +4,7 @@ import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import fr.pandacube.lib.util.Log;
import fr.pandacube.lib.util.log.Log;
/**
* A SQL {@code WHERE} expression.

View File

@ -5,7 +5,7 @@ import java.io.PrintStream;
import java.net.InetAddress;
import java.net.Socket;
import fr.pandacube.lib.util.Log;
import fr.pandacube.lib.util.log.Log;
public abstract class AbstractRequestExecutor {

View File

@ -1,6 +1,6 @@
package fr.pandacube.lib.netapi.server;
import fr.pandacube.lib.util.Log;
import fr.pandacube.lib.util.log.Log;
import java.io.IOException;
import java.net.InetAddress;

View File

@ -5,7 +5,7 @@ import java.io.PrintStream;
import java.net.Socket;
import fr.pandacube.lib.netapi.server.RequestAnalyser.BadRequestException;
import fr.pandacube.lib.util.Log;
import fr.pandacube.lib.util.log.Log;
/**
* Prends en charge un socket client et le transmet au gestionnaire de paquet

View File

@ -23,7 +23,7 @@ import org.bukkit.permissions.ServerOperator;
import org.bukkit.plugin.java.JavaPlugin;
import fr.pandacube.lib.permissions.Permissions;
import fr.pandacube.lib.util.Log;
import fr.pandacube.lib.util.log.Log;
/**
* Class that integrates the {@code pandalib-permissions} system into a Bukkit/Spigot/Paper instance.

View File

@ -6,7 +6,7 @@ import com.google.common.cache.CacheLoader;
import com.google.common.cache.LoadingCache;
import fr.pandacube.lib.permissions.Permissions;
import fr.pandacube.lib.reflect.Reflect;
import fr.pandacube.lib.util.Log;
import fr.pandacube.lib.util.log.Log;
import org.bukkit.command.CommandSender;
import org.bukkit.command.ConsoleCommandSender;
import org.bukkit.entity.Player;

View File

@ -2,7 +2,7 @@ package fr.pandacube.lib.paper.permissions;
import fr.pandacube.lib.permissions.PermGroup;
import fr.pandacube.lib.permissions.Permissions;
import fr.pandacube.lib.util.Log;
import fr.pandacube.lib.util.log.Log;
import net.milkbowl.vault.chat.Chat;
import net.milkbowl.vault.permission.Permission;
import org.bukkit.Bukkit;

View File

@ -11,7 +11,7 @@ import org.bukkit.plugin.ServicePriority;
import fr.pandacube.lib.permissions.PermPlayer;
import fr.pandacube.lib.permissions.Permissions;
import fr.pandacube.lib.util.Log;
import fr.pandacube.lib.util.log.Log;
/* package */ class PermissionsInjectorWEPIF {

View File

@ -2,7 +2,7 @@ package fr.pandacube.lib.paper.backup;
import fr.pandacube.lib.paper.scheduler.SchedulerUtil;
import fr.pandacube.lib.paper.util.WorldUtil;
import fr.pandacube.lib.util.Log;
import fr.pandacube.lib.util.log.Log;
import net.md_5.bungee.api.ChatColor;
import org.bukkit.Bukkit;
import org.bukkit.World;

View File

@ -31,7 +31,7 @@ import fr.pandacube.lib.players.standalone.AbstractOffPlayer;
import fr.pandacube.lib.players.standalone.AbstractOnlinePlayer;
import fr.pandacube.lib.players.standalone.AbstractPlayerManager;
import fr.pandacube.lib.reflect.wrapper.ReflectWrapper;
import fr.pandacube.lib.util.Log;
import fr.pandacube.lib.util.log.Log;
import net.kyori.adventure.text.Component;
import org.bukkit.Bukkit;
import org.bukkit.World;

View File

@ -20,7 +20,7 @@ import org.bukkit.event.player.PlayerRespawnEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.PlayerInventory;
import fr.pandacube.lib.util.Log;
import fr.pandacube.lib.util.log.Log;
import fr.pandacube.lib.paper.util.BukkitEvent;
/**

View File

@ -13,7 +13,7 @@ import fr.pandacube.lib.paper.scheduler.SchedulerUtil;
import fr.pandacube.lib.paper.util.AutoUpdatedBossBar;
import fr.pandacube.lib.paper.util.AutoUpdatedBossBar.BarUpdater;
import fr.pandacube.lib.players.standalone.AbstractPlayerManager;
import fr.pandacube.lib.util.Log;
import fr.pandacube.lib.util.log.Log;
import fr.pandacube.lib.util.MemoryUtil;
import fr.pandacube.lib.util.MemoryUtil.MemoryUnit;
import fr.pandacube.lib.util.TimeUtil;

View File

@ -1,7 +1,7 @@
package fr.pandacube.lib.paper.players;
import fr.pandacube.lib.paper.PandaLibPaper;
import fr.pandacube.lib.util.Log;
import fr.pandacube.lib.util.log.Log;
import org.bukkit.Bukkit;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.configuration.InvalidConfigurationException;

View File

@ -19,7 +19,7 @@ import java.util.stream.Collectors;
import org.bukkit.Bukkit;
import fr.pandacube.lib.util.Log;
import fr.pandacube.lib.util.log.Log;
import fr.pandacube.lib.reflect.Reflect;
import fr.pandacube.lib.reflect.ReflectClass;
import fr.pandacube.lib.reflect.ReflectField;

View File

@ -4,7 +4,7 @@ import fr.pandacube.lib.paper.PandaLibPaper;
import fr.pandacube.lib.paper.reflect.wrapper.minecraft.world.AABB;
import fr.pandacube.lib.paper.reflect.wrapper.minecraft.world.block.BambooStalkBlock;
import fr.pandacube.lib.paper.reflect.wrapper.paper.AABBVoxelShape;
import fr.pandacube.lib.util.Log;
import fr.pandacube.lib.util.log.Log;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.entity.LivingEntity;

View File

@ -15,7 +15,7 @@ import org.bukkit.scheduler.BukkitScheduler;
import org.bukkit.scheduler.BukkitTask;
import fr.pandacube.lib.chat.Chat;
import fr.pandacube.lib.util.Log;
import fr.pandacube.lib.util.log.Log;
import fr.pandacube.lib.paper.PandaLibPaper;
import net.kyori.adventure.bossbar.BossBar;
import net.kyori.adventure.bossbar.BossBar.Color;

View File

@ -12,7 +12,7 @@ import org.bukkit.event.Listener;
import fr.pandacube.lib.util.BiMap;
import fr.pandacube.lib.util.FileUtils;
import fr.pandacube.lib.util.Log;
import fr.pandacube.lib.util.log.Log;
import fr.pandacube.lib.util.RandomUtil;
public class GameWorldUtils implements Listener {

View File

@ -1,6 +1,6 @@
package fr.pandacube.lib.permissions;
import fr.pandacube.lib.util.Log;
import fr.pandacube.lib.util.log.Log;
import java.util.UUID;

View File

@ -11,7 +11,7 @@ import fr.pandacube.lib.chat.ChatTreeNode;
import fr.pandacube.lib.permissions.PermissionExpressionParser.LiteralPermissionTester;
import fr.pandacube.lib.permissions.PermissionsCachedBackendReader.CachedEntity;
import fr.pandacube.lib.permissions.SQLPermissions.EntityType;
import fr.pandacube.lib.util.Log;
import fr.pandacube.lib.util.log.Log;
/**
* Represents an entity in the permission system, either a group or a player.

View File

@ -8,7 +8,7 @@ import java.util.function.Function;
import fr.pandacube.lib.db.DB;
import fr.pandacube.lib.db.DBConnection;
import fr.pandacube.lib.db.DBException;
import fr.pandacube.lib.util.Log;
import fr.pandacube.lib.util.log.Log;
/**
* Main class for the Pandalib permission system.

View File

@ -19,7 +19,7 @@ import fr.pandacube.lib.db.DB;
import fr.pandacube.lib.db.DBException;
import fr.pandacube.lib.db.SQLElementList;
import fr.pandacube.lib.permissions.SQLPermissions.EntityType;
import fr.pandacube.lib.util.Log;
import fr.pandacube.lib.util.log.Log;
/* package */ class PermissionsCachedBackendReader
{

View File

@ -23,7 +23,7 @@ import fr.pandacube.lib.permissions.PermissionsCachedBackendReader.CachedEntity;
import fr.pandacube.lib.permissions.PermissionsCachedBackendReader.CachedGroup;
import fr.pandacube.lib.permissions.PermissionsCachedBackendReader.CachedPlayer;
import fr.pandacube.lib.permissions.SQLPermissions.EntityType;
import fr.pandacube.lib.util.Log;
import fr.pandacube.lib.util.log.Log;
/* package */ class PermissionsResolver {

View File

@ -2,7 +2,7 @@ package fr.pandacube.lib.reflect.wrapper;
import fr.pandacube.lib.reflect.Reflect;
import fr.pandacube.lib.reflect.ReflectConstructor;
import fr.pandacube.lib.util.Log;
import fr.pandacube.lib.util.log.Log;
import java.lang.reflect.Modifier;
import java.util.HashMap;

View File

@ -4,43 +4,39 @@ import java.util.Objects;
import java.util.function.Supplier;
/**
* Represents a lazy loaded value.
*
* The value will be computed using the Supplier provided in the
* constructor, only the first time the {@link #get()} method is
* called.
* A Supplier that cache the value the first time it is called.
*
* @param <T> the type of the enclosed value.
* @param <T> the type of the supplied value.
*/
public class Lazy<T> implements Supplier<T> {
public class CachedSupplier<T> implements Supplier<T> {
private T cachedValue;
private final Supplier<T> supplier;
private final Supplier<T> source;
private boolean cached = false;
/**
* Create a lazy value loader that will call the provided supplier to get the value.
* @param s the supplier from which the value is fetched.
*/
public Lazy(Supplier<T> s) {
supplier = Objects.requireNonNull(s);
public CachedSupplier(Supplier<T> s) {
source = Objects.requireNonNull(s);
}
/**
* Get the wrapped value, from cache or from the provider if it is not yet cached.
*
* Get the value, from cache or from the source supplier if it's not yet cached.
* <p>
* If the provider throws an exception, it will be redirected to the caller as is, and no value will be cached
* (the next call to this method will execute the supplier again).
*/
@Override
public synchronized T get() {
if (!cached)
set(supplier.get());
set(source.get());
return cachedValue;
}
/**
* Reset the cached value. The next call to {@link #get()} will get the value from the provider.
* Reset the cached value. The next call to {@link #get()} will get the value from the source.
*/
public synchronized void reset() {
cached = false;

View File

@ -1,35 +1,31 @@
package fr.pandacube.lib.util;
import fr.pandacube.lib.util.function.SupplierException;
import java.util.Objects;
import fr.pandacube.lib.util.ThrowableUtil.SupplierException;
/**
* Represents a lazy loaded value.
* <p>
* The value will be computed using the Supplier provided in the
* constructor, only the first time the {@link #get()} method is
* called.
* A Supplier that cache the value the first time it is called.
*
* @param <T> the type of the enclosed value.
* @param <E> the exception type
* @param <T> the type of the supplied value.
* @param <E> the exception type that may be thrown by the source supplier.
*/
public class LazyOrException<T, E extends Exception> implements SupplierException<T, E> {
public class CachedSupplierException<T, E extends Exception> implements SupplierException<T, E> {
private T cachedValue;
private final SupplierException<T, E> supplier;
private final SupplierException<T, E> source;
private boolean cached = false;
/**
* Create a lazy value loader that will call the provided supplier to get the value.
* @param s the supplier from which the value is fetched.
*/
public LazyOrException(SupplierException<T, E> s) {
supplier = Objects.requireNonNull(s);
public CachedSupplierException(SupplierException<T, E> s) {
source = Objects.requireNonNull(s);
}
/**
* Get the wrapped value, from cache or from the provider if it is not yet cached.
* Get the value, from cache or from the provider if it's not yet cached.
* <p>
* If the provider throws an exception, it will be redirected to the caller as is, and no value will be cached
* (the next call to this method will execute the supplier again).
@ -37,12 +33,12 @@ public class LazyOrException<T, E extends Exception> implements SupplierExceptio
@Override
public synchronized T get() throws E {
if (!cached)
set(supplier.get());
set(source.get());
return cachedValue;
}
/**
* Reset the cached value. The next call to {@link #get()} will get the value from the provider.
* Reset the cached value. The next call to {@link #get()} will get the value from the source.
*/
public synchronized void reset() {
cached = false;

View File

@ -1,7 +1,7 @@
package fr.pandacube.lib.util;
import fr.pandacube.lib.util.ThrowableUtil.RunnableException;
import fr.pandacube.lib.util.ThrowableUtil.SupplierException;
import fr.pandacube.lib.util.function.RunnableException;
import fr.pandacube.lib.util.function.SupplierException;
import java.util.function.Supplier;

View File

@ -1,5 +1,8 @@
package fr.pandacube.lib.util;
import fr.pandacube.lib.util.function.RunnableException;
import fr.pandacube.lib.util.function.SupplierException;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.PrintStream;
@ -145,101 +148,4 @@ public class ThrowableUtil {
}
/**
* A supplier that can possibly throw a checked exception.
*/
@FunctionalInterface
public interface SupplierException<T, E extends Exception> {
/**
* Gets a result.
* @return a result.
* @throws E if implementation failed to run.
*/
T get() throws E;
}
/**
* A runnable that can possibly throw a checked exception.
*/
@FunctionalInterface
public interface RunnableException<E extends Exception> {
/**
* Run any code implemented.
* @throws E if implementation failed to run.
*/
void run() throws E;
}
/**
* A predicate that can possibly throw a checked exception.
*/
@FunctionalInterface
public interface PredicateException<T, E extends Exception> {
/**
* Test the predicate on the specified value.
* @param value the value to test against.
* @return the result of the test.
* @throws E if implementation failed to run.
*/
boolean test(T value) throws E;
}
/**
* A function that can possibly throw a checked exception.
*/
public interface ToIntBiFunctionException<T, U, E extends Exception> {
/**
* Run on the specified parameters to return an int value.
* @param t the first parameter of the function.
* @param u the second parameter of the function.
* @return the result of the function.
* @throws E if the function fails.
*/
int applyAsInt(T t, U u) throws E;
}
/**
* A consumer that can possibly throw a checked exception.
*/
public interface BiConsumerException<T, U, E extends Exception> {
/**
* Run the consumer on the specified parameters.
* @param t the first parameter of the consumer.
* @param u the second parameter of the consumer.
* @throws E if the function fails.
*/
void accept(T t, U u) throws E;
}
/**
* A consumer that can possibly throw a checked exception.
*/
public interface TriConsumerException<T, U, V, E extends Exception> {
/**
* Run the consumer on the specified parameters.
* @param t the first parameter of the consumer.
* @param u the second parameter of the consumer.
* @param v the tird parameter of the consumer.
* @throws E if the function fails.
*/
void accept(T t, U u, V v) throws E;
}
}

View File

@ -0,0 +1,16 @@
package fr.pandacube.lib.util.function;
/**
* A consumer that can possibly throw a checked exception.
*/
@FunctionalInterface
public interface BiConsumerException<T, U, E extends Exception> {
/**
* Run the consumer on the specified parameters.
*
* @param t the first parameter of the consumer.
* @param u the second parameter of the consumer.
* @throws E if the function fails.
*/
void accept(T t, U u) throws E;
}

View File

@ -0,0 +1,16 @@
package fr.pandacube.lib.util.function;
/**
* A predicate that can possibly throw a checked exception.
*/
@FunctionalInterface
public interface PredicateException<T, E extends Exception> {
/**
* Test the predicate on the specified value.
*
* @param value the value to test against.
* @return the result of the test.
* @throws E if implementation failed to run.
*/
boolean test(T value) throws E;
}

View File

@ -0,0 +1,14 @@
package fr.pandacube.lib.util.function;
/**
* A runnable that can possibly throw a checked exception.
*/
@FunctionalInterface
public interface RunnableException<E extends Exception> {
/**
* Run any code implemented.
*
* @throws E if implementation failed to run.
*/
void run() throws E;
}

View File

@ -0,0 +1,15 @@
package fr.pandacube.lib.util.function;
/**
* A supplier that can possibly throw a checked exception.
*/
@FunctionalInterface
public interface SupplierException<T, E extends Exception> {
/**
* Gets a result.
*
* @return a result.
* @throws E if implementation failed to run.
*/
T get() throws E;
}

View File

@ -0,0 +1,17 @@
package fr.pandacube.lib.util.function;
/**
* A function that can possibly throw a checked exception.
*/
@FunctionalInterface
public interface ToIntBiFunctionException<T, U, E extends Exception> {
/**
* Run on the specified parameters to return an int value.
*
* @param t the first parameter of the function.
* @param u the second parameter of the function.
* @return the result of the function.
* @throws E if the function fails.
*/
int applyAsInt(T t, U u) throws E;
}

View File

@ -0,0 +1,17 @@
package fr.pandacube.lib.util.function;
/**
* A consumer that can possibly throw a checked exception.
*/
@FunctionalInterface
public interface TriConsumerException<T, U, V, E extends Exception> {
/**
* Run the consumer on the specified parameters.
*
* @param t the first parameter of the consumer.
* @param u the second parameter of the consumer.
* @param v the third parameter of the consumer.
* @throws E if the function fails.
*/
void accept(T t, U u, V v) throws E;
}

View File

@ -1,4 +1,4 @@
package fr.pandacube.lib.util.logs;
package fr.pandacube.lib.util.log;
import java.io.BufferedWriter;
import java.io.File;

View File

@ -1,4 +1,4 @@
package fr.pandacube.lib.util;
package fr.pandacube.lib.util.log;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.logging.Level;

View File

@ -1,8 +1,8 @@
package fr.pandacube.lib.ws;
import com.google.gson.JsonParseException;
import fr.pandacube.lib.util.Log;
import fr.pandacube.lib.util.ThrowableUtil.RunnableException;
import fr.pandacube.lib.util.log.Log;
import fr.pandacube.lib.util.function.RunnableException;
import fr.pandacube.lib.ws.payloads.ErrorPayload;
import fr.pandacube.lib.ws.payloads.Payload;