Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package me.Austin.Stocks;
- import java.io.File;
- import java.io.InputStream;
- import java.sql.DriverManager;
- import java.sql.SQLException;
- import java.util.logging.Logger;
- import org.bukkit.command.Command;
- import org.bukkit.command.CommandSender;
- import org.bukkit.configuration.file.FileConfiguration;
- import org.bukkit.configuration.file.YamlConfiguration;
- import org.bukkit.plugin.java.JavaPlugin;
- import com.mysql.jdbc.Connection;
- import com.mysql.jdbc.Statement;
- public class Stocks extends JavaPlugin {
- private static Stocks instance;
- Logger logger = this.getLogger();
- static final String DB_NAME = "jdbc:mysql://localhost:3306/minecraft";
- static final String USER = "root";
- static final String PASS = "password";
- Connection conn;
- Statement s;
- public void onEnable() {
- logger.info("Stock market is enabling for the server");
- saveConfig();
- savemarketYML();
- try {
- Class.forName("com.mysql.jdbc.Driver"); // Gets the driver class
- getLogger().info("About to connect to database"); // These are just
- // for debugging
- // purposes.
- conn = (Connection) DriverManager.getConnection(DB_NAME, USER, PASS); // Gets
- // a
- // connection
- // to
- // the
- // database
- // using
- // the
- // details
- // you
- // provided.
- getLogger().info("Successfully connected.");
- getLogger().info("About to create a statement");
- s = (Statement) conn.createStatement(); // Creates a statement. You
- // can execute queries on
- // this.
- getLogger().info("Successfully created statement.");
- } catch (Exception ex) {
- ex.printStackTrace();
- }
- }
- private FileConfiguration marketYML = null;
- private File marketYMLFile = null;
- public void reloadMarketYMLFile() {
- if (marketYMLFile == null) {
- marketYMLFile = new File(getDataFolder(), "Market.yml");
- }
- marketYML = YamlConfiguration.loadConfiguration(marketYMLFile);
- InputStream defConfigStream = this.getResource("Market.yml");
- if (defConfigStream != null) {
- @SuppressWarnings("deprecation")
- YamlConfiguration defConfig = YamlConfiguration.loadConfiguration(defConfigStream);
- marketYML.setDefaults(defConfig);
- }
- }
- private void savemarketYML() {
- if (marketYML == null) {
- this.reloadMarketYMLFile();
- }
- }
- public FileConfiguration getMarketYML() {
- if (marketYML == null) {
- reloadMarketYMLFile();
- }
- return marketYML;
- }
- public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {
- if (commandLabel.equalsIgnoreCase("open")) {
- try {
- openMarket.openMarket(getConfig().getString("openMarketMSG"));
- } catch (SQLException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
- if (commandLabel.equalsIgnoreCase("buy")) {
- if (args.length != 0) {
- try {
- int number = Integer.parseInt(args[1]);
- buyStock.buy(args[0], number);
- } catch (SQLException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- } else {
- sender.sendMessage("Error");
- }
- }
- return false;
- }
- public static Stocks get() {
- return instance;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement