Fix infinite gson loop by separating dependencies.
This commit is contained in:
parent
9c45a48a26
commit
d7ba2e4731
|
@ -11,9 +11,11 @@ import mineplex.core.common.jsonchat.ClickEvent;
|
|||
import mineplex.core.common.jsonchat.JsonMessage;
|
||||
import mineplex.core.portal.Portal;
|
||||
import mineplex.core.preferences.PreferencesManager;
|
||||
import mineplex.core.report.command.ReportNotificationCallback;
|
||||
import mineplex.core.report.command.ReportNotification;
|
||||
import mineplex.serverdata.Region;
|
||||
import mineplex.serverdata.Utility;
|
||||
import mineplex.serverdata.commands.ServerCommandManager;
|
||||
import mineplex.serverdata.data.DataRepository;
|
||||
import mineplex.serverdata.redis.RedisDataRepository;
|
||||
|
||||
|
@ -55,6 +57,8 @@ public class ReportManager {
|
|||
_activeReports = new HashMap<String, Integer>();
|
||||
_reportSqlRepository = new ReportRepository(plugin);
|
||||
_reportSqlRepository.initialize();
|
||||
|
||||
ServerCommandManager.getInstance().registerCommandType("ReportNotification", ReportNotification.class, new ReportNotificationCallback(this));
|
||||
}
|
||||
|
||||
public void retrieveReportResult(int reportId, Player reportCloser, String reason)
|
||||
|
@ -142,7 +146,7 @@ public class ReportManager {
|
|||
}
|
||||
|
||||
// only start notifying staff when
|
||||
if (report.getReporters().size() >= 3)
|
||||
if (report.getReporters().size() >= 1)
|
||||
{
|
||||
// [Report 42] [MrTwiggy +7] [Cheater102 - 5 - Speed hacking]
|
||||
String message = String.format("[Report %d] [%s %d] [%s - %d - %s]", report.getReportId(),
|
||||
|
@ -252,6 +256,7 @@ public class ReportManager {
|
|||
{
|
||||
boolean isStaff = CommandCenter.Instance.GetClientManager().Get(player).GetRank().has(Rank.MODERATOR);
|
||||
boolean hasReportNotifications = _preferencesManager.Get(player).ShowUserReports;
|
||||
System.out.println("player " + player.getName() + " isstaff " + isStaff + " hasnotif " + hasReportNotifications);
|
||||
return isStaff && hasReportNotifications;
|
||||
}
|
||||
|
||||
|
@ -261,7 +266,7 @@ public class ReportManager {
|
|||
*/
|
||||
public void sendReportNotification(JsonMessage message)
|
||||
{
|
||||
ReportNotification reportNotification = new ReportNotification(this, message);
|
||||
ReportNotification reportNotification = new ReportNotification(message);
|
||||
reportNotification.publish();
|
||||
}
|
||||
|
||||
|
@ -271,7 +276,7 @@ public class ReportManager {
|
|||
*/
|
||||
public void sendReportNotification(String message)
|
||||
{
|
||||
ReportNotification reportNotification = new ReportNotification(this, message);
|
||||
ReportNotification reportNotification = new ReportNotification(message);
|
||||
reportNotification.publish();
|
||||
}
|
||||
|
||||
|
|
|
@ -1,11 +1,6 @@
|
|||
package mineplex.core.report.command;
|
||||
|
||||
import org.bukkit.Server;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import mineplex.core.common.jsonchat.JsonMessage;
|
||||
import mineplex.core.common.util.UtilServer;
|
||||
import mineplex.core.report.ReportManager;
|
||||
import mineplex.serverdata.commands.ServerCommand;
|
||||
|
||||
/**
|
||||
|
@ -13,31 +8,26 @@ import mineplex.serverdata.commands.ServerCommand;
|
|||
*/
|
||||
public class ReportNotification extends ServerCommand
|
||||
{
|
||||
private ReportManager _reportManager;
|
||||
private String _notification; // in json format
|
||||
|
||||
public ReportNotification(ReportManager reportManager, String notification)
|
||||
public ReportNotification(String notification)
|
||||
{
|
||||
this(reportManager, new JsonMessage(notification));
|
||||
this(new JsonMessage(notification));
|
||||
}
|
||||
|
||||
public ReportNotification(ReportManager reportManager, JsonMessage notification)
|
||||
public ReportNotification(JsonMessage notification)
|
||||
{
|
||||
super(); // Send to all servers
|
||||
_reportManager = reportManager;
|
||||
_notification = notification.toString();
|
||||
}
|
||||
|
||||
|
||||
public String getNotification()
|
||||
{
|
||||
return _notification;
|
||||
}
|
||||
|
||||
public void run()
|
||||
{
|
||||
// Message all players that can receive report notifications.
|
||||
for (Player player : UtilServer.getPlayers())
|
||||
{
|
||||
if (_reportManager.hasReportNotifications(player))
|
||||
{
|
||||
Server server = UtilServer.getServer();
|
||||
server.dispatchCommand(server.getConsoleSender(), "tellraw " + player.getName() + " " + _notification);
|
||||
}
|
||||
}
|
||||
// Utilitizes a callback functionality to seperate dependencies
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,42 @@
|
|||
package mineplex.core.report.command;
|
||||
|
||||
import org.bukkit.Server;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import mineplex.core.common.util.UtilServer;
|
||||
import mineplex.core.report.ReportManager;
|
||||
import mineplex.serverdata.commands.CommandCallback;
|
||||
import mineplex.serverdata.commands.ServerCommand;
|
||||
|
||||
/**
|
||||
* Handles receiving of report notifications.
|
||||
* @author iKeirNez
|
||||
*/
|
||||
public class ReportNotificationCallback implements CommandCallback
|
||||
{
|
||||
private ReportManager _reportManager;
|
||||
|
||||
public ReportNotificationCallback(ReportManager reportManager)
|
||||
{
|
||||
_reportManager = reportManager;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run(ServerCommand command)
|
||||
{
|
||||
if (command instanceof ReportNotification)
|
||||
{
|
||||
ReportNotification reportNotification = (ReportNotification) command;
|
||||
|
||||
// Message all players that can receive report notifications.
|
||||
for (Player player : UtilServer.getPlayers())
|
||||
{
|
||||
if (_reportManager.hasReportNotifications(player))
|
||||
{
|
||||
Server server = UtilServer.getServer();
|
||||
server.dispatchCommand(server.getConsoleSender(), "tellraw " + player.getName() + " " + reportNotification.getNotification());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue