2015-10-19 17:43:46 +00:00
|
|
|
package me.totalfreedom.totalfreedommod.bridge;
|
2013-09-24 14:13:38 +00:00
|
|
|
|
|
|
|
import com.earth2me.essentials.Essentials;
|
|
|
|
import com.earth2me.essentials.User;
|
2016-03-01 16:47:01 +00:00
|
|
|
import me.totalfreedom.totalfreedommod.FreedomService;
|
2015-10-19 17:43:46 +00:00
|
|
|
import me.totalfreedom.totalfreedommod.util.FLog;
|
|
|
|
import me.totalfreedom.totalfreedommod.util.FUtil;
|
|
|
|
import me.totalfreedom.totalfreedommod.TotalFreedomMod;
|
2013-09-24 14:13:38 +00:00
|
|
|
import org.bukkit.Bukkit;
|
|
|
|
import org.bukkit.plugin.Plugin;
|
|
|
|
|
2016-03-01 16:47:01 +00:00
|
|
|
public class EssentialsBridge extends FreedomService
|
2013-09-24 14:13:38 +00:00
|
|
|
{
|
|
|
|
|
2015-10-19 17:43:46 +00:00
|
|
|
private Essentials essentialsPlugin = null;
|
|
|
|
|
|
|
|
public EssentialsBridge(TotalFreedomMod plugin)
|
|
|
|
{
|
|
|
|
super(plugin);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void onStart()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void onStop()
|
2013-09-24 14:13:38 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2015-10-19 17:43:46 +00:00
|
|
|
public Essentials getEssentialsPlugin()
|
2013-09-24 14:13:38 +00:00
|
|
|
{
|
2014-05-19 17:32:25 +00:00
|
|
|
if (essentialsPlugin == null)
|
2013-09-24 14:13:38 +00:00
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
final Plugin essentials = Bukkit.getServer().getPluginManager().getPlugin("Essentials");
|
|
|
|
if (essentials != null)
|
|
|
|
{
|
|
|
|
if (essentials instanceof Essentials)
|
|
|
|
{
|
2014-05-19 17:32:25 +00:00
|
|
|
essentialsPlugin = (Essentials) essentials;
|
2013-09-24 14:13:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (Exception ex)
|
|
|
|
{
|
2015-10-19 17:43:46 +00:00
|
|
|
FLog.severe(ex);
|
2013-09-24 14:13:38 +00:00
|
|
|
}
|
|
|
|
}
|
2014-05-19 17:32:25 +00:00
|
|
|
return essentialsPlugin;
|
2013-09-24 14:13:38 +00:00
|
|
|
}
|
|
|
|
|
2015-10-19 17:43:46 +00:00
|
|
|
public User getEssentialsUser(String username)
|
2013-09-24 14:13:38 +00:00
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
final Essentials essentials = getEssentialsPlugin();
|
|
|
|
if (essentials != null)
|
|
|
|
{
|
|
|
|
return essentials.getUserMap().getUser(username);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (Exception ex)
|
|
|
|
{
|
2015-10-19 17:43:46 +00:00
|
|
|
FLog.severe(ex);
|
2013-09-24 14:13:38 +00:00
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2015-10-19 17:43:46 +00:00
|
|
|
public void setNickname(String username, String nickname)
|
2013-09-24 14:13:38 +00:00
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
final User user = getEssentialsUser(username);
|
|
|
|
if (user != null)
|
|
|
|
{
|
|
|
|
user.setNickname(nickname);
|
|
|
|
user.setDisplayNick();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (Exception ex)
|
|
|
|
{
|
2015-10-19 17:43:46 +00:00
|
|
|
FLog.severe(ex);
|
2013-09-24 14:13:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-10-19 17:43:46 +00:00
|
|
|
public String getNickname(String username)
|
2014-08-14 23:07:52 +00:00
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
final User user = getEssentialsUser(username);
|
|
|
|
if (user != null)
|
|
|
|
{
|
|
|
|
return user.getNickname();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (Exception ex)
|
|
|
|
{
|
2015-10-19 17:43:46 +00:00
|
|
|
FLog.severe(ex);
|
2014-08-14 23:07:52 +00:00
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2015-10-19 17:43:46 +00:00
|
|
|
public long getLastActivity(String username)
|
2013-10-08 18:41:05 +00:00
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
final User user = getEssentialsUser(username);
|
|
|
|
if (user != null)
|
|
|
|
{
|
2015-10-19 17:43:46 +00:00
|
|
|
return FUtil.<Long>getField(user, "lastActivity"); // This is weird
|
2013-10-08 18:41:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (Exception ex)
|
|
|
|
{
|
2015-10-19 17:43:46 +00:00
|
|
|
FLog.severe(ex);
|
2013-10-08 18:41:05 +00:00
|
|
|
}
|
|
|
|
return 0L;
|
|
|
|
}
|
|
|
|
|
2015-10-19 17:43:46 +00:00
|
|
|
public boolean isEssentialsEnabled()
|
2013-10-08 18:41:05 +00:00
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
final Essentials essentials = getEssentialsPlugin();
|
|
|
|
if (essentials != null)
|
|
|
|
{
|
|
|
|
return essentials.isEnabled();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (Exception ex)
|
|
|
|
{
|
2015-10-19 17:43:46 +00:00
|
|
|
FLog.severe(ex);
|
2013-10-08 18:41:05 +00:00
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
2013-09-24 14:13:38 +00:00
|
|
|
}
|