Some docs

This commit is contained in:
Marc Baloup 2023-10-28 23:46:47 +02:00
parent 2f0b59a032
commit ecd8b3b0c9
6 changed files with 46 additions and 7 deletions

View File

@ -120,15 +120,27 @@ public abstract sealed class Chat extends ChatStatic implements HoverEventSource
return getAdv(); return getAdv();
} }
public Component getAsDownsampledColorsComponent() { /**
* Builds the component into Adventure Component instance, also down sampling the RGB colors to named colors.
* @return the {@link Component} built from this {@link Chat} component, with down-sampled colors.
*/
public Component getAsDownSampledColorsComponent() {
String json = GsonComponentSerializer.colorDownsamplingGson().serialize(getAdv()); String json = GsonComponentSerializer.colorDownsamplingGson().serialize(getAdv());
return GsonComponentSerializer.gson().deserialize(json); return GsonComponentSerializer.gson().deserialize(json);
} }
public Chat getAsDownsampledColors() { /**
return chatComponent(getAsDownsampledColorsComponent()); * Returns a new {@link Chat} consisting of this {@link Chat} instance, with the RGB colors down-sampled to named colors.
* @return a new {@link Chat} instance, with down-sampled colors.
*/
public Chat getAsDownSampledColors() {
return chatComponent(getAsDownSampledColorsComponent());
} }
/**
* Returns a MiniMessage representation of this {@link Chat} component.
* @return the MiniMessage representation if this {@link Chat} component.
*/
public String getMiniMessage() { public String getMiniMessage() {
return MiniMessage.miniMessage().serialize(getAdv()); return MiniMessage.miniMessage().serialize(getAdv());
} }

View File

@ -93,7 +93,7 @@ public abstract class CLIApplication {
} finally { } finally {
Log.info("Bye bye."); Log.info("Bye bye.");
CLILogger.ShutdownHookDelayerLogManager.resetFinally(); CLILogger.actuallyResetLogManager();
if (!Thread.currentThread().equals(shutdownThread)) if (!Thread.currentThread().equals(shutdownThread))
System.exit(0); System.exit(0);
} }

View File

@ -1,6 +1,7 @@
package fr.pandacube.lib.cli.log; package fr.pandacube.lib.cli.log;
import fr.pandacube.lib.cli.CLI; import fr.pandacube.lib.cli.CLI;
import fr.pandacube.lib.cli.CLIApplication;
import fr.pandacube.lib.util.log.Log; import fr.pandacube.lib.util.log.Log;
import fr.pandacube.lib.util.ThrowableUtil; import fr.pandacube.lib.util.ThrowableUtil;
import fr.pandacube.lib.util.log.DailyLogRotateFileHandler; import fr.pandacube.lib.util.log.DailyLogRotateFileHandler;
@ -28,12 +29,21 @@ public class CLILogger {
private static Logger logger = null; private static Logger logger = null;
public static class ShutdownHookDelayerLogManager extends LogManager { private static class ShutdownHookDelayerLogManager extends LogManager {
static ShutdownHookDelayerLogManager instance; static ShutdownHookDelayerLogManager instance;
public ShutdownHookDelayerLogManager() { instance = this; } public ShutdownHookDelayerLogManager() { instance = this; }
@Override public void reset() { /* don't reset yet. */ } @Override public void reset() { /* don't reset yet. */ }
private void reset0() { super.reset(); } private void actuallyReset() { super.reset(); }
public static void resetFinally() { instance.reset0(); } }
/**
* Tells the LogManager to actually reset.
*
* This method is called by the shutdown hook of {@link CLIApplication}, because the {@link CLILogger} uses a custom
* {@link LogManager} that bypass the reset process during the shutdown of the process.
*/
public static void actuallyResetLogManager() {
ShutdownHookDelayerLogManager.instance.actuallyReset();
} }

View File

@ -51,6 +51,9 @@ public record MinecraftVersionList(
* Gson Adapter that ensure the data in {@link MinecraftVersionList} is sorted correctly when deserializing. * Gson Adapter that ensure the data in {@link MinecraftVersionList} is sorted correctly when deserializing.
*/ */
public static class MinecraftVersionListAdapter implements JsonSerializer<MinecraftVersionList>, JsonDeserializer<MinecraftVersionList> { public static class MinecraftVersionListAdapter implements JsonSerializer<MinecraftVersionList>, JsonDeserializer<MinecraftVersionList> {
/**
* Gson adapter factory for {@link MinecraftVersionList}.
*/
public static final TypeAdapterFactory FACTORY = TreeTypeAdapter.newTypeHierarchyFactory(MinecraftVersionList.class, new MinecraftVersionListAdapter()); public static final TypeAdapterFactory FACTORY = TreeTypeAdapter.newTypeHierarchyFactory(MinecraftVersionList.class, new MinecraftVersionListAdapter());
private static final TypeToken<Map<String, Integer>> MAP_STR_INT_TYPE = new TypeToken<>() { }; private static final TypeToken<Map<String, Integer>> MAP_STR_INT_TYPE = new TypeToken<>() { };

View File

@ -216,10 +216,18 @@ public class ProtocolVersion implements Comparable<ProtocolVersion> {
return displayOptimizedListOfVersions(List.of(this), finalWordSeparator); return displayOptimizedListOfVersions(List.of(this), finalWordSeparator);
} }
/**
* Gets the first (earliest) Minecraft version that supports this protocol version.
* @return the first (earliest) Minecraft version that supports this protocol version.
*/
public String getFirstVersion() { public String getFirstVersion() {
return versions.get(0); return versions.get(0);
} }
/**
* Gets the last (latest) Minecraft version that supports this protocol version.
* @return the last (latest) Minecraft version that supports this protocol version.
*/
public String getLastVersion() { public String getLastVersion() {
return versions.get(versions.size() - 1); return versions.get(versions.size() - 1);
} }

View File

@ -5,8 +5,14 @@ package fr.pandacube.lib.util;
*/ */
public class Tick { public class Tick {
/**
* The number of Minecraft server ticks in a second.
*/
public static final int TPS = 20; public static final int TPS = 20;
/**
* The duration of a Minecraft server tick in millisecond.
*/
public static final int MS_PER_TICK = 1000 / TPS; public static final int MS_PER_TICK = 1000 / TPS;