mirror of
https://github.com/EssentialsX/Essentials.git
synced 2025-01-03 06:57:39 +01:00
add delayed task for XMPP presence update
This commit is contained in:
parent
601bdbff46
commit
27ee587887
@ -3,6 +3,9 @@ package com.earth2me.essentials.xmpp;
|
||||
import com.earth2me.essentials.IEssentials;
|
||||
import com.earth2me.essentials.User;
|
||||
import java.util.List;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
import net.ess3.api.IUser;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
@ -10,64 +13,86 @@ import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.AsyncPlayerChatEvent;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
import org.bukkit.event.player.PlayerQuitEvent;
|
||||
import org.bukkit.Server;
|
||||
|
||||
|
||||
class EssentialsXMPPPlayerListener implements Listener
|
||||
{
|
||||
private final transient IEssentials ess;
|
||||
private final transient IEssentials ess;
|
||||
|
||||
EssentialsXMPPPlayerListener(final IEssentials ess)
|
||||
{
|
||||
super();
|
||||
this.ess = 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());
|
||||
sendMessageToSpyUsers("Player " + user.getDisplayName() + " joined the game");
|
||||
}
|
||||
@EventHandler(priority = EventPriority.MONITOR)
|
||||
public void onPlayerJoin(final PlayerJoinEvent event)
|
||||
{
|
||||
final User user = ess.getUser(event.getPlayer());
|
||||
|
||||
@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()));
|
||||
}
|
||||
Bukkit.getScheduler().scheduleSyncDelayedTask(ess, new Runnable()
|
||||
{
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
EssentialsXMPP.updatePresence();
|
||||
}
|
||||
});
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR)
|
||||
public void onPlayerQuit(final PlayerQuitEvent event)
|
||||
{
|
||||
final User user = ess.getUser(event.getPlayer());
|
||||
sendMessageToSpyUsers("Player " + user.getDisplayName() + " left the game");
|
||||
}
|
||||
sendMessageToSpyUsers("Player " + user.getDisplayName() + " joined 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);
|
||||
}
|
||||
@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());
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
// Ignore exceptions
|
||||
}
|
||||
}
|
||||
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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user