mirror of
https://github.com/EssentialsX/Essentials.git
synced 2025-01-21 23:51:42 +01:00
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.
This commit is contained in:
parent
1b3698283e
commit
fb211d722c
@ -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);
|
||||
}
|
||||
|
@ -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())
|
||||
{
|
||||
|
@ -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();
|
||||
|
||||
|
@ -54,4 +54,6 @@ public interface IUser
|
||||
InetSocketAddress getAddress();
|
||||
|
||||
String getDisplayName();
|
||||
|
||||
boolean isHidden();
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -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()));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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);
|
||||
|
@ -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)));
|
||||
}
|
||||
}
|
||||
|
@ -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());
|
||||
}
|
||||
}
|
||||
|
@ -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()));
|
||||
}
|
||||
}
|
||||
|
@ -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));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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())
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -47,7 +47,7 @@ public class UserManager implements IConf
|
||||
return username;
|
||||
}
|
||||
}
|
||||
return search;
|
||||
return null;
|
||||
}
|
||||
|
||||
public void setAddress(final String username, final String address)
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user