forked from LogBlock/LogBlock
Made lookups with sum parameter pageable.
This commit is contained in:
@@ -295,10 +295,10 @@ public class CommandsHandler implements CommandExecutor
|
||||
sender.sendMessage(ChatColor.RED + "You have to be a player.");
|
||||
} else if (command.equals("writelogfile")) {
|
||||
if (logblock.hasPermission(sender, "logblock.rollback")) {
|
||||
final QueryParams params = new QueryParams(logblock, sender, argsToList(args, 1));
|
||||
final QueryParams params = new QueryParams(logblock);
|
||||
params.limit = -1;
|
||||
params.bct = BlockChangeType.ALL;
|
||||
params.sum = SummarizationMode.NONE;
|
||||
params.parseArgs(sender, argsToList(args, 1));
|
||||
new CommandWriteLogFile(sender, params, true);
|
||||
} else
|
||||
sender.sendMessage(ChatColor.RED + "You aren't allowed to do this");
|
||||
@@ -348,7 +348,7 @@ public class CommandsHandler implements CommandExecutor
|
||||
}
|
||||
} catch (final NullPointerException ex) {
|
||||
sender.sendMessage(ChatColor.RED + "Error, check log");
|
||||
log.log(Level.WARNING, "NPE in commandshandler: ", ex);
|
||||
log.log(Level.WARNING, "[LogBlock] NPE in commandshandler: ", ex);
|
||||
} catch (final Exception ex) {
|
||||
sender.sendMessage(ChatColor.RED + ex.getMessage());
|
||||
}
|
||||
@@ -445,20 +445,18 @@ public class CommandsHandler implements CommandExecutor
|
||||
sender.sendMessage(ChatColor.DARK_AQUA + params.getTitle() + ":");
|
||||
if (rs.next()) {
|
||||
rs.beforeFirst();
|
||||
if (params.sum == SummarizationMode.NONE) {
|
||||
final List<BlockChange> blockchanges = new ArrayList<BlockChange>();
|
||||
while (rs.next())
|
||||
final List<LookupCacheElement> blockchanges = new ArrayList<LookupCacheElement>();
|
||||
while (rs.next())
|
||||
if (params.sum == SummarizationMode.NONE)
|
||||
blockchanges.add(new BlockChange(rs, params));
|
||||
logblock.getSession(senderName(sender)).lookupCache = blockchanges.toArray(new BlockChange[blockchanges.size()]);
|
||||
if (blockchanges.size() > config.linesPerPage)
|
||||
sender.sendMessage(ChatColor.DARK_AQUA.toString() + blockchanges.size() + " changes found." + (blockchanges.size() == config.linesLimit ? " Use 'limit -1' to see all changes." : ""));
|
||||
showPage(sender, 1);
|
||||
} else {
|
||||
final HistoryFormatter histformatter = new HistoryFormatter(params, sender instanceof Player ? 2 / 3f : 1);
|
||||
else
|
||||
blockchanges.add(new SummedBlockChanges(rs, params, sender instanceof Player ? 2 / 3f : 1));
|
||||
logblock.getSession(senderName(sender)).lookupCache = blockchanges.toArray(new LookupCacheElement[blockchanges.size()]);
|
||||
if (blockchanges.size() > config.linesPerPage)
|
||||
sender.sendMessage(ChatColor.DARK_AQUA.toString() + blockchanges.size() + " changes found." + (blockchanges.size() == config.linesLimit ? " Use 'limit -1' to see all changes." : ""));
|
||||
if (params.sum != SummarizationMode.NONE)
|
||||
sender.sendMessage(ChatColor.GOLD + "Created - Destroyed - " + (params.sum == SummarizationMode.TYPES ? "Block" : "Player"));
|
||||
while (rs.next())
|
||||
sender.sendMessage(ChatColor.GOLD + histformatter.format(rs));
|
||||
}
|
||||
showPage(sender, 1);
|
||||
} else {
|
||||
sender.sendMessage(ChatColor.DARK_AQUA + "No results found.");
|
||||
logblock.getSession(senderName(sender)).lookupCache = null;
|
||||
@@ -499,11 +497,15 @@ public class CommandsHandler implements CommandExecutor
|
||||
file.createNewFile();
|
||||
final FileWriter writer = new FileWriter(file);
|
||||
final String newline = System.getProperty("line.separator");
|
||||
final HistoryFormatter histformatter = new HistoryFormatter(params, 1);
|
||||
file.getParentFile().mkdirs();
|
||||
int counter = 0;
|
||||
if (params.sum != SummarizationMode.NONE)
|
||||
writer.write("Created - Destroyed - " + (params.sum == SummarizationMode.TYPES ? "Block" : "Player") + newline);
|
||||
while (rs.next()) {
|
||||
writer.write(histformatter.format(rs) + newline);
|
||||
if (params.sum == SummarizationMode.NONE)
|
||||
writer.write(new BlockChange(rs, params).getMessage() + newline);
|
||||
else
|
||||
writer.write(new SummedBlockChanges(rs, params, 1).getMessage() + newline);
|
||||
counter++;
|
||||
}
|
||||
writer.close();
|
||||
|
@@ -1,29 +0,0 @@
|
||||
package de.diddiz.LogBlock;
|
||||
|
||||
import static de.diddiz.util.BukkitUtils.materialName;
|
||||
import static de.diddiz.util.Utils.spaces;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import de.diddiz.LogBlock.QueryParams.SummarizationMode;
|
||||
|
||||
public class HistoryFormatter
|
||||
{
|
||||
private final QueryParams params;
|
||||
private final float factor;
|
||||
|
||||
HistoryFormatter(QueryParams params, float factor) {
|
||||
this.params = params;
|
||||
this.factor = factor;
|
||||
}
|
||||
|
||||
String format(ResultSet rs) throws SQLException {
|
||||
if (params.sum == SummarizationMode.NONE)
|
||||
return new BlockChange(rs, params).toString();
|
||||
String c1 = String.valueOf(rs.getInt(2)), c2 = String.valueOf(rs.getInt(3));
|
||||
c1 += spaces((int)((10 - c1.length()) / factor));
|
||||
c2 += spaces((int)((10 - c2.length()) / factor));
|
||||
if (params.sum == SummarizationMode.TYPES)
|
||||
return c1 + c2 + materialName(rs.getInt(1));
|
||||
return c1 + c2 + rs.getString(1);
|
||||
}
|
||||
}
|
@@ -132,7 +132,10 @@ public class QueryParams implements Cloneable
|
||||
else if (radius == 0)
|
||||
title.append("at clicked block ");
|
||||
if (!(sel != null && prepareToolQuery))
|
||||
title.append("in " + friendlyWorldname(world.getName()));
|
||||
title.append("in " + friendlyWorldname(world.getName()) + " ");
|
||||
if (sum != SummarizationMode.NONE)
|
||||
title.append("summed up by " + (sum == SummarizationMode.TYPES ? "blocks" : "players") + " ");
|
||||
title.deleteCharAt(title.length() - 1);
|
||||
title.setCharAt(0, String.valueOf(title.charAt(0)).toUpperCase().toCharArray()[0]);
|
||||
return title.toString();
|
||||
}
|
||||
|
32
src/de/diddiz/LogBlock/SummedBlockChanges.java
Normal file
32
src/de/diddiz/LogBlock/SummedBlockChanges.java
Normal file
@@ -0,0 +1,32 @@
|
||||
package de.diddiz.LogBlock;
|
||||
|
||||
import static de.diddiz.util.BukkitUtils.materialName;
|
||||
import static de.diddiz.util.Utils.spaces;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import org.bukkit.Location;
|
||||
import de.diddiz.LogBlock.QueryParams.SummarizationMode;
|
||||
|
||||
public class SummedBlockChanges implements LookupCacheElement
|
||||
{
|
||||
private final String group;
|
||||
private final int created, destroyed;
|
||||
private final float spaceFactor;
|
||||
|
||||
public SummedBlockChanges(ResultSet rs, QueryParams p, float spaceFactor) throws SQLException {
|
||||
group = p.sum == SummarizationMode.PLAYERS ? rs.getString(1) : materialName(rs.getInt(1));
|
||||
created = rs.getInt(2);
|
||||
destroyed = rs.getInt(3);
|
||||
this.spaceFactor = spaceFactor;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Location getLocation() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMessage() {
|
||||
return created + spaces((int)((10 - String.valueOf(created).length()) / spaceFactor)) + destroyed + spaces((int)((10 - String.valueOf(destroyed).length()) / spaceFactor)) + group;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user