Added Brand New F Audit Base.
This commit is contained in:
@@ -4,11 +4,13 @@ import com.massivecraft.factions.FPlayer;
|
||||
import com.massivecraft.factions.FPlayers;
|
||||
import com.massivecraft.factions.Faction;
|
||||
import com.massivecraft.factions.FactionsPlugin;
|
||||
import com.massivecraft.factions.cmd.audit.FLogType;
|
||||
import com.massivecraft.factions.event.FPlayerJoinEvent;
|
||||
import com.massivecraft.factions.struct.Permission;
|
||||
import com.massivecraft.factions.struct.Role;
|
||||
import com.massivecraft.factions.zcore.util.TL;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
|
||||
public class CmdAdmin extends FCommand {
|
||||
|
||||
@@ -84,6 +86,8 @@ public class CmdAdmin extends FCommand {
|
||||
fyou.setRole(Role.LEADER);
|
||||
context.msg(TL.COMMAND_ADMIN_PROMOTES, fyou.describeTo(context.fPlayer, true));
|
||||
|
||||
FactionsPlugin.instance.getFlogManager().log(targetFaction, FLogType.RANK_EDIT, context.fPlayer.getName(), fyou.getName(), ChatColor.RED + "Admin");
|
||||
|
||||
// Inform all players
|
||||
for (FPlayer fplayer : FPlayers.getInstance().getOnlinePlayers()) {
|
||||
fplayer.msg(TL.COMMAND_ADMIN_PROMOTED,
|
||||
|
||||
@@ -2,9 +2,11 @@ package com.massivecraft.factions.cmd;
|
||||
|
||||
import com.massivecraft.factions.FPlayer;
|
||||
import com.massivecraft.factions.FactionsPlugin;
|
||||
import com.massivecraft.factions.cmd.audit.FLogType;
|
||||
import com.massivecraft.factions.event.FPlayerLeaveEvent;
|
||||
import com.massivecraft.factions.struct.BanInfo;
|
||||
import com.massivecraft.factions.struct.Permission;
|
||||
import com.massivecraft.factions.util.CC;
|
||||
import com.massivecraft.factions.zcore.fperms.PermissableAction;
|
||||
import com.massivecraft.factions.zcore.util.TL;
|
||||
import org.bukkit.Bukkit;
|
||||
@@ -79,6 +81,7 @@ public class CmdBan extends FCommand {
|
||||
|
||||
// Lets inform the people!
|
||||
target.msg(TL.COMMAND_BAN_TARGET, context.faction.getTag(target.getFaction()));
|
||||
FactionsPlugin.instance.logFactionEvent(context.faction, FLogType.BANS, context.fPlayer.getName(), CC.Green + "banned", target.getName());
|
||||
context.faction.msg(TL.COMMAND_BAN_BANNED, context.fPlayer.getName(), target.getName());
|
||||
}
|
||||
|
||||
|
||||
@@ -3,6 +3,8 @@ package com.massivecraft.factions.cmd;
|
||||
import com.massivecraft.factions.Conf;
|
||||
import com.massivecraft.factions.FPlayer;
|
||||
import com.massivecraft.factions.Faction;
|
||||
import com.massivecraft.factions.FactionsPlugin;
|
||||
import com.massivecraft.factions.cmd.audit.FLogType;
|
||||
import com.massivecraft.factions.struct.Permission;
|
||||
import com.massivecraft.factions.struct.Role;
|
||||
import com.massivecraft.factions.zcore.util.TL;
|
||||
@@ -81,6 +83,7 @@ public class CmdColeader extends FCommand {
|
||||
you.setRole(Role.COLEADER);
|
||||
targetFaction.msg(TL.COMMAND_COLEADER_PROMOTED, you.describeTo(targetFaction, true));
|
||||
context.msg(TL.COMMAND_COLEADER_PROMOTES, you.describeTo(context.fPlayer, true));
|
||||
FactionsPlugin.instance.getFlogManager().log(targetFaction, FLogType.RANK_EDIT, context.fPlayer.getName(), you.getName(), ChatColor.RED + "Co-Leader");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -4,9 +4,11 @@ import com.massivecraft.factions.Conf;
|
||||
import com.massivecraft.factions.FPlayer;
|
||||
import com.massivecraft.factions.FPlayers;
|
||||
import com.massivecraft.factions.FactionsPlugin;
|
||||
import com.massivecraft.factions.cmd.audit.FLogType;
|
||||
import com.massivecraft.factions.struct.Permission;
|
||||
import com.massivecraft.factions.zcore.util.TL;
|
||||
import com.massivecraft.factions.zcore.util.TextUtil;
|
||||
import org.bukkit.Bukkit;
|
||||
|
||||
public class CmdDescription extends FCommand {
|
||||
|
||||
@@ -38,8 +40,9 @@ public class CmdDescription extends FCommand {
|
||||
|
||||
// since "&" color tags seem to work even through plain old FPlayer.sendMessage() for some reason, we need to break those up
|
||||
// And replace all the % because it messes with string formatting and this is easy way around that.
|
||||
context.faction.setDescription(TextUtil.implode(context.args, " ").replaceAll("%", "").replaceAll("(&([a-f0-9klmnor]))", "& $2"));
|
||||
|
||||
String desc = TextUtil.implode(context.args, " ").replaceAll("%", "").replaceAll("(&([a-f0-9klmnor]))", "& $2");
|
||||
context.faction.setDescription(desc);
|
||||
Bukkit.getScheduler().scheduleSyncDelayedTask(FactionsPlugin.instance, () -> FactionsPlugin.instance.logFactionEvent(context.faction, FLogType.FDESC_EDIT, context.fPlayer.getName(), desc));
|
||||
if (!Conf.broadcastDescriptionChanges) {
|
||||
context.msg(TL.COMMAND_DESCRIPTION_CHANGED, context.faction.describeTo(context.fPlayer));
|
||||
context.sendMessage(context.faction.getDescription());
|
||||
|
||||
@@ -3,7 +3,9 @@ package com.massivecraft.factions.cmd;
|
||||
import com.massivecraft.factions.Conf;
|
||||
import com.massivecraft.factions.FPlayer;
|
||||
import com.massivecraft.factions.FactionsPlugin;
|
||||
import com.massivecraft.factions.cmd.audit.FLogType;
|
||||
import com.massivecraft.factions.struct.Permission;
|
||||
import com.massivecraft.factions.util.CC;
|
||||
import com.massivecraft.factions.zcore.fperms.PermissableAction;
|
||||
import com.massivecraft.factions.zcore.util.TL;
|
||||
import mkremins.fanciful.FancyMessage;
|
||||
@@ -68,11 +70,10 @@ public class CmdInvite extends FCommand {
|
||||
.command("/" + Conf.baseCommandAliases.get(0) + " join " + context.faction.getTag())
|
||||
.then(context.faction.describeTo(target)).tooltip(TL.COMMAND_INVITE_CLICKTOJOIN.toString())
|
||||
.command("/" + Conf.baseCommandAliases.get(0) + " join " + context.faction.getTag());
|
||||
|
||||
message.send(target.getPlayer());
|
||||
}
|
||||
|
||||
context.faction.msg(TL.COMMAND_INVITE_INVITED, context.fPlayer.describeTo(context.faction, true), target.describeTo(context.faction));
|
||||
FactionsPlugin.instance.logFactionEvent(context.faction, FLogType.INVITES, context.fPlayer.getName(), CC.Green + "invited", target.getName());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1,15 +1,19 @@
|
||||
package com.massivecraft.factions.cmd;
|
||||
|
||||
import com.massivecraft.factions.*;
|
||||
import com.massivecraft.factions.cmd.audit.FLogType;
|
||||
import com.massivecraft.factions.discord.Discord;
|
||||
import com.massivecraft.factions.event.FPlayerJoinEvent;
|
||||
import com.massivecraft.factions.struct.Permission;
|
||||
import com.massivecraft.factions.util.CC;
|
||||
import com.massivecraft.factions.zcore.fupgrades.UpgradeType;
|
||||
import com.massivecraft.factions.zcore.util.TL;
|
||||
import net.dv8tion.jda.core.entities.Member;
|
||||
import net.dv8tion.jda.core.exceptions.HierarchyException;
|
||||
import org.bukkit.Bukkit;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
public class CmdJoin extends FCommand {
|
||||
|
||||
/**
|
||||
@@ -125,10 +129,11 @@ public class CmdJoin extends FCommand {
|
||||
faction.deinvite(fplayer);
|
||||
try {
|
||||
context.fPlayer.setRole(faction.getDefaultRole());
|
||||
FactionsPlugin.instance.logFactionEvent(faction, FLogType.INVITES, context.fPlayer.getName(), CC.Green + "joined", "the faction");
|
||||
if (Discord.useDiscord && context.fPlayer.discordSetup() && Discord.isInMainGuild(context.fPlayer.discordUser()) && Discord.mainGuild != null) {
|
||||
Member m = Discord.mainGuild.getMember(context.fPlayer.discordUser());
|
||||
if (Conf.factionRoles) {
|
||||
Discord.mainGuild.getController().addSingleRoleToMember(m, Discord.createFactionRole(faction.getTag())).queue();
|
||||
Discord.mainGuild.getController().addSingleRoleToMember(m, Objects.requireNonNull(Discord.createFactionRole(faction.getTag()))).queue();
|
||||
}
|
||||
if (Conf.factionDiscordTags) {
|
||||
Discord.mainGuild.getController().setNickname(m, Discord.getNicknameString(context.fPlayer)).queue();
|
||||
|
||||
@@ -4,9 +4,11 @@ import com.massivecraft.factions.Conf;
|
||||
import com.massivecraft.factions.FPlayer;
|
||||
import com.massivecraft.factions.Faction;
|
||||
import com.massivecraft.factions.FactionsPlugin;
|
||||
import com.massivecraft.factions.cmd.audit.FLogType;
|
||||
import com.massivecraft.factions.event.FPlayerLeaveEvent;
|
||||
import com.massivecraft.factions.struct.Permission;
|
||||
import com.massivecraft.factions.struct.Role;
|
||||
import com.massivecraft.factions.util.CC;
|
||||
import com.massivecraft.factions.zcore.fperms.PermissableAction;
|
||||
import com.massivecraft.factions.zcore.util.TL;
|
||||
import mkremins.fanciful.FancyMessage;
|
||||
@@ -122,6 +124,7 @@ public class CmdKick extends FCommand {
|
||||
if (toKick.getRole() == Role.LEADER) {
|
||||
toKickFaction.promoteNewLeader();
|
||||
}
|
||||
FactionsPlugin.instance.logFactionEvent(toKickFaction, FLogType.INVITES, context.fPlayer.getName(), CC.Red + "kicked", toKick.getName());
|
||||
toKickFaction.deinvite(toKick);
|
||||
toKick.resetFactionData();
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ import com.massivecraft.factions.Conf;
|
||||
import com.massivecraft.factions.FPlayer;
|
||||
import com.massivecraft.factions.Faction;
|
||||
import com.massivecraft.factions.FactionsPlugin;
|
||||
import com.massivecraft.factions.cmd.audit.FLogType;
|
||||
import com.massivecraft.factions.struct.Permission;
|
||||
import com.massivecraft.factions.struct.Role;
|
||||
import com.massivecraft.factions.zcore.util.TL;
|
||||
@@ -77,6 +78,8 @@ public class CmdMod extends FCommand {
|
||||
you.setRole(Role.MODERATOR);
|
||||
targetFaction.msg(TL.COMMAND_MOD_PROMOTED, you.describeTo(targetFaction, true));
|
||||
context.msg(TL.COMMAND_MOD_PROMOTES, you.describeTo(context.fPlayer, true));
|
||||
FactionsPlugin.instance.getFlogManager().log(targetFaction, FLogType.RANK_EDIT, context.fPlayer.getName(), you.getName(), ChatColor.LIGHT_PURPLE + "Mod");
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,9 +1,6 @@
|
||||
package com.massivecraft.factions.cmd;
|
||||
|
||||
import com.massivecraft.factions.Board;
|
||||
import com.massivecraft.factions.Conf;
|
||||
import com.massivecraft.factions.FPlayers;
|
||||
import com.massivecraft.factions.Factions;
|
||||
import com.massivecraft.factions.*;
|
||||
import com.massivecraft.factions.shop.ShopConfig;
|
||||
import com.massivecraft.factions.struct.Permission;
|
||||
import com.massivecraft.factions.zcore.util.TL;
|
||||
@@ -29,6 +26,11 @@ public class CmdSaveAll extends FCommand {
|
||||
Factions.getInstance().forceSave(false);
|
||||
Board.getInstance().forceSave(false);
|
||||
Conf.save();
|
||||
try {
|
||||
FactionsPlugin.instance.getFlogManager().saveLogs();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
ShopConfig.saveShop();
|
||||
context.msg(TL.COMMAND_SAVEALL_SUCCESS);
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.massivecraft.factions.cmd;
|
||||
|
||||
import com.massivecraft.factions.*;
|
||||
import com.massivecraft.factions.cmd.audit.FLogType;
|
||||
import com.massivecraft.factions.discord.Discord;
|
||||
import com.massivecraft.factions.event.FactionRenameEvent;
|
||||
import com.massivecraft.factions.scoreboards.FTeamWrapper;
|
||||
@@ -69,6 +70,8 @@ public class CmdTag extends FCommand {
|
||||
String oldtag = context.faction.getTag();
|
||||
context.faction.setTag(tag);
|
||||
Discord.changeFactionTag(context.faction, oldtag);
|
||||
FactionsPlugin.instance.logFactionEvent(context.faction, FLogType.FTAG_EDIT, context.fPlayer.getName(), tag);
|
||||
|
||||
|
||||
// Inform
|
||||
for (FPlayer fplayer : FPlayers.getInstance().getOnlinePlayers()) {
|
||||
@@ -76,14 +79,12 @@ public class CmdTag extends FCommand {
|
||||
fplayer.msg(TL.COMMAND_TAG_FACTION, context.fPlayer.describeTo(context.faction, true), context.faction.getTag(context.faction));
|
||||
continue;
|
||||
}
|
||||
|
||||
// Broadcast the tag change (if applicable)
|
||||
if (Conf.broadcastTagChanges) {
|
||||
Faction faction = fplayer.getFaction();
|
||||
fplayer.msg(TL.COMMAND_TAG_CHANGED, context.fPlayer.getColorTo(faction) + oldtag, context.faction.getTag(faction));
|
||||
}
|
||||
}
|
||||
|
||||
FTeamWrapper.updatePrefixes(context.faction);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -6,8 +6,10 @@ import com.massivecraft.factions.FactionsPlugin;
|
||||
import com.massivecraft.factions.cmd.CommandContext;
|
||||
import com.massivecraft.factions.cmd.CommandRequirements;
|
||||
import com.massivecraft.factions.cmd.FCommand;
|
||||
import com.massivecraft.factions.cmd.audit.FLogType;
|
||||
import com.massivecraft.factions.struct.Permission;
|
||||
import com.massivecraft.factions.struct.Role;
|
||||
import com.massivecraft.factions.util.CC;
|
||||
import com.massivecraft.factions.zcore.fperms.Access;
|
||||
import com.massivecraft.factions.zcore.fperms.PermissableAction;
|
||||
import com.massivecraft.factions.zcore.util.TL;
|
||||
@@ -84,7 +86,7 @@ public class CmdInviteAlt extends FCommand {
|
||||
.command("/" + Conf.baseCommandAliases.get(0) + " join " + context.faction.getTag());
|
||||
|
||||
message.send(target.getPlayer());
|
||||
|
||||
FactionsPlugin.instance.logFactionEvent(context.faction, FLogType.INVITES, context.fPlayer.getName(), CC.Green + "invited", target.getName());
|
||||
context.faction.msg(TL.COMMAND_ALTINVITE_INVITED_ALT, context.fPlayer.describeTo(context.faction, true), target.describeTo(context.faction));
|
||||
}
|
||||
|
||||
|
||||
@@ -7,9 +7,11 @@ import com.massivecraft.factions.FactionsPlugin;
|
||||
import com.massivecraft.factions.cmd.CommandContext;
|
||||
import com.massivecraft.factions.cmd.CommandRequirements;
|
||||
import com.massivecraft.factions.cmd.FCommand;
|
||||
import com.massivecraft.factions.cmd.audit.FLogType;
|
||||
import com.massivecraft.factions.event.FPlayerLeaveEvent;
|
||||
import com.massivecraft.factions.struct.Permission;
|
||||
import com.massivecraft.factions.struct.Role;
|
||||
import com.massivecraft.factions.util.CC;
|
||||
import com.massivecraft.factions.zcore.fperms.Access;
|
||||
import com.massivecraft.factions.zcore.fperms.PermissableAction;
|
||||
import com.massivecraft.factions.zcore.util.TL;
|
||||
@@ -126,7 +128,7 @@ public class CmdKickAlt extends FCommand {
|
||||
toKickFaction.promoteNewLeader();
|
||||
}
|
||||
|
||||
|
||||
FactionsPlugin.instance.logFactionEvent(toKickFaction, FLogType.INVITES, context.fPlayer.getName(), CC.Red + "kicked alt", toKick.getName());
|
||||
toKickFaction.removeAltPlayer(toKick);
|
||||
toKickFaction.deinvite(toKick);
|
||||
toKick.resetFactionData();
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
package com.massivecraft.factions.cmd.audit;
|
||||
|
||||
/**
|
||||
* @author Saser
|
||||
*/
|
||||
|
||||
import com.massivecraft.factions.Faction;
|
||||
import com.massivecraft.factions.cmd.CommandContext;
|
||||
import com.massivecraft.factions.cmd.CommandRequirements;
|
||||
import com.massivecraft.factions.cmd.FCommand;
|
||||
import com.massivecraft.factions.struct.Permission;
|
||||
import com.massivecraft.factions.zcore.util.TL;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class CmdAudit extends FCommand {
|
||||
|
||||
public CmdAudit() {
|
||||
super();
|
||||
this.aliases.add("audit");
|
||||
this.aliases.add("logs");
|
||||
this.aliases.add("log");
|
||||
|
||||
|
||||
this.requirements = new CommandRequirements.Builder(Permission.AUDIT)
|
||||
.playerOnly()
|
||||
.memberOnly()
|
||||
.noErrorOnManyArgs()
|
||||
.build();
|
||||
}
|
||||
@Override
|
||||
public void perform(CommandContext context) {
|
||||
Faction faction = context.args.size() == 1 && context.sender.isOp() ? context.argAsFaction(0) : context.faction;
|
||||
new FAuditMenu((Player)context.sender, faction).open((Player)context.sender);
|
||||
}
|
||||
|
||||
@Override
|
||||
public TL getUsageTranslation() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,157 @@
|
||||
package com.massivecraft.factions.cmd.audit;
|
||||
|
||||
/**
|
||||
* @author Saser
|
||||
*/
|
||||
import com.google.common.collect.Lists;
|
||||
import com.massivecraft.factions.Faction;
|
||||
import com.massivecraft.factions.FactionsPlugin;
|
||||
import com.massivecraft.factions.util.CC;
|
||||
import com.massivecraft.factions.util.ItemBuilder;
|
||||
import com.massivecraft.factions.util.serializable.ClickableItemStack;
|
||||
import com.massivecraft.factions.util.serializable.GUIMenu;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.inventory.ClickType;
|
||||
|
||||
import java.util.Iterator;
|
||||
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;
|
||||
|
||||
public FAuditMenu(Player player, Faction faction) {
|
||||
super("Faction Logs", 18);
|
||||
this.faction = faction;
|
||||
this.player = player;
|
||||
}
|
||||
|
||||
public void drawItems() {
|
||||
int index = 0;
|
||||
FLogType[] logTypes = FLogType.values();
|
||||
int length1 = logTypes.length;
|
||||
|
||||
for (FLogType type : logTypes) {
|
||||
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();
|
||||
}
|
||||
|
||||
LinkedList<FactionLogs.FactionLog> recentLogs = logs.getMostRecentLogs().get(type);
|
||||
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();
|
||||
while (backwars.hasNext()) {
|
||||
FactionLogs.FactionLog log = (FactionLogs.FactionLog) backwars.next();
|
||||
if (added >= logsPerPage) {
|
||||
break;
|
||||
}
|
||||
|
||||
String length = log.getLogLine(type, this.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...");
|
||||
}
|
||||
|
||||
lore.add("");
|
||||
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) -> {
|
||||
click.setCancelled(true);
|
||||
if (click.getClick() == ClickType.RIGHT) {
|
||||
this.showTimestamps = !this.showTimestamps;
|
||||
this.drawItems();
|
||||
} else {
|
||||
if (logsLeft <= 0) {
|
||||
this.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));
|
||||
}
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class FAuditLogMenu extends GUIMenu {
|
||||
private Player player;
|
||||
private Faction faction;
|
||||
private FLogType logType;
|
||||
private boolean timeStamp = false;
|
||||
|
||||
public FAuditLogMenu(Player player, Faction faction, FLogType type) {
|
||||
super("Faction Logs", 9);
|
||||
this.player = player;
|
||||
this.faction = faction;
|
||||
this.logType = type;
|
||||
}
|
||||
|
||||
public void drawItems() {
|
||||
FactionLogs logs = FactionsPlugin.instance.getFlogManager().getFactionLogMap().get(faction.getId());
|
||||
int perPage = this.logType == FLogType.F_TNT ? 25 : 20;
|
||||
if (logs != null) {
|
||||
LinkedList<FactionLogs.FactionLog> log = logs.getMostRecentLogs().get(this.logType);
|
||||
if (log != null) {
|
||||
int slot = this.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) {
|
||||
int startIndex = log.size() - (page * perPage - perPage);
|
||||
if (startIndex >= log.size()) {
|
||||
startIndex = log.size() - 1;
|
||||
}
|
||||
|
||||
List<String> lore = Lists.newArrayList("", CC.GreenB + "Logs");
|
||||
|
||||
for(int i = startIndex; i > startIndex - perPage; --i) {
|
||||
if (i < log.size()) {
|
||||
if (i < 0) {
|
||||
break;
|
||||
}
|
||||
|
||||
FactionLogs.FactionLog l = log.get(i);
|
||||
lore.add(" " + CC.Yellow + l.getLogLine(this.logType, this.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) -> {
|
||||
e.setCancelled(true);
|
||||
this.timeStamp = !this.timeStamp;
|
||||
this.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) -> {
|
||||
event.setCancelled(true);
|
||||
Bukkit.getScheduler().scheduleSyncDelayedTask(FactionsPlugin.instance, () -> (new FAuditMenu(this.player, this.faction)).open(this.player));
|
||||
}));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,109 @@
|
||||
package com.massivecraft.factions.cmd.audit;
|
||||
|
||||
/**
|
||||
* @author Saser
|
||||
*/
|
||||
import com.massivecraft.factions.FPlayer;
|
||||
import com.massivecraft.factions.FPlayers;
|
||||
import com.massivecraft.factions.Faction;
|
||||
import com.massivecraft.factions.FactionsPlugin;
|
||||
import com.massivecraft.factions.util.CC;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.inventory.ClickType;
|
||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
import org.bukkit.event.inventory.InventoryDragEvent;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
public class FChestListener implements Listener {
|
||||
|
||||
@EventHandler
|
||||
public void onInventoryDrag(InventoryDragEvent e) {
|
||||
|
||||
Player player = (Player) e.getWhoClicked();
|
||||
FPlayer fPlayer = FPlayers.getInstance().getByPlayer(player);
|
||||
if (!fPlayer.isInFactionsChest()) return;
|
||||
if (e.isCancelled()) return;
|
||||
e.setCancelled(true);
|
||||
e.getWhoClicked().sendMessage(CC.RedB + "(!) " + CC.Red + "You cannot drag items while viewing a /f chest!");
|
||||
}
|
||||
|
||||
|
||||
@EventHandler(
|
||||
priority = EventPriority.HIGHEST,
|
||||
ignoreCancelled = true
|
||||
)
|
||||
public void onPlayerClickInventory(InventoryClickEvent event) {
|
||||
Player player = (Player) event.getWhoClicked();
|
||||
FPlayer fPlayer = FPlayers.getInstance().getByPlayer(player);
|
||||
if (!fPlayer.isInFactionsChest()) return;
|
||||
|
||||
if (event.getClick() == ClickType.UNKNOWN) {
|
||||
event.setCancelled(true);
|
||||
player.sendMessage(CC.RedB + "(!) " + CC.Red + "You cannot use that click type inside the /f chest!");
|
||||
return;
|
||||
}
|
||||
|
||||
ItemStack currentItem = event.getCurrentItem();
|
||||
if (event.getClick() == ClickType.NUMBER_KEY) {
|
||||
currentItem = event.getClickedInventory().getItem(event.getSlot());
|
||||
}
|
||||
|
||||
Material currentItemType = currentItem != null ? currentItem.getType() : Material.AIR;
|
||||
|
||||
ItemStack cursorItem = event.getCursor();
|
||||
if (event.getClick() == ClickType.NUMBER_KEY) {
|
||||
cursorItem = player.getInventory().getItem(event.getHotbarButton());
|
||||
}
|
||||
|
||||
Material cursorItemType = cursorItem != null ? cursorItem.getType() : Material.AIR;
|
||||
FPlayer fplayer = FPlayers.getInstance().getByPlayer(player);
|
||||
Faction faction;
|
||||
if (fplayer == null || !(faction = fplayer.getFaction()).isNormal()) {
|
||||
player.closeInventory();
|
||||
player.sendMessage(CC.RedB + "(!) " + CC.Red + "You are no longer in your faction!");
|
||||
return;
|
||||
}
|
||||
|
||||
if (event.getClickedInventory() == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (event.getView().getTitle().equalsIgnoreCase(FactionsPlugin.getInstance().color(FactionsPlugin.getInstance().getConfig().getString("fchest.Inventory-Title")))) {
|
||||
if (currentItemType != Material.AIR) {
|
||||
Inventory ours = faction.getChestInventory();
|
||||
if (ours == null || !ours.contains(currentItem)) {
|
||||
event.setCancelled(true);
|
||||
player.sendMessage(CC.RedB + "(!) That item not longer exists!");
|
||||
Bukkit.getLogger().info("[FactionChest] " + player.getName() + " tried to remove " + currentItem + " from /f chest when it didnt contain! Items: " + (ours == null ? "none" : Arrays.toString(ours.getContents())));
|
||||
player.closeInventory();
|
||||
return;
|
||||
}
|
||||
|
||||
this.logRemoveItem(currentItem, fplayer, player);
|
||||
} else if (cursorItemType != Material.AIR && !event.isShiftClick()) {
|
||||
this.logAddItem(cursorItem, fplayer, player);
|
||||
}
|
||||
} else if (event.isShiftClick() && currentItemType != Material.AIR) {
|
||||
this.logAddItem(currentItem, fplayer, player);
|
||||
}
|
||||
}
|
||||
|
||||
private void logAddItem(ItemStack cursorItem, FPlayer fplayer, Player player) {
|
||||
String itemName = cursorItem.hasItemMeta() && cursorItem.getItemMeta().hasDisplayName() ? cursorItem.getItemMeta().getDisplayName() : StringUtils.capitaliseAllWords(cursorItem.getType().name().replace("_", " ").toLowerCase());
|
||||
FactionsPlugin.instance.logFactionEvent(fplayer.getFaction(), FLogType.FCHEST_EDIT, player.getName(), CC.GreenB + "ADDED", itemName);
|
||||
}
|
||||
|
||||
private void logRemoveItem(ItemStack currentItem, FPlayer fplayer, Player player) {
|
||||
String itemName = currentItem.hasItemMeta() && currentItem.getItemMeta().hasDisplayName() ? currentItem.getItemMeta().getDisplayName() : StringUtils.capitaliseAllWords(currentItem.getType().name().replace("_", " ").toLowerCase());
|
||||
FactionsPlugin.instance.logFactionEvent(fplayer.getFaction(), FLogType.FCHEST_EDIT, player.getName(), CC.RedB + "TOOK", itemName);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,151 @@
|
||||
package com.massivecraft.factions.cmd.audit;
|
||||
|
||||
/**
|
||||
* @author Saser
|
||||
*/
|
||||
import com.google.common.reflect.TypeToken;
|
||||
import com.massivecraft.factions.Faction;
|
||||
import com.massivecraft.factions.Factions;
|
||||
import com.massivecraft.factions.FactionsPlugin;
|
||||
import com.massivecraft.factions.util.JSONUtils;
|
||||
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<>();
|
||||
private File logFile;
|
||||
private Type logToken = (new TypeToken<ConcurrentHashMap<String, FactionLogs>>() {
|
||||
}).getType();
|
||||
private Map<UUID, LogTimer> logTimers = new ConcurrentHashMap<>();
|
||||
private boolean saving = false;
|
||||
|
||||
public FLogManager() {
|
||||
}
|
||||
|
||||
public void log(Faction faction, FLogType type, String... arguments) {
|
||||
FactionLogs logs = factionLogMap.computeIfAbsent(faction.getId(), (n) -> new FactionLogs());
|
||||
logs.log(type, arguments);
|
||||
}
|
||||
|
||||
public void loadLogs(FactionsPlugin plugin) {
|
||||
try {
|
||||
logFile = new File(plugin.getDataFolder(), "factionLogs.json");
|
||||
if (!logFile.exists()) {
|
||||
logFile.createNewFile();
|
||||
}
|
||||
|
||||
factionLogMap = (Map) JSONUtils.fromJson(logFile, logToken);
|
||||
if (factionLogMap == null) {
|
||||
factionLogMap = new ConcurrentHashMap<>();
|
||||
}
|
||||
|
||||
factionLogMap.forEach((factionId, factionLogs) -> {
|
||||
|
||||
Faction faction = Factions.getInstance().getFactionById(factionId);
|
||||
if (faction != null && faction.isNormal()) {
|
||||
factionLogs.checkExpired();
|
||||
if (factionLogs.isEmpty()) {
|
||||
factionLogMap.remove(factionId);
|
||||
}
|
||||
|
||||
} else {
|
||||
Bukkit.getLogger().info("Removing dead faction logs for " + factionId + "!");
|
||||
factionLogMap.remove(factionId);
|
||||
}
|
||||
});
|
||||
} catch (Exception e) {
|
||||
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!");
|
||||
} else {
|
||||
logTimers.forEach((uuid, logTimer) -> {
|
||||
if (logTimer != null && logTimer.getFactionId() != null) {
|
||||
Faction faction = Factions.getInstance().getFactionById(logTimer.getFactionId());
|
||||
if (faction == null) {
|
||||
logTimers.remove(uuid);
|
||||
Bukkit.getLogger().info("Null faction for logs " + logTimer.getFactionId());
|
||||
} else {
|
||||
if (logTimer.isEmpty()) {
|
||||
logTimers.remove(uuid);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
logTimers.remove(uuid);
|
||||
}
|
||||
});
|
||||
}
|
||||
}, 20L, 400L);
|
||||
}
|
||||
|
||||
public void pushPendingLogs(LogTimer.TimerType type) {
|
||||
Faction faction = null;
|
||||
|
||||
for (Map.Entry<UUID, LogTimer> uuidLogTimerEntry : getLogTimers().entrySet()) {
|
||||
Map.Entry<UUID, LogTimer> timer = uuidLogTimerEntry;
|
||||
LogTimer logTimer = timer.getValue();
|
||||
if (faction == null) {
|
||||
faction = Factions.getInstance().getFactionById(logTimer.getFactionId());
|
||||
}
|
||||
|
||||
if (type != null) {
|
||||
Map<LogTimer.TimerSubType, Timer> timers = (Map) logTimer.get(type);
|
||||
if (timers != null && faction != null) {
|
||||
logTimer.pushLogs(faction, type);
|
||||
}
|
||||
} else if (faction != null) {
|
||||
Faction finalFaction = faction;
|
||||
logTimer.keySet().forEach((timerType) -> logTimer.pushLogs(finalFaction, timerType));
|
||||
logTimer.clear();
|
||||
}
|
||||
}
|
||||
|
||||
if (type == null) {
|
||||
getLogTimers().clear();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void saveLogs() {
|
||||
if (saving) {
|
||||
Bukkit.getLogger().info("Ignoring saveLogs due to saving==true!");
|
||||
} else {
|
||||
saving = true;
|
||||
|
||||
try {
|
||||
pushPendingLogs(null);
|
||||
} catch (Exception e) {
|
||||
Bukkit.getLogger().info("error pushing pending logs: " + e.getMessage());
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
try {
|
||||
JSONUtils.saveJSONToFile(logFile, factionLogMap,logToken);
|
||||
} catch (Exception e1) {
|
||||
Bukkit.getLogger().info("ERRRO SAVING JSON LOGS: " + e1.getMessage());
|
||||
e1.printStackTrace();
|
||||
}
|
||||
|
||||
saving = false;
|
||||
}
|
||||
}
|
||||
|
||||
public Map<String, FactionLogs> getFactionLogMap() {
|
||||
return factionLogMap;
|
||||
}
|
||||
|
||||
public Map<UUID, LogTimer> getLogTimers() {
|
||||
return logTimers;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
package com.massivecraft.factions.cmd.audit;
|
||||
|
||||
import com.massivecraft.factions.util.XMaterial;
|
||||
import org.bukkit.Material;
|
||||
|
||||
/**
|
||||
* @author Saser
|
||||
*/
|
||||
public enum FLogType {
|
||||
|
||||
INVITES("Roster Edits", XMaterial.WRITABLE_BOOK.parseMaterial(), "&e%s&7 &a%s&7 &e%s", 3),
|
||||
BANS("Player Bans", XMaterial.ANVIL.parseMaterial(), "&e%s&7 &e%s&6 &e%s", 3),
|
||||
CHUNK_CLAIMS("Claim Edits", XMaterial.WOODEN_AXE.parseMaterial(), "&e%s&7 %s&7 &e%s&7 near &e%s", 3),
|
||||
PERM_EDIT_DEFAULTS("Default Perm Edits", XMaterial.WRITTEN_BOOK.parseMaterial(), "&e%s&7 %s&7 %s for &e%s", 4),
|
||||
BANK_EDIT("/f money Edits", XMaterial.GOLD_INGOT.parseMaterial(), "&e%s&7 %s &e&l$&e%s", 3),
|
||||
FCHEST_EDIT("/f chest Edits", XMaterial.CHEST.parseMaterial(), "&e%s&7 %s &f%s", 3),
|
||||
RELATION_CHANGE("Relation Edits", XMaterial.GOLDEN_SWORD.parseMaterial(), "&e%s %s&e'd %s", 3),
|
||||
FTAG_EDIT("/f tag Edits", XMaterial.NAME_TAG.parseMaterial(), "&e%s&7 set to &e'%s'", 2),
|
||||
FDESC_EDIT("/f desc Edits", XMaterial.PAPER.parseMaterial(), "&e%s&7 set to &e'%s'", 2),
|
||||
ROLE_PERM_EDIT("/f promote Edits", XMaterial.WRITTEN_BOOK.parseMaterial(), "&e%s&7&e %s &e%s &7to &e%s", 4),
|
||||
SPAWNER_EDIT("Spawner Edits", XMaterial.SPAWNER.parseMaterial(), "&e%s&7 %s &e%s&7 %s", 4),
|
||||
RANK_EDIT("Rank Edits", XMaterial.GOLDEN_HELMET.parseMaterial(), "&e%s&7 set &e%s&7 to %s", 3),
|
||||
F_TNT("/f tnt Edits", XMaterial.TNT.parseMaterial(), "&e%s&7 %s &e%s", 3);
|
||||
|
||||
private String displayName;
|
||||
private Material displayMaterial;
|
||||
private String msg;
|
||||
private int requiredArgs;
|
||||
|
||||
public String getDisplayName() {
|
||||
return this.displayName;
|
||||
}
|
||||
|
||||
public Material getDisplayMaterial() {
|
||||
return this.displayMaterial;
|
||||
}
|
||||
|
||||
public String getMsg() {
|
||||
return this.msg;
|
||||
}
|
||||
|
||||
public int getRequiredArgs() {
|
||||
return this.requiredArgs;
|
||||
}
|
||||
|
||||
FLogType(String displayName, Material displayMaterial, String msg, int requiredArgs) {
|
||||
this.displayName = displayName;
|
||||
this.displayMaterial = displayMaterial;
|
||||
this.msg = msg;
|
||||
this.requiredArgs = requiredArgs;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,106 @@
|
||||
package com.massivecraft.factions.cmd.audit;
|
||||
|
||||
/**
|
||||
* @author Saser
|
||||
*/
|
||||
import com.google.common.collect.Lists;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
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() {
|
||||
}
|
||||
|
||||
public void log(FLogType type, String... arguments) {
|
||||
if (type.getRequiredArgs() > arguments.length) {
|
||||
Bukkit.getLogger().info("INVALID ARGUMENT COUNT MET: " + type.getRequiredArgs() + " REQUIRED: ");
|
||||
Thread.dumpStack();
|
||||
} else {
|
||||
LinkedList<FactionLog> logs = this.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) {
|
||||
logs.pop();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isEmpty() {
|
||||
return this.mostRecentLogs.isEmpty();
|
||||
}
|
||||
|
||||
public void checkExpired() {
|
||||
long duration = TimeUnit.DAYS.toMillis(7L);
|
||||
List<FLogType> toRemove = Lists.newArrayList();
|
||||
mostRecentLogs.forEach((logType, logs) -> {
|
||||
if (logs == null) {
|
||||
toRemove.add(logType);
|
||||
} else if (logType != FLogType.F_TNT) {
|
||||
Iterator iter = logs.iterator();
|
||||
while (iter.hasNext()) {
|
||||
try {
|
||||
FactionLog log = (FactionLog) iter.next();
|
||||
if (log == null || log.isExpired(duration)) {
|
||||
iter.remove();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
Bukkit.getLogger().info("ERROR TRYING TO GET next FACTION LOG: " + e.getMessage());
|
||||
try {
|
||||
iter.remove();
|
||||
} catch (Exception e1) {
|
||||
e1.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
if (logs.size() <= 0)
|
||||
toRemove.add(logType);
|
||||
}
|
||||
});
|
||||
toRemove.forEach((rem) -> {
|
||||
LinkedList linkedList = this.mostRecentLogs.remove(rem);
|
||||
});
|
||||
}
|
||||
|
||||
public Map<FLogType, LinkedList<FactionLog>> getMostRecentLogs() {
|
||||
return this.mostRecentLogs;
|
||||
}
|
||||
|
||||
public class FactionLog {
|
||||
private long t;
|
||||
private List<String> a;
|
||||
|
||||
public FactionLog(long t, List<String> a) {
|
||||
this.t = t;
|
||||
this.a = a;
|
||||
}
|
||||
|
||||
public boolean isExpired(long duration) {
|
||||
return System.currentTimeMillis() - this.t >= duration;
|
||||
}
|
||||
|
||||
public String getLogLine(FLogType type, boolean timestamp) {
|
||||
String[] args = this.a.toArray(new String[0]);
|
||||
String timeFormat = "";
|
||||
if (timestamp) {
|
||||
timeFormat = FactionLogs.format.format(this.t);
|
||||
if (timeFormat.startsWith("0")) {
|
||||
timeFormat = timeFormat.substring(1);
|
||||
}
|
||||
}
|
||||
return String.format(ChatColor.translateAlternateColorCodes('&', type.getMsg()), (String[])args) + (timestamp ? ChatColor.GRAY + " - " + timeFormat : "");
|
||||
}
|
||||
}
|
||||
}
|
||||
126
src/main/java/com/massivecraft/factions/cmd/audit/LogTimer.java
Normal file
126
src/main/java/com/massivecraft/factions/cmd/audit/LogTimer.java
Normal file
@@ -0,0 +1,126 @@
|
||||
package com.massivecraft.factions.cmd.audit;
|
||||
|
||||
/**
|
||||
* @author Saser
|
||||
*/
|
||||
import com.massivecraft.factions.Faction;
|
||||
import com.massivecraft.factions.FactionsPlugin;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.material.MaterialData;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
public class LogTimer extends ConcurrentHashMap<LogTimer.TimerType, Map<LogTimer.TimerSubType, LogTimer.Timer>> {
|
||||
private String factionId;
|
||||
private String username;
|
||||
|
||||
public LogTimer(String username, String factionId) {
|
||||
this.username = username;
|
||||
this.factionId = factionId;
|
||||
}
|
||||
|
||||
public Map<LogTimer.TimerSubType, LogTimer.Timer> getCurrentTimersOrCreate(LogTimer.TimerType type) {
|
||||
return this.computeIfAbsent(type, (m) -> new ConcurrentHashMap<>());
|
||||
}
|
||||
|
||||
public LogTimer.Timer attemptLog(LogTimer.TimerType type, LogTimer.TimerSubType subType, long increment) {
|
||||
return this.getCurrentTimersOrCreate(type).computeIfAbsent(subType, (e) -> new Timer(System.currentTimeMillis(), 0L, null)).increment(increment);
|
||||
}
|
||||
|
||||
public void pushLogs(Faction faction, LogTimer.TimerType type) {
|
||||
StringBuilder soldString = new StringBuilder();
|
||||
forEach((timerType, map) -> {
|
||||
if (timerType == type) {
|
||||
if (timerType == LogTimer.TimerType.SPAWNER_EDIT) {
|
||||
map.forEach((subTimer, timer) -> {
|
||||
Map<EntityType, AtomicInteger> entityCounts = new HashMap<>();
|
||||
Map<MaterialData, AtomicInteger> currentCounts = (Map) timer.getExtraData();
|
||||
if (currentCounts != null) {
|
||||
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 + "!");
|
||||
} 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("_", " "))));
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
this.remove(type);
|
||||
}
|
||||
|
||||
public String getFactionId() {
|
||||
return this.factionId;
|
||||
}
|
||||
|
||||
public String getUsername() {
|
||||
return this.username;
|
||||
}
|
||||
|
||||
public class Timer {
|
||||
private long startTime;
|
||||
private long count;
|
||||
private Object extraData;
|
||||
|
||||
LogTimer.Timer increment(long amount) {
|
||||
this.count += amount;
|
||||
return this;
|
||||
}
|
||||
|
||||
public boolean isReadyToLog(long expiration) {
|
||||
return System.currentTimeMillis() - this.startTime >= expiration;
|
||||
}
|
||||
|
||||
public Timer(long startTime, long count, Object extraData) {
|
||||
this.startTime = startTime;
|
||||
this.count = count;
|
||||
this.extraData = extraData;
|
||||
}
|
||||
|
||||
public long getStartTime() {
|
||||
return this.startTime;
|
||||
}
|
||||
|
||||
public long getCount() {
|
||||
return this.count;
|
||||
}
|
||||
|
||||
public Object getExtraData() {
|
||||
return this.extraData;
|
||||
}
|
||||
|
||||
public void setStartTime(long startTime) {
|
||||
this.startTime = startTime;
|
||||
}
|
||||
|
||||
public void setCount(long count) {
|
||||
this.count = count;
|
||||
}
|
||||
|
||||
public void setExtraData(Object extraData) {
|
||||
this.extraData = extraData;
|
||||
}
|
||||
}
|
||||
|
||||
public enum TimerSubType {
|
||||
SPAWNER_BREAK,
|
||||
SPAWNER_PLACE;
|
||||
TimerSubType() {
|
||||
}
|
||||
}
|
||||
|
||||
public enum TimerType {
|
||||
SPAWNER_EDIT;
|
||||
TimerType() {
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,11 +1,15 @@
|
||||
package com.massivecraft.factions.cmd.claim;
|
||||
|
||||
import com.massivecraft.factions.FLocation;
|
||||
import com.massivecraft.factions.Faction;
|
||||
import com.massivecraft.factions.FactionsPlugin;
|
||||
import com.massivecraft.factions.cmd.CommandContext;
|
||||
import com.massivecraft.factions.cmd.CommandRequirements;
|
||||
import com.massivecraft.factions.cmd.FCommand;
|
||||
import com.massivecraft.factions.cmd.audit.FLogType;
|
||||
import com.massivecraft.factions.struct.Permission;
|
||||
import com.massivecraft.factions.struct.Role;
|
||||
import com.massivecraft.factions.util.CC;
|
||||
import com.massivecraft.factions.zcore.fperms.Access;
|
||||
import com.massivecraft.factions.zcore.fperms.PermissableAction;
|
||||
import com.massivecraft.factions.zcore.util.TL;
|
||||
@@ -59,7 +63,7 @@ public class CmdAutoClaim extends FCommand {
|
||||
}
|
||||
|
||||
context.fPlayer.setAutoClaimFor(forFaction);
|
||||
|
||||
FactionsPlugin.instance.logFactionEvent(forFaction, FLogType.CHUNK_CLAIMS, context.fPlayer.getName(), CC.GreenB + "CLAIMED", "1", new FLocation(context.fPlayer.getPlayer().getLocation()).formatXAndZ(","));
|
||||
context.msg(TL.COMMAND_AUTOCLAIM_ENABLED, forFaction.describeTo(context.fPlayer));
|
||||
context.fPlayer.attemptClaim(forFaction, context.fPlayer.getPlayer().getLocation(), true);
|
||||
}
|
||||
|
||||
@@ -3,11 +3,14 @@ package com.massivecraft.factions.cmd.claim;
|
||||
import com.massivecraft.factions.Conf;
|
||||
import com.massivecraft.factions.FLocation;
|
||||
import com.massivecraft.factions.Faction;
|
||||
import com.massivecraft.factions.FactionsPlugin;
|
||||
import com.massivecraft.factions.cmd.CommandContext;
|
||||
import com.massivecraft.factions.cmd.CommandRequirements;
|
||||
import com.massivecraft.factions.cmd.FCommand;
|
||||
import com.massivecraft.factions.cmd.audit.FLogType;
|
||||
import com.massivecraft.factions.struct.Permission;
|
||||
import com.massivecraft.factions.struct.Role;
|
||||
import com.massivecraft.factions.util.CC;
|
||||
import com.massivecraft.factions.util.SpiralTask;
|
||||
import com.massivecraft.factions.zcore.fperms.Access;
|
||||
import com.massivecraft.factions.zcore.fperms.PermissableAction;
|
||||
@@ -73,6 +76,7 @@ public class CmdClaim extends FCommand {
|
||||
boolean success = context.fPlayer.attemptClaim(forFaction, this.currentLocation(), true);
|
||||
if (success) {
|
||||
failCount = 0;
|
||||
FactionsPlugin.instance.logFactionEvent(forFaction, FLogType.CHUNK_CLAIMS, context.fPlayer.getName(), CC.GreenB + "CLAIMED", "1", (new FLocation(context.fPlayer.getPlayer().getLocation())).formatXAndZ(","));
|
||||
} else if (failCount++ >= limit) {
|
||||
this.stop();
|
||||
return false;
|
||||
|
||||
@@ -1,11 +1,15 @@
|
||||
package com.massivecraft.factions.cmd.claim;
|
||||
|
||||
import com.massivecraft.factions.Conf;
|
||||
import com.massivecraft.factions.FLocation;
|
||||
import com.massivecraft.factions.Faction;
|
||||
import com.massivecraft.factions.FactionsPlugin;
|
||||
import com.massivecraft.factions.cmd.CommandContext;
|
||||
import com.massivecraft.factions.cmd.CommandRequirements;
|
||||
import com.massivecraft.factions.cmd.FCommand;
|
||||
import com.massivecraft.factions.cmd.audit.FLogType;
|
||||
import com.massivecraft.factions.struct.Permission;
|
||||
import com.massivecraft.factions.util.CC;
|
||||
import com.massivecraft.factions.zcore.fperms.Access;
|
||||
import com.massivecraft.factions.zcore.fperms.PermissableAction;
|
||||
import com.massivecraft.factions.zcore.util.TL;
|
||||
@@ -83,8 +87,9 @@ public class CmdClaimLine extends FCommand {
|
||||
for (int i = 0; i < amount; i++) {
|
||||
context.fPlayer.attemptClaim(forFaction, location, true);
|
||||
location = location.add(blockFace.getModX() * 16, 0, blockFace.getModZ() * 16);
|
||||
FactionsPlugin.instance.logFactionEvent(forFaction, FLogType.CHUNK_CLAIMS, context.fPlayer.getName(), CC.GreenB + "CLAIMED", String.valueOf(i), new FLocation(context.player.getLocation()).formatXAndZ(","));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public TL getUsageTranslation() {
|
||||
|
||||
@@ -4,10 +4,12 @@ import com.massivecraft.factions.*;
|
||||
import com.massivecraft.factions.cmd.CommandContext;
|
||||
import com.massivecraft.factions.cmd.CommandRequirements;
|
||||
import com.massivecraft.factions.cmd.FCommand;
|
||||
import com.massivecraft.factions.cmd.audit.FLogType;
|
||||
import com.massivecraft.factions.event.LandUnclaimEvent;
|
||||
import com.massivecraft.factions.integration.Econ;
|
||||
import com.massivecraft.factions.struct.Permission;
|
||||
import com.massivecraft.factions.struct.Role;
|
||||
import com.massivecraft.factions.util.CC;
|
||||
import com.massivecraft.factions.util.SpiralTask;
|
||||
import com.massivecraft.factions.zcore.fperms.Access;
|
||||
import com.massivecraft.factions.zcore.fperms.PermissableAction;
|
||||
@@ -126,6 +128,7 @@ public class CmdUnclaim extends FCommand {
|
||||
}
|
||||
|
||||
Board.getInstance().removeAt(target);
|
||||
FactionsPlugin.instance.logFactionEvent(targetFaction, FLogType.CHUNK_CLAIMS, context.fPlayer.getName(), CC.RedB + "UNCLAIMED", "1", (new FLocation(context.fPlayer.getPlayer().getLocation())).formatXAndZ(","));
|
||||
|
||||
targetFaction.msg(TL.COMMAND_UNCLAIM_UNCLAIMED, context.fPlayer.describeTo(targetFaction, true));
|
||||
context.msg(TL.COMMAND_UNCLAIM_UNCLAIMS);
|
||||
@@ -180,6 +183,7 @@ public class CmdUnclaim extends FCommand {
|
||||
|
||||
Board.getInstance().removeAt(target);
|
||||
context.faction.msg(TL.COMMAND_UNCLAIM_FACTIONUNCLAIMED, context.fPlayer.describeTo(context.faction, true));
|
||||
FactionsPlugin.instance.logFactionEvent(targetFaction, FLogType.CHUNK_CLAIMS, context.fPlayer.getName(), CC.RedB + "UNCLAIMED", "1", (new FLocation(context.fPlayer.getPlayer().getLocation())).formatXAndZ(","));
|
||||
|
||||
if (Conf.logLandUnclaims) {
|
||||
FactionsPlugin.getInstance().log(TL.COMMAND_UNCLAIM_LOG.format(context.fPlayer.getName(), target.getCoordString(), targetFaction.getTag()));
|
||||
|
||||
@@ -1,15 +1,14 @@
|
||||
package com.massivecraft.factions.cmd.claim;
|
||||
|
||||
import com.massivecraft.factions.Board;
|
||||
import com.massivecraft.factions.Conf;
|
||||
import com.massivecraft.factions.Faction;
|
||||
import com.massivecraft.factions.FactionsPlugin;
|
||||
import com.massivecraft.factions.*;
|
||||
import com.massivecraft.factions.cmd.CommandContext;
|
||||
import com.massivecraft.factions.cmd.CommandRequirements;
|
||||
import com.massivecraft.factions.cmd.FCommand;
|
||||
import com.massivecraft.factions.cmd.audit.FLogType;
|
||||
import com.massivecraft.factions.event.LandUnclaimAllEvent;
|
||||
import com.massivecraft.factions.integration.Econ;
|
||||
import com.massivecraft.factions.struct.Permission;
|
||||
import com.massivecraft.factions.util.CC;
|
||||
import com.massivecraft.factions.zcore.fperms.PermissableAction;
|
||||
import com.massivecraft.factions.zcore.util.TL;
|
||||
import org.bukkit.Bukkit;
|
||||
@@ -73,9 +72,12 @@ public class CmdUnclaimall extends FCommand {
|
||||
if (unclaimAllEvent.isCancelled()) {
|
||||
return;
|
||||
}
|
||||
int unclaimed = target.getAllClaims().size();
|
||||
|
||||
|
||||
Board.getInstance().unclaimAll(target.getId());
|
||||
context.faction.msg(TL.COMMAND_UNCLAIMALL_UNCLAIMED, context.fPlayer.describeTo(context.faction, true));
|
||||
FactionsPlugin.instance.logFactionEvent(context.faction, FLogType.CHUNK_CLAIMS, context.fPlayer.getName(), CC.RedB + "UNCLAIMED", String.valueOf(unclaimed), new FLocation(context.fPlayer.getPlayer().getLocation()).formatXAndZ(","));
|
||||
|
||||
if (Conf.logLandUnclaims) {
|
||||
FactionsPlugin.getInstance().log(TL.COMMAND_UNCLAIMALL_LOG.format(context.fPlayer.getName(), context.faction.getTag()));
|
||||
|
||||
@@ -5,6 +5,7 @@ import com.massivecraft.factions.FactionsPlugin;
|
||||
import com.massivecraft.factions.cmd.CommandContext;
|
||||
import com.massivecraft.factions.cmd.CommandRequirements;
|
||||
import com.massivecraft.factions.cmd.FCommand;
|
||||
import com.massivecraft.factions.cmd.audit.FLogType;
|
||||
import com.massivecraft.factions.iface.EconomyParticipator;
|
||||
import com.massivecraft.factions.integration.Econ;
|
||||
import com.massivecraft.factions.struct.Permission;
|
||||
@@ -42,6 +43,8 @@ public class CmdMoneyDeposit extends FCommand {
|
||||
|
||||
if (success && Conf.logMoneyTransactions) {
|
||||
FactionsPlugin.getInstance().log(ChatColor.stripColor(FactionsPlugin.getInstance().txt.parse(TL.COMMAND_MONEYDEPOSIT_DEPOSITED.toString(), context.fPlayer.getName(), Econ.moneyString(amount), faction.describeTo(null))));
|
||||
FactionsPlugin.instance.logFactionEvent(context.faction, FLogType.BANK_EDIT, context.fPlayer.getName(), ChatColor.GREEN + ChatColor.BOLD.toString() + "DEPOSITED", amount + "");
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,14 +1,17 @@
|
||||
package com.massivecraft.factions.cmd.econ;
|
||||
|
||||
import com.massivecraft.factions.Conf;
|
||||
import com.massivecraft.factions.Faction;
|
||||
import com.massivecraft.factions.FactionsPlugin;
|
||||
import com.massivecraft.factions.cmd.CommandContext;
|
||||
import com.massivecraft.factions.cmd.CommandRequirements;
|
||||
import com.massivecraft.factions.cmd.FCommand;
|
||||
import com.massivecraft.factions.cmd.audit.FLogType;
|
||||
import com.massivecraft.factions.iface.EconomyParticipator;
|
||||
import com.massivecraft.factions.integration.Econ;
|
||||
import com.massivecraft.factions.struct.Permission;
|
||||
import com.massivecraft.factions.struct.Role;
|
||||
import com.massivecraft.factions.util.CC;
|
||||
import com.massivecraft.factions.zcore.fperms.Access;
|
||||
import com.massivecraft.factions.zcore.fperms.PermissableAction;
|
||||
import com.massivecraft.factions.zcore.util.TL;
|
||||
@@ -52,6 +55,7 @@ public class CmdMoneyWithdraw extends FCommand {
|
||||
|
||||
if (success && Conf.logMoneyTransactions) {
|
||||
FactionsPlugin.getInstance().log(ChatColor.stripColor(FactionsPlugin.getInstance().txt.parse(TL.COMMAND_MONEYWITHDRAW_WITHDRAW.toString(), context.fPlayer.getName(), Econ.moneyString(amount), faction.describeTo(null))));
|
||||
FactionsPlugin.instance.logFactionEvent((Faction) faction, FLogType.BANK_EDIT, context.fPlayer.getName(), CC.RedB + "WITHDREW", amount + "");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@ import com.massivecraft.factions.FactionsPlugin;
|
||||
import com.massivecraft.factions.cmd.CommandContext;
|
||||
import com.massivecraft.factions.cmd.CommandRequirements;
|
||||
import com.massivecraft.factions.cmd.FCommand;
|
||||
import com.massivecraft.factions.cmd.audit.FLogType;
|
||||
import com.massivecraft.factions.event.FactionRelationEvent;
|
||||
import com.massivecraft.factions.event.FactionRelationWishEvent;
|
||||
import com.massivecraft.factions.scoreboards.FTeamWrapper;
|
||||
@@ -83,6 +84,8 @@ public abstract class FRelationCommand extends FCommand {
|
||||
// trigger the faction relation event
|
||||
FactionRelationEvent relationEvent = new FactionRelationEvent(context.faction, them, oldRelation, currentRelation);
|
||||
Bukkit.getServer().getPluginManager().callEvent(relationEvent);
|
||||
FactionsPlugin.instance.logFactionEvent(context.faction, FLogType.RELATION_CHANGE,context.fPlayer.getName(), this.targetRelation.getColor() + this.targetRelation.name(), oldRelation.getColor() + them.getTag());
|
||||
FactionsPlugin.instance.logFactionEvent(them, FLogType.RELATION_CHANGE, oldRelation.getColor() + context.fPlayer.getName(), this.targetRelation.getColor() + this.targetRelation.name(), "your faction");
|
||||
|
||||
them.msg(TL.COMMAND_RELATIONS_MUTUAL, currentRelationColor + targetRelation.getTranslation(), currentRelationColor + context.faction.getTag());
|
||||
context.faction.msg(TL.COMMAND_RELATIONS_MUTUAL, currentRelationColor + targetRelation.getTranslation(), currentRelationColor + them.getTag());
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
package com.massivecraft.factions.cmd.roles;
|
||||
|
||||
import com.massivecraft.factions.FPlayer;
|
||||
import com.massivecraft.factions.FactionsPlugin;
|
||||
import com.massivecraft.factions.cmd.CommandContext;
|
||||
import com.massivecraft.factions.cmd.CommandRequirements;
|
||||
import com.massivecraft.factions.cmd.FCommand;
|
||||
import com.massivecraft.factions.cmd.audit.FLogType;
|
||||
import com.massivecraft.factions.struct.Permission;
|
||||
import com.massivecraft.factions.struct.Role;
|
||||
import com.massivecraft.factions.zcore.fperms.PermissableAction;
|
||||
@@ -82,6 +84,8 @@ public class FPromoteCommand extends FCommand {
|
||||
}
|
||||
|
||||
context.msg(TL.COMMAND_PROMOTE_SUCCESS, action, target.getName(), promotion.nicename);
|
||||
FactionsPlugin.instance.getFlogManager().log(context.faction, FLogType.ROLE_PERM_EDIT, context.fPlayer.getName(), action, target.getName(), promotion.nicename);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -4,6 +4,7 @@ import com.massivecraft.factions.FactionsPlugin;
|
||||
import com.massivecraft.factions.cmd.CommandContext;
|
||||
import com.massivecraft.factions.cmd.CommandRequirements;
|
||||
import com.massivecraft.factions.cmd.FCommand;
|
||||
import com.massivecraft.factions.cmd.audit.FLogType;
|
||||
import com.massivecraft.factions.struct.Permission;
|
||||
import com.massivecraft.factions.util.XMaterial;
|
||||
import com.massivecraft.factions.zcore.fperms.PermissableAction;
|
||||
@@ -76,6 +77,7 @@ public class CmdTnt extends FCommand {
|
||||
|
||||
context.faction.addTnt(amount);
|
||||
context.msg(TL.COMMAND_TNT_DEPOSIT_SUCCESS);
|
||||
FactionsPlugin.instance.getFlogManager().log(context.faction, FLogType.F_TNT, context.fPlayer.getName(), "DEPOSITED", amount + "x TNT");
|
||||
context.fPlayer.sendMessage(FactionsPlugin.instance.color(TL.COMMAND_TNT_AMOUNT.toString().replace("{amount}", context.faction.getTnt() + "").replace("{maxAmount}", context.faction.getTntBankLimit() + "")));
|
||||
return;
|
||||
|
||||
@@ -113,6 +115,7 @@ public class CmdTnt extends FCommand {
|
||||
context.faction.takeTnt(amount);
|
||||
context.player.updateInventory();
|
||||
context.msg(TL.COMMAND_TNT_WIDTHDRAW_SUCCESS);
|
||||
FactionsPlugin.instance.getFlogManager().log(context.faction, FLogType.F_TNT, context.fPlayer.getName(), "WITHDREW", amount + "x TNT");
|
||||
}
|
||||
} else if (context.args.size() == 1) {
|
||||
if (context.args.get(0).equalsIgnoreCase("addall")) {
|
||||
@@ -136,6 +139,8 @@ public class CmdTnt extends FCommand {
|
||||
context.player.updateInventory();
|
||||
context.faction.addTnt(invTnt);
|
||||
context.msg(TL.COMMAND_TNT_DEPOSIT_SUCCESS);
|
||||
FactionsPlugin.instance.getFlogManager().log(context.faction, FLogType.F_TNT, context.fPlayer.getName(), "DEPOSITED", invTnt + "x TNT");
|
||||
|
||||
context.fPlayer.sendMessage(FactionsPlugin.instance.color(TL.COMMAND_TNT_AMOUNT.toString().replace("{amount}", context.faction.getTnt() + "").replace("{maxAmount}", context.faction.getTntBankLimit() + "")));
|
||||
return;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user