Skip to content

Commit faf2140

Browse files
committed
PlaceholderAPI support, final touches
1 parent 426a707 commit faf2140

File tree

14 files changed

+77
-84
lines changed

14 files changed

+77
-84
lines changed

README.md

Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
# SimplePMs
22

3-
This plugin allows players to send private messages to one another, and reply to previous messages.
4-
This plugin also gives staff members the ability to toggle 'socialspy', letting them view these messages
3+
A simple plugin that allows for players to send private messages to one another, and reply to the last person who they messaged or received a message from.
4+
<br>This plugin also has 'social spy' which allows for moderation of these messages.
55

6-
### Commands
6+
### Commands
77

8-
- `/msg` (or `/dm`, `/m`, `/pm`)
8+
- `/msg` (or `dm`, `m`, `pm`, `tell`, `t`)
99
<br>Allows the user to send a private message to another player.
1010
<br>**Usage**: /msg <recipient\> <message\>.
11-
<br>This command requires the `spm.send` permission.
11+
<br>This command requires the `spm.message.send` permission.
1212

1313
- `/reply` (or `/r`, `/re`):
1414
<br> Allows the user to reply to a previously received private message.
1515
<br> **Usage:** /r <message\>.
16-
<br> This command also requires the spm.send permission.
16+
<br> This command also requires the `spm.message.send` permission.
1717

1818
- `/socialspy` (or `/ss`, `/spy`, `/sspy`):
1919
<br> Toggles socialspy for the user.
@@ -24,14 +24,32 @@ This plugin also gives staff members the ability to toggle 'socialspy', letting
2424
<br> Reloads the SimplePM configuration.
2525
<br> This command requires the `spm.reload` permission.
2626

27-
### Permissions
27+
### Permissions
2828

29+
- `spm.socialspy`
30+
<br> Allows a player to read other player's private messages.
31+
<br> Default: `op`
2932
- `spm.socialspy.toggle`:
30-
<br> Allows a user to read other people's private messages.
33+
<br> Allows a player to toggle socialspy on and off
34+
<br> Default: `op`
35+
- `spm.recipient.override`
36+
<br> Allows a player to send players a direct message whether they have the `receive` permission or not. Useful for staff.
3137
<br> Default: `op`
38+
- `spm.consolespy:`
39+
<br> Allows a player to read messages being sent from the console directly to players
40+
<br> Default: op
3241
- `spm.reload`:
33-
<br> Allows the player to reload the configuration.
42+
<br> Allows a player to reload the plugin configuration/locale.
3443
<br> Default: `op`
35-
- `spm.send`:
44+
- `spm.message.send`:
3645
<br> Allows a player to send direct messages with /msg and /r.
3746
<br> Default: `true`
47+
- `spm.message.receive`
48+
<br> Allows a player to receive direct messages
49+
<br> Default: `true`
50+
51+
### PlaceholderAPI integration
52+
53+
You can use placeholderAPI placeholders in the messages by doing: `<papi:placeholder>`
54+
<br>You will need to remove any `%` from the placeholder, and put in the text alone, so for the placeholder `%player_displayname%` you would use `<papi:player_displayname>` in the file here.
55+
<br>You will need placeholderAPI installed for those placeholders to work

pom.xml

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

77
<groupId>ADHDMC</groupId>
88
<artifactId>SimplePMs</artifactId>
9-
<version>0.1</version>
9+
<version>1.0</version>
1010
<packaging>jar</packaging>
1111

1212
<name>SimplePMs</name>

src/main/java/adhdmc/simplepms/SimplePMs.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
import adhdmc.simplepms.commands.ReloadCommand;
55
import adhdmc.simplepms.commands.ReplyCommand;
66
import adhdmc.simplepms.commands.SocialSpyCommand;
7+
import adhdmc.simplepms.config.LocaleConfig;
78
import adhdmc.simplepms.listeners.LoginListener;
8-
import adhdmc.simplepms.utils.Message;
99
import net.kyori.adventure.text.minimessage.MiniMessage;
1010
import org.bukkit.entity.Player;
1111
import org.bukkit.plugin.Plugin;
@@ -14,8 +14,6 @@
1414
import java.util.HashSet;
1515

1616
public final class SimplePMs extends JavaPlugin {
17-
//todo: Add placeholderAPI support
18-
//todo: Add message event
1917

2018
private static Plugin instance;
2119
private static final MiniMessage miniMessage = MiniMessage.miniMessage();
@@ -31,6 +29,7 @@ public void onEnable() {
3129
} else {
3230
this.getLogger().info("You do not have PlaceholderAPI loaded on your server. Any PlaceholderAPI placeholders used in this plugin's messages, will not work.");
3331
}
32+
LocaleConfig.getInstance().reloadLocale();
3433
}
3534

3635
public static MiniMessage getMiniMessage() {

src/main/java/adhdmc/simplepms/commands/PrivateMessage.java

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,8 @@
1515
import java.util.stream.Collectors;
1616

1717
public class PrivateMessage implements TabExecutor {
18-
private static PrivateMessage instance;
19-
20-
public static PrivateMessage getInstance() {
21-
return instance;
22-
}
2318

19+
public static final ArrayList<String> blankList = new ArrayList<>();
2420
@Override
2521
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
2622
if (args.length == 0) {
@@ -45,7 +41,7 @@ public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command
4541
sender.sendMessage(Resolvers.getInstance().parsePluginPrefixAndString(Message.ERROR_RECIPIENT_OFFLINE.getMessage(), "receiver", args[0]));
4642
return false;
4743
}
48-
if (!recipient.hasPermission(Perm.RECEIVE_MESSAGE.getPerm()) && !sender.hasPermission(Perm.RECEIVE_BYPASS.getPerm())) {
44+
if (!recipient.hasPermission(Perm.RECEIVE_MESSAGE.getPerm()) && !sender.hasPermission(Perm.RECEIVE_OVERRIDE.getPerm())) {
4945
sender.sendMessage(Resolvers.getInstance().parsePluginPrefix(Message.ERROR_RECIPIENT_NO_PERMS.getMessage()));
5046
return false;
5147
}
@@ -61,7 +57,7 @@ public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command
6157

6258
@Override
6359
public @Nullable List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
64-
if (args.length > 1) return new ArrayList<>();
60+
if (args.length > 1) return blankList;
6561
return null;
6662
}
6763
}

src/main/java/adhdmc/simplepms/commands/ReloadCommand.java

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,9 @@
99
import org.bukkit.command.Command;
1010
import org.bukkit.command.CommandExecutor;
1111
import org.bukkit.command.CommandSender;
12-
import org.bukkit.command.TabCompleter;
1312
import org.jetbrains.annotations.NotNull;
14-
import org.jetbrains.annotations.Nullable;
1513

16-
import java.util.List;
17-
18-
public class ReloadCommand implements CommandExecutor, TabCompleter {
14+
public class ReloadCommand implements CommandExecutor {
1915
MiniMessage miniMessage = SimplePMs.getMiniMessage();
2016

2117
@Override
@@ -31,8 +27,5 @@ public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command
3127
return false;
3228
}
3329

34-
@Override
35-
public @Nullable List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
36-
return null;
37-
}
30+
3831
}

src/main/java/adhdmc/simplepms/commands/ReplyCommand.java

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,29 @@
11
package adhdmc.simplepms.commands;
22

3-
import adhdmc.simplepms.SimplePMs;
43
import adhdmc.simplepms.handling.MessageHandling;
54
import adhdmc.simplepms.utils.Perm;
65
import adhdmc.simplepms.utils.SPMKey;
76
import adhdmc.simplepms.utils.Message;
87
import adhdmc.simplepms.handling.Resolvers;
9-
import net.kyori.adventure.text.minimessage.MiniMessage;
108
import org.bukkit.Bukkit;
119
import org.bukkit.NamespacedKey;
12-
import org.bukkit.Server;
1310
import org.bukkit.command.*;
1411
import org.bukkit.entity.Player;
1512
import org.bukkit.persistence.PersistentDataContainer;
1613
import org.bukkit.persistence.PersistentDataType;
1714
import org.jetbrains.annotations.NotNull;
1815
import org.jetbrains.annotations.Nullable;
1916

20-
import java.util.ArrayList;
21-
import java.util.Arrays;
22-
import java.util.HashSet;
2317
import java.util.List;
24-
import java.util.stream.Collectors;
2518

2619
public class ReplyCommand implements TabExecutor {
2720
private final NamespacedKey lastMessaged = SPMKey.LAST_MESSAGED.getKey();
2821
@Override
2922
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
23+
if (args.length == 0) {
24+
sender.sendMessage(Resolvers.getInstance().parsePluginPrefix(Message.ERROR_BLANK_MESSAGE.getMessage()));
25+
return false;
26+
}
3027
if (!(sender instanceof Player playerInitiator)) {
3128
sender.sendMessage(Resolvers.getInstance().parsePluginPrefix(Message.ERROR_PLAYER_COMMAND.getMessage()));
3229
return false;
@@ -46,17 +43,16 @@ public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command
4643
if (!recipient.isOnline()) {
4744
playerInitiator.sendMessage(Resolvers.getInstance().parsePluginPrefixAndString(Message.ERROR_RECIPIENT_OFFLINE.getMessage(), "receiver", lastMessagedPlayer));
4845
}
49-
if (!recipient.hasPermission(Perm.RECEIVE_MESSAGE.getPerm()) && !sender.hasPermission(Perm.RECEIVE_BYPASS.getPerm())) {
46+
if (!recipient.hasPermission(Perm.RECEIVE_MESSAGE.getPerm()) && !sender.hasPermission(Perm.RECEIVE_OVERRIDE.getPerm())) {
5047
sender.sendMessage(Resolvers.getInstance().parsePluginPrefix(Message.ERROR_RECIPIENT_NO_PERMS.getMessage()));
5148
return false;
5249
}
5350
MessageHandling.getInstance().playerSenderAndReceiver(playerInitiator, recipient, message);
5451
return true;
5552
}
5653

57-
5854
@Override
59-
public @Nullable List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
60-
return null;
55+
public @Nullable List<String> onTabComplete(@NotNull CommandSender commandSender, @NotNull Command command, @NotNull String s, @NotNull String[] strings) {
56+
return PrivateMessage.blankList;
6157
}
6258
}

src/main/java/adhdmc/simplepms/commands/SocialSpyCommand.java

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,24 +4,18 @@
44
import adhdmc.simplepms.handling.Resolvers;
55
import adhdmc.simplepms.utils.SPMKey;
66
import adhdmc.simplepms.utils.Message;
7-
import adhdmc.simplepms.utils.Perm;
8-
import net.kyori.adventure.text.minimessage.MiniMessage;
9-
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
107
import org.bukkit.NamespacedKey;
118
import org.bukkit.command.Command;
129
import org.bukkit.command.CommandExecutor;
1310
import org.bukkit.command.CommandSender;
14-
import org.bukkit.command.TabCompleter;
1511
import org.bukkit.entity.Player;
1612
import org.bukkit.persistence.PersistentDataContainer;
1713
import org.bukkit.persistence.PersistentDataType;
1814
import org.jetbrains.annotations.NotNull;
19-
import org.jetbrains.annotations.Nullable;
2015

2116
import java.util.HashSet;
22-
import java.util.List;
2317

24-
public class SocialSpyCommand implements CommandExecutor, TabCompleter {
18+
public class SocialSpyCommand implements CommandExecutor {
2519

2620
private final HashSet<Player> spyingPlayers = SimplePMs.getSpyingPlayers();
2721
private final NamespacedKey spyToggle = SPMKey.SPY_TOGGLE.getKey();
@@ -31,7 +25,7 @@ public class SocialSpyCommand implements CommandExecutor, TabCompleter {
3125
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
3226
//Console cannot toggle social spy
3327
if (!(sender instanceof Player player)) {
34-
sender.sendMessage(Resolvers.
28+
sender.sendMessage(Resolvers.getInstance().parsePluginPrefix(Message.ERROR_PLAYER_COMMAND.getMessage()));
3529
return false;
3630
}
3731
PersistentDataContainer playerPDC = player.getPersistentDataContainer();
@@ -40,21 +34,16 @@ public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command
4034
if (toggleValue == (byte)0) {
4135
playerPDC.set(spyToggle, PersistentDataType.BYTE, (byte)1);
4236
spyingPlayers.add(player);
43-
player.sendMessage(miniMessage.deserialize(Message.SPY_ENABLED.getMessage()));
37+
player.sendMessage(SimplePMs.getMiniMessage().deserialize(Message.SPY_ENABLED.getMessage()));
4438
return true;
4539
}
4640
//If social spy was enabled, disable, remove player from the set if they are there, message the player, and return
4741
if (toggleValue == (byte)1) {
4842
playerPDC.set(spyToggle, PersistentDataType.BYTE, (byte) 0);
4943
spyingPlayers.remove(player);
50-
player.sendMessage(miniMessage.deserialize(Message.SPY_DISABLED.getMessage()));
44+
player.sendMessage(SimplePMs.getMiniMessage().deserialize(Message.SPY_DISABLED.getMessage()));
5145
return true;
5246
}
5347
return false;
5448
}
55-
56-
@Override
57-
public @Nullable List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
58-
return null;
59-
}
6049
}

src/main/java/adhdmc/simplepms/listeners/LoginListener.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public void onPlayerLogin(PlayerLoginEvent loginEvent) {
2424
Player player = loginEvent.getPlayer();
2525
PersistentDataContainer playerPDC = player.getPersistentDataContainer();
2626
if ((playerPDC.getOrDefault(spyToggle, PersistentDataType.BYTE, (byte)0) == (byte)1) &&
27-
player.hasPermission(Perm.SOCIAL_SPY_TOGGLE.getPerm())) {
27+
player.hasPermission(Perm.SOCIAL_SPY.getPerm())) {
2828
spyingPlayers.add(player);
2929
}
3030
},4);

src/main/java/adhdmc/simplepms/utils/Message.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
package adhdmc.simplepms.utils;
22

3-
import adhdmc.simplepms.SimplePMs;
4-
import org.bukkit.configuration.file.FileConfiguration;
5-
63
public enum Message {
74
//plugin
85
PLUGIN_PREFIX("<yellow>SimplePM<white> »"),

src/main/java/adhdmc/simplepms/utils/Perm.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,9 @@
44

55
public enum Perm {
66
SOCIAL_SPY(new Permission("spm.socialspy")),
7-
SOCIAL_SPY_TOGGLE(new Permission("spm.socialspy.toggle")),
87
CONSOLE_MESSAGE_SPY(new Permission("spm.consolespy")),
9-
RECEIVE_BYPASS(new Permission("spm.bypass.recipient")),
8+
RECEIVE_OVERRIDE(new Permission("spm.recipient.override")),
109
RELOAD_CONFIG(new Permission("spm.reload")),
11-
MESSAGE_BASE(new Permission("spm.message")),
1210
SEND_MESSAGE(new Permission("spm.message.send")),
1311
RECEIVE_MESSAGE(new Permission("spm.message.receive"));
1412

0 commit comments

Comments
 (0)