diff --git a/api/src/main/java/com/craftmend/openaudiomc/api/ApiHolder.java b/api/src/main/java/com/craftmend/openaudiomc/api/ApiHolder.java index 2316d799d..1b04c950b 100644 --- a/api/src/main/java/com/craftmend/openaudiomc/api/ApiHolder.java +++ b/api/src/main/java/com/craftmend/openaudiomc/api/ApiHolder.java @@ -6,19 +6,46 @@ public class ApiHolder { static WorldApi worldApiInstance; static VoiceApi voiceApiInstance; static MediaApi mediaApiInstance; + static EventApi eventApiInstance; public static void initiate( - ClientApi clientApi, - WorldApi worldApi, - VoiceApi voiceApi, - MediaApi mediaApi + ClientApi clientApi ) { if (clientApiInstance != null) throw new IllegalStateException("Api already initiated"); clientApiInstance = clientApi; + } + + public static void initiate( + WorldApi worldApi + ) { + if (worldApiInstance != null) throw new IllegalStateException("Api already initiated"); + worldApiInstance = worldApi; + } + + public static void initiate( + VoiceApi voiceApi + ) { + if (voiceApiInstance != null) throw new IllegalStateException("Api already initiated"); + voiceApiInstance = voiceApi; + } + + public static void initiate( + MediaApi mediaApi + ) { + if (mediaApiInstance != null) throw new IllegalStateException("Api already initiated"); + mediaApiInstance = mediaApi; } + public static void initiate( + EventApi eventApi + ) { + if (eventApiInstance != null) throw new IllegalStateException("Api already initiated"); + + eventApiInstance = eventApi; + } + } diff --git a/api/src/main/java/com/craftmend/openaudiomc/api/EventApi.java b/api/src/main/java/com/craftmend/openaudiomc/api/EventApi.java new file mode 100644 index 000000000..ec9131c29 --- /dev/null +++ b/api/src/main/java/com/craftmend/openaudiomc/api/EventApi.java @@ -0,0 +1,42 @@ +package com.craftmend.openaudiomc.api; + +import com.craftmend.openaudiomc.api.events.BaseEvent; +import com.craftmend.openaudiomc.api.events.SingleHandler; + +public interface EventApi { + + /** + * Get an instance of the event api. May be null if the plugin is not loaded yet + * @return instance + */ + static EventApi getInstance() { + return ApiHolder.eventApiInstance; + } + + /** + * Register a listener for events annotated with @Handler + * @param listener the listener to register + */ + void registerHandlers(Object listener); + + /** + * Unregister a listener for events annotated with @Handler + * @param listener the listener to unregister + */ + void unregisterHandlers(Object listener); + + /** + * Call an event + * @param event the event to call + */ + BaseEvent callEvent(BaseEvent event); + + /** + * Register a handler for a specific event + * @param event the event to listen for + * @param handler the handler to call + * @param the event type + */ + void registerHandler(Class event, SingleHandler handler); + +} diff --git a/api/src/main/java/com/craftmend/openaudiomc/api/clients/Client.java b/api/src/main/java/com/craftmend/openaudiomc/api/clients/Client.java index 83be77b03..d9048063e 100644 --- a/api/src/main/java/com/craftmend/openaudiomc/api/clients/Client.java +++ b/api/src/main/java/com/craftmend/openaudiomc/api/clients/Client.java @@ -66,4 +66,5 @@ public interface Client { * @param media the media to play */ void playMedia(@NotNull Media media); + } diff --git a/api/src/main/java/com/craftmend/openaudiomc/api/events/BaseEvent.java b/api/src/main/java/com/craftmend/openaudiomc/api/events/BaseEvent.java new file mode 100644 index 000000000..f3188604b --- /dev/null +++ b/api/src/main/java/com/craftmend/openaudiomc/api/events/BaseEvent.java @@ -0,0 +1,9 @@ +package com.craftmend.openaudiomc.api.events; + +public abstract class BaseEvent { + + /** + * Base event class, all events should extend this class + */ + +} diff --git a/api/src/main/java/com/craftmend/openaudiomc/api/events/Cancellable.java b/api/src/main/java/com/craftmend/openaudiomc/api/events/Cancellable.java new file mode 100644 index 000000000..10be52598 --- /dev/null +++ b/api/src/main/java/com/craftmend/openaudiomc/api/events/Cancellable.java @@ -0,0 +1,17 @@ +package com.craftmend.openaudiomc.api.events; + +public interface Cancellable { + + /** + * Check if the event is cancelled + * @return true if the event is cancelled + */ + boolean isCancelled(); + + /** + * Set the event to cancelled + * @param cancelled true if the event should be cancelled + */ + void setCancelled(boolean cancelled); + +} diff --git a/api/src/main/java/com/craftmend/openaudiomc/api/events/CancellableClientEvent.java b/api/src/main/java/com/craftmend/openaudiomc/api/events/CancellableClientEvent.java new file mode 100644 index 000000000..007e82835 --- /dev/null +++ b/api/src/main/java/com/craftmend/openaudiomc/api/events/CancellableClientEvent.java @@ -0,0 +1,27 @@ +package com.craftmend.openaudiomc.api.events; + +import com.craftmend.openaudiomc.api.clients.Client; + +public class CancellableClientEvent extends ClientEvent implements Cancellable { + + private boolean cancelled = false; + + /** + * Create a new client event + * + * @param client the client that this event is about + */ + public CancellableClientEvent(Client client) { + super(client); + } + + @Override + public boolean isCancelled() { + return cancelled; + } + + @Override + public void setCancelled(boolean cancelled) { + this.cancelled = cancelled; + } +} diff --git a/api/src/main/java/com/craftmend/openaudiomc/api/events/CancellableEvent.java b/api/src/main/java/com/craftmend/openaudiomc/api/events/CancellableEvent.java new file mode 100644 index 000000000..ea2c9a5ff --- /dev/null +++ b/api/src/main/java/com/craftmend/openaudiomc/api/events/CancellableEvent.java @@ -0,0 +1,16 @@ +package com.craftmend.openaudiomc.api.events; + +public class CancellableEvent extends BaseEvent implements Cancellable { + + private boolean cancelled = false; + + @Override + public boolean isCancelled() { + return cancelled; + } + + @Override + public void setCancelled(boolean cancelled) { + this.cancelled = cancelled; + } +} diff --git a/api/src/main/java/com/craftmend/openaudiomc/api/events/ClientEvent.java b/api/src/main/java/com/craftmend/openaudiomc/api/events/ClientEvent.java new file mode 100644 index 000000000..39aa90c8e --- /dev/null +++ b/api/src/main/java/com/craftmend/openaudiomc/api/events/ClientEvent.java @@ -0,0 +1,24 @@ +package com.craftmend.openaudiomc.api.events; + +import com.craftmend.openaudiomc.api.clients.Client; + +public class ClientEvent extends BaseEvent { + + private final Client client; + + /** + * Create a new client event + * @param client the client that this event is about + */ + public ClientEvent(Client client) { + this.client = client; + } + + /** + * Get the client that this event is about + * @return the client + */ + public Client getClient() { + return client; + } +} diff --git a/api/src/main/java/com/craftmend/openaudiomc/api/events/Handler.java b/api/src/main/java/com/craftmend/openaudiomc/api/events/Handler.java new file mode 100644 index 000000000..108a69a02 --- /dev/null +++ b/api/src/main/java/com/craftmend/openaudiomc/api/events/Handler.java @@ -0,0 +1,16 @@ +package com.craftmend.openaudiomc.api.events; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +@Retention(RetentionPolicy.RUNTIME) +@Target(ElementType.METHOD) +public @interface Handler { + + /** + * This is a marker annotation for event handlers. + */ + +} diff --git a/api/src/main/java/com/craftmend/openaudiomc/api/events/SingleHandler.java b/api/src/main/java/com/craftmend/openaudiomc/api/events/SingleHandler.java new file mode 100644 index 000000000..9f73c3f69 --- /dev/null +++ b/api/src/main/java/com/craftmend/openaudiomc/api/events/SingleHandler.java @@ -0,0 +1,8 @@ +package com.craftmend.openaudiomc.api.events; + +public interface SingleHandler { + + @Handler + void handle(T event); + +} diff --git a/api/src/main/java/com/craftmend/openaudiomc/api/events/client/ClientAuthenticationEvent.java b/api/src/main/java/com/craftmend/openaudiomc/api/events/client/ClientAuthenticationEvent.java new file mode 100644 index 000000000..4bfc066f8 --- /dev/null +++ b/api/src/main/java/com/craftmend/openaudiomc/api/events/client/ClientAuthenticationEvent.java @@ -0,0 +1,25 @@ +package com.craftmend.openaudiomc.api.events.client; + +import com.craftmend.openaudiomc.api.basic.Actor; +import com.craftmend.openaudiomc.api.events.CancellableEvent; +import lombok.Getter; +import lombok.Setter; + +@Getter +@Setter +public class ClientAuthenticationEvent extends CancellableEvent { + + private Actor actor; + private String token; + + /** + * This event is called when a client is attempting to authenticate + * + * @param actor The actor that is trying to authenticate + * @param token The token that is being used + */ + public ClientAuthenticationEvent(Actor actor, String token) { + this.actor = actor; + this.token = token; + } +} diff --git a/api/src/main/java/com/craftmend/openaudiomc/api/events/client/ClientConnectEvent.java b/api/src/main/java/com/craftmend/openaudiomc/api/events/client/ClientConnectEvent.java new file mode 100644 index 000000000..9355991a8 --- /dev/null +++ b/api/src/main/java/com/craftmend/openaudiomc/api/events/client/ClientConnectEvent.java @@ -0,0 +1,15 @@ +package com.craftmend.openaudiomc.api.events.client; + +import com.craftmend.openaudiomc.api.clients.Client; +import com.craftmend.openaudiomc.api.events.ClientEvent; + +public class ClientConnectEvent extends ClientEvent { + /** + * Create a new client connect event, representing a client that has connected to the web client + * + * @param client the client that this event is about + */ + public ClientConnectEvent(Client client) { + super(client); + } +} diff --git a/api/src/main/java/com/craftmend/openaudiomc/api/events/client/ClientDisconnectEvent.java b/api/src/main/java/com/craftmend/openaudiomc/api/events/client/ClientDisconnectEvent.java new file mode 100644 index 000000000..904073547 --- /dev/null +++ b/api/src/main/java/com/craftmend/openaudiomc/api/events/client/ClientDisconnectEvent.java @@ -0,0 +1,15 @@ +package com.craftmend.openaudiomc.api.events.client; + +import com.craftmend.openaudiomc.api.clients.Client; +import com.craftmend.openaudiomc.api.events.ClientEvent; + +public class ClientDisconnectEvent extends ClientEvent { + /** + * Create a new client event that represents a client that has disconnected from the web client + * + * @param client the client that this event is about + */ + public ClientDisconnectEvent(Client client) { + super(client); + } +} diff --git a/api/src/main/java/com/craftmend/openaudiomc/api/events/client/ClientEnableVoiceEvent.java b/api/src/main/java/com/craftmend/openaudiomc/api/events/client/ClientEnableVoiceEvent.java new file mode 100644 index 000000000..17bdb3ed9 --- /dev/null +++ b/api/src/main/java/com/craftmend/openaudiomc/api/events/client/ClientEnableVoiceEvent.java @@ -0,0 +1,12 @@ +package com.craftmend.openaudiomc.api.events.client; + +import com.craftmend.openaudiomc.api.clients.Client; +import com.craftmend.openaudiomc.api.events.CancellableClientEvent; + +public class ClientEnableVoiceEvent extends CancellableClientEvent { + + public ClientEnableVoiceEvent(Client client) { + super(client); + } + +} diff --git a/api/src/main/java/com/craftmend/openaudiomc/api/events/client/ClientPeerAddedEvent.java b/api/src/main/java/com/craftmend/openaudiomc/api/events/client/ClientPeerAddedEvent.java new file mode 100644 index 000000000..9449b5d40 --- /dev/null +++ b/api/src/main/java/com/craftmend/openaudiomc/api/events/client/ClientPeerAddedEvent.java @@ -0,0 +1,28 @@ +package com.craftmend.openaudiomc.api.events.client; + +import com.craftmend.openaudiomc.api.clients.Client; +import com.craftmend.openaudiomc.api.events.ClientEvent; +import com.craftmend.openaudiomc.api.voice.VoicePeerOptions; +import lombok.Getter; +import lombok.Setter; + +@Getter +@Setter +public class ClientPeerAddedEvent extends ClientEvent { + + private Client peer; + private VoicePeerOptions options; + + /** + * Create a new client event + * + * @param client the client that this event is about + * @param peer the peer that was added + * @param options the options that were used to add the peer + */ + public ClientPeerAddedEvent(Client client, Client peer, VoicePeerOptions options) { + super(client); + this.peer = peer; + this.options = options; + } +} diff --git a/api/src/main/java/com/craftmend/openaudiomc/api/events/client/ClientPeerRemovedEvent.java b/api/src/main/java/com/craftmend/openaudiomc/api/events/client/ClientPeerRemovedEvent.java new file mode 100644 index 000000000..1bb2ed4ae --- /dev/null +++ b/api/src/main/java/com/craftmend/openaudiomc/api/events/client/ClientPeerRemovedEvent.java @@ -0,0 +1,24 @@ +package com.craftmend.openaudiomc.api.events.client; + +import com.craftmend.openaudiomc.api.clients.Client; +import com.craftmend.openaudiomc.api.events.ClientEvent; +import lombok.Getter; +import lombok.Setter; + +@Getter +@Setter +public class ClientPeerRemovedEvent extends ClientEvent { + + private Client peer; + + /** + * Create a new client event + * + * @param client the client that this event is about + * @param peer the peer that was removed + */ + public ClientPeerRemovedEvent(Client client, Client peer) { + super(client); + this.peer = peer; + } +} diff --git a/api/src/main/java/com/craftmend/openaudiomc/api/events/client/MediaErrorEvent.java b/api/src/main/java/com/craftmend/openaudiomc/api/events/client/MediaErrorEvent.java new file mode 100644 index 000000000..8190bf2b8 --- /dev/null +++ b/api/src/main/java/com/craftmend/openaudiomc/api/events/client/MediaErrorEvent.java @@ -0,0 +1,40 @@ +package com.craftmend.openaudiomc.api.events.client; + +import com.craftmend.openaudiomc.api.clients.Client; +import com.craftmend.openaudiomc.api.events.ClientEvent; +import com.craftmend.openaudiomc.api.media.MediaError; + +public class MediaErrorEvent extends ClientEvent { + + private String mediaSource; + private MediaError mediaError; + + /** + * This event resembles an internal error in the web client (like bad or failed HTTP media requests). + * + * @param client the client that this event is about + */ + public MediaErrorEvent(Client client, String mediaSource, MediaError mediaError) { + super(client); + this.mediaSource = mediaSource; + this.mediaError = mediaError; + } + + /** + * Get the media source that failed + * + * @return the media source + */ + public String getMediaSource() { + return mediaSource; + } + + /** + * Get the media error + * + * @return the media error + */ + public MediaError getMediaError() { + return mediaError; + } +} diff --git a/api/src/main/java/com/craftmend/openaudiomc/api/events/client/MicrophoneMuteEvent.java b/api/src/main/java/com/craftmend/openaudiomc/api/events/client/MicrophoneMuteEvent.java new file mode 100644 index 000000000..dd73f0e32 --- /dev/null +++ b/api/src/main/java/com/craftmend/openaudiomc/api/events/client/MicrophoneMuteEvent.java @@ -0,0 +1,15 @@ +package com.craftmend.openaudiomc.api.events.client; + +import com.craftmend.openaudiomc.api.clients.Client; +import com.craftmend.openaudiomc.api.events.ClientEvent; + +public class MicrophoneMuteEvent extends ClientEvent { + /** + * This is a simple event that gets called whenever a player explicitly mutes their microphone + * + * @param client the client that this event is about + */ + public MicrophoneMuteEvent(Client client) { + super(client); + } +} diff --git a/api/src/main/java/com/craftmend/openaudiomc/api/events/client/MicrophoneUnmuteEvent.java b/api/src/main/java/com/craftmend/openaudiomc/api/events/client/MicrophoneUnmuteEvent.java new file mode 100644 index 000000000..d6edd6c7a --- /dev/null +++ b/api/src/main/java/com/craftmend/openaudiomc/api/events/client/MicrophoneUnmuteEvent.java @@ -0,0 +1,15 @@ +package com.craftmend.openaudiomc.api.events.client; + +import com.craftmend.openaudiomc.api.clients.Client; +import com.craftmend.openaudiomc.api.events.ClientEvent; + +public class MicrophoneUnmuteEvent extends ClientEvent { + /** + * This is a simple event that gets called whenever a player explicitly unmutes their microphone + * + * @param client the client that this event is about + */ + public MicrophoneUnmuteEvent(Client client) { + super(client); + } +} diff --git a/api/src/main/java/com/craftmend/openaudiomc/api/events/client/SystemReloadEvent.java b/api/src/main/java/com/craftmend/openaudiomc/api/events/client/SystemReloadEvent.java new file mode 100644 index 000000000..3934393ea --- /dev/null +++ b/api/src/main/java/com/craftmend/openaudiomc/api/events/client/SystemReloadEvent.java @@ -0,0 +1,7 @@ +package com.craftmend.openaudiomc.api.events.client; + +import com.craftmend.openaudiomc.api.events.BaseEvent; + +public class SystemReloadEvent extends BaseEvent { + // no additional data, fired when the plugin is reloaded for whatever reason +} diff --git a/api/src/main/java/com/craftmend/openaudiomc/api/events/client/VoicechatDeafenEvent.java b/api/src/main/java/com/craftmend/openaudiomc/api/events/client/VoicechatDeafenEvent.java new file mode 100644 index 000000000..3f35feabd --- /dev/null +++ b/api/src/main/java/com/craftmend/openaudiomc/api/events/client/VoicechatDeafenEvent.java @@ -0,0 +1,15 @@ +package com.craftmend.openaudiomc.api.events.client; + +import com.craftmend.openaudiomc.api.clients.Client; +import com.craftmend.openaudiomc.api.events.ClientEvent; + +public class VoicechatDeafenEvent extends ClientEvent { + /** + * This is a simple event that gets called whenever a player explicitly deafens their audio + * + * @param client the client that this event is about + */ + public VoicechatDeafenEvent(Client client) { + super(client); + } +} diff --git a/api/src/main/java/com/craftmend/openaudiomc/api/events/client/VoicechatPeerTickEvent.java b/api/src/main/java/com/craftmend/openaudiomc/api/events/client/VoicechatPeerTickEvent.java new file mode 100644 index 000000000..6e9ec1324 --- /dev/null +++ b/api/src/main/java/com/craftmend/openaudiomc/api/events/client/VoicechatPeerTickEvent.java @@ -0,0 +1,9 @@ +package com.craftmend.openaudiomc.api.events.client; + +import com.craftmend.openaudiomc.api.events.BaseEvent; + +public class VoicechatPeerTickEvent extends BaseEvent { + + // An empty event that gets fired whenever the voicechat system ticked, this is useful for things like + +} diff --git a/api/src/main/java/com/craftmend/openaudiomc/api/events/client/VoicechatReadyEvent.java b/api/src/main/java/com/craftmend/openaudiomc/api/events/client/VoicechatReadyEvent.java new file mode 100644 index 000000000..92f868103 --- /dev/null +++ b/api/src/main/java/com/craftmend/openaudiomc/api/events/client/VoicechatReadyEvent.java @@ -0,0 +1,15 @@ +package com.craftmend.openaudiomc.api.events.client; + +import com.craftmend.openaudiomc.api.clients.Client; +import com.craftmend.openaudiomc.api.events.ClientEvent; + +public class VoicechatReadyEvent extends ClientEvent { + /** + * Fired whenever a client is ready to use voicechat + * + * @param client the client that this event is about + */ + public VoicechatReadyEvent(Client client) { + super(client); + } +} diff --git a/api/src/main/java/com/craftmend/openaudiomc/api/events/client/VoicechatUndeafenEvent.java b/api/src/main/java/com/craftmend/openaudiomc/api/events/client/VoicechatUndeafenEvent.java new file mode 100644 index 000000000..f652a6b14 --- /dev/null +++ b/api/src/main/java/com/craftmend/openaudiomc/api/events/client/VoicechatUndeafenEvent.java @@ -0,0 +1,15 @@ +package com.craftmend.openaudiomc.api.events.client; + +import com.craftmend.openaudiomc.api.clients.Client; +import com.craftmend.openaudiomc.api.events.ClientEvent; + +public class VoicechatUndeafenEvent extends ClientEvent { + /** + * This is a simple event that gets called whenever a player explicitly undeafens their audio + * + * @param client the client that this event is about + */ + public VoicechatUndeafenEvent(Client client) { + super(client); + } +} diff --git a/plugin/src/main/java/com/craftmend/openaudiomc/generic/networking/enums/MediaError.java b/api/src/main/java/com/craftmend/openaudiomc/api/media/MediaError.java similarity index 94% rename from plugin/src/main/java/com/craftmend/openaudiomc/generic/networking/enums/MediaError.java rename to api/src/main/java/com/craftmend/openaudiomc/api/media/MediaError.java index bd5ca3949..bb4b0a1c5 100644 --- a/plugin/src/main/java/com/craftmend/openaudiomc/generic/networking/enums/MediaError.java +++ b/api/src/main/java/com/craftmend/openaudiomc/api/media/MediaError.java @@ -1,4 +1,4 @@ -package com.craftmend.openaudiomc.generic.networking.enums; +package com.craftmend.openaudiomc.api.media; import lombok.Getter; diff --git a/modules/vistas-client/src/main/java/com/craftmend/openaudiomc/vistas/client/client/VistasRedisClient.java b/modules/vistas-client/src/main/java/com/craftmend/openaudiomc/vistas/client/client/VistasRedisClient.java index ad6ffb010..d14dae63f 100644 --- a/modules/vistas-client/src/main/java/com/craftmend/openaudiomc/vistas/client/client/VistasRedisClient.java +++ b/modules/vistas-client/src/main/java/com/craftmend/openaudiomc/vistas/client/client/VistasRedisClient.java @@ -1,9 +1,7 @@ package com.craftmend.openaudiomc.vistas.client.client; import com.craftmend.openaudiomc.OpenAudioMc; -import com.craftmend.openaudiomc.api.impl.event.events.SpigotAudioCommandEvent; -import com.craftmend.openaudiomc.api.interfaces.AudioApi; -import com.craftmend.openaudiomc.generic.logging.OpenAudioLogger; +import com.craftmend.openaudiomc.api.EventApi; import com.craftmend.openaudiomc.generic.networking.abstracts.AbstractPacketPayload; import com.craftmend.openaudiomc.generic.proxy.interfaces.UserHooks; import com.craftmend.openaudiomc.generic.service.Inject; @@ -11,6 +9,7 @@ import com.craftmend.openaudiomc.generic.storage.enums.StorageKey; import com.craftmend.openaudiomc.generic.storage.interfaces.Configuration; import com.craftmend.openaudiomc.generic.user.User; +import com.craftmend.openaudiomc.spigot.modules.events.SpigotAudioCommandEvent; import com.craftmend.openaudiomc.spigot.modules.proxy.service.ProxyNetworkingService; import com.craftmend.openaudiomc.vistas.client.redis.handlers.DefaultPacketHandler; import com.craftmend.openaudiomc.vistas.client.Vistas; @@ -40,17 +39,16 @@ public VistasRedisClient(Configuration configuration) { "deputy_to_server" ); - AudioApi.getInstance().getEventDriver().on(SpigotAudioCommandEvent.class) - .setHandler(spigotAudioCommandEvent -> { - if (spigotAudioCommandEvent.getCommandSender() instanceof Player) { - spigotAudioCommandEvent.setCanceled(true); - sendPacket(new UserExecuteAudioCommandPacket( - spigotAudioCommandEvent.getCommandSender().getName(), - ((Player) spigotAudioCommandEvent.getCommandSender()).getUniqueId(), - spigotAudioCommandEvent.getArgs() - )); - } - }); + EventApi.getInstance().registerHandler(SpigotAudioCommandEvent.class, event -> { + if (event.getSender() instanceof Player) { + event.setCancelled(true); + sendPacket(new UserExecuteAudioCommandPacket( + event.getSender().getName(), + ((Player) event.getSender()).getUniqueId(), + event.getArgs() + )); + } + }); // handle chat messages etc packetEvents.registerPacket(InvokeUserPacket.class).setHandler(invocation -> { diff --git a/modules/vistas-server/dependency-reduced-pom.xml b/modules/vistas-server/dependency-reduced-pom.xml index 3cb256284..922179d83 100644 --- a/modules/vistas-server/dependency-reduced-pom.xml +++ b/modules/vistas-server/dependency-reduced-pom.xml @@ -174,12 +174,6 @@ junit 4.13.2 test - - - hamcrest-core - org.hamcrest - - diff --git a/modules/voice-join-permission/src/main/java/com/craftmend/voicejoinpermission/OaVoicechatJoinPermission.java b/modules/voice-join-permission/src/main/java/com/craftmend/voicejoinpermission/OaVoicechatJoinPermission.java index ae59d887e..c3663c1fc 100644 --- a/modules/voice-join-permission/src/main/java/com/craftmend/voicejoinpermission/OaVoicechatJoinPermission.java +++ b/modules/voice-join-permission/src/main/java/com/craftmend/voicejoinpermission/OaVoicechatJoinPermission.java @@ -1,14 +1,10 @@ package com.craftmend.voicejoinpermission; -import com.craftmend.openaudiomc.OpenAudioMc; +import com.craftmend.openaudiomc.api.EventApi; import com.craftmend.openaudiomc.api.enums.ModuleEvent; -import com.craftmend.openaudiomc.api.impl.event.events.ClientRequestVoiceEvent; -import com.craftmend.openaudiomc.api.interfaces.AudioApi; +import com.craftmend.openaudiomc.api.events.client.ClientEnableVoiceEvent; import com.craftmend.openaudiomc.api.interfaces.ExternalModule; -import com.craftmend.openaudiomc.spigot.modules.voicechat.filters.CustomFilterFunction; -import com.craftmend.openaudiomc.spigot.modules.voicechat.filters.FilterService; import lombok.NoArgsConstructor; -import org.bukkit.entity.Player; import org.bukkit.event.Listener; @NoArgsConstructor @@ -38,16 +34,12 @@ public void on(ModuleEvent event) { private void bootComponent() { // hook into both plugins - AudioApi.getInstance().getEventDriver() - .on(ClientRequestVoiceEvent.class) - .setHandler((handler) -> { - boolean hasPermission = handler.getRequester().getUser().hasPermission("openaudiomc.voicechat.join"); - if (!hasPermission) { - handler.getRequester().getUser().sendMessage("You don't have permission to join voicechat"); - handler.setCanceled(true); - } else { - handler.setCanceled(false); - } - }); + EventApi.getInstance().registerHandler(ClientEnableVoiceEvent.class, event -> { + boolean hasPermission = event.getClient().getActor().hasPermission("openaudiomc.voicechat.join"); + if (!hasPermission) { + event.setCancelled(true); + event.getClient().getActor().sendMessage("You don't have permission to join voicechat"); + } + }); } } diff --git a/plugin/src/main/bash/data.bin b/plugin/src/main/bash/data.bin index 240378200..54e8dae8b 100755 --- a/plugin/src/main/bash/data.bin +++ b/plugin/src/main/bash/data.bin @@ -1 +1 @@ -BUILD_NUM="1118" +BUILD_NUM="1132" diff --git a/plugin/src/main/java/com/craftmend/openaudiomc/OpenAudioMc.java b/plugin/src/main/java/com/craftmend/openaudiomc/OpenAudioMc.java index 59e94bfd8..1fef033dc 100644 --- a/plugin/src/main/java/com/craftmend/openaudiomc/OpenAudioMc.java +++ b/plugin/src/main/java/com/craftmend/openaudiomc/OpenAudioMc.java @@ -11,6 +11,7 @@ import com.craftmend.openaudiomc.generic.environment.EnvironmentService; import com.craftmend.openaudiomc.generic.environment.GlobalConstantService; import com.craftmend.openaudiomc.generic.environment.MagicValue; +import com.craftmend.openaudiomc.generic.events.EventService; import com.craftmend.openaudiomc.generic.logging.OpenAudioLogger; import com.craftmend.openaudiomc.generic.media.MediaService; import com.craftmend.openaudiomc.generic.media.time.TimeService; @@ -96,8 +97,11 @@ public OpenAudioMc(OpenAudioInvoker invoker) throws Exception { instance = this; OpenAudioLogger.toConsole("Initializing build " + BUILD.getBuildNumber() + " by " + BUILD.getBuildAuthor()); - // load runtime shit - serviceManager.loadService(RuntimeDependencyService.class); + // load core internal API's which are heavily used by the rest of the plugin + serviceManager.loadServices( + RuntimeDependencyService.class, + EventService.class // platform agnostic event manager + ); // setup this.invoker = invoker; diff --git a/plugin/src/main/java/com/craftmend/openaudiomc/api/impl/DefaultApi.java b/plugin/src/main/java/com/craftmend/openaudiomc/api/impl/DefaultApi.java index f6ce3eb38..df418ffd0 100644 --- a/plugin/src/main/java/com/craftmend/openaudiomc/api/impl/DefaultApi.java +++ b/plugin/src/main/java/com/craftmend/openaudiomc/api/impl/DefaultApi.java @@ -11,6 +11,7 @@ import java.util.UUID; @NoArgsConstructor +@Deprecated public class DefaultApi implements AudioApi { private static DefaultApi instance; @@ -18,6 +19,7 @@ public class DefaultApi implements AudioApi { private final MediaApiImpl mediaApi = new MediaApiImpl(); private final RegistryApiImpl registryApi = new RegistryApiImpl(); + @Deprecated public static AudioApi i() { if (instance != null) return instance; instance = new DefaultApi(); @@ -25,36 +27,43 @@ public static AudioApi i() { } @Override + @Deprecated public Client getClient(UUID uuid) { return OpenAudioMc.getService(NetworkingService.class).getClient(uuid); } @Override + @Deprecated public boolean isClientConnected(UUID uuid) { return getClient(uuid).isConnected(); } @Override + @Deprecated public ApiEventDriver getEventDriver() { return OpenAudioMc.getInstance().getApiEventDriver(); } @Override + @Deprecated public Collection getAllClients() { return new ArrayList<>(OpenAudioMc.getService(NetworkingService.class).getClients()); } @Override + @Deprecated public WorldApi getWorldApi() { return worldApi; } @Override + @Deprecated public MediaApi getMediaApi() { return mediaApi; } @Override + @Deprecated public RegistryApi getRegistryApi() { return registryApi; } diff --git a/plugin/src/main/java/com/craftmend/openaudiomc/api/impl/MediaApiImpl.java b/plugin/src/main/java/com/craftmend/openaudiomc/api/impl/MediaApiImpl.java index f6866c362..ba7811f8a 100644 --- a/plugin/src/main/java/com/craftmend/openaudiomc/api/impl/MediaApiImpl.java +++ b/plugin/src/main/java/com/craftmend/openaudiomc/api/impl/MediaApiImpl.java @@ -19,34 +19,41 @@ import java.time.Instant; import java.util.UUID; +@Deprecated public class MediaApiImpl implements MediaApi { + @Deprecated private ClientConnection validateClient(Client client) { if (!(client instanceof ClientConnection)) throw new IllegalStateException("This player isn't a instance of ClientConnection"); return (ClientConnection) client; } @Override + @Deprecated public void playMedia(Client client, String source) { validateClient(client).sendMedia(new Media(source)); } @Override + @Deprecated public void playMedia(Client client, String source, MediaOptions mediaOptions) { validateClient(client).sendMedia(new Media(source).applySettings(mediaOptions)); } @Override + @Deprecated public void stopMedia(Client client) { OpenAudioMc.getService(NetworkingService.class).send(validateClient(client), new PacketClientDestroyMedia(null)); } @Override + @Deprecated public void stopMedia(Client client, String id) { OpenAudioMc.getService(NetworkingService.class).send(validateClient(client), new PacketClientDestroyMedia(id)); } @Override + @Deprecated public String playSpatialSound(Client client, String source, int x, int y, int z, int radius, boolean useSurroundSound, int obstructions) { ClientSpeaker clientSpeaker = new ClientSpeaker( new Vector3(x, y, z), @@ -67,6 +74,7 @@ public String playSpatialSound(Client client, String source, int x, int y, int z } @Override + @Deprecated public void stopSpatialSound(Client client, String spatialSoundId) { ClientSpeaker clientSpeaker = new ClientSpeaker( Vector3.EMPTY, diff --git a/plugin/src/main/java/com/craftmend/openaudiomc/api/impl/RegistryApiImpl.java b/plugin/src/main/java/com/craftmend/openaudiomc/api/impl/RegistryApiImpl.java index a6021a4fd..298bc559d 100644 --- a/plugin/src/main/java/com/craftmend/openaudiomc/api/impl/RegistryApiImpl.java +++ b/plugin/src/main/java/com/craftmend/openaudiomc/api/impl/RegistryApiImpl.java @@ -25,46 +25,55 @@ import lombok.Getter; import org.bukkit.entity.Player; +@Deprecated public class RegistryApiImpl implements RegistryApi { @Getter private Class forcedService; @Override + @Deprecated public void registerSubCommand(SubCommand subCommand) { OpenAudioMc.getService(CommandService.class).registerSubCommands(CommandContext.OPENAUDIOMC, subCommand); } @Override + @Deprecated public void registerMutation(String pattern, UrlMutation urlMutation) { OpenAudioMc.getService(MediaService.class).registerMutation(pattern, urlMutation); } @Override + @Deprecated public void registerAlias(String aliasName, String value) { OpenAudioMc.getService(AliasService.class).getAliasMap().put(aliasName, new Alias(aliasName, value)); } @Override + @Deprecated public void setProximityFilter(Filter filter) { OpenAudioMc.getService(SpigotVoiceChatService.class).getPeerTicker().setFilter(filter); } @Override + @Deprecated public void addProximityFilter(Filter filter) { OpenAudioMc.getService(SpigotVoiceChatService.class).getPeerTicker().addFilter(filter); } @Override + @Deprecated public void forceNetworkingInterface(Class service) { forcedService = service; } @Override + @Deprecated public void registerTokenProvider(ITokenProvider provider) { AuthenticationService.TOKEN_PROVIDER = provider; } @Override + @Deprecated public void removeRegion(String worldName, String regionName) throws RegionException { if (OpenAudioMc.getInstance().getPlatform() != Platform.SPIGOT) throw new RegionException("This API functionality is only accessible on Spigot"); OpenAudioMcSpigot openAudioMcSpigot = OpenAudioMcSpigot.getInstance(); @@ -88,6 +97,7 @@ public void removeRegion(String worldName, String regionName) throws RegionExcep } @Override + @Deprecated public void registerTempRegion(String worldName, TimedRegionProperties regionProperties) throws RegionException { if (OpenAudioMc.getInstance().getPlatform() != Platform.SPIGOT) throw new RegionException("This API functionality is only accessible on Spigot"); OpenAudioMcSpigot openAudioMcSpigot = OpenAudioMcSpigot.getInstance(); @@ -115,6 +125,7 @@ public void registerTempRegion(String worldName, TimedRegionProperties regionPro } @Override + @Deprecated public void registerRegion(String worldName, RegionProperties regionProperties) throws RegionException { if (OpenAudioMc.getInstance().getPlatform() != Platform.SPIGOT) throw new RegionException("This API functionality is only accessible on Spigot"); OpenAudioMcSpigot openAudioMcSpigot = OpenAudioMcSpigot.getInstance(); diff --git a/plugin/src/main/java/com/craftmend/openaudiomc/api/impl/WorldApiImpl.java b/plugin/src/main/java/com/craftmend/openaudiomc/api/impl/WorldApiImpl.java index a57a9cb3c..9bf792a57 100644 --- a/plugin/src/main/java/com/craftmend/openaudiomc/api/impl/WorldApiImpl.java +++ b/plugin/src/main/java/com/craftmend/openaudiomc/api/impl/WorldApiImpl.java @@ -20,15 +20,18 @@ import java.util.List; import java.util.stream.Collectors; +@Deprecated public class WorldApiImpl implements WorldApi { @Override + @Deprecated public void setRegionHandler(AbstractRegionAdapter regionHandler) { if (OpenAudioMc.getInstance().getPlatform() != Platform.SPIGOT) throw new IllegalStateException("This method is only available in a SPIGOT server."); OpenAudioMcSpigot.getInstance().setRegionModule(new RegionModule(regionHandler)); } @Override + @Deprecated public Collection getApplicableRegions(Location location) { if (OpenAudioMc.getInstance().getPlatform() != Platform.SPIGOT) throw new IllegalStateException("This method is only available in a SPIGOT server."); if (OpenAudioMcSpigot.getInstance().getRegionModule() == null ) throw new IllegalStateException("The region module is not enabled."); @@ -43,6 +46,7 @@ public Speaker getPhysicalSpeaker(Location location) { } @Override + @Deprecated public Collection getPredictedSources(Location location) { if (OpenAudioMc.getInstance().getPlatform() != Platform.SPIGOT) throw new IllegalStateException("This method is only available in a SPIGOT server."); @@ -56,6 +60,7 @@ public Collection getPredictedSources(Location location) { } @Override + @Deprecated public ConcurrentHeatMap getChunkContext(Location location) { if (OpenAudioMc.getInstance().getPlatform() != Platform.SPIGOT) throw new IllegalStateException("This method is only available in a SPIGOT server."); @@ -69,6 +74,7 @@ public ConcurrentHeatMap getChunkContext(Location location) { } @Override + @Deprecated public void setChunkContext(Location location, List.Value> context) { if (OpenAudioMc.getInstance().getPlatform() != Platform.SPIGOT) throw new IllegalStateException("This method is only available in a SPIGOT server."); @@ -80,10 +86,12 @@ public void setChunkContext(Location location, List, EventSupport> eventSupportCache = new HashMap<>(); /** @@ -33,6 +35,7 @@ public class ApiEventDriver { * expect that there'll be events registered during normal application flow, but is important * since most (if not all) events are async for networking and platform reasons. */ + @Deprecated private final HashMap, Set>> handlers = new HashMap<>(); /** @@ -42,6 +45,7 @@ public class ApiEventDriver { * @param event Event class * @return Event support type */ + @Deprecated public EventSupport getEventSupportFor(Class event) throws InstantiationException, IllegalAccessException { if (eventSupportCache.containsKey(event)) return eventSupportCache.get(event); EventSupport s = null; @@ -62,6 +66,7 @@ public EventSupport getEventSupportFor(Class event) throws * @param eventClass Specific event implementation to match * @return A collection of callable event listeners, or an empty set if there are none. */ + @Deprecated private Set> getHandlersFor(Class eventClass) { return handlers.getOrDefault(eventClass, new HashSet<>()); } @@ -73,8 +78,18 @@ private Set> getHandlersFor(Class HandlerHolder on(Class eventType) { + + // get the caller class name, method name and line number + StackTraceElement[] stacktrace = Thread.currentThread().getStackTrace(); + StackTraceElement e = stacktrace[2]; + String methodThatInvoked = e.getMethodName(); + String classThatInvoked = e.getClassName(); + int lineThatInvoked = e.getLineNumber(); + OpenAudioLogger.toConsole("Deprecated event listener registration, please use the new event system. Invoked from " + classThatInvoked + "#" + methodThatInvoked + ":" + lineThatInvoked); + // check if this event is supported here EventSupport support = getEventSupportFor(eventType); // is the plugin real? @@ -100,6 +115,7 @@ public HandlerHolder on(Class eventType) { * @param event instance to fire * @return instance that got fired, possibly mutated if the event was cancellable or had any other setters */ + @Deprecated public T fire(T event) { // get handlers Set> subscribers = getHandlersFor(event.getClass()); @@ -118,6 +134,7 @@ public T fire(T event) { return event; } + @Deprecated public boolean isSupported(EventSupport supportType, Platform platform, boolean isNode) { switch (supportType) { case UNKNOWN: @@ -142,6 +159,7 @@ public boolean isSupported(EventSupport supportType, Platform platform, boolean return false; } + @Deprecated public boolean isSupported(Class af) { try { return isSupported(getEventSupportFor(af), OpenAudioMc.getInstance().getPlatform(), OpenAudioMc.getInstance().getInvoker().isNodeServer()); diff --git a/plugin/src/main/java/com/craftmend/openaudiomc/api/impl/event/AudioEvent.java b/plugin/src/main/java/com/craftmend/openaudiomc/api/impl/event/AudioEvent.java index d47a20f1d..52c6b15a7 100644 --- a/plugin/src/main/java/com/craftmend/openaudiomc/api/impl/event/AudioEvent.java +++ b/plugin/src/main/java/com/craftmend/openaudiomc/api/impl/event/AudioEvent.java @@ -1,5 +1,6 @@ package com.craftmend.openaudiomc.api.impl.event; +@Deprecated public abstract class AudioEvent { // Extending this event requires you to add the @EventSupport class annotation diff --git a/plugin/src/main/java/com/craftmend/openaudiomc/api/impl/event/ClientEvent.java b/plugin/src/main/java/com/craftmend/openaudiomc/api/impl/event/ClientEvent.java index 237a59e32..8710e3ef7 100644 --- a/plugin/src/main/java/com/craftmend/openaudiomc/api/impl/event/ClientEvent.java +++ b/plugin/src/main/java/com/craftmend/openaudiomc/api/impl/event/ClientEvent.java @@ -2,6 +2,7 @@ import com.craftmend.openaudiomc.generic.client.objects.ClientConnection; +@Deprecated public interface ClientEvent { ClientConnection getClient(); diff --git a/plugin/src/main/java/com/craftmend/openaudiomc/api/impl/event/Handler.java b/plugin/src/main/java/com/craftmend/openaudiomc/api/impl/event/Handler.java index af1ce53a4..7ae5750ed 100644 --- a/plugin/src/main/java/com/craftmend/openaudiomc/api/impl/event/Handler.java +++ b/plugin/src/main/java/com/craftmend/openaudiomc/api/impl/event/Handler.java @@ -4,6 +4,7 @@ * Basic interface which is used to carry an event handler * @param Is the specific event that its calling, which is specified by the event driver. */ +@Deprecated public interface Handler { void onEvent(T event); diff --git a/plugin/src/main/java/com/craftmend/openaudiomc/api/impl/event/HandlerHolder.java b/plugin/src/main/java/com/craftmend/openaudiomc/api/impl/event/HandlerHolder.java index 4570fe955..5c3a95d25 100644 --- a/plugin/src/main/java/com/craftmend/openaudiomc/api/impl/event/HandlerHolder.java +++ b/plugin/src/main/java/com/craftmend/openaudiomc/api/impl/event/HandlerHolder.java @@ -3,6 +3,7 @@ import lombok.Getter; import lombok.Setter; +@Deprecated public class HandlerHolder { public HandlerHolder(T type) { diff --git a/plugin/src/main/java/com/craftmend/openaudiomc/api/impl/event/enums/EventSupport.java b/plugin/src/main/java/com/craftmend/openaudiomc/api/impl/event/enums/EventSupport.java index 2c46825b5..b580a01b3 100644 --- a/plugin/src/main/java/com/craftmend/openaudiomc/api/impl/event/enums/EventSupport.java +++ b/plugin/src/main/java/com/craftmend/openaudiomc/api/impl/event/enums/EventSupport.java @@ -2,6 +2,7 @@ import lombok.Getter; +@Deprecated public enum EventSupport { UNKNOWN("Failed to fetch event support for this event"), diff --git a/plugin/src/main/java/com/craftmend/openaudiomc/api/impl/event/enums/TickEventType.java b/plugin/src/main/java/com/craftmend/openaudiomc/api/impl/event/enums/TickEventType.java index e5e8835e2..7e9173905 100644 --- a/plugin/src/main/java/com/craftmend/openaudiomc/api/impl/event/enums/TickEventType.java +++ b/plugin/src/main/java/com/craftmend/openaudiomc/api/impl/event/enums/TickEventType.java @@ -1,5 +1,6 @@ package com.craftmend.openaudiomc.api.impl.event.enums; +@Deprecated public enum TickEventType { BEFORE_TICK, AFTER_TICK diff --git a/plugin/src/main/java/com/craftmend/openaudiomc/api/impl/event/events/AccountAddTagEvent.java b/plugin/src/main/java/com/craftmend/openaudiomc/api/impl/event/events/AccountAddTagEvent.java deleted file mode 100644 index 70a0dd564..000000000 --- a/plugin/src/main/java/com/craftmend/openaudiomc/api/impl/event/events/AccountAddTagEvent.java +++ /dev/null @@ -1,24 +0,0 @@ -package com.craftmend.openaudiomc.api.impl.event.events; - -import com.craftmend.openaudiomc.api.impl.event.AudioEvent; -import com.craftmend.openaudiomc.api.impl.event.enums.EventSupport; -import com.craftmend.openaudiomc.api.interfaces.EventSupportFlag; -import com.craftmend.openaudiomc.generic.oac.enums.CraftmendTag; -import lombok.AllArgsConstructor; -import lombok.Getter; -import lombok.NoArgsConstructor; - -/** - * This event gets called whenever a new {@link CraftmendTag} gets activated for this - * OpenAudioMc installation. CraftmendTags are flags which tell the plugin - * if it can enable specific features (like voicechat) - */ -@Getter -@NoArgsConstructor -@AllArgsConstructor -@EventSupportFlag(support = EventSupport.EVERYWHERE) -public class AccountAddTagEvent extends AudioEvent { - - private CraftmendTag addedTag; - -} diff --git a/plugin/src/main/java/com/craftmend/openaudiomc/api/impl/event/events/AccountRemoveTagEvent.java b/plugin/src/main/java/com/craftmend/openaudiomc/api/impl/event/events/AccountRemoveTagEvent.java deleted file mode 100644 index f064cbe03..000000000 --- a/plugin/src/main/java/com/craftmend/openaudiomc/api/impl/event/events/AccountRemoveTagEvent.java +++ /dev/null @@ -1,24 +0,0 @@ -package com.craftmend.openaudiomc.api.impl.event.events; - -import com.craftmend.openaudiomc.api.impl.event.AudioEvent; -import com.craftmend.openaudiomc.api.impl.event.enums.EventSupport; -import com.craftmend.openaudiomc.api.interfaces.EventSupportFlag; -import com.craftmend.openaudiomc.generic.oac.enums.CraftmendTag; -import lombok.AllArgsConstructor; -import lombok.Getter; -import lombok.NoArgsConstructor; - -/** - * This event gets called whenever a new {@link CraftmendTag} gets activated for this - * OpenAudioMc installation. CraftmendTags are flags which tell the plugin - * if it can disable specific features (like voicechat) - */ -@Getter -@NoArgsConstructor -@AllArgsConstructor -@EventSupportFlag(support = EventSupport.EVERYWHERE) -public class AccountRemoveTagEvent extends AudioEvent { - - private CraftmendTag removedTag; - -} diff --git a/plugin/src/main/java/com/craftmend/openaudiomc/api/impl/event/events/ClientConnectEvent.java b/plugin/src/main/java/com/craftmend/openaudiomc/api/impl/event/events/ClientConnectEvent.java index b0a0e3aaa..c18833eec 100644 --- a/plugin/src/main/java/com/craftmend/openaudiomc/api/impl/event/events/ClientConnectEvent.java +++ b/plugin/src/main/java/com/craftmend/openaudiomc/api/impl/event/events/ClientConnectEvent.java @@ -14,6 +14,7 @@ */ @NoArgsConstructor @EventSupportFlag(support = EventSupport.EVERYWHERE) +@Deprecated public class ClientConnectEvent extends AudioEvent implements ClientEvent { @Getter diff --git a/plugin/src/main/java/com/craftmend/openaudiomc/api/impl/event/events/ClientDisconnectEvent.java b/plugin/src/main/java/com/craftmend/openaudiomc/api/impl/event/events/ClientDisconnectEvent.java index 25a31c7a8..32bef2831 100644 --- a/plugin/src/main/java/com/craftmend/openaudiomc/api/impl/event/events/ClientDisconnectEvent.java +++ b/plugin/src/main/java/com/craftmend/openaudiomc/api/impl/event/events/ClientDisconnectEvent.java @@ -17,6 +17,7 @@ */ @NoArgsConstructor @EventSupportFlag(support = EventSupport.EVERYWHERE) +@Deprecated public class ClientDisconnectEvent extends AudioEvent implements ClientEvent { @Getter diff --git a/plugin/src/main/java/com/craftmend/openaudiomc/api/impl/event/events/ClientErrorEvent.java b/plugin/src/main/java/com/craftmend/openaudiomc/api/impl/event/events/ClientErrorEvent.java index 8a8688f2e..e4f505a1a 100644 --- a/plugin/src/main/java/com/craftmend/openaudiomc/api/impl/event/events/ClientErrorEvent.java +++ b/plugin/src/main/java/com/craftmend/openaudiomc/api/impl/event/events/ClientErrorEvent.java @@ -4,7 +4,7 @@ import com.craftmend.openaudiomc.api.impl.event.enums.EventSupport; import com.craftmend.openaudiomc.api.interfaces.EventSupportFlag; import com.craftmend.openaudiomc.generic.client.objects.ClientConnection; -import com.craftmend.openaudiomc.generic.networking.enums.MediaError; +import com.craftmend.openaudiomc.api.media.MediaError; import lombok.AllArgsConstructor; import lombok.Getter; import lombok.NoArgsConstructor; @@ -19,6 +19,7 @@ @NoArgsConstructor @AllArgsConstructor @EventSupportFlag(support = EventSupport.ONLY_PROXY_IF_AVAILABLE) +@Deprecated public class ClientErrorEvent extends AudioEvent { @Getter diff --git a/plugin/src/main/java/com/craftmend/openaudiomc/api/impl/event/events/ClientPreAuthEvent.java b/plugin/src/main/java/com/craftmend/openaudiomc/api/impl/event/events/ClientPreAuthEvent.java deleted file mode 100644 index e462b0d23..000000000 --- a/plugin/src/main/java/com/craftmend/openaudiomc/api/impl/event/events/ClientPreAuthEvent.java +++ /dev/null @@ -1,28 +0,0 @@ -package com.craftmend.openaudiomc.api.impl.event.events; - -import com.craftmend.openaudiomc.api.impl.event.AudioEvent; -import com.craftmend.openaudiomc.api.impl.event.enums.EventSupport; -import com.craftmend.openaudiomc.api.interfaces.EventSupportFlag; -import com.craftmend.openaudiomc.generic.networking.interfaces.Authenticatable; -import lombok.Getter; -import lombok.NoArgsConstructor; -import lombok.Setter; - -@NoArgsConstructor -@EventSupportFlag(support = EventSupport.ONLY_PROXY_IF_AVAILABLE) -public class ClientPreAuthEvent extends AudioEvent { - - @Setter - @Getter - private boolean canceled = false; - @Getter - private Authenticatable requester; - @Getter - private String token; - - public ClientPreAuthEvent(Authenticatable authenticatable, String token) { - this.requester = authenticatable; - this.token = token; - } - -} diff --git a/plugin/src/main/java/com/craftmend/openaudiomc/api/impl/event/events/ClientRequestVoiceEvent.java b/plugin/src/main/java/com/craftmend/openaudiomc/api/impl/event/events/ClientRequestVoiceEvent.java index b7438e330..6632f3109 100644 --- a/plugin/src/main/java/com/craftmend/openaudiomc/api/impl/event/events/ClientRequestVoiceEvent.java +++ b/plugin/src/main/java/com/craftmend/openaudiomc/api/impl/event/events/ClientRequestVoiceEvent.java @@ -15,6 +15,7 @@ */ @NoArgsConstructor @EventSupportFlag(support = EventSupport.ONLY_PROXY_IF_AVAILABLE) +@Deprecated public class ClientRequestVoiceEvent extends AudioEvent { @Setter diff --git a/plugin/src/main/java/com/craftmend/openaudiomc/api/impl/event/events/MicrophoneMuteEvent.java b/plugin/src/main/java/com/craftmend/openaudiomc/api/impl/event/events/MicrophoneMuteEvent.java index b3aab1454..dac9a2fd9 100644 --- a/plugin/src/main/java/com/craftmend/openaudiomc/api/impl/event/events/MicrophoneMuteEvent.java +++ b/plugin/src/main/java/com/craftmend/openaudiomc/api/impl/event/events/MicrophoneMuteEvent.java @@ -17,6 +17,7 @@ @NoArgsConstructor @AllArgsConstructor @EventSupportFlag(support = EventSupport.EVERYWHERE) +@Deprecated public class MicrophoneMuteEvent extends AudioEvent implements ClientEvent { private ClientConnection client; diff --git a/plugin/src/main/java/com/craftmend/openaudiomc/api/impl/event/events/MicrophoneUnmuteEvent.java b/plugin/src/main/java/com/craftmend/openaudiomc/api/impl/event/events/MicrophoneUnmuteEvent.java index e9f995911..938d2d39a 100644 --- a/plugin/src/main/java/com/craftmend/openaudiomc/api/impl/event/events/MicrophoneUnmuteEvent.java +++ b/plugin/src/main/java/com/craftmend/openaudiomc/api/impl/event/events/MicrophoneUnmuteEvent.java @@ -18,6 +18,7 @@ @NoArgsConstructor @AllArgsConstructor @EventSupportFlag(support = EventSupport.EVERYWHERE) +@Deprecated public class MicrophoneUnmuteEvent extends AudioEvent implements ClientEvent { private ClientConnection client; diff --git a/plugin/src/main/java/com/craftmend/openaudiomc/api/impl/event/events/PlayerConnectVoicechatEvent.java b/plugin/src/main/java/com/craftmend/openaudiomc/api/impl/event/events/PlayerConnectVoicechatEvent.java index b56ad603a..32baead07 100644 --- a/plugin/src/main/java/com/craftmend/openaudiomc/api/impl/event/events/PlayerConnectVoicechatEvent.java +++ b/plugin/src/main/java/com/craftmend/openaudiomc/api/impl/event/events/PlayerConnectVoicechatEvent.java @@ -13,6 +13,7 @@ @NoArgsConstructor @AllArgsConstructor @EventSupportFlag(support = EventSupport.EVERYWHERE) +@Deprecated public class PlayerConnectVoicechatEvent extends AudioEvent implements ClientEvent { private ClientConnection client; diff --git a/plugin/src/main/java/com/craftmend/openaudiomc/api/impl/event/events/PlayerEnterVoiceProximityEvent.java b/plugin/src/main/java/com/craftmend/openaudiomc/api/impl/event/events/PlayerEnterVoiceProximityEvent.java index f34e85b13..cf4cb4d34 100644 --- a/plugin/src/main/java/com/craftmend/openaudiomc/api/impl/event/events/PlayerEnterVoiceProximityEvent.java +++ b/plugin/src/main/java/com/craftmend/openaudiomc/api/impl/event/events/PlayerEnterVoiceProximityEvent.java @@ -21,6 +21,7 @@ @NoArgsConstructor @AllArgsConstructor @EventSupportFlag(support = EventSupport.SPIGOT_ONLY) +@Deprecated public class PlayerEnterVoiceProximityEvent extends AudioEvent { private ClientConnection speaker; diff --git a/plugin/src/main/java/com/craftmend/openaudiomc/api/impl/event/events/PlayerLeaveVoiceProximityEvent.java b/plugin/src/main/java/com/craftmend/openaudiomc/api/impl/event/events/PlayerLeaveVoiceProximityEvent.java index 5d55bd615..b03256311 100644 --- a/plugin/src/main/java/com/craftmend/openaudiomc/api/impl/event/events/PlayerLeaveVoiceProximityEvent.java +++ b/plugin/src/main/java/com/craftmend/openaudiomc/api/impl/event/events/PlayerLeaveVoiceProximityEvent.java @@ -21,6 +21,7 @@ @NoArgsConstructor @AllArgsConstructor @EventSupportFlag(support = EventSupport.SPIGOT_ONLY) +@Deprecated public class PlayerLeaveVoiceProximityEvent extends AudioEvent { private ClientConnection speaker; diff --git a/plugin/src/main/java/com/craftmend/openaudiomc/api/impl/event/events/SpigotAudioCommandEvent.java b/plugin/src/main/java/com/craftmend/openaudiomc/api/impl/event/events/SpigotAudioCommandEvent.java deleted file mode 100644 index c5e598d10..000000000 --- a/plugin/src/main/java/com/craftmend/openaudiomc/api/impl/event/events/SpigotAudioCommandEvent.java +++ /dev/null @@ -1,28 +0,0 @@ -package com.craftmend.openaudiomc.api.impl.event.events; - -import com.craftmend.openaudiomc.api.impl.event.AudioEvent; -import com.craftmend.openaudiomc.api.impl.event.enums.EventSupport; -import com.craftmend.openaudiomc.api.interfaces.EventSupportFlag; -import lombok.Getter; -import lombok.NoArgsConstructor; -import lombok.Setter; -import org.bukkit.command.CommandSender; - -@NoArgsConstructor -@EventSupportFlag(support = EventSupport.SPIGOT_ONLY) -public class SpigotAudioCommandEvent extends AudioEvent { - - @Setter - @Getter - private boolean canceled = false; - @Getter - private CommandSender commandSender; - @Getter - private String[] args; - - public SpigotAudioCommandEvent(CommandSender commandSender, String[] args) { - this.commandSender = commandSender; - this.args = args; - } - -} diff --git a/plugin/src/main/java/com/craftmend/openaudiomc/api/impl/event/events/StateChangeEvent.java b/plugin/src/main/java/com/craftmend/openaudiomc/api/impl/event/events/StateChangeEvent.java deleted file mode 100644 index ef8fdf035..000000000 --- a/plugin/src/main/java/com/craftmend/openaudiomc/api/impl/event/events/StateChangeEvent.java +++ /dev/null @@ -1,30 +0,0 @@ -package com.craftmend.openaudiomc.api.impl.event.events; - -import com.craftmend.openaudiomc.api.impl.event.AudioEvent; -import com.craftmend.openaudiomc.api.impl.event.enums.EventSupport; -import com.craftmend.openaudiomc.api.interfaces.EventSupportFlag; -import com.craftmend.openaudiomc.generic.state.interfaces.State; -import lombok.AllArgsConstructor; -import lombok.Getter; -import lombok.NoArgsConstructor; - -/** - * This even gets called whenever OpenAudioMc changes its internal networking state - * or runs into an error that it couldn't recover from. - * - * This provides the new and old state, and isn't necessarily the result of any user interaction. - * - * This event might come in handy on development servers or during debugging, since states - * carry small messages and state descriptors with them that can come in handy when working with - * clients. - */ -@Getter -@NoArgsConstructor -@AllArgsConstructor -@EventSupportFlag(support = EventSupport.ONLY_PROXY_IF_AVAILABLE) -public class StateChangeEvent extends AudioEvent { - - private State oldState; - private State newState; - -} diff --git a/plugin/src/main/java/com/craftmend/openaudiomc/api/impl/event/events/SystemReloadEvent.java b/plugin/src/main/java/com/craftmend/openaudiomc/api/impl/event/events/SystemReloadEvent.java index 9f6b8e1a8..597a94b53 100644 --- a/plugin/src/main/java/com/craftmend/openaudiomc/api/impl/event/events/SystemReloadEvent.java +++ b/plugin/src/main/java/com/craftmend/openaudiomc/api/impl/event/events/SystemReloadEvent.java @@ -9,6 +9,7 @@ @Getter @NoArgsConstructor @EventSupportFlag(support = EventSupport.EVERYWHERE) +@Deprecated public class SystemReloadEvent extends AudioEvent { // no additional data } diff --git a/plugin/src/main/java/com/craftmend/openaudiomc/api/impl/event/events/TimeServiceUpdateEvent.java b/plugin/src/main/java/com/craftmend/openaudiomc/api/impl/event/events/TimeServiceUpdateEvent.java index 460f29e01..b524a32b7 100644 --- a/plugin/src/main/java/com/craftmend/openaudiomc/api/impl/event/events/TimeServiceUpdateEvent.java +++ b/plugin/src/main/java/com/craftmend/openaudiomc/api/impl/event/events/TimeServiceUpdateEvent.java @@ -15,6 +15,7 @@ @NoArgsConstructor @AllArgsConstructor @EventSupportFlag(support = EventSupport.ONLY_PROXY_IF_AVAILABLE) +@Deprecated public class TimeServiceUpdateEvent extends AudioEvent { private TimeService timeService; diff --git a/plugin/src/main/java/com/craftmend/openaudiomc/api/impl/event/events/VoiceChatPeerTickEvent.java b/plugin/src/main/java/com/craftmend/openaudiomc/api/impl/event/events/VoiceChatPeerTickEvent.java index de602735b..e0d782a77 100644 --- a/plugin/src/main/java/com/craftmend/openaudiomc/api/impl/event/events/VoiceChatPeerTickEvent.java +++ b/plugin/src/main/java/com/craftmend/openaudiomc/api/impl/event/events/VoiceChatPeerTickEvent.java @@ -12,6 +12,7 @@ @NoArgsConstructor @AllArgsConstructor @EventSupportFlag(support = EventSupport.SPIGOT_ONLY) +@Deprecated public class VoiceChatPeerTickEvent extends AudioEvent { private TickEventType when; diff --git a/plugin/src/main/java/com/craftmend/openaudiomc/api/impl/event/events/VoicechatDeafenEvent.java b/plugin/src/main/java/com/craftmend/openaudiomc/api/impl/event/events/VoicechatDeafenEvent.java index 96cc40153..8a81d7317 100644 --- a/plugin/src/main/java/com/craftmend/openaudiomc/api/impl/event/events/VoicechatDeafenEvent.java +++ b/plugin/src/main/java/com/craftmend/openaudiomc/api/impl/event/events/VoicechatDeafenEvent.java @@ -17,6 +17,7 @@ @NoArgsConstructor @AllArgsConstructor @EventSupportFlag(support = EventSupport.EVERYWHERE) +@Deprecated public class VoicechatDeafenEvent extends AudioEvent implements ClientEvent { private ClientConnection client; diff --git a/plugin/src/main/java/com/craftmend/openaudiomc/api/impl/event/events/VoicechatUndeafenEvent.java b/plugin/src/main/java/com/craftmend/openaudiomc/api/impl/event/events/VoicechatUndeafenEvent.java index d4f802d9c..634077274 100644 --- a/plugin/src/main/java/com/craftmend/openaudiomc/api/impl/event/events/VoicechatUndeafenEvent.java +++ b/plugin/src/main/java/com/craftmend/openaudiomc/api/impl/event/events/VoicechatUndeafenEvent.java @@ -17,6 +17,7 @@ @NoArgsConstructor @AllArgsConstructor @EventSupportFlag(support = EventSupport.EVERYWHERE) +@Deprecated public class VoicechatUndeafenEvent extends AudioEvent implements ClientEvent { private ClientConnection client; diff --git a/plugin/src/main/java/com/craftmend/openaudiomc/api/interfaces/AudioApi.java b/plugin/src/main/java/com/craftmend/openaudiomc/api/interfaces/AudioApi.java index 82c48d151..60e939400 100644 --- a/plugin/src/main/java/com/craftmend/openaudiomc/api/interfaces/AudioApi.java +++ b/plugin/src/main/java/com/craftmend/openaudiomc/api/interfaces/AudioApi.java @@ -7,6 +7,7 @@ import java.util.Collection; import java.util.UUID; +@Deprecated public interface AudioApi { /** @@ -17,6 +18,7 @@ public interface AudioApi { * @return Client instance */ @Nullable + @Deprecated Client getClient(UUID uuid); /** @@ -28,30 +30,35 @@ public interface AudioApi { * @param uuid Player UUID to check * @return If the client is connected or not */ + @Deprecated boolean isClientConnected(UUID uuid); /** * Get the internal event driver * @return Internal event driver */ + @Deprecated ApiEventDriver getEventDriver(); /** * Fetch all clients that are currently known to the server * @return All clients */ + @Deprecated Collection getAllClients(); /** * Get the World Api (used for regions and speakers) * @return World API instance */ + @Deprecated WorldApi getWorldApi(); /** * Get the media API instance (used for media management) * @return Media API instance */ + @Deprecated MediaApi getMediaApi(); /** @@ -59,8 +66,10 @@ public interface AudioApi { * on a low level * @return Registry api instance */ + @Deprecated RegistryApi getRegistryApi(); + @Deprecated static AudioApi getInstance() { return DefaultApi.i(); } diff --git a/plugin/src/main/java/com/craftmend/openaudiomc/api/interfaces/Client.java b/plugin/src/main/java/com/craftmend/openaudiomc/api/interfaces/Client.java index c548078b1..a5eb4352c 100644 --- a/plugin/src/main/java/com/craftmend/openaudiomc/api/interfaces/Client.java +++ b/plugin/src/main/java/com/craftmend/openaudiomc/api/interfaces/Client.java @@ -9,11 +9,13 @@ public interface Client { /** * @return Whether the client is connected or not */ + @Deprecated boolean isConnected(); /** * @return Gets the basic player wrapper, wraps Bungeecord and Spigot */ + @Deprecated User getUser(); /** @@ -21,6 +23,7 @@ public interface Client { * * @param runnable Handler */ + @Deprecated void onConnect(Runnable runnable); /** @@ -28,6 +31,7 @@ public interface Client { * * @param media media to be send */ + @Deprecated void sendMedia(Media media); /** @@ -35,18 +39,21 @@ public interface Client { * * @param runnable Handler */ + @Deprecated void onDisconnect(Runnable runnable); /** * Get the client volume * return Last used client volume, or -1 if it's unknown */ + @Deprecated int getVolume(); /** * Whether the client has their microphone enabled * @return true if voice is enabled and microphone isn't muted */ + @Deprecated boolean isMicrophoneActive(); /** @@ -54,16 +61,27 @@ public interface Client { * this can be used as a safe method to mute clients for moderation or other features. * @param disabled If the mic should be disabled */ + @Deprecated void forcefullyDisableMicrophone(boolean disabled); /** * @return Whether or not the client is currently moderating */ + @Deprecated boolean isModerating(); /** * @param source The source to preload */ + @Deprecated void preloadMedia(String source); + default com.craftmend.openaudiomc.api.clients.Client toModernClient() { + if (this instanceof com.craftmend.openaudiomc.api.clients.Client) { + return (com.craftmend.openaudiomc.api.clients.Client) this; + } + throw new IllegalStateException("This client is not a modern client"); + } + + } diff --git a/plugin/src/main/java/com/craftmend/openaudiomc/api/interfaces/EventSupportFlag.java b/plugin/src/main/java/com/craftmend/openaudiomc/api/interfaces/EventSupportFlag.java index 021101d50..f980b4cec 100644 --- a/plugin/src/main/java/com/craftmend/openaudiomc/api/interfaces/EventSupportFlag.java +++ b/plugin/src/main/java/com/craftmend/openaudiomc/api/interfaces/EventSupportFlag.java @@ -9,6 +9,7 @@ @Target({ElementType.TYPE}) @Retention(RetentionPolicy.RUNTIME) +@Deprecated public @interface EventSupportFlag { EventSupport support() default EventSupport.EVERYWHERE; } diff --git a/plugin/src/main/java/com/craftmend/openaudiomc/api/interfaces/ExternalModule.java b/plugin/src/main/java/com/craftmend/openaudiomc/api/interfaces/ExternalModule.java index 07b7bf31c..c43dd57d3 100644 --- a/plugin/src/main/java/com/craftmend/openaudiomc/api/interfaces/ExternalModule.java +++ b/plugin/src/main/java/com/craftmend/openaudiomc/api/interfaces/ExternalModule.java @@ -5,6 +5,7 @@ import lombok.Getter; import lombok.Setter; +@Deprecated public abstract class ExternalModule { @Getter @Setter private ClassLoader loader; diff --git a/plugin/src/main/java/com/craftmend/openaudiomc/api/interfaces/MediaApi.java b/plugin/src/main/java/com/craftmend/openaudiomc/api/interfaces/MediaApi.java index 4ff5ea7a4..e6d888ece 100644 --- a/plugin/src/main/java/com/craftmend/openaudiomc/api/interfaces/MediaApi.java +++ b/plugin/src/main/java/com/craftmend/openaudiomc/api/interfaces/MediaApi.java @@ -2,6 +2,7 @@ import com.craftmend.openaudiomc.api.media.MediaOptions; +@Deprecated public interface MediaApi { /** diff --git a/plugin/src/main/java/com/craftmend/openaudiomc/api/interfaces/RegistryApi.java b/plugin/src/main/java/com/craftmend/openaudiomc/api/interfaces/RegistryApi.java index 0da9f8cb2..86fd97903 100644 --- a/plugin/src/main/java/com/craftmend/openaudiomc/api/interfaces/RegistryApi.java +++ b/plugin/src/main/java/com/craftmend/openaudiomc/api/interfaces/RegistryApi.java @@ -10,6 +10,7 @@ import com.craftmend.openaudiomc.spigot.modules.regions.objects.TimedRegionProperties; import org.bukkit.entity.Player; +@Deprecated public interface RegistryApi { /** diff --git a/plugin/src/main/java/com/craftmend/openaudiomc/api/interfaces/WorldApi.java b/plugin/src/main/java/com/craftmend/openaudiomc/api/interfaces/WorldApi.java index dc9482664..3a04c1827 100644 --- a/plugin/src/main/java/com/craftmend/openaudiomc/api/interfaces/WorldApi.java +++ b/plugin/src/main/java/com/craftmend/openaudiomc/api/interfaces/WorldApi.java @@ -10,6 +10,7 @@ import java.util.Collection; import java.util.List; +@Deprecated public interface WorldApi { /** diff --git a/plugin/src/main/java/com/craftmend/openaudiomc/bungee/modules/punishments/LitebansIntegration.java b/plugin/src/main/java/com/craftmend/openaudiomc/bungee/modules/punishments/LitebansIntegration.java index 45a9f53a1..1a418567c 100644 --- a/plugin/src/main/java/com/craftmend/openaudiomc/bungee/modules/punishments/LitebansIntegration.java +++ b/plugin/src/main/java/com/craftmend/openaudiomc/bungee/modules/punishments/LitebansIntegration.java @@ -1,8 +1,7 @@ package com.craftmend.openaudiomc.bungee.modules.punishments; -import com.craftmend.openaudiomc.api.impl.event.ApiEventDriver; -import com.craftmend.openaudiomc.api.impl.event.events.ClientRequestVoiceEvent; -import com.craftmend.openaudiomc.api.interfaces.AudioApi; +import com.craftmend.openaudiomc.api.EventApi; +import com.craftmend.openaudiomc.api.events.client.ClientEnableVoiceEvent; import com.craftmend.openaudiomc.bungee.modules.dependency.DependencyHandler; import com.craftmend.openaudiomc.generic.logging.OpenAudioLogger; import litebans.api.Database; @@ -14,19 +13,14 @@ public class LitebansIntegration implements DependencyHandler { public void onLoad(String pluginName, Plugin plugin) { // enable voicechat blocking for muted players - ApiEventDriver driver = AudioApi.getInstance().getEventDriver(); - if (driver.isSupported(ClientRequestVoiceEvent.class)) { - driver.on(ClientRequestVoiceEvent.class) - .setHandler(event -> { + EventApi.getInstance().registerHandler(ClientEnableVoiceEvent.class, event -> { + boolean isMuted = Database.get().isPlayerMuted(event.getClient().getActor().getUniqueId(), null); - boolean isMuted = Database.get().isPlayerMuted(event.getRequester().getOwner().getUniqueId(), null); - - if (isMuted) { - OpenAudioLogger.toConsole("Blocking voicechat for " + event.getRequester().getUser().getName() + " because they are muted on LiteBans"); - event.setCanceled(true); - } - }); - } + if (isMuted) { + OpenAudioLogger.toConsole("Blocking voicechat for " + event.getClient().getActor().getName() + " because they are muted on LiteBans"); + event.setCancelled(true); + } + }); } } diff --git a/plugin/src/main/java/com/craftmend/openaudiomc/generic/api/ApiService.java b/plugin/src/main/java/com/craftmend/openaudiomc/generic/api/ApiService.java index 9fa320bfd..e1db09f27 100644 --- a/plugin/src/main/java/com/craftmend/openaudiomc/generic/api/ApiService.java +++ b/plugin/src/main/java/com/craftmend/openaudiomc/generic/api/ApiService.java @@ -5,6 +5,7 @@ import com.craftmend.openaudiomc.generic.api.implementaions.MediaApiImpl; import com.craftmend.openaudiomc.generic.api.implementaions.VoiceApiImpl; import com.craftmend.openaudiomc.generic.api.implementaions.WorldApiImpl; +import com.craftmend.openaudiomc.generic.events.EventService; import com.craftmend.openaudiomc.generic.networking.interfaces.NetworkingService; import com.craftmend.openaudiomc.generic.service.Inject; import com.craftmend.openaudiomc.generic.service.Service; @@ -16,12 +17,10 @@ public ApiService( NetworkingService networkingService ) { // initialize api - ApiHolder.initiate( - new ClientApiImpl(networkingService), - new WorldApiImpl(), - new VoiceApiImpl(), - new MediaApiImpl() - ); + ApiHolder.initiate(new ClientApiImpl(networkingService)); + ApiHolder.initiate(new WorldApiImpl()); + ApiHolder.initiate(new VoiceApiImpl()); + ApiHolder.initiate(new MediaApiImpl()); } } diff --git a/plugin/src/main/java/com/craftmend/openaudiomc/generic/client/objects/ClientConnection.java b/plugin/src/main/java/com/craftmend/openaudiomc/generic/client/objects/ClientConnection.java index 1c69377ed..bb0500a41 100644 --- a/plugin/src/main/java/com/craftmend/openaudiomc/generic/client/objects/ClientConnection.java +++ b/plugin/src/main/java/com/craftmend/openaudiomc/generic/client/objects/ClientConnection.java @@ -1,11 +1,12 @@ package com.craftmend.openaudiomc.generic.client.objects; import com.craftmend.openaudiomc.OpenAudioMc; +import com.craftmend.openaudiomc.api.EventApi; import com.craftmend.openaudiomc.api.basic.Actor; import com.craftmend.openaudiomc.api.clients.Client; -import com.craftmend.openaudiomc.api.impl.event.events.ClientConnectEvent; -import com.craftmend.openaudiomc.api.impl.event.events.ClientDisconnectEvent; -import com.craftmend.openaudiomc.api.impl.event.events.ClientErrorEvent; +import com.craftmend.openaudiomc.api.events.client.ClientConnectEvent; +import com.craftmend.openaudiomc.api.events.client.ClientDisconnectEvent; +import com.craftmend.openaudiomc.api.events.client.MediaErrorEvent; import com.craftmend.openaudiomc.api.interfaces.AudioApi; import com.craftmend.openaudiomc.api.media.Media; import com.craftmend.openaudiomc.generic.client.ClientDataService; @@ -19,7 +20,7 @@ import com.craftmend.openaudiomc.generic.environment.MagicValue; import com.craftmend.openaudiomc.generic.media.MediaService; import com.craftmend.openaudiomc.generic.networking.abstracts.AbstractPacket; -import com.craftmend.openaudiomc.generic.networking.enums.MediaError; +import com.craftmend.openaudiomc.api.media.MediaError; import com.craftmend.openaudiomc.generic.networking.interfaces.Authenticatable; import com.craftmend.openaudiomc.generic.networking.interfaces.NetworkingService; import com.craftmend.openaudiomc.generic.networking.packets.PacketSocketKickClient; @@ -123,7 +124,7 @@ public void onConnect() { // am I a proxy thingy? then send it to my other thingy OpenAudioMc.resolveDependency(UserHooks.class).sendPacket(user, new ClientConnectedPacket(user.getUniqueId())); - AudioApi.getInstance().getEventDriver().fire(new ClientConnectEvent(this)); + EventApi.getInstance().callEvent(new ClientConnectEvent(this)); if (OpenAudioMc.getInstance().getPlatform() == Platform.SPIGOT && OpenAudioMcSpigot.getInstance().getProxyModule().getMode() == OAClientMode.NODE) return; @@ -145,7 +146,7 @@ public void onDisconnect() { // am I a proxy thingy? then send it to my other thingy OpenAudioMc.resolveDependency(UserHooks.class).sendPacket(user, new ClientDisconnectedPacket(user.getUniqueId())); - AudioApi.getInstance().getEventDriver().fire(new ClientDisconnectEvent(this)); + EventApi.getInstance().callEvent(new ClientDisconnectEvent(this)); // Don't send if i'm spigot and a node if (OpenAudioMc.getInstance().getPlatform() == Platform.SPIGOT && OpenAudioMcSpigot.getInstance().getProxyModule().getMode() == OAClientMode.NODE) @@ -248,7 +249,7 @@ public ClientAuth getAuth() { @Override public void handleError(MediaError error, String source) { - AudioApi.getInstance().getEventDriver().fire(new ClientErrorEvent(this, error, source)); + EventApi.getInstance().callEvent(new MediaErrorEvent(this, source, error)); if (this.getUser().isAdministrator() && OpenAudioMc.getInstance().getConfiguration().getBoolean(StorageKey.SETTINGS_STAFF_TIPS)) { String prefix = MagicValue.COMMAND_PREFIX.get(String.class); this.getUser().sendMessage(prefix + "Something went wrong while playing a sound for you, here's what we know:"); diff --git a/plugin/src/main/java/com/craftmend/openaudiomc/generic/client/session/RtcSessionManager.java b/plugin/src/main/java/com/craftmend/openaudiomc/generic/client/session/RtcSessionManager.java index f8a5d31db..4cfcfcc50 100644 --- a/plugin/src/main/java/com/craftmend/openaudiomc/generic/client/session/RtcSessionManager.java +++ b/plugin/src/main/java/com/craftmend/openaudiomc/generic/client/session/RtcSessionManager.java @@ -1,8 +1,8 @@ package com.craftmend.openaudiomc.generic.client.session; import com.craftmend.openaudiomc.OpenAudioMc; -import com.craftmend.openaudiomc.api.impl.event.events.*; -import com.craftmend.openaudiomc.api.interfaces.AudioApi; +import com.craftmend.openaudiomc.api.EventApi; +import com.craftmend.openaudiomc.api.events.client.*; import com.craftmend.openaudiomc.api.voice.VoicePeerOptions; import com.craftmend.openaudiomc.generic.client.enums.RtcBlockReason; import com.craftmend.openaudiomc.generic.client.enums.RtcStateFlag; @@ -98,7 +98,13 @@ public boolean requestLinkage(ClientConnection peer, boolean mutual, VoicePeerOp if (mutual && !peer.getRtcSessionManager().currentProximityPeers.contains(clientConnection.getOwner().getUniqueId())) { peer.getRtcSessionManager().getCurrentProximityPeers().add(clientConnection.getOwner().getUniqueId()); peer.getPeerQueue().addSubscribe(clientConnection, peer, options); - AudioApi.getInstance().getEventDriver().fire(new PlayerEnterVoiceProximityEvent(clientConnection, peer)); + + EventApi.getInstance().callEvent(new ClientPeerAddedEvent( + clientConnection, + peer, + options + )); + peer.getRtcSessionManager().updateLocationWatcher(); } @@ -109,7 +115,12 @@ public boolean requestLinkage(ClientConnection peer, boolean mutual, VoicePeerOp currentProximityPeers.add(peer.getOwner().getUniqueId()); clientConnection.getPeerQueue().addSubscribe(peer, clientConnection, options); - AudioApi.getInstance().getEventDriver().fire(new PlayerEnterVoiceProximityEvent(peer, clientConnection)); + + EventApi.getInstance().callEvent(new ClientPeerAddedEvent( + peer, + clientConnection, + options + )); updateLocationWatcher(); return true; @@ -150,7 +161,7 @@ public void makePeersDrop() { peer.getRtcSessionManager().updateLocationWatcher(); peer.getPeerQueue().drop(streamKey); - AudioApi.getInstance().getEventDriver().fire(new PlayerLeaveVoiceProximityEvent(clientConnection, peer)); + EventApi.getInstance().callEvent(new ClientPeerRemovedEvent(clientConnection, peer)); } } } @@ -206,9 +217,9 @@ public void setVoicechatDeafened(boolean state) { if (!this.isReady()) return; if (state) { - AudioApi.getInstance().getEventDriver().fire(new VoicechatDeafenEvent(clientConnection)); + EventApi.getInstance().callEvent(new VoicechatDeafenEvent(clientConnection)); } else { - AudioApi.getInstance().getEventDriver().fire(new VoicechatUndeafenEvent(clientConnection)); + EventApi.getInstance().callEvent(new VoicechatUndeafenEvent(clientConnection)); } } @@ -225,9 +236,9 @@ public void setMicrophoneEnabled(boolean state) { if (!this.isReady()) return; if (state) { - AudioApi.getInstance().getEventDriver().fire(new MicrophoneUnmuteEvent(clientConnection)); + EventApi.getInstance().callEvent(new MicrophoneUnmuteEvent(clientConnection)); } else { - AudioApi.getInstance().getEventDriver().fire(new MicrophoneMuteEvent(clientConnection)); + EventApi.getInstance().callEvent(new MicrophoneMuteEvent(clientConnection)); } } diff --git a/plugin/src/main/java/com/craftmend/openaudiomc/generic/commands/subcommands/ReloadSubCommand.java b/plugin/src/main/java/com/craftmend/openaudiomc/generic/commands/subcommands/ReloadSubCommand.java index 73e172dd7..bd5378ab1 100644 --- a/plugin/src/main/java/com/craftmend/openaudiomc/generic/commands/subcommands/ReloadSubCommand.java +++ b/plugin/src/main/java/com/craftmend/openaudiomc/generic/commands/subcommands/ReloadSubCommand.java @@ -1,8 +1,8 @@ package com.craftmend.openaudiomc.generic.commands.subcommands; import com.craftmend.openaudiomc.OpenAudioMc; -import com.craftmend.openaudiomc.api.impl.event.events.SystemReloadEvent; -import com.craftmend.openaudiomc.api.interfaces.AudioApi; +import com.craftmend.openaudiomc.api.EventApi; +import com.craftmend.openaudiomc.api.events.client.SystemReloadEvent; import com.craftmend.openaudiomc.generic.commands.interfaces.SubCommand; import com.craftmend.openaudiomc.generic.commands.objects.Argument; import com.craftmend.openaudiomc.generic.oac.OpenaudioAccountService; @@ -35,7 +35,7 @@ public void onExecute(User sender, String[] args) { message(sender, Platform.makeColor("RED") + "Re-activating account..."); OpenAudioMc.getService(NetworkingService.class).connectIfDown(); - AudioApi.getInstance().getEventDriver().fire(new SystemReloadEvent()); + EventApi.getInstance().callEvent(new SystemReloadEvent()); message(sender, Platform.makeColor("GREEN") + "Reloaded system! Welcome back."); } diff --git a/plugin/src/main/java/com/craftmend/openaudiomc/generic/events/EventService.java b/plugin/src/main/java/com/craftmend/openaudiomc/generic/events/EventService.java new file mode 100644 index 000000000..829f20ff6 --- /dev/null +++ b/plugin/src/main/java/com/craftmend/openaudiomc/generic/events/EventService.java @@ -0,0 +1,76 @@ +package com.craftmend.openaudiomc.generic.events; + +import com.craftmend.openaudiomc.api.ApiHolder; +import com.craftmend.openaudiomc.api.EventApi; +import com.craftmend.openaudiomc.api.events.BaseEvent; +import com.craftmend.openaudiomc.api.events.Handler; +import com.craftmend.openaudiomc.api.events.SingleHandler; +import com.craftmend.openaudiomc.generic.events.adapter.LegacyEventAdapter; +import com.craftmend.openaudiomc.generic.events.internal.EventMethod; +import com.craftmend.openaudiomc.generic.logging.OpenAudioLogger; +import com.craftmend.openaudiomc.generic.service.Service; +import lombok.SneakyThrows; + +import java.lang.reflect.Method; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +public class EventService extends Service implements EventApi { + + private final Map, List> eventHandlers = new HashMap<>(); + + public EventService() { + // register register events + ApiHolder.initiate(this); + registerHandlers(new LegacyEventAdapter()); + } + + @Override + public void registerHandlers(Object listener) { + for (Method method : listener.getClass().getMethods()) { + if (method.isAnnotationPresent(Handler.class) && method.getParameterCount() == 1) { + // get type of event + Class methodType = method.getParameterTypes()[0]; + if (!BaseEvent.class.isAssignableFrom(methodType)) { + throw new IllegalArgumentException("Event handler " + method.getName() + " in " + listener.getClass().getSimpleName() + " has an invalid parameter type (" + methodType.getName() + ")"); + } + registerHandler((Class) methodType, method, listener, true); + } + } + } + + @Override + public void unregisterHandlers(Object listener) { + for (List eventMethods : eventHandlers.values()) { + eventMethods.removeIf(eventMethod -> eventMethod.matchesHolder(listener)); + } + } + + private void registerHandler(Class eventType, Method method, Object listener, boolean enforceType) { + if (enforceType && !BaseEvent.class.isAssignableFrom(eventType)) { + throw new IllegalArgumentException("Event handler " + method.getName() + " in " + listener.getClass().getSimpleName() + " has an invalid parameter type (" + eventType.getName() + ")"); + } + eventHandlers.computeIfAbsent(eventType, k -> new ArrayList<>()).add(new EventMethod(listener, method)); + } + + @Override + public BaseEvent callEvent(BaseEvent event) { + List handlers = eventHandlers.get(event.getClass()); + if (handlers != null && !handlers.isEmpty()) { + for (EventMethod handler : handlers) { + handler.invoke(event); + } + } + return event; + } + + @Override + @SneakyThrows + public void registerHandler(Class event, SingleHandler handler) { + // get Method from handler + Method m = handler.getClass().getMethod("handle", Object.class); + registerHandler(event, m, handler, false); + } +} diff --git a/plugin/src/main/java/com/craftmend/openaudiomc/generic/events/adapter/LegacyEventAdapter.java b/plugin/src/main/java/com/craftmend/openaudiomc/generic/events/adapter/LegacyEventAdapter.java new file mode 100644 index 000000000..c1dedb404 --- /dev/null +++ b/plugin/src/main/java/com/craftmend/openaudiomc/generic/events/adapter/LegacyEventAdapter.java @@ -0,0 +1,102 @@ +package com.craftmend.openaudiomc.generic.events.adapter; + +import com.craftmend.openaudiomc.api.events.Handler; +import com.craftmend.openaudiomc.api.events.client.*; +import com.craftmend.openaudiomc.api.impl.event.ApiEventDriver; +import com.craftmend.openaudiomc.api.impl.event.enums.TickEventType; +import com.craftmend.openaudiomc.api.impl.event.events.ClientRequestVoiceEvent; +import com.craftmend.openaudiomc.api.interfaces.AudioApi; +import com.craftmend.openaudiomc.generic.client.objects.ClientConnection; +import com.craftmend.openaudiomc.generic.events.events.TimeServiceUpdateEvent; + +public class LegacyEventAdapter { + + /** + * Legacy event adapter, used to bridge the gap between the new and old event system, will be removed in the future + */ + + /** + * Legacy event driver + */ + private ApiEventDriver legacyEventDriver = AudioApi.getInstance().getEventDriver(); + + + @Handler + public void onConnect(ClientConnectEvent event) { + legacyEventDriver.fire(new com.craftmend.openaudiomc.api.impl.event.events.ClientConnectEvent(toClientConnection(event.getClient()))); + } + + @Handler + public void onDisconnect(com.craftmend.openaudiomc.api.events.client.ClientDisconnectEvent event) { + legacyEventDriver.fire(new com.craftmend.openaudiomc.api.impl.event.events.ClientDisconnectEvent(toClientConnection(event.getClient()))); + } + + @Handler + public void onMediaError(com.craftmend.openaudiomc.api.events.client.MediaErrorEvent event) { + legacyEventDriver.fire(new com.craftmend.openaudiomc.api.impl.event.events.ClientErrorEvent(toClientConnection(event.getClient()), event.getMediaError(), event.getMediaSource())); + } + + @Handler + public void onVoiceEnable(ClientEnableVoiceEvent event) { + if (event.isCancelled()) return; + ClientRequestVoiceEvent e = legacyEventDriver.fire(new com.craftmend.openaudiomc.api.impl.event.events.ClientRequestVoiceEvent(toClientConnection(event.getClient()))); + if (e.isCanceled()) event.setCancelled(true); + } + + @Handler + public void onMute(MicrophoneMuteEvent event) { + legacyEventDriver.fire(new com.craftmend.openaudiomc.api.impl.event.events.MicrophoneMuteEvent(toClientConnection(event.getClient()))); + } + + @Handler + public void onUnmute(MicrophoneUnmuteEvent event) { + legacyEventDriver.fire(new com.craftmend.openaudiomc.api.impl.event.events.MicrophoneUnmuteEvent(toClientConnection(event.getClient()))); + } + + @Handler + public void onDeafen(VoicechatDeafenEvent event) { + legacyEventDriver.fire(new com.craftmend.openaudiomc.api.impl.event.events.VoicechatDeafenEvent(toClientConnection(event.getClient()))); + } + + @Handler + public void onUndeafen(VoicechatUndeafenEvent event) { + legacyEventDriver.fire(new com.craftmend.openaudiomc.api.impl.event.events.VoicechatUndeafenEvent(toClientConnection(event.getClient()))); + } + + @Handler + public void onVoiceRead(VoicechatReadyEvent event) { + legacyEventDriver.fire(new com.craftmend.openaudiomc.api.impl.event.events.PlayerConnectVoicechatEvent(toClientConnection(event.getClient()))); + } + + @Handler + public void onPeerAdd(ClientPeerAddedEvent event) { + legacyEventDriver.fire(new com.craftmend.openaudiomc.api.impl.event.events.PlayerEnterVoiceProximityEvent(toClientConnection(event.getClient()), toClientConnection(event.getPeer()))); + } + + @Handler + public void onPeerRemove(ClientPeerRemovedEvent event) { + legacyEventDriver.fire(new com.craftmend.openaudiomc.api.impl.event.events.PlayerLeaveVoiceProximityEvent(toClientConnection(event.getClient()), toClientConnection(event.getPeer()))); + } + + @Handler + public void onReload(SystemReloadEvent event) { + legacyEventDriver.fire(new com.craftmend.openaudiomc.api.impl.event.events.SystemReloadEvent()); + } + + @Handler + public void onTimeServiceUpdate(TimeServiceUpdateEvent event) { + legacyEventDriver.fire(new com.craftmend.openaudiomc.api.impl.event.events.TimeServiceUpdateEvent(event.getTimeService())); + } + + @Handler + public void onVoicePeerTick(VoicechatPeerTickEvent event) { + legacyEventDriver.fire(new com.craftmend.openaudiomc.api.impl.event.events.VoiceChatPeerTickEvent(TickEventType.AFTER_TICK)); + } + + @Deprecated + private ClientConnection toClientConnection(com.craftmend.openaudiomc.api.clients.Client client) { + if (client == null) throw new IllegalArgumentException("Client cannot be null"); + if (client instanceof ClientConnection) return (ClientConnection) client; + throw new IllegalArgumentException("Client is not a legacy client"); + } +} diff --git a/plugin/src/main/java/com/craftmend/openaudiomc/generic/events/events/AccountAddTagEvent.java b/plugin/src/main/java/com/craftmend/openaudiomc/generic/events/events/AccountAddTagEvent.java new file mode 100644 index 000000000..cd921f494 --- /dev/null +++ b/plugin/src/main/java/com/craftmend/openaudiomc/generic/events/events/AccountAddTagEvent.java @@ -0,0 +1,14 @@ +package com.craftmend.openaudiomc.generic.events.events; + +import com.craftmend.openaudiomc.api.events.BaseEvent; +import com.craftmend.openaudiomc.generic.oac.enums.CraftmendTag; +import lombok.AllArgsConstructor; +import lombok.Data; + +@Data +@AllArgsConstructor +public class AccountAddTagEvent extends BaseEvent { + + private CraftmendTag addedTag; + +} diff --git a/plugin/src/main/java/com/craftmend/openaudiomc/generic/events/events/AccountRemoveTagEvent.java b/plugin/src/main/java/com/craftmend/openaudiomc/generic/events/events/AccountRemoveTagEvent.java new file mode 100644 index 000000000..28db9e7cb --- /dev/null +++ b/plugin/src/main/java/com/craftmend/openaudiomc/generic/events/events/AccountRemoveTagEvent.java @@ -0,0 +1,14 @@ +package com.craftmend.openaudiomc.generic.events.events; + +import com.craftmend.openaudiomc.api.events.BaseEvent; +import com.craftmend.openaudiomc.generic.oac.enums.CraftmendTag; +import lombok.AllArgsConstructor; +import lombok.Data; + +@Data +@AllArgsConstructor +public class AccountRemoveTagEvent extends BaseEvent { + + private CraftmendTag addedTag; + +} diff --git a/plugin/src/main/java/com/craftmend/openaudiomc/generic/events/events/StateChangeEvent.java b/plugin/src/main/java/com/craftmend/openaudiomc/generic/events/events/StateChangeEvent.java new file mode 100644 index 000000000..9783cdf03 --- /dev/null +++ b/plugin/src/main/java/com/craftmend/openaudiomc/generic/events/events/StateChangeEvent.java @@ -0,0 +1,15 @@ +package com.craftmend.openaudiomc.generic.events.events; + +import com.craftmend.openaudiomc.api.events.BaseEvent; +import com.craftmend.openaudiomc.generic.state.interfaces.State; +import lombok.AllArgsConstructor; +import lombok.Data; + +@Data +@AllArgsConstructor +public class StateChangeEvent extends BaseEvent { + + private State oldState; + private State newState; + +} diff --git a/plugin/src/main/java/com/craftmend/openaudiomc/generic/events/events/TimeServiceUpdateEvent.java b/plugin/src/main/java/com/craftmend/openaudiomc/generic/events/events/TimeServiceUpdateEvent.java new file mode 100644 index 000000000..084603e4f --- /dev/null +++ b/plugin/src/main/java/com/craftmend/openaudiomc/generic/events/events/TimeServiceUpdateEvent.java @@ -0,0 +1,12 @@ +package com.craftmend.openaudiomc.generic.events.events; + +import com.craftmend.openaudiomc.api.events.BaseEvent; +import com.craftmend.openaudiomc.generic.media.time.TimeService; +import lombok.AllArgsConstructor; +import lombok.Data; + +@Data +@AllArgsConstructor +public class TimeServiceUpdateEvent extends BaseEvent { + private TimeService timeService; +} diff --git a/plugin/src/main/java/com/craftmend/openaudiomc/generic/events/internal/EventMethod.java b/plugin/src/main/java/com/craftmend/openaudiomc/generic/events/internal/EventMethod.java new file mode 100644 index 000000000..0a45e6269 --- /dev/null +++ b/plugin/src/main/java/com/craftmend/openaudiomc/generic/events/internal/EventMethod.java @@ -0,0 +1,33 @@ +package com.craftmend.openaudiomc.generic.events.internal; + + +import com.craftmend.openaudiomc.generic.logging.OpenAudioLogger; +import lombok.Getter; + +import java.lang.reflect.Method; + +public class EventMethod { + + @Getter private Object holder; + private Method method; + + public EventMethod(Object holder, Method method) { + this.holder = holder; + this.method = method; + this.method.setAccessible(true); + } + + public boolean matchesHolder(Object holder) { + return this.holder.equals(holder); + } + + public void invoke(Object event) { + try { + method.invoke(holder, event); + } catch (Exception e) { + OpenAudioLogger.toConsole("Failed to invoke event handler " + method.getName() + " in " + holder.getClass().getSimpleName() + " due to " + e.getMessage()); + e.printStackTrace(); + } + } + +} diff --git a/plugin/src/main/java/com/craftmend/openaudiomc/generic/media/time/TimeService.java b/plugin/src/main/java/com/craftmend/openaudiomc/generic/media/time/TimeService.java index 1d465ba43..1b0510ee9 100644 --- a/plugin/src/main/java/com/craftmend/openaudiomc/generic/media/time/TimeService.java +++ b/plugin/src/main/java/com/craftmend/openaudiomc/generic/media/time/TimeService.java @@ -1,7 +1,7 @@ package com.craftmend.openaudiomc.generic.media.time; -import com.craftmend.openaudiomc.api.impl.event.events.TimeServiceUpdateEvent; -import com.craftmend.openaudiomc.api.interfaces.AudioApi; +import com.craftmend.openaudiomc.api.EventApi; +import com.craftmend.openaudiomc.generic.events.events.TimeServiceUpdateEvent; import com.craftmend.openaudiomc.generic.service.Service; import lombok.Getter; import lombok.NoArgsConstructor; @@ -52,7 +52,7 @@ public void pushServerUpdate(long timeStamp, long offset) { lastUpdated = Instant.now(); // push to child servers - AudioApi.getInstance().getEventDriver().fire(new TimeServiceUpdateEvent(this)); + EventApi.getInstance().callEvent(new TimeServiceUpdateEvent(this)); } @Override diff --git a/plugin/src/main/java/com/craftmend/openaudiomc/generic/networking/DefaultNetworkingService.java b/plugin/src/main/java/com/craftmend/openaudiomc/generic/networking/DefaultNetworkingService.java index 4994c82e8..316a61c61 100644 --- a/plugin/src/main/java/com/craftmend/openaudiomc/generic/networking/DefaultNetworkingService.java +++ b/plugin/src/main/java/com/craftmend/openaudiomc/generic/networking/DefaultNetworkingService.java @@ -1,9 +1,8 @@ package com.craftmend.openaudiomc.generic.networking; import com.craftmend.openaudiomc.OpenAudioMc; -import com.craftmend.openaudiomc.api.impl.event.ApiEventDriver; -import com.craftmend.openaudiomc.api.impl.event.events.ClientPreAuthEvent; -import com.craftmend.openaudiomc.api.interfaces.AudioApi; +import com.craftmend.openaudiomc.api.EventApi; +import com.craftmend.openaudiomc.api.events.client.ClientAuthenticationEvent; import com.craftmend.openaudiomc.generic.authentication.AuthenticationService; import com.craftmend.openaudiomc.generic.client.helpers.SerializableClient; import com.craftmend.openaudiomc.generic.client.objects.ClientConnection; @@ -64,23 +63,25 @@ public void onModuleLoad() { init(); // default auth check middleware - ApiEventDriver driver = AudioApi.getInstance().getEventDriver(); - if (driver.isSupported(ClientPreAuthEvent.class)) { - AudioApi.getInstance().getEventDriver() - .on(ClientPreAuthEvent.class) - .setHandler((event -> { - // cancel the request if the client is already open, don't bother checking the token - if (event.getRequester().isConnected()) { - event.setCanceled(true); - return; - } - - // cancel the login if the token is invalid - if (!event.getRequester().getAuth().isKeyCorrect(event.getToken())) { - event.setCanceled(true); - } - })); - } + EventApi.getInstance().registerHandler(ClientAuthenticationEvent.class, event -> { + // get Client from event + ClientConnection client = getClient(event.getActor().getUniqueId()); + if (client == null) { + event.setCancelled(true); + return; + } + + // check if the client is already connected + if (client.isConnected()) { + event.setCancelled(true); + return; + } + + // check if the token is correct + if (!client.getAuth().isKeyCorrect(event.getToken())) { + event.setCancelled(true); + } + }); OpenAudioMc.resolveDependency(TaskService.class).scheduleAsyncRepeatingTask(() -> { packetThroughput = 0; diff --git a/plugin/src/main/java/com/craftmend/openaudiomc/generic/networking/drivers/ClientDriver.java b/plugin/src/main/java/com/craftmend/openaudiomc/generic/networking/drivers/ClientDriver.java index db8d5f7dc..9ad03604b 100644 --- a/plugin/src/main/java/com/craftmend/openaudiomc/generic/networking/drivers/ClientDriver.java +++ b/plugin/src/main/java/com/craftmend/openaudiomc/generic/networking/drivers/ClientDriver.java @@ -1,8 +1,8 @@ package com.craftmend.openaudiomc.generic.networking.drivers; import com.craftmend.openaudiomc.OpenAudioMc; -import com.craftmend.openaudiomc.api.impl.event.events.ClientPreAuthEvent; -import com.craftmend.openaudiomc.api.interfaces.AudioApi; +import com.craftmend.openaudiomc.api.EventApi; +import com.craftmend.openaudiomc.api.events.client.ClientAuthenticationEvent; import com.craftmend.openaudiomc.generic.logging.OpenAudioLogger; import com.craftmend.openaudiomc.generic.networking.abstracts.AbstractPacket; import com.craftmend.openaudiomc.generic.client.objects.ClientConnection; @@ -34,10 +34,10 @@ public void boot(Socket socket, SocketIoConnector connector) { if (authenticatable == null) { callback.call(false); } else { - ClientPreAuthEvent checkEvent = new ClientPreAuthEvent(authenticatable, payload.getToken()); - AudioApi.getInstance().getEventDriver().fire(checkEvent); + ClientAuthenticationEvent checkEvent = new ClientAuthenticationEvent(authenticatable.getOwner(), payload.getToken()); + EventApi.getInstance().callEvent(checkEvent); - if (!checkEvent.isCanceled()) { + if (!checkEvent.isCancelled()) { // allow callback.call(true); authenticatable.onConnect(); diff --git a/plugin/src/main/java/com/craftmend/openaudiomc/generic/networking/handlers/ClientInitializedRtcHandler.java b/plugin/src/main/java/com/craftmend/openaudiomc/generic/networking/handlers/ClientInitializedRtcHandler.java index 06d18c891..a59f1046e 100644 --- a/plugin/src/main/java/com/craftmend/openaudiomc/generic/networking/handlers/ClientInitializedRtcHandler.java +++ b/plugin/src/main/java/com/craftmend/openaudiomc/generic/networking/handlers/ClientInitializedRtcHandler.java @@ -1,8 +1,8 @@ package com.craftmend.openaudiomc.generic.networking.handlers; import com.craftmend.openaudiomc.OpenAudioMc; -import com.craftmend.openaudiomc.api.impl.event.events.PlayerConnectVoicechatEvent; -import com.craftmend.openaudiomc.api.interfaces.AudioApi; +import com.craftmend.openaudiomc.api.EventApi; +import com.craftmend.openaudiomc.api.events.client.VoicechatReadyEvent; import com.craftmend.openaudiomc.generic.proxy.interfaces.UserHooks; import com.craftmend.openaudiomc.generic.user.User; import com.craftmend.openaudiomc.generic.networking.abstracts.PayloadHandler; @@ -108,7 +108,7 @@ private void handleState(ClientConnection cc, ClientOpenedRtcPayload payload) { cc.getRtcSessionManager().setMicrophoneEnabled(true); cc.getRtcSessionManager().setVoicechatDeafened(false); // send a welcome message - AudioApi.getInstance().getEventDriver().fire(new PlayerConnectVoicechatEvent(cc)); + EventApi.getInstance().callEvent(new VoicechatReadyEvent(cc)); cc.getUser().sendMessage(Platform.translateColors(StorageKey.MESSAGE_VC_SETUP.getString())); // notify the proxy, if applicable broadcastRtcUpdate(cc.getUser(), true, true, cc.getRtcSessionManager().isVoicechatDeafened(), cc.getRtcSessionManager().getStreamKey(), cc); diff --git a/plugin/src/main/java/com/craftmend/openaudiomc/generic/networking/interfaces/Authenticatable.java b/plugin/src/main/java/com/craftmend/openaudiomc/generic/networking/interfaces/Authenticatable.java index b3889dc2c..fb9969c59 100644 --- a/plugin/src/main/java/com/craftmend/openaudiomc/generic/networking/interfaces/Authenticatable.java +++ b/plugin/src/main/java/com/craftmend/openaudiomc/generic/networking/interfaces/Authenticatable.java @@ -3,7 +3,7 @@ import com.craftmend.openaudiomc.OpenAudioMc; import com.craftmend.openaudiomc.generic.client.objects.ClientConnection; import com.craftmend.openaudiomc.generic.client.session.ClientAuth; -import com.craftmend.openaudiomc.generic.networking.enums.MediaError; +import com.craftmend.openaudiomc.api.media.MediaError; import com.craftmend.openaudiomc.generic.networking.packets.PacketSocketKickClient; import com.craftmend.openaudiomc.generic.user.User; import net.md_5.bungee.api.connection.ProxiedPlayer; diff --git a/plugin/src/main/java/com/craftmend/openaudiomc/generic/networking/io/SocketIoConnector.java b/plugin/src/main/java/com/craftmend/openaudiomc/generic/networking/io/SocketIoConnector.java index cf46689e3..2c931ef47 100644 --- a/plugin/src/main/java/com/craftmend/openaudiomc/generic/networking/io/SocketIoConnector.java +++ b/plugin/src/main/java/com/craftmend/openaudiomc/generic/networking/io/SocketIoConnector.java @@ -1,11 +1,11 @@ package com.craftmend.openaudiomc.generic.networking.io; import com.craftmend.openaudiomc.OpenAudioMc; +import com.craftmend.openaudiomc.api.EventApi; import com.craftmend.openaudiomc.api.impl.event.ApiEventDriver; -import com.craftmend.openaudiomc.api.impl.event.events.StateChangeEvent; -import com.craftmend.openaudiomc.api.interfaces.AudioApi; import com.craftmend.openaudiomc.generic.authentication.AuthenticationService; import com.craftmend.openaudiomc.generic.authentication.objects.ServerKeySet; +import com.craftmend.openaudiomc.generic.events.events.StateChangeEvent; import com.craftmend.openaudiomc.generic.oac.OpenaudioAccountService; import com.craftmend.openaudiomc.generic.logging.OpenAudioLogger; import com.craftmend.openaudiomc.generic.networking.certificate.CertificateHelper; @@ -43,10 +43,12 @@ public class SocketIoConnector { private Socket socket; - @Getter private RestRequest relayLoginRequest; + @Getter + private RestRequest relayLoginRequest; private RestRequest relayLogoutRequest; private boolean registeredLogout = false; - @Getter private String lastUsedRelay = "none"; + @Getter + private String lastUsedRelay = "none"; private ServerKeySet keySet; private final SocketDriver[] drivers = new SocketDriver[]{ @@ -70,16 +72,11 @@ public void setupConnection() { relayLoginRequest.setQuery("oa-version", OpenAudioMc.BUILD.getBuildNumber() + ""); relayLogoutRequest = new RestRequest(NoResponse.class, Endpoint.RELAY_LOGOUT); - // listen for state events - ApiEventDriver driver = AudioApi.getInstance().getEventDriver(); - if (driver.isSupported(StateChangeEvent.class)) { - driver.on(StateChangeEvent.class) - .setHandler(event -> { - if (event.getOldState() instanceof ConnectedState) { - relayLogoutRequest.run(); - } - }); - } + EventApi.getInstance().registerHandler(StateChangeEvent.class, event -> { + if (event.getOldState() instanceof ConnectedState) { + relayLogoutRequest.run(); + } + }); registeredLogout = true; } diff --git a/plugin/src/main/java/com/craftmend/openaudiomc/generic/networking/payloads/in/ClientFailedMediaPayload.java b/plugin/src/main/java/com/craftmend/openaudiomc/generic/networking/payloads/in/ClientFailedMediaPayload.java index ee0fed58c..d1f5795b3 100644 --- a/plugin/src/main/java/com/craftmend/openaudiomc/generic/networking/payloads/in/ClientFailedMediaPayload.java +++ b/plugin/src/main/java/com/craftmend/openaudiomc/generic/networking/payloads/in/ClientFailedMediaPayload.java @@ -1,7 +1,7 @@ package com.craftmend.openaudiomc.generic.networking.payloads.in; import com.craftmend.openaudiomc.generic.networking.abstracts.AbstractPacketPayload; -import com.craftmend.openaudiomc.generic.networking.enums.MediaError; +import com.craftmend.openaudiomc.api.media.MediaError; import lombok.AllArgsConstructor; import lombok.Data; import lombok.NoArgsConstructor; diff --git a/plugin/src/main/java/com/craftmend/openaudiomc/generic/oac/OpenaudioAccountService.java b/plugin/src/main/java/com/craftmend/openaudiomc/generic/oac/OpenaudioAccountService.java index df9101664..26afa7601 100644 --- a/plugin/src/main/java/com/craftmend/openaudiomc/generic/oac/OpenaudioAccountService.java +++ b/plugin/src/main/java/com/craftmend/openaudiomc/generic/oac/OpenaudioAccountService.java @@ -1,10 +1,10 @@ package com.craftmend.openaudiomc.generic.oac; import com.craftmend.openaudiomc.OpenAudioMc; -import com.craftmend.openaudiomc.api.impl.event.events.AccountAddTagEvent; -import com.craftmend.openaudiomc.api.impl.event.events.AccountRemoveTagEvent; -import com.craftmend.openaudiomc.api.interfaces.AudioApi; +import com.craftmend.openaudiomc.api.EventApi; import com.craftmend.openaudiomc.generic.authentication.AuthenticationService; +import com.craftmend.openaudiomc.generic.events.events.AccountAddTagEvent; +import com.craftmend.openaudiomc.generic.events.events.AccountRemoveTagEvent; import com.craftmend.openaudiomc.generic.oac.enums.AccountState; import com.craftmend.openaudiomc.generic.oac.enums.CraftmendTag; import com.craftmend.openaudiomc.generic.oac.response.OpenaudioSettingsResponse; @@ -123,7 +123,7 @@ public void syncAccount() { } for (CraftmendTag tag : tags) { - AudioApi.getInstance().getEventDriver().fire(new AccountRemoveTagEvent(tag)); + EventApi.getInstance().callEvent(new AccountRemoveTagEvent(tag)); } tags.clear(); @@ -150,12 +150,12 @@ public boolean is(CraftmendTag tag) { public void addTag(CraftmendTag tag) { tags.add(tag); - AudioApi.getInstance().getEventDriver().fire(new AccountAddTagEvent(tag)); + EventApi.getInstance().callEvent(new AccountAddTagEvent(tag)); } private void removeTag(CraftmendTag tag) { tags.remove(tag); - AudioApi.getInstance().getEventDriver().fire(new AccountRemoveTagEvent(tag)); + EventApi.getInstance().callEvent(new AccountRemoveTagEvent(tag)); } public void startVoiceHandshake() { diff --git a/plugin/src/main/java/com/craftmend/openaudiomc/generic/proxy/ProxyHostService.java b/plugin/src/main/java/com/craftmend/openaudiomc/generic/proxy/ProxyHostService.java index 24bf97a52..b54831ca2 100644 --- a/plugin/src/main/java/com/craftmend/openaudiomc/generic/proxy/ProxyHostService.java +++ b/plugin/src/main/java/com/craftmend/openaudiomc/generic/proxy/ProxyHostService.java @@ -1,10 +1,9 @@ package com.craftmend.openaudiomc.generic.proxy; import com.craftmend.openaudiomc.OpenAudioMc; -import com.craftmend.openaudiomc.api.impl.event.ApiEventDriver; -import com.craftmend.openaudiomc.api.impl.event.events.TimeServiceUpdateEvent; -import com.craftmend.openaudiomc.api.interfaces.AudioApi; +import com.craftmend.openaudiomc.api.EventApi; import com.craftmend.openaudiomc.generic.client.objects.ClientConnection; +import com.craftmend.openaudiomc.generic.events.events.TimeServiceUpdateEvent; import com.craftmend.openaudiomc.generic.oac.OpenaudioAccountService; import com.craftmend.openaudiomc.generic.oac.enums.CraftmendTag; import com.craftmend.openaudiomc.generic.networking.interfaces.NetworkingService; @@ -32,15 +31,11 @@ public class ProxyHostService extends Service { public ProxyHostService(UserHooks adapter) { // syncronize task updates this.userHooks = adapter; - ApiEventDriver driver = AudioApi.getInstance().getEventDriver(); - if (driver.isSupported(TimeServiceUpdateEvent.class)) { - driver.on(TimeServiceUpdateEvent.class) - .setHandler(service -> { - for (ProxyNode node : adapter.getNodes()) { - node.sendPacket(new ServerUpdateTimePacket(service.getTimeService())); - } - }); - } + EventApi.getInstance().registerHandler(TimeServiceUpdateEvent.class, event -> { + for (ProxyNode node : adapter.getNodes()) { + node.sendPacket(new ServerUpdateTimePacket(event.getTimeService())); + } + }); } public void onServerSwitch(User user, ProxyNode from, ProxyNode to) { diff --git a/plugin/src/main/java/com/craftmend/openaudiomc/generic/state/StateService.java b/plugin/src/main/java/com/craftmend/openaudiomc/generic/state/StateService.java index e09c16962..2f31861a7 100644 --- a/plugin/src/main/java/com/craftmend/openaudiomc/generic/state/StateService.java +++ b/plugin/src/main/java/com/craftmend/openaudiomc/generic/state/StateService.java @@ -1,8 +1,8 @@ package com.craftmend.openaudiomc.generic.state; import com.craftmend.openaudiomc.OpenAudioMc; -import com.craftmend.openaudiomc.api.impl.event.events.StateChangeEvent; -import com.craftmend.openaudiomc.api.interfaces.AudioApi; +import com.craftmend.openaudiomc.api.EventApi; +import com.craftmend.openaudiomc.generic.events.events.StateChangeEvent; import com.craftmend.openaudiomc.generic.logging.OpenAudioLogger; import com.craftmend.openaudiomc.generic.platform.Platform; import com.craftmend.openaudiomc.generic.service.Service; @@ -54,7 +54,7 @@ public void registerDetail(StateDetail detail) { } public void setState(State state) { - AudioApi.getInstance().getEventDriver().fire(new StateChangeEvent(currentState, state)); + EventApi.getInstance().callEvent(new StateChangeEvent(currentState, state)); if (StorageKey.DEBUG_LOG_STATE_CHANGES.getBoolean()) { OpenAudioLogger.toConsole("Updating state to: " + state.getClass().getSimpleName() + " - " + state.getDescription()); diff --git a/plugin/src/main/java/com/craftmend/openaudiomc/generic/voicechat/bus/VoiceApiConnection.java b/plugin/src/main/java/com/craftmend/openaudiomc/generic/voicechat/bus/VoiceApiConnection.java index d82c3bf05..b3bf1f31a 100644 --- a/plugin/src/main/java/com/craftmend/openaudiomc/generic/voicechat/bus/VoiceApiConnection.java +++ b/plugin/src/main/java/com/craftmend/openaudiomc/generic/voicechat/bus/VoiceApiConnection.java @@ -1,7 +1,8 @@ package com.craftmend.openaudiomc.generic.voicechat.bus; import com.craftmend.openaudiomc.OpenAudioMc; -import com.craftmend.openaudiomc.api.impl.event.events.ClientRequestVoiceEvent; +import com.craftmend.openaudiomc.api.EventApi; +import com.craftmend.openaudiomc.api.events.client.ClientEnableVoiceEvent; import com.craftmend.openaudiomc.generic.environment.MagicValue; import com.craftmend.openaudiomc.generic.logging.OpenAudioLogger; import com.craftmend.openaudiomc.generic.networking.DefaultNetworkingService; @@ -81,8 +82,8 @@ public VoiceApiConnection() { } // make an event, and invite the client if it isn't cancelled - ClientRequestVoiceEvent event = OpenAudioMc.getInstance().getApiEventDriver().fire(new ClientRequestVoiceEvent(clientConnection)); - if (!event.isCanceled()) { + ClientEnableVoiceEvent event = (ClientEnableVoiceEvent) EventApi.getInstance().callEvent(new ClientEnableVoiceEvent(clientConnection)); + if (!event.isCancelled()) { clientConnection.sendPacket(new PacketClientUnlockVoiceChat(new ClientVoiceChatUnlockPayload( clientConnection.getRtcSessionManager().getStreamKey(), this.host, diff --git a/plugin/src/main/java/com/craftmend/openaudiomc/spigot/modules/commands/command/SpigotAudioCommand.java b/plugin/src/main/java/com/craftmend/openaudiomc/spigot/modules/commands/command/SpigotAudioCommand.java index 4686d8c04..ff254c87b 100644 --- a/plugin/src/main/java/com/craftmend/openaudiomc/spigot/modules/commands/command/SpigotAudioCommand.java +++ b/plugin/src/main/java/com/craftmend/openaudiomc/spigot/modules/commands/command/SpigotAudioCommand.java @@ -1,9 +1,8 @@ package com.craftmend.openaudiomc.spigot.modules.commands.command; import com.craftmend.openaudiomc.OpenAudioMc; +import com.craftmend.openaudiomc.api.EventApi; import com.craftmend.openaudiomc.api.clients.Client; -import com.craftmend.openaudiomc.api.impl.event.events.SpigotAudioCommandEvent; -import com.craftmend.openaudiomc.api.interfaces.AudioApi; import com.craftmend.openaudiomc.generic.client.objects.ClientConnection; import com.craftmend.openaudiomc.generic.commands.helpers.CommandMiddewareExecutor; import com.craftmend.openaudiomc.generic.commands.interfaces.CommandMiddleware; @@ -20,6 +19,7 @@ import com.craftmend.openaudiomc.generic.state.states.WorkerState; import com.craftmend.openaudiomc.generic.user.User; import com.craftmend.openaudiomc.generic.user.adapters.SpigotUserAdapter; +import com.craftmend.openaudiomc.spigot.modules.events.SpigotAudioCommandEvent; import com.craftmend.openaudiomc.spigot.modules.players.objects.SpigotPlayerSelector; import lombok.NoArgsConstructor; @@ -43,8 +43,8 @@ public class SpigotAudioCommand implements CommandExecutor { @Override public boolean onCommand(CommandSender commandSender, Command command, String s, String[] args) { - SpigotAudioCommandEvent event = AudioApi.getInstance().getEventDriver().fire(new SpigotAudioCommandEvent(commandSender, args)); - if (event.isCanceled()) { + SpigotAudioCommandEvent event = (SpigotAudioCommandEvent) EventApi.getInstance().callEvent(new SpigotAudioCommandEvent(commandSender, args)); + if (event.isCancelled()) { return true; } diff --git a/plugin/src/main/java/com/craftmend/openaudiomc/spigot/modules/events/SpigotAudioCommandEvent.java b/plugin/src/main/java/com/craftmend/openaudiomc/spigot/modules/events/SpigotAudioCommandEvent.java new file mode 100644 index 000000000..5b1434a5d --- /dev/null +++ b/plugin/src/main/java/com/craftmend/openaudiomc/spigot/modules/events/SpigotAudioCommandEvent.java @@ -0,0 +1,13 @@ +package com.craftmend.openaudiomc.spigot.modules.events; + +import com.craftmend.openaudiomc.api.events.CancellableEvent; +import lombok.AllArgsConstructor; +import lombok.Data; +import org.bukkit.command.CommandSender; + +@Data +@AllArgsConstructor +public class SpigotAudioCommandEvent extends CancellableEvent { + private CommandSender sender; + private String[] args; +} diff --git a/plugin/src/main/java/com/craftmend/openaudiomc/spigot/modules/proxy/listeners/BukkitPacketListener.java b/plugin/src/main/java/com/craftmend/openaudiomc/spigot/modules/proxy/listeners/BukkitPacketListener.java index 73bb1142a..e13c1b76e 100644 --- a/plugin/src/main/java/com/craftmend/openaudiomc/spigot/modules/proxy/listeners/BukkitPacketListener.java +++ b/plugin/src/main/java/com/craftmend/openaudiomc/spigot/modules/proxy/listeners/BukkitPacketListener.java @@ -1,13 +1,13 @@ package com.craftmend.openaudiomc.spigot.modules.proxy.listeners; import com.craftmend.openaudiomc.OpenAudioMc; -import com.craftmend.openaudiomc.api.impl.event.events.TimeServiceUpdateEvent; -import com.craftmend.openaudiomc.api.interfaces.AudioApi; +import com.craftmend.openaudiomc.api.EventApi; import com.craftmend.openaudiomc.generic.authentication.AuthenticationService; import com.craftmend.openaudiomc.generic.authentication.objects.Key; import com.craftmend.openaudiomc.generic.commands.CommandService; import com.craftmend.openaudiomc.generic.commands.enums.CommandContext; import com.craftmend.openaudiomc.generic.commands.objects.CommandError; +import com.craftmend.openaudiomc.generic.events.events.TimeServiceUpdateEvent; import com.craftmend.openaudiomc.generic.oac.OpenaudioAccountService; import com.craftmend.openaudiomc.generic.oac.enums.CraftmendTag; import com.craftmend.openaudiomc.generic.environment.MagicValue; @@ -50,7 +50,7 @@ public void onDisconnect(User user, ClientDisconnectedPacket packet) { @ProxyPacketHandler public void onTimeUpdate(User user, ServerUpdateTimePacket packet) { OpenAudioMc.getInstance().getServiceManager().replaceService(TimeService.class, packet.getTimeService()); - AudioApi.getInstance().getEventDriver().fire(new TimeServiceUpdateEvent(packet.getTimeService())); + EventApi.getInstance().callEvent(new TimeServiceUpdateEvent(packet.getTimeService())); } @ProxyPacketHandler diff --git a/plugin/src/main/java/com/craftmend/openaudiomc/spigot/modules/punishments/EssentialsIntegration.java b/plugin/src/main/java/com/craftmend/openaudiomc/spigot/modules/punishments/EssentialsIntegration.java index 4d9012aaf..71a16d209 100644 --- a/plugin/src/main/java/com/craftmend/openaudiomc/spigot/modules/punishments/EssentialsIntegration.java +++ b/plugin/src/main/java/com/craftmend/openaudiomc/spigot/modules/punishments/EssentialsIntegration.java @@ -1,8 +1,7 @@ package com.craftmend.openaudiomc.spigot.modules.punishments; -import com.craftmend.openaudiomc.api.impl.event.ApiEventDriver; -import com.craftmend.openaudiomc.api.impl.event.events.ClientRequestVoiceEvent; -import com.craftmend.openaudiomc.api.interfaces.AudioApi; +import com.craftmend.openaudiomc.api.EventApi; +import com.craftmend.openaudiomc.api.events.client.ClientEnableVoiceEvent; import com.craftmend.openaudiomc.generic.logging.OpenAudioLogger; import com.craftmend.openaudiomc.spigot.services.dependency.DependencyHandler; import com.earth2me.essentials.Essentials; @@ -15,22 +14,14 @@ public class EssentialsIntegration implements DependencyHandler { @Override public void onLoad(String pluginName, Plugin plugin) { // enable voicechat blocking for muted players with Essentials :D - ApiEventDriver driver = AudioApi.getInstance().getEventDriver(); - Essentials ess = (Essentials) Bukkit.getServer().getPluginManager().getPlugin("Essentials"); - if (driver.isSupported(ClientRequestVoiceEvent.class)) { - driver.on(ClientRequestVoiceEvent.class) - .setHandler(event -> { - - User usr = ess.getUser(event.getRequester().getOwner().getUniqueId()); - if (usr == null) return; - boolean isMuted = usr.isMuted(); - - if (isMuted) { - OpenAudioLogger.toConsole("Blocking voicechat for " + event.getRequester().getUser().getName() + " because they are muted on Essentials"); - event.setCanceled(true); - } - }); - } + EventApi.getInstance().registerHandler(ClientEnableVoiceEvent.class, event -> { + User user = ((Essentials) Bukkit.getServer().getPluginManager().getPlugin("Essentials")).getUser(event.getClient().getActor().getUniqueId()); + if (user == null) return; + if (user.isMuted()) { + OpenAudioLogger.toConsole("Blocking voicechat for " + event.getClient().getActor().getName() + " because they are muted on Essentials"); + event.setCancelled(true); + } + }); } diff --git a/plugin/src/main/java/com/craftmend/openaudiomc/spigot/modules/punishments/LitebansIntegration.java b/plugin/src/main/java/com/craftmend/openaudiomc/spigot/modules/punishments/LitebansIntegration.java index 2ac235726..75d70bb2b 100644 --- a/plugin/src/main/java/com/craftmend/openaudiomc/spigot/modules/punishments/LitebansIntegration.java +++ b/plugin/src/main/java/com/craftmend/openaudiomc/spigot/modules/punishments/LitebansIntegration.java @@ -1,8 +1,7 @@ package com.craftmend.openaudiomc.spigot.modules.punishments; -import com.craftmend.openaudiomc.api.impl.event.ApiEventDriver; -import com.craftmend.openaudiomc.api.impl.event.events.ClientRequestVoiceEvent; -import com.craftmend.openaudiomc.api.interfaces.AudioApi; +import com.craftmend.openaudiomc.api.EventApi; +import com.craftmend.openaudiomc.api.events.client.ClientEnableVoiceEvent; import com.craftmend.openaudiomc.generic.logging.OpenAudioLogger; import com.craftmend.openaudiomc.spigot.services.dependency.DependencyHandler; import litebans.api.Database; @@ -13,19 +12,13 @@ public class LitebansIntegration implements DependencyHandler { @Override public void onLoad(String pluginName, Plugin plugin) { // enable voicechat blocking for muted players - ApiEventDriver driver = AudioApi.getInstance().getEventDriver(); - if (driver.isSupported(ClientRequestVoiceEvent.class)) { - driver.on(ClientRequestVoiceEvent.class) - .setHandler(event -> { - - boolean isMuted = Database.get().isPlayerMuted(event.getRequester().getOwner().getUniqueId(), null); - - if (isMuted) { - OpenAudioLogger.toConsole("Blocking voicechat for " + event.getRequester().getUser().getName() + " because they are muted on LiteBans"); - event.setCanceled(true); - } - }); - } + EventApi.getInstance().registerHandler(ClientEnableVoiceEvent.class, event -> { + boolean isMuted = Database.get().isPlayerMuted(event.getClient().getActor().getUniqueId(), null); + if (isMuted) { + OpenAudioLogger.toConsole("Blocking voicechat for " + event.getClient().getActor().getName() + " because they are muted on LiteBans"); + event.setCancelled(true); + } + }); } diff --git a/plugin/src/main/java/com/craftmend/openaudiomc/spigot/modules/voicechat/SpigotVoiceChatService.java b/plugin/src/main/java/com/craftmend/openaudiomc/spigot/modules/voicechat/SpigotVoiceChatService.java index 77e7ebd5d..4a2e0c352 100644 --- a/plugin/src/main/java/com/craftmend/openaudiomc/spigot/modules/voicechat/SpigotVoiceChatService.java +++ b/plugin/src/main/java/com/craftmend/openaudiomc/spigot/modules/voicechat/SpigotVoiceChatService.java @@ -1,12 +1,14 @@ package com.craftmend.openaudiomc.spigot.modules.voicechat; import com.craftmend.openaudiomc.OpenAudioMc; -import com.craftmend.openaudiomc.api.impl.event.ApiEventDriver; +import com.craftmend.openaudiomc.api.EventApi; +import com.craftmend.openaudiomc.api.basic.Actor; +import com.craftmend.openaudiomc.api.events.client.*; import com.craftmend.openaudiomc.api.impl.event.enums.TickEventType; -import com.craftmend.openaudiomc.api.impl.event.events.*; import com.craftmend.openaudiomc.api.interfaces.AudioApi; import com.craftmend.openaudiomc.generic.client.objects.ClientConnection; import com.craftmend.openaudiomc.generic.client.session.RtcSessionManager; +import com.craftmend.openaudiomc.generic.events.events.AccountAddTagEvent; import com.craftmend.openaudiomc.generic.logging.OpenAudioLogger; import com.craftmend.openaudiomc.generic.networking.interfaces.NetworkingService; import com.craftmend.openaudiomc.generic.platform.Platform; @@ -45,7 +47,7 @@ public class SpigotVoiceChatService extends Service { @Override public void onEnable() { - ApiEventDriver eventDriver = AudioApi.getInstance().getEventDriver(); + EventApi eventApi = EventApi.getInstance(); if (StorageKey.SETTINGS_VOICECHAT_VICINITY_REMINDER_ENABLED.getBoolean()) { taskService.scheduleAsyncRepeatingTask( @@ -56,47 +58,50 @@ public void onEnable() { } // enable voice chat when the tag gets added - eventDriver.on(AccountAddTagEvent.class) - .setHandler(handler -> { - if (firstRun) { - int maxDistance = StorageKey.SETTINGS_VC_RADIUS.getInt(); - - // tick every second - peerTicker = new PlayerPeerTicker(maxDistance, new PeerFilter()); - taskService.scheduleAsyncRepeatingTask(peerTicker, 20, 20); - taskService.scheduleAsyncRepeatingTask(new TickVoicePacketQueue(), 3, 3); - } - firstRun = false; - }); + eventApi.registerHandler(AccountAddTagEvent.class, handler -> { + if (firstRun) { + int maxDistance = StorageKey.SETTINGS_VC_RADIUS.getInt(); + + // tick every second + peerTicker = new PlayerPeerTicker(maxDistance, new PeerFilter()); + taskService.scheduleAsyncRepeatingTask(peerTicker, 20, 20); + taskService.scheduleAsyncRepeatingTask(new TickVoicePacketQueue(), 3, 3); + } + firstRun = false; + }); - // register events to notify players when player enter, leave, and whatever - eventDriver.on(PlayerEnterVoiceProximityEvent.class).setHandler(event -> { + eventApi.registerHandler(ClientPeerAddedEvent.class, event -> { // skip if this is disabled in the settings + if (!event.getOptions().isSpatialAudio()) return; // exclude non-spatial audio clients if (!StorageKey.SETTINGS_VC_ANNOUNCEMENTS.getBoolean()) return; - if (event.getListener().isModerating() && !event.getSpeaker().isModerating()) { + if (event.getClient().isModerating() && !event.getPeer().isModerating()) { return; } - event.getSpeaker().getRtcSessionManager().getCurrentProximityAdditions().add(event.getListener().getOwner().getUniqueId()); - event.getSpeaker().getRtcSessionManager().getCurrentProximityDrops().remove(event.getListener().getOwner().getUniqueId()); + ClientConnection listener = (ClientConnection) event.getClient(); + + listener.getRtcSessionManager().getCurrentProximityAdditions().add(event.getPeer().getActor().getUniqueId()); + listener.getRtcSessionManager().getCurrentProximityDrops().remove(event.getPeer().getActor().getUniqueId()); }); - eventDriver.on(PlayerLeaveVoiceProximityEvent.class).setHandler(event -> { + eventApi.registerHandler(ClientPeerRemovedEvent.class, event -> { // skip if this is disabled in the settings if (!StorageKey.SETTINGS_VC_ANNOUNCEMENTS.getBoolean()) return; - if (event.getListener().isModerating() && !event.getSpeaker().isModerating()) { + if (event.getClient().isModerating() && !event.getPeer().isModerating()) { return; } - event.getSpeaker().getRtcSessionManager().getCurrentProximityDrops().add(event.getListener().getOwner().getUniqueId()); - event.getSpeaker().getRtcSessionManager().getCurrentProximityAdditions().remove(event.getListener().getOwner().getUniqueId()); + ClientConnection peer = (ClientConnection) event.getPeer(); + ClientConnection listener = (ClientConnection) event.getClient(); + + listener.getRtcSessionManager().getCurrentProximityAdditions().remove(event.getPeer().getActor().getUniqueId()); + listener.getRtcSessionManager().getCurrentProximityDrops().add(event.getPeer().getActor().getUniqueId()); }); // do vc tick loop - eventDriver.on(VoiceChatPeerTickEvent.class).setHandler(event -> { - if (event.getWhen() == TickEventType.BEFORE_TICK) return; + eventApi.registerHandler(VoicechatPeerTickEvent.class, handler -> { if (broadcastTickLoop > 2) { broadcastTickLoop = 0; return; @@ -156,25 +161,24 @@ public void onEnable() { }); // mute messages - eventDriver.on(MicrophoneMuteEvent.class).setHandler(event -> { + eventApi.registerHandler(MicrophoneMuteEvent.class, event -> { if (!event.getClient().isConnected()) return; - sendMessage(event.getClient().getUser(), Platform.translateColors(StorageKey.MESSAGE_VC_MIC_MUTE.getString())); + sendMessage(event.getClient().getActor(), Platform.translateColors(StorageKey.MESSAGE_VC_MIC_MUTE.getString())); }); - eventDriver.on(MicrophoneUnmuteEvent.class).setHandler(event -> { + eventApi.registerHandler(MicrophoneUnmuteEvent.class, event -> { if (!event.getClient().isConnected()) return; - sendMessage(event.getClient().getUser(), Platform.translateColors(StorageKey.MESSAGE_VC_MIC_UNMUTE.getString())); + sendMessage(event.getClient().getActor(), Platform.translateColors(StorageKey.MESSAGE_VC_MIC_UNMUTE.getString())); }); - // deafen messages - eventDriver.on(VoicechatDeafenEvent.class).setHandler(event -> { + eventApi.registerHandler(VoicechatDeafenEvent.class, event -> { if (!event.getClient().isConnected()) return; - sendMessage(event.getClient().getUser(), Platform.translateColors(StorageKey.MESSAGE_VC_DEAFEN.getString())); + sendMessage(event.getClient().getActor(), Platform.translateColors(StorageKey.MESSAGE_VC_DEAFEN.getString())); }); - eventDriver.on(VoicechatUndeafenEvent.class).setHandler(event -> { + eventApi.registerHandler(VoicechatUndeafenEvent.class, event -> { if (!event.getClient().isConnected()) return; - sendMessage(event.getClient().getUser(), Platform.translateColors(StorageKey.MESSAGE_VC_UNDEAFEN.getString())); + sendMessage(event.getClient().getActor(), Platform.translateColors(StorageKey.MESSAGE_VC_UNDEAFEN.getString())); }); // enable default rules @@ -189,10 +193,11 @@ public void onEnable() { } } - private void sendMessage(User player, String message) { + private void sendMessage(Actor player, String message) { if (StorageKey.SETTINGS_VC_USE_HOTBAR.getBoolean()) { // use hotbar - player.sendActionbarMessage(message); + User user = (User) player; + user.sendActionbarMessage(message); } else { // normal player.sendMessage(message); diff --git a/plugin/src/main/java/com/craftmend/openaudiomc/spigot/modules/voicechat/VoiceChannelService.java b/plugin/src/main/java/com/craftmend/openaudiomc/spigot/modules/voicechat/VoiceChannelService.java index 4756c636a..f9246751c 100644 --- a/plugin/src/main/java/com/craftmend/openaudiomc/spigot/modules/voicechat/VoiceChannelService.java +++ b/plugin/src/main/java/com/craftmend/openaudiomc/spigot/modules/voicechat/VoiceChannelService.java @@ -1,7 +1,8 @@ package com.craftmend.openaudiomc.spigot.modules.voicechat; -import com.craftmend.openaudiomc.api.impl.event.events.ClientDisconnectEvent; -import com.craftmend.openaudiomc.api.interfaces.AudioApi; +import com.craftmend.openaudiomc.api.EventApi; +import com.craftmend.openaudiomc.api.events.client.ClientDisconnectEvent; +import com.craftmend.openaudiomc.generic.client.objects.ClientConnection; import com.craftmend.openaudiomc.generic.commands.CommandService; import com.craftmend.openaudiomc.generic.commands.enums.CommandContext; import com.craftmend.openaudiomc.generic.commands.subcommands.HelpSubCommand; @@ -33,13 +34,13 @@ public VoiceChannelService( new ChannelSubCommand() ); - AudioApi.getInstance().getEventDriver() - .on(ClientDisconnectEvent.class) - .setHandler(event -> { - if (event.getClient().getRtcSessionManager().getCurrentChannel() != null) { - event.getClient().getRtcSessionManager().getCurrentChannel().removeMember(event.getClient().getUser()); - } - }); + // register events + EventApi.getInstance().registerHandler(ClientDisconnectEvent.class, event -> { + ClientConnection client = (ClientConnection) event.getClient(); + if (client.getRtcSessionManager().getCurrentChannel() != null) { + client.getRtcSessionManager().getCurrentChannel().removeMember(client.getUser()); + } + }); } public boolean createChannel(String name, User creator) { diff --git a/plugin/src/main/java/com/craftmend/openaudiomc/spigot/modules/voicechat/tasks/PlayerPeerTicker.java b/plugin/src/main/java/com/craftmend/openaudiomc/spigot/modules/voicechat/tasks/PlayerPeerTicker.java index db70afa00..c0eb5acba 100644 --- a/plugin/src/main/java/com/craftmend/openaudiomc/spigot/modules/voicechat/tasks/PlayerPeerTicker.java +++ b/plugin/src/main/java/com/craftmend/openaudiomc/spigot/modules/voicechat/tasks/PlayerPeerTicker.java @@ -1,11 +1,10 @@ package com.craftmend.openaudiomc.spigot.modules.voicechat.tasks; import com.craftmend.openaudiomc.OpenAudioMc; -import com.craftmend.openaudiomc.api.impl.event.enums.TickEventType; -import com.craftmend.openaudiomc.api.impl.event.events.PlayerLeaveVoiceProximityEvent; -import com.craftmend.openaudiomc.api.impl.event.events.SystemReloadEvent; -import com.craftmend.openaudiomc.api.impl.event.events.VoiceChatPeerTickEvent; -import com.craftmend.openaudiomc.api.interfaces.AudioApi; +import com.craftmend.openaudiomc.api.EventApi; +import com.craftmend.openaudiomc.api.events.client.ClientPeerRemovedEvent; +import com.craftmend.openaudiomc.api.events.client.SystemReloadEvent; +import com.craftmend.openaudiomc.api.events.client.VoicechatPeerTickEvent; import com.craftmend.openaudiomc.api.voice.VoicePeerOptions; import com.craftmend.openaudiomc.generic.client.objects.ClientConnection; import com.craftmend.openaudiomc.generic.networking.interfaces.NetworkingService; @@ -55,7 +54,7 @@ public PlayerPeerTicker(int maxDistance, PeerFilter peerFilter) { this.filter = peerFilter; this.filter.updateProperty("d", maxDistance); - AudioApi.getInstance().getEventDriver().on(SystemReloadEvent.class).setHandler(e -> { + EventApi.getInstance().registerHandler(SystemReloadEvent.class, e -> { this.filter.updateProperty("d", maxDistance); }); } @@ -66,9 +65,6 @@ public void addFilter(Filter extraFilter) { @Override public void run() { - // pre-tick event, to take care of any pre-tick logic elsewhere - AudioApi.getInstance().getEventDriver().fire(new VoiceChatPeerTickEvent(TickEventType.BEFORE_TICK)); - // we'll reference everything during this tick based on this initial time snapshot. This prevents // concurrency issues later on, and means we can do relatively fast arrayCopy's when needed. // to save time, we'll pre-filter some results. @@ -147,8 +143,6 @@ public void run() { // unsubscribe these ClientConnection peer = OpenAudioMc.getService(NetworkingService.class).getClient(uuid); - System.out.println("Found non-applicable peer: " + peer.getOwner().getName() + ", our stateIs" + combinationChecker.stateIs(client.getOwner().getUniqueId(), uuid)); - if (peer == null) { // remove from list client.getRtcSessionManager().getCurrentProximityPeers().remove(uuid); @@ -156,7 +150,7 @@ public void run() { } client.getPeerQueue().drop(peer.getRtcSessionManager().getStreamKey()); - AudioApi.getInstance().getEventDriver().fire(new PlayerLeaveVoiceProximityEvent(client, peer)); + EventApi.getInstance().callEvent(new ClientPeerRemovedEvent(client, peer)); client.getRtcSessionManager().updateLocationWatcher(); client.getRtcSessionManager().getCurrentProximityPeers().remove(peer.getOwner().getUniqueId()); @@ -166,8 +160,8 @@ public void run() { } peer.getPeerQueue().drop(client.getRtcSessionManager().getStreamKey()); + EventApi.getInstance().callEvent(new ClientPeerRemovedEvent(peer, client)); peer.getRtcSessionManager().getCurrentProximityPeers().remove(client.getOwner().getUniqueId()); - AudioApi.getInstance().getEventDriver().fire(new PlayerLeaveVoiceProximityEvent(peer, client)); peer.getRtcSessionManager().updateLocationWatcher(); } @@ -190,6 +184,6 @@ public void run() { client.getSession().setResetVc(false); } - AudioApi.getInstance().getEventDriver().fire(new VoiceChatPeerTickEvent(TickEventType.AFTER_TICK)); + EventApi.getInstance().callEvent(new VoicechatPeerTickEvent()); } } diff --git a/plugin/src/main/resources/data.bin b/plugin/src/main/resources/data.bin index 240378200..54e8dae8b 100755 --- a/plugin/src/main/resources/data.bin +++ b/plugin/src/main/resources/data.bin @@ -1 +1 @@ -BUILD_NUM="1118" +BUILD_NUM="1132" diff --git a/plugin/src/main/resources/openaudiomc-build.properties b/plugin/src/main/resources/openaudiomc-build.properties index ebb66bab8..b7e8c8ce1 100644 --- a/plugin/src/main/resources/openaudiomc-build.properties +++ b/plugin/src/main/resources/openaudiomc-build.properties @@ -1,3 +1,3 @@ -BUILD_VERSION="1118" -BUILD_COMMIT="196427046234ca343f2f9f3db23c8311909e9609" +BUILD_VERSION="1132" +BUILD_COMMIT="e0842006cab8285737dfa84b3a4eeeab0e4e7e13" BUILD_AUTHOR="Mats" diff --git a/plugin/src/test/java/com/craftmend/tests/EventHandlerTest.java b/plugin/src/test/java/com/craftmend/tests/EventHandlerTest.java deleted file mode 100644 index c41729069..000000000 --- a/plugin/src/test/java/com/craftmend/tests/EventHandlerTest.java +++ /dev/null @@ -1,49 +0,0 @@ -package com.craftmend.tests; - -import com.craftmend.openaudiomc.api.impl.event.ApiEventDriver; -import com.craftmend.openaudiomc.api.impl.event.enums.EventSupport; -import com.craftmend.openaudiomc.generic.platform.Platform; -import com.craftmend.utils.ClassScanner; -import lombok.SneakyThrows; - -import org.junit.Assert; -import org.junit.Test; - -public class EventHandlerTest { - - // test if all events within the events package have public constructors - // and valid values for supported platforms - @SneakyThrows - @Test - public void testEvents() { - Class[] events = ClassScanner.getClasses("com.craftmend.openaudiomc.api.impl.event.events", null); - - Assert.assertTrue("There must be one or more events, but I found", events.length != 0); - - ApiEventDriver eventDriver = new ApiEventDriver(); - - for (Class event : events) { - EventSupport support = eventDriver.getEventSupportFor(event); - Assert.assertNotEquals(EventSupport.UNKNOWN.toString(), support.toString()); - } - } - - @SneakyThrows - @Test - public void testEventTypes() { - ApiEventDriver eventDriver = new ApiEventDriver(); - - // spigot only test - Assert.assertTrue(eventDriver.isSupported(EventSupport.SPIGOT_ONLY, Platform.SPIGOT, false)); - Assert.assertFalse(eventDriver.isSupported(EventSupport.SPIGOT_ONLY, Platform.BUNGEE, false)); - - // only prox if avi - Assert.assertFalse(eventDriver.isSupported(EventSupport.ONLY_PROXY_IF_AVAILABLE, Platform.SPIGOT, true)); - Assert.assertTrue(eventDriver.isSupported(EventSupport.ONLY_PROXY_IF_AVAILABLE, Platform.SPIGOT, false)); - - // only prox - Assert.assertTrue(eventDriver.isSupported(EventSupport.PROXY_ONLY, Platform.BUNGEE, false)); - Assert.assertFalse(eventDriver.isSupported(EventSupport.PROXY_ONLY, Platform.SPIGOT, false)); - } - -} diff --git a/plugin/src/test/java/com/craftmend/tests/EventListenerTest.java b/plugin/src/test/java/com/craftmend/tests/EventListenerTest.java deleted file mode 100644 index c5a04f78e..000000000 --- a/plugin/src/test/java/com/craftmend/tests/EventListenerTest.java +++ /dev/null @@ -1,47 +0,0 @@ -package com.craftmend.tests; - -import com.craftmend.openaudiomc.OpenAudioMcBuild; -import com.craftmend.openaudiomc.api.impl.event.ApiEventDriver; -import com.craftmend.openaudiomc.api.impl.event.AudioEvent; -import com.craftmend.openaudiomc.api.impl.event.enums.EventSupport; -import com.craftmend.openaudiomc.api.impl.event.events.ClientConnectEvent; -import com.craftmend.openaudiomc.api.interfaces.EventSupportFlag; -import lombok.SneakyThrows; -import org.junit.Assert; -import org.junit.Test; - -import java.util.concurrent.atomic.AtomicBoolean; - -public class EventListenerTest { - - @SneakyThrows - @Test - public void testEvents() { - OpenAudioMcBuild.IS_TESTING = true; - AtomicBoolean goodTriggered = new AtomicBoolean(false); - AtomicBoolean badTriggered = new AtomicBoolean(false); - - ApiEventDriver eventDriver = new ApiEventDriver(); - - eventDriver.on(TestEvent.class) - .setHandler((e) -> { - goodTriggered.set(true); - }); - - eventDriver.on(ClientConnectEvent.class) - .setHandler(b -> { - badTriggered.set(true); - }); - - eventDriver.fire(new TestEvent()); - - Assert.assertTrue(goodTriggered.get()); - Assert.assertFalse(badTriggered.get()); - } - - @EventSupportFlag(support = EventSupport.EVERYWHERE) - public static class TestEvent extends AudioEvent { - // no data - } - -}