Skip to content

Commit e466cc3

Browse files
committed
Update license header, update to java 21 and remove unused imports
1 parent 1e0b01c commit e466cc3

39 files changed

Lines changed: 458 additions & 454 deletions

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ plugins {
1717
group = "com.mcmoddev"
1818
archivesBaseName = "ReLauncher"
1919

20-
java.toolchain.languageVersion = JavaLanguageVersion.of(17)
20+
java.toolchain.languageVersion = JavaLanguageVersion.of(21)
2121

2222
sourceSets {
2323
api {}

src/agent/java/com/mcmoddev/relauncher/agent/Agent.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
* ReLauncher - https://github.com/MinecraftModDevelopment/ReLauncher
3-
* Copyright (C) 2016-2023 <MMD - MinecraftModDevelopment>
3+
* Copyright (C) 2016-2024 <MMD - MinecraftModDevelopment>
44
*
55
* This library is free software; you can redistribute it and/or
66
* modify it under the terms of the GNU Lesser General Public
@@ -21,8 +21,8 @@
2121
package com.mcmoddev.relauncher.agent;
2222

2323
import com.mcmoddev.relauncher.agent.logback.DiscordLogbackAppender;
24-
import com.mcmoddev.relauncher.api.connector.ProcessConnector;
2524
import com.mcmoddev.relauncher.api.StatusListener;
25+
import com.mcmoddev.relauncher.api.connector.ProcessConnector;
2626

2727
import java.lang.instrument.Instrumentation;
2828
import java.rmi.NotBoundException;
@@ -38,6 +38,7 @@
3838

3939
public final class Agent {
4040
public static final String VERSION;
41+
4142
static {
4243
var version = Agent.class.getPackage().getImplementationVersion();
4344
if (version == null) {
@@ -93,7 +94,7 @@ public static void premain(String args, Instrumentation inst) {
9394

9495
public static String colour(String text) {
9596
return "\033[94;1m==== \033[36;1m" + text
96-
+ " \033[94;1m====\033[0m";
97+
+ " \033[94;1m====\033[0m";
9798
}
9899

99100
public static void executeOnListeners(Consumer<? super StatusListener> consumer) {

src/agent/java/com/mcmoddev/relauncher/agent/ProcessConnectorServer.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
* ReLauncher - https://github.com/MinecraftModDevelopment/ReLauncher
3-
* Copyright (C) 2016-2023 <MMD - MinecraftModDevelopment>
3+
* Copyright (C) 2016-2024 <MMD - MinecraftModDevelopment>
44
*
55
* This library is free software; you can redistribute it and/or
66
* modify it under the terms of the GNU Lesser General Public
@@ -21,10 +21,10 @@
2121
package com.mcmoddev.relauncher.agent;
2222

2323
import com.mcmoddev.relauncher.Properties;
24+
import com.mcmoddev.relauncher.api.StatusListener;
2425
import com.mcmoddev.relauncher.api.connector.MemoryUsage;
2526
import com.mcmoddev.relauncher.api.connector.ProcessConnector;
2627
import com.mcmoddev.relauncher.api.connector.ThreadInfo;
27-
import com.mcmoddev.relauncher.api.StatusListener;
2828

2929
import java.lang.management.ManagementFactory;
3030
import java.lang.management.RuntimeMXBean;
@@ -41,9 +41,9 @@ public class ProcessConnectorServer implements ProcessConnector {
4141
@Override
4242
public ThreadInfo[] getThreads() throws RemoteException {
4343
return Thread.getAllStackTraces()
44-
.entrySet()
45-
.stream()
46-
.map(e -> ThreadInfo.fromThread(e.getKey(), e.getValue())).toArray(ThreadInfo[]::new);
44+
.entrySet()
45+
.stream()
46+
.map(e -> ThreadInfo.fromThread(e.getKey(), e.getValue())).toArray(ThreadInfo[]::new);
4747
}
4848

4949
@Override

src/agent/java/com/mcmoddev/relauncher/agent/ProfilingUtils.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
* ReLauncher - https://github.com/MinecraftModDevelopment/ReLauncher
3-
* Copyright (C) 2016-2023 <MMD - MinecraftModDevelopment>
3+
* Copyright (C) 2016-2024 <MMD - MinecraftModDevelopment>
44
*
55
* This library is free software; you can redistribute it and/or
66
* modify it under the terms of the GNU Lesser General Public

src/agent/java/com/mcmoddev/relauncher/agent/logback/DiscordLogbackAppender.java

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
* ReLauncher - https://github.com/MinecraftModDevelopment/ReLauncher
3-
* Copyright (C) 2016-2023 <MMD - MinecraftModDevelopment>
3+
* Copyright (C) 2016-2024 <MMD - MinecraftModDevelopment>
44
*
55
* This library is free software; you can redistribute it and/or
66
* modify it under the terms of the GNU Lesser General Public
@@ -39,6 +39,7 @@ public class DiscordLogbackAppender extends AppenderBase<ILoggingEvent> {
3939
public static final Logger LOG = LoggerFactory.getLogger("DiscordLogbackAppender");
4040

4141
public static final String POST_URL = "https://discord.com/api/v9/webhooks/%s/%s";
42+
4243
public static void setup(String webhookId, String webhookToken) throws ClassNotFoundException, ClassCastException {
4344
final LoggerContext context = (LoggerContext) LoggerFactory.getILoggerFactory();
4445

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

6566
private final HttpClient client = HttpClient.newBuilder()
66-
.executor(Executors.newSingleThreadExecutor(r -> {
67-
final Thread thread = new Thread(r);
68-
thread.setName("DiscordLoggingAppender");
69-
thread.setDaemon(true);
70-
return thread;
71-
}))
72-
.build();
67+
.executor(Executors.newSingleThreadExecutor(r -> {
68+
final Thread thread = new Thread(r);
69+
thread.setName("DiscordLoggingAppender");
70+
thread.setDaemon(true);
71+
return thread;
72+
}))
73+
.build();
7374

7475
private URI uri;
7576

@@ -93,15 +94,15 @@ protected void append(final ILoggingEvent eventObject) {
9394
final StringBuffer contentBuf = new StringBuffer();
9495
escape(getMessageContent(eventObject), contentBuf);
9596
final String body = '{' +
96-
"\"content\":\"" + contentBuf + "\"," +
97-
"\"allowed_mentions\":{\"parse\": []}" +
98-
'}';
97+
"\"content\":\"" + contentBuf + "\"," +
98+
"\"allowed_mentions\":{\"parse\": []}" +
99+
'}';
99100
client.send(
100-
HttpRequest.newBuilder(uri)
101-
.header("Content-Type", "application/json")
102-
.POST(HttpRequest.BodyPublishers.ofString(body))
103-
.build(),
104-
HttpResponse.BodyHandlers.ofString()
101+
HttpRequest.newBuilder(uri)
102+
.header("Content-Type", "application/json")
103+
.POST(HttpRequest.BodyPublishers.ofString(body))
104+
.build(),
105+
HttpResponse.BodyHandlers.ofString()
105106
).body();
106107
} catch (IOException | InterruptedException e) {
107108
LOG.error("Error trying to send webhook message: ", e);
@@ -114,7 +115,7 @@ protected String getMessageContent(final ILoggingEvent event) {
114115

115116
private static void escape(String s, StringBuffer sb) {
116117
final int len = s.length();
117-
for (int i = 0; i < len; i++){
118+
for (int i = 0; i < len; i++) {
118119
char ch = s.charAt(i);
119120
switch (ch) {
120121
case '"':
@@ -143,7 +144,7 @@ private static void escape(String s, StringBuffer sb) {
143144
break;
144145
default:
145146
//Reference: http://www.unicode.org/versions/Unicode5.1.0/
146-
if (ch <= '\u001F' || ch >= '\u007F' && ch <= '\u009F' || ch >= '\u2000' && ch <= '\u20FF'){
147+
if (ch <= '\u001F' || ch >= '\u007F' && ch <= '\u009F' || ch >= '\u2000' && ch <= '\u20FF') {
147148
String ss = Integer.toHexString(ch);
148149
sb.append("\\u");
149150
sb.append("0".repeat(4 - ss.length()));

src/agent/java/com/mcmoddev/relauncher/agent/logback/DiscordLogbackLayout.java

Lines changed: 37 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
* ReLauncher - https://github.com/MinecraftModDevelopment/ReLauncher
3-
* Copyright (C) 2016-2023 <MMD - MinecraftModDevelopment>
3+
* Copyright (C) 2016-2024 <MMD - MinecraftModDevelopment>
44
*
55
* This library is free software; you can redistribute it and/or
66
* modify it under the terms of the GNU Lesser General Public
@@ -25,10 +25,10 @@
2525
import ch.qos.logback.classic.spi.IThrowableProxy;
2626
import ch.qos.logback.core.CoreConstants;
2727
import ch.qos.logback.core.LayoutBase;
28-
import net.dv8tion.jda.api.entities.channel.middleman.GuildChannel;
2928
import net.dv8tion.jda.api.entities.IMentionable;
3029
import net.dv8tion.jda.api.entities.Role;
3130
import net.dv8tion.jda.api.entities.User;
31+
import net.dv8tion.jda.api.entities.channel.middleman.GuildChannel;
3232
import net.dv8tion.jda.api.entities.emoji.Emoji;
3333
import org.slf4j.helpers.MessageFormatter;
3434

@@ -51,11 +51,11 @@ public class DiscordLogbackLayout extends LayoutBase<ILoggingEvent> {
5151
* Used for visual distinction of log messages within the Discord console channel.
5252
*/
5353
public static final Map<Level, String> LEVEL_TO_EMOTE = Map.of(
54-
Level.ERROR, ":red_square:",
55-
Level.WARN, ":yellow_circle:",
56-
Level.INFO, ":white_medium_small_square:",
57-
Level.DEBUG, ":large_blue_diamond:",
58-
Level.TRACE, ":small_orange_diamond:"
54+
Level.ERROR, ":red_square:",
55+
Level.WARN, ":yellow_circle:",
56+
Level.INFO, ":white_medium_small_square:",
57+
Level.DEBUG, ":large_blue_diamond:",
58+
Level.TRACE, ":small_orange_diamond:"
5959
);
6060
private static final boolean JDA_EXISTS;
6161
/**
@@ -84,22 +84,22 @@ private static Object tryFormat(final Object obj) {
8484
}
8585
if (obj instanceof Collection<?> col) {
8686
final Stream<Object> stream = col.stream()
87-
.map(DiscordLogbackLayout::tryFormat);
87+
.map(DiscordLogbackLayout::tryFormat);
8888
if (obj instanceof Set) {
8989
return stream.collect(Collectors.toSet());
9090
}
9191
return stream.collect(Collectors.toList());
9292

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

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

104104
}
105105
return obj;
@@ -115,27 +115,27 @@ private static Object tryFormat(final Object obj) {
115115
public String doLayout(final ILoggingEvent event) {
116116
final StringBuilder builder = new StringBuilder(2000);
117117
builder
118-
.append(LEVEL_TO_EMOTE.getOrDefault(event.getLevel(), UNKNOWN_EMOTE));
118+
.append(LEVEL_TO_EMOTE.getOrDefault(event.getLevel(), UNKNOWN_EMOTE));
119119
builder
120-
.append(" [**")
121-
.append(event.getLoggerName());
120+
.append(" [**")
121+
.append(event.getLoggerName());
122122
if (event.getMarker() != null) {
123123
builder
124-
.append("**/**")
125-
.append(event.getMarker().getName());
124+
.append("**/**")
125+
.append(event.getMarker().getName());
126126
}
127127
builder
128-
.append("**] - ")
129-
.append(getFormattedMessage(event))
130-
.append(CoreConstants.LINE_SEPARATOR);
128+
.append("**] - ")
129+
.append(getFormattedMessage(event))
130+
.append(CoreConstants.LINE_SEPARATOR);
131131

132132
if (event.getThrowableProxy() != null) {
133133
final var t = event.getThrowableProxy();
134134
builder
135-
.append(t.getClassName())
136-
.append(": ")
137-
.append(t.getMessage())
138-
.append(CoreConstants.LINE_SEPARATOR);
135+
.append(t.getClassName())
136+
.append(": ")
137+
.append(t.getMessage())
138+
.append(CoreConstants.LINE_SEPARATOR);
139139

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

148148
builder.append(CoreConstants.LINE_SEPARATOR)
149-
.append("```ansi")
150-
.append(CoreConstants.LINE_SEPARATOR)
151-
.append(stacktrace)
152-
.append("```");
149+
.append("```ansi")
150+
.append(CoreConstants.LINE_SEPARATOR)
151+
.append(stacktrace)
152+
.append("```");
153153

154154
if (stacktraceCutoff != null) {
155155
builder.append("*Too long to fully display. ")
156-
.append(stacktraceCutoff.length())
157-
.append(" characters or ")
158-
.append(stacktraceCutoff.lines().count())
159-
.append(" lines were truncated.*");
156+
.append(stacktraceCutoff.length())
157+
.append(" characters or ")
158+
.append(stacktraceCutoff.lines().count())
159+
.append(" lines were truncated.*");
160160
}
161161
}
162162
return builder.toString();
@@ -166,7 +166,7 @@ private StringBuilder buildStacktrace(IThrowableProxy exception) {
166166
final var builder = new StringBuilder();
167167
for (int i = 0; i < exception.getStackTraceElementProxyArray().length; i++) {
168168
builder.append("\t ").append(exception.getStackTraceElementProxyArray()[i].toString())
169-
.append(CoreConstants.LINE_SEPARATOR);
169+
.append(CoreConstants.LINE_SEPARATOR);
170170
}
171171
return builder;
172172
}
@@ -211,7 +211,7 @@ public static Object format(final Object obj) {
211211
if (obj instanceof IMentionable) {
212212
String name = null;
213213
if (obj instanceof User) {
214-
name = ((User) obj).getAsTag();
214+
name = ((User) obj).getName();
215215
} else if (obj instanceof Role) {
216216
name = ((Role) obj).getName();
217217
} else if (obj instanceof GuildChannel) {
@@ -221,10 +221,10 @@ public static Object format(final Object obj) {
221221
}
222222
if (name != null) {
223223
return String.format("%s (%s;`%s`)", ((IMentionable) obj).getAsMention(), name, ((IMentionable)
224-
obj).getIdLong());
224+
obj).getIdLong());
225225
} else {
226226
return String.format("%s (`%s`)", ((IMentionable) obj).getAsMention(),
227-
((IMentionable) obj).getIdLong());
227+
((IMentionable) obj).getIdLong());
228228
}
229229
} else {
230230
return null;

src/api/java/com/mcmoddev/relauncher/Properties.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
* ReLauncher - https://github.com/MinecraftModDevelopment/ReLauncher
3-
* Copyright (C) 2016-2023 <MMD - MinecraftModDevelopment>
3+
* Copyright (C) 2016-2024 <MMD - MinecraftModDevelopment>
44
*
55
* This library is free software; you can redistribute it and/or
66
* modify it under the terms of the GNU Lesser General Public

src/api/java/com/mcmoddev/relauncher/api/BaseProcessManager.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
* ReLauncher - https://github.com/MinecraftModDevelopment/ReLauncher
3-
* Copyright (C) 2016-2023 <MMD - MinecraftModDevelopment>
3+
* Copyright (C) 2016-2024 <MMD - MinecraftModDevelopment>
44
*
55
* This library is free software; you can redistribute it and/or
66
* modify it under the terms of the GNU Lesser General Public
@@ -52,6 +52,7 @@ public interface BaseProcessManager {
5252

5353
/**
5454
* Kills the currently running process.
55+
*
5556
* @param forcibly if the process should be forcibly destroyed
5657
*/
5758
default void destroy(boolean forcibly) {

src/api/java/com/mcmoddev/relauncher/api/CustomScriptManager.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
* ReLauncher - https://github.com/MinecraftModDevelopment/ReLauncher
3-
* Copyright (C) 2016-2023 <MMD - MinecraftModDevelopment>
3+
* Copyright (C) 2016-2024 <MMD - MinecraftModDevelopment>
44
*
55
* This library is free software; you can redistribute it and/or
66
* modify it under the terms of the GNU Lesser General Public

src/api/java/com/mcmoddev/relauncher/api/DiscordIntegration.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
* ReLauncher - https://github.com/MinecraftModDevelopment/ReLauncher
3-
* Copyright (C) 2016-2023 <MMD - MinecraftModDevelopment>
3+
* Copyright (C) 2016-2024 <MMD - MinecraftModDevelopment>
44
*
55
* This library is free software; you can redistribute it and/or
66
* modify it under the terms of the GNU Lesser General Public

0 commit comments

Comments
 (0)