From 4f0a02dccacdcb28ac39471bef7f042e45d8774b Mon Sep 17 00:00:00 2001 From: md_5 Date: Sat, 12 Jan 2013 11:15:40 +1100 Subject: [PATCH] Think this is a good way to manage events, since many will be targeted between specific nodes. It is expected for developers to cast as needed. --- .../md_5/bungee/api/PendingConnection.java | 8 ++++++ .../net/md_5/bungee/api/event/ChatEvent.java | 25 +++++++++++-------- .../net/md_5/bungee/api/event/LoginEvent.java | 14 +++-------- .../bungee/api/event/PluginMessageEvent.java | 22 ++++++++-------- .../md_5/bungee/api/event/TargetedEvent.java | 20 +++++++++++++++ 5 files changed, 58 insertions(+), 31 deletions(-) create mode 100644 api/src/main/java/net/md_5/bungee/api/PendingConnection.java create mode 100644 api/src/main/java/net/md_5/bungee/api/event/TargetedEvent.java diff --git a/api/src/main/java/net/md_5/bungee/api/PendingConnection.java b/api/src/main/java/net/md_5/bungee/api/PendingConnection.java new file mode 100644 index 00000000..246dc44c --- /dev/null +++ b/api/src/main/java/net/md_5/bungee/api/PendingConnection.java @@ -0,0 +1,8 @@ +package net.md_5.bungee.api; + +/** + * Represents a user attempting to log into the proxy. + */ +public interface PendingConnection extends Connection +{ +} diff --git a/api/src/main/java/net/md_5/bungee/api/event/ChatEvent.java b/api/src/main/java/net/md_5/bungee/api/event/ChatEvent.java index 022e9c49..af76d1d7 100644 --- a/api/src/main/java/net/md_5/bungee/api/event/ChatEvent.java +++ b/api/src/main/java/net/md_5/bungee/api/event/ChatEvent.java @@ -1,28 +1,33 @@ package net.md_5.bungee.api.event; import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.ToString; import net.md_5.bungee.api.Connection; -import net.md_5.bungee.api.ProxiedPlayer; import net.md_5.bungee.api.plugin.Cancellable; +/** + * Event called when a player sends a message to a server, or a server sends a + * message to a player. + */ @Data -public class ChatEvent implements Cancellable +@ToString(callSuper = true) +@EqualsAndHashCode(callSuper = true) +public class ChatEvent extends TargetedEvent implements Cancellable { /** * Cancelled state. */ private boolean cancelled; - /** - * Where this message is being sent to. - */ - private final Connection destination; - /** - * User involved with sending or receiving this message. - */ - private final ProxiedPlayer player; /** * Text contained in this chat. */ private String message; + + public ChatEvent(Connection sender, Connection receiver, String message) + { + super(sender, receiver); + this.message = message; + } } diff --git a/api/src/main/java/net/md_5/bungee/api/event/LoginEvent.java b/api/src/main/java/net/md_5/bungee/api/event/LoginEvent.java index 473518ff..bc300590 100644 --- a/api/src/main/java/net/md_5/bungee/api/event/LoginEvent.java +++ b/api/src/main/java/net/md_5/bungee/api/event/LoginEvent.java @@ -1,7 +1,7 @@ package net.md_5.bungee.api.event; -import java.net.InetAddress; import lombok.Data; +import net.md_5.bungee.api.PendingConnection; import net.md_5.bungee.api.plugin.Cancellable; /** @@ -20,15 +20,7 @@ public class LoginEvent implements Cancellable */ private String cancelReason; /** - * Username which the player wishes to use. + * Connection attempting to login. */ - private final String username; - /** - * IP address of the remote connection. - */ - private final InetAddress address; - /** - * Hostname which the user tried to connect to. - */ - private final String hostname; + private final PendingConnection connection; } diff --git a/api/src/main/java/net/md_5/bungee/api/event/PluginMessageEvent.java b/api/src/main/java/net/md_5/bungee/api/event/PluginMessageEvent.java index 27fa0744..3daec111 100644 --- a/api/src/main/java/net/md_5/bungee/api/event/PluginMessageEvent.java +++ b/api/src/main/java/net/md_5/bungee/api/event/PluginMessageEvent.java @@ -1,29 +1,24 @@ package net.md_5.bungee.api.event; import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.ToString; import net.md_5.bungee.api.Connection; -import net.md_5.bungee.api.ProxiedPlayer; import net.md_5.bungee.api.plugin.Cancellable; /** * Event called when a plugin message is sent to the client or server. */ @Data -public class PluginMessageEvent implements Cancellable +@ToString(callSuper = true) +@EqualsAndHashCode(callSuper = true) +public class PluginMessageEvent extends TargetedEvent implements Cancellable { /** * Cancelled state. */ private boolean cancelled; - /** - * Dispatcher of this message. - */ - private final Connection sender; - /** - * Player involved with sending or receiving this message. - */ - private final ProxiedPlayer player; /** * Tag specified for this plugin message. */ @@ -32,4 +27,11 @@ public class PluginMessageEvent implements Cancellable * Data contained in this plugin message. */ private byte[] data; + + public PluginMessageEvent(Connection sender, Connection receiver, String tag, byte[] data) + { + super(sender, receiver); + this.tag = tag; + this.data = data; + } } diff --git a/api/src/main/java/net/md_5/bungee/api/event/TargetedEvent.java b/api/src/main/java/net/md_5/bungee/api/event/TargetedEvent.java new file mode 100644 index 00000000..c04d9be6 --- /dev/null +++ b/api/src/main/java/net/md_5/bungee/api/event/TargetedEvent.java @@ -0,0 +1,20 @@ +package net.md_5.bungee.api.event; + +import lombok.AllArgsConstructor; +import lombok.Data; +import net.md_5.bungee.api.Connection; + +/** + * An event which occurs in the communication between two nodes. It is not + * recommended to call {@link #setSender(net.md_5.bungee.api.Connection)} or + * {@link #setReceiver(net.md_5.bungee.api.Connection)} and the results of doing + * so are undefined. + */ +@Data +@AllArgsConstructor +public abstract class TargetedEvent +{ + + private Connection sender; + private Connection receiver; +}