2020-08-15 22:58:48 +00:00
|
|
|
package me.totalfreedom.totalfreedommod;
|
|
|
|
|
|
|
|
import me.totalfreedom.totalfreedommod.util.FLog;
|
2022-11-17 08:34:45 +00:00
|
|
|
import net.kyori.adventure.text.Component;
|
|
|
|
import net.kyori.adventure.text.format.NamedTextColor;
|
2020-08-15 22:58:48 +00:00
|
|
|
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();
|
|
|
|
|
2022-11-17 08:34:45 +00:00
|
|
|
server.getOnlinePlayers().stream().filter(pl -> !plugin.al.isAdmin(player)
|
|
|
|
&& plugin.al.isVanished(pl.getUniqueId())).forEach(pl -> player.hidePlayer(plugin, pl));
|
2020-08-15 22:58:48 +00:00
|
|
|
|
2022-11-17 08:34:45 +00:00
|
|
|
server.getOnlinePlayers().stream().filter(pl -> !plugin.al.isAdmin(pl)
|
|
|
|
&& plugin.al.isVanished(player.getUniqueId())).forEach(pl -> pl.hidePlayer(plugin, player));
|
2020-08-15 22:58:48 +00:00
|
|
|
|
2022-11-17 08:34:45 +00:00
|
|
|
if (plugin.al.isVanished(player.getUniqueId()))
|
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.");
|
2022-11-17 08:34:45 +00:00
|
|
|
event.joinMessage(null);
|
2020-08-15 22:58:48 +00:00
|
|
|
|
|
|
|
new BukkitRunnable()
|
|
|
|
{
|
|
|
|
@Override
|
|
|
|
public void run()
|
|
|
|
{
|
2022-11-17 08:34:45 +00:00
|
|
|
if (plugin.al.isVanished(player.getUniqueId()))
|
|
|
|
{
|
|
|
|
player.sendActionBar(Component.text("You are hidden from other players.").color(NamedTextColor.GOLD));
|
|
|
|
}
|
|
|
|
else
|
2020-08-15 22:58:48 +00:00
|
|
|
{
|
|
|
|
this.cancel();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}.runTaskTimer(plugin, 0L, 4L);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@EventHandler
|
|
|
|
public void onPlayerLeave(PlayerQuitEvent event)
|
|
|
|
{
|
|
|
|
Player player = event.getPlayer();
|
|
|
|
|
2022-11-17 08:34:45 +00:00
|
|
|
if (plugin.al.isVanished(player.getUniqueId()))
|
2020-08-15 22:58:48 +00:00
|
|
|
{
|
2022-11-17 08:34:45 +00:00
|
|
|
event.quitMessage(null);
|
2020-08-15 22:58:48 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|