mirror of
https://github.com/AtlasMediaGroup/TotalFreedomMod.git
synced 2025-06-29 19:46:42 +00:00
Fixing marco's mistakes (#8)
This commit is contained in:
@ -1,5 +1,3 @@
|
||||
|
||||
|
||||
package me.totalfreedom.totalfreedommod.bridge;
|
||||
|
||||
import org.bukkit.event.player.PlayerQuitEvent;
|
||||
@ -27,165 +25,216 @@ import me.totalfreedom.totalfreedommod.FreedomService;
|
||||
|
||||
public class EssentialsBridge extends FreedomService
|
||||
{
|
||||
|
||||
private Essentials essentialsPlugin;
|
||||
|
||||
public EssentialsBridge(final TotalFreedomMod plugin) {
|
||||
|
||||
public EssentialsBridge(final TotalFreedomMod plugin)
|
||||
{
|
||||
super(plugin);
|
||||
this.essentialsPlugin = null;
|
||||
}
|
||||
|
||||
protected void onStart() {
|
||||
|
||||
@Override
|
||||
protected void onStart()
|
||||
{
|
||||
}
|
||||
|
||||
protected void onStop() {
|
||||
|
||||
@Override
|
||||
protected void onStop()
|
||||
{
|
||||
Command_vanish.vanished.clear();
|
||||
}
|
||||
|
||||
public Essentials getEssentialsPlugin() {
|
||||
if (this.essentialsPlugin == null) {
|
||||
try {
|
||||
|
||||
public Essentials getEssentialsPlugin()
|
||||
{
|
||||
if (this.essentialsPlugin == null)
|
||||
{
|
||||
try
|
||||
{
|
||||
final Plugin essentials = Bukkit.getServer().getPluginManager().getPlugin("Essentials");
|
||||
if (essentials != null && essentials instanceof Essentials) {
|
||||
this.essentialsPlugin = (Essentials)essentials;
|
||||
if (essentials != null && essentials instanceof Essentials)
|
||||
{
|
||||
this.essentialsPlugin = (Essentials) essentials;
|
||||
}
|
||||
}
|
||||
catch (Exception ex) {
|
||||
catch (Exception ex)
|
||||
{
|
||||
FLog.severe(ex);
|
||||
}
|
||||
}
|
||||
return this.essentialsPlugin;
|
||||
}
|
||||
|
||||
public User getEssentialsUser(final String username) {
|
||||
try {
|
||||
|
||||
public User getEssentialsUser(final String username)
|
||||
{
|
||||
try
|
||||
{
|
||||
final Essentials essentials = this.getEssentialsPlugin();
|
||||
if (essentials != null) {
|
||||
if (essentials != null)
|
||||
{
|
||||
return essentials.getUserMap().getUser(username);
|
||||
}
|
||||
}
|
||||
catch (Exception ex) {
|
||||
catch (Exception ex)
|
||||
{
|
||||
FLog.severe(ex);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public void setNickname(final String username, final String nickname) {
|
||||
try {
|
||||
|
||||
public void setNickname(final String username, final String nickname)
|
||||
{
|
||||
try
|
||||
{
|
||||
final User user = this.getEssentialsUser(username);
|
||||
if (user != null) {
|
||||
if (user != null)
|
||||
{
|
||||
user.setNickname(nickname);
|
||||
user.setDisplayNick();
|
||||
}
|
||||
}
|
||||
catch (Exception ex) {
|
||||
catch (Exception ex)
|
||||
{
|
||||
FLog.severe(ex);
|
||||
}
|
||||
}
|
||||
|
||||
public String getNickname(final String username) {
|
||||
try {
|
||||
|
||||
public String getNickname(final String username)
|
||||
{
|
||||
try
|
||||
{
|
||||
final User user = this.getEssentialsUser(username);
|
||||
if (user != null) {
|
||||
if (user != null)
|
||||
{
|
||||
return user.getNickname();
|
||||
}
|
||||
}
|
||||
catch (Exception ex) {
|
||||
catch (Exception ex)
|
||||
{
|
||||
FLog.severe(ex);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public long getLastActivity(final String username) {
|
||||
try {
|
||||
|
||||
public long getLastActivity(final String username)
|
||||
{
|
||||
try
|
||||
{
|
||||
final User user = this.getEssentialsUser(username);
|
||||
if (user != null) {
|
||||
if (user != null)
|
||||
{
|
||||
return FUtil.getField(user, "lastActivity");
|
||||
}
|
||||
}
|
||||
catch (Exception ex) {
|
||||
catch (Exception ex)
|
||||
{
|
||||
FLog.severe(ex);
|
||||
}
|
||||
return 0L;
|
||||
}
|
||||
|
||||
public void setVanished(final String username, final boolean vanished) {
|
||||
try {
|
||||
|
||||
public void setVanished(final String username, final boolean vanished)
|
||||
{
|
||||
try
|
||||
{
|
||||
final User user = this.getEssentialsUser(username);
|
||||
if (user != null) {
|
||||
if (user != null)
|
||||
{
|
||||
user.setVanished(vanished);
|
||||
}
|
||||
}
|
||||
catch (Exception ex) {
|
||||
catch (Exception ex)
|
||||
{
|
||||
FLog.severe(ex);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR)
|
||||
public void onInventoryClickEvent(final InventoryClickEvent event) {
|
||||
public void onInventoryClickEvent(final InventoryClickEvent event)
|
||||
{
|
||||
Player refreshPlayer = null;
|
||||
final Inventory top = event.getView().getTopInventory();
|
||||
final InventoryType type = top.getType();
|
||||
final Player playerdata = (Player)event.getWhoClicked();
|
||||
final FPlayer fPlayer = ((TotalFreedomMod)this.plugin).pl.getPlayer(playerdata);
|
||||
if (type == InventoryType.PLAYER && fPlayer.isInvsee()) {
|
||||
final Player playerdata = (Player) event.getWhoClicked();
|
||||
final FPlayer fPlayer = ((TotalFreedomMod) this.plugin).pl.getPlayer(playerdata);
|
||||
if (type == InventoryType.PLAYER && fPlayer.isInvSee())
|
||||
{
|
||||
final InventoryHolder invHolder = top.getHolder();
|
||||
if (invHolder != null && invHolder instanceof HumanEntity) {
|
||||
final Player invOwner = (Player)invHolder;
|
||||
final Rank recieverRank = ((TotalFreedomMod)this.plugin).rm.getRank(playerdata);
|
||||
final Rank playerRank = ((TotalFreedomMod)this.plugin).rm.getRank(invOwner);
|
||||
if (playerRank.ordinal() >= recieverRank.ordinal() || !invOwner.isOnline()) {
|
||||
if (invHolder != null && invHolder instanceof HumanEntity)
|
||||
{
|
||||
final Player invOwner = (Player) invHolder;
|
||||
final Rank recieverRank = ((TotalFreedomMod) this.plugin).rm.getRank(playerdata);
|
||||
final Rank playerRank = ((TotalFreedomMod) this.plugin).rm.getRank(invOwner);
|
||||
if (playerRank.ordinal() >= recieverRank.ordinal() || !invOwner.isOnline())
|
||||
{
|
||||
event.setCancelled(true);
|
||||
refreshPlayer = playerdata;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (refreshPlayer != null) {
|
||||
if (refreshPlayer != null)
|
||||
{
|
||||
final Player player = refreshPlayer;
|
||||
new BukkitRunnable() {
|
||||
public void run() {
|
||||
new BukkitRunnable()
|
||||
{
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
player.updateInventory();
|
||||
}
|
||||
}.runTaskLater((Plugin)this.plugin, 20L);
|
||||
}.runTaskLater((Plugin) this.plugin, 20L);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR)
|
||||
public void onInventoryCloseEvent(final InventoryCloseEvent event) {
|
||||
public void onInventoryCloseEvent(final InventoryCloseEvent event)
|
||||
{
|
||||
Player refreshPlayer = null;
|
||||
final Inventory top = event.getView().getTopInventory();
|
||||
final InventoryType type = top.getType();
|
||||
final Player playerdata = (Player)event.getPlayer();
|
||||
final FPlayer fPlayer = ((TotalFreedomMod)this.plugin).pl.getPlayer(playerdata);
|
||||
if (type == InventoryType.PLAYER && fPlayer.isInvsee()) {
|
||||
fPlayer.setInvsee(false);
|
||||
final Player playerdata = (Player) event.getPlayer();
|
||||
final FPlayer fPlayer = ((TotalFreedomMod) this.plugin).pl.getPlayer(playerdata);
|
||||
if (type == InventoryType.PLAYER && fPlayer.isInvSee())
|
||||
{
|
||||
fPlayer.setInvSee(false);
|
||||
refreshPlayer = playerdata;
|
||||
}
|
||||
if (refreshPlayer != null) {
|
||||
if (refreshPlayer != null)
|
||||
{
|
||||
final Player player = refreshPlayer;
|
||||
new BukkitRunnable() {
|
||||
public void run() {
|
||||
new BukkitRunnable()
|
||||
{
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
player.updateInventory();
|
||||
}
|
||||
}.runTaskLater((Plugin)this.plugin, 20L);
|
||||
}.runTaskLater((Plugin) this.plugin, 20L);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR)
|
||||
public void onPlayerQuitEvent(final PlayerQuitEvent event) {
|
||||
public void onPlayerQuitEvent(final PlayerQuitEvent event)
|
||||
{
|
||||
final Player player = event.getPlayer();
|
||||
if (Command_vanish.vanished.contains(player)) {
|
||||
if (Command_vanish.vanished.contains(player))
|
||||
{
|
||||
Command_vanish.vanished.remove(player);
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isEssentialsEnabled() {
|
||||
try {
|
||||
|
||||
public boolean isEssentialsEnabled()
|
||||
{
|
||||
try
|
||||
{
|
||||
final Essentials essentials = this.getEssentialsPlugin();
|
||||
if (essentials != null) {
|
||||
if (essentials != null)
|
||||
{
|
||||
return essentials.isEnabled();
|
||||
}
|
||||
}
|
||||
catch (Exception ex) {
|
||||
catch (Exception ex)
|
||||
{
|
||||
FLog.severe(ex);
|
||||
}
|
||||
return false;
|
||||
|
Reference in New Issue
Block a user