Bukkit-API  1.7.9-R0.2
The inofficial Bukkit-API
PluginMessageListenerRegistration.java
1 package org.bukkit.plugin.messaging;
2 
3 import org.bukkit.plugin.Plugin;
4 
5 /**
6  * Contains information about a {@link Plugin}s registration to a plugin
7  * channel.
8  */
10  private final Messenger messenger;
11  private final Plugin plugin;
12  private final String channel;
13  private final PluginMessageListener listener;
14 
15  public PluginMessageListenerRegistration(Messenger messenger, Plugin plugin, String channel, PluginMessageListener listener) {
16  if (messenger == null) {
17  throw new IllegalArgumentException("Messenger cannot be null!");
18  }
19  if (plugin == null) {
20  throw new IllegalArgumentException("Plugin cannot be null!");
21  }
22  if (channel == null) {
23  throw new IllegalArgumentException("Channel cannot be null!");
24  }
25  if (listener == null) {
26  throw new IllegalArgumentException("Listener cannot be null!");
27  }
28 
29  this.messenger = messenger;
30  this.plugin = plugin;
31  this.channel = channel;
32  this.listener = listener;
33  }
34 
35  /**
36  * Gets the plugin channel that this registration is about.
37  *
38  * @return Plugin channel.
39  */
40  public String getChannel() {
41  return channel;
42  }
43 
44  /**
45  * Gets the registered listener described by this registration.
46  *
47  * @return Registered listener.
48  */
50  return listener;
51  }
52 
53  /**
54  * Gets the plugin that this registration is for.
55  *
56  * @return Registered plugin.
57  */
58  public Plugin getPlugin() {
59  return plugin;
60  }
61 
62  /**
63  * Checks if this registration is still valid.
64  *
65  * @return True if this registration is still valid, otherwise false.
66  */
67  public boolean isValid() {
68  return messenger.isRegistrationValid(this);
69  }
70 
71  @Override
72  public boolean equals(Object obj) {
73  if (obj == null) {
74  return false;
75  }
76  if (getClass() != obj.getClass()) {
77  return false;
78  }
79  final PluginMessageListenerRegistration other = (PluginMessageListenerRegistration) obj;
80  if (this.messenger != other.messenger && (this.messenger == null || !this.messenger.equals(other.messenger))) {
81  return false;
82  }
83  if (this.plugin != other.plugin && (this.plugin == null || !this.plugin.equals(other.plugin))) {
84  return false;
85  }
86  if ((this.channel == null) ? (other.channel != null) : !this.channel.equals(other.channel)) {
87  return false;
88  }
89  if (this.listener != other.listener && (this.listener == null || !this.listener.equals(other.listener))) {
90  return false;
91  }
92  return true;
93  }
94 
95  @Override
96  public int hashCode() {
97  int hash = 7;
98  hash = 53 * hash + (this.messenger != null ? this.messenger.hashCode() : 0);
99  hash = 53 * hash + (this.plugin != null ? this.plugin.hashCode() : 0);
100  hash = 53 * hash + (this.channel != null ? this.channel.hashCode() : 0);
101  hash = 53 * hash + (this.listener != null ? this.listener.hashCode() : 0);
102  return hash;
103  }
104 }
boolean isRegistrationValid(PluginMessageListenerRegistration registration)