Hakens

Untitled

Dec 10th, 2017
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5.78 KB | None | 0 0
  1. public class Zegar {
  2.     static String IP_Adrr="";
  3.     static  String Log="";
  4.     static String Pass="";
  5.     static String Nick="";
  6.     static String ID1="";
  7.     static String ID2="";
  8.     static String ID3="";
  9.     static String ID4="";
  10.     static String Port="";
  11.     public static void main(String[] args) {
  12.        
  13.         Properties prop = new Properties();
  14.        
  15.         try {
  16.            
  17.  
  18.            
  19.             prop.setProperty("IP", "xxx.xxx.xxx.xxx");
  20.             prop.setProperty("Login", "xxxx");
  21.             prop.setProperty("Pass", "xxxxx");
  22.             prop.setProperty("Nick", "xxxxx");
  23.             prop.setProperty("Port", "xxxxx");
  24.             prop.setProperty("1ID", "xxx");
  25.             prop.setProperty("2ID", "xxx");
  26.             prop.setProperty("3ID", "xxx");
  27.             prop.setProperty("4ID", "xxx");
  28.            
  29.             File f = new File("server.properties");
  30.             if(!f.exists()){
  31.                 PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(new FileOutputStream(f, false), "UTF-8")), true);
  32.                     prop.store(out, "Autoconfig, generated by ZegarBot");
  33.            
  34.             }
  35.  
  36.         } catch (Exception io) {
  37.             io.printStackTrace();
  38.         }
  39.         try {
  40.             BufferedReader in = new BufferedReader(new InputStreamReader(new FileInputStream("server.properties"), "UTF8"));
  41.             prop.load(in);
  42.              IP_Adrr=prop.getProperty("IP");
  43.              Log=prop.getProperty("Login");
  44.              Pass=prop.getProperty("Pass");
  45.              Nick=prop.getProperty("Nick");
  46.              ID1=prop.getProperty("1ID");
  47.              ID2=prop.getProperty("2ID");
  48.              ID3=prop.getProperty("3ID");
  49.              ID4=prop.getProperty("4ID");
  50.              Port=prop.getProperty("Port");
  51.         } catch (IOException  | NumberFormatException e) {
  52.             System.err.println("Utworzono plik konfiguracyjny, edytuj jego wartości na poprawne.");
  53.         }
  54.        
  55.          
  56.         final TS3Config config = new TS3Config();
  57.         final TS3Query query = new TS3Query(config);
  58.         final TS3Api api = query.getApi();
  59.     try {
  60.         config.setHost((IP_Adrr));
  61.         config.setQueryPort(Integer.parseInt(Port));
  62.         config.setDebugLevel(Level.SEVERE);
  63.         config.setFloodRate(FloodRate.UNLIMITED);
  64.         query.connect();
  65.         api.login((Log), (Pass));
  66.         api.selectVirtualServerById(1);
  67.         api.setNickname((Nick));
  68.         api.registerAllEvents();
  69.  
  70.     } catch(NumberFormatException e) {
  71.             System.err.println("Uruchom ponownie po edycji zmiennych");
  72.       }
  73.          
  74.        
  75.        
  76.  
  77.        
  78.        
  79.         ScheduledExecutorService ses2 = Executors.newSingleThreadScheduledExecutor();
  80.         ses2.scheduleAtFixedRate(new Runnable() {
  81.             @Override
  82.            public void run() {
  83.      String[][] czcionka ={{"▄▀▀▀█─", "─█─", "─▀▀▀█─", "─▀▀▀█─", "▄───█─", "▄▀▀▀▀─", "▄▀▀▀▀─", "▄▀▀▀█─", "▄▀▀▀█─", "▄▀▀▀█─", "────"},
  84.                            {"█───█─", "─█─", "▄▄▄▄█─", "─▄▄▄█─", "█▄▄▄█─", "█▄▄▄▄─", "█▄▄▄▄─", "────█─", "█▄▄▄█─", "█▄▄▄█─", "─▀──"},
  85.                            {"█───█─", "─█─", "█─────", "────█─", "────█─", "────█─", "█───█─", "────█─", "█───█─", "────█─", "─▄──"},
  86.                            {"▀▀▀▀──", "─▀─", "▀▀▀▀──", "▀▀▀▀──", "────▀─", "▀▀▀▀──", "▀▀▀▀──", "────▀─", "▀▀▀▀──", "▀▀▀▀──", "────"}};
  87.        
  88.        
  89.        
  90.        
  91.        
  92.        
  93.         Calendar teraz = Calendar.getInstance();
  94.         int hours = teraz.get(Calendar.HOUR_OF_DAY);
  95.         int minutes = teraz.get(Calendar.MINUTE);
  96.         String[] linie= {"", "", "", ""};
  97.        
  98.         for(int i = 0; i<4;i++) {
  99.             linie[i]="[cspacer]-";
  100.             if(hours>=10) {
  101.                 linie[i] +=czcionka[i][(int) Math.floor(hours / 10)];
  102.             }
  103.             linie[i]+=czcionka[i][hours % 10];
  104.             linie[i]+=czcionka[i][10];
  105.             linie[i]+=czcionka[i][(int) Math.floor(minutes / 10)];
  106.             linie[i]+=czcionka[i][minutes%10];
  107.            
  108.            
  109.            
  110.            
  111.         }
  112.        
  113.         final HashMap<ChannelProperty, String> zegar1 = new HashMap<>();
  114.         final HashMap<ChannelProperty, String> zegar2 = new HashMap<>();
  115.         final HashMap<ChannelProperty, String> zegar3 = new HashMap<>();
  116.         final HashMap<ChannelProperty, String> zegar4 = new HashMap<>();
  117.         zegar1.put(ChannelProperty.CHANNEL_NAME, linie[0]);
  118.         zegar2.put(ChannelProperty.CHANNEL_NAME, linie[1]);
  119.         zegar3.put(ChannelProperty.CHANNEL_NAME, linie[2]);
  120.         zegar4.put(ChannelProperty.CHANNEL_NAME, linie[3]);
  121.         api.editChannel(Integer.parseInt(ID1), zegar1);
  122.         api.editChannel(Integer.parseInt((ID2)), zegar2);
  123.         api.editChannel(Integer.parseInt((ID3)), zegar3);
  124.         api.editChannel(Integer.parseInt((ID4)), zegar4);
  125.             }
  126.         }, 0, 1, TimeUnit.MINUTES);
  127.        
  128.         System.err.println("Zegarynka Dziala");
  129.          
  130.        
  131.        
  132.        
  133.        
  134.        
  135.        
  136.        
  137.        
  138.        
  139.        
  140.        
  141.         api.addTS3Listeners(new TS3Listener() {
  142.            
  143.            
  144.             @Override
  145.             public void onTextMessage(TextMessageEvent e) {
  146.                
  147.            
  148.             }
  149.  
  150.             @Override
  151.             public void onServerEdit(ServerEditedEvent e) {
  152.                
  153.             }
  154.  
  155.             @Override
  156.             public void onClientMoved(ClientMovedEvent e) {
  157.                
  158.                
  159.             }
  160.             @Override
  161.             public void onClientLeave(ClientLeaveEvent e) {
  162.                
  163.             }
  164.  
  165.             @Override
  166.             public void onClientJoin(ClientJoinEvent e) {
  167.                 // ...
  168.             }
  169.  
  170.             @Override
  171.             public void onChannelEdit(ChannelEditedEvent e) {
  172.                 // ...
  173.             }
  174.  
  175.             @Override
  176.             public void onChannelDescriptionChanged(ChannelDescriptionEditedEvent e) {
  177.                 // ...
  178.             }
  179.  
  180.             @Override
  181.             public void onChannelCreate(ChannelCreateEvent e) {
  182.                 // ...
  183.             }
  184.  
  185.             @Override
  186.             public void onChannelDeleted(ChannelDeletedEvent e) {
  187.                 // ...
  188.             }
  189.  
  190.             @Override
  191.             public void onChannelMoved(ChannelMovedEvent e) {
  192.                 // ...
  193.             }
  194.  
  195.             @Override
  196.             public void onChannelPasswordChanged(ChannelPasswordChangedEvent e) {
  197.                 // ...
  198.             }
  199.  
  200.             @Override
  201.             public void onPrivilegeKeyUsed(PrivilegeKeyUsedEvent e) {
  202.                 // ...
  203.             }
  204.         });
  205.     }
  206.    
  207.    
  208. }
Advertisement
Add Comment
Please, Sign In to add comment