Throw an event when we change a prisoner's time.
This commit is contained in:
parent
96cb530add
commit
196b7c33ed
@ -11,6 +11,7 @@ import com.graywolf336.jail.beans.Jail;
|
|||||||
import com.graywolf336.jail.beans.Prisoner;
|
import com.graywolf336.jail.beans.Prisoner;
|
||||||
import com.graywolf336.jail.enums.Lang;
|
import com.graywolf336.jail.enums.Lang;
|
||||||
import com.graywolf336.jail.enums.Settings;
|
import com.graywolf336.jail.enums.Settings;
|
||||||
|
import com.graywolf336.jail.events.PrisonerTimeChangeEvent;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Contains all the logic for counting down the time of the prisoners time.
|
* Contains all the logic for counting down the time of the prisoners time.
|
||||||
@ -82,9 +83,18 @@ public class JailTimer {
|
|||||||
//while the prisoner is offline, then let's do it
|
//while the prisoner is offline, then let's do it
|
||||||
if(pl.getConfig().getBoolean(Settings.COUNTDOWNTIMEOFFLINE.getPath())) {
|
if(pl.getConfig().getBoolean(Settings.COUNTDOWNTIMEOFFLINE.getPath())) {
|
||||||
//Set their remaining time but if it is less than zero, set it to zero
|
//Set their remaining time but if it is less than zero, set it to zero
|
||||||
p.setRemainingTime(Math.max(0, p.getRemainingTime() - timePassed));
|
long before = p.getRemainingTime();
|
||||||
|
long after = Math.max(0, p.getRemainingTime() - timePassed);
|
||||||
|
|
||||||
|
PrisonerTimeChangeEvent event = new PrisonerTimeChangeEvent(j, j.getCellPrisonerIsIn(p.getUUID()), p, player, before, after);
|
||||||
|
pl.getServer().getPluginManager().callEvent(event);
|
||||||
|
|
||||||
|
if(!event.isCancelled()) {
|
||||||
|
after = event.getTimeAfterChange();
|
||||||
|
p.setRemainingTime(after);
|
||||||
if(p.getRemainingTime() == 0) pl.getPrisonerManager().schedulePrisonerRelease(p);
|
if(p.getRemainingTime() == 0) pl.getPrisonerManager().schedulePrisonerRelease(p);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}else {
|
}else {
|
||||||
if(afkTime > 0) {
|
if(afkTime > 0) {
|
||||||
p.setAFKTime(p.getAFKTime() + timePassed);
|
p.setAFKTime(p.getAFKTime() + timePassed);
|
||||||
@ -103,7 +113,15 @@ public class JailTimer {
|
|||||||
|
|
||||||
//The prisoner isn't offline, so let's count down
|
//The prisoner isn't offline, so let's count down
|
||||||
//Set their remaining time but if it is less than zero, set it to zero
|
//Set their remaining time but if it is less than zero, set it to zero
|
||||||
p.setRemainingTime(Math.max(0, p.getRemainingTime() - timePassed));
|
long before = p.getRemainingTime();
|
||||||
|
long after = Math.max(0, p.getRemainingTime() - timePassed);
|
||||||
|
|
||||||
|
PrisonerTimeChangeEvent event = new PrisonerTimeChangeEvent(j, j.getCellPrisonerIsIn(p.getUUID()), p, player, before, after);
|
||||||
|
pl.getServer().getPluginManager().callEvent(event);
|
||||||
|
|
||||||
|
if(!event.isCancelled()) {
|
||||||
|
after = event.getTimeAfterChange();
|
||||||
|
p.setRemainingTime(after);
|
||||||
if(p.getRemainingTime() == 0) pl.getPrisonerManager().schedulePrisonerRelease(p);
|
if(p.getRemainingTime() == 0) pl.getPrisonerManager().schedulePrisonerRelease(p);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -111,4 +129,5 @@ public class JailTimer {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -66,6 +66,11 @@ public class PrePrisonerJailedByJailStickEvent extends Event implements Cancella
|
|||||||
this.cell = cell;
|
this.cell = cell;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Checks if there is a cell involved. */
|
||||||
|
public boolean hasCell() {
|
||||||
|
return this.cell != null;
|
||||||
|
}
|
||||||
|
|
||||||
/** Gets the {@link Prisoner} data for this prisoner. */
|
/** Gets the {@link Prisoner} data for this prisoner. */
|
||||||
public Prisoner getPrisoner() {
|
public Prisoner getPrisoner() {
|
||||||
return this.prisoner;
|
return this.prisoner;
|
||||||
|
@ -65,6 +65,11 @@ public class PrePrisonerJailedEvent extends Event implements Cancellable {
|
|||||||
this.cell = cell;
|
this.cell = cell;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Checks if there is a cell involved. */
|
||||||
|
public boolean hasCell() {
|
||||||
|
return this.cell != null;
|
||||||
|
}
|
||||||
|
|
||||||
/** Gets the {@link Prisoner} data for this prisoner. */
|
/** Gets the {@link Prisoner} data for this prisoner. */
|
||||||
public Prisoner getPrisoner() {
|
public Prisoner getPrisoner() {
|
||||||
return this.prisoner;
|
return this.prisoner;
|
||||||
|
@ -53,6 +53,11 @@ public class PrePrisonerReleasedEvent extends Event {
|
|||||||
return this.cell;
|
return this.cell;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Checks if there is a cell involved. */
|
||||||
|
public boolean hasCell() {
|
||||||
|
return this.cell != null;
|
||||||
|
}
|
||||||
|
|
||||||
/** Gets the {@link Prisoner} data for this prisoner. */
|
/** Gets the {@link Prisoner} data for this prisoner. */
|
||||||
public Prisoner getPrisoner() {
|
public Prisoner getPrisoner() {
|
||||||
return this.prisoner;
|
return this.prisoner;
|
||||||
|
@ -61,6 +61,11 @@ public class PrePrisonerTransferredEvent extends Event implements Cancellable {
|
|||||||
return this.originalCell;
|
return this.originalCell;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Checks if there is an original cell involved. */
|
||||||
|
public boolean hasOriginalCell() {
|
||||||
|
return this.originalCell != null;
|
||||||
|
}
|
||||||
|
|
||||||
/** Gets the {@link Jail} this prisoner is being transferred to. */
|
/** Gets the {@link Jail} this prisoner is being transferred to. */
|
||||||
public Jail getTargetJail() {
|
public Jail getTargetJail() {
|
||||||
return this.targetJail;
|
return this.targetJail;
|
||||||
@ -84,6 +89,11 @@ public class PrePrisonerTransferredEvent extends Event implements Cancellable {
|
|||||||
else return null;
|
else return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Checks if there is a target cell involved. */
|
||||||
|
public boolean hasTargetCell() {
|
||||||
|
return this.getTargetCell() != null;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the target {@link Cell} this prisoner is being sent to.
|
* Sets the target {@link Cell} this prisoner is being sent to.
|
||||||
*
|
*
|
||||||
|
@ -56,6 +56,11 @@ public class PrisonerDeathEvent extends Event {
|
|||||||
return this.cell;
|
return this.cell;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Checks if there is a cell involved. */
|
||||||
|
public boolean hasCell() {
|
||||||
|
return this.cell != null;
|
||||||
|
}
|
||||||
|
|
||||||
/** Gets the {@link Prisoner}'s data. */
|
/** Gets the {@link Prisoner}'s data. */
|
||||||
public Prisoner getPrisoner() {
|
public Prisoner getPrisoner() {
|
||||||
return this.prisoner;
|
return this.prisoner;
|
||||||
|
@ -53,6 +53,11 @@ public class PrisonerJailedEvent extends Event {
|
|||||||
return this.cell;
|
return this.cell;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Checks if there was a cell involved. */
|
||||||
|
public boolean hasCell() {
|
||||||
|
return this.cell != null;
|
||||||
|
}
|
||||||
|
|
||||||
/** Gets the {@link Prisoner} data for this prisoner. */
|
/** Gets the {@link Prisoner} data for this prisoner. */
|
||||||
public Prisoner getPrisoner() {
|
public Prisoner getPrisoner() {
|
||||||
return this.prisoner;
|
return this.prisoner;
|
||||||
|
@ -53,6 +53,11 @@ public class PrisonerReleasedEvent extends Event {
|
|||||||
return this.cell;
|
return this.cell;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Checks if there was a cell involved. */
|
||||||
|
public boolean hasCell() {
|
||||||
|
return this.cell != null;
|
||||||
|
}
|
||||||
|
|
||||||
/** Gets the {@link Prisoner} data for this prisoner. */
|
/** Gets the {@link Prisoner} data for this prisoner. */
|
||||||
public Prisoner getPrisoner() {
|
public Prisoner getPrisoner() {
|
||||||
return this.prisoner;
|
return this.prisoner;
|
||||||
|
@ -0,0 +1,119 @@
|
|||||||
|
package com.graywolf336.jail.events;
|
||||||
|
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.event.Cancellable;
|
||||||
|
import org.bukkit.event.Event;
|
||||||
|
import org.bukkit.event.HandlerList;
|
||||||
|
|
||||||
|
import com.graywolf336.jail.beans.Cell;
|
||||||
|
import com.graywolf336.jail.beans.Jail;
|
||||||
|
import com.graywolf336.jail.beans.Prisoner;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Event thrown when a prisoner's time changes.
|
||||||
|
*
|
||||||
|
* @author graywolf336
|
||||||
|
* @since 3.0.0
|
||||||
|
* @version 1.0.0
|
||||||
|
*/
|
||||||
|
public class PrisonerTimeChangeEvent extends Event implements Cancellable {
|
||||||
|
private static final HandlerList handlers = new HandlerList();
|
||||||
|
private boolean cancelled = false;
|
||||||
|
private Jail jail;
|
||||||
|
private Cell cell;
|
||||||
|
private Prisoner prisoner;
|
||||||
|
private Player player;
|
||||||
|
private long before, after;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new {@link PrisonerTimeChangeEvent prisoner time change event} for the given prisoner.
|
||||||
|
*
|
||||||
|
* @param jail The jail the prisoner is in.
|
||||||
|
* @param cell The cell the prisoner is in, can be null.
|
||||||
|
* @param prisoner The prisoner's data.
|
||||||
|
* @param player The player being jailed.
|
||||||
|
* @param before the time before it changed
|
||||||
|
* @param after the time after it changed
|
||||||
|
*/
|
||||||
|
public PrisonerTimeChangeEvent(Jail jail, Cell cell, Prisoner prisoner, Player player, long before, long after) {
|
||||||
|
this.jail = jail;
|
||||||
|
this.cell = cell;
|
||||||
|
this.prisoner = prisoner;
|
||||||
|
this.player = player;
|
||||||
|
this.before = before;
|
||||||
|
this.after = after;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Gets the {@link Jail} this prisoner is in. */
|
||||||
|
public Jail getJail() {
|
||||||
|
return this.jail;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Gets the cell the prisoner is in, can be null. */
|
||||||
|
public Cell getCell() {
|
||||||
|
return this.cell;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Checks if there is a cell involved. */
|
||||||
|
public boolean hasCell() {
|
||||||
|
return this.cell != null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Gets the {@link Prisoner}'s data. */
|
||||||
|
public Prisoner getPrisoner() {
|
||||||
|
return this.prisoner;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Gets the instance of the player who died. */
|
||||||
|
public Player getPlayer() {
|
||||||
|
return this.player;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Gets the time the prisoner had before it changed. */
|
||||||
|
public long getTimeBeforeChange() {
|
||||||
|
return this.before;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Gets the time the prisoner will have after the change. */
|
||||||
|
public long getTimeAfterChange() {
|
||||||
|
return this.after;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Sets the time the prisoner will have after the change. */
|
||||||
|
public void setTimeAfterChange(long newtime) {
|
||||||
|
this.after = Math.max(0, newtime);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the difference the change is making.
|
||||||
|
*
|
||||||
|
* <p />
|
||||||
|
*
|
||||||
|
* The change can be positive or negative. If it is positive then the
|
||||||
|
* time after is smaller than it was before. If it is negative then the
|
||||||
|
* time after is larger than it was before.
|
||||||
|
*
|
||||||
|
* @return The difference between the two time changes.
|
||||||
|
*/
|
||||||
|
public long getTimeDifference() {
|
||||||
|
return this.before - this.after;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Checks whether this event is cancelled or not. */
|
||||||
|
public boolean isCancelled() {
|
||||||
|
return this.cancelled;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Sets whether this event should be cancelled. */
|
||||||
|
public void setCancelled(boolean cancel) {
|
||||||
|
this.cancelled = cancel;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static HandlerList getHandlerList() {
|
||||||
|
return handlers;
|
||||||
|
}
|
||||||
|
|
||||||
|
public HandlerList getHandlers() {
|
||||||
|
return handlers;
|
||||||
|
}
|
||||||
|
}
|
@ -55,6 +55,11 @@ public class PrisonerTransferredEvent extends Event {
|
|||||||
return this.originalCell;
|
return this.originalCell;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Checks if there was an original cell involved. */
|
||||||
|
public boolean hasOriginalCell() {
|
||||||
|
return this.originalCell != null;
|
||||||
|
}
|
||||||
|
|
||||||
/** Gets the {@link Jail} this prisoner is being transferred to. */
|
/** Gets the {@link Jail} this prisoner is being transferred to. */
|
||||||
public Jail getTargetJail() {
|
public Jail getTargetJail() {
|
||||||
return this.targetJail;
|
return this.targetJail;
|
||||||
@ -69,6 +74,11 @@ public class PrisonerTransferredEvent extends Event {
|
|||||||
else return null;
|
else return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Checks if there was a target cell involved. */
|
||||||
|
public boolean hasTargetCell() {
|
||||||
|
return this.getTargetCell() != null;
|
||||||
|
}
|
||||||
|
|
||||||
/** Gets the {@link Prisoner} data for this prisoner. */
|
/** Gets the {@link Prisoner} data for this prisoner. */
|
||||||
public Prisoner getPrisoner() {
|
public Prisoner getPrisoner() {
|
||||||
return this.prisoner;
|
return this.prisoner;
|
||||||
|
Loading…
Reference in New Issue
Block a user