2020-08-15 22:58:48 +00:00
|
|
|
package me.totalfreedom.totalfreedommod;
|
|
|
|
|
|
|
|
import me.totalfreedom.totalfreedommod.util.FLog;
|
|
|
|
import net.md_5.bungee.api.ChatMessageType;
|
|
|
|
import net.md_5.bungee.api.chat.TextComponent;
|
|
|
|
import org.bukkit.ChatColor;
|
|
|
|
import org.bukkit.entity.Player;
|
|
|
|
import org.bukkit.event.EventHandler;
|
|
|
|
import org.bukkit.event.EventPriority;
|
|
|
|
import org.bukkit.event.player.PlayerJoinEvent;
|
|
|
|
import org.bukkit.event.player.PlayerQuitEvent;
|
|
|
|
import org.bukkit.scheduler.BukkitRunnable;
|
|
|
|
|
|
|
|
public class VanishHandler extends FreedomService
|
|
|
|
{
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onStart()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onStop()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
@EventHandler(priority = EventPriority.HIGH)
|
|
|
|
public void onPlayerJoin(PlayerJoinEvent event)
|
|
|
|
{
|
|
|
|
Player player = event.getPlayer();
|
|
|
|
|
|
|
|
for (Player p : server.getOnlinePlayers())
|
|
|
|
{
|
2020-12-04 00:28:53 +00:00
|
|
|
if (!plugin.al.isAdmin(player) && plugin.al.isVanished(p.getName()))
|
2020-08-15 22:58:48 +00:00
|
|
|
{
|
|
|
|
player.hidePlayer(plugin, p);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for (Player p : server.getOnlinePlayers())
|
|
|
|
{
|
2020-12-04 00:28:53 +00:00
|
|
|
if (!plugin.al.isAdmin(p) && plugin.al.isVanished(player.getName()))
|
2020-08-15 22:58:48 +00:00
|
|
|
{
|
|
|
|
p.hidePlayer(plugin, player);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-12-04 00:28:53 +00:00
|
|
|
if (plugin.al.isVanished(player.getName()))
|
2020-08-15 22:58:48 +00:00
|
|
|
{
|
|
|
|
plugin.esb.setVanished(player.getName(), true);
|
|
|
|
FLog.info(player.getName() + " joined while still vanished.");
|
2020-12-04 00:28:53 +00:00
|
|
|
plugin.al.messageAllAdmins(ChatColor.YELLOW + player.getName() + " has joined silently.");
|
2020-08-15 22:58:48 +00:00
|
|
|
event.setJoinMessage(null);
|
|
|
|
|
|
|
|
new BukkitRunnable()
|
|
|
|
{
|
|
|
|
@Override
|
|
|
|
public void run()
|
|
|
|
{
|
2020-12-04 00:28:53 +00:00
|
|
|
if (!plugin.al.isVanished(player.getName()))
|
2020-08-15 22:58:48 +00:00
|
|
|
{
|
|
|
|
this.cancel();
|
|
|
|
}
|
|
|
|
|
|
|
|
player.spigot().sendMessage(ChatMessageType.ACTION_BAR, TextComponent.fromLegacyText(ChatColor.GOLD + "You are hidden from other players."));
|
|
|
|
}
|
|
|
|
}.runTaskTimer(plugin, 0L, 4L);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@EventHandler
|
|
|
|
public void onPlayerLeave(PlayerQuitEvent event)
|
|
|
|
{
|
|
|
|
Player player = event.getPlayer();
|
|
|
|
|
2020-12-04 00:28:53 +00:00
|
|
|
if (plugin.al.isVanished(player.getName()))
|
2020-08-15 22:58:48 +00:00
|
|
|
{
|
|
|
|
event.setQuitMessage(null);
|
|
|
|
FLog.info(player.getName() + " left while still vanished.");
|
2020-12-04 00:28:53 +00:00
|
|
|
plugin.al.messageAllAdmins(ChatColor.YELLOW + player.getName() + " has left silently.");
|
2020-08-15 22:58:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|