rename Reflections -> ReflectionsHelper

add a default case in the switch statement
This commit is contained in:
spacerocket62 2021-07-29 16:16:39 -07:00
parent 11b3e194ec
commit eba2b655c8
5 changed files with 38 additions and 31 deletions

View file

@ -11,7 +11,7 @@
</profile> </profile>
</annotationProcessing> </annotationProcessing>
<bytecodeTargetLevel> <bytecodeTargetLevel>
<module name="TFGuilds" target="11" /> <module name="TFGuilds" target="16" />
</bytecodeTargetLevel> </bytecodeTargetLevel>
</component> </component>
</project> </project>

View file

@ -25,8 +25,8 @@
<artifactId>maven-compiler-plugin</artifactId> <artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version> <version>3.8.1</version>
<configuration> <configuration>
<source>11</source> <source>16</source>
<target>11</target> <target>16</target>
</configuration> </configuration>
</plugin> </plugin>
<plugin> <plugin>

View file

@ -2,7 +2,7 @@ package me.totalfreedom.tfguilds;
import java.lang.reflect.InvocationTargetException; import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import me.totalfreedom.tfguilds.util.Reflections; import me.totalfreedom.tfguilds.util.ReflectionsHelper;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
@ -41,8 +41,8 @@ public class TFMBridge
Bukkit.getLogger().warning("TotalFreedomMod not detected, checking operator status instead."); Bukkit.getLogger().warning("TotalFreedomMod not detected, checking operator status instead.");
return player.isOp(); return player.isOp();
} }
Object al = Reflections.getField(getTfm(), "al"); Object al = ReflectionsHelper.getField(getTfm(), "al");
Method isAdmin = Reflections.getMethod(al, "isAdmin", Player.class); Method isAdmin = ReflectionsHelper.getMethod(al, "isAdmin", Player.class);
try try
{ {
return (boolean)isAdmin.invoke(al, player) /*getTfm().al.isAdmin(player)*/; 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."); Bukkit.getLogger().warning("TotalFreedomMod not detected, checking operator status instead.");
return sender.isOp(); return sender.isOp();
} }
Object al = Reflections.getField(getTfm(), "al"); Object al = ReflectionsHelper.getField(getTfm(), "al");
Method isAdmin = Reflections.getMethod(al, "isAdmin", CommandSender.class); Method isAdmin = ReflectionsHelper.getMethod(al, "isAdmin", CommandSender.class);
try try
{ {
return (boolean)isAdmin.invoke(al, sender) /*getTfm().al.isAdmin(player)*/; 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."); Bukkit.getLogger().warning("TotalFreedomMod not detected, vanish will return false.");
return false; return false;
} }
Object al = Reflections.getField(getTfm(), "al"); Object al = ReflectionsHelper.getField(getTfm(), "al");
Method isVanished = Reflections.getMethod(al, "isVanished", String.class); Method isVanished = ReflectionsHelper.getMethod(al, "isVanished", String.class);
try try
{ {
return (boolean)isVanished.invoke(al, player.getName()) /*getTfm().al.isVanished(player.getName)*/; return (boolean)isVanished.invoke(al, player.getName()) /*getTfm().al.isVanished(player.getName)*/;
@ -101,12 +101,12 @@ public class TFMBridge
return null; return null;
} }
Object pl = Reflections.getField(getTfm(), "pl"); Object pl = ReflectionsHelper.getField(getTfm(), "pl");
Method getPlayer = Reflections.getMethod(pl, "getPlayer", Player.class); Method getPlayer = ReflectionsHelper.getMethod(pl, "getPlayer", Player.class);
try try
{ {
Object fPlayer = getPlayer.invoke(pl, player); Object fPlayer = getPlayer.invoke(pl, player);
Method getTag = Reflections.getMethod(fPlayer, "getTag"); Method getTag = ReflectionsHelper.getMethod(fPlayer, "getTag");
return (String)getTag.invoke(fPlayer); return (String)getTag.invoke(fPlayer);
} }
@ -125,12 +125,12 @@ public class TFMBridge
return; return;
} }
// getTfm().pl.getPlayer(player).setTag(null); // getTfm().pl.getPlayer(player).setTag(null);
Object pl = Reflections.getField(getTfm(), "pl"); Object pl = ReflectionsHelper.getField(getTfm(), "pl");
Method getPlayer = Reflections.getMethod(pl, "getPlayer", Player.class); Method getPlayer = ReflectionsHelper.getMethod(pl, "getPlayer", Player.class);
try try
{ {
Object fPlayer = getPlayer.invoke(pl, player); 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); setTag.invoke(fPlayer, (Object)null);
} }

View file

@ -25,20 +25,7 @@ public class SQLDatabase
switch (ConfigEntry.CONNECTION_TYPE.getString().toLowerCase()) switch (ConfigEntry.CONNECTION_TYPE.getString().toLowerCase())
{ {
case "sqlite": case "sqlite":
File file = new File(plugin.getDataFolder(), "database.db"); connection = DriverManager.getConnection("jdbc:sqlite:" + createDBFile(plugin).getAbsolutePath().replace("%20", " "));
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", " "));
break; break;
case "mysql": case "mysql":
connection = DriverManager.getConnection(String.format("jdbc:mysql://%s:%d/%s", connection = DriverManager.getConnection(String.format("jdbc:mysql://%s:%d/%s",
@ -48,6 +35,8 @@ public class SQLDatabase
ConfigEntry.MYSQL_USERNAME.getString(), ConfigEntry.MYSQL_USERNAME.getString(),
password); password);
break; break;
default:
connection = DriverManager.getConnection("jdbc:sqlite:" + createDBFile(plugin).getAbsolutePath().replace("%20", " "));
} }
createTables(); createTables();
@ -106,4 +95,22 @@ public class SQLDatabase
"`rowid` INTEGER AUTO_INCREMENT PRIMARY KEY)") "`rowid` INTEGER AUTO_INCREMENT PRIMARY KEY)")
.execute(); .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;
}
} }

View file

@ -3,7 +3,7 @@ package me.totalfreedom.tfguilds.util;
import java.lang.reflect.Field; import java.lang.reflect.Field;
import java.lang.reflect.Method; import java.lang.reflect.Method;
public class Reflections public class ReflectionsHelper
{ {
public static <T> Object getField(T instance, String name) { public static <T> Object getField(T instance, String name) {