Skip to content

Instantly share code, notes, and snippets.

@HugoSilvaF
Last active February 11, 2016 11:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save HugoSilvaF/e68af1b5f56dc279fe21 to your computer and use it in GitHub Desktop.
Save HugoSilvaF/e68af1b5f56dc279fe21 to your computer and use it in GitHub Desktop.
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;
}
}
@HugoSilvaF
Copy link
Author

Caso encontre algum erro ou tenha alguma sugestão, me contate ou comente por gentileza.

Antes de usar Crie o Objective SIDEBAR

Scoreboard scoreboard = Bukkit.getScoreboardManager().getMainScoreboard();

Objective objective = scoreboard.registerNewObjective("Top Kills", "dummy");
objective.setDisplayName("Top Kills");
objective.setDisplaySlot(DisplaySlot.SIDEBAR);

Como usar:

ScoreboardScroller scroller = new ScoreboardScroller();
scroller.setAutoUpdate(true);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment