diff options
author | patjense <patjense@cisco.com> | 2013-10-13 12:55:10 -0700 |
---|---|---|
committer | KHobbits <rob@khobbits.co.uk> | 2013-10-16 20:52:50 +0100 |
commit | 12bf4e9dcf3c44c68a76a65afdf4a89fa5df3dd0 (patch) | |
tree | c1598ae1f986aea3d2ee39bf369dbe6537a199f2 /EssentialsXMPP/src/com/earth2me | |
parent | 59b501b2b194ad9abb19cf4aff13f4c47f3b2068 (diff) | |
download | Essentials-12bf4e9dcf3c44c68a76a65afdf4a89fa5df3dd0.tar Essentials-12bf4e9dcf3c44c68a76a65afdf4a89fa5df3dd0.tar.gz Essentials-12bf4e9dcf3c44c68a76a65afdf4a89fa5df3dd0.tar.lz Essentials-12bf4e9dcf3c44c68a76a65afdf4a89fa5df3dd0.tar.xz Essentials-12bf4e9dcf3c44c68a76a65afdf4a89fa5df3dd0.zip |
add update for global presence handler
Diffstat (limited to 'EssentialsXMPP/src/com/earth2me')
-rw-r--r-- | EssentialsXMPP/src/com/earth2me/essentials/xmpp/EssentialsXMPP.java | 259 |
1 files changed, 133 insertions, 126 deletions
diff --git a/EssentialsXMPP/src/com/earth2me/essentials/xmpp/EssentialsXMPP.java b/EssentialsXMPP/src/com/earth2me/essentials/xmpp/EssentialsXMPP.java index b9b4fddbc..bdfb3557d 100644 --- a/EssentialsXMPP/src/com/earth2me/essentials/xmpp/EssentialsXMPP.java +++ b/EssentialsXMPP/src/com/earth2me/essentials/xmpp/EssentialsXMPP.java @@ -16,130 +16,137 @@ import org.bukkit.plugin.java.JavaPlugin; public class EssentialsXMPP extends JavaPlugin implements IEssentialsXMPP { - private static final Logger LOGGER = Logger.getLogger("Minecraft"); - private static EssentialsXMPP instance = null; - private transient UserManager users; - private transient XMPPManager xmpp; - private transient IEssentials ess; - - public static IEssentialsXMPP getInstance() - { - return instance; - } - - @Override - public void onEnable() - { - instance = this; - - final PluginManager pluginManager = getServer().getPluginManager(); - ess = (IEssentials)pluginManager.getPlugin("Essentials"); - if (!this.getDescription().getVersion().equals(ess.getDescription().getVersion())) - { - LOGGER.log(Level.WARNING, _("versionMismatchAll")); - } - if (!ess.isEnabled()) - { - this.setEnabled(false); - return; - } - - final EssentialsXMPPPlayerListener playerListener = new EssentialsXMPPPlayerListener(ess); - pluginManager.registerEvents(playerListener, this); - - users = new UserManager(this.getDataFolder()); - xmpp = new XMPPManager(this); - - ess.addReloadListener(users); - ess.addReloadListener(xmpp); - } - - @Override - public void onDisable() - { - if (xmpp != null) - { - xmpp.disconnect(); - } - instance = null; - } - - @Override - public boolean onCommand(final CommandSender sender, final Command command, final String commandLabel, final String[] args) - { - return ess.onCommandEssentials(sender, command, commandLabel, args, EssentialsXMPP.class.getClassLoader(), "com.earth2me.essentials.xmpp.Command", "essentials.", null); - } - - @Override - public void setAddress(final Player user, final String address) - { - final String username = user.getName().toLowerCase(Locale.ENGLISH); - instance.users.setAddress(username, address); - } - - @Override - public String getAddress(final String name) - { - return instance.users.getAddress(name); - } - - @Override - public IUser getUserByAddress(final String address) - { - String username = instance.users.getUserByAddress(address); - return username == null ? null : ess.getUser(username); - } - - @Override - public boolean toggleSpy(final Player user) - { - final String username = user.getName().toLowerCase(Locale.ENGLISH); - final boolean spy = !instance.users.isSpy(username); - instance.users.setSpy(username, spy); - return spy; - } - - @Override - public String getAddress(final Player user) - { - return instance.users.getAddress(user.getName()); - } - - @Override - public boolean sendMessage(final Player user, final String message) - { - return instance.xmpp.sendMessage(instance.users.getAddress(user.getName()), message); - } - - @Override - public boolean sendMessage(final String address, final String message) - { - return instance.xmpp.sendMessage(address, message); - } - - @Override - public List<String> getSpyUsers() - { - return instance.users.getSpyUsers(); - } - - @Override - public void broadcastMessage(final IUser sender, final String message, final String xmppAddress) - { - ess.broadcastMessage(sender, message); - try - { - for (String address : getSpyUsers()) - { - if (!address.equalsIgnoreCase(xmppAddress)) - { - sendMessage(address, message); - } - } - } - catch (Exception ex) - { - // Ignore exceptions - } - } + private static final Logger LOGGER = Logger.getLogger("Minecraft"); + private static EssentialsXMPP instance = null; + private transient UserManager users; + private transient XMPPManager xmpp; + private transient IEssentials ess; + + public static IEssentialsXMPP getInstance() + { + return instance; + } + + @Override + public void onEnable() + { + instance = this; + + final PluginManager pluginManager = getServer().getPluginManager(); + ess = (IEssentials)pluginManager.getPlugin("Essentials"); + if (!this.getDescription().getVersion().equals(ess.getDescription().getVersion())) + { + LOGGER.log(Level.WARNING, _("versionMismatchAll")); + } + if (!ess.isEnabled()) + { + this.setEnabled(false); + return; + } + + final EssentialsXMPPPlayerListener playerListener = new EssentialsXMPPPlayerListener(ess); + pluginManager.registerEvents(playerListener, this); + + users = new UserManager(this.getDataFolder()); + xmpp = new XMPPManager(this); + + ess.addReloadListener(users); + ess.addReloadListener(xmpp); + } + + @Override + public void onDisable() + { + if (xmpp != null) + { + xmpp.disconnect(); + } + instance = null; + } + + @Override + public boolean onCommand(final CommandSender sender, final Command command, final String commandLabel, final String[] args) + { + return ess.onCommandEssentials(sender, command, commandLabel, args, EssentialsXMPP.class.getClassLoader(), "com.earth2me.essentials.xmpp.Command", "essentials.", null); + } + + @Override + public void setAddress(final Player user, final String address) + { + final String username = user.getName().toLowerCase(Locale.ENGLISH); + instance.users.setAddress(username, address); + } + + @Override + public String getAddress(final String name) + { + return instance.users.getAddress(name); + } + + @Override + public IUser getUserByAddress(final String address) + { + String username = instance.users.getUserByAddress(address); + return username == null ? null : ess.getUser(username); + } + + @Override + public boolean toggleSpy(final Player user) + { + final String username = user.getName().toLowerCase(Locale.ENGLISH); + final boolean spy = !instance.users.isSpy(username); + instance.users.setSpy(username, spy); + return spy; + } + + @Override + public String getAddress(final Player user) + { + return instance.users.getAddress(user.getName()); + } + + @Override + public boolean sendMessage(final Player user, final String message) + { + return instance.xmpp.sendMessage(instance.users.getAddress(user.getName()), message); + } + + @Override + public boolean sendMessage(final String address, final String message) + { + return instance.xmpp.sendMessage(address, message); + } + + // @Override + public static boolean updatePresence() + { + instance.xmpp.updatePresence(); + return true; + } + + @Override + public List<String> getSpyUsers() + { + return instance.users.getSpyUsers(); + } + + @Override + public void broadcastMessage(final IUser sender, final String message, final String xmppAddress) + { + ess.broadcastMessage(sender, message); + try + { + for (String address : getSpyUsers()) + { + if (!address.equalsIgnoreCase(xmppAddress)) + { + sendMessage(address, message); + } + } + } + catch (Exception ex) + { + // Ignore exceptions + } + } } |