Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package husky.staffpin;
- import java.io.File;
- import java.io.IOException;
- import java.sql.Connection;
- import java.sql.DriverManager;
- import java.sql.SQLException;
- import java.sql.Statement;
- import java.util.ArrayList;
- import java.util.HashMap;
- import java.util.List;
- import java.util.logging.Logger;
- 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.entity.Player;
- import org.bukkit.plugin.Plugin;
- import org.bukkit.plugin.java.JavaPlugin;
- import husky.staffpin.Events.EventListener;
- public class Main
- extends JavaPlugin
- {
- public static Plugin plugin;
- static FileConfiguration config;
- HashMap<Player, Integer> attempts = new HashMap();
- public static List<Player> notLoggedIn = new ArrayList();
- private Connection connection;
- public String host, database, username, password, table;
- public int port;
- public void onEnable()
- {
- new EventListener(this);
- plugin = this;
- saveDefaultConfig();
- getLogger().info("Staff Pin has been enabled");
- config = getConfig();
- mysqlSetup();
- }
- public void onDisable()
- {
- getLogger().info("Staff Pin has been disabled");
- }
- public void mysqlSetup() {
- host = "localhost";
- port = 3306;
- database = "mcadmin";
- username = "root";
- password = "";
- Connection conn;
- Statement s;
- try{
- synchronized (this){
- if(getConnection() != null && !getConnection().isClosed()){
- return;
- }
- Class.forName("com.mysql.jdbc.Driver");
- setConnection( DriverManager.getConnection("jdbc:mysql://" + this.host + ":"
- + this.port + "/" + this.database, this.username, this.password));
- Bukkit.getConsoleSender().sendMessage(ChatColor.GREEN + "MYSQL CONNECTED");
- }
- }catch(SQLException e){
- e.printStackTrace();
- }catch(ClassNotFoundException e){
- e.printStackTrace();
- }
- }
- public Connection getConnection() {
- return connection;
- }
- public void setConnection(Connection connection) {
- this.connection = connection;
- }
- public static FileConfiguration getConfiguration()
- {
- return config;
- }
- public static void saveConfig(FileConfiguration config)
- {
- File file = new File(plugin.getDataFolder(), "config.yml");
- try
- {
- config.save(file);
- }
- catch (IOException e)
- {
- e.printStackTrace();
- }
- }
- String prefix = ChatColor.RED + "Staff Pin ";
- public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args)
- {
- if ((cmd.getName().equalsIgnoreCase("pin")) && ((sender instanceof Player)) && (args.length == 1))
- {
- Player player = (Player)sender;
- if (player.hasPermission("staff.pin"))
- {
- if (!this.attempts.containsKey(player)) {
- this.attempts.put(player, Integer.valueOf(0));
- }
- if (!notLoggedIn.contains(player))
- {
- player.sendMessage(this.prefix + ChatColor.RED + "You have already entered your pin!");
- return true;
- }
- if (args[0].equalsIgnoreCase())
- {
- notLoggedIn.remove(player);
- this.attempts.remove(player);
- player.sendMessage(this.prefix + ChatColor.GRAY + "Pin recognized. Welcome, " + player.getDisplayName() + ChatColor.GRAY + ".");
- return true;
- }
- if (!args[0].equalsIgnoreCase(config.getString(player.getName())))
- {
- this.attempts.replace(player, Integer.valueOf(((Integer)this.attempts.get(player)).intValue() + 1));
- if (((Integer)this.attempts.get(player)).intValue() >= 3) {
- Bukkit.getServer().dispatchCommand(Bukkit.getServer().getConsoleSender(), "ban " + player.getName() + " Invalid Pin (Contact SMT)");
- }
- 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!");
- return true;
- }
- }
- }
- return false;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement