mirror of
https://github.com/SimplexDevelopment/FreedomNetworkSuite.git
synced 2025-06-26 19:44:27 +00:00
Slight bugfix, also more code spec alignment
This commit is contained in:
@ -28,11 +28,11 @@ public class MutableAudienceForwarder implements Audience
|
||||
{
|
||||
private final Set<Audience> 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<? super Audience> filter)
|
||||
public @NotNull Audience filterAudience(@NotNull final Predicate<? super Audience> filter)
|
||||
{
|
||||
return audiences.stream()
|
||||
.filter(filter)
|
||||
@ -66,49 +66,49 @@ public class MutableAudienceForwarder implements Audience
|
||||
}
|
||||
|
||||
@Override
|
||||
public void forEachAudience(@NotNull Consumer<? super Audience> action)
|
||||
public void forEachAudience(@NotNull final Consumer<? super Audience> 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 <T> void sendTitlePart(@NotNull TitlePart<T> part, @NotNull T value)
|
||||
public <T> void sendTitlePart(@NotNull final TitlePart<T> 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));
|
||||
}
|
||||
|
@ -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")
|
||||
|
@ -31,7 +31,7 @@ public class EventRegistry
|
||||
{
|
||||
if (clazz.isInstance(event))
|
||||
{
|
||||
return () -> (T) event;
|
||||
return () -> clazz.cast(event);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
|
@ -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
|
||||
* <br>
|
||||
* <code>worldName,x,y,z</code>
|
||||
* <br>
|
||||
*
|
||||
* @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)
|
||||
|
@ -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<Component> supplier)
|
||||
public static String toPlainText(final Supplier<Component> supplier)
|
||||
{
|
||||
return toPlainText(supplier.get());
|
||||
}
|
||||
|
||||
public static Supplier<String> supplyPlainText(Supplier<Component> supplier)
|
||||
public static Supplier<String> supplyPlainText(final Supplier<Component> supplier)
|
||||
{
|
||||
return new StringRepresentationSupplier(supplier.get());
|
||||
}
|
||||
|
||||
public static Supplier<String> supplyPlainText(Component component)
|
||||
public static Supplier<String> supplyPlainText(final Component component)
|
||||
{
|
||||
return new StringRepresentationSupplier(component);
|
||||
}
|
||||
|
@ -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> component)
|
||||
public String infoComponent(final Supplier<Component> 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> component)
|
||||
public String errorComponent(final Supplier<Component> 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> component)
|
||||
public String debugComponent(final Supplier<Component> 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.
|
||||
}
|
||||
|
@ -1,22 +1,5 @@
|
||||
package me.totalfreedom.utils;
|
||||
|
||||
public class Pair<K, V>
|
||||
public record Pair<K, V>(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;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user