Skip to content

Commit

Permalink
Merge pull request #71 from EpiCanard/develop
Browse files Browse the repository at this point in the history
V1.2.0
  • Loading branch information
EpiCanard authored May 18, 2019
2 parents a2562bd + 3cc36bf commit a65ade4
Show file tree
Hide file tree
Showing 39 changed files with 2,104 additions and 86 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,5 @@ Notes.java

# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
hs_err_pid*

dependency-reduced-pom.xml
40 changes: 36 additions & 4 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
<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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>fr.epicanard</groupId>
<artifactId>globalmarketchest</artifactId>
<version>1.1.0</version>
<version>1.2.0</version>
<name>GlobalMarketChest</name>
<description>Shop plugin to create economy between user</description>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<powermock.version>1.7.1</powermock.version>
<spigot.version>1.14.1-R0.1-SNAPSHOT</spigot.version>
</properties>
<build>
<finalName>${project.name}-${project.version}</finalName>
Expand All @@ -21,6 +22,28 @@
<directory>${basedir}/src/main/resources</directory>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.2.1</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<artifactSet>
<includes>
<include>org.apache.commons:commons-lang3</include>
</includes>
</artifactSet>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
<repositories>
<repository>
Expand All @@ -35,6 +58,10 @@
<id>lombok-repo</id>
<url>https://mvnrepository.com/artifact/org.projectlombok/lombok</url>
</repository>
<repository>
<id>apache-repo</id>
<url>https://mvnrepository.com/artifact/org.apache.commons/commons-lang3</url>
</repository>
</repositories>
<dependencies>
<!-- Unit test -->
Expand All @@ -61,7 +88,7 @@
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot</artifactId>
<version>1.13.2-R0.1-SNAPSHOT</version>
<version>${spigot.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
Expand All @@ -70,5 +97,10 @@
<version>1.7</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.2.1</version>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import fr.epicanard.globalmarketchest.commands.CommandNode;
import fr.epicanard.globalmarketchest.permissions.Permissions;
import fr.epicanard.globalmarketchest.shops.ShopInfo;
import fr.epicanard.globalmarketchest.utils.ChatUtils;
import fr.epicanard.globalmarketchest.utils.chat.ChatUtils;
import fr.epicanard.globalmarketchest.utils.LangUtils;
import fr.epicanard.globalmarketchest.utils.PlayerUtils;
import fr.epicanard.globalmarketchest.utils.WorldUtils;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public class HelpConsumer implements CommandConsumer {
public Boolean accept(CommandNode node, String command, CommandSender sender, String[] args) {
PlayerUtils.sendMessageConfig(sender, "Commands.HelpCommand.Usage");
PlayerUtils.sendMessageConfig(sender, "Commands.HelpCommand.Help");
PlayerUtils.sendMessageConfig(sender, "Commands.HelpCommand.Version");
if (Permissions.CMD_RELOAD.isSetOn(sender))
PlayerUtils.sendMessageConfig(sender, "Commands.HelpCommand.Reload");
if (Permissions.CMD_LIST.isSetOn(sender))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import fr.epicanard.globalmarketchest.commands.CommandNode;
import fr.epicanard.globalmarketchest.permissions.Permissions;
import fr.epicanard.globalmarketchest.shops.ShopInfo;
import fr.epicanard.globalmarketchest.utils.ChatUtils;
import fr.epicanard.globalmarketchest.utils.chat.ChatUtils;
import fr.epicanard.globalmarketchest.utils.LangUtils;
import net.md_5.bungee.api.ChatColor;
import net.md_5.bungee.api.chat.TextComponent;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
package fr.epicanard.globalmarketchest.configuration;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.util.function.UnaryOperator;

import org.bukkit.configuration.InvalidConfigurationException;
import org.bukkit.configuration.file.YamlConfiguration;

import fr.epicanard.globalmarketchest.GlobalMarketChest;
import fr.epicanard.globalmarketchest.exceptions.CantLoadConfigException;
import fr.epicanard.globalmarketchest.utils.Utils;
import lombok.Getter;

public class ConfigLoader {
Expand All @@ -27,33 +31,75 @@ public ConfigLoader() {
this.categories = null;
}

/**
* Save an InputStream inside a file already opened
*
* @param file File opened
* @param stream Stream to right inside
* @throws IOException
*/
private void saveStream(File file, InputStream stream) throws IOException {
OutputStream out = new FileOutputStream(file);
byte[] buf = new byte[1024];
int len;

while ((len = stream.read(buf)) > 0) {
out.write(buf, 0, len);
}
out.close();
stream.close();
}

/**
* Load one file from plugin folder and save it if it doesn't exist
*
* @throws CantLoadConfigException Throw this exception when the file can't be loaded (InvalidFile or wrong permissions)
* @param filename Name of the file that must be load
* @param path Path to get the file inside jar
* @return Return the yamlconfiguration file
*/
private YamlConfiguration loadOneFile(String fileName) throws CantLoadConfigException {
private YamlConfiguration loadOneFile(String fileName, String path, String alternatePath) throws CantLoadConfigException {
if (!fileName.substring(fileName.length() - 4).equals(".yml"))
fileName += ".yml";
final String finalFileName = fileName;

File confFile = new File(GlobalMarketChest.plugin.getDataFolder(), fileName);

if (!confFile.exists()) {
confFile.getParentFile().mkdirs();
GlobalMarketChest.plugin.saveResource(fileName, false);
}
final File confFile = new File(GlobalMarketChest.plugin.getDataFolder(), fileName);
final YamlConfiguration conf = new YamlConfiguration();

YamlConfiguration conf = new YamlConfiguration();
try {
if (!confFile.exists()) {
confFile.getParentFile().mkdirs();
final UnaryOperator<String> processPath = (p) -> (p != null ? p + "/" : "") + finalFileName;
InputStream stream = GlobalMarketChest.plugin.getResource(processPath.apply(path));
if (stream == null) {
if (alternatePath != null) {
stream = GlobalMarketChest.plugin.getResource(processPath.apply(alternatePath));
} else {
throw new CantLoadConfigException(fileName);
}
}

this.saveStream(confFile, stream);
}

conf.load(confFile);
return conf;
} catch (IOException | IllegalArgumentException | InvalidConfigurationException e) {
throw new CantLoadConfigException(fileName);
}
}

/**
* Load one file from plugin folder and save it if it doesn't exist
*
* @throws CantLoadConfigException Throw this exception when the file can't be loaded (InvalidFile or wrong permissions)
* @param filename Name of the file that must be load
* @return Return the yamlconfiguration file
*/
private YamlConfiguration loadOneFile(String fileName) throws CantLoadConfigException {
return this.loadOneFile(fileName, null, null);
}

/**
* Load one resource from jar. It doesn't extract it from the jar
*
Expand All @@ -77,13 +123,11 @@ public void loadFiles() throws CantLoadConfigException {
this.categories = null;
this.languages = null;

this.config = this.loadOneFile("config.yml");
this.categories = this.loadOneFile("categories.yml");
this.config = this.loadOneFile("config.yml", Utils.getVersion(), Utils.getLastSupportedVersion());
this.categories = this.loadOneFile("categories.yml", Utils.getVersion(), Utils.getLastSupportedVersion());
if (this.config != null) {
String tmp = this.config.getString("General.Lang");
if (tmp == null)
tmp = "lang-en_EN.yml";
this.languages = this.loadOneFile(tmp);
final String langFilename = this.config.getString("General.Lang", "lang-en_US.yml");
this.languages = this.loadOneFile(langFilename, "langs", null);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.Properties;

import org.apache.commons.lang3.tuple.Pair;

import fr.epicanard.globalmarketchest.GlobalMarketChest;
import fr.epicanard.globalmarketchest.exceptions.ConfigException;

public abstract class DatabaseConnection {
protected Properties properties = new Properties();
protected String host;
protected String port;
protected String database;
Expand All @@ -19,7 +21,7 @@ public abstract class DatabaseConnection {
public static String tableAuctions = "GMC_auctions";
public static String tableShops = "GMC_shops";

public static void configureTables() throws ConfigException {
public static void configureTables() throws ConfigException {
String prefix = GlobalMarketChest.plugin.getConfigLoader().getConfig().getString("Connection.TablePrefix");
if (prefix == null)
return;
Expand All @@ -31,7 +33,7 @@ public static void configureTables() throws ConfigException {
}

protected String buildUrl() {
return String.format("%s:%s/%s?autoReconnect=true", this.host, this.port, this.database);
return String.format("%s:%s/%s", this.host, this.port, this.database);
}

protected abstract Connection connect() throws ConfigException;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Properties;
import java.util.concurrent.LinkedBlockingQueue;

import org.apache.commons.lang3.tuple.Pair;
Expand Down Expand Up @@ -82,21 +83,28 @@ public void configFromConfigFile() throws ConfigException {
this.user = config.getString("Connection.User");
this.password = config.getString("Connection.Password");

if (this.host == null || this.port == null || this.database == null || this.user == null
|| this.password == null)
final String useSSL = config.getString("Connection.UseSSL");
if (useSSL != null) {
this.properties.put("useSSL", useSSL);
}
this.properties.put("autoReconnect", "true");
this.properties.put("user", this.user);
this.properties.put("password", this.password);

if (this.host == null || this.port == null || this.database == null || this.user == null || this.password == null)
throw new ConfigException("Some database informations are missing");
}

/**
* Create connection to database
*
* @return Connection
*/
@Override
protected Connection connect() throws ConfigException {
try {
Class.forName("com.mysql.jdbc.Driver");
return DriverManager.getConnection("jdbc:mysql://" + this.buildUrl(),
this.user, this.password);
return DriverManager.getConnection("jdbc:mysql://" + this.buildUrl(), new Properties(this.properties));
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (SQLException e) {
Expand All @@ -120,6 +128,7 @@ protected void disconnect(Connection connection) {

/**
* Get a connection from the pool or create it is no connected
*
* @return Connection
*/
@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package fr.epicanard.globalmarketchest.exceptions;

import fr.epicanard.globalmarketchest.utils.Utils;

public class MissingMethodException extends Exception {

static final long serialVersionUID = -7914157352976633988L;

public MissingMethodException(String methodName) {
super(String.format("Missing method %s for versions %s and latest", methodName, Utils.getVersion()));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
import fr.epicanard.globalmarketchest.gui.shops.baseinterfaces.ShopInterface;
import fr.epicanard.globalmarketchest.gui.shops.Warning;
import fr.epicanard.globalmarketchest.utils.LangUtils;
import fr.epicanard.globalmarketchest.utils.PlayerUtils;
import fr.epicanard.globalmarketchest.utils.Utils;
import fr.epicanard.globalmarketchest.utils.chat.ChatUtils;
import lombok.Getter;

/**
Expand Down Expand Up @@ -82,7 +82,9 @@ public void setChatReturn(String value) {
this.chatEditing = false;
this.open();
this.player.removePotionEffect(PotionEffectType.BLINDNESS);
this.chatConsumer.accept(value);
if (value != null) {
this.chatConsumer.accept(value);
}
this.chatConsumer = null;
}

Expand All @@ -97,9 +99,7 @@ public void openChat(String path, Consumer<String> consumer) {
this.close();
this.player.addPotionEffect(new PotionEffect(PotionEffectType.BLINDNESS, Integer.MAX_VALUE, 1), true);
this.chatConsumer = consumer;
this.player.sendMessage("");
PlayerUtils.sendMessage(this.player, LangUtils.get(path));
this.player.sendMessage("");
ChatUtils.newConversation(this.player, LangUtils.get(path)).begin();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
import fr.epicanard.globalmarketchest.GlobalMarketChest;
import fr.epicanard.globalmarketchest.exceptions.InvalidPaginatorParameter;
import fr.epicanard.globalmarketchest.utils.Utils;
import fr.epicanard.globalmarketchest.utils.Reflection.VersionSupportUtils;
import fr.epicanard.globalmarketchest.utils.reflection.VersionSupportUtils;
import lombok.Getter;
import lombok.Setter;

Expand Down
Loading

0 comments on commit a65ade4

Please sign in to comment.