Skip to content

Commit

Permalink
Update license header, update to java 21 and remove unused imports
Browse files Browse the repository at this point in the history
  • Loading branch information
KiriCattus committed Jun 1, 2024
1 parent 1e0b01c commit e466cc3
Show file tree
Hide file tree
Showing 39 changed files with 458 additions and 454 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ plugins {
group = "com.mcmoddev"
archivesBaseName = "ReLauncher"

java.toolchain.languageVersion = JavaLanguageVersion.of(17)
java.toolchain.languageVersion = JavaLanguageVersion.of(21)

sourceSets {
api {}
Expand Down
7 changes: 4 additions & 3 deletions src/agent/java/com/mcmoddev/relauncher/agent/Agent.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* ReLauncher - https://github.com/MinecraftModDevelopment/ReLauncher
* Copyright (C) 2016-2023 <MMD - MinecraftModDevelopment>
* Copyright (C) 2016-2024 <MMD - MinecraftModDevelopment>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
Expand All @@ -21,8 +21,8 @@
package com.mcmoddev.relauncher.agent;

import com.mcmoddev.relauncher.agent.logback.DiscordLogbackAppender;
import com.mcmoddev.relauncher.api.connector.ProcessConnector;
import com.mcmoddev.relauncher.api.StatusListener;
import com.mcmoddev.relauncher.api.connector.ProcessConnector;

import java.lang.instrument.Instrumentation;
import java.rmi.NotBoundException;
Expand All @@ -38,6 +38,7 @@

public final class Agent {
public static final String VERSION;

static {
var version = Agent.class.getPackage().getImplementationVersion();
if (version == null) {
Expand Down Expand Up @@ -93,7 +94,7 @@ public static void premain(String args, Instrumentation inst) {

public static String colour(String text) {
return "\033[94;1m==== \033[36;1m" + text
+ " \033[94;1m====\033[0m";
+ " \033[94;1m====\033[0m";
}

public static void executeOnListeners(Consumer<? super StatusListener> consumer) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* ReLauncher - https://github.com/MinecraftModDevelopment/ReLauncher
* Copyright (C) 2016-2023 <MMD - MinecraftModDevelopment>
* Copyright (C) 2016-2024 <MMD - MinecraftModDevelopment>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
Expand All @@ -21,10 +21,10 @@
package com.mcmoddev.relauncher.agent;

import com.mcmoddev.relauncher.Properties;
import com.mcmoddev.relauncher.api.StatusListener;
import com.mcmoddev.relauncher.api.connector.MemoryUsage;
import com.mcmoddev.relauncher.api.connector.ProcessConnector;
import com.mcmoddev.relauncher.api.connector.ThreadInfo;
import com.mcmoddev.relauncher.api.StatusListener;

import java.lang.management.ManagementFactory;
import java.lang.management.RuntimeMXBean;
Expand All @@ -41,9 +41,9 @@ public class ProcessConnectorServer implements ProcessConnector {
@Override
public ThreadInfo[] getThreads() throws RemoteException {
return Thread.getAllStackTraces()
.entrySet()
.stream()
.map(e -> ThreadInfo.fromThread(e.getKey(), e.getValue())).toArray(ThreadInfo[]::new);
.entrySet()
.stream()
.map(e -> ThreadInfo.fromThread(e.getKey(), e.getValue())).toArray(ThreadInfo[]::new);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* ReLauncher - https://github.com/MinecraftModDevelopment/ReLauncher
* Copyright (C) 2016-2023 <MMD - MinecraftModDevelopment>
* Copyright (C) 2016-2024 <MMD - MinecraftModDevelopment>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* ReLauncher - https://github.com/MinecraftModDevelopment/ReLauncher
* Copyright (C) 2016-2023 <MMD - MinecraftModDevelopment>
* Copyright (C) 2016-2024 <MMD - MinecraftModDevelopment>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
Expand Down Expand Up @@ -39,6 +39,7 @@ public class DiscordLogbackAppender extends AppenderBase<ILoggingEvent> {
public static final Logger LOG = LoggerFactory.getLogger("DiscordLogbackAppender");

public static final String POST_URL = "https://discord.com/api/v9/webhooks/%s/%s";

public static void setup(String webhookId, String webhookToken) throws ClassNotFoundException, ClassCastException {
final LoggerContext context = (LoggerContext) LoggerFactory.getILoggerFactory();

Expand All @@ -63,13 +64,13 @@ public static void setup(String webhookId, String webhookToken) throws ClassNotF
private Layout<ILoggingEvent> layout;

private final HttpClient client = HttpClient.newBuilder()
.executor(Executors.newSingleThreadExecutor(r -> {
final Thread thread = new Thread(r);
thread.setName("DiscordLoggingAppender");
thread.setDaemon(true);
return thread;
}))
.build();
.executor(Executors.newSingleThreadExecutor(r -> {
final Thread thread = new Thread(r);
thread.setName("DiscordLoggingAppender");
thread.setDaemon(true);
return thread;
}))
.build();

private URI uri;

Expand All @@ -93,15 +94,15 @@ protected void append(final ILoggingEvent eventObject) {
final StringBuffer contentBuf = new StringBuffer();
escape(getMessageContent(eventObject), contentBuf);
final String body = '{' +
"\"content\":\"" + contentBuf + "\"," +
"\"allowed_mentions\":{\"parse\": []}" +
'}';
"\"content\":\"" + contentBuf + "\"," +
"\"allowed_mentions\":{\"parse\": []}" +
'}';
client.send(
HttpRequest.newBuilder(uri)
.header("Content-Type", "application/json")
.POST(HttpRequest.BodyPublishers.ofString(body))
.build(),
HttpResponse.BodyHandlers.ofString()
HttpRequest.newBuilder(uri)
.header("Content-Type", "application/json")
.POST(HttpRequest.BodyPublishers.ofString(body))
.build(),
HttpResponse.BodyHandlers.ofString()
).body();
} catch (IOException | InterruptedException e) {
LOG.error("Error trying to send webhook message: ", e);
Expand All @@ -114,7 +115,7 @@ protected String getMessageContent(final ILoggingEvent event) {

private static void escape(String s, StringBuffer sb) {
final int len = s.length();
for (int i = 0; i < len; i++){
for (int i = 0; i < len; i++) {
char ch = s.charAt(i);
switch (ch) {
case '"':
Expand Down Expand Up @@ -143,7 +144,7 @@ private static void escape(String s, StringBuffer sb) {
break;
default:
//Reference: http://www.unicode.org/versions/Unicode5.1.0/
if (ch <= '\u001F' || ch >= '\u007F' && ch <= '\u009F' || ch >= '\u2000' && ch <= '\u20FF'){
if (ch <= '\u001F' || ch >= '\u007F' && ch <= '\u009F' || ch >= '\u2000' && ch <= '\u20FF') {
String ss = Integer.toHexString(ch);
sb.append("\\u");
sb.append("0".repeat(4 - ss.length()));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* ReLauncher - https://github.com/MinecraftModDevelopment/ReLauncher
* Copyright (C) 2016-2023 <MMD - MinecraftModDevelopment>
* Copyright (C) 2016-2024 <MMD - MinecraftModDevelopment>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
Expand All @@ -25,10 +25,10 @@
import ch.qos.logback.classic.spi.IThrowableProxy;
import ch.qos.logback.core.CoreConstants;
import ch.qos.logback.core.LayoutBase;
import net.dv8tion.jda.api.entities.channel.middleman.GuildChannel;
import net.dv8tion.jda.api.entities.IMentionable;
import net.dv8tion.jda.api.entities.Role;
import net.dv8tion.jda.api.entities.User;
import net.dv8tion.jda.api.entities.channel.middleman.GuildChannel;
import net.dv8tion.jda.api.entities.emoji.Emoji;
import org.slf4j.helpers.MessageFormatter;

Expand All @@ -51,11 +51,11 @@ public class DiscordLogbackLayout extends LayoutBase<ILoggingEvent> {
* Used for visual distinction of log messages within the Discord console channel.
*/
public static final Map<Level, String> LEVEL_TO_EMOTE = Map.of(
Level.ERROR, ":red_square:",
Level.WARN, ":yellow_circle:",
Level.INFO, ":white_medium_small_square:",
Level.DEBUG, ":large_blue_diamond:",
Level.TRACE, ":small_orange_diamond:"
Level.ERROR, ":red_square:",
Level.WARN, ":yellow_circle:",
Level.INFO, ":white_medium_small_square:",
Level.DEBUG, ":large_blue_diamond:",
Level.TRACE, ":small_orange_diamond:"
);
private static final boolean JDA_EXISTS;
/**
Expand Down Expand Up @@ -84,22 +84,22 @@ private static Object tryFormat(final Object obj) {
}
if (obj instanceof Collection<?> col) {
final Stream<Object> stream = col.stream()
.map(DiscordLogbackLayout::tryFormat);
.map(DiscordLogbackLayout::tryFormat);
if (obj instanceof Set) {
return stream.collect(Collectors.toSet());
}
return stream.collect(Collectors.toList());

} else if (obj instanceof Map) {
return ((Map<?, ?>) obj).entrySet().stream()
.map(entry -> new AbstractMap.SimpleImmutableEntry<>(
tryFormat(entry.getKey()), tryFormat(entry.getValue())
))
.collect(Collectors.toUnmodifiableMap(Map.Entry::getKey, Map.Entry::getValue));
.map(entry -> new AbstractMap.SimpleImmutableEntry<>(
tryFormat(entry.getKey()), tryFormat(entry.getValue())
))
.collect(Collectors.toUnmodifiableMap(Map.Entry::getKey, Map.Entry::getValue));

} else if (obj instanceof final Map.Entry<?, ?> entry) {
return new AbstractMap.SimpleImmutableEntry<>(tryFormat(entry.getKey()),
tryFormat(entry.getValue()));
tryFormat(entry.getValue()));

}
return obj;
Expand All @@ -115,27 +115,27 @@ private static Object tryFormat(final Object obj) {
public String doLayout(final ILoggingEvent event) {
final StringBuilder builder = new StringBuilder(2000);
builder
.append(LEVEL_TO_EMOTE.getOrDefault(event.getLevel(), UNKNOWN_EMOTE));
.append(LEVEL_TO_EMOTE.getOrDefault(event.getLevel(), UNKNOWN_EMOTE));
builder
.append(" [**")
.append(event.getLoggerName());
.append(" [**")
.append(event.getLoggerName());
if (event.getMarker() != null) {
builder
.append("**/**")
.append(event.getMarker().getName());
.append("**/**")
.append(event.getMarker().getName());
}
builder
.append("**] - ")
.append(getFormattedMessage(event))
.append(CoreConstants.LINE_SEPARATOR);
.append("**] - ")
.append(getFormattedMessage(event))
.append(CoreConstants.LINE_SEPARATOR);

if (event.getThrowableProxy() != null) {
final var t = event.getThrowableProxy();
builder
.append(t.getClassName())
.append(": ")
.append(t.getMessage())
.append(CoreConstants.LINE_SEPARATOR);
.append(t.getClassName())
.append(": ")
.append(t.getMessage())
.append(CoreConstants.LINE_SEPARATOR);

final StringBuilder stacktrace = buildStacktrace(t);
String stacktraceCutoff = null;
Expand All @@ -146,17 +146,17 @@ public String doLayout(final ILoggingEvent event) {
}

builder.append(CoreConstants.LINE_SEPARATOR)
.append("```ansi")
.append(CoreConstants.LINE_SEPARATOR)
.append(stacktrace)
.append("```");
.append("```ansi")
.append(CoreConstants.LINE_SEPARATOR)
.append(stacktrace)
.append("```");

if (stacktraceCutoff != null) {
builder.append("*Too long to fully display. ")
.append(stacktraceCutoff.length())
.append(" characters or ")
.append(stacktraceCutoff.lines().count())
.append(" lines were truncated.*");
.append(stacktraceCutoff.length())
.append(" characters or ")
.append(stacktraceCutoff.lines().count())
.append(" lines were truncated.*");
}
}
return builder.toString();
Expand All @@ -166,7 +166,7 @@ private StringBuilder buildStacktrace(IThrowableProxy exception) {
final var builder = new StringBuilder();
for (int i = 0; i < exception.getStackTraceElementProxyArray().length; i++) {
builder.append("\t ").append(exception.getStackTraceElementProxyArray()[i].toString())
.append(CoreConstants.LINE_SEPARATOR);
.append(CoreConstants.LINE_SEPARATOR);
}
return builder;
}
Expand Down Expand Up @@ -211,7 +211,7 @@ public static Object format(final Object obj) {
if (obj instanceof IMentionable) {
String name = null;
if (obj instanceof User) {
name = ((User) obj).getAsTag();
name = ((User) obj).getName();
} else if (obj instanceof Role) {
name = ((Role) obj).getName();
} else if (obj instanceof GuildChannel) {
Expand All @@ -221,10 +221,10 @@ public static Object format(final Object obj) {
}
if (name != null) {
return String.format("%s (%s;`%s`)", ((IMentionable) obj).getAsMention(), name, ((IMentionable)
obj).getIdLong());
obj).getIdLong());
} else {
return String.format("%s (`%s`)", ((IMentionable) obj).getAsMention(),
((IMentionable) obj).getIdLong());
((IMentionable) obj).getIdLong());
}
} else {
return null;
Expand Down
2 changes: 1 addition & 1 deletion src/api/java/com/mcmoddev/relauncher/Properties.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* ReLauncher - https://github.com/MinecraftModDevelopment/ReLauncher
* Copyright (C) 2016-2023 <MMD - MinecraftModDevelopment>
* Copyright (C) 2016-2024 <MMD - MinecraftModDevelopment>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* ReLauncher - https://github.com/MinecraftModDevelopment/ReLauncher
* Copyright (C) 2016-2023 <MMD - MinecraftModDevelopment>
* Copyright (C) 2016-2024 <MMD - MinecraftModDevelopment>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
Expand Down Expand Up @@ -52,6 +52,7 @@ public interface BaseProcessManager {

/**
* Kills the currently running process.
*
* @param forcibly if the process should be forcibly destroyed
*/
default void destroy(boolean forcibly) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* ReLauncher - https://github.com/MinecraftModDevelopment/ReLauncher
* Copyright (C) 2016-2023 <MMD - MinecraftModDevelopment>
* Copyright (C) 2016-2024 <MMD - MinecraftModDevelopment>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* ReLauncher - https://github.com/MinecraftModDevelopment/ReLauncher
* Copyright (C) 2016-2023 <MMD - MinecraftModDevelopment>
* Copyright (C) 2016-2024 <MMD - MinecraftModDevelopment>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
Expand Down
2 changes: 1 addition & 1 deletion src/api/java/com/mcmoddev/relauncher/api/JarUpdater.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* ReLauncher - https://github.com/MinecraftModDevelopment/ReLauncher
* Copyright (C) 2016-2023 <MMD - MinecraftModDevelopment>
* Copyright (C) 2016-2024 <MMD - MinecraftModDevelopment>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
Expand Down
5 changes: 3 additions & 2 deletions src/api/java/com/mcmoddev/relauncher/api/LauncherConfig.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* ReLauncher - https://github.com/MinecraftModDevelopment/ReLauncher
* Copyright (C) 2016-2023 <MMD - MinecraftModDevelopment>
* Copyright (C) 2016-2024 <MMD - MinecraftModDevelopment>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
Expand Down Expand Up @@ -65,7 +65,8 @@ default LauncherMode getLauncherMode() {
return LauncherMode.JAR;
}

record CheckingRate(long amount, TimeUnit unit) {}
record CheckingRate(long amount, TimeUnit unit) {
}

enum LauncherMode {
/**
Expand Down
Loading

0 comments on commit e466cc3

Please sign in to comment.