Skip to content

Commit

Permalink
Improve javadoc and error messages.
Browse files Browse the repository at this point in the history
  • Loading branch information
Rapha149 committed Dec 13, 2024
1 parent e84d32b commit 8b1bfbe
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package de.rapha149.signgui.exception;

/**
* An exception thrown when the server version is not supported by this api or the support for this version failed to load.
* An exception thrown when the server version is not supported by this api or an error occured during initialization.
*/
public class SignGUIVersionException extends Exception {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,24 +14,37 @@
import java.net.URL;
import java.util.stream.Collectors;

/**
* A utility class to get the version wrapper for the server version.
*/
public class VersionMatcher {

private static boolean initialized;
private static VersionWrapper wrapper;

/**
* Returns the appropriate version wrapper for the current server version.
* If this method is called for the first time, the wrapper is initialized beforehand.
*
* @return The {@link VersionWrapper} instance
* @throws SignGUIVersionException If the server version is not supported by this api or an error occured during initialization.
*/
public static VersionWrapper getWrapper() throws SignGUIVersionException {
if (!initialized) {
initialized = true;
return wrapper = initWrapper();
} else if (wrapper == null) {
throw new SignGUIVersionException("The previous attempt to initialize the version wrapper failed. " +
"This could be because this server version is not supported or " +
"because the support for this server version failed to load.");
"because an error occured during initialization.");
} else {
return wrapper;
}
}

/**
* Internal method to initialize the version wrapper.
*/
private static VersionWrapper initWrapper() throws SignGUIVersionException {
String craftBukkitPackage = Bukkit.getServer().getClass().getPackage().getName();

Expand Down

0 comments on commit 8b1bfbe

Please sign in to comment.