New feature allows a user to ignore other players

git-svn-id: https://svn.java.net/svn/essentials~svn/trunk@1474 e251c2fe-e539-e718-e476-b85c1f46cddb
This commit is contained in:
snowleo 2011-05-15 11:40:46 +00:00
parent 86dce6e092
commit 0246d21e69
16 changed files with 122 additions and 17 deletions

View file

@ -451,7 +451,7 @@ public class Essentials extends JavaPlugin
catch (NotEnoughArgumentsException ex)
{
sender.sendMessage(command.getDescription());
sender.sendMessage(command.getUsage());
sender.sendMessage(command.getUsage().replaceAll("<command>", commandLabel));
return true;
}
catch (Throwable ex)
@ -663,4 +663,18 @@ public class Essentials extends JavaPlugin
{
return paymentMethod;
}
public int broadcastMessage(String name, String message) {
Player[] players = getServer().getOnlinePlayers();
for (Player player : players) {
User u = getUser(player);
if (!u.isIgnoredPlayer(name))
{
player.sendMessage(message);
}
}
return players.length;
}
}

View file

@ -1,6 +1,8 @@
package com.earth2me.essentials;
import java.util.Iterator;
import java.util.List;
import java.util.Set;
import java.util.logging.Level;
import java.util.logging.Logger;
import net.minecraft.server.InventoryPlayer;
@ -56,6 +58,15 @@ public class EssentialsPlayerListener extends PlayerListener
event.setCancelled(true);
logger.info(Util.format("mutedUserSpeaks", user.getName()));
}
Iterator<Player> it = event.getRecipients().iterator();
while (it.hasNext())
{
User u = ess.getUser(it.next());
if (u.isIgnoredPlayer(user.getName()))
{
it.remove();
}
}
}
@Override

View file

@ -415,18 +415,18 @@ public abstract class UserData extends PlayerExtension implements IConf
public boolean isIgnoredPlayer(String name)
{
return ignoredPlayers.contains(name);
return ignoredPlayers.contains(name.toLowerCase());
}
public void setIgnoredPlayer(String name, boolean set)
{
if (set)
{
ignoredPlayers.add(name);
ignoredPlayers.add(name.toLowerCase());
}
else
{
ignoredPlayers.remove(name);
ignoredPlayers.remove(name.toLowerCase());
}
setIgnoredPlayers(ignoredPlayers);
}

View file

@ -20,10 +20,10 @@ public class Commandafk extends EssentialsCommand
if (!user.toggleAfk())
{
user.sendMessage(Util.i18n("markedAsNotAway"));
server.broadcastMessage(Util.format("userIsNotAway", user.getDisplayName()));
ess.broadcastMessage(user.getName(), Util.format("userIsNotAway", user.getDisplayName()));
} else {
user.sendMessage(Util.i18n("markedAsAway"));
server.broadcastMessage(Util.format("userIsAway", user.getDisplayName()));
ess.broadcastMessage(user.getName(), Util.format("userIsAway", user.getDisplayName()));
}
}
}

View file

@ -20,8 +20,8 @@ public class Commandantioch extends EssentialsCommand
public void run(Server server, User user, String commandLabel, String[] args) throws Exception
{
charge(user);
server.broadcastMessage("...lobbest thou thy Holy Hand Grenade of Antioch towards thy foe,");
server.broadcastMessage("who being naughty in My sight, shall snuff it.");
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.");
Location loc = user.getLocation();
World world = ((CraftWorld)user.getWorld()).getHandle();

View file

@ -1,8 +1,10 @@
package com.earth2me.essentials.commands;
import com.earth2me.essentials.Console;
import com.earth2me.essentials.Util;
import org.bukkit.Server;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
public class Commandbroadcast extends EssentialsCommand
@ -21,6 +23,7 @@ public class Commandbroadcast extends EssentialsCommand
}
charge(sender);
server.broadcastMessage(Util.format("broadcast", getFinalArg(args, 0)));
ess.broadcastMessage(sender instanceof Player ? ((Player)sender).getName() : Console.NAME,
Util.format("broadcast", getFinalArg(args, 0)));
}
}

View file

@ -0,0 +1,49 @@
package com.earth2me.essentials.commands;
import com.earth2me.essentials.User;
import com.earth2me.essentials.Util;
import org.bukkit.Server;
public class Commandignore extends EssentialsCommand
{
public Commandignore()
{
super("ignore");
}
@Override
protected void run(Server server, User user, String commandLabel, String[] args) throws Exception
{
if (args.length < 1)
{
throw new NotEnoughArgumentsException();
}
User u;
try
{
u = getPlayer(server, args, 0);
}
catch(NoSuchFieldException ex)
{
u = ess.getOfflineUser(args[0]);
}
if (u == null)
{
throw new Exception(Util.i18n("playerNotFound"));
}
String name = u.getName();
if (user.isIgnoredPlayer(name)) {
user.setIgnoredPlayer(name, false);
user.sendMessage(Util.format("unignorePlayer", u.getName()));
}
else
{
user.setIgnoredPlayer(name, true);
user.sendMessage(Util.format("ignorePlayer", u.getName()));
}
}
}

View file

@ -57,7 +57,10 @@ public class Commandmail extends EssentialsCommand
return;
}
charge(user);
if (!u.isIgnoredPlayer(user.getName()))
{
u.addMail(ChatColor.stripColor(user.getDisplayName()) + ": " + getFinalArg(args, 2));
}
user.sendMessage(Util.i18n("mailSent"));
return;
}

View file

@ -32,6 +32,6 @@ public class Commandme extends EssentialsCommand
message.append(' ');
}
charge(user);
server.broadcastMessage("* " + user.getDisplayName() + " " + message);
ess.broadcastMessage(user.getName(), "* " + user.getDisplayName() + " " + message);
}
}

View file

@ -51,6 +51,10 @@ public class Commandmsg extends EssentialsCommand
charge(sender);
for (Player p : matches)
{
if (sender instanceof Player && ess.getUser(p).isIgnoredPlayer(((Player)sender).getName()))
{
continue;
}
sender.sendMessage("[" + translatedMe + " -> " + p.getDisplayName() + "§f] " + message);
p.sendMessage("[" + senderName + " -> " + translatedMe + "§f] " + message);
replyTo.setReplyTo(ess.getUser(p));

View file

@ -2,6 +2,7 @@ package com.earth2me.essentials.commands;
import com.earth2me.essentials.Console;
import com.earth2me.essentials.IReplyTo;
import com.earth2me.essentials.User;
import com.earth2me.essentials.Util;
import org.bukkit.*;
import org.bukkit.command.CommandSender;
@ -36,6 +37,14 @@ public class Commandr extends EssentialsCommand
charge(sender);
sender.sendMessage("[" + Util.i18n("me")+ " -> " + targetName + "] " + message);
if (target instanceof Player)
{
User u = ess.getUser(target);
if (u.isIgnoredPlayer(sender instanceof Player ? ((Player)sender).getName() : Console.NAME))
{
return;
}
}
target.sendMessage("[" + senderName + " -> " + Util.i18n("me") +"] " + message);
replyTo.setReplyTo(target);
if (target != sender)

View file

@ -18,6 +18,7 @@ public class Commandsuicide extends EssentialsCommand
charge(user);
user.setHealth(0);
user.sendMessage(Util.i18n("suicideMessage"));
server.broadcastMessage(Util.format("suicideSuccess",user.getDisplayName()));
ess.broadcastMessage(user.getName(),
Util.format("suicideSuccess",user.getDisplayName()));
}
}

View file

@ -26,10 +26,13 @@ public class Commandtpa extends EssentialsCommand
throw new Exception(Util.format("teleportDisabled", p.getDisplayName()));
}
player.charge(this);
if (!p.isIgnoredPlayer(player.getName()))
{
p.requestTeleport(player, false);
p.sendMessage(Util.format("teleportRequest", player.getDisplayName()));
p.sendMessage(Util.i18n("typeTpaccept"));
p.sendMessage(Util.i18n("typeTpdeny"));
}
player.sendMessage(Util.format("requestSent", p.getDisplayName()));
}
}

View file

@ -300,3 +300,5 @@ typeWorldName = \u00a77You can also type the name of a specific world.
worth = \u00a77Stack of {0} worth \u00a7c{1}\u00a77 ({2} item(s) at {3} each)
worthMeta = \u00a77Stack of {0} with metadata of {1} worth \u00a7c{2}\u00a77 ({3} item(s) at {4} each)
onlyPlayers = Only in-game players can use {0}.
unignorePlayer = You are not ignoring player {0} anymore.
ignorePlayer = You ignore player {0} from now on.

View file

@ -300,3 +300,5 @@ typeWorldName = \u00a77You can also type the name of a specific world.
worth = \u00a77Stack of {0} worth \u00a7c{1}\u00a77 ({2} item(s) at {3} each)
worthMeta = \u00a77Stack of {0} with metadata of {1} worth \u00a7c{2}\u00a77 ({3} item(s) at {4} each)
onlyPlayers = Only in-game players can use {0}.
unignorePlayer = You are not ignoring player {0} anymore.
ignorePlayer = You ignore player {0} from now on.

View file

@ -107,6 +107,10 @@ commands:
description: Teleport to your home.
usage: /<command> <player>
aliases: [ehome]
ignore:
description: Ignore other players.
usage: /<command> <player>
aliases: [eignore]
info:
description: Shows information set by the server owner
usage: /<command> [chapter] [page]