Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import org.bukkit.command.Command;
- import org.bukkit.command.CommandExecutor;
- import org.bukkit.command.CommandSender;
- import org.bukkit.entity.Player;
- import org.bukkit.plugin.java.JavaPlugin;
- import java.sql.*;
- public class Main extends JavaPlugin {
- String host, port, database, username, password;
- static Connection c;
- @Override
- public void onEnable() {
- this.getCommand("stats").setExecutor(new Stats());
- host = "localhost";
- port = "3306";
- database = "TestDatabase";
- username = "user";
- password = "pass";
- try {
- openConnection();
- Statement statement = c.createStatement();
- } catch (ClassNotFoundException e) {
- e.printStackTrace();
- } catch (SQLException e) {
- e.printStackTrace();
- }
- }
- @Override
- public void onDisable() {
- }
- public void openConnection() throws SQLException, ClassNotFoundException {
- if (c != null && !c.isClosed()) {
- return;
- }
- Class.forName("com.mysql.jdbc.Driver");
- c = DriverManager.getConnection("jdbc:mysql://"
- + this.host + ":" + this.port + "/" + this.database,
- this.username, this.password);
- }
- //statement.executeUpdate("INSERT INTO SStats (PLAYERNAME, BALANCE) VALUES ('Playername', 100);");
- public class Stats implements CommandExecutor {
- //This method is called, when somebody uses our command
- @Override
- public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
- if (sender instanceof Player) {
- ResultSet result = statement.executeUpdate("INSERT INTO...blablabla");
- }
- }
- // If the player (or console) uses our command correct, we can return true
- return true;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement