Skip to content

Commit

Permalink
General code cleanup and improvements (#57)
Browse files Browse the repository at this point in the history
* style(api): small codestyle improvements and QoL updates

* style: reformat code using IntelliJ's code refactoring tool
  • Loading branch information
jonesdevelopment authored Oct 6, 2023
1 parent b45626e commit 3faf8c8
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 13 deletions.
13 changes: 7 additions & 6 deletions sonar-api/src/main/java/xyz/jonesdev/sonar/api/Sonar.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ public interface Sonar {
/**
* Set a custom verbose handler
*/
@SuppressWarnings("unused")
void setVerboseHandler(final @NotNull Verbose verboseHandler);

/**
Expand All @@ -65,19 +66,19 @@ public interface Sonar {
void reload();

@NotNull
default SonarEventManager getEventManager() {
return SonarEventManager.INSTANCE;
default SonarVersion getVersion() {
return SonarVersion.GET;
}

@NotNull
default SonarVersion getVersion() {
return SonarVersion.GET;
default SonarEventManager getEventManager() {
// We don't want anyone else to create a new instance.
return SonarEventManager.INSTANCE;
}

@NotNull
default Fallback getFallback() {
// We only have one single instance of Fallback,
// and we don't want anyone else to create a new instance.
// We don't want anyone else to create a new instance.
return Fallback.INSTANCE;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -623,7 +623,8 @@ public void load() {
))));

messagesConfig.getYaml().setComment("messages.verification.too-many-online-per-ip",
"Disconnect message that is shown when someone joins but there are too many online players with their IP address");
"Disconnect message that is shown when someone joins but there are too many online players with their IP " +
"address");
tooManyOnlinePerIp = deserialize(fromList(messagesConfig.getStringList("messages.too-many-online-per-ip",
Arrays.asList(
"%header%",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,17 +50,17 @@ public final class Fallback {

@Override
public void info(final String message, final Object... args) {
SONAR.getLogger().info("[Fallback] " + message, args);
SONAR.getLogger().info("[fallback] " + message, args);
}

@Override
public void warn(final String message, final Object... args) {
SONAR.getLogger().warn("[Fallback] " + message, args);
SONAR.getLogger().warn("[fallback] " + message, args);
}

@Override
public void error(final String message, final Object... args) {
SONAR.getLogger().error("[Fallback] " + message, args);
SONAR.getLogger().error("[fallback] " + message, args);
}
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -414,7 +414,8 @@ private void finish() {
user.getFallback().getConnected().remove(username);

// Add verified player to the database
final VerifiedPlayer verifiedPlayer = new VerifiedPlayer(user.getInetAddress().toString(), playerUuid, login.getStart());
final VerifiedPlayer verifiedPlayer = new VerifiedPlayer(user.getInetAddress().toString(), playerUuid,
login.getStart());
Sonar.get().getVerifiedPlayerController().add(verifiedPlayer);

// Call the VerifySuccessEvent for external API usage
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ public void checkForUpdates() {
LOGGER.info("You are currently using the latest stable release of Sonar!");
} else {
LOGGER.warn("You are currently using the latest development version of Sonar!");
LOGGER.warn("The contributors of Sonar are not responsible for any damage done by using an unstable version.");
LOGGER.warn("The contributors of Sonar are not responsible for any damage done by using an unstable version" +
".");
}
} catch (Exception exception) {
LOGGER.warn("Could not retrieve latest version information: {}", exception);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,8 @@ public void handle(final @NotNull PreLoginEvent event) throws Throwable {
// Check if the username matches the valid name regex in order to prevent
// UTF-16 names or other types of flood attacks
if (!Sonar.get().getConfig().getValidNameRegex().matcher(event.getUsername()).matches()) {
mcConnection.closeWith(Disconnect.create(Sonar.get().getConfig().getInvalidUsername(), mcConnection.getProtocolVersion()));
mcConnection.closeWith(Disconnect.create(Sonar.get().getConfig().getInvalidUsername(),
mcConnection.getProtocolVersion()));
return;
}

Expand Down

0 comments on commit 3faf8c8

Please sign in to comment.