Skip to content

Commit

Permalink
Updated to 1.15.2
Browse files Browse the repository at this point in the history
Also changed how the plugin connects to databases
  • Loading branch information
RoinujNosde committed Apr 5, 2020
1 parent 5f40968 commit 119b7d4
Show file tree
Hide file tree
Showing 12 changed files with 326 additions and 235 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/target/
/.classpath
/.project
2 changes: 2 additions & 0 deletions .settings/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/org.eclipse.jdt.core.prefs
/org.eclipse.m2e.core.prefs
58 changes: 58 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>net.epconsortium</groupId>
<artifactId>CryptoMarket</artifactId>
<version>1.0.1</version>
<name>CryptoMarket</name>
<description>A plugin that brings the cryptocoins market experience to your server!</description>
<url>https://www.spigotmc.org/resources/cryptomarket.69031/</url>

<build>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
<showDeprecation>true</showDeprecation>
<showWarnings>true</showWarnings>
</configuration>
</plugin>
</plugins>
</build>

<repositories>
<repository>
<id>vault-repo</id>
<url>http://nexus.hc.to/content/repositories/pub_releases</url>
</repository>
<repository>
<id>paper-repo</id>
<url>https://repo.destroystokyo.com/repository/maven-public/</url>
</repository>
</repositories>

<dependencies>
<dependency>
<groupId>com.destroystokyo.paper</groupId>
<artifactId>paper-api</artifactId>
<version>1.15.2-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>net.milkbowl.vault</groupId>
<artifactId>VaultAPI</artifactId>
<version>1.7</version>
<scope>provided</scope>
</dependency>
</dependencies>
</project>
41 changes: 25 additions & 16 deletions src/main/java/net/epconsortium/cryptomarket/CryptoMarket.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import org.bukkit.plugin.PluginManager;
import org.bukkit.plugin.RegisteredServiceProvider;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.scheduler.BukkitRunnable;

import java.util.logging.Level;
import net.epconsortium.cryptomarket.database.dao.InvestorDao;
Expand Down Expand Up @@ -57,30 +58,38 @@ public void onEnable() {
return;
}

// Atualizando as cotações
ExchangeRates rates = new ExchangeRates(this);
rates.updateAll();
// Iniciando tarefa repetitiva de atualizacão de cotações
updateRates = new UpdateExchangeRatesTask(rates);
updateRates.start(this);
//Starting the Save Investors task
saveInvestors = new SaveInvestorsTask(this);
saveInvestors.start();

debug = getConfig().getBoolean("debug", false);

InvestorDao.configureDatabase(this, (success) -> {
if (!success) {
getServer().getPluginManager().disablePlugin(this);
} else {
getServer().getConsoleSender().sendMessage(
"[CryptoMarket] Database configured successfuly!");
}
new BukkitRunnable() {

@Override
public void run() {
if (!success) {
getServer().getPluginManager().disablePlugin(CryptoMarket.this);
} else {
getServer().getConsoleSender().sendMessage(
"[CryptoMarket] Database configured successfuly!");

ExchangeRates rates = new ExchangeRates(CryptoMarket.this);
rates.updateAll();

updateRates = new UpdateExchangeRatesTask(rates);
updateRates.start(CryptoMarket.this);

saveInvestors = new SaveInvestorsTask(CryptoMarket.this);
saveInvestors.start();
}
}
}.runTask(this);

});
}

@Override
public void onDisable() {
if (saveInvestors == null || updateRates == null) return;

new InvestorDao(this).saveAll();
saveInvestors.cancel();
updateRates.cancel();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ public boolean onCommand(CommandSender commandSender, Command command,
String label, String[] args) {
if (commandSender instanceof Player) {
Player player = (Player) commandSender;
player.sendMessage("Entity ID for "+ player.getName() + "is " +player.getEntityId());

if (args.length != 0) {
String subCommand = args[0].toLowerCase();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
package net.epconsortium.cryptomarket.database;

import com.mysql.cj.jdbc.MysqlDataSource;
import net.epconsortium.cryptomarket.CryptoMarket;
import net.epconsortium.cryptomarket.util.Configuration;
import org.sqlite.SQLiteDataSource;

import java.io.File;
import java.io.IOException;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.Objects;
import java.util.Properties;

import net.epconsortium.cryptomarket.CryptoMarket;
import net.epconsortium.cryptomarket.util.Configuration;

/**
* Class used to create a Connection object
Expand Down Expand Up @@ -58,10 +58,15 @@ private Connection getSQLiteConnection() throws SQLException {
} catch (IOException ex) {
throw new SQLException(ex);
}

SQLiteDataSource dataSource = new SQLiteDataSource();
dataSource.setUrl("jdbc:sqlite:" + file.getAbsolutePath());
Connection connection = dataSource.getConnection();

Connection connection = null;

try {
Class.forName("org.sqlite.JDBC");
connection = DriverManager.getConnection("jdbc:sqlite:" + file.getAbsolutePath());
} catch (ClassNotFoundException e) {
throw new SQLException(e);
}

return connection;
}
Expand All @@ -73,15 +78,21 @@ private Connection getSQLiteConnection() throws SQLException {
* @throws SQLException
*/
private Connection getMySQLConnection() throws SQLException {
MysqlDataSource dataSource = new MysqlDataSource();
dataSource.setUser(config.getMySQLUser());
dataSource.setPassword(config.getMySQLPassword());
dataSource.setServerName(config.getMySQLHostname());
dataSource.setPort(config.getMySQLPort());
dataSource.setDatabaseName(config.getMySQLDatabaseName());
dataSource.setUseSSL(false);
Connection connection = null;

Properties properties = new Properties();
properties.setProperty("user", config.getMySQLUser());
properties.setProperty("password", config.getMySQLPassword());
properties.setProperty("useSSL", "false");
properties.setProperty("characterEncoding", "utf-8");
properties.setProperty("autoReconnect", "true");

Connection connection = dataSource.getConnection();
try {
Class.forName("com.mysql.jdbc.Driver");
connection = DriverManager.getConnection("jdbc:mysql://" + config.getMySQLHostname() + ":" + config.getMySQLPort() + "/" + config.getMySQLDatabaseName(), properties);
} catch (ClassNotFoundException e) {
throw new SQLException(e);
}

return connection;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public void onInventoryClickEvent(InventoryClickEvent event) {
}
event.setCancelled(true);

if (event.getClickedInventory().getName().equals(
if (event.getView().getTitle().equals(
config.getCalendarMenuName())) {
if (processBackButton(event, player)) {
return;
Expand All @@ -48,7 +48,7 @@ public void onInventoryClickEvent(InventoryClickEvent event) {

@EventHandler
public void onInventoryClose(InventoryCloseEvent event) {
String name = event.getInventory().getName();
String name = event.getView().getTitle();
if (name == null || !name.equals(config.getCalendarMenuName())) {
return;
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/net/epconsortium/cryptomarket/ui/Helper.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class Helper {
static boolean isCustomInventory(InventoryClickEvent event) {
Objects.requireNonNull(event);

return event.getInventory().getName() != null
return event.getView().getTitle() != null
&& event.getCurrentItem() != null
&& event.getCurrentItem().hasItemMeta()
&& event.getCurrentItem().getItemMeta().hasDisplayName();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public void onInventoryClick(InventoryClickEvent event) {
}
event.setCancelled(true);

if (event.getClickedInventory().getName().equals(config.getMenuName())) {
if (event.getView().getTitle().equals(config.getMenuName())) {
if (processCoinsButton(event, player)) {
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public void onInventoryClickEvent(InventoryClickEvent event) {
}
event.setCancelled(true);

if (event.getInventory().getName().equals(config.getRankingMenuName())) {
if (event.getView().getTitle().equals(config.getRankingMenuName())) {
processBackButton(event, player);
}
}
Expand Down
Loading

0 comments on commit 119b7d4

Please sign in to comment.