From 70a68282aaafb0520f3e27f7390c996eeb65a590 Mon Sep 17 00:00:00 2001 From: zontreck Date: Sun, 23 Feb 2025 01:49:18 -0700 Subject: [PATCH] move stuff --- .../zontreck/ariaslib/http/HTTPMethod.java | 8 - .../zontreck/ariaslib/http/HTTPRequest.java | 14 -- .../ariaslib/http/HTTPRequestBuilder.java | 131 -------------- .../zontreck/ariaslib/http/HTTPResponse.java | 32 ---- .../zontreck/ariaslib/terminal/Banners.java | 47 ----- .../com/zontreck/ariaslib/terminal/Task.java | 86 ---------- .../terminal/TaskCompletionToken.java | 20 --- .../com/zontreck/ariaslib/util/FileIO.java | 51 ------ .../com/zontreck/ariaslib/util/Hashing.java | 120 ------------- .../com/zontreck/ariaslib/util/Lists.java | 94 ---------- .../java/com/zontreck/ariaslib/util/Maps.java | 49 ------ .../com/zontreck/ariaslib/util/MathUtil.java | 18 -- .../com/zontreck/ariaslib/util/Percent.java | 23 --- .../com/zontreck/ariaslib/util/Progress.java | 56 ------ .../zontreck/ariaslib/util/ProgressBar.java | 66 ------- .../zontreck/ariaslib/util/TimeNotation.java | 161 ------------------ .../com/zontreck/ariaslib/util/TimeUtil.java | 96 ----------- .../com/zontreck/effects/FlightEffect.java | 84 --------- 18 files changed, 1156 deletions(-) delete mode 100644 src/old/java/com/zontreck/ariaslib/http/HTTPMethod.java delete mode 100644 src/old/java/com/zontreck/ariaslib/http/HTTPRequest.java delete mode 100644 src/old/java/com/zontreck/ariaslib/http/HTTPRequestBuilder.java delete mode 100644 src/old/java/com/zontreck/ariaslib/http/HTTPResponse.java delete mode 100644 src/old/java/com/zontreck/ariaslib/terminal/Banners.java delete mode 100644 src/old/java/com/zontreck/ariaslib/terminal/Task.java delete mode 100644 src/old/java/com/zontreck/ariaslib/terminal/TaskCompletionToken.java delete mode 100644 src/old/java/com/zontreck/ariaslib/util/FileIO.java delete mode 100644 src/old/java/com/zontreck/ariaslib/util/Hashing.java delete mode 100644 src/old/java/com/zontreck/ariaslib/util/Lists.java delete mode 100644 src/old/java/com/zontreck/ariaslib/util/Maps.java delete mode 100644 src/old/java/com/zontreck/ariaslib/util/MathUtil.java delete mode 100644 src/old/java/com/zontreck/ariaslib/util/Percent.java delete mode 100644 src/old/java/com/zontreck/ariaslib/util/Progress.java delete mode 100644 src/old/java/com/zontreck/ariaslib/util/ProgressBar.java delete mode 100644 src/old/java/com/zontreck/ariaslib/util/TimeNotation.java delete mode 100644 src/old/java/com/zontreck/ariaslib/util/TimeUtil.java delete mode 100644 src/old/java/com/zontreck/effects/FlightEffect.java diff --git a/src/old/java/com/zontreck/ariaslib/http/HTTPMethod.java b/src/old/java/com/zontreck/ariaslib/http/HTTPMethod.java deleted file mode 100644 index 0841bef..0000000 --- a/src/old/java/com/zontreck/ariaslib/http/HTTPMethod.java +++ /dev/null @@ -1,8 +0,0 @@ -package com.zontreck.ariaslib.http; - -public enum HTTPMethod { - GET, - POST, - PUT, - DELETE -} diff --git a/src/old/java/com/zontreck/ariaslib/http/HTTPRequest.java b/src/old/java/com/zontreck/ariaslib/http/HTTPRequest.java deleted file mode 100644 index e3fddab..0000000 --- a/src/old/java/com/zontreck/ariaslib/http/HTTPRequest.java +++ /dev/null @@ -1,14 +0,0 @@ -package com.zontreck.ariaslib.http; - -public class HTTPRequest { - - public String url; - - public String method; - public String body; - public String contentType; - - protected HTTPRequest() { - - } -} diff --git a/src/old/java/com/zontreck/ariaslib/http/HTTPRequestBuilder.java b/src/old/java/com/zontreck/ariaslib/http/HTTPRequestBuilder.java deleted file mode 100644 index 526b750..0000000 --- a/src/old/java/com/zontreck/ariaslib/http/HTTPRequestBuilder.java +++ /dev/null @@ -1,131 +0,0 @@ -package com.zontreck.ariaslib.http; - -import java.io.*; -import java.net.HttpURLConnection; -import java.net.MalformedURLException; -import java.net.URL; - -public class HTTPRequestBuilder { - - private HttpURLConnection connection; - private URL url; - private HTTPRequest request = new HTTPRequest(); - - public static HTTPRequestBuilder builder() { - return new HTTPRequestBuilder(); - } - - protected HTTPRequestBuilder() { - - } - - /** - * Sets the url in this request to the one supplied - * - * @param url The url to connect to - * @return Builder instance - * @throws MalformedURLException If the URL supplied was invalid - */ - public HTTPRequestBuilder withURL(String url) throws MalformedURLException { - request.url = url; - this.url = new URL(url); - - return this; - } - - /** - * Sets the HTTP Request method - * - * @param method The method you want to use - * @see HTTPMethod - * @return Builder instance - */ - public HTTPRequestBuilder withMethod(HTTPMethod method) { - switch (method) { - case GET: { - request.method = "GET"; - break; - } - case POST: { - request.method = "POST"; - if (request.contentType.isEmpty()) - request.contentType = "application/x-www-form-urlencoded"; - break; - } - case DELETE: { - request.method = "DELETE"; - break; - } - case PUT: { - request.method = "PUT"; - if (request.contentType.isEmpty()) - request.contentType = "application/x-www-form-urlencoded"; - break; - } - } - - return this; - } - - /** - * Sets the request body. This may only be processed by the server when using - * POST or PUT, depending on the server's setup - * - * @param body The body to upload - * @return Builder Instance - */ - public HTTPRequestBuilder withBody(String body) { - request.body = body; - return this; - } - - /** - * Sets the content type header - * Default: application/x-www-form-urlencoded for POST/PUT, and null/not present - * for GET - * - * @param type - * @return - */ - public HTTPRequestBuilder withContentType(String type) { - request.contentType = type; - return this; - } - - public HTTPResponse build() { - try { - connection = (HttpURLConnection) url.openConnection(); - connection.setRequestMethod(request.method); - byte[] array = request.body.getBytes("UTF-8"); - connection.setRequestProperty("Content-Length", "" + array.length); - connection.setRequestProperty("Content-Type", request.contentType); - connection.setDoInput(true); - connection.setUseCaches(false); - connection.setDoOutput(true); - DataOutputStream dos = new DataOutputStream(connection.getOutputStream()); - dos.write(array); - dos.flush(); - dos.close(); - - // Get the response body - InputStream inputStream = connection.getInputStream(); - BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream)); - StringBuilder response = new StringBuilder(); - String line; - - while ((line = reader.readLine()) != null) { - response.append(line); - } - reader.close(); - inputStream.close(); - - String responseBody = response.toString(); - - return new HTTPResponse(connection.getContentType(), connection.getResponseCode(), responseBody, request); - } catch (IOException e) { - throw new RuntimeException(e); - } finally { - connection.disconnect(); - } - } -} diff --git a/src/old/java/com/zontreck/ariaslib/http/HTTPResponse.java b/src/old/java/com/zontreck/ariaslib/http/HTTPResponse.java deleted file mode 100644 index d7640b4..0000000 --- a/src/old/java/com/zontreck/ariaslib/http/HTTPResponse.java +++ /dev/null @@ -1,32 +0,0 @@ -package com.zontreck.ariaslib.http; - -public class HTTPResponse { - private String ContentType; - private int ResponseCode; - private String ResponseBody; - private HTTPRequest OriginalRequest; - - protected HTTPResponse(String contentType, int code, String body, HTTPRequest request) { - this.ContentType = contentType; - this.ResponseCode = code; - this.ResponseBody = body; - this.OriginalRequest = request; - - } - - public String getContentType() { - return ContentType; - } - - public int getResponseCode() { - return ResponseCode; - } - - public String getResponseBody() { - return ResponseBody; - } - - public HTTPRequest getOriginalRequest() { - return OriginalRequest; - } -} diff --git a/src/old/java/com/zontreck/ariaslib/terminal/Banners.java b/src/old/java/com/zontreck/ariaslib/terminal/Banners.java deleted file mode 100644 index 5545acd..0000000 --- a/src/old/java/com/zontreck/ariaslib/terminal/Banners.java +++ /dev/null @@ -1,47 +0,0 @@ -package com.zontreck.ariaslib.terminal; - -import java.util.ArrayList; -import java.util.List; - -public class Banners -{ - - public static String generateBanner(String text) { - int maxLength = calculateMaxLength(text); - List bannerLines = new ArrayList<>(); - StringBuilder border = new StringBuilder(); - for (int i = 0; i < maxLength + 4; i++) { - border.append("*"); - } - bannerLines.add(border.toString()); - bannerLines.add("* " + centerText(text, maxLength) + " *"); - bannerLines.add(border.toString()); - return String.join("\n", bannerLines); - } - - private static String centerText(String text, int maxLength) { - StringBuilder centeredText = new StringBuilder(); - int spacesToAdd = (maxLength - text.length()) / 2; - for (int i = 0; i < spacesToAdd; i++) { - centeredText.append(" "); - } - centeredText.append(text); - for (int i = 0; i < spacesToAdd; i++) { - centeredText.append(" "); - } - if (centeredText.length() < maxLength) { - centeredText.append(" "); - } - return centeredText.toString(); - } - - private static int calculateMaxLength(String text) { - int maxLength = 0; - for (String line : text.split("\n")) { - if (line.length() > maxLength) { - maxLength = line.length(); - } - } - return maxLength; - } -} diff --git a/src/old/java/com/zontreck/ariaslib/terminal/Task.java b/src/old/java/com/zontreck/ariaslib/terminal/Task.java deleted file mode 100644 index fb57e09..0000000 --- a/src/old/java/com/zontreck/ariaslib/terminal/Task.java +++ /dev/null @@ -1,86 +0,0 @@ -package com.zontreck.ariaslib.terminal; - -import com.zontreck.ariaslib.util.Progress; - -import java.util.TimerTask; - -public abstract class Task extends TimerTask implements Runnable { - public final String TASK_NAME; - private TaskCompletionToken token = new TaskCompletionToken ( ); - - public static final String CHECK = "P"; - public static final String FAIL = "F"; - // Else use the progress spinner from the Progress class - private boolean isSilent = false; - - public Task ( String name ) { - TASK_NAME = name; - } - - /** - * This constructor is meant to be used to create silent tasks that do not output to the console. (Example usage: DelayedExecutionService) - * - * @param name Task name - * @param silent Whether to print to the terminal - */ - public Task ( String name , boolean silent ) { - this ( name ); - isSilent = silent; - } - - - public boolean isComplete ( ) { - return token.get ( ); - } - - public void startTask ( ) { - Thread tx = new Thread(this); - tx.start(); - - if(! isSilent) - { - Thread tx2 = new Thread(new SpinnerTask(token, this)); - tx2.start(); - } - } - - public void stopTask ( ) { - if ( token.get ( ) && ! isSilent ) { - System.out.printf ( "\r" + TASK_NAME + "\t\t[" + token.status + "]\n" ); - } - } - - public void setSuccess ( ) { - token.completed ( CHECK ); - } - - public void setFail ( ) { - token.completed ( FAIL ); - } - - public class SpinnerTask extends Task { - public final Task task; - public final TaskCompletionToken token; - private final Progress spinner = new Progress ( 100 ); - - public SpinnerTask ( TaskCompletionToken token , Task parent ) { - super ( "spinner" , true ); - this.token = token; - this.task = parent; - } - - @Override - public void run ( ) { - while ( ! task.isComplete ( ) ) { - try { - Thread.sleep ( 50L ); - - if ( ! task.isSilent && ! task.isComplete ( ) ) - System.out.printf ( "\r" + task.TASK_NAME + "\t\t" + spinner.getSpinnerTick ( ) + "\r" ); - } catch ( Exception e ) { - e.printStackTrace ( ); - } - } - } - } -} \ No newline at end of file diff --git a/src/old/java/com/zontreck/ariaslib/terminal/TaskCompletionToken.java b/src/old/java/com/zontreck/ariaslib/terminal/TaskCompletionToken.java deleted file mode 100644 index 6094019..0000000 --- a/src/old/java/com/zontreck/ariaslib/terminal/TaskCompletionToken.java +++ /dev/null @@ -1,20 +0,0 @@ -package com.zontreck.ariaslib.terminal; - -import java.util.concurrent.atomic.AtomicBoolean; - -/** - * Should not be re-used for multiple tasks!!! - */ -public class TaskCompletionToken -{ - private AtomicBoolean complete = new AtomicBoolean(false); - public String status = ""; - public void completed(String reason){ - status=reason; - complete.set(true); - } - - public boolean get(){ - return complete.get(); - } -} diff --git a/src/old/java/com/zontreck/ariaslib/util/FileIO.java b/src/old/java/com/zontreck/ariaslib/util/FileIO.java deleted file mode 100644 index f517adf..0000000 --- a/src/old/java/com/zontreck/ariaslib/util/FileIO.java +++ /dev/null @@ -1,51 +0,0 @@ -package com.zontreck.ariaslib.util; - -import java.io.File; -import java.io.IOException; -import java.nio.file.Files; -import java.nio.file.Paths; - -public class FileIO -{ - - public static String readFile(String filePath) { - try { - byte[] fileBytes = Files.readAllBytes(Paths.get(filePath)); - return new String(fileBytes); - } catch (IOException e) { - return "An error occurred: " + e.getMessage(); - } - } - public static void writeFile(String filePath, String newContent) { - try { - Files.write(Paths.get(filePath), newContent.getBytes()); - } catch (IOException e) { - } - } - - - /** - * Recursively delete a directory - * @param directory The folder to delete - */ - public static void deleteDirectory(File directory) { - if (directory.exists()) { - File[] files = directory.listFiles(); - if (files != null) { - for (File file : files) { - if (file.isDirectory()) { - deleteDirectory(file); - } else { - file.delete(); - } - } - } - // Now directory is empty, so delete it - directory.delete(); - System.out.println("Directory deleted: " + directory.getAbsolutePath()); - } else { - System.out.println("Directory does not exist: " + directory.getAbsolutePath()); - } - } -} - diff --git a/src/old/java/com/zontreck/ariaslib/util/Hashing.java b/src/old/java/com/zontreck/ariaslib/util/Hashing.java deleted file mode 100644 index 08c77c2..0000000 --- a/src/old/java/com/zontreck/ariaslib/util/Hashing.java +++ /dev/null @@ -1,120 +0,0 @@ -package com.zontreck.ariaslib.util; - -import java.security.MessageDigest; -import java.security.NoSuchAlgorithmException; - -public class Hashing -{ - - - /** - * A md5 hashing function that is compatible with literally every other hashing function out there - * @param input The string to hash - * @return The hash - */ - public static String md5(String input) { - try { - MessageDigest md = MessageDigest.getInstance("MD5"); - md.update(input.getBytes()); - - byte[] byteData = md.digest(); - - // Convert the byte array to a hexadecimal string - StringBuilder hexString = new StringBuilder(); - for (byte aByteData : byteData) { - String hex = Integer.toHexString(0xff & aByteData); - if (hex.length() == 1) { - hexString.append('0'); - } - hexString.append(hex); - } - return hexString.toString(); - } catch (NoSuchAlgorithmException e) { - e.printStackTrace(); - return null; - } - } - /** - * A md5 hashing function that is compatible with literally every other hashing function out there - * @param input The bytes to hash - * @return The hash - */ - public static String md5(byte[] input) { - try { - MessageDigest md = MessageDigest.getInstance("MD5"); - md.update(input); - - byte[] byteData = md.digest(); - - // Convert the byte array to a hexadecimal string - StringBuilder hexString = new StringBuilder(); - for (byte aByteData : byteData) { - String hex = Integer.toHexString(0xff & aByteData); - if (hex.length() == 1) { - hexString.append('0'); - } - hexString.append(hex); - } - return hexString.toString(); - } catch (NoSuchAlgorithmException e) { - e.printStackTrace(); - return null; - } - } - - - /** - * A sha256 hashing function that is compatible with literally every other hashing function out there - * @param input The string to hash - * @return The hash - */ - public static String sha256(String input) { - try { - MessageDigest md = MessageDigest.getInstance("SHA256"); - md.update(input.getBytes()); - - byte[] byteData = md.digest(); - - // Convert the byte array to a hexadecimal string - StringBuilder hexString = new StringBuilder(); - for (byte aByteData : byteData) { - String hex = Integer.toHexString(0xff & aByteData); - if (hex.length() == 1) { - hexString.append('0'); - } - hexString.append(hex); - } - return hexString.toString(); - } catch (NoSuchAlgorithmException e) { - e.printStackTrace(); - return null; - } - } - /** - * A sha256 hashing function that is compatible with literally every other hashing function out there - * @param input The bytes to hash - * @return The hash - */ - public static String sha256(byte[] input) { - try { - MessageDigest md = MessageDigest.getInstance("SHA256"); - md.update(input); - - byte[] byteData = md.digest(); - - // Convert the byte array to a hexadecimal string - StringBuilder hexString = new StringBuilder(); - for (byte aByteData : byteData) { - String hex = Integer.toHexString(0xff & aByteData); - if (hex.length() == 1) { - hexString.append('0'); - } - hexString.append(hex); - } - return hexString.toString(); - } catch (NoSuchAlgorithmException e) { - e.printStackTrace(); - return null; - } - } -} diff --git a/src/old/java/com/zontreck/ariaslib/util/Lists.java b/src/old/java/com/zontreck/ariaslib/util/Lists.java deleted file mode 100644 index f0fe39b..0000000 --- a/src/old/java/com/zontreck/ariaslib/util/Lists.java +++ /dev/null @@ -1,94 +0,0 @@ -package com.zontreck.ariaslib.util; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; - -public class Lists -{ - /** - * Programatically constructs a list - * @param values The list of values - * @return The new list - * @param An arbitrary type parameter - */ - public static List of(T... values) - { - List arr = new ArrayList<>(); - for(T value : values) - { - arr.add(value); - } - - return arr; - } - - - /** - * Splits a string into a list - * @param input The string to split - * @param delimiters The list of delimiters - * @return A non-strided list - */ - public static List split(String input, String... delimiters) { - List result = new ArrayList<>(); - StringBuilder regex = new StringBuilder("("); - - // Constructing the regular expression pattern with provided delimiters - for (String delimiter : delimiters) { - regex.append(delimiter).append("|"); - } - regex.deleteCharAt(regex.length() - 1); // Remove the extra '|' character - regex.append(")"); - - String[] tokens = input.split(regex.toString()); - - // Add non-empty tokens to the result list - for (String token : tokens) { - if (!token.isEmpty()) { - result.add(token); - } - } - - return result; - } - - /** - * Split a string, and keep the delimiters - * @param input The string to be parsed and split - * @param delimiters A list of delimiters - * @return A strided list containing the parsed options, and the delimiters - */ - public static List splitWithDelim(String input, String... delimiters) { - List result = new ArrayList<>(); - StringBuilder regex = new StringBuilder("("); - - // Constructing the regular expression pattern with provided delimiters - for (String delimiter : delimiters) { - regex.append(delimiter).append("|"); - } - regex.deleteCharAt(regex.length() - 1); // Remove the extra '|' character - regex.append(")"); - - // Splitting the input string using the regex pattern - String[] tokens = input.split(regex.toString()); - - // Adding tokens and delimiters to the result list in a strided manner - for (int i = 0; i < tokens.length; i++) { - if (!tokens[i].isEmpty()) { - result.add(tokens[i]); - } - // Adding delimiter if it exists and it's not the last token - if (i < tokens.length - 1) { - result.add(input.substring(input.indexOf(tokens[i]) + tokens[i].length(), input.indexOf(tokens[i + 1]))); - } - } - - return result; - } - - - private Lists(){ - - } -} diff --git a/src/old/java/com/zontreck/ariaslib/util/Maps.java b/src/old/java/com/zontreck/ariaslib/util/Maps.java deleted file mode 100644 index d8de013..0000000 --- a/src/old/java/com/zontreck/ariaslib/util/Maps.java +++ /dev/null @@ -1,49 +0,0 @@ -package com.zontreck.ariaslib.util; - -import java.util.HashMap; -import java.util.Map; - -/** - * Utility class to assist in creating a dictionary programmatically in one line of code. - */ -public class Maps -{ - /** - * This takes a list of entries and returns a HashMap - * @param entries The entries you want in your hashmap - * @return The map itself - * @param Any typed parameter - * @param Any typed parameter - */ - public static Map of(Entry... entries) { - Map map = new HashMap<>(); - for(Entry E : entries) - { - map.put(E.key, E.value); - } - - return map; - } - - /** - * A virtual entry used only by the Maps#of function. - * @see Maps#of(Entry[]) - * @param Any typed parameter - * @param Any typed parameter - */ - public static class Entry { - public final A key; - public final B value; - - /** - * Initializes the readonly entry - * @param a The dictionary key - * @param b The value - */ - public Entry(A a, B b) - { - this.key=a; - this.value=b; - } - } -} diff --git a/src/old/java/com/zontreck/ariaslib/util/MathUtil.java b/src/old/java/com/zontreck/ariaslib/util/MathUtil.java deleted file mode 100644 index 4dc7924..0000000 --- a/src/old/java/com/zontreck/ariaslib/util/MathUtil.java +++ /dev/null @@ -1,18 +0,0 @@ -package com.zontreck.ariaslib.util; - -/** - * This class will be used to house math helper functions - */ -public class MathUtil -{ - /** - * A newer helper function to get the percentage with large number support - * @param current Min value - * @param max Maximum value for progress - * @return Percentage - */ - public static int getPercent(long current, long max) - { - return Math.round(current*100/max); - } -} diff --git a/src/old/java/com/zontreck/ariaslib/util/Percent.java b/src/old/java/com/zontreck/ariaslib/util/Percent.java deleted file mode 100644 index a8e75d7..0000000 --- a/src/old/java/com/zontreck/ariaslib/util/Percent.java +++ /dev/null @@ -1,23 +0,0 @@ -package com.zontreck.ariaslib.util; - -import java.io.PrintStream; - -public class Percent -{ - int current; - int maximum; - - public Percent(int cur, int max) - { - current=cur; - maximum=max; - } - - - public int get() - { - return ((current * 100) / maximum); - } - - -} diff --git a/src/old/java/com/zontreck/ariaslib/util/Progress.java b/src/old/java/com/zontreck/ariaslib/util/Progress.java deleted file mode 100644 index af51310..0000000 --- a/src/old/java/com/zontreck/ariaslib/util/Progress.java +++ /dev/null @@ -1,56 +0,0 @@ -package com.zontreck.ariaslib.util; - -import java.util.concurrent.atomic.AtomicInteger; - -public class Progress -{ - private int maximum; - private int current; - private AtomicInteger tickNum = new AtomicInteger(0); - private static final String TICKS="-\\|/"; - - public String getSpinnerTick() - { - if(tickNum.get()>=TICKS.length()) tickNum.set(0); - - return "[" + TICKS.substring(tickNum.getAndIncrement(), tickNum.get()) + "]"; - } - - public Progress(int maximum) - { - current=0; - this.maximum=maximum; - } - - public int getPercent(){ - return (current*100/maximum); - } - - public String getPercentStr() - { - return (getPercent()+"%"); - } - - public static int getPercentOf(int current, int max) - { - return (current*100/max); - } - - public void increment(){ - current++; - sanity(); - } - private void sanity(){ - if(current > maximum) current = maximum; - if(current < 0)current = 0; - } - public void decrement(){ - current--; - sanity(); - } - - public void setCurrent(int cur) - { - current=cur; - } -} diff --git a/src/old/java/com/zontreck/ariaslib/util/ProgressBar.java b/src/old/java/com/zontreck/ariaslib/util/ProgressBar.java deleted file mode 100644 index 5fbcb84..0000000 --- a/src/old/java/com/zontreck/ariaslib/util/ProgressBar.java +++ /dev/null @@ -1,66 +0,0 @@ -package com.zontreck.ariaslib.util; - -import java.io.PrintStream; - -/** - * Utility to create an ascii progress bar - */ -public class ProgressBar -{ - - private static final int DEFAULT_BAR_WIDTH = 50; - - /** - * Reserved spaces for the brackets, and the carrot, and the percent value. - */ - private static final int PROGRESS_BAR_RESERVED=5; - - /** - * Always will return 80 - * @return 80 - */ - private static int getConsoleWidth() { - return 80; // Default console width, can be adjusted for different consoles - } - - /** - * Build a progress bar - *

- * your text here [========= ] 40% your text here - * @param percent The percentage - * @param beforeText - * @param afterText - * @return ProgressBar as a String - */ - public static String printProgressBar(int percent, String beforeText, String afterText) { - StringBuilder sb = new StringBuilder(); - int consoleWidth = getConsoleWidth(); - int barWidth = Math.min(consoleWidth - beforeText.length() - afterText.length() - PROGRESS_BAR_RESERVED, DEFAULT_BAR_WIDTH); - - // Calculate progress - int progressBarLength = (int) ((double) percent / 100 * barWidth); - - // Print before text - sb.append(beforeText); - - // Print progress bar - sb.append("["); - for (int i = 0; i < barWidth; i++) { - if (i < progressBarLength) { - sb.append("="); - }else if(i==progressBarLength) sb.append(">"); - else { - sb.append(" "); - } - } - sb.append("]"); - - // Print percentage - sb.append(" " + percent + "%"); - - // Print after text - sb.append(afterText); - - return sb.toString(); - } -} diff --git a/src/old/java/com/zontreck/ariaslib/util/TimeNotation.java b/src/old/java/com/zontreck/ariaslib/util/TimeNotation.java deleted file mode 100644 index 6ea72eb..0000000 --- a/src/old/java/com/zontreck/ariaslib/util/TimeNotation.java +++ /dev/null @@ -1,161 +0,0 @@ -package com.zontreck.ariaslib.util; - -import java.util.List; - -/** - * Contains useful structures and functions for dealing with, and manipulation of, time. - */ -public class TimeNotation -{ - public int Years; - public int Months; - public int Weeks; - public int Days; - public int Hours; - public int Minutes; - public int Seconds; - - public TimeNotation(int years, int months, int weeks, int days, int hours, int minutes, int seconds) - { - Years=years; - Months=months; - Weeks=weeks; - Days=days; - Hours=hours; - Minutes=minutes; - Seconds = seconds; - } - - private TimeNotation(){} - - - @Override - public String toString() { - String str = - someOrNone(Years,Pluralize(Years, "year") + ", ") + - someOrNone(Months, Pluralize(Months, "month") + ", ") + - someOrNone(Weeks, Pluralize(Weeks, "week") + ", ") + - someOrNone(Days, Pluralize(Days, "day") + ", ") + - someOrNone(Hours, Pluralize(Hours, "hour") + ", ") + - someOrNone(Minutes, Pluralize(Minutes, "minute") + ", ") + - someOrNone(Seconds, Pluralize(Seconds, "second")); - - if(str == ""){ - return "No Seconds"; - } else return str; - } - - /** - * Create a plural version for a number - * @param num The number to prefix - * @param str The singular form of the string - * @return Combined string, num + str in plural form if necessary - */ - private String Pluralize(int num, String str) - { - return num + " " + ((num > 1) ? str+"s" : str); - } - - /** - * A simple function to test a number, return a string, or return nothing at all. - * @param num The number to check - * @param str The string to return if the number is greater than zero - * @return Str if num >1, or empty string - */ - private String someOrNone(int num, String str) - { - if(num > 0) return str; - else return ""; - } - /** - * A simple function to test a number, return a string, or return something else. - * @param num The number to check - * @param str The string to return if the number is greater than zero - * @return Str if num >1, or other string - */ - private String someOrOther(int num, String str, String other) - { - if(num > 0) return str; - else return other; - } - - /** - * Encodes time notation! - * @return A program readable string that can be decoded back to a time notation - */ - public String toNotation() - { - return Years + "Y" + Months + "M" + Weeks + "W" + Days + "d" + Hours + "h" + Minutes + "m" + Seconds + "s"; - } - - /** - * Parses a time notation string - * @param notation Serialized time notation - * @return The deserialized time notation object - */ - public static TimeNotation fromNotation(String notation) - { - TimeNotation notationX = new TimeNotation(); - String[] delims = new String[]{"Y", "M", "W", "d", "h", "m", "s"}; - List opts = Lists.split(notation, delims); - - - int index = 0; - for(String dlim : delims) - { - if(notation.contains(dlim)) - { - switch (dlim) - { - case "Y": - { - notationX.Years = Integer.parseInt(opts.get(index)); - - break; - } - case "M": - { - notationX.Months = Integer.parseInt(opts.get(index)); - - break; - } - case "W": - { - notationX.Weeks = Integer.parseInt(opts.get(index)); - - break; - } - case "d": - { - notationX.Days = Integer.parseInt(opts.get(index)); - - break; - } - case "h": - { - notationX.Hours = Integer.parseInt(opts.get(index)); - - break; - } - case "m": - { - notationX.Minutes = Integer.parseInt(opts.get(index)); - - break; - } - case "s": - { - notationX.Seconds = Integer.parseInt(opts.get(index)); - - break; - } - } - - index++; - } - } - - return notationX; - - } -} diff --git a/src/old/java/com/zontreck/ariaslib/util/TimeUtil.java b/src/old/java/com/zontreck/ariaslib/util/TimeUtil.java deleted file mode 100644 index 587cb16..0000000 --- a/src/old/java/com/zontreck/ariaslib/util/TimeUtil.java +++ /dev/null @@ -1,96 +0,0 @@ -package com.zontreck.ariaslib.util; - -/** - * This class is a helper with some minecraft specific functions - */ -public class TimeUtil -{ - /** - * Converts seconds to ticks. (seconds*ticks) - * @param seconds Number of seconds - * @param ticks Number of ticks in a single second - * @return Number of ticks - */ - public static int secondsToTicks(int seconds, int ticks) - { - return seconds*ticks; - } - - /** - * Converts the number of ticks to seconds - * @param ticks The number of ticks to convert - * @param ticksInASecond The number of ticks in a single second - * @return Number of seconds - */ - public static int ticksToSeconds(int ticks, int ticksInASecond) - { - return ticks / ticksInASecond; - } - - /** - * Encodes a LibAC Time Notation - * @param seconds Number of seconds to convert - * @return Time Notation - */ - public static TimeNotation secondsToTimeNotation(int seconds) - { - int years = seconds / YEAR; - if(years > 0) seconds -= YEAR * years; - - int month = seconds / MONTH; - if(month > 0) seconds -= MONTH * month; - - int week = seconds / WEEK; - if(week > 0) seconds -= WEEK * week; - - int day = seconds / DAY; - if(day > 0) seconds -= DAY * day; - - int hour = seconds / HOUR; - if(hour > 0) seconds -= HOUR * hour; - - int minute = seconds / MINUTE; - if(minute > 0) seconds -= MINUTE * minute; - - return new TimeNotation(years, month, week, day, hour, minute, seconds); - } - - /** - * Convert a time notation to seconds - * @param notation Notation to convert - * @return Total seconds - */ - public static int notationToSeconds(TimeNotation notation) - { - int seconds = 0; - - seconds += (notation.Years * YEAR); - seconds += (notation.Months * MONTH); - seconds += (notation.Weeks * WEEK); - seconds += (notation.Days * DAY); - seconds += (notation.Hours * HOUR); - seconds += (notation.Minutes * MINUTE); - seconds += (notation.Seconds); - - return seconds; - } - - - public static final int SECOND; - public static final int MINUTE; - public static final int HOUR; - public static final int DAY; - public static final int WEEK; - public static final int MONTH; - public static final int YEAR; - - static { - SECOND = 1; - MINUTE = SECOND * 60; - HOUR = MINUTE * 60; - DAY = HOUR*24; - WEEK = DAY*7; - MONTH = WEEK*4; - YEAR = DAY*365; - } -} diff --git a/src/old/java/com/zontreck/effects/FlightEffect.java b/src/old/java/com/zontreck/effects/FlightEffect.java deleted file mode 100644 index 07ffba1..0000000 --- a/src/old/java/com/zontreck/effects/FlightEffect.java +++ /dev/null @@ -1,84 +0,0 @@ -package com.zontreck.effects; - - -import com.zontreck.Messages; -import com.zontreck.libzontreck.util.ChatHelpers; -import com.zontreck.libzontreck.util.ServerUtilities; -import net.minecraft.server.level.ServerPlayer; -import net.minecraft.world.effect.MobEffect; -import net.minecraft.world.effect.MobEffectCategory; -import net.minecraft.world.entity.LivingEntity; -import net.minecraft.world.entity.ai.attributes.AttributeMap; -import net.minecraft.world.entity.player.Player; - -public class FlightEffect extends MobEffect { - int lastDuration = -1; - ServerPlayer myPlayer; - protected FlightEffect(MobEffectCategory pCategory, int pColor) { - super(pCategory, pColor); - } - - @Override - public boolean isDurationEffectTick(int pDuration, int pAmplifier) { - lastDuration=pDuration; - - if(myPlayer!=null) { - if(myPlayer.getAbilities().mayfly == false) { - myPlayer.getAbilities().mayfly=true; - myPlayer.onUpdateAbilities(); - } - } - - //OTEMod.LOGGER.info("Effect duration: " + lastDuration); - return pDuration > 0; - } - - @Override - public boolean isBeneficial() { - return true; - } - - @Override - public void addAttributeModifiers(LivingEntity entity, AttributeMap map, int i) { - super.addAttributeModifiers(entity, map, i); - - if(entity instanceof ServerPlayer player) - { - if(player.getAbilities().mayfly==false) - { - myPlayer=player; - player.getAbilities().mayfly=true; - player.onUpdateAbilities(); - - ChatHelpers.broadcastTo(player, ChatHelpers.macro(Messages.FLIGHT_GIVEN), player.server); - } - } - } - - private void removeFlightModifier(LivingEntity entity) - { - if(lastDuration == -1) - { - return; - } - if ( entity instanceof Player player ) - { - if(ServerUtilities.isServer() && lastDuration < (5*20)) - { - ServerPlayer serverPlayer = (ServerPlayer) player; - serverPlayer.getAbilities().mayfly = false; - serverPlayer.getAbilities().flying = false; - - serverPlayer.onUpdateAbilities(); - - ChatHelpers.broadcastTo(serverPlayer, ChatHelpers.macro(Messages.FLIGHT_REMOVED), serverPlayer.server); - } - } - } - - @Override - public void removeAttributeModifiers(LivingEntity entity, AttributeMap p_19470_, int p_19471_) { - super.removeAttributeModifiers(entity, p_19470_, p_19471_); - removeFlightModifier(entity); - } -}