diff --git a/Plugins/Mineplex.Core/src/mineplex/core/punish/UI/PunishPage.java b/Plugins/Mineplex.Core/src/mineplex/core/punish/UI/PunishPage.java index cc43ff8b6..3f0c3925c 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/punish/UI/PunishPage.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/punish/UI/PunishPage.java @@ -20,6 +20,7 @@ import mineplex.core.common.util.LineFormat; import mineplex.core.common.util.UtilText; import mineplex.core.common.util.UtilTime; import mineplex.core.donation.DonationManager; +import mineplex.core.itemstack.ItemBuilder; import mineplex.core.punish.Category; import mineplex.core.punish.Punish; import mineplex.core.punish.PunishClient; @@ -92,7 +93,7 @@ public abstract class PunishPage extends ShopPageBase if (punishment.GetHours() > 0) { lore.add(""); - lore.add(C.Reset + "Expires On: " + C.cYellow + UtilTime.when(punishment.GetTime() + punishment.GetRemaining())); + lore.add(C.Reset + "Expires On: " + C.cYellow + UtilTime.when(System.currentTimeMillis() + punishment.GetRemaining())); lore.add(C.cYellow + "(" + Punish.getDurationString(punishment.GetRemaining() / UtilTime.TimeUnit.HOURS.getMilliseconds()) + ")"); } } @@ -112,6 +113,36 @@ public abstract class PunishPage extends ShopPageBase return itemStack; } + private boolean canBeReapplied(Punishment punishment) + { + if (!_client.hasPermission(Punish.Perm.PUNISHMENT_REAPPLY)) + { + return false; + } + + if (punishment.GetActive()) + { + return false; + } + + if (!punishment.GetRemoved()) + { + return false; + } + + if (punishment.GetHours() == -1) + { + return true; + } + + if (punishment.GetRemaining() > 0) + { + return true; + } + + return false; + } + protected void addHistoryItem(int slot, Punishment punishment) { ItemStack itemStack = buildHistoryItem(punishment); @@ -123,7 +154,7 @@ public abstract class PunishPage extends ShopPageBase return; } - if ((punishment.GetHours() == -1 || punishment.GetRemaining() > 0) && !punishment.GetRemoved() && punishment.GetActive()) + if ((punishment.GetHours() < 0 || punishment.GetRemaining() > 0) && !punishment.GetRemoved() && punishment.GetActive()) { addButton(slot, itemStack, (p, c) -> { if (getPlugin().GetClients().Get(getPlayer()).hasPermission(Punish.Perm.BYPASS_REMOVE_CONFIRMATION)) @@ -132,46 +163,37 @@ public abstract class PunishPage extends ShopPageBase return; } - getShop().openPageForPlayer(getPlayer(), new ConfirmationPage(getPlayer(), this, new ConfirmationProcessor() + getShop().openPageForPlayer(getPlayer(), new ConfirmationPage<>(getPlayer(), this, new ConfirmationProcessor() { @Override - public void init(Inventory inventory) - { - - } + public void init(Inventory inventory) {} @Override public void process(ConfirmationCallback callback) { removePunishment(punishment); + callback.resolve("Successfully removed 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()) + else if (canBeReapplied(punishment)) { - addButton(slot, itemStack, (p, c)-> - { - getShop().openPageForPlayer(getPlayer(), new ConfirmationPage(getPlayer(), this, new ConfirmationProcessor() - { - @Override - public void init(Inventory inventory) - { + ItemStack reapplyItem = new ItemBuilder(itemStack).addLore("", C.cGreen + "Click to reapply punishment").build(); - } - - @Override - public void process(ConfirmationCallback callback) + addButton(slot, reapplyItem, (p, c)-> + getShop().openPageForPlayer(getPlayer(), new ConfirmationPage<>(getPlayer(), this, new ConfirmationProcessor() { - reapplyPunishment(punishment); - } - }, itemStack, "Confirm Punishment Reapply")); - }); + @Override + public void init(Inventory inventory) {} + + @Override + public void process(ConfirmationCallback callback) + { + reapplyPunishment(punishment); + callback.resolve("Successfully reapplied punishment."); + } + }, itemStack, "Confirm Punishment Reapply"))); } else { @@ -291,7 +313,7 @@ public abstract class PunishPage extends ShopPageBase protected void reapplyPunishment(Punishment punishment) { - if (punishment.GetRemaining() == 0 || punishment.GetActive() || !punishment.GetRemoved()) + if (!canBeReapplied(punishment)) { return; } @@ -299,17 +321,19 @@ public abstract class PunishPage extends ShopPageBase Bukkit.broadcastMessage("Remaining: " + punishment.GetRemaining()); Bukkit.broadcastMessage("In hours: " + (long) Math.floor(punishment.GetRemaining() / UtilTime.TimeUnit.HOURS.getMilliseconds())); Bukkit.broadcastMessage("Is permanent: " + ((punishment.GetRemaining() < 0) ? "yes" : "no")); - return; - _reason = punishment.GetReason() + " - Reapplied"; + if ('c' != 'c') + { + _reason = punishment.GetReason() + " - Reapplied"; - if (punishment.GetRemaining() < 0) - { - doPunishment(punishment.GetCategory(), punishment.GetSeverity(), -1); - } - else - { - doPunishment(punishment.GetCategory(), punishment.GetSeverity(), (long) Math.floor(punishment.GetRemaining() / UtilTime.TimeUnit.HOURS.getMilliseconds())); + 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())); + } } }