Skip to content

Commit

Permalink
v1.2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
hypothermic committed Feb 24, 2018
1 parent b451f99 commit 310b9a5
Show file tree
Hide file tree
Showing 5 changed files with 111 additions and 37 deletions.
13 changes: 10 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ You can download the JAR [here](../../releases/).
**Administrator commands**
*Permission: tekkitreference.admin*
- `/ref admin reload`
- `/ref admin info`

**Availible filters**
- `all`
Expand All @@ -33,12 +34,18 @@ You can download the JAR [here](../../releases/).
5. Reload/restart your server. Check your console if the SQL connection succeeded.

## Changelog
**v1.2.0**
- Fixed search for items without data (ex. 151).
- Created seperate functionn for connecting to DB.
- Admin reload command now forces reconnect to DB.
- Replaces *null* with *N/A* in output.

**v1.1.0**
- Removed JFX toolkit and Services, plugin now works for CLI-only machines
- Added Item ID as search term
- Removed JFX toolkit and Services, plugin now works for CLI-only machines.
- Added Item ID as search term.

**v1.0.0**
- Initial version
- Initial version.

## TODO
- ~~Item ID as search term~~
Expand Down
7 changes: 6 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>nl.hypothermic</groupId>
<artifactId>tekkitreference</artifactId>
<version>1.1.0-RELEASE</version>
<version>1.2.0-RELEASE</version>
<name>TekkitReference</name>
<build>
<plugins>
Expand Down Expand Up @@ -34,5 +34,10 @@
<scope>system</scope>
<systemPath>${project.basedir}/src/main/resources/bukkit-unofficial-1.2.5-R5.0-hypothermic.jar</systemPath>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-model</artifactId>
<version>3.3.9</version>
</dependency>
</dependencies>
</project>
67 changes: 56 additions & 11 deletions src/main/java/nl/hypothermic/tekkitreference/trCommandExecutor.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package nl.hypothermic.tekkitreference;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Scanner;
Expand All @@ -16,10 +18,6 @@
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;

import javafx.concurrent.WorkerStateEvent;
import javafx.embed.swing.JFXPanel;
import javafx.event.EventHandler;

public class trCommandExecutor implements CommandExecutor {

/********************************\
Expand All @@ -30,13 +28,15 @@ public class trCommandExecutor implements CommandExecutor {
*---------= 21/02/2018 =---------*
\********************************/

public trCommandExecutor(trMain main, Connection conn) {
public trCommandExecutor(trMain main, Connection conn, String ver) {
this.cl = main;
this.sqlconn = conn;
this.ver = ver;
}

private final trMain cl;
private Connection sqlconn;
private String ver;

@Override public boolean onCommand(final CommandSender sender, Command cmd, String label, final String[] args) {
if (// aliases
Expand All @@ -58,7 +58,11 @@ public trCommandExecutor(trMain main, Connection conn) {
sender.sendMessage("You must be a player to use this command");
return false;
} else {
searchparam = ((Player) sender).getInventory().getItemInHand().getTypeId() + ":" + ((Player) sender).getInventory().getItemInHand().getData().getData();
if (((Player) sender).getInventory().getItemInHand().getData().getData() != 0) {
searchparam = ((Player) sender).getInventory().getItemInHand().getTypeId() + ":" + ((Player) sender).getInventory().getItemInHand().getData().getData();
} else {
searchparam = "" + ((Player) sender).getInventory().getItemInHand().getTypeId();
}
column = 1;
}
}
Expand All @@ -67,7 +71,11 @@ public trCommandExecutor(trMain main, Connection conn) {
sender.sendMessage("You must be a player to use this command");
return false;
} else {
searchparam = ((Player) sender).getTargetBlock(null, 100).getTypeId() + ":" + ((Player) sender).getTargetBlock(null, 100).getData();
if (((Player) sender).getInventory().getItemInHand().getData().getData() != 0) {
searchparam = ((Player) sender).getTargetBlock(null, 100).getTypeId() + ":" + ((Player) sender).getTargetBlock(null, 100).getData();
} else {
searchparam = "" + ((Player) sender).getTargetBlock(null, 100).getTypeId();
}
column = 1;
}
}
Expand All @@ -79,21 +87,41 @@ public trCommandExecutor(trMain main, Connection conn) {
if (args.length == 2) {
if (args[1].contains("reload")) {
cl.reloadConfig();
sender.sendMessage(ChatColor.GREEN + "" + ChatColor.BOLD + "[REF]" + ChatColor.RESET + ChatColor.WHITE + " Configuration has been reloaded.");
sender.sendMessage(ChatColor.GREEN + "" + ChatColor.BOLD + "[REF]" + ChatColor.RESET + ChatColor.WHITE + " Configuration has been reloaded, now reconnecting to database...");
try {
sqlconn.close();
DriverManager.setLoginTimeout(10);
sqlconn = DriverManager.getConnection("jdbc:mysql://" + cl.getConfig().getString("mysql-server") + "/" +
cl.getConfig().getString("mysql-database"),
cl.getConfig().getString("mysql-user") ,
cl.getConfig().getString("mysql-password"));
sender.sendMessage(ChatColor.GREEN + "" + ChatColor.BOLD + "[REF]" + ChatColor.RESET + ChatColor.WHITE + " Successfully reconnected to database.");
} catch (SQLException e) {
sender.sendMessage(ChatColor.GREEN + "" + ChatColor.BOLD + "[REF]" + ChatColor.RESET + ChatColor.RED + " Error: Could not connect to database!");
e.printStackTrace();
}
return true;
}
if (args[1].contains("info")) {
sender.sendMessage(ChatColor.GREEN + "" + ChatColor.BOLD + "[REF]" + ChatColor.RESET + ChatColor.WHITE + " TekkitReference " + ver + " by Hypothermic");
sender.sendMessage(ChatColor.GREEN + "" + ChatColor.BOLD + "[REF]" + ChatColor.RESET + ChatColor.WHITE + " www.github.com/hypothermic/tekkitreference");
return true;
}
// more cmds
}
sender.sendMessage(ChatColor.GREEN + "" + ChatColor.BOLD + "[REF]" + ChatColor.RESET + ChatColor.WHITE + " Usage: /ref admin <command>");
return true;
}
// ex: 151:2
if (args[0].contains(":")) {
String[] s = args[0].split(":");
if (s.length != 2 || s[0] == null || s[0] == "" || s[1] == null || s[1] == "") {
sender.sendMessage(ChatColor.GREEN + "" + ChatColor.BOLD + "[REF]" + ChatColor.RESET + ChatColor.WHITE + " Example: /ref 150:8");
}
Bukkit.getLogger().info("debug s: " + Arrays.toString(s));
Bukkit.getLogger().info("debug searchparam: " + args[0].trim());
column = 1;
searchparam = args[0].trim();
//ex 151
} else if (args[0].replaceAll("\\D", " ").length() == args[0].length()) {
column = 1;
searchparam = args[0].trim();
}
Expand All @@ -116,10 +144,15 @@ private String format(String searchparam) {
String word = l.next();
out += Character.toUpperCase(word.charAt(0)) + word.substring(1) + " ";
}
l.close();
return out.trim();
}

public void run() { try {
if (xconnection.isClosed()) {
Bukkit.getLogger().severe("Connection to MySQL database is closed. Re-connecting...");
return;
}
PreparedStatement stmt;
if (xcolumn == 0) {
stmt = xconnection.prepareStatement("SELECT * FROM `refs` WHERE `name` = ?");
Expand Down Expand Up @@ -177,7 +210,19 @@ public void run() { try {
sender.sendMessage(ChatColor.GREEN + "Type: " + ChatColor.WHITE + type);
sender.sendMessage(ChatColor.GREEN + "Max stack: " + ChatColor.WHITE + maxstack);
if (type.toLowerCase().contains("Machine".toLowerCase())) {
sender.sendMessage(ChatColor.GREEN + "Item input: " + ChatColor.WHITE + sidein + ChatColor.GREEN + ", output: "+ ChatColor.WHITE + sideout + ChatColor.GREEN + ", power: " + ChatColor.WHITE + sidepwd);
String xsidein = sidein;
String xsideout = sideout;
String xsidepwd = sidepwd;
if (xsidein == null || xsidein == "null") {
xsidein = "N/A";
}
if (xsideout == null || xsideout == "null") {
xsideout = "N/A";
}
if (xsidepwd == null || xsidepwd == "null") {
xsidepwd = "N/A";
}
sender.sendMessage(ChatColor.GREEN + "Item input: " + ChatColor.WHITE + xsidein + ChatColor.GREEN + ", output: "+ ChatColor.WHITE + xsideout + ChatColor.GREEN + ", power: " + ChatColor.WHITE + xsidepwd);
if (xmod.toLowerCase().contains("redpower2")) {
if (rprequirebt.contains("Y")) {
sender.sendMessage(ChatColor.DARK_PURPLE + "- " + "Requires blutricity");
Expand Down
57 changes: 37 additions & 20 deletions src/main/java/nl/hypothermic/tekkitreference/trMain.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStreamReader;
Expand All @@ -16,12 +17,12 @@

import javax.swing.SwingUtilities;

import org.apache.maven.model.Model;
import org.apache.maven.model.io.xpp3.MavenXpp3Reader;
import org.bukkit.Bukkit;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.plugin.java.JavaPlugin;

import javafx.embed.swing.JFXPanel;

public class trMain extends JavaPlugin {

/********************************\
Expand All @@ -32,20 +33,7 @@ public class trMain extends JavaPlugin {
*---------= 21/02/2018 =---------*
\********************************/

@Override public void onEnable() {
try {
boolean xs = new File(getDataFolder().getPath() + File.separator + "config.yml").exists();
defconfig(getConfig(), !xs);
} catch (IOException e1) {
getLogger().severe("Could not write config file correctly.");
e1.printStackTrace();
}
/*comment: v1.1.0 // SwingUtilities.invokeLater(new Runnable() {
public void run() {
// init jfx service platform
new JFXPanel();
}
});*/
private Connection connect() {
Connection sqlconn;
try {
getLogger().info("Connecting to database. This should not take more than 5 seconds. Timeout is 2 minutes.");
Expand All @@ -54,22 +42,40 @@ public void run() {
getConfig().getString("mysql-database"),
getConfig().getString("mysql-user") ,
getConfig().getString("mysql-password"));
return sqlconn;
} catch (SQLException e) {
getLogger().severe("[ERROR] TekkitReference could not be enabled: Connection to sql failed. Possible solutions: ");
getLogger().severe("[ERROR] 1) Check your server address in config file");
getLogger().severe("[ERROR] 2) Check if SQL drivers are installed (if needed)");
getLogger().severe("[ERROR] 3) Check that the server is accessible");
return null;
}
}

@Override public void onEnable() {
loadVer();
try {
boolean xs = new File(getDataFolder().getPath() + File.separator + "config.yml").exists();
defconfig(getConfig(), !xs);
} catch (IOException e1) {
getLogger().severe("Could not write config file correctly.");
e1.printStackTrace();
}
Connection sqlconn = connect();
if (sqlconn == null) {
return;
}
this.getCommand("ref").setExecutor(new trCommandExecutor(this, sqlconn));
this.getCommand("docs").setExecutor(new trCommandExecutor(this, sqlconn));
getLogger().info("TekkitReference has been enabled.");
this.getCommand("ref").setExecutor(new trCommandExecutor(this, sqlconn, v));
this.getCommand("docs").setExecutor(new trCommandExecutor(this, sqlconn,v));
getLogger().info("TekkitReference " + v + " has been enabled.");
}

@Override public void onDisable() {
getLogger().info("TekkitReference has been disabled.");
}

private String v;

public void defconfig(FileConfiguration cfg, Boolean xs) throws IOException {
if (!getDataFolder().exists()) {
getDataFolder().mkdir();
Expand All @@ -88,7 +94,7 @@ public void defconfig(FileConfiguration cfg, Boolean xs) throws IOException {
while( (line = br.readLine()) != null){
result = result + line + "\n";
}
result = "# ---------- TekkitReference Configuration File ----------\n"
result = "# ----- TekkitReference Configuration (v" + v + ")-----\n"
+ "# The default mysql settings are for the Public Database\n"
+ "# which is hosted on ext1.hypothermic.nl. It's recommended\n"
+ "# that you host your own database for better performance.\n" + result;
Expand All @@ -99,6 +105,17 @@ public void defconfig(FileConfiguration cfg, Boolean xs) throws IOException {
}
}

public void loadVer() {
try {
v = this.getDescription().getVersion();
} catch (Exception x) {
v = "[unknown]";
}
if (v == null) {
v = "[unknown]";
}
}

public void error(String message) {
try {
if(!getDataFolder().exists()) {
Expand Down
4 changes: 2 additions & 2 deletions src/main/resources/plugin.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: TekkitReference
main: nl.hypothermic.tekkitreference.trMain
version: 1.0.0-RELEASE
version: 1.2.0-RELEASE
author: hypothermicdotnl
commands:
ref:
Expand Down Expand Up @@ -28,4 +28,4 @@ permissions:
default: true
tekkitreference.admin:
description: Allows you to use admin features
default: op
default: op

0 comments on commit 310b9a5

Please sign in to comment.