Advertisement
Guest User

Untitled

a guest
Jan 28th, 2018
191
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.86 KB | None | 0 0
  1. package sk.YMasterSk.VIP;
  2.  
  3. import java.sql.Connection;
  4. import java.sql.DriverManager;
  5. import java.sql.SQLException;
  6. import java.sql.Statement;
  7. import java.text.DateFormat;
  8. import java.text.SimpleDateFormat;
  9. import java.util.Calendar;
  10. import java.util.Date;
  11.  
  12. import org.bukkit.Bukkit;
  13. import org.bukkit.command.Command;
  14. import org.bukkit.command.CommandSender;
  15. import org.bukkit.plugin.java.JavaPlugin;
  16.  
  17. public class Main extends JavaPlugin {
  18.  
  19. static String JDBCuser;
  20. static String JDBCpass;
  21. static String JDBCurl;
  22. static Connection connection;
  23. static Statement st;
  24. private static final DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  25.  
  26. public void onEnable(){
  27.  
  28. getConfig().options().copyDefaults(true);
  29. saveConfig();
  30.  
  31. JDBCuser = getConfig().getString("user");
  32. JDBCpass = getConfig().getString("password");
  33. JDBCurl = getConfig().getString("uri");
  34.  
  35. try {
  36.  
  37. connection = DriverManager.getConnection(JDBCurl, JDBCuser, JDBCpass);
  38.  
  39. Bukkit.getConsoleSender().sendMessage("§8[§cVIP§8] §aVIP has been connected to MySQL Server!");
  40.  
  41. st = connection.createStatement();
  42. st.execute("CREATE TABLE IF NOT EXISTS `vip` (`steamid` VARCHAR(20), `timestamp` VARCHAR(40), `enddate` VARCHAR(40));");
  43.  
  44. } catch (SQLException e){
  45.  
  46. Bukkit.getPluginManager().disablePlugin(this);
  47.  
  48. Bukkit.getConsoleSender().sendMessage("§8[§cVIP§8] §cCouldn't connect to MySQL database, disabling plugin.");
  49. Bukkit.getConsoleSender().sendMessage("§8[§cVIP§8] §7SQLException: §a" + e.getMessage());
  50. Bukkit.getConsoleSender().sendMessage("§8[§cVIP§8] §7SQLState: §a" + e.getSQLState());
  51.  
  52. }
  53.  
  54. }
  55.  
  56. public void onDisable(){
  57.  
  58. try {
  59.  
  60. if(connection != null && connection.isClosed()){
  61.  
  62. connection.close();
  63.  
  64. }
  65.  
  66. } catch (Exception e){
  67.  
  68. e.printStackTrace();
  69.  
  70. }
  71.  
  72. }
  73.  
  74. public void setVIP(String steamid){
  75.  
  76. try {
  77.  
  78. Date cd = new Date();
  79. Calendar c = Calendar.getInstance();
  80. c.setTime(cd);
  81.  
  82. c.add(Calendar.DATE, 31);
  83.  
  84. Date nd = c.getTime();
  85.  
  86. st.execute("INSERT INTO `vip` (`steamid`, `timestamp`, `enddate`) VALUES ('" + steamid + "', '" + df.format(cd) + "', '" + df.format(nd) + "');");
  87.  
  88. } catch (Exception e){
  89.  
  90. e.printStackTrace();
  91.  
  92. }
  93.  
  94. }
  95.  
  96. public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args){
  97.  
  98. if(cmd.getName().equalsIgnoreCase("vipadd")){
  99.  
  100. if(sender.hasPermission("*")){
  101.  
  102. if(args.length == 1){
  103.  
  104. String steamid = args[0];
  105.  
  106. setVIP(steamid);
  107.  
  108. sender.sendMessage("§7Inserted to database, where Steam ID is: §a" + steamid);
  109.  
  110. }else {
  111.  
  112. sender.sendMessage("§cUsage: §7/vipadd <steamid>");
  113.  
  114. }
  115.  
  116. }
  117.  
  118. }
  119. return false;
  120.  
  121. }
  122.  
  123. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement