move stuff

This commit is contained in:
zontreck 2025-02-23 01:49:18 -07:00
parent 6ccef8275c
commit 70a68282aa
18 changed files with 0 additions and 1156 deletions

View file

@ -1,8 +0,0 @@
package com.zontreck.ariaslib.http;
public enum HTTPMethod {
GET,
POST,
PUT,
DELETE
}

View file

@ -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() {
}
}

View file

@ -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();
}
}
}

View file

@ -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;
}
}

View file

@ -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<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;
}
}

View file

@ -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 ( );
}
}
}
}
}

View file

@ -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();
}
}

View file

@ -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());
}
}
}

View file

@ -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;
}
}
}

View file

@ -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 <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(){
}
}

View file

@ -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 <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;
}
}
}

View file

@ -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);
}
}

View file

@ -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);
}
}

View file

@ -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;
}
}

View file

@ -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
* <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();
}
}

View file

@ -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<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;
}
}

View file

@ -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;
}
}

View file

@ -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);
}
}