Passed
Push — main ( b981dd...7422f7 )
by Etienne
01:33
created

de.kleiner3.lasertag.lasertaggame.management.blocktick.LasertagBlockTickManager   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 14
c 1
b 0
f 0
dl 0
loc 24
rs 10
wmc 5

5 Methods

Rating   Name   Duplication   Size   Complexity  
A tick() 0 2 1
A registerTicker(LasertagCustomBlockTickable) 0 2 1
A LasertagBlockTickManager(MinecraftServer) 0 3 1
A clear() 0 2 1
A dispose() 0 2 1
1
package de.kleiner3.lasertag.lasertaggame.management.blocktick;
2
3
import de.kleiner3.lasertag.block.entity.LasertagCustomBlockTickable;
4
import de.kleiner3.lasertag.lasertaggame.management.IManager;
5
import net.minecraft.server.MinecraftServer;
6
7
import java.util.ArrayList;
8
import java.util.List;
9
10
/**
11
 * Manages the custom lasertag block ticks. This a workaround for the weird behaviour observed when reloading the arena.
12
 *
13
 * @author Étienne Muser
14
 */
15
public class LasertagBlockTickManager implements IManager {
16
17
    private final List<LasertagCustomBlockTickable> blockEntityTickers;
18
    private final MinecraftServer server;
19
20
    public LasertagBlockTickManager(MinecraftServer server) {
21
        this.blockEntityTickers = new ArrayList<>();
22
        this.server = server;
23
    }
24
25
    public void registerTicker(LasertagCustomBlockTickable ticker) {
26
        blockEntityTickers.add(ticker);
27
    }
28
29
    public void clear() {
30
        this.blockEntityTickers.clear();
31
    }
32
33
    public void tick() {
34
        blockEntityTickers.forEach(ticker -> ticker.serverTick(this.server.getOverworld()));
35
    }
36
37
    @Override
38
    public void dispose() {
39
        // Nothing to dispose
40
    }
41
}
42