Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update PlaceholderAPI Version and Add Server Status Check #19

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
<dependency>
<groupId>me.clip</groupId>
<artifactId>placeholderapi</artifactId>
<version>2.10.6</version>
<version>2.11.6</version>
<scope>provided</scope>
</dependency>
</dependencies>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import me.clip.placeholderapi.expansion.Taskable;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.entity.Player;
import org.bukkit.plugin.messaging.PluginMessageListener;
import org.bukkit.scheduler.BukkitTask;
Expand All @@ -33,10 +34,12 @@ public final class BungeeExpansion extends PlaceholderExpansion implements Plugi

private static final Splitter SPLITTER = Splitter.on(",").trimResults();


private final Map<String, Integer> counts = new HashMap<>();
private final Map<String, Integer> counts = new HashMap<>();
private final AtomicReference<BukkitTask> cached = new AtomicReference<>();

private String online = "Online";
private String offline = "Offline";

private static Field inputField;

static {
Expand All @@ -60,19 +63,28 @@ public String getAuthor() {

@Override
public String getVersion() {
return "2.3";
return "2.4";
}

@Override
public Map<String, Object> getDefaults() {
return Collections.singletonMap(CONFIG_INTERVAL, 30);
Map<String, Object> defaults = new HashMap<>();
defaults.put(CONFIG_INTERVAL, 30);
defaults.put("online", "Online");
defaults.put("offline", "Offline");
return defaults;
}


@Override
public String onRequest(final OfflinePlayer player, String identifier) {
final int value;

if (identifier.startsWith("online_")) {
final String server = identifier.substring(7).toLowerCase();
return counts.containsKey(server) ? online : offline;
}

switch (identifier.toLowerCase()) {
case "all":
case "total":
Expand All @@ -88,12 +100,14 @@ public String onRequest(final OfflinePlayer player, String identifier) {

@Override
public void start() {
this.online = getString("online", "Online");
this.offline = getString("offline", "Offline");

final BukkitTask task = Bukkit.getScheduler().runTaskTimer(getPlaceholderAPI(), () -> {

if (counts.isEmpty()) {
sendServersChannelMessage();
}
else {
} else {
counts.keySet().forEach(this::sendPlayersChannelMessage);
}

Expand Down Expand Up @@ -135,13 +149,13 @@ public void onPluginMessageReceived(final String channel, final Player player, f
try {
DataInputStream stream = (DataInputStream) inputField.get(in);
switch (in.readUTF()) {
case PLAYERS_CHANNEL:
if (stream.available() == 0) return; // how ?
final String server = in.readUTF();
if (stream.available() == 0) { // how ? x2
getPlaceholderAPI().getLogger().log(Level.SEVERE, String.format("[%s] Could not get the player count from server %s.", getName(), server));
counts.put(server.toLowerCase(), 0);
} else counts.put(server.toLowerCase(), in.readInt());
case PLAYERS_CHANNEL:
if (stream.available() == 0) return; // how ?
final String server = in.readUTF();
if (stream.available() == 0) { // how ? x2
getPlaceholderAPI().getLogger().log(Level.SEVERE, String.format("[%s] Could not get the player count from server %s.", getName(), server));
counts.put(server.toLowerCase(), 0);
} else counts.put(server.toLowerCase(), in.readInt());
break;
case SERVERS_CHANNEL:
SPLITTER.split(in.readUTF()).forEach(serverName -> counts.putIfAbsent(serverName.toLowerCase(), 0));
Expand All @@ -154,7 +168,8 @@ public void onPluginMessageReceived(final String channel, final Player player, f


private void sendServersChannelMessage() {
sendMessage(SERVERS_CHANNEL, out -> { });
sendMessage(SERVERS_CHANNEL, out -> {
});
}

private void sendPlayersChannelMessage(final String serverName) {
Expand Down