Move the old stuff out of the way, begin fixing one by one
This commit is contained in:
parent
abfaa02ace
commit
6ccef8275c
1579 changed files with 252390 additions and 76 deletions
|
@ -1,72 +1,20 @@
|
||||||
package com.zontreck;
|
package com.zontreck;
|
||||||
|
|
||||||
import com.zontreck.block.DeprecatedModBlocks;
|
|
||||||
import com.zontreck.block.ModBlocks;
|
|
||||||
import com.zontreck.client.TimeBoostEntityRenderer;
|
|
||||||
import com.zontreck.configs.client.AEClientConfig;
|
import com.zontreck.configs.client.AEClientConfig;
|
||||||
import com.zontreck.configs.server.AEServerConfig;
|
import com.zontreck.configs.server.AEServerConfig;
|
||||||
import com.zontreck.effects.ModEffects;
|
|
||||||
import com.zontreck.effects.ModPotions;
|
|
||||||
import com.zontreck.enchantments.ModEnchantments;
|
|
||||||
import com.zontreck.entities.ModEntities;
|
|
||||||
import com.zontreck.items.DeprecatedModItems;
|
|
||||||
import com.zontreck.items.ModItems;
|
|
||||||
import com.zontreck.libzontreck.config.ServerConfig;
|
|
||||||
|
|
||||||
import net.minecraft.client.renderer.entity.EntityRenderers;
|
|
||||||
import net.neoforged.api.distmarker.Dist;
|
|
||||||
import net.neoforged.bus.api.IEventBus;
|
import net.neoforged.bus.api.IEventBus;
|
||||||
import net.neoforged.bus.api.SubscribeEvent;
|
|
||||||
import net.neoforged.fml.common.EventBusSubscriber;
|
|
||||||
import net.neoforged.fml.common.EventBusSubscriber.Bus;
|
|
||||||
import net.neoforged.fml.common.Mod;
|
import net.neoforged.fml.common.Mod;
|
||||||
import net.neoforged.fml.event.lifecycle.FMLClientSetupEvent;
|
|
||||||
|
|
||||||
import java.time.Instant;
|
@Mod(value = AriasEssentials.MOD_ID)
|
||||||
import java.util.Random;
|
public class AriasEssentials {
|
||||||
|
|
||||||
import org.apache.logging.log4j.Logger;
|
|
||||||
|
|
||||||
import com.zontreck.items.CreativeModeTabs;
|
|
||||||
|
|
||||||
import net.neoforged.fml.loading.FMLLoader;
|
|
||||||
import net.neoforged.neoforge.common.NeoForgeMod;
|
|
||||||
|
|
||||||
@Mod(AriasEssentials.MOD_ID)
|
|
||||||
public final class AriasEssentials {
|
|
||||||
public static Logger LOGGER = LoggerFactory.getLogger("ariaessentials");
|
|
||||||
public static final String MOD_ID = "ariasessentials";
|
public static final String MOD_ID = "ariasessentials";
|
||||||
public static final Random random = new Random(Instant.now().getEpochSecond());
|
|
||||||
|
|
||||||
public AriasEssentials(IEventBus bus) {
|
public AriasEssentials(IEventBus bus) {
|
||||||
// This code runs as soon as Minecraft is in a mod-load-ready state.
|
|
||||||
// However, some things (like registries and resources) may still be
|
|
||||||
// uninitialized.
|
|
||||||
// Proceed with mild caution.
|
|
||||||
|
|
||||||
LOGGER.info("/!\\ Loading Aria's Essentials Configuration Files /!\\");
|
|
||||||
AEServerConfig.loadFromFile();
|
AEServerConfig.loadFromFile();
|
||||||
AEClientConfig.loadFromFile();
|
AEClientConfig.loadFromFile();
|
||||||
ServerConfig.init();
|
|
||||||
LOGGER.info("/!\\ DONE LOADING AECONFIG /!\\");
|
|
||||||
|
|
||||||
ModItems.ITEMS.register(bus);
|
|
||||||
CreativeModeTabs.register(bus);
|
|
||||||
ModEntities.register(bus);
|
|
||||||
ModEffects.register(bus);
|
|
||||||
ModPotions.register(bus);
|
|
||||||
DeprecatedModItems.register(bus);
|
|
||||||
ModEnchantments.register(bus);
|
|
||||||
DeprecatedModBlocks.register(bus);
|
|
||||||
ModBlocks.register(bus);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventBusSubscriber(bus = Bus.MOD, value = Dist.CLIENT)
|
|
||||||
public static class ClientModEvents {
|
|
||||||
@SubscribeEvent
|
|
||||||
public static void onClientSetup(FMLClientSetupEvent ev) {
|
|
||||||
EntityRenderers.register(ModEntities.TIAB_ENTITY.get(), TimeBoostEntityRenderer::new);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,10 +1,11 @@
|
||||||
package com.zontreck.configs.client;
|
package com.zontreck.configs.client;
|
||||||
|
|
||||||
|
import java.nio.file.Path;
|
||||||
|
|
||||||
import com.zontreck.libzontreck.util.SNbtIo;
|
import com.zontreck.libzontreck.util.SNbtIo;
|
||||||
import com.zontreck.util.EssentialsDatastore;
|
import com.zontreck.util.EssentialsDatastore;
|
||||||
import net.minecraft.nbt.CompoundTag;
|
|
||||||
|
|
||||||
import java.nio.file.Path;
|
import net.minecraft.nbt.CompoundTag;
|
||||||
|
|
||||||
public class AEClientConfig
|
public class AEClientConfig
|
||||||
{
|
{
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package com.zontreck.configs.server;
|
package com.zontreck.configs.server;
|
||||||
|
|
||||||
import com.zontreck.AriasEssentials;
|
import java.nio.file.Path;
|
||||||
|
|
||||||
import com.zontreck.ariaslib.util.Lists;
|
import com.zontreck.ariaslib.util.Lists;
|
||||||
import com.zontreck.configs.server.sections.Bottles;
|
import com.zontreck.configs.server.sections.Bottles;
|
||||||
import com.zontreck.configs.server.sections.Drops;
|
import com.zontreck.configs.server.sections.Drops;
|
||||||
|
@ -9,11 +10,8 @@ import com.zontreck.configs.server.sections.Teleportation;
|
||||||
import com.zontreck.libzontreck.util.SNbtIo;
|
import com.zontreck.libzontreck.util.SNbtIo;
|
||||||
import com.zontreck.libzontreck.vectors.WorldPosition;
|
import com.zontreck.libzontreck.vectors.WorldPosition;
|
||||||
import com.zontreck.util.EssentialsDatastore;
|
import com.zontreck.util.EssentialsDatastore;
|
||||||
import net.minecraft.nbt.*;
|
|
||||||
|
|
||||||
import java.nio.file.Path;
|
import net.minecraft.nbt.CompoundTag;
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
public class AEServerConfig
|
public class AEServerConfig
|
||||||
{
|
{
|
||||||
|
@ -31,7 +29,6 @@ public class AEServerConfig
|
||||||
{
|
{
|
||||||
AEServerConfig config = new AEServerConfig();
|
AEServerConfig config = new AEServerConfig();
|
||||||
try {
|
try {
|
||||||
AriasEssentials.LOGGER.info("Loading Aria's Essentials configuration for - Server");
|
|
||||||
if(tag.contains(Bottles.TAG_NAME))
|
if(tag.contains(Bottles.TAG_NAME))
|
||||||
{
|
{
|
||||||
config.bottles = Bottles.deserialize(tag.getCompound(Bottles.TAG_NAME));
|
config.bottles = Bottles.deserialize(tag.getCompound(Bottles.TAG_NAME));
|
||||||
|
@ -63,8 +60,6 @@ public class AEServerConfig
|
||||||
}else {
|
}else {
|
||||||
config.worldSpawn = null;
|
config.worldSpawn = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
AriasEssentials.LOGGER.info("Aria's Essentials Server Configuration Loaded");
|
|
||||||
} catch(Exception e){
|
} catch(Exception e){
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,7 +7,7 @@ import java.nio.file.Path;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import net.minecraftforge.fml.loading.FMLPaths;
|
import net.neoforged.fml.loading.FMLPaths;
|
||||||
|
|
||||||
public class FileTreeDatastore {
|
public class FileTreeDatastore {
|
||||||
private static final Path BASE;
|
private static final Path BASE;
|
||||||
|
|
|
@ -1,13 +1,14 @@
|
||||||
package com.zontreck.libzontreck.util;
|
package com.zontreck.libzontreck.util;
|
||||||
|
|
||||||
import com.mojang.brigadier.exceptions.CommandSyntaxException;
|
|
||||||
import com.zontreck.ariaslib.util.FileIO;
|
|
||||||
import net.minecraft.nbt.CompoundTag;
|
|
||||||
import net.minecraft.nbt.NbtUtils;
|
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
|
|
||||||
|
import com.mojang.brigadier.exceptions.CommandSyntaxException;
|
||||||
|
import com.zontreck.ariaslib.util.FileIO;
|
||||||
|
|
||||||
|
import net.minecraft.nbt.CompoundTag;
|
||||||
|
import net.minecraft.nbt.NbtUtils;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Provides helpers for reading and writing snbt to file
|
* Provides helpers for reading and writing snbt to file
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -1,13 +1,13 @@
|
||||||
package com.zontreck.libzontreck.vectors;
|
package com.zontreck.libzontreck.vectors;
|
||||||
|
|
||||||
import com.zontreck.libzontreck.LibZontreck;
|
|
||||||
import com.zontreck.libzontreck.exceptions.InvalidDeserialization;
|
import com.zontreck.libzontreck.exceptions.InvalidDeserialization;
|
||||||
|
|
||||||
import net.minecraft.nbt.CompoundTag;
|
import net.minecraft.nbt.CompoundTag;
|
||||||
import net.minecraft.nbt.NbtUtils;
|
import net.minecraft.nbt.NbtUtils;
|
||||||
import net.minecraft.resources.ResourceLocation;
|
import net.minecraft.resources.ResourceLocation;
|
||||||
import net.minecraft.server.level.ServerLevel;
|
import net.minecraft.server.level.ServerLevel;
|
||||||
import net.minecraft.server.level.ServerPlayer;
|
import net.minecraft.server.level.ServerPlayer;
|
||||||
import net.minecraftforge.server.ServerLifecycleHooks;
|
import net.neoforged.neoforge.server.ServerLifecycleHooks;
|
||||||
|
|
||||||
public class WorldPosition implements Cloneable
|
public class WorldPosition implements Cloneable
|
||||||
{
|
{
|
||||||
|
@ -37,7 +37,7 @@ public class WorldPosition implements Cloneable
|
||||||
}
|
}
|
||||||
|
|
||||||
public WorldPosition(ServerPlayer player) {
|
public WorldPosition(ServerPlayer player) {
|
||||||
this(new Vector3d(player.position()), player.getLevel());
|
this(new Vector3d(player.position()), player.serverLevel());
|
||||||
}
|
}
|
||||||
|
|
||||||
public WorldPosition(Vector3d pos, ServerLevel lvl) {
|
public WorldPosition(Vector3d pos, ServerLevel lvl) {
|
||||||
|
@ -94,7 +94,8 @@ public class WorldPosition implements Cloneable
|
||||||
String dim = Dimension;
|
String dim = Dimension;
|
||||||
String[] dims = dim.split(":");
|
String[] dims = dim.split(":");
|
||||||
|
|
||||||
ResourceLocation rl = new ResourceLocation(dims[0], dims[1]);
|
ResourceLocation rl = ResourceLocation.fromNamespaceAndPath(dims[0], dims[1]);
|
||||||
|
|
||||||
ServerLevel dimL = null;
|
ServerLevel dimL = null;
|
||||||
for (ServerLevel lServerLevel : ServerLifecycleHooks.getCurrentServer().getAllLevels()) {
|
for (ServerLevel lServerLevel : ServerLifecycleHooks.getCurrentServer().getAllLevels()) {
|
||||||
ResourceLocation XL = lServerLevel.dimension().location();
|
ResourceLocation XL = lServerLevel.dimension().location();
|
||||||
|
@ -107,7 +108,6 @@ public class WorldPosition implements Cloneable
|
||||||
}
|
}
|
||||||
|
|
||||||
if (dimL == null) {
|
if (dimL == null) {
|
||||||
LibZontreck.LOGGER.error("DIMENSION COULD NOT BE FOUND : " + Dimension);
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
72
src/old/java/com/zontreck/AriasEssentials.java
Normal file
72
src/old/java/com/zontreck/AriasEssentials.java
Normal file
|
@ -0,0 +1,72 @@
|
||||||
|
package com.zontreck;
|
||||||
|
|
||||||
|
import com.zontreck.block.DeprecatedModBlocks;
|
||||||
|
import com.zontreck.block.ModBlocks;
|
||||||
|
import com.zontreck.client.TimeBoostEntityRenderer;
|
||||||
|
import com.zontreck.configs.client.AEClientConfig;
|
||||||
|
import com.zontreck.configs.server.AEServerConfig;
|
||||||
|
import com.zontreck.effects.ModEffects;
|
||||||
|
import com.zontreck.effects.ModPotions;
|
||||||
|
import com.zontreck.enchantments.ModEnchantments;
|
||||||
|
import com.zontreck.entities.ModEntities;
|
||||||
|
import com.zontreck.items.DeprecatedModItems;
|
||||||
|
import com.zontreck.items.ModItems;
|
||||||
|
import com.zontreck.libzontreck.config.ServerConfig;
|
||||||
|
|
||||||
|
import net.minecraft.client.renderer.entity.EntityRenderers;
|
||||||
|
import net.neoforged.api.distmarker.Dist;
|
||||||
|
import net.neoforged.bus.api.IEventBus;
|
||||||
|
import net.neoforged.bus.api.SubscribeEvent;
|
||||||
|
import net.neoforged.fml.common.EventBusSubscriber;
|
||||||
|
import net.neoforged.fml.common.EventBusSubscriber.Bus;
|
||||||
|
import net.neoforged.fml.common.Mod;
|
||||||
|
import net.neoforged.fml.event.lifecycle.FMLClientSetupEvent;
|
||||||
|
|
||||||
|
import java.time.Instant;
|
||||||
|
import java.util.Random;
|
||||||
|
|
||||||
|
import org.apache.logging.log4j.Logger;
|
||||||
|
|
||||||
|
import com.zontreck.items.CreativeModeTabs;
|
||||||
|
|
||||||
|
import net.neoforged.fml.loading.FMLLoader;
|
||||||
|
import net.neoforged.neoforge.common.NeoForgeMod;
|
||||||
|
|
||||||
|
@Mod(AriasEssentials.MOD_ID)
|
||||||
|
public final class AriasEssentials {
|
||||||
|
public static Logger LOGGER = LoggerFactory.getLogger("ariaessentials");
|
||||||
|
public static final String MOD_ID = "ariasessentials";
|
||||||
|
public static final Random random = new Random(Instant.now().getEpochSecond());
|
||||||
|
|
||||||
|
public AriasEssentials(IEventBus bus) {
|
||||||
|
// This code runs as soon as Minecraft is in a mod-load-ready state.
|
||||||
|
// However, some things (like registries and resources) may still be
|
||||||
|
// uninitialized.
|
||||||
|
// Proceed with mild caution.
|
||||||
|
|
||||||
|
LOGGER.info("/!\\ Loading Aria's Essentials Configuration Files /!\\");
|
||||||
|
AEServerConfig.loadFromFile();
|
||||||
|
AEClientConfig.loadFromFile();
|
||||||
|
ServerConfig.init();
|
||||||
|
LOGGER.info("/!\\ DONE LOADING AECONFIG /!\\");
|
||||||
|
|
||||||
|
ModItems.ITEMS.register(bus);
|
||||||
|
CreativeModeTabs.register(bus);
|
||||||
|
ModEntities.register(bus);
|
||||||
|
ModEffects.register(bus);
|
||||||
|
ModPotions.register(bus);
|
||||||
|
DeprecatedModItems.register(bus);
|
||||||
|
ModEnchantments.register(bus);
|
||||||
|
DeprecatedModBlocks.register(bus);
|
||||||
|
ModBlocks.register(bus);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventBusSubscriber(bus = Bus.MOD, value = Dist.CLIENT)
|
||||||
|
public static class ClientModEvents {
|
||||||
|
@SubscribeEvent
|
||||||
|
public static void onClientSetup(FMLClientSetupEvent ev) {
|
||||||
|
EntityRenderers.register(ModEntities.TIAB_ENTITY.get(), TimeBoostEntityRenderer::new);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
8
src/old/java/com/zontreck/ariaslib/http/HTTPMethod.java
Normal file
8
src/old/java/com/zontreck/ariaslib/http/HTTPMethod.java
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
package com.zontreck.ariaslib.http;
|
||||||
|
|
||||||
|
public enum HTTPMethod {
|
||||||
|
GET,
|
||||||
|
POST,
|
||||||
|
PUT,
|
||||||
|
DELETE
|
||||||
|
}
|
14
src/old/java/com/zontreck/ariaslib/http/HTTPRequest.java
Normal file
14
src/old/java/com/zontreck/ariaslib/http/HTTPRequest.java
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
package com.zontreck.ariaslib.http;
|
||||||
|
|
||||||
|
public class HTTPRequest {
|
||||||
|
|
||||||
|
public String url;
|
||||||
|
|
||||||
|
public String method;
|
||||||
|
public String body;
|
||||||
|
public String contentType;
|
||||||
|
|
||||||
|
protected HTTPRequest() {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
131
src/old/java/com/zontreck/ariaslib/http/HTTPRequestBuilder.java
Normal file
131
src/old/java/com/zontreck/ariaslib/http/HTTPRequestBuilder.java
Normal file
|
@ -0,0 +1,131 @@
|
||||||
|
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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
32
src/old/java/com/zontreck/ariaslib/http/HTTPResponse.java
Normal file
32
src/old/java/com/zontreck/ariaslib/http/HTTPResponse.java
Normal file
|
@ -0,0 +1,32 @@
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
47
src/old/java/com/zontreck/ariaslib/terminal/Banners.java
Normal file
47
src/old/java/com/zontreck/ariaslib/terminal/Banners.java
Normal file
|
@ -0,0 +1,47 @@
|
||||||
|
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<String> 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;
|
||||||
|
}
|
||||||
|
}
|
86
src/old/java/com/zontreck/ariaslib/terminal/Task.java
Normal file
86
src/old/java/com/zontreck/ariaslib/terminal/Task.java
Normal file
|
@ -0,0 +1,86 @@
|
||||||
|
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 ( );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,20 @@
|
||||||
|
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();
|
||||||
|
}
|
||||||
|
}
|
51
src/old/java/com/zontreck/ariaslib/util/FileIO.java
Normal file
51
src/old/java/com/zontreck/ariaslib/util/FileIO.java
Normal file
|
@ -0,0 +1,51 @@
|
||||||
|
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());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
120
src/old/java/com/zontreck/ariaslib/util/Hashing.java
Normal file
120
src/old/java/com/zontreck/ariaslib/util/Hashing.java
Normal file
|
@ -0,0 +1,120 @@
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
94
src/old/java/com/zontreck/ariaslib/util/Lists.java
Normal file
94
src/old/java/com/zontreck/ariaslib/util/Lists.java
Normal file
|
@ -0,0 +1,94 @@
|
||||||
|
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 <T> An arbitrary type parameter
|
||||||
|
*/
|
||||||
|
public static <T> List<T> of(T... values)
|
||||||
|
{
|
||||||
|
List<T> 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<String> split(String input, String... delimiters) {
|
||||||
|
List<String> 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<String> splitWithDelim(String input, String... delimiters) {
|
||||||
|
List<String> 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(){
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
49
src/old/java/com/zontreck/ariaslib/util/Maps.java
Normal file
49
src/old/java/com/zontreck/ariaslib/util/Maps.java
Normal file
|
@ -0,0 +1,49 @@
|
||||||
|
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 <A> Any typed parameter
|
||||||
|
* @param <B> Any typed parameter
|
||||||
|
*/
|
||||||
|
public static <A,B> Map<A,B> of(Entry<A,B>... entries) {
|
||||||
|
Map<A,B> map = new HashMap<>();
|
||||||
|
for(Entry<A,B> 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 <A> Any typed parameter
|
||||||
|
* @param <B> Any typed parameter
|
||||||
|
*/
|
||||||
|
public static class Entry<A,B> {
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
18
src/old/java/com/zontreck/ariaslib/util/MathUtil.java
Normal file
18
src/old/java/com/zontreck/ariaslib/util/MathUtil.java
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
23
src/old/java/com/zontreck/ariaslib/util/Percent.java
Normal file
23
src/old/java/com/zontreck/ariaslib/util/Percent.java
Normal file
|
@ -0,0 +1,23 @@
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
56
src/old/java/com/zontreck/ariaslib/util/Progress.java
Normal file
56
src/old/java/com/zontreck/ariaslib/util/Progress.java
Normal file
|
@ -0,0 +1,56 @@
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
66
src/old/java/com/zontreck/ariaslib/util/ProgressBar.java
Normal file
66
src/old/java/com/zontreck/ariaslib/util/ProgressBar.java
Normal file
|
@ -0,0 +1,66 @@
|
||||||
|
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
|
||||||
|
* <br><br>
|
||||||
|
* 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();
|
||||||
|
}
|
||||||
|
}
|
161
src/old/java/com/zontreck/ariaslib/util/TimeNotation.java
Normal file
161
src/old/java/com/zontreck/ariaslib/util/TimeNotation.java
Normal file
|
@ -0,0 +1,161 @@
|
||||||
|
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<String> 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;
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
96
src/old/java/com/zontreck/ariaslib/util/TimeUtil.java
Normal file
96
src/old/java/com/zontreck/ariaslib/util/TimeUtil.java
Normal file
|
@ -0,0 +1,96 @@
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Add a link
Reference in a new issue