Skip to content

Instantly share code, notes, and snippets.

@ucchyocean
Created September 27, 2013 01:14
Show Gist options
  • Save ucchyocean/6722906 to your computer and use it in GitHub Desktop.
Save ucchyocean/6722906 to your computer and use it in GitHub Desktop.
スコアボードのテスト
name: ScoreboardTestPlugin
main: jp.ucchy.ScoreboardTestPlugin
version: 0.0.1
author: ucchy
description: scoreboard test
commands:
scoreboardtest:
description: scoreboard test command
aliases: [st]
usage: /<command>
package jp.ucchy;
import org.bukkit.Bukkit;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.scoreboard.DisplaySlot;
import org.bukkit.scoreboard.Objective;
import org.bukkit.scoreboard.Scoreboard;
public class ScoreboardTestPlugin extends JavaPlugin {
private Objective ob;
/**
* コマンド実行時に呼び出されるメソッド
* @see org.bukkit.plugin.java.JavaPlugin#onCommand(org.bukkit.command.CommandSender, org.bukkit.command.Command, java.lang.String, java.lang.String[])
*/
@Override
public boolean onCommand(
CommandSender sender, Command command,
String label, String[] args) {
if ( ob == null ) {
Scoreboard sb = getServer().getScoreboardManager().getMainScoreboard();
if ( sb.getObjective("testobjective") != null ) {
ob = sb.getObjective("testobjective");
} else {
ob = sb.registerNewObjective("testobjective", "dummy");
ob.setDisplaySlot(DisplaySlot.PLAYER_LIST);
}
}
Player[] players = Bukkit.getOnlinePlayers();
for ( Player p : players ) {
int score = ob.getScore(p).getScore();
ob.getScore(p).setScore(score - 1);
}
return true;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment