mirror of
https://github.com/darksaid98/Carbon.git
synced 2026-12-01 22:15:08 +00:00
MySQL now works on Bukkit
This commit is contained in:
1 parent
751ca43f15
commit
b871adef8f
32 files changed
+593
-116
No files matched your search
+14
-6
@@ -157,21 +157,29 @@ public final class CarbonPlayerArgument extends CommandArgument<Commander, Carbo
|
||||
final @NonNull Queue<@NonNull String> inputQueue
|
||||
) {
|
||||
final String input = inputQueue.peek();
|
||||
|
||||
if (input == null) {
|
||||
return ArgumentParseResult.failure(new NoInputProvidedException(
|
||||
CarbonPlayerParser.class,
|
||||
commandContext
|
||||
));
|
||||
}
|
||||
final var playerResult = CarbonChatProvider.carbonChat().server().player(input).join();
|
||||
|
||||
if (playerResult.player() == null) {
|
||||
return ArgumentParseResult.failure(new CarbonPlayerParseException(input, commandContext, this.messageService));
|
||||
}
|
||||
return CarbonChatProvider.carbonChat().server().resolveUUID(input).thenApply(uuid -> {
|
||||
if (uuid == null) {
|
||||
return ArgumentParseResult.<CarbonPlayer>failure(new CarbonPlayerParseException(input, commandContext, this.messageService));
|
||||
}
|
||||
|
||||
inputQueue.remove();
|
||||
final var playerResult = CarbonChatProvider.carbonChat().server().userManager().carbonPlayer(uuid).join();
|
||||
|
||||
return ArgumentParseResult.success(playerResult.player());
|
||||
if (playerResult.player() == null) {
|
||||
return ArgumentParseResult.<CarbonPlayer>failure(new CarbonPlayerParseException(input, commandContext, this.messageService));
|
||||
}
|
||||
|
||||
inputQueue.remove();
|
||||
|
||||
return ArgumentParseResult.<CarbonPlayer>success(playerResult.player());
|
||||
}).join();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+2
-2
@@ -94,8 +94,8 @@ public class ContinueCommand extends CarbonCommand {
|
||||
return;
|
||||
}
|
||||
|
||||
final ComponentPlayerResult<@NonNull CarbonPlayer> result = this.carbonChat.server()
|
||||
.player(whisperTarget).join();
|
||||
final ComponentPlayerResult<@NonNull ? extends CarbonPlayer> result = carbonChat.server()
|
||||
.userManager().carbonPlayer(whisperTarget).join();
|
||||
final @MonotonicNonNull CarbonPlayer recipient = result.player();
|
||||
|
||||
if (sender.equals(recipient)) {
|
||||
|
||||
@@ -25,7 +25,6 @@ import cloud.commandframework.minecraft.extras.MinecraftExtrasMetaKeys;
|
||||
import cloud.commandframework.minecraft.extras.RichDescription;
|
||||
import com.google.inject.Inject;
|
||||
import java.util.Objects;
|
||||
import java.util.UUID;
|
||||
import net.draycia.carbon.api.CarbonChat;
|
||||
import net.draycia.carbon.api.users.CarbonPlayer;
|
||||
import net.draycia.carbon.common.command.CarbonCommand;
|
||||
@@ -90,7 +89,7 @@ public class IgnoreCommand extends CarbonCommand {
|
||||
if (handler.contains("player")) {
|
||||
target = handler.get("player");
|
||||
} else if (handler.flags().contains("uuid")) {
|
||||
final var result = this.carbonChat.server().player(handler.<UUID>get("uuid")).join();
|
||||
final var result = carbonChat.server().userManager().carbonPlayer(handler.get("uuid")).join();
|
||||
target = Objects.requireNonNull(result.player(), "No player found for UUID.");
|
||||
} else {
|
||||
this.messageService.ignoreTargetInvalid(sender);
|
||||
|
||||
@@ -25,7 +25,6 @@ import cloud.commandframework.minecraft.extras.MinecraftExtrasMetaKeys;
|
||||
import cloud.commandframework.minecraft.extras.RichDescription;
|
||||
import com.google.inject.Inject;
|
||||
import java.util.Objects;
|
||||
import java.util.UUID;
|
||||
import net.draycia.carbon.api.CarbonChat;
|
||||
import net.draycia.carbon.api.users.CarbonPlayer;
|
||||
import net.draycia.carbon.common.command.CarbonCommand;
|
||||
@@ -90,7 +89,7 @@ public class MuteCommand extends CarbonCommand {
|
||||
if (handler.contains("player")) {
|
||||
target = handler.get("player");
|
||||
} else if (handler.flags().contains("uuid")) {
|
||||
final var result = this.carbonChat.server().player(handler.<UUID>get("uuid")).join();
|
||||
final var result = carbonChat.server().userManager().carbonPlayer(handler.get("uuid")).join();
|
||||
target = Objects.requireNonNull(result.player(), "No player found for UUID.");
|
||||
} else {
|
||||
this.messageService.muteNoTarget(sender);
|
||||
|
||||
+1
-2
@@ -25,7 +25,6 @@ import cloud.commandframework.minecraft.extras.MinecraftExtrasMetaKeys;
|
||||
import cloud.commandframework.minecraft.extras.RichDescription;
|
||||
import com.google.inject.Inject;
|
||||
import java.util.Objects;
|
||||
import java.util.UUID;
|
||||
import net.draycia.carbon.api.CarbonChat;
|
||||
import net.draycia.carbon.api.users.CarbonPlayer;
|
||||
import net.draycia.carbon.common.command.CarbonCommand;
|
||||
@@ -90,7 +89,7 @@ public class MuteInfoCommand extends CarbonCommand {
|
||||
if (handler.contains("player")) {
|
||||
target = handler.get("player");
|
||||
} else if (handler.flags().contains("uuid")) {
|
||||
final var result = this.carbonChat.server().player(handler.<UUID>get("uuid")).join();
|
||||
final var result = carbonChat.server().userManager().carbonPlayer(handler.get("uuid")).join();
|
||||
target = Objects.requireNonNull(result.player(), "No player found for UUID.");
|
||||
} else {
|
||||
target = sender;
|
||||
|
||||
@@ -95,7 +95,7 @@ public class ReplyCommand extends CarbonCommand {
|
||||
return;
|
||||
}
|
||||
|
||||
final ComponentPlayerResult<CarbonPlayer> result = this.carbonChat.server().player(replyTarget).join();
|
||||
final ComponentPlayerResult<? extends CarbonPlayer> result = carbonChat.server().userManager().carbonPlayer(replyTarget).join();
|
||||
final @MonotonicNonNull CarbonPlayer recipient = result.player();
|
||||
|
||||
if (sender.equals(recipient)) {
|
||||
|
||||
+1
-2
@@ -25,7 +25,6 @@ import cloud.commandframework.minecraft.extras.MinecraftExtrasMetaKeys;
|
||||
import cloud.commandframework.minecraft.extras.RichDescription;
|
||||
import com.google.inject.Inject;
|
||||
import java.util.Objects;
|
||||
import java.util.UUID;
|
||||
import net.draycia.carbon.api.CarbonChat;
|
||||
import net.draycia.carbon.api.users.CarbonPlayer;
|
||||
import net.draycia.carbon.common.command.CarbonCommand;
|
||||
@@ -91,7 +90,7 @@ public class UnignoreCommand extends CarbonCommand {
|
||||
if (handler.contains("player")) {
|
||||
target = handler.get("player");
|
||||
} else if (handler.flags().contains("uuid")) {
|
||||
final var result = this.carbonChat.server().player(handler.<UUID>get("uuid")).join();
|
||||
final var result = carbonChat.server().userManager().carbonPlayer(handler.get("uuid")).join();
|
||||
target = Objects.requireNonNull(result.player(), "No player found for UUID.");
|
||||
} else {
|
||||
this.messageService.ignoreTargetInvalid(sender);
|
||||
|
||||
@@ -25,7 +25,6 @@ import cloud.commandframework.minecraft.extras.MinecraftExtrasMetaKeys;
|
||||
import cloud.commandframework.minecraft.extras.RichDescription;
|
||||
import com.google.inject.Inject;
|
||||
import java.util.Objects;
|
||||
import java.util.UUID;
|
||||
import net.draycia.carbon.api.CarbonChat;
|
||||
import net.draycia.carbon.api.users.CarbonPlayer;
|
||||
import net.draycia.carbon.common.command.CarbonCommand;
|
||||
@@ -90,7 +89,7 @@ public class UnmuteCommand extends CarbonCommand {
|
||||
if (handler.contains("player")) {
|
||||
target = handler.get("player");
|
||||
} else if (handler.flags().contains("uuid")) {
|
||||
final var result = this.carbonChat.server().player(handler.<UUID>get("uuid")).join();
|
||||
final var result = carbonChat.server().userManager().carbonPlayer(handler.get("uuid")).join();
|
||||
target = Objects.requireNonNull(result.player(), "No player found for UUID.");
|
||||
} else {
|
||||
this.messageService.unmuteNoTarget(sender);
|
||||
|
||||
@@ -24,6 +24,7 @@ import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Objects;
|
||||
import java.util.UUID;
|
||||
import net.draycia.carbon.api.CarbonChat;
|
||||
import net.draycia.carbon.api.CarbonChatProvider;
|
||||
import net.draycia.carbon.api.channels.ChatChannel;
|
||||
import net.draycia.carbon.api.users.CarbonPlayer;
|
||||
@@ -42,6 +43,8 @@ import org.jetbrains.annotations.NotNull;
|
||||
@DefaultQualifier(NonNull.class)
|
||||
public class CarbonPlayerCommon implements CarbonPlayer, ForwardingAudience.Single {
|
||||
|
||||
private final CarbonChat carbonChat = CarbonChatProvider.carbonChat();
|
||||
|
||||
protected boolean muted = false;
|
||||
protected boolean deafened = false;
|
||||
|
||||
@@ -124,6 +127,10 @@ public class CarbonPlayerCommon implements CarbonPlayer, ForwardingAudience.Sing
|
||||
@Override
|
||||
public void displayName(final @Nullable Component displayName) {
|
||||
this.displayName = displayName;
|
||||
|
||||
if (this.carbonChat.server().userManager() instanceof SaveOnChange userManager) {
|
||||
userManager.saveDisplayName(this.uuid(), displayName);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -149,6 +156,10 @@ public class CarbonPlayerCommon implements CarbonPlayer, ForwardingAudience.Sing
|
||||
@Override
|
||||
public void muted(final boolean muted) {
|
||||
this.muted = muted;
|
||||
|
||||
if (this.carbonChat.server().userManager() instanceof SaveOnChange userManager) {
|
||||
userManager.saveMuted(this.uuid(), muted);
|
||||
}
|
||||
}
|
||||
|
||||
public List<UUID> ignoredPlayers() {
|
||||
@@ -174,6 +185,14 @@ public class CarbonPlayerCommon implements CarbonPlayer, ForwardingAudience.Sing
|
||||
} else {
|
||||
this.ignoredPlayers.remove(player);
|
||||
}
|
||||
|
||||
if (this.carbonChat.server().userManager() instanceof SaveOnChange userManager) {
|
||||
if (nowIgnoring) {
|
||||
userManager.addIgnore(this.uuid, player);
|
||||
} else {
|
||||
userManager.removeIgnore(this.uuid, player);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -189,6 +208,10 @@ public class CarbonPlayerCommon implements CarbonPlayer, ForwardingAudience.Sing
|
||||
@Override
|
||||
public void deafened(final boolean deafened) {
|
||||
this.deafened = deafened;
|
||||
|
||||
if (this.carbonChat.server().userManager() instanceof SaveOnChange userManager) {
|
||||
userManager.saveDeafened(this.uuid(), deafened);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -199,6 +222,10 @@ public class CarbonPlayerCommon implements CarbonPlayer, ForwardingAudience.Sing
|
||||
@Override
|
||||
public void spying(final boolean spying) {
|
||||
this.spying = spying;
|
||||
|
||||
if (this.carbonChat.server().userManager() instanceof SaveOnChange userManager) {
|
||||
userManager.saveSpying(this.uuid(), spying);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -222,8 +249,12 @@ public class CarbonPlayerCommon implements CarbonPlayer, ForwardingAudience.Sing
|
||||
}
|
||||
|
||||
@Override
|
||||
public void whisperReplyTarget(final @Nullable UUID uuid) {
|
||||
this.whisperReplyTarget = uuid;
|
||||
public void whisperReplyTarget(final @Nullable UUID whisperReplyTarget) {
|
||||
this.whisperReplyTarget = whisperReplyTarget;
|
||||
|
||||
if (this.carbonChat.server().userManager() instanceof SaveOnChange userManager) {
|
||||
userManager.saveWhisperReplyTarget(this.uuid(), whisperReplyTarget);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -232,8 +263,12 @@ public class CarbonPlayerCommon implements CarbonPlayer, ForwardingAudience.Sing
|
||||
}
|
||||
|
||||
@Override
|
||||
public void lastWhisperTarget(final @Nullable UUID uuid) {
|
||||
this.lastWhisperTarget = uuid;
|
||||
public void lastWhisperTarget(final @Nullable UUID lastWhisperTarget) {
|
||||
this.lastWhisperTarget = lastWhisperTarget;
|
||||
|
||||
if (this.carbonChat.server().userManager() instanceof SaveOnChange userManager) {
|
||||
userManager.saveLastWhisperTarget(this.uuid(), lastWhisperTarget);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -268,6 +303,10 @@ public class CarbonPlayerCommon implements CarbonPlayer, ForwardingAudience.Sing
|
||||
@Override
|
||||
public void selectedChannel(final @Nullable ChatChannel chatChannel) {
|
||||
this.selectedChannel = chatChannel.key();
|
||||
|
||||
if (this.carbonChat.server().userManager() instanceof SaveOnChange userManager) {
|
||||
userManager.saveSelectedChannel(this.uuid(), chatChannel.key());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -0,0 +1,88 @@
|
||||
/*
|
||||
* CarbonChat
|
||||
*
|
||||
* Copyright (c) 2021 Josua Parks (Vicarious)
|
||||
* Contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package net.draycia.carbon.common.users;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import net.draycia.carbon.api.CarbonChat;
|
||||
import net.draycia.carbon.api.users.ComponentPlayerResult;
|
||||
import net.draycia.carbon.api.users.UserManager;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
import org.checkerframework.framework.qual.DefaultQualifier;
|
||||
import static net.kyori.adventure.text.Component.text;
|
||||
|
||||
@DefaultQualifier(NonNull.class)
|
||||
public class ProxiedCachingUserManager implements UserManager<CarbonPlayerCommon> {
|
||||
|
||||
private final Map<UUID, CarbonPlayerCommon> userCache = new ConcurrentHashMap<>();
|
||||
private final UserManager<CarbonPlayerCommon> proxiedUserManager;
|
||||
private final CarbonChat carbonChat;
|
||||
|
||||
public ProxiedCachingUserManager(final UserManager<CarbonPlayerCommon> proxiedUserManager, final CarbonChat carbonChat) {
|
||||
this.proxiedUserManager = proxiedUserManager;
|
||||
this.carbonChat = carbonChat;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompletableFuture<ComponentPlayerResult<CarbonPlayerCommon>> carbonPlayer(UUID uuid) {
|
||||
return CompletableFuture.supplyAsync(() -> {
|
||||
final @Nullable CarbonPlayerCommon cachedPlayer = this.userCache.get(uuid);
|
||||
|
||||
if (cachedPlayer != null) {
|
||||
return new ComponentPlayerResult<>(cachedPlayer, Component.empty());
|
||||
}
|
||||
|
||||
final ComponentPlayerResult<CarbonPlayerCommon> result = this.proxiedUserManager.carbonPlayer(uuid).join();
|
||||
|
||||
if (result.player() != null) {
|
||||
this.userCache.put(uuid, result.player());
|
||||
|
||||
return new ComponentPlayerResult<>(result.player(), Component.empty());
|
||||
}
|
||||
|
||||
final @Nullable String name = this.carbonChat.server().resolveName(uuid).join();
|
||||
|
||||
if (name != null) {
|
||||
final CarbonPlayerCommon player = new CarbonPlayerCommon(name, uuid);
|
||||
|
||||
this.userCache.put(uuid, player);
|
||||
|
||||
return new ComponentPlayerResult<>(player, Component.empty());
|
||||
}
|
||||
|
||||
return new ComponentPlayerResult<>(null, text("Name not found for uuid!"));
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompletableFuture<ComponentPlayerResult<CarbonPlayerCommon>> savePlayer(final CarbonPlayerCommon player) {
|
||||
return this.proxiedUserManager.savePlayer(player);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompletableFuture<ComponentPlayerResult<CarbonPlayerCommon>> saveAndInvalidatePlayer(final CarbonPlayerCommon player) {
|
||||
return this.proxiedUserManager.saveAndInvalidatePlayer(player);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
/*
|
||||
* CarbonChat
|
||||
*
|
||||
* Copyright (c) 2021 Josua Parks (Vicarious)
|
||||
* Contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package net.draycia.carbon.common.users;
|
||||
|
||||
import java.util.UUID;
|
||||
import net.kyori.adventure.key.Key;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
import org.checkerframework.framework.qual.DefaultQualifier;
|
||||
|
||||
@DefaultQualifier(NonNull.class)
|
||||
public interface SaveOnChange {
|
||||
|
||||
int saveDisplayName(final UUID id, final @Nullable Component component);
|
||||
|
||||
int saveMuted(final UUID id, final boolean muted);
|
||||
|
||||
int saveDeafened(final UUID id, final boolean deafened);
|
||||
|
||||
int saveSpying(final UUID id, final boolean spying);
|
||||
|
||||
int saveSelectedChannel(final UUID id, final @Nullable Key selectedChannel);
|
||||
|
||||
int saveLastWhisperTarget(final UUID id, final @Nullable UUID lastWhisperTarget);
|
||||
|
||||
int saveWhisperReplyTarget(final UUID id, final @Nullable UUID whisperReplyTarget);
|
||||
|
||||
int addIgnore(final UUID id, final UUID ignoredPlayer);
|
||||
|
||||
int removeIgnore(final UUID id, final UUID ignoredPlayer);
|
||||
|
||||
}
|
||||
@@ -229,4 +229,9 @@ public abstract class WrappedCarbonPlayer implements CarbonPlayer {
|
||||
return this.carbonPlayerCommon().speechPermitted(message);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean vanished() {
|
||||
return this.carbonPlayerCommon().vanished();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -31,7 +31,7 @@ public final class DBType {
|
||||
return this.basePath;
|
||||
}
|
||||
|
||||
public static final DBType MYSQL = new DBType("queries/sql/");
|
||||
public static final DBType MYSQL = new DBType("queries/mysql/");
|
||||
//public static final DBType POSTGRESQL = new DBType("queries/postgresql/");
|
||||
|
||||
}
|
||||
@@ -34,6 +34,13 @@ import net.draycia.carbon.api.users.ComponentPlayerResult;
|
||||
import net.draycia.carbon.api.users.UserManager;
|
||||
import net.draycia.carbon.common.config.DatabaseSettings;
|
||||
import net.draycia.carbon.common.users.CarbonPlayerCommon;
|
||||
import net.draycia.carbon.common.users.SaveOnChange;
|
||||
import net.draycia.carbon.common.users.db.jdbi.CarbonPlayerCommonRowMapper;
|
||||
import net.draycia.carbon.common.users.db.jdbi.ComponentMapper;
|
||||
import net.draycia.carbon.common.users.db.jdbi.KeyArgumentFactory;
|
||||
import net.draycia.carbon.common.users.db.jdbi.KeyMapper;
|
||||
import net.draycia.carbon.common.users.db.jdbi.UUIDArgumentFactory;
|
||||
import net.kyori.adventure.key.Key;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
@@ -42,13 +49,14 @@ import org.flywaydb.core.Flyway;
|
||||
import org.jdbi.v3.core.Jdbi;
|
||||
import org.jdbi.v3.core.statement.PreparedBatch;
|
||||
import org.jdbi.v3.core.statement.Update;
|
||||
import org.jdbi.v3.sqlobject.SqlObjectPlugin;
|
||||
|
||||
import static net.kyori.adventure.text.Component.empty;
|
||||
import static net.kyori.adventure.text.Component.text;
|
||||
|
||||
// TODO: Dispatch updates using messaging system when users are modified
|
||||
@DefaultQualifier(NonNull.class)
|
||||
public final class MariaDBUserManager implements UserManager<CarbonPlayerCommon> {
|
||||
public final class MariaDBUserManager implements UserManager<CarbonPlayerCommon>, SaveOnChange {
|
||||
|
||||
private final Jdbi jdbi;
|
||||
|
||||
@@ -74,7 +82,7 @@ public final class MariaDBUserManager implements UserManager<CarbonPlayerCommon>
|
||||
Flyway.configure(CarbonChatProvider.carbonChat().getClass().getClassLoader())
|
||||
.baselineVersion("0")
|
||||
.baselineOnMigrate(true)
|
||||
.locations("queries/migrations/sql")
|
||||
.locations("queries/migrations/mysql")
|
||||
.dataSource(dataSource)
|
||||
.validateOnMigrate(true)
|
||||
.load()
|
||||
@@ -83,8 +91,11 @@ public final class MariaDBUserManager implements UserManager<CarbonPlayerCommon>
|
||||
final Jdbi jdbi = Jdbi.create(dataSource)
|
||||
.registerArrayType(UUID.class, "uuid")
|
||||
.registerArgument(new UUIDArgumentFactory())
|
||||
.registerArgument(new KeyArgumentFactory())
|
||||
.registerColumnMapper(Component.class, new ComponentMapper())
|
||||
.registerRowMapper(new CarbonPlayerCommonRowMapper());
|
||||
.registerColumnMapper(Key.class, new KeyMapper())
|
||||
.registerRowMapper(new CarbonPlayerCommonRowMapper())
|
||||
.installPlugin(new SqlObjectPlugin());
|
||||
|
||||
return new MariaDBUserManager(jdbi);
|
||||
}
|
||||
@@ -175,4 +186,49 @@ public final class MariaDBUserManager implements UserManager<CarbonPlayerCommon>
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public int saveDisplayName(final UUID id, final @Nullable Component displayName) {
|
||||
return this.jdbi.withExtension(SQLSaveOnChange.class, changeSaver -> changeSaver.saveDisplayName(id, displayName));
|
||||
}
|
||||
|
||||
@Override
|
||||
public int saveMuted(UUID id, boolean muted) {
|
||||
return this.jdbi.withExtension(SQLSaveOnChange.class, changeSaver -> changeSaver.saveMuted(id, muted));
|
||||
}
|
||||
|
||||
@Override
|
||||
public int saveDeafened(UUID id, boolean deafened) {
|
||||
return this.jdbi.withExtension(SQLSaveOnChange.class, changeSaver -> changeSaver.saveDeafened(id, deafened));
|
||||
}
|
||||
|
||||
@Override
|
||||
public int saveSpying(UUID id, boolean spying) {
|
||||
return this.jdbi.withExtension(SQLSaveOnChange.class, changeSaver -> changeSaver.saveSpying(id, spying));
|
||||
}
|
||||
|
||||
@Override
|
||||
public int saveSelectedChannel(UUID id, @Nullable Key selectedChannel) {
|
||||
return this.jdbi.withExtension(SQLSaveOnChange.class, changeSaver -> changeSaver.saveSelectedChannel(id, selectedChannel));
|
||||
}
|
||||
|
||||
@Override
|
||||
public int saveLastWhisperTarget(UUID id, @Nullable UUID lastWhisperTarget) {
|
||||
return this.jdbi.withExtension(SQLSaveOnChange.class, changeSaver -> changeSaver.saveLastWhisperTarget(id, lastWhisperTarget));
|
||||
}
|
||||
|
||||
@Override
|
||||
public int saveWhisperReplyTarget(UUID id, @Nullable UUID whisperReplyTarget) {
|
||||
return this.jdbi.withExtension(SQLSaveOnChange.class, changeSaver -> changeSaver.saveWhisperReplyTarget(id, whisperReplyTarget));
|
||||
}
|
||||
|
||||
@Override
|
||||
public int addIgnore(UUID id, UUID ignoredPlayer) {
|
||||
return this.jdbi.withExtension(SQLSaveOnChange.class, changeSaver -> changeSaver.addIgnore(id, ignoredPlayer));
|
||||
}
|
||||
|
||||
@Override
|
||||
public int removeIgnore(UUID id, UUID ignoredPlayer) {
|
||||
return this.jdbi.withExtension(SQLSaveOnChange.class, changeSaver -> changeSaver.removeIgnore(id, ignoredPlayer));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
/*
|
||||
* CarbonChat
|
||||
*
|
||||
* Copyright (c) 2021 Josua Parks (Vicarious)
|
||||
* Contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package net.draycia.carbon.common.users.db;
|
||||
|
||||
import java.util.UUID;
|
||||
import net.draycia.carbon.common.users.SaveOnChange;
|
||||
import net.kyori.adventure.key.Key;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
import org.checkerframework.framework.qual.DefaultQualifier;
|
||||
import org.jdbi.v3.sqlobject.statement.SqlUpdate;
|
||||
|
||||
@DefaultQualifier(NonNull.class)
|
||||
public interface SQLSaveOnChange extends SaveOnChange {
|
||||
|
||||
@SqlUpdate("UPDATE carbon_users SET (displayname = :displayname) WHERE id = UNHEX(REPLACE(:id, '-', ''))")
|
||||
int saveDisplayName(final UUID id, final @Nullable Component component);
|
||||
|
||||
@SqlUpdate("UPDATE carbon_users SET (muted = :muted) WHERE id = UNHEX(REPLACE(:id, '-', ''))")
|
||||
int saveMuted(final UUID id, final boolean muted);
|
||||
|
||||
@SqlUpdate("UPDATE carbon_users SET (deafened = :deafened) WHERE id = UNHEX(REPLACE(:id, '-', ''))")
|
||||
int saveDeafened(final UUID id, final boolean deafened);
|
||||
|
||||
@SqlUpdate("UPDATE carbon_users SET (spying = :spying) WHERE id = UNHEX(REPLACE(:id, '-', ''))")
|
||||
int saveSpying(final UUID id, final boolean spying);
|
||||
|
||||
@SqlUpdate("UPDATE carbon_users SET selectedchannel = :selectedChannel WHERE id = UNHEX(REPLACE(:id, '-', ''))")
|
||||
int saveSelectedChannel(final UUID id, final @Nullable Key selectedChannel);
|
||||
|
||||
@SqlUpdate("UPDATE carbon_users SET (lastwhispertarget = :lastWhisperTarget) WHERE id = UNHEX(REPLACE(:id, '-', ''))")
|
||||
int saveLastWhisperTarget(final UUID id, final @Nullable UUID lastWhisperTarget);
|
||||
|
||||
@SqlUpdate("UPDATE carbon_users SET (whisperreplytarget = :whisperReplyTarget) WHERE id = UNHEX(REPLACE(:id, '-', ''))")
|
||||
int saveWhisperReplyTarget(final UUID id, final @Nullable UUID whisperReplyTarget);
|
||||
|
||||
@SqlUpdate("INSERT INTO carbon_ignores VALUES (id = UNHEX(REPLACE(:id, '-', '')), ignoredplayer = :ignoredPlayer)")
|
||||
int addIgnore(final UUID id, final UUID ignoredPlayer);
|
||||
|
||||
@SqlUpdate("DELETE FROM carbon_ignores WHERE (id = UNHEX(REPLACE(:id, '-', '')), ignoredplayer = UNHEX(REPLACE(:ignoredPlayer, '-', '')))")
|
||||
int removeIgnore(final UUID id, final UUID ignoredPlayer);
|
||||
|
||||
}
|
||||
+6
-4
@@ -17,7 +17,7 @@
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package net.draycia.carbon.common.users.db;
|
||||
package net.draycia.carbon.common.users.db.jdbi;
|
||||
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
@@ -26,6 +26,7 @@ import net.draycia.carbon.common.users.CarbonPlayerCommon;
|
||||
import net.kyori.adventure.key.Key;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
import org.intellij.lang.annotations.Subst;
|
||||
import org.jdbi.v3.core.mapper.RowMapper;
|
||||
import org.jdbi.v3.core.statement.StatementContext;
|
||||
|
||||
@@ -35,17 +36,18 @@ public class CarbonPlayerCommonRowMapper implements RowMapper<CarbonPlayerCommon
|
||||
public CarbonPlayerCommon map(final ResultSet rs, final StatementContext ctx) throws SQLException {
|
||||
final String id = rs.getString("id");
|
||||
final @Nullable String lastWhisperTarget = rs.getString("lastwhispertarget");
|
||||
final @Nullable String whisperreplytarget = rs.getString("whisperreplytarget");
|
||||
final @Nullable String whisperReplyTarget = rs.getString("whisperreplytarget");
|
||||
final @Nullable @Subst("carbon:global") String selectedChannel = rs.getString("selectedchannel");
|
||||
|
||||
return new CarbonPlayerCommon(
|
||||
rs.getBoolean("muted"),
|
||||
rs.getBoolean("deafened"),
|
||||
rs.getObject("selectedchannel", Key.class),
|
||||
selectedChannel == null ? null : Key.key(selectedChannel),
|
||||
rs.getString("username"),
|
||||
UUID.fromString(id),
|
||||
rs.getObject("displayname", Component.class),
|
||||
lastWhisperTarget == null ? null : UUID.fromString(lastWhisperTarget),
|
||||
whisperreplytarget == null ? null : UUID.fromString(whisperreplytarget),
|
||||
whisperReplyTarget == null ? null : UUID.fromString(whisperReplyTarget),
|
||||
rs.getBoolean("spying")
|
||||
);
|
||||
}
|
||||
+1
-1
@@ -17,7 +17,7 @@
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package net.draycia.carbon.common.users.db;
|
||||
package net.draycia.carbon.common.users.db.jdbi;
|
||||
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
@@ -0,0 +1,40 @@
|
||||
/*
|
||||
* CarbonChat
|
||||
*
|
||||
* Copyright (c) 2021 Josua Parks (Vicarious)
|
||||
* Contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package net.draycia.carbon.common.users.db.jdbi;
|
||||
|
||||
import java.sql.Types;
|
||||
import java.util.UUID;
|
||||
import net.kyori.adventure.key.Key;
|
||||
import org.jdbi.v3.core.argument.AbstractArgumentFactory;
|
||||
import org.jdbi.v3.core.argument.Argument;
|
||||
import org.jdbi.v3.core.config.ConfigRegistry;
|
||||
|
||||
public final class KeyArgumentFactory extends AbstractArgumentFactory<Key> {
|
||||
|
||||
public KeyArgumentFactory() {
|
||||
super(Types.VARCHAR);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Argument build(final Key value, final ConfigRegistry config) {
|
||||
return (position, statement, ctx) -> statement.setString(position, value.toString());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
/*
|
||||
* CarbonChat
|
||||
*
|
||||
* Copyright (c) 2021 Josua Parks (Vicarious)
|
||||
* Contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package net.draycia.carbon.common.users.db.jdbi;
|
||||
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import net.kyori.adventure.key.Key;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer;
|
||||
import org.jdbi.v3.core.mapper.ColumnMapper;
|
||||
import org.jdbi.v3.core.statement.StatementContext;
|
||||
|
||||
public class KeyMapper implements ColumnMapper<Key> {
|
||||
|
||||
@Override
|
||||
public Key map(final ResultSet r, final int columnNumber, final StatementContext ctx) throws SQLException {
|
||||
return Key.key(r.getString(columnNumber));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Key map(final ResultSet r, final String columnLabel, final StatementContext ctx) throws SQLException {
|
||||
return Key.key(r.getString(columnLabel));
|
||||
}
|
||||
|
||||
}
|
||||
+1
-1
@@ -17,7 +17,7 @@
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package net.draycia.carbon.common.users.db;
|
||||
package net.draycia.carbon.common.users.db.jdbi;
|
||||
|
||||
import java.sql.Types;
|
||||
import java.util.UUID;
|
||||
Reference in new issue
Block a user