More Audit Things + Code Cleanup + SaberException Added for Debugging

This commit is contained in:
Driftay
2019-12-28 04:58:33 -05:00
parent acf06c78ed
commit 8e855bc9bb
18 changed files with 178 additions and 190 deletions

View File

@@ -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));
}));
}
}

View File

@@ -88,12 +88,12 @@ public class FChestListener implements Listener {
return;
}
this.logRemoveItem(currentItem, fplayer, player);
logRemoveItem(currentItem, fplayer, player);
} else if (cursorItemType != Material.AIR && !event.isShiftClick()) {
this.logAddItem(cursorItem, fplayer, player);
logAddItem(cursorItem, fplayer, player);
}
} else if (event.isShiftClick() && currentItemType != Material.AIR) {
this.logAddItem(currentItem, fplayer, player);
logAddItem(currentItem, fplayer, player);
}
}

View File

@@ -13,10 +13,8 @@ import org.bukkit.Bukkit;
import java.io.File;
import java.lang.reflect.Type;
import java.util.Map;
import java.util.Timer;
import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.TimeUnit;
public class FLogManager {
private Map<String, FactionLogs> factionLogMap = new ConcurrentHashMap<>();
@@ -41,7 +39,7 @@ public class FLogManager {
logFile.createNewFile();
}
factionLogMap = (Map) JSONUtils.fromJson(logFile, logToken);
factionLogMap = (Map<String, FactionLogs>) JSONUtils.fromJson(logFile, logToken);
if (factionLogMap == null) {
factionLogMap = new ConcurrentHashMap<>();
}
@@ -64,8 +62,6 @@ public class FLogManager {
e.printStackTrace();
}
long delay = TimeUnit.SECONDS.toMillis(15L);
long sellDelay = TimeUnit.SECONDS.toMillis(30L);
Bukkit.getScheduler().scheduleSyncRepeatingTask(FactionsPlugin.instance, () -> {
if (saving) {
Bukkit.getLogger().info("Ignoring saveLogs scheduler due to saving == true!");
@@ -100,7 +96,7 @@ public class FLogManager {
}
if (type != null) {
Map<LogTimer.TimerSubType, Timer> timers = (Map) logTimer.get(type);
Map<LogTimer.TimerSubType, LogTimer.Timer> timers = logTimer.get(type);
if (timers != null && faction != null) {
logTimer.pushLogs(faction, type);
}
@@ -133,7 +129,7 @@ public class FLogManager {
try {
JSONUtils.saveJSONToFile(logFile, factionLogMap,logToken);
} catch (Exception e1) {
Bukkit.getLogger().info("ERRRO SAVING JSON LOGS: " + e1.getMessage());
Bukkit.getLogger().info("ERROR SAVING JSON LOGS: " + e1.getMessage());
e1.printStackTrace();
}

View File

@@ -1,6 +1,8 @@
package com.massivecraft.factions.cmd.audit;
import com.massivecraft.factions.FactionsPlugin;
import com.massivecraft.factions.util.XMaterial;
import com.massivecraft.factions.zcore.fperms.PermissableAction;
import org.bukkit.Material;
/**
@@ -31,6 +33,25 @@ public enum FLogType {
return this.displayName;
}
/**
* Case insensitive check for action.
*
* @param check
* @return - action
*/
public static FLogType fromString(String check) {
for (FLogType fLogType : values()) {
if (fLogType.displayName.equalsIgnoreCase(check)) {
return fLogType;
}
}
return null;
}
public int getSlot() {
return FactionsPlugin.getInstance().getConfig().getInt("faudit-gui.slots." + this.displayName.toLowerCase());
}
public Material getDisplayMaterial() {
return this.displayMaterial;
}

View File

@@ -18,7 +18,6 @@ import java.util.concurrent.TimeUnit;
public class FactionLogs {
private Map<FLogType, LinkedList<FactionLog>> mostRecentLogs = new ConcurrentHashMap<>();
public static transient SimpleDateFormat format = new SimpleDateFormat("MM/dd hh:mmaa");
private static transient int MAX_LOG_SIZE = 60;
public FactionLogs() {
}
@@ -28,7 +27,7 @@ public class FactionLogs {
Bukkit.getLogger().info("INVALID ARGUMENT COUNT MET: " + type.getRequiredArgs() + " REQUIRED: ");
Thread.dumpStack();
} else {
LinkedList<FactionLog> logs = this.mostRecentLogs.computeIfAbsent(type, (lists) -> new LinkedList<>());
LinkedList<FactionLog> logs = mostRecentLogs.computeIfAbsent(type, (lists) -> new LinkedList<>());
logs.add(new FactionLog(System.currentTimeMillis(), Lists.newArrayList(arguments)));
int maxLog = type == FLogType.F_TNT ? 200 : 60;
if (logs.size() > maxLog) {
@@ -69,16 +68,14 @@ public class FactionLogs {
toRemove.add(logType);
}
});
toRemove.forEach((rem) -> {
LinkedList linkedList = this.mostRecentLogs.remove(rem);
});
toRemove.forEach((rem) -> mostRecentLogs.remove(rem));
}
public Map<FLogType, LinkedList<FactionLog>> getMostRecentLogs() {
return this.mostRecentLogs;
return mostRecentLogs;
}
public class FactionLog {
public static class FactionLog {
private long t;
private List<String> a;
@@ -88,19 +85,19 @@ public class FactionLogs {
}
public boolean isExpired(long duration) {
return System.currentTimeMillis() - this.t >= duration;
return System.currentTimeMillis() - t >= duration;
}
public String getLogLine(FLogType type, boolean timestamp) {
String[] args = this.a.toArray(new String[0]);
String[] args = a.toArray(new String[0]);
String timeFormat = "";
if (timestamp) {
timeFormat = FactionLogs.format.format(this.t);
timeFormat = FactionLogs.format.format(t);
if (timeFormat.startsWith("0")) {
timeFormat = timeFormat.substring(1);
}
}
return String.format(ChatColor.translateAlternateColorCodes('&', type.getMsg()), (String[])args) + (timestamp ? ChatColor.GRAY + " - " + timeFormat : "");
return String.format(ChatColor.translateAlternateColorCodes('&', type.getMsg()), args) + (timestamp ? ChatColor.GRAY + " - " + timeFormat : "");
}
}
}

View File

@@ -33,7 +33,6 @@ public class LogTimer extends ConcurrentHashMap<LogTimer.TimerType, Map<LogTimer
}
public void pushLogs(Faction faction, LogTimer.TimerType type) {
StringBuilder soldString = new StringBuilder();
forEach((timerType, map) -> {
if (timerType == type) {
if (timerType == LogTimer.TimerType.SPAWNER_EDIT) {
@@ -44,18 +43,18 @@ public class LogTimer extends ConcurrentHashMap<LogTimer.TimerType, Map<LogTimer
currentCounts.forEach((data, ints) -> {
EntityType types = EntityType.fromId(data.getData());
if (types == null) {
Bukkit.getLogger().info("Unable to find EntityType for " + data.getData() + " for " + subTimer + " for fac " + this.factionId + "!");
Bukkit.getLogger().info("Unable to find EntityType for " + data.getData() + " for " + subTimer + " for fac " + factionId + "!");
} else {
entityCounts.computeIfAbsent(types, (e) -> new AtomicInteger(0)).addAndGet(ints.get());
}
});
entityCounts.forEach((entityType, count) -> FactionsPlugin.instance.getFlogManager().log(faction, FLogType.SPAWNER_EDIT, this.username, subTimer == TimerSubType.SPAWNER_BREAK ? "broke" : "placed", count.get() + "x", StringUtils.capitaliseAllWords(entityType.name().toLowerCase().replace("_", " "))));
entityCounts.forEach((entityType, count) -> FactionsPlugin.instance.getFlogManager().log(faction, FLogType.SPAWNER_EDIT, username, subTimer == TimerSubType.SPAWNER_BREAK ? "broke" : "placed", count.get() + "x", StringUtils.capitaliseAllWords(entityType.name().toLowerCase().replace("_", " "))));
}
});
}
}
});
this.remove(type);
remove(type);
}
public String getFactionId() {