Initial commit

This commit is contained in:
Scifi9902
2026-10-12 13:57:05 -03:00
commit 4bde3b176a
2576 changed files with 212659 additions and 0 deletions
@@ -0,0 +1,60 @@
package net.crankedpvp.factionlogs;
import lombok.Getter;
import net.crankedpvp.factionlogs.commands.FactionLogsCommand;
import net.crankedpvp.factionlogs.data.FactionLogsData;
import net.crankedpvp.factionlogs.data.FactionLogsManager;
import net.crankedpvp.factionlogs.listeners.FactionListeners;
import net.crankedpvp.factionlogs.struct.typeadapters.FactionLogDeserializer;
import net.crankedpvp.storageutils.StorageUtils;
import net.crankedpvp.storageutils.gson.Gson;
import org.bukkit.Bukkit;
import org.bukkit.plugin.java.JavaPlugin;
@Getter
public class FactionLogsPlugin extends JavaPlugin {
public FactionLogsManager logManager;
private static FactionLogsPlugin instance;
private Gson gson;
public void onEnable() {
instance = this;
this.gson = StorageUtils.getInstance()
.getGson()
.newBuilder()
.registerTypeAdapter(FactionLogsData.class, new FactionLogDeserializer()).setLenient()
.create();
this.logManager = new FactionLogsManager();
this.logManager.loadAll();
loadListeners();
loadCommands();
Bukkit.getScheduler().runTaskTimer(this, () -> {
this.logManager.saveAll();
}, 100L, 20 * 60 * 15);
}
public void onDisable() {
//this.logManager.purge();
this.logManager.saveAll();
instance = null;
}
public void loadListeners() {
Bukkit.getPluginManager().registerEvents(new FactionListeners(), this);
}
public void loadCommands() {
Bukkit.getPluginManager().registerEvents(new FactionLogsCommand(), this);
}
public static FactionLogsPlugin getInstance() {
return instance;
}
}
@@ -0,0 +1,37 @@
package net.crankedpvp.factionlogs.commands;
import com.massivecraft.factions.FPlayer;
import com.massivecraft.factions.FPlayers;
import com.massivecraft.factions.perms.Role;
import net.crankedpvp.crankedutils.utils.Arrow;
import net.crankedpvp.crankedutils.utils.CC;
import net.crankedpvp.factionlogs.gui.FactionLogsGUI;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
public class FactionLogsCommand implements Listener {
@EventHandler(priority = EventPriority.LOWEST)
public void onCommand(PlayerCommandPreprocessEvent event) {
if (event.getMessage().equalsIgnoreCase("/f logs") || event.getMessage().equalsIgnoreCase("/f log")) {
event.setMessage("/null");
event.setCancelled(true);
FPlayer fPlayer = FPlayers.getInstance().getByPlayer(event.getPlayer());
if (!fPlayer.hasFaction()) {
fPlayer.sendMessage(CC.translate("&a&lFactions &8" + Arrow.arrow() + " &cError&8: &7You need a faction to type this command!"));
return;
}
if (!fPlayer.getRole().isAtLeast(Role.MODERATOR)) {
fPlayer.sendMessage(CC.translate("&a&lFactions &8" + Arrow.arrow() + " &cError&8: &7You need to be atleast a mod to type this command!"));
return;
}
FactionLogsGUI factionLogsGUI = new FactionLogsGUI(event.getPlayer(), fPlayer.getFaction());
factionLogsGUI.getFLogGui().open(event.getPlayer());
fPlayer.sendMessage(CC.translate("&a&lFactions &8" + Arrow.arrow() + "&7 Opening the faction logs gui."));
}
}
}
@@ -0,0 +1,43 @@
package net.crankedpvp.factionlogs.data;
import lombok.Getter;
import net.crankedpvp.factionlogs.enums.LogType;
import net.crankedpvp.factionlogs.struct.FactionLog;
import net.crankedpvp.storageutils.utils.KeyToSave;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@Getter
public class FactionLogsData implements KeyToSave {
private final Map<LogType, List<FactionLog>> logs;
private String factionId;
public FactionLogsData(String factionId) {
this.factionId = factionId;
this.logs = new HashMap<>();
}
public void addFactionLog(FactionLog factionLog) {
if (this.logs.containsKey(factionLog.getLogtype())) {
this.logs.get(factionLog.getLogtype()).add(factionLog);
} else {
List<FactionLog> list = new ArrayList<>();
list.add(factionLog);
this.logs.put(factionLog.getLogtype(), list);
}
}
@Override
public String getKey() {
return factionId;
}
@Override
public void setKey(String s) {
this.factionId = s;
}
}
@@ -0,0 +1,19 @@
package net.crankedpvp.factionlogs.data;
import net.crankedpvp.factionlogs.FactionLogsPlugin;
import net.crankedpvp.storageutils.utils.SaveLoadManager;
public class FactionLogsManager extends SaveLoadManager<FactionLogsData> {
public FactionLogsManager() {
super(FactionLogsPlugin.getInstance(), FactionLogsPlugin.getInstance().getGson(), "data/", FactionLogsData.class);
}
public FactionLogsData getFactionLogsData(String factionId) {
if (!super.containsKey(factionId)) {
FactionLogsData factionLogsData = new FactionLogsData(factionId);
addToCache(factionLogsData);
}
return getFromCache(factionId);
}
}
@@ -0,0 +1,32 @@
package net.crankedpvp.factionlogs.enums;
import lombok.AllArgsConstructor;
import lombok.Getter;
import net.crankedpvp.factionlogs.struct.FactionLog;
import net.crankedpvp.factionlogs.struct.impl.*;
import org.bukkit.Material;
@AllArgsConstructor
@Getter
public enum LogType {
SPAWNER_PLACE("Spawner Place Logs", Material.MOB_SPAWNER, "&a&l", SpawnerPlace.class),
SPAWNER_BREAK("Spawner Break Logs", Material.MOB_SPAWNER, "&c&l", SpawnerBreak.class),
RELATION_EDITS("Relation Edits", Material.DIAMOND_CHESTPLATE, "&d&l", RelationEdits.class),
FACTION_RENAME("Rename Logs", Material.NAME_TAG, "&b&l", FactionRename.class),
PLAYER_LEAVE("Player Leaves", Material.WOOD_DOOR, "&c&l", PlayerLeave.class),
PLAYER_JOIN("Player Joins", Material.IRON_DOOR, "&a&l", PlayerJoin.class),
CLAIM("Claim Logs", Material.GRASS, "&a&l", LandClaim.class),
RADIUSCLAIM("Radius Claim Logs", Material.GRAVEL, "&e&l", RadiusLandClaim.class),
UNCLAIM("Unclaim Logs", Material.DIRT, "&c&l", LandUnclaim.class),
UNCLAIMALL("Unclaimall Logs", Material.REDSTONE_BLOCK, "&4&l", LandUnclaimAll.class),
CHUNKBUST("Chunkbust Logs", Material.ENDER_PORTAL_FRAME, "&3&l", ChunkBust.class);
private final String displayName;
private final Material guiMaterial;
private final String guiColorCode;
private final Class<? extends FactionLog> logClass;
}
@@ -0,0 +1,113 @@
package net.crankedpvp.factionlogs.gui;
import com.massivecraft.factions.Faction;
import dev.triumphteam.gui.guis.GuiItem;
import dev.triumphteam.gui.guis.PaginatedGui;
import lombok.Getter;
import net.crankedpvp.crankedutils.utils.Arrow;
import net.crankedpvp.crankedutils.utils.CC;
import net.crankedpvp.crankedutils.utils.items.ItemBuilder;
import net.crankedpvp.factionlogs.FactionLogsPlugin;
import net.crankedpvp.factionlogs.enums.LogType;
import net.crankedpvp.factionlogs.struct.FactionLog;
import net.crankedpvp.factionlogs.struct.impl.*;
import net.crankedpvp.factionlogs.utils.*;
import org.bukkit.Bukkit;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player;
import java.util.Collections;
import java.util.UUID;
import java.util.stream.Collectors;
public class FactionLogsGUI {
@Getter
private final PaginatedGui fLogGui;
public FactionLogsGUI(Player player, Faction faction) {
this.fLogGui = new PaginatedGui(3, CC.translate(CC.DarkGray + faction.getTag() + " Faction Logs"));
for (LogType logType : LogType.values()) {
ItemBuilder item = new ItemBuilder(logType.getGuiMaterial(), CC.translate(logType.getGuiColorCode() + logType.getDisplayName()))
.addLoreLine(CC.translate("&7Below you can find the 10 latest logs:"))
.addLoreLine("")
.addLoreLine(CC.translate("&f&l" + logType.getDisplayName() + " &7(" + FactionsLogsAPI.getFactionLogs(faction, logType).size() + " total)"));
String prefix = logType.getGuiColorCode() + " * &e";
FactionsLogsAPI.getFactionLogs(faction, logType).sort(Collections.reverseOrder());
for (FactionLog log : FactionsLogsAPI.getFactionLogs(faction, logType).stream().limit(10).collect(Collectors.toList())) {
try {
switch (logType) {
case CLAIM:
LandClaim landClaim = (LandClaim) log;
item.addLoreLine(CC.translate(prefix + Bukkit.getOfflinePlayer(UUID.fromString(landClaim.getUuid())).getName() + " &7claimed land at &d" + LocationUtils.locToString(landClaim.getFLocation()) + "&7. &8(&7" + TimeDateUtils.splitToComponentTimes((System.currentTimeMillis() - log.getTime()) / 1000) + "ago&8)"));
break;
case RADIUSCLAIM:
RadiusLandClaim radiusLandClaim = (RadiusLandClaim) log;
item.addLoreLine(CC.translate(prefix + Bukkit.getOfflinePlayer(UUID.fromString(radiusLandClaim.getUuid())).getName() + " &7claimed land in a &d" + radiusLandClaim.getRadius() + " &7radius at &d" + LocationUtils.locToString(radiusLandClaim.getFLocation()) + "&7. &8(&7" + TimeDateUtils.splitToComponentTimes((System.currentTimeMillis() - log.getTime()) / 1000) + "ago&8)"));
break;
case UNCLAIM:
LandUnclaim landUnClaim = (LandUnclaim) log;
item.addLoreLine(CC.translate(prefix + Bukkit.getOfflinePlayer(UUID.fromString(landUnClaim.getUuid())).getName() + " &7unclaimed land at &d" + LocationUtils.locToString(landUnClaim.getFLocation()) + "&7. &8(&7" + TimeDateUtils.splitToComponentTimes((System.currentTimeMillis() - log.getTime()) / 1000) + "ago&8)"));
break;
case UNCLAIMALL:
LandUnclaimAll landUnclaimAll = (LandUnclaimAll) log;
item.addLoreLine(CC.translate(prefix + Bukkit.getOfflinePlayer(UUID.fromString(landUnclaimAll.getUuid())).getName() + " &7unclaimed ALL land. " + "&8(&7" + TimeDateUtils.splitToComponentTimes((System.currentTimeMillis() - log.getTime()) / 1000) + "ago&8)"));
break;
case PLAYER_JOIN:
PlayerJoin playerJoin = (PlayerJoin) log;
if (playerJoin.getPlayerJoinReason() == null) break;
item.addLoreLine(CC.translate(prefix + Bukkit.getOfflinePlayer(UUID.fromString(playerJoin.getUuid())).getName() + " &7join the faction due to &e" + playerJoin.getPlayerJoinReason().name().toLowerCase() + "&7. &8(&7" + TimeDateUtils.splitToComponentTimes((System.currentTimeMillis() - log.getTime()) / 1000) + "ago&8)"));
break;
case PLAYER_LEAVE:
PlayerLeave playerLeave = (PlayerLeave) log;
item.addLoreLine(CC.translate(prefix + Bukkit.getOfflinePlayer(UUID.fromString(playerLeave.getUuid())).getName() + " &7left the faction due to &e" + playerLeave.getPlayerLeaveReason().name().toLowerCase() + "&7. &8(&7" + TimeDateUtils.splitToComponentTimes((System.currentTimeMillis() - log.getTime()) / 1000) + "ago&8)"));
break;
case CHUNKBUST:
ChunkBust chunkBust = (ChunkBust) log;
item.addLoreLine(CC.translate(prefix + Bukkit.getOfflinePlayer(UUID.fromString(chunkBust.getUuid())).getName() + " &7placed a chunkbuster at &d" + LocationUtils.locToString(chunkBust.getLocation()) + "&7. &8(&7" + TimeDateUtils.splitToComponentTimes((System.currentTimeMillis() - log.getTime()) / 1000) + "ago&8)"));
break;
case SPAWNER_BREAK:
SpawnerBreak spawnerBreak = (SpawnerBreak) log;
item.addLoreLine(CC.translate(prefix + Bukkit.getOfflinePlayer(UUID.fromString(spawnerBreak.getUuid())).getName() + " &7broke &ex" + spawnerBreak.getAmount() + " " + EntityUtils.getEntityName(EntityType.valueOf(spawnerBreak.getEntityType())) + "&7 at &d" + LocationUtils.locToString(spawnerBreak.getLocation()) + "&7. &8(&7" + TimeDateUtils.splitToComponentTimes((System.currentTimeMillis() - log.getTime()) / 1000) + "ago&8)"));
break;
case SPAWNER_PLACE:
SpawnerPlace spawnerPlace = (SpawnerPlace) log;
item.addLoreLine(CC.translate(prefix + Bukkit.getOfflinePlayer(UUID.fromString(spawnerPlace.getUuid())).getName() + " &7placed &ex" + spawnerPlace.getAmount() + " " + EntityUtils.getEntityName(EntityType.valueOf(spawnerPlace.getEntityType())) + "&7 at &d" + LocationUtils.locToString(spawnerPlace.getLocation()) + "&7. &8(&7" + TimeDateUtils.splitToComponentTimes((System.currentTimeMillis() - log.getTime()) / 1000) + "ago&8)"));
break;
case RELATION_EDITS:
RelationEdits relationEdits = (RelationEdits) log;
item.addLoreLine(CC.translate(prefix + relationEdits.getSender() + " &7changed relation: &d" + relationEdits.getOldRelation() + " &7-> &d" + relationEdits.getNewRelation() + "&7. &8(&7" + TimeDateUtils.splitToComponentTimes((System.currentTimeMillis() - log.getTime()) / 1000) + "ago&8)"));
break;
case FACTION_RENAME:
FactionRename factionRename = (FactionRename) log;
item.addLoreLine(CC.translate(prefix + Bukkit.getOfflinePlayer(UUID.fromString(factionRename.getPlayer())).getName() + " &7renamed the faction tag &d" + factionRename.getOldTag() + " &7-> &d" + factionRename.getNewTag() + "&7. &8(&7" + TimeDateUtils.splitToComponentTimes((System.currentTimeMillis() - log.getTime()) / 1000) + "ago&8)"));
break;
}
} catch (Exception e) {
e.printStackTrace();
}
}
item.addLoreLine("");
item.addLoreLine(CC.translate("&7&nClick&7 to view all the " + FactionsLogsAPI.getFactionLogs(faction, logType).size() + " " + logType.getDisplayName()));
this.fLogGui.addItem(new GuiItem(item.build(), event -> {
Bukkit.getScheduler().runTaskAsynchronously(FactionLogsPlugin.getInstance(), () -> {
if (FactionsLogsAPI.getFactionLogs(faction, logType).isEmpty()) {
player.sendMessage(CC.translate("&a&lFactions &8" + Arrow.arrow() + " &cError&8: &7There are no " + logType.getDisplayName() + " available!"));
return;
}
HastebinUtils.sendLog(player, faction.getId(), logType, false);
});
}));
}
this.fLogGui.setDefaultClickAction(event -> event.setCancelled(true));
}
}
@@ -0,0 +1,84 @@
package net.crankedpvp.factionlogs.listeners;
import com.massivecraft.factions.Faction;
import com.massivecraft.factions.event.*;
import de.tr7zw.nbtapi.NBTItem;
import net.crankedpvp.crankedutils.utils.FactionUtils;
import net.crankedpvp.crankedutils.utils.items.ItemUtils;
import net.crankedpvp.factionlogs.struct.impl.*;
import net.crankedpvp.factionlogs.utils.FactionsLogsAPI;
import org.bukkit.Material;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.block.BlockPlaceEvent;
public class FactionListeners implements Listener {
@EventHandler
public void onCBusterPlace(BlockPlaceEvent event) {
if (ItemUtils.isAirOrNull(event.getItemInHand())) return;
if (event.getItemInHand().getType() != Material.ENDER_PORTAL_FRAME) return;
NBTItem nbtItem = new NBTItem(event.getItemInHand());
if(!nbtItem.hasKey("kore.chunkbuster.isbuster")) return;
Faction faction = FactionUtils.getFaction(event.getPlayer());
FactionsLogsAPI.log(faction.getId(), new ChunkBust(event.getBlock().getLocation(), event.getPlayer().getUniqueId()));
}
@EventHandler
public void onLandClaim(LandClaimEvent event) {
if (event.isCancelled()) return;
FactionsLogsAPI.log(event.getFactionId(), new LandClaim(event.getfPlayer().getPlayer().getUniqueId(), event.getPlayer().getLocation()));
}
@EventHandler
public void onLandUnClaim(LandUnclaimEvent event) {
if (event.isCancelled()) return;
FactionsLogsAPI.log(event.getFactionId(), new LandUnclaim(event.getfPlayer().getPlayer().getUniqueId(), event.getPlayer().getLocation()));
}
@EventHandler
public void onLandUnClaimAll(LandUnclaimAllEvent event) {
if (event.isCancelled()) return;
FactionsLogsAPI.log(event.getFactionId(), new LandUnclaimAll(event.getfPlayer().getPlayer().getUniqueId()));
}
@EventHandler
public void onRadiusLandClaim(LandClaimRadiusEvent event) {
if (event.isCancelled()) return;
FactionsLogsAPI.log(event.getFactionId(), new RadiusLandClaim(event.getfPlayer().getPlayer().getUniqueId(), event.getfPlayer().getLocation(), event.getRadius()));
}
@EventHandler
public void onPlayerJoinFaction(FPlayerJoinEvent event) {
if (event.isCancelled()) return;
FactionsLogsAPI.log(event.getFaction().getId(), new PlayerJoin(event.getfPlayer().getPlayer().getUniqueId(), event.getReason()));
}
@EventHandler
public void onPlayerLeaveFaction(FPlayerLeaveEvent event) {
if (event.isCancelled()) return;
if (event.getfPlayer() == null) return;
if (event.getfPlayer().getPlayer() == null) return;
if (event.getfPlayer().getPlayer().getUniqueId() == null) return;
if (event.getReason() == null) return;
FactionsLogsAPI.log(event.getFaction().getId(), new PlayerLeave(event.getfPlayer().getPlayer().getUniqueId(), event.getReason()));
}
@EventHandler
public void onRelationChange(FactionRelationEvent event) {
FactionsLogsAPI.log(event.getFaction().getId(), new RelationEdits(event.getFaction(), event.getTargetFaction(), event.getOldRelation(), event.getRelation()));
FactionsLogsAPI.log(event.getTargetFaction().getId(), new RelationEdits(event.getFaction(), event.getTargetFaction(), event.getOldRelation(), event.getRelation()));
}
@EventHandler
public void onFactionRename(FactionRenameEvent event) {
if (event.isCancelled()) return;
FactionsLogsAPI.log(event.getFaction().getId(), new FactionRename(event.getPlayer().getUniqueId(), event.getOldFactionTag(), event.getFactionTag()));
}
@EventHandler
public void onFactionCreate(FactionCreateEvent event) {
FactionsLogsAPI.getFactionLogs(event.getFaction()).clear();
}
}
@@ -0,0 +1,21 @@
package net.crankedpvp.factionlogs.struct;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import lombok.Setter;
import net.crankedpvp.factionlogs.enums.LogType;
@RequiredArgsConstructor
@Getter
public abstract class FactionLog implements Comparable<FactionLog> {
private final LogType logtype;
@Setter
private Long time = System.currentTimeMillis();
@Override
public int compareTo(FactionLog e) {
return this.getTime().compareTo(e.getTime());
}
}
@@ -0,0 +1,38 @@
package net.crankedpvp.factionlogs.struct.impl;
import lombok.Getter;
import net.crankedpvp.factionlogs.enums.LogType;
import net.crankedpvp.factionlogs.struct.FactionLog;
import net.crankedpvp.factionlogs.utils.LocationUtils;
import net.crankedpvp.factionlogs.utils.TimeDateUtils;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import java.util.UUID;
@Getter
public class ChunkBust extends FactionLog {
private final Location location;
private final String uuid;
public ChunkBust(Location location, UUID uuid) {
super(LogType.CHUNKBUST);
this.location = location;
this.uuid = uuid.toString();
}
public ChunkBust(Location location, UUID uuid, long time) {
super(LogType.CHUNKBUST);
this.location = location;
this.uuid = uuid.toString();
super.setTime(time);
}
@Override
public String toString() {
return "(" + TimeDateUtils.splitToComponentTimes((System.currentTimeMillis() - getTime()) / 1000) + "ago) " + Bukkit.getOfflinePlayer(UUID.fromString(getUuid())).getName() + " chunkbusted at " + LocationUtils.locToString(getLocation()) + "&7.";
}
}
@@ -0,0 +1,38 @@
package net.crankedpvp.factionlogs.struct.impl;
import lombok.Getter;
import net.crankedpvp.factionlogs.enums.LogType;
import net.crankedpvp.factionlogs.struct.FactionLog;
import net.crankedpvp.factionlogs.utils.TimeDateUtils;
import org.bukkit.Bukkit;
import java.util.UUID;
@Getter
public class FactionRename extends FactionLog {
private final String player;
private final String oldTag;
private final String newTag;
public FactionRename(UUID playerUUID, String oldTag, String newTag) {
super(LogType.FACTION_RENAME);
this.player = playerUUID.toString();
this.oldTag = oldTag;
this.newTag = newTag;
}
public FactionRename(UUID playerUUID, String oldTag, String newTag, long time) {
super(LogType.FACTION_RENAME);
this.player = playerUUID.toString();
this.oldTag = oldTag;
this.newTag = newTag;
super.setTime(time);
}
@Override
public String toString() {
return "(" + TimeDateUtils.splitToComponentTimes((System.currentTimeMillis() - getTime()) / 1000) + "ago) " + Bukkit.getOfflinePlayer(UUID.fromString(player)).getName() + " renamed the faction tag " + getOldTag() + " -> " + getNewTag() + ".";
}
}
@@ -0,0 +1,36 @@
package net.crankedpvp.factionlogs.struct.impl;
import lombok.Getter;
import net.crankedpvp.factionlogs.enums.LogType;
import net.crankedpvp.factionlogs.struct.FactionLog;
import net.crankedpvp.factionlogs.utils.LocationUtils;
import net.crankedpvp.factionlogs.utils.TimeDateUtils;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import java.util.UUID;
@Getter
public class LandClaim extends FactionLog {
private final String uuid;
private final Location fLocation;
public LandClaim(UUID uuid, Location fLocation) {
super(LogType.CLAIM);
this.uuid = uuid.toString();
this.fLocation = fLocation;
}
public LandClaim(UUID uuid, Location fLocation, long time) {
super(LogType.CLAIM);
this.uuid = uuid.toString();
this.fLocation = fLocation;
super.setTime(time);
}
@Override
public String toString() {
return "(" + TimeDateUtils.splitToComponentTimes((System.currentTimeMillis() - getTime()) / 1000) + "ago) " + Bukkit.getOfflinePlayer(UUID.fromString(uuid)).getName() + " claimed land at " + LocationUtils.locToString(fLocation);
}
}
@@ -0,0 +1,35 @@
package net.crankedpvp.factionlogs.struct.impl;
import lombok.Getter;
import net.crankedpvp.factionlogs.enums.LogType;
import net.crankedpvp.factionlogs.struct.FactionLog;
import net.crankedpvp.factionlogs.utils.LocationUtils;
import net.crankedpvp.factionlogs.utils.TimeDateUtils;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import java.util.UUID;
@Getter
public class LandUnclaim extends FactionLog {
private final String uuid;
private final Location fLocation;
public LandUnclaim(UUID uuid, Location fLocation) {
super(LogType.UNCLAIM);
this.uuid = uuid.toString();
this.fLocation = fLocation;
}
public LandUnclaim(UUID uuid, Location fLocation, long time) {
super(LogType.UNCLAIM);
this.uuid = uuid.toString();
this.fLocation = fLocation;
super.setTime(time);
}
@Override
public String toString() {
return "(" + TimeDateUtils.splitToComponentTimes((System.currentTimeMillis() - getTime()) / 1000) + "ago) " + Bukkit.getOfflinePlayer(UUID.fromString(uuid)).getName() + " unclaimed land at " + LocationUtils.locToString(fLocation);
}
}
@@ -0,0 +1,33 @@
package net.crankedpvp.factionlogs.struct.impl;
import lombok.Getter;
import net.crankedpvp.factionlogs.enums.LogType;
import net.crankedpvp.factionlogs.struct.FactionLog;
import net.crankedpvp.factionlogs.utils.TimeDateUtils;
import org.bukkit.Bukkit;
import java.util.UUID;
@Getter
public class LandUnclaimAll extends FactionLog {
private final String uuid;
public LandUnclaimAll(UUID uuid) {
super(LogType.UNCLAIMALL);
this.uuid = uuid.toString();
}
public LandUnclaimAll(UUID uuid, long time) {
super(LogType.UNCLAIMALL);
this.uuid = uuid.toString();
super.setTime(time);
}
@Override
public String toString() {
return "(" + TimeDateUtils.splitToComponentTimes((System.currentTimeMillis() - getTime()) / 1000) + "ago) " + Bukkit.getOfflinePlayer(UUID.fromString(uuid)).getName() + " unclaimed ALL land";
}
}
@@ -0,0 +1,38 @@
package net.crankedpvp.factionlogs.struct.impl;
import com.massivecraft.factions.event.FPlayerJoinEvent;
import lombok.Getter;
import net.crankedpvp.factionlogs.enums.LogType;
import net.crankedpvp.factionlogs.struct.FactionLog;
import net.crankedpvp.factionlogs.utils.TimeDateUtils;
import org.bukkit.Bukkit;
import java.util.UUID;
@Getter
public class PlayerJoin extends FactionLog {
private final String uuid;
private transient final FPlayerJoinEvent.PlayerJoinReason playerJoinReason;
public PlayerJoin(UUID uuid, FPlayerJoinEvent.PlayerJoinReason playerJoinReason) {
super(LogType.PLAYER_JOIN);
this.uuid = uuid.toString();
this.playerJoinReason = playerJoinReason;
}
public PlayerJoin(UUID uuid, FPlayerJoinEvent.PlayerJoinReason playerJoinReason, long time) {
super(LogType.PLAYER_JOIN);
this.uuid = uuid.toString();
this.playerJoinReason = playerJoinReason;
super.setTime(time);
}
@Override
public String toString() {
return "(" + TimeDateUtils.splitToComponentTimes((System.currentTimeMillis() - getTime()) / 1000) + "ago) " + Bukkit.getOfflinePlayer(UUID.fromString(uuid)).getName() + " joined the faction because of: " + playerJoinReason;
}
}
@@ -0,0 +1,38 @@
package net.crankedpvp.factionlogs.struct.impl;
import com.massivecraft.factions.event.FPlayerLeaveEvent;
import lombok.Getter;
import net.crankedpvp.factionlogs.enums.LogType;
import net.crankedpvp.factionlogs.struct.FactionLog;
import net.crankedpvp.factionlogs.utils.TimeDateUtils;
import org.bukkit.Bukkit;
import java.util.UUID;
@Getter
public class PlayerLeave extends FactionLog {
private final String uuid;
private final transient FPlayerLeaveEvent.PlayerLeaveReason playerLeaveReason;
public PlayerLeave(UUID uuid, FPlayerLeaveEvent.PlayerLeaveReason playerLeaveReason) {
super(LogType.PLAYER_LEAVE);
this.uuid = uuid.toString();
this.playerLeaveReason = playerLeaveReason;
}
public PlayerLeave(UUID uuid, FPlayerLeaveEvent.PlayerLeaveReason playerLeaveReason, long time) {
super(LogType.PLAYER_LEAVE);
this.uuid = uuid.toString();
this.playerLeaveReason = playerLeaveReason;
super.setTime(time);
}
@Override
public String toString() {
return "(" + TimeDateUtils.splitToComponentTimes((System.currentTimeMillis() - getTime()) / 1000) + "ago) " + Bukkit.getOfflinePlayer(UUID.fromString(uuid)).getName() + " left the faction because of: " + playerLeaveReason;
}
}
@@ -0,0 +1,39 @@
package net.crankedpvp.factionlogs.struct.impl;
import lombok.Getter;
import net.crankedpvp.factionlogs.enums.LogType;
import net.crankedpvp.factionlogs.struct.FactionLog;
import net.crankedpvp.factionlogs.utils.LocationUtils;
import net.crankedpvp.factionlogs.utils.TimeDateUtils;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import java.util.UUID;
@Getter
public class RadiusLandClaim extends FactionLog {
private final String uuid;
private final Location fLocation;
private final Integer radius;
public RadiusLandClaim(UUID uuid, Location fLocation, int radius) {
super(LogType.RADIUSCLAIM);
this.uuid = uuid.toString();
this.fLocation = fLocation;
this.radius = radius;
}
public RadiusLandClaim(UUID uuid, Location fLocation,int radius, long time) {
super(LogType.RADIUSCLAIM);
this.uuid = uuid.toString();
this.fLocation = fLocation;
this.radius = radius;
super.setTime(time);
}
@Override
public String toString() {
return "(" + TimeDateUtils.splitToComponentTimes((System.currentTimeMillis() - getTime()) / 1000) + "ago) " + Bukkit.getOfflinePlayer(UUID.fromString(uuid)).getName() + " claimed land in a radius of " + radius + " radius at " + LocationUtils.locToString(fLocation);
}
}
@@ -0,0 +1,39 @@
package net.crankedpvp.factionlogs.struct.impl;
import com.massivecraft.factions.Faction;
import com.massivecraft.factions.perms.Relation;
import lombok.Getter;
import net.crankedpvp.factionlogs.enums.LogType;
import net.crankedpvp.factionlogs.struct.FactionLog;
import net.crankedpvp.factionlogs.utils.TimeDateUtils;
@Getter
public class RelationEdits extends FactionLog {
private final String sender;
private final String target;
private final String oldRelation;
private final String newRelation;
public RelationEdits(Faction sender, Faction target, Relation oldRelation, Relation newRelation) {
super(LogType.RELATION_EDITS);
this.sender = sender.getTag();
this.target = target.getTag();
this.oldRelation = oldRelation.nicename;
this.newRelation = newRelation.nicename;
}
public RelationEdits(Faction sender, Faction target, Relation oldRelation, Relation newRelation, long time) {
super(LogType.RELATION_EDITS);
this.sender = sender.getTag();
this.target = target.getTag();
this.oldRelation = oldRelation.nicename;
this.newRelation = newRelation.nicename;
super.setTime(time);
}
@Override
public String toString() {
return "(" + TimeDateUtils.splitToComponentTimes((System.currentTimeMillis() - getTime()) / 1000) + "ago) " + getSender() + " changed relation: " + getOldRelation() + " -> " + getNewRelation() + ".";
}
}
@@ -0,0 +1,47 @@
package net.crankedpvp.factionlogs.struct.impl;
import lombok.Getter;
import net.crankedpvp.factionlogs.enums.LogType;
import net.crankedpvp.factionlogs.struct.FactionLog;
import net.crankedpvp.factionlogs.utils.EntityUtils;
import net.crankedpvp.factionlogs.utils.LocationUtils;
import net.crankedpvp.factionlogs.utils.TimeDateUtils;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.entity.EntityType;
import java.util.UUID;
@Getter
public class SpawnerBreak extends FactionLog {
private final Integer amount;
private final Location location;
private final String entityType;
private final String uuid;
public SpawnerBreak(int amount, Location location, EntityType entityType, UUID uuid) {
super(LogType.SPAWNER_BREAK);
this.amount = amount;
this.location = location;
this.entityType = entityType.toString();
this.uuid = uuid.toString();
}
public SpawnerBreak(int amount, Location location, EntityType entityType, UUID uuid, long time) {
super(LogType.SPAWNER_BREAK);
this.amount = amount;
this.location = location;
this.entityType = entityType.toString();
this.uuid = uuid.toString();
super.setTime(time);
}
@Override
public String toString() {
return "(" + TimeDateUtils.splitToComponentTimes((System.currentTimeMillis() - getTime()) / 1000) + "ago) " + Bukkit.getOfflinePlayer(UUID.fromString(getUuid())).getName() + " broke x" + getAmount() + " " + EntityUtils.getEntityName(EntityType.valueOf(getEntityType())) + " at " + LocationUtils.locToString(getLocation()) + ".";
}
}
@@ -0,0 +1,45 @@
package net.crankedpvp.factionlogs.struct.impl;
import lombok.Getter;
import net.crankedpvp.factionlogs.enums.LogType;
import net.crankedpvp.factionlogs.struct.FactionLog;
import net.crankedpvp.factionlogs.utils.EntityUtils;
import net.crankedpvp.factionlogs.utils.LocationUtils;
import net.crankedpvp.factionlogs.utils.TimeDateUtils;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.entity.EntityType;
import java.util.UUID;
@Getter
public class SpawnerPlace extends FactionLog {
private final Integer amount;
private final Location location;
private final String entityType;
private final String uuid;
public SpawnerPlace(int amount, Location location, EntityType entityType, UUID uuid) {
super(LogType.SPAWNER_PLACE);
this.amount = amount;
this.location = location;
this.uuid = uuid.toString();
this.entityType = entityType.toString();
}
public SpawnerPlace(int amount, Location location, EntityType entityType, UUID uuid, long time) {
super(LogType.SPAWNER_PLACE);
this.amount = amount;
this.location = location;
this.uuid = uuid.toString();
this.entityType = entityType.toString();
super.setTime(time);
}
@Override
public String toString() {
return "(" + TimeDateUtils.splitToComponentTimes((System.currentTimeMillis() - getTime()) / 1000) + "ago) " + Bukkit.getOfflinePlayer(UUID.fromString(getUuid())).getName() + " placed x" + getAmount() + " " + EntityUtils.getEntityName(EntityType.valueOf(getEntityType())) + " at " + LocationUtils.locToString(getLocation()) + ".";
}
}
@@ -0,0 +1,28 @@
package net.crankedpvp.factionlogs.struct.typeadapters;
import net.crankedpvp.factionlogs.data.FactionLogsData;
import net.crankedpvp.factionlogs.enums.LogType;
import net.crankedpvp.storageutils.gson.*;
import java.lang.reflect.Type;
public class FactionLogDeserializer implements JsonDeserializer<FactionLogsData> {
@Override
public FactionLogsData deserialize(JsonElement jsonElement, Type type, JsonDeserializationContext context) throws JsonParseException {
JsonObject jsonObject = jsonElement.getAsJsonObject();
FactionLogsData factionLogsData = new FactionLogsData(jsonObject.get("factionId").getAsString());
JsonObject logs = jsonObject.getAsJsonObject("logs");
for (String key : logs.keySet()) {
JsonArray jsonArray = logs.getAsJsonArray(key);
LogType logType = LogType.valueOf(key);
for (JsonElement element : jsonArray) {
factionLogsData.addFactionLog(context.deserialize(element, logType.getLogClass()));
}
}
return factionLogsData;
}
}
@@ -0,0 +1,16 @@
package net.crankedpvp.factionlogs.utils;
import org.bukkit.entity.EntityType;
public class EntityUtils {
public static String getEntityName(EntityType type) {
if (type == null) return "null";
if (type == EntityType.IRON_GOLEM) {
return "Iron Golem";
}
if (type == EntityType.MUSHROOM_COW) {
return "Mushroom Cow";
}
return type.getName();
}
}
@@ -0,0 +1,53 @@
package net.crankedpvp.factionlogs.utils;
import com.massivecraft.factions.Faction;
import net.crankedpvp.factionlogs.FactionLogsPlugin;
import net.crankedpvp.factionlogs.enums.LogType;
import net.crankedpvp.factionlogs.struct.FactionLog;
import java.util.Collections;
import java.util.List;
import java.util.Map;
public class FactionsLogsAPI {
public static void log(Faction faction, FactionLog factionLog) {
try {
FactionLogsPlugin.getInstance().getLogManager().getFactionLogsData(faction.getId()).addFactionLog(factionLog);
} catch (NullPointerException exception) {
exception.printStackTrace();
}
}
public static void log(String id, FactionLog factionLog) {
try {
FactionLogsPlugin.getInstance().getLogManager().getFactionLogsData(id).addFactionLog(factionLog);
} catch (NullPointerException exception) {
exception.printStackTrace();
} }
public static List<FactionLog> getFactionLogs(String id, LogType logType) {
if (FactionLogsPlugin.getInstance().getLogManager().getFactionLogsData(id).getLogs().containsKey(logType)) {
return FactionLogsPlugin.getInstance().getLogManager().getFactionLogsData(id).getLogs().get(logType);
}
return Collections.emptyList();
}
public static List<FactionLog> getFactionLogs(Faction faction, LogType logType) {
if (FactionLogsPlugin.getInstance().getLogManager().getFactionLogsData(faction.getId()).getLogs().containsKey(logType)) {
return FactionLogsPlugin.getInstance().getLogManager().getFactionLogsData(faction.getId()).getLogs().get(logType);
}
return Collections.emptyList();
}
public static Map<LogType, List<FactionLog>> getFactionLogs(Faction faction) {
return FactionLogsPlugin.getInstance().getLogManager().getFactionLogsData(faction.getId()).getLogs();
}
public static boolean hasEmptyLog(Faction faction) {
return FactionLogsPlugin.getInstance().getLogManager().getFactionLogsData(faction.getId()).getLogs().isEmpty();
}
}
@@ -0,0 +1,98 @@
package net.crankedpvp.factionlogs.utils;
import net.crankedpvp.crankedutils.utils.Arrow;
import net.crankedpvp.crankedutils.utils.CC;
import net.crankedpvp.crankedutils.utils.FactionUtils;
import net.crankedpvp.factionlogs.enums.LogType;
import net.crankedpvp.factionlogs.struct.FactionLog;
import org.bukkit.entity.Player;
import javax.net.ssl.HttpsURLConnection;
import java.io.BufferedReader;
import java.io.DataOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.format.DateTimeFormatter;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class HastebinUtils {
private static final DateTimeFormatter DATE_FORMATED = DateTimeFormatter.ofPattern("EEE, MMM dd | HH:mm");
private static final Map<String, Long> clickCooldown = new HashMap<>();
private static final String REQUEST_URL = "https://hastebin.com/documents";
public static String post(String text, boolean raw) throws IOException {
byte[] postData = text.getBytes(StandardCharsets.UTF_8);
int postDataLength = postData.length;
URL url = new URL(REQUEST_URL);
HttpsURLConnection conn = (HttpsURLConnection) url.openConnection();
conn.setDoOutput(true);
conn.setInstanceFollowRedirects(false);
conn.setRequestMethod("POST");
conn.setRequestProperty("User-Agent", "Hastebin Java Api");
conn.setRequestProperty("content-type", "text/plain");
conn.setRequestProperty("Authorization", "Bearer 2614226daf8202446aba715e2b25cdf80e38fd0fe35c758eaacad03a9198dc6cc2f76a7cabd09fd937e6f3fc7dc24dd36120432df2a1212c7ee8e014497cad59");
conn.setRequestProperty("Content-Length", Integer.toString(postDataLength));
conn.setUseCaches(false);
String response = null;
DataOutputStream wr;
try {
wr = new DataOutputStream(conn.getOutputStream());
wr.write(postData);
BufferedReader reader = new BufferedReader(new InputStreamReader(conn.getInputStream()));
response = reader.readLine();
} catch (IOException e) {
e.printStackTrace();
}
assert response != null;
if (response.contains("\"key\"")) {
response = response.substring(response.indexOf(":") + 2, response.length() - 2);
String postURL = raw ? "https://hastebin.com/raw/" : "https://hastebin.com/share/";
response = postURL + response;
}
return response;
}
public static void sendLog(Player sender, String factionId, LogType logType, boolean raw) {
long msCooldown = 300000;
if (clickCooldown.containsKey(factionId) && !sender.isOp()) {
if (clickCooldown.get(factionId) + msCooldown > System.currentTimeMillis()) {
sender.sendMessage(CC.translate("&a&lFactions &8" + Arrow.arrow() + " &cError&8: &7Your faction recently generated an f log URL, please wait another &7" + TimeDateUtils.fancy((clickCooldown.get(factionId) + msCooldown) - System.currentTimeMillis())));
return;
}
}
clickCooldown.put(factionId, System.currentTimeMillis());
sender.sendMessage(CC.translate("&a&lFactions &8" + Arrow.arrow() + " &7Generating " + logType.getDisplayName() + " faction logs..."));
LocalDateTime localDateTime = LocalDateTime.now(ZoneId.of("America/New_York"));
String date = localDateTime.format(DATE_FORMATED);
StringBuilder text = new StringBuilder();
text.append(logType.getDisplayName()).append(" Generated on ").append(date).append(" (EST)").append(" for faction ").append(FactionUtils.getFactionById(factionId).getTag()).append("\n");
List<FactionLog> factionLogsList = FactionsLogsAPI.getFactionLogs(factionId, logType);
for (FactionLog factionLog : factionLogsList) {
text.append(" ").append(factionLog.toString()).append("\n");
}
try {
String url = post(text.toString(), raw);
sender.sendMessage(CC.translate("&a&lFactions &8" + Arrow.arrow() + " &7" + logType.getDisplayName() + " &7(Logs URL): &a&n" + url));
} catch (IOException e) {
sender.sendMessage(CC.translate("&a&lFactions &8" + Arrow.arrow() + " &cError&8: &eAn error occurred, please try again!"));
e.printStackTrace();
}
}
}
@@ -0,0 +1,30 @@
package net.crankedpvp.factionlogs.utils;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.World;
public class LocationSerializer {
public static String serialize(Location obj) {
if (obj == null) {
return "";
}
return obj.getWorld().getName() + ":" + obj.getBlockX() + ":" + obj.getBlockY() + ":" + obj.getBlockZ();
}
public static Location deserialize(String s) {
if (s == null || s.trim().equals("")) {
return null;
}
final String[] parts = s.split(":");
if (parts.length == 4) {
final World w = Bukkit.getServer().getWorld(parts[0]);
final int x = Integer.parseInt(parts[1]);
final int y = Integer.parseInt(parts[2]);
final int z = Integer.parseInt(parts[3]);
return new Location(w, x, y, z);
}
return null;
}
}
@@ -0,0 +1,9 @@
package net.crankedpvp.factionlogs.utils;
import org.bukkit.Location;
public class LocationUtils {
public static String locToString(Location l) {
return "[" + l.getWorld().getName() + "," + l.getX() + "," + l.getY() + "," + l.getZ() + "]";
}
}
@@ -0,0 +1,29 @@
package net.crankedpvp.factionlogs.utils;
import java.util.concurrent.TimeUnit;
public class TimeDateUtils {
public static String splitToComponentTimes(long seconds) {
int days = (int) seconds / 86400;
int hours = (int) seconds / 3600;
int remainder = (int) seconds - hours * 3600;
int mins = remainder / 60;
remainder = remainder - mins * 60;
int secs = remainder;
return days + "d " + hours + "h " + mins + "m " + secs + "s ";
}
public static String fancy(long seconds) {
seconds = seconds / 1000;
int day = (int) TimeUnit.SECONDS.toDays(seconds);
long hours = TimeUnit.SECONDS.toHours(seconds) - (day * 24L);
long minute = TimeUnit.SECONDS.toMinutes(seconds) - (TimeUnit.SECONDS.toHours(seconds) * 60);
long second = TimeUnit.SECONDS.toSeconds(seconds) - (TimeUnit.SECONDS.toMinutes(seconds) * 60);
return day + "d " + hours + "h " + minute + "m " + second + "s ";
}
}
+10
View File
@@ -0,0 +1,10 @@
name: CrankedFactionLogs
main: net.crankedpvp.factionlogs.FactionLogsPlugin
version: ${git.total.commit.count}.0
description: "§fCommit ID: §a${git.commit.id.abbrev}"
website: https://crankedpvp.net/
depend:
- CrankedUtils
- Factions
- CrankedSpawners
- StorageUtil