summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKHobbits <rob@khobbits.co.uk>2013-06-16 01:07:16 +0100
committerKHobbits <rob@khobbits.co.uk>2013-06-16 01:07:16 +0100
commitaa6d85eacc6e8e53c2b43a633c0c8f0a61031619 (patch)
tree5cf359d249ce6d899f8bfaab9b4e3da1cd044a1a
parentf5986194aac7db1737c61d54fbce1a4f88b7c9d9 (diff)
downloadEssentials-aa6d85eacc6e8e53c2b43a633c0c8f0a61031619.tar
Essentials-aa6d85eacc6e8e53c2b43a633c0c8f0a61031619.tar.gz
Essentials-aa6d85eacc6e8e53c2b43a633c0c8f0a61031619.tar.lz
Essentials-aa6d85eacc6e8e53c2b43a633c0c8f0a61031619.tar.xz
Essentials-aa6d85eacc6e8e53c2b43a633c0c8f0a61031619.zip
Cleanup broadcast, allow limited keywords in.
-rw-r--r--Essentials/src/com/earth2me/essentials/Essentials.java24
-rw-r--r--Essentials/src/com/earth2me/essentials/IEssentials.java4
-rw-r--r--Essentials/src/com/earth2me/essentials/commands/Commandban.java2
-rw-r--r--Essentials/src/com/earth2me/essentials/commands/Commandbanip.java2
-rw-r--r--Essentials/src/com/earth2me/essentials/commands/Commandbroadcast.java14
-rw-r--r--Essentials/src/com/earth2me/essentials/commands/Commandkick.java2
-rw-r--r--Essentials/src/com/earth2me/essentials/commands/Commandmute.java2
-rw-r--r--Essentials/src/com/earth2me/essentials/commands/Commandtempban.java2
-rw-r--r--Essentials/src/com/earth2me/essentials/commands/Commandunban.java2
-rw-r--r--Essentials/src/com/earth2me/essentials/commands/Commandunbanip.java2
-rw-r--r--Essentials/src/com/earth2me/essentials/textreader/KeywordReplacer.java33
11 files changed, 59 insertions, 30 deletions
diff --git a/Essentials/src/com/earth2me/essentials/Essentials.java b/Essentials/src/com/earth2me/essentials/Essentials.java
index db46f166e..4981897e1 100644
--- a/Essentials/src/com/earth2me/essentials/Essentials.java
+++ b/Essentials/src/com/earth2me/essentials/Essentials.java
@@ -31,6 +31,9 @@ import com.earth2me.essentials.register.payment.Methods;
import com.earth2me.essentials.signs.SignBlockListener;
import com.earth2me.essentials.signs.SignEntityListener;
import com.earth2me.essentials.signs.SignPlayerListener;
+import com.earth2me.essentials.textreader.IText;
+import com.earth2me.essentials.textreader.KeywordReplacer;
+import com.earth2me.essentials.textreader.SimpleTextInput;
import com.earth2me.essentials.utils.DateUtil;
import java.io.File;
import java.io.FileReader;
@@ -614,27 +617,32 @@ public class Essentials extends JavaPlugin implements IEssentials
}
@Override
+ public int broadcastMessage(final String message)
+ {
+ return broadcastMessage(null, null, message);
+ }
+
+ @Override
public int broadcastMessage(final IUser sender, final String message)
{
return broadcastMessage(sender, null, message);
}
@Override
- public int broadcastMessage(final CommandSender sender, final String permission, final String message)
+ public int broadcastMessage(final String permission, final String message)
{
return broadcastMessage(null, permission, message);
}
private int broadcastMessage(final IUser sender, final String permission, final String message)
{
- if (sender == null && permission == null)
- {
- return getServer().broadcastMessage(message);
- }
if (sender != null && sender.isHidden())
{
return 0;
}
+
+ final IText input = new SimpleTextInput(message);
+
final Player[] players = getServer().getOnlinePlayers();
for (Player player : players)
@@ -643,7 +651,11 @@ public class Essentials extends JavaPlugin implements IEssentials
if ((permission == null && (sender == null || !user.isIgnoredPlayer(sender)))
|| (permission != null && user.isAuthorized(permission)))
{
- player.sendMessage(message);
+ final IText output = new KeywordReplacer(input, player, this, false);
+ for (String messageText : output.getLines())
+ {
+ player.sendMessage(messageText);
+ }
}
}
diff --git a/Essentials/src/com/earth2me/essentials/IEssentials.java b/Essentials/src/com/earth2me/essentials/IEssentials.java
index fd5e39bcd..88dd81c46 100644
--- a/Essentials/src/com/earth2me/essentials/IEssentials.java
+++ b/Essentials/src/com/earth2me/essentials/IEssentials.java
@@ -30,9 +30,11 @@ public interface IEssentials extends Plugin
World getWorld(String name);
+ int broadcastMessage(String message);
+
int broadcastMessage(IUser sender, String message);
- int broadcastMessage(CommandSender sender, String permission, String message);
+ int broadcastMessage(String permission, String message);
ISettings getSettings();
diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandban.java b/Essentials/src/com/earth2me/essentials/commands/Commandban.java
index 260e68e03..0cf353094 100644
--- a/Essentials/src/com/earth2me/essentials/commands/Commandban.java
+++ b/Essentials/src/com/earth2me/essentials/commands/Commandban.java
@@ -75,6 +75,6 @@ public class Commandban extends EssentialsCommand
sender.sendMessage(_("userUnknown", user.getName()));
}
- ess.broadcastMessage(sender, "essentials.ban.notify", _("playerBanned", senderName, user.getName(), banReason));
+ ess.broadcastMessage("essentials.ban.notify", _("playerBanned", senderName, user.getName(), banReason));
}
}
diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandbanip.java b/Essentials/src/com/earth2me/essentials/commands/Commandbanip.java
index e1b861cb5..e8ac16bdb 100644
--- a/Essentials/src/com/earth2me/essentials/commands/Commandbanip.java
+++ b/Essentials/src/com/earth2me/essentials/commands/Commandbanip.java
@@ -53,6 +53,6 @@ public class Commandbanip extends EssentialsCommand
ess.getServer().banIP(ipAddress);
server.getLogger().log(Level.INFO, _("playerBanIpAddress", senderName, ipAddress));
- ess.broadcastMessage(sender, "essentials.ban.notify", _("playerBanIpAddress", senderName, ipAddress));
+ ess.broadcastMessage("essentials.ban.notify", _("playerBanIpAddress", senderName, ipAddress));
}
}
diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandbroadcast.java b/Essentials/src/com/earth2me/essentials/commands/Commandbroadcast.java
index e54866452..2f9bea293 100644
--- a/Essentials/src/com/earth2me/essentials/commands/Commandbroadcast.java
+++ b/Essentials/src/com/earth2me/essentials/commands/Commandbroadcast.java
@@ -17,22 +17,22 @@ public class Commandbroadcast extends EssentialsCommand
@Override
public void run(final Server server, final User user, final String commandLabel, final String[] args) throws Exception
{
- if (args.length < 1)
- {
- throw new NotEnoughArgumentsException();
- }
-
- ess.broadcastMessage(null, _("broadcast", FormatUtil.replaceFormat(getFinalArg(args, 0)), user.getDisplayName()));
+ sendBroadcast(user.getDisplayName(), args);
}
@Override
public void run(final Server server, final CommandSender sender, final String commandLabel, final String[] args) throws Exception
{
+ sendBroadcast(sender.getName(), args);
+ }
+
+ private void sendBroadcast(final String name, final String[] args) throws NotEnoughArgumentsException
+ {
if (args.length < 1)
{
throw new NotEnoughArgumentsException();
}
- ess.broadcastMessage(null, _("broadcast", FormatUtil.replaceFormat(getFinalArg(args, 0)), sender.getName()));
+ ess.broadcastMessage(_("broadcast", FormatUtil.replaceFormat(getFinalArg(args, 0)), name));
}
}
diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandkick.java b/Essentials/src/com/earth2me/essentials/commands/Commandkick.java
index d4a46b9ef..3825d7865 100644
--- a/Essentials/src/com/earth2me/essentials/commands/Commandkick.java
+++ b/Essentials/src/com/earth2me/essentials/commands/Commandkick.java
@@ -47,6 +47,6 @@ public class Commandkick extends EssentialsCommand
final String senderName = sender instanceof Player ? ((Player)sender).getDisplayName() : Console.NAME;
server.getLogger().log(Level.INFO, _("playerKicked", senderName, target.getName(), kickReason));
- ess.broadcastMessage(sender, "essentials.kick.notify", _("playerKicked", senderName, target.getName(), kickReason));
+ ess.broadcastMessage("essentials.kick.notify", _("playerKicked", senderName, target.getName(), kickReason));
}
}
diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandmute.java b/Essentials/src/com/earth2me/essentials/commands/Commandmute.java
index a2b8ae20e..7777e4a5a 100644
--- a/Essentials/src/com/earth2me/essentials/commands/Commandmute.java
+++ b/Essentials/src/com/earth2me/essentials/commands/Commandmute.java
@@ -54,7 +54,7 @@ public class Commandmute extends EssentialsCommand
sender.sendMessage(_("mutedPlayer", player.getDisplayName()));
player.sendMessage(_("playerMuted"));
}
- ess.broadcastMessage(sender, "essentials.mute.notify", _("muteNotify", sender.getName(), player.getName()));
+ ess.broadcastMessage("essentials.mute.notify", _("muteNotify", sender.getName(), player.getName()));
}
else
{
diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandtempban.java b/Essentials/src/com/earth2me/essentials/commands/Commandtempban.java
index 3a1be66d9..911c8c96e 100644
--- a/Essentials/src/com/earth2me/essentials/commands/Commandtempban.java
+++ b/Essentials/src/com/earth2me/essentials/commands/Commandtempban.java
@@ -60,6 +60,6 @@ public class Commandtempban extends EssentialsCommand
user.setBanned(true);
user.kickPlayer(banReason);
- ess.broadcastMessage(sender, "essentials.ban.notify", _("playerBanned", senderName, user.getName(), banReason));
+ ess.broadcastMessage("essentials.ban.notify", _("playerBanned", senderName, user.getName(), banReason));
}
}
diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandunban.java b/Essentials/src/com/earth2me/essentials/commands/Commandunban.java
index e583b4b44..49ddd0b97 100644
--- a/Essentials/src/com/earth2me/essentials/commands/Commandunban.java
+++ b/Essentials/src/com/earth2me/essentials/commands/Commandunban.java
@@ -46,6 +46,6 @@ public class Commandunban extends EssentialsCommand
final String senderName = sender instanceof Player ? ((Player)sender).getDisplayName() : Console.NAME;
server.getLogger().log(Level.INFO, _("playerUnbanned", senderName, name));
- ess.broadcastMessage(sender, "essentials.ban.notify", _("playerUnbanned", senderName, name));
+ ess.broadcastMessage("essentials.ban.notify", _("playerUnbanned", senderName, name));
}
}
diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandunbanip.java b/Essentials/src/com/earth2me/essentials/commands/Commandunbanip.java
index 2a37916cf..8d6c5909d 100644
--- a/Essentials/src/com/earth2me/essentials/commands/Commandunbanip.java
+++ b/Essentials/src/com/earth2me/essentials/commands/Commandunbanip.java
@@ -52,6 +52,6 @@ public class Commandunbanip extends EssentialsCommand
final String senderName = sender instanceof Player ? ((Player)sender).getDisplayName() : Console.NAME;
server.getLogger().log(Level.INFO, _("playerUnbanIpAddress", senderName, ipAddress));
- ess.broadcastMessage(sender, "essentials.ban.notify", _("playerUnbanIpAddress", senderName, ipAddress));
+ ess.broadcastMessage("essentials.ban.notify", _("playerUnbanIpAddress", senderName, ipAddress));
}
}
diff --git a/Essentials/src/com/earth2me/essentials/textreader/KeywordReplacer.java b/Essentials/src/com/earth2me/essentials/textreader/KeywordReplacer.java
index c3790414a..94882454c 100644
--- a/Essentials/src/com/earth2me/essentials/textreader/KeywordReplacer.java
+++ b/Essentials/src/com/earth2me/essentials/textreader/KeywordReplacer.java
@@ -20,12 +20,23 @@ public class KeywordReplacer implements IText
private final transient IText input;
private final transient List<String> replaced;
private final transient IEssentials ess;
+ private final transient boolean extended;
public KeywordReplacer(final IText input, final CommandSender sender, final IEssentials ess)
{
this.input = input;
this.replaced = new ArrayList<String>(this.input.getLines().size());
this.ess = ess;
+ this.extended = true;
+ replaceKeywords(sender);
+ }
+
+ public KeywordReplacer(final IText input, final CommandSender sender, final IEssentials ess, final boolean extended)
+ {
+ this.input = input;
+ this.replaced = new ArrayList<String>(this.input.getLines().size());
+ this.ess = ess;
+ this.extended = extended;
replaceKeywords(sender);
}
@@ -34,15 +45,13 @@ public class KeywordReplacer implements IText
String displayName, ipAddress, balance, mails, world;
String worlds, online, unique, playerlist, date, time;
String worldTime12, worldTime24, worldDate, plugins;
- String userName, address, version;
+ String userName, version;
if (sender instanceof Player)
{
final User user = ess.getUser(sender);
user.setDisplayNick();
- displayName = user.getDisplayName();
- userName = user.getName();
+ displayName = user.getDisplayName();
ipAddress = user.getAddress() == null || user.getAddress().getAddress() == null ? "" : user.getAddress().getAddress().toString();
- address = user.getAddress() == null ? "" : user.getAddress().toString();
balance = NumberUtil.displayCurrency(user.getMoney(), ess);
mails = Integer.toString(user.getMails().size());
world = user.getLocation() == null || user.getLocation().getWorld() == null ? "" : user.getLocation().getWorld().getName();
@@ -55,6 +64,7 @@ public class KeywordReplacer implements IText
displayName = ipAddress = balance = mails = world = worldTime12 = worldTime24 = worldDate = "";
}
+ userName = sender.getName();
int playerHidden = 0;
for (Player p : ess.getServer().getOnlinePlayers())
{
@@ -114,9 +124,7 @@ public class KeywordReplacer implements IText
line = line.replace("{PLAYER}", displayName);
line = line.replace("{DISPLAYNAME}", displayName);
- line = line.replace("{USERNAME}", displayName);
- line = line.replace("{IP}", ipAddress);
- line = line.replace("{ADDRESS}", ipAddress);
+ line = line.replace("{USERNAME}", userName);
line = line.replace("{BALANCE}", balance);
line = line.replace("{MAILS}", mails);
line = line.replace("{WORLD}", world);
@@ -129,8 +137,15 @@ public class KeywordReplacer implements IText
line = line.replace("{WORLDTIME12}", worldTime12);
line = line.replace("{WORLDTIME24}", worldTime24);
line = line.replace("{WORLDDATE}", worldDate);
- line = line.replace("{PLUGINS}", plugins);
- line = line.replace("{VERSION}", version);
+
+ if (extended)
+ {
+ line = line.replace("{IP}", ipAddress);
+ line = line.replace("{ADDRESS}", ipAddress);
+ line = line.replace("{PLUGINS}", plugins);
+ line = line.replace("{VERSION}", version);
+ }
+
replaced.add(line);
}
}