Skip to content

Commit d0536de

Browse files
committed
9.0.1 - updated mc server updater
1 parent 6e6a455 commit d0536de

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+613
-396
lines changed

pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@ AUTO-GENERATED FILE, CHANGES SHOULD BE DONE IN ./JPM.java or ./src/main/java/JPM
1111
<modelVersion>4.0.0</modelVersion>
1212
<groupId>com.osiris.autoplug.client</groupId>
1313
<artifactId>AutoPlug-Client</artifactId>
14-
<version>9.0.0</version>
14+
<version>9.0.1</version>
1515
<properties>
1616
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
1717
<java.version>9</java.version>
18-
<version>9.0.0</version>
18+
<version>9.0.1</version>
1919
<main-class>com.osiris.autoplug.client.Main</main-class>
2020
<slf4j.version>2.0.13</slf4j.version>
2121
<name>AutoPlug-Client</name>

src/main/java/JPM.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public ThisProject(List<String> args) {
2121
// Override default configurations
2222
this.groupId = "com.osiris.autoplug.client";
2323
this.artifactId = "AutoPlug-Client";
24-
this.version = "9.0.0";
24+
this.version = "9.0.1";
2525
this.mainClass = "com.osiris.autoplug.client.Main";
2626
this.jarName = "AutoPlug-Client-original.jar";
2727
this.fatJarName = "AutoPlug-Client.jar";

src/main/java/com/osiris/autoplug/client/configs/MyYaml.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ public Yaml addSingletonConfigFileEventListener(Consumer<FileEvent> listener) th
112112
String preInfo = this.file.getName() + " (" + e.getWatchEventKind() + "): ";
113113
//AL.debug(this.getClass(), preInfo);
114114
if (e.isDeleteEvent())
115-
AL.info(preInfo + "Deleted. Thus clean config with defaults will be created once ist needed.");
115+
AL.info(preInfo + "Deleted. Thus clean config with defaults will be created once its needed.");
116116
if (e.isModifyEvent()) {
117117
synchronized (filesAndPEvents) {
118118
PSave p = filesAndPEvents.get(path);

src/main/java/com/osiris/autoplug/client/configs/UpdaterConfig.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
import com.osiris.dyml.YamlSection;
1515
import com.osiris.dyml.exceptions.*;
1616
import com.osiris.jlib.logger.AL;
17-
import me.hsgamer.mcserverupdater.UpdateBuilder;
17+
import io.github.projectunified.mcserverupdater.UpdateBuilder;
1818

1919
import java.io.IOException;
2020
import java.util.stream.Collectors;

src/main/java/com/osiris/autoplug/client/tasks/updater/server/TaskServerUpdater.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@
2626
import com.osiris.dyml.YamlSection;
2727
import com.osiris.dyml.exceptions.*;
2828
import com.osiris.jlib.logger.AL;
29-
import me.hsgamer.mcserverupdater.UpdateBuilder;
30-
import me.hsgamer.mcserverupdater.UpdateStatus;
29+
import io.github.projectunified.mcserverupdater.UpdateBuilder;
30+
import io.github.projectunified.mcserverupdater.UpdateStatus;
3131
import org.apache.commons.io.FileUtils;
3232

3333
import java.io.File;

src/main/java/me/hsgamer/mcserverupdater/UpdateBuilder.java renamed to src/main/java/io/github/projectunified/mcserverupdater/UpdateBuilder.java

Lines changed: 51 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,25 @@
1-
package me.hsgamer.mcserverupdater;
1+
package io.github.projectunified.mcserverupdater;
22

3-
import me.hsgamer.hscore.collections.map.CaseInsensitiveStringLinkedMap;
4-
import me.hsgamer.hscore.logger.common.LogLevel;
5-
import me.hsgamer.hscore.logger.common.Logger;
6-
import me.hsgamer.mcserverupdater.api.Checksum;
7-
import me.hsgamer.mcserverupdater.api.Updater;
8-
import me.hsgamer.mcserverupdater.updater.*;
9-
import me.hsgamer.mcserverupdater.util.Utils;
10-
import me.hsgamer.mcserverupdater.util.VersionQuery;
3+
import io.github.projectunified.mcserverupdater.api.Checksum;
4+
import io.github.projectunified.mcserverupdater.api.DebugConsumer;
5+
import io.github.projectunified.mcserverupdater.api.Updater;
6+
import io.github.projectunified.mcserverupdater.updater.*;
7+
import io.github.projectunified.mcserverupdater.util.Utils;
8+
import io.github.projectunified.mcserverupdater.util.VersionQuery;
119

1210
import java.io.File;
1311
import java.io.IOException;
14-
import java.util.Map;
15-
import java.util.Optional;
16-
import java.util.Set;
12+
import java.util.*;
1713
import java.util.concurrent.CompletableFuture;
1814
import java.util.concurrent.CompletionException;
1915
import java.util.concurrent.ExecutionException;
20-
import java.util.function.Consumer;
2116
import java.util.function.Function;
2217

2318
/**
2419
* Where to create the update process
2520
*/
2621
public final class UpdateBuilder {
27-
private static final Map<String, Function<VersionQuery, Updater>> UPDATERS = new CaseInsensitiveStringLinkedMap<>();
22+
private static final Map<String, Function<VersionQuery, Updater>> UPDATERS = new HashMap<>();
2823

2924
static {
3025
registerUpdater(versionQuery -> new PaperUpdater(versionQuery, "paper"), "paper", "papermc", "paperspigot");
@@ -46,6 +41,7 @@ public final class UpdateBuilder {
4641
}
4742
registerUpdater(versionQuery -> new MohistUpdater(versionQuery, "mohist"), "mohist");
4843
registerUpdater(versionQuery -> new MohistUpdater(versionQuery, "banner"), "banner");
44+
registerUpdater(versionQuery -> new MohistUpdater(versionQuery, "youer"), "youer");
4945
registerUpdater(PlazmaUpdater::new, "plazma");
5046
registerUpdater(DivineUpdater::new, "divine", "divinemc");
5147
registerUpdater(LeafUpdater::new, "leaf");
@@ -55,6 +51,7 @@ public final class UpdateBuilder {
5551
registerUpdater(versionQuery -> new MultiPaperUpdater(versionQuery, "multipaper"), "multipaper");
5652
registerUpdater(versionQuery -> new MultiPaperUpdater(versionQuery, "multipaper", "master"), "multipaper-master");
5753
registerUpdater(versionQuery -> new MultiPaperUpdater(versionQuery, "shreddedpaper"), "shreddedpaper");
54+
registerUpdater(GeyserUpdater::new, "geyser", "geysermc");
5855
}
5956

6057
private final String project;
@@ -65,8 +62,9 @@ public final class UpdateBuilder {
6562
private ChecksumSupplier checksumSupplier = () -> "";
6663
private ChecksumConsumer checksumConsumer = s -> {
6764
};
68-
private Logger logger = (logLevel, s) -> {
65+
private DebugConsumer debugConsumer = s -> {
6966
};
67+
private String userAgent;
7068

7169
private UpdateBuilder(String project) {
7270
this.project = project;
@@ -178,25 +176,15 @@ public UpdateBuilder checksumConsumer(ChecksumConsumer checksumConsumer) {
178176
return this;
179177
}
180178

181-
/**
182-
* Set the logger
183-
*
184-
* @param logger the logger
185-
* @return the update process
186-
*/
187-
public UpdateBuilder logger(Logger logger) {
188-
this.logger = logger;
189-
return this;
190-
}
191-
192179
/**
193180
* Set the debug consumer
194181
*
195182
* @param debugConsumer the debug consumer
196183
* @return the update process
197184
*/
198-
public UpdateBuilder debugConsumer(Consumer<String> debugConsumer) {
199-
return logger((logLevel, s) -> debugConsumer.accept("[" + logLevel.name() + "] " + s));
185+
public UpdateBuilder debugConsumer(DebugConsumer debugConsumer) {
186+
this.debugConsumer = debugConsumer;
187+
return this;
200188
}
201189

202190
/**
@@ -241,6 +229,17 @@ public UpdateBuilder checkOnly(boolean checkOnly) {
241229
return this;
242230
}
243231

232+
/**
233+
* Set the user agent for the update process
234+
*
235+
* @param userAgent the user agent string
236+
* @return the update process
237+
*/
238+
public UpdateBuilder userAgent(String userAgent) {
239+
this.userAgent = userAgent;
240+
return this;
241+
}
242+
244243
/**
245244
* Get the checksum consumer
246245
*
@@ -282,12 +281,21 @@ public File workingDirectory() {
282281
}
283282

284283
/**
285-
* Get the logger
284+
* Get the debug consumer
286285
*
287-
* @return the logger
286+
* @return the debug consumer
288287
*/
289-
public Logger logger() {
290-
return logger;
288+
public DebugConsumer debugConsumer() {
289+
return debugConsumer;
290+
}
291+
292+
/**
293+
* Get the user agent
294+
*
295+
* @return the user agent string
296+
*/
297+
public String userAgent() {
298+
return userAgent;
291299
}
292300

293301
/**
@@ -296,7 +304,7 @@ public Logger logger() {
296304
* @param message the message
297305
*/
298306
public void debug(String message) {
299-
logger.log(LogLevel.DEBUG, message);
307+
debugConsumer.consume(message);
300308
}
301309

302310
/**
@@ -307,15 +315,20 @@ public void debug(String message) {
307315
public CompletableFuture<UpdateStatus> executeAsync() {
308316
return CompletableFuture.supplyAsync(() -> {
309317
VersionQuery versionQuery = new VersionQuery(version, this);
310-
Updater update = Optional.ofNullable(UPDATERS.get(project)).map(f -> f.apply(versionQuery)).orElse(null);
318+
Updater update = Optional.ofNullable(UPDATERS.get(project.toLowerCase(Locale.ROOT))).map(f -> f.apply(versionQuery)).orElse(null);
311319
if (update == null) {
312320
return UpdateStatus.NO_PROJECT;
313321
}
314322

323+
Checksum checksum = update.getChecksumChecker();
324+
325+
if (checkOnly && checksum == null) {
326+
return UpdateStatus.FAILED;
327+
}
328+
315329
try {
316330
if (outputFile.exists()) {
317-
if (update instanceof Checksum) {
318-
Checksum checksum = (Checksum) update;
331+
if (checksum != null) {
319332
if (checksum.checksum(outputFile)) {
320333
return UpdateStatus.UP_TO_DATE;
321334
} else if (checkOnly) {
@@ -331,8 +344,8 @@ public CompletableFuture<UpdateStatus> executeAsync() {
331344

332345
try {
333346
if (update.update(outputFile)) {
334-
if (update instanceof Checksum) {
335-
((Checksum) update).setChecksum(outputFile);
347+
if (checksum != null) {
348+
checksum.setChecksum(outputFile);
336349
}
337350
return UpdateStatus.SUCCESS;
338351
} else {

src/main/java/me/hsgamer/mcserverupdater/UpdateStatus.java renamed to src/main/java/io/github/projectunified/mcserverupdater/UpdateStatus.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package me.hsgamer.mcserverupdater;
1+
package io.github.projectunified.mcserverupdater;
22

33
/**
44
* The update status

src/main/java/me/hsgamer/mcserverupdater/api/BibliothekUpdater.java renamed to src/main/java/io/github/projectunified/mcserverupdater/api/BibliothekUpdater.java

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
1-
package me.hsgamer.mcserverupdater.api;
1+
package io.github.projectunified.mcserverupdater.api;
22

3-
import me.hsgamer.hscore.logger.common.Logger;
4-
import me.hsgamer.hscore.web.UserAgent;
5-
import me.hsgamer.hscore.web.WebUtils;
6-
import me.hsgamer.mcserverupdater.UpdateBuilder;
7-
import me.hsgamer.mcserverupdater.util.VersionQuery;
3+
import io.github.projectunified.mcserverupdater.UpdateBuilder;
4+
import io.github.projectunified.mcserverupdater.api.checksum.FileDigestChecksum;
5+
import io.github.projectunified.mcserverupdater.util.VersionQuery;
6+
import io.github.projectunified.mcserverupdater.util.WebUtils;
87
import org.json.JSONArray;
98
import org.json.JSONObject;
109
import org.json.JSONTokener;
@@ -13,7 +12,7 @@
1312
import java.io.InputStream;
1413
import java.net.URLConnection;
1514

16-
public abstract class BibliothekUpdater implements UrlInputStreamUpdater, FileDigestChecksum {
15+
public abstract class BibliothekUpdater implements InputStreamUpdater, FileDigestChecksum {
1716
private final UpdateBuilder updateBuilder;
1817
private final String version;
1918
private final String build;
@@ -45,7 +44,7 @@ protected BibliothekUpdater(VersionQuery versionQuery, String project) {
4544
private String getDefaultVersion() {
4645
updateBuilder.debug("Getting default version from " + projectUrl);
4746
try {
48-
URLConnection connection = UserAgent.CHROME.assignToConnection(WebUtils.createConnection(projectUrl));
47+
URLConnection connection = WebUtils.openConnection(projectUrl, updateBuilder);
4948
InputStream inputStream = connection.getInputStream();
5049
JSONObject jsonObject = new JSONObject(new JSONTokener(inputStream));
5150
JSONArray builds = jsonObject.getJSONArray("versions");
@@ -59,7 +58,7 @@ private String getBuild() {
5958
String formattedUrl = String.format(versionUrl, version);
6059
updateBuilder.debug("Getting latest build from " + formattedUrl);
6160
try {
62-
URLConnection connection = UserAgent.CHROME.assignToConnection(WebUtils.createConnection(formattedUrl));
61+
URLConnection connection = WebUtils.openConnection(formattedUrl, updateBuilder);
6362
InputStream inputStream = connection.getInputStream();
6463
JSONObject jsonObject = new JSONObject(new JSONTokener(inputStream));
6564
JSONArray builds = jsonObject.getJSONArray("builds");
@@ -72,7 +71,7 @@ private String getBuild() {
7271
private JSONObject getDownload() throws IOException {
7372
String formattedUrl = String.format(buildUrl, version, build);
7473
updateBuilder.debug("Getting download from " + formattedUrl);
75-
URLConnection connection = UserAgent.CHROME.assignToConnection(WebUtils.createConnection(formattedUrl));
74+
URLConnection connection = WebUtils.openConnection(formattedUrl, updateBuilder);
7675
InputStream inputStream = connection.getInputStream();
7776
JSONObject jsonObject = new JSONObject(new JSONTokener(inputStream));
7877
JSONObject downloads = jsonObject.getJSONObject("downloads");
@@ -85,13 +84,18 @@ public final String getChecksum() {
8584
JSONObject application = getDownload();
8685
return application.getString(getChecksumAlgorithm());
8786
} catch (Exception e) {
88-
e.printStackTrace();
87+
debug("Failed to get checksum", e);
8988
return null;
9089
}
9190
}
9291

9392
@Override
94-
public final String getFileUrl() {
93+
public Checksum getChecksumChecker() {
94+
return this;
95+
}
96+
97+
@Override
98+
public InputStream getInputStream() {
9599
String downloadName;
96100
try {
97101
JSONObject application = getDownload();
@@ -100,11 +104,12 @@ public final String getFileUrl() {
100104
debug(e);
101105
return null;
102106
}
103-
return String.format(downloadUrl, version, build, downloadName);
107+
String url = String.format(downloadUrl, version, build, downloadName);
108+
return WebUtils.getInputStreamOrNull(url, updateBuilder);
104109
}
105110

106111
@Override
107-
public final Logger getLogger() {
108-
return updateBuilder.logger();
112+
public DebugConsumer getDebugConsumer() {
113+
return updateBuilder.debugConsumer();
109114
}
110115
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package io.github.projectunified.mcserverupdater.api;
2+
3+
import java.io.File;
4+
5+
public interface Checksum {
6+
boolean checksum(File file) throws Exception;
7+
8+
void setChecksum(File file) throws Exception;
9+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package io.github.projectunified.mcserverupdater.api;
2+
3+
public interface DebugConsumer {
4+
void consume(String message);
5+
6+
default void consume(Throwable throwable) {
7+
consume(throwable.getClass().getSimpleName() + ": " + throwable.getMessage());
8+
for (StackTraceElement element : throwable.getStackTrace()) {
9+
consume(" at " + element.toString());
10+
}
11+
}
12+
13+
default void consume(String message, Throwable throwable) {
14+
consume(message);
15+
consume(throwable);
16+
}
17+
}

0 commit comments

Comments
 (0)