Passed
Push — main ( 06eb13...1446ae )
by Etienne
01:33
created

de.kleiner3.lasertag.mixin.MinecraftServerMixin   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Importance

Changes 8
Bugs 0 Features 0
Metric Value
eloc 17
c 8
b 0
f 0
dl 0
loc 41
rs 10
wmc 3

5 Methods

Rating   Name   Duplication   Size   Complexity  
A atShutdown(CallbackInfo) 0 8 1
getOverworld() 0 2 ?
A init(CallbackInfo) 0 4 1
getPlayerManager() 0 2 ?
A getLasertagServerManager() 0 3 1
1
package de.kleiner3.lasertag.mixin;
2
3
import de.kleiner3.lasertag.lasertaggame.ILasertagServerManagerAccessor;
4
import de.kleiner3.lasertag.lasertaggame.management.LasertagGameManager;
5
import de.kleiner3.lasertag.lasertaggame.management.LasertagServerManager;
6
import net.minecraft.server.MinecraftServer;
7
import net.minecraft.server.PlayerManager;
8
import net.minecraft.server.world.ServerWorld;
9
import org.spongepowered.asm.mixin.Mixin;
10
import org.spongepowered.asm.mixin.Shadow;
11
import org.spongepowered.asm.mixin.injection.At;
12
import org.spongepowered.asm.mixin.injection.Inject;
13
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
14
15
/**
16
 * Interface injection into MinecraftServer to implement the lasertag game
17
 *
18
 * @author Étienne Muser
19
 */
20
@Mixin(MinecraftServer.class)
21
public abstract class MinecraftServerMixin implements ILasertagServerManagerAccessor {
22
23
    private LasertagServerManager lasertagServerManager;
24
25
    @Shadow
26
    public abstract PlayerManager getPlayerManager();
27
28
    @Shadow
29
    public abstract ServerWorld getOverworld();
30
31
    /**
32
     * Inject into constructor of MinecraftServer
33
     *
34
     * @param ci The CallbackInfo
35
     */
36
    @Inject(method = "<init>", at = @At("TAIL"))
37
    private void init(CallbackInfo ci) {
38
39
        lasertagServerManager = new LasertagServerManager((MinecraftServer) (Object) this);
40
    }
41
42
    /**
43
     * Inject into the stop method of the minecraft server.
44
     * This method gets called after entering the /stop command or typing stop into the server console.
45
     *
46
     * @param ci
47
     */
48
    @Inject(method = "shutdown", at = @At("HEAD"))
49
    private void atShutdown(CallbackInfo ci) {
50
51
        // Stop the lasertag game
52
        lasertagServerManager.stopLasertagGame();
53
54
        // Dispose the game managers
55
        LasertagGameManager.getInstance().dispose();
56
    }
57
58
    @Override
59
    public LasertagServerManager getLasertagServerManager() {
60
        return lasertagServerManager;
61
    }
62
}