goauth

Fabric plugin for enhanced whitelists
git clone git://git.bain.cz/goauth.git
Log | Files | Refs | README | LICENSE

OnServerTickListener.java (2291B)


      1 package cz.bain.plugins.goauth.events.listeners;
      2 
      3 import cz.bain.plugins.goauth.Goauth;
      4 import cz.bain.plugins.goauth.AuthUpdate;
      5 import cz.bain.plugins.goauth.StringRepository;
      6 import cz.bain.plugins.goauth.events.callbacks.OnServerTickCallback;
      7 import net.minecraft.network.packet.s2c.play.PlayerRespawnS2CPacket;
      8 import net.minecraft.server.PlayerManager;
      9 import net.minecraft.server.network.ServerPlayerEntity;
     10 import net.minecraft.text.Text;
     11 import net.minecraft.util.ActionResult;
     12 
     13 public class OnServerTickListener implements OnServerTickCallback {
     14 
     15     private final Goauth plugin;
     16 
     17     public OnServerTickListener(Goauth plugin) {
     18         this.plugin = plugin;
     19     }
     20 
     21     @Override
     22     public ActionResult interact(PlayerManager playerManager, long ticks) {
     23         if (ticks % 20 == 0) {
     24             synchronized (this.plugin.completed) {
     25                 for (AuthUpdate update : this.plugin.completed) {
     26                     switch (update.getType()) {
     27                         case UPDATE -> {
     28                             ServerPlayerEntity player = this.plugin.playersLimbo.get(update.getUsername());
     29                             if (player == null) {
     30                                 this.plugin.logger.info("Cannot authenticate an offline player! {}", update.getUsername());
     31                                 continue;
     32                             }
     33                             this.plugin.authStore.put(player);
     34                             player.networkHandler.disconnect(Text.of(StringRepository.limboRemoveDisconnect));
     35                         }
     36                         case REMOVE -> {
     37                             if (this.plugin.authStore.remove(update.getUsername())) {
     38                                 this.plugin.logger.info("Removed " + update.getUsername() + " from authentication db");
     39                                 ServerPlayerEntity player = playerManager.getPlayer(update.getUsername());
     40                                 if (player != null)
     41                                     player.networkHandler.disconnect(Text.of(StringRepository.playerUnregisterKick));
     42                             }
     43                         }
     44                     }
     45                 }
     46                 this.plugin.completed.clear();
     47             }
     48         }
     49         return ActionResult.PASS;
     50     }
     51 }