1
0
mirror of https://github.com/essentials/Essentials.git synced 2025-09-25 13:49:12 +02:00

Remove xmpp

This commit is contained in:
ementalo
2015-04-10 23:22:14 +01:00
parent 1020521190
commit ce8313bd68
16 changed files with 1 additions and 1036 deletions

3
.gitignore vendored
View File

@@ -5,7 +5,6 @@
/EssentialsGroupBridge/nbproject/private/
/EssentialsGeoIP/nbproject/private/
/EssentialsSpawn/nbproject/private/
/EssentialsXMPP/nbproject/private/
/EssentialsGroupManager/nbproject/private/
/BuildAll/build/
/EssentialsGroupBridge/dist/
@@ -19,8 +18,6 @@
/EssentialsChat/dist/
/EssentialsSpawn/build/
/EssentialsSpawn/dist/
/EssentialsXMPP/dist/
/EssentialsXMPP/build/
/EssentialsProtect/dist/
/EssentialsProtect/build/
/EssentialsPermissionsCommands/nbproject/private/

View File

@@ -25,8 +25,7 @@ public class MetricsStarter implements Runnable
EssentialsChat,
EssentialsSpawn,
EssentialsProtect,
EssentialsGeoIP,
EssentialsXMPP
EssentialsGeoIP
};
public MetricsStarter(final IEssentials plugin)

View File

@@ -18,7 +18,6 @@ public class FormatUtil
static final transient Pattern REPLACE_FORMAT_PATTERN = Pattern.compile("(?<!&)&([l-orL-OR])");
static final transient Pattern REPLACE_PATTERN = Pattern.compile("&&(?=[0-9a-fk-orA-FK-OR])");
//Used to prepare xmpp output
static final transient Pattern LOGCOLOR_PATTERN = Pattern.compile("\\x1B\\[([0-9]{1,2}(;[0-9]{1,2})?)?[m|K]");
static final transient Pattern URL_PATTERN = Pattern.compile("((?:(?:https?)://)?[\\w-_\\.]{2,})\\.([a-zA-Z]{2,3}(?:/\\S+)?)");
public static final Pattern IPPATTERN = Pattern.compile("^([01]?\\d\\d?|2[0-4]\\d|25[0-5])\\.([01]?\\d\\d?|2[0-4]\\d|25[0-5])\\." + "([01]?\\d\\d?|2[0-4]\\d|25[0-5])\\.([01]?\\d\\d?|2[0-4]\\d|25[0-5])$");
@@ -107,15 +106,6 @@ public class FormatUtil
return message;
}
public static String stripLogColorFormat(final String input)
{
if (input == null)
{
return null;
}
return stripColor(input, LOGCOLOR_PATTERN);
}
static String stripColor(final String input, final Pattern pattern)
{
return pattern.matcher(input).replaceAll("");

View File

@@ -181,7 +181,6 @@ player-commands:
- seen
- sell
- sethome
- setxmpp
- signs.create.protection
- signs.create.trade
- signs.break.protection
@@ -214,7 +213,6 @@ player-commands:
- warp.list
- world
- worth
- xmpp
# Note: All items MUST be followed by a quantity!
# All kit names should be lower case, and will be treated as lower in permissions/costs.

View File

@@ -1,82 +0,0 @@
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>net.ess3</groupId>
<artifactId>EssentialsParent</artifactId>
<version>2.x-SNAPSHOT</version>
</parent>
<artifactId>EssentialsXMPP</artifactId>
<url>http://ess3.net/</url>
<organization>
<name>Essentials Team</name>
<url>http://ess3.net/</url>
</organization>
<licenses>
<license>
<name>GPLv3</name>
<url>http://www.gnu.org/copyleft/gpl.html</url>
</license>
</licenses>
<scm>
<connection>scm:git:https://github.com/essentials/Essentials.git</connection>
<developerConnection>scm:git:https://github.com/essentials/Essentials.git</developerConnection>
<url>https://github.com/essentials/Essentials</url>
</scm>
<issueManagement>
<system>JIRA</system>
<url>http://essentials3.atlassian.net</url>
</issueManagement>
<ciManagement>
<system>TeamCity</system>
<url>http://ci.ess3.net/</url>
</ciManagement>
<dependencies>
<dependency>
<groupId>net.ess3</groupId>
<artifactId>Essentials</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.igniterealtime.smack</groupId>
<artifactId>smack</artifactId>
<version>3.2.1</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>2.1</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
</execution>
</executions>
<configuration>
<artifactSet>
<includes>
<include>org.igniterealtime.smack:smack</include>
</includes>
</artifactSet>
</configuration>
</plugin>
</plugins>
</build>
</project>

View File

@@ -1,27 +0,0 @@
package com.earth2me.essentials.xmpp;
import com.earth2me.essentials.User;
import com.earth2me.essentials.commands.EssentialsCommand;
import com.earth2me.essentials.commands.NotEnoughArgumentsException;
import org.bukkit.Server;
public class Commandsetxmpp extends EssentialsCommand
{
public Commandsetxmpp()
{
super("setxmpp");
}
@Override
protected void run(final Server server, final User user, final String commandLabel, final String[] args) throws NotEnoughArgumentsException
{
if (args.length < 1)
{
throw new NotEnoughArgumentsException();
}
EssentialsXMPP.getInstance().setAddress(user.getBase(), args[0]);
user.sendMessage("XMPP address set to " + args[0]);
}
}

View File

@@ -1,41 +0,0 @@
package com.earth2me.essentials.xmpp;
import com.earth2me.essentials.CommandSource;
import com.earth2me.essentials.Console;
import com.earth2me.essentials.commands.EssentialsCommand;
import com.earth2me.essentials.commands.NotEnoughArgumentsException;
import org.bukkit.Server;
public class Commandxmpp extends EssentialsCommand
{
public Commandxmpp()
{
super("xmpp");
}
@Override
protected void run(final Server server, final CommandSource sender, final String commandLabel, final String[] args) throws NotEnoughArgumentsException
{
if (args.length < 2)
{
throw new NotEnoughArgumentsException();
}
final String address = EssentialsXMPP.getInstance().getAddress(args[0]);
if (address == null)
{
sender.sendMessage("§cThere are no players matching that name.");
}
else
{
final String message = getFinalArg(args, 1);
final String senderName = sender.isPlayer() ? ess.getUser(sender.getPlayer()).getDisplayName() : Console.NAME;
sender.sendMessage("[" + senderName + ">" + address + "] " + message);
if (!EssentialsXMPP.getInstance().sendMessage(address, "[" + senderName + "] " + message))
{
sender.sendMessage("§cError sending message.");
}
}
}
}

View File

@@ -1,46 +0,0 @@
package com.earth2me.essentials.xmpp;
import com.earth2me.essentials.CommandSource;
import com.earth2me.essentials.commands.EssentialsCommand;
import com.earth2me.essentials.commands.NotEnoughArgumentsException;
import java.util.List;
import org.bukkit.Server;
import org.bukkit.entity.Player;
public class Commandxmppspy extends EssentialsCommand
{
public Commandxmppspy()
{
super("xmppspy");
}
@Override
protected void run(final Server server, final CommandSource sender, final String commandLabel, final String[] args) throws NotEnoughArgumentsException
{
if (args.length < 1)
{
throw new NotEnoughArgumentsException();
}
final List<Player> matches = server.matchPlayer(args[0]);
if (matches.isEmpty())
{
sender.sendMessage("§cThere are no players matching that name.");
}
for (Player p : matches)
{
try
{
final boolean toggle = EssentialsXMPP.getInstance().toggleSpy(p);
sender.sendMessage("XMPP Spy " + (toggle ? "enabled" : "disabled") + " for " + p.getDisplayName());
}
catch (Exception ex)
{
sender.sendMessage("Error: " + ex.getMessage());
}
}
}
}

View File

@@ -1,158 +0,0 @@
package com.earth2me.essentials.xmpp;
import static com.earth2me.essentials.I18n.tl;
import com.earth2me.essentials.IEssentials;
import net.ess3.api.IUser;
import java.util.List;
import java.util.Locale;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.plugin.PluginManager;
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, tl("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
}
}
@Override
public IEssentials getEss()
{
return ess;
}
}

View File

@@ -1,93 +0,0 @@
package com.earth2me.essentials.xmpp;
import com.earth2me.essentials.IEssentials;
import com.earth2me.essentials.User;
import java.util.List;
import org.bukkit.Bukkit;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.player.AsyncPlayerChatEvent;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerQuitEvent;
class EssentialsXMPPPlayerListener implements Listener
{
private final transient IEssentials ess;
EssentialsXMPPPlayerListener(final IEssentials ess)
{
super();
this.ess = ess;
}
@EventHandler(priority = EventPriority.MONITOR)
public void onPlayerJoin(final PlayerJoinEvent event)
{
final User user = ess.getUser(event.getPlayer());
Bukkit.getScheduler().scheduleSyncDelayedTask(ess, new Runnable()
{
@Override
public void run()
{
EssentialsXMPP.updatePresence();
}
});
sendMessageToSpyUsers("Player " + user.getDisplayName() + " joined the game");
}
@EventHandler(priority = EventPriority.MONITOR)
public void onPlayerChat(final AsyncPlayerChatEvent event)
{
final User user = ess.getUser(event.getPlayer());
sendMessageToSpyUsers(String.format(event.getFormat(), user.getDisplayName(), event.getMessage()));
}
@EventHandler(priority = EventPriority.MONITOR)
public void onPlayerQuit(final PlayerQuitEvent event)
{
final User user = ess.getUser(event.getPlayer());
Bukkit.getScheduler().scheduleSyncDelayedTask(ess, new Runnable()
{
@Override
public void run()
{
EssentialsXMPP.updatePresence();
}
});
sendMessageToSpyUsers("Player " + user.getDisplayName() + " left the game");
}
private void sendMessageToSpyUsers(final String message)
{
try
{
List<String> users = EssentialsXMPP.getInstance().getSpyUsers();
synchronized (users)
{
for (final String address : users)
{
Bukkit.getScheduler().scheduleSyncDelayedTask(ess, new Runnable()
{
@Override
public void run()
{
EssentialsXMPP.getInstance().sendMessage(address, message);
}
});
}
}
}
catch (Exception ex)
{
// Ignore exceptions
}
}
}

View File

@@ -1,31 +0,0 @@
package com.earth2me.essentials.xmpp;
import com.earth2me.essentials.IEssentials;
import net.ess3.api.IUser;
import java.util.List;
import org.bukkit.entity.Player;
import org.bukkit.plugin.Plugin;
public interface IEssentialsXMPP extends Plugin
{
String getAddress(final Player user);
String getAddress(final String name);
List<String> getSpyUsers();
IUser getUserByAddress(final String address);
boolean sendMessage(final Player user, final String message);
boolean sendMessage(final String address, final String message);
void setAddress(final Player user, final String address);
boolean toggleSpy(final Player user);
void broadcastMessage(final IUser sender, final String message, final String xmppAddress);
IEssentials getEss();
}

View File

@@ -1,89 +0,0 @@
package com.earth2me.essentials.xmpp;
import com.earth2me.essentials.EssentialsConf;
import com.earth2me.essentials.IConf;
import java.io.File;
import java.util.*;
public class UserManager implements IConf
{
private final transient EssentialsConf users;
private final transient List<String> spyusers = Collections.synchronizedList(new ArrayList<String>());
private static final String ADDRESS = "address";
private static final String SPY = "spy";
public UserManager(final File folder)
{
users = new EssentialsConf(new File(folder, "users.yml"));
reloadConfig();
}
public final boolean isSpy(final String username)
{
return users.getBoolean(username.toLowerCase(Locale.ENGLISH) + "." + SPY, false);
}
public void setSpy(final String username, final boolean spy)
{
setUser(username.toLowerCase(Locale.ENGLISH), getAddress(username), spy);
}
public final String getAddress(final String username)
{
return users.getString(username.toLowerCase(Locale.ENGLISH) + "." + ADDRESS, null);
}
public final String getUserByAddress(final String search)
{
final Set<String> usernames = users.getKeys(false);
for (String username : usernames)
{
final String address = users.getString(username + "." + ADDRESS, null);
if (address != null && search.equalsIgnoreCase(address))
{
return username;
}
}
return null;
}
public void setAddress(final String username, final String address)
{
setUser(username.toLowerCase(Locale.ENGLISH), address, isSpy(username));
}
public List<String> getSpyUsers()
{
return spyusers;
}
private void setUser(final String username, final String address, final boolean spy)
{
final Map<String, Object> userdata = new HashMap<String, Object>();
userdata.put(ADDRESS, address);
userdata.put(SPY, spy);
users.setProperty(username, userdata);
users.save();
reloadConfig();
}
@Override
public final void reloadConfig()
{
users.load();
spyusers.clear();
final Set<String> keys = users.getKeys(false);
for (String key : keys)
{
if (isSpy(key))
{
final String address = getAddress(key);
if (address != null)
{
spyusers.add(address);
}
}
}
}
}

View File

@@ -1,407 +0,0 @@
package com.earth2me.essentials.xmpp;
import com.earth2me.essentials.Console;
import com.earth2me.essentials.EssentialsConf;
import com.earth2me.essentials.IConf;
import net.ess3.api.IUser;
import com.earth2me.essentials.utils.FormatUtil;
import java.io.File;
import java.util.*;
import java.util.logging.Handler;
import java.util.logging.Level;
import java.util.logging.LogRecord;
import java.util.logging.Logger;
import java.util.logging.SimpleFormatter;
import org.bukkit.entity.Player;
import org.jivesoftware.smack.*;
import org.jivesoftware.smack.Roster.SubscriptionMode;
import org.jivesoftware.smack.packet.Message;
import org.jivesoftware.smack.packet.Presence;
import org.jivesoftware.smack.util.StringUtils;
public class XMPPManager extends Handler implements MessageListener, ChatManagerListener, IConf
{
private static final Logger LOGGER = Logger.getLogger("Minecraft");
private static final SimpleFormatter formatter = new SimpleFormatter();
private final transient EssentialsConf config;
private transient XMPPConnection connection;
private transient ChatManager chatManager;
private final transient Map<String, Chat> chats = Collections.synchronizedMap(new HashMap<String, Chat>());
private final transient Set<LogRecord> logrecords = Collections.synchronizedSet(new HashSet<LogRecord>());
private final transient IEssentialsXMPP parent;
private transient List<String> logUsers;
private transient Level logLevel;
private transient boolean ignoreLagMessages = true;
private transient Thread loggerThread;
private transient boolean threadrunning = true;
public XMPPManager(final IEssentialsXMPP parent)
{
super();
this.parent = parent;
config = new EssentialsConf(new File(parent.getDataFolder(), "config.yml"));
config.setTemplateName("/config.yml", EssentialsXMPP.class);
reloadConfig();
}
public boolean sendMessage(final String address, final String message)
{
if (address != null && !address.isEmpty())
{
try
{
startChat(address);
final Chat chat;
synchronized (chats)
{
chat = chats.get(address);
}
if (chat != null)
{
if (!connection.isConnected())
{
disconnect();
connect();
}
chat.sendMessage(FormatUtil.stripFormat(message));
return true;
}
}
catch (XMPPException ex)
{
disableChat(address);
}
}
return false;
}
@Override
public void processMessage(final Chat chat, final Message msg)
{
// Normally we should log the error message
// But we would create a loop if the connection to a log-user fails.
if (msg.getType() != Message.Type.error && msg.getBody().length() > 0)
{
final String message = msg.getBody();
switch (message.charAt(0))
{
case '@':
sendPrivateMessage(chat, message);
break;
case '/':
sendCommand(chat, message);
break;
default:
final IUser sender = parent.getUserByAddress(StringUtils.parseBareAddress(chat.getParticipant()));
parent.broadcastMessage(sender, "=" + sender.getBase().getDisplayName() + ": " + message, StringUtils.parseBareAddress(chat.getParticipant()));
}
}
}
private boolean connect()
{
final String server = config.getString("xmpp.server");
if (server == null || server.equals("example.com"))
{
LOGGER.log(Level.WARNING, "config broken for xmpp");
return false;
}
final int port = config.getInt("xmpp.port", 5222);
final String serviceName = config.getString("xmpp.servicename", server);
final String xmppuser = config.getString("xmpp.user");
final String password = config.getString("xmpp.password");
final ConnectionConfiguration connConf = new ConnectionConfiguration(server, port, serviceName);
final StringBuilder stringBuilder = new StringBuilder();
stringBuilder.append("Connecting to xmpp server ").append(server).append(":").append(port);
stringBuilder.append(" as user ").append(xmppuser).append(".");
LOGGER.log(Level.INFO, stringBuilder.toString());
connConf.setSASLAuthenticationEnabled(config.getBoolean("xmpp.sasl-enabled", false));
connConf.setSendPresence(true);
connConf.setReconnectionAllowed(true);
connConf.setDebuggerEnabled(config.getBoolean("debug", false));
connection = new XMPPConnection(connConf);
try
{
connection.connect();
connection.login(xmppuser, password, "Essentials-XMPP");
connection.sendPacket(new Presence(Presence.Type.available, "No one online.", 2, Presence.Mode.available));
connection.getRoster().setSubscriptionMode(SubscriptionMode.accept_all);
chatManager = connection.getChatManager();
chatManager.addChatListener(this);
return true;
}
catch (XMPPException ex)
{
LOGGER.log(Level.WARNING, "Failed to connect to server: " + server, ex);
return false;
}
}
public final void disconnect()
{
if (loggerThread != null)
{
loggerThread.interrupt();
}
if (chatManager != null)
{
chatManager.removeChatListener(this);
chatManager = null;
}
if (connection != null)
{
connection.disconnect(new Presence(Presence.Type.unavailable));
}
}
public final void updatePresence()
{
final int usercount;
final StringBuilder stringBuilder = new StringBuilder();
usercount = parent.getEss().getOnlinePlayers().size();
if (usercount == 0)
{
final String presenceMsg = "No one online.";
connection.sendPacket(new Presence(Presence.Type.available, presenceMsg, 2, Presence.Mode.dnd));
}
if (usercount == 1)
{
final String presenceMsg = "1 player online.";
connection.sendPacket(new Presence(Presence.Type.available, presenceMsg, 2, Presence.Mode.available));
}
if (usercount > 1)
{
stringBuilder.append(usercount).append(" players online.");
connection.sendPacket(new Presence(Presence.Type.available, stringBuilder.toString(), 2, Presence.Mode.available));
}
}
@Override
public void chatCreated(final Chat chat, final boolean createdLocally)
{
if (!createdLocally)
{
chat.addMessageListener(this);
final Chat old = chats.put(StringUtils.parseBareAddress(chat.getParticipant()), chat);
if (old != null)
{
old.removeMessageListener(this);
}
}
}
@Override
public final void reloadConfig()
{
LOGGER.removeHandler(this);
config.load();
synchronized (chats)
{
disconnect();
chats.clear();
if (!connect())
{
return;
}
startLoggerThread();
}
if (config.getBoolean("log-enabled", false))
{
LOGGER.addHandler(this);
logUsers = config.getStringList("log-users");
final String level = config.getString("log-level", "info");
try
{
logLevel = Level.parse(level.toUpperCase(Locale.ENGLISH));
}
catch (IllegalArgumentException e)
{
logLevel = Level.INFO;
}
ignoreLagMessages = config.getBoolean("ignore-lag-messages", true);
}
}
@Override
public void publish(final LogRecord logRecord)
{
try
{
if (ignoreLagMessages && logRecord.getMessage().equals("Can't keep up! Did the system time change, or is the server overloaded?"))
{
return;
}
if (logRecord.getLevel().intValue() >= logLevel.intValue())
{
synchronized (logrecords)
{
logrecords.add(logRecord);
}
}
}
catch (Exception e)
{
// Ignore all exceptions
// Otherwise we create a loop.
}
}
@Override
public void flush()
{
// Ignore this
}
@Override
public void close() throws SecurityException
{
// Ignore this
}
private void startLoggerThread()
{
loggerThread = new Thread(new Runnable()
{
@Override
public void run()
{
final Set<LogRecord> copy = new HashSet<LogRecord>();
final Set<String> failedUsers = new HashSet<String>();
while (threadrunning)
{
synchronized (logrecords)
{
if (!logrecords.isEmpty())
{
copy.addAll(logrecords);
logrecords.clear();
}
}
if (!copy.isEmpty())
{
for (String user : logUsers)
{
try
{
XMPPManager.this.startChat(user);
for (LogRecord logRecord : copy)
{
final String message = formatter.format(logRecord);
if (!XMPPManager.this.sendMessage(user, FormatUtil.stripLogColorFormat(message)))
{
failedUsers.add(user);
break;
}
}
}
catch (XMPPException ex)
{
failedUsers.add(user);
LOGGER.removeHandler(XMPPManager.this);
LOGGER.log(Level.SEVERE, "Failed to deliver log message! Disabling logging to XMPP.", ex);
}
}
logUsers.removeAll(failedUsers);
if (logUsers.isEmpty())
{
LOGGER.removeHandler(XMPPManager.this);
threadrunning = false;
}
copy.clear();
}
try
{
Thread.sleep(2000);
}
catch (InterruptedException ex)
{
threadrunning = false;
}
}
LOGGER.removeHandler(XMPPManager.this);
}
});
loggerThread.start();
}
private void startChat(final String address) throws XMPPException
{
if (chatManager == null)
{
return;
}
synchronized (chats)
{
if (!chats.containsKey(address))
{
final Chat chat = chatManager.createChat(address, this);
if (chat == null)
{
throw new XMPPException("Could not start Chat with " + address);
}
chats.put(address, chat);
}
}
}
private void sendPrivateMessage(final Chat chat, final String message)
{
final String[] parts = message.split(" ", 2);
if (parts.length == 2)
{
final List<Player> matches = parent.getServer().matchPlayer(parts[0].substring(1));
if (matches.isEmpty())
{
try
{
chat.sendMessage("User " + parts[0] + " not found");
}
catch (XMPPException ex)
{
LOGGER.log(Level.WARNING, "Failed to send xmpp message.", ex);
}
}
else
{
final String from = "[" + parent.getUserByAddress(StringUtils.parseBareAddress(chat.getParticipant())) + ">";
for (Player p : matches)
{
p.sendMessage(from + p.getDisplayName() + "] " + message);
}
}
}
}
private void sendCommand(final Chat chat, final String message)
{
if (config.getStringList("op-users").contains(StringUtils.parseBareAddress(chat.getParticipant())))
{
try
{
parent.getServer().dispatchCommand(Console.getCommandSender(parent.getServer()), message.substring(1));
}
catch (Exception ex)
{
LOGGER.log(Level.SEVERE, ex.getMessage(), ex);
}
}
}
private void disableChat(final String address)
{
final Chat chat = chats.get(address);
if (chat != null)
{
chat.removeMessageListener(this);
chats.remove(address);
}
}
}

View File

@@ -1,19 +0,0 @@
xmpp:
server: 'example.com'
user: 'name@example.com'
password: 'password'
# servicename: 'example.com'
# port: 5222
# sasl-enabled: false
debug: false
op-users:
# - 'name@example.com'
log-enabled: false
# Level is minimum level that should be send: info, warning, severe
log-level: warning
log-users:
# - 'name@example.com'

View File

@@ -1,20 +0,0 @@
# This determines the command prefix when there are conflicts (/name:home, /name:help, etc.)
name: EssentialsXMPP
main: com.earth2me.essentials.xmpp.EssentialsXMPP
# Note to developers: This next line cannot change, or the automatic versioning system will break.
version: TeamCity
website: http://ess.khhq.net/wiki/XMPP
description: Provides xmpp communication.
authors:
- snowleo
depend: [Essentials]
commands:
setxmpp:
description: set your xmpp address
usage: /<command> <address>
xmpp:
description: send a message to a player
usage: /<command> <player> <message>
xmppspy:
description: toggle xmpp spy for all messages
usage: /<command> <player>

View File

@@ -64,7 +64,6 @@
<module>EssentialsGeoIP</module>
<module>EssentialsProtect</module>
<module>EssentialsSpawn</module>
<module>EssentialsXMPP</module>
</modules>
<dependencies>
@@ -163,11 +162,6 @@
<artifactId>EssentialsSpawn</artifactId>
<version>${project.version}</version>
</artifactItem>
<artifactItem>
<groupId>${project.groupId}</groupId>
<artifactId>EssentialsXMPP</artifactId>
<version>${project.version}</version>
</artifactItem>
</artifactItems>
</configuration>
<inherited>false</inherited>