Skip to content

Commit bd25b93

Browse files
committed
asd;lfkjasdfj
1 parent 4a90b1d commit bd25b93

11 files changed

Lines changed: 97 additions & 92 deletions

File tree

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>SimplePMs</artifactId>
9-
<version>2.3.2</version>
9+
<version>2.4.0</version>
1010
<packaging>jar</packaging>
1111

1212
<name>SimplePMs</name>

src/main/java/simplexity/simplepms/SimplePMs.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import simplexity.simplepms.listeners.JoinListener;
1818
import simplexity.simplepms.listeners.PreCommandListener;
1919
import simplexity.simplepms.listeners.QuitListener;
20+
import simplexity.simplepms.logic.Constants;
2021
import simplexity.simplepms.saving.SqlHandler;
2122

2223
@SuppressWarnings("UnstableApiUsage")
@@ -57,6 +58,18 @@ public void onEnable() {
5758
commands.registrar().register(Reload.createCommand());
5859
commands.registrar().register(Blocklist.createCommand());
5960
});
61+
getServer().getPluginManager().addPermission(Constants.MESSAGE_BASIC);
62+
getServer().getPluginManager().addPermission(Constants.MESSAGE_ADMIN);
63+
getServer().getPluginManager().addPermission(Constants.MESSAGE_SEND);
64+
getServer().getPluginManager().addPermission(Constants.MESSAGE_RECEIVE);
65+
getServer().getPluginManager().addPermission(Constants.MESSAGE_TOGGLE);
66+
getServer().getPluginManager().addPermission(Constants.MESSAGE_BLOCK);
67+
getServer().getPluginManager().addPermission(Constants.PLUGIN_RELOAD);
68+
getServer().getPluginManager().addPermission(Constants.ADMIN_OVERRIDE);
69+
getServer().getPluginManager().addPermission(Constants.ADMIN_SOCIAL_SPY);
70+
getServer().getPluginManager().addPermission(Constants.ADMIN_CONSOLE_SPY);
71+
getServer().getPluginManager().addPermission(Constants.BYPASS_SOCIAL_SPY);
72+
getServer().getPluginManager().addPermission(Constants.BYPASS_COMMAND_SPY);
6073
}
6174

6275
@Override

src/main/java/simplexity/simplepms/commands/Reload.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public class Reload {
1515
public static LiteralCommandNode<CommandSourceStack> createCommand() {
1616

1717
return Commands.literal("spmreload")
18-
.requires(css -> css.getSender().hasPermission(Constants.RELOAD))
18+
.requires(css -> css.getSender().hasPermission(Constants.PLUGIN_RELOAD))
1919
.executes(ctx -> {
2020
CommandSender sender = ctx.getSource().getSender();
2121
ConfigHandler.getInstance().loadConfigValues();

src/main/java/simplexity/simplepms/config/ConfigHandler.java

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
package simplexity.simplepms.config;
22

3+
import net.kyori.adventure.key.Key;
4+
import org.bukkit.NamespacedKey;
5+
import org.bukkit.Registry;
36
import org.bukkit.Sound;
47
import org.bukkit.configuration.file.FileConfiguration;
58
import simplexity.simplepms.SimplePMs;
@@ -20,7 +23,7 @@ public static ConfigHandler getInstance() {
2023
private final Logger logger = SimplePMs.getInstance().getLogger();
2124
private boolean mysqlEnabled, playersSendToConsole, playersSendToHiddenPlayers, consoleHasSocialSpy,
2225
commandSpyEnabled, consoleHasCommandSpy, receiveSoundEnabled, sendSoundEnabled, spySoundEnabled;
23-
private Sound receiveSound, sendSound, spySound;
26+
private NamespacedKey receiveSound, sendSound, spySound;
2427
private float receivePitch, receiveVolume, sendPitch, sendVolume, spyPitch, spyVolume;
2528
private String mysqlIp, mysqlName, mysqlUsername, mysqlPassword, normalFormat, socialSpyFormat;
2629
private final List<String> validNamesForConsole = new ArrayList<>();
@@ -60,38 +63,36 @@ private void updateHashSet(HashSet<String> set, List<String> list) {
6063
}
6164

6265
private void loadReceiveSoundInfo(FileConfiguration config) {
63-
String soundString = config.getString("sounds.received.sound", "BLOCK_NOTE_BLOCK_XYLOPHONE");
64-
receiveSound = getValidSound(soundString, Sound.BLOCK_NOTE_BLOCK_XYLOPHONE);
66+
String soundString = config.getString("sounds.received.sound", "minecraft:block.note_block.xylophone");
67+
receiveSound = getValidSound(soundString, Registry.SOUNDS.getKey(Sound.BLOCK_NOTE_BLOCK_XYLOPHONE));
6568
receivePitch = getValidFloat(config.getDouble("sounds.received.pitch", 1.8));
6669
receiveVolume = getValidFloat(config.getDouble("sounds.received.volume", 0.5));
6770
}
6871

6972
private void loadSendSoundInfo(FileConfiguration config){
70-
String soundString = config.getString("sounds.sent.sound", "ENTITY_ALLAY_ITEM_THROWN");
71-
sendSound = getValidSound(soundString, Sound.ENTITY_ALLAY_ITEM_THROWN);
73+
String soundString = config.getString("sounds.sent.sound", "minecraft:entity.allay.item_thrown");
74+
sendSound = getValidSound(soundString, Registry.SOUNDS.getKey(Sound.ENTITY_ALLAY_ITEM_THROWN));
7275
sendPitch = getValidFloat(config.getDouble("sounds.sent.pitch", 1.8));
7376
sendVolume = getValidFloat(config.getDouble("sounds.sent.volume", 0.5));
7477
}
7578

7679
private void loadSpySoundInfo(FileConfiguration config){
77-
String soundString = config.getString("sounds.spy.sound", "ENTITY_ITEM_FRAME_ROTATE_ITEM");
78-
spySound = getValidSound(soundString, Sound.ENTITY_ITEM_FRAME_ROTATE_ITEM);
80+
String soundString = config.getString("sounds.spy.sound", "minecraft:entity.item_frame.rotate_item");
81+
spySound = getValidSound(soundString, Registry.SOUNDS.getKey(Sound.ENTITY_ITEM_FRAME_ROTATE_ITEM));
7982
spyPitch = getValidFloat(config.getDouble("sounds.spy.pitch", 1.8));
8083
spyVolume = getValidFloat(config.getDouble("sounds.spy.volume", 0.5));
8184
}
8285

83-
private Sound getValidSound(String soundString, Sound defaultSound){
84-
Sound sound;
85-
try {
86-
sound = Sound.valueOf(soundString);
87-
} catch (IllegalArgumentException exception) {
86+
private NamespacedKey getValidSound(String soundString, NamespacedKey defaultSound){
87+
NamespacedKey key = NamespacedKey.fromString(soundString);
88+
if (key == null || Registry.SOUNDS.get(key) == null) {
8889
String warning = LocaleMessage.LOG_ERROR_SOUND_NOT_VALID.getMessage().replace("%sound-string%", soundString);
89-
String warning2 = LocaleMessage.LOG_ERROR_USING_DEFAULT_SOUND.getMessage().replace("%default-sound%", defaultSound.name());
90+
String warning2 = LocaleMessage.LOG_ERROR_USING_DEFAULT_SOUND.getMessage().replace("%default-sound%", defaultSound.getKey());
9091
logger.warning(warning);
9192
logger.warning(warning2);
92-
sound = defaultSound;
93+
return defaultSound;
9394
}
94-
return sound;
95+
return key;
9596
}
9697

9798
private float getValidFloat(double numberToCheck){
@@ -178,15 +179,15 @@ public String getSocialSpyFormat() {
178179
return socialSpyFormat;
179180
}
180181

181-
public Sound getReceiveSound() {
182+
public NamespacedKey getReceiveSound() {
182183
return receiveSound;
183184
}
184185

185-
public Sound getSendSound() {
186+
public NamespacedKey getSendSound() {
186187
return sendSound;
187188
}
188189

189-
public Sound getSpySound() {
190+
public NamespacedKey getSpySound() {
190191
return spySound;
191192
}
192193

src/main/java/simplexity/simplepms/config/LocaleMessage.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,9 @@ public enum LocaleMessage {
3232
ERROR_CANNOT_MESSAGE_CONSOLE("error.cannot-message-console", "<red>Sorry, you cannot message the server</red>"),
3333
ERROR_SOMETHING_WENT_WRONG("error.something-wrong", "<red>Sorry, something went wrong, please check console for more information</red>"),
3434
ERROR_NAME_NOT_FOUND("error.name-not-found", "Name not found"),
35-
LOG_ERROR_SOUND_NOT_VALID("console-error.sound-not-valid", "Warning! The sound you have input: '%sound-string%' is invalid! Please be sure you use a sound that is listed on https://jd.papermc.io/paper/1.21.4/org/bukkit/Sound.html"),
35+
LOG_ERROR_SOUND_NOT_VALID("console-error.sound-not-valid", "Warning! The sound you have input: '%sound-string%' is invalid! " +
36+
"Sounds must now be in namespaced-key format, you can find the namespaced versions here: " +
37+
"https://jd.papermc.io/paper/1.21.5/io/papermc/paper/registry/keys/SoundEventKeys.html"),
3638
LOG_ERROR_USING_DEFAULT_SOUND("console-error.using-default-sound", "Using %default-sound% until a valid sound is provided"),
3739
LOG_ERROR_FLOAT_OUT_OF_RANGE("console-error.float-out-of-range", "The number %number% is out of range! Volume and pitch values must be a number between 0 and 2!"),
3840
LOG_ERROR_USING_DEFAULT_FLOAT("console-error.using-default-float", "Setting to 1.0 until a valid value is provided");
Lines changed: 41 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,47 @@
11
package simplexity.simplepms.logic;
22

33
import org.bukkit.permissions.Permission;
4+
import org.bukkit.permissions.PermissionDefault;
5+
6+
import java.util.Map;
47

58
public class Constants {
6-
public static Permission MESSAGE_SEND = new Permission("message.basic.send");
7-
public static Permission MESSAGE_RECEIVE = new Permission("message.basic.receive");
8-
public static Permission MESSAGE_TOGGLE = new Permission("message.basic.toggle");
9-
public static Permission MESSAGE_BLOCK = new Permission("message.basic.block");
10-
public static Permission RELOAD = new Permission("message.reload");
11-
public static Permission ADMIN_OVERRIDE = new Permission("message.admin.override");
12-
public static Permission ADMIN_SOCIAL_SPY = new Permission("message.admin.social-spy");
13-
public static Permission ADMIN_CONSOLE_SPY = new Permission("message.admin.console-spy");
14-
public static Permission BYPASS_SOCIAL_SPY = new Permission("message.bypass.social-spy");
15-
public static Permission BYPASS_COMMAND_SPY = new Permission("message.bypass.command-spy");
9+
public static Permission MESSAGE_BASIC = new Permission("message.basic", "Base permission for basic functionality",
10+
PermissionDefault.TRUE, Map.of(
11+
"message.basic.send", true,
12+
"message.basic.receive", true,
13+
"message.basic.toggle", true,
14+
"message.basic.block", true
15+
));
16+
public static Permission MESSAGE_ADMIN = new Permission("message.admin", "Base permission for the admin commands",
17+
PermissionDefault.OP, Map.of(
18+
"message.admin.override", true,
19+
"message.admin.social-spy", true,
20+
"message.admin.console-spy", true
21+
));
22+
23+
public static Permission MESSAGE_SEND = new Permission("message.basic.send",
24+
"Allows sending messages", PermissionDefault.TRUE);
25+
public static Permission MESSAGE_RECEIVE = new Permission("message.basic.receive",
26+
"Allows receiving messages", PermissionDefault.TRUE);
27+
public static Permission MESSAGE_TOGGLE = new Permission("message.basic.toggle",
28+
"Allows enabling/disabling direct messages", PermissionDefault.TRUE);
29+
public static Permission MESSAGE_BLOCK = new Permission("message.basic.block",
30+
"Allows blocking direct messages from and to specific users", PermissionDefault.TRUE);
31+
public static Permission PLUGIN_RELOAD = new Permission("message.reload",
32+
"Reloads the Simple PMs plugin", PermissionDefault.OP);
33+
public static Permission ADMIN_OVERRIDE = new Permission("message.admin.override",
34+
"Allows messaging someone who has their messages currently disabled, " +
35+
"has you blocked or does not have permissions to usually see messages", PermissionDefault.OP);
36+
public static Permission ADMIN_SOCIAL_SPY = new Permission("message.admin.social-spy",
37+
"Shows the direct messages of other players for moderation purposes", PermissionDefault.OP);
38+
public static Permission ADMIN_CONSOLE_SPY = new Permission("message.admin.console-spy",
39+
"Shows the direct messages sent to and from the console sender (from this plugin) " +
40+
"to other players", PermissionDefault.OP);
41+
public static Permission BYPASS_SOCIAL_SPY = new Permission("message.bypass.social-spy",
42+
"Prevents messages to and from this player from showing in social spy, " +
43+
"does not prevent the message from being formatted on console", PermissionDefault.OP);
44+
public static Permission BYPASS_COMMAND_SPY = new Permission("message.bypass.command-spy",
45+
"Stops your commands from being shown to others with command spy (if they are configured to be tracked). " +
46+
"Does not prevent the message from being formatted on console", PermissionDefault.OP);
1647
}

src/main/java/simplexity/simplepms/logic/PMHandler.java

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

3+
import org.bukkit.Registry;
34
import org.bukkit.command.CommandSender;
45
import org.bukkit.entity.Player;
56
import simplexity.simplepms.SimplePMs;
@@ -37,7 +38,7 @@ private static void handleMessageSend(CommandSender initiator, CommandSender tar
3738
if (!ConfigHandler.getInstance().sendingMessagePlaysSound()) return;
3839
if (!(initiator instanceof Player player)) return;
3940
player.playSound(player,
40-
ConfigHandler.getInstance().getSendSound(),
41+
Registry.SOUNDS.get(ConfigHandler.getInstance().getSendSound()),
4142
ConfigHandler.getInstance().getSendVolume(),
4243
ConfigHandler.getInstance().getSendPitch());
4344
}
@@ -49,7 +50,7 @@ private static void handleMessageReceive(CommandSender initiator, CommandSender
4950
if (!ConfigHandler.getInstance().receivingMessagePlaysSound()) return;
5051
if (!(target instanceof Player player)) return;
5152
player.playSound(player,
52-
ConfigHandler.getInstance().getReceiveSound(),
53+
Registry.SOUNDS.get(ConfigHandler.getInstance().getReceiveSound()),
5354
ConfigHandler.getInstance().getReceiveVolume(),
5455
ConfigHandler.getInstance().getReceivePitch());
5556
}

src/main/java/simplexity/simplepms/logic/SpyHandler.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package simplexity.simplepms.logic;
22

33
import net.kyori.adventure.text.Component;
4+
import org.bukkit.Registry;
45
import org.bukkit.command.CommandSender;
56
import org.bukkit.entity.Player;
67
import simplexity.simplepms.SimplePMs;
@@ -65,7 +66,7 @@ public static void handleConsoleSpy(PrivateMessageEvent messageEvent) {
6566
private static void playSpySound(Player spyingPlayer) {
6667
if (!ConfigHandler.getInstance().messagePlaysSoundForSpy()) return;
6768
spyingPlayer.playSound(spyingPlayer,
68-
ConfigHandler.getInstance().getSpySound(),
69+
Registry.SOUNDS.get(ConfigHandler.getInstance().getSpySound()),
6970
ConfigHandler.getInstance().getSpyVolume(),
7071
ConfigHandler.getInstance().getSpyPitch());
7172
}

src/main/resources/config.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,16 +37,16 @@ command-spy:
3737
sounds:
3838
received:
3939
enabled: false
40-
sound: BLOCK_NOTE_BLOCK_XYLOPHONE
40+
sound: minecraft:block.note_block.xylophone
4141
pitch: 1.8
4242
volume: 0.5
4343
sent:
4444
enabled: false
45-
sound: ENTITY_ALLAY_ITEM_THROWN
45+
sound: minecraft:entity.allay.item_thrown
4646
pitch: 1.8
4747
volume: 0.5
4848
spy:
4949
enabled: false
50-
sound: ENTITY_ITEM_FRAME_ROTATE_ITEM
50+
sound: minecraft:entity.item_frame.rotate_item
5151
pitch: 1.8
52-
volume: 0.5
52+
volume: 0.5
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
name: SimplePMs
2+
version: '${project.version}'
3+
main: simplexity.simplepms.SimplePMs
4+
api-version: 1.20.6
5+
description: Plugin focused on simple private messaging.
6+
dependencies:
7+
server:
8+
PlaceholderAPI:
9+
load: OMIT
10+
required: false

0 commit comments

Comments
 (0)