-
Notifications
You must be signed in to change notification settings - Fork 10
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
JobsonMarinho
wants to merge
3
commits into
PlaceholderAPI:master
Choose a base branch
from
JobsonMarinho:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
972a5b1
fix: Update version of PlaceholderAPI to 2.11.6 in pom.xml
JobsonMarinho c6c5579
feat: Add functionality to check if a server is online in onRequest m…
JobsonMarinho 8848173
fix: Fix configuration section retrieval and update default online an…
JobsonMarinho File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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; | ||
|
@@ -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 { | ||
|
@@ -73,6 +76,11 @@ public Map<String, Object> getDefaults() { | |
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": | ||
|
@@ -88,12 +96,16 @@ public String onRequest(final OfflinePlayer player, String identifier) { | |
|
||
@Override | ||
public void start() { | ||
if (hasString("online")) | ||
this.online = getString("online", "Online"); | ||
if (hasString("offline")) | ||
this.offline = getString("offline", "Offline"); | ||
|
||
final BukkitTask task = Bukkit.getScheduler().runTaskTimer(getPlaceholderAPI(), () -> { | ||
|
||
if (counts.isEmpty()) { | ||
sendServersChannelMessage(); | ||
} | ||
else { | ||
} else { | ||
counts.keySet().forEach(this::sendPlayersChannelMessage); | ||
} | ||
|
||
|
@@ -109,6 +121,13 @@ public void start() { | |
} | ||
} | ||
|
||
private boolean hasString(String path) { | ||
ConfigurationSection section = this.getConfigSection(); | ||
if (section == null) | ||
return false; | ||
return section.contains(path); | ||
} | ||
|
||
Comment on lines
+124
to
+130
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This isn't needed as per the above stated suggestions. |
||
@Override | ||
public void stop() { | ||
final BukkitTask prev = cached.getAndSet(null); | ||
|
@@ -135,13 +154,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)); | ||
|
@@ -154,7 +173,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) { | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of making this extra method, just update the
getDefaults()
method to include these new entries and it should update accordingly, especially since the getString method returns the default given if returned path is null.