use of pl.themolka.arcade.capture.point.PointCapturedEvent in project Arcade2 by ShootGame.
the class CapturingState method heartbeat.
@Override
public void heartbeat(long ticks, Match match, Multimap<Participator, GamePlayer> competitors, Multimap<Participator, GamePlayer> dominators, List<Participator> canCapture, Participator owner) {
if (!dominators.isEmpty()) {
if (!canCapture.contains(this.capturer)) {
// The dominator has changed.
this.startLosing(this.point, this.capturer, dominators, this.getProgress());
return;
}
if (canCapture.size() == 1) {
// Progress the state if there is only one dominator who can dominate the point.
this.progress();
}
}
if (this.getProgress() >= CAPTURED) {
// The point is captured at 100%.
if (owner != null && owner.equals(this.capturer)) {
return;
}
CapturedState capturedState = this.point.createCapturedState(this);
PointCapturedEvent event = new PointCapturedEvent(this.game.getPlugin(), this.point, this, capturedState, owner, this.capturer);
this.game.getPlugin().getEventBus().publish(event);
if (event.isCanceled()) {
return;
}
PointState newState = event.getNewState();
this.point.setState(newState);
if (newState instanceof CapturedState) {
Participator oldOwner = event.getOldOwner();
Participator newOwner = event.getNewOwner();
if (newOwner != null && (oldOwner == null || !oldOwner.equals(newOwner))) {
this.point.capture(newOwner, null);
}
}
}
}
Aggregations