Fix formatting in AutoUpdateItem

This commit is contained in:
NichtStudioCode 2022-12-21 13:39:20 +01:00
parent a57c880ef6
commit a53d353535

@ -14,36 +14,35 @@ import java.util.function.Supplier;
* of ticks.
*/
public class AutoUpdateItem extends SuppliedItem {
private final int period;
private BukkitTask task;
public AutoUpdateItem(int period, Supplier<? extends ItemProvider> builderSupplier) {
super(builderSupplier, null);
this.period = period;
}
public void start() {
if (task != null) task.cancel();
task = Bukkit.getScheduler().runTaskTimer(InvUI.getInstance().getPlugin(), this::notifyWindows, 0, period);
}
public void cancel() {
task.cancel();
task = null;
}
@Override
public void addWindow(Window window) {
super.addWindow(window);
if (task == null) start();
}
@Override
public void removeWindow(Window window) {
super.removeWindow(window);
if (getWindows().isEmpty() && task != null) cancel();
}
}