Last active
February 11, 2016 11:02
-
-
Save HugoSilvaF/e68af1b5f56dc279fe21 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class ScoreboardScroller implements Runnable { | |
private final Plugin plugin; | |
private final Thread thread; | |
private final Scoreboard scoreboard; | |
private String title; | |
private boolean usetTitleScoreboard; | |
private boolean useScoreboardPlayer; | |
private boolean autoUpdate | |
private boolean destroy; | |
public ScoreboardScroller () { | |
this.title = "Default title"; | |
this.plugin = Bukkit.getPluginManager().getPlugin("MeuPlugin"); | |
this.scoreboard = Bukkit.getScoreboardManager().getMainScoreboard(); | |
this.thread = new Thread(this); | |
this.thread.start(); | |
} | |
@Override | |
public run() { | |
while(!destroy) { | |
if(autoUpdate) { | |
for(Player player: Bukkit.getOnlinePlayers()){ | |
updateScoreboardToPlayer(player); | |
} | |
} | |
if(scoreboard != null) { | |
if(usetTitleScoreboard) { | |
runUpdate(scoreboard, scoreboard.getObjective(DisplaySlot.SIDEBAR).getDisplayName()); | |
} else { | |
runUpdate(scoreboard, title); | |
} | |
} | |
} | |
} | |
public void runUpdate(Scoreboard score, String string) { | |
for(int i = 0; i < string.length(); i++) { | |
String title = ChatColor.RED + string.substring(i, string.length()) + string.substring(0, i); | |
if(title.length() > 16) { | |
title = title.substring(0, 16); | |
} | |
Objective objective = score.getObjective(DisplaySlot.SIDEBAR); | |
objective.setDisplayName(title); | |
try { | |
Thread.sleep(200); | |
} catch (InterruptedException ex) { | |
} | |
} | |
} | |
public void updateScoreboardToPlayer(Player player) { | |
if(player.getScoreboard() == null || (player.getScoreboard() != null && player.getScoreboard().equals(scoreboard))) { | |
player.setScoreboard(scoreboard); | |
} | |
} | |
public ScoreboardScroller destroy() { | |
this.destroy = true; | |
this.thread.stop(); | |
} | |
public ScoreboardScroller setTitle(String string){ | |
this.title = string; | |
return this; | |
} | |
public ScoreboardScroller setScoreboard(Scoreboard scoreboard) { | |
this.scoreboard = scoreboard; | |
return this; | |
} | |
public ScoreboardScroller setAutoUpdate(Boolean bool) { | |
this.autoUpdate = bool; | |
return this; | |
} | |
public ScoreboardScroller setUseScoreboardPlayer(Boolean bool) { | |
this.useScoreboardPlayer = bool; | |
return this; | |
} | |
public ScoreboardScroller setUseTitleScoreboard(Boolean bool) { | |
this.usetTitleScoreboard = bool; | |
return this; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Caso encontre algum erro ou tenha alguma sugestão, me contate ou comente por gentileza.
Antes de usar Crie o Objective SIDEBAR
Como usar: