Update dependencies and IDE suggestions (#8)

Update dependencies and IDE suggestions

Signed-off-by: Etzelia <etzelia@hotmail.com>

Reviewed-on: https://git.etztech.xyz/Minecraft/PluginAPI/pulls/8
Reviewed-by: ZeroHD <joey@ahines.net>
pull/2/head
Etzelia 2020-08-12 02:44:04 +02:00
parent ca49c89440
commit 787a47108a
4 changed files with 18 additions and 22 deletions

View File

@ -6,7 +6,7 @@
<groupId>xyz.etztech</groupId> <groupId>xyz.etztech</groupId>
<artifactId>plugin-api</artifactId> <artifactId>plugin-api</artifactId>
<version>1.0.6</version> <version>1.0.7</version>
<build> <build>
<plugins> <plugins>
<plugin> <plugin>
@ -30,12 +30,12 @@
<dependency> <dependency>
<groupId>com.zaxxer</groupId> <groupId>com.zaxxer</groupId>
<artifactId>HikariCP</artifactId> <artifactId>HikariCP</artifactId>
<version>2.6.1</version> <version>3.4.5</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>com.h2database</groupId> <groupId>com.h2database</groupId>
<artifactId>h2</artifactId> <artifactId>h2</artifactId>
<version>1.4.197</version> <version>1.4.200</version>
</dependency> </dependency>
</dependencies> </dependencies>

View File

@ -11,13 +11,13 @@ import java.sql.SQLException;
* A class to initialize an H2 database and retrieve connections * A class to initialize an H2 database and retrieve connections
*/ */
public class DataSource { public class DataSource {
private HikariConfig config = new HikariConfig(); private final HikariDataSource dataSource;
private HikariDataSource dataSource;
/** Create a data source for a plugin /** Create a data source for a plugin
* @param plugin The plugin using this database. Used for creation purposes. * @param plugin The plugin using this database. Used for creation purposes.
*/ */
public DataSource(JavaPlugin plugin) { public DataSource(JavaPlugin plugin) {
HikariConfig config = new HikariConfig();
config.setJdbcUrl("jdbc:h2:" + plugin.getDataFolder().getAbsolutePath() + "/" + plugin.getName().toLowerCase()); config.setJdbcUrl("jdbc:h2:" + plugin.getDataFolder().getAbsolutePath() + "/" + plugin.getName().toLowerCase());
config.setDriverClassName("org.h2.Driver"); config.setDriverClassName("org.h2.Driver");
dataSource = new HikariDataSource(config); dataSource = new HikariDataSource(config);

View File

@ -21,10 +21,10 @@ import java.util.List;
public class MultipartUtility { public class MultipartUtility {
private final String boundary; private final String boundary;
private static final String LINE_FEED = "\r\n"; private static final String LINE_FEED = "\r\n";
private HttpURLConnection httpConn; private final HttpURLConnection httpConn;
private String charset; private final String charset;
private OutputStream outputStream; private final OutputStream outputStream;
private PrintWriter writer; private final PrintWriter writer;
/** /**
* This constructor initializes a new HTTP POST request where content type * This constructor initializes a new HTTP POST request where content type
@ -59,10 +59,10 @@ public class MultipartUtility {
* @param value field value * @param value field value
*/ */
public void addFormField(String name, String value) { public void addFormField(String name, String value) {
writer.append("--" + boundary).append(LINE_FEED); writer.append("--").append(boundary).append(LINE_FEED);
writer.append("Content-Disposition: form-data; name=\"" + name + "\"") writer.append("Content-Disposition: form-data; name=\"").append(name).append("\"")
.append(LINE_FEED); .append(LINE_FEED);
writer.append("Content-Type: text/plain; charset=" + charset).append( writer.append("Content-Type: text/plain; charset=").append(charset).append(
LINE_FEED); LINE_FEED);
writer.append(LINE_FEED); writer.append(LINE_FEED);
writer.append(value).append(LINE_FEED); writer.append(value).append(LINE_FEED);
@ -78,14 +78,10 @@ public class MultipartUtility {
public void addFilePart(String fieldName, File uploadFile) public void addFilePart(String fieldName, File uploadFile)
throws IOException { throws IOException {
String fileName = uploadFile.getName(); String fileName = uploadFile.getName();
writer.append("--" + boundary).append(LINE_FEED); writer.append("--").append(boundary).append(LINE_FEED);
writer.append( writer.append("Content-Disposition: form-data; name=\"").append(fieldName).append("\"; filename=\"").append(fileName).append("\"")
"Content-Disposition: form-data; name=\"" + fieldName
+ "\"; filename=\"" + fileName + "\"")
.append(LINE_FEED); .append(LINE_FEED);
writer.append( writer.append("Content-Type: ").append(URLConnection.guessContentTypeFromName(fileName))
"Content-Type: "
+ URLConnection.guessContentTypeFromName(fileName))
.append(LINE_FEED); .append(LINE_FEED);
writer.append("Content-Transfer-Encoding: binary").append(LINE_FEED); writer.append("Content-Transfer-Encoding: binary").append(LINE_FEED);
writer.append(LINE_FEED); writer.append(LINE_FEED);
@ -110,7 +106,7 @@ public class MultipartUtility {
* @param value - value of the header field * @param value - value of the header field
*/ */
public void addHeaderField(String name, String value) { public void addHeaderField(String name, String value) {
writer.append(name + ": " + value).append(LINE_FEED); writer.append(name).append(": ").append(value).append(LINE_FEED);
writer.flush(); writer.flush();
} }
@ -123,7 +119,7 @@ public class MultipartUtility {
StringBuilder response = new StringBuilder(); StringBuilder response = new StringBuilder();
//writer.append(LINE_FEED).flush(); //writer.append(LINE_FEED).flush();
writer.append("--" + boundary + "--").append(LINE_FEED); writer.append("--").append(boundary).append("--").append(LINE_FEED);
writer.close(); writer.close();
// checks server's status code first // checks server's status code first

View File

@ -18,7 +18,7 @@ public class Response {
private Boolean status; private Boolean status;
private String message; private String message;
private static Logger log = Logger.getLogger("Minecraft"); private static final Logger log = Logger.getLogger("Minecraft");
/** /**
* @param httpResponse A JSON array e.g. multiple results from one call * @param httpResponse A JSON array e.g. multiple results from one call