diff --git a/.idea/compiler.xml b/.idea/compiler.xml index e67be4a..ec2a0b4 100644 --- a/.idea/compiler.xml +++ b/.idea/compiler.xml @@ -11,7 +11,7 @@ - + \ No newline at end of file diff --git a/pom.xml b/pom.xml index 74016ba..d78711d 100644 --- a/pom.xml +++ b/pom.xml @@ -25,8 +25,8 @@ maven-compiler-plugin 3.8.1 - 11 - 11 + 16 + 16 diff --git a/src/main/java/me/totalfreedom/tfguilds/TFMBridge.java b/src/main/java/me/totalfreedom/tfguilds/TFMBridge.java index a1211e6..775d1b2 100644 --- a/src/main/java/me/totalfreedom/tfguilds/TFMBridge.java +++ b/src/main/java/me/totalfreedom/tfguilds/TFMBridge.java @@ -2,7 +2,7 @@ package me.totalfreedom.tfguilds; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; -import me.totalfreedom.tfguilds.util.Reflections; +import me.totalfreedom.tfguilds.util.ReflectionsHelper; import org.bukkit.Bukkit; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; @@ -41,8 +41,8 @@ public class TFMBridge Bukkit.getLogger().warning("TotalFreedomMod not detected, checking operator status instead."); return player.isOp(); } - Object al = Reflections.getField(getTfm(), "al"); - Method isAdmin = Reflections.getMethod(al, "isAdmin", Player.class); + Object al = ReflectionsHelper.getField(getTfm(), "al"); + Method isAdmin = ReflectionsHelper.getMethod(al, "isAdmin", Player.class); try { return (boolean)isAdmin.invoke(al, player) /*getTfm().al.isAdmin(player)*/; @@ -61,8 +61,8 @@ public class TFMBridge Bukkit.getLogger().warning("TotalFreedomMod not detected, checking operator status instead."); return sender.isOp(); } - Object al = Reflections.getField(getTfm(), "al"); - Method isAdmin = Reflections.getMethod(al, "isAdmin", CommandSender.class); + Object al = ReflectionsHelper.getField(getTfm(), "al"); + Method isAdmin = ReflectionsHelper.getMethod(al, "isAdmin", CommandSender.class); try { return (boolean)isAdmin.invoke(al, sender) /*getTfm().al.isAdmin(player)*/; @@ -81,8 +81,8 @@ public class TFMBridge Bukkit.getLogger().warning("TotalFreedomMod not detected, vanish will return false."); return false; } - Object al = Reflections.getField(getTfm(), "al"); - Method isVanished = Reflections.getMethod(al, "isVanished", String.class); + Object al = ReflectionsHelper.getField(getTfm(), "al"); + Method isVanished = ReflectionsHelper.getMethod(al, "isVanished", String.class); try { return (boolean)isVanished.invoke(al, player.getName()) /*getTfm().al.isVanished(player.getName)*/; @@ -101,12 +101,12 @@ public class TFMBridge return null; } - Object pl = Reflections.getField(getTfm(), "pl"); - Method getPlayer = Reflections.getMethod(pl, "getPlayer", Player.class); + Object pl = ReflectionsHelper.getField(getTfm(), "pl"); + Method getPlayer = ReflectionsHelper.getMethod(pl, "getPlayer", Player.class); try { Object fPlayer = getPlayer.invoke(pl, player); - Method getTag = Reflections.getMethod(fPlayer, "getTag"); + Method getTag = ReflectionsHelper.getMethod(fPlayer, "getTag"); return (String)getTag.invoke(fPlayer); } @@ -125,12 +125,12 @@ public class TFMBridge return; } // getTfm().pl.getPlayer(player).setTag(null); - Object pl = Reflections.getField(getTfm(), "pl"); - Method getPlayer = Reflections.getMethod(pl, "getPlayer", Player.class); + Object pl = ReflectionsHelper.getField(getTfm(), "pl"); + Method getPlayer = ReflectionsHelper.getMethod(pl, "getPlayer", Player.class); try { Object fPlayer = getPlayer.invoke(pl, player); - Method setTag = Reflections.getMethod(fPlayer, "setTag", String.class); + Method setTag = ReflectionsHelper.getMethod(fPlayer, "setTag", String.class); setTag.invoke(fPlayer, (Object)null); } diff --git a/src/main/java/me/totalfreedom/tfguilds/sql/SQLDatabase.java b/src/main/java/me/totalfreedom/tfguilds/sql/SQLDatabase.java index 4e0594e..5209c46 100644 --- a/src/main/java/me/totalfreedom/tfguilds/sql/SQLDatabase.java +++ b/src/main/java/me/totalfreedom/tfguilds/sql/SQLDatabase.java @@ -25,20 +25,7 @@ public class SQLDatabase switch (ConfigEntry.CONNECTION_TYPE.getString().toLowerCase()) { case "sqlite": - File file = new File(plugin.getDataFolder(), "database.db"); - if (!file.exists()) - { - try - { - file.createNewFile(); - plugin.getLogger().info("Creating database.db file"); - } - catch (IOException e) - { - e.printStackTrace(); - } - } - connection = DriverManager.getConnection("jdbc:sqlite:" + file.getAbsolutePath().replace("%20", " ")); + connection = DriverManager.getConnection("jdbc:sqlite:" + createDBFile(plugin).getAbsolutePath().replace("%20", " ")); break; case "mysql": connection = DriverManager.getConnection(String.format("jdbc:mysql://%s:%d/%s", @@ -48,6 +35,8 @@ public class SQLDatabase ConfigEntry.MYSQL_USERNAME.getString(), password); break; + default: + connection = DriverManager.getConnection("jdbc:sqlite:" + createDBFile(plugin).getAbsolutePath().replace("%20", " ")); } createTables(); @@ -106,4 +95,22 @@ public class SQLDatabase "`rowid` INTEGER AUTO_INCREMENT PRIMARY KEY)") .execute(); } + + private File createDBFile(TFGuilds plugin) + { + File file = new File(plugin.getDataFolder(), "database.db"); + if (!file.exists()) + { + try + { + file.createNewFile(); + plugin.getLogger().info("Creating database.db file"); + } + catch (IOException e) + { + e.printStackTrace(); + } + } + return file; + } } diff --git a/src/main/java/me/totalfreedom/tfguilds/util/Reflections.java b/src/main/java/me/totalfreedom/tfguilds/util/ReflectionsHelper.java similarity index 96% rename from src/main/java/me/totalfreedom/tfguilds/util/Reflections.java rename to src/main/java/me/totalfreedom/tfguilds/util/ReflectionsHelper.java index 1341407..9a6e03b 100644 --- a/src/main/java/me/totalfreedom/tfguilds/util/Reflections.java +++ b/src/main/java/me/totalfreedom/tfguilds/util/ReflectionsHelper.java @@ -3,7 +3,7 @@ package me.totalfreedom.tfguilds.util; import java.lang.reflect.Field; import java.lang.reflect.Method; -public class Reflections +public class ReflectionsHelper { public static Object getField(T instance, String name) {