mirror of
https://code.chipmunk.land/Parker2991/NitoriBot/
synced 2026-12-05 08:35:39 -05:00
refactor: utility classes
This commit is contained in:
+4
-4
@@ -1,10 +1,10 @@
|
||||
package land.chipmunk.parker2991.nitoribot.nightofnights.util;
|
||||
|
||||
public final class BetweenUtil {
|
||||
public static double between (
|
||||
int min,
|
||||
int max
|
||||
) {
|
||||
private BetweenUtil () {
|
||||
}
|
||||
|
||||
public static double between (int min, int max) {
|
||||
return Math.floor(Math.random() * (max - min) + min);
|
||||
}
|
||||
}
|
||||
@@ -42,6 +42,9 @@ public final class ComponentUtil {
|
||||
.flattener(getFlattener(false))
|
||||
.build();
|
||||
|
||||
private ComponentUtil () {
|
||||
}
|
||||
|
||||
public static NamedTextColor convertColorString (String color) {
|
||||
return NamedTextColor.NAMES.value(color);
|
||||
}
|
||||
|
||||
+4
-6
@@ -1,16 +1,14 @@
|
||||
package land.chipmunk.parker2991.nitoribot.nightofnights.util;
|
||||
|
||||
public final class FormatTimeUtil {
|
||||
private FormatTimeUtil () {
|
||||
}
|
||||
|
||||
public static String format (double time) {
|
||||
final int hours = (int) Math.floor(time / (60 * 60));
|
||||
final int minutes = (int) Math.floor((time % (60 * 60)) / 60);
|
||||
final int seconds = (int) Math.floor(time % 60);
|
||||
|
||||
return String.format(
|
||||
"%s Hours %s Minutes %s Seconds",
|
||||
hours,
|
||||
minutes,
|
||||
seconds
|
||||
);
|
||||
return String.format("%s Hours %s Minutes %s Seconds", hours, minutes, seconds);
|
||||
}
|
||||
}
|
||||
+7
-12
@@ -8,27 +8,22 @@ import java.net.http.HttpResponse;
|
||||
import java.time.Duration;
|
||||
|
||||
public final class HttpsClientUtil {
|
||||
private HttpsClientUtil () {
|
||||
}
|
||||
|
||||
public static String getRequest (String url) throws IOException, InterruptedException {
|
||||
final HttpClient client = HttpClient
|
||||
.newBuilder()
|
||||
final HttpClient client = HttpClient.newBuilder()
|
||||
.followRedirects(HttpClient.Redirect.NORMAL)
|
||||
.connectTimeout(Duration.ofSeconds(20))
|
||||
.build();
|
||||
|
||||
final HttpRequest request = HttpRequest
|
||||
.newBuilder()
|
||||
final HttpRequest request = HttpRequest.newBuilder()
|
||||
.uri(URI.create(url))
|
||||
.timeout(Duration.ofSeconds(20))
|
||||
.header(
|
||||
"accept",
|
||||
"application/json"
|
||||
)
|
||||
.header("accept", "application/json")
|
||||
.build();
|
||||
|
||||
final HttpResponse<String> response = client.send(
|
||||
request,
|
||||
HttpResponse.BodyHandlers.ofString()
|
||||
);
|
||||
final HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());
|
||||
|
||||
return response.body();
|
||||
}
|
||||
|
||||
@@ -5,13 +5,16 @@ import java.util.concurrent.Executor;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
public final class SleepUtil {
|
||||
public static CompletableFuture<Void> sleep (long ms) {
|
||||
final Executor executor = CompletableFuture.delayedExecutor(
|
||||
ms,
|
||||
TimeUnit.MILLISECONDS
|
||||
);
|
||||
private SleepUtil () {
|
||||
}
|
||||
|
||||
return CompletableFuture.runAsync(() -> {}, executor);
|
||||
public static CompletableFuture<Void> sleep (long ms) {
|
||||
final Executor executor = CompletableFuture.delayedExecutor(ms, TimeUnit.MILLISECONDS);
|
||||
|
||||
return CompletableFuture.runAsync(
|
||||
() -> {
|
||||
}, executor
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@ import org.cloudburstmc.nbt.NbtMapBuilder;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.util.UUID;
|
||||
|
||||
public class UUIDUtil {
|
||||
public final class UUIDUtil {
|
||||
private UUIDUtil () {
|
||||
}
|
||||
|
||||
|
||||
+8
-11
@@ -1,20 +1,17 @@
|
||||
package land.chipmunk.parker2991.nitoribot.nightofnights.util;
|
||||
|
||||
public class UsernameGenUtil {
|
||||
public final class UsernameGenUtil {
|
||||
private static final String CHARACTERS = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
|
||||
|
||||
private UsernameGenUtil () {
|
||||
}
|
||||
|
||||
public static String generateUsername () {
|
||||
String username = "";
|
||||
|
||||
for (
|
||||
int i = 0;
|
||||
i < 3 + Math.floor(Math.random() * 14);
|
||||
i++
|
||||
) {
|
||||
StringBuilder username = new StringBuilder();
|
||||
for (int i = 0; i < 3 + Math.floor(Math.random() * 14); i++) {
|
||||
final int randomIndex = (int) Math.floor(Math.random() * CHARACTERS.length());
|
||||
|
||||
username += CHARACTERS.toCharArray()[randomIndex];
|
||||
username.append(CHARACTERS.toCharArray()[randomIndex]);
|
||||
}
|
||||
return username;
|
||||
return username.toString();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user