Cache online players amount.

This commit is contained in:
filoghost 2015-02-20 22:25:25 +01:00
parent a07ae1892d
commit b0f4894b15
4 changed files with 39 additions and 3 deletions

View File

@ -16,6 +16,11 @@ menu-settings:
# Bind multiple commands using ; (command: 'menu; m; me')
command: 'menu'
# auto-refresh - OPTIONAL
# How frequently the menu will be refreshed, in seconds.
# Useful if you have variables in items' descriptions.
auto-refresh: 5
# This command command will be execute when the menu is opened.
# Supports all the icon command types.
open-action: 'sound: note pling; tell: &eYou opened the example menu.'
@ -153,6 +158,17 @@ a-talking-head:
POSITION-Y: 2
a-talking-head:
COMMAND: 'tell: This is a simple message, without using commands!'
NAME: '&3Tells you something.'
LORE:
- '&7It tells you something without commands.'
ID: head
DATA-VALUE: 3
POSITION-X: 1
POSITION-Y: 2
test-multiple-command:
COMMAND: 'console: Say Did you know that...; console: say you can run multiple commands?;'
NAME: '&aMultiple commands'

View File

@ -1,6 +1,6 @@
name: ChestCommands
main: com.gmail.filoghost.chestcommands.ChestCommands
version: 3.0.8
version: 3.1
softdepend: [Vault, BarAPI, PlayerPoints]
commands:

View File

@ -0,0 +1,20 @@
package com.gmail.filoghost.chestcommands.internal;
import org.bukkit.Bukkit;
public class CachedGetters {
private static long lastOnlinePlayersRefresh;
private static int onlinePlayers;
public static int getOnlinePlayers() {
long now = System.currentTimeMillis();
if (lastOnlinePlayersRefresh == 0 || now - lastOnlinePlayersRefresh > 1000) {
// getOnlinePlayers() could be expensive if called frequently
onlinePlayers = Bukkit.getOnlinePlayers().length;
}
return onlinePlayers;
}
}

View File

@ -7,7 +7,7 @@ import com.gmail.filoghost.chestcommands.bridge.EconomyBridge;
import com.gmail.filoghost.chestcommands.bridge.PlayerPointsBridge;
public enum Variable {
PLAYER("{player}") {
public String getReplacement(Player executor) {
return executor.getName();
@ -16,7 +16,7 @@ public enum Variable {
ONLINE("{online}") {
public String getReplacement(Player executor) {
return String.valueOf(Bukkit.getOnlinePlayers().length);
return String.valueOf(CachedGetters.getOnlinePlayers());
}
},