Fixed merge conflicts

This commit is contained in:
AlexTheCoder 2018-01-07 06:21:21 -05:00 committed by Alexander Meech
parent da5d58fcbd
commit 7b955dad16
2 changed files with 234 additions and 492 deletions

View File

@ -15,7 +15,6 @@ import mineplex.core.common.util.F;
import mineplex.core.common.util.UtilPlayer;
import mineplex.core.punish.Punish;
import mineplex.core.punish.UI.PunishPage;
import mineplex.core.punish.UI.PunishPageOld;
import mineplex.core.punish.UI.PunishShop;
public class PunishCommand extends CommandBase<Punish>

View File

@ -1,580 +1,240 @@
package mineplex.core.punish.UI;
import java.util.AbstractMap;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.craftbukkit.v1_8_R3.inventory.CraftInventoryCustom;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.HandlerList;
import org.bukkit.event.Listener;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.event.inventory.InventoryCloseEvent;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import mineplex.core.Managers;
import mineplex.core.antihack.AntiHack;
import mineplex.core.common.util.C;
import mineplex.core.common.util.F;
import mineplex.core.common.util.LineFormat;
import mineplex.core.common.util.NautHashMap;
import mineplex.core.common.util.UtilText;
import mineplex.core.common.util.UtilTime;
import mineplex.core.donation.DonationManager;
import mineplex.core.punish.Category;
import mineplex.core.punish.Punish;
import mineplex.core.punish.PunishClient;
import mineplex.core.punish.Punishment;
import mineplex.core.punish.PunishmentResponse;
import mineplex.core.punish.PunishmentSorter;
import mineplex.core.shop.item.IButton;
import mineplex.core.shop.item.ShopItem;
import mineplex.core.shop.confirmation.ConfirmationCallback;
import mineplex.core.shop.confirmation.ConfirmationPage;
import mineplex.core.shop.confirmation.ConfirmationProcessor;
import mineplex.core.shop.page.ShopPageBase;
public class PunishPage extends CraftInventoryCustom implements Listener
public abstract class PunishPage extends ShopPageBase<Punish, PunishShop>
{
private Punish _plugin;
private NautHashMap<Integer, IButton> _buttonMap;
private Player _player;
private String _target;
private String _reason;
private boolean _wasDisguised;
private String _originalName;
private String _disguisedName;
private ShopItem _chatOffenseButton;
private ShopItem _exploitingButton;
private ShopItem _hackingButton;
private ShopItem _warningButton;
private ShopItem _permMuteButton;
private ShopItem _permBanButton;
private ShopItem _permReportBanButton;
protected String _target;
protected String _reason;
public PunishPage(Punish plugin, Player player, String target, String reason, boolean wasDisguised, String originalName, String disguisedName)
protected Map<Category, Map<Integer, Integer>> _offenseMap;
protected List<Punishment> _pastPunishments;
public PunishPage(Punish punish, PunishShop shop, String name, Player player, String target, String reason)
{
super(null, 54, " Punish");
super(punish, shop, punish.GetClients(), Managers.require(DonationManager.class), name, player);
_plugin = plugin;
_buttonMap = new NautHashMap<>();
_player = player;
_target = target;
_reason = reason;
_wasDisguised = wasDisguised;
_originalName = originalName;
_disguisedName = disguisedName;
BuildPage();
_offenseMap = new HashMap<>();
_pastPunishments = new LinkedList<>();
_player.openInventory(this);
_plugin.registerEvents(this);
processOffenses();
}
private void BuildPage()
protected ItemStack buildHistoryItem(Punishment punishment)
{
// Player head
getInventory().setItem(4, new ShopItem(Material.SKULL_ITEM, (byte)3, _target, new String[] { ChatColor.RESET + _reason }, 1, false, true).getHandle());
boolean canSeeAllDetails = getPlugin().GetClients().Get(getPlayer()).hasPermission(Punish.Perm.PUNISHMENT_COMMAND);
PunishClient client = _plugin.GetClient(_target);
List<String> lore = new ArrayList<>();
Map<Category, Map<Integer, Integer>> offenseMap = new HashMap<>();
for (Category category : Category.values())
lore.add(C.Reset + "Punishment Type: " + C.cYellow + punishment.GetCategory().getName());
lore.add(C.Reset + "Severity: " + C.cYellow + punishment.GetSeverity());
// Don't let nonstaff see who banned them
if (canSeeAllDetails)
{
//Initialise Offences
offenseMap.put(category, new HashMap<>());
offenseMap.get(category).put(1, 0);
offenseMap.get(category).put(2, 0);
offenseMap.get(category).put(3, 0);
lore.add(C.Reset + "Staff: " + C.cYellow + punishment.GetAdmin());
}
List<Entry<Category, Punishment>> punishments = new ArrayList<>();
lore.add(C.Reset + "Date: " + C.cYellow + UtilTime.when(punishment.GetTime()));
for (Category category : client.GetPunishments().keySet())
{
for (Punishment punishment : client.GetPunishments().get(category))
if (!punishment.GetCategory().equals(Category.Warning))
{
lore.add(C.Reset + "Length: " + C.cYellow + UtilTime.convertString((long) punishment.GetHours()*UtilTime.TimeUnit.HOURS.getMilliseconds(), 1, UtilTime.TimeUnit.FIT));
}
lore.add("");
lore.addAll(UtilText.splitLine(C.Reset + "Reason: " + C.cYellow + punishment.GetReason(), LineFormat.LORE));
if (punishment.GetRemoved())
{
lore.add("");
if (canSeeAllDetails)
{
punishments.add(new AbstractMap.SimpleEntry<Category, Punishment>(category, punishment));
lore.add(C.Reset + "Remove Staff: " + C.cYellow + punishment.GetRemoveAdmin());
}
//Count by Severity
if (!punishment.GetRemoved() && punishment.GetSeverity() > 0 && punishment.GetSeverity() < 4)
lore.addAll(UtilText.splitLine(C.Reset + "Remove Reason: " + C.cYellow + punishment.GetRemoveReason(), LineFormat.LORE));
}
else
{
if (punishment.GetHours() > 0)
{
lore.add("");
lore.add(C.Reset + "Expires On: " + C.cYellow + UtilTime.when(punishment.GetTime() + punishment.GetRemaining()));
lore.add(C.cYellow + "(" + Punish.getDurationString(punishment.GetRemaining() / UtilTime.TimeUnit.HOURS.getMilliseconds()) + ")");
}
}
ItemStack itemStack = new ItemStack(punishment.GetCategory().getIcon());
ItemMeta meta = itemStack.getItemMeta();
meta.setDisplayName(C.cGreenB + punishment.GetCategory().getName());
meta.setLore(lore);
itemStack.setItemMeta(meta);
if ((punishment.GetHours() == -1 || punishment.GetRemaining() > 0) && !punishment.GetRemoved() && punishment.GetActive())
{
itemStack.addUnsafeEnchantment(Enchantment.DURABILITY, 1);
}
return itemStack;
}
protected void addHistoryItem(int slot, Punishment punishment)
{
ItemStack itemStack = buildHistoryItem(punishment);
// It's not in the staff ui
if (_reason == null)
{
addItem(slot, itemStack);
return;
}
if ((punishment.GetHours() == -1 || punishment.GetRemaining() > 0) && !punishment.GetRemoved() && punishment.GetActive())
{
addButton(slot, itemStack, (p, c) -> {
if (getPlugin().GetClients().Get(getPlayer()).hasPermission(Punish.Perm.BYPASS_REMOVE_CONFIRMATION))
{
offenseMap.get(category).put(punishment.GetSeverity(), 1 + offenseMap.get(category).get(punishment.GetSeverity()));
removePunishment(punishment);
return;
}
}
}
String examplePrefix = ChatColor.RESET + "" + ChatColor.GRAY;
String examplePrefixEx = ChatColor.RESET + "" + ChatColor.WHITE;
String examplePrefixNote = ChatColor.RESET + "" + ChatColor.DARK_GREEN;
_chatOffenseButton = new ShopItem(Material.BOOK_AND_QUILL, (byte)0, "Chat Offense", new String[] { examplePrefix + "Verbal Abuse, Spam, Harassment, Trolling, etc" }, 1, false, true);
_exploitingButton = new ShopItem(Material.HOPPER, (byte)0, "General Offense", new String[] { examplePrefix + "Command/Map/Class/Skill exploits, etc" }, 1, false, true);
_hackingButton = new ShopItem(Material.IRON_SWORD, (byte)0, "Client Mod", new String[] { examplePrefix + "X-ray, Forcefield, Speed, Fly, Inventory Hacks, etc" }, 1, false, true);
_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());
getInventory().setItem(14, _hackingButton.getHandle());
//XXX Mute
{
AddButton(19, new ShopItem(Material.INK_SACK, (byte)2, "Severity 1", new String[]
{
ChatColor.RESET + "Past Offences: " + ChatColor.YELLOW + offenseMap.get(Category.ChatOffense).get(1),
ChatColor.RESET + "Mute Duration: " + ChatColor.YELLOW + getDurationString(Category.ChatOffense, 1, offenseMap),
" ",
examplePrefix + "Light Spam",
examplePrefixEx + " Sending the same message 2-5 times",
" ",
examplePrefix + "Light Advertising;",
examplePrefixEx + " 'anyone want to play on minecade?'",
" ",
examplePrefix + "Light Abuse/Harassment",
examplePrefixEx + " 'you suck a this game'",
" ",
examplePrefix + "Hackusations",
examplePrefixEx + " 'you're such a hacker!'",
" ",
examplePrefix + "Trolling",
" ",
examplePrefixNote + "Give Warning if 0 Past Offences and 0 Warnings.",
}, 1, false, true), new PunishButton(this, Category.ChatOffense, 1, false, getDuration(Category.ChatOffense, 1, offenseMap)));
if (_plugin.GetClients().Get(_player).hasPermission(Punish.Perm.FULL_PUNISHMENT_ACCESS))
{
AddButton(28, new ShopItem(Material.INK_SACK, (byte) 11, "Severity 2", new String[]
{
ChatColor.RESET + "Past Offences: " + ChatColor.YELLOW + offenseMap.get(Category.ChatOffense).get(2),
ChatColor.RESET + "Mute Duration: " + ChatColor.YELLOW + getDurationString(Category.ChatOffense, 2, offenseMap),
" ",
examplePrefix + "Medium Spam",
examplePrefixEx + " Sending the same message 6-20 times",
" ",
examplePrefix + "Medium Advertising;",
examplePrefixEx + " 'join crap.server.net' - posted once",
" ",
examplePrefix + "Medium Abuse/Harassment",
examplePrefixEx + " 'piss off you stupid newb'",
examplePrefixEx + " 'SHIT ADMINS ARE SHIT!!!'",
examplePrefixEx + " 'you're terrible, learn to play'",
" ",
examplePrefix + "Avoiding Chat Filter",
examplePrefixEx + " 'F|_|<K YOU'",
}, 1, false, true), new PunishButton(this, Category.ChatOffense, 2, false, getDuration(Category.ChatOffense, 2, offenseMap)));
AddButton(37, new ShopItem(Material.INK_SACK, (byte) 1, "Severity 3", new String[]
{
ChatColor.RESET + "Past Offences: " + ChatColor.YELLOW + offenseMap.get(Category.ChatOffense).get(3),
ChatColor.RESET + "Mute Duration: " + ChatColor.YELLOW + getDurationString(Category.ChatOffense, 3, offenseMap),
" ",
examplePrefix + "Severe Spam",
examplePrefixEx + " Sending the same message 20+ times",
examplePrefixEx + " Only really used for a spam bot",
" ",
examplePrefix + "Severe Abuse/Harassment",
examplePrefixEx + " 'go fucking die in a fire you fucking sack of shit'",
}, 1, false, true), new PunishButton(this, Category.ChatOffense, 3, false, getDuration(Category.ChatOffense, 3, offenseMap)));
}
}
//XXX General
{
AddButton(21, new ShopItem(Material.INK_SACK, (byte)2, "Severity 1", new String[]
{
ChatColor.RESET + "Past Offences: " + ChatColor.YELLOW + offenseMap.get(Category.Exploiting).get(1),
ChatColor.RESET + "Ban Duration: " + ChatColor.YELLOW + getDurationString(Category.Exploiting, 1, offenseMap),
" ",
examplePrefix + "Team Killing",
examplePrefixEx + " Intentionally killing your team mates",
" ",
examplePrefix + "Trolling (Gameplay)",
examplePrefixEx + " Using abilities to trap players in spawn",
" ",
examplePrefix + "Map/Bug Exploiting",
examplePrefixEx + " Abusing an exploit to gain an advantage",
}, 1, false, true), new PunishButton(this, Category.Exploiting, 1, true, getDuration(Category.Exploiting, 1, offenseMap)));
}
//XXX Hacks
{
AddButton(23, new ShopItem(Material.INK_SACK, (byte)2, "Severity 1", new String[]
{
ChatColor.RESET + "Past Offences: " + ChatColor.YELLOW + offenseMap.get(Category.Hacking).get(1),
ChatColor.RESET + "Ban Duration: " + ChatColor.YELLOW + getDurationString(Category.Hacking, 1, offenseMap),
" ",
examplePrefix + "Examples;",
examplePrefixEx + " Damage Indicators",
examplePrefixEx + " Player Radar",
}, 1, false, true), new PunishButton(this, Category.Hacking, 1, true, getDuration(Category.Hacking, 1, offenseMap)));
if (_plugin.GetClients().Get(_player).hasPermission(Punish.Perm.FULL_PUNISHMENT_ACCESS))
{
AddButton(32, new ShopItem(Material.INK_SACK, (byte) 11, "Severity 2", new String[]
{
ChatColor.RESET + "Past Offences: " + ChatColor.YELLOW + offenseMap.get(Category.Hacking).get(2),
ChatColor.RESET + "Ban Duration: " + ChatColor.YELLOW + getDurationString(Category.Hacking, 2, offenseMap),
" ",
examplePrefix + "Hacks;",
examplePrefixEx + " Forcefield",
examplePrefixEx + " Speed Hack",
examplePrefixEx + " Reach Hack",
examplePrefixEx + " Speed Hack",
examplePrefixEx + " Other Hack",
" ",
examplePrefix + "Hack Reports (SR & FR);",
examplePrefixEx + " Forcefield",
examplePrefixEx + " Speed Hack",
examplePrefixEx + " Reach Hack",
examplePrefixEx + " Speed Hack",
examplePrefixEx + " Other Hack",
examplePrefixEx + " Fly Hack",
}, 1, false, true), new PunishButton(this, Category.Hacking, 2, true, getDuration(Category.Hacking, 2, offenseMap)));
int flightSeverity = 2;
try
getShop().openPageForPlayer(getPlayer(), new ConfirmationPage<Punish, PunishShop>(getPlayer(), this, new ConfirmationProcessor()
{
if (Managers.get(AntiHack.class).isStrict())
@Override
public void init(Inventory inventory)
{
flightSeverity = 3;
}
}
catch (Exception e) {}
AddButton(41, new ShopItem(Material.INK_SACK, (byte) 1, "Severity 3", new String[]
{
ChatColor.RESET + "Past Offences: " + ChatColor.YELLOW + offenseMap.get(Category.Hacking).get(flightSeverity),
ChatColor.RESET + "Ban Duration: " + ChatColor.YELLOW + getDurationString(Category.Hacking, flightSeverity, offenseMap),
" ",
examplePrefix + "Hacks;",
examplePrefixEx + " Fly Hack",
" ",
C.cRed + C.Bold + "WARNING;",
C.cRed + "Use Severity 2 for Forum/Staff Reports"
}, 1, false, true), new PunishButton(this, Category.Hacking, 3, true, getDuration(Category.Hacking, flightSeverity, offenseMap)));
}
}
//XXX Other
AddButton(25, new ShopItem(Material.PAPER, (byte)0, "Warning", new String[]
{
" ",
examplePrefix + "Example Warning Input;",
examplePrefixEx + " Spam - Repeatedly writing MEOW",
examplePrefixEx + " Swearing - Saying 'fuck' and 'shit'",
examplePrefixEx + " Hack Accusation - Accused Tomp13 of hacking",
examplePrefixEx + " Trolling - was trying to make bob angry in chat",
}, 1, false, true), new PunishButton(this, Category.Warning, 1, false, 0));
if (_plugin.GetClients().Get(_player).hasPermission(Punish.Perm.FULL_PUNISHMENT_ACCESS))
{
AddButton(34, new ShopItem(Material.REDSTONE_BLOCK, (byte) 0, "Permanent Ban", new String[]
@Override
public void process(ConfirmationCallback callback)
{
ChatColor.RESET + "Ban Duration: " + ChatColor.YELLOW + "Permanent",
" ",
examplePrefixNote + "Must supply detailed reason for Ban."
}, 1, false, true), new PunishButton(this, Category.Other, 1, true, -1));
AddButton(43, new ShopItem(Material.BOOK_AND_QUILL, (byte) 0, "Permanent Mute", new String[]
removePunishment(punishment);
}
}, itemStack, "Confirm Punishment Removal"));
});
}
else if (getPlugin().GetClients().Get(getPlayer()).hasPermission(Punish.Perm.PUNISHMENT_REAPPLY)
// Punishment must have time remaining,
// be inactive, and removed.
&& punishment.GetRemaining() != 0
&& !punishment.GetActive()
&& punishment.GetRemoved())
{
addButton(slot, itemStack, (p, c)->
{
getShop().openPageForPlayer(getPlayer(), new ConfirmationPage<Punish, PunishShop>(getPlayer(), this, new ConfirmationProcessor()
{
@Override
public void init(Inventory inventory)
{
ChatColor.RESET + "Mute Duration: " + ChatColor.YELLOW + "Permanent",
" ",
examplePrefix + "Severe Advertising;",
examplePrefixEx + " 'JOIN MINECADE! MINEPLEX SUCKS!",
examplePrefixEx + " 'join crap.server.net! FREE ADMIN!",
" ",
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[]
}
@Override
public void process(ConfirmationCallback callback)
{
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));
reapplyPunishment(punishment);
}
}, itemStack, "Confirm Punishment Reapply"));
});
}
if (_wasDisguised)
else
{
ShopItem disguiseWarning = new ShopItem(Material.NETHER_STAR, "Disguise Warning", UtilText.splitLinesToArray(new String[]
{
ChatColor.RESET + "The player you are attempting to punish is disguised.",
ChatColor.RESET + "Original Name: " + ChatColor.GREEN + ChatColor.BOLD + _originalName,
ChatColor.RESET + "Disguised Name: " + ChatColor.GREEN + ChatColor.BOLD + _disguisedName,
}, LineFormat.LORE), 1, true, true);
disguiseWarning.addGlow();
AddButton(8, disguiseWarning, (player, clickType) -> {});
}
Collections.sort(punishments, new PunishmentSorter());
int slot = 45;
for (Entry<Category, Punishment> punishmentEntry : punishments)
{
if (punishmentEntry.getKey() == Category.Advertisement)
{
continue;
}
if (slot >= 54)
{
break;
}
ShopItem button = null;
switch (punishmentEntry.getKey())
{
case ChatOffense:
button = _chatOffenseButton.clone();
break;
case Exploiting:
button = _exploitingButton.clone();
break;
case Hacking:
button = _hackingButton.clone();
break;
case Warning:
button = _warningButton.clone();
break;
case PermMute:
button = _permMuteButton.clone();
break;
case ReportAbuse:
button = _permReportBanButton.clone();
break;
case Other:
button = _permBanButton.clone();
break;
default:
break;
}
Punishment punishment = punishmentEntry.getValue();
//Reason Lines for LORE
List<String> reasonLines = new ArrayList<>();
String reason = punishment.GetReason();
while (reason.length() > 0)
{
int index = Math.min(reason.length(), 24);
while (index < reason.length() && reason.charAt(index) != ' ')
{
index++;
}
reasonLines.add(reason.substring(0, index));
reason = reason.substring(index, reason.length());
}
//LORE
List<String> output = new ArrayList<>();
output.add(C.cYellow + "Punishment Type: " + ChatColor.RESET + punishment.GetCategory().toString());
if (punishmentEntry.getKey() == Category.ChatOffense ||
punishmentEntry.getKey() == Category.Exploiting ||
punishmentEntry.getKey() == Category.Hacking)
{
output.add(C.cYellow + "Severity: " + ChatColor.RESET + punishment.GetSeverity());
}
output.add(" ");
for (int i=0 ; i<reasonLines.size() ; i++)
{
if (i == 0)
{
output.add(C.cYellow + "Reason: " + ChatColor.RESET + reasonLines.get(i));
}
else
{
output.add(C.cYellow + " " + ChatColor.RESET + reasonLines.get(i));
}
}
output.add(" ");
output.add(C.cYellow + "Staff: " + ChatColor.RESET + punishment.GetAdmin());
output.add(" ");
output.add(C.cYellow + "Date: " + ChatColor.RESET + UtilTime.when(punishment.GetTime()));
if (punishment.GetRemoved())
{
output.add(" ");
output.add(C.cYellow + "Removed by: " + (punishment.GetRemoved() ? ChatColor.RESET + punishment.GetRemoveAdmin() : ChatColor.RED + "Not Removed"));
output.add(C.cYellow + "Remove Reason: " + (punishment.GetRemoved() ? ChatColor.RESET + punishment.GetRemoveReason() : ChatColor.RED + "Not Removed"));
}
String[] loreString = new String[output.size()];
for (int i=0 ; i<output.size() ; i++)
{
loreString[i] = output.get(i);
}
button.SetLore(loreString);
if ((punishment.GetHours() == -1 || punishment.GetRemaining() > 0) && !punishment.GetRemoved() && punishment.GetActive())
{
button.addUnsafeEnchantment(Enchantment.DURABILITY, 1);
AddButton(slot, button, new RemovePunishmentButton(this, punishment, button));
}
else
{
getInventory().setItem(slot, button.getHandle());
}
slot++;
addItem(slot, itemStack);
}
}
@EventHandler
public void OnInventoryClick(InventoryClickEvent event)
{
if (inventory.getName().equalsIgnoreCase(event.getInventory().getTitle()) && event.getWhoClicked() == _player)
{
if (_buttonMap.containsKey(event.getRawSlot()))
{
if (event.getWhoClicked() instanceof Player)
{
_buttonMap.get(event.getRawSlot()).onClick(((Player) event.getWhoClicked()), event.getClick());
}
}
event.setCancelled(true);
}
}
@EventHandler
public void OnInventoryClose(InventoryCloseEvent event)
{
if (inventory.getName().equalsIgnoreCase(event.getInventory().getTitle()) && event.getPlayer() == _player)
{
ClosePunish();
}
}
private void AddButton(int slot, ShopItem item, IButton button)
{
getInventory().setItem(slot, item.getHandle());
_buttonMap.put(slot, button);
}
public void AddInfraction(Category category, int severity, boolean ban, long punishTime)
{
_plugin.AddPunishment(_target, category, _reason, _player, severity, ban, punishTime);
_player.closeInventory();
ClosePunish();
}
private void ClosePunish()
{
HandlerList.unregisterAll(this);
}
public void RemovePunishment(final Punishment punishment, final ItemStack item)
{
_plugin.RemovePunishment(punishment, _target, _player, _reason, result ->
{
PunishmentResponse punishResponse = PunishmentResponse.valueOf(result);
if (punishResponse != PunishmentResponse.PunishmentRemoved)
{
_player.sendMessage(F.main(_plugin.getName(), "There was a problem removing the punishment."));
}
else
{
punishment.Remove(_player.getName(), _reason);
_player.closeInventory();
ClosePunish();
}
});
}
public String getDurationString(Category category, int severity, Map<Category, Map<Integer, Integer>> pastOffences)
{
int hours = getDuration(category, severity, pastOffences);
if (hours == -1)
{
return "Permanent";
}
return UtilTime.MakeStr((long)hours * 3600000L);
}
public int getDuration(Category category, int severity, Map<Category, Map<Integer, Integer>> pastOffences)
// nobody knows how or why this works
public int getDuration(Category category, int severity)
{
if (category == Category.ChatOffense)
{
int hours = 0;
if (severity >= 1)
{
hours += calculateTime(2, 2, 48, pastOffences.get(category).get(1), severity != 1);
hours += calculateTime(2, 2, 48, _offenseMap.get(category).get(1), severity != 1);
}
if (severity >= 2)
{
hours += calculateTime(24, 24, 168, pastOffences.get(category).get(2), severity != 2);
hours += calculateTime(24, 24, 168, _offenseMap.get(category).get(2), severity != 2);
}
if (severity >= 3)
{
hours += calculateTime(720, 720, 720, pastOffences.get(category).get(3), severity != 3);
hours += calculateTime(720, 720, 720, _offenseMap.get(category).get(3), severity != 3);
}
return hours;
return hours;
}
if (category == Category.Exploiting)
{
int hours = 0;
if (severity >= 1)
{
hours += calculateTime(4, 4, 96, pastOffences.get(category).get(1), severity != 1);
hours += calculateTime(4, 4, 96, _offenseMap.get(category).get(1), severity != 1);
}
if (severity >= 2)
{
hours += calculateTime(48, 48, 336, pastOffences.get(category).get(2), severity != 2);
hours += calculateTime(48, 48, 336, _offenseMap.get(category).get(2), severity != 2);
}
if (severity >= 3)
{
return -1;
}
return hours;
return hours;
}
if (category == Category.Hacking)
{
int hours = 0;
if (severity >= 1)
{
hours += calculateTime(24, 24, 168, pastOffences.get(category).get(1), severity != 1);
hours += calculateTime(24, 24, 168, _offenseMap.get(category).get(1), severity != 1);
}
if (severity >= 2)
{
if (pastOffences.get(category).get(2) > 1)
if (_offenseMap.get(category).get(2) > 1)
{
hours = 960;
}
else
} else
{
hours = 720;
}
@ -583,32 +243,115 @@ public class PunishPage extends CraftInventoryCustom implements Listener
{
hours = 960;
}
return hours;
return hours;
}
if (category == Category.Other || category == Category.PermMute || category == Category.ReportAbuse)
{
return -1;
}
return 0;
}
private int calculateTime(int baseAmount, int addAmount, int pastLimit, int offenses, boolean zeroBase)
protected int calculateTime(int baseAmount, int addAmount, int pastLimit, int offenses, boolean zeroBase)
{
int amount = 0;
if (zeroBase)
{
baseAmount = 0;
}
// At what point does Bonus > pastLimit
int breakLimitCount = 0;
int breakLimitCount = 0;
while (baseAmount + addAmount * breakLimitCount * breakLimitCount < pastLimit)
{
breakLimitCount++;
}
amount += Math.min(baseAmount + addAmount * offenses * offenses, pastLimit);
amount += Math.max(0, (offenses - breakLimitCount) * pastLimit);
return amount;
}
protected void doPunishment(Category category, int severity, long length)
{
getPlugin().AddPunishment(_target, category, _reason, getPlayer(), severity, category.isBan(), length);
getPlayer().closeInventory();
}
protected void doPunishment(Category category, int severity)
{
doPunishment(category, severity, getDuration(category, severity));
}
protected void reapplyPunishment(Punishment punishment)
{
if (punishment.GetRemaining() == 0)
{
return;
}
_reason = punishment.GetReason() + " - Reapplied";
if (punishment.GetRemaining() == -1)
{
doPunishment(punishment.GetCategory(), punishment.GetSeverity(), -1);
}
else
{
doPunishment(punishment.GetCategory(), punishment.GetSeverity(), (long) Math.floor(punishment.GetRemaining() / UtilTime.TimeUnit.HOURS.getMilliseconds()));
}
}
protected void removePunishment(Punishment punishment)
{
getPlugin().RemovePunishment(punishment, _target, getPlayer(), _reason, result ->
{
PunishmentResponse punishResponse = PunishmentResponse.valueOf(result);
if (punishResponse != PunishmentResponse.PunishmentRemoved)
{
getPlayer().sendMessage(F.main(_plugin.getName(), "There was a problem removing the punishment."));
}
else
{
punishment.Remove(getPlayer().getName(), _reason);
getPlayer().closeInventory();
}
});
}
protected void processOffenses()
{
PunishClient client = getPlugin().GetClient(_target);
for (Category category : Category.values())
{
_offenseMap.put(category, new HashMap<>());
_offenseMap.get(category).put(1, 0);
_offenseMap.get(category).put(2, 0);
_offenseMap.get(category).put(3, 0);
}
for (Category category : client.GetPunishments().keySet())
{
for (Punishment punishment : client.GetPunishments().get(category))
{
_pastPunishments.add(punishment);
//Count by Severity
if (!punishment.GetRemoved() && punishment.GetSeverity() > 0 && punishment.GetSeverity() < 4)
{
_offenseMap.get(category).put(punishment.GetSeverity(), 1 + _offenseMap.get(category).get(punishment.GetSeverity()));
}
}
}
_pastPunishments.sort((a, b) -> Long.compare(b.GetTime(), a.GetTime()));
}
}