splitText = new ArrayList<>(Arrays.asList(text.split("§")));
16 | String lastColor = ChatColour.GRAY;
17 | if (splitText.size() == 1) {
18 | strongArr.add(getParagraphElement(splitText.get(0), ChatColour.GRAY, "normal", "none"));
19 | } else {
20 | //For every individualSplitText in splitText
21 | for (String inSplitText : splitText) {
22 | if (inSplitText.startsWith("0")) {
23 | //black
24 | strongArr.add(getParagraphElement(removeFirstChar(inSplitText), ChatColour.BLACK, "normal", "none"));
25 | lastColor = ChatColour.BLACK;
26 | } else if (inSplitText.startsWith("1")) {
27 | //dark blue
28 | strongArr.add(getParagraphElement(removeFirstChar(inSplitText), ChatColour.DARK_BLUE, "normal", "none"));
29 | lastColor = ChatColour.DARK_BLUE;
30 | } else if (inSplitText.startsWith("2")) {
31 | //dark green
32 | strongArr.add(getParagraphElement(removeFirstChar(inSplitText), ChatColour.DARK_GREEN, "normal", "none"));
33 | lastColor = ChatColour.DARK_GREEN;
34 | } else if (inSplitText.startsWith("3")) {
35 | //Dark Aqua
36 | strongArr.add(getParagraphElement(removeFirstChar(inSplitText), ChatColour.DARK_AQUA, "normal", "none"));
37 | lastColor = ChatColour.DARK_AQUA;
38 | } else if (inSplitText.startsWith("4")) {
39 | //Dark red
40 | strongArr.add(getParagraphElement(removeFirstChar(inSplitText), ChatColour.DARK_RED, "normal", "none"));
41 | lastColor = ChatColour.DARK_RED;
42 | } else if (inSplitText.startsWith("5")) {
43 | //Dark purple
44 | strongArr.add(getParagraphElement(removeFirstChar(inSplitText), ChatColour.DARK_PURPLE, "normal", "none"));
45 | lastColor = ChatColour.DARK_PURPLE;
46 | } else if (inSplitText.startsWith("6")) {
47 | //Gold
48 | strongArr.add(getParagraphElement(removeFirstChar(inSplitText), ChatColour.GOLD, "normal", "none"));
49 | lastColor = ChatColour.GOLD;
50 | } else if (inSplitText.startsWith("7")) {
51 | //Gray
52 | strongArr.add(getParagraphElement(removeFirstChar(inSplitText), ChatColour.GRAY, "normal", "none"));
53 | lastColor = ChatColour.GRAY;
54 | } else if (inSplitText.startsWith("8")) {
55 | //Dark gray
56 | strongArr.add(getParagraphElement(removeFirstChar(inSplitText), ChatColour.DARK_GRAY, "normal", "none"));
57 | lastColor = ChatColour.DARK_GRAY;
58 | } else if (inSplitText.startsWith("9")) {
59 | //Blue
60 | strongArr.add(getParagraphElement(removeFirstChar(inSplitText), ChatColour.BLUE, "normal", "none"));
61 | lastColor = ChatColour.BLUE;
62 | } else if (inSplitText.startsWith("a")) {
63 | //Green
64 | strongArr.add(getParagraphElement(removeFirstChar(inSplitText), ChatColour.GREEN, "normal", "none"));
65 | lastColor = ChatColour.GREEN;
66 | } else if (inSplitText.startsWith("b")) {
67 | //Aqua
68 | strongArr.add(getParagraphElement(removeFirstChar(inSplitText), ChatColour.AQUA, "normal", "none"));
69 | lastColor = ChatColour.AQUA;
70 | } else if (inSplitText.startsWith("c")) {
71 | //Red
72 | strongArr.add(getParagraphElement(removeFirstChar(inSplitText), ChatColour.RED, "normal", "none"));
73 | lastColor = ChatColour.RED;
74 | } else if (inSplitText.startsWith("d")) {
75 | //Light purple
76 | strongArr.add(getParagraphElement(removeFirstChar(inSplitText), ChatColour.LIGHT_PURPLE, "normal", "none"));
77 | lastColor = ChatColour.LIGHT_PURPLE;
78 | } else if (inSplitText.startsWith("e")) {
79 | //Yellow
80 | strongArr.add(getParagraphElement(removeFirstChar(inSplitText), ChatColour.YELLOW, "normal", "none"));
81 | lastColor = ChatColour.YELLOW;
82 | } else if (inSplitText.startsWith("f")) {
83 | //White
84 | strongArr.add(getParagraphElement(removeFirstChar(inSplitText), ChatColour.WHITE, "normal", "none"));
85 | lastColor = ChatColour.WHITE;
86 | } else if (inSplitText.startsWith("k")) {
87 | //obfuscated
88 | int leftLimit = 97; // letter 'a'
89 | int rightLimit = 122; // letter 'z'
90 | Random random = new Random();
91 |
92 | String generatedText = random.ints(leftLimit, rightLimit + 1)
93 | .limit(inSplitText.length()) //limit the lengh to the lengh of the source string
94 | .collect(StringBuilder::new, StringBuilder::appendCodePoint, StringBuilder::append)
95 | .toString();
96 |
97 | strongArr.add(getParagraphElement(inSplitText, lastColor, "normal", "none"));
98 | } else if (inSplitText.startsWith("l")) {
99 | //bold
100 | strongArr.add(getParagraphElement(removeFirstChar(inSplitText), lastColor, "bold", "none"));
101 | } else if (inSplitText.startsWith("m")) {
102 | //strikethroug
103 | strongArr.add(getParagraphElement(removeFirstChar(inSplitText), lastColor, "normal", "line-through"));
104 | } else if (inSplitText.startsWith("n")) {
105 | //underline
106 | strongArr.add(getParagraphElement(removeFirstChar(inSplitText), lastColor, "normal", "underline"));
107 | } else if (inSplitText.startsWith("o")) {
108 | //italic
109 | strongArr.add("" + text + "");
110 | } else if (inSplitText.startsWith("r")) { //Proveriti u slucaju greske
111 | //reset
112 | lastColor = ChatColour.GRAY;
113 | strongArr.add(getParagraphElement(removeFirstChar(inSplitText), ChatColour.GRAY, "normal", "none"));
114 | } else {
115 | lastColor = ChatColour.GRAY;
116 | strongArr.add(getParagraphElement(inSplitText, ChatColour.GRAY, "normal", "none"));
117 | }
118 | }
119 | }
120 | //After the md is done , we can assemble the paragraph
121 | //DebugMD - strongArr.add(text);
122 | String paragraph = "";
123 | for (String strong : strongArr) {
124 | paragraph += strong;
125 | }
126 | paragraph += "
";
127 | return paragraph.replace("\n", "");
128 | }
129 |
130 | private static String removeFirstChar(String s) {
131 | return s.substring(1);
132 | }
133 |
134 | private static String getParagraphElement(String text, String color, String fontWeight, String textDecoration) {
135 | return "" + text + "";
136 | }
137 | }
138 |
--------------------------------------------------------------------------------
/src/main/java/app/admintools/textprocessing/TellrawFormatter.java:
--------------------------------------------------------------------------------
1 | package app.admintools.textprocessing;
2 |
3 | /**
4 | *
5 | * @author lukak
6 | */
7 | public class TellrawFormatter {
8 |
9 | public static String assembleSimpleTellraw(String message) {
10 | return "tellraw @a [\"\",{\"text\":\"[Admin Tools]\",\"color\":\"#00FF82\"},{\"text\":\" " + message + "\",\"color\":\"#E1E1E1\"},{\"text\":\" \"}]";
11 | }
12 |
13 | public static String assembleLoginTellraw(String username) {
14 | return "tellraw @a [\"\",{\"text\":\"[Admin Tools] \",\"color\":\"#00FF82\"},{\"text\":\"" + username + " \",\"color\":\"aqua\"},{\"text\":\"logged in\",\"color\":\"#E1E1E1\"}]";
15 | }
16 |
17 | public static String assembleLogoutTellraw(String username) {
18 | return "tellraw @a [\"\",{\"text\":\"[Admin Tools] \",\"color\":\"#00FF82\"},{\"text\":\"" + username + " \",\"color\":\"aqua\"},{\"text\":\"logged out\",\"color\":\"#E1E1E1\"}]";
19 | }
20 |
21 | public static String assembleSayTellraw(String username, String message) {
22 | return "tellraw @a [\"\",{\"text\":\"[Admin Tools] \",\"color\":\"#00FF82\"},{\"text\":\"" + username + " \",\"color\":\"aqua\"},{\"text\":\"said : " + message + "\",\"color\":\"#E1E1E1\"}]";
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/src/main/java/app/admintools/threadmanager/ThreadManager.java:
--------------------------------------------------------------------------------
1 | /*
2 | * To change this license header, choose License Headers in Project Properties.
3 | * To change this template file, choose Tools | Templates
4 | * and open the template in the editor.
5 | */
6 | package app.admintools.threadmanager;
7 |
8 | import java.util.ArrayList;
9 |
10 | /**
11 | *
12 | * @author lukak
13 | */
14 | public class ThreadManager {
15 |
16 | private static ArrayList singleThreadPool = new ArrayList();
17 |
18 | /**
19 | * Managed starting of threads. Beware worker thread management uses names
20 | *
21 | * @param thread Thread that is going to be started.
22 | * @param type Type of thread. If the ThreadType is WORKER the thread
23 | * will be started only if its the only thread of its type in the
24 | * application, and if its ThreadType is ASYNCJOB then it starts
25 | * anyways.
26 | * @return If the thread has been started
27 | */
28 | public static boolean startThread(Thread thread, ThreadType type) {
29 | if (type == ThreadType.WORKER) {
30 | if (!singleThreadPool.contains(thread.getName())) {
31 | singleThreadPool.add(thread.getName());
32 | thread.start();
33 | System.out.println("Started thread " + thread.getName());
34 | return true;
35 | }
36 | return false;
37 | }
38 | if (type == ThreadType.ASYNCJOB) {
39 | thread.start();
40 | return true;
41 | }
42 | return false;
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/src/main/java/app/admintools/threadmanager/ThreadType.java:
--------------------------------------------------------------------------------
1 | /*
2 | * To change this license header, choose License Headers in Project Properties.
3 | * To change this template file, choose Tools | Templates
4 | * and open the template in the editor.
5 | */
6 | package app.admintools.threadmanager;
7 |
8 | /**
9 | *
10 | * @author lukak
11 | */
12 | public enum ThreadType {
13 | WORKER,
14 | ASYNCJOB
15 | }
16 |
--------------------------------------------------------------------------------
/src/main/java/app/admintools/util/AtLogger.java:
--------------------------------------------------------------------------------
1 | package app.admintools.util;
2 |
3 | import java.io.File;
4 | import java.io.IOException;
5 | import java.io.InputStream;
6 | import java.util.Arrays;
7 | import java.util.Objects;
8 | import java.util.logging.Level;
9 | import java.util.logging.LogManager;
10 | import java.util.logging.Logger;
11 |
12 | /**
13 | *
14 | * @author lukak
15 | */
16 | public class AtLogger {
17 | public static Logger logger = null;
18 |
19 | public static void init(){
20 | if(logger == null){
21 | try {
22 | //%1$tY-%1$tm-%1$td %1$tH:%1$tM:%1$tS %4$s %2$s %5$s%6$s%n
23 | //"[%1$tF %1$tT] [%6$-10s] [%4$-7s] %5$s %n"
24 | System.setProperty("java.util.logging.SimpleFormatter.format", "[%1$tF %1$tT] (%2$s) [%4$-7s] %5$s %n");
25 | LogManager.getLogManager().readConfiguration();
26 | } catch (IOException e) {
27 | e.printStackTrace();
28 | }
29 | logger = Logger.getLogger(AtLogger.class.getName());
30 | }
31 | }
32 |
33 | public static String formatException(Exception ex){
34 | return ex.getClass().getName() + " : " + ex.getMessage();
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/src/main/java/app/admintools/util/CustomRcon.java:
--------------------------------------------------------------------------------
1 | package app.admintools.util;
2 |
3 | import java.io.IOException;
4 | import java.net.Socket;
5 | import java.nio.charset.StandardCharsets;
6 |
7 | import net.kronos.rkon.core.Rcon;
8 | import net.kronos.rkon.core.ex.AuthenticationException;
9 | import app.admintools.textprocessing.TellrawFormatter;
10 |
11 | public class CustomRcon extends Rcon {
12 |
13 | private static CustomRcon instance;
14 |
15 | private CustomRcon(String host, int port, byte[] password) throws IOException, AuthenticationException {
16 | super(host, port, password);
17 | }
18 |
19 | public static CustomRcon getInstance() throws IOException, AuthenticationException {
20 | if (instance == null) {
21 | //Variable declaration
22 | Data data = Data.getInstance();
23 | String host = data.getSelectedCredentials().getIP();
24 | int port = data.getSelectedCredentials().getPort();
25 | byte[] password = data.getSelectedCredentials().getPassword().getBytes(StandardCharsets.UTF_8);
26 |
27 | //Reading configuration from file
28 | //Constructing the instance
29 | instance = new CustomRcon(host, port, password);
30 | }
31 | //Returns the instance
32 | return instance;
33 | }
34 |
35 | public static CustomRcon getInstance(String host, int port, byte[] password) throws IOException, AuthenticationException {
36 | instance = null;
37 | instance = new CustomRcon(host, port, password);
38 | return instance;
39 | }
40 |
41 | public static void setToNull(){
42 | instance = null;
43 | }
44 |
45 | //Short-circuit evaluation
46 | private static boolean empty(final String s) {
47 | return s == null || s.trim().isEmpty();
48 | }
49 |
50 | @Override
51 | public String command(String payload) throws IOException {
52 | String uc = "Unknown command";
53 | Data data = Data.getInstance();
54 | if (!empty(payload)) {
55 | if (data.getMessageOverwriteSay()) {
56 | if (payload.split(" ")[0].equals("say")) {
57 | payload = TellrawFormatter.assembleSayTellraw(data.getMessageUsername(), payload.substring(payload.indexOf(" ") + 1));
58 | }
59 | }
60 | String response = super.command(payload);
61 | if (empty(response)) {
62 | return "No command response";
63 | }
64 | if (response.startsWith(uc)) {
65 | return uc;
66 | }
67 | return response;
68 | }
69 | return uc;
70 | }
71 |
72 | @Override
73 | public String toString() {
74 | Socket s = getSocket();
75 | return s.getInetAddress() + ":" + s.getPort();
76 | }
77 | }
78 |
--------------------------------------------------------------------------------
/src/main/java/app/admintools/util/DRPC.java:
--------------------------------------------------------------------------------
1 | package app.admintools.util;
2 |
3 | import net.arikia.dev.drpc.DiscordEventHandlers;
4 | import net.arikia.dev.drpc.DiscordRPC;
5 | import net.arikia.dev.drpc.DiscordRichPresence;
6 |
7 | public class DRPC {
8 | /**
9 | * Initialise the discord rich presence.
10 | */
11 | public static void initialise(){
12 | DiscordEventHandlers handlers = new DiscordEventHandlers.Builder().setReadyEventHandler((user) -> {
13 | AtLogger.logger.info( "Connected to discord rpc as " + user.username + ":" + user.discriminator);
14 | }).build();
15 | DiscordRPC.discordInitialize("790613792702726185", handlers ,true);
16 | DiscordRPC.discordRegister("790613792702726185", "");
17 | DiscordRPC.discordRunCallbacks();
18 | DiscordRichPresence rich = new DiscordRichPresence.Builder("In home").setDetails("").setStartTimestamps(System.currentTimeMillis()).setBigImage("default", "AdminTools release " + Version.getInstance().getStrippedVersion()).build();
19 | DiscordRPC.discordUpdatePresence(rich);
20 | }
21 |
22 | /**
23 | * Update the discord rich presence status.
24 | * @param richPresence The next rich presence.
25 | */
26 | public static void updateStatus(DiscordRichPresence richPresence){
27 | DiscordRPC.discordUpdatePresence(richPresence);
28 | AtLogger.logger.info("Updated status : " + richPresence.details);
29 | }
30 |
31 | /**
32 | * Simple generation of a instance of DiscordRichPresence.
33 | * @param state The current state of the user for example In Home.
34 | * @param details More details.
35 | * @return A instance of DiscordRichPresence.
36 | */
37 | public static DiscordRichPresence generatePresence(String state, String details){
38 | String bigImage;
39 | if(Version.getInstance().isDevelopmentVersion()){
40 | bigImage = "dev";
41 | }else {
42 | bigImage = "default";
43 | }
44 | return new DiscordRichPresence.Builder(state).setDetails(details).setStartTimestamps(System.currentTimeMillis()).setBigImage(bigImage, "AdminTools release " + Version.getInstance().getStrippedVersion()).build();
45 | }
46 |
47 | /**
48 | * Simple generation of a instance of DiscordRichPresence.
49 | * @param state The current state of the user for example In Home.
50 | * @return A instance of DiscordRichPresence.
51 | */
52 | public static DiscordRichPresence generatePresence(String state){
53 | return generatePresence(state, "");
54 | }
55 |
56 | public static void statusManagingServer() {
57 | DRPC.updateStatus(DRPC.generatePresence("Managing server"));
58 | }
59 | }
60 |
--------------------------------------------------------------------------------
/src/main/java/app/admintools/util/Data.java:
--------------------------------------------------------------------------------
1 | /*
2 | * To change this license header, choose License Headers in Project Properties.
3 | * To change this template file, choose Tools | Templates
4 | * and open the template in the editor.
5 | */
6 | package app.admintools.util;
7 |
8 | import java.io.File;
9 | import java.io.FileInputStream;
10 | import java.io.FileNotFoundException;
11 | import java.io.FileOutputStream;
12 | import java.io.IOException;
13 | import java.io.InputStream;
14 | import java.io.OutputStream;
15 | import java.lang.module.ModuleDescriptor;
16 | import java.util.ArrayList;
17 | import java.util.Arrays;
18 | import java.util.HashMap;
19 | import java.util.Properties;
20 | import app.admintools.security.credentials.Credentials;
21 |
22 | /**
23 | *
24 | * @author lukak
25 | */
26 | public class Data {
27 | //All the variables
28 |
29 | static File config = new File("admintools.properties");
30 |
31 | //public data
32 | /**
33 | * Java arguments
34 | */
35 | public static String[] arguments = new String[1];
36 | /**
37 | * Text and contents from the webview
38 | */
39 | public static ArrayList rconTextData = null;
40 |
41 | //Used in rconWindow to get if its starting up
42 | //In versions >5.0.0 it is used to indicate if the selected credentials have changed
43 | public static boolean startingUp = true;
44 |
45 | /**
46 | * Is the view on the status window
47 | * Used in stopping and starting tick threads in the status window
48 | */
49 | public static boolean isOnStatusWindow = false;
50 |
51 | /**
52 | * Selected credentials
53 | */
54 | private static Credentials credentials = null;
55 |
56 | private static final String VERSION = "7.0.0.0.0";
57 |
58 | //Singleton
59 | private static Data instance = null;
60 |
61 | private Data() {
62 | if (!config.exists()) {
63 | try {
64 | write(DataType.RCON_REMEMBER, defaults.get(DataType.RCON_REMEMBER));
65 | write(DataType.QUERRY_API_REFRESHRATE, defaults.get(DataType.QUERRY_API_REFRESHRATE));
66 | write(DataType.QUERRY_MC_REFRESHRATE, defaults.get(DataType.QUERRY_MC_REFRESHRATE));
67 | write(DataType.MESSAGE_SEND_ON_LOGON, defaults.get(DataType.MESSAGE_SEND_ON_LOGON));
68 | write(DataType.MESSAGE_OVERWRITE_SAY, defaults.get(DataType.MESSAGE_OVERWRITE_SAY));
69 | write(DataType.USERNAME, defaults.get(DataType.USERNAME));
70 | write(DataType.THEME, defaults.get(DataType.THEME));
71 | } catch (IOException e) {
72 | AtLogger.logger.severe(AtLogger.formatException(e));
73 | }
74 | }
75 | }
76 |
77 | /**
78 | * Gets the instance of DATA
79 | *
80 | * @return instance of DATA
81 | */
82 | public static Data getInstance() {
83 | if (instance == null) {
84 | instance = new Data();
85 | }
86 | return instance;
87 | }
88 |
89 | /**
90 | * Refreshes Data instance
91 | *
92 | * @return Data instanceaa
93 | */
94 | public static Data refresh() {
95 | instance = new Data();
96 | return instance;
97 | }
98 |
99 | /**
100 | * Gets the stored selected credentials
101 | * @return Credentials instance
102 | */
103 | public Credentials getSelectedCredentials(){
104 | return credentials;
105 | }
106 |
107 | /**
108 | *
109 | * @param creds
110 | */
111 | public static void setSelectedCredentials(Credentials creds){
112 | credentials = creds;
113 | startingUp = true; //Sets starting up to true to indicate to the rconWindow that stuff has changed
114 | }
115 |
116 |
117 | /**
118 | * Gets remember property
119 | *
120 | * @return remember property
121 | */
122 | public boolean getRconRemember() throws IOException {
123 | return Boolean.parseBoolean(read(DataType.RCON_REMEMBER));
124 | }
125 |
126 | /**
127 | * Gets the refresh rate for mc serv querry
128 | *
129 | * @return refresh rate
130 | */
131 | public int getQuerryMcRefreshRate() throws IOException {
132 | return Integer.parseInt(read(DataType.QUERRY_MC_REFRESHRATE));
133 | }
134 |
135 | /**
136 | * Gets refresh rate for Mojang API
137 | *
138 | * @return refresh rate
139 | */
140 | public double getQuerryMojangApiRefreshRate() throws IOException {
141 | return Double.parseDouble(read(DataType.QUERRY_API_REFRESHRATE));
142 | }
143 |
144 | public boolean getMessageNotify() throws IOException {
145 | return Boolean.parseBoolean(read(DataType.MESSAGE_SEND_ON_LOGON));
146 | }
147 |
148 | public boolean getMessageOverwriteSay() throws IOException {
149 | return Boolean.parseBoolean(read(DataType.MESSAGE_OVERWRITE_SAY));
150 | }
151 |
152 | public String getMessageUsername() throws IOException {
153 | return read(DataType.USERNAME);
154 | }
155 |
156 | public String getSelectedTheme() throws IOException {
157 | return read(DataType.THEME);
158 | }
159 | /**
160 | * Default valiues for the properties
161 | * "false", "10", "100", "false", "false", "username", "Default"
162 | */
163 | public static HashMap defaults = new HashMap<>(){{
164 | put(DataType.RCON_REMEMBER, "false");
165 | put(DataType.QUERRY_MC_REFRESHRATE, "10");
166 | put(DataType.QUERRY_API_REFRESHRATE, "100");
167 | put(DataType.MESSAGE_SEND_ON_LOGON, "false");
168 | put(DataType.MESSAGE_OVERWRITE_SAY, "false");
169 | put(DataType.USERNAME, "username");
170 | put(DataType.THEME, "default");
171 | }};
172 |
173 | /**
174 | * Writes the properties to disk
175 | *
176 | * @param key Key
177 | * @param value The valiue to write
178 | */
179 | public static void write(String key, String value) throws IOException {
180 | Properties prop = new Properties();
181 | OutputStream output = new FileOutputStream(config);
182 | prop.setProperty(key, value);
183 | prop.store(output, "AdminTools properties" + System.lineSeparator() + "Created by: LukeOnuke - https://github.com/LukeOnuke");
184 | }
185 |
186 | /**
187 | * Reads the properties from disk
188 | *
189 | * @return ArrayList of properites
190 | */
191 | public static String read(String key) throws IOException {
192 | Properties prop = new Properties();
193 | InputStream input = new FileInputStream(config);
194 | prop.load(input);
195 | return prop.getProperty(key, defaults.get(key));
196 | }
197 | }
198 |
--------------------------------------------------------------------------------
/src/main/java/app/admintools/util/DataType.java:
--------------------------------------------------------------------------------
1 | package app.admintools.util;
2 |
3 | public class DataType {
4 | public static final String RCON_REMEMBER = "rcon.remember";
5 | public static final String QUERRY_MC_REFRESHRATE = "querry.mc.refreshrate";
6 | public static final String QUERRY_API_REFRESHRATE = "querry.api.mojang.refreshrate";
7 | public static final String MESSAGE_SEND_ON_LOGON = "message.send.on.login";
8 | public static final String MESSAGE_OVERWRITE_SAY = "message.overwrite.say";
9 | public static final String USERNAME = "message.username";
10 | public static final String THEME = "theme.selected";
11 | }
12 |
--------------------------------------------------------------------------------
/src/main/java/app/admintools/util/Utill.java:
--------------------------------------------------------------------------------
1 | package app.admintools.util;
2 |
3 | import javafx.scene.Parent;
4 | import javafx.scene.Scene;
5 | import javafx.scene.layout.AnchorPane;
6 | import org.apache.commons.lang3.SystemUtils;
7 |
8 | import java.io.BufferedReader;
9 | import java.io.File;
10 | import java.io.IOException;
11 | import java.io.InputStreamReader;
12 | import java.net.HttpURLConnection;
13 | import java.net.URL;
14 | import java.text.SimpleDateFormat;
15 | import java.util.Date;
16 |
17 | /**
18 | *
19 | * @author lukak
20 | */
21 | public class Utill {
22 |
23 | public static String getDate() {
24 | SimpleDateFormat sd = new SimpleDateFormat("[HH:mm:ss] ");
25 | return sd.format(new Date());
26 | }
27 |
28 | /**
29 | * Gets responce of GET request sent to a url
30 | *
31 | * @param getUrl The url of the server to witch we send the GET request
32 | * @return String of what the servers responce was to the get request
33 | * @throws IOException When there is a IO error
34 | */
35 | public static String getHTTPRequest(String getUrl) throws IOException {
36 | URL obj = new URL(getUrl);
37 | HttpURLConnection con = (HttpURLConnection) obj.openConnection(); //create HTTP connection
38 | con.setRequestMethod("GET"); //Send get request
39 |
40 | int responseCode = con.getResponseCode(); //responce code
41 | if (responseCode == HttpURLConnection.HTTP_OK) { // success
42 | BufferedReader in = new BufferedReader(new InputStreamReader(
43 | con.getInputStream()));
44 | String inputLine;
45 | StringBuffer response = new StringBuffer();
46 |
47 | while ((inputLine = in.readLine()) != null) {
48 | response.append(inputLine);
49 | }
50 | in.close();
51 |
52 | //return the results lol
53 | return response.toString();
54 | } else {
55 | throw new IOException();
56 | }
57 | }
58 |
59 | public static String removeSpigotFormatting(String commandReply) {
60 | commandReply = commandReply.replaceAll("[§][1-9a-zA-Z]", ""); //remove numbers and letters
61 |
62 | return commandReply;
63 | }
64 |
65 | public static void exit(int code) {
66 | System.exit(code);
67 | }
68 |
69 | /**
70 | * https://stackoverflow.com/questions/924394/how-to-get-the-filename-without-the-extension-in-java
71 | * @param str
72 | * @return
73 | */
74 | public static String stripExtension (String str) {
75 | // Handle null case specially.
76 |
77 | if (str == null) return null;
78 |
79 | // Get position of last '.'.
80 |
81 | int pos = str.lastIndexOf(".");
82 |
83 | // If there wasn't any '.' just return the string as is.
84 |
85 | if (pos == -1) return str;
86 |
87 | // Otherwise return the string, up to the dot.
88 |
89 | return str.substring(0, pos);
90 | }
91 |
92 | public static String removeArrrayFormatting(String string){
93 | return string.replace(",", "").replace("[", "").replace("]", "");
94 | }
95 |
96 | public static String getPath(String path){
97 | if(SystemUtils.IS_OS_WINDOWS){
98 | return path.replace("\\", "/");
99 | }
100 | return path.replace("\\", File.separator).replace("/", File.separator);
101 |
102 | }
103 |
104 | public static void setSelectedTheme(AnchorPane anchorPane){
105 | try {
106 | anchorPane.getStylesheets().add(Utill.getPath("file:assets/themes/" + Data.getInstance().getSelectedTheme() + "/style.css"));
107 | } catch (IOException e) {
108 | AtLogger.logger.severe(AtLogger.formatException(e));
109 | }
110 | }
111 |
112 | public static void setSelectedTheme(Parent root){
113 | try {
114 | root.getStylesheets().add(Utill.getPath("file:assets/themes/" + Data.getInstance().getSelectedTheme() + "/style.css"));
115 | } catch (IOException e) {
116 | AtLogger.logger.severe(AtLogger.formatException(e));
117 | }
118 | }
119 |
120 | public static void setSelectedTheme(Scene scene){
121 | try {
122 | scene.getStylesheets().add(Utill.getPath("file:assets/themes/" + Data.getInstance().getSelectedTheme() + "/style.css"));
123 | } catch (IOException e) {
124 | AtLogger.logger.severe(AtLogger.formatException(e));
125 | }
126 | }
127 | }
128 |
--------------------------------------------------------------------------------
/src/main/java/app/admintools/util/Version.java:
--------------------------------------------------------------------------------
1 | package app.admintools.util;
2 |
3 | import java.util.ArrayList;
4 | import java.util.Arrays;
5 | import java.util.concurrent.atomic.AtomicInteger;
6 |
7 | public class Version {
8 | private final String VERSION_NUMBER = "7.1.0";
9 | /**
10 | * Snapshot version, only used if isDevelopmentVersion is true
11 | *
12 | * Version number goes like 23d12m2020y001v . So its [Day Of Release]d[Month Of Release]m[Year Of Release]y[Snapshot Number]v
13 | */
14 | private final String SNAPSHOT_VER = "17d3m2022y000v";
15 | private final boolean isDevelopmentVersion = false;
16 | private static Version instance = null;
17 |
18 | public static Version getInstance() {
19 | if(instance == null){
20 | instance = new Version();
21 | }
22 | return instance;
23 | }
24 |
25 | public String getStrippedVersion(){
26 | return VERSION_NUMBER.substring(0, 5);
27 | }
28 |
29 | public boolean isDevelopmentVersion() {
30 | return isDevelopmentVersion;
31 | }
32 |
33 | public String getSnapshotVersion() {
34 | return SNAPSHOT_VER;
35 | }
36 |
37 | public String getFullVersionNumber() {
38 | return VERSION_NUMBER;
39 | }
40 |
41 | public static int getVersionAsInt(String versionNumber){
42 | versionNumber = versionNumber.replace("v", "");
43 | ArrayList splitVer = new ArrayList<>(Arrays.asList(versionNumber.split("[.]")));
44 | final AtomicInteger multiplier = new AtomicInteger(10000);
45 | final AtomicInteger result = new AtomicInteger(0);
46 | splitVer.forEach((verSegment) -> {
47 | result.getAndAdd(Integer.parseInt(verSegment) * multiplier.get());
48 | multiplier.set(multiplier.get() / 10);
49 | });
50 | return result.get();
51 | }
52 | }
53 |
--------------------------------------------------------------------------------
/src/main/java/app/admintools/util/WindowLoader.java:
--------------------------------------------------------------------------------
1 | /*
2 | * To change this license header, choose License Headers in Project Properties.
3 | * To change this template file, choose Tools | Templates
4 | * and open the template in the editor.
5 | */
6 | package app.admintools.util;
7 |
8 | import java.io.IOException;
9 |
10 | import app.admintools.gui.splash.SplashScreen;
11 | import javafx.animation.FadeTransition;
12 | import javafx.fxml.FXMLLoader;
13 | import javafx.scene.Scene;
14 | import javafx.scene.layout.AnchorPane;
15 | import javafx.stage.Stage;
16 | import javafx.util.Duration;
17 | import app.admintools.gui.SettingsWindowController;
18 |
19 | /**
20 | *
21 | * @author lukak
22 | */
23 | public class WindowLoader {
24 |
25 | public static void loadRcon(AnchorPane rootPane) {
26 | loadWindow(rootPane, Utill.getPath("/gui/fxml/RconWindow.fxml"));
27 | Data.isOnStatusWindow = false;
28 | }
29 |
30 | public static void loadSettings(AnchorPane rootPane) {
31 | loadWindow(rootPane, Utill.getPath("/gui/fxml/SettingsWindow.fxml"));
32 | Data.isOnStatusWindow = false;
33 | }
34 |
35 | public static void loadStatus(AnchorPane rootPane) {
36 | Data.isOnStatusWindow = true;
37 | loadWindow(rootPane, Utill.getPath("/gui/fxml/StatusWindow.fxml"));
38 | }
39 |
40 | public static void loadHome(AnchorPane rootPane) {
41 | loadWindow(rootPane, Utill.getPath("/gui/fxml/HomeWindow.fxml"));
42 | Data.isOnStatusWindow = false;
43 | }
44 |
45 | private static void loadWindow(AnchorPane rootPane, String url) {
46 |
47 | try {
48 | Data d = Data.getInstance(); //Get instance of data
49 |
50 | AnchorPane ap = FXMLLoader.load(SettingsWindowController.class.getResource(url)); //Get anchorpane
51 |
52 | //Set style for selected theme
53 | Utill.setSelectedTheme(ap);
54 |
55 | //Create stage yes
56 | Scene scene2 = new Scene(ap);
57 | Stage windowStage = (Stage) rootPane.getScene().getWindow();
58 | //Get widht and height
59 | double width = windowStage.getWidth();
60 | double height = windowStage.getHeight();
61 |
62 | //Swich scene
63 | windowStage.setScene(scene2);
64 |
65 | //Get fade transition inbetween windows
66 | //Fade in
67 | //Foreach just netben
68 | ap.getChildren().stream().map((child) -> new FadeTransition(Duration.seconds(0.25), child)).map((ft) -> {
69 | ft.setFromValue(.3d);
70 | return ft;
71 | }).map((ft) -> {
72 | ft.setToValue(1.0d);
73 | return ft;
74 | }).forEachOrdered((ft) -> {
75 | ft.play();
76 | });
77 |
78 | //Refresh title
79 | windowStage.setTitle("Admin Tools - " + d.getSelectedCredentials().getIP() + ":" + d.getSelectedCredentials().getPort());
80 |
81 | //Set width after scene swithch
82 | windowStage.setWidth(width);
83 | windowStage.setHeight(height);
84 |
85 | } catch (IOException ex) {
86 | AtLogger.logger.warning(AtLogger.formatException(ex));
87 | }
88 |
89 | }
90 | }
91 |
--------------------------------------------------------------------------------
/src/main/resources/gui/fxml/HomeWindow.fxml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
--------------------------------------------------------------------------------
/src/main/resources/gui/fxml/RconWindow.fxml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
18 |
19 |
20 |
21 |
22 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
--------------------------------------------------------------------------------
/src/main/resources/gui/fxml/SettingsWindow.fxml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
--------------------------------------------------------------------------------
/src/main/resources/gui/fxml/StatusWindow.fxml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
--------------------------------------------------------------------------------
/src/main/resources/img/icon-baked.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/LukeOnuke/AdminTools/0c7fb6b85a304d9966b64568d306b3c8b1afb184/src/main/resources/img/icon-baked.ico
--------------------------------------------------------------------------------
/src/main/resources/img/icon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/LukeOnuke/AdminTools/0c7fb6b85a304d9966b64568d306b3c8b1afb184/src/main/resources/img/icon.png
--------------------------------------------------------------------------------
/src/main/resources/img/unknown-server.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/LukeOnuke/AdminTools/0c7fb6b85a304d9966b64568d306b3c8b1afb184/src/main/resources/img/unknown-server.png
--------------------------------------------------------------------------------