SHARE
TWEET

Untitled

a guest Feb 18th, 2019 58 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package fr.yazhog.uhchost.utils;
  2.  
  3. import fr.yazhog.uhchost.Main;
  4. import fr.yazhog.uhchost.events.PlayerJoin;
  5. import fr.yazhog.uhchost.events.ScenariosEvent.LoupGarou.Role;
  6. import fr.yazhog.uhchost.events.ScenariosEvent.LoupGarou.Roles;
  7. import fr.yazhog.uhchost.events.ScenariosInvClickEvent;
  8. import fr.yazhog.uhchost.runnable.GameRunnable;
  9. import fr.yazhog.uhchost.runnable.TeleportRunnable;
  10. import org.bukkit.Bukkit;
  11. import org.bukkit.entity.Player;
  12. import org.bukkit.scheduler.BukkitTask;
  13. import org.bukkit.scoreboard.DisplaySlot;
  14. import org.bukkit.scoreboard.Objective;
  15. import org.bukkit.scoreboard.Scoreboard;
  16.  
  17. import java.util.Map;
  18.  
  19. public class UhcPlayer {
  20.  
  21.     private Player player;
  22.     private Scoreboard scoreboard;
  23.     private Objective o;
  24.     private String scoreboardName;
  25.     private int afkTime = 300;
  26.     private BukkitTask taskId;
  27.  
  28.     public UhcPlayer(Player p){
  29.         this.player = p;
  30.     }
  31.  
  32.     public void registerNewScorebaord(String name){
  33.         this.scoreboardName = name;
  34.         this.scoreboard = Bukkit.getScoreboardManager().getNewScoreboard();
  35.         if(Main.getInstance().getScoreboardManagerMap().containsKey(player)) return;
  36.         this.o = scoreboard.registerNewObjective(name, "dummy");
  37.         o.setDisplayName(name);
  38.         o.setDisplaySlot(DisplaySlot.SIDEBAR);
  39.         //Main.getInstance().getScoreboardManagerMap().put(player, this);
  40.     }
  41.  
  42.     public Player getPlayer() {
  43.         return player;
  44.     }
  45.  
  46.     public void sendLines(){
  47.         o.getScore("§aPlayers ").setScore(Bukkit.getOnlinePlayers().size());
  48.     }
  49.  
  50.     public void sendLgLines(){
  51.         int i = (TeleportRunnable.playingPlayers.size() / 3);
  52.  
  53.         if(i == 0){
  54.             i = 1;
  55.         }
  56.         o.unregister();
  57.         this.o = scoreboard.registerNewObjective(scoreboardName, "dummy");
  58.         o.setDisplayName(scoreboardName);
  59.         o.setDisplaySlot(DisplaySlot.SIDEBAR);
  60.  
  61.         o.getScore("§1").setScore(10);
  62.         o.getScore("§3Host: " + Bukkit.getPlayer(PlayerJoin.getHost()).getName()).setScore(9);
  63.         o.getScore("§2").setScore(8);
  64.         o.getScore("§4Groupes de : " + i).setScore(7);
  65.         o.getScore("§3").setScore(6);
  66.         o.getScore("§bJoueurs: " + TeleportRunnable.playingPlayers.size()).setScore(5);
  67.         o.getScore("§4").setScore(4);
  68.         o.getScore("§6Timer: " + GameRunnable.notResetMin + ":" + GameRunnable.sec).setScore(3);
  69.         o.getScore("§4").setScore(2);
  70.         o.getScore("51.75.195.47").setScore(1);
  71.     }
  72.  
  73.     public void sendRolesBoard(){
  74.  
  75.         o.unregister();
  76.         Main.getInstance().getRolesNumber().clear();
  77.  
  78.         this.o = scoreboard.registerNewObjective(scoreboardName, "dummy");
  79.         o.setDisplayName(scoreboardName);
  80.         o.setDisplaySlot(DisplaySlot.SIDEBAR);
  81.  
  82.         for(Player pls : TeleportRunnable.playingPlayers){
  83.             if(Roles.getRole(pls) == null) continue;
  84.             Role.RolesEnum roles = Roles.getRole(pls);
  85.  
  86.             if(Main.getInstance().getRolesNumber().containsKey(roles)){
  87.                 Main.getInstance().getRolesNumber().replace(roles, Main.getInstance().getRolesNumber().get(roles),(Main.getInstance().getRolesNumber().get(roles) +1));
  88.             } else {
  89.                 Main.getInstance().getRolesNumber().put(roles, 1);
  90.             }
  91.         }
  92.  
  93.         for(Map.Entry<Role.RolesEnum, Integer> rolesNumber : Main.getInstance().getRolesNumber().entrySet()){
  94.  
  95.             o.getScore(rolesNumber.getKey().getName()).setScore(rolesNumber.getValue());
  96.  
  97.         }
  98.  
  99.     }
  100.  
  101.     public void refresh() {
  102.         Main.getInstance().getRolesEnums().clear();
  103.         if(ScenariosInvClickEvent.getScenarios().contains(ScenariosInvClickEvent.Scenarios.LOUPGAROU)){
  104.             for(Role.RolesEnum rolesEnum : Role.RolesEnum.values()){
  105.                 if(rolesEnum.isEnable()){
  106.                     Main.getInstance().getRolesEnums().add(rolesEnum);
  107.                 }
  108.             }
  109.         }
  110.     }
  111.  
  112.     public void setScoreboard(){
  113.         player.setScoreboard(scoreboard);
  114.     }
  115.  
  116.     public void startAfkTime(){
  117.  
  118.         taskId = Bukkit.getScheduler().runTaskTimer(Main.getInstance(), new Runnable() {
  119.             @Override
  120.             public void run() {
  121.                 afkTime--;
  122.                 if(afkTime == 0){
  123.                     TeleportRunnable.playingPlayers.remove(player);
  124.                     Bukkit.broadcastMessage("§c" + player.getName() + " est mort de deconnexion");
  125.  
  126.                 }
  127.             }
  128.         }, 20, 20);
  129.  
  130.     }
  131.  
  132.     public void stopAfkTime(){
  133.         taskId.cancel();
  134.     }
  135.  
  136. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top