2019-11-25 06:29:25 +00:00
|
|
|
package com.burnedkirby.TurnBasedMinecraft.common;
|
2018-08-28 06:13:14 +00:00
|
|
|
|
2019-10-25 07:42:54 +00:00
|
|
|
|
|
|
|
import net.minecraftforge.event.TickEvent;
|
|
|
|
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
|
|
|
|
2018-09-20 06:15:34 +00:00
|
|
|
import java.util.concurrent.atomic.AtomicBoolean;
|
2018-09-06 08:08:36 +00:00
|
|
|
|
2019-10-25 07:42:54 +00:00
|
|
|
public class BattleUpdater
|
2018-08-28 06:13:14 +00:00
|
|
|
{
|
2018-08-29 06:09:44 +00:00
|
|
|
private BattleManager manager;
|
2018-09-20 06:15:34 +00:00
|
|
|
private AtomicBoolean isRunning;
|
2019-10-25 07:42:54 +00:00
|
|
|
private int tick;
|
|
|
|
private final int tickLimit = 10;
|
2018-10-18 07:26:09 +00:00
|
|
|
|
2018-08-28 06:13:14 +00:00
|
|
|
public BattleUpdater(BattleManager manager)
|
|
|
|
{
|
|
|
|
this.manager = manager;
|
2018-09-20 06:15:34 +00:00
|
|
|
isRunning = new AtomicBoolean(true);
|
2019-10-25 07:42:54 +00:00
|
|
|
tick = 0;
|
2018-08-28 06:13:14 +00:00
|
|
|
}
|
|
|
|
|
2019-10-25 07:42:54 +00:00
|
|
|
public void setRunning(boolean isRunning) {
|
|
|
|
this.isRunning.set(isRunning);
|
|
|
|
}
|
|
|
|
|
|
|
|
@SubscribeEvent
|
|
|
|
public void update(TickEvent.ServerTickEvent tickEvent) {
|
|
|
|
if(tickEvent.phase != TickEvent.Phase.START && isRunning.get() && ++tick > tickLimit) {
|
|
|
|
tick = 0;
|
|
|
|
manager.battleMap.entrySet().removeIf(entry -> entry.getValue().update());
|
2018-10-17 09:28:47 +00:00
|
|
|
manager.updateRecentlyLeftBattle();
|
2018-08-28 06:13:14 +00:00
|
|
|
}
|
2018-08-29 06:09:44 +00:00
|
|
|
}
|
2018-08-28 06:13:14 +00:00
|
|
|
}
|