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>
</annotationProcessing>
<bytecodeTargetLevel>
<module name="TFGuilds" target="11" />
<module name="TFGuilds" target="16" />
</bytecodeTargetLevel>
</component>
</project>

View file

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

View file

@ -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);
}

View file

@ -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;
}
}

View file

@ -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 <T> Object getField(T instance, String name) {