Advertisement
Guest User

Untitled

a guest
Jan 8th, 2018
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.18 KB | None | 0 0
  1. package husky.staffpin;
  2.  
  3. import java.io.File;
  4. import java.io.IOException;
  5. import java.sql.Connection;
  6. import java.sql.DriverManager;
  7. import java.sql.SQLException;
  8. import java.sql.Statement;
  9. import java.util.ArrayList;
  10. import java.util.HashMap;
  11. import java.util.List;
  12. import java.util.logging.Logger;
  13. import org.bukkit.Bukkit;
  14. import org.bukkit.ChatColor;
  15. import org.bukkit.Server;
  16. import org.bukkit.command.Command;
  17. import org.bukkit.command.CommandSender;
  18. import org.bukkit.configuration.file.FileConfiguration;
  19. import org.bukkit.entity.Player;
  20. import org.bukkit.plugin.Plugin;
  21. import org.bukkit.plugin.java.JavaPlugin;
  22.  
  23. import husky.staffpin.Events.EventListener;
  24.  
  25. public class Main
  26. extends JavaPlugin
  27. {
  28. public static Plugin plugin;
  29. static FileConfiguration config;
  30. HashMap<Player, Integer> attempts = new HashMap();
  31. public static List<Player> notLoggedIn = new ArrayList();
  32.  
  33. private Connection connection;
  34. public String host, database, username, password, table;
  35. public int port;
  36.  
  37. public void onEnable()
  38. {
  39. new EventListener(this);
  40. plugin = this;
  41. saveDefaultConfig();
  42. getLogger().info("Staff Pin has been enabled");
  43. config = getConfig();
  44. mysqlSetup();
  45. }
  46.  
  47. public void onDisable()
  48. {
  49. getLogger().info("Staff Pin has been disabled");
  50. }
  51.  
  52. public void mysqlSetup() {
  53. host = "localhost";
  54. port = 3306;
  55. database = "mcadmin";
  56. username = "root";
  57. password = "";
  58. Connection conn;
  59. Statement s;
  60. try{
  61.  
  62. synchronized (this){
  63. if(getConnection() != null && !getConnection().isClosed()){
  64. return;
  65. }
  66.  
  67. Class.forName("com.mysql.jdbc.Driver");
  68. setConnection( DriverManager.getConnection("jdbc:mysql://" + this.host + ":"
  69. + this.port + "/" + this.database, this.username, this.password));
  70.  
  71. Bukkit.getConsoleSender().sendMessage(ChatColor.GREEN + "MYSQL CONNECTED");
  72. }
  73. }catch(SQLException e){
  74. e.printStackTrace();
  75. }catch(ClassNotFoundException e){
  76. e.printStackTrace();
  77. }
  78. }
  79.  
  80. public Connection getConnection() {
  81. return connection;
  82. }
  83.  
  84. public void setConnection(Connection connection) {
  85. this.connection = connection;
  86. }
  87.  
  88.  
  89.  
  90. public static FileConfiguration getConfiguration()
  91. {
  92. return config;
  93. }
  94.  
  95. public static void saveConfig(FileConfiguration config)
  96. {
  97. File file = new File(plugin.getDataFolder(), "config.yml");
  98. try
  99. {
  100. config.save(file);
  101. }
  102. catch (IOException e)
  103. {
  104. e.printStackTrace();
  105. }
  106. }
  107.  
  108. String prefix = ChatColor.RED + "Staff Pin ";
  109.  
  110. public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args)
  111. {
  112.  
  113. if ((cmd.getName().equalsIgnoreCase("pin")) && ((sender instanceof Player)) && (args.length == 1))
  114. {
  115. Player player = (Player)sender;
  116. if (player.hasPermission("staff.pin"))
  117. {
  118. if (!this.attempts.containsKey(player)) {
  119. this.attempts.put(player, Integer.valueOf(0));
  120. }
  121. if (!notLoggedIn.contains(player))
  122. {
  123. player.sendMessage(this.prefix + ChatColor.RED + "You have already entered your pin!");
  124. return true;
  125. }
  126. if (args[0].equalsIgnoreCase())
  127. {
  128. notLoggedIn.remove(player);
  129. this.attempts.remove(player);
  130. player.sendMessage(this.prefix + ChatColor.GRAY + "Pin recognized. Welcome, " + player.getDisplayName() + ChatColor.GRAY + ".");
  131. return true;
  132. }
  133. if (!args[0].equalsIgnoreCase(config.getString(player.getName())))
  134. {
  135. this.attempts.replace(player, Integer.valueOf(((Integer)this.attempts.get(player)).intValue() + 1));
  136. if (((Integer)this.attempts.get(player)).intValue() >= 3) {
  137. Bukkit.getServer().dispatchCommand(Bukkit.getServer().getConsoleSender(), "ban " + player.getName() + " Invalid Pin (Contact SMT)");
  138. }
  139. player.sendMessage(this.prefix + ChatColor.GRAY + "Incorrect pin! You have " + ChatColor.BOLD + (3 - ((Integer)this.attempts.get(player)).intValue()) + ChatColor.GRAY + " attempts remaining until you are banned!");
  140. return true;
  141. }
  142. }
  143. }
  144. return false;
  145. }
  146. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement