Advertisement
Guest User

Untitled

a guest
Nov 17th, 2019
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.24 KB | None | 0 0
  1.      package command;
  2.      
  3.      import java.awt.event.ActionEvent;
  4. import java.awt.event.ActionListener;
  5. import java.util.HashMap;
  6. import java.util.Map;
  7. import java.util.Map.Entry;
  8.  
  9. import javax.swing.Timer;
  10.  
  11. import org.Wokama.client.Player;
  12.  
  13. import common.SQLManager;
  14. import common.SocketManager;
  15. import common.World;
  16.      
  17.         public class Reboot
  18.             {
  19.                 private static Map<Player, Boolean> vote = new HashMap<Player,Boolean>();
  20.      
  21.                 public static long lastReboot = 0L;
  22.                 public static boolean wait = false;
  23.                 public static Timer shutdown = null;
  24.                 private Timer reboot;
  25.                 private Player owner;
  26.      
  27.         public Reboot(Player _perso)
  28.             {
  29.                 if (_perso == null) return;
  30.      
  31.                 this.owner = _perso;
  32.                 wait = true;
  33.      
  34.                 this.reboot = createTimer(5);
  35.                 this.reboot.start();
  36.                 SocketManager.GAME_SEND_INBOX_TO_All("Une demande de redémarrage a etait faite par <b>" + _perso.get_name() + "</b> veuillez voter avec la commande .votereboot .");
  37.        }
  38.      
  39.        private Timer redemarrage(int time) {
  40.        ActionListener action = new ActionListener() {
  41.            int Time;
  42.      
  43.        public void actionPerformed(ActionEvent event) { this.Time -= 1;
  44.           if (this.Time == 1)
  45.              SocketManager.GAME_SEND_Im_PACKET_TO_ALL("115;" + this.Time +
  46.                " minute");
  47.              else {
  48.              SocketManager.GAME_SEND_Im_PACKET_TO_ALL("115;" + this.Time +
  49.                " minutes");
  50.              }
  51.            if (this.Time <= 0) {
  52.              SQLManager.LOAD_ACTION();
  53.              SocketManager.SEND_MESSAGE_DECO_ALL(4, "");
  54.              System.exit(0);
  55.              }
  56.            }
  57.          };
  58.        return new Timer(60000, action);
  59.        }
  60.        private Timer createTimer(int time) {
  61.        ActionListener action = new ActionListener() {
  62.            int Time;
  63.      
  64.          public void actionPerformed(ActionEvent event) { this.Time -= 1;
  65.            if (this.Time <= 0) {
  66.              Reboot.wait = false;
  67.              Reboot.this.reboot.stop();
  68.              Reboot.lastReboot = System.currentTimeMillis();
  69.              int nbr_max = World.getOnlinePersos().size();
  70.             int nbr = 0;
  71.            for (Entry<?, ?> vote : Reboot.vote.entrySet()) {
  72.                if (((Boolean)vote.getValue()).booleanValue()) {
  73.                  nbr++;
  74.                  }
  75.               }
  76.              if (nbr_max / 100 * 66 <= nbr) {
  77.                 SocketManager.GAME_SEND_INBOX_TO_All("Un redémarrage aura bien lieu !");
  78.               Reboot.shutdown = Reboot.this.redemarrage(11);
  79.                Reboot.shutdown.start();
  80.                } else {
  81.                SocketManager.GAME_SEND_INBOX_TO_All("Aucun redémarrage n'aura lieu !");
  82.                }
  83.              }
  84.            }
  85.          };
  86.        return new Timer(120000, action);
  87.        }
  88.        public Player getOwner() {
  89.        return this.owner;
  90.        }
  91.        public void setOwner(Player owner) {
  92.        this.owner = owner;
  93.        }
  94.        public static Boolean getVote(Player p) {
  95.            return (Boolean)vote.get(p);
  96.        }
  97.        public static void addVote(Player p, boolean avis) {
  98.        vote.put(p, Boolean.valueOf(avis));
  99.        }
  100.      }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement