mirror of
https://github.com/AtlasMediaGroup/TotalFreedomMod.git
synced 2025-04-04 19:03:15 +00:00
Mass Refractoring, now uses me.totalfreedom.totalfreedommod as package Uses Aero https://github.com/Pravian/Aero Revamped command system Remove all TFM_ prefixes Revamp rank system Use new service based system Cleanup
140 lines
3.2 KiB
Java
140 lines
3.2 KiB
Java
package me.totalfreedom.totalfreedommod.bridge;
|
|
|
|
import com.earth2me.essentials.Essentials;
|
|
import com.earth2me.essentials.User;
|
|
import me.totalfreedom.totalfreedommod.util.FLog;
|
|
import me.totalfreedom.totalfreedommod.util.FUtil;
|
|
import me.totalfreedom.totalfreedommod.TotalFreedomMod;
|
|
import net.pravian.aero.component.service.AbstractService;
|
|
import org.bukkit.Bukkit;
|
|
import org.bukkit.plugin.Plugin;
|
|
|
|
public class EssentialsBridge extends AbstractService<TotalFreedomMod>
|
|
{
|
|
|
|
private Essentials essentialsPlugin = null;
|
|
|
|
public EssentialsBridge(TotalFreedomMod plugin)
|
|
{
|
|
super(plugin);
|
|
}
|
|
|
|
@Override
|
|
protected void onStart()
|
|
{
|
|
}
|
|
|
|
@Override
|
|
protected void onStop()
|
|
{
|
|
}
|
|
|
|
public Essentials getEssentialsPlugin()
|
|
{
|
|
if (essentialsPlugin == null)
|
|
{
|
|
try
|
|
{
|
|
final Plugin essentials = Bukkit.getServer().getPluginManager().getPlugin("Essentials");
|
|
if (essentials != null)
|
|
{
|
|
if (essentials instanceof Essentials)
|
|
{
|
|
essentialsPlugin = (Essentials) essentials;
|
|
}
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
FLog.severe(ex);
|
|
}
|
|
}
|
|
return essentialsPlugin;
|
|
}
|
|
|
|
public User getEssentialsUser(String username)
|
|
{
|
|
try
|
|
{
|
|
final Essentials essentials = getEssentialsPlugin();
|
|
if (essentials != null)
|
|
{
|
|
return essentials.getUserMap().getUser(username);
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
FLog.severe(ex);
|
|
}
|
|
return null;
|
|
}
|
|
|
|
public void setNickname(String username, String nickname)
|
|
{
|
|
try
|
|
{
|
|
final User user = getEssentialsUser(username);
|
|
if (user != null)
|
|
{
|
|
user.setNickname(nickname);
|
|
user.setDisplayNick();
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
FLog.severe(ex);
|
|
}
|
|
}
|
|
|
|
public String getNickname(String username)
|
|
{
|
|
try
|
|
{
|
|
final User user = getEssentialsUser(username);
|
|
if (user != null)
|
|
{
|
|
return user.getNickname();
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
FLog.severe(ex);
|
|
}
|
|
return null;
|
|
}
|
|
|
|
public long getLastActivity(String username)
|
|
{
|
|
try
|
|
{
|
|
final User user = getEssentialsUser(username);
|
|
if (user != null)
|
|
{
|
|
return FUtil.<Long>getField(user, "lastActivity"); // This is weird
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
FLog.severe(ex);
|
|
}
|
|
return 0L;
|
|
}
|
|
|
|
public boolean isEssentialsEnabled()
|
|
{
|
|
try
|
|
{
|
|
final Essentials essentials = getEssentialsPlugin();
|
|
if (essentials != null)
|
|
{
|
|
return essentials.isEnabled();
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
FLog.severe(ex);
|
|
}
|
|
return false;
|
|
}
|
|
}
|