Added /findip

This commit is contained in:
JeromSar 2013-08-12 21:35:59 +02:00
parent 259335958a
commit 0f6b053727
31 changed files with 94 additions and 55 deletions

View File

@ -1,5 +1,5 @@
#Mon, 12 Aug 2013 20:45:53 +0200 #Mon, 12 Aug 2013 21:33:34 +0200
program.VERSION=2.22 program.VERSION=2.22
program.BUILDNUM=409 program.BUILDNUM=411
program.BUILDDATE=08/12/2013 08\:45 PM program.BUILDDATE=08/12/2013 09\:33 PM

View File

@ -1,3 +1,3 @@
#Build Number for ANT. Do not edit! #Build Number for ANT. Do not edit!
#Mon Aug 12 20:45:53 CEST 2013 #Mon Aug 12 21:33:34 CEST 2013
build.number=410 build.number=412

View File

@ -41,7 +41,7 @@ public class Command_blockcmd extends TFM_Command
{ {
p = getPlayer(args[0]); p = getPlayer(args[0]);
} }
catch (CantFindPlayerException ex) catch (PlayerNotFoundException ex)
{ {
playerMsg(ex.getMessage()); playerMsg(ex.getMessage());
return true; return true;

View File

@ -26,7 +26,7 @@ public class Command_cage extends TFM_Command
{ {
p = getPlayer(args[0]); p = getPlayer(args[0]);
} }
catch (CantFindPlayerException ex) catch (PlayerNotFoundException ex)
{ {
sender.sendMessage(ex.getMessage()); sender.sendMessage(ex.getMessage());
return true; return true;

View File

@ -21,7 +21,7 @@ public class Command_cartsit extends TFM_Command
{ {
target_player = getPlayer(args[0]); target_player = getPlayer(args[0]);
} }
catch (CantFindPlayerException ex) catch (PlayerNotFoundException ex)
{ {
sender.sendMessage(ex.getMessage()); sender.sendMessage(ex.getMessage());
return true; return true;

View File

@ -58,7 +58,7 @@ public class Command_creative extends TFM_Command
{ {
p = getPlayer(args[0]); p = getPlayer(args[0]);
} }
catch (CantFindPlayerException ex) catch (PlayerNotFoundException ex)
{ {
sender.sendMessage(ex.getMessage()); sender.sendMessage(ex.getMessage());
return true; return true;

View File

@ -27,7 +27,7 @@ public class Command_doom extends TFM_Command
{ {
p = getPlayer(args[0]); p = getPlayer(args[0]);
} }
catch (CantFindPlayerException ex) catch (PlayerNotFoundException ex)
{ {
sender.sendMessage(ex.getMessage()); sender.sendMessage(ex.getMessage());
return true; return true;

View File

@ -0,0 +1,39 @@
package me.StevenLawson.TotalFreedomMod.Commands;
import me.StevenLawson.TotalFreedomMod.TFM_UserList;
import me.StevenLawson.TotalFreedomMod.TotalFreedomMod;
import org.apache.commons.lang.StringUtils;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
@CommandPermissions(level = AdminLevel.SUPER, source = SourceType.BOTH)
@CommandParameters(description = "Shows all IPs registered to a player", usage = "/<command> <player>")
public class Command_findip extends TFM_Command
{
@Override
public boolean run(CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
{
if (args.length != 1)
{
return false;
}
final Player p;
try
{
p = getPlayer(args[0]);
}
catch (PlayerNotFoundException ex)
{
playerMsg(ex.getMessage());
return true;
}
playerMsg("Player IPs: " + StringUtils.join(TFM_UserList.getInstance(TotalFreedomMod.plugin).getEntry(p).getIpAddresses(), ", "));
return true;
}
}

View File

@ -77,7 +77,7 @@ public class Command_fr extends TFM_Command
{ {
p = getPlayer(args[0]); p = getPlayer(args[0]);
} }
catch (CantFindPlayerException ex) catch (PlayerNotFoundException ex)
{ {
playerMsg(ex.getMessage(), ChatColor.RED); playerMsg(ex.getMessage(), ChatColor.RED);
return true; return true;

View File

@ -22,7 +22,7 @@ public class Command_gcmd extends TFM_Command
{ {
p = getPlayer(args[0]); p = getPlayer(args[0]);
} }
catch (CantFindPlayerException ex) catch (PlayerNotFoundException ex)
{ {
sender.sendMessage(ex.getMessage()); sender.sendMessage(ex.getMessage());
return true; return true;

View File

@ -56,7 +56,7 @@ public class Command_glist extends TFM_Command
username = p.getName(); username = p.getName();
ip_addresses.add(p.getAddress().getAddress().getHostAddress()); ip_addresses.add(p.getAddress().getAddress().getHostAddress());
} }
catch (CantFindPlayerException ex) catch (PlayerNotFoundException ex)
{ {
TFM_UserListEntry entry = TFM_UserList.getInstance(plugin).getEntry(args[1]); TFM_UserListEntry entry = TFM_UserList.getInstance(plugin).getEntry(args[1]);

View File

@ -30,7 +30,7 @@ public class Command_gtfo extends TFM_Command
{ {
p = getPlayer(args[0]); p = getPlayer(args[0]);
} }
catch (CantFindPlayerException ex) catch (PlayerNotFoundException ex)
{ {
playerMsg(ex.getMessage(), ChatColor.RED); playerMsg(ex.getMessage(), ChatColor.RED);
return true; return true;

View File

@ -81,7 +81,7 @@ public class Command_halt extends TFM_Command
{ {
p = getPlayer(args[0]); p = getPlayer(args[0]);
} }
catch (CantFindPlayerException ex) catch (PlayerNotFoundException ex)
{ {
sender.sendMessage(ex.getMessage()); sender.sendMessage(ex.getMessage());
return true; return true;

View File

@ -23,7 +23,7 @@ public class Command_lastcmd extends TFM_Command
{ {
p = getPlayer(args[0]); p = getPlayer(args[0]);
} }
catch (CantFindPlayerException ex) catch (PlayerNotFoundException ex)
{ {
playerMsg(ex.getMessage(), ChatColor.RED); playerMsg(ex.getMessage(), ChatColor.RED);
return true; return true;

View File

@ -51,7 +51,7 @@ public class Command_lockup extends TFM_Command
{ {
p = getPlayer(args[0]); p = getPlayer(args[0]);
} }
catch (CantFindPlayerException ex) catch (PlayerNotFoundException ex)
{ {
sender.sendMessage(ex.getMessage()); sender.sendMessage(ex.getMessage());
return true; return true;
@ -68,7 +68,7 @@ public class Command_lockup extends TFM_Command
{ {
p = getPlayer(args[0]); p = getPlayer(args[0]);
} }
catch (CantFindPlayerException ex) catch (PlayerNotFoundException ex)
{ {
sender.sendMessage(ex.getMessage()); sender.sendMessage(ex.getMessage());
return true; return true;

View File

@ -26,7 +26,7 @@ public class Command_orbit extends TFM_Command
{ {
p = getPlayer(args[0]); p = getPlayer(args[0]);
} }
catch (CantFindPlayerException ex) catch (PlayerNotFoundException ex)
{ {
playerMsg(ex.getMessage(), ChatColor.RED); playerMsg(ex.getMessage(), ChatColor.RED);
return true; return true;

View File

@ -62,7 +62,7 @@ public class Command_potion extends TFM_Command
{ {
target = getPlayer(args[1]); target = getPlayer(args[1]);
} }
catch (CantFindPlayerException ex) catch (PlayerNotFoundException ex)
{ {
playerMsg(ex.getMessage(), ChatColor.RED); playerMsg(ex.getMessage(), ChatColor.RED);
return true; return true;
@ -107,7 +107,7 @@ public class Command_potion extends TFM_Command
{ {
target = getPlayer(args[4]); target = getPlayer(args[4]);
} }
catch (CantFindPlayerException ex) catch (PlayerNotFoundException ex)
{ {
playerMsg(ex.getMessage(), ChatColor.RED); playerMsg(ex.getMessage(), ChatColor.RED);
return true; return true;

View File

@ -38,7 +38,7 @@ public class Command_rank extends TFM_Command
{ {
p = getPlayer(args[0]); p = getPlayer(args[0]);
} }
catch (CantFindPlayerException ex) catch (PlayerNotFoundException ex)
{ {
sender.sendMessage(ex.getMessage()); sender.sendMessage(ex.getMessage());
return true; return true;

View File

@ -58,7 +58,7 @@ public class Command_ro extends TFM_Command
{ {
target_player = getPlayer(args[2]); target_player = getPlayer(args[2]);
} }
catch (CantFindPlayerException ex) catch (PlayerNotFoundException ex)
{ {
playerMsg(ex.getMessage(), ChatColor.RED); playerMsg(ex.getMessage(), ChatColor.RED);
return true; return true;

View File

@ -60,7 +60,7 @@ public class Command_rollback extends TFM_Command
playerName = player.getName(); playerName = player.getName();
} }
} }
catch (CantFindPlayerException ex) catch (PlayerNotFoundException ex)
{ {
} }

View File

@ -66,7 +66,7 @@ public class Command_saconfig extends TFM_Command
{ {
superadmin = TFM_SuperadminList.getAdminEntry(getPlayer(args[1]).getName().toLowerCase()); superadmin = TFM_SuperadminList.getAdminEntry(getPlayer(args[1]).getName().toLowerCase());
} }
catch (CantFindPlayerException ex) catch (PlayerNotFoundException ex)
{ {
} }
} }
@ -98,7 +98,7 @@ public class Command_saconfig extends TFM_Command
{ {
p = getPlayer(args[1]); p = getPlayer(args[1]);
} }
catch (CantFindPlayerException ex) catch (PlayerNotFoundException ex)
{ {
TFM_Superadmin superadmin = TFM_SuperadminList.getAdminEntry(args[1].toLowerCase()); TFM_Superadmin superadmin = TFM_SuperadminList.getAdminEntry(args[1].toLowerCase());
if (superadmin != null) if (superadmin != null)
@ -137,7 +137,7 @@ public class Command_saconfig extends TFM_Command
{ {
target_name = getPlayer(target_name).getName(); target_name = getPlayer(target_name).getName();
} }
catch (CantFindPlayerException ex) catch (PlayerNotFoundException ex)
{ {
} }

View File

@ -26,7 +26,7 @@ public class Command_smite extends TFM_Command
{ {
p = getPlayer(args[0]); p = getPlayer(args[0]);
} }
catch (CantFindPlayerException ex) catch (PlayerNotFoundException ex)
{ {
playerMsg(ex.getMessage(), ChatColor.RED); playerMsg(ex.getMessage(), ChatColor.RED);
return true; return true;

View File

@ -103,7 +103,7 @@ public class Command_stfu extends TFM_Command
{ {
p = getPlayer(args[0]); p = getPlayer(args[0]);
} }
catch (CantFindPlayerException ex) catch (PlayerNotFoundException ex)
{ {
sender.sendMessage(ex.getMessage()); sender.sendMessage(ex.getMessage());
return true; return true;

View File

@ -57,7 +57,7 @@ public class Command_survival extends TFM_Command
{ {
p = getPlayer(args[0]); p = getPlayer(args[0]);
} }
catch (CantFindPlayerException ex) catch (PlayerNotFoundException ex)
{ {
playerMsg(ex.getMessage(), ChatColor.RED); playerMsg(ex.getMessage(), ChatColor.RED);
return true; return true;

View File

@ -109,7 +109,7 @@ public class Command_tag extends TFM_Command
{ {
p = getPlayer(args[1]); p = getPlayer(args[1]);
} }
catch (CantFindPlayerException ex) catch (PlayerNotFoundException ex)
{ {
playerMsg(ex.getMessage()); playerMsg(ex.getMessage());
return true; return true;

View File

@ -24,7 +24,7 @@ public class Command_tban extends TFM_Command
{ {
p = getPlayer(args[0]); p = getPlayer(args[0]);
} }
catch (CantFindPlayerException ex) catch (PlayerNotFoundException ex)
{ {
playerMsg(ex.getMessage(), ChatColor.RED); playerMsg(ex.getMessage(), ChatColor.RED);
return true; return true;

View File

@ -30,7 +30,7 @@ public class Command_tempban extends TFM_Command
{ {
p = getPlayer(args[0]); p = getPlayer(args[0]);
} }
catch (CantFindPlayerException ex) catch (PlayerNotFoundException ex)
{ {
playerMsg(ex.getMessage(), ChatColor.RED); playerMsg(ex.getMessage(), ChatColor.RED);
return true; return true;

View File

@ -93,7 +93,7 @@ public class Command_whitelist extends TFM_Command
{ {
p = getPlayer(search_name); p = getPlayer(search_name);
} }
catch (CantFindPlayerException ex) catch (PlayerNotFoundException ex)
{ {
p = server.getOfflinePlayer(search_name); p = server.getOfflinePlayer(search_name);
} }
@ -118,7 +118,7 @@ public class Command_whitelist extends TFM_Command
{ {
p = getPlayer(search_name); p = getPlayer(search_name);
} }
catch (CantFindPlayerException ex) catch (PlayerNotFoundException ex)
{ {
p = server.getOfflinePlayer(search_name); p = server.getOfflinePlayer(search_name);
} }

View File

@ -2,17 +2,17 @@ package me.StevenLawson.TotalFreedomMod.Commands;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
public class CantFindPlayerException extends Exception public class PlayerNotFoundException extends Exception
{ {
// apparently, java needs this // apparently, java needs this
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
public CantFindPlayerException() public PlayerNotFoundException()
{ {
super(ChatColor.GRAY + "Can't find player."); super(ChatColor.GRAY + "Can't find player.");
} }
public CantFindPlayerException(String msg) public PlayerNotFoundException(String msg)
{ {
super(ChatColor.GRAY + "Can't find player: " + msg); super(ChatColor.GRAY + "Can't find player: " + msg);
} }

View File

@ -138,7 +138,7 @@ public abstract class TFM_Command
return true; return true;
} }
public Player getPlayer(final String partialname) throws CantFindPlayerException public Player getPlayer(final String partialname) throws PlayerNotFoundException
{ {
List<Player> matches = server.matchPlayer(partialname); List<Player> matches = server.matchPlayer(partialname);
if (matches.isEmpty()) if (matches.isEmpty())
@ -150,7 +150,7 @@ public abstract class TFM_Command
return p; return p;
} }
} }
throw new CantFindPlayerException(partialname); throw new PlayerNotFoundException(partialname);
} }
else else
{ {

View File

@ -16,12 +16,12 @@ public class TFM_UserList
{ {
private static final String USERLIST_FILENAME = "userlist.yml"; private static final String USERLIST_FILENAME = "userlist.yml";
private static TFM_UserList instance = null; private static TFM_UserList instance = null;
private Map<String, TFM_UserListEntry> _userlist = new HashMap<String, TFM_UserListEntry>(); private Map<String, TFM_UserListEntry> userlist = new HashMap<String, TFM_UserListEntry>();
private final TotalFreedomMod _plugin; private final TotalFreedomMod plugin;
protected TFM_UserList(TotalFreedomMod plugin) protected TFM_UserList(TotalFreedomMod plugin)
{ {
_plugin = plugin; this.plugin = plugin;
primeList(); primeList();
} }
@ -30,17 +30,17 @@ public class TFM_UserList
{ {
try try
{ {
_userlist.clear(); userlist.clear();
FileConfiguration saved_userlist = YamlConfiguration.loadConfiguration(new File(_plugin.getDataFolder(), USERLIST_FILENAME)); FileConfiguration saved_userlist = YamlConfiguration.loadConfiguration(new File(plugin.getDataFolder(), USERLIST_FILENAME));
for (String username : saved_userlist.getKeys(false)) for (String username : saved_userlist.getKeys(false))
{ {
TFM_UserListEntry entry = new TFM_UserListEntry(username, saved_userlist.getStringList(username)); TFM_UserListEntry entry = new TFM_UserListEntry(username, saved_userlist.getStringList(username));
_userlist.put(username, entry); userlist.put(username, entry);
} }
for (Player p : _plugin.getServer().getOnlinePlayers()) for (Player p : plugin.getServer().getOnlinePlayers())
{ {
addUser(p); addUser(p);
} }
@ -58,14 +58,14 @@ public class TFM_UserList
{ {
FileConfiguration new_userlist = new YamlConfiguration(); FileConfiguration new_userlist = new YamlConfiguration();
for (TFM_UserListEntry entry : _userlist.values()) for (TFM_UserListEntry entry : userlist.values())
{ {
new_userlist.set(entry.getUsername(), entry.getIpAddresses()); new_userlist.set(entry.getUsername(), entry.getIpAddresses());
} }
try try
{ {
new_userlist.save(new File(_plugin.getDataFolder(), USERLIST_FILENAME)); new_userlist.save(new File(plugin.getDataFolder(), USERLIST_FILENAME));
} }
catch (IOException ex) catch (IOException ex)
{ {
@ -91,13 +91,13 @@ public class TFM_UserList
{ {
username = username.toLowerCase(); username = username.toLowerCase();
TFM_UserListEntry entry = _userlist.get(username); TFM_UserListEntry entry = userlist.get(username);
if (entry == null) if (entry == null)
{ {
entry = new TFM_UserListEntry(username); entry = new TFM_UserListEntry(username);
} }
_userlist.put(username, entry); userlist.put(username, entry);
if (entry.addIpAddress(ip_address)) if (entry.addIpAddress(ip_address))
{ {
@ -112,14 +112,14 @@ public class TFM_UserList
public TFM_UserListEntry getEntry(String username) public TFM_UserListEntry getEntry(String username)
{ {
return _userlist.get(username.toLowerCase()); return userlist.get(username.toLowerCase());
} }
public void purge() public void purge()
{ {
_userlist.clear(); userlist.clear();
for (Player p : _plugin.getServer().getOnlinePlayers()) for (Player p : plugin.getServer().getOnlinePlayers())
{ {
addUser(p); addUser(p);
} }
@ -132,7 +132,7 @@ public class TFM_UserList
needle = needle.toLowerCase().trim(); needle = needle.toLowerCase().trim();
Integer minEditDistance = null; Integer minEditDistance = null;
String minEditMatch = null; String minEditMatch = null;
Iterator<String> it = _userlist.keySet().iterator(); Iterator<String> it = userlist.keySet().iterator();
while (it.hasNext()) while (it.hasNext())
{ {
String haystack = it.next(); String haystack = it.next();