Lucasdesigner

MinesManager.java

Oct 16th, 2021
947
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package net.sf.l2j.gameserver.custom.events.mines;
  2.  
  3. import net.sf.l2j.commons.concurrent.ThreadPool;
  4. import net.sf.l2j.gameserver.model.WorldObject;
  5. import net.sf.l2j.gameserver.model.actor.instance.Player;
  6. import net.sf.l2j.gameserver.util.Broadcast;
  7.  
  8. import java.util.Map;
  9. import java.util.concurrent.ConcurrentHashMap;
  10. import java.util.concurrent.Future;
  11. import java.util.logging.Logger;
  12.  
  13. public class MinesManager {
  14.     private static final Logger _log = Logger.getLogger(WorldObject.class.getName());
  15.     protected int _countdown = 120;
  16.     protected Future<?> _startTask = null;
  17.     protected boolean _started = false;
  18.     private final Map<Integer, Mines> _mineGame = new ConcurrentHashMap<>();
  19.  
  20.  
  21.     public static MinesManager getInstance()
  22.     {
  23.         return MinesManager.SingletonHolder._instance;
  24.     }
  25.  
  26.     public MinesManager() {
  27.         _log.info("[Mines] - Enabled.");
  28.     }
  29.  
  30.     public void start(){
  31.         Broadcast.announceToOnlinePlayers("[EVENT] ~ [Mines] type .mines to join.", true);
  32.         _countdown = 30;
  33.         setStarted(true);
  34.         _startTask = ThreadPool.scheduleAtFixedRate(new StartRegistration(), 1000, 1000);
  35.     }
  36.  
  37.     public void stop(){
  38.         if(_startTask != null) {
  39.             Broadcast.announceToOnlinePlayers("[EVENT] ~ [Mines] stopped.", true);
  40.             MinesEvent.getInstance().stop();
  41.             setStarted(false);
  42.             _startTask.cancel(true);
  43.             _startTask = null;
  44.         }
  45.     }
  46.  
  47.     public class StartRegistration implements Runnable
  48.     {
  49.         @Override
  50.         public void run()
  51.         {
  52.             if (_countdown < 0)
  53.             {
  54.                 _startTask.cancel(true);
  55.                 _startTask = null;
  56.             }
  57.  
  58.             switch (_countdown)
  59.             {
  60.                 case 300:
  61.                 case 240:
  62.                 case 120:
  63.                     int tempTimer = _countdown / 60;
  64.                     Broadcast.announceToOnlinePlayers("[EVENT] ~ [Mines] Registration time left ["+tempTimer+"] minute(s)", true);
  65.                     break;
  66.                 case 60:
  67.                     tempTimer = _countdown / 60;
  68.                     Broadcast.announceToOnlinePlayers("[EVENT] ~ [Mines] Registration time left ["+tempTimer+"] minute(s)", true);
  69.                     break;
  70.                 case 30:
  71.                 case 20:
  72.                 case 10:
  73.                 case 5:
  74.                 case 4:
  75.                 case 3:
  76.                 case 2:
  77.                 case 1:
  78.                     Broadcast.announceToOnlinePlayers("[EVENT] ~ [Mines] Registration time left ["+_countdown+"] second(s)", true);
  79.                     break;
  80.                 case 0:
  81.                     Broadcast.announceToOnlinePlayers("[EVENT] ~ [Mines] Registrations closed.", true);
  82.  
  83.                    if(MinesEvent.getInstance().getTotalPlayers() < 1) {
  84.                         Broadcast.announceToOnlinePlayers("[EVENT] ~ [Mines] Cancelled due to luck of participants.", true);
  85.                    }else {
  86.                         MinesEvent.getInstance().start();
  87.                    }
  88.                     setStarted(false);
  89.                     break;
  90.             }
  91.  
  92.             _countdown--;
  93.         }
  94.  
  95.     }
  96.  
  97.     public Mines getMine(int plrObjId)
  98.     {
  99.         return _mineGame.get(plrObjId);
  100.     }
  101.  
  102.     public void addNewMine(Player player, Mines page, int plrObjId)
  103.     {
  104.         if (player == null)
  105.             return;
  106.  
  107.         _mineGame.put(plrObjId, page);
  108.     }
  109.  
  110.     public boolean isStarted() {
  111.  
  112.         return _started;
  113.     }
  114.  
  115.     public boolean setStarted(boolean started) {
  116.         _started = started;
  117.  
  118.         return _started;
  119.     }
  120.  
  121.     private static class SingletonHolder
  122.     {
  123.         protected static final MinesManager _instance = new MinesManager();
  124.     }
  125. }
RAW Paste Data