event) {
67 | this.onExited = event;
68 | return this;
69 | }
70 |
71 | @Override
72 | public void mouseExited(MouseEvent e) {
73 | if (onExited != null) onExited.accept(e);
74 | }
75 | }
76 |
--------------------------------------------------------------------------------
/src/main/java/com/osiris/autoplug/client/utils/ConsoleOutputCapturer.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2021-2023 Osiris-Team.
3 | * All rights reserved.
4 | *
5 | * This software is copyrighted work, licensed under the terms
6 | * of the MIT-License. Consult the "LICENSE" file for details.
7 | */
8 | package com.osiris.autoplug.client.utils;
9 |
10 | import java.io.ByteArrayOutputStream;
11 | import java.io.OutputStream;
12 | import java.io.PrintStream;
13 | import java.io.UnsupportedEncodingException;
14 | import java.nio.charset.StandardCharsets;
15 |
16 | public class ConsoleOutputCapturer {
17 | private final ByteArrayOutputStream baos = new ByteArrayOutputStream();
18 | private final PrintStream ps = new PrintStream(baos);
19 | private final PrintStream oldOut = System.out;
20 | private final PrintStream oldErr = System.err;
21 |
22 | public void start() {
23 | System.setOut(new PrintStream(new OutputStream() {
24 | @Override
25 | public void write(int b) {
26 | ps.write(b);
27 | oldOut.write(b);
28 | }
29 |
30 | @Override
31 | public void write(byte[] b, int off, int len) {
32 | ps.write(b, off, len);
33 | oldOut.write(b, off, len);
34 | }
35 | }));
36 |
37 | System.setErr(new PrintStream(new OutputStream() {
38 | @Override
39 | public void write(int b) {
40 | ps.write(b);
41 | oldErr.write(b);
42 | }
43 |
44 | @Override
45 | public void write(byte[] b, int off, int len) {
46 | ps.write(b, off, len);
47 | oldErr.write(b, off, len);
48 | }
49 | }));
50 | }
51 |
52 | public void stop() {
53 | System.setOut(oldOut);
54 | System.setErr(oldErr);
55 | }
56 |
57 | public String getNewOutput() {
58 | String newOutput = null;
59 | try {
60 | newOutput = baos.toString(StandardCharsets.UTF_8.name());
61 | } catch (UnsupportedEncodingException e) {
62 | throw new RuntimeException(e); // Never should be thrown
63 | }
64 | baos.reset();
65 | return newOutput;
66 | }
67 | }
68 |
--------------------------------------------------------------------------------
/src/main/java/com/osiris/autoplug/client/utils/GD.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2021-2023 Osiris-Team.
3 | * All rights reserved.
4 | *
5 | * This software is copyrighted work, licensed under the terms
6 | * of the MIT-License. Consult the "LICENSE" file for details.
7 | */
8 |
9 | package com.osiris.autoplug.client.utils;
10 |
11 | import com.osiris.autoplug.client.Target;
12 | import com.osiris.autoplug.client.configs.GeneralConfig;
13 | import com.osiris.dyml.exceptions.DuplicateKeyException;
14 | import com.osiris.dyml.exceptions.IllegalListException;
15 | import com.osiris.dyml.exceptions.YamlReaderException;
16 | import com.osiris.dyml.exceptions.YamlWriterException;
17 | import com.osiris.jlib.logger.AL;
18 | import org.jetbrains.annotations.NotNull;
19 |
20 | import java.io.File;
21 | import java.io.IOException;
22 | import java.util.Scanner;
23 |
24 | /**
25 | * GlobalData, which is always static and used frequently in this project
26 | */
27 | public class GD {
28 | public static final String AUTHOR = "Osiris-Team";
29 | public static final File FILE_ERR_OUT = new File(System.getProperty("user.dir") + "/autoplug/logs/console-mirror-err.log");
30 | // TODO make all of these not static and deprecate this class
31 | public static String OFFICIAL_WEBSITE = "https://autoplug.one/";
32 | public static boolean IS_TEST_MODE = false;
33 | @NotNull
34 | public static String VERSION = "AutoPlug-Client (ERROR RETRIEVING VERSION)";
35 | public static File WORKING_DIR;
36 | public static File PLUGINS_DIR;
37 | public static File DOWNLOADS_DIR;
38 | public static File AP_LATEST_LOG = new File(System.getProperty("user.dir") + "/autoplug/logs/latest.log");
39 | public static File SYSTEM_LATEST_LOG = new File(System.getProperty("user.dir") + "/autoplug/logs/system-latest.log");
40 | public static File FILE_OUT = new File(System.getProperty("user.dir") + "/autoplug/logs/console-mirror.log");
41 | public static Target TARGET = null;
42 |
43 | static {
44 | WORKING_DIR = new File(System.getProperty("user.dir"));
45 | PLUGINS_DIR = new File(System.getProperty("user.dir") + "/plugins");
46 | DOWNLOADS_DIR = new File(System.getProperty("user.dir") + "/autoplug/downloads");
47 | try {
48 | VERSION = "AutoPlug-Client " + new UtilsJar().getThisJarsAutoPlugProperties().getProperty("version");
49 | } catch (Exception e) {
50 | System.err.println("Failed to determine AutoPlug-Client version. More details below. Keep in mind that" +
51 | " the exception is ignored and does not further affect the application.");
52 | e.printStackTrace();
53 | }
54 | }
55 |
56 | public static String errorMsgFailedToGetMCVersion() {
57 | return "Failed to determine Minecraft version. Make sure the server jar exists or the version is provided in general.yml or updater.yml.";
58 | }
59 |
60 | public static void determineTarget(GeneralConfig generalConfig) throws YamlReaderException, YamlWriterException, IOException, DuplicateKeyException, IllegalListException {
61 | String target = generalConfig.autoplug_target_software.asString();
62 | while (true) {
63 | if (target == null) {
64 | for (String comment : generalConfig.autoplug_target_software.getComments()) {
65 | AL.info(comment);
66 | }
67 | AL.info("Please enter a valid option and press enter:");
68 | target = new Scanner(System.in).nextLine();
69 | generalConfig.autoplug_target_software.setValues(target);
70 | generalConfig.save();
71 | } else {
72 | TARGET = Target.fromString(target);
73 | if (TARGET != null) break;
74 | for (String comment : generalConfig.autoplug_target_software.getComments()) {
75 | AL.info(comment);
76 | }
77 | AL.info("The selected target software '" + target + "' is not a valid option.");
78 | AL.info("Please enter a valid option and press enter:");
79 | target = new Scanner(System.in).nextLine();
80 | generalConfig.autoplug_target_software.setValues(target);
81 | generalConfig.save();
82 | }
83 | }
84 | }
85 | }
86 |
--------------------------------------------------------------------------------
/src/main/java/com/osiris/autoplug/client/utils/Streams.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2022 Osiris-Team.
3 | * All rights reserved.
4 | *
5 | * This software is copyrighted work, licensed under the terms
6 | * of the MIT-License. Consult the "LICENSE" file for details.
7 | */
8 |
9 | package com.osiris.autoplug.client.utils;
10 |
11 | import java.io.BufferedReader;
12 | import java.io.IOException;
13 | import java.io.InputStream;
14 | import java.io.InputStreamReader;
15 |
16 | public class Streams {
17 | public String read(InputStream in) throws IOException {
18 | if (in == null) return null;
19 | StringBuilder s = new StringBuilder();
20 | try (BufferedReader reader = new BufferedReader(new InputStreamReader(in))) {
21 | String l = null;
22 | while ((l = reader.readLine()) != null) {
23 | s.append(l + "\n");
24 | }
25 | }
26 | return s.toString();
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/src/main/java/com/osiris/autoplug/client/utils/StringComparator.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2021 Osiris-Team.
3 | * All rights reserved.
4 | *
5 | * This software is copyrighted work, licensed under the terms
6 | * of the MIT-License. Consult the "LICENSE" file for details.
7 | */
8 |
9 | package com.osiris.autoplug.client.utils;
10 |
11 | public class StringComparator {
12 |
13 | /**
14 | * Calculates the similarity (a number within 0 and 1) between two strings.
15 | */
16 | public static synchronized double similarity(String s1, String s2) {
17 | String longer = s1, shorter = s2;
18 | if (s1.length() < s2.length()) { // longer should always have greater length
19 | longer = s2;
20 | shorter = s1;
21 | }
22 | int longerLength = longer.length();
23 | if (longerLength == 0) {
24 | return 1.0; /* both strings are zero length */
25 | }
26 | /* // If you have StringUtils, you can use it to calculate the edit distance:
27 | return (longerLength - StringUtils.getLevenshteinDistance(longer, shorter)) /
28 | (double) longerLength; */
29 | return (longerLength - editDistance(longer, shorter)) / (double) longerLength;
30 |
31 | }
32 |
33 | // Example implementation of the Levenshtein Edit Distance
34 | // See http://r...content-available-to-author-only...e.org/wiki/Levenshtein_distance#Java
35 | public static synchronized int editDistance(String s1, String s2) {
36 | s1 = s1.toLowerCase();
37 | s2 = s2.toLowerCase();
38 |
39 | int[] costs = new int[s2.length() + 1];
40 | for (int i = 0; i <= s1.length(); i++) {
41 | int lastValue = i;
42 | for (int j = 0; j <= s2.length(); j++) {
43 | if (i == 0)
44 | costs[j] = j;
45 | else {
46 | if (j > 0) {
47 | int newValue = costs[j - 1];
48 | if (s1.charAt(i - 1) != s2.charAt(j - 1))
49 | newValue = Math.min(Math.min(newValue, lastValue),
50 | costs[j]) + 1;
51 | costs[j - 1] = lastValue;
52 | lastValue = newValue;
53 | }
54 | }
55 | }
56 | if (i > 0)
57 | costs[s2.length()] = lastValue;
58 | }
59 | return costs[s2.length()];
60 | }
61 |
62 | //You can use this to print out the similarity
63 | public static void printSimilarity(String s, String t) {
64 | System.out.printf("%.3f is the similarity between \"%s\" and \"%s\"%n", similarity(s, t), s, t);
65 | }
66 |
67 | }
68 |
--------------------------------------------------------------------------------
/src/main/java/com/osiris/autoplug/client/utils/UpdateCheckerThread.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2023 Osiris-Team.
3 | * All rights reserved.
4 | *
5 | * This software is copyrighted work, licensed under the terms
6 | * of the MIT-License. Consult the "LICENSE" file for details.
7 | */
8 |
9 | package com.osiris.autoplug.client.utils;
10 |
11 | import com.osiris.autoplug.client.configs.SystemConfig;
12 | import com.osiris.autoplug.client.configs.UpdaterConfig;
13 | import com.osiris.autoplug.client.tasks.updater.java.TaskJavaUpdater;
14 | import com.osiris.autoplug.client.tasks.updater.mods.TaskModsUpdater;
15 | import com.osiris.autoplug.client.tasks.updater.plugins.TaskPluginsUpdater;
16 | import com.osiris.autoplug.client.tasks.updater.self.TaskSelfUpdater;
17 | import com.osiris.autoplug.client.tasks.updater.server.TaskServerUpdater;
18 | import com.osiris.autoplug.client.utils.tasks.MyBThreadManager;
19 | import com.osiris.autoplug.client.utils.tasks.UtilsTasks;
20 | import com.osiris.jlib.logger.AL;
21 |
22 | import java.text.SimpleDateFormat;
23 |
24 | public class UpdateCheckerThread extends Thread {
25 | public boolean isRunning = false;
26 |
27 | @Override
28 | public void run() {
29 | try {
30 | isRunning = true;
31 | while (isRunning) {
32 | long last = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss")
33 | .parse(new SystemConfig().timestamp_last_updater_tasks.asString())
34 | .getTime();
35 | long now1 = System.currentTimeMillis();
36 | long msSinceLast = now1 - last;
37 | long msLeft = (new UpdaterConfig().global_recurring_checks_intervall.asInt() * 3600000L) // 1h in ms
38 | - msSinceLast;
39 | if (msLeft > 0) Thread.sleep(msLeft);
40 | AL.info("Running tasks from recurring update-checker thread.");
41 | MyBThreadManager man = new UtilsTasks().createManagerAndPrinter();
42 | TaskSelfUpdater selfUpdater = new TaskSelfUpdater("SelfUpdater", man.manager);
43 | TaskJavaUpdater taskJavaUpdater = new TaskJavaUpdater("JavaUpdater", man.manager);
44 | TaskServerUpdater taskServerUpdater = new TaskServerUpdater("ServerUpdater", man.manager);
45 | TaskPluginsUpdater taskPluginsUpdater = new TaskPluginsUpdater("PluginsUpdater", man.manager);
46 | TaskModsUpdater taskModsUpdater = new TaskModsUpdater("ModsUpdater", man.manager);
47 | selfUpdater.start();
48 | while (!selfUpdater.isFinished()) // Wait until the self updater finishes
49 | Thread.sleep(1000);
50 | taskJavaUpdater.start();
51 | taskServerUpdater.start();
52 | taskPluginsUpdater.start();
53 | taskModsUpdater.start();
54 | while (!man.manager.isFinished())
55 | Thread.sleep(1000);
56 | }
57 | } catch (Exception e) {
58 | AL.warn(e);
59 | }
60 | }
61 | }
62 |
--------------------------------------------------------------------------------
/src/main/java/com/osiris/autoplug/client/utils/UtilsByte.java:
--------------------------------------------------------------------------------
1 | package com.osiris.autoplug.client.utils;
2 |
3 | /*
4 | * Copyright (c) Cedar Software, LLC
5 | *
6 | * Licensed under the Apache License, Version 2.0 (the "License"); you
7 | * may not use this file except in compliance with the License. You may
8 | * obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 |
19 | public final class UtilsByte {
20 | private static final char[] _hex =
21 | {
22 | '0', '1', '2', '3', '4', '5', '6', '7',
23 | '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'
24 | };
25 |
26 |
27 | /**
28 | *
29 | * {@code StringUtilities} instances should NOT be constructed in standard
30 | * programming. Instead, the class should be used statically as
31 | * {@code StringUtilities.trim();}.
32 | *
33 | */
34 | private UtilsByte() {
35 | super();
36 | }
37 |
38 | // Turn hex String into byte[]
39 | // If string is not even length, return null.
40 |
41 | public static byte[] decode(final String s) {
42 | final int len = s.length();
43 | if (len % 2 != 0) {
44 | return null;
45 | }
46 |
47 | byte[] bytes = new byte[len / 2];
48 | int pos = 0;
49 |
50 | for (int i = 0; i < len; i += 2) {
51 | byte hi = (byte) Character.digit(s.charAt(i), 16);
52 | byte lo = (byte) Character.digit(s.charAt(i + 1), 16);
53 | bytes[pos++] = (byte) (hi * 16 + lo);
54 | }
55 |
56 | return bytes;
57 | }
58 |
59 | /**
60 | * Convert a byte array into a printable format containing a String of hex
61 | * digit characters (two per byte).
62 | *
63 | * @param bytes array representation
64 | * @return String hex digits
65 | */
66 | public static String encode(final byte[] bytes) {
67 | StringBuilder sb = new StringBuilder(bytes.length << 1);
68 | for (byte aByte : bytes) {
69 | sb.append(convertDigit(aByte >> 4));
70 | sb.append(convertDigit(aByte & 0x0f));
71 | }
72 | return sb.toString();
73 | }
74 |
75 | /**
76 | * Convert the specified value (0 .. 15) to the corresponding hex digit.
77 | *
78 | * @param value to be converted
79 | * @return '0'..'F' in char format.
80 | */
81 | private static char convertDigit(final int value) {
82 | return _hex[value & 0x0f];
83 | }
84 |
85 | /**
86 | * @param bytes byte[] of bytes to test
87 | * @return true if bytes are gzip compressed, false otherwise.
88 | */
89 | public static boolean isGzipped(byte[] bytes) {
90 | return bytes[0] == (byte) 0x1f && bytes[1] == (byte) 0x8b;
91 | }
92 | }
93 |
94 |
--------------------------------------------------------------------------------
/src/main/java/com/osiris/autoplug/client/utils/UtilsFile.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2022-2024 Osiris-Team.
3 | * All rights reserved.
4 | *
5 | * This software is copyrighted work, licensed under the terms
6 | * of the MIT-License. Consult the "LICENSE" file for details.
7 | */
8 |
9 | package com.osiris.autoplug.client.utils;
10 |
11 | import java.io.File;
12 | import java.io.IOException;
13 | import java.nio.file.Files;
14 |
15 | public class UtilsFile {
16 |
17 | public String getFileName(String s) {
18 | return new File(s).getName();
19 | }
20 |
21 | /**
22 | * Removes unsupported chars like control chars
23 | * and specific printable chars like \ or / from the provided string and returns it.
24 | * Works for all operating systems.
25 | */
26 | public String getValidFileName(String fileName) {
27 | return fileName.replaceAll("\\p{Cc}", "") // First remove control/not-printable chars
28 | .replaceAll("[/\\\\<>:\"'|*?]", ""); // Then remove invalid printable chars
29 | }
30 |
31 | public void copyDirectoryContent(File sourceDir, File targetDir) throws IOException {
32 | targetDir.mkdirs();
33 | for (File sourceFile : sourceDir.listFiles()) {
34 | File targetFile = new File(targetDir + "/" + sourceFile.getName());
35 | targetFile.createNewFile();
36 | Files.copy(sourceFile.toPath(), targetFile.toPath());
37 | }
38 | }
39 |
40 | public File renameFile(File file, String newName) {
41 | File newFile = new File(file.getParentFile() + "/" + newName);
42 | if (newFile.exists()) newFile.delete(); // Replace existing
43 | file.renameTo(newFile);
44 | file.delete(); // Delete old
45 | return newFile;
46 | }
47 |
48 | public File pathToFile(String path) {
49 | File file = null;
50 | if (path.contains("./"))
51 | path = path.replace("./", GD.WORKING_DIR.getAbsolutePath() + File.separator);
52 | if (path.contains(".\\"))
53 | path = path.replace(".\\", GD.WORKING_DIR.getAbsolutePath() + File.separator);
54 | if (!path.contains("/") && !path.contains("\\"))
55 | path = GD.WORKING_DIR.getAbsolutePath() + File.separator + path;
56 |
57 | return new File(path);
58 | }
59 | }
60 |
--------------------------------------------------------------------------------
/src/main/java/com/osiris/autoplug/client/utils/UtilsJar.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2021-2022 Osiris-Team.
3 | * All rights reserved.
4 | *
5 | * This software is copyrighted work, licensed under the terms
6 | * of the MIT-License. Consult the "LICENSE" file for details.
7 | */
8 |
9 | package com.osiris.autoplug.client.utils;
10 |
11 | import com.osiris.autoplug.client.Main;
12 | import com.osiris.autoplug.client.configs.GeneralConfig;
13 | import com.osiris.dyml.exceptions.*;
14 | import org.jetbrains.annotations.NotNull;
15 |
16 | import java.io.File;
17 | import java.io.IOException;
18 | import java.net.URISyntaxException;
19 | import java.net.URL;
20 | import java.net.URLClassLoader;
21 | import java.util.ArrayList;
22 | import java.util.Collection;
23 | import java.util.Properties;
24 |
25 | public class UtilsJar {
26 |
27 | public File determineServerJar() throws YamlWriterException, NotLoadedException, IOException, IllegalKeyException, DuplicateKeyException, YamlReaderException, IllegalListException {
28 | GeneralConfig generalConfig = new GeneralConfig();
29 | String path = generalConfig.server_start_command.asString();
30 | if (path == null) return null;
31 | if (path.contains("-jar ")) { // jar file
32 | path = path.substring(path.indexOf("-jar "));
33 | if (path.codePointAt(5) == '"') {
34 | for (int i = 6; i < path.length(); i++) {
35 | char c = (char) path.codePointAt(i);
36 | if (c == '\"') return new File(path.substring(6, i));
37 | }
38 | throw new RuntimeException("Server jar path started with \" but didn't finish with another \"!" + path);
39 | } else {
40 | return new File(path.split(" ")[1]);
41 | }
42 | } else { // probably exe file
43 | if (path.startsWith("\"")) {
44 | for (int i = 1; i < path.length(); i++) {
45 | char c = (char) path.codePointAt(i);
46 | if (c == '\"') return new File(path.substring(1, i));
47 | }
48 | throw new RuntimeException("Server jar path started with \" but didn't finish with another \"! " + path);
49 | } else {
50 | return new File(path.split(" ")[0]);
51 | }
52 | }
53 | }
54 |
55 | /**
56 | * Returns the currently running jar file.
57 | */
58 | public File getThisJar() throws URISyntaxException {
59 | String path = Main.class
60 | .getProtectionDomain()
61 | .getCodeSource()
62 | .getLocation()
63 | .toURI()
64 | .getPath();
65 | return new File(path);
66 | }
67 |
68 | @NotNull
69 | public Properties getThisJarsAutoPlugProperties() throws Exception {
70 | return getAutoPlugPropertiesFromJar(Main.class
71 | .getProtectionDomain()
72 | .getCodeSource()
73 | .getLocation()
74 | .toURI()
75 | .getPath());
76 | }
77 |
78 | @NotNull
79 | public Properties getAutoPlugPropertiesFromJar(@NotNull String path) throws Exception {
80 | return getPropertiesFromJar(path, "autoplug");
81 | }
82 |
83 | /**
84 | * This creates an URLClassLoader so we can access the autoplug.properties file inside the jar and then returns the properties file.
85 | *
86 | * @param path The jars path
87 | * @param propertiesFileName Properties file name without its .properties extension.
88 | * @return autoplug.properties
89 | * @throws Exception
90 | */
91 | @NotNull
92 | public Properties getPropertiesFromJar(@NotNull String path, String propertiesFileName) throws Exception {
93 | File file = new File(path); // The properties file
94 | if (file.exists()) {
95 | Collection urls = new ArrayList();
96 | urls.add(file.toURI().toURL());
97 | URLClassLoader fileClassLoader = new URLClassLoader(urls.toArray(new URL[urls.size()]));
98 |
99 | java.io.InputStream is = fileClassLoader.getResourceAsStream(propertiesFileName + ".properties");
100 | java.util.Properties p = new java.util.Properties();
101 | p.load(is);
102 | return p;
103 | } else
104 | throw new Exception("Couldn't find the properties file at: " + path);
105 | }
106 |
107 | }
108 |
--------------------------------------------------------------------------------
/src/main/java/com/osiris/autoplug/client/utils/UtilsLists.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2022 Osiris-Team.
3 | * All rights reserved.
4 | *
5 | * This software is copyrighted work, licensed under the terms
6 | * of the MIT-License. Consult the "LICENSE" file for details.
7 | */
8 |
9 | package com.osiris.autoplug.client.utils;
10 |
11 | import java.util.Arrays;
12 | import java.util.List;
13 |
14 | public class UtilsLists {
15 | public String toString(List list) {
16 | return Arrays.toString(list.toArray());
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/src/main/java/com/osiris/autoplug/client/utils/UtilsLogger.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2022 Osiris-Team.
3 | * All rights reserved.
4 | *
5 | * This software is copyrighted work, licensed under the terms
6 | * of the MIT-License. Consult the "LICENSE" file for details.
7 | */
8 |
9 | package com.osiris.autoplug.client.utils;
10 |
11 | import com.osiris.jlib.logger.AL;
12 |
13 | import java.util.Arrays;
14 | import java.util.Scanner;
15 | import java.util.concurrent.atomic.AtomicBoolean;
16 |
17 |
18 | public class UtilsLogger {
19 |
20 | public void animatedPrintln(String s) throws InterruptedException {
21 | System.out.print(" > ");
22 | AtomicBoolean skip = new AtomicBoolean(false);
23 | Scanner scanner = new Scanner(System.in);
24 | Thread t = new Thread(() -> {
25 | scanner.nextLine();
26 | skip.set(true);
27 | });
28 | t.start();
29 |
30 | for (int i = 0; i < s.length(); i++) {
31 | if (skip.get()) {
32 | for (int j = i; j < s.length(); j++) {
33 | System.out.print(s.charAt(j));
34 | }
35 | System.out.flush();
36 | break;
37 | }
38 | System.out.print(s.charAt(i));
39 | System.out.flush();
40 | Thread.sleep(50);
41 | }
42 | System.out.println();
43 | t.interrupt();
44 | }
45 |
46 | public String expectInput(String... expectedInput) {
47 | String line;
48 | Scanner scanner = new Scanner(System.in);
49 | while (true) {
50 | line = scanner.nextLine();
51 | if (expectedInput == null || expectedInput.length == 0) {
52 | return line;
53 | }
54 | boolean equals = false;
55 | for (String s :
56 | expectedInput) {
57 | if (line.equals(s)) {
58 | equals = true;
59 | break;
60 | }
61 | }
62 | if (equals) {
63 | return line;
64 | } else AL.warn("Your input was wrong. Please try again. Expected: " + Arrays.toString(expectedInput));
65 | }
66 | }
67 | }
68 |
--------------------------------------------------------------------------------
/src/main/java/com/osiris/autoplug/client/utils/UtilsMap.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2021-2022 Osiris-Team.
3 | * All rights reserved.
4 | *
5 | * This software is copyrighted work, licensed under the terms
6 | * of the MIT-License. Consult the "LICENSE" file for details.
7 | */
8 |
9 | package com.osiris.autoplug.client.utils;
10 |
11 | import java.util.ArrayList;
12 | import java.util.LinkedHashMap;
13 | import java.util.List;
14 | import java.util.Map;
15 |
16 | public class UtilsMap {
17 |
18 | public void printStringMap(Map map) {
19 | System.out.println(getStringMapFormatted(map));
20 | }
21 |
22 | /**
23 | * Returns a formatted String representation of the map object.
24 | */
25 | public String getStringMapFormatted(Map map) {
26 | String result = "";
27 | for (K key :
28 | map.keySet()) {
29 | result = result + "key: " + key + " value: " + map.get(key) + "\n";
30 | }
31 | return result;
32 | }
33 |
34 | /**
35 | * Returns a new sorted entries list that is sorted by value in ascending (small to big) order.
36 | */
37 | public > List> getEntriesListSortedByValue(Map map) {
38 | List> list = new ArrayList<>(map.entrySet());
39 | list.sort(Map.Entry.comparingByValue());
40 |
41 | return new ArrayList<>(list);
42 | }
43 |
44 | /**
45 | * Returns a new sorted map that is sorted by value in ascending (small to big) order.
46 | */
47 | public > Map getSortedByValue(Map map) {
48 | List> list = new ArrayList<>(map.entrySet());
49 | list.sort(Map.Entry.comparingByValue());
50 |
51 | Map result = new LinkedHashMap<>();
52 | for (Map.Entry entry : list) {
53 | result.put(entry.getKey(), entry.getValue());
54 | }
55 | return result;
56 | }
57 |
58 |
59 | }
60 |
--------------------------------------------------------------------------------
/src/main/java/com/osiris/autoplug/client/utils/UtilsRandom.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2022 Osiris-Team.
3 | * All rights reserved.
4 | *
5 | * This software is copyrighted work, licensed under the terms
6 | * of the MIT-License. Consult the "LICENSE" file for details.
7 | */
8 |
9 | package com.osiris.autoplug.client.utils;
10 |
11 | public class UtilsRandom {
12 | public String generateNewKey(int length) {
13 | // chose a Character random from this String
14 | String AlphaNumericString =
15 | "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
16 | + "0123456789"
17 | + "abcdefghijklmnopqrstuvxyz";
18 |
19 | // create StringBuffer size of AlphaNumericString
20 | StringBuilder sb = new StringBuilder(length);
21 |
22 | for (int i = 0; i < length; i++) {
23 |
24 | // generate a random number between
25 | // 0 to AlphaNumericString variable length
26 | int index
27 | = (int) (AlphaNumericString.length()
28 | * Math.random());
29 |
30 | // add Character one by one in end of sb
31 | sb.append(AlphaNumericString
32 | .charAt(index));
33 | }
34 |
35 | return sb.toString();
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/src/main/java/com/osiris/autoplug/client/utils/UtilsString.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2022 Osiris-Team.
3 | * All rights reserved.
4 | *
5 | * This software is copyrighted work, licensed under the terms
6 | * of the MIT-License. Consult the "LICENSE" file for details.
7 | */
8 |
9 | package com.osiris.autoplug.client.utils;
10 |
11 | import java.util.ArrayList;
12 | import java.util.Arrays;
13 | import java.util.List;
14 |
15 | public class UtilsString {
16 |
17 | /**
18 | * Input: "Hello there" my "friend"
19 | * Output list: ["Hello there", my, "friend"]
20 | * Spaces inside quotes are ignored.
21 | */
22 | public List splitBySpacesAndQuotes(String s) throws Exception {
23 | List list = new ArrayList<>();
24 | int countQuotes = 0;
25 | for (int i = 0; i < s.length(); i++) {
26 | char c = (char) s.codePointAt(i);
27 | if (c == '\"') countQuotes++;
28 | }
29 | if (countQuotes == 0) {
30 | list.addAll(Arrays.asList(s.split(" ")));
31 | return list;
32 | }
33 | if (countQuotes % 2 == 1) throw new Exception("Open quote found! Please close the quote in: " + s);
34 | // "bla""bla"
35 | // "bla" "bla"
36 | // bla "bla"
37 | // "bla" bla
38 | // "bla" bla "bla"
39 | boolean isInQuote = false;
40 | int iLastOpenQuote = 0;
41 | int iLastSpace = 0;
42 | for (int i = 0; i < s.length(); i++) {
43 | char c = (char) s.codePointAt(i);
44 | if (c == ' ') {
45 | if (!isInQuote) {
46 | if (iLastSpace != -1)
47 | list.add(s.substring(iLastSpace, i).trim());
48 | }
49 | iLastSpace = i;
50 | }
51 | if (c == '\"')
52 | if (!isInQuote) {
53 | iLastOpenQuote = i;
54 | isInQuote = true;
55 | } else {
56 | list.add(s.substring(iLastOpenQuote, i + 1).trim());
57 | isInQuote = false;
58 | iLastSpace = -1;
59 | }
60 | }
61 | if (iLastSpace != -1) list.add(s.substring(iLastSpace).trim()); // Add last one if there is
62 | return list;
63 | }
64 |
65 | /**
66 | * Checks each char from the source (left to right)
67 | * string with the provided query char.
68 | * If there is a match exits the loop and returns it.
69 | * If loopCount is bigger than one continues until the last char of the string.
70 | */
71 | public int indexOf(String source, char query, int loopCount) {
72 | int lastMatch = 0;
73 | for (int j = 0; j < loopCount; j++) {
74 | for (int i = lastMatch; i < source.length(); i++) {
75 | if (source.charAt(i) == query) {
76 | lastMatch = i;
77 | break;
78 | }
79 | }
80 | }
81 | return lastMatch;
82 | }
83 | }
84 |
--------------------------------------------------------------------------------
/src/main/java/com/osiris/autoplug/client/utils/UtilsURL.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2022 Osiris-Team.
3 | * All rights reserved.
4 | *
5 | * This software is copyrighted work, licensed under the terms
6 | * of the MIT-License. Consult the "LICENSE" file for details.
7 | */
8 |
9 | package com.osiris.autoplug.client.utils;
10 |
11 | public class UtilsURL {
12 |
13 | public String clean(String url) {
14 | return url.replaceAll("\"", "%22");
15 | }
16 |
17 | }
18 |
--------------------------------------------------------------------------------
/src/main/java/com/osiris/autoplug/client/utils/io/AsyncInputStream.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2021-2022 Osiris-Team.
3 | * All rights reserved.
4 | *
5 | * This software is copyrighted work, licensed under the terms
6 | * of the MIT-License. Consult the "LICENSE" file for details.
7 | */
8 |
9 | package com.osiris.autoplug.client.utils.io;
10 |
11 | import java.io.BufferedReader;
12 | import java.io.IOException;
13 | import java.io.InputStream;
14 | import java.io.InputStreamReader;
15 | import java.util.List;
16 | import java.util.concurrent.CopyOnWriteArrayList;
17 | import java.util.function.Consumer;
18 |
19 | public class AsyncInputStream {
20 | private final InputStream inputStream;
21 | private final Thread thread;
22 | public List> listeners = new CopyOnWriteArrayList<>();
23 |
24 | public AsyncInputStream(InputStream inputStream) {
25 | this.inputStream = inputStream;
26 |
27 | Object o = this;
28 | thread = new Thread(() -> {
29 | String line = "";
30 | try (BufferedReader br = new BufferedReader(new InputStreamReader(inputStream))) {
31 | while ((line = br.readLine()) != null) {
32 | for (Consumer listener :
33 | listeners) {
34 | listener.accept(line);
35 | }
36 | }
37 | } catch (IOException e) {
38 | System.err.println("Error in thread for object '" + o + "' Details:");
39 | e.printStackTrace();
40 | }
41 | });
42 | thread.start();
43 | }
44 |
45 | public InputStream getInputStream() {
46 | return inputStream;
47 | }
48 |
49 | public Thread getThread() {
50 | return thread;
51 | }
52 |
53 | /**
54 | * Returns the list of listeners.
55 | * Each listener listens for write line events.
56 | */
57 | public List> getListeners() {
58 | return listeners;
59 | }
60 | }
61 |
--------------------------------------------------------------------------------
/src/main/java/com/osiris/autoplug/client/utils/io/AsyncReader.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2022 Osiris-Team.
3 | * All rights reserved.
4 | *
5 | * This software is copyrighted work, licensed under the terms
6 | * of the MIT-License. Consult the "LICENSE" file for details.
7 | */
8 |
9 | package com.osiris.autoplug.client.utils.io;
10 |
11 | import java.io.BufferedReader;
12 | import java.io.IOException;
13 | import java.io.InputStream;
14 | import java.io.InputStreamReader;
15 | import java.util.Arrays;
16 | import java.util.List;
17 | import java.util.concurrent.CopyOnWriteArrayList;
18 | import java.util.function.Consumer;
19 |
20 | public class AsyncReader {
21 | public final InputStream inputStream;
22 | public final Thread thread;
23 | public List> listeners = new CopyOnWriteArrayList<>();
24 |
25 | @SafeVarargs
26 | public AsyncReader(InputStream inputStream, Consumer... listeners) {
27 | this.inputStream = inputStream;
28 | if (listeners != null && listeners.length != 0) this.listeners.addAll(Arrays.asList(listeners));
29 | Object o = this;
30 | thread = new Thread(() -> {
31 | String line = "";
32 | try (BufferedReader br = new BufferedReader(new InputStreamReader(inputStream))) {
33 | while ((line = br.readLine()) != null) {
34 | for (Consumer listener :
35 | this.listeners) {
36 | listener.accept(line);
37 | }
38 | }
39 | } catch (IOException e) {
40 | System.out.println("Error in thread for object '" + o + "' Details:");
41 | e.printStackTrace();
42 | }
43 | });
44 | thread.start();
45 | }
46 | }
--------------------------------------------------------------------------------
/src/main/java/com/osiris/autoplug/client/utils/io/MyTeeOutputStream.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2021-2022 Osiris-Team.
3 | * All rights reserved.
4 | *
5 | * This software is copyrighted work, licensed under the terms
6 | * of the MIT-License. Consult the "LICENSE" file for details.
7 | */
8 |
9 | package com.osiris.autoplug.client.utils.io;
10 |
11 | import org.jetbrains.annotations.NotNull;
12 | import org.jetbrains.annotations.Nullable;
13 |
14 | import java.io.IOException;
15 | import java.io.OutputStream;
16 |
17 | /**
18 | * Only used for testing.
19 | * Original TeeOutputStream seems to be more performant.
20 | */
21 | public final class MyTeeOutputStream extends OutputStream {
22 |
23 | @Nullable
24 | private final OutputStream out;
25 | @Nullable
26 | private final OutputStream tee;
27 |
28 | public MyTeeOutputStream(@Nullable OutputStream out, @Nullable OutputStream tee) {
29 | if (out == null)
30 | throw new NullPointerException();
31 | else if (tee == null)
32 | throw new NullPointerException();
33 |
34 | this.out = out;
35 | this.tee = tee;
36 | }
37 |
38 |
39 | @Override
40 | public void write(int b) throws IOException {
41 | out.write(b);
42 | tee.write(b);
43 | }
44 |
45 | @Override
46 | public void write(@NotNull byte[] b) throws IOException {
47 | out.write(b);
48 | tee.write(b);
49 | }
50 |
51 | @Override
52 | public void write(@NotNull byte[] b, int off, int len) throws IOException {
53 | out.write(b, off, len);
54 | tee.write(b, off, len);
55 | }
56 |
57 | @Override
58 | public void flush() throws IOException {
59 | out.flush();
60 | tee.flush();
61 | }
62 |
63 | @Override
64 | public void close() throws IOException {
65 | try {
66 | out.close();
67 | } finally {
68 | tee.close();
69 | }
70 | }
71 | }
--------------------------------------------------------------------------------
/src/main/java/com/osiris/autoplug/client/utils/io/NonBlockingPipedInputStream.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2021-2022 Osiris-Team.
3 | * All rights reserved.
4 | *
5 | * This software is copyrighted work, licensed under the terms
6 | * of the MIT-License. Consult the "LICENSE" file for details.
7 | */
8 |
9 | package com.osiris.autoplug.client.utils.io;
10 |
11 | import com.osiris.jlib.logger.AL;
12 | import org.jetbrains.annotations.NotNull;
13 |
14 | import java.io.BufferedReader;
15 | import java.io.InputStreamReader;
16 | import java.io.PipedInputStream;
17 | import java.util.List;
18 | import java.util.concurrent.CopyOnWriteArrayList;
19 |
20 | public class NonBlockingPipedInputStream extends PipedInputStream { // PipedInputStream
21 | @NotNull
22 | private final Thread thread;
23 | /**
24 | * Add actions to this list, which get run after a line has been written.
25 | * Contains the line as parameter.
26 | */
27 | @NotNull
28 | public List> actionsOnWriteLineEvent = new CopyOnWriteArrayList<>();
29 |
30 | /**
31 | * Creates and starts a new {@link Thread}, that reads the {@link PipedInputStream}
32 | * and fires an event every time a full line was written to it.
33 | * To listen for those events, add the action that should be run to the {@link #actionsOnWriteLineEvent} list.
34 | */
35 | public NonBlockingPipedInputStream() {
36 | thread = new Thread(() -> {
37 | try {
38 | BufferedReader reader = new BufferedReader(new InputStreamReader(this));
39 | String line;
40 | while ((line = reader.readLine()) != null) {
41 | String finalLine = line;
42 | actionsOnWriteLineEvent.forEach(action -> action.executeOnEvent(finalLine));
43 | }
44 | } catch (Exception e) {
45 | AL.warn(e);
46 | }
47 | });
48 | thread.start();
49 |
50 | }
51 |
52 | @NotNull
53 | public Thread getThread() {
54 | return thread;
55 | }
56 |
57 | public interface WriteLineEvent {
58 | void executeOnEvent(L l);
59 | }
60 | }
61 |
--------------------------------------------------------------------------------
/src/main/java/com/osiris/autoplug/client/utils/io/UFDataIn.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2021-2024 Osiris-Team.
3 | * All rights reserved.
4 | *
5 | * This software is copyrighted work, licensed under the terms
6 | * of the MIT-License. Consult the "LICENSE" file for details.
7 | */
8 |
9 | package com.osiris.autoplug.client.utils.io;
10 |
11 | import com.osiris.jlib.logger.AL;
12 | import com.osiris.jlib.network.UFDataOut;
13 |
14 | import javax.naming.LimitExceededException;
15 | import java.io.*;
16 | import java.nio.charset.StandardCharsets;
17 | import java.util.Base64;
18 |
19 | /**
20 | * ULTRA FAST DATA INPUTSTREAM!
21 | */
22 | public class UFDataIn {
23 | private final DataInputStream dis;
24 |
25 | public UFDataIn(InputStream inputStream) {
26 | this.dis = new DataInputStream(inputStream);
27 | }
28 |
29 | public String readLine() throws IOException {
30 | return dis.readUTF();
31 | }
32 |
33 | public boolean readBoolean() throws IOException {
34 | return dis.readBoolean();
35 | }
36 |
37 | /**
38 | * @param file write receiving data to this file.
39 | */
40 | public void readFile(File file) throws IOException {
41 | try (FileOutputStream out = new FileOutputStream(file)) {
42 | readStream(out);
43 | }
44 | }
45 |
46 | /**
47 | * @param file write receiving data to this file.
48 | * @param maxBytes set to -1 if no limit wanted.
49 | */
50 | public void readFile(File file, long maxBytes) throws IOException, LimitExceededException {
51 | try (FileOutputStream out = new FileOutputStream(file)) {
52 | readStream(out, maxBytes);
53 | }
54 | }
55 |
56 | /**
57 | * @param out write receiving data to this stream.
58 | */
59 | public void readStream(OutputStream out) throws IOException {
60 | try{
61 | readStream(out, -1);
62 | } catch (LimitExceededException e) { // Not excepted to happen since no limit
63 | throw new RuntimeException(e);
64 | }
65 | }
66 |
67 | /**
68 | * @param out write receiving data to this stream.
69 | * @param maxBytes set to -1 if no limit wanted.
70 | */
71 | public void readStream(OutputStream out, long maxBytes) throws IOException, LimitExceededException {
72 | /*
73 | * Handling Non-Text Data: If the input stream
74 | * contains binary data (like images or other non-text files),
75 | * Base64 encoding allows this data to be represented as text,
76 | * which can then be safely written using writeUTF.
77 | * By using Base64 encoding, we ensure that the binary data is first converted
78 | * to a string representation that can be safely written using writeUTF.
79 | */
80 | Base64.Decoder decoder = Base64.getDecoder();
81 | long countBytesRead = 0;
82 | int count;
83 | byte[] buffer = new byte[8192]; // or 4096, or more
84 | String buffer_s = "";
85 | while (!(buffer_s = dis.readUTF()).equals(UFDataOut.EOF)) {
86 | buffer = decoder.decode(buffer_s.getBytes(StandardCharsets.UTF_8));
87 | count = buffer.length;
88 |
89 | countBytesRead += count;
90 | if (maxBytes >= 0 && countBytesRead > maxBytes) {
91 | throw new LimitExceededException("Exceeded the maximum allowed bytes: " + maxBytes);
92 | }
93 | out.write(buffer, 0, count);
94 | out.flush();
95 | }
96 | AL.debug(this.getClass(), "Bytes read: " + countBytesRead);
97 | //read("\u001a") // Not needed here since already read above by read()
98 | }
99 |
100 | public byte readByte() throws IOException {
101 | return dis.readByte();
102 | }
103 |
104 | public short readShort() throws IOException {
105 | return dis.readShort();
106 | }
107 |
108 | public int readInt() throws IOException {
109 | return dis.readInt();
110 | }
111 |
112 | public long readLong() throws IOException {
113 | return dis.readLong();
114 | }
115 |
116 | public float readFloat() throws IOException {
117 | return dis.readFloat();
118 | }
119 |
120 | }
121 |
--------------------------------------------------------------------------------
/src/main/java/com/osiris/autoplug/client/utils/io/UFDataOut.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2021-2024 Osiris-Team.
3 | * All rights reserved.
4 | *
5 | * This software is copyrighted work, licensed under the terms
6 | * of the MIT-License. Consult the "LICENSE" file for details.
7 | */
8 |
9 | package com.osiris.autoplug.client.utils.io;
10 |
11 | import com.osiris.jlib.logger.AL;
12 |
13 | import java.io.*;
14 | import java.nio.charset.StandardCharsets;
15 | import java.util.Arrays;
16 | import java.util.Base64;
17 |
18 | /**
19 | * ULTRA FAST DATA OUTPUTSTREAM!
20 | */
21 | public class UFDataOut extends DataOutputStream {
22 |
23 | public UFDataOut(OutputStream outputStream) {
24 | super(outputStream);
25 | }
26 |
27 | public void writeLine(String s) throws IOException {
28 | writeUTF(s);
29 | }
30 |
31 | public static final String EOF = new String("EOF_MARKER_1714941978".getBytes(StandardCharsets.UTF_8),
32 | StandardCharsets.UTF_8);
33 |
34 | /**
35 | * @param file read data from this file and send it.
36 | */
37 | public void writeFile(File file) throws IOException {
38 | try (FileInputStream in = new FileInputStream(file)) {
39 | writeStream(in);
40 | }
41 | }
42 |
43 | /**
44 | * @param in read data from this stream and send it.
45 | */
46 | public void writeStream(InputStream in) throws IOException {
47 | /*
48 | * Handling Non-Text Data: If the input stream
49 | * contains binary data (like images or other non-text files),
50 | * Base64 encoding allows this data to be represented as text,
51 | * which can then be safely written using writeUTF.
52 | * It converts binary data into a set of 64 characters that are safe for text-based transmission.
53 | * By using Base64 encoding, we ensure that the binary data is first converted
54 | * to a string representation that can be safely written using writeUTF.
55 | */
56 | Base64.Encoder encoder = Base64.getEncoder();
57 | long totalCount = 0;
58 | int count;
59 | byte[] buffer = new byte[8192]; // or 4096, or more
60 | while ((count = in.read(buffer)) > 0) {
61 | if (count == buffer.length) writeUTF(new String(encoder.encode(buffer), StandardCharsets.UTF_8));
62 | else writeUTF(new String(encoder.encode(Arrays.copyOf(buffer, count)), StandardCharsets.UTF_8));
63 | flush();
64 | totalCount += count;
65 | }
66 | writeUTF(EOF); // Write since not included above
67 | AL.debug(this.getClass(), "Bytes sent: " + totalCount);
68 | flush();
69 | }
70 | }
71 |
--------------------------------------------------------------------------------
/src/main/java/com/osiris/autoplug/client/utils/tasks/CoolDownReport.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2021-2022 Osiris-Team.
3 | * All rights reserved.
4 | *
5 | * This software is copyrighted work, licensed under the terms
6 | * of the MIT-License. Consult the "LICENSE" file for details.
7 | */
8 |
9 | package com.osiris.autoplug.client.utils.tasks;
10 |
11 | public class CoolDownReport {
12 | private long msPassedSinceLast;
13 | private long msCoolDown;
14 |
15 | public CoolDownReport(long msPassedSinceLast, long msCoolDown) {
16 | this.msPassedSinceLast = msPassedSinceLast;
17 | this.msCoolDown = msCoolDown;
18 | }
19 |
20 | public long getMsRemaining() {
21 | return msCoolDown - msPassedSinceLast;
22 | }
23 |
24 | public boolean isInCoolDown() {
25 | return msPassedSinceLast < msCoolDown;
26 | }
27 |
28 | public long getMsPassedSinceLast() {
29 | return msPassedSinceLast;
30 | }
31 |
32 | public void setMsPassedSinceLast(long msPassedSinceLast) {
33 | this.msPassedSinceLast = msPassedSinceLast;
34 | }
35 |
36 | public long getMsCoolDown() {
37 | return msCoolDown;
38 | }
39 |
40 | public void setMsCoolDown(long msCoolDown) {
41 | this.msCoolDown = msCoolDown;
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/src/main/java/com/osiris/autoplug/client/utils/tasks/MyBThreadManager.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2022-2023 Osiris-Team.
3 | * All rights reserved.
4 | *
5 | * This software is copyrighted work, licensed under the terms
6 | * of the MIT-License. Consult the "LICENSE" file for details.
7 | */
8 |
9 | package com.osiris.autoplug.client.utils.tasks;
10 |
11 | import com.osiris.betterthread.BThreadManager;
12 | import com.osiris.betterthread.BThreadPrinter;
13 |
14 | import java.util.concurrent.atomic.AtomicReference;
15 |
16 |
17 | public class MyBThreadManager {
18 | public static final AtomicReference lastCreatedPrinter = new AtomicReference<>();
19 | public BThreadManager manager;
20 | public BThreadPrinter printer;
21 |
22 | public MyBThreadManager(BThreadManager manager, BThreadPrinter printer) {
23 | this.manager = manager;
24 | this.printer = printer;
25 | lastCreatedPrinter.set(printer);
26 | }
27 |
28 | }
29 |
--------------------------------------------------------------------------------
/src/main/java/com/osiris/autoplug/client/utils/tasks/MyDate.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2022 Osiris-Team.
3 | * All rights reserved.
4 | *
5 | * This software is copyrighted work, licensed under the terms
6 | * of the MIT-License. Consult the "LICENSE" file for details.
7 | */
8 |
9 | package com.osiris.autoplug.client.utils.tasks;
10 |
11 | import com.osiris.betterthread.BThread;
12 | import com.osiris.betterthread.BThreadManager;
13 | import com.osiris.betterthread.BThreadPrinter;
14 | import com.osiris.betterthread.modules.Date;
15 | import org.fusesource.jansi.Ansi;
16 |
17 | import java.time.LocalDateTime;
18 |
19 | import static org.fusesource.jansi.Ansi.ansi;
20 |
21 | public class MyDate extends Date {
22 | @Override
23 | public void append(BThreadManager manager, BThreadPrinter printer, BThread thread, StringBuilder line) {
24 | line.append(ansi().bg(Ansi.Color.WHITE).fgBlack().a("[" + dateFormatter.format(LocalDateTime.now()) + "]")
25 | .reset());
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/src/main/java/com/osiris/autoplug/client/utils/terminal/AsyncTerminal.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2022-2023 Osiris-Team.
3 | * All rights reserved.
4 | *
5 | * This software is copyrighted work, licensed under the terms
6 | * of the MIT-License. Consult the "LICENSE" file for details.
7 | */
8 |
9 | package com.osiris.autoplug.client.utils.terminal;
10 |
11 | import com.osiris.autoplug.client.utils.io.AsyncReader;
12 | import org.jline.utils.OSUtils;
13 |
14 | import java.io.File;
15 | import java.io.IOException;
16 | import java.io.InputStream;
17 | import java.io.OutputStream;
18 | import java.nio.charset.StandardCharsets;
19 | import java.util.function.Consumer;
20 |
21 | public class AsyncTerminal implements AutoCloseable {
22 | public Process process;
23 | public AsyncReader readerLines;
24 | public AsyncReader readerErrLines;
25 | public OutputStream out;
26 |
27 | public AsyncTerminal(File workingDir, Consumer onLineReceived,
28 | Consumer onErrorLineReceived, String... commands) throws IOException {
29 | if (workingDir == null) workingDir = new File(System.getProperty("user.dir"));
30 | Process p;
31 | if (OSUtils.IS_WINDOWS) {
32 | try { // Try powershell first, use cmd as fallback
33 | p = new ProcessBuilder("powershell").directory(workingDir).start();
34 | if (!p.isAlive()) throw new Exception();
35 | } catch (Exception e) {
36 | p = new ProcessBuilder("cmd").directory(workingDir).start();
37 | }
38 | } else { // Unix based system, like Linux, Mac etc...
39 | try { // Try bash first, use sh as fallback
40 | p = new ProcessBuilder("/bin/bash").directory(workingDir).start();
41 | if (!p.isAlive()) throw new Exception();
42 | } catch (Exception e) {
43 | p = new ProcessBuilder("/bin/sh").directory(workingDir).start();
44 | }
45 | }
46 | this.process = p;
47 | InputStream in = process.getInputStream();
48 | InputStream inErr = process.getErrorStream();
49 | this.out = process.getOutputStream();
50 | this.readerLines = new AsyncReader(in, onLineReceived);
51 | this.readerErrLines = new AsyncReader(inErr, onErrorLineReceived);
52 | sendCommands(commands);
53 | }
54 |
55 | public void sendCommands(String... commands) throws IOException {
56 | if (commands != null)
57 | for (String command :
58 | commands) {
59 | out.write((command + "\n").getBytes(StandardCharsets.UTF_8));
60 | out.flush();
61 | }
62 | }
63 |
64 | @Override
65 | public void close() {
66 | process.destroy();
67 | process.destroyForcibly();
68 | }
69 | }
70 |
--------------------------------------------------------------------------------
/src/main/java/com/osiris/autoplug/client/utils/terminal/Terminal.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2022-2023 Osiris-Team.
3 | * All rights reserved.
4 | *
5 | * This software is copyrighted work, licensed under the terms
6 | * of the MIT-License. Consult the "LICENSE" file for details.
7 | */
8 |
9 | package com.osiris.autoplug.client.utils.terminal;
10 |
11 | import org.jline.utils.OSUtils;
12 |
13 | import java.io.File;
14 | import java.io.IOException;
15 | import java.io.OutputStream;
16 | import java.nio.charset.StandardCharsets;
17 |
18 | public class Terminal {
19 | public Process process;
20 |
21 | public Terminal(File workingDir, String... commands) throws IOException {
22 | if (workingDir == null) workingDir = new File(System.getProperty("user.dir"));
23 | Process p;
24 | if (OSUtils.IS_WINDOWS) {
25 | try { // Try powershell first, use cmd as fallback
26 | p = new ProcessBuilder("powershell").directory(workingDir).start();
27 | if (!p.isAlive()) throw new Exception();
28 | } catch (Exception e) {
29 | p = new ProcessBuilder("cmd").directory(workingDir).start();
30 | }
31 | } else { // Unix based system, like Linux, Mac etc...
32 | try { // Try bash first, use sh as fallback
33 | p = new ProcessBuilder("/bin/bash").directory(workingDir).start();
34 | if (!p.isAlive()) throw new Exception();
35 | } catch (Exception e) {
36 | p = new ProcessBuilder("/bin/sh").directory(workingDir).start();
37 | }
38 | }
39 | this.process = p;
40 | OutputStream out = process.getOutputStream();
41 | if (commands != null)
42 | for (String command :
43 | commands) {
44 | out.write((command + "\n").getBytes(StandardCharsets.UTF_8));
45 | out.flush();
46 | }
47 | }
48 | }
49 |
--------------------------------------------------------------------------------
/src/main/resources/autoplug-icon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Osiris-Team/AutoPlug-Client/b23647c9ad705775c6ca38a011279af23c57eaf4/src/main/resources/autoplug-icon.png
--------------------------------------------------------------------------------
/src/main/resources/log4j.xml:
--------------------------------------------------------------------------------
1 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/src/main/resources/log4j2.xml:
--------------------------------------------------------------------------------
1 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/src/main/resources/quartz.properties:
--------------------------------------------------------------------------------
1 | #
2 | # Copyright (c) 2021 Osiris-Team.
3 | # All rights reserved.
4 | #
5 | # This software is copyrighted work, licensed under the terms
6 | # of the MIT-License. Consult the "LICENSE" file for details.
7 | #
8 | org.quartz.scheduler.instanceName=TaskScheduler
9 | org.quartz.threadPool.threadCount=10
10 | org.quartz.jobStore.class=org.quartz.simpl.RAMJobStore
--------------------------------------------------------------------------------
/src/test/java/com/osiris/autoplug/client/SystemCheckerTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2023 Osiris-Team.
3 | * All rights reserved.
4 | *
5 | * This software is copyrighted work, licensed under the terms
6 | * of the MIT-License. Consult the "LICENSE" file for details.
7 | */
8 |
9 | package com.osiris.autoplug.client;
10 |
11 | import org.junit.jupiter.api.Test;
12 |
13 | import java.net.HttpURLConnection;
14 | import java.net.InetAddress;
15 | import java.net.URL;
16 |
17 | class SystemCheckerTest {
18 |
19 | @Test
20 | void checkInternetAccessMethod1() throws Exception {
21 | boolean reachable = InetAddress.getByName("www.google.com").isReachable(10000);
22 | if (!reachable) throw new Exception("Failed to reach www.google.com!");
23 | }
24 |
25 | @Test
26 | void checkInternetAccessMethod2() throws Exception {
27 | HttpURLConnection connection = (HttpURLConnection) new URL("https://www.google.com").openConnection();
28 | connection.connect();
29 | connection.disconnect();
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/src/test/java/com/osiris/autoplug/client/UtilsTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2022-2023 Osiris-Team.
3 | * All rights reserved.
4 | *
5 | * This software is copyrighted work, licensed under the terms
6 | * of the MIT-License. Consult the "LICENSE" file for details.
7 | */
8 |
9 | package com.osiris.autoplug.client;
10 |
11 | import com.osiris.autoplug.client.configs.GeneralConfig;
12 | import com.osiris.autoplug.client.utils.GD;
13 | import com.osiris.autoplug.client.utils.tasks.MyBThreadManager;
14 | import com.osiris.autoplug.client.utils.tasks.UtilsTasks;
15 | import com.osiris.betterthread.exceptions.JLineLinkException;
16 | import com.osiris.dyml.exceptions.*;
17 | import com.osiris.jlib.logger.AL;
18 |
19 | import java.io.File;
20 | import java.io.IOException;
21 |
22 | /**
23 | * Utils for tests.
24 | */
25 | public class UtilsTest {
26 | public static MyBThreadManager createManagerWithDisplayer() throws JLineLinkException, NotLoadedException, YamlReaderException, YamlWriterException, IOException, IllegalKeyException, DuplicateKeyException, IllegalListException {
27 | return new UtilsTasks().createManagerAndPrinter();
28 | }
29 |
30 | public static void init() throws IOException {
31 | initLogger();
32 | initDefaults();
33 | }
34 |
35 | private static void initDefaults() throws IOException {
36 | GD.VERSION = "AutoPlug-Client Test-Version";
37 | GD.WORKING_DIR = new File(System.getProperty("user.dir") + "/test");
38 | System.setProperty("user.dir", GD.WORKING_DIR.getAbsolutePath());
39 | GD.DOWNLOADS_DIR = new File(GD.WORKING_DIR + "/downloads");
40 | GD.DOWNLOADS_DIR.mkdirs();
41 |
42 | File serverJar = new File(GD.WORKING_DIR + "/server.jar");
43 | GeneralConfig config = null;
44 | try {
45 | config = new GeneralConfig();
46 | config.lockFile();
47 | config.load();
48 | config.server_start_command.setValues("java -jar \"" + serverJar + "\"");
49 | config.save();
50 | } catch (Exception e) {
51 | if (config != null) config.unlockFile();
52 | throw new RuntimeException(e);
53 | } finally {
54 | if (config != null) config.unlockFile();
55 | }
56 |
57 | if (!serverJar.exists()) serverJar.createNewFile();
58 | }
59 |
60 | private static void initLogger() {
61 | File logFile = new File(System.getProperty("user.dir") + "/logs/latest.log");
62 | logFile.getParentFile().mkdirs();
63 | new AL().start("AL", true, logFile, false, false);
64 | }
65 | }
66 |
--------------------------------------------------------------------------------
/src/test/java/com/osiris/autoplug/client/bugs/VersionBugs.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2023 Osiris-Team.
3 | * All rights reserved.
4 | *
5 | * This software is copyrighted work, licensed under the terms
6 | * of the MIT-License. Consult the "LICENSE" file for details.
7 | */
8 |
9 | package com.osiris.autoplug.client.bugs;
10 |
11 | import com.osiris.autoplug.client.UtilsTest;
12 | import com.osiris.jlib.search.Version;
13 | import org.junit.jupiter.api.Test;
14 |
15 | import java.io.IOException;
16 |
17 | public class VersionBugs {
18 |
19 | @Test
20 | void test() throws IOException {
21 | UtilsTest.init();
22 | Version.isLatestBigger("0", "10000000000000000000000000000000000");
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/src/test/java/com/osiris/autoplug/client/tasks/updater/TaskPluginDownloadTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2021-2023 Osiris-Team.
3 | * All rights reserved.
4 | *
5 | * This software is copyrighted work, licensed under the terms
6 | * of the MIT-License. Consult the "LICENSE" file for details.
7 | */
8 |
9 | package com.osiris.autoplug.client.tasks.updater;
10 |
11 | import com.osiris.autoplug.client.UtilsTest;
12 | import com.osiris.autoplug.client.tasks.updater.plugins.TaskPluginDownload;
13 | import com.osiris.autoplug.client.tasks.updater.plugins.TaskPluginsUpdater;
14 | import com.osiris.betterthread.BThreadManager;
15 | import com.osiris.betterthread.BThreadPrinter;
16 | import com.osiris.dyml.utils.UtilsTimeStopper;
17 | import com.osiris.jlib.logger.AL;
18 |
19 | import java.io.File;
20 |
21 | class TaskPluginDownloadTest {
22 |
23 | @org.junit.jupiter.api.Test
24 | void pluginDownloadTest() throws Exception {
25 | UtilsTest.init();
26 | BThreadManager man = new BThreadManager();
27 | BThreadPrinter printer = new BThreadPrinter(man);
28 | printer.start();
29 |
30 | UtilsTimeStopper timeStopper = new UtilsTimeStopper();
31 | timeStopper.start();
32 | TaskPluginDownload download = new TaskPluginDownload("Downloader", man,
33 | "Autorank",
34 | "LATEST", "https://api.spiget.org/v2/resources/3239/download", "MANUAL",
35 | new File("" + System.getProperty("user.dir") + "/src/main/test/TestPlugin.jar"));
36 | download.start();
37 |
38 | TaskPluginDownload download1 = new TaskPluginDownload("Downloader", man,
39 | "UltimateChat",
40 | "LATEST", "https://api.spiget.org/v2/resources/23767/download", "MANUAL",
41 | new File("" + System.getProperty("user.dir") + "/src/main/test/TestPlugin.jar"));
42 | download1.start();
43 |
44 | TaskPluginDownload download2 = new TaskPluginDownload("Downloader", man,
45 | "ViaRewind",
46 | "LATEST", "https://api.spiget.org/v2/resources/52109/download", "MANUAL",
47 | new File("" + System.getProperty("user.dir") + "/src/main/test/TestPlugin.jar"));
48 | download2.start();
49 |
50 | TaskPluginsUpdater taskPluginsUpdater = new TaskPluginsUpdater("PluginsUpdater", man);
51 | taskPluginsUpdater.start();
52 |
53 | while (!download.isFinished() || !download1.isFinished() || !download2.isFinished())
54 | Thread.sleep(100);
55 | timeStopper.stop();
56 | AL.info("Time took to finish download tasks: " + timeStopper.getFormattedSeconds() + " seconds!");
57 | }
58 | }
--------------------------------------------------------------------------------
/src/test/java/com/osiris/autoplug/client/tasks/updater/TestPluginUpdaters.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2024 Osiris-Team.
3 | * All rights reserved.
4 | *
5 | * This software is copyrighted work, licensed under the terms
6 | * of the MIT-License. Consult the "LICENSE" file for details.
7 | */
8 |
9 | package com.osiris.autoplug.client.tasks.updater;
10 |
11 | import com.osiris.autoplug.client.UtilsTest;
12 | import com.osiris.autoplug.client.tasks.updater.mods.ModrinthAPI;
13 | import com.osiris.autoplug.client.tasks.updater.plugins.MinecraftPlugin;
14 | import com.osiris.autoplug.client.tasks.updater.search.CustomCheckURL;
15 | import com.osiris.autoplug.client.tasks.updater.search.SearchResult;
16 | import org.junit.jupiter.api.Test;
17 |
18 | import java.io.IOException;
19 |
20 | import static org.junit.jupiter.api.Assertions.assertSame;
21 |
22 |
23 | class TestPluginUpdaters {
24 | @Test
25 | void testCustom() throws IOException {
26 | UtilsTest.init();
27 | MinecraftPlugin pl = new MinecraftPlugin("./plugins/", "Chunky", "0.0.0", "pop4959", 0, 0, null);
28 | pl.customCheckURL = "https://api.modrinth.com/v2/project/chunky/version";
29 | pl.customDownloadURL = "https://cdn.modrinth.com/data/fALzjamp/versions/dPliWter/Chunky-1.4.16.jar";
30 | SearchResult sr = new CustomCheckURL().doCustomCheck(pl.customCheckURL, pl.getVersion());
31 | assertSame(SearchResult.Type.UPDATE_AVAILABLE, sr.type);
32 | }
33 |
34 | @Test
35 | void testModrinth() throws IOException {
36 | UtilsTest.init();
37 | MinecraftPlugin pl = new MinecraftPlugin("./plugins/", "BMMarker", "0.0.0", "Miraculixx", 0, 0, null);
38 | pl.modrinthId = "a8UoyV2h";
39 | SearchResult sr = new ModrinthAPI().searchUpdatePlugin(pl, "1.21.1");
40 | assertSame(SearchResult.Type.UPDATE_AVAILABLE, sr.type);
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/src/test/java/com/osiris/autoplug/client/tasks/updater/server/TaskServerUpdaterTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2022-2024 Osiris-Team.
3 | * All rights reserved.
4 | *
5 | * This software is copyrighted work, licensed under the terms
6 | * of the MIT-License. Consult the "LICENSE" file for details.
7 | */
8 |
9 | package com.osiris.autoplug.client.tasks.updater.server;
10 |
11 | import com.osiris.autoplug.client.UtilsTest;
12 | import com.osiris.autoplug.client.configs.UpdaterConfig;
13 | import com.osiris.autoplug.client.utils.tasks.MyBThreadManager;
14 | import com.osiris.betterthread.BWarning;
15 | import com.osiris.jlib.logger.AL;
16 |
17 | import java.util.List;
18 |
19 | import static org.junit.jupiter.api.Assertions.assertEquals;
20 | import static org.junit.jupiter.api.Assertions.assertTrue;
21 |
22 | class TaskServerUpdaterTest {
23 |
24 | private void defaultTest(String serverSoftware) throws Exception {
25 | defaultTest(serverSoftware, null);
26 | }
27 |
28 | private void defaultTest(String serverSoftware, String version) throws Exception {
29 | if (true) return; // TODO RE-ENABLE TESTS
30 | if (version == null) version = "1.18.2";
31 | UtilsTest.init();
32 | MyBThreadManager maMan = UtilsTest.createManagerWithDisplayer();
33 | UpdaterConfig updaterConfig = new UpdaterConfig();
34 | updaterConfig.load();
35 | updaterConfig.server_updater.setValues("true");
36 | updaterConfig.server_updater_profile.setValues("AUTOMATIC");
37 | updaterConfig.server_software.setValues(serverSoftware);
38 | updaterConfig.server_updater_version.setValues(version);
39 | updaterConfig.server_build_id.setValues("");
40 | updaterConfig.save();
41 | new TaskServerUpdater("ServerUpdater", maMan.manager)
42 | .start(); // Do not run too often because of rest API limits
43 | maMan.printer.join(); // Wait for completion
44 | List warnings = maMan.manager.getAllWarnings();
45 | for (BWarning warning : warnings) {
46 | AL.warn(warning.getExtraInfo(), warning.getException());
47 | }
48 | assertEquals(0, warnings.size());
49 | assertTrue(maMan.manager.getAll().get(0).isSuccess());
50 | }
51 |
52 | @org.junit.jupiter.api.Test
53 | void testSpigot() throws Exception {
54 | defaultTest("spigot", "1.16.5");
55 | }
56 |
57 | @org.junit.jupiter.api.Test
58 | void testWindSpigot() throws Exception {
59 | defaultTest("windspigot");
60 | }
61 |
62 | @org.junit.jupiter.api.Test
63 | void testBungeeCord() throws Exception {
64 | defaultTest("bungeecord");
65 | }
66 |
67 | @org.junit.jupiter.api.Test
68 | void testPaper() throws Exception {
69 | defaultTest("paper");
70 | }
71 |
72 | @org.junit.jupiter.api.Test
73 | void testWaterfall() throws Exception {
74 | defaultTest("waterfall", "1.18");
75 | }
76 |
77 | @org.junit.jupiter.api.Test
78 | void testVelocity() throws Exception {
79 | defaultTest("velocity", "3.1.1");
80 | }
81 |
82 | @org.junit.jupiter.api.Test
83 | void testTravertine() throws Exception {
84 | defaultTest("travertine", "1.16");
85 | }
86 |
87 | @org.junit.jupiter.api.Test
88 | void testPurpur() throws Exception {
89 | defaultTest("purpur");
90 | }
91 |
92 | @org.junit.jupiter.api.Test
93 | void testFabric() throws Exception {
94 | defaultTest("fabric");
95 | }
96 |
97 | @org.junit.jupiter.api.Test
98 | void testSpongeVanilla() throws Exception {
99 | defaultTest("spongevanilla");
100 | }
101 |
102 | @org.junit.jupiter.api.Test
103 | void testSpongeForge() throws Exception {
104 | defaultTest("spongeforge", "1.16.5");
105 | }
106 |
107 | @org.junit.jupiter.api.Test
108 | void testPatina() throws Exception {
109 | defaultTest("patina");
110 | }
111 |
112 | @org.junit.jupiter.api.Test
113 | void testPufferfish() throws Exception {
114 | defaultTest("pufferfish");
115 | }
116 |
117 | @org.junit.jupiter.api.Test
118 | void testMirai() throws Exception {
119 | defaultTest("mirai");
120 | }
121 |
122 | @org.junit.jupiter.api.Test
123 | void testPearl() throws Exception {
124 | defaultTest("pearl");
125 | }
126 |
127 |
128 | }
--------------------------------------------------------------------------------
/src/test/java/com/osiris/autoplug/client/utils/SteamCMDTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2023 Osiris-Team.
3 | * All rights reserved.
4 | *
5 | * This software is copyrighted work, licensed under the terms
6 | * of the MIT-License. Consult the "LICENSE" file for details.
7 | */
8 |
9 | package com.osiris.autoplug.client.utils;
10 |
11 | import com.osiris.autoplug.client.UtilsTest;
12 | import org.junit.jupiter.api.Test;
13 |
14 | import java.io.IOException;
15 |
16 | class SteamCMDTest {
17 |
18 | @Test
19 | void installSteamcmd() throws IOException {
20 | UtilsTest.init();
21 | new SteamCMD().installIfNeeded();
22 | }
23 | }
--------------------------------------------------------------------------------
/src/test/java/com/osiris/autoplug/client/utils/UtilsFileTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2022 Osiris-Team.
3 | * All rights reserved.
4 | *
5 | * This software is copyrighted work, licensed under the terms
6 | * of the MIT-License. Consult the "LICENSE" file for details.
7 | */
8 |
9 | package com.osiris.autoplug.client.utils;
10 |
11 | import org.junit.jupiter.api.Test;
12 |
13 | import static org.junit.jupiter.api.Assertions.assertEquals;
14 |
15 | class UtilsFileTest {
16 |
17 | @Test
18 | void getSafeFileName() {
19 | assertEquals("", new UtilsFile().getValidFileName("/\\\\<>:\"'|*?\u0000\u0001\u0002\u0010\n"));
20 | }
21 | }
--------------------------------------------------------------------------------
/src/test/java/com/osiris/autoplug/client/utils/UtilsLoggerTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2022 Osiris-Team.
3 | * All rights reserved.
4 | *
5 | * This software is copyrighted work, licensed under the terms
6 | * of the MIT-License. Consult the "LICENSE" file for details.
7 | */
8 |
9 | package com.osiris.autoplug.client.utils;
10 |
11 | import org.junit.jupiter.api.Test;
12 |
13 | import java.io.IOException;
14 |
15 | class UtilsLoggerTest {
16 |
17 | @Test
18 | void animatedPrintln() throws InterruptedException, IOException {
19 | UtilsLogger uLog = new UtilsLogger();
20 | uLog.animatedPrintln("Thank you for installing AutoPlug!");
21 | // DOESNT WORK IN INTELLIJ CONSOLE
22 | }
23 | }
--------------------------------------------------------------------------------
/src/test/java/com/osiris/autoplug/client/utils/UtilsMapTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2022 Osiris-Team.
3 | * All rights reserved.
4 | *
5 | * This software is copyrighted work, licensed under the terms
6 | * of the MIT-License. Consult the "LICENSE" file for details.
7 | */
8 |
9 | package com.osiris.autoplug.client.utils;
10 |
11 | import org.junit.jupiter.api.Test;
12 |
13 | import java.util.HashMap;
14 | import java.util.Map;
15 |
16 | class UtilsMapTest {
17 | @Test
18 | void sortByValue() {
19 | UtilsMap utilsMap = new UtilsMap();
20 | Map map = new HashMap<>();
21 | map.put("fifty", 50);
22 | map.put("null", 0);
23 | map.put("ten", 10);
24 | utilsMap.printStringMap(utilsMap.getSortedByValue(map));
25 | }
26 | }
--------------------------------------------------------------------------------
/src/test/java/com/osiris/autoplug/client/utils/UtilsStringTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2022 Osiris-Team.
3 | * All rights reserved.
4 | *
5 | * This software is copyrighted work, licensed under the terms
6 | * of the MIT-License. Consult the "LICENSE" file for details.
7 | */
8 |
9 | package com.osiris.autoplug.client.utils;
10 |
11 | import org.junit.jupiter.api.Test;
12 |
13 | import java.util.List;
14 |
15 | import static org.junit.jupiter.api.Assertions.assertEquals;
16 |
17 | class UtilsStringTest {
18 |
19 | @Test
20 | void splitBySpacesAndQuotes() throws Exception {
21 | List l;
22 | l = new UtilsString().splitBySpacesAndQuotes("hello there");
23 | assertEquals(2, l.size());
24 | l = new UtilsString().splitBySpacesAndQuotes("\"Hello there\" my friend \"!\"");
25 | assertEquals(4, l.size());
26 | l = new UtilsString().splitBySpacesAndQuotes("hello there \"mate\"");
27 | assertEquals(3, l.size());
28 | assertEquals("hello", l.get(0));
29 | assertEquals("there", l.get(1));
30 | assertEquals("\"mate\"", l.get(2));
31 | l = new UtilsString().splitBySpacesAndQuotes("" +
32 | "\"D:\\Coding\\JAVA\\AutoPlug-Client\\AP-TEST-SERVER\\autoplug\\system\\jre\\jdk-17.0.1+12\\bin\\java.exe\"" +
33 | " -Xms2G" +
34 | " -Xmx2G" +
35 | " -jar" +
36 | " D:\\Coding\\JAVA\\AutoPlug-Client\\AP-TEST-SERVER\\fabric-server-mc.1.18.2-loader.0.13.3-launcher.0.10.2.jar" +
37 | " nogui");
38 | assertEquals(6, l.size());
39 | }
40 | }
--------------------------------------------------------------------------------