Work on pushing chat snapshots to db
This commit is contained in:
parent
ef0c3721d8
commit
09a74e3772
@ -5,12 +5,11 @@ import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
/**
|
||||
@ -18,53 +17,50 @@ import static com.google.common.base.Preconditions.checkNotNull;
|
||||
*/
|
||||
public class Snapshot implements Comparable<Snapshot>
|
||||
{
|
||||
@SerializedName("type")
|
||||
protected Long _id = null;
|
||||
private MessageType _messageType;
|
||||
|
||||
@SerializedName("sender")
|
||||
private UUID _sender;
|
||||
|
||||
@SerializedName("recipients")
|
||||
private Collection<UUID> _recipients;
|
||||
|
||||
@SerializedName("message")
|
||||
private int _senderId;
|
||||
private Collection<Integer> _recipientIds;
|
||||
private String _message;
|
||||
|
||||
@SerializedName("time")
|
||||
private LocalDateTime _time;
|
||||
|
||||
public Snapshot(UUID sender, UUID recipient, String message)
|
||||
public Snapshot(int senderId, int recipientId, String message)
|
||||
{
|
||||
this(MessageType.PM, sender, Collections.singletonList(recipient), message, LocalDateTime.now());
|
||||
this(MessageType.PM, senderId, Collections.singletonList(recipientId), message, LocalDateTime.now());
|
||||
}
|
||||
|
||||
public Snapshot(UUID sender, Collection<UUID> recipients, String message)
|
||||
public Snapshot(int senderId, Collection<Integer> recipientIds, String message)
|
||||
{
|
||||
this(MessageType.CHAT, sender, recipients, message, LocalDateTime.now());
|
||||
this(MessageType.CHAT, senderId, recipientIds, message, LocalDateTime.now());
|
||||
}
|
||||
|
||||
public Snapshot(MessageType messageType, UUID sender, Collection<UUID> recipients, String message, LocalDateTime time)
|
||||
public Snapshot(MessageType messageType, int senderId, Collection<Integer> recipientIds, String message, LocalDateTime time)
|
||||
{
|
||||
_messageType = messageType;
|
||||
_sender = checkNotNull(sender);
|
||||
_recipients = checkNotNull(recipients);
|
||||
_senderId = checkNotNull(senderId);
|
||||
_recipientIds = checkNotNull(recipientIds);
|
||||
_message = checkNotNull(message);
|
||||
_time = checkNotNull(time);
|
||||
|
||||
if (messageType == MessageType.PM && recipients.size() > 1)
|
||||
if (messageType == MessageType.PM && recipientIds.size() > 1)
|
||||
{
|
||||
throw new IllegalArgumentException("Snapshot type PM may not have more than 1 recipient.");
|
||||
}
|
||||
}
|
||||
|
||||
public MessageType getMessageType()
|
||||
public Optional<Long> getId()
|
||||
{
|
||||
return Optional.ofNullable(_id);
|
||||
}
|
||||
|
||||
public MessageType getType()
|
||||
{
|
||||
return _messageType;
|
||||
}
|
||||
|
||||
public UUID getSender()
|
||||
public int getSenderId()
|
||||
{
|
||||
return _sender;
|
||||
return _senderId;
|
||||
}
|
||||
|
||||
public String getMessage()
|
||||
@ -72,9 +68,9 @@ public class Snapshot implements Comparable<Snapshot>
|
||||
return _message;
|
||||
}
|
||||
|
||||
public Set<UUID> getRecipients()
|
||||
public Set<Integer> getRecipientIds()
|
||||
{
|
||||
return new HashSet<>(_recipients);
|
||||
return new HashSet<>(_recipientIds);
|
||||
}
|
||||
|
||||
public LocalDateTime getSentTime()
|
||||
@ -95,23 +91,23 @@ public class Snapshot implements Comparable<Snapshot>
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
Snapshot that = (Snapshot) o;
|
||||
return _time == that._time &&
|
||||
Objects.equals(_sender, that._sender) &&
|
||||
Objects.equals(_recipients, that._recipients) &&
|
||||
Objects.equals(_senderId, that._senderId) &&
|
||||
Objects.equals(_recipientIds, that._recipientIds) &&
|
||||
Objects.equals(_message, that._message);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode()
|
||||
{
|
||||
return Objects.hash(_sender, _recipients, _message, _time);
|
||||
return Objects.hash(_senderId, _recipientIds, _message, _time);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
return "Snapshot{" +
|
||||
"sender=" + _sender +
|
||||
", recipients=" + _recipients +
|
||||
"sender=" + _senderId +
|
||||
", recipients=" + _recipientIds +
|
||||
", message='" + ChatColor.stripColor(_message) + '\'' +
|
||||
", created=" + _time +
|
||||
'}';
|
||||
|
@ -8,7 +8,6 @@ import java.util.stream.Collectors;
|
||||
|
||||
import com.google.common.cache.Cache;
|
||||
import com.google.common.cache.CacheBuilder;
|
||||
import mineplex.core.chatsnap.publishing.SnapshotPublisher;
|
||||
|
||||
/**
|
||||
* Handles temporary storage of {@link Snapshot} instances.
|
||||
@ -24,16 +23,16 @@ public class SnapshotManager
|
||||
.expireAfterWrite(30, TimeUnit.MINUTES)
|
||||
.build();
|
||||
|
||||
private final SnapshotPublisher _snapshotPublisher;
|
||||
private final SnapshotRepository _snapshotRepository;
|
||||
|
||||
public SnapshotManager(SnapshotPublisher snapshotPublisher)
|
||||
public SnapshotManager(SnapshotRepository snapshotRepository)
|
||||
{
|
||||
_snapshotPublisher = snapshotPublisher;
|
||||
_snapshotRepository = snapshotRepository;
|
||||
}
|
||||
|
||||
public SnapshotPublisher getSnapshotPublisher()
|
||||
public SnapshotRepository getSnapshotRepository()
|
||||
{
|
||||
return _snapshotPublisher;
|
||||
return _snapshotRepository;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -65,13 +64,13 @@ public class SnapshotManager
|
||||
* Gets all instances of {@link Snapshot} which involve a particular user.
|
||||
* The user may be the sender or recipient of a message.
|
||||
*
|
||||
* @param search the user to search for snaps involved in
|
||||
* @param accountId the user to search for snaps involved in
|
||||
* @return the snaps that the user is involved in
|
||||
*/
|
||||
public Set<Snapshot> getSnapshots(UUID search)
|
||||
public Set<Snapshot> getSnapshots(int accountId)
|
||||
{
|
||||
return _snapshots.asMap().keySet().stream()
|
||||
.filter(snapshot -> snapshot.getSender().equals(search) || snapshot.getRecipients().contains(search))
|
||||
.filter(snapshot -> snapshot.getSenderId() == accountId || snapshot.getRecipientIds().contains(accountId))
|
||||
.collect(Collectors.toCollection(TreeSet::new));
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,129 @@
|
||||
package mineplex.core.chatsnap;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Timestamp;
|
||||
import java.time.ZoneId;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import com.google.gson.JsonObject;
|
||||
import com.mysql.jdbc.Statement;
|
||||
import mineplex.core.database.MinecraftRepository;
|
||||
import mineplex.serverdata.Utility;
|
||||
import mineplex.serverdata.database.DBPool;
|
||||
import mineplex.serverdata.servers.ServerManager;
|
||||
import redis.clients.jedis.Jedis;
|
||||
import redis.clients.jedis.JedisPool;
|
||||
|
||||
/**
|
||||
* Class responsible for publishing snapshots on the website via Redis and a separate Report server.
|
||||
*/
|
||||
public class SnapshotRepository extends MinecraftRepository
|
||||
{
|
||||
private static final ZoneId ZONE_ID = ZoneId.of("America/Chicago"); // This means "CST"
|
||||
|
||||
public static String getURL(String token)
|
||||
{
|
||||
return URL_PREFIX + token;
|
||||
}
|
||||
|
||||
private static final String URL_PREFIX = "http://file.mineplex.com/chatsnap/view.php?identifier=";
|
||||
|
||||
private static final String INSERT_SNAPSHOT = "INSERT INTO snapshots (senderId, `server`, `time`, message, snapshotType) VALUES (?, ?, ?, ?, ?);";
|
||||
private static final String INSERT_SNAPSHOT_RECIPIENT = "INSERT INTO snapshotRecipients (snapshotId, recipientId) VALUES (?, ?);";
|
||||
private static final String INSERT_REPORT_SNAPSHOT_MAPPING = "INSERT INTO reportSnapshots (reportId, snapshotId) VALUES (?, ?);";
|
||||
|
||||
private final String _serverName;
|
||||
|
||||
public SnapshotRepository(JavaPlugin plugin, String serverName)
|
||||
{
|
||||
super(plugin, DBPool.getAccount());
|
||||
_serverName = serverName;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void initialize()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void update()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public CompletableFuture<Void> insertSnapshots(int reportId, Collection<Snapshot> snapshots)
|
||||
{
|
||||
return CompletableFuture.<Void>allOf(snapshots.stream()
|
||||
.map(snapshot -> insertSnapshot(reportId, snapshot))
|
||||
.toArray(CompletableFuture[]::new));
|
||||
}
|
||||
|
||||
public CompletableFuture<Void> insertSnapshot(int reportId, Snapshot snapshot)
|
||||
{
|
||||
return CompletableFuture.supplyAsync(() ->
|
||||
{
|
||||
try (Connection connection = DBPool.getAccount().getConnection())
|
||||
{
|
||||
long messageId = snapshot.getId().orElse((long) -1);
|
||||
|
||||
if (messageId == -1)
|
||||
{
|
||||
PreparedStatement insertSnapshotStatement = connection.prepareStatement(INSERT_SNAPSHOT, Statement.RETURN_GENERATED_KEYS);
|
||||
insertSnapshotStatement.setInt(1, snapshot.getSenderId());
|
||||
insertSnapshotStatement.setString(2, _serverName);
|
||||
insertSnapshotStatement.setTimestamp(3, new Timestamp(snapshot.getSentTime().atZone(ZONE_ID).toInstant().toEpochMilli()));
|
||||
insertSnapshotStatement.setString(4, snapshot.getMessage());
|
||||
insertSnapshotStatement.setInt(5, snapshot.getType().getId());
|
||||
insertSnapshotStatement.executeUpdate();
|
||||
|
||||
ResultSet resultSet = insertSnapshotStatement.getGeneratedKeys();
|
||||
if (resultSet.next())
|
||||
{
|
||||
messageId = resultSet.getLong(1);
|
||||
snapshot._id = messageId;
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new IllegalStateException("Query did not return a message id (we need one).");
|
||||
}
|
||||
|
||||
insertSnapshotStatement.close();
|
||||
|
||||
for (int recipientId : snapshot.getRecipientIds())
|
||||
{
|
||||
PreparedStatement insertRecipientStatement = connection.prepareStatement(INSERT_SNAPSHOT_RECIPIENT);
|
||||
insertRecipientStatement.setLong(1, messageId);
|
||||
insertRecipientStatement.setInt(2, recipientId);
|
||||
insertRecipientStatement.execute();
|
||||
}
|
||||
}
|
||||
|
||||
PreparedStatement reportSnapshotMapping = connection.prepareStatement(INSERT_REPORT_SNAPSHOT_MAPPING);
|
||||
reportSnapshotMapping.setInt(1, reportId);
|
||||
reportSnapshotMapping.setLong(2, messageId);
|
||||
reportSnapshotMapping.execute();
|
||||
}
|
||||
catch (SQLException e)
|
||||
{
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
return null;
|
||||
});
|
||||
}
|
||||
}
|
@ -1,33 +0,0 @@
|
||||
package mineplex.core.chatsnap.publishing;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.ZoneId;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.time.temporal.ChronoUnit;
|
||||
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonPrimitive;
|
||||
import com.google.gson.JsonSerializationContext;
|
||||
import com.google.gson.JsonSerializer;
|
||||
|
||||
/**
|
||||
* Handles serialization of Java 8's {@link LocalDateTime}.
|
||||
*/
|
||||
public class LocalDateTimeSerializer implements JsonSerializer<LocalDateTime>
|
||||
{
|
||||
private static final DateTimeFormatter FORMATTER = DateTimeFormatter.ISO_LOCAL_DATE_TIME;
|
||||
|
||||
private ZoneId _zoneId;
|
||||
|
||||
public LocalDateTimeSerializer(ZoneId zoneId)
|
||||
{
|
||||
_zoneId = zoneId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public JsonElement serialize(LocalDateTime localDateTime, Type type, JsonSerializationContext jsonSerializationContext)
|
||||
{
|
||||
return new JsonPrimitive(localDateTime.atZone(_zoneId).toLocalDateTime().truncatedTo(ChronoUnit.SECONDS).format(FORMATTER));
|
||||
}
|
||||
}
|
@ -1,57 +0,0 @@
|
||||
package mineplex.core.chatsnap.publishing;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.Optional;
|
||||
|
||||
import com.google.gson.JsonArray;
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.JsonSerializationContext;
|
||||
import com.google.gson.JsonSerializer;
|
||||
import mineplex.core.report.Report;
|
||||
import mineplex.core.report.ReportMessage;
|
||||
|
||||
/**
|
||||
* Handles serialization of {@link Report} instances.
|
||||
*/
|
||||
public class ReportSerializer implements JsonSerializer<Report>
|
||||
{
|
||||
@Override
|
||||
public JsonElement serialize(Report report, Type type, JsonSerializationContext jsonSerializationContext)
|
||||
{
|
||||
// todo update report site for new json format
|
||||
Optional<Integer> reportIdOptional = report.getReportId();
|
||||
Optional<Integer> handlerIdOptional = report.getHandlerId();
|
||||
JsonObject jsonObject = new JsonObject();
|
||||
|
||||
if (reportIdOptional.isPresent())
|
||||
{
|
||||
jsonObject.addProperty("id", reportIdOptional.get());
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new IllegalStateException("Report has no id assigned to it.");
|
||||
}
|
||||
|
||||
jsonObject.addProperty("suspect", report.getSuspectId());
|
||||
|
||||
if (handlerIdOptional.isPresent())
|
||||
{
|
||||
jsonObject.addProperty("handler", handlerIdOptional.get());
|
||||
}
|
||||
|
||||
JsonArray messagesArray = new JsonArray();
|
||||
for (ReportMessage reportMessage : report.getMessages().values())
|
||||
{
|
||||
JsonObject reportMessageObject = new JsonObject();
|
||||
reportMessageObject.addProperty("reporter", reportMessage.getReporterId());
|
||||
reportMessageObject.addProperty("message", reportMessage.getMessage());
|
||||
reportMessageObject.addProperty("server", reportMessage.getServer());
|
||||
reportMessageObject.addProperty("time", reportMessage.getTimeCreated().getTime());
|
||||
messagesArray.add(reportMessageObject);
|
||||
}
|
||||
|
||||
jsonObject.add("messages", messagesArray);
|
||||
return jsonObject;
|
||||
}
|
||||
}
|
@ -1,119 +0,0 @@
|
||||
package mineplex.core.chatsnap.publishing;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.ZoneId;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.GsonBuilder;
|
||||
import com.google.gson.JsonObject;
|
||||
import mineplex.core.chatsnap.Snapshot;
|
||||
import mineplex.core.report.Report;
|
||||
import mineplex.serverdata.Utility;
|
||||
import mineplex.serverdata.servers.ServerManager;
|
||||
import redis.clients.jedis.Jedis;
|
||||
import redis.clients.jedis.JedisPool;
|
||||
|
||||
/**
|
||||
* Class responsible for publishing snapshots on the website via Redis and a separate Report server.
|
||||
*/
|
||||
public class SnapshotPublisher
|
||||
{
|
||||
private static final ZoneId ZONE_ID = ZoneId.of("America/Chicago"); // This means "CST"
|
||||
private static final Gson GSON = new GsonBuilder()
|
||||
.setPrettyPrinting()
|
||||
.registerTypeAdapter(LocalDateTime.class, new LocalDateTimeSerializer(ZONE_ID))
|
||||
.registerTypeAdapter(Report.class, new ReportSerializer())
|
||||
.create();
|
||||
|
||||
public static ZoneId getZoneId()
|
||||
{
|
||||
return ZONE_ID;
|
||||
}
|
||||
|
||||
public static Gson getGson()
|
||||
{
|
||||
return GSON;
|
||||
}
|
||||
|
||||
public static String getURL(String token)
|
||||
{
|
||||
return URL_PREFIX + token;
|
||||
}
|
||||
|
||||
private static final String URL_PREFIX = "http://file.mineplex.com/chatsnap/view.php?identifier=";
|
||||
public static final String CHANNEL_DEPLOY = "reportserver:deploy";
|
||||
public static final String CHANNEL_DESTROY = "reportserver:destroy";
|
||||
|
||||
private JavaPlugin _plugin;
|
||||
private JedisPool _jedisPool;
|
||||
|
||||
public SnapshotPublisher(JavaPlugin plugin)
|
||||
{
|
||||
_plugin = plugin;
|
||||
_jedisPool = Utility.generatePool(ServerManager.getMasterConnection());
|
||||
}
|
||||
|
||||
public void publishChatLog(String token, JsonObject jsonObject)
|
||||
{
|
||||
jsonObject.addProperty("token", token);
|
||||
String json = GSON.toJson(jsonObject);
|
||||
|
||||
// getting a Jedis resource can block, so lets async it
|
||||
Bukkit.getScheduler().runTaskAsynchronously(_plugin, () ->
|
||||
{
|
||||
try (Jedis jedis = _jedisPool.getResource())
|
||||
{
|
||||
jedis.publish(CHANNEL_DEPLOY, json);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void unpublishChatLog(String token)
|
||||
{
|
||||
// getting a Jedis resource can block, so lets async it
|
||||
Bukkit.getScheduler().runTaskAsynchronously(_plugin, () ->
|
||||
{
|
||||
try (Jedis jedis = _jedisPool.getResource())
|
||||
{
|
||||
jedis.publish(CHANNEL_DESTROY, token);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public Set<UUID> getUUIDs(Collection<Snapshot> snapshots)
|
||||
{
|
||||
// Being a Set ensures no duplicates
|
||||
Set<UUID> uuids = new HashSet<>();
|
||||
|
||||
for (Snapshot snapshot : snapshots)
|
||||
{
|
||||
uuids.add(snapshot.getSender());
|
||||
uuids.addAll(snapshot.getRecipients().stream().collect(Collectors.toList()));
|
||||
}
|
||||
|
||||
return uuids;
|
||||
}
|
||||
|
||||
public Map<UUID, String> getUsernameMap(Collection<UUID> collection)
|
||||
{
|
||||
Map<UUID, String> uuidUsernameMap = new HashMap<>();
|
||||
|
||||
for (UUID uuid : collection)
|
||||
{
|
||||
String username = Bukkit.getOfflinePlayer(uuid).getName();
|
||||
uuidUsernameMap.put(uuid, username);
|
||||
}
|
||||
|
||||
return uuidUsernameMap;
|
||||
}
|
||||
}
|
@ -17,14 +17,13 @@ import com.google.gson.JsonObject;
|
||||
import mineplex.core.account.CoreClientManager;
|
||||
import mineplex.core.chatsnap.Snapshot;
|
||||
import mineplex.core.chatsnap.SnapshotManager;
|
||||
import mineplex.core.chatsnap.publishing.SnapshotPublisher;
|
||||
import mineplex.core.chatsnap.SnapshotRepository;
|
||||
import mineplex.core.command.CommandCenter;
|
||||
import mineplex.core.common.Rank;
|
||||
import mineplex.core.common.jsonchat.JsonMessage;
|
||||
import mineplex.core.common.util.BukkitFuture;
|
||||
import mineplex.core.common.util.C;
|
||||
import mineplex.core.common.util.F;
|
||||
import mineplex.core.common.util.UtilFuture;
|
||||
import mineplex.core.portal.Portal;
|
||||
import mineplex.core.preferences.PreferencesManager;
|
||||
import mineplex.core.report.command.ReportHandlerNotification;
|
||||
@ -119,7 +118,7 @@ public class ReportManager
|
||||
|
||||
if (report.getCategory() == ReportCategory.CHAT_ABUSE) // only chat abuse reports have chat logs published
|
||||
{
|
||||
_snapshotManager.getSnapshotPublisher().unpublishChatLog(report.getToken());
|
||||
_snapshotManager.getSnapshotRepository().unpublishChatLog(report.getToken());
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -154,7 +153,8 @@ public class ReportManager
|
||||
|
||||
if (report.getCategory() == ReportCategory.CHAT_ABUSE)
|
||||
{
|
||||
publishChatSnap(report, true);
|
||||
Set<Snapshot> relatedSnapshots = _snapshotManager.getSnapshots(report.getSuspectId());
|
||||
_snapshotManager.getSnapshotRepository().insertSnapshots(reportId, relatedSnapshots);
|
||||
}
|
||||
|
||||
_reportRepository.updateReport(report);
|
||||
@ -247,58 +247,6 @@ public class ReportManager
|
||||
});
|
||||
}
|
||||
|
||||
public void publishChatSnap(Report report, boolean updateChat)
|
||||
{
|
||||
List<CompletableFuture> futureList = new ArrayList<>(2);
|
||||
SnapshotPublisher publisher = _snapshotManager.getSnapshotPublisher();
|
||||
Gson gson = SnapshotPublisher.getGson();
|
||||
Set<UUID> uniqueIds = new HashSet<>();
|
||||
|
||||
CompletableFuture<Collection<UUID>> reportIdsFuture = getUUIDs(report);
|
||||
reportIdsFuture.thenAccept(uniqueIds::addAll);
|
||||
futureList.add(reportIdsFuture);
|
||||
|
||||
JsonObject jsonObject = new JsonObject();
|
||||
jsonObject.addProperty("timezone", SnapshotPublisher.getZoneId().getId());
|
||||
jsonObject.add("generated", gson.toJsonTree(LocalDateTime.now()));
|
||||
jsonObject.add("report", gson.toJsonTree(report));
|
||||
|
||||
if (updateChat)
|
||||
{
|
||||
CompletableFuture<UUID> suspectIdFuture = _reportRepository.getAccountUUID(report.getSuspectId());
|
||||
|
||||
suspectIdFuture.thenAccept(suspectUUID -> {
|
||||
Set<Snapshot> snapshots = _snapshotManager.getSnapshots(suspectUUID);
|
||||
uniqueIds.addAll(publisher.getUUIDs(snapshots));
|
||||
jsonObject.add("snapshots", gson.toJsonTree(snapshots));
|
||||
});
|
||||
|
||||
futureList.add(suspectIdFuture);
|
||||
}
|
||||
|
||||
CompletableFuture.allOf(futureList.toArray(new CompletableFuture[futureList.size()])).thenAccept(v -> {
|
||||
Map<UUID, String> usernameMap = publisher.getUsernameMap(uniqueIds);
|
||||
jsonObject.add("usernames", gson.toJsonTree(usernameMap));
|
||||
|
||||
publisher.publishChatLog(report.getToken(), jsonObject);
|
||||
});
|
||||
}
|
||||
|
||||
private CompletableFuture<Collection<UUID>> getUUIDs(Report report)
|
||||
{
|
||||
Set<Integer> accountIds = new HashSet<>();
|
||||
accountIds.addAll(report.getReporterIds());
|
||||
accountIds.add(report.getSuspectId());
|
||||
|
||||
Optional<Integer> handlerIdOptional = report.getHandlerId();
|
||||
if (handlerIdOptional.isPresent())
|
||||
{
|
||||
accountIds.add(handlerIdOptional.get());
|
||||
}
|
||||
|
||||
return _reportRepository.getAccountUUIDs(accountIds).thenApply(Map::values);
|
||||
}
|
||||
|
||||
public void onPlayerJoin(Player player)
|
||||
{
|
||||
int playerId = _clientManager.Get(player).getAccountId();
|
||||
|
@ -4,7 +4,7 @@ import java.util.Collection;
|
||||
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
|
||||
import mineplex.core.chatsnap.publishing.SnapshotPublisher;
|
||||
import mineplex.core.chatsnap.SnapshotRepository;
|
||||
import mineplex.core.common.jsonchat.ClickEvent;
|
||||
import mineplex.core.common.jsonchat.JsonMessage;
|
||||
import mineplex.core.common.util.C;
|
||||
@ -51,7 +51,7 @@ public class ReportHandlerMessageTask extends BukkitRunnable
|
||||
.add(C.cAqua + "Suspect: " + C.cGold + suspectName)
|
||||
.add("\n")
|
||||
.add((_report.hasToken() ? C.cAqua + "Chat Log: " + C.cGold + "Click Here" + "\n" : ""))
|
||||
.click(ClickEvent.OPEN_URL, SnapshotPublisher.getURL(_report.getToken()))
|
||||
.click(ClickEvent.OPEN_URL, SnapshotRepository.getURL(_report.getToken()))
|
||||
.add("\n")
|
||||
.add(C.cAqua + "Type " + C.cGold + "/reportclose " + reportId + " <reason>" + C.cAqua + " to close this report.")
|
||||
.click(ClickEvent.SUGGEST_COMMAND, "/reportclose " + reportId)
|
||||
|
@ -14,7 +14,7 @@ import mineplex.core.blockrestore.BlockRestore;
|
||||
import mineplex.core.chat.Chat;
|
||||
import mineplex.core.chatsnap.SnapshotManager;
|
||||
import mineplex.core.chatsnap.SnapshotPlugin;
|
||||
import mineplex.core.chatsnap.publishing.SnapshotPublisher;
|
||||
import mineplex.core.chatsnap.SnapshotRepository;
|
||||
import mineplex.core.command.CommandCenter;
|
||||
import mineplex.core.common.MinecraftVersion;
|
||||
import mineplex.core.common.Pair;
|
||||
@ -145,7 +145,7 @@ public class Clans extends JavaPlugin
|
||||
Pair.create(MinecraftVersion.Version1_9, "http://file.mineplex.com/ResClans19.zip")
|
||||
}, true);
|
||||
|
||||
SnapshotManager snapshotManager = new SnapshotManager(new SnapshotPublisher(this));
|
||||
SnapshotManager snapshotManager = new SnapshotManager(new SnapshotRepository(this));
|
||||
new SnapshotPlugin(this, snapshotManager);
|
||||
new ReportPlugin(this, new ReportManager(this, preferenceManager, snapshotManager, _clientManager, serverStatusManager.getCurrentServerName(), 1));
|
||||
|
||||
|
@ -16,7 +16,7 @@ import mineplex.core.boosters.BoosterManager;
|
||||
import mineplex.core.chat.Chat;
|
||||
import mineplex.core.chatsnap.SnapshotManager;
|
||||
import mineplex.core.chatsnap.SnapshotPlugin;
|
||||
import mineplex.core.chatsnap.publishing.SnapshotPublisher;
|
||||
import mineplex.core.chatsnap.SnapshotRepository;
|
||||
import mineplex.core.command.CommandCenter;
|
||||
import mineplex.core.common.events.ServerShutdownEvent;
|
||||
import mineplex.core.creature.Creature;
|
||||
@ -78,10 +78,6 @@ import mineplex.minecraft.game.core.combat.CombatManager;
|
||||
import mineplex.minecraft.game.core.damage.DamageManager;
|
||||
import mineplex.minecraft.game.core.fire.Fire;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
public class Hub extends JavaPlugin implements IRelation
|
||||
{
|
||||
private String WEB_CONFIG = "webServer";
|
||||
@ -173,7 +169,7 @@ public class Hub extends JavaPlugin implements IRelation
|
||||
new GlobalPacketManager(this, clientManager, serverStatusManager, inventoryManager, donationManager, petManager, statsManager, hubManager.getBonusManager().getRewardManager());
|
||||
//new Replay(this, packetHandler);
|
||||
|
||||
SnapshotManager snapshotManager = new SnapshotManager(new SnapshotPublisher(this));
|
||||
SnapshotManager snapshotManager = new SnapshotManager(new SnapshotRepository(this));
|
||||
ReportManager reportManager = new ReportManager(this, preferenceManager, snapshotManager, clientManager, serverStatusManager.getCurrentServerName(), 3);
|
||||
new SnapshotPlugin(this, snapshotManager);
|
||||
new ReportPlugin(this, reportManager);
|
||||
|
@ -11,11 +11,10 @@ import org.bukkit.plugin.java.JavaPlugin;
|
||||
import mineplex.core.CustomTagFix;
|
||||
import mineplex.core.FoodDupeFix;
|
||||
import mineplex.core.PacketsInteractionFix;
|
||||
import mineplex.core.chatsnap.publishing.SnapshotPublisher;
|
||||
import mineplex.core.chatsnap.SnapshotRepository;
|
||||
import mineplex.core.customdata.CustomDataManager;
|
||||
import mineplex.core.chatsnap.SnapshotManager;
|
||||
import mineplex.core.chatsnap.SnapshotPlugin;
|
||||
import mineplex.core.giveaway.GiveawayManager;
|
||||
import mineplex.core.globalpacket.GlobalPacketManager;
|
||||
import net.minecraft.server.v1_8_R3.BiomeBase;
|
||||
import net.minecraft.server.v1_8_R3.MinecraftServer;
|
||||
@ -37,7 +36,6 @@ import mineplex.core.elo.EloManager;
|
||||
import mineplex.core.friend.FriendManager;
|
||||
import mineplex.core.gadget.GadgetManager;
|
||||
import mineplex.core.give.Give;
|
||||
import mineplex.core.globalpacket.GlobalPacketManager;
|
||||
import mineplex.core.hologram.HologramManager;
|
||||
import mineplex.core.ignore.IgnoreManager;
|
||||
import mineplex.core.incognito.IncognitoManager;
|
||||
@ -70,7 +68,6 @@ import mineplex.core.velocity.VelocityFix;
|
||||
import mineplex.core.visibility.VisibilityManager;
|
||||
import mineplex.minecraft.game.core.combat.CombatManager;
|
||||
import mineplex.minecraft.game.core.damage.DamageManager;
|
||||
import nautilus.game.arcade.broadcast.BroadcastManager;
|
||||
import nautilus.game.arcade.game.GameServerConfig;
|
||||
|
||||
public class Arcade extends JavaPlugin
|
||||
@ -151,7 +148,7 @@ public class Arcade extends JavaPlugin
|
||||
Chat chat = new Chat(this, incognito, _clientManager, preferenceManager, achievementManager, serverStatusManager.getCurrentServerName());
|
||||
new MessageManager(this, incognito, _clientManager, preferenceManager, ignoreManager, punish, friendManager, chat);
|
||||
|
||||
SnapshotManager snapshotManager = new SnapshotManager(new SnapshotPublisher(this));
|
||||
SnapshotManager snapshotManager = new SnapshotManager(new SnapshotRepository(this));
|
||||
ReportManager reportManager = new ReportManager(this, preferenceManager, snapshotManager, _clientManager, serverStatusManager.getCurrentServerName(), 1);
|
||||
new SnapshotPlugin(this, snapshotManager);
|
||||
new ReportPlugin(this, reportManager);
|
||||
|
Loading…
Reference in New Issue
Block a user