API-Tutorial

This page contains a tutorial for the API.
If you don't know what I'm talking about use the "back"-button of your browser.

API Features

The API allows you to:

  • Modify other player's score.
  • Get whether or not the scoreboard feature is activated.
  • Which display slot is used for the scoreboard.
  • Get how many score a player gets for the standard actions.

Get whether the server is running GlobalScore or not

Before you use the API you have to make sure that GlobalScore is installed.
In order to do that you could do this:

	@Override
	public void onEnable() {
		if(Bukkit.getServer().getPluginManager().getPlugin("GlobalScore") != null) {
			//Use the API
		} else {
			//Don't use the API
		}
	}

In addition to that to make sure that GlobalScore is loaded before your plugin add a softdepend node to your plugin.yml:

softdepend: [GlobalScore]

But that's not required.

Get the scores

To get the score of a player you can use:

int score = GlobalScore.getScore(player);

You can also get the score of an offline player:

int score = GlobalScore.getScore(Bukkit.getServer().getOfflinePlayer("thePlayersName"));

This works for all GlobalScore API methods that require a player as parameter.

Modify the scores

Example 1

Always when a player writes something in chat he gets 2 global score points.

	@EventHandler
	public void onPlayerChat(AsyncPlayerChatEvent event) {
		Player p = event.getPlayer();
		GlobalScore.giveScore(p, 2);
	}

Using GlobalScore.giveScore(player, scoreToAdd) you can give the player some score.

Example 2

Every time when a player dies his score will be set to 0.

	@EventHandler
	public void onPlayerDeath(PlayerDeathEvent event) {
		Player p = event.getEntity();
		GlobalScore.setScore(p, 0);
	}

Using GlobalScore.setScore(player, score) you can set the player's score.

Example 3

Always when a player leaves the server he'll loose 10 points.

	@EventHandler
	public void onPlayerQuit(PlayerQuitEvent event) {
		Player p = event.getPlayer();
		GlobalScore.setScore(p, GlobalScore.getScore(p) - 10);
	}

Here we set the score to his current score minus 10. So we took him 10 points.

ScoreSetting

ScoreSetting is a class that contains information about how many score a player gets/looses on supported actions.
Here's a small example:

	System.out.println("A player gets " + GlobalScore.getScoreSettings().getCraftIronSword() + " global score points for crafting an iron sword.");

If you want to learn more about the ScoreSetting class have a look at the JavaDoc.

Other methods

To get whether the scoreboard feature is activated or not you can do:

	boolean isUsingScoreboard = GlobalScore.isUsingScoreboard();

To get the displaySlot of the scoreboard used to display the global score you can do:

	DisplaySlot slot = GlobalScore.getScoreboardDisplaySlot();

To get whether the player is messaged when his score changes do:

	boolean messagePlayers = GlobalScore.getMessagePlayer();

Please note that GlobalScore will only message the player if the score changes because the player does some of the by default supported actions.
If you change the players score and want to message him you could do:

	GlobalScore.setScore(player, 134);
	if(GlobalScore.getMessagePlayer()) {
		player.sendMessage("Your global score was set to 134.");
	}

JavaDocs and Important notes

You can find the API's JavaDocs here.
If your plugin supports GlobalScore please message me so I can add your plugin to the "plugins using GlobalScore" list.
Thank you!


Comments

  • To post a comment, please or register a new account.
Posts Quoted:
Reply
Clear All Quotes