package me.illuminatiproductions.youtubeplugin;
import me.illuminatiproductions.youtubeplugin.commands.VanishCommand;
import me.illuminatiproductions.youtubeplugin.events.JoinEvent;
import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;
import java.util.ArrayList;
public class YoutubePlugin extends JavaPlugin {
public ArrayList<Player> invisible_list = new ArrayList<>();
@Override
public void onEnable() {
// Plugin startup logic
getCommand("vanish").setExecutor(new VanishCommand(this));
getServer().getPluginManager().registerEvents(new JoinEvent(this), this);
}
}
package me.illuminatiproductions.youtubeplugin.commands;
import me.illuminatiproductions.youtubeplugin.YoutubePlugin;
import org.bukkit.Bukkit;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
public class VanishCommand implements CommandExecutor {
YoutubePlugin plugin;
public VanishCommand(YoutubePlugin plugin) {
this.plugin = plugin;
}
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
if (sender instanceof Player){
Player player = (Player) sender;
if (plugin.invisible_list.contains(player)){
//Since they are on the list, remove them and make them visible
for (Player people : Bukkit.getOnlinePlayers()){
people.showPlayer(plugin, player);
}
plugin.invisible_list.remove(player);
player.sendMessage("You are now visible to other players");
}else if (!plugin.invisible_list.contains(player)){
//Hide yourself from every other player on the server
for (Player people : Bukkit.getOnlinePlayers()){
people.hidePlayer(plugin, player); //Hides you from that player
}
plugin.invisible_list.add(player);
player.sendMessage("You are now invisible to other players");
}
}
return true;
}
}
package me.illuminatiproductions.youtubeplugin.events;
import me.illuminatiproductions.youtubeplugin.YoutubePlugin;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerJoinEvent;
public class JoinEvent implements Listener {
YoutubePlugin plugin;
public JoinEvent(YoutubePlugin plugin) {
this.plugin = plugin;
}
@EventHandler
public void PlayerJoin(PlayerJoinEvent e){
//When a player joins, make the players on the invisible list invisible for them
Player player = e.getPlayer();
for (int i = 0;i < plugin.invisible_list.size(); i++){
player.hidePlayer(plugin, plugin.invisible_list.get(i));
}
}
}