Skip to content

Commit f04079b

Browse files
committed
Cleanup, async sql calls, javadocs
1 parent 25d4219 commit f04079b

8 files changed

Lines changed: 280 additions & 78 deletions

File tree

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

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import simplexity.simplepms.config.ConfigHandler;
1818
import simplexity.simplepms.listeners.LoginListener;
1919
import simplexity.simplepms.listeners.PreCommandListener;
20+
import simplexity.simplepms.listeners.PreLoginListener;
2021
import simplexity.simplepms.listeners.QuitListener;
2122

2223
import java.util.HashSet;
@@ -32,21 +33,19 @@ public final class SimplePMs extends JavaPlugin {
3233
private static ConsoleCommandSender consoleSender;
3334

3435

35-
3636
public static Set<Player> getSpyingPlayers() {
3737
return spyingPlayers;
3838
}
3939

4040
@Override
4141
public void onEnable() {
4242
instance = this;
43-
this.getServer().getPluginManager().registerEvents(new LoginListener(), this);
43+
this.getServer().getPluginManager().registerEvents(new PreLoginListener(), this);
4444
this.getServer().getPluginManager().registerEvents(new QuitListener(), this);
4545
this.getServer().getPluginManager().registerEvents(new PreCommandListener(), this);
46+
this.getServer().getPluginManager().registerEvents(new LoginListener(), this);
4647
if (this.getServer().getPluginManager().getPlugin("PlaceholderAPI") != null) {
4748
papiEnabled = true;
48-
} else {
49-
this.getLogger().info("You do not have PlaceholderAPI loaded on your server. Any PlaceholderAPI placeholders used in this plugin's messages, will not work.");
5049
}
5150
consoleSender = this.getServer().getConsoleSender();
5251
this.saveDefaultConfig();

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

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import javax.annotation.Nullable;
99
import java.util.UUID;
1010

11+
@SuppressWarnings("unused")
1112
public class BlockUserEvent extends Event implements Cancellable {
1213
private boolean cancelled;
1314
private UUID initiatorUuid;
@@ -25,16 +26,34 @@ public BlockUserEvent(@NotNull UUID initiatorUuid, @NotNull UUID blockedPlayerUu
2526
}
2627

2728

29+
/**
30+
* Gets whether this event has been cancelled
31+
*
32+
* @return boolean Cancelled
33+
*/
34+
2835
@Override
2936
public boolean isCancelled() {
3037
return cancelled;
3138
}
3239

40+
/**
41+
* Sets whether this event should be cancelled
42+
*
43+
* @param cancel boolean
44+
*/
45+
3346
@Override
3447
public void setCancelled(boolean cancel) {
3548
this.cancelled = cancel;
3649
}
3750

51+
/**
52+
* Gets the handlerList for this event
53+
*
54+
* @return HandlerList
55+
*/
56+
3857
public @NotNull HandlerList getHandlers() {
3958
return handlers;
4059
}
@@ -48,38 +67,90 @@ public static HandlerList getHandlerList() {
4867
return handlers;
4968
}
5069

70+
/**
71+
* Gets the UUID of the player doing the blocking
72+
* @return UUID
73+
*/
74+
5175
@NotNull
5276
public UUID getInitiatorUuid() {
5377
return initiatorUuid;
5478
}
5579

80+
/**
81+
* Sets the UUID for which player will have their block list altered
82+
* Changing this UUID will change which user has a new player added to their blocked list
83+
* This method expects a Player UUID, using andy UUID that does not belong to a player will lead to
84+
* unexpected and unsupported behavior
85+
*
86+
* @param initiatorUuid UUID
87+
*/
5688
public void setInitiatorUuid(@NotNull UUID initiatorUuid) {
5789
this.initiatorUuid = initiatorUuid;
5890
}
5991

92+
/**
93+
* Gets the UUID of the player being blocked in this event
94+
*
95+
* @return UUID player Being blocked
96+
*/
6097
@NotNull
6198
public UUID getBlockedPlayerUuid() {
6299
return blockedPlayerUuid;
63100
}
64101

102+
/**
103+
* Sets the UUID of which player should be blocked
104+
* Changing this UUID will alter which user is being placed into the player's block list
105+
* This method expects a Player UUID, using any UUID that does not belong to a player will lead to
106+
* unexpected and unsupported behavior
107+
*
108+
* @param blockedPlayerUuid UUID
109+
*/
65110
public void setBlockedPlayerUuid(@NotNull UUID blockedPlayerUuid) {
66111
this.blockedPlayerUuid = blockedPlayerUuid;
67112
}
68113

114+
/**
115+
* Gets the name of the player being blocked
116+
* This name is not automatically updated when someone's username changes
117+
* it is only used as a player-readable identifier for remembering who they blocked and being able to unblock them
118+
* All verification is done through UUID
119+
*
120+
* @return String name
121+
*/
69122
@NotNull
70123
public String getBlockedPlayerName() {
71124
return blockedPlayerName;
72125
}
73126

127+
/**
128+
* Sets the name of the player being blocked, as of the current time.
129+
* This is solely for player-readable identification
130+
* This is used in the block list and in the unblock command, but UUID is used for actual verification.
131+
* Display names can be used here
132+
* @param blockedPlayerName String name
133+
*/
74134
public void setBlockedPlayerName(@NotNull String blockedPlayerName) {
75135
this.blockedPlayerName = blockedPlayerName;
76136
}
77137

138+
/**
139+
* Gets the provided reason for blocking. May be null if no reason was provided.
140+
*
141+
* @return String block reason
142+
*/
78143
@Nullable
79144
public String getBlockReason() {
80145
return blockReason;
81146
}
82147

148+
/**
149+
* Sets the reason for blocking the other player.
150+
* This is displayed in the user's own blocklist, and when hovering over usernames when unblocking
151+
*
152+
* @param blockReason String
153+
*/
83154
public void setBlockReason(@Nullable String blockReason) {
84155
this.blockReason = blockReason;
85156
}

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

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
/**
1414
* Called when a private message is sent
1515
*/
16+
@SuppressWarnings("unused")
1617
public class PrivateMessageEvent extends Event implements Cancellable {
1718

1819
private CommandSender initiator;
@@ -30,7 +31,7 @@ public PrivateMessageEvent(@NotNull CommandSender initiator, @NotNull CommandSen
3031
}
3132

3233
/**
33-
* Gets the CommandSender who sent the message
34+
* Gets the CommandSender who sent the message.
3435
*
3536
* @return CommandSender
3637
*/
@@ -39,7 +40,11 @@ public CommandSender getInitiator() {
3940
}
4041

4142
/**
42-
* Sets the CommandSender who sent the message
43+
* Sets which CommandSender will start this message.
44+
* Expected types are either a Player or a ConsoleCommandSender
45+
* Using other types of CommandSender may lead to unexpected and unsupported behavior
46+
*
47+
* @param initiator CommandSender
4348
*/
4449

4550
public void setInitiator(CommandSender initiator) {
@@ -56,24 +61,31 @@ public CommandSender getRecipient() {
5661
}
5762

5863
/**
59-
* Sets the CommandSender who will receive the message
64+
* Sets which CommandSender will receive this message.
65+
* Expected types are either a Player or a ConsoleCommandSender
66+
* Using other types of CommandSender may lead to unexpected and unsupported behavior
67+
*
68+
* @param recipient CommandSender
6069
*/
6170

6271
public void setRecipient(CommandSender recipient){
6372
this.recipient = recipient;
6473
}
6574

6675
/**
67-
* Gets the content of the message being sent
76+
* Gets the message that is going to be sent from this event
6877
*
69-
* @return String
78+
* @return String message
7079
*/
7180
public String getMessageContent() {
7281
return messageContent;
7382
}
7483

7584
/**
76-
* Sets the message content
85+
* Sets the message that will be sent from this event.
86+
* Note that this only affects the actual message content and not the way the message is formatted
87+
*
88+
* @param messageContent String
7789
*/
7890

7991
public void setMessageContent(String messageContent){
@@ -108,6 +120,12 @@ public void setCancelled(boolean cancel) {
108120
}
109121

110122

123+
/**
124+
* Gets the handlerList for this event
125+
*
126+
* @return HandlerList
127+
*/
128+
111129
public @NotNull HandlerList getHandlers() {
112130
return handlers;
113131
}

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

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,28 +7,45 @@
77

88
import java.util.UUID;
99

10+
@SuppressWarnings("unused")
1011
public class UnblockUserEvent extends Event implements Cancellable {
1112
private boolean cancelled;
1213
private UUID initiatorUuid;
1314
private UUID blockedPlayerUuid;
1415
private static final HandlerList handlers = new HandlerList();
1516

16-
public UnblockUserEvent(UUID initiatorUuid, UUID blockedPlayerUuid){
17+
public UnblockUserEvent(UUID initiatorUuid, UUID blockedPlayerUuid) {
1718
this.initiatorUuid = initiatorUuid;
1819
this.blockedPlayerUuid = blockedPlayerUuid;
1920
}
2021

22+
/**
23+
* Gets whether this event has been cancelled
24+
* @return boolean Cancelled
25+
*/
2126

2227
@Override
2328
public boolean isCancelled() {
2429
return cancelled;
2530
}
2631

32+
/**
33+
* Sets whether this event should be cancelled
34+
*
35+
* @param cancel boolean
36+
*/
37+
2738
@Override
2839
public void setCancelled(boolean cancel) {
2940
this.cancelled = cancel;
3041
}
3142

43+
/**
44+
* Gets the handler list, idk bukkit requires 2 of these or I'm just doing it wrong
45+
*
46+
* @return HandlerList
47+
*/
48+
3249
public @NotNull HandlerList getHandlers() {
3350
return handlers;
3451
}
@@ -42,18 +59,39 @@ public static HandlerList getHandlerList() {
4259
return handlers;
4360
}
4461

62+
/**
63+
* Gets the UUID of the player who requested to unblock someone
64+
*
65+
* @return UUID
66+
*/
4567
public UUID getInitiatorUuid() {
4668
return initiatorUuid;
4769
}
4870

71+
/**
72+
* Sets the UUID of the person who will request to unblock someone
73+
*
74+
* @param initiatorUuid UUID
75+
*/
76+
4977
public void setInitiatorUuid(UUID initiatorUuid) {
5078
this.initiatorUuid = initiatorUuid;
5179
}
5280

81+
/**
82+
* Gets the UUID of the player who will be unblocked
83+
*
84+
* @return UUID
85+
*/
5386
public UUID getBlockedPlayerUuid() {
5487
return blockedPlayerUuid;
5588
}
5689

90+
/**
91+
* Sets the UUID of the player who will be unblocked
92+
*
93+
* @param blockedPlayerUuid UUID
94+
*/
5795
public void setBlockedPlayerUuid(UUID blockedPlayerUuid) {
5896
this.blockedPlayerUuid = blockedPlayerUuid;
5997
}
Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package simplexity.simplepms.listeners;
22

3-
import org.bukkit.entity.Player;
43
import org.bukkit.event.EventHandler;
54
import org.bukkit.event.Listener;
65
import org.bukkit.event.player.PlayerLoginEvent;
@@ -11,14 +10,9 @@
1110
public class LoginListener implements Listener {
1211

1312
@EventHandler
14-
public void onLogin(PlayerLoginEvent event) {
15-
Player player = event.getPlayer();
16-
Cache.addPlayerSettingsToCache(player.getUniqueId());
17-
Cache.addBlockListToCache(player.getUniqueId());
18-
PlayerSettings playerSettings = Cache.getPlayerSettings(player.getUniqueId());
19-
if (playerSettings.isSocialSpyEnabled()) {
20-
SimplePMs.getSpyingPlayers().add(player);
21-
}
22-
}
13+
public void onLogin(PlayerLoginEvent loginEvent) {
14+
PlayerSettings settings = Cache.getPlayerSettings(loginEvent.getPlayer().getUniqueId());
15+
if (settings.isSocialSpyEnabled()) SimplePMs.getSpyingPlayers().add(loginEvent.getPlayer());
2316

17+
}
2418
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package simplexity.simplepms.listeners;
2+
3+
import com.destroystokyo.paper.profile.PlayerProfile;
4+
import org.bukkit.event.EventHandler;
5+
import org.bukkit.event.Listener;
6+
import org.bukkit.event.player.AsyncPlayerPreLoginEvent;
7+
import simplexity.simplepms.saving.Cache;
8+
9+
public class PreLoginListener implements Listener {
10+
11+
@EventHandler
12+
public void onPreLogin(AsyncPlayerPreLoginEvent event) {
13+
PlayerProfile player = event.getPlayerProfile();
14+
Cache.addPlayerSettingsToCache(player.getId());
15+
Cache.addBlockListToCache(player.getId());
16+
}
17+
18+
}

0 commit comments

Comments
 (0)