Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package command;
- import java.awt.event.ActionEvent;
- import java.awt.event.ActionListener;
- import java.util.HashMap;
- import java.util.Map;
- import java.util.Map.Entry;
- import javax.swing.Timer;
- import org.Wokama.client.Player;
- import common.SQLManager;
- import common.SocketManager;
- import common.World;
- public class Reboot
- {
- private static Map<Player, Boolean> vote = new HashMap<Player,Boolean>();
- public static long lastReboot = 0L;
- public static boolean wait = false;
- public static Timer shutdown = null;
- private Timer reboot;
- private Player owner;
- public Reboot(Player _perso)
- {
- if (_perso == null) return;
- this.owner = _perso;
- wait = true;
- this.reboot = createTimer(5);
- this.reboot.start();
- 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 .");
- }
- private Timer redemarrage(int time) {
- ActionListener action = new ActionListener() {
- int Time;
- public void actionPerformed(ActionEvent event) { this.Time -= 1;
- if (this.Time == 1)
- SocketManager.GAME_SEND_Im_PACKET_TO_ALL("115;" + this.Time +
- " minute");
- else {
- SocketManager.GAME_SEND_Im_PACKET_TO_ALL("115;" + this.Time +
- " minutes");
- }
- if (this.Time <= 0) {
- SQLManager.LOAD_ACTION();
- SocketManager.SEND_MESSAGE_DECO_ALL(4, "");
- System.exit(0);
- }
- }
- };
- return new Timer(60000, action);
- }
- private Timer createTimer(int time) {
- ActionListener action = new ActionListener() {
- int Time;
- public void actionPerformed(ActionEvent event) { this.Time -= 1;
- if (this.Time <= 0) {
- Reboot.wait = false;
- Reboot.this.reboot.stop();
- Reboot.lastReboot = System.currentTimeMillis();
- int nbr_max = World.getOnlinePersos().size();
- int nbr = 0;
- for (Entry<?, ?> vote : Reboot.vote.entrySet()) {
- if (((Boolean)vote.getValue()).booleanValue()) {
- nbr++;
- }
- }
- if (nbr_max / 100 * 66 <= nbr) {
- SocketManager.GAME_SEND_INBOX_TO_All("Un redémarrage aura bien lieu !");
- Reboot.shutdown = Reboot.this.redemarrage(11);
- Reboot.shutdown.start();
- } else {
- SocketManager.GAME_SEND_INBOX_TO_All("Aucun redémarrage n'aura lieu !");
- }
- }
- }
- };
- return new Timer(120000, action);
- }
- public Player getOwner() {
- return this.owner;
- }
- public void setOwner(Player owner) {
- this.owner = owner;
- }
- public static Boolean getVote(Player p) {
- return (Boolean)vote.get(p);
- }
- public static void addVote(Player p, boolean avis) {
- vote.put(p, Boolean.valueOf(avis));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement