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
1 changed files with 62 additions and 38 deletions

View File

@ -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<Punish, PunishShop>
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<Punish, PunishShop>
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<Punish, PunishShop>
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<Punish, PunishShop>
return;
}
getShop().openPageForPlayer(getPlayer(), new ConfirmationPage<Punish, PunishShop>(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<Punish, PunishShop>(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<Punish, PunishShop>
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<Punish, PunishShop>
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()));
}
}
}