Skip to content

Commit c065eff

Browse files
committed
Add placeholders for vanish stuff
1 parent a82c797 commit c065eff

6 files changed

Lines changed: 90 additions & 8 deletions

File tree

README.md

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# SimpleVanish
22

3-
Hide a player to make them appear offline.
3+
Hide a player to make them appear offline.
44

55
## Commands
66

@@ -12,9 +12,9 @@ Hide a player to make them appear offline.
1212
### `/fake` | Sends a fake join or leave message
1313

1414
- **Permission:** `vanish.command.fake`
15-
- **Arguments:**
16-
- Player: `/fake <leave|join>`
17-
- Console: `/fake <leave|join> <player>`
15+
- **Arguments:**
16+
- Player: `/fake <leave|join>`
17+
- Console: `/fake <leave|join> <player>`
1818

1919
### `/vanish-reload` | Reloads the plugin configuration and messages.
2020

@@ -64,9 +64,9 @@ Hide a player to make them appear offline.
6464

6565
### Command Permissions
6666

67-
| Permission | What it do |
68-
|-----------------------------|------------------------------------|
69-
| `vanish.command` | Use the `/vanish` command. |
67+
| Permission | What it do |
68+
|-----------------------|------------------------------------------------|
69+
| `vanish.command` | Use the `/vanish` command. |
7070
| `vanish.command.fake` | Use the `/fake leave` and `/fake join`command. |
7171

7272
### Settings Permissions
@@ -160,3 +160,14 @@ Hide a player to make them appear offline.
160160
| `remind-while-vanished` | Boolean | Toggles reminders for vanished players. |
161161
| `remind-interval-in-seconds` | Boolean | Interval for vanish reminders. |
162162

163+
## Placeholder API placeholders
164+
165+
If you are using Placeholder API, there are a few placeholders you can use from this plugin:
166+
167+
| Placeholder | What it do |
168+
|:----------------------------------|:-------------------------------------------------------------------------------------|
169+
| `%simplevanish_total-online%` | Total players online on this server, vanished and non-vanished |
170+
| `%simplevanish_current-vanished%` | Number of players that are currently vanished on this server |
171+
| `%simplevanish_current-visible%` | Number of visible players that are currently on this server |
172+
| `%simplevanish_is-vanished%` | Whether this user is currently in vanish mode or not |
173+
| `%simplevanish_vanished-prefix%` | A prefix that shows the text from `view.placeholder-format` when someone is vanished |

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
<groupId>simplexity</groupId>
88
<artifactId>SimpleVanish</artifactId>
9-
<version>1.0.1</version>
9+
<version>1.1.0</version>
1010
<packaging>jar</packaging>
1111

1212
<name>SimpleVanish</name>

src/main/java/simplexity/simplevanish/SimpleVanish.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package simplexity.simplevanish;
22

3+
import me.clip.placeholderapi.expansion.PlaceholderExpansion;
34
import net.kyori.adventure.text.minimessage.MiniMessage;
45
import org.bukkit.plugin.java.JavaPlugin;
56
import simplexity.simplevanish.commands.FakeCommand;
@@ -19,6 +20,7 @@
1920
import simplexity.simplevanish.commands.settings.VanishNotifications;
2021
import simplexity.simplevanish.config.ConfigHandler;
2122
import simplexity.simplevanish.config.Message;
23+
import simplexity.simplevanish.hooks.VanishPlaceholders;
2224
import simplexity.simplevanish.listeners.AttackListener;
2325
import simplexity.simplevanish.listeners.BlockBreakListener;
2426
import simplexity.simplevanish.listeners.BlockInteractListener;
@@ -106,6 +108,7 @@ private void registerListeners() {
106108
private void checkForPapi() {
107109
if (this.getServer().getPluginManager().getPlugin("PlaceholderAPI") != null) {
108110
papiEnabled = true;
111+
new VanishPlaceholders().register();
109112
} else {
110113
this.getLogger().info("You do not have PlaceholderAPI loaded on your server. Any PlaceholderAPI placeholders used in this plugin's messages, will not work.");
111114
}

src/main/java/simplexity/simplevanish/config/Message.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ public enum Message {
2424
VIEW_USER_LEFT_SILENTLY("view.user-left-silently", "<gray> <username> left silently</gray>"),
2525
VIEW_USER_VANISHED("view.user-vanished", "<gray> <username> vanished</gray>"),
2626
VIEW_USER_UNVANISHED("view.user-unvanished", "<gray> <username> unvanished</gray>"),
27+
VIEW_PLACEHOLDER_FORMAT("view.placeholder-format", "<gray><i>[Hidden] </i></gray>"),
2728
VIEW_TABLIST_FORMAT("view.tablist-format", "<gray><i>[Hidden] <username></i></gray>"),
2829
MESSAGE_FAKE_JOIN("message.fake-join", "<yellow><lang:multiplayer.player.joined:<username>></yellow>"),
2930
MESSAGE_FAKE_LEAVE("message.fake-leave", "<yellow><lang:multiplayer.player.left:<username>></yellow>"),
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
package simplexity.simplevanish.hooks;
2+
3+
import me.clip.placeholderapi.expansion.PlaceholderExpansion;
4+
import org.bukkit.Bukkit;
5+
import org.bukkit.OfflinePlayer;
6+
import org.bukkit.entity.Player;
7+
import org.jetbrains.annotations.NotNull;
8+
import simplexity.simplevanish.config.Message;
9+
import simplexity.simplevanish.saving.Cache;
10+
11+
public class VanishPlaceholders extends PlaceholderExpansion {
12+
13+
public VanishPlaceholders() {
14+
}
15+
16+
@Override
17+
public @NotNull String getIdentifier() {
18+
return "simplevanish";
19+
}
20+
21+
@Override
22+
public @NotNull String getAuthor() {
23+
return "Simplexity";
24+
}
25+
26+
@Override
27+
public @NotNull String getVersion() {
28+
return "1.0.0";
29+
}
30+
31+
@Override
32+
public boolean persist() {
33+
return true;
34+
}
35+
36+
@Override
37+
public String onRequest(OfflinePlayer player, @NotNull String params) {
38+
if (params.equalsIgnoreCase("total-online")) {
39+
int count = Bukkit.getServer().getOnlinePlayers().size();
40+
return String.valueOf(count);
41+
}
42+
if (params.equalsIgnoreCase("current-vanished")) {
43+
int count = Cache.getVanishedPlayers().size();
44+
return String.valueOf(count);
45+
}
46+
if (params.equalsIgnoreCase("current-visible")) {
47+
int vanishedCount = Cache.getVanishedPlayers().size();
48+
int onlineCount = Bukkit.getOnlinePlayers().size();
49+
int visibleCount = onlineCount - vanishedCount;
50+
return String.valueOf(visibleCount);
51+
}
52+
if (!(player instanceof Player onlinePlayer)) return null;
53+
boolean isVanished = Cache.getVanishedPlayers().contains(onlinePlayer);
54+
if (params.equalsIgnoreCase("is-vanished")) {
55+
return String.valueOf(isVanished);
56+
}
57+
if (params.equalsIgnoreCase("vanished-prefix")) {
58+
if (isVanished) {
59+
return Message.VIEW_PLACEHOLDER_FORMAT.getMessage();
60+
} else {
61+
return "";
62+
}
63+
}
64+
return null;
65+
}
66+
}

src/main/java/simplexity/simplevanish/listeners/PingServerListener.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import java.util.List;
1212

1313
public class PingServerListener implements Listener {
14+
1415
@EventHandler
1516
public void onPingServer(PaperServerListPingEvent pingEvent) {
1617
if (Cache.getVanishedPlayers().isEmpty()) return;

0 commit comments

Comments
 (0)