Skip to content

Commit

Permalink
PlaceholderAPI support, final touches
Browse files Browse the repository at this point in the history
  • Loading branch information
RhythmicSys committed Apr 26, 2023
1 parent 426a707 commit faf2140
Show file tree
Hide file tree
Showing 14 changed files with 77 additions and 84 deletions.
38 changes: 28 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
# SimplePMs

This plugin allows players to send private messages to one another, and reply to previous messages.
This plugin also gives staff members the ability to toggle 'socialspy', letting them view these messages
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.
<br>This plugin also has 'social spy' which allows for moderation of these messages.

### Commands
### Commands

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

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

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

### Permissions
### Permissions

- `spm.socialspy`
<br> Allows a player to read other player's private messages.
<br> Default: `op`
- `spm.socialspy.toggle`:
<br> Allows a user to read other people's private messages.
<br> Allows a player to toggle socialspy on and off
<br> Default: `op`
- `spm.recipient.override`
<br> Allows a player to send players a direct message whether they have the `receive` permission or not. Useful for staff.
<br> Default: `op`
- `spm.consolespy:`
<br> Allows a player to read messages being sent from the console directly to players
<br> Default: op
- `spm.reload`:
<br> Allows the player to reload the configuration.
<br> Allows a player to reload the plugin configuration/locale.
<br> Default: `op`
- `spm.send`:
- `spm.message.send`:
<br> Allows a player to send direct messages with /msg and /r.
<br> Default: `true`
- `spm.message.receive`
<br> Allows a player to receive direct messages
<br> Default: `true`

### PlaceholderAPI integration

You can use placeholderAPI placeholders in the messages by doing: `<papi:placeholder>`
<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.
<br>You will need placeholderAPI installed for those placeholders to work
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>ADHDMC</groupId>
<artifactId>SimplePMs</artifactId>
<version>0.1</version>
<version>1.0</version>
<packaging>jar</packaging>

<name>SimplePMs</name>
Expand Down
5 changes: 2 additions & 3 deletions src/main/java/adhdmc/simplepms/SimplePMs.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
import adhdmc.simplepms.commands.ReloadCommand;
import adhdmc.simplepms.commands.ReplyCommand;
import adhdmc.simplepms.commands.SocialSpyCommand;
import adhdmc.simplepms.config.LocaleConfig;
import adhdmc.simplepms.listeners.LoginListener;
import adhdmc.simplepms.utils.Message;
import net.kyori.adventure.text.minimessage.MiniMessage;
import org.bukkit.entity.Player;
import org.bukkit.plugin.Plugin;
Expand All @@ -14,8 +14,6 @@
import java.util.HashSet;

public final class SimplePMs extends JavaPlugin {
//todo: Add placeholderAPI support
//todo: Add message event

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

public static MiniMessage getMiniMessage() {
Expand Down
10 changes: 3 additions & 7 deletions src/main/java/adhdmc/simplepms/commands/PrivateMessage.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,8 @@
import java.util.stream.Collectors;

public class PrivateMessage implements TabExecutor {
private static PrivateMessage instance;

public static PrivateMessage getInstance() {
return instance;
}

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

@Override
public @Nullable List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
if (args.length > 1) return new ArrayList<>();
if (args.length > 1) return blankList;
return null;
}
}
11 changes: 2 additions & 9 deletions src/main/java/adhdmc/simplepms/commands/ReloadCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,9 @@
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.command.TabCompleter;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.List;

public class ReloadCommand implements CommandExecutor, TabCompleter {
public class ReloadCommand implements CommandExecutor {
MiniMessage miniMessage = SimplePMs.getMiniMessage();

@Override
Expand All @@ -31,8 +27,5 @@ public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command
return false;
}

@Override
public @Nullable List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
return null;
}

}
18 changes: 7 additions & 11 deletions src/main/java/adhdmc/simplepms/commands/ReplyCommand.java
Original file line number Diff line number Diff line change
@@ -1,32 +1,29 @@
package adhdmc.simplepms.commands;

import adhdmc.simplepms.SimplePMs;
import adhdmc.simplepms.handling.MessageHandling;
import adhdmc.simplepms.utils.Perm;
import adhdmc.simplepms.utils.SPMKey;
import adhdmc.simplepms.utils.Message;
import adhdmc.simplepms.handling.Resolvers;
import net.kyori.adventure.text.minimessage.MiniMessage;
import org.bukkit.Bukkit;
import org.bukkit.NamespacedKey;
import org.bukkit.Server;
import org.bukkit.command.*;
import org.bukkit.entity.Player;
import org.bukkit.persistence.PersistentDataContainer;
import org.bukkit.persistence.PersistentDataType;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.stream.Collectors;

public class ReplyCommand implements TabExecutor {
private final NamespacedKey lastMessaged = SPMKey.LAST_MESSAGED.getKey();
@Override
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
if (args.length == 0) {
sender.sendMessage(Resolvers.getInstance().parsePluginPrefix(Message.ERROR_BLANK_MESSAGE.getMessage()));
return false;
}
if (!(sender instanceof Player playerInitiator)) {
sender.sendMessage(Resolvers.getInstance().parsePluginPrefix(Message.ERROR_PLAYER_COMMAND.getMessage()));
return false;
Expand All @@ -46,17 +43,16 @@ public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command
if (!recipient.isOnline()) {
playerInitiator.sendMessage(Resolvers.getInstance().parsePluginPrefixAndString(Message.ERROR_RECIPIENT_OFFLINE.getMessage(), "receiver", lastMessagedPlayer));
}
if (!recipient.hasPermission(Perm.RECEIVE_MESSAGE.getPerm()) && !sender.hasPermission(Perm.RECEIVE_BYPASS.getPerm())) {
if (!recipient.hasPermission(Perm.RECEIVE_MESSAGE.getPerm()) && !sender.hasPermission(Perm.RECEIVE_OVERRIDE.getPerm())) {
sender.sendMessage(Resolvers.getInstance().parsePluginPrefix(Message.ERROR_RECIPIENT_NO_PERMS.getMessage()));
return false;
}
MessageHandling.getInstance().playerSenderAndReceiver(playerInitiator, recipient, message);
return true;
}


@Override
public @Nullable List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
return null;
public @Nullable List<String> onTabComplete(@NotNull CommandSender commandSender, @NotNull Command command, @NotNull String s, @NotNull String[] strings) {
return PrivateMessage.blankList;
}
}
19 changes: 4 additions & 15 deletions src/main/java/adhdmc/simplepms/commands/SocialSpyCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,18 @@
import adhdmc.simplepms.handling.Resolvers;
import adhdmc.simplepms.utils.SPMKey;
import adhdmc.simplepms.utils.Message;
import adhdmc.simplepms.utils.Perm;
import net.kyori.adventure.text.minimessage.MiniMessage;
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
import org.bukkit.NamespacedKey;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.command.TabCompleter;
import org.bukkit.entity.Player;
import org.bukkit.persistence.PersistentDataContainer;
import org.bukkit.persistence.PersistentDataType;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.HashSet;
import java.util.List;

public class SocialSpyCommand implements CommandExecutor, TabCompleter {
public class SocialSpyCommand implements CommandExecutor {

private final HashSet<Player> spyingPlayers = SimplePMs.getSpyingPlayers();
private final NamespacedKey spyToggle = SPMKey.SPY_TOGGLE.getKey();
Expand All @@ -31,7 +25,7 @@ public class SocialSpyCommand implements CommandExecutor, TabCompleter {
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
//Console cannot toggle social spy
if (!(sender instanceof Player player)) {
sender.sendMessage(Resolvers.
sender.sendMessage(Resolvers.getInstance().parsePluginPrefix(Message.ERROR_PLAYER_COMMAND.getMessage()));
return false;
}
PersistentDataContainer playerPDC = player.getPersistentDataContainer();
Expand All @@ -40,21 +34,16 @@ public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command
if (toggleValue == (byte)0) {
playerPDC.set(spyToggle, PersistentDataType.BYTE, (byte)1);
spyingPlayers.add(player);
player.sendMessage(miniMessage.deserialize(Message.SPY_ENABLED.getMessage()));
player.sendMessage(SimplePMs.getMiniMessage().deserialize(Message.SPY_ENABLED.getMessage()));
return true;
}
//If social spy was enabled, disable, remove player from the set if they are there, message the player, and return
if (toggleValue == (byte)1) {
playerPDC.set(spyToggle, PersistentDataType.BYTE, (byte) 0);
spyingPlayers.remove(player);
player.sendMessage(miniMessage.deserialize(Message.SPY_DISABLED.getMessage()));
player.sendMessage(SimplePMs.getMiniMessage().deserialize(Message.SPY_DISABLED.getMessage()));
return true;
}
return false;
}

@Override
public @Nullable List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
return null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public void onPlayerLogin(PlayerLoginEvent loginEvent) {
Player player = loginEvent.getPlayer();
PersistentDataContainer playerPDC = player.getPersistentDataContainer();
if ((playerPDC.getOrDefault(spyToggle, PersistentDataType.BYTE, (byte)0) == (byte)1) &&
player.hasPermission(Perm.SOCIAL_SPY_TOGGLE.getPerm())) {
player.hasPermission(Perm.SOCIAL_SPY.getPerm())) {
spyingPlayers.add(player);
}
},4);
Expand Down
3 changes: 0 additions & 3 deletions src/main/java/adhdmc/simplepms/utils/Message.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
package adhdmc.simplepms.utils;

import adhdmc.simplepms.SimplePMs;
import org.bukkit.configuration.file.FileConfiguration;

public enum Message {
//plugin
PLUGIN_PREFIX("<yellow>SimplePM<white> »"),
Expand Down
4 changes: 1 addition & 3 deletions src/main/java/adhdmc/simplepms/utils/Perm.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,9 @@

public enum Perm {
SOCIAL_SPY(new Permission("spm.socialspy")),
SOCIAL_SPY_TOGGLE(new Permission("spm.socialspy.toggle")),
CONSOLE_MESSAGE_SPY(new Permission("spm.consolespy")),
RECEIVE_BYPASS(new Permission("spm.bypass.recipient")),
RECEIVE_OVERRIDE(new Permission("spm.recipient.override")),
RELOAD_CONFIG(new Permission("spm.reload")),
MESSAGE_BASE(new Permission("spm.message")),
SEND_MESSAGE(new Permission("spm.message.send")),
RECEIVE_MESSAGE(new Permission("spm.message.receive"));

Expand Down
1 change: 0 additions & 1 deletion src/main/java/adhdmc/simplepms/utils/SPMKey.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import org.bukkit.NamespacedKey;

public enum SPMKey {
IGNORE_LIST(new NamespacedKey(SimplePMs.getInstance(), "ignore-list")),
SPY_TOGGLE(new NamespacedKey(SimplePMs.getInstance(), "spy-toggle")),
LAST_MESSAGED(new NamespacedKey(SimplePMs.getInstance(), "last-messaged"));

Expand Down
16 changes: 0 additions & 16 deletions src/main/resources/lang.yml

This file was deleted.

18 changes: 18 additions & 0 deletions src/main/resources/locale.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
"PLUGIN_PREFIX": "<yellow>SimplePM<white> »"
"CONSOLE_FORMAT": "<dark_red>[<red>Server</red>]</dark_red>"
"CONSOLE_FORMAT_SPY": "<gray>[Server]</gray>"
"CONFIG_RELOADED": "<plugin_prefix> <gold>SimplePM Config has been reloaded"
"ERROR_NO_PERMISSION": "<plugin_prefix> <red>You do not have permission to do this"
"ERROR_NO_RECIPIENT_PROVIDED": "<plugin_prefix> <red>You must provide a valid recipient for your message"
"ERROR_RECIPIENT_OFFLINE": "<plugin_prefix> There are no players online by the name of <target>"
"ERROR_BLANK_MESSAGE": "<plugin_prefix> You cannot send someone a blank message"
"ERROR_RECIPIENT_NO_PERMS": "<plugin_prefix> Sorry, looks like that player cannot receive messages right now"
"ERROR_PLAYER_COMMAND": "<plugin_prefix> <red>You must be a player to execute this command."
"ERROR_PAPI_NEEDS_ARGUMENT": "papi tag requires an argument"
"SENDING_FORMAT": "<gray>[<yellow>You</yellow> <gold>→</gold> <green><target></green>]</gray><reset> <message>"
"RECEIVING_FORMAT": "<gray>[<green><initiator></green> <gold>→</gold> <yellow>You</yellow>]</gray><reset> <message>"
"NO_USER_TO_REPLY": "<red>There is nobody to reply to, sorry. Try <gray>/msg [name]</gray> instead"
"SPY_FORMAT": "<dark_gray>[<#989898>PM-Spy</#989898>]</dark_gray> <#989898><initiator> → <target> <dark_gray>»</dark_gray> <gray><message>"
"SPY_ENABLED": "<dark_gray>[<#989898>PM-Spy</#989898>]</dark_gray> <green>PM Spy has been enabled"
"SPY_DISABLED": "<dark_gray>[<#989898>PM-Spy</#989898>]</dark_gray> <gray>PM Spy has been disabled"
"LOGGER_INVALID_LOCALE_KEY": "Invalid locale key found: "
14 changes: 10 additions & 4 deletions src/main/resources/plugin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ commands:
description: "Allows the user to send a private message to someone."
aliases: [dm, m, pm, tell, t]
usage: "Usage: /msg <recipient> <message>"
permission: spm.send
permission: spm.message.send
reply:
description: "allows the user to reply to a private message"
aliases: [r, re]
usage: "Usage: /r <message>"
permission: spm.send
permission: spm.message.send
socialspy:
description: "toggles socialspy"
aliases: [ss, spy, sspy]
Expand All @@ -38,9 +38,15 @@ permissions:
spm.reload:
description: "Allows the player to reload the configuration"
default: op
spm.send:
spm.recipient.override:
description: "Allows the player to send messages to someone who does not have the 'receive' permission"
default: op
spm.message.*:
description: "Allows a player to send and receive direct messages with /msg and /r"
default: op
spm.message.send:
description: "Allows a player to send direct messages with /msg and /r"
default: true
spm.receive:
spm.message.receive:
description: "Allows a player to receive direct messages from /msg and /r"
default: true

0 comments on commit faf2140

Please sign in to comment.