Add fabric builds for older MC versions & add checkstyle (#449)

* Remove instance getters, improve command logic, register APi

* Publish multiple fabric builds, enforce checkstyle

* Bump guava

* Bump to 4.4.2
This commit is contained in:
William authored and GitHub committed 2023-07-02 13:26:12 +01:00
1 parent 51baf196b3
commit c9f5262292
219 files changed
+8032 -1392

No files matched your search

@@ -35,7 +35,7 @@ public abstract class Broker {
protected final HuskHomes plugin;
/**
* Create a new broker
* Create a new broker.
*
* @param plugin the HuskHomes plugin instance
*/
@@ -44,9 +44,9 @@ public abstract class Broker {
}
/**
* Handle an inbound {@link Message}
* Handle an inbound {@link Message}.
*
* @param receiver The user who received the message, if a receiver exists
* @param receiver The user who received the message if a receiver exists
* @param message The message
*/
protected void handle(@NotNull OnlineUser receiver, @NotNull Message message) {
@@ -117,18 +117,19 @@ public abstract class Broker {
plugin.getManager().homes().updatePublicHomeCache();
plugin.getManager().warps().updateWarpCache();
}
default -> throw new IllegalStateException("Unexpected value: " + message.getType());
}
}
/**
* Initialize the message broker
* Initialize the message broker.
*
* @throws RuntimeException if the broker fails to initialize
*/
public abstract void initialize() throws IllegalStateException;
/**
* Send a message to the broker
* Send a message to the broker.
*
* @param message the message to send
* @param sender the sender of the message
@@ -136,7 +137,7 @@ public abstract class Broker {
protected abstract void send(@NotNull Message message, @NotNull OnlineUser sender);
/**
* Move an {@link OnlineUser} to a new server on the proxy network
* Move an {@link OnlineUser} to a new server on the proxy network.
*
* @param user the user to move
* @param server the server to move the user to
@@ -144,7 +145,7 @@ public abstract class Broker {
public abstract void changeServer(@NotNull OnlineUser user, @NotNull String server);
/**
* Terminate the broker
* Terminate the broker.
*/
public abstract void close();
@@ -160,7 +161,7 @@ public abstract class Broker {
}
/**
* Identifies types of message brokers
* Identifies types of message brokers.
*/
public enum Type {
PLUGIN_MESSAGE("Plugin Messages"),
@@ -33,7 +33,7 @@ import java.util.UUID;
public class Message {
/**
* Message target indicating all players
* Message target indicating all players.
*/
public static final String TARGET_ALL = "ALL";
@@ -111,7 +111,7 @@ public class Message {
}
/**
* Builder for {@link Message}s
* Builder for {@link Message}s.
*/
public static class Builder {
private Type type;
@@ -160,7 +160,7 @@ public class Message {
}
/**
* Different types of cross-server messages
* Different types of cross-server messages.
*/
public enum Type {
TELEPORT_TO_POSITION,
@@ -30,7 +30,7 @@ import java.util.List;
import java.util.Optional;
/**
* Represents a payload sent in a cross-server {@link Message}
* Represents a payload sent in a cross-server {@link Message}.
*/
public class Payload {
@@ -53,7 +53,7 @@ public class Payload {
private List<String> stringList;
/**
* Returns an empty cross-server message payload
* Returns an empty cross-server message payload.
*
* @return an empty payload
*/
@@ -63,7 +63,7 @@ public class Payload {
}
/**
* Returns a payload containing a {@link Position}
* Returns a payload containing a {@link Position}.
*
* @param position the position to send
* @return a payload containing the position
@@ -76,7 +76,7 @@ public class Payload {
}
/**
* Returns a payload containing a {@link TeleportRequest}
* Returns a payload containing a {@link TeleportRequest}.
*
* @param teleportRequest the teleport to send
* @return a payload containing the teleport request
@@ -89,7 +89,7 @@ public class Payload {
}
/**
* A string field
* A string field.
*/
@NotNull
public static Payload withString(@NotNull String target) {
@@ -99,7 +99,7 @@ public class Payload {
}
/**
* A string list field
* A string list field.
*/
@NotNull
public static Payload withStringList(@NotNull List<String> target) {
@@ -112,7 +112,7 @@ public class Payload {
}
/**
* A position field
* A position field.
*/
public Optional<Position> getPosition() {
return Optional.ofNullable(position);
@@ -120,21 +120,21 @@ public class Payload {
/**
* A teleport request field
* A teleport request field.
*/
public Optional<TeleportRequest> getTeleportRequest() {
return Optional.ofNullable(teleportRequest);
}
/**
* A string field
* A string field.
*/
public Optional<String> getString() {
return Optional.ofNullable(string);
}
/**
* A string list field
* A string list field.
*/
public Optional<List<String>> getStringList() {
return Optional.ofNullable(stringList);
@@ -31,18 +31,15 @@ import java.util.logging.Level;
/**
* <a href="https://www.spigotmc.org/wiki/bukkit-bungee-plugin-messaging-channel/">Plugin Messaging channel</a> message
* broker implementation
* broker implementation.
*/
public class PluginMessageBroker extends Broker {
/**
* The name of BungeeCord's provided plugin channel.
*
* @implNote Technically, the effective identifier of this channel is {@code bungeecord:main}, but Spigot remaps
* {@code BungeeCord} automatically to the new one (<a href="https://wiki.vg/Plugin_channels#bungeecord:main">source</a>).
* Spigot's <a href="https://www.spigotmc.org/wiki/bukkit-bungee-plugin-messaging-channel/">official documentation</a>
* still instructs usage of {@code BungeeCord} as the name to use, however. It's all a bit inconsistent, so just in case
* it's best to leave it how it is for to maintain backwards compatibility.
* <p>Internally, this is <a href="https://wiki.vg/Plugin_channels#bungeecord:main">{@code bungeecord:main}</a>,
* but Spigot remaps {@code BungeeCord} automatically to the new one (hence BungeeCord is kept for back-compat).
*/
public static final String BUNGEE_CHANNEL_ID = "BungeeCord";
@@ -55,7 +52,6 @@ public class PluginMessageBroker extends Broker {
plugin.initializePluginChannels();
}
@SuppressWarnings("UnstableApiUsage")
public final void onReceive(@NotNull String channel, @NotNull OnlineUser user, byte[] message) {
if (!channel.equals(BUNGEE_CHANNEL_ID)) {
return;
@@ -79,7 +75,6 @@ public class PluginMessageBroker extends Broker {
}
@Override
@SuppressWarnings("UnstableApiUsage")
protected void send(@NotNull Message message, @NotNull OnlineUser sender) {
final ByteArrayDataOutput messageWriter = ByteStreams.newDataOutput();
messageWriter.writeUTF(message.getScope().getPluginMessageChannel());
@@ -102,7 +97,6 @@ public class PluginMessageBroker extends Broker {
}
@Override
@SuppressWarnings("UnstableApiUsage")
public void changeServer(@NotNull OnlineUser user, @NotNull String server) {
final ByteArrayDataOutput outputStream = ByteStreams.newDataOutput();
@@ -115,4 +109,5 @@ public class PluginMessageBroker extends Broker {
@Override
public void close() {
}
}
}
@@ -30,7 +30,7 @@ import redis.clients.jedis.JedisPubSub;
import java.util.logging.Level;
/**
* Redis PubSub broker implementation
* Redis PubSub broker implementation.
*/
public class RedisBroker extends PluginMessageBroker {
private JedisPool jedisPool;
@@ -78,13 +78,13 @@ public class RedisBroker extends PluginMessageBroker {
if (message.getScope() == Message.Scope.PLAYER) {
plugin.getOnlineUsers().stream()
.filter(online -> message.getTarget().equals(Message.TARGET_ALL)
|| online.getUsername().equals(message.getTarget()))
|| online.getUsername().equals(message.getTarget()))
.forEach(receiver -> handle(receiver, message));
return;
}
if (message.getTarget().equals(plugin.getServerName())
|| message.getTarget().equals(Message.TARGET_ALL)) {
|| message.getTarget().equals(Message.TARGET_ALL)) {
plugin.getOnlineUsers().stream()
.findAny()
.ifPresent(receiver -> handle(receiver, message));