summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorsnowleo <schneeleo@gmail.com>2011-09-02 16:15:57 +0200
committersnowleo <schneeleo@gmail.com>2011-09-02 16:16:15 +0200
commitfb211d722cb93d1234930015746d963a02818d5f (patch)
tree3d8a80cd6094c5cd2d04cb546a92112ad897bfae
parent1b3698283e0608d7fc8173d2a366ead01e12afee (diff)
downloadEssentials-fb211d722cb93d1234930015746d963a02818d5f.tar
Essentials-fb211d722cb93d1234930015746d963a02818d5f.tar.gz
Essentials-fb211d722cb93d1234930015746d963a02818d5f.tar.lz
Essentials-fb211d722cb93d1234930015746d963a02818d5f.tar.xz
Essentials-fb211d722cb93d1234930015746d963a02818d5f.zip
Prevent that hidden players broadcast afk messages
Prevent that moving players triggers unafk too early, they can now move within a radius of 3 blocks from the position where they went afk.
-rw-r--r--Essentials/src/com/earth2me/essentials/Essentials.java10
-rw-r--r--Essentials/src/com/earth2me/essentials/EssentialsPlayerListener.java4
-rw-r--r--Essentials/src/com/earth2me/essentials/IEssentials.java2
-rw-r--r--Essentials/src/com/earth2me/essentials/IUser.java2
-rw-r--r--Essentials/src/com/earth2me/essentials/User.java20
-rw-r--r--Essentials/src/com/earth2me/essentials/commands/Commandafk.java10
-rw-r--r--Essentials/src/com/earth2me/essentials/commands/Commandantioch.java4
-rw-r--r--Essentials/src/com/earth2me/essentials/commands/Commandbroadcast.java5
-rw-r--r--Essentials/src/com/earth2me/essentials/commands/Commandme.java7
-rw-r--r--Essentials/src/com/earth2me/essentials/commands/Commandsuicide.java2
-rw-r--r--EssentialsSpawn/src/com/earth2me/essentials/spawn/EssentialsSpawnPlayerListener.java2
-rw-r--r--EssentialsXMPP/src/com/earth2me/essentials/xmpp/EssentialsXMPP.java10
-rw-r--r--EssentialsXMPP/src/com/earth2me/essentials/xmpp/IEssentialsXMPP.java5
-rw-r--r--EssentialsXMPP/src/com/earth2me/essentials/xmpp/UserManager.java2
-rw-r--r--EssentialsXMPP/src/com/earth2me/essentials/xmpp/XMPPManager.java5
15 files changed, 62 insertions, 28 deletions
diff --git a/Essentials/src/com/earth2me/essentials/Essentials.java b/Essentials/src/com/earth2me/essentials/Essentials.java
index a9f77f401..386e9cc5a 100644
--- a/Essentials/src/com/earth2me/essentials/Essentials.java
+++ b/Essentials/src/com/earth2me/essentials/Essentials.java
@@ -612,14 +612,20 @@ public class Essentials extends JavaPlugin implements IEssentials
}
@Override
- public int broadcastMessage(final String name, final String message)
+ public int broadcastMessage(final IUser sender, final String message)
{
+ if (sender == null) {
+ return getServer().broadcastMessage(message);
+ }
+ if (sender.isHidden()) {
+ return 0;
+ }
final Player[] players = getServer().getOnlinePlayers();
for (Player player : players)
{
final User user = getUser(player);
- if (!user.isIgnoredPlayer(name))
+ if (!user.isIgnoredPlayer(sender.getName()))
{
player.sendMessage(message);
}
diff --git a/Essentials/src/com/earth2me/essentials/EssentialsPlayerListener.java b/Essentials/src/com/earth2me/essentials/EssentialsPlayerListener.java
index ebf9a97dc..4828382d2 100644
--- a/Essentials/src/com/earth2me/essentials/EssentialsPlayerListener.java
+++ b/Essentials/src/com/earth2me/essentials/EssentialsPlayerListener.java
@@ -107,7 +107,9 @@ public class EssentialsPlayerListener extends PlayerListener
return;
}
- user.updateActivity(true);
+ if (user.getAfkPosition().distanceSquared(user.getLocation()) > 9) {
+ user.updateActivity(true);
+ }
if (!ess.getSettings().getNetherPortalsEnabled())
{
diff --git a/Essentials/src/com/earth2me/essentials/IEssentials.java b/Essentials/src/com/earth2me/essentials/IEssentials.java
index b47ebd5ab..0ac8c54d3 100644
--- a/Essentials/src/com/earth2me/essentials/IEssentials.java
+++ b/Essentials/src/com/earth2me/essentials/IEssentials.java
@@ -23,7 +23,7 @@ public interface IEssentials extends Plugin
World getWorld(String name);
- int broadcastMessage(String name, String message);
+ int broadcastMessage(IUser sender, String message);
ISettings getSettings();
diff --git a/Essentials/src/com/earth2me/essentials/IUser.java b/Essentials/src/com/earth2me/essentials/IUser.java
index 91a121e0a..27f95430c 100644
--- a/Essentials/src/com/earth2me/essentials/IUser.java
+++ b/Essentials/src/com/earth2me/essentials/IUser.java
@@ -54,4 +54,6 @@ public interface IUser
InetSocketAddress getAddress();
String getDisplayName();
+
+ boolean isHidden();
}
diff --git a/Essentials/src/com/earth2me/essentials/User.java b/Essentials/src/com/earth2me/essentials/User.java
index 9ba353cf9..ebc89570d 100644
--- a/Essentials/src/com/earth2me/essentials/User.java
+++ b/Essentials/src/com/earth2me/essentials/User.java
@@ -21,12 +21,14 @@ public class User extends UserData implements Comparable<User>, IReplyTo, IUser
private transient long lastActivity = System.currentTimeMillis();
private boolean hidden = false;
private transient boolean godStateBeforeAfk;
+ private transient Location afkPosition;
User(final Player base, final IEssentials ess)
{
super(base, ess);
teleport = new Teleport(this, ess);
godStateBeforeAfk = isGodModeEnabled();
+ afkPosition = getLocation();
}
User update(final Player base)
@@ -355,6 +357,9 @@ public class User extends UserData implements Comparable<User>, IReplyTo, IUser
{
setGodModeEnabled(godStateBeforeAfk);
}
+ if (set && !isAfk()) {
+ afkPosition = getLocation();
+ }
super.setAfk(set);
}
@@ -418,9 +423,9 @@ public class User extends UserData implements Comparable<User>, IReplyTo, IUser
if (isAfk())
{
setAfk(false);
- if (broadcast)
+ if (broadcast && !isHidden())
{
- ess.broadcastMessage(getName(), Util.format("userIsNotAway", getDisplayName()));
+ ess.broadcastMessage(this, Util.format("userIsNotAway", getDisplayName()));
}
return;
}
@@ -431,7 +436,7 @@ public class User extends UserData implements Comparable<User>, IReplyTo, IUser
{
final long autoafkkick = ess.getSettings().getAutoAfkKick();
if (autoafkkick > 0 && lastActivity + autoafkkick * 1000 < System.currentTimeMillis()
- && !isAuthorized("essentials.kick.exempt") && !isAuthorized("essentials.afk.kickexempt"))
+ && !isHidden() && !isAuthorized("essentials.kick.exempt") && !isAuthorized("essentials.afk.kickexempt"))
{
final String kickReason = Util.format("autoAfkKickReason", autoafkkick / 60.0);
kickPlayer(kickReason);
@@ -450,7 +455,14 @@ public class User extends UserData implements Comparable<User>, IReplyTo, IUser
if (!isAfk() && autoafk > 0 && lastActivity + autoafk * 1000 < System.currentTimeMillis())
{
setAfk(true);
- ess.broadcastMessage(getName(), Util.format("userIsAway", getDisplayName()));
+ if (!isHidden()) {
+ ess.broadcastMessage(this, Util.format("userIsAway", getDisplayName()));
+ }
}
}
+
+ public Location getAfkPosition()
+ {
+ return afkPosition;
+ }
}
diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandafk.java b/Essentials/src/com/earth2me/essentials/commands/Commandafk.java
index bb749f66f..8bf70873d 100644
--- a/Essentials/src/com/earth2me/essentials/commands/Commandafk.java
+++ b/Essentials/src/com/earth2me/essentials/commands/Commandafk.java
@@ -34,13 +34,19 @@ public class Commandafk extends EssentialsCommand
if (!user.toggleAfk())
{
//user.sendMessage(Util.i18n("markedAsNotAway"));
- ess.broadcastMessage(user.getName(), Util.format("userIsNotAway", user.getDisplayName()));
+ if (!user.isHidden())
+ {
+ ess.broadcastMessage(user, Util.format("userIsNotAway", user.getDisplayName()));
+ }
user.updateActivity(false);
}
else
{
//user.sendMessage(Util.i18n("markedAsAway"));
- ess.broadcastMessage(user.getName(), Util.format("userIsAway", user.getDisplayName()));
+ if (!user.isHidden())
+ {
+ ess.broadcastMessage(user, Util.format("userIsAway", user.getDisplayName()));
+ }
}
}
}
diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandantioch.java b/Essentials/src/com/earth2me/essentials/commands/Commandantioch.java
index c30975b03..5bfdd3835 100644
--- a/Essentials/src/com/earth2me/essentials/commands/Commandantioch.java
+++ b/Essentials/src/com/earth2me/essentials/commands/Commandantioch.java
@@ -17,8 +17,8 @@ public class Commandantioch extends EssentialsCommand
@Override
public void run(final Server server, final User user, final String commandLabel, final String[] args) throws Exception
{
- ess.broadcastMessage(user.getName(), "...lobbest thou thy Holy Hand Grenade of Antioch towards thy foe,");
- ess.broadcastMessage(user.getName(), "who being naughty in My sight, shall snuff it.");
+ ess.broadcastMessage(user, "...lobbest thou thy Holy Hand Grenade of Antioch towards thy foe,");
+ ess.broadcastMessage(user, "who being naughty in My sight, shall snuff it.");
final Location loc = new TargetBlock(user).getTargetBlock().getLocation();
loc.getWorld().spawn(loc, TNTPrimed.class);
diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandbroadcast.java b/Essentials/src/com/earth2me/essentials/commands/Commandbroadcast.java
index 684920114..9b92434a4 100644
--- a/Essentials/src/com/earth2me/essentials/commands/Commandbroadcast.java
+++ b/Essentials/src/com/earth2me/essentials/commands/Commandbroadcast.java
@@ -1,6 +1,5 @@
package com.earth2me.essentials.commands;
-import com.earth2me.essentials.Console;
import com.earth2me.essentials.Util;
import org.bukkit.Server;
import org.bukkit.command.CommandSender;
@@ -15,14 +14,14 @@ public class Commandbroadcast extends EssentialsCommand
}
@Override
- public void run(Server server, CommandSender sender, String commandLabel, String[] args) throws Exception
+ public void run(final Server server, final CommandSender sender, final String commandLabel, final String[] args) throws Exception
{
if (args.length < 1)
{
throw new NotEnoughArgumentsException();
}
- ess.broadcastMessage(sender instanceof Player ? ((Player)sender).getName() : Console.NAME,
+ ess.broadcastMessage(null,
Util.format("broadcast", getFinalArg(args, 0)));
}
}
diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandme.java b/Essentials/src/com/earth2me/essentials/commands/Commandme.java
index 7441b723b..02bcecdc2 100644
--- a/Essentials/src/com/earth2me/essentials/commands/Commandme.java
+++ b/Essentials/src/com/earth2me/essentials/commands/Commandme.java
@@ -24,12 +24,15 @@ public class Commandme extends EssentialsCommand
{
throw new NotEnoughArgumentsException();
}
- StringBuilder message = new StringBuilder();
+ final StringBuilder message = new StringBuilder();
+ message.append("* ");
+ message.append(user.getDisplayName());
+ message.append(' ');
for (int i = 0; i < args.length; i++)
{
message.append(args[i]);
message.append(' ');
}
- ess.broadcastMessage(user.getName(), "* " + user.getDisplayName() + " " + message);
+ ess.broadcastMessage(user, message.toString());
}
}
diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandsuicide.java b/Essentials/src/com/earth2me/essentials/commands/Commandsuicide.java
index 90f40a4bf..ca9fee47b 100644
--- a/Essentials/src/com/earth2me/essentials/commands/Commandsuicide.java
+++ b/Essentials/src/com/earth2me/essentials/commands/Commandsuicide.java
@@ -17,7 +17,7 @@ public class Commandsuicide extends EssentialsCommand
{
user.setHealth(0);
user.sendMessage(Util.i18n("suicideMessage"));
- ess.broadcastMessage(user.getName(),
+ ess.broadcastMessage(user,
Util.format("suicideSuccess",user.getDisplayName()));
}
}
diff --git a/EssentialsSpawn/src/com/earth2me/essentials/spawn/EssentialsSpawnPlayerListener.java b/EssentialsSpawn/src/com/earth2me/essentials/spawn/EssentialsSpawnPlayerListener.java
index 3c85c3661..459eee60a 100644
--- a/EssentialsSpawn/src/com/earth2me/essentials/spawn/EssentialsSpawnPlayerListener.java
+++ b/EssentialsSpawn/src/com/earth2me/essentials/spawn/EssentialsSpawnPlayerListener.java
@@ -79,7 +79,7 @@ public class EssentialsSpawnPlayerListener extends PlayerListener
if (ess.getSettings().getAnnounceNewPlayers())
{
- ess.broadcastMessage(user.getName(), ess.getSettings().getAnnounceNewPlayerFormat(user));
+ ess.broadcastMessage(user, ess.getSettings().getAnnounceNewPlayerFormat(user));
}
}
}
diff --git a/EssentialsXMPP/src/com/earth2me/essentials/xmpp/EssentialsXMPP.java b/EssentialsXMPP/src/com/earth2me/essentials/xmpp/EssentialsXMPP.java
index 8ab62cd4d..34f862627 100644
--- a/EssentialsXMPP/src/com/earth2me/essentials/xmpp/EssentialsXMPP.java
+++ b/EssentialsXMPP/src/com/earth2me/essentials/xmpp/EssentialsXMPP.java
@@ -1,6 +1,7 @@
package com.earth2me.essentials.xmpp;
import com.earth2me.essentials.IEssentials;
+import com.earth2me.essentials.IUser;
import com.earth2me.essentials.Util;
import java.util.List;
import java.util.logging.Level;
@@ -83,9 +84,10 @@ public class EssentialsXMPP extends JavaPlugin implements IEssentialsXMPP
}
@Override
- public String getUserByAddress(final String address)
+ public IUser getUserByAddress(final String address)
{
- return instance.users.getUserByAddress(address);
+ String username = instance.users.getUserByAddress(address);
+ return username == null ? null : ess.getUser(username);
}
@Override
@@ -122,9 +124,9 @@ public class EssentialsXMPP extends JavaPlugin implements IEssentialsXMPP
}
@Override
- public void broadcastMessage(final String name, final String message)
+ public void broadcastMessage(final IUser sender, final String message)
{
- ess.broadcastMessage(name, message);
+ ess.broadcastMessage(sender, message);
try
{
for (String address : getSpyUsers())
diff --git a/EssentialsXMPP/src/com/earth2me/essentials/xmpp/IEssentialsXMPP.java b/EssentialsXMPP/src/com/earth2me/essentials/xmpp/IEssentialsXMPP.java
index d90bff803..1ed9fa732 100644
--- a/EssentialsXMPP/src/com/earth2me/essentials/xmpp/IEssentialsXMPP.java
+++ b/EssentialsXMPP/src/com/earth2me/essentials/xmpp/IEssentialsXMPP.java
@@ -1,5 +1,6 @@
package com.earth2me.essentials.xmpp;
+import com.earth2me.essentials.IUser;
import java.util.List;
import org.bukkit.entity.Player;
import org.bukkit.plugin.Plugin;
@@ -13,7 +14,7 @@ public interface IEssentialsXMPP extends Plugin
List<String> getSpyUsers();
- String getUserByAddress(final String address);
+ IUser getUserByAddress(final String address);
boolean sendMessage(final Player user, final String message);
@@ -23,5 +24,5 @@ public interface IEssentialsXMPP extends Plugin
boolean toggleSpy(final Player user);
- void broadcastMessage(final String name, final String message);
+ void broadcastMessage(final IUser sender, final String message);
}
diff --git a/EssentialsXMPP/src/com/earth2me/essentials/xmpp/UserManager.java b/EssentialsXMPP/src/com/earth2me/essentials/xmpp/UserManager.java
index 6a2a6e80a..9734444ad 100644
--- a/EssentialsXMPP/src/com/earth2me/essentials/xmpp/UserManager.java
+++ b/EssentialsXMPP/src/com/earth2me/essentials/xmpp/UserManager.java
@@ -47,7 +47,7 @@ public class UserManager implements IConf
return username;
}
}
- return search;
+ return null;
}
public void setAddress(final String username, final String address)
diff --git a/EssentialsXMPP/src/com/earth2me/essentials/xmpp/XMPPManager.java b/EssentialsXMPP/src/com/earth2me/essentials/xmpp/XMPPManager.java
index e43844c5b..d7aedb9f4 100644
--- a/EssentialsXMPP/src/com/earth2me/essentials/xmpp/XMPPManager.java
+++ b/EssentialsXMPP/src/com/earth2me/essentials/xmpp/XMPPManager.java
@@ -3,6 +3,7 @@ package com.earth2me.essentials.xmpp;
import com.earth2me.essentials.Console;
import com.earth2me.essentials.EssentialsConf;
import com.earth2me.essentials.IConf;
+import com.earth2me.essentials.IUser;
import java.io.File;
import java.util.ArrayList;
import java.util.Collections;
@@ -101,8 +102,8 @@ public class XMPPManager extends Handler implements MessageListener, ChatManager
sendCommand(chat, message);
break;
default:
- final String name = parent.getUserByAddress(StringUtils.parseBareAddress(chat.getParticipant()));
- parent.broadcastMessage(name, "="+name+": "+ message);
+ final IUser sender = parent.getUserByAddress(StringUtils.parseBareAddress(chat.getParticipant()));
+ parent.broadcastMessage(sender, "="+sender.getDisplayName()+": "+ message);
}
}
}