Update for TFM refactor

This commit is contained in:
Telesphoreo 2021-12-07 17:29:02 -06:00
parent 7d1b8fd580
commit 89bdd6d5fd
2 changed files with 24 additions and 25 deletions

View File

@ -38,7 +38,7 @@ public class TFGuilds extends JavaPlugin
User.loadAll();
Guild.loadAll();
tfmBridge = new TFMBridge();
tfmBridge.getTfm();
tfmBridge.getTFM();
new JoinListener(this);
new ChatListener(this);
loadSubCommands();

View File

@ -10,11 +10,10 @@ import org.bukkit.plugin.Plugin;
public class TFMBridge
{
private final TFGuilds plugin = TFGuilds.getPlugin();
private /*TotalFreedomMod*/ Plugin tfm = null;
public /*TotalFreedomMod*/ Plugin getTfm()
public /*TotalFreedomMod*/ Plugin getTFM()
{
if (tfm == null)
{
@ -36,16 +35,16 @@ public class TFMBridge
public boolean isAdmin(Player player)
{
if (getTfm() == null)
if (getTFM() == null)
{
Bukkit.getLogger().warning("TotalFreedomMod not detected, checking operator status instead.");
return player.isOp();
}
Object al = ReflectionsHelper.getField(getTfm(), "al");
Method isAdmin = ReflectionsHelper.getMethod(al, "isAdmin", Player.class);
Object adminList = ReflectionsHelper.getField(getTFM(), "adminList");
Method isAdmin = ReflectionsHelper.getMethod(adminList, "isAdmin", Player.class);
try
{
return (boolean)isAdmin.invoke(al, player) /*getTfm().al.isAdmin(player)*/;
return (boolean)isAdmin.invoke(adminList, player) /*getTfm().al.isAdmin(player)*/;
}
catch (IllegalAccessException | InvocationTargetException e)
{
@ -56,16 +55,16 @@ public class TFMBridge
public boolean isAdmin(CommandSender sender)
{
if (getTfm() == null)
if (getTFM() == null)
{
Bukkit.getLogger().warning("TotalFreedomMod not detected, checking operator status instead.");
return sender.isOp();
}
Object al = ReflectionsHelper.getField(getTfm(), "al");
Method isAdmin = ReflectionsHelper.getMethod(al, "isAdmin", CommandSender.class);
Object adminList = ReflectionsHelper.getField(getTFM(), "adminList");
Method isAdmin = ReflectionsHelper.getMethod(adminList, "isAdmin", CommandSender.class);
try
{
return (boolean)isAdmin.invoke(al, sender) /*getTfm().al.isAdmin(player)*/;
return (boolean)isAdmin.invoke(adminList, sender) /*getTfm().al.isAdmin(player)*/;
}
catch (IllegalAccessException | InvocationTargetException e)
{
@ -76,16 +75,16 @@ public class TFMBridge
public boolean isVanished(Player player)
{
if (getTfm() == null)
if (getTFM() == null)
{
Bukkit.getLogger().warning("TotalFreedomMod not detected, vanish will return false.");
return false;
}
Object al = ReflectionsHelper.getField(getTfm(), "al");
Method isVanished = ReflectionsHelper.getMethod(al, "isVanished", String.class);
Object adminList = ReflectionsHelper.getField(getTFM(), "adminList");
Method isVanished = ReflectionsHelper.getMethod(adminList, "isVanished", String.class);
try
{
return (boolean)isVanished.invoke(al, player.getName()) /*getTfm().al.isVanished(player.getName)*/;
return (boolean)isVanished.invoke(adminList, player.getName()) /*getTfm().adminList.isVanished(player.getName)*/;
}
catch (IllegalAccessException | InvocationTargetException e)
{
@ -96,16 +95,16 @@ public class TFMBridge
public String getTag(Player player)
{
if (getTfm() == null)
if (getTFM() == null)
{
return null;
}
Object pl = ReflectionsHelper.getField(getTfm(), "pl");
Method getPlayer = ReflectionsHelper.getMethod(pl, "getPlayer", Player.class);
Object playerList = ReflectionsHelper.getField(getTFM(), "playerList");
Method getPlayer = ReflectionsHelper.getMethod(playerList, "getPlayer", Player.class);
try
{
Object fPlayer = getPlayer.invoke(pl, player);
Object fPlayer = getPlayer.invoke(playerList, player);
Method getTag = ReflectionsHelper.getMethod(fPlayer, "getTag");
return (String)getTag.invoke(fPlayer);
@ -115,21 +114,21 @@ public class TFMBridge
e.printStackTrace();
}
return "" /*ChatColor.stripColor(getTfm().pl.getPlayer(player).getTag())*/;
return "" /*ChatColor.stripColor(getTfm().playerList.getPlayer(player).getTag())*/;
}
public void clearTag(Player player)
{
if (getTfm() == null)
if (getTFM() == null)
{
return;
}
// getTfm().pl.getPlayer(player).setTag(null);
Object pl = ReflectionsHelper.getField(getTfm(), "pl");
Method getPlayer = ReflectionsHelper.getMethod(pl, "getPlayer", Player.class);
// getTfm().playerList.getPlayer(player).setTag(null);
Object playerList = ReflectionsHelper.getField(getTFM(), "playerList");
Method getPlayer = ReflectionsHelper.getMethod(playerList, "getPlayer", Player.class);
try
{
Object fPlayer = getPlayer.invoke(pl, player);
Object fPlayer = getPlayer.invoke(playerList, player);
Method setTag = ReflectionsHelper.getMethod(fPlayer, "setTag", String.class);
setTag.invoke(fPlayer, (Object)null);