2015-10-19 17:43:46 +00:00
|
|
|
package me.totalfreedom.totalfreedommod.bridge;
|
2013-09-24 14:13:38 +00:00
|
|
|
|
2018-07-30 07:23:01 +00:00
|
|
|
import com.earth2me.essentials.Essentials;
|
|
|
|
import com.earth2me.essentials.User;
|
|
|
|
import me.totalfreedom.totalfreedommod.FreedomService;
|
2017-10-13 18:35:11 +00:00
|
|
|
import me.totalfreedom.totalfreedommod.player.FPlayer;
|
2018-07-30 07:23:01 +00:00
|
|
|
import me.totalfreedom.totalfreedommod.rank.Rank;
|
|
|
|
import me.totalfreedom.totalfreedommod.util.FLog;
|
|
|
|
import me.totalfreedom.totalfreedommod.util.FUtil;
|
2017-10-13 18:35:11 +00:00
|
|
|
import org.bukkit.entity.HumanEntity;
|
|
|
|
import org.bukkit.entity.Player;
|
2018-07-30 07:23:01 +00:00
|
|
|
import org.bukkit.event.EventHandler;
|
|
|
|
import org.bukkit.event.EventPriority;
|
2017-10-13 18:35:11 +00:00
|
|
|
import org.bukkit.event.inventory.InventoryClickEvent;
|
2018-07-30 07:23:01 +00:00
|
|
|
import org.bukkit.event.inventory.InventoryCloseEvent;
|
|
|
|
import org.bukkit.event.inventory.InventoryType;
|
|
|
|
import org.bukkit.event.player.PlayerQuitEvent;
|
|
|
|
import org.bukkit.inventory.Inventory;
|
|
|
|
import org.bukkit.inventory.InventoryHolder;
|
2017-10-13 18:35:11 +00:00
|
|
|
import org.bukkit.plugin.Plugin;
|
2018-07-30 07:23:01 +00:00
|
|
|
import org.bukkit.scheduler.BukkitRunnable;
|
2013-09-24 14:13:38 +00:00
|
|
|
|
2016-03-01 16:47:01 +00:00
|
|
|
public class EssentialsBridge extends FreedomService
|
2013-09-24 14:13:38 +00:00
|
|
|
{
|
2017-12-23 04:07:36 +00:00
|
|
|
|
2018-01-01 03:43:10 +00:00
|
|
|
private Essentials essentialsPlugin = null;
|
2017-12-23 04:07:36 +00:00
|
|
|
|
|
|
|
@Override
|
2020-07-01 01:51:06 +00:00
|
|
|
public void onStart()
|
2017-12-23 04:07:36 +00:00
|
|
|
{
|
2015-10-19 17:43:46 +00:00
|
|
|
}
|
2017-12-23 04:07:36 +00:00
|
|
|
|
|
|
|
@Override
|
2020-07-01 01:51:06 +00:00
|
|
|
public void onStop()
|
2017-12-23 04:07:36 +00:00
|
|
|
{
|
2013-09-24 14:13:38 +00:00
|
|
|
}
|
2017-12-23 04:07:36 +00:00
|
|
|
|
|
|
|
public Essentials getEssentialsPlugin()
|
|
|
|
{
|
2018-01-01 03:43:10 +00:00
|
|
|
if (essentialsPlugin == null)
|
2017-12-23 04:07:36 +00:00
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
2018-01-01 03:43:10 +00:00
|
|
|
final Plugin essentials = server.getPluginManager().getPlugin("Essentials");
|
2020-12-25 19:46:43 +00:00
|
|
|
assert essentials != null;
|
|
|
|
if (essentials instanceof Essentials)
|
2017-12-23 04:07:36 +00:00
|
|
|
{
|
2018-07-31 07:01:29 +00:00
|
|
|
essentialsPlugin = (Essentials)essentials;
|
2013-09-24 14:13:38 +00:00
|
|
|
}
|
|
|
|
}
|
2017-12-23 04:07:36 +00:00
|
|
|
catch (Exception ex)
|
|
|
|
{
|
2015-10-19 17:43:46 +00:00
|
|
|
FLog.severe(ex);
|
2013-09-24 14:13:38 +00:00
|
|
|
}
|
|
|
|
}
|
2018-01-01 03:43:10 +00:00
|
|
|
return essentialsPlugin;
|
2013-09-24 14:13:38 +00:00
|
|
|
}
|
2017-12-23 04:07:36 +00:00
|
|
|
|
2018-01-01 03:43:10 +00:00
|
|
|
public User getEssentialsUser(String username)
|
2017-12-23 04:07:36 +00:00
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
2018-01-01 03:43:10 +00:00
|
|
|
Essentials essentials = getEssentialsPlugin();
|
2017-12-23 04:07:36 +00:00
|
|
|
if (essentials != null)
|
|
|
|
{
|
2013-09-24 14:13:38 +00:00
|
|
|
return essentials.getUserMap().getUser(username);
|
|
|
|
}
|
|
|
|
}
|
2017-12-23 04:07:36 +00:00
|
|
|
catch (Exception ex)
|
|
|
|
{
|
2015-10-19 17:43:46 +00:00
|
|
|
FLog.severe(ex);
|
2013-09-24 14:13:38 +00:00
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
2017-12-23 04:07:36 +00:00
|
|
|
|
2018-01-01 03:43:10 +00:00
|
|
|
public void setNickname(String username, String nickname)
|
2017-12-23 04:07:36 +00:00
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
2018-01-01 03:43:10 +00:00
|
|
|
User user = getEssentialsUser(username);
|
2017-12-23 04:07:36 +00:00
|
|
|
if (user != null)
|
|
|
|
{
|
2013-09-24 14:13:38 +00:00
|
|
|
user.setNickname(nickname);
|
|
|
|
user.setDisplayNick();
|
|
|
|
}
|
|
|
|
}
|
2017-12-23 04:07:36 +00:00
|
|
|
catch (Exception ex)
|
|
|
|
{
|
2015-10-19 17:43:46 +00:00
|
|
|
FLog.severe(ex);
|
2013-09-24 14:13:38 +00:00
|
|
|
}
|
|
|
|
}
|
2017-12-23 04:07:36 +00:00
|
|
|
|
2018-01-01 03:43:10 +00:00
|
|
|
public String getNickname(String username)
|
2017-12-23 04:07:36 +00:00
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
2018-01-01 03:43:10 +00:00
|
|
|
User user = getEssentialsUser(username);
|
2017-12-23 04:07:36 +00:00
|
|
|
if (user != null)
|
|
|
|
{
|
2014-08-14 23:07:52 +00:00
|
|
|
return user.getNickname();
|
|
|
|
}
|
|
|
|
}
|
2017-12-23 04:07:36 +00:00
|
|
|
catch (Exception ex)
|
|
|
|
{
|
2015-10-19 17:43:46 +00:00
|
|
|
FLog.severe(ex);
|
2014-08-14 23:07:52 +00:00
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
2017-12-23 04:07:36 +00:00
|
|
|
|
2018-01-01 03:43:10 +00:00
|
|
|
public long getLastActivity(String username)
|
2017-12-23 04:07:36 +00:00
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
2018-01-01 03:43:10 +00:00
|
|
|
User user = getEssentialsUser(username);
|
2017-12-23 04:07:36 +00:00
|
|
|
if (user != null)
|
|
|
|
{
|
2022-04-15 11:03:41 +00:00
|
|
|
return user.getLastOnlineActivity();
|
2013-10-08 18:41:05 +00:00
|
|
|
}
|
|
|
|
}
|
2017-12-23 04:07:36 +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;
|
|
|
|
}
|
2017-12-23 04:07:36 +00:00
|
|
|
|
2018-01-01 03:43:10 +00:00
|
|
|
public void setVanished(String username, boolean vanished)
|
2017-12-23 04:07:36 +00:00
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
2018-01-01 03:43:10 +00:00
|
|
|
User user = getEssentialsUser(username);
|
2017-12-23 04:07:36 +00:00
|
|
|
if (user != null)
|
|
|
|
{
|
2017-10-13 18:35:11 +00:00
|
|
|
user.setVanished(vanished);
|
|
|
|
}
|
|
|
|
}
|
2017-12-23 04:07:36 +00:00
|
|
|
catch (Exception ex)
|
|
|
|
{
|
2017-10-13 18:35:11 +00:00
|
|
|
FLog.severe(ex);
|
|
|
|
}
|
|
|
|
}
|
2017-12-23 04:07:36 +00:00
|
|
|
|
2017-10-13 18:35:11 +00:00
|
|
|
@EventHandler(priority = EventPriority.MONITOR)
|
2018-01-01 03:43:10 +00:00
|
|
|
public void onInventoryClick(InventoryClickEvent event)
|
2017-12-23 04:07:36 +00:00
|
|
|
{
|
2017-10-13 18:35:11 +00:00
|
|
|
Player refreshPlayer = null;
|
2018-01-01 03:43:10 +00:00
|
|
|
Inventory inventory = event.getView().getTopInventory();
|
|
|
|
InventoryType inventoryType = inventory.getType();
|
2018-07-31 07:01:29 +00:00
|
|
|
Player player = (Player)event.getWhoClicked();
|
2018-01-01 03:43:10 +00:00
|
|
|
FPlayer fPlayer = plugin.pl.getPlayer(player);
|
|
|
|
if (inventoryType == InventoryType.PLAYER && fPlayer.isInvSee())
|
|
|
|
{
|
|
|
|
final InventoryHolder inventoryHolder = inventory.getHolder();
|
2020-12-25 19:46:43 +00:00
|
|
|
if (inventoryHolder instanceof HumanEntity)
|
2017-12-23 04:07:36 +00:00
|
|
|
{
|
2018-07-31 07:01:29 +00:00
|
|
|
Player invOwner = (Player)inventoryHolder;
|
2018-01-01 03:43:10 +00:00
|
|
|
Rank recieverRank = plugin.rm.getRank(player);
|
|
|
|
Rank playerRank = plugin.rm.getRank(invOwner);
|
2017-12-23 04:07:36 +00:00
|
|
|
if (playerRank.ordinal() >= recieverRank.ordinal() || !invOwner.isOnline())
|
|
|
|
{
|
2017-10-13 18:35:11 +00:00
|
|
|
event.setCancelled(true);
|
2018-01-01 03:43:10 +00:00
|
|
|
refreshPlayer = player;
|
2017-10-13 18:35:11 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-12-23 04:07:36 +00:00
|
|
|
if (refreshPlayer != null)
|
|
|
|
{
|
2018-01-01 03:43:10 +00:00
|
|
|
final Player p = refreshPlayer;
|
2017-12-23 04:07:36 +00:00
|
|
|
new BukkitRunnable()
|
|
|
|
{
|
|
|
|
@Override
|
|
|
|
public void run()
|
|
|
|
{
|
2018-01-01 03:43:10 +00:00
|
|
|
p.updateInventory();
|
2017-10-13 18:35:11 +00:00
|
|
|
}
|
2018-01-01 03:43:10 +00:00
|
|
|
}.runTaskLater(plugin, 20L);
|
2017-10-13 18:35:11 +00:00
|
|
|
}
|
|
|
|
}
|
2017-12-23 04:07:36 +00:00
|
|
|
|
2017-10-13 18:35:11 +00:00
|
|
|
@EventHandler(priority = EventPriority.MONITOR)
|
2018-01-01 03:43:10 +00:00
|
|
|
public void onInventoryClose(InventoryCloseEvent event)
|
2017-12-23 04:07:36 +00:00
|
|
|
{
|
2017-10-13 18:35:11 +00:00
|
|
|
Player refreshPlayer = null;
|
2018-01-01 03:43:10 +00:00
|
|
|
Inventory inventory = event.getView().getTopInventory();
|
|
|
|
InventoryType inventoryType = inventory.getType();
|
2018-07-31 07:01:29 +00:00
|
|
|
Player player = (Player)event.getPlayer();
|
2018-01-01 03:43:10 +00:00
|
|
|
FPlayer fPlayer = plugin.pl.getPlayer(player);
|
|
|
|
if (inventoryType == InventoryType.PLAYER && fPlayer.isInvSee())
|
2017-12-23 04:07:36 +00:00
|
|
|
{
|
|
|
|
fPlayer.setInvSee(false);
|
2018-01-01 03:43:10 +00:00
|
|
|
refreshPlayer = player;
|
2017-10-13 18:35:11 +00:00
|
|
|
}
|
2017-12-23 04:07:36 +00:00
|
|
|
if (refreshPlayer != null)
|
|
|
|
{
|
2018-01-01 03:43:10 +00:00
|
|
|
final Player p = refreshPlayer;
|
2017-12-23 04:07:36 +00:00
|
|
|
new BukkitRunnable()
|
|
|
|
{
|
|
|
|
@Override
|
|
|
|
public void run()
|
|
|
|
{
|
2018-01-01 03:43:10 +00:00
|
|
|
p.updateInventory();
|
2017-10-13 18:35:11 +00:00
|
|
|
}
|
2018-01-01 03:43:10 +00:00
|
|
|
}.runTaskLater(plugin, 20L);
|
2017-10-13 18:35:11 +00:00
|
|
|
}
|
|
|
|
}
|
2017-12-23 04:07:36 +00:00
|
|
|
|
2018-07-30 07:23:01 +00:00
|
|
|
public boolean isEnabled()
|
2017-12-23 04:07:36 +00:00
|
|
|
{
|
2018-07-30 07:23:01 +00:00
|
|
|
final Essentials ess = getEssentialsPlugin();
|
|
|
|
|
|
|
|
return ess != null && ess.isEnabled();
|
2013-10-08 18:41:05 +00:00
|
|
|
}
|
2020-12-04 00:28:53 +00:00
|
|
|
}
|