mirror of
https://github.com/EssentialsX/Essentials.git
synced 2025-02-10 09:21:25 +01:00
[Feature] Allow IP lookup in /seen command.
[Permission] essentials.seen.ipsearch - allows /seen <ip address>
This commit is contained in:
parent
3d5aa40965
commit
964bdc6d30
@ -716,4 +716,11 @@ public class Util
|
|||||||
{
|
{
|
||||||
return pattern.matcher(input).replaceAll("\u00a7$1");
|
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();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,7 +2,10 @@ package com.earth2me.essentials.commands;
|
|||||||
|
|
||||||
import static com.earth2me.essentials.I18n._;
|
import static com.earth2me.essentials.I18n._;
|
||||||
import com.earth2me.essentials.User;
|
import com.earth2me.essentials.User;
|
||||||
|
import com.earth2me.essentials.UserMap;
|
||||||
import com.earth2me.essentials.Util;
|
import com.earth2me.essentials.Util;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.Server;
|
import org.bukkit.Server;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
@ -18,16 +21,16 @@ public class Commandseen extends EssentialsCommand
|
|||||||
@Override
|
@Override
|
||||||
protected void run(final Server server, final CommandSender sender, final String commandLabel, final String[] args) throws Exception
|
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
|
@Override
|
||||||
protected void run(final Server server, final User user, final String commandLabel, final String[] args) throws Exception
|
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)
|
if (args.length < 1)
|
||||||
{
|
{
|
||||||
@ -36,6 +39,30 @@ public class Commandseen extends EssentialsCommand
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
User user = getPlayer(server, args, 0);
|
User user = getPlayer(server, args, 0);
|
||||||
|
seenOnline(server, sender, user, showBan, extra);
|
||||||
|
}
|
||||||
|
catch (NoSuchFieldException e)
|
||||||
|
{
|
||||||
|
User player = ess.getOfflineUser(args[0]);
|
||||||
|
if (player == null)
|
||||||
|
{
|
||||||
|
if (ipLookup && Util.validIP(args[0]))
|
||||||
|
{
|
||||||
|
seenIP(server, sender, args[0]);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
throw new Exception(_("playerNotFound"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
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();
|
user.setDisplayNick();
|
||||||
sender.sendMessage(_("seenOnline", user.getDisplayName(), Util.formatDateDiff(user.getLastLogin())));
|
sender.sendMessage(_("seenOnline", user.getDisplayName(), Util.formatDateDiff(user.getLastLogin())));
|
||||||
if (user.isAfk())
|
if (user.isAfk())
|
||||||
@ -59,19 +86,16 @@ public class Commandseen extends EssentialsCommand
|
|||||||
sender.sendMessage(_("whoisIPAddress", user.getAddress().getAddress().toString()));
|
sender.sendMessage(_("whoisIPAddress", user.getAddress().getAddress().toString()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (NoSuchFieldException e)
|
|
||||||
|
private void seenOffline(final Server server, final CommandSender sender, User player, final boolean showBan, final boolean extra) throws Exception
|
||||||
{
|
{
|
||||||
User player = ess.getOfflineUser(args[0]);
|
|
||||||
if (player == null)
|
|
||||||
{
|
|
||||||
throw new Exception(_("playerNotFound"));
|
|
||||||
}
|
|
||||||
player.setDisplayNick();
|
player.setDisplayNick();
|
||||||
if (player.getLastLogout() > 0)
|
if (player.getLastLogout() > 0)
|
||||||
{
|
{
|
||||||
sender.sendMessage(_("seenOffline", player.getName(), Util.formatDateDiff(player.getLastLogout())));
|
sender.sendMessage(_("seenOffline", player.getName(), Util.formatDateDiff(player.getLastLogout())));
|
||||||
}
|
}
|
||||||
else {
|
else
|
||||||
|
{
|
||||||
sender.sendMessage(_("userUnknown", player.getName()));
|
sender.sendMessage(_("userUnknown", player.getName()));
|
||||||
}
|
}
|
||||||
if (player.isBanned())
|
if (player.isBanned())
|
||||||
@ -91,5 +115,46 @@ public class Commandseen extends EssentialsCommand
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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()
|
||||||
|
{
|
||||||
|
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(_("matchingIPAddress"));
|
||||||
|
sender.sendMessage(Util.joinList(matches));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
sender.sendMessage(_("noMatchingPlayers"));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -506,3 +506,6 @@ bedMissing=\u00a74Your bed is either unset, missing or blocked.
|
|||||||
bedSet=\u00a76Bed spawn set!
|
bedSet=\u00a76Bed spawn set!
|
||||||
kitGiveTo=\u00a76Giving kit\u00a7c {0}\u00a76 to {1}\u00a7.
|
kitGiveTo=\u00a76Giving kit\u00a7c {0}\u00a76 to {1}\u00a7.
|
||||||
kitReceive=\u00a76Received kit\u00a7c {0}\u00a76.
|
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)
|
||||||
|
@ -509,3 +509,6 @@ bedMissing=\u00a74Your bed is either unset, missing or blocked.
|
|||||||
bedSet=\u00a76Bed spawn set!
|
bedSet=\u00a76Bed spawn set!
|
||||||
kitGiveTo=\u00a76Giving kit\u00a7c {0}\u00a76 to {1}\u00a7.
|
kitGiveTo=\u00a76Giving kit\u00a7c {0}\u00a76 to {1}\u00a7.
|
||||||
kitReceive=\u00a76Received kit\u00a7c {0}\u00a76.
|
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)
|
||||||
|
@ -506,3 +506,6 @@ bedMissing=\u00a74Your bed is either unset, missing or blocked.
|
|||||||
bedSet=\u00a76Bed spawn set!
|
bedSet=\u00a76Bed spawn set!
|
||||||
kitGiveTo=\u00a76Giving kit\u00a7c {0}\u00a76 to {1}\u00a7.
|
kitGiveTo=\u00a76Giving kit\u00a7c {0}\u00a76 to {1}\u00a7.
|
||||||
kitReceive=\u00a76Received kit\u00a7c {0}\u00a76.
|
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)
|
||||||
|
@ -506,3 +506,6 @@ bedMissing=\u00a74Your bed is either unset, missing or blocked.
|
|||||||
bedSet=\u00a76Bed spawn set!
|
bedSet=\u00a76Bed spawn set!
|
||||||
kitGiveTo=\u00a76Giving kit\u00a7c {0}\u00a76 to {1}\u00a7.
|
kitGiveTo=\u00a76Giving kit\u00a7c {0}\u00a76 to {1}\u00a7.
|
||||||
kitReceive=\u00a76Received kit\u00a7c {0}\u00a76.
|
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)
|
||||||
|
@ -507,3 +507,6 @@ bedMissing=\u00a74Your bed is either unset, missing or blocked.
|
|||||||
bedSet=\u00a76Bed spawn set!
|
bedSet=\u00a76Bed spawn set!
|
||||||
kitGiveTo=\u00a76Giving kit\u00a7c {0}\u00a76 to {1}\u00a7.
|
kitGiveTo=\u00a76Giving kit\u00a7c {0}\u00a76 to {1}\u00a7.
|
||||||
kitReceive=\u00a76Received kit\u00a7c {0}\u00a76.
|
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)
|
||||||
|
@ -506,3 +506,6 @@ bedMissing=\u00a74Your bed is either unset, missing or blocked.
|
|||||||
bedSet=\u00a76Bed spawn set!
|
bedSet=\u00a76Bed spawn set!
|
||||||
kitGiveTo=\u00a76Giving kit\u00a7c {0}\u00a76 to {1}\u00a7.
|
kitGiveTo=\u00a76Giving kit\u00a7c {0}\u00a76 to {1}\u00a7.
|
||||||
kitReceive=\u00a76Received kit\u00a7c {0}\u00a76.
|
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)
|
||||||
|
@ -506,3 +506,6 @@ bedMissing=\u00a74Your bed is either unset, missing or blocked.
|
|||||||
bedSet=\u00a76Bed spawn set!
|
bedSet=\u00a76Bed spawn set!
|
||||||
kitGiveTo=\u00a76Giving kit\u00a7c {0}\u00a76 to {1}\u00a7.
|
kitGiveTo=\u00a76Giving kit\u00a7c {0}\u00a76 to {1}\u00a7.
|
||||||
kitReceive=\u00a76Received kit\u00a7c {0}\u00a76.
|
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)
|
||||||
|
@ -506,3 +506,6 @@ bedMissing=\u00a74Your bed is either unset, missing or blocked.
|
|||||||
bedSet=\u00a76Bed spawn set!
|
bedSet=\u00a76Bed spawn set!
|
||||||
kitGiveTo=\u00a76Giving kit\u00a7c {0}\u00a76 to {1}\u00a7.
|
kitGiveTo=\u00a76Giving kit\u00a7c {0}\u00a76 to {1}\u00a7.
|
||||||
kitReceive=\u00a76Received kit\u00a7c {0}\u00a76.
|
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)
|
||||||
|
@ -506,3 +506,6 @@ bedMissing=\u00a74Your bed is either unset, missing or blocked.
|
|||||||
bedSet=\u00a76Bed spawn set!
|
bedSet=\u00a76Bed spawn set!
|
||||||
kitGiveTo=\u00a76Giving kit\u00a7c {0}\u00a76 to {1}\u00a7.
|
kitGiveTo=\u00a76Giving kit\u00a7c {0}\u00a76 to {1}\u00a7.
|
||||||
kitReceive=\u00a76Received kit\u00a7c {0}\u00a76.
|
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)
|
||||||
|
@ -506,3 +506,6 @@ bedMissing=\u00a74Your bed is either unset, missing or blocked.
|
|||||||
bedSet=\u00a76Bed spawn set!
|
bedSet=\u00a76Bed spawn set!
|
||||||
kitGiveTo=\u00a76Giving kit\u00a7c {0}\u00a76 to {1}\u00a7.
|
kitGiveTo=\u00a76Giving kit\u00a7c {0}\u00a76 to {1}\u00a7.
|
||||||
kitReceive=\u00a76Received kit\u00a7c {0}\u00a76.
|
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)
|
||||||
|
@ -506,3 +506,6 @@ bedMissing=\u00a74Twoje lozko nie jest ustawione, lub jest zablokowane.
|
|||||||
bedSet=\u00a77Spawn w lozku ustawiony!
|
bedSet=\u00a77Spawn w lozku ustawiony!
|
||||||
kitGiveTo=\u00a74{1} \u00a77otrzymal zestaw\u00a7c {0}\u00a77.
|
kitGiveTo=\u00a74{1} \u00a77otrzymal zestaw\u00a7c {0}\u00a77.
|
||||||
kitReceive=\u00a77Otrzymales 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)
|
||||||
|
@ -506,3 +506,6 @@ bedMissing=\u00a74Your bed is either unset, missing or blocked.
|
|||||||
bedSet=\u00a76Bed spawn set!
|
bedSet=\u00a76Bed spawn set!
|
||||||
kitGiveTo=\u00a76Giving kit\u00a7c {0}\u00a76 to {1}\u00a7.
|
kitGiveTo=\u00a76Giving kit\u00a7c {0}\u00a76 to {1}\u00a7.
|
||||||
kitReceive=\u00a76Received kit\u00a7c {0}\u00a76.
|
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)
|
||||||
|
@ -506,3 +506,6 @@ bedMissing=\u00a74Your bed is either unset, missing or blocked.
|
|||||||
bedSet=\u00a76Bed spawn set!
|
bedSet=\u00a76Bed spawn set!
|
||||||
kitGiveTo=\u00a76Giving kit\u00a7c {0}\u00a76 to {1}\u00a7.
|
kitGiveTo=\u00a76Giving kit\u00a7c {0}\u00a76 to {1}\u00a7.
|
||||||
kitReceive=\u00a76Received kit\u00a7c {0}\u00a76.
|
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)
|
||||||
|
Loading…
Reference in New Issue
Block a user