PC-886 Move report bans over to punishment gui

This commit is contained in:
Keir Nellyer 2016-09-16 17:40:14 +01:00
parent ebe212c8ff
commit 2cdab061b6
14 changed files with 180 additions and 201 deletions

View File

@ -8,6 +8,7 @@ public enum Category
Hacking, // Illegal Mods
Warning,
PermMute,
ReportAbuse, // Abusing /report command
Other; // Represents perm ban - (or old perm mutes)
public static boolean contains(String s)

View File

@ -1,6 +1,7 @@
package mineplex.core.punish;
import java.util.HashMap;
import java.util.logging.Level;
import mineplex.core.account.CoreClient;
import org.bukkit.Bukkit;
@ -188,8 +189,24 @@ public class Punish extends MiniPlugin
_punishClients.put(playerName.toLowerCase(), new PunishClient());
}
final PunishmentSentence sentence = !ban ? PunishmentSentence.Mute : PunishmentSentence.Ban;
final PunishmentSentence sentence;
if (ban)
{
sentence = PunishmentSentence.Ban;
}
else
{
if (category == Category.ReportAbuse)
{
sentence = PunishmentSentence.ReportBan;
}
else
{
sentence = PunishmentSentence.Mute;
}
}
final long finalDuration = duration;
_repository.Punish(new Callback<String>()
@ -241,6 +258,34 @@ public class Punish extends MiniPlugin
informOfPunish(finalPlayerName, F.main(getName(), caller == null ? "Mineplex Anti-Cheat" : caller.getName() + " banned " + finalPlayerName + " for " + durationString + "."));
}
}
else if (sentence == PunishmentSentence.ReportBan)
{
if (caller == null)
System.out.println(F.main(getName(), F.elem(caller == null ? "Mineplex Anti-Cheat" : caller.getName()) + " report banned " + F.elem(finalPlayerName) + " because of " + F.elem(reason) + " for " +
durationString + "."));
if (!silent)
{
informOfPunish(finalPlayerName, F.main(getName(), caller == null ? "Mineplex Anti-Cheat" : caller.getName() + " report banned " + finalPlayerName + " for " + durationString + "."));
}
//Inform
if (player != null)
{
UtilPlayer.message(player, F.main("Punish", F.elem(C.cGray + C.Bold + "Reason: ") + reason));
player.playSound(player.getLocation(), Sound.CAT_MEOW, 1f, 1f);
}
else
new mineplex.serverdata.commands.PunishCommand(finalPlayerName, false, finalDuration != 0, F.main("Punish", F.elem(C.cGray + C.Bold + "Report Ban Reason: ") + reason)).publish();
_repository.LoadPunishClient(finalPlayerName, new Callback<PunishClientToken>()
{
public void run(PunishClientToken token)
{
LoadClient(token);
}
});
}
else
{
if (caller == null)
@ -306,7 +351,22 @@ public class Punish extends MiniPlugin
for (PunishmentToken punishment : token.Punishments)
{
client.AddPunishment(Category.valueOf(punishment.Category), new Punishment(punishment.PunishmentId, PunishmentSentence.valueOf(punishment.Sentence), Category.valueOf(punishment.Category), punishment.Reason, punishment.Admin, punishment.Duration, punishment.Severity, punishment.Time + timeDifference, punishment.Active, punishment.Removed, punishment.RemoveAdmin, punishment.RemoveReason));
Category category;
PunishmentSentence punishmentType;
// catch if category or punishment type no longer exists
try
{
category = Category.valueOf(punishment.Category);
punishmentType = PunishmentSentence.valueOf(punishment.Sentence);
}
catch(IllegalArgumentException e)
{
getPlugin().getLogger().log(Level.WARNING, "Skipping loading of punishment id " + punishment.PunishmentId + ", invalid category or punishment type.");
continue;
}
client.AddPunishment(category, new Punishment(punishment.PunishmentId, punishmentType, category, punishment.Reason, punishment.Admin, punishment.Duration, punishment.Severity, punishment.Time + timeDifference, punishment.Active, punishment.Removed, punishment.RemoveAdmin, punishment.RemoveReason));
}
_punishClients.put(token.Name.toLowerCase(), client);

View File

@ -54,6 +54,22 @@ public class PunishClient
return false;
}
public boolean IsReportBanned()
{
for (List<Punishment> punishments : _punishments.values())
{
for (Punishment punishment : punishments)
{
if (punishment.IsReportBanned())
{
return true;
}
}
}
return false;
}
public Punishment GetPunishment(PunishmentSentence sentence)
{
for (List<Punishment> punishments : _punishments.values())
@ -68,6 +84,10 @@ public class PunishClient
{
return punishment;
}
else if (sentence == PunishmentSentence.ReportBan && punishment.IsReportBanned())
{
return punishment;
}
}
}

View File

@ -105,6 +105,11 @@ public class Punishment
return _punishmentType == PunishmentSentence.Mute && (GetRemaining() > 0 || _hours < 0) && _active;
}
public boolean IsReportBanned()
{
return _punishmentType == PunishmentSentence.ReportBan && (GetRemaining() > 0 || _hours < 0) && _active;
}
public long GetRemaining()
{
return _hours < 0 ? -1 : (long) ((_time + (TimeSpan.HOUR * _hours)) - System.currentTimeMillis());

View File

@ -3,5 +3,6 @@ package mineplex.core.punish;
public enum PunishmentSentence
{
Ban,
Mute
Mute,
ReportBan
}

View File

@ -55,6 +55,7 @@ public class PunishPage extends CraftInventoryCustom implements Listener
private ShopItem _warningButton;
private ShopItem _permMuteButton;
private ShopItem _permBanButton;
private ShopItem _permReportBanButton;
public PunishPage(Punish plugin, Player player, String target, String reason, boolean wasDisguised, String originalName, String disguisedName)
{
@ -118,6 +119,7 @@ public class PunishPage extends CraftInventoryCustom implements Listener
_warningButton = new ShopItem(Material.PAPER, (byte)0, "Warning", new String[] { }, 1, false, true);
_permMuteButton = new ShopItem(Material.EMERALD_BLOCK, (byte)0, "Permanent Mute", new String[] { }, 1, false, true);
_permBanButton = new ShopItem(Material.REDSTONE_BLOCK, (byte)0, "Permanent Ban", new String[] { }, 1, false, true);
_permReportBanButton = new ShopItem(Material.ENCHANTED_BOOK, (byte)0, "Permanent Report Ban", new String[] { }, 1, false, true);
getInventory().setItem(10, _chatOffenseButton.getHandle());
getInventory().setItem(12, _exploitingButton.getHandle());
@ -310,6 +312,14 @@ public class PunishPage extends CraftInventoryCustom implements Listener
" ",
examplePrefixNote + "Must supply detailed reason for Mute."
}, 1, false, true), new PunishButton(this, Category.ChatOffense, 4, false, -1));
AddButton(26, new ShopItem(Material.ENCHANTED_BOOK, (byte)0, "Permanent Report Ban", new String[] {
ChatColor.RESET + "Report Ban Duration: " + ChatColor.YELLOW + "Permanent",
" ",
examplePrefix + "Abusing Report Feature",
examplePrefixEx + " /report SomeUser THE STAFF HERE SUCK",
examplePrefixEx + " /report SomeUser MINEPLEX IS A F****** PIECE OF S***"
}, 1, false, true), new PunishButton(this, Category.ReportAbuse, 3, false, -1));
}
if (_plugin.GetClients().Get(_player).GetRank() == Rank.DEVELOPER || _plugin.GetClients().Get(_player).GetRank() == Rank.JNR_DEV)
@ -372,9 +382,12 @@ public class PunishPage extends CraftInventoryCustom implements Listener
case PermMute:
button = _permMuteButton.clone();
break;
case ReportAbuse:
button = _permReportBanButton.clone();
break;
case Other:
button = _permBanButton.clone();
break;
break;
default:
break;
}

View File

@ -19,6 +19,7 @@ import org.bukkit.plugin.java.JavaPlugin;
import com.google.common.collect.HashMultimap;
import com.google.common.collect.Multimap;
import mineplex.core.account.CoreClient;
import mineplex.core.account.CoreClientManager;
import mineplex.core.chatsnap.SnapshotManager;
import mineplex.core.chatsnap.command.PushSnapshotsCommand;
@ -33,6 +34,9 @@ import mineplex.core.common.util.UtilFuture;
import mineplex.core.common.util.UtilPlayer;
import mineplex.core.incognito.IncognitoManager;
import mineplex.core.portal.Portal;
import mineplex.core.punish.Category;
import mineplex.core.punish.Punish;
import mineplex.core.punish.PunishClient;
import mineplex.core.report.redis.HandlerNotification;
import mineplex.core.report.data.Report;
import mineplex.core.report.data.ReportMessage;
@ -56,6 +60,7 @@ public class ReportManager
private final SnapshotManager _snapshotManager;
private final CoreClientManager _clientManager;
private final IncognitoManager _incognitoManager;
private final Punish _punish;
private final String _serverName;
private final int _serverWeight;
@ -63,12 +68,13 @@ public class ReportManager
private final ReportUserRepository _reportUserRepository;
public ReportManager(JavaPlugin plugin, SnapshotManager snapshotManager, CoreClientManager clientManager,
IncognitoManager incognitoManager, String serverName, int serverWeight)
IncognitoManager incognitoManager, Punish punish, String serverName, int serverWeight)
{
_plugin = plugin;
_snapshotManager = snapshotManager;
_clientManager = clientManager;
_incognitoManager = incognitoManager;
_punish = punish;
_serverName = serverName;
_serverWeight = serverWeight;
@ -264,7 +270,12 @@ public class ReportManager
{
// if report was marked abusive, check if each of the reporters
// should be banned from using the report system
report.getReporterIds().forEach(this::checkAbuseBan);
report.getReporterIds().forEach(reporterId ->
_reportRepository.getAccountUUID(reporterId).thenAccept(reporterUUID ->
{
CoreClient reporterClient = _clientManager.Get(reporterUUID);
checkAbuseBan(reporterClient, reportCloser);
}));
}
Bukkit.getScheduler().runTask(_plugin, () ->
@ -321,27 +332,25 @@ public class ReportManager
* Checks if the account should be banned from using the report system.
* If so, a ban will be applied.
*
* @param accountId the account to check for a ban
* @param reporter the player who should be banned if threshold is met
* @param handler the handler of the report
*/
private void checkAbuseBan(int accountId)
private void checkAbuseBan(CoreClient reporter, Player handler)
{
_reportRepository.hasBan(accountId).thenCompose(banned ->
String clientName = reporter.getName();
PunishClient punishClient = _punish.GetClient(clientName);
boolean reportBanned = punishClient.IsReportBanned();
if (!reportBanned)
{
if (!banned)
_reportRepository.getResultCount(reporter.getAccountId(), ReportResultType.ABUSIVE).thenAccept(abuseCount ->
{
return _reportRepository.getResultCount(accountId, ReportResultType.ABUSIVE).thenCompose(abuseCount ->
if (abuseCount >= ABUSE_BAN_THRESHOLD)
{
if (abuseCount >= ABUSE_BAN_THRESHOLD)
{
return _reportRepository.addBan(accountId);
}
return CompletableFuture.completedFuture(null);
});
}
return CompletableFuture.completedFuture(null);
});
_punish.AddPunishment(clientName, Category.ReportAbuse, "Automatic report ban for reaching abuse threshold.", handler, 3, false, -1);
}
});
}
}
/**
@ -416,15 +425,9 @@ public class ReportManager
* @param player the player to check if they can report
* @return true if the player can report, false if banned
*/
public CompletableFuture<Boolean> canReport(Player player)
public boolean canReport(Player player)
{
int accountId = _clientManager.Get(player).getAccountId();
return _reportRepository.hasBan(accountId).exceptionally(throwable ->
{
_plugin.getLogger().log(Level.SEVERE, "Error fetching user report ban status.", throwable);
return false;
}).thenApply(banned -> !banned);
return !_punish.GetClient(player.getName()).IsReportBanned();
}
/**

View File

@ -12,7 +12,6 @@ import mineplex.core.report.command.ReportCommand;
import mineplex.core.report.command.ReportHandleCommand;
import mineplex.core.report.command.ReportInfoCommand;
import mineplex.core.report.command.ReportStatsCommand;
import mineplex.core.report.command.ReportUnbanCommand;
/**
* Main class for this module, handles initialization and disabling of the module.
@ -40,7 +39,6 @@ public class ReportPlugin extends MiniPlugin
addCommand(new ReportCloseCommand(this));
addCommand(new ReportStatsCommand(this));
addCommand(new ReportAbortCommand(this));
addCommand(new ReportUnbanCommand(this));
addCommand(new ReportInfoCommand(this));
}

View File

@ -35,58 +35,56 @@ public class ReportCommand extends CommandBase<ReportPlugin>
else
{
ReportManager reportManager = Plugin.getReportManager();
boolean canReport = reportManager.canReport(reporter);
reportManager.canReport(reporter).thenCompose(BukkitFuture.accept(canReport ->
if (canReport)
{
if (canReport)
if(args == null || args.length < 2)
{
if(args == null || args.length < 2)
{
UtilPlayer.message(reporter, F.main(Plugin.getName(), C.cRed + "Invalid Usage: " + F.elem("/" + _aliasUsed + " <player> <reason>")));
}
else
{
CoreClientManager clientManager = _commandCenter.GetClientManager();
int reporterId = clientManager.getAccountId(reporter);
String playerName = args[0];
Player suspect = UtilPlayer.searchOnline(reporter, playerName, false);
String reason = F.combine(args, 1, null, false);
if (suspect != null)
{
// allow developer (iKeirNez) to report himself (for easy testing reasons)
if (suspect == reporter && !reportManager.isDevMode(reporter.getUniqueId()))
{
UtilPlayer.message(reporter, F.main(Plugin.getName(), C.cRed + "You cannot report yourself."));
}
else
{
CoreClient suspectClient = clientManager.Get(suspect);
new ReportCategoryPage(Plugin, reporter, reporterId, suspectClient, reason).openInventory();
}
}
else
{
clientManager.loadClientByName(playerName, suspectClient ->
{
if (suspectClient != null)
{
new ReportCategoryPage(Plugin, reporter, reporterId, suspectClient, reason).openInventory();
}
else
{
UtilPlayer.message(reporter, F.main(Plugin.getName(), C.cRed + "Unable to find player '"
+ playerName + "'!"));
}
});
}
}
UtilPlayer.message(reporter, F.main(Plugin.getName(), C.cRed + "Invalid Usage: " + F.elem("/" + _aliasUsed + " <player> <reason>")));
}
else
{
reporter.sendMessage(C.cRed + "You are banned from using the report command.");
CoreClientManager clientManager = _commandCenter.GetClientManager();
int reporterId = clientManager.getAccountId(reporter);
String playerName = args[0];
Player suspect = UtilPlayer.searchOnline(reporter, playerName, false);
String reason = F.combine(args, 1, null, false);
if (suspect != null)
{
// allow developer (iKeirNez) to report himself (for easy testing reasons)
if (suspect == reporter && !reportManager.isDevMode(reporter.getUniqueId()))
{
UtilPlayer.message(reporter, F.main(Plugin.getName(), C.cRed + "You cannot report yourself."));
}
else
{
CoreClient suspectClient = clientManager.Get(suspect);
new ReportCategoryPage(Plugin, reporter, reporterId, suspectClient, reason).openInventory();
}
}
else
{
clientManager.loadClientByName(playerName, suspectClient ->
{
if (suspectClient != null)
{
new ReportCategoryPage(Plugin, reporter, reporterId, suspectClient, reason).openInventory();
}
else
{
UtilPlayer.message(reporter, F.main(Plugin.getName(), C.cRed + "Unable to find player '"
+ playerName + "'!"));
}
});
}
}
}));
}
else
{
UtilPlayer.message(reporter, C.cRed + "You are banned from using the report feature.");
}
}
}
}

View File

@ -1,60 +0,0 @@
package mineplex.core.report.command;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import mineplex.core.command.CommandBase;
import mineplex.core.common.Rank;
import mineplex.core.common.util.C;
import mineplex.core.common.util.F;
import mineplex.core.common.util.UtilPlayer;
import mineplex.core.report.ReportPlugin;
import mineplex.core.report.data.ReportRepository;
/**
* A temporary command to allow unbanning of users who have abused the report system.
*/
public class ReportUnbanCommand extends CommandBase<ReportPlugin>
{
public ReportUnbanCommand(ReportPlugin plugin)
{
super(plugin, Rank.MODERATOR, "reportunban", "runban");
}
@Override
public void Execute(Player caller, String[] args)
{
if (args != null && args.length == 1)
{
String targetName = args[0];
Player target = Bukkit.getPlayerExact(targetName);
if (target != null)
{
ReportRepository repository = Plugin.getReportManager().getReportRepository();
int targetId = _commandCenter.GetClientManager().getAccountId(target);
repository.hasBan(targetId).thenAccept(hasBan ->
{
if (hasBan)
{
repository.removeBan(targetId).thenAccept(aVoid ->
UtilPlayer.message(caller, F.main(Plugin.getName(), "Unbanned player from the report system.")));
}
else
{
UtilPlayer.message(caller, F.main(Plugin.getName(), C.cRed + "That player is not banned from using the report system."));
}
});
}
else
{
UtilPlayer.message(caller, F.main(Plugin.getName(), C.cRed + "Couldn't find player named: " + F.elem(targetName)));
}
}
else
{
UtilPlayer.message(caller, F.main(Plugin.getName(), C.cRed + "Invalid Usage: " + F.elem("/" + _aliasUsed + " <player>")));
}
}
}

View File

@ -142,12 +142,6 @@ public class ReportRepository
"ORDER BY reports.id DESC\n" +
"LIMIT ?;";
/** BANS **/
private static final String CHECK_FOR_BAN = "SELECT accountId FROM reportBans WHERE accountId = ? LIMIT 1;";
private static final String INSERT_BAN = "INSERT INTO reportBans (accountId) VALUES (?);";
private static final String REMOVE_BAN = "DELETE FROM reportBans WHERE accountId = ?;";
private final ReportManager _reportManager;
private final Logger _logger;
@ -746,60 +740,6 @@ public class ReportRepository
return reportIds;
}
public CompletableFuture<Boolean> hasBan(int accountId)
{
return CompletableFuture.supplyAsync(() ->
{
try (Connection connection = DBPool.getAccount().getConnection())
{
PreparedStatement preparedStatement = connection.prepareStatement(CHECK_FOR_BAN);
preparedStatement.setInt(1, accountId);
ResultSet resultSet = preparedStatement.executeQuery();
return resultSet.next();
}
catch (SQLException e)
{
throw new RuntimeException(e);
}
});
}
public CompletableFuture<Void> addBan(int accountId)
{
return CompletableFuture.supplyAsync(() ->
{
try (Connection connection = DBPool.getAccount().getConnection())
{
PreparedStatement preparedStatement = connection.prepareStatement(INSERT_BAN);
preparedStatement.setInt(1, accountId);
preparedStatement.execute();
return null;
}
catch (SQLException e)
{
throw new RuntimeException(e);
}
});
}
public CompletableFuture<Void> removeBan(int accountId)
{
return CompletableFuture.supplyAsync(() ->
{
try (Connection connection = DBPool.getAccount().getConnection())
{
PreparedStatement preparedStatement = connection.prepareStatement(REMOVE_BAN);
preparedStatement.setInt(1, accountId);
preparedStatement.execute();
return null;
}
catch (SQLException e)
{
throw new RuntimeException(e);
}
});
}
/**
* Disposes of cached reports which are cached as a result of this user.
* This function is called when a user leaves the server.

View File

@ -235,7 +235,7 @@ public class Clans extends JavaPlugin
SnapshotManager snapshotManager = new SnapshotManager(this, new SnapshotRepository(serverStatusManager.getCurrentServerName(), getLogger()));
new SnapshotPlugin(this, snapshotManager, _clientManager);
new ReportPlugin(this, new ReportManager(this, snapshotManager, _clientManager, incognito, serverStatusManager.getCurrentServerName(), 1));
new ReportPlugin(this, new ReportManager(this, snapshotManager, _clientManager, incognito, punish, serverStatusManager.getCurrentServerName(), 1));
// Enable custom-gear related managers
new CustomTagFix(this, packetHandler);

View File

@ -187,7 +187,7 @@ public class Hub extends JavaPlugin implements IRelation
//new Replay(this, packetHandler);
SnapshotManager snapshotManager = new SnapshotManager(this, new SnapshotRepository(serverStatusManager.getCurrentServerName(), getLogger()));
ReportManager reportManager = new ReportManager(this, snapshotManager, clientManager, incognito, serverStatusManager.getCurrentServerName(), 3);
ReportManager reportManager = new ReportManager(this, snapshotManager, clientManager, incognito, punish, serverStatusManager.getCurrentServerName(), 3);
new SnapshotPlugin(this, snapshotManager, clientManager);
new ReportPlugin(this, reportManager);

View File

@ -157,7 +157,7 @@ public class Arcade extends JavaPlugin
new MessageManager(this, incognito, _clientManager, preferenceManager, ignoreManager, punish, friendManager, chat);
SnapshotManager snapshotManager = new SnapshotManager(this, new SnapshotRepository(serverStatusManager.getCurrentServerName(), getLogger()));
ReportManager reportManager = new ReportManager(this, snapshotManager, _clientManager, incognito, serverStatusManager.getCurrentServerName(), 1);
ReportManager reportManager = new ReportManager(this, snapshotManager, _clientManager, incognito, punish, serverStatusManager.getCurrentServerName(), 1);
new SnapshotPlugin(this, snapshotManager, _clientManager);
new ReportPlugin(this, reportManager);