67 lines
1.4 KiB
Java
67 lines
1.4 KiB
Java
package eu.univento.core.api.player;
|
|
|
|
import eu.univento.core.api.server.ServerSettings;
|
|
import org.bukkit.Bukkit;
|
|
import org.bukkit.GameMode;
|
|
import org.bukkit.entity.Player;
|
|
|
|
import java.util.ArrayList;
|
|
|
|
/**
|
|
*
|
|
* @author joethei
|
|
* @version 1.0
|
|
*/
|
|
public class Spectator {
|
|
|
|
/**
|
|
* contains all spectators
|
|
*/
|
|
private static ArrayList<CustomPlayer> spectators = new ArrayList<>();
|
|
|
|
/**
|
|
* adds player to spectators
|
|
* @param p CustomPlayer
|
|
*/
|
|
public static void add(CustomPlayer p) {
|
|
for (Player on : Bukkit.getOnlinePlayers()) {
|
|
on.hidePlayer(p);
|
|
}
|
|
spectators.add(p);
|
|
p.setGameMode(GameMode.ADVENTURE);
|
|
p.setAllowFlight(true);
|
|
p.setFlying(true);
|
|
}
|
|
|
|
/**
|
|
* removes player from spectator
|
|
* @param p CustomPlayer
|
|
*/
|
|
public static void remove(CustomPlayer p) {
|
|
for (Player on : Bukkit.getOnlinePlayers()) {
|
|
on.showPlayer(p);
|
|
}
|
|
spectators.remove(p);
|
|
p.setGameMode(ServerSettings.getGameMode());
|
|
p.setAllowFlight(false);
|
|
p.setFlying(false);
|
|
}
|
|
|
|
/**
|
|
* gets all spectators
|
|
* @return ArrayList<CustomPlayer>
|
|
*/
|
|
public static ArrayList<CustomPlayer> getSpectators() {
|
|
return spectators;
|
|
}
|
|
|
|
/**
|
|
* checks if players is spectator
|
|
* @param p CustomPlayer
|
|
* @return true/false
|
|
*/
|
|
public static boolean is(CustomPlayer p) {
|
|
return spectators.contains(p);
|
|
}
|
|
|
|
} |