mirror of
https://github.com/SimplexDevelopment/FreedomNetworkSuite.git
synced 2025-06-27 19:56:41 +00:00
Upgrades
This commit is contained in:
131
Patchwork/src/main/java/me/totalfreedom/utils/FreedomLogger.java
Normal file
131
Patchwork/src/main/java/me/totalfreedom/utils/FreedomLogger.java
Normal file
@ -0,0 +1,131 @@
|
||||
package me.totalfreedom.utils;
|
||||
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.util.function.Supplier;
|
||||
|
||||
public class FreedomLogger
|
||||
{
|
||||
private final Logger logger;
|
||||
private boolean debug = false;
|
||||
|
||||
private FreedomLogger(String moduleName)
|
||||
{
|
||||
this.logger = LoggerFactory.getLogger("FreedomNetworkSuite::" + moduleName);
|
||||
}
|
||||
|
||||
public static FreedomLogger getLogger(String moduleName)
|
||||
{
|
||||
return new FreedomLogger(moduleName);
|
||||
}
|
||||
|
||||
public void setDebugMode(boolean debug)
|
||||
{
|
||||
this.debug = debug;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method allows you to log a message to the console.
|
||||
*
|
||||
* @param message The message to send.
|
||||
*/
|
||||
public void info(String message)
|
||||
{
|
||||
logger.info(message);
|
||||
}
|
||||
|
||||
/**
|
||||
* This method allows you to log a message to the console,
|
||||
* while also returning a Component that could be used to
|
||||
* message a player.
|
||||
*
|
||||
* @param message The message to send.
|
||||
* @return A component representation of the message.
|
||||
*/
|
||||
public Component info(Supplier<String> message)
|
||||
{
|
||||
logger.info(message.get());
|
||||
return Component.text(message.get());
|
||||
}
|
||||
|
||||
/**
|
||||
* This method allows you to log a warning to the console.
|
||||
*
|
||||
* @param message The message to send.
|
||||
*/
|
||||
public void warn(String message)
|
||||
{
|
||||
logger.warn(message);
|
||||
}
|
||||
|
||||
/**
|
||||
* This method logs an error message to the console.
|
||||
* It is highly recommended to deconstruct the stack trace and pass it
|
||||
* in a more readable format to this method.
|
||||
*
|
||||
* @param message The message to send.
|
||||
*/
|
||||
public void error(String message)
|
||||
{
|
||||
logger.error(message);
|
||||
}
|
||||
|
||||
/**
|
||||
* This method allows you to log an exception directly to the console.
|
||||
*
|
||||
* @param th The exception to log.
|
||||
*/
|
||||
public void error(Throwable th)
|
||||
{
|
||||
logger.error("An error occurred:\n", th);
|
||||
}
|
||||
|
||||
/**
|
||||
* This method allows you to log an error message to the console,
|
||||
* while also returning a Component that could be used to
|
||||
* message a player. It is highly recommended that you deconstruct and limit
|
||||
* the stack trace before passing it to this method, if you are intending to
|
||||
* use it for player communication.
|
||||
*
|
||||
* @param message The message to send.
|
||||
* @return A component representation of the message.
|
||||
*/
|
||||
public Component error(Supplier<String> message)
|
||||
{
|
||||
logger.error(message.get());
|
||||
return Component.text(message.get());
|
||||
}
|
||||
|
||||
/**
|
||||
* This method allows you to log a debug message to the console.
|
||||
* This method will only log if debug mode is enabled.
|
||||
*
|
||||
* @param message The message to send.
|
||||
*/
|
||||
public void debug(String message)
|
||||
{
|
||||
if (debug)
|
||||
logger.debug(message);
|
||||
}
|
||||
|
||||
/**
|
||||
* This method allows you to log a debug message to the console,
|
||||
* while also returning a Component that could be used to
|
||||
* message a player. This method will only log if debug mode is enabled.
|
||||
* If debug mode is not enabled, this method will return an empty component.
|
||||
*
|
||||
* @param message The message to send.
|
||||
* @return A component representation of the message.
|
||||
*/
|
||||
public Component debug(Supplier<String> message)
|
||||
{
|
||||
if (debug)
|
||||
{
|
||||
logger.debug(message.get());
|
||||
return Component.text(message.get());
|
||||
}
|
||||
return Component.empty();
|
||||
}
|
||||
}
|
26
Patchwork/src/main/java/me/totalfreedom/utils/Identity.java
Normal file
26
Patchwork/src/main/java/me/totalfreedom/utils/Identity.java
Normal file
@ -0,0 +1,26 @@
|
||||
package me.totalfreedom.utils;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
public class Identity
|
||||
{
|
||||
private final String key;
|
||||
|
||||
private final UUID id;
|
||||
|
||||
public Identity(String key)
|
||||
{
|
||||
this.key = key;
|
||||
this.id = UUID.nameUUIDFromBytes(key.getBytes());
|
||||
}
|
||||
|
||||
public String getKey()
|
||||
{
|
||||
return key;
|
||||
}
|
||||
|
||||
public UUID getId()
|
||||
{
|
||||
return id;
|
||||
}
|
||||
}
|
22
Patchwork/src/main/java/me/totalfreedom/utils/Pair.java
Normal file
22
Patchwork/src/main/java/me/totalfreedom/utils/Pair.java
Normal file
@ -0,0 +1,22 @@
|
||||
package me.totalfreedom.utils;
|
||||
|
||||
public class Pair<K, V>
|
||||
{
|
||||
private final K key;
|
||||
private final V value;
|
||||
|
||||
public Pair(K key, V value) {
|
||||
this.key = key;
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public K getKey()
|
||||
{
|
||||
return key;
|
||||
}
|
||||
|
||||
public V getValue()
|
||||
{
|
||||
return value;
|
||||
}
|
||||
}
|
40
Patchwork/src/main/java/me/totalfreedom/utils/Shaper.java
Normal file
40
Patchwork/src/main/java/me/totalfreedom/utils/Shaper.java
Normal file
@ -0,0 +1,40 @@
|
||||
package me.totalfreedom.utils;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.function.DoubleUnaryOperator;
|
||||
|
||||
public class Shaper
|
||||
{
|
||||
private final double start;
|
||||
private final double end;
|
||||
private final World world;
|
||||
|
||||
public Shaper(World world, double start, double end)
|
||||
{
|
||||
this.start = start;
|
||||
this.end = end;
|
||||
this.world = world;
|
||||
}
|
||||
|
||||
public List<Location> generate(int count, DoubleUnaryOperator x, DoubleUnaryOperator y, DoubleUnaryOperator z)
|
||||
{
|
||||
double step = (start - end) / (count - 1);
|
||||
LinkedList<Location> lset = new LinkedList<>();
|
||||
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
double t = start + i * step;
|
||||
double xp = x.applyAsDouble(t);
|
||||
double yp = y.applyAsDouble(t);
|
||||
double zp = z.applyAsDouble(t);
|
||||
|
||||
lset.add(new Location(world, xp, yp, zp));
|
||||
}
|
||||
|
||||
return lset;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user