Fix punish expiration, and possibly invalid reapply times

This commit is contained in:
ArcticZeroo 2018-01-09 20:37:29 -05:00 committed by Alexander Meech
parent 4e9ac86e9f
commit 79f0355288

View File

@ -20,6 +20,7 @@ import mineplex.core.common.util.LineFormat;
import mineplex.core.common.util.UtilText; import mineplex.core.common.util.UtilText;
import mineplex.core.common.util.UtilTime; import mineplex.core.common.util.UtilTime;
import mineplex.core.donation.DonationManager; import mineplex.core.donation.DonationManager;
import mineplex.core.itemstack.ItemBuilder;
import mineplex.core.punish.Category; import mineplex.core.punish.Category;
import mineplex.core.punish.Punish; import mineplex.core.punish.Punish;
import mineplex.core.punish.PunishClient; import mineplex.core.punish.PunishClient;
@ -92,7 +93,7 @@ public abstract class PunishPage extends ShopPageBase<Punish, PunishShop>
if (punishment.GetHours() > 0) if (punishment.GetHours() > 0)
{ {
lore.add(""); 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()) + ")"); lore.add(C.cYellow + "(" + Punish.getDurationString(punishment.GetRemaining() / UtilTime.TimeUnit.HOURS.getMilliseconds()) + ")");
} }
} }
@ -112,6 +113,36 @@ public abstract class PunishPage extends ShopPageBase<Punish, PunishShop>
return itemStack; 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) protected void addHistoryItem(int slot, Punishment punishment)
{ {
ItemStack itemStack = buildHistoryItem(punishment); ItemStack itemStack = buildHistoryItem(punishment);
@ -123,7 +154,7 @@ public abstract class PunishPage extends ShopPageBase<Punish, PunishShop>
return; 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) -> { addButton(slot, itemStack, (p, c) -> {
if (getPlugin().GetClients().Get(getPlayer()).hasPermission(Punish.Perm.BYPASS_REMOVE_CONFIRMATION)) if (getPlugin().GetClients().Get(getPlayer()).hasPermission(Punish.Perm.BYPASS_REMOVE_CONFIRMATION))
@ -132,46 +163,37 @@ public abstract class PunishPage extends ShopPageBase<Punish, PunishShop>
return; return;
} }
getShop().openPageForPlayer(getPlayer(), new ConfirmationPage<Punish, PunishShop>(getPlayer(), this, new ConfirmationProcessor() getShop().openPageForPlayer(getPlayer(), new ConfirmationPage<>(getPlayer(), this, new ConfirmationProcessor()
{ {
@Override @Override
public void init(Inventory inventory) public void init(Inventory inventory) {}
{
}
@Override @Override
public void process(ConfirmationCallback callback) public void process(ConfirmationCallback callback)
{ {
removePunishment(punishment); removePunishment(punishment);
callback.resolve("Successfully removed punishment.");
} }
}, itemStack, "Confirm Punishment Removal")); }, itemStack, "Confirm Punishment Removal"));
}); });
} }
else if (getPlugin().GetClients().Get(getPlayer()).hasPermission(Punish.Perm.PUNISHMENT_REAPPLY) else if (canBeReapplied(punishment))
// Punishment must have time remaining,
// be inactive, and removed.
&& punishment.GetRemaining() != 0
&& !punishment.GetActive()
&& punishment.GetRemoved())
{ {
addButton(slot, itemStack, (p, c)-> ItemStack reapplyItem = new ItemBuilder(itemStack).addLore("", C.cGreen + "Click to reapply punishment").build();
{
getShop().openPageForPlayer(getPlayer(), new ConfirmationPage<Punish, PunishShop>(getPlayer(), this, new ConfirmationProcessor() addButton(slot, reapplyItem, (p, c)->
getShop().openPageForPlayer(getPlayer(), new ConfirmationPage<>(getPlayer(), this, new ConfirmationProcessor()
{ {
@Override @Override
public void init(Inventory inventory) public void init(Inventory inventory) {}
{
}
@Override @Override
public void process(ConfirmationCallback callback) public void process(ConfirmationCallback callback)
{ {
reapplyPunishment(punishment); reapplyPunishment(punishment);
callback.resolve("Successfully reapplied punishment.");
} }
}, itemStack, "Confirm Punishment Reapply")); }, itemStack, "Confirm Punishment Reapply")));
});
} }
else else
{ {
@ -291,7 +313,7 @@ public abstract class PunishPage extends ShopPageBase<Punish, PunishShop>
protected void reapplyPunishment(Punishment punishment) protected void reapplyPunishment(Punishment punishment)
{ {
if (punishment.GetRemaining() == 0 || punishment.GetActive() || !punishment.GetRemoved()) if (!canBeReapplied(punishment))
{ {
return; return;
} }
@ -299,11 +321,12 @@ public abstract class PunishPage extends ShopPageBase<Punish, PunishShop>
Bukkit.broadcastMessage("Remaining: " + punishment.GetRemaining()); Bukkit.broadcastMessage("Remaining: " + punishment.GetRemaining());
Bukkit.broadcastMessage("In hours: " + (long) Math.floor(punishment.GetRemaining() / UtilTime.TimeUnit.HOURS.getMilliseconds())); Bukkit.broadcastMessage("In hours: " + (long) Math.floor(punishment.GetRemaining() / UtilTime.TimeUnit.HOURS.getMilliseconds()));
Bukkit.broadcastMessage("Is permanent: " + ((punishment.GetRemaining() < 0) ? "yes" : "no")); Bukkit.broadcastMessage("Is permanent: " + ((punishment.GetRemaining() < 0) ? "yes" : "no"));
return;
if ('c' != 'c')
{
_reason = punishment.GetReason() + " - Reapplied"; _reason = punishment.GetReason() + " - Reapplied";
if (punishment.GetRemaining() < 0) if (punishment.GetRemaining() == -1)
{ {
doPunishment(punishment.GetCategory(), punishment.GetSeverity(), -1); doPunishment(punishment.GetCategory(), punishment.GetSeverity(), -1);
} }
@ -312,6 +335,7 @@ public abstract class PunishPage extends ShopPageBase<Punish, PunishShop>
doPunishment(punishment.GetCategory(), punishment.GetSeverity(), (long) Math.floor(punishment.GetRemaining() / UtilTime.TimeUnit.HOURS.getMilliseconds())); doPunishment(punishment.GetCategory(), punishment.GetSeverity(), (long) Math.floor(punishment.GetRemaining() / UtilTime.TimeUnit.HOURS.getMilliseconds()));
} }
} }
}
protected void removePunishment(Punishment punishment) protected void removePunishment(Punishment punishment)
{ {