Added chat reports
This commit is contained in:
7 files changed
+152
-3
No files matched your search
@@ -32,6 +32,7 @@ public class StaffOGPlugin extends JavaPlugin {
|
||||
TaskManager taskManager = new TaskManager(this);
|
||||
|
||||
getCommand("linkpanel").setExecutor(new LinkPanelCommand());
|
||||
getCommand("chatreport").setExecutor(new ChatReportCommand());
|
||||
|
||||
getCommand("permban").setExecutor(new PermPunishCommand());
|
||||
getCommand("tempban").setExecutor(new TempPunishCommand());
|
||||
@@ -39,7 +40,6 @@ public class StaffOGPlugin extends JavaPlugin {
|
||||
getCommand("permmute").setExecutor(new PermPunishCommand());
|
||||
getCommand("tempmute").setExecutor(new TempPunishCommand());
|
||||
getCommand("unmute").setExecutor(new UnpunishCommand());
|
||||
|
||||
getCommand("kick").setExecutor(new KickCommand());
|
||||
|
||||
databaseManager.setStatEntry("server_status", "online");
|
||||
|
||||
@@ -0,0 +1,49 @@
|
||||
package uk.hotten.staffog.commands;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import uk.hotten.staffog.StaffOGPlugin;
|
||||
import uk.hotten.staffog.punish.PunishManager;
|
||||
import uk.hotten.staffog.security.SecurityManager;
|
||||
import uk.hotten.staffog.security.data.StaffIPInfo;
|
||||
import uk.hotten.staffog.utils.Message;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
public class ChatReportCommand implements CommandExecutor {
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
|
||||
if (!(sender instanceof Player player)) {
|
||||
sender.sendMessage(Message.format(ChatColor.RED + "You cannot run this command!"));
|
||||
return true;
|
||||
}
|
||||
|
||||
if (args == null || args.length < 1) {
|
||||
player.sendMessage(Message.format(ChatColor.RED + "Correct Usage: /chatreport <player>"));
|
||||
return true;
|
||||
}
|
||||
|
||||
PunishManager pm = PunishManager.getInstance();
|
||||
if (!pm.isIncludedInCurrentChatReport(args[0])) {
|
||||
player.sendMessage(Message.format(ChatColor.RED + args[0] + " has not used chat in the past two minutes."));
|
||||
return true;
|
||||
}
|
||||
|
||||
UUID reported = pm.getUUIDFromChatReport(args[0]);
|
||||
|
||||
String reportId = pm.exportChatReport(player.getUniqueId(), reported);
|
||||
if (reportId == null) {
|
||||
player.sendMessage(Message.format(ChatColor.RED + "Failed to generate chat report. Please try again."));
|
||||
return true;
|
||||
}
|
||||
|
||||
player.sendMessage(Message.format(ChatColor.GREEN + "Chat report successfully created. Please quote the report ID " + ChatColor.WHITE + "#" + reportId + ChatColor.GREEN + " to staff when required."));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -443,6 +443,7 @@ public class DatabaseManager {
|
||||
String sql = "CREATE TABLE `staffog_chatreport` (" +
|
||||
" `id` int(11) NOT NULL AUTO_INCREMENT," +
|
||||
" `uuid` varchar(36) NOT NULL," +
|
||||
" `by_uuid` varchar(36) NOT NULL," +
|
||||
" `time` bigint(20) NOT NULL," +
|
||||
" `messages` varchar(2048) NOT NULL," +
|
||||
" PRIMARY KEY (`id`)" +
|
||||
|
||||
@@ -1,11 +1,14 @@
|
||||
package uk.hotten.staffog.punish;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.AsyncPlayerChatEvent;
|
||||
import org.bukkit.event.player.AsyncPlayerPreLoginEvent;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
import uk.hotten.staffog.punish.data.ChatReportEntry;
|
||||
import uk.hotten.staffog.punish.data.PunishEntry;
|
||||
import uk.hotten.staffog.punish.data.PunishType;
|
||||
import uk.hotten.staffog.utils.Message;
|
||||
@@ -45,4 +48,14 @@ public class PunishEventListener implements Listener {
|
||||
+ ChatColor.WHITE + TimeUtils.formatMillisecondTime(entry.calculateRemaining()))));
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST )
|
||||
public void onAsyncChatReport(AsyncPlayerChatEvent event) {
|
||||
if (event.isCancelled())
|
||||
return;
|
||||
|
||||
PunishManager pm = PunishManager.getInstance();
|
||||
ChatReportEntry entry = new ChatReportEntry(event.getPlayer().getUniqueId(), event.getPlayer().getName(), event.getMessage(), System.currentTimeMillis());
|
||||
pm.getChatReportEntries().add(entry);
|
||||
Bukkit.getServer().getScheduler().runTaskLater(pm.getPlugin(), () -> pm.getChatReportEntries().remove(entry), 2400); // remove 2m later
|
||||
}
|
||||
}
|
||||
@@ -1,10 +1,13 @@
|
||||
package uk.hotten.staffog.punish;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import lombok.Getter;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import uk.hotten.staffog.data.DatabaseManager;
|
||||
import uk.hotten.staffog.punish.data.ChatReportEntry;
|
||||
import uk.hotten.staffog.punish.data.KickPunishEntry;
|
||||
import uk.hotten.staffog.punish.data.PunishEntry;
|
||||
import uk.hotten.staffog.punish.data.PunishType;
|
||||
@@ -16,17 +19,21 @@ import uk.hotten.staffog.utils.TimeUtils;
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.util.Date;
|
||||
import java.sql.Statement;
|
||||
import java.util.ArrayList;
|
||||
import java.util.UUID;
|
||||
|
||||
public class PunishManager {
|
||||
|
||||
private JavaPlugin plugin;
|
||||
@Getter private JavaPlugin plugin;
|
||||
@Getter private static PunishManager instance;
|
||||
|
||||
@Getter private ArrayList<ChatReportEntry> chatReportEntries;
|
||||
|
||||
public PunishManager(JavaPlugin plugin) {
|
||||
this.plugin = plugin;
|
||||
instance = this;
|
||||
chatReportEntries = new ArrayList<>();
|
||||
|
||||
plugin.getServer().getPluginManager().registerEvents(new PunishEventListener(), plugin);
|
||||
}
|
||||
@@ -298,4 +305,56 @@ public class PunishManager {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isIncludedInCurrentChatReport(String name) {
|
||||
for (ChatReportEntry entry : chatReportEntries) {
|
||||
if (name.equalsIgnoreCase(entry.getName())) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public UUID getUUIDFromChatReport(String name) {
|
||||
for (ChatReportEntry entry : chatReportEntries) {
|
||||
if (name.equalsIgnoreCase(entry.getName())) {
|
||||
return entry.getUuid();
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public String exportChatReport(UUID by, UUID reported) {
|
||||
Gson gson = new Gson();
|
||||
String data = gson.toJson(chatReportEntries);
|
||||
|
||||
try (Connection connection = DatabaseManager.getInstance().createConnection()) {
|
||||
PreparedStatement statement = connection.prepareStatement(
|
||||
"INSERT INTO `staffog_chatreport` (`uuid`, `by_uuid`, `time`, `messages`) VALUES (?, ?, ?, ?)",
|
||||
Statement.RETURN_GENERATED_KEYS
|
||||
);
|
||||
statement.setString(1, reported.toString());
|
||||
statement.setString(2, by.toString());
|
||||
statement.setLong(3, System.currentTimeMillis());
|
||||
statement.setString(4, data);
|
||||
|
||||
int affectedRows = statement.executeUpdate();
|
||||
|
||||
if (affectedRows == 0)
|
||||
return null;
|
||||
|
||||
ResultSet rs = statement.getGeneratedKeys();
|
||||
if (rs.next()) {
|
||||
return "" + rs.getInt(1);
|
||||
}
|
||||
|
||||
return null;
|
||||
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
package uk.hotten.staffog.punish.data;
|
||||
|
||||
import lombok.Getter;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
public class ChatReportEntry {
|
||||
|
||||
@Getter private UUID uuid;
|
||||
@Getter private String name;
|
||||
@Getter private String message;
|
||||
@Getter private long time;
|
||||
|
||||
public ChatReportEntry(UUID uuid, String name, String message, long time) {
|
||||
this.uuid = uuid;
|
||||
this.name = name;
|
||||
this.message = message;
|
||||
this.time = time;
|
||||
}
|
||||
|
||||
public ChatReportEntry() { }
|
||||
|
||||
}
|
||||
@@ -12,6 +12,10 @@ commands:
|
||||
permission: staffog.panelaccess
|
||||
usage: /<command>
|
||||
|
||||
chatreport:
|
||||
description: Takes a snapshot of a player's messages, used for reporting chat offences.
|
||||
usage: /<command> <player>
|
||||
|
||||
permban:
|
||||
description: Permanently ban a player.
|
||||
permission: staffog.command.permban
|
||||
|
||||
Reference in new issue
Block a user