Advertisement
Guest User

Untitled

a guest
Jul 26th, 2016
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 17.82 KB | None | 0 0
  1. package me.TS3.benni;
  2.  
  3. import java.io.PrintStream;
  4. import java.sql.ResultSet;
  5. import java.sql.ResultSetMetaData;
  6. import java.sql.SQLException;
  7. import java.util.ArrayList;
  8. import java.util.List;
  9. import me.r3fresh.mysql.MySQL;
  10. import org.bukkit.Bukkit;
  11. import org.bukkit.ChatColor;
  12. import org.bukkit.Server;
  13. import org.bukkit.command.Command;
  14. import org.bukkit.command.CommandSender;
  15. import org.bukkit.configuration.file.FileConfiguration;
  16. import org.bukkit.configuration.file.FileConfigurationOptions;
  17. import org.bukkit.entity.Player;
  18. import org.bukkit.plugin.PluginManager;
  19. import org.bukkit.plugin.java.JavaPlugin;
  20. import org.bukkit.scheduler.BukkitScheduler;
  21.  
  22. public class Musik
  23. extends JavaPlugin
  24. {
  25. public String botID;
  26. public String password = getConfig().getString("MySQL.Password");
  27. public String database = getConfig().getString("MySQL.Database");
  28. public String host = getConfig().getString("MySQL.Host");
  29. public String port = getConfig().getString("MySQL.Port");
  30. public String user = getConfig().getString("MySQL.User");
  31. public String prefix = ChatColor.RED + "[TS3Music]";
  32. public List<String> tracks = new ArrayList();
  33. Boolean empty = Boolean.valueOf(true);
  34. int size;
  35.  
  36. public void onEnable()
  37. {
  38. MySQL MySQL = new MySQL(this.host, this.port, this.database, this.user, this.password);
  39. getConfig().options().copyDefaults(true);
  40. saveConfig();
  41. try
  42. {
  43. MySQL.openConnection();
  44. System.out.println("This is a Hack watch out pls! thx m8 i rekt your server!");
  45. }
  46. catch (ClassNotFoundException e)
  47. {
  48. Bukkit.getServer().getPluginManager().disablePlugin(this);
  49. System.out.print(this.prefix + "MySQL Error, Check if Database exists");
  50. }
  51. catch (SQLException e)
  52. {
  53. Bukkit.getServer().getPluginManager().disablePlugin(this);
  54. System.out.print(this.prefix + "MySQL Error, Check if Database exists");
  55. }
  56. try
  57. {
  58. MySQL.updateSQL("CREATE TABLE BotIDs(name varchar(255), BotId varchar(255), channel varchar(255), permission varchar(255));");
  59. }
  60. catch (ClassNotFoundException|SQLException localClassNotFoundException1) {}
  61. try
  62. {
  63. ResultSet test = MySQL.querySQL("SELECT * FROM BotIDs;");
  64. if (!test.next()) {
  65. this.empty = Boolean.valueOf(true);
  66. } else {
  67. this.empty = Boolean.valueOf(false);
  68. }
  69. }
  70. catch (ClassNotFoundException|SQLException e1)
  71. {
  72. e1.printStackTrace();
  73. }
  74. try
  75. {
  76. MySQL.closeConnection();
  77. }
  78. catch (SQLException e)
  79. {
  80. e.printStackTrace();
  81. }
  82. final db dbase = new db();
  83. System.out.println(ChatColor.RED + "[Music]" + ChatColor.RESET + "Plugin started!");
  84. List<String> botname = dbase.allName(this.host, this.port, this.database, this.user, this.password);
  85. this.size = botname.size();
  86. Bukkit.getServer().getScheduler().scheduleAsyncRepeatingTask(this, new Runnable()
  87. {
  88. public void run()
  89. {
  90. TS3 botApi;
  91. List<String> botname;
  92. List<String> permission;
  93. int i;
  94. if (!Musik.this.empty.booleanValue())
  95. {
  96. botApi = new TS3(Musik.this.getConfig().getString("Sinusbot.Host"), Musik.this.getConfig().getInt("Sinusbot.Port"));
  97. botApi.login(Musik.this.getConfig().getString("Sinusbot.User"), Musik.this.getConfig().getString("Sinusbot.Password"));
  98. List<String> bots = dbase.allBots(Musik.this.host, Musik.this.port, Musik.this.database, Musik.this.user, Musik.this.password);
  99. botname = dbase.allName(Musik.this.host, Musik.this.port, Musik.this.database, Musik.this.user, Musik.this.password);
  100. if ((Musik.this.size < botname.size()) || (botname.size() > Musik.this.tracks.size()))
  101. {
  102. Musik.this.tracks.clear();
  103. for (int i = 0; i < botname.size(); i++) {
  104. Musik.this.tracks.add(" ");
  105. }
  106. Musik.this.size = botname.size();
  107. }
  108. permission = dbase.perm(Musik.this.host, Musik.this.port, Musik.this.database, Musik.this.user, Musik.this.password);
  109. i = 0;
  110. for (String id : bots)
  111. {
  112. botApi.setBotId(id);
  113. String[] current = botApi.currenTrack();
  114. String track = current[0];
  115. String artist = current[1];
  116. if (!((String)Musik.this.tracks.get(i)).equals(track))
  117. {
  118. Musik.this.tracks.set(i, track);
  119. Bukkit.broadcast(ChatColor.RED + "Now playing on " + (String)botname.get(i) + " the track: " + artist + "-" + track, "music." +
  120. (String)permission.get(i));
  121. }
  122. i++;
  123. }
  124. }
  125. }
  126. }, 0L, 20L);
  127. }
  128.  
  129. public void onDisable()
  130. {
  131. System.out.println(this.prefix + ChatColor.RESET + "Plugin stopped");
  132. }
  133.  
  134. public boolean onCommand(CommandSender sender, Command command, String label, String[] args)
  135. {
  136. Player p = (Player)sender;
  137. MySQL MySQL = new MySQL(this.host, this.port, this.database, this.user, this.password);
  138. if (command.getName().equalsIgnoreCase("music"))
  139. {
  140. if (args.length == 0)
  141. {
  142. p.sendMessage(ChatColor.RED + "Try /music help for more information!");
  143. return true;
  144. }
  145. if (args.length > 0)
  146. {
  147. if (args[0].equalsIgnoreCase("help"))
  148. {
  149. p.sendMessage(ChatColor.RED + "########################################");
  150. p.sendMessage(ChatColor.RED + "Usage: /music [task] \n");
  151. p.sendMessage(ChatColor.RED + "Tasks:");
  152. p.sendMessage(ChatColor.RED + "-help: opens the help menu");
  153. p.sendMessage(ChatColor.RED + "-list [page]: lists all tracks - 10 per");
  154. p.sendMessage(ChatColor.RED + " page and site");
  155. p.sendMessage(ChatColor.RED + "-registerBot [name] [BotId] [Channel]:");
  156. p.sendMessage(ChatColor.RED + " register a new Bot into a Database");
  157. p.sendMessage(ChatColor.RED + "-next [bot]: plays the next track in the queue");
  158. p.sendMessage(ChatColor.RED + "-prevous [bot]: plays the prevous track in the");
  159. p.sendMessage(ChatColor.RED + " queue");
  160. p.sendMessage(ChatColor.RED + "-stop [bot]: stops the bot");
  161. p.sendMessage(ChatColor.RED + "-addQueue [bot] [track]: adds a track to the");
  162. p.sendMessage(ChatColor.RED + " queue");
  163. p.sendMessage(ChatColor.RED + "-playTrack [bot] [track]: immediately plays");
  164. p.sendMessage(ChatColor.RED + " the track");
  165. p.sendMessage(ChatColor.RED + "botList: prints all bot IDs and their names");
  166. p.sendMessage(ChatColor.RED + "searchTitle [bot] [song]: search a song");
  167. p.sendMessage(ChatColor.RED + "searchArtist [bot] [Artist]: search songs from artists");
  168. p.sendMessage(ChatColor.RED + "########################################");
  169. return true;
  170. }
  171. if (args[0].equalsIgnoreCase("registerBot"))
  172. {
  173. if (args.length >= 5)
  174. {
  175. String name = args[1];
  176. String botID = args[2];
  177. String channel = args[3];
  178. String perm = args[4];
  179. try
  180. {
  181. MySQL.openConnection();
  182. try
  183. {
  184. MySQL.updateSQL("INSERT INTO BotIDs VALUES ('" + name + "','" + botID + "','" + channel + "','" + perm + "');");
  185.  
  186. this.empty = Boolean.valueOf(false);
  187. }
  188. catch (ClassNotFoundException|SQLException e)
  189. {
  190. e.printStackTrace();
  191. }
  192. }
  193. catch (ClassNotFoundException|SQLException e)
  194. {
  195. e.printStackTrace();
  196. }
  197. }
  198. return true;
  199. }
  200. if (!this.empty.booleanValue())
  201. {
  202. if (args[0].equalsIgnoreCase("botList"))
  203. {
  204. try
  205. {
  206. MySQL.openConnection();
  207. ResultSet rs1 = MySQL.querySQL("Select * FROM BotIDs;");
  208. ResultSetMetaData rsmd = rs1.getMetaData();
  209. int spaltenZahl = rsmd.getColumnCount();
  210. while (rs1.next())
  211. {
  212. for (int i = 1; i <= spaltenZahl; i++)
  213. {
  214. String wertSpalte = rs1.getString(i);
  215. p.sendMessage(wertSpalte + " " + rsmd.getColumnName(i));
  216. }
  217. p.sendMessage("");
  218. }
  219. MySQL.closeConnection();
  220. }
  221. catch (ClassNotFoundException|SQLException e)
  222. {
  223. System.out.print(this.prefix + "MySQL Error");
  224. e.printStackTrace();
  225. }
  226. return true;
  227. }
  228. if (args[0].equalsIgnoreCase("next"))
  229. {
  230. db dbase = new db();
  231.  
  232. TS3 botApi = new TS3(getConfig().getString("Sinusbot.Host"), getConfig().getInt("Sinusbot.Port"));
  233.  
  234. this.botID = dbase.searchBot(this.host, this.port, this.database, this.user, this.password, args[1]);
  235. botApi.login(getConfig().getString("Sinusbot.User"),
  236. getConfig().getString("Sinusbot.Password"));
  237. botApi.setBotId(this.botID);
  238. botApi.loadAllTracks();
  239. botApi.playNext();
  240. return true;
  241. }
  242. int j;
  243. if (args[0].equalsIgnoreCase("list"))
  244. {
  245. if (args.length == 2)
  246. {
  247. p.sendMessage(ChatColor.RED + "Please point out what Page you would see!");
  248. }
  249. else if (args.length == 3)
  250. {
  251. int i = 0;
  252. db dbase = new db();
  253.  
  254. TS3 botApi = new TS3(getConfig().getString("Sinusbot.Host"), getConfig().getInt("Sinusbot.Port"));
  255.  
  256. this.botID = dbase.searchBot(this.host, this.port, this.database, this.user, this.password, args[1]);
  257. botApi.login(getConfig().getString("Sinusbot.User"),
  258. getConfig().getString("Sinusbot.Password"));
  259. botApi.setBotId(this.botID);
  260. botApi.loadAllTracks();
  261. TS3.Track[] tracks = botApi.listTracks();
  262. try
  263. {
  264. String s = args[2];
  265. i = Integer.parseInt(s);
  266. p.sendMessage(ChatColor.RED + "Page: " + i);
  267. }
  268. catch (NumberFormatException nfe)
  269. {
  270. sender.sendMessage("Please use a number");
  271. }
  272. if (i == 1) {
  273. i = 0;
  274. } else {
  275. i = (i - 1) * 10;
  276. }
  277. j = 0;
  278. while ((i < tracks.length) && (j < 10))
  279. {
  280. p.sendMessage(tracks[i].title);
  281. i++;
  282. j++;
  283. }
  284. }
  285. else
  286. {
  287. p.sendMessage("Somthing went wrong hax!");
  288. }
  289. return true;
  290. }
  291. if (args[0].equalsIgnoreCase("searchTitle"))
  292. {
  293. if (args.length == 2)
  294. {
  295. p.sendMessage(ChatColor.RED + "Please point out what Song you want search!");
  296. }
  297. else if (args.length == 3)
  298. {
  299. db dbase = new db();
  300.  
  301. TS3 botApi = new TS3(getConfig().getString("Sinusbot.Host"), getConfig().getInt("Sinusbot.Port"));
  302. this.botID = dbase.searchBot(this.host, this.port, this.database, this.user, this.password, args[1]);
  303. botApi.login(getConfig().getString("Sinusbot.User"),
  304. getConfig().getString("Sinusbot.Password"));
  305. botApi.setBotId(this.botID);
  306. TS3.Track[] tracks = botApi.listTracks();
  307. boolean found = false;
  308. p.sendMessage(ChatColor.RED + "Results:");
  309. for (TS3.Track track : tracks)
  310. {
  311. String title = track.title;
  312. title = title.toLowerCase();
  313. String search = args[2];
  314. search = search.toLowerCase();
  315. String temp = search.replaceAll("_", " ");
  316. if (title.contains(temp))
  317. {
  318. p.sendRawMessage(ChatColor.BOLD + track.artist + "-" + track.title);
  319. found = true;
  320. }
  321. }
  322. if (!found) {
  323. p.sendMessage(ChatColor.RED + "No Results!");
  324. }
  325. }
  326. return true;
  327. }
  328. if (args[0].equalsIgnoreCase("searchArtist"))
  329. {
  330. if (args.length == 2)
  331. {
  332. p.sendMessage(ChatColor.RED + "Please point out what Artist you want search!");
  333. }
  334. else if (args.length == 3)
  335. {
  336. db dbase = new db();
  337.  
  338. TS3 botApi = new TS3(getConfig().getString("Sinusbot.Host"), getConfig().getInt("Sinusbot.Port"));
  339. this.botID = dbase.searchBot(this.host, this.port, this.database, this.user, this.password, args[1]);
  340. botApi.login(getConfig().getString("Sinusbot.User"),
  341. getConfig().getString("Sinusbot.Password"));
  342. botApi.setBotId(this.botID);
  343. TS3.Track[] tracks = botApi.listTracks();
  344. boolean found = false;
  345. p.sendMessage(ChatColor.RED + "Results:");
  346. for (TS3.Track track : tracks)
  347. {
  348. String artist = track.artist;
  349. if (artist != null)
  350. {
  351. artist = artist.toLowerCase();
  352. String search = args[2];
  353. search = search.toLowerCase();
  354. String temp = search.replaceAll("_", " ");
  355. if (artist.contains(temp))
  356. {
  357. p.sendRawMessage(ChatColor.BOLD + track.artist + "-" + track.title);
  358. found = true;
  359. }
  360. }
  361. }
  362. if (!found) {
  363. p.sendMessage(ChatColor.RED + "No Results!");
  364. }
  365. }
  366. return true;
  367. }
  368. if (args[0].equalsIgnoreCase("playTrack"))
  369. {
  370. db dbase = new db();
  371.  
  372. TS3 botApi = new TS3(getConfig().getString("Sinusbot.Host"), getConfig().getInt("Sinusbot.Port"));
  373.  
  374. this.botID = dbase.searchBot(this.host, this.port, this.database, this.user, this.password, args[1]);
  375. botApi.login(getConfig().getString("Sinusbot.User"),
  376. getConfig().getString("Sinusbot.Password"));
  377. botApi.setBotId(this.botID);
  378. botApi.loadAllTracks();
  379. if (args.length == 1)
  380. {
  381. p.sendMessage(ChatColor.RED + "Please point out what Track you want to play!");
  382. }
  383. else if (args.length == 3)
  384. {
  385. String track = args[2];
  386. String temp = track.replaceAll("_", " ");
  387. botApi.playTrack(temp);
  388. p.sendMessage(ChatColor.RED + "You started the song: " + temp);
  389. }
  390. else
  391. {
  392. p.sendMessage(ChatColor.RED + "Somthing went wrong hax!");
  393. }
  394. return true;
  395. }
  396. if (args[0].equalsIgnoreCase("stop"))
  397. {
  398. db dbase = new db();
  399.  
  400. TS3 botApi = new TS3(getConfig().getString("Sinusbot.Host"), getConfig().getInt("Sinusbot.Port"));
  401.  
  402. this.botID = dbase.searchBot(this.host, this.port, this.database, this.user, this.password, args[1]);
  403. botApi.login(getConfig().getString("Sinusbot.User"),
  404. getConfig().getString("Sinusbot.Password"));
  405. botApi.setBotId(this.botID);
  406. botApi.loadAllTracks();
  407. botApi.stopTrack();
  408. return true;
  409. }
  410. if (args[0].equalsIgnoreCase("prevous"))
  411. {
  412. db dbase = new db();
  413.  
  414. TS3 botApi = new TS3(getConfig().getString("Sinusbot.Host"), getConfig().getInt("Sinusbot.Port"));
  415.  
  416. this.botID = dbase.searchBot(this.host, this.port, this.database, this.user, this.password, args[1]);
  417. botApi.login(getConfig().getString("Sinusbot.User"),
  418. getConfig().getString("Sinusbot.Password"));
  419. botApi.setBotId(this.botID);
  420. botApi.loadAllTracks();
  421. botApi.playPrevious();
  422. return true;
  423. }
  424. if (args[0].equalsIgnoreCase("addQueue"))
  425. {
  426. db dbase = new db();
  427.  
  428. TS3 botApi = new TS3(getConfig().getString("Sinusbot.Host"), getConfig().getInt("Sinusbot.Port"));
  429.  
  430. this.botID = dbase.searchBot(this.host, this.port, this.database, this.user, this.password, args[1]);
  431. botApi.login(getConfig().getString("Sinusbot.User"),
  432. getConfig().getString("Sinusbot.Password"));
  433. botApi.setBotId(this.botID);
  434. botApi.loadAllTracks();
  435. if (args.length == 2)
  436. {
  437. p.sendMessage(ChatColor.RED + "Please point out what Track you want append!");
  438. }
  439. else if (args.length == 3)
  440. {
  441. String track = args[2];
  442. botApi.addQueue(track);
  443. p.sendMessage(ChatColor.RED + "You added " + track + " to the Queue");
  444. }
  445. else
  446. {
  447. p.sendMessage(ChatColor.RED + "Somthing went wrong hax!");
  448. }
  449. return true;
  450. }
  451. return true;
  452. }
  453. return true;
  454. }
  455. return true;
  456. }
  457. return false;
  458. }
  459. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement