Fixed QueryParams getTitle for custom tool params

This commit is contained in:
Robin Kupper
2011-07-07 16:35:01 +02:00
parent a20728d2fe
commit ec01b10e13
2 changed files with 42 additions and 29 deletions

View File

@@ -31,7 +31,6 @@ import de.diddiz.LogBlockQuestioner.LogBlockQuestioner;
public class CommandsHandler implements CommandExecutor
{
private final QueryParams defaultToolParams;
private final Logger log;
private final LogBlock logblock;
private final Config config;
@@ -44,9 +43,6 @@ public class CommandsHandler implements CommandExecutor
config = logblock.getConfig();
scheduler = logblock.getServer().getScheduler();
questioner = (LogBlockQuestioner)logblock.getServer().getPluginManager().getPlugin("LogBlockQuestioner");
defaultToolParams = new QueryParams(logblock);
defaultToolParams.radius = 0;
defaultToolParams.bct = BlockChangeType.ALL;
}
@Override
@@ -77,6 +73,7 @@ public class CommandsHandler implements CommandExecutor
sender.sendMessage(ChatColor.GOLD + "/lb tp [params] -- Teleports you to the location of griefing");
sender.sendMessage(ChatColor.GOLD + "/lb writelogfile [params] -- Writes a log file");
sender.sendMessage(ChatColor.GOLD + "/lb lookup [params] -- Lookup");
sender.sendMessage(ChatColor.GOLD + "/lb page /lb prev /lb next -- Browse lookup result pages");
sender.sendMessage(ChatColor.GOLD + "/lb me -- Displays your stats");
sender.sendMessage(ChatColor.GOLD + "Look at github.com/DiddiZ/LogBlock/wiki/Commands for the full commands reference");
} else if (command.equals("params")) {
@@ -96,6 +93,7 @@ public class CommandsHandler implements CommandExecutor
sender.sendMessage(ChatColor.GOLD + "sum [none|blocks|players] -- Sums the result");
sender.sendMessage(ChatColor.GOLD + "asc, desc -- Changes the order of the displayed log");
sender.sendMessage(ChatColor.GOLD + "coords -- Shows coordinates for each block");
sender.sendMessage(ChatColor.GOLD + "silent -- Displays lesser messages");
} else if (command.equals("permissions")) {
final String[] permissions = {"tool", "toolblock", "me", "lookup", "tp", "rollback", "clearlog", "hide", "ignoreRestrictions"};
sender.sendMessage(ChatColor.DARK_AQUA + "You've got the following permissions:");
@@ -138,7 +136,7 @@ public class CommandsHandler implements CommandExecutor
sender.sendMessage(ChatColor.GREEN + "Tool parameters set to default.");
} else if (logblock.hasPermission(player, "logblock.lookup"))
try {
final QueryParams params = defaultToolParams.clone();
final QueryParams params = config.toolQuery.clone();
params.parseArgs(sender, argsToList(args, 1));
logblock.getSession(player.getName()).toolQuery = params;
sender.sendMessage(ChatColor.GREEN + "Set tool query to: " + params.getTitle());
@@ -185,7 +183,7 @@ public class CommandsHandler implements CommandExecutor
sender.sendMessage(ChatColor.GREEN + "Toolblock parameters set to default.");
} else if (logblock.hasPermission(player, "logblock.lookup"))
try {
final QueryParams params = defaultToolParams.clone();
final QueryParams params = config.toolBlockQuery.clone();
params.parseArgs(sender, argsToList(args, 1));
logblock.getSession(player.getName()).toolBlockQuery = params;
sender.sendMessage(ChatColor.GREEN + "Set tool block query to: " + params.getTitle());
@@ -200,7 +198,7 @@ public class CommandsHandler implements CommandExecutor
if (sender instanceof Player) {
if (logblock.hasPermission(sender, "logblock.hide")) {
if (logblock.getConsumer().hide((Player)sender))
sender.sendMessage(ChatColor.GREEN + "You are now hided and won't appear in any log. Type '/lb hide' again to unhide");
sender.sendMessage(ChatColor.GREEN + "You are now hidden and aren't logged. Type '/lb hide' again to unhide");
else
sender.sendMessage(ChatColor.GREEN + "You aren't hidden anylonger.");
} else
@@ -408,7 +406,7 @@ public class CommandsHandler implements CommandExecutor
if (params.limit == 15)
params.limit = config.linesLimit;
rs = state.executeQuery(params.getLookupQuery());
sender.sendMessage(ChatColor.DARK_AQUA + params.getTitle());
sender.sendMessage(ChatColor.DARK_AQUA + params.getTitle() + ":");
final List<BlockChange> blockchanges = new ArrayList<BlockChange>();
if (rs.next()) {
rs.beforeFirst();

View File

@@ -90,19 +90,23 @@ public class QueryParams implements Cloneable
public String getTitle() {
final StringBuilder title = new StringBuilder();
if (!types.isEmpty()) {
final String[] blocknames = new String[types.size()];
for (int i = 0; i < types.size(); i++)
blocknames[i] = materialName(types.get(i));
title.append(listing(blocknames, ", ", " and ") + " ");
} else
title.append("block ");
if (bct == BlockChangeType.CREATED)
title.append("creations ");
else if (bct == BlockChangeType.DESTROYED)
title.append("destructions ");
else
title.append("changes ");
if (bct == BlockChangeType.CHESTACCESS)
title.append("chest accesses ");
else {
if (!types.isEmpty()) {
final String[] blocknames = new String[types.size()];
for (int i = 0; i < types.size(); i++)
blocknames[i] = materialName(types.get(i));
title.append(listing(blocknames, ", ", " and ") + " ");
} else
title.append("block ");
if (bct == BlockChangeType.CREATED)
title.append("creations ");
else if (bct == BlockChangeType.DESTROYED)
title.append("destructions ");
else
title.append("changes ");
}
if (players.size() > 10)
title.append((excludePlayersMode ? "without" : "from") + " many players ");
else if (!players.isEmpty())
@@ -111,13 +115,20 @@ public class QueryParams implements Cloneable
title.append("in the last " + minutes + " minutes ");
if (minutes < 0)
title.append("up to " + minutes * -1 + " minutes ago ");
if (loc != null && radius > 0)
title.append("within " + radius + " blocks of you ");
if (loc != null && radius == 0)
title.append("at " + loc.getBlockX() + ":" + loc.getBlockY() + ":" + loc.getBlockZ() + " ");
else if (sel != null)
title.append("inside selection ");
title.append("in " + friendlyWorldname(world.getName()));
if (loc != null) {
if (radius > 0)
title.append("within " + radius + " blocks of " + (prepareToolQuery ? "clicked block" : "you") + " ");
else if (radius == 0)
title.append("at " + loc.getBlockX() + ":" + loc.getBlockY() + ":" + loc.getBlockZ() + " ");
} else if (sel != null)
title.append(prepareToolQuery ? "at double chest" : "inside selection ");
else if (prepareToolQuery)
if (radius > 0)
title.append("within " + radius + " blocks of clicked block ");
else if (radius == 0)
title.append("at clicked block ");
if (!(sel != null && prepareToolQuery))
title.append("in " + friendlyWorldname(world.getName()));
title.setCharAt(0, String.valueOf(title.charAt(0)).toUpperCase().toCharArray()[0]);
return title.toString();
}
@@ -359,7 +370,10 @@ public class QueryParams implements Cloneable
@Override
protected QueryParams clone() {
try {
return (QueryParams)super.clone();
final QueryParams params = (QueryParams)super.clone();
params.players = new ArrayList<String>(players);
params.types = new ArrayList<Integer>(types);
return params;
} catch (final CloneNotSupportedException ex) {}
return null;
}
@@ -379,6 +393,7 @@ public class QueryParams implements Cloneable
public void merge(QueryParams params) {
players = params.players;
excludePlayersMode = params.excludePlayersMode;
types = params.types;
loc = params.loc;
radius = params.radius;