Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package me.wafflemaster.com;
- import java.sql.Connection;
- import java.sql.DriverManager;
- import java.sql.PreparedStatement;
- import java.sql.ResultSet;
- import java.util.logging.Logger;
- import org.bukkit.ChatColor;
- import org.bukkit.command.Command;
- import org.bukkit.command.CommandSender;
- import org.bukkit.entity.Player;
- import org.bukkit.plugin.PluginDescriptionFile;
- import org.bukkit.plugin.java.JavaPlugin;
- public class main extends JavaPlugin{
- public final Logger logger = Logger.getLogger("Minecraft");
- public static main plugin;
- @Override
- public void onDisable() {
- PluginDescriptionFile pdfFile = this.getDescription();
- this.logger.info(pdfFile.getName() + " s-a dezactivat!");
- }
- @Override
- public void onEnable() {
- PluginDescriptionFile pdfFile = this.getDescription();
- this.logger.info(pdfFile.getName() + " versiunea " + pdfFile.getVersion() + " s-a activat!");
- openConnection();
- createTable();
- closeConnection();
- }
- public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {
- Player player = (Player)sender;
- if(commandLabel.equalsIgnoreCase("arena")) {
- if(args.length == 0){
- player.sendMessage("Foloseste /arena join");
- return true;
- }
- if(args[0].equalsIgnoreCase("join")) {
- addPlayer(player);
- return true;
- }
- }
- return true;
- }
- private static Connection connection;
- static String table = "event1";
- public static void openConnection() {
- try
- {
- connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/ArenaEvent", "root", "");
- }
- catch(Exception e)
- {
- e.printStackTrace();
- }
- }
- public static void closeConnection() {
- try
- {
- connection.close();
- }
- catch(Exception e)
- {
- e.printStackTrace();
- }
- }
- public static void createTable() {
- try{
- PreparedStatement sql = connection.prepareStatement("CREATE TABLE IF NOT EXISTS " + table + " (ID INT(11) NOT NULL AUTO_INCREMENT, USERNAME VARCHAR(17), primary key (ID));");
- sql.execute();
- sql.close();
- }catch (Exception e){
- e.printStackTrace();
- }
- }
- public void addPlayer(Player player) {
- if(!checkPlayer(player)){
- try{
- openConnection();
- PreparedStatement sql = connection.prepareStatement("INSERT INTO `" + table + "` (USERNAME) VALUES (" + player + ");");
- sql.execute();
- sql.close();
- }catch (Exception e){
- e.printStackTrace();
- } finally {
- closeConnection();
- }
- }else{
- player.sendMessage(ChatColor.RED + "Esti deja inscris!");
- }
- }
- public synchronized static boolean checkPlayer(Player player){
- try{
- openConnection();
- PreparedStatement sql = connection.prepareStatement("SELECT * FROM `" + table + "` WHERE username=" + player + ";");
- ResultSet resultSet = sql.executeQuery();
- boolean containsPlayer = resultSet.next();
- sql.close();
- resultSet.close();
- return containsPlayer;
- } catch(Exception e){
- e.printStackTrace();
- return false;
- } finally {
- closeConnection();
- }
- }
- public void select() {
- try{
- PreparedStatement sql = connection.prepareStatement("SELECT id FROM " + table + ";");
- sql.execute();
- sql.close();
- } catch (Exception e){
- e.printStackTrace();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement