More Audit Things + Code Cleanup + SaberException Added for Debugging
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
package com.massivecraft.factions.cmd.audit;
|
||||
|
||||
/**
|
||||
* @author Saser
|
||||
/*
|
||||
@author Saser
|
||||
*/
|
||||
import com.google.common.collect.Lists;
|
||||
import com.massivecraft.factions.Faction;
|
||||
@@ -20,7 +20,6 @@ import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
public class FAuditMenu extends GUIMenu {
|
||||
private static int logsPerPage = 20;
|
||||
private Player player;
|
||||
private boolean showTimestamps = true;
|
||||
private Faction faction;
|
||||
@@ -33,62 +32,42 @@ public class FAuditMenu extends GUIMenu {
|
||||
|
||||
public void drawItems() {
|
||||
int index = 0;
|
||||
FLogType[] logTypes = FLogType.values();
|
||||
int length1 = logTypes.length;
|
||||
|
||||
for (FLogType type : logTypes) {
|
||||
for (FLogType type : FLogType.values()) {
|
||||
if (type.getSlot() == -1) continue;
|
||||
if (type != FLogType.F_TNT || FactionsPlugin.getInstance().getConfig().getBoolean("f-points.Enabled")) {
|
||||
if (index == 9) {
|
||||
index = FactionsPlugin.getInstance().getConfig().getBoolean("f-points.Enabled") ? 11 : 12;
|
||||
}
|
||||
|
||||
FactionLogs logs = FactionsPlugin.instance.getFlogManager().getFactionLogMap().get(this.faction.getId());
|
||||
if (logs == null) {
|
||||
logs = new FactionLogs();
|
||||
}
|
||||
|
||||
if (index == 9) index = FactionsPlugin.getInstance().getConfig().getBoolean("f-points.Enabled") ? 11 : 12;
|
||||
FactionLogs logs = FactionsPlugin.instance.getFlogManager().getFactionLogMap().get(faction.getId());
|
||||
if (logs == null) logs = new FactionLogs();
|
||||
LinkedList<FactionLogs.FactionLog> recentLogs = logs.getMostRecentLogs().get(type);
|
||||
if (recentLogs == null) {
|
||||
recentLogs = Lists.newLinkedList();
|
||||
}
|
||||
|
||||
if (recentLogs == null) recentLogs = Lists.newLinkedList();
|
||||
List<String> lore = Lists.newArrayList("", CC.GreenB + "Recent Logs " + CC.Green + "(" + CC.GreenB + recentLogs.size() + CC.Green + ")");
|
||||
int added = 0;
|
||||
Iterator backwars = recentLogs.descendingIterator();
|
||||
int logsPerPage = 20;
|
||||
while (backwars.hasNext()) {
|
||||
FactionLogs.FactionLog log = (FactionLogs.FactionLog) backwars.next();
|
||||
if (added >= logsPerPage) {
|
||||
break;
|
||||
}
|
||||
|
||||
String length = log.getLogLine(type, this.showTimestamps);
|
||||
if (added >= logsPerPage) break;
|
||||
String length = log.getLogLine(type, showTimestamps);
|
||||
lore.add(" " + CC.Yellow + length);
|
||||
++added;
|
||||
}
|
||||
|
||||
int logSize = recentLogs.size();
|
||||
int logsLeft = logSize - logsPerPage;
|
||||
if (logsLeft > 0) {
|
||||
lore.add(CC.YellowB + logsLeft + CC.Yellow + " more logs...");
|
||||
}
|
||||
|
||||
if (logsLeft > 0) lore.add(CC.YellowB + logsLeft + CC.Yellow + " more logs...");
|
||||
lore.add("");
|
||||
if (logsLeft > 0) {
|
||||
lore.add(CC.Yellow + "Left-Click " + CC.Gray + "to view more logs");
|
||||
}
|
||||
|
||||
if (logsLeft > 0) lore.add(CC.Yellow + "Left-Click " + CC.Gray + "to view more logs");
|
||||
lore.add(CC.Yellow + "Right-Click " + CC.Gray + "to toggle timestamps");
|
||||
this.setItem(index++, (new ClickableItemStack((new ItemBuilder(type.getDisplayMaterial())).name(CC.GreenB + type.getDisplayName()).lore(lore).build())).setClickCallback((click) -> {
|
||||
setItem(index++, (new ClickableItemStack((new ItemBuilder(type.getDisplayMaterial())).name(CC.GreenB + type.getDisplayName()).lore(lore).build())).setClickCallback((click) -> {
|
||||
click.setCancelled(true);
|
||||
if (click.getClick() == ClickType.RIGHT) {
|
||||
this.showTimestamps = !this.showTimestamps;
|
||||
this.drawItems();
|
||||
showTimestamps = !showTimestamps;
|
||||
drawItems();
|
||||
} else {
|
||||
if (logsLeft <= 0) {
|
||||
this.player.sendMessage(CC.Red + "No extra logs to load.");
|
||||
player.sendMessage(CC.Red + "No extra logs to load.");
|
||||
return;
|
||||
}
|
||||
Bukkit.getScheduler().scheduleSyncDelayedTask(FactionsPlugin.instance, () -> (new FAuditLogMenu(this.player, this.faction, type)).open(this.player));
|
||||
Bukkit.getScheduler().scheduleSyncDelayedTask(FactionsPlugin.instance, () -> (new FAuditLogMenu(player, faction, type)).open(player));
|
||||
}
|
||||
}));
|
||||
}
|
||||
@@ -96,7 +75,7 @@ public class FAuditMenu extends GUIMenu {
|
||||
|
||||
}
|
||||
|
||||
class FAuditLogMenu extends GUIMenu {
|
||||
static class FAuditLogMenu extends GUIMenu {
|
||||
private Player player;
|
||||
private Faction faction;
|
||||
private FLogType logType;
|
||||
@@ -111,11 +90,11 @@ public class FAuditMenu extends GUIMenu {
|
||||
|
||||
public void drawItems() {
|
||||
FactionLogs logs = FactionsPlugin.instance.getFlogManager().getFactionLogMap().get(faction.getId());
|
||||
int perPage = this.logType == FLogType.F_TNT ? 25 : 20;
|
||||
int perPage = logType == FLogType.F_TNT ? 25 : 20;
|
||||
if (logs != null) {
|
||||
LinkedList<FactionLogs.FactionLog> log = logs.getMostRecentLogs().get(this.logType);
|
||||
LinkedList<FactionLogs.FactionLog> log = logs.getMostRecentLogs().get(logType);
|
||||
if (log != null) {
|
||||
int slot = this.logType == FLogType.F_TNT ? 0 : 3;
|
||||
int slot = logType == FLogType.F_TNT ? 0 : 3;
|
||||
int pagesToShow = (int)Math.max(1.0D, Math.ceil((double)log.size() / (double)perPage));
|
||||
|
||||
for(int page = 1; page <= pagesToShow; ++page) {
|
||||
@@ -131,26 +110,23 @@ public class FAuditMenu extends GUIMenu {
|
||||
if (i < 0) {
|
||||
break;
|
||||
}
|
||||
|
||||
FactionLogs.FactionLog l = log.get(i);
|
||||
lore.add(" " + CC.Yellow + l.getLogLine(this.logType, this.timeStamp));
|
||||
lore.add(" " + CC.Yellow + l.getLogLine(logType, timeStamp));
|
||||
}
|
||||
}
|
||||
|
||||
lore.add("");
|
||||
lore.add(CC.Gray + "Click to toggle timestamp");
|
||||
this.setItem(slot++, (new ClickableItemStack((new ItemBuilder(Material.PAPER)).name(CC.GreenB + "Log #" + page).lore(lore).build())).setClickCallback((e) -> {
|
||||
setItem(slot++, (new ClickableItemStack((new ItemBuilder(Material.PAPER)).name(CC.GreenB + "Log #" + page).lore(lore).build())).setClickCallback((e) -> {
|
||||
e.setCancelled(true);
|
||||
this.timeStamp = !this.timeStamp;
|
||||
this.drawItems();
|
||||
timeStamp = !timeStamp;
|
||||
drawItems();
|
||||
}));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
this.setItem(this.getSize() - 1, (new ClickableItemStack((new ItemBuilder(Material.ARROW)).name(CC.Green + "Previous Page").lore("", CC.Gray + "Click to view previous page!").build())).setClickCallback((event) -> {
|
||||
setItem(getSize() - 1, (new ClickableItemStack((new ItemBuilder(Material.ARROW)).name(CC.Green + "Previous Page").lore("", CC.Gray + "Click to view previous page!").build())).setClickCallback((event) -> {
|
||||
event.setCancelled(true);
|
||||
Bukkit.getScheduler().scheduleSyncDelayedTask(FactionsPlugin.instance, () -> (new FAuditMenu(this.player, this.faction)).open(this.player));
|
||||
Bukkit.getScheduler().scheduleSyncDelayedTask(FactionsPlugin.instance, () -> (new FAuditMenu(player, faction)).open(player));
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user