Reformatting

This commit is contained in:
Paul Reilly 2023-06-02 17:58:08 -05:00
parent 9a56a404af
commit e160868967
27 changed files with 280 additions and 244 deletions

View File

@ -34,7 +34,7 @@ import org.bukkit.plugin.java.JavaPlugin;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
@Info(name = "cage", description = "Cage a player.", @Info(name = "cage", description = "Cage a player.",
usage = "/cage <player> <on|off> [material]") usage = "/cage <player> <on|off> [material]")
@Permissive(perm = "datura.cage") @Permissive(perm = "datura.cage")
public class CageCommand extends Commander public class CageCommand extends Commander
{ {
@ -52,12 +52,14 @@ public class CageCommand extends Commander
{ {
case "on" -> case "on" ->
{ {
((Datura) getPlugin()).getCager().cagePlayer(player.getUniqueId()); ((Datura) getPlugin()).getCager()
.cagePlayer(player.getUniqueId());
sender.sendPlainMessage("Caged " + player.getName() + "."); sender.sendPlainMessage("Caged " + player.getName() + ".");
} }
case "off" -> case "off" ->
{ {
((Datura) getPlugin()).getCager().uncagePlayer(player.getUniqueId()); ((Datura) getPlugin()).getCager()
.uncagePlayer(player.getUniqueId());
sender.sendPlainMessage("Liberated " + player.getName() + "."); sender.sendPlainMessage("Liberated " + player.getName() + ".");
} }
} }
@ -65,18 +67,21 @@ public class CageCommand extends Commander
@Completion(args = {"[material]"}, index = 2) @Completion(args = {"[material]"}, index = 2)
@Subcommand(permission = "datura.cage.custom", args = {Player.class, String.class, Material.class}) @Subcommand(permission = "datura.cage.custom", args = {Player.class, String.class, Material.class})
public void cagePlayer(final CommandSender sender, final Player player, final String string, final Material material) public void cagePlayer(final CommandSender sender, final Player player, final String string,
final Material material)
{ {
switch (string.toLowerCase()) switch (string.toLowerCase())
{ {
case "on" -> case "on" ->
{ {
((Datura) getPlugin()).getCager().cagePlayer(player.getUniqueId(), material); ((Datura) getPlugin()).getCager()
.cagePlayer(player.getUniqueId(), material);
sender.sendPlainMessage("Caged " + player.getName() + "."); sender.sendPlainMessage("Caged " + player.getName() + ".");
} }
case "off" -> case "off" ->
{ {
((Datura) getPlugin()).getCager().uncagePlayer(player.getUniqueId()); ((Datura) getPlugin()).getCager()
.uncagePlayer(player.getUniqueId());
sender.sendPlainMessage("Liberated " + player.getName() + "."); sender.sendPlainMessage("Liberated " + player.getName() + ".");
} }
} }

View File

@ -31,8 +31,7 @@ public final class LockerCommand extends Commander
.lock(player); .lock(player);
sender.sendPlainMessage("Locked " + player.getName() + "."); sender.sendPlainMessage("Locked " + player.getName() + ".");
} } else if (string.equalsIgnoreCase("off"))
else if (string.equalsIgnoreCase("off"))
{ {
((Datura) getPlugin()).getLocker() ((Datura) getPlugin()).getLocker()
.unlock(player); .unlock(player);

View File

@ -16,9 +16,9 @@ record PermissionNode(String key,
public Permission bukkit() public Permission bukkit()
{ {
return new Permission(key(), return new Permission(key(),
value() value()
? PermissionDefault.TRUE ? PermissionDefault.TRUE
: PermissionDefault.FALSE); : PermissionDefault.FALSE);
} }
@Override @Override

View File

@ -62,42 +62,42 @@ public class MySQL implements SQL
{ {
return getConnection() return getConnection()
.thenApplyAsync(connection -> .thenApplyAsync(connection ->
{ {
try try
{ {
final PreparedStatement statement = connection.prepareStatement(query); final PreparedStatement statement = connection.prepareStatement(query);
for (int i = 0; i < args.length; i++) for (int i = 0; i < args.length; i++)
{ {
statement.setObject(i + 1, args[i]); statement.setObject(i + 1, args[i]);
} }
return statement; return statement;
} }
catch (SQLException ex) catch (SQLException ex)
{ {
throw new CompletionException("Failed to prepare statement: " throw new CompletionException("Failed to prepare statement: "
+ query + "\n", ex); + query + "\n", ex);
} }
}, CommonsBase.getInstance() }, CommonsBase.getInstance()
.getExecutor() .getExecutor()
.getAsync()); .getAsync());
} }
private CompletableFuture<Connection> getConnection() private CompletableFuture<Connection> getConnection()
{ {
return CompletableFuture.supplyAsync(() -> return CompletableFuture.supplyAsync(() ->
{ {
try try
{ {
return DriverManager.getConnection(url.toString()); return DriverManager.getConnection(url.toString());
} }
catch (SQLException ex) catch (SQLException ex)
{ {
throw new CompletionException("Failed to connect to the database: " throw new CompletionException("Failed to connect to the database: "
+ url.toString() + "\n", ex); + url.toString() + "\n", ex);
} }
}, CommonsBase.getInstance() }, CommonsBase.getInstance()
.getExecutor() .getExecutor()
.getAsync()); .getAsync());
} }
@Override @Override
@ -105,20 +105,20 @@ public class MySQL implements SQL
{ {
return prepareStatement(query, args) return prepareStatement(query, args)
.thenApplyAsync(statement -> .thenApplyAsync(statement ->
{ {
try try
{ {
return statement.executeQuery(); return statement.executeQuery();
} }
catch (SQLException ex) catch (SQLException ex)
{ {
throw new CompletionException( throw new CompletionException(
"Failed to retrieve a result set from query: " "Failed to retrieve a result set from query: "
+ query + "\n", ex); + query + "\n", ex);
} }
}, CommonsBase.getInstance() }, CommonsBase.getInstance()
.getExecutor() .getExecutor()
.getAsync()); .getAsync());
} }
@Override @Override
@ -126,19 +126,19 @@ public class MySQL implements SQL
{ {
return prepareStatement(query, args) return prepareStatement(query, args)
.thenApplyAsync(statement -> .thenApplyAsync(statement ->
{ {
try try
{ {
return statement.executeUpdate(); return statement.executeUpdate();
} }
catch (SQLException ex) catch (SQLException ex)
{ {
throw new CompletionException("Failed to execute update: " throw new CompletionException("Failed to execute update: "
+ query + "\n", ex); + query + "\n", ex);
} }
}, CommonsBase.getInstance() }, CommonsBase.getInstance()
.getExecutor() .getExecutor()
.getAsync()); .getAsync());
} }
@Override @Override
@ -146,19 +146,19 @@ public class MySQL implements SQL
{ {
return prepareStatement(query, args) return prepareStatement(query, args)
.thenApplyAsync(statement -> .thenApplyAsync(statement ->
{ {
try try
{ {
return statement.execute(); return statement.execute();
} }
catch (SQLException ex) catch (SQLException ex)
{ {
throw new CompletionException("Failed to execute statement: " throw new CompletionException("Failed to execute statement: "
+ query + "\n", ex); + query + "\n", ex);
} }
}, CommonsBase.getInstance() }, CommonsBase.getInstance()
.getExecutor() .getExecutor()
.getAsync()); .getAsync());
} }
@Override @Override
@ -185,25 +185,25 @@ public class MySQL implements SQL
{ {
return executeQuery("SELECT ? FROM ? WHERE ? = ?", column, table, key, identity.getId()) return executeQuery("SELECT ? FROM ? WHERE ? = ?", column, table, key, identity.getId())
.thenApplyAsync(resultSet -> .thenApplyAsync(resultSet ->
{ {
try try
{ {
if (resultSet.next()) if (resultSet.next())
{ {
return resultSet.getObject(column, type); return resultSet.getObject(column, type);
} }
} }
catch (SQLException ex) catch (SQLException ex)
{ {
throw new CompletionException( throw new CompletionException(
"Failed to retrieve column: " + column + " from table: " + table + " " + "Failed to retrieve column: " + column + " from table: " + table + " " +
"where primary key: " + key + " is equal to: " + identity.getId() + "\n", "where primary key: " + key + " is equal to: " + identity.getId() + "\n",
ex); ex);
} }
return null; return null;
}, CommonsBase.getInstance() }, CommonsBase.getInstance()
.getExecutor() .getExecutor()
.getAsync()); .getAsync());
} }
public CompletableFuture<Boolean> updateColumn(final String table, final String column, final Object value, public CompletableFuture<Boolean> updateColumn(final String table, final String column, final Object value,

View File

@ -71,62 +71,62 @@ public class SimpleUserData implements UserData
{ {
return sql.executeQuery("SELECT * FROM users WHERE UUID = ?", uuid) return sql.executeQuery("SELECT * FROM users WHERE UUID = ?", uuid)
.thenApplyAsync(result -> .thenApplyAsync(result ->
{ {
try try
{ {
if (result.next()) if (result.next())
{ {
final String g = result.getString("group"); final String g = result.getString("group");
final UUID u = UUID.fromString(uuid); final UUID u = UUID.fromString(uuid);
final String username = result.getString("username"); final String username = result.getString("username");
final Player player = Bukkit.getPlayer(u); final Player player = Bukkit.getPlayer(u);
if (player == null) if (player == null)
throw new IllegalStateException( throw new IllegalStateException(
"Player should be online but they are not!"); "Player should be online but they are not!");
final User user = new FreedomUser(player); final User user = new FreedomUser(player);
final Group group = CommonsBase.getInstance() final Group group = CommonsBase.getInstance()
.getRegistrations() .getRegistrations()
.getGroupRegistry() .getGroupRegistry()
.getGroup(g); .getGroup(g);
final long playtime = result.getLong("playtime"); final long playtime = result.getLong("playtime");
final boolean frozen = result.getBoolean("frozen"); final boolean frozen = result.getBoolean("frozen");
final boolean canInteract = result.getBoolean("canInteract"); final boolean canInteract = result.getBoolean("canInteract");
final boolean caged = result.getBoolean("caged"); final boolean caged = result.getBoolean("caged");
final long balance = result.getLong("balance"); final long balance = result.getLong("balance");
final boolean transactionsFrozen = result.getBoolean( final boolean transactionsFrozen = result.getBoolean(
"transactionsFrozen"); "transactionsFrozen");
return new SimpleUserData(u, username, user, group, playtime, frozen, return new SimpleUserData(u, username, user, group, playtime, frozen,
canInteract, caged, balance, canInteract, caged, balance,
transactionsFrozen); transactionsFrozen);
} }
} }
catch (SQLException ex) catch (SQLException ex)
{ {
final String sb = "An error occurred while trying to retrieve user data for" + final String sb = "An error occurred while trying to retrieve user data for" +
" UUID " + " UUID " +
uuid + uuid +
" from the database." + " from the database." +
"\nCaused by: " + "\nCaused by: " +
ExceptionUtils.getRootCauseMessage(ex) + ExceptionUtils.getRootCauseMessage(ex) +
"\nStack trace: " + "\nStack trace: " +
ExceptionUtils.getStackTrace(ex); ExceptionUtils.getStackTrace(ex);
FreedomLogger.getLogger("Datura") FreedomLogger.getLogger("Datura")
.error(sb); .error(sb);
} }
final Player player = Bukkit.getPlayer(UUID.fromString(uuid)); final Player player = Bukkit.getPlayer(UUID.fromString(uuid));
if (player == null) throw new IllegalStateException( if (player == null) throw new IllegalStateException(
"Player should be online but they are not!"); "Player should be online but they are not!");
return new SimpleUserData(player); return new SimpleUserData(player);
}, CommonsBase.getInstance() }, CommonsBase.getInstance()
.getExecutor() .getExecutor()
.getAsync()) .getAsync())
.join(); .join();
} }

View File

@ -46,13 +46,17 @@ public class CakeCommand extends Commander
@Base @Base
public void broadcastCake(final CommandSender sender) public void broadcastCake(final CommandSender sender)
{ {
Bukkit.broadcast(FreedomMiniMessage.deserialize(true, "<rainbow>But there's no sense crying over every mistake. You just keep on trying till you run out of cake.</rainbow>")); Bukkit.broadcast(FreedomMiniMessage.deserialize(true,
"<rainbow>But there's no sense crying over every mistake. You just keep on trying till you run out of " +
"cake.</rainbow>"));
final ItemStack stack = new ItemStack(Material.CAKE, 1); final ItemStack stack = new ItemStack(Material.CAKE, 1);
final ItemMeta meta = stack.getItemMeta(); final ItemMeta meta = stack.getItemMeta();
meta.displayName(FreedomMiniMessage.deserialize(true, "<dark_gray>The <white>Lie")); meta.displayName(FreedomMiniMessage.deserialize(true, "<dark_gray>The <white>Lie"));
stack.setItemMeta(meta); stack.setItemMeta(meta);
Bukkit.getOnlinePlayers().forEach(player -> player.getInventory().addItem(stack)); Bukkit.getOnlinePlayers()
.forEach(player -> player.getInventory()
.addItem(stack));
} }
} }

View File

@ -8,7 +8,7 @@ public class SimpleTransactionResult implements TransactionResult
{ {
public static final TransactionResult SUCCESSFUL = new SimpleTransactionResult("Successful transaction.", true); public static final TransactionResult SUCCESSFUL = new SimpleTransactionResult("Successful transaction.", true);
public static final TransactionResult UNAUTHORIZED = new SimpleTransactionResult("Unauthorized transaction.", public static final TransactionResult UNAUTHORIZED = new SimpleTransactionResult("Unauthorized transaction.",
false); false);
public static final TransactionResult AMOUNT_TOO_SMALL = new SimpleTransactionResult( public static final TransactionResult AMOUNT_TOO_SMALL = new SimpleTransactionResult(
"Transaction balance too small.", false); "Transaction balance too small.", false);
public static final TransactionResult INSUFFICIENT_FUNDS = new SimpleTransactionResult( public static final TransactionResult INSUFFICIENT_FUNDS = new SimpleTransactionResult(

View File

@ -20,8 +20,10 @@ public final class ClownfishItem extends ShopItem
{ {
if (target == null) return; if (target == null) return;
final Location location = user.getEyeLocation().clone(); final Location location = user.getEyeLocation()
final Vector vector = location.getDirection().multiply(2); .clone();
final Vector vector = location.getDirection()
.multiply(2);
target.setVelocity(vector); target.setVelocity(vector);
} }

View File

@ -27,6 +27,7 @@ public final class BasicTrail extends SimpleTrail
final Location location = player.getLocation() final Location location = player.getLocation()
.clone() .clone()
.subtract(0, 1, 0); .subtract(0, 1, 0);
location.getWorld().spawnParticle(particle, location, 1, 0.0, 0.5, 0.0, options); location.getWorld()
.spawnParticle(particle, location, 1, 0.0, 0.5, 0.0, options);
} }
} }

View File

@ -24,6 +24,6 @@ public final class FlameTrail extends SimpleTrail
final Vector direction = location.getDirection(); final Vector direction = location.getDirection();
location.getWorld() location.getWorld()
.spawnParticle(getTrailType().getType(), location, 0, direction.getX(), direction.getY(), .spawnParticle(getTrailType().getType(), location, 0, direction.getX(), direction.getY(),
direction.getZ(), 0.1); direction.getZ(), 0.1);
} }
} }

View File

@ -20,6 +20,7 @@ public final class HeartTrail extends SimpleTrail
final Location location = player.getLocation() final Location location = player.getLocation()
.clone() .clone()
.subtract(0, 1, 0); .subtract(0, 1, 0);
location.getWorld().spawnParticle(getTrailType().getType(), location, 1, 0.0, 0.5, 0.0); location.getWorld()
.spawnParticle(getTrailType().getType(), location, 1, 0.0, 0.5, 0.0);
} }
} }

View File

@ -21,7 +21,8 @@ public abstract class SimpleTrail implements Trail
private Set<Color> gradientColor = null; private Set<Color> gradientColor = null;
private boolean active = false; private boolean active = false;
protected SimpleTrail(final Player player, final TrailType trailType) { protected SimpleTrail(final Player player, final TrailType trailType)
{
this.associatedPlayerUUID = player.getUniqueId(); this.associatedPlayerUUID = player.getUniqueId();
this.trailType = trailType; this.trailType = trailType;
} }

View File

@ -25,6 +25,7 @@ public final class StrobeTrail extends SimpleTrail
final Location location = player.getLocation() final Location location = player.getLocation()
.clone() .clone()
.subtract(0, 1, 0); .subtract(0, 1, 0);
location.getWorld().spawnParticle(getTrailType().getType(), location, 1, 0.0, 0.5, 0.0, dustTransition); location.getWorld()
.spawnParticle(getTrailType().getType(), location, 1, 0.0, 0.5, 0.0, dustTransition);
} }
} }

View File

@ -4,7 +4,8 @@ import org.bukkit.entity.Player;
public final class TrailProvider public final class TrailProvider
{ {
public BasicTrail basicTrail(final Player player) { public BasicTrail basicTrail(final Player player)
{
return new BasicTrail(player); return new BasicTrail(player);
} }

View File

@ -20,9 +20,10 @@ public class CommonsBase extends JavaPlugin
@Override @Override
public void onDisable() public void onDisable()
{ {
Bukkit.getScheduler().runTaskLater(this, () -> getRegistrations() Bukkit.getScheduler()
.getServiceRegistry() .runTaskLater(this, () -> getRegistrations()
.stopAllServices(), 1L); .getServiceRegistry()
.stopAllServices(), 1L);
getRegistrations().getServiceRegistry() getRegistrations().getServiceRegistry()
.unregisterService(EventBus.class); .unregisterService(EventBus.class);

View File

@ -1,15 +1,11 @@
package me.totalfreedom.config; package me.totalfreedom.config;
import org.bukkit.configuration.file.YamlConfiguration;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.util.List; import java.util.List;
public interface Configuration public interface Configuration
{ {
YamlConfiguration asYaml();
void save() throws IOException; void save() throws IOException;
void load() throws IOException; void load() throws IOException;

View File

@ -0,0 +1,6 @@
package me.totalfreedom.config;
public final class YamlWrapper
{
}

View File

@ -76,13 +76,13 @@ public abstract class AbstractMenu
{ {
Bukkit.getOnlinePlayers() Bukkit.getOnlinePlayers()
.forEach(player -> .forEach(player ->
{ {
if (openInvs.get(player.getUniqueId()) if (openInvs.get(player.getUniqueId())
.equals(getDisplayableUUID())) .equals(getDisplayableUUID()))
{ {
close(player); close(player);
} }
}); });
invByUUID.remove(getDisplayableUUID()); invByUUID.remove(getDisplayableUUID());
} }

View File

@ -30,7 +30,9 @@ public final class Displayable implements Inventory, InventoryHolder
// If the size is not a multiple of nine, find the difference to the next highest multiple of 9 and make up // If the size is not a multiple of nine, find the difference to the next highest multiple of 9 and make up
// the difference. // the difference.
this.size = (size % 9 == 0) ? size : size + (9 - size % 9); this.size = (size % 9 == 0)
? size
: size + (9 - size % 9);
this.contents = new ItemStack[size]; this.contents = new ItemStack[size];
} }
@ -152,7 +154,7 @@ public final class Displayable implements Inventory, InventoryHolder
if (remainingAmount < item.getAmount()) if (remainingAmount < item.getAmount())
{ {
removedItems.put(removedItems.size(), removedItems.put(removedItems.size(),
new ItemStack(item.getType(), item.getAmount() - remainingAmount)); new ItemStack(item.getType(), item.getAmount() - remainingAmount));
} }
} }

View File

@ -25,14 +25,14 @@ class SubscriptionBox<T extends FEvent>
public void tick() public void tick()
{ {
subscriptions.forEach(s -> subscriptions.forEach(s ->
{ {
if (!s.event() if (!s.event()
.shouldCall()) return; .shouldCall()) return;
s.callback() s.callback()
.call(s.event()); .call(s.event());
s.event() s.event()
.reset(); .reset();
}); });
} }
} }

View File

@ -3,10 +3,8 @@ package me.totalfreedom.particle;
import me.totalfreedom.api.Interpolator; import me.totalfreedom.api.Interpolator;
import me.totalfreedom.utils.InterpolationUtils; import me.totalfreedom.utils.InterpolationUtils;
import org.bukkit.Color; import org.bukkit.Color;
import org.bukkit.Location;
import org.bukkit.OfflinePlayer; import org.bukkit.OfflinePlayer;
import org.bukkit.Particle; import org.bukkit.Particle;
import org.bukkit.World;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;

View File

@ -3,6 +3,7 @@ package me.totalfreedom.provider;
import net.kyori.adventure.text.Component; import net.kyori.adventure.text.Component;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.World; import org.bukkit.World;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
@ -21,6 +22,7 @@ public class ContextProvider
toInt(string), toInt(string),
toLong(string), toLong(string),
toFloat(string), toFloat(string),
toMaterial(string),
toPlayer(string), toPlayer(string),
toWorld(string), toWorld(string),
toLocation(string), toLocation(string),
@ -92,6 +94,11 @@ public class ContextProvider
} }
} }
private @Nullable Material toMaterial(final String string)
{
return Material.matchMaterial(string);
}
private @Nullable Player toPlayer(final String string) private @Nullable Player toPlayer(final String string)
{ {
return Bukkit.getPlayer(string); return Bukkit.getPlayer(string);

View File

@ -3,6 +3,7 @@ package me.totalfreedom.service;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.scheduler.BukkitTask; import org.bukkit.scheduler.BukkitTask;
import org.jetbrains.annotations.NotNull;
import java.util.concurrent.Executor; import java.util.concurrent.Executor;
@ -15,7 +16,7 @@ public final class ServiceSubscription<T extends Service>
private boolean isActive = false; private boolean isActive = false;
ServiceSubscription(final JavaPlugin plugin, final T service, final boolean async) ServiceSubscription(@NotNull final JavaPlugin plugin, @NotNull final T service, final boolean async)
{ {
this.service = service; this.service = service;
this.async = async; this.async = async;
@ -52,12 +53,8 @@ public final class ServiceSubscription<T extends Service>
public void stop() public void stop()
{ {
this.isActive = false; this.isActive = false;
Bukkit.getScheduler().cancelTask(this.getServiceId()); Bukkit.getScheduler()
} .cancelTask(this.getServiceId());
public T getService()
{
return service;
} }
public int getServiceId() public int getServiceId()
@ -65,6 +62,12 @@ public final class ServiceSubscription<T extends Service>
return serviceId; return serviceId;
} }
@NotNull
public T getService()
{
return service;
}
public boolean isAsync() public boolean isAsync()
{ {
return async; return async;

View File

@ -22,10 +22,10 @@ public interface SQLProperties
default String toURLPlain() default String toURLPlain()
{ {
return String.format("jdbc:%s://%s:%s/%s", return String.format("jdbc:%s://%s:%s/%s",
this.getDriver(), this.getDriver(),
this.getHost(), this.getHost(),
this.getPort(), this.getPort(),
this.getDatabase()); this.getDatabase());
} }
String getDriver(); String getDriver();
@ -39,12 +39,12 @@ public interface SQLProperties
default String toURLWithLogin() default String toURLWithLogin()
{ {
return String.format("jdbc:%s://%s:%s/%s?user=%s&password=%s", return String.format("jdbc:%s://%s:%s/%s?user=%s&password=%s",
this.getDriver(), this.getDriver(),
this.getHost(), this.getHost(),
this.getPort(), this.getPort(),
this.getDatabase(), this.getDatabase(),
this.getUsername(), this.getUsername(),
this.getPassword()); this.getPassword());
} }
String getUsername(); String getUsername();

View File

@ -56,14 +56,6 @@ public class FreedomLogger implements Audience
public String infoComponent(final Supplier<Component> component) public String infoComponent(final Supplier<Component> component)
{ {
return this.infoComponent(component.get()); return this.infoComponent(component.get());
} /**
* This method allows you to log a message to the console.
*
* @param message The message to send.
*/
public void info(final String message)
{
logger.info(message);
} }
/** /**
@ -78,6 +70,14 @@ public class FreedomLogger implements Audience
logger.info(plainText); logger.info(plainText);
return plainText; return plainText;
} /**
* This method allows you to log a message to the console.
*
* @param message The message to send.
*/
public void info(final String message)
{
logger.info(message);
} }
/** /**

View File

@ -32,46 +32,54 @@ import net.kyori.adventure.text.minimessage.tag.standard.StandardTags;
*/ */
public class FreedomMiniMessage public class FreedomMiniMessage
{ {
private static final MiniMessage unsafe = MiniMessage.miniMessage();
private static final MiniMessage safe = MiniMessage.builder()
.tags(TagResolver.resolver(
StandardTags.color(),
StandardTags.rainbow(),
StandardTags.gradient(),
StandardTags.newline(),
StandardTags.decorations(TextDecoration.ITALIC),
StandardTags.decorations(TextDecoration.BOLD),
StandardTags.decorations(TextDecoration.STRIKETHROUGH),
StandardTags.decorations(TextDecoration.UNDERLINED)
))
.build();
private FreedomMiniMessage() private FreedomMiniMessage()
{ {
throw new UnsupportedOperationException("Instantiation of a static utility class is not supported."); throw new UnsupportedOperationException("Instantiation of a static utility class is not supported.");
} }
private static final MiniMessage unsafe = MiniMessage.miniMessage();
private static final MiniMessage safe = MiniMessage.builder().tags(TagResolver.resolver(
StandardTags.color(),
StandardTags.rainbow(),
StandardTags.gradient(),
StandardTags.newline(),
StandardTags.decorations(TextDecoration.ITALIC),
StandardTags.decorations(TextDecoration.BOLD),
StandardTags.decorations(TextDecoration.STRIKETHROUGH),
StandardTags.decorations(TextDecoration.UNDERLINED)
)).build();
/** /**
* Deserializes an input string using an instance of MiniMessage that is either safe (resolves only a specific set of tags) * Deserializes an input string using an instance of MiniMessage that is either safe (resolves only a specific
* or unsafe (resolves all tags). * set of tags)
* @param safe Whether to use a safe instance of MiniMessage * or unsafe (resolves all tags).
* @param input An input string formatted with MiniMessage's input *
* @param placeholders Custom placeholders to use when processing the input * @param safe Whether to use a safe instance of MiniMessage
* @return A processed Component * @param input An input string formatted with MiniMessage's input
* @param placeholders Custom placeholders to use when processing the input
* @return A processed Component
*/ */
public static Component deserialize(boolean safe, String input, TagResolver... placeholders) public static Component deserialize(boolean safe, String input, TagResolver... placeholders)
{ {
return (safe ? FreedomMiniMessage.safe : unsafe).deserialize(input, placeholders); return (safe
? FreedomMiniMessage.safe
: unsafe).deserialize(input, placeholders);
} }
/** /**
* Serializes an input component using an instance of MiniMessage that is either safe (resolves only a specific set * Serializes an input component using an instance of MiniMessage that is either safe (resolves only a specific set
* of tags) or unsafe (resolves all tags). * of tags) or unsafe (resolves all tags).
* @param safe Whether to use a safe instance of MiniMessage *
* @param input An already processed component * @param safe Whether to use a safe instance of MiniMessage
* @return A processed Component * @param input An already processed component
* @return A processed Component
*/ */
public static String serialize(boolean safe, Component input) public static String serialize(boolean safe, Component input)
{ {
return (safe ? FreedomMiniMessage.safe : unsafe).serialize(input); return (safe
? FreedomMiniMessage.safe
: unsafe).serialize(input);
} }
} }

View File

@ -69,18 +69,18 @@ public final class InterpolationUtils
{ {
final LinkedHashSet<TextColor> base = new LinkedHashSet<>(); final LinkedHashSet<TextColor> base = new LinkedHashSet<>();
final Set<TextColor> redToOrange = componentRGBGradient(length, NamedTextColor.RED, final Set<TextColor> redToOrange = componentRGBGradient(length, NamedTextColor.RED,
NamedTextColor.GOLD, InterpolationUtils::linear); NamedTextColor.GOLD, InterpolationUtils::linear);
final Set<TextColor> orangeToYellow = componentRGBGradient(length, NamedTextColor.GOLD, final Set<TextColor> orangeToYellow = componentRGBGradient(length, NamedTextColor.GOLD,
NamedTextColor.YELLOW, InterpolationUtils::linear); NamedTextColor.YELLOW, InterpolationUtils::linear);
final Set<TextColor> yellowToGreen = componentRGBGradient(length, NamedTextColor.YELLOW, final Set<TextColor> yellowToGreen = componentRGBGradient(length, NamedTextColor.YELLOW,
NamedTextColor.GREEN, InterpolationUtils::linear); NamedTextColor.GREEN, InterpolationUtils::linear);
final Set<TextColor> greenToBlue = componentRGBGradient(length, NamedTextColor.GREEN, final Set<TextColor> greenToBlue = componentRGBGradient(length, NamedTextColor.GREEN,
NamedTextColor.BLUE, InterpolationUtils::linear); NamedTextColor.BLUE, InterpolationUtils::linear);
final Set<TextColor> blueToPurple = componentRGBGradient(length, NamedTextColor.BLUE, final Set<TextColor> blueToPurple = componentRGBGradient(length, NamedTextColor.BLUE,
NamedTextColor.LIGHT_PURPLE, NamedTextColor.LIGHT_PURPLE,
InterpolationUtils::linear); InterpolationUtils::linear);
final Set<TextColor> purpleToRed = componentRGBGradient(length, TextColor.color(75, 0, 130), final Set<TextColor> purpleToRed = componentRGBGradient(length, TextColor.color(75, 0, 130),
TextColor.color(255, 0, 0), InterpolationUtils::linear); TextColor.color(255, 0, 0), InterpolationUtils::linear);
base.addAll(redToOrange); base.addAll(redToOrange);
base.addAll(orangeToYellow); base.addAll(orangeToYellow);
base.addAll(yellowToGreen); base.addAll(yellowToGreen);