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(); User.loadAll();
Guild.loadAll(); Guild.loadAll();
tfmBridge = new TFMBridge(); tfmBridge = new TFMBridge();
tfmBridge.getTfm(); tfmBridge.getTFM();
new JoinListener(this); new JoinListener(this);
new ChatListener(this); new ChatListener(this);
loadSubCommands(); loadSubCommands();

View file

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