diff --git a/README.md b/README.md index f251dcf..0793344 100644 --- a/README.md +++ b/README.md @@ -16,7 +16,7 @@ Cluster mode compatibility in version 0.8.0: If you are using static legacy method `RedisBungee#getPool()` it might fail in: * if Cluster mode is enabled, due fact its Uses different classes -* JedisPool compatibility mode is disabled in the config due fact project internally switched to JedisPooled than Jedis +* if JedisPool compatibility mode is disabled in the config due fact project internally switched to JedisPooled than Jedis ## notes If you are looking to use Original RedisBungee without a change to internals, diff --git a/RedisBungee-API/src/main/java/com/imaginarycode/minecraft/redisbungee/AbstractRedisBungeeAPI.java b/RedisBungee-API/src/main/java/com/imaginarycode/minecraft/redisbungee/AbstractRedisBungeeAPI.java index 8a85e8f..874eff4 100644 --- a/RedisBungee-API/src/main/java/com/imaginarycode/minecraft/redisbungee/AbstractRedisBungeeAPI.java +++ b/RedisBungee-API/src/main/java/com/imaginarycode/minecraft/redisbungee/AbstractRedisBungeeAPI.java @@ -31,13 +31,18 @@ public abstract class AbstractRedisBungeeAPI { protected final List reservedChannels; AbstractRedisBungeeAPI(RedisBungeePlugin plugin) { - abstractRedisBungeeAPI = this; - this.plugin = plugin; + // this does make sure that no one can place first initiated API class. + if (abstractRedisBungeeAPI == null) { + abstractRedisBungeeAPI = this; + } this.reservedChannels = ImmutableList.of( "redisbungee-allservers", "redisbungee-" + plugin.getConfiguration().getProxyId(), "redisbungee-data" ); + + this.plugin = plugin; + } /** @@ -59,6 +64,7 @@ public abstract class AbstractRedisBungeeAPI { public final long getLastOnline(@NonNull UUID player) { return plugin.getDataManager().getLastOnline(player); } + /** * Get the server where the specified player is playing. This function also deals with the case of local players * as well, and will return local information on them. @@ -338,7 +344,7 @@ public abstract class AbstractRedisBungeeAPI { * Kicks a player from the network * * @param playerName player name - * @param message kick message that player will see on kick + * @param message kick message that player will see on kick * @since 0.8.0 */ @@ -350,7 +356,7 @@ public abstract class AbstractRedisBungeeAPI { * Kicks a player from the network * * @param playerUUID player name - * @param message kick message that player will see on kick + * @param message kick message that player will see on kick * @since 0.8.0 */ public void kickPlayer(UUID playerUUID, String message) { @@ -361,9 +367,9 @@ public abstract class AbstractRedisBungeeAPI { * This gives you instance of Jedis * * @return {@link Jedis} - * @since 0.7.0 * @throws IllegalStateException if the {@link #getMode()} is not equal to {@link RedisBungeeMode#SINGLE} * @see #getJedisPool() + * @since 0.7.0 */ public Jedis requestJedis() { if (getMode() == RedisBungeeMode.SINGLE) { @@ -377,9 +383,9 @@ public abstract class AbstractRedisBungeeAPI { * This gets Redis Bungee {@link JedisPool} * * @return {@link JedisPool} - * @since 0.6.5 * @throws IllegalStateException if the {@link #getMode()} is not equal to {@link RedisBungeeMode#SINGLE} * @throws IllegalStateException if JedisPool compatibility mode is disabled in the config + * @since 0.6.5 */ public JedisPool getJedisPool() { if (getMode() == RedisBungeeMode.SINGLE) { @@ -398,8 +404,8 @@ public abstract class AbstractRedisBungeeAPI { * WARNING DO NOT USE {@link JedisCluster#close()} it will break the functionally * * @return {@link redis.clients.jedis.JedisCluster} - * @since 0.8.0 * @throws IllegalStateException if the {@link #getMode()} is not equal to {@link RedisBungeeMode#CLUSTER} + * @since 0.8.0 */ public JedisCluster requestClusterJedis() { if (getMode() == RedisBungeeMode.CLUSTER) { @@ -414,8 +420,8 @@ public abstract class AbstractRedisBungeeAPI { * WARNING: DO NOT USE {@link redis.clients.jedis.JedisPooled#close()} it will break the functionally * * @return {@link redis.clients.jedis.JedisPooled} - * @since 0.8.0 * @throws IllegalStateException if the {@link #getMode()} is not equal to {@link RedisBungeeMode#SINGLE} + * @since 0.8.0 */ public JedisCluster requestJedisPooled() { if (getMode() == RedisBungeeMode.SINGLE) { diff --git a/RedisBungee-API/src/main/java/com/imaginarycode/minecraft/redisbungee/api/AbstractDataManager.java b/RedisBungee-API/src/main/java/com/imaginarycode/minecraft/redisbungee/api/AbstractDataManager.java index 7311a3e..ba3830b 100644 --- a/RedisBungee-API/src/main/java/com/imaginarycode/minecraft/redisbungee/api/AbstractDataManager.java +++ b/RedisBungee-API/src/main/java/com/imaginarycode/minecraft/redisbungee/api/AbstractDataManager.java @@ -171,7 +171,7 @@ public abstract class AbstractDataManager { ipCache.put(message1.getTarget(), message1.getPayload().getAddress()); plugin.executeAsync(() -> { Object event = plugin.createPlayerJoinedNetworkEvent(message1.getTarget()); - plugin.callEvent(event); + plugin.fireEvent(event); }); break; case LEAVE: @@ -181,7 +181,7 @@ public abstract class AbstractDataManager { lastOnlineCache.put(message2.getTarget(), message2.getPayload().getTimestamp()); plugin.executeAsync(() -> { Object event = plugin.createPlayerLeftNetworkEvent(message2.getTarget()); - plugin.callEvent(event); + plugin.fireEvent(event); }); break; case SERVER_CHANGE: @@ -189,8 +189,8 @@ public abstract class AbstractDataManager { }.getType()); serverCache.put(message3.getTarget(), message3.getPayload().getServer()); plugin.executeAsync(() -> { - Object event = plugin.createPlayerChangedNetworkEvent(message3.getTarget(), message3.getPayload().getOldServer(), message3.getPayload().getServer()); - plugin.callEvent(event); + Object event = plugin.createPlayerChangedServerNetworkEvent(message3.getTarget(), message3.getPayload().getOldServer(), message3.getPayload().getServer()); + plugin.fireEvent(event); }); break; case KICK: diff --git a/RedisBungee-API/src/main/java/com/imaginarycode/minecraft/redisbungee/api/AbstractRedisBungeeListener.java b/RedisBungee-API/src/main/java/com/imaginarycode/minecraft/redisbungee/api/AbstractRedisBungeeListener.java index f88fc40..1317da6 100644 --- a/RedisBungee-API/src/main/java/com/imaginarycode/minecraft/redisbungee/api/AbstractRedisBungeeListener.java +++ b/RedisBungee-API/src/main/java/com/imaginarycode/minecraft/redisbungee/api/AbstractRedisBungeeListener.java @@ -38,34 +38,6 @@ public abstract class AbstractRedisBungeeListener { public abstract void onPluginMessage(PM event); - protected void serializeMultiset(Multiset collection, ByteArrayDataOutput output) { - output.writeInt(collection.elementSet().size()); - for (Multiset.Entry entry : collection.entrySet()) { - output.writeUTF(entry.getElement()); - output.writeInt(entry.getCount()); - } - } - - @SuppressWarnings("SameParameterValue") - protected void serializeMultimap(Multimap collection, boolean includeNames, ByteArrayDataOutput output) { - output.writeInt(collection.keySet().size()); - for (Map.Entry> entry : collection.asMap().entrySet()) { - output.writeUTF(entry.getKey()); - if (includeNames) { - serializeCollection(entry.getValue(), output); - } else { - output.writeInt(entry.getValue().size()); - } - } - } - - private void serializeCollection(Collection collection, ByteArrayDataOutput output) { - output.writeInt(collection.size()); - for (Object o : collection) { - output.writeUTF(o.toString()); - } - } - public abstract void onPubSubMessage(PS event); diff --git a/RedisBungee-API/src/main/java/com/imaginarycode/minecraft/redisbungee/api/EventsPlatform.java b/RedisBungee-API/src/main/java/com/imaginarycode/minecraft/redisbungee/api/EventsPlatform.java deleted file mode 100644 index 8f89847..0000000 --- a/RedisBungee-API/src/main/java/com/imaginarycode/minecraft/redisbungee/api/EventsPlatform.java +++ /dev/null @@ -1,23 +0,0 @@ -package com.imaginarycode.minecraft.redisbungee.api; - -import java.util.UUID; - -/** - * Since each platform have their own events' implementation for example Bungeecord events extends Event while velocity don't - * - * @author Ham1255 - * @since 0.7.0 - * - */ -public interface EventsPlatform { - - Object createPlayerChangedNetworkEvent(UUID uuid, String previousServer, String server); - - Object createPlayerJoinedNetworkEvent(UUID uuid); - - Object createPlayerLeftNetworkEvent(UUID uuid); - - Object createPubSubEvent(String channel, String message); - - -} diff --git a/RedisBungee-API/src/main/java/com/imaginarycode/minecraft/redisbungee/api/JedisPubSubHandler.java b/RedisBungee-API/src/main/java/com/imaginarycode/minecraft/redisbungee/api/JedisPubSubHandler.java index 77e048c..7a71b36 100644 --- a/RedisBungee-API/src/main/java/com/imaginarycode/minecraft/redisbungee/api/JedisPubSubHandler.java +++ b/RedisBungee-API/src/main/java/com/imaginarycode/minecraft/redisbungee/api/JedisPubSubHandler.java @@ -3,8 +3,6 @@ package com.imaginarycode.minecraft.redisbungee.api; import redis.clients.jedis.JedisPubSub; -import java.lang.reflect.InvocationTargetException; - public class JedisPubSubHandler extends JedisPubSub { @@ -21,7 +19,7 @@ public class JedisPubSubHandler extends JedisPubSub { @Override public void run() { Object event = plugin.createPubSubEvent(s, s2); - plugin.callEvent(event); + plugin.fireEvent(event); } }); } diff --git a/RedisBungee-API/src/main/java/com/imaginarycode/minecraft/redisbungee/api/RedisBungeePlugin.java b/RedisBungee-API/src/main/java/com/imaginarycode/minecraft/redisbungee/api/RedisBungeePlugin.java index ee26fee..e3a8b0b 100644 --- a/RedisBungee-API/src/main/java/com/imaginarycode/minecraft/redisbungee/api/RedisBungeePlugin.java +++ b/RedisBungee-API/src/main/java/com/imaginarycode/minecraft/redisbungee/api/RedisBungeePlugin.java @@ -5,8 +5,8 @@ import com.google.common.collect.ImmutableMultimap; import com.google.common.collect.ImmutableSet; import com.google.common.collect.Multimap; import com.imaginarycode.minecraft.redisbungee.AbstractRedisBungeeAPI; -import com.imaginarycode.minecraft.redisbungee.api.config.ConfigLoader; import com.imaginarycode.minecraft.redisbungee.api.config.RedisBungeeConfiguration; +import com.imaginarycode.minecraft.redisbungee.api.events.EventsPlatform; import com.imaginarycode.minecraft.redisbungee.api.summoners.Summoner; import com.imaginarycode.minecraft.redisbungee.api.tasks.RedisTask; import com.imaginarycode.minecraft.redisbungee.api.util.RedisUtil; @@ -24,12 +24,12 @@ import static com.google.common.base.Preconditions.checkArgument; /** - * This Class has all internal methods needed by every redis bungee plugin, and it can be used to implement another platforms than bungeecord + * This Class has all internal methods needed by every redis bungee plugin, and it can be used to implement another platforms than bungeecord or another forks of RedisBungee * * @author Ham1255 * @since 0.7.0 */ -public interface RedisBungeePlugin

extends EventsPlatform, ConfigLoader { +public interface RedisBungeePlugin

extends EventsPlatform { default void initialize() { @@ -201,8 +201,6 @@ public interface RedisBungeePlugin

extends EventsPlatform, ConfigLoader { void executeAsyncAfter(Runnable runnable, TimeUnit timeUnit, int time); - void callEvent(Object event); - boolean isOnlineMode(); void logInfo(String msg); diff --git a/RedisBungee-API/src/main/java/com/imaginarycode/minecraft/redisbungee/api/events/EventsPlatform.java b/RedisBungee-API/src/main/java/com/imaginarycode/minecraft/redisbungee/api/events/EventsPlatform.java new file mode 100644 index 0000000..445040d --- /dev/null +++ b/RedisBungee-API/src/main/java/com/imaginarycode/minecraft/redisbungee/api/events/EventsPlatform.java @@ -0,0 +1,24 @@ +package com.imaginarycode.minecraft.redisbungee.api.events; + +import java.util.UUID; + +/** + * Since each platform have their own events' implementation for example Bungeecord events extends Event while velocity don't + * + * @author Ham1255 + * @since 0.7.0 + * + */ +public interface EventsPlatform { + + IPlayerChangedServerNetworkEvent createPlayerChangedServerNetworkEvent(UUID uuid, String previousServer, String server); + + IPlayerJoinedNetworkEvent createPlayerJoinedNetworkEvent(UUID uuid); + + IPlayerLeftNetworkEvent createPlayerLeftNetworkEvent(UUID uuid); + + IPubSubMessageEvent createPubSubEvent(String channel, String message); + + void fireEvent(Object event); + +} diff --git a/RedisBungee-API/src/main/java/com/imaginarycode/minecraft/redisbungee/api/events/IPlayerChangedServerNetworkEvent.java b/RedisBungee-API/src/main/java/com/imaginarycode/minecraft/redisbungee/api/events/IPlayerChangedServerNetworkEvent.java new file mode 100644 index 0000000..a306a7c --- /dev/null +++ b/RedisBungee-API/src/main/java/com/imaginarycode/minecraft/redisbungee/api/events/IPlayerChangedServerNetworkEvent.java @@ -0,0 +1,13 @@ +package com.imaginarycode.minecraft.redisbungee.api.events; + +import java.util.UUID; + +public interface IPlayerChangedServerNetworkEvent extends RedisBungeeEvent { + + UUID getUuid(); + + String getServer(); + + String getPreviousServer(); + +} diff --git a/RedisBungee-API/src/main/java/com/imaginarycode/minecraft/redisbungee/api/events/IPlayerJoinedNetworkEvent.java b/RedisBungee-API/src/main/java/com/imaginarycode/minecraft/redisbungee/api/events/IPlayerJoinedNetworkEvent.java new file mode 100644 index 0000000..9d5e746 --- /dev/null +++ b/RedisBungee-API/src/main/java/com/imaginarycode/minecraft/redisbungee/api/events/IPlayerJoinedNetworkEvent.java @@ -0,0 +1,9 @@ +package com.imaginarycode.minecraft.redisbungee.api.events; + +import java.util.UUID; + +public interface IPlayerJoinedNetworkEvent extends RedisBungeeEvent { + + UUID getUuid(); + +} diff --git a/RedisBungee-API/src/main/java/com/imaginarycode/minecraft/redisbungee/api/events/IPlayerLeftNetworkEvent.java b/RedisBungee-API/src/main/java/com/imaginarycode/minecraft/redisbungee/api/events/IPlayerLeftNetworkEvent.java new file mode 100644 index 0000000..3423ff9 --- /dev/null +++ b/RedisBungee-API/src/main/java/com/imaginarycode/minecraft/redisbungee/api/events/IPlayerLeftNetworkEvent.java @@ -0,0 +1,9 @@ +package com.imaginarycode.minecraft.redisbungee.api.events; + +import java.util.UUID; + +public interface IPlayerLeftNetworkEvent extends RedisBungeeEvent { + + UUID getUuid(); + +} diff --git a/RedisBungee-API/src/main/java/com/imaginarycode/minecraft/redisbungee/api/events/IPubSubMessageEvent.java b/RedisBungee-API/src/main/java/com/imaginarycode/minecraft/redisbungee/api/events/IPubSubMessageEvent.java new file mode 100644 index 0000000..fb37747 --- /dev/null +++ b/RedisBungee-API/src/main/java/com/imaginarycode/minecraft/redisbungee/api/events/IPubSubMessageEvent.java @@ -0,0 +1,10 @@ +package com.imaginarycode.minecraft.redisbungee.api.events; + +public interface IPubSubMessageEvent extends RedisBungeeEvent { + + String getChannel(); + + String getMessage(); + + +} diff --git a/RedisBungee-API/src/main/java/com/imaginarycode/minecraft/redisbungee/api/events/RedisBungeeEvent.java b/RedisBungee-API/src/main/java/com/imaginarycode/minecraft/redisbungee/api/events/RedisBungeeEvent.java new file mode 100644 index 0000000..3370ae1 --- /dev/null +++ b/RedisBungee-API/src/main/java/com/imaginarycode/minecraft/redisbungee/api/events/RedisBungeeEvent.java @@ -0,0 +1,4 @@ +package com.imaginarycode.minecraft.redisbungee.api.events; + +interface RedisBungeeEvent { +} diff --git a/RedisBungee-API/src/main/java/com/imaginarycode/minecraft/redisbungee/api/util/serialize/Serializations.java b/RedisBungee-API/src/main/java/com/imaginarycode/minecraft/redisbungee/api/util/serialize/Serializations.java new file mode 100644 index 0000000..7ee9cc5 --- /dev/null +++ b/RedisBungee-API/src/main/java/com/imaginarycode/minecraft/redisbungee/api/util/serialize/Serializations.java @@ -0,0 +1,39 @@ +package com.imaginarycode.minecraft.redisbungee.api.util.serialize; + +import com.google.common.collect.Multimap; +import com.google.common.collect.Multiset; +import com.google.common.io.ByteArrayDataOutput; + +import java.util.Collection; +import java.util.Map; + +public class Serializations { + + public static void serializeMultiset(Multiset collection, ByteArrayDataOutput output) { + output.writeInt(collection.elementSet().size()); + for (Multiset.Entry entry : collection.entrySet()) { + output.writeUTF(entry.getElement()); + output.writeInt(entry.getCount()); + } + } + + @SuppressWarnings("SameParameterValue") + public static void serializeMultimap(Multimap collection, boolean includeNames, ByteArrayDataOutput output) { + output.writeInt(collection.keySet().size()); + for (Map.Entry> entry : collection.asMap().entrySet()) { + output.writeUTF(entry.getKey()); + if (includeNames) { + serializeCollection(entry.getValue(), output); + } else { + output.writeInt(entry.getValue().size()); + } + } + } + + public static void serializeCollection(Collection collection, ByteArrayDataOutput output) { + output.writeInt(collection.size()); + for (Object o : collection) { + output.writeUTF(o.toString()); + } + } +} diff --git a/RedisBungee-Bungee/src/main/java/com/imaginarycode/minecraft/redisbungee/RedisBungee.java b/RedisBungee-Bungee/src/main/java/com/imaginarycode/minecraft/redisbungee/RedisBungee.java index c2822fe..6516e1f 100644 --- a/RedisBungee-Bungee/src/main/java/com/imaginarycode/minecraft/redisbungee/RedisBungee.java +++ b/RedisBungee-Bungee/src/main/java/com/imaginarycode/minecraft/redisbungee/RedisBungee.java @@ -4,7 +4,12 @@ import com.google.common.cache.Cache; import com.google.common.cache.CacheBuilder; import com.google.common.collect.ImmutableSet; import com.google.common.collect.Multimap; +import com.imaginarycode.minecraft.redisbungee.api.config.ConfigLoader; import com.imaginarycode.minecraft.redisbungee.api.config.RedisBungeeConfiguration; +import com.imaginarycode.minecraft.redisbungee.api.events.IPlayerChangedServerNetworkEvent; +import com.imaginarycode.minecraft.redisbungee.api.events.IPlayerJoinedNetworkEvent; +import com.imaginarycode.minecraft.redisbungee.api.events.IPlayerLeftNetworkEvent; +import com.imaginarycode.minecraft.redisbungee.api.events.IPubSubMessageEvent; import com.imaginarycode.minecraft.redisbungee.api.tasks.*; import com.imaginarycode.minecraft.redisbungee.commands.RedisBungeeCommands; import com.imaginarycode.minecraft.redisbungee.events.PlayerChangedServerNetworkEvent; @@ -34,7 +39,7 @@ import java.util.concurrent.atomic.AtomicInteger; import java.util.logging.Level; -public class RedisBungee extends Plugin implements RedisBungeePlugin { +public class RedisBungee extends Plugin implements RedisBungeePlugin, ConfigLoader { private static RedisBungeeAPI apiStatic; @@ -121,7 +126,7 @@ public class RedisBungee extends Plugin implements RedisBungeePlugin plugin) { + public RedisBungeeAPI(RedisBungeePlugin plugin) { super(plugin); - redisBungeeApi = this; + if (redisBungeeApi == null) { + redisBungeeApi = this; + } } /** @@ -29,7 +31,7 @@ public class RedisBungeeAPI extends AbstractRedisBungeeAPI { * * @param player a player uuid * @return {@link ServerInfo} Can be null if proxy can't find it. - * @see #getServerNameFor(UUID) + * @see #getServerNameFor(UUID) */ public final ServerInfo getServerFor(@NonNull UUID player) { return ((Plugin) this.plugin).getProxy().getServerInfo(this.getServerNameFor(player)); diff --git a/RedisBungee-Bungee/src/main/java/com/imaginarycode/minecraft/redisbungee/RedisBungeeBungeeListener.java b/RedisBungee-Bungee/src/main/java/com/imaginarycode/minecraft/redisbungee/RedisBungeeBungeeListener.java index 51cf597..c44ae7c 100644 --- a/RedisBungee-Bungee/src/main/java/com/imaginarycode/minecraft/redisbungee/RedisBungeeBungeeListener.java +++ b/RedisBungee-Bungee/src/main/java/com/imaginarycode/minecraft/redisbungee/RedisBungeeBungeeListener.java @@ -25,6 +25,9 @@ import redis.clients.jedis.UnifiedJedis; import java.net.InetAddress; import java.util.*; +import static com.imaginarycode.minecraft.redisbungee.api.util.serialize.Serializations.serializeMultimap; +import static com.imaginarycode.minecraft.redisbungee.api.util.serialize.Serializations.serializeMultiset; + public class RedisBungeeBungeeListener extends AbstractRedisBungeeListener implements Listener { diff --git a/RedisBungee-Bungee/src/main/java/com/imaginarycode/minecraft/redisbungee/events/PlayerChangedServerNetworkEvent.java b/RedisBungee-Bungee/src/main/java/com/imaginarycode/minecraft/redisbungee/events/PlayerChangedServerNetworkEvent.java index ac01a96..a927202 100644 --- a/RedisBungee-Bungee/src/main/java/com/imaginarycode/minecraft/redisbungee/events/PlayerChangedServerNetworkEvent.java +++ b/RedisBungee-Bungee/src/main/java/com/imaginarycode/minecraft/redisbungee/events/PlayerChangedServerNetworkEvent.java @@ -1,5 +1,6 @@ package com.imaginarycode.minecraft.redisbungee.events; +import com.imaginarycode.minecraft.redisbungee.api.events.IPlayerChangedServerNetworkEvent; import net.md_5.bungee.api.plugin.Event; import java.util.UUID; @@ -13,7 +14,7 @@ import java.util.UUID; * * @since 0.3.4 */ -public class PlayerChangedServerNetworkEvent extends Event { +public class PlayerChangedServerNetworkEvent extends Event implements IPlayerChangedServerNetworkEvent { private final UUID uuid; private final String previousServer; private final String server; @@ -24,14 +25,17 @@ public class PlayerChangedServerNetworkEvent extends Event { this.server = server; } + @Override public UUID getUuid() { return uuid; } + @Override public String getServer() { return server; } + @Override public String getPreviousServer() { return previousServer; } diff --git a/RedisBungee-Bungee/src/main/java/com/imaginarycode/minecraft/redisbungee/events/PlayerJoinedNetworkEvent.java b/RedisBungee-Bungee/src/main/java/com/imaginarycode/minecraft/redisbungee/events/PlayerJoinedNetworkEvent.java index b9eac18..21a837e 100644 --- a/RedisBungee-Bungee/src/main/java/com/imaginarycode/minecraft/redisbungee/events/PlayerJoinedNetworkEvent.java +++ b/RedisBungee-Bungee/src/main/java/com/imaginarycode/minecraft/redisbungee/events/PlayerJoinedNetworkEvent.java @@ -1,5 +1,6 @@ package com.imaginarycode.minecraft.redisbungee.events; +import com.imaginarycode.minecraft.redisbungee.api.events.IPlayerJoinedNetworkEvent; import net.md_5.bungee.api.plugin.Event; import java.util.UUID; @@ -13,13 +14,14 @@ import java.util.UUID; * * @since 0.3.4 */ -public class PlayerJoinedNetworkEvent extends Event { +public class PlayerJoinedNetworkEvent extends Event implements IPlayerJoinedNetworkEvent { private final UUID uuid; public PlayerJoinedNetworkEvent(UUID uuid) { this.uuid = uuid; } + @Override public UUID getUuid() { return uuid; } diff --git a/RedisBungee-Bungee/src/main/java/com/imaginarycode/minecraft/redisbungee/events/PlayerLeftNetworkEvent.java b/RedisBungee-Bungee/src/main/java/com/imaginarycode/minecraft/redisbungee/events/PlayerLeftNetworkEvent.java index 5e9e5ab..0a68698 100644 --- a/RedisBungee-Bungee/src/main/java/com/imaginarycode/minecraft/redisbungee/events/PlayerLeftNetworkEvent.java +++ b/RedisBungee-Bungee/src/main/java/com/imaginarycode/minecraft/redisbungee/events/PlayerLeftNetworkEvent.java @@ -1,5 +1,6 @@ package com.imaginarycode.minecraft.redisbungee.events; +import com.imaginarycode.minecraft.redisbungee.api.events.IPlayerLeftNetworkEvent; import net.md_5.bungee.api.plugin.Event; import java.util.UUID; @@ -13,13 +14,14 @@ import java.util.UUID; * * @since 0.3.4 */ -public class PlayerLeftNetworkEvent extends Event { +public class PlayerLeftNetworkEvent extends Event implements IPlayerLeftNetworkEvent { private final UUID uuid; public PlayerLeftNetworkEvent(UUID uuid) { this.uuid = uuid; } + @Override public UUID getUuid() { return uuid; } diff --git a/RedisBungee-Bungee/src/main/java/com/imaginarycode/minecraft/redisbungee/events/PubSubMessageEvent.java b/RedisBungee-Bungee/src/main/java/com/imaginarycode/minecraft/redisbungee/events/PubSubMessageEvent.java index 32bcb40..212c46b 100644 --- a/RedisBungee-Bungee/src/main/java/com/imaginarycode/minecraft/redisbungee/events/PubSubMessageEvent.java +++ b/RedisBungee-Bungee/src/main/java/com/imaginarycode/minecraft/redisbungee/events/PubSubMessageEvent.java @@ -1,5 +1,6 @@ package com.imaginarycode.minecraft.redisbungee.events; +import com.imaginarycode.minecraft.redisbungee.api.events.IPubSubMessageEvent; import net.md_5.bungee.api.plugin.Event; /** @@ -10,7 +11,7 @@ import net.md_5.bungee.api.plugin.Event; * @since 0.2.6 */ -public class PubSubMessageEvent extends Event { +public class PubSubMessageEvent extends Event implements IPubSubMessageEvent { private final String channel; private final String message; @@ -19,10 +20,12 @@ public class PubSubMessageEvent extends Event { this.message = message; } + @Override public String getChannel() { return channel; } + @Override public String getMessage() { return message; } diff --git a/RedisBungee-Velocity/src/main/java/com/imaginarycode/minecraft/redisbungee/RedisBungeeAPI.java b/RedisBungee-Velocity/src/main/java/com/imaginarycode/minecraft/redisbungee/RedisBungeeAPI.java index 2e30971..4eb69a8 100644 --- a/RedisBungee-Velocity/src/main/java/com/imaginarycode/minecraft/redisbungee/RedisBungeeAPI.java +++ b/RedisBungee-Velocity/src/main/java/com/imaginarycode/minecraft/redisbungee/RedisBungeeAPI.java @@ -18,9 +18,12 @@ public class RedisBungeeAPI extends AbstractRedisBungeeAPI { private static RedisBungeeAPI redisBungeeApi; - RedisBungeeAPI(RedisBungeePlugin plugin) { + public RedisBungeeAPI(RedisBungeePlugin plugin) { super(plugin); - redisBungeeApi = this; + if (redisBungeeApi == null) { + redisBungeeApi = this; + } + } /** diff --git a/RedisBungee-Velocity/src/main/java/com/imaginarycode/minecraft/redisbungee/RedisBungeeVelocityListener.java b/RedisBungee-Velocity/src/main/java/com/imaginarycode/minecraft/redisbungee/RedisBungeeVelocityListener.java index 00dbbad..47c063f 100644 --- a/RedisBungee-Velocity/src/main/java/com/imaginarycode/minecraft/redisbungee/RedisBungeeVelocityListener.java +++ b/RedisBungee-Velocity/src/main/java/com/imaginarycode/minecraft/redisbungee/RedisBungeeVelocityListener.java @@ -33,6 +33,9 @@ import java.net.InetAddress; import java.util.*; import java.util.stream.Collectors; +import static com.imaginarycode.minecraft.redisbungee.api.util.serialize.Serializations.serializeMultimap; +import static com.imaginarycode.minecraft.redisbungee.api.util.serialize.Serializations.serializeMultiset; + public class RedisBungeeVelocityListener extends AbstractRedisBungeeListener { // Some messages are using legacy characters private final LegacyComponentSerializer serializer = LegacyComponentSerializer.legacySection(); diff --git a/RedisBungee-Velocity/src/main/java/com/imaginarycode/minecraft/redisbungee/RedisBungeeVelocityPlugin.java b/RedisBungee-Velocity/src/main/java/com/imaginarycode/minecraft/redisbungee/RedisBungeeVelocityPlugin.java index 033973b..386c304 100644 --- a/RedisBungee-Velocity/src/main/java/com/imaginarycode/minecraft/redisbungee/RedisBungeeVelocityPlugin.java +++ b/RedisBungee-Velocity/src/main/java/com/imaginarycode/minecraft/redisbungee/RedisBungeeVelocityPlugin.java @@ -6,7 +6,12 @@ import com.google.common.collect.ImmutableSet; import com.google.common.collect.Multimap; import com.google.inject.Inject; import com.imaginarycode.minecraft.redisbungee.api.*; +import com.imaginarycode.minecraft.redisbungee.api.config.ConfigLoader; import com.imaginarycode.minecraft.redisbungee.api.config.RedisBungeeConfiguration; +import com.imaginarycode.minecraft.redisbungee.api.events.IPlayerChangedServerNetworkEvent; +import com.imaginarycode.minecraft.redisbungee.api.events.IPlayerJoinedNetworkEvent; +import com.imaginarycode.minecraft.redisbungee.api.events.IPlayerLeftNetworkEvent; +import com.imaginarycode.minecraft.redisbungee.api.events.IPubSubMessageEvent; import com.imaginarycode.minecraft.redisbungee.api.summoners.Summoner; import com.imaginarycode.minecraft.redisbungee.api.tasks.*; import com.imaginarycode.minecraft.redisbungee.api.util.uuid.NameFetcher; @@ -43,7 +48,7 @@ import java.util.concurrent.*; import java.util.concurrent.atomic.AtomicInteger; @Plugin(id = "redisbungee", name = "RedisBungee", version = PomData.VERSION, url = "https://github.com/ProxioDev/RedisBungee", authors = {"astei", "ProxioDev"}) -public class RedisBungeeVelocityPlugin implements RedisBungeePlugin { +public class RedisBungeeVelocityPlugin implements RedisBungeePlugin, ConfigLoader { private final ProxyServer server; private final Logger logger; private final Path dataFolder; @@ -169,7 +174,7 @@ public class RedisBungeeVelocityPlugin implements RedisBungeePlugin { } @Override - public void callEvent(Object event) { + public void fireEvent(Object event) { this.getProxy().getEventManager().fireAndForget(event); } @@ -327,22 +332,22 @@ public class RedisBungeeVelocityPlugin implements RedisBungeePlugin { @Override - public Object createPlayerChangedNetworkEvent(UUID uuid, String previousServer, String server) { + public IPlayerChangedServerNetworkEvent createPlayerChangedServerNetworkEvent(UUID uuid, String previousServer, String server) { return new PlayerChangedServerNetworkEvent(uuid, previousServer, server); } @Override - public Object createPlayerJoinedNetworkEvent(UUID uuid) { + public IPlayerJoinedNetworkEvent createPlayerJoinedNetworkEvent(UUID uuid) { return new PlayerJoinedNetworkEvent(uuid); } @Override - public Object createPlayerLeftNetworkEvent(UUID uuid) { + public IPlayerLeftNetworkEvent createPlayerLeftNetworkEvent(UUID uuid) { return new PlayerLeftNetworkEvent(uuid); } @Override - public Object createPubSubEvent(String channel, String message) { + public IPubSubMessageEvent createPubSubEvent(String channel, String message) { return new PubSubMessageEvent(channel, message); } diff --git a/RedisBungee-Velocity/src/main/java/com/imaginarycode/minecraft/redisbungee/events/PlayerChangedServerNetworkEvent.java b/RedisBungee-Velocity/src/main/java/com/imaginarycode/minecraft/redisbungee/events/PlayerChangedServerNetworkEvent.java index 1a80703..d00c67e 100644 --- a/RedisBungee-Velocity/src/main/java/com/imaginarycode/minecraft/redisbungee/events/PlayerChangedServerNetworkEvent.java +++ b/RedisBungee-Velocity/src/main/java/com/imaginarycode/minecraft/redisbungee/events/PlayerChangedServerNetworkEvent.java @@ -1,6 +1,8 @@ package com.imaginarycode.minecraft.redisbungee.events; +import com.imaginarycode.minecraft.redisbungee.api.events.IPlayerChangedServerNetworkEvent; + import java.util.UUID; /** @@ -12,7 +14,7 @@ import java.util.UUID; * * @since 0.3.4 */ -public class PlayerChangedServerNetworkEvent { +public class PlayerChangedServerNetworkEvent implements IPlayerChangedServerNetworkEvent { private final UUID uuid; private final String previousServer; private final String server; @@ -23,14 +25,17 @@ public class PlayerChangedServerNetworkEvent { this.server = server; } + @Override public UUID getUuid() { return uuid; } + @Override public String getServer() { return server; } + @Override public String getPreviousServer() { return previousServer; } diff --git a/RedisBungee-Velocity/src/main/java/com/imaginarycode/minecraft/redisbungee/events/PlayerJoinedNetworkEvent.java b/RedisBungee-Velocity/src/main/java/com/imaginarycode/minecraft/redisbungee/events/PlayerJoinedNetworkEvent.java index 5e5338e..5d91406 100644 --- a/RedisBungee-Velocity/src/main/java/com/imaginarycode/minecraft/redisbungee/events/PlayerJoinedNetworkEvent.java +++ b/RedisBungee-Velocity/src/main/java/com/imaginarycode/minecraft/redisbungee/events/PlayerJoinedNetworkEvent.java @@ -1,6 +1,8 @@ package com.imaginarycode.minecraft.redisbungee.events; +import com.imaginarycode.minecraft.redisbungee.api.events.IPlayerJoinedNetworkEvent; + import java.util.UUID; /** @@ -12,13 +14,14 @@ import java.util.UUID; * * @since 0.3.4 */ -public class PlayerJoinedNetworkEvent { +public class PlayerJoinedNetworkEvent implements IPlayerJoinedNetworkEvent { private final UUID uuid; public PlayerJoinedNetworkEvent(UUID uuid) { this.uuid = uuid; } + @Override public UUID getUuid() { return uuid; } diff --git a/RedisBungee-Velocity/src/main/java/com/imaginarycode/minecraft/redisbungee/events/PlayerLeftNetworkEvent.java b/RedisBungee-Velocity/src/main/java/com/imaginarycode/minecraft/redisbungee/events/PlayerLeftNetworkEvent.java index 8d83681..7266bf1 100644 --- a/RedisBungee-Velocity/src/main/java/com/imaginarycode/minecraft/redisbungee/events/PlayerLeftNetworkEvent.java +++ b/RedisBungee-Velocity/src/main/java/com/imaginarycode/minecraft/redisbungee/events/PlayerLeftNetworkEvent.java @@ -1,6 +1,8 @@ package com.imaginarycode.minecraft.redisbungee.events; +import com.imaginarycode.minecraft.redisbungee.api.events.IPlayerLeftNetworkEvent; + import java.util.UUID; /** @@ -12,13 +14,14 @@ import java.util.UUID; * * @since 0.3.4 */ -public class PlayerLeftNetworkEvent { +public class PlayerLeftNetworkEvent implements IPlayerLeftNetworkEvent { private final UUID uuid; public PlayerLeftNetworkEvent(UUID uuid) { this.uuid = uuid; } + @Override public UUID getUuid() { return uuid; } diff --git a/RedisBungee-Velocity/src/main/java/com/imaginarycode/minecraft/redisbungee/events/PubSubMessageEvent.java b/RedisBungee-Velocity/src/main/java/com/imaginarycode/minecraft/redisbungee/events/PubSubMessageEvent.java index f168fd3..ba6abd5 100644 --- a/RedisBungee-Velocity/src/main/java/com/imaginarycode/minecraft/redisbungee/events/PubSubMessageEvent.java +++ b/RedisBungee-Velocity/src/main/java/com/imaginarycode/minecraft/redisbungee/events/PubSubMessageEvent.java @@ -1,6 +1,7 @@ package com.imaginarycode.minecraft.redisbungee.events; +import com.imaginarycode.minecraft.redisbungee.api.events.IPubSubMessageEvent; /** * This event is posted when a PubSub message is received. @@ -10,7 +11,7 @@ package com.imaginarycode.minecraft.redisbungee.events; * @since 0.2.6 */ -public class PubSubMessageEvent { +public class PubSubMessageEvent implements IPubSubMessageEvent { private final String channel; private final String message; @@ -19,10 +20,12 @@ public class PubSubMessageEvent { this.message = message; } + @Override public String getChannel() { return channel; } + @Override public String getMessage() { return message; } diff --git a/pom.xml b/pom.xml index 7c6a4cf..22335b5 100644 --- a/pom.xml +++ b/pom.xml @@ -37,9 +37,10 @@ + RedisBungee-API RedisBungee-Bungee RedisBungee-Velocity - +