001 package org.bukkit.plugin.messaging; 002 003 import org.bukkit.plugin.Plugin; 004 005 /** 006 * Contains information about a {@link Plugin}s registration to a plugin 007 * channel. 008 */ 009 public final class PluginMessageListenerRegistration { 010 private final Messenger messenger; 011 private final Plugin plugin; 012 private final String channel; 013 private final PluginMessageListener listener; 014 015 public PluginMessageListenerRegistration(Messenger messenger, Plugin plugin, String channel, PluginMessageListener listener) { 016 if (messenger == null) { 017 throw new IllegalArgumentException("Messenger cannot be null!"); 018 } 019 if (plugin == null) { 020 throw new IllegalArgumentException("Plugin cannot be null!"); 021 } 022 if (channel == null) { 023 throw new IllegalArgumentException("Channel cannot be null!"); 024 } 025 if (listener == null) { 026 throw new IllegalArgumentException("Listener cannot be null!"); 027 } 028 029 this.messenger = messenger; 030 this.plugin = plugin; 031 this.channel = channel; 032 this.listener = listener; 033 } 034 035 /** 036 * Gets the plugin channel that this registration is about. 037 * 038 * @return Plugin channel. 039 */ 040 public String getChannel() { 041 return channel; 042 } 043 044 /** 045 * Gets the registered listener described by this registration. 046 * 047 * @return Registered listener. 048 */ 049 public PluginMessageListener getListener() { 050 return listener; 051 } 052 053 /** 054 * Gets the plugin that this registration is for. 055 * 056 * @return Registered plugin. 057 */ 058 public Plugin getPlugin() { 059 return plugin; 060 } 061 062 /** 063 * Checks if this registration is still valid. 064 * 065 * @return True if this registration is still valid, otherwise false. 066 */ 067 public boolean isValid() { 068 return messenger.isRegistrationValid(this); 069 } 070 071 @Override 072 public boolean equals(Object obj) { 073 if (obj == null) { 074 return false; 075 } 076 if (getClass() != obj.getClass()) { 077 return false; 078 } 079 final PluginMessageListenerRegistration other = (PluginMessageListenerRegistration) obj; 080 if (this.messenger != other.messenger && (this.messenger == null || !this.messenger.equals(other.messenger))) { 081 return false; 082 } 083 if (this.plugin != other.plugin && (this.plugin == null || !this.plugin.equals(other.plugin))) { 084 return false; 085 } 086 if ((this.channel == null) ? (other.channel != null) : !this.channel.equals(other.channel)) { 087 return false; 088 } 089 if (this.listener != other.listener && (this.listener == null || !this.listener.equals(other.listener))) { 090 return false; 091 } 092 return true; 093 } 094 095 @Override 096 public int hashCode() { 097 int hash = 7; 098 hash = 53 * hash + (this.messenger != null ? this.messenger.hashCode() : 0); 099 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 }