Guest User

Untitled

a guest
May 25th, 2019
99
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package de.bananentoast.ttt.listeners;
  2.  
  3. import org.bukkit.Bukkit;
  4. import org.bukkit.entity.Player;
  5. import org.bukkit.event.EventHandler;
  6. import org.bukkit.event.Listener;
  7. import org.bukkit.event.player.PlayerJoinEvent;
  8. import org.bukkit.event.player.PlayerQuitEvent;
  9.  
  10. import de.bananentoast.ttt.countdowns.LobbyCountdown;
  11. import de.bananentoast.ttt.gamestates.LobbyState;
  12. import de.bananentoast.ttt.main.Main;
  13. import de.bananentoast.ttt.util.ConfigLocationUtil;
  14.  
  15. public class PlayerLobbyConectionListener implements Listener{
  16.  
  17. private Main plugin;
  18.  
  19. public PlayerLobbyConectionListener(Main plugin) {
  20. this.plugin = plugin;
  21. }
  22.  
  23. @EventHandler
  24. public void handlePlayerJoin(PlayerJoinEvent event) {
  25. if(!(plugin.getGameStateManager().getCurrentGameState() instanceof LobbyState)) return;
  26. Player player = event.getPlayer();
  27. plugin.getPlayers().add(player);
  28. event.setJoinMessage(Main.PREFIX + "§a" + player.getDisplayName() + " §7ist beigetreten. §8[§6" + plugin.getPlayers().size() + "§8/§6" + LobbyState.MAX_PLAYERS + "§8]");
  29.  
  30. ConfigLocationUtil locationUtil = new ConfigLocationUtil(plugin, "lobby");
  31. if(locationUtil.loadLocation() != null) {
  32. player.teleport(locationUtil.loadLocation());
  33. } else
  34. Bukkit.getConsoleSender().sendMessage("§cDer LobbySpawn wurde noch nicht gesetzt");
  35.  
  36. LobbyState lobbyState = (LobbyState) plugin.getGameStateManager().getCurrentGameState();
  37. LobbyCountdown countdown = lobbyState.getCountdown();
  38. if(plugin.getPlayers().size() >= LobbyState.MIN_PLAYERS) {
  39. if(!countdown.isRunning()) {
  40. countdown.stopidle();
  41. countdown.start();
  42. }
  43. }
  44. }
  45.  
  46. @EventHandler
  47. public void handlePlayerQuit(PlayerQuitEvent event) {
  48. if(!(plugin.getGameStateManager().getCurrentGameState() instanceof LobbyState)) return;
  49. Player player = event.getPlayer();
  50. plugin.getPlayers().remove(player);
  51. event.setQuitMessage(Main.PREFIX + "§a" + player.getDisplayName() + " §chat verlassen. §8[§6" + plugin.getPlayers().size() + "§8/§6" + LobbyState.MAX_PLAYERS + "§8]");
  52.  
  53. LobbyState lobbyState = (LobbyState) plugin.getGameStateManager().getCurrentGameState();
  54. LobbyCountdown countdown = lobbyState.getCountdown();
  55. if(plugin.getPlayers().size() <= LobbyState.MIN_PLAYERS) {
  56. if(countdown.isRunning()) {
  57. countdown.stop();
  58. countdown.startidle();
  59. }
  60. }
  61. }
  62. }
RAW Paste Data