From 5f6e7a153ea9d2f1c85cd87770657aab39673fdc Mon Sep 17 00:00:00 2001 From: Paul Reilly Date: Sun, 21 May 2023 22:11:31 -0500 Subject: [PATCH] Slight bugfix, also more code spec alignment --- .../totalfreedom/datura/punishment/Cager.java | 2 + .../datura/user/SimpleUserData.java | 18 ++--- .../economy/SimpleCompletedTransaction.java | 2 +- .../economy/SimpleLoggedTransactor.java | 6 +- .../economy/SimpleMutableTransaction.java | 8 +-- .../fossil/economy/SimpleTransaction.java | 2 +- .../economy/SimpleTransactionLogger.java | 23 ++++--- .../economy/SimpleTransactionResult.java | 4 +- .../fossil/economy/SimpleTransactor.java | 22 ++++--- .../audience/MutableAudienceForwarder.java | 66 +++++++++---------- .../totalfreedom/command/BukkitDelegator.java | 2 +- .../me/totalfreedom/data/EventRegistry.java | 2 +- .../provider/ContextProvider.java | 25 +++++-- .../totalfreedom/utils/FreedomAdventure.java | 8 +-- .../me/totalfreedom/utils/FreedomLogger.java | 34 +++++----- .../main/java/me/totalfreedom/utils/Pair.java | 19 +----- 16 files changed, 124 insertions(+), 119 deletions(-) diff --git a/Datura/src/main/java/me/totalfreedom/datura/punishment/Cager.java b/Datura/src/main/java/me/totalfreedom/datura/punishment/Cager.java index b84a9c4..7ffc02b 100644 --- a/Datura/src/main/java/me/totalfreedom/datura/punishment/Cager.java +++ b/Datura/src/main/java/me/totalfreedom/datura/punishment/Cager.java @@ -14,6 +14,8 @@ import org.bukkit.event.player.PlayerQuitEvent; import java.util.HashMap; import java.util.HashSet; +import java.util.List; +import java.util.LinkedList; import java.util.Map; import java.util.Set; import java.util.UUID; diff --git a/Datura/src/main/java/me/totalfreedom/datura/user/SimpleUserData.java b/Datura/src/main/java/me/totalfreedom/datura/user/SimpleUserData.java index 57de38e..b1c7c0d 100644 --- a/Datura/src/main/java/me/totalfreedom/datura/user/SimpleUserData.java +++ b/Datura/src/main/java/me/totalfreedom/datura/user/SimpleUserData.java @@ -90,12 +90,12 @@ public class SimpleUserData implements UserData .getGroupRegistry() .getGroup(g); - long playtime = result.getLong("playtime"); - boolean frozen = result.getBoolean("frozen"); - boolean canInteract = result.getBoolean("canInteract"); - boolean caged = result.getBoolean("caged"); - long balance = result.getLong("balance"); - boolean transactionsFrozen = result.getBoolean("transactionsFrozen"); + final long playtime = result.getLong("playtime"); + final boolean frozen = result.getBoolean("frozen"); + final boolean canInteract = result.getBoolean("canInteract"); + final boolean caged = result.getBoolean("caged"); + final long balance = result.getLong("balance"); + final boolean transactionsFrozen = result.getBoolean("transactionsFrozen"); return new SimpleUserData(u, username, user, group, playtime, frozen, canInteract, caged, balance, transactionsFrozen); } } catch (SQLException ex) @@ -231,19 +231,19 @@ public class SimpleUserData implements UserData } @Override - public long addToBalance(long amount) + public long addToBalance(final long amount) { return balance.addAndGet(amount); } @Override - public long removeFromBalance(long amount) + public long removeFromBalance(final long amount) { return balance.addAndGet(-amount); } @Override - public void setBalance(long newBalance) + public void setBalance(final long newBalance) { balance.set(newBalance); } diff --git a/Fossil/src/main/java/me/totalfreedom/fossil/economy/SimpleCompletedTransaction.java b/Fossil/src/main/java/me/totalfreedom/fossil/economy/SimpleCompletedTransaction.java index b7ba257..d9c666a 100644 --- a/Fossil/src/main/java/me/totalfreedom/fossil/economy/SimpleCompletedTransaction.java +++ b/Fossil/src/main/java/me/totalfreedom/fossil/economy/SimpleCompletedTransaction.java @@ -12,7 +12,7 @@ public class SimpleCompletedTransaction implements CompletedTransaction private final EconomicEntity destination; private final long balance; - public SimpleCompletedTransaction(Transaction transaction, TransactionResult transactionResult) + public SimpleCompletedTransaction(final Transaction transaction, final TransactionResult transactionResult) { this.source = transaction.getSource(); diff --git a/Fossil/src/main/java/me/totalfreedom/fossil/economy/SimpleLoggedTransactor.java b/Fossil/src/main/java/me/totalfreedom/fossil/economy/SimpleLoggedTransactor.java index 4bf35ca..440c0b3 100644 --- a/Fossil/src/main/java/me/totalfreedom/fossil/economy/SimpleLoggedTransactor.java +++ b/Fossil/src/main/java/me/totalfreedom/fossil/economy/SimpleLoggedTransactor.java @@ -15,16 +15,16 @@ public class SimpleLoggedTransactor implements Transactor this(new SimpleTransactor(), new SimpleTransactionLogger()); } - public SimpleLoggedTransactor(Transactor transactor, TransactionLogger transactionLogger) + public SimpleLoggedTransactor(final Transactor transactor, final TransactionLogger transactionLogger) { this.transactor = transactor; this.transactionLogger = transactionLogger; } @Override - public CompletedTransaction handleTransaction(MutableTransaction transaction) + public CompletedTransaction handleTransaction(final MutableTransaction transaction) { - CompletedTransaction completedTransaction = transactor.handleTransaction(transaction); + final CompletedTransaction completedTransaction = transactor.handleTransaction(transaction); transactionLogger.logTransaction(completedTransaction); return completedTransaction; diff --git a/Fossil/src/main/java/me/totalfreedom/fossil/economy/SimpleMutableTransaction.java b/Fossil/src/main/java/me/totalfreedom/fossil/economy/SimpleMutableTransaction.java index c99cb65..9aadb26 100644 --- a/Fossil/src/main/java/me/totalfreedom/fossil/economy/SimpleMutableTransaction.java +++ b/Fossil/src/main/java/me/totalfreedom/fossil/economy/SimpleMutableTransaction.java @@ -5,25 +5,25 @@ import me.totalfreedom.economy.MutableTransaction; public class SimpleMutableTransaction extends SimpleTransaction implements MutableTransaction { - public SimpleMutableTransaction(EconomicEntity source, EconomicEntity destination, long balance) + public SimpleMutableTransaction(final EconomicEntity source, final EconomicEntity destination, final long balance) { super(source, destination, balance); } @Override - public long addToBalance(long amount) + public long addToBalance(final long amount) { return balance.addAndGet(amount); } @Override - public long removeFromBalance(long amount) + public long removeFromBalance(final long amount) { return this.addToBalance(-amount); } @Override - public void setBalance(long newBalance) + public void setBalance(final long newBalance) { balance.set(newBalance); } diff --git a/Fossil/src/main/java/me/totalfreedom/fossil/economy/SimpleTransaction.java b/Fossil/src/main/java/me/totalfreedom/fossil/economy/SimpleTransaction.java index 4e3e008..6c6f9ac 100644 --- a/Fossil/src/main/java/me/totalfreedom/fossil/economy/SimpleTransaction.java +++ b/Fossil/src/main/java/me/totalfreedom/fossil/economy/SimpleTransaction.java @@ -11,7 +11,7 @@ public class SimpleTransaction implements Transaction private final EconomicEntity destination; protected final AtomicLong balance; - public SimpleTransaction(EconomicEntity source, EconomicEntity destination, long balance) + public SimpleTransaction(final EconomicEntity source, final EconomicEntity destination, final long balance) { this.source = source; this.destination = destination; diff --git a/Fossil/src/main/java/me/totalfreedom/fossil/economy/SimpleTransactionLogger.java b/Fossil/src/main/java/me/totalfreedom/fossil/economy/SimpleTransactionLogger.java index e53551b..8ef43e9 100644 --- a/Fossil/src/main/java/me/totalfreedom/fossil/economy/SimpleTransactionLogger.java +++ b/Fossil/src/main/java/me/totalfreedom/fossil/economy/SimpleTransactionLogger.java @@ -1,7 +1,10 @@ package me.totalfreedom.fossil.economy; import me.totalfreedom.audience.MutableAudienceForwarder; -import me.totalfreedom.economy.*; +import me.totalfreedom.economy.TransactionResult; +import me.totalfreedom.economy.CompletedTransaction; +import me.totalfreedom.economy.TransactionLogger; +import me.totalfreedom.economy.EconomicEntity; import me.totalfreedom.utils.FreedomLogger; import net.kyori.adventure.text.Component; @@ -10,16 +13,16 @@ public class SimpleTransactionLogger implements TransactionLogger private final MutableAudienceForwarder audience = MutableAudienceForwarder.from(FreedomLogger.getLogger("Fossil")); @Override - public void logTransaction(CompletedTransaction completedTransaction) + public void logTransaction(final CompletedTransaction completedTransaction) { - StringBuilder transactionLoggingStatementBuilder = new StringBuilder(); - TransactionResult result = completedTransaction.getResult(); - boolean resultSuccess = result.isSuccessful(); - String resultMessage = result.getMessage(); + final StringBuilder transactionLoggingStatementBuilder = new StringBuilder(); + final TransactionResult result = completedTransaction.getResult(); + final boolean resultSuccess = result.isSuccessful(); + final String resultMessage = result.getMessage(); - EconomicEntity source = completedTransaction.getSource(); - EconomicEntity destination = completedTransaction.getDestination(); - long transactionAmount = completedTransaction.getBalance(); + final EconomicEntity source = completedTransaction.getSource(); + final EconomicEntity destination = completedTransaction.getDestination(); + final long transactionAmount = completedTransaction.getBalance(); transactionLoggingStatementBuilder.append(resultSuccess ? "Successful" : "Unsuccessful") .append(" (") @@ -33,7 +36,7 @@ public class SimpleTransactionLogger implements TransactionLogger .append(transactionAmount) .append("."); - Component message = Component.text(transactionLoggingStatementBuilder.toString()); + final Component message = Component.text(transactionLoggingStatementBuilder.toString()); audience.sendMessage(message); } diff --git a/Fossil/src/main/java/me/totalfreedom/fossil/economy/SimpleTransactionResult.java b/Fossil/src/main/java/me/totalfreedom/fossil/economy/SimpleTransactionResult.java index 258ae84..935ea22 100644 --- a/Fossil/src/main/java/me/totalfreedom/fossil/economy/SimpleTransactionResult.java +++ b/Fossil/src/main/java/me/totalfreedom/fossil/economy/SimpleTransactionResult.java @@ -14,12 +14,12 @@ public class SimpleTransactionResult implements TransactionResult private final Component component; private final boolean successful; - public SimpleTransactionResult(String message, boolean successful) + public SimpleTransactionResult(final String message, final boolean successful) { this(message, Component.text(message, successful ? NamedTextColor.GREEN : NamedTextColor.RED), successful); } - public SimpleTransactionResult(String message, Component component, boolean successful) + public SimpleTransactionResult(final String message, final Component component, final boolean successful) { this.message = message; this.component = component; diff --git a/Fossil/src/main/java/me/totalfreedom/fossil/economy/SimpleTransactor.java b/Fossil/src/main/java/me/totalfreedom/fossil/economy/SimpleTransactor.java index 735571e..7524174 100644 --- a/Fossil/src/main/java/me/totalfreedom/fossil/economy/SimpleTransactor.java +++ b/Fossil/src/main/java/me/totalfreedom/fossil/economy/SimpleTransactor.java @@ -1,37 +1,41 @@ package me.totalfreedom.fossil.economy; -import me.totalfreedom.economy.*; +import me.totalfreedom.economy.CompletedTransaction; +import me.totalfreedom.economy.EconomicEntity; +import me.totalfreedom.economy.EconomicEntityData; +import me.totalfreedom.economy.MutableTransaction; +import me.totalfreedom.economy.Transactor; public class SimpleTransactor implements Transactor { @Override - public CompletedTransaction handleTransaction(MutableTransaction transaction) + public CompletedTransaction handleTransaction(final MutableTransaction transaction) { - EconomicEntity source = transaction.getSource(); - EconomicEntityData sourceData = source.getEconomicData(); + final EconomicEntity source = transaction.getSource(); + final EconomicEntityData sourceData = source.getEconomicData(); if (sourceData.areTransactionsFrozen()) { return new SimpleCompletedTransaction(transaction, SimpleTransactionResult.UNAUTHORIZED); } - long transactionAmount = transaction.getBalance(); + final long transactionAmount = transaction.getBalance(); if (transactionAmount >= 0) { return new SimpleCompletedTransaction(transaction, SimpleTransactionResult.AMOUNT_TOO_SMALL); } - long sourceBalance = sourceData.getBalance(); - long diff = sourceBalance - transactionAmount; + final long sourceBalance = sourceData.getBalance(); + final long diff = sourceBalance - transactionAmount; if (diff > 0) { return new SimpleCompletedTransaction(transaction, SimpleTransactionResult.INSUFFICIENT_FUNDS); } - EconomicEntity destination = transaction.getDestination(); - EconomicEntityData destinationData = destination.getEconomicData(); + final EconomicEntity destination = transaction.getDestination(); + final EconomicEntityData destinationData = destination.getEconomicData(); if (destinationData.areTransactionsFrozen()) { diff --git a/Patchwork/src/main/java/me/totalfreedom/audience/MutableAudienceForwarder.java b/Patchwork/src/main/java/me/totalfreedom/audience/MutableAudienceForwarder.java index 60fc88b..7ade549 100644 --- a/Patchwork/src/main/java/me/totalfreedom/audience/MutableAudienceForwarder.java +++ b/Patchwork/src/main/java/me/totalfreedom/audience/MutableAudienceForwarder.java @@ -28,11 +28,11 @@ public class MutableAudienceForwarder implements Audience { private final Set audiences = new HashSet<>(); - public static MutableAudienceForwarder from(Audience... audiences) + public static MutableAudienceForwarder from(final Audience... audiences) { - MutableAudienceForwarder audienceForwarder = new MutableAudienceForwarder(); + final MutableAudienceForwarder audienceForwarder = new MutableAudienceForwarder(); - for (Audience audience : audiences) + for (final Audience audience : audiences) { audienceForwarder.addAudience(audience); } @@ -40,7 +40,7 @@ public class MutableAudienceForwarder implements Audience return audienceForwarder; } - public void addAudience(Audience audience) + public void addAudience(final Audience audience) { if (audiences.contains(audience) || audience == this /* Protect against honest self-referential calls */) { @@ -50,14 +50,14 @@ public class MutableAudienceForwarder implements Audience audiences.add(audience); } - public boolean removeAudience(Audience audience) + public boolean removeAudience(final Audience audience) { return audiences.remove(audience); } @Override - public @NotNull Audience filterAudience(@NotNull Predicate filter) + public @NotNull Audience filterAudience(@NotNull final Predicate filter) { return audiences.stream() .filter(filter) @@ -66,49 +66,49 @@ public class MutableAudienceForwarder implements Audience } @Override - public void forEachAudience(@NotNull Consumer action) + public void forEachAudience(@NotNull final Consumer action) { audiences.forEach(action); } @Override - public void sendMessage(@NotNull ComponentLike message) + public void sendMessage(@NotNull final ComponentLike message) { audiences.forEach(a -> a.sendMessage(message)); } @Override - public void sendMessage(@NotNull Component message) + public void sendMessage(@NotNull final Component message) { audiences.forEach(a -> a.sendMessage(message)); } @Override - public void sendMessage(@NotNull Component message, ChatType.@NotNull Bound boundChatType) + public void sendMessage(@NotNull final Component message, final ChatType.@NotNull Bound boundChatType) { audiences.forEach(a -> a.sendMessage(message, boundChatType)); } @Override - public void sendMessage(@NotNull ComponentLike message, ChatType.@NotNull Bound boundChatType) + public void sendMessage(@NotNull final ComponentLike message, final ChatType.@NotNull Bound boundChatType) { audiences.forEach(a -> a.sendMessage(message, boundChatType)); } @Override - public void sendMessage(@NotNull SignedMessage signedMessage, ChatType.@NotNull Bound boundChatType) + public void sendMessage(@NotNull final SignedMessage signedMessage, final ChatType.@NotNull Bound boundChatType) { audiences.forEach(a -> a.sendMessage(signedMessage, boundChatType)); } @Override - public void deleteMessage(@NotNull SignedMessage signedMessage) + public void deleteMessage(@NotNull final SignedMessage signedMessage) { audiences.forEach(a -> a.deleteMessage(signedMessage)); } @Override - public void deleteMessage(SignedMessage.@NotNull Signature signature) + public void deleteMessage(final SignedMessage.@NotNull Signature signature) { audiences.forEach(a -> a.deleteMessage(signature)); } @@ -116,61 +116,61 @@ public class MutableAudienceForwarder implements Audience // The methods below here will (probably) never be used, however it's good to keep them for completeness' sake. @Override - public void sendActionBar(@NotNull ComponentLike message) + public void sendActionBar(@NotNull final ComponentLike message) { audiences.forEach(a -> a.sendActionBar(message)); } @Override - public void sendActionBar(@NotNull Component message) + public void sendActionBar(@NotNull final Component message) { audiences.forEach(a -> a.sendActionBar(message)); } @Override - public void sendPlayerListHeader(@NotNull ComponentLike header) + public void sendPlayerListHeader(@NotNull final ComponentLike header) { audiences.forEach(a -> a.sendPlayerListHeader(header)); } @Override - public void sendPlayerListHeader(@NotNull Component header) + public void sendPlayerListHeader(@NotNull final Component header) { audiences.forEach(a -> a.sendPlayerListHeader(header)); } @Override - public void sendPlayerListFooter(@NotNull ComponentLike footer) + public void sendPlayerListFooter(@NotNull final ComponentLike footer) { audiences.forEach(a -> a.sendPlayerListFooter(footer)); } @Override - public void sendPlayerListFooter(@NotNull Component footer) + public void sendPlayerListFooter(@NotNull final Component footer) { audiences.forEach(a -> a.sendPlayerListFooter(footer)); } @Override - public void sendPlayerListHeaderAndFooter(@NotNull ComponentLike header, @NotNull ComponentLike footer) + public void sendPlayerListHeaderAndFooter(@NotNull final ComponentLike header, @NotNull final ComponentLike footer) { audiences.forEach(a -> a.sendPlayerListHeaderAndFooter(header, footer)); } @Override - public void sendPlayerListHeaderAndFooter(@NotNull Component header, @NotNull Component footer) + public void sendPlayerListHeaderAndFooter(@NotNull final Component header, @NotNull final Component footer) { audiences.forEach(a -> a.sendPlayerListHeaderAndFooter(header, footer)); } @Override - public void showTitle(@NotNull Title title) + public void showTitle(@NotNull final Title title) { audiences.forEach(a -> a.showTitle(title)); } @Override - public void sendTitlePart(@NotNull TitlePart part, @NotNull T value) + public void sendTitlePart(@NotNull final TitlePart part, @NotNull final T value) { audiences.forEach(a -> a.sendTitlePart(part, value)); } @@ -188,56 +188,56 @@ public class MutableAudienceForwarder implements Audience } @Override - public void showBossBar(@NotNull BossBar bar) + public void showBossBar(@NotNull final BossBar bar) { audiences.forEach(a -> a.showBossBar(bar)); } @Override - public void hideBossBar(@NotNull BossBar bar) + public void hideBossBar(@NotNull final BossBar bar) { audiences.forEach(a -> a.hideBossBar(bar)); } @Override - public void playSound(@NotNull Sound sound) + public void playSound(@NotNull final Sound sound) { audiences.forEach(a -> a.playSound(sound)); } @Override - public void playSound(@NotNull Sound sound, double x, double y, double z) + public void playSound(@NotNull final Sound sound, final double x, final double y, final double z) { audiences.forEach(a -> a.playSound(sound, x, y, z)); } @Override - public void playSound(@NotNull Sound sound, Sound.@NotNull Emitter emitter) + public void playSound(@NotNull final Sound sound, final Sound.@NotNull Emitter emitter) { audiences.forEach(a -> a.playSound(sound, emitter)); } @Override - public void stopSound(@NotNull Sound sound) + public void stopSound(@NotNull final Sound sound) { audiences.forEach(a -> a.stopSound(sound)); } @Override - public void stopSound(@NotNull SoundStop stop) + public void stopSound(@NotNull final SoundStop stop) { audiences.forEach(a -> a.stopSound(stop)); } @Override - public void openBook(Book.@NotNull Builder book) + public void openBook(final Book.@NotNull Builder book) { audiences.forEach(a -> a.openBook(book)); } @Override - public void openBook(@NotNull Book book) + public void openBook(@NotNull final Book book) { audiences.forEach(a -> a.openBook(book)); } diff --git a/Patchwork/src/main/java/me/totalfreedom/command/BukkitDelegator.java b/Patchwork/src/main/java/me/totalfreedom/command/BukkitDelegator.java index e34c95d..eb249e8 100644 --- a/Patchwork/src/main/java/me/totalfreedom/command/BukkitDelegator.java +++ b/Patchwork/src/main/java/me/totalfreedom/command/BukkitDelegator.java @@ -102,7 +102,7 @@ public class BukkitDelegator extends Command implements PluginIdentifiableComman { try { - command.getBaseMethodPair().getValue().invoke(command, sender); + command.getBaseMethodPair().value().invoke(command, sender); } catch (Exception ex) { FreedomLogger.getLogger("Patchwork") diff --git a/Patchwork/src/main/java/me/totalfreedom/data/EventRegistry.java b/Patchwork/src/main/java/me/totalfreedom/data/EventRegistry.java index ae0f0f1..b98d6cb 100644 --- a/Patchwork/src/main/java/me/totalfreedom/data/EventRegistry.java +++ b/Patchwork/src/main/java/me/totalfreedom/data/EventRegistry.java @@ -31,7 +31,7 @@ public class EventRegistry { if (clazz.isInstance(event)) { - return () -> (T) event; + return () -> clazz.cast(event); } } return null; diff --git a/Patchwork/src/main/java/me/totalfreedom/provider/ContextProvider.java b/Patchwork/src/main/java/me/totalfreedom/provider/ContextProvider.java index 8651c83..9c278f5 100644 --- a/Patchwork/src/main/java/me/totalfreedom/provider/ContextProvider.java +++ b/Patchwork/src/main/java/me/totalfreedom/provider/ContextProvider.java @@ -98,20 +98,33 @@ public class ContextProvider return toPlayer(string); } - private @Nullable World toWorld(String string) + private @Nullable World toWorld(final String string) { return Bukkit.getWorld(string); } + // If we decide to, we can "modify" this to use spaces + // and adjust our inputs accordingly. + /** + * When using this method, the input string must be formatted as + *
+ * worldName,x,y,z + *
+ * + * @param string The string to parse + * @return A location object if xyz is valid + */ private @Nullable Location toLocation(final String string) { final String[] split = string.split(","); - if (split.length != 4 || toWorld(split[0]) == null) return null; - if (toDouble(split[1]) == null - || toDouble(split[2]) == null - || toDouble(split[3]) == null) return null; - return new Location(toWorld(split[0]), toDouble(split[1]), toDouble(split[2]), toDouble(split[3])); + if (split.length != 4 || toWorld(split[0]) == null) return null; + + final double x = Double.parseDouble(split[1]); + final double y = Double.parseDouble(split[2]); + final double z = Double.parseDouble(split[3]); + + return new Location(toWorld(split[0]), x, y, z); } private @NotNull Component toComponent(final String string) diff --git a/Patchwork/src/main/java/me/totalfreedom/utils/FreedomAdventure.java b/Patchwork/src/main/java/me/totalfreedom/utils/FreedomAdventure.java index cd0fa3d..fc28035 100644 --- a/Patchwork/src/main/java/me/totalfreedom/utils/FreedomAdventure.java +++ b/Patchwork/src/main/java/me/totalfreedom/utils/FreedomAdventure.java @@ -17,22 +17,22 @@ public class FreedomAdventure private static final PlainTextComponentSerializer PLAIN_TEXT_COMPONENT_SERIALIZER = PlainTextComponentSerializer.plainText(); - public static String toPlainText(Component component) + public static String toPlainText(final Component component) { return PLAIN_TEXT_COMPONENT_SERIALIZER.serialize(component); } - public static String toPlainText(Supplier supplier) + public static String toPlainText(final Supplier supplier) { return toPlainText(supplier.get()); } - public static Supplier supplyPlainText(Supplier supplier) + public static Supplier supplyPlainText(final Supplier supplier) { return new StringRepresentationSupplier(supplier.get()); } - public static Supplier supplyPlainText(Component component) + public static Supplier supplyPlainText(final Component component) { return new StringRepresentationSupplier(component); } diff --git a/Patchwork/src/main/java/me/totalfreedom/utils/FreedomLogger.java b/Patchwork/src/main/java/me/totalfreedom/utils/FreedomLogger.java index 37e2953..4ec4b82 100644 --- a/Patchwork/src/main/java/me/totalfreedom/utils/FreedomLogger.java +++ b/Patchwork/src/main/java/me/totalfreedom/utils/FreedomLogger.java @@ -47,9 +47,9 @@ public class FreedomLogger implements Audience * @param component The component to send. * @return A plain text representation of the message */ - public String infoComponent(Component component) + public String infoComponent(final Component component) { - String plainText = FreedomAdventure.toPlainText(component); + final String plainText = FreedomAdventure.toPlainText(component); logger.info(plainText); return plainText; @@ -77,7 +77,7 @@ public class FreedomLogger implements Audience * @param component The component to send. * @return A string representation of the message. */ - public String infoComponent(Supplier component) + public String infoComponent(final Supplier component) { return this.infoComponent(component.get()); } @@ -97,9 +97,9 @@ public class FreedomLogger implements Audience * * @param component The component to send. */ - public void warnComponent(Component component) + public void warnComponent(final Component component) { - String plainText = FreedomAdventure.toPlainText(component); + final String plainText = FreedomAdventure.toPlainText(component); logger.warn(plainText); } @@ -121,9 +121,9 @@ public class FreedomLogger implements Audience * * @param component The message to send. */ - public String errorComponent(Component component) + public String errorComponent(final Component component) { - String plainText = FreedomAdventure.toPlainText(component); + final String plainText = FreedomAdventure.toPlainText(component); logger.error(plainText); @@ -164,7 +164,7 @@ public class FreedomLogger implements Audience * @param component The component to send. * @return A String representation of the component. */ - public String errorComponent(Supplier component) + public String errorComponent(final Supplier component) { return this.errorComponent(component.get()); } @@ -187,9 +187,9 @@ public class FreedomLogger implements Audience * * @param component The component to send. */ - public String debugComponent(Component component) + public String debugComponent(final Component component) { - String plainText = FreedomAdventure.toPlainText(component); + final String plainText = FreedomAdventure.toPlainText(component); this.debug(plainText); @@ -222,7 +222,7 @@ public class FreedomLogger implements Audience * @param component The component to send. * @return A String representation of the message. */ - public String debugComponent(Supplier component) + public String debugComponent(final Supplier component) { if (debug) { @@ -233,9 +233,9 @@ public class FreedomLogger implements Audience @Override - public void sendMessage(@NotNull ComponentLike message) + public void sendMessage(@NotNull final ComponentLike message) { - Component component = ComponentLike.unbox(message); + final Component component = ComponentLike.unbox(message); if (component == null) { @@ -247,25 +247,25 @@ public class FreedomLogger implements Audience } @Override - public void sendMessage(@NotNull Component message) + public void sendMessage(@NotNull final Component message) { this.infoComponent(message); } @Override - public void sendMessage(@NotNull Component message, ChatType.@NotNull Bound boundChatType) + public void sendMessage(@NotNull final Component message, final ChatType.@NotNull Bound boundChatType) { this.infoComponent(message); } @Override - public void sendMessage(@NotNull ComponentLike message, ChatType.@NotNull Bound boundChatType) + public void sendMessage(@NotNull final ComponentLike message, final ChatType.@NotNull Bound boundChatType) { this.sendMessage(message); } @Override - public void sendMessage(@NotNull SignedMessage signedMessage, ChatType.@NotNull Bound boundChatType) + public void sendMessage(@NotNull final SignedMessage signedMessage, final ChatType.@NotNull Bound boundChatType) { this.info(signedMessage.message()); // TODO: We might want to investigate whether this logs the ENTIRE message, including unsigned & signed content, or only the signed part. This method was written in the assumption that it provided all content. } diff --git a/Patchwork/src/main/java/me/totalfreedom/utils/Pair.java b/Patchwork/src/main/java/me/totalfreedom/utils/Pair.java index 029adad..9ab5e2f 100644 --- a/Patchwork/src/main/java/me/totalfreedom/utils/Pair.java +++ b/Patchwork/src/main/java/me/totalfreedom/utils/Pair.java @@ -1,22 +1,5 @@ package me.totalfreedom.utils; -public class Pair +public record Pair(K key, V value) { - private final K key; - private final V value; - - public Pair(final K key, final V value) { - this.key = key; - this.value = value; - } - - public K getKey() - { - return key; - } - - public V getValue() - { - return value; - } }