summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKHobbits <rob@khobbits.co.uk>2013-02-24 03:55:20 +0000
committerKHobbits <rob@khobbits.co.uk>2013-02-24 03:55:20 +0000
commit964bdc6d30748d843c8e510758d69838f8d29791 (patch)
treea22db04acc4b43c13bf8dff22bec20854839885c
parent3d5aa4096583bf3fcf58047cf68f0342c6c8984e (diff)
downloadEssentials-964bdc6d30748d843c8e510758d69838f8d29791.tar
Essentials-964bdc6d30748d843c8e510758d69838f8d29791.tar.gz
Essentials-964bdc6d30748d843c8e510758d69838f8d29791.tar.lz
Essentials-964bdc6d30748d843c8e510758d69838f8d29791.tar.xz
Essentials-964bdc6d30748d843c8e510758d69838f8d29791.zip
[Feature] Allow IP lookup in /seen command.
[Permission] essentials.seen.ipsearch - allows /seen <ip address>
-rw-r--r--Essentials/src/com/earth2me/essentials/Util.java9
-rw-r--r--Essentials/src/com/earth2me/essentials/commands/Commandseen.java147
-rw-r--r--Essentials/src/messages.properties3
-rw-r--r--Essentials/src/messages_cs.properties3
-rw-r--r--Essentials/src/messages_da.properties3
-rw-r--r--Essentials/src/messages_de.properties3
-rw-r--r--Essentials/src/messages_en.properties3
-rw-r--r--Essentials/src/messages_es.properties3
-rw-r--r--Essentials/src/messages_fi.properties3
-rw-r--r--Essentials/src/messages_fr.properties3
-rw-r--r--Essentials/src/messages_it.properties3
-rw-r--r--Essentials/src/messages_nl.properties3
-rw-r--r--Essentials/src/messages_pl.properties3
-rw-r--r--Essentials/src/messages_pt.properties3
-rw-r--r--Essentials/src/messages_se.properties3
15 files changed, 153 insertions, 42 deletions
diff --git a/Essentials/src/com/earth2me/essentials/Util.java b/Essentials/src/com/earth2me/essentials/Util.java
index ad24a80d8..f1d0485c3 100644
--- a/Essentials/src/com/earth2me/essentials/Util.java
+++ b/Essentials/src/com/earth2me/essentials/Util.java
@@ -692,7 +692,7 @@ public class Util
}
return message;
}
-
+
private static String blockURL(final String input)
{
if (input == null)
@@ -716,4 +716,11 @@ public class Util
{
return pattern.matcher(input).replaceAll("\u00a7$1");
}
+ private static final Pattern IPPATTERN = Pattern.compile(
+ "^([01]?\\d\\d?|2[0-4]\\d|25[0-5])\\.([01]?\\d\\d?|2[0-4]\\d|25[0-5])\\." +
+ "([01]?\\d\\d?|2[0-4]\\d|25[0-5])\\.([01]?\\d\\d?|2[0-4]\\d|25[0-5])$");
+
+ public static boolean validIP(String ipAddress) {
+ return IPPATTERN.matcher(ipAddress).matches();
+ }
}
diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandseen.java b/Essentials/src/com/earth2me/essentials/commands/Commandseen.java
index f5bf1bc0c..0b6cd6e46 100644
--- a/Essentials/src/com/earth2me/essentials/commands/Commandseen.java
+++ b/Essentials/src/com/earth2me/essentials/commands/Commandseen.java
@@ -2,7 +2,10 @@ package com.earth2me.essentials.commands;
import static com.earth2me.essentials.I18n._;
import com.earth2me.essentials.User;
+import com.earth2me.essentials.UserMap;
import com.earth2me.essentials.Util;
+import java.util.ArrayList;
+import java.util.List;
import org.bukkit.Location;
import org.bukkit.Server;
import org.bukkit.command.CommandSender;
@@ -18,16 +21,16 @@ public class Commandseen extends EssentialsCommand
@Override
protected void run(final Server server, final CommandSender sender, final String commandLabel, final String[] args) throws Exception
{
- seen(server, sender, args, true, true);
+ seen(server, sender, args, true, true, true);
}
@Override
protected void run(final Server server, final User user, final String commandLabel, final String[] args) throws Exception
{
- seen(server, user, args, user.isAuthorized("essentials.seen.banreason"), user.isAuthorized("essentials.seen.extra"));
+ seen(server, user, args, user.isAuthorized("essentials.seen.banreason"), user.isAuthorized("essentials.seen.extra"), user.isAuthorized("essentials.seen.ipsearch"));
}
- protected void seen(final Server server, final CommandSender sender, final String[] args, final boolean showBan, final boolean extra) throws Exception
+ protected void seen(final Server server, final CommandSender sender, final String[] args, final boolean showBan, final boolean extra, final boolean ipLookup) throws Exception
{
if (args.length < 1)
{
@@ -36,60 +39,122 @@ public class Commandseen extends EssentialsCommand
try
{
User user = getPlayer(server, args, 0);
- user.setDisplayNick();
- sender.sendMessage(_("seenOnline", user.getDisplayName(), Util.formatDateDiff(user.getLastLogin())));
- if (user.isAfk())
- {
- sender.sendMessage(_("whoisAFK", _("true")));
- }
- if (user.isJailed())
- {
- sender.sendMessage(_("whoisJail", (user.getJailTimeout() > 0
- ? Util.formatDateDiff(user.getJailTimeout())
- : _("true"))));
- }
- if (user.isMuted())
- {
- sender.sendMessage(_("whoisMuted", (user.getMuteTimeout() > 0
- ? Util.formatDateDiff(user.getMuteTimeout())
- : _("true"))));
- }
- if (extra)
- {
- sender.sendMessage(_("whoisIPAddress", user.getAddress().getAddress().toString()));
- }
+ seenOnline(server, sender, user, showBan, extra);
}
catch (NoSuchFieldException e)
{
User player = ess.getOfflineUser(args[0]);
if (player == null)
{
- throw new Exception(_("playerNotFound"));
+ if (ipLookup && Util.validIP(args[0]))
+ {
+ seenIP(server, sender, args[0]);
+ return;
+ }
+ else
+ {
+ throw new Exception(_("playerNotFound"));
+ }
}
- player.setDisplayNick();
- if (player.getLastLogout() > 0)
+ seenOffline(server, sender, player, showBan, extra);
+ }
+ }
+
+ private void seenOnline(final Server server, final CommandSender sender, final User user, final boolean showBan, final boolean extra) throws Exception
+ {
+
+ user.setDisplayNick();
+ sender.sendMessage(_("seenOnline", user.getDisplayName(), Util.formatDateDiff(user.getLastLogin())));
+ if (user.isAfk())
+ {
+ sender.sendMessage(_("whoisAFK", _("true")));
+ }
+ if (user.isJailed())
+ {
+ sender.sendMessage(_("whoisJail", (user.getJailTimeout() > 0
+ ? Util.formatDateDiff(user.getJailTimeout())
+ : _("true"))));
+ }
+ if (user.isMuted())
+ {
+ sender.sendMessage(_("whoisMuted", (user.getMuteTimeout() > 0
+ ? Util.formatDateDiff(user.getMuteTimeout())
+ : _("true"))));
+ }
+ if (extra)
+ {
+ sender.sendMessage(_("whoisIPAddress", user.getAddress().getAddress().toString()));
+ }
+ }
+
+ private void seenOffline(final Server server, final CommandSender sender, User player, final boolean showBan, final boolean extra) throws Exception
+ {
+ player.setDisplayNick();
+ if (player.getLastLogout() > 0)
+ {
+ sender.sendMessage(_("seenOffline", player.getName(), Util.formatDateDiff(player.getLastLogout())));
+ }
+ else
+ {
+ sender.sendMessage(_("userUnknown", player.getName()));
+ }
+ if (player.isBanned())
+ {
+ sender.sendMessage(_("whoisBanned", showBan ? player.getBanReason() : _("true")));
+ }
+ if (extra)
+ {
+ if (!player.getLastLoginAddress().isEmpty())
{
- sender.sendMessage(_("seenOffline", player.getName(), Util.formatDateDiff(player.getLastLogout())));
+ sender.sendMessage(_("whoisIPAddress", player.getLastLoginAddress()));
}
- else {
- sender.sendMessage(_("userUnknown", player.getName()));
- }
- if (player.isBanned())
+ final Location loc = player.getLogoutLocation();
+ if (loc != null)
{
- sender.sendMessage(_("whoisBanned", showBan ? player.getBanReason() : _("true")));
+ sender.sendMessage(_("whoisLocation", loc.getWorld().getName(), loc.getBlockX(), loc.getBlockY(), loc.getBlockZ()));
}
- if (extra)
+ }
+ }
+
+ private void seenIP(final Server server, final CommandSender sender, final String ipAddress) throws Exception
+ {
+ final UserMap userMap = ess.getUserMap();
+ sender.sendMessage(_("runningPlayerMatch", ipAddress));
+
+ ess.runTaskAsynchronously(new Runnable()
+ {
+ @Override
+ public void run()
{
- if (!player.getLastLoginAddress().isEmpty())
+ final List<String> matches = new ArrayList<String>();
+ for (final String u : userMap.getAllUniqueUsers())
+ {
+ final User user = ess.getUserMap().getUser(u);
+ if (user == null)
+ {
+ continue;
+ }
+
+ final String uIPAddress = user.getLastLoginAddress();
+
+ if (!uIPAddress.isEmpty() && uIPAddress.equalsIgnoreCase(ipAddress))
+ {
+ matches.add(user.getName());
+ }
+ }
+
+ if (matches.size() > 0)
{
- sender.sendMessage(_("whoisIPAddress", player.getLastLoginAddress()));
+ sender.sendMessage(_("matchingIPAddress"));
+ sender.sendMessage(Util.joinList(matches));
}
- final Location loc = player.getLogoutLocation();
- if (loc != null)
+ else
{
- sender.sendMessage(_("whoisLocation", loc.getWorld().getName(), loc.getBlockX(), loc.getBlockY(), loc.getBlockZ()));
+ sender.sendMessage(_("noMatchingPlayers"));
}
+
}
- }
+ });
+
}
}
diff --git a/Essentials/src/messages.properties b/Essentials/src/messages.properties
index 227acfbc0..a3e355687 100644
--- a/Essentials/src/messages.properties
+++ b/Essentials/src/messages.properties
@@ -506,3 +506,6 @@ bedMissing=\u00a74Your bed is either unset, missing or blocked.
bedSet=\u00a76Bed spawn set!
kitGiveTo=\u00a76Giving kit\u00a7c {0}\u00a76 to {1}\u00a7.
kitReceive=\u00a76Received kit\u00a7c {0}\u00a76.
+noMatchingPlayers=\u00a76No matching players found.
+matchingIPAddress=\u00a76The following players previously logged in from that IP address:
+runningPlayerMatch=\u00a76Running search for players matching ''\u00a7c{0}\u00a76'' (this could take a little while)
diff --git a/Essentials/src/messages_cs.properties b/Essentials/src/messages_cs.properties
index 229022490..261bd9c7d 100644
--- a/Essentials/src/messages_cs.properties
+++ b/Essentials/src/messages_cs.properties
@@ -509,3 +509,6 @@ bedMissing=\u00a74Your bed is either unset, missing or blocked.
bedSet=\u00a76Bed spawn set!
kitGiveTo=\u00a76Giving kit\u00a7c {0}\u00a76 to {1}\u00a7.
kitReceive=\u00a76Received kit\u00a7c {0}\u00a76.
+noMatchingPlayers=\u00a76No matching players found.
+matchingIPAddress=\u00a76The following players previously logged in from that IP address:
+runningPlayerMatch=\u00a76Running search for players matching ''\u00a7c{0}\u00a76'' (this could take a little while)
diff --git a/Essentials/src/messages_da.properties b/Essentials/src/messages_da.properties
index ba420af02..c51202c64 100644
--- a/Essentials/src/messages_da.properties
+++ b/Essentials/src/messages_da.properties
@@ -506,3 +506,6 @@ bedMissing=\u00a74Your bed is either unset, missing or blocked.
bedSet=\u00a76Bed spawn set!
kitGiveTo=\u00a76Giving kit\u00a7c {0}\u00a76 to {1}\u00a7.
kitReceive=\u00a76Received kit\u00a7c {0}\u00a76.
+noMatchingPlayers=\u00a76No matching players found.
+matchingIPAddress=\u00a76The following players previously logged in from that IP address:
+runningPlayerMatch=\u00a76Running search for players matching ''\u00a7c{0}\u00a76'' (this could take a little while)
diff --git a/Essentials/src/messages_de.properties b/Essentials/src/messages_de.properties
index bf593d93f..4fdd96fc8 100644
--- a/Essentials/src/messages_de.properties
+++ b/Essentials/src/messages_de.properties
@@ -506,3 +506,6 @@ bedMissing=\u00a74Your bed is either unset, missing or blocked.
bedSet=\u00a76Bed spawn set!
kitGiveTo=\u00a76Giving kit\u00a7c {0}\u00a76 to {1}\u00a7.
kitReceive=\u00a76Received kit\u00a7c {0}\u00a76.
+noMatchingPlayers=\u00a76No matching players found.
+matchingIPAddress=\u00a76The following players previously logged in from that IP address:
+runningPlayerMatch=\u00a76Running search for players matching ''\u00a7c{0}\u00a76'' (this could take a little while)
diff --git a/Essentials/src/messages_en.properties b/Essentials/src/messages_en.properties
index 8f6b510e9..6c0091bfe 100644
--- a/Essentials/src/messages_en.properties
+++ b/Essentials/src/messages_en.properties
@@ -507,3 +507,6 @@ bedMissing=\u00a74Your bed is either unset, missing or blocked.
bedSet=\u00a76Bed spawn set!
kitGiveTo=\u00a76Giving kit\u00a7c {0}\u00a76 to {1}\u00a7.
kitReceive=\u00a76Received kit\u00a7c {0}\u00a76.
+noMatchingPlayers=\u00a76No matching players found.
+matchingIPAddress=\u00a76The following players previously logged in from that IP address:
+runningPlayerMatch=\u00a76Running search for players matching ''\u00a7c{0}\u00a76'' (this could take a little while)
diff --git a/Essentials/src/messages_es.properties b/Essentials/src/messages_es.properties
index a764eca24..29c169494 100644
--- a/Essentials/src/messages_es.properties
+++ b/Essentials/src/messages_es.properties
@@ -506,3 +506,6 @@ bedMissing=\u00a74Your bed is either unset, missing or blocked.
bedSet=\u00a76Bed spawn set!
kitGiveTo=\u00a76Giving kit\u00a7c {0}\u00a76 to {1}\u00a7.
kitReceive=\u00a76Received kit\u00a7c {0}\u00a76.
+noMatchingPlayers=\u00a76No matching players found.
+matchingIPAddress=\u00a76The following players previously logged in from that IP address:
+runningPlayerMatch=\u00a76Running search for players matching ''\u00a7c{0}\u00a76'' (this could take a little while)
diff --git a/Essentials/src/messages_fi.properties b/Essentials/src/messages_fi.properties
index 66f6ff6c3..03b972c76 100644
--- a/Essentials/src/messages_fi.properties
+++ b/Essentials/src/messages_fi.properties
@@ -506,3 +506,6 @@ bedMissing=\u00a74Your bed is either unset, missing or blocked.
bedSet=\u00a76Bed spawn set!
kitGiveTo=\u00a76Giving kit\u00a7c {0}\u00a76 to {1}\u00a7.
kitReceive=\u00a76Received kit\u00a7c {0}\u00a76.
+noMatchingPlayers=\u00a76No matching players found.
+matchingIPAddress=\u00a76The following players previously logged in from that IP address:
+runningPlayerMatch=\u00a76Running search for players matching ''\u00a7c{0}\u00a76'' (this could take a little while)
diff --git a/Essentials/src/messages_fr.properties b/Essentials/src/messages_fr.properties
index 4db002785..8030ab3bc 100644
--- a/Essentials/src/messages_fr.properties
+++ b/Essentials/src/messages_fr.properties
@@ -506,3 +506,6 @@ bedMissing=\u00a74Your bed is either unset, missing or blocked.
bedSet=\u00a76Bed spawn set!
kitGiveTo=\u00a76Giving kit\u00a7c {0}\u00a76 to {1}\u00a7.
kitReceive=\u00a76Received kit\u00a7c {0}\u00a76.
+noMatchingPlayers=\u00a76No matching players found.
+matchingIPAddress=\u00a76The following players previously logged in from that IP address:
+runningPlayerMatch=\u00a76Running search for players matching ''\u00a7c{0}\u00a76'' (this could take a little while)
diff --git a/Essentials/src/messages_it.properties b/Essentials/src/messages_it.properties
index 5bae0171c..0a5fc41b3 100644
--- a/Essentials/src/messages_it.properties
+++ b/Essentials/src/messages_it.properties
@@ -506,3 +506,6 @@ bedMissing=\u00a74Your bed is either unset, missing or blocked.
bedSet=\u00a76Bed spawn set!
kitGiveTo=\u00a76Giving kit\u00a7c {0}\u00a76 to {1}\u00a7.
kitReceive=\u00a76Received kit\u00a7c {0}\u00a76.
+noMatchingPlayers=\u00a76No matching players found.
+matchingIPAddress=\u00a76The following players previously logged in from that IP address:
+runningPlayerMatch=\u00a76Running search for players matching ''\u00a7c{0}\u00a76'' (this could take a little while)
diff --git a/Essentials/src/messages_nl.properties b/Essentials/src/messages_nl.properties
index a7c814498..6327984ad 100644
--- a/Essentials/src/messages_nl.properties
+++ b/Essentials/src/messages_nl.properties
@@ -506,3 +506,6 @@ bedMissing=\u00a74Your bed is either unset, missing or blocked.
bedSet=\u00a76Bed spawn set!
kitGiveTo=\u00a76Giving kit\u00a7c {0}\u00a76 to {1}\u00a7.
kitReceive=\u00a76Received kit\u00a7c {0}\u00a76.
+noMatchingPlayers=\u00a76No matching players found.
+matchingIPAddress=\u00a76The following players previously logged in from that IP address:
+runningPlayerMatch=\u00a76Running search for players matching ''\u00a7c{0}\u00a76'' (this could take a little while)
diff --git a/Essentials/src/messages_pl.properties b/Essentials/src/messages_pl.properties
index fa75f32e5..fa5ab6541 100644
--- a/Essentials/src/messages_pl.properties
+++ b/Essentials/src/messages_pl.properties
@@ -506,3 +506,6 @@ bedMissing=\u00a74Twoje lozko nie jest ustawione, lub jest zablokowane.
bedSet=\u00a77Spawn w lozku ustawiony!
kitGiveTo=\u00a74{1} \u00a77otrzymal zestaw\u00a7c {0}\u00a77.
kitReceive=\u00a77Otrzymales zestaw\u00a7c {0}\u00a77.
+noMatchingPlayers=\u00a76No matching players found.
+matchingIPAddress=\u00a76The following players previously logged in from that IP address:
+runningPlayerMatch=\u00a76Running search for players matching ''\u00a7c{0}\u00a76'' (this could take a little while)
diff --git a/Essentials/src/messages_pt.properties b/Essentials/src/messages_pt.properties
index 86ee24189..1027a40d0 100644
--- a/Essentials/src/messages_pt.properties
+++ b/Essentials/src/messages_pt.properties
@@ -506,3 +506,6 @@ bedMissing=\u00a74Your bed is either unset, missing or blocked.
bedSet=\u00a76Bed spawn set!
kitGiveTo=\u00a76Giving kit\u00a7c {0}\u00a76 to {1}\u00a7.
kitReceive=\u00a76Received kit\u00a7c {0}\u00a76.
+noMatchingPlayers=\u00a76No matching players found.
+matchingIPAddress=\u00a76The following players previously logged in from that IP address:
+runningPlayerMatch=\u00a76Running search for players matching ''\u00a7c{0}\u00a76'' (this could take a little while)
diff --git a/Essentials/src/messages_se.properties b/Essentials/src/messages_se.properties
index 8f0d5f944..ffb0ed14e 100644
--- a/Essentials/src/messages_se.properties
+++ b/Essentials/src/messages_se.properties
@@ -506,3 +506,6 @@ bedMissing=\u00a74Your bed is either unset, missing or blocked.
bedSet=\u00a76Bed spawn set!
kitGiveTo=\u00a76Giving kit\u00a7c {0}\u00a76 to {1}\u00a7.
kitReceive=\u00a76Received kit\u00a7c {0}\u00a76.
+noMatchingPlayers=\u00a76No matching players found.
+matchingIPAddress=\u00a76The following players previously logged in from that IP address:
+runningPlayerMatch=\u00a76Running search for players matching ''\u00a7c{0}\u00a76'' (this could take a little while)