Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package me.TS3.benni;
- import java.io.PrintStream;
- import java.sql.ResultSet;
- import java.sql.ResultSetMetaData;
- import java.sql.SQLException;
- import java.util.ArrayList;
- import java.util.List;
- import me.r3fresh.mysql.MySQL;
- import org.bukkit.Bukkit;
- import org.bukkit.ChatColor;
- import org.bukkit.Server;
- import org.bukkit.command.Command;
- import org.bukkit.command.CommandSender;
- import org.bukkit.configuration.file.FileConfiguration;
- import org.bukkit.configuration.file.FileConfigurationOptions;
- import org.bukkit.entity.Player;
- import org.bukkit.plugin.PluginManager;
- import org.bukkit.plugin.java.JavaPlugin;
- import org.bukkit.scheduler.BukkitScheduler;
- public class Musik
- extends JavaPlugin
- {
- public String botID;
- public String password = getConfig().getString("MySQL.Password");
- public String database = getConfig().getString("MySQL.Database");
- public String host = getConfig().getString("MySQL.Host");
- public String port = getConfig().getString("MySQL.Port");
- public String user = getConfig().getString("MySQL.User");
- public String prefix = ChatColor.RED + "[TS3Music]";
- public List<String> tracks = new ArrayList();
- Boolean empty = Boolean.valueOf(true);
- int size;
- public void onEnable()
- {
- MySQL MySQL = new MySQL(this.host, this.port, this.database, this.user, this.password);
- getConfig().options().copyDefaults(true);
- saveConfig();
- try
- {
- MySQL.openConnection();
- System.out.println("This is a Hack watch out pls! thx m8 i rekt your server!");
- }
- catch (ClassNotFoundException e)
- {
- Bukkit.getServer().getPluginManager().disablePlugin(this);
- System.out.print(this.prefix + "MySQL Error, Check if Database exists");
- }
- catch (SQLException e)
- {
- Bukkit.getServer().getPluginManager().disablePlugin(this);
- System.out.print(this.prefix + "MySQL Error, Check if Database exists");
- }
- try
- {
- MySQL.updateSQL("CREATE TABLE BotIDs(name varchar(255), BotId varchar(255), channel varchar(255), permission varchar(255));");
- }
- catch (ClassNotFoundException|SQLException localClassNotFoundException1) {}
- try
- {
- ResultSet test = MySQL.querySQL("SELECT * FROM BotIDs;");
- if (!test.next()) {
- this.empty = Boolean.valueOf(true);
- } else {
- this.empty = Boolean.valueOf(false);
- }
- }
- catch (ClassNotFoundException|SQLException e1)
- {
- e1.printStackTrace();
- }
- try
- {
- MySQL.closeConnection();
- }
- catch (SQLException e)
- {
- e.printStackTrace();
- }
- final db dbase = new db();
- System.out.println(ChatColor.RED + "[Music]" + ChatColor.RESET + "Plugin started!");
- List<String> botname = dbase.allName(this.host, this.port, this.database, this.user, this.password);
- this.size = botname.size();
- Bukkit.getServer().getScheduler().scheduleAsyncRepeatingTask(this, new Runnable()
- {
- public void run()
- {
- TS3 botApi;
- List<String> botname;
- List<String> permission;
- int i;
- if (!Musik.this.empty.booleanValue())
- {
- botApi = new TS3(Musik.this.getConfig().getString("Sinusbot.Host"), Musik.this.getConfig().getInt("Sinusbot.Port"));
- botApi.login(Musik.this.getConfig().getString("Sinusbot.User"), Musik.this.getConfig().getString("Sinusbot.Password"));
- List<String> bots = dbase.allBots(Musik.this.host, Musik.this.port, Musik.this.database, Musik.this.user, Musik.this.password);
- botname = dbase.allName(Musik.this.host, Musik.this.port, Musik.this.database, Musik.this.user, Musik.this.password);
- if ((Musik.this.size < botname.size()) || (botname.size() > Musik.this.tracks.size()))
- {
- Musik.this.tracks.clear();
- for (int i = 0; i < botname.size(); i++) {
- Musik.this.tracks.add(" ");
- }
- Musik.this.size = botname.size();
- }
- permission = dbase.perm(Musik.this.host, Musik.this.port, Musik.this.database, Musik.this.user, Musik.this.password);
- i = 0;
- for (String id : bots)
- {
- botApi.setBotId(id);
- String[] current = botApi.currenTrack();
- String track = current[0];
- String artist = current[1];
- if (!((String)Musik.this.tracks.get(i)).equals(track))
- {
- Musik.this.tracks.set(i, track);
- Bukkit.broadcast(ChatColor.RED + "Now playing on " + (String)botname.get(i) + " the track: " + artist + "-" + track, "music." +
- (String)permission.get(i));
- }
- i++;
- }
- }
- }
- }, 0L, 20L);
- }
- public void onDisable()
- {
- System.out.println(this.prefix + ChatColor.RESET + "Plugin stopped");
- }
- public boolean onCommand(CommandSender sender, Command command, String label, String[] args)
- {
- Player p = (Player)sender;
- MySQL MySQL = new MySQL(this.host, this.port, this.database, this.user, this.password);
- if (command.getName().equalsIgnoreCase("music"))
- {
- if (args.length == 0)
- {
- p.sendMessage(ChatColor.RED + "Try /music help for more information!");
- return true;
- }
- if (args.length > 0)
- {
- if (args[0].equalsIgnoreCase("help"))
- {
- p.sendMessage(ChatColor.RED + "########################################");
- p.sendMessage(ChatColor.RED + "Usage: /music [task] \n");
- p.sendMessage(ChatColor.RED + "Tasks:");
- p.sendMessage(ChatColor.RED + "-help: opens the help menu");
- p.sendMessage(ChatColor.RED + "-list [page]: lists all tracks - 10 per");
- p.sendMessage(ChatColor.RED + " page and site");
- p.sendMessage(ChatColor.RED + "-registerBot [name] [BotId] [Channel]:");
- p.sendMessage(ChatColor.RED + " register a new Bot into a Database");
- p.sendMessage(ChatColor.RED + "-next [bot]: plays the next track in the queue");
- p.sendMessage(ChatColor.RED + "-prevous [bot]: plays the prevous track in the");
- p.sendMessage(ChatColor.RED + " queue");
- p.sendMessage(ChatColor.RED + "-stop [bot]: stops the bot");
- p.sendMessage(ChatColor.RED + "-addQueue [bot] [track]: adds a track to the");
- p.sendMessage(ChatColor.RED + " queue");
- p.sendMessage(ChatColor.RED + "-playTrack [bot] [track]: immediately plays");
- p.sendMessage(ChatColor.RED + " the track");
- p.sendMessage(ChatColor.RED + "botList: prints all bot IDs and their names");
- p.sendMessage(ChatColor.RED + "searchTitle [bot] [song]: search a song");
- p.sendMessage(ChatColor.RED + "searchArtist [bot] [Artist]: search songs from artists");
- p.sendMessage(ChatColor.RED + "########################################");
- return true;
- }
- if (args[0].equalsIgnoreCase("registerBot"))
- {
- if (args.length >= 5)
- {
- String name = args[1];
- String botID = args[2];
- String channel = args[3];
- String perm = args[4];
- try
- {
- MySQL.openConnection();
- try
- {
- MySQL.updateSQL("INSERT INTO BotIDs VALUES ('" + name + "','" + botID + "','" + channel + "','" + perm + "');");
- this.empty = Boolean.valueOf(false);
- }
- catch (ClassNotFoundException|SQLException e)
- {
- e.printStackTrace();
- }
- }
- catch (ClassNotFoundException|SQLException e)
- {
- e.printStackTrace();
- }
- }
- return true;
- }
- if (!this.empty.booleanValue())
- {
- if (args[0].equalsIgnoreCase("botList"))
- {
- try
- {
- MySQL.openConnection();
- ResultSet rs1 = MySQL.querySQL("Select * FROM BotIDs;");
- ResultSetMetaData rsmd = rs1.getMetaData();
- int spaltenZahl = rsmd.getColumnCount();
- while (rs1.next())
- {
- for (int i = 1; i <= spaltenZahl; i++)
- {
- String wertSpalte = rs1.getString(i);
- p.sendMessage(wertSpalte + " " + rsmd.getColumnName(i));
- }
- p.sendMessage("");
- }
- MySQL.closeConnection();
- }
- catch (ClassNotFoundException|SQLException e)
- {
- System.out.print(this.prefix + "MySQL Error");
- e.printStackTrace();
- }
- return true;
- }
- if (args[0].equalsIgnoreCase("next"))
- {
- db dbase = new db();
- TS3 botApi = new TS3(getConfig().getString("Sinusbot.Host"), getConfig().getInt("Sinusbot.Port"));
- this.botID = dbase.searchBot(this.host, this.port, this.database, this.user, this.password, args[1]);
- botApi.login(getConfig().getString("Sinusbot.User"),
- getConfig().getString("Sinusbot.Password"));
- botApi.setBotId(this.botID);
- botApi.loadAllTracks();
- botApi.playNext();
- return true;
- }
- int j;
- if (args[0].equalsIgnoreCase("list"))
- {
- if (args.length == 2)
- {
- p.sendMessage(ChatColor.RED + "Please point out what Page you would see!");
- }
- else if (args.length == 3)
- {
- int i = 0;
- db dbase = new db();
- TS3 botApi = new TS3(getConfig().getString("Sinusbot.Host"), getConfig().getInt("Sinusbot.Port"));
- this.botID = dbase.searchBot(this.host, this.port, this.database, this.user, this.password, args[1]);
- botApi.login(getConfig().getString("Sinusbot.User"),
- getConfig().getString("Sinusbot.Password"));
- botApi.setBotId(this.botID);
- botApi.loadAllTracks();
- TS3.Track[] tracks = botApi.listTracks();
- try
- {
- String s = args[2];
- i = Integer.parseInt(s);
- p.sendMessage(ChatColor.RED + "Page: " + i);
- }
- catch (NumberFormatException nfe)
- {
- sender.sendMessage("Please use a number");
- }
- if (i == 1) {
- i = 0;
- } else {
- i = (i - 1) * 10;
- }
- j = 0;
- while ((i < tracks.length) && (j < 10))
- {
- p.sendMessage(tracks[i].title);
- i++;
- j++;
- }
- }
- else
- {
- p.sendMessage("Somthing went wrong hax!");
- }
- return true;
- }
- if (args[0].equalsIgnoreCase("searchTitle"))
- {
- if (args.length == 2)
- {
- p.sendMessage(ChatColor.RED + "Please point out what Song you want search!");
- }
- else if (args.length == 3)
- {
- db dbase = new db();
- TS3 botApi = new TS3(getConfig().getString("Sinusbot.Host"), getConfig().getInt("Sinusbot.Port"));
- this.botID = dbase.searchBot(this.host, this.port, this.database, this.user, this.password, args[1]);
- botApi.login(getConfig().getString("Sinusbot.User"),
- getConfig().getString("Sinusbot.Password"));
- botApi.setBotId(this.botID);
- TS3.Track[] tracks = botApi.listTracks();
- boolean found = false;
- p.sendMessage(ChatColor.RED + "Results:");
- for (TS3.Track track : tracks)
- {
- String title = track.title;
- title = title.toLowerCase();
- String search = args[2];
- search = search.toLowerCase();
- String temp = search.replaceAll("_", " ");
- if (title.contains(temp))
- {
- p.sendRawMessage(ChatColor.BOLD + track.artist + "-" + track.title);
- found = true;
- }
- }
- if (!found) {
- p.sendMessage(ChatColor.RED + "No Results!");
- }
- }
- return true;
- }
- if (args[0].equalsIgnoreCase("searchArtist"))
- {
- if (args.length == 2)
- {
- p.sendMessage(ChatColor.RED + "Please point out what Artist you want search!");
- }
- else if (args.length == 3)
- {
- db dbase = new db();
- TS3 botApi = new TS3(getConfig().getString("Sinusbot.Host"), getConfig().getInt("Sinusbot.Port"));
- this.botID = dbase.searchBot(this.host, this.port, this.database, this.user, this.password, args[1]);
- botApi.login(getConfig().getString("Sinusbot.User"),
- getConfig().getString("Sinusbot.Password"));
- botApi.setBotId(this.botID);
- TS3.Track[] tracks = botApi.listTracks();
- boolean found = false;
- p.sendMessage(ChatColor.RED + "Results:");
- for (TS3.Track track : tracks)
- {
- String artist = track.artist;
- if (artist != null)
- {
- artist = artist.toLowerCase();
- String search = args[2];
- search = search.toLowerCase();
- String temp = search.replaceAll("_", " ");
- if (artist.contains(temp))
- {
- p.sendRawMessage(ChatColor.BOLD + track.artist + "-" + track.title);
- found = true;
- }
- }
- }
- if (!found) {
- p.sendMessage(ChatColor.RED + "No Results!");
- }
- }
- return true;
- }
- if (args[0].equalsIgnoreCase("playTrack"))
- {
- db dbase = new db();
- TS3 botApi = new TS3(getConfig().getString("Sinusbot.Host"), getConfig().getInt("Sinusbot.Port"));
- this.botID = dbase.searchBot(this.host, this.port, this.database, this.user, this.password, args[1]);
- botApi.login(getConfig().getString("Sinusbot.User"),
- getConfig().getString("Sinusbot.Password"));
- botApi.setBotId(this.botID);
- botApi.loadAllTracks();
- if (args.length == 1)
- {
- p.sendMessage(ChatColor.RED + "Please point out what Track you want to play!");
- }
- else if (args.length == 3)
- {
- String track = args[2];
- String temp = track.replaceAll("_", " ");
- botApi.playTrack(temp);
- p.sendMessage(ChatColor.RED + "You started the song: " + temp);
- }
- else
- {
- p.sendMessage(ChatColor.RED + "Somthing went wrong hax!");
- }
- return true;
- }
- if (args[0].equalsIgnoreCase("stop"))
- {
- db dbase = new db();
- TS3 botApi = new TS3(getConfig().getString("Sinusbot.Host"), getConfig().getInt("Sinusbot.Port"));
- this.botID = dbase.searchBot(this.host, this.port, this.database, this.user, this.password, args[1]);
- botApi.login(getConfig().getString("Sinusbot.User"),
- getConfig().getString("Sinusbot.Password"));
- botApi.setBotId(this.botID);
- botApi.loadAllTracks();
- botApi.stopTrack();
- return true;
- }
- if (args[0].equalsIgnoreCase("prevous"))
- {
- db dbase = new db();
- TS3 botApi = new TS3(getConfig().getString("Sinusbot.Host"), getConfig().getInt("Sinusbot.Port"));
- this.botID = dbase.searchBot(this.host, this.port, this.database, this.user, this.password, args[1]);
- botApi.login(getConfig().getString("Sinusbot.User"),
- getConfig().getString("Sinusbot.Password"));
- botApi.setBotId(this.botID);
- botApi.loadAllTracks();
- botApi.playPrevious();
- return true;
- }
- if (args[0].equalsIgnoreCase("addQueue"))
- {
- db dbase = new db();
- TS3 botApi = new TS3(getConfig().getString("Sinusbot.Host"), getConfig().getInt("Sinusbot.Port"));
- this.botID = dbase.searchBot(this.host, this.port, this.database, this.user, this.password, args[1]);
- botApi.login(getConfig().getString("Sinusbot.User"),
- getConfig().getString("Sinusbot.Password"));
- botApi.setBotId(this.botID);
- botApi.loadAllTracks();
- if (args.length == 2)
- {
- p.sendMessage(ChatColor.RED + "Please point out what Track you want append!");
- }
- else if (args.length == 3)
- {
- String track = args[2];
- botApi.addQueue(track);
- p.sendMessage(ChatColor.RED + "You added " + track + " to the Queue");
- }
- else
- {
- p.sendMessage(ChatColor.RED + "Somthing went wrong hax!");
- }
- return true;
- }
- return true;
- }
- return true;
- }
- return true;
- }
- return false;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement