Skip to content

Commit 6928823

Browse files
committed
cleanup
1 parent bd25b93 commit 6928823

17 files changed

Lines changed: 86 additions & 57 deletions

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

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -32,19 +32,32 @@ public final class SimplePMs extends JavaPlugin {
3232
@Override
3333
public void onEnable() {
3434
instance = this;
35-
this.getServer().getPluginManager().registerEvents(new QuitListener(), this);
36-
this.getServer().getPluginManager().registerEvents(new PreCommandListener(), this);
37-
this.getServer().getPluginManager().registerEvents(new JoinListener(), this);
38-
if (this.getServer().getPluginManager().getPlugin("PlaceholderAPI") != null) {
35+
consoleSender = getServer().getConsoleSender();
36+
if (getServer().getPluginManager().getPlugin("PlaceholderAPI") != null) {
3937
papiEnabled = true;
4038
}
41-
consoleSender = this.getServer().getConsoleSender();
42-
this.saveDefaultConfig();
39+
SqlHandler.getInstance().init();
40+
loadConfigStuff();
41+
registerListeners();
42+
registerCommands();
43+
registerPermissions();
44+
}
45+
46+
private void registerListeners() {
47+
getServer().getPluginManager().registerEvents(new QuitListener(), this);
48+
getServer().getPluginManager().registerEvents(new PreCommandListener(), this);
49+
getServer().getPluginManager().registerEvents(new JoinListener(), this);
50+
}
51+
52+
private void loadConfigStuff() {
53+
saveDefaultConfig();
4354
getConfig().options().copyDefaults(true);
4455
saveConfig();
4556
ConfigHandler.getInstance().loadConfigValues();
46-
SqlHandler.getInstance().init();
47-
this.getLifecycleManager().registerEventHandler(LifecycleEvents.COMMANDS, commands -> {
57+
}
58+
59+
private void registerCommands() {
60+
getLifecycleManager().registerEventHandler(LifecycleEvents.COMMANDS, commands -> {
4861
commands.registrar().register(PrivateMessage.createCommand());
4962
commands.registrar().register(PrivateMessage.createTellAlias());
5063
commands.registrar().register(PrivateMessage.createWhisperAlias());
@@ -58,6 +71,9 @@ public void onEnable() {
5871
commands.registrar().register(Reload.createCommand());
5972
commands.registrar().register(Blocklist.createCommand());
6073
});
74+
}
75+
76+
private void registerPermissions() {
6177
getServer().getPluginManager().addPermission(Constants.MESSAGE_BASIC);
6278
getServer().getPluginManager().addPermission(Constants.MESSAGE_ADMIN);
6379
getServer().getPluginManager().addPermission(Constants.MESSAGE_SEND);
@@ -73,7 +89,6 @@ public void onEnable() {
7389
}
7490

7591
@Override
76-
7792
public void onDisable() {
7893
SqlHandler.getInstance().shutdownConnection();
7994
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@
99
import io.papermc.paper.command.brigadier.CommandSourceStack;
1010
import io.papermc.paper.command.brigadier.Commands;
1111
import org.bukkit.command.CommandSender;
12+
import simplexity.simplepms.commands.arguments.Target;
1213
import simplexity.simplepms.commands.arguments.TargetArgument;
1314
import simplexity.simplepms.commands.util.MessageChecks;
1415
import simplexity.simplepms.logic.Constants;
1516
import simplexity.simplepms.logic.PMHandler;
16-
import simplexity.simplepms.commands.arguments.Target;
1717

1818
@SuppressWarnings("UnstableApiUsage")
1919
public class PrivateMessage {
@@ -40,7 +40,7 @@ public static LiteralCommandNode<CommandSourceStack> createWhisperAlias() {
4040
.then(messageArg())).build();
4141
}
4242

43-
private static RequiredArgumentBuilder<CommandSourceStack, Target> targetArg(){
43+
private static RequiredArgumentBuilder<CommandSourceStack, Target> targetArg() {
4444
TargetArgument targetArg = new TargetArgument();
4545
return Commands.argument("target", targetArg)
4646
.suggests(targetArg::suggestOnlinePlayers);

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,19 +16,19 @@
1616
@SuppressWarnings({"UnstableApiUsage", "SameReturnValue"})
1717
public class SocialSpy {
1818

19-
public static LiteralCommandNode<CommandSourceStack> createCommand(){
19+
public static LiteralCommandNode<CommandSourceStack> createCommand() {
2020
return Commands.literal("socialspy")
2121
.requires(SocialSpy::canExecute)
2222
.executes(SocialSpy::execute).build();
2323
}
2424

25-
public static LiteralCommandNode<CommandSourceStack> createAlias(){
25+
public static LiteralCommandNode<CommandSourceStack> createAlias() {
2626
return Commands.literal("ss")
2727
.requires(SocialSpy::canExecute)
2828
.executes(SocialSpy::execute).build();
2929
}
3030

31-
private static boolean canExecute(CommandSourceStack css){
31+
private static boolean canExecute(CommandSourceStack css) {
3232
if (!(css.getSender() instanceof Player)) return false;
3333
return css.getSender().hasPermission(Constants.ADMIN_SOCIAL_SPY);
3434
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@
1818
import simplexity.simplepms.config.LocaleMessage;
1919
import simplexity.simplepms.logic.Constants;
2020
import simplexity.simplepms.logic.UnblockHandler;
21-
import simplexity.simplepms.saving.objects.PlayerBlock;
2221
import simplexity.simplepms.saving.Cache;
22+
import simplexity.simplepms.saving.objects.PlayerBlock;
2323

2424
import java.util.List;
2525
import java.util.concurrent.CompletableFuture;

src/main/java/simplexity/simplepms/commands/arguments/TargetArgument.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ public class TargetArgument implements CustomArgumentType<Target, String> {
2828
@Override
2929
public @NotNull Target parse(@NotNull StringReader reader) throws CommandSyntaxException {
3030
String targetName = reader.readString();
31-
if (ConfigHandler.getInstance().getValidNamesForConsole().contains(targetName.toLowerCase())) return new Target(consoleSender, targetName);
31+
if (ConfigHandler.getInstance().getValidNamesForConsole().contains(targetName.toLowerCase()))
32+
return new Target(consoleSender, targetName);
3233
Player targetPlayer = Bukkit.getPlayerExact(targetName);
3334
if (targetPlayer != null) return new Target(targetPlayer, targetName);
3435
throw Exceptions.ERROR_INVALID_USER.create(targetName);

src/main/java/simplexity/simplepms/commands/util/MessageChecks.java

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,27 +5,27 @@
55
import org.bukkit.entity.Player;
66
import simplexity.simplepms.config.ConfigHandler;
77
import simplexity.simplepms.logic.Constants;
8+
import simplexity.simplepms.saving.Cache;
89
import simplexity.simplepms.saving.objects.PlayerBlock;
910
import simplexity.simplepms.saving.objects.PlayerSettings;
10-
import simplexity.simplepms.saving.Cache;
1111

1212
import java.util.List;
1313

1414
public class MessageChecks {
1515

1616

1717
public static void userChecks(CommandSender initiator, CommandSender target, String providedName) throws CommandSyntaxException {
18-
if (target instanceof Player playerTarget) {
19-
if (!initiator.hasPermission(Constants.ADMIN_OVERRIDE)) {
20-
targetCanGetMessageCheck(playerTarget);
21-
}
22-
if (initiator instanceof Player playerInitiator) {
23-
MessageChecks.ownMessagesDisabledCheck(playerInitiator);
24-
MessageChecks.initiatorBlockedTargetCheck(playerInitiator, playerTarget);
18+
if (initiator instanceof Player playerInitiator) {
19+
ownMessagesDisabledCheck(playerInitiator);
20+
if (target instanceof Player playerTarget) {
21+
initiatorBlockedTargetCheck(playerInitiator, playerTarget);
2522
if (!initiator.hasPermission(Constants.ADMIN_OVERRIDE)) {
26-
MessageChecks.targetBlockedInitiatorCheck(playerInitiator, playerTarget);
27-
MessageChecks.vanishCheck(playerInitiator, playerTarget, providedName);
23+
targetCanGetMessageCheck(playerTarget);
24+
targetBlockedInitiatorCheck(playerInitiator, playerTarget);
25+
vanishCheck(playerInitiator, playerTarget, providedName);
2826
}
27+
} else {
28+
canSendToConsole(providedName);
2929
}
3030
}
3131
}
@@ -58,6 +58,11 @@ private static void initiatorBlockedTargetCheck(Player initiatingPlayer, Player
5858
throw Exceptions.ERROR_CANNOT_MESSAGE_SOMEONE_YOU_HAVE_BLOCKED.create();
5959
}
6060

61+
private static void canSendToConsole(String providedName) throws CommandSyntaxException {
62+
if (!ConfigHandler.getInstance().canPlayersSendToConsole())
63+
throw Exceptions.ERROR_INVALID_USER.create(providedName);
64+
}
65+
6166
private static boolean userBlocked(Player blocklistPlayer, Player potentialBlock) {
6267
List<PlayerBlock> playerBlocks = Cache.blockList.get(blocklistPlayer.getUniqueId());
6368
if (playerBlocks == null) {

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

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

3-
import net.kyori.adventure.key.Key;
43
import org.bukkit.NamespacedKey;
54
import org.bukkit.Registry;
65
import org.bukkit.Sound;
76
import org.bukkit.configuration.file.FileConfiguration;
7+
import org.jetbrains.annotations.NotNull;
88
import simplexity.simplepms.SimplePMs;
99

1010
import java.util.ArrayList;
@@ -23,7 +23,9 @@ public static ConfigHandler getInstance() {
2323
private final Logger logger = SimplePMs.getInstance().getLogger();
2424
private boolean mysqlEnabled, playersSendToConsole, playersSendToHiddenPlayers, consoleHasSocialSpy,
2525
commandSpyEnabled, consoleHasCommandSpy, receiveSoundEnabled, sendSoundEnabled, spySoundEnabled;
26-
private NamespacedKey receiveSound, sendSound, spySound;
26+
private NamespacedKey receiveSound = Registry.SOUNDS.getKey(Sound.BLOCK_NOTE_BLOCK_XYLOPHONE);
27+
private NamespacedKey sendSound = Registry.SOUNDS.getKey(Sound.ENTITY_ALLAY_ITEM_THROWN);
28+
private NamespacedKey spySound = Registry.SOUNDS.getKey(Sound.ENTITY_ITEM_FRAME_ROTATE_ITEM);
2729
private float receivePitch, receiveVolume, sendPitch, sendVolume, spyPitch, spyVolume;
2830
private String mysqlIp, mysqlName, mysqlUsername, mysqlPassword, normalFormat, socialSpyFormat;
2931
private final List<String> validNamesForConsole = new ArrayList<>();
@@ -64,26 +66,26 @@ private void updateHashSet(HashSet<String> set, List<String> list) {
6466

6567
private void loadReceiveSoundInfo(FileConfiguration config) {
6668
String soundString = config.getString("sounds.received.sound", "minecraft:block.note_block.xylophone");
67-
receiveSound = getValidSound(soundString, Registry.SOUNDS.getKey(Sound.BLOCK_NOTE_BLOCK_XYLOPHONE));
69+
receiveSound = getValidSound(soundString, Registry.SOUNDS.getKey(Sound.BLOCK_NOTE_BLOCK_XYLOPHONE));
6870
receivePitch = getValidFloat(config.getDouble("sounds.received.pitch", 1.8));
6971
receiveVolume = getValidFloat(config.getDouble("sounds.received.volume", 0.5));
7072
}
7173

72-
private void loadSendSoundInfo(FileConfiguration config){
74+
private void loadSendSoundInfo(FileConfiguration config) {
7375
String soundString = config.getString("sounds.sent.sound", "minecraft:entity.allay.item_thrown");
74-
sendSound = getValidSound(soundString, Registry.SOUNDS.getKey(Sound.ENTITY_ALLAY_ITEM_THROWN));
76+
sendSound = getValidSound(soundString, Registry.SOUNDS.getKey(Sound.ENTITY_ALLAY_ITEM_THROWN));
7577
sendPitch = getValidFloat(config.getDouble("sounds.sent.pitch", 1.8));
7678
sendVolume = getValidFloat(config.getDouble("sounds.sent.volume", 0.5));
7779
}
7880

79-
private void loadSpySoundInfo(FileConfiguration config){
81+
private void loadSpySoundInfo(FileConfiguration config) {
8082
String soundString = config.getString("sounds.spy.sound", "minecraft:entity.item_frame.rotate_item");
8183
spySound = getValidSound(soundString, Registry.SOUNDS.getKey(Sound.ENTITY_ITEM_FRAME_ROTATE_ITEM));
8284
spyPitch = getValidFloat(config.getDouble("sounds.spy.pitch", 1.8));
8385
spyVolume = getValidFloat(config.getDouble("sounds.spy.volume", 0.5));
8486
}
8587

86-
private NamespacedKey getValidSound(String soundString, NamespacedKey defaultSound){
88+
private NamespacedKey getValidSound(String soundString, NamespacedKey defaultSound) {
8789
NamespacedKey key = NamespacedKey.fromString(soundString);
8890
if (key == null || Registry.SOUNDS.get(key) == null) {
8991
String warning = LocaleMessage.LOG_ERROR_SOUND_NOT_VALID.getMessage().replace("%sound-string%", soundString);
@@ -95,7 +97,7 @@ private NamespacedKey getValidSound(String soundString, NamespacedKey defaultSou
9597
return key;
9698
}
9799

98-
private float getValidFloat(double numberToCheck){
100+
private float getValidFloat(double numberToCheck) {
99101
if (numberToCheck <= 2 && numberToCheck >= 0) return (float) numberToCheck;
100102
String warning = LocaleMessage.LOG_ERROR_FLOAT_OUT_OF_RANGE.getMessage().replace("%number%", String.valueOf(numberToCheck));
101103
logger.warning(warning);
@@ -159,15 +161,15 @@ public boolean isCommandSpyEnabled() {
159161
return commandSpyEnabled;
160162
}
161163

162-
public boolean receivingMessagePlaysSound(){
164+
public boolean receivingMessagePlaysSound() {
163165
return receiveSoundEnabled;
164166
}
165167

166-
public boolean sendingMessagePlaysSound(){
168+
public boolean sendingMessagePlaysSound() {
167169
return sendSoundEnabled;
168170
}
169171

170-
public boolean messagePlaysSoundForSpy(){
172+
public boolean messagePlaysSoundForSpy() {
171173
return spySoundEnabled;
172174
}
173175

@@ -179,14 +181,17 @@ public String getSocialSpyFormat() {
179181
return socialSpyFormat;
180182
}
181183

184+
@NotNull
182185
public NamespacedKey getReceiveSound() {
183186
return receiveSound;
184187
}
185188

189+
@NotNull
186190
public NamespacedKey getSendSound() {
187191
return sendSound;
188192
}
189193

194+
@NotNull
190195
public NamespacedKey getSpySound() {
191196
return spySound;
192197
}

src/main/java/simplexity/simplepms/events/BlockUserEvent.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ public static HandlerList getHandlerList() {
6969

7070
/**
7171
* Gets the UUID of the player doing the blocking
72+
*
7273
* @return UUID
7374
*/
7475

@@ -129,6 +130,7 @@ public String getBlockedPlayerName() {
129130
* This is solely for player-readable identification
130131
* This is used in the block list and in the unblock command, but UUID is used for actual verification.
131132
* Display names can be used here
133+
*
132134
* @param blockedPlayerName String name
133135
*/
134136
public void setBlockedPlayerName(@NotNull String blockedPlayerName) {

src/main/java/simplexity/simplepms/events/PrivateMessageEvent.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ public CommandSender getRecipient() {
6868
* @param recipient CommandSender
6969
*/
7070

71-
public void setRecipient(CommandSender recipient){
71+
public void setRecipient(CommandSender recipient) {
7272
this.recipient = recipient;
7373
}
7474

@@ -88,7 +88,7 @@ public String getMessageContent() {
8888
* @param messageContent String
8989
*/
9090

91-
public void setMessageContent(String messageContent){
91+
public void setMessageContent(String messageContent) {
9292
this.messageContent = messageContent;
9393
}
9494

@@ -139,4 +139,3 @@ public static HandlerList getHandlerList() {
139139
return handlers;
140140
}
141141
}
142-

src/main/java/simplexity/simplepms/events/UnblockUserEvent.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ public UnblockUserEvent(UUID initiatorUuid, UUID blockedPlayerUuid) {
2121

2222
/**
2323
* Gets whether this event has been cancelled
24+
*
2425
* @return boolean Cancelled
2526
*/
2627

0 commit comments

Comments
 (0)