mirror of
https://github.com/filoghost/ChestCommands.git
synced 2024-11-23 02:25:26 +01:00
Cache online players amount.
This commit is contained in:
parent
a07ae1892d
commit
b0f4894b15
@ -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'
|
||||
|
@ -1,6 +1,6 @@
|
||||
name: ChestCommands
|
||||
main: com.gmail.filoghost.chestcommands.ChestCommands
|
||||
version: 3.0.8
|
||||
version: 3.1
|
||||
softdepend: [Vault, BarAPI, PlayerPoints]
|
||||
|
||||
commands:
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
@ -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());
|
||||
}
|
||||
},
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user