| 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 |  |  | } |