Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package fr.zitugi.scoreboardvite;
- import org.bukkit.Bukkit;
- import org.bukkit.entity.Player;
- import org.bukkit.event.EventHandler;
- import org.bukkit.event.Listener;
- import org.bukkit.event.entity.PlayerDeathEvent;
- import org.bukkit.event.player.PlayerJoinEvent;
- import org.bukkit.scoreboard.DisplaySlot;
- import org.bukkit.scoreboard.Objective;
- import org.bukkit.scoreboard.Score;
- import org.bukkit.scoreboard.Scoreboard;
- import org.bukkit.scoreboard.ScoreboardManager;
- public class Scoreboards implements Listener {
- public Scoreboards(Main main) {
- }
- @EventHandler
- public void onJoin(PlayerJoinEvent e){
- Player p = e.getPlayer();
- createNewScoreboard(p);
- }
- public void createNewScoreboard(Player p){
- ScoreboardManager sm = Bukkit.getScoreboardManager();
- Scoreboard board = sm.getNewScoreboard();
- Objective obj = board.registerNewObjective("Stats", "dummy");
- Score kill = obj.getScore("Kills : 0");
- kill.setScore(-1);
- Score mort = obj.getScore("Morts : 0");
- mort.setScore(-2);
- obj.setDisplayName("Statistiques");
- obj.setDisplaySlot(DisplaySlot.SIDEBAR);
- p.setScoreboard(board);
- }
- @EventHandler
- public void onDeath(PlayerDeathEvent e){
- Player killed = e.getEntity();
- Player killer = killed.getKiller();
- if(killed instanceof Player){
- Scoreboard boardkilled = ((Player) killed).getScoreboard();
- Objective objkilled = boardkilled.getObjective(DisplaySlot.SIDEBAR);
- resetMorts(killed, boardkilled, objkilled);
- }
- else{
- return;
- }
- if(killer instanceof Player){
- Scoreboard boardkiller = ((Player) killer).getScoreboard();
- Objective objkiller = boardkiller.getObjective(DisplaySlot.SIDEBAR);
- resetKills(killer, boardkiller, objkiller);
- }
- }
- public void resetMorts(Player arg0, Scoreboard arg1, Objective arg2){
- for(String ligne : arg1.getEntries()){
- if(ligne.contains("Morts :")){
- arg1.resetScores(ligne);
- int score = 0;
- score = Integer.parseInt(ligne.split(" : ")[1]);
- int score2 = score+1;
- String lastligne = ligne.split(":")[0];
- String newligne = lastligne + ": " + score2;
- arg0.getScoreboard().resetScores(newligne);
- arg2.getScore(newligne).setScore(-2);
- return;
- }
- }
- }
- public void resetKills(Player arg0, Scoreboard arg1, Objective arg2){
- for(String ligne : arg1.getEntries()){
- if(ligne.contains("Kills :")){
- arg1.resetScores(ligne);
- int score = 0;
- score = Integer.parseInt(ligne.split(" : ")[1]);
- int score2 = score+1;
- String lastligne = ligne.split(":")[0];
- String newligne = lastligne + ": " + score2;
- arg0.getScoreboard().resetScores(newligne);
- arg2.getScore(newligne).setScore(-1);
- return;
- }
- }
- }
- }
Add Comment
Please, Sign In to add comment