Skip to content

Commit 26329f2

Browse files
committed
SQL stuff is all async now, I think
1 parent f04079b commit 26329f2

19 files changed

Lines changed: 178 additions & 129 deletions

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

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import io.papermc.paper.plugin.lifecycle.event.types.LifecycleEvents;
44
import net.kyori.adventure.text.minimessage.MiniMessage;
55
import org.bukkit.command.ConsoleCommandSender;
6-
import org.bukkit.entity.Player;
76
import org.bukkit.plugin.Plugin;
87
import org.bukkit.plugin.java.JavaPlugin;
98
import simplexity.simplepms.commands.Block;
@@ -15,35 +14,26 @@
1514
import simplexity.simplepms.commands.SocialSpy;
1615
import simplexity.simplepms.commands.Unblock;
1716
import simplexity.simplepms.config.ConfigHandler;
18-
import simplexity.simplepms.listeners.LoginListener;
17+
import simplexity.simplepms.listeners.JoinListener;
1918
import simplexity.simplepms.listeners.PreCommandListener;
20-
import simplexity.simplepms.listeners.PreLoginListener;
2119
import simplexity.simplepms.listeners.QuitListener;
22-
23-
import java.util.HashSet;
24-
import java.util.Set;
20+
import simplexity.simplepms.saving.SqlHandler;
2521

2622
@SuppressWarnings("UnstableApiUsage")
2723
public final class SimplePMs extends JavaPlugin {
2824

2925
private static Plugin instance;
3026
private static final MiniMessage miniMessage = MiniMessage.miniMessage();
3127
private static boolean papiEnabled = false;
32-
private static final HashSet<Player> spyingPlayers = new HashSet<>();
3328
private static ConsoleCommandSender consoleSender;
3429

3530

36-
public static Set<Player> getSpyingPlayers() {
37-
return spyingPlayers;
38-
}
39-
4031
@Override
4132
public void onEnable() {
4233
instance = this;
43-
this.getServer().getPluginManager().registerEvents(new PreLoginListener(), this);
4434
this.getServer().getPluginManager().registerEvents(new QuitListener(), this);
4535
this.getServer().getPluginManager().registerEvents(new PreCommandListener(), this);
46-
this.getServer().getPluginManager().registerEvents(new LoginListener(), this);
36+
this.getServer().getPluginManager().registerEvents(new JoinListener(), this);
4737
if (this.getServer().getPluginManager().getPlugin("PlaceholderAPI") != null) {
4838
papiEnabled = true;
4939
}
@@ -52,6 +42,7 @@ public void onEnable() {
5242
getConfig().options().copyDefaults(true);
5343
saveConfig();
5444
ConfigHandler.getInstance().loadConfigValues();
45+
SqlHandler.getInstance().init();
5546
this.getLifecycleManager().registerEventHandler(LifecycleEvents.COMMANDS, commands -> {
5647
commands.registrar().register(PrivateMessage.createCommand());
5748
commands.registrar().register(PrivateMessage.createTellAlias());
@@ -68,6 +59,12 @@ public void onEnable() {
6859
});
6960
}
7061

62+
@Override
63+
64+
public void onDisable() {
65+
SqlHandler.getInstance().shutdownConnection();
66+
}
67+
7168
public static MiniMessage getMiniMessage() {
7269
return miniMessage;
7370
}

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,11 @@ public static LiteralCommandNode<CommandSourceStack> createCommand() {
3838
message = message.appendNewline();
3939
message = message.append(miniMessage.deserialize(
4040
LocaleMessage.BLOCKLIST_NAME.getMessage(),
41-
Placeholder.parsed("name", block.blockedPlayerName())
41+
Placeholder.parsed("name", block.getBlockedPlayerName())
4242
));
43-
if (block.blockReason() == null || block.blockReason().isEmpty()) continue;
43+
if (block.getBlockReason() == null || block.getBlockReason().isEmpty()) continue;
4444
message = message.append(miniMessage.deserialize(LocaleMessage.BLOCKLIST_REASON.getMessage(),
45-
Placeholder.parsed("reason", block.blockReason())));
45+
Placeholder.parsed("reason", block.getBlockReason())));
4646
}
4747
player.sendMessage(message);
4848
return Command.SINGLE_SUCCESS;

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import simplexity.simplepms.config.ConfigHandler;
99
import simplexity.simplepms.config.LocaleMessage;
1010
import simplexity.simplepms.logic.Constants;
11+
import simplexity.simplepms.saving.SqlHandler;
1112

1213
@SuppressWarnings("UnstableApiUsage")
1314
public class Reload {
@@ -18,6 +19,7 @@ public static LiteralCommandNode<CommandSourceStack> createCommand() {
1819
.executes(ctx -> {
1920
CommandSender sender = ctx.getSource().getSender();
2021
ConfigHandler.getInstance().loadConfigValues();
22+
SqlHandler.getInstance().reloadDatabase();
2123
sender.sendRichMessage(LocaleMessage.RELOADED.getMessage());
2224
return Command.SINGLE_SUCCESS;
2325
}).build();

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
import io.papermc.paper.command.brigadier.CommandSourceStack;
77
import io.papermc.paper.command.brigadier.Commands;
88
import org.bukkit.entity.Player;
9-
import simplexity.simplepms.SimplePMs;
109
import simplexity.simplepms.config.LocaleMessage;
1110
import simplexity.simplepms.logic.Constants;
1211
import simplexity.simplepms.saving.Cache;
@@ -41,12 +40,12 @@ private static int execute(CommandContext<CommandSourceStack> ctx) {
4140
if (settings == null || settings.isSocialSpyEnabled()) {
4241
Cache.updateSocialSpySettings(uuid, false);
4342
player.sendRichMessage(LocaleMessage.SOCIAL_SPY_DISABLED.getMessage());
44-
SimplePMs.getSpyingPlayers().remove(player);
43+
Cache.getSpyingPlayers().remove(player);
4544
return Command.SINGLE_SUCCESS;
4645
}
4746
Cache.updateSocialSpySettings(uuid, true);
4847
player.sendRichMessage(LocaleMessage.SOCIAL_SPY_ENABLED.getMessage());
49-
SimplePMs.getSpyingPlayers().add(player);
48+
Cache.getSpyingPlayers().add(player);
5049
return Command.SINGLE_SUCCESS;
5150
}
5251

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,8 @@ private static CompletableFuture<Suggestions> suggestBlockedUsers(final CommandC
6363
List<PlayerBlock> blockedPlayers = Cache.getBlockList(playerSender.getUniqueId());
6464
if (blockedPlayers.isEmpty()) return builder.buildFuture();
6565
for (PlayerBlock block : blockedPlayers) {
66-
builder.suggest(block.blockedPlayerName(),
67-
MessageComponentSerializer.message().serialize(Component.text(block.blockReason())));
66+
builder.suggest(block.getBlockedPlayerName(),
67+
MessageComponentSerializer.message().serialize(Component.text(block.getBlockReason())));
6868
}
6969
return builder.buildFuture();
7070
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public class OfflinePlayerArgument implements CustomArgumentType<OfflinePlayer,
4343

4444
@Override
4545
public @NotNull ArgumentType<String> getNativeType() {
46-
return StringArgumentType.word();
46+
return StringArgumentType.greedyString();
4747
}
4848

4949
/**

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ private static boolean userBlocked(Player blocklistPlayer, Player potentialBlock
6464
return false;
6565
}
6666
for (PlayerBlock playerBlock : playerBlocks) {
67-
if (playerBlock.blockedPlayerUUID().equals(potentialBlock.getUniqueId())) {
67+
if (playerBlock.getBlockedPlayerUUID().equals(potentialBlock.getUniqueId())) {
6868
return true;
6969
}
7070
}

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import org.bukkit.Sound;
44
import org.bukkit.configuration.file.FileConfiguration;
55
import simplexity.simplepms.SimplePMs;
6-
import simplexity.simplepms.saving.SqlHandler;
76

87
import java.util.ArrayList;
98
import java.util.HashSet;
@@ -30,7 +29,6 @@ public static ConfigHandler getInstance() {
3029
public void loadConfigValues() {
3130
SimplePMs.getInstance().reloadConfig();
3231
FileConfiguration config = SimplePMs.getInstance().getConfig();
33-
SqlHandler.getInstance().init();
3432
LocaleHandler.getInstance().reloadLocale();
3533
List<String> commands = config.getStringList("command-spy.commands");
3634
List<String> consoleNames = config.getStringList("valid-console-names");

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ public enum LocaleMessage {
3131
ERROR_CANNOT_MESSAGE_SOMEONE_YOU_BLOCKED("error.cannot-message-someone-you-blocked", "<red>Sorry, you cannot message someone you currently have blocked.</red>"),
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>"),
34+
ERROR_NAME_NOT_FOUND("error.name-not-found", "Name not found"),
3435
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"),
3536
LOG_ERROR_USING_DEFAULT_SOUND("console-error.using-default-sound", "Using %default-sound% until a valid sound is provided"),
3637
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!"),
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package simplexity.simplepms.listeners;
2+
3+
import org.bukkit.entity.Player;
4+
import org.bukkit.event.EventHandler;
5+
import org.bukkit.event.Listener;
6+
import org.bukkit.event.player.PlayerJoinEvent;
7+
import simplexity.simplepms.logic.Constants;
8+
import simplexity.simplepms.saving.Cache;
9+
10+
import java.util.UUID;
11+
12+
public class JoinListener implements Listener {
13+
14+
@EventHandler
15+
public void onLogin(PlayerJoinEvent joinEvent) {
16+
Player player = joinEvent.getPlayer();
17+
UUID playerUuid = player.getUniqueId();
18+
Cache.populateCache(playerUuid, player, player.hasPermission(Constants.ADMIN_SOCIAL_SPY));
19+
}
20+
}

0 commit comments

Comments
 (0)