diff options
author | snowleo <snowleo@e251c2fe-e539-e718-e476-b85c1f46cddb> | 2011-05-15 11:40:46 +0000 |
---|---|---|
committer | snowleo <snowleo@e251c2fe-e539-e718-e476-b85c1f46cddb> | 2011-05-15 11:40:46 +0000 |
commit | bdc72d1ae50f27048cabbeae319668831106ac41 (patch) | |
tree | 09b6142b23a557f86f5b8a7c590b4ad36be7036c | |
parent | e78ed3ad5d3e47bad368c3a069a17fa064b48d3d (diff) | |
download | Essentials-bdc72d1ae50f27048cabbeae319668831106ac41.tar Essentials-bdc72d1ae50f27048cabbeae319668831106ac41.tar.gz Essentials-bdc72d1ae50f27048cabbeae319668831106ac41.tar.lz Essentials-bdc72d1ae50f27048cabbeae319668831106ac41.tar.xz Essentials-bdc72d1ae50f27048cabbeae319668831106ac41.zip |
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
16 files changed, 122 insertions, 17 deletions
diff --git a/Essentials/src/com/earth2me/essentials/Essentials.java b/Essentials/src/com/earth2me/essentials/Essentials.java index a46bc021f..68e48ca8c 100644 --- a/Essentials/src/com/earth2me/essentials/Essentials.java +++ b/Essentials/src/com/earth2me/essentials/Essentials.java @@ -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; + } } diff --git a/Essentials/src/com/earth2me/essentials/EssentialsPlayerListener.java b/Essentials/src/com/earth2me/essentials/EssentialsPlayerListener.java index 59d577053..f824ad394 100644 --- a/Essentials/src/com/earth2me/essentials/EssentialsPlayerListener.java +++ b/Essentials/src/com/earth2me/essentials/EssentialsPlayerListener.java @@ -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 diff --git a/Essentials/src/com/earth2me/essentials/UserData.java b/Essentials/src/com/earth2me/essentials/UserData.java index 81b8eac67..319509abc 100644 --- a/Essentials/src/com/earth2me/essentials/UserData.java +++ b/Essentials/src/com/earth2me/essentials/UserData.java @@ -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); } diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandafk.java b/Essentials/src/com/earth2me/essentials/commands/Commandafk.java index a222f9c0b..24ff9758b 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandafk.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandafk.java @@ -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())); } } } diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandantioch.java b/Essentials/src/com/earth2me/essentials/commands/Commandantioch.java index 62ff41899..a7d778921 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandantioch.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandantioch.java @@ -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(); diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandbroadcast.java b/Essentials/src/com/earth2me/essentials/commands/Commandbroadcast.java index d88d35169..3ca9d3fd0 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandbroadcast.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandbroadcast.java @@ -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))); } } diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandignore.java b/Essentials/src/com/earth2me/essentials/commands/Commandignore.java new file mode 100644 index 000000000..953bf742c --- /dev/null +++ b/Essentials/src/com/earth2me/essentials/commands/Commandignore.java @@ -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())); + } + } + + +} diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandmail.java b/Essentials/src/com/earth2me/essentials/commands/Commandmail.java index ad96ee832..9b7f57fb1 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandmail.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandmail.java @@ -57,7 +57,10 @@ public class Commandmail extends EssentialsCommand return; } charge(user); - u.addMail(ChatColor.stripColor(user.getDisplayName()) + ": " + getFinalArg(args, 2)); + if (!u.isIgnoredPlayer(user.getName())) + { + u.addMail(ChatColor.stripColor(user.getDisplayName()) + ": " + getFinalArg(args, 2)); + } user.sendMessage(Util.i18n("mailSent")); return; } diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandme.java b/Essentials/src/com/earth2me/essentials/commands/Commandme.java index d338a102a..098558f11 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandme.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandme.java @@ -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); } } diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandmsg.java b/Essentials/src/com/earth2me/essentials/commands/Commandmsg.java index 8585dcef9..13ad11441 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandmsg.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandmsg.java @@ -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)); diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandr.java b/Essentials/src/com/earth2me/essentials/commands/Commandr.java index 44cd9bb0b..bc83ca82d 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandr.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandr.java @@ -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) diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandsuicide.java b/Essentials/src/com/earth2me/essentials/commands/Commandsuicide.java index a38276bae..57e5e3fd5 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandsuicide.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandsuicide.java @@ -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())); } } diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandtpa.java b/Essentials/src/com/earth2me/essentials/commands/Commandtpa.java index 34e9a36f0..77a510438 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandtpa.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandtpa.java @@ -26,10 +26,13 @@ public class Commandtpa extends EssentialsCommand throw new Exception(Util.format("teleportDisabled", p.getDisplayName())); } player.charge(this); - p.requestTeleport(player, false); - p.sendMessage(Util.format("teleportRequest", player.getDisplayName())); - p.sendMessage(Util.i18n("typeTpaccept")); - p.sendMessage(Util.i18n("typeTpdeny")); + 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())); } } diff --git a/Essentials/src/messages.properties b/Essentials/src/messages.properties index 559bb6740..ccbc8fa68 100644 --- a/Essentials/src/messages.properties +++ b/Essentials/src/messages.properties @@ -299,4 +299,6 @@ possibleWorlds = \u00a77Possible worlds are the numbers 0 through {0}. 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}.
\ No newline at end of file +onlyPlayers = Only in-game players can use {0}. +unignorePlayer = You are not ignoring player {0} anymore. +ignorePlayer = You ignore player {0} from now on.
\ No newline at end of file diff --git a/Essentials/src/messages_de.properties b/Essentials/src/messages_de.properties index 0166b21ac..276f9594d 100644 --- a/Essentials/src/messages_de.properties +++ b/Essentials/src/messages_de.properties @@ -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.
\ No newline at end of file diff --git a/Essentials/src/plugin.yml b/Essentials/src/plugin.yml index 468540769..2e813a2a5 100644 --- a/Essentials/src/plugin.yml +++ b/Essentials/src/plugin.yml @@ -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]
|