mirror of
https://github.com/darksaid98/Carbon.git
synced 2026-12-04 14:38:49 +00:00
Remove SaveOnChange & fix checkstyle errors
This commit is contained in:
1 parent
8d672c829b
commit
0251440600
15 files changed
+26
-510
No files matched your search
@@ -92,6 +92,12 @@ public interface CarbonChat {
|
|||||||
*/
|
*/
|
||||||
CarbonServer server();
|
CarbonServer server();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The user manager.
|
||||||
|
*
|
||||||
|
* @return the user manager
|
||||||
|
* @since 2.1.0
|
||||||
|
*/
|
||||||
UserManager<?> userManager();
|
UserManager<?> userManager();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -53,9 +53,9 @@ public interface CarbonServer extends Audience {
|
|||||||
/**
|
/**
|
||||||
* Manager used to load/obtain and save {@link CarbonPlayer CarbonPlayers}.
|
* Manager used to load/obtain and save {@link CarbonPlayer CarbonPlayers}.
|
||||||
*
|
*
|
||||||
|
* @deprecated Use {@link CarbonChat#userManager} (internal code: inject the UserManager)
|
||||||
* @return the user manager
|
* @return the user manager
|
||||||
* @since 2.1.0
|
* @since 2.1.0
|
||||||
* @deprecated Use {@link CarbonChat#userManager} (internal code: inject the UserManager)
|
|
||||||
*/
|
*/
|
||||||
@Deprecated(forRemoval = true)
|
@Deprecated(forRemoval = true)
|
||||||
UserManager<? extends CarbonPlayer> userManager();
|
UserManager<? extends CarbonPlayer> userManager();
|
||||||
|
|||||||
@@ -48,6 +48,13 @@ public interface UserManager<C extends CarbonPlayer> {
|
|||||||
.exceptionally(thr -> new ComponentPlayerResult<>(null, ComponentMessageThrowable.getOrConvertMessage(thr)));
|
.exceptionally(thr -> new ComponentPlayerResult<>(null, ComponentMessageThrowable.getOrConvertMessage(thr)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Loads and returns the CarbonPlayer with the corresponding uuid.
|
||||||
|
*
|
||||||
|
* @param uuid the player's id
|
||||||
|
* @return the player
|
||||||
|
* @since 2.1.0
|
||||||
|
*/
|
||||||
CompletableFuture<C> user(final UUID uuid);
|
CompletableFuture<C> user(final UUID uuid);
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -130,10 +130,6 @@ public class CarbonPlayerCommon implements CarbonPlayer, ForwardingAudience.Sing
|
|||||||
@Override
|
@Override
|
||||||
public void displayName(final @Nullable Component displayName) {
|
public void displayName(final @Nullable Component displayName) {
|
||||||
this.displayName = displayName;
|
this.displayName = displayName;
|
||||||
|
|
||||||
if (this.carbonChat.userManager() instanceof SaveOnChange userManager) {
|
|
||||||
userManager.saveDisplayName(this.uuid(), displayName);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -159,10 +155,6 @@ public class CarbonPlayerCommon implements CarbonPlayer, ForwardingAudience.Sing
|
|||||||
@Override
|
@Override
|
||||||
public void muted(final boolean muted) {
|
public void muted(final boolean muted) {
|
||||||
this.muted = muted;
|
this.muted = muted;
|
||||||
|
|
||||||
if (this.carbonChat.userManager() instanceof SaveOnChange userManager) {
|
|
||||||
userManager.saveMuted(this.uuid(), muted);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<UUID> ignoredPlayers() {
|
public List<UUID> ignoredPlayers() {
|
||||||
@@ -188,14 +180,6 @@ public class CarbonPlayerCommon implements CarbonPlayer, ForwardingAudience.Sing
|
|||||||
} else {
|
} else {
|
||||||
this.ignoredPlayers.remove(player);
|
this.ignoredPlayers.remove(player);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.carbonChat.userManager() instanceof SaveOnChange userManager) {
|
|
||||||
if (nowIgnoring) {
|
|
||||||
userManager.addIgnore(this.uuid, player);
|
|
||||||
} else {
|
|
||||||
userManager.removeIgnore(this.uuid, player);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -211,10 +195,6 @@ public class CarbonPlayerCommon implements CarbonPlayer, ForwardingAudience.Sing
|
|||||||
@Override
|
@Override
|
||||||
public void deafened(final boolean deafened) {
|
public void deafened(final boolean deafened) {
|
||||||
this.deafened = deafened;
|
this.deafened = deafened;
|
||||||
|
|
||||||
if (this.carbonChat.userManager() instanceof SaveOnChange userManager) {
|
|
||||||
userManager.saveDeafened(this.uuid(), deafened);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -225,10 +205,6 @@ public class CarbonPlayerCommon implements CarbonPlayer, ForwardingAudience.Sing
|
|||||||
@Override
|
@Override
|
||||||
public void spying(final boolean spying) {
|
public void spying(final boolean spying) {
|
||||||
this.spying = spying;
|
this.spying = spying;
|
||||||
|
|
||||||
if (this.carbonChat.userManager() instanceof SaveOnChange userManager) {
|
|
||||||
userManager.saveSpying(this.uuid(), spying);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -254,10 +230,6 @@ public class CarbonPlayerCommon implements CarbonPlayer, ForwardingAudience.Sing
|
|||||||
@Override
|
@Override
|
||||||
public void whisperReplyTarget(final @Nullable UUID whisperReplyTarget) {
|
public void whisperReplyTarget(final @Nullable UUID whisperReplyTarget) {
|
||||||
this.whisperReplyTarget = whisperReplyTarget;
|
this.whisperReplyTarget = whisperReplyTarget;
|
||||||
|
|
||||||
if (this.carbonChat.userManager() instanceof SaveOnChange userManager) {
|
|
||||||
userManager.saveWhisperReplyTarget(this.uuid(), whisperReplyTarget);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -268,10 +240,6 @@ public class CarbonPlayerCommon implements CarbonPlayer, ForwardingAudience.Sing
|
|||||||
@Override
|
@Override
|
||||||
public void lastWhisperTarget(final @Nullable UUID lastWhisperTarget) {
|
public void lastWhisperTarget(final @Nullable UUID lastWhisperTarget) {
|
||||||
this.lastWhisperTarget = lastWhisperTarget;
|
this.lastWhisperTarget = lastWhisperTarget;
|
||||||
|
|
||||||
if (this.carbonChat.userManager() instanceof SaveOnChange userManager) {
|
|
||||||
userManager.saveLastWhisperTarget(this.uuid(), lastWhisperTarget);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -292,17 +260,11 @@ public class CarbonPlayerCommon implements CarbonPlayer, ForwardingAudience.Sing
|
|||||||
@Override
|
@Override
|
||||||
public void joinChannel(final ChatChannel channel) {
|
public void joinChannel(final ChatChannel channel) {
|
||||||
this.leftChannels.remove(channel.key());
|
this.leftChannels.remove(channel.key());
|
||||||
if (this.carbonChat.userManager() instanceof SaveOnChange userManager) {
|
|
||||||
userManager.removeLeftChannel(this.uuid(), channel.key());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void leaveChannel(final ChatChannel channel) {
|
public void leaveChannel(final ChatChannel channel) {
|
||||||
this.leftChannels.add(channel.key());
|
this.leftChannels.add(channel.key());
|
||||||
if (this.carbonChat.userManager() instanceof SaveOnChange userManager) {
|
|
||||||
userManager.addLeftChannel(this.uuid(), channel.key());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -335,10 +297,6 @@ public class CarbonPlayerCommon implements CarbonPlayer, ForwardingAudience.Sing
|
|||||||
} else {
|
} else {
|
||||||
this.selectedChannel = chatChannel.key();
|
this.selectedChannel = chatChannel.key();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.carbonChat.userManager() instanceof SaveOnChange userManager) {
|
|
||||||
userManager.saveSelectedChannel(this.uuid(), this.selectedChannel);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -1,98 +0,0 @@
|
|||||||
/*
|
|
||||||
* CarbonChat
|
|
||||||
*
|
|
||||||
* Copyright (c) 2023 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.draycia.carbon.api.users.UserManager;
|
|
||||||
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 final class ImposterSaveOnChange implements SaveOnChange {
|
|
||||||
|
|
||||||
private static final SaveOnChange IMPOSTER = new ImposterSaveOnChange();
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int saveDisplayName(UUID id, @Nullable Component displayName) {
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int saveMuted(UUID id, boolean muted) {
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int saveDeafened(UUID id, boolean deafened) {
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int saveSpying(UUID id, boolean spying) {
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int saveSelectedChannel(UUID id, @Nullable Key selectedChannel) {
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int saveLastWhisperTarget(UUID id, @Nullable UUID lastWhisperTarget) {
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int saveWhisperReplyTarget(UUID id, @Nullable UUID whisperReplyTarget) {
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int addIgnore(UUID id, UUID ignoredPlayer) {
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int removeIgnore(UUID id, UUID ignoredPlayer) {
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int addLeftChannel(UUID id, Key channel) {
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int removeLeftChannel(UUID id, Key channel) {
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static SaveOnChange impersonateIfNeeded(final UserManager<?> userManager) {
|
|
||||||
if (userManager instanceof SaveOnChange saveOnChange) {
|
|
||||||
return saveOnChange;
|
|
||||||
} else {
|
|
||||||
return IMPOSTER;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -21,84 +21,24 @@ package net.draycia.carbon.common.users;
|
|||||||
|
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import java.util.concurrent.CompletableFuture;
|
import java.util.concurrent.CompletableFuture;
|
||||||
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.NonNull;
|
||||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
|
||||||
import org.checkerframework.framework.qual.DefaultQualifier;
|
import org.checkerframework.framework.qual.DefaultQualifier;
|
||||||
|
|
||||||
@DefaultQualifier(NonNull.class)
|
@DefaultQualifier(NonNull.class)
|
||||||
public abstract class PlatformUserManager<C extends WrappedCarbonPlayer> implements UserManagerInternal<C>, SaveOnChange {
|
public abstract class PlatformUserManager<C extends WrappedCarbonPlayer> implements UserManagerInternal<C> {
|
||||||
|
|
||||||
private final UserManagerInternal<CarbonPlayerCommon> wrapped;
|
private final UserManagerInternal<CarbonPlayerCommon> wrapped;
|
||||||
private final SaveOnChange saveOnChange;
|
|
||||||
|
|
||||||
public PlatformUserManager(final UserManagerInternal<CarbonPlayerCommon> wrapped) {
|
public PlatformUserManager(final UserManagerInternal<CarbonPlayerCommon> wrapped) {
|
||||||
this.wrapped = wrapped;
|
this.wrapped = wrapped;
|
||||||
this.saveOnChange = ImposterSaveOnChange.impersonateIfNeeded(wrapped);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CompletableFuture<C> user(UUID uuid) {
|
public CompletableFuture<C> user(final UUID uuid) {
|
||||||
return this.wrapped.user(uuid).thenApply(this::wrap);
|
return this.wrapped.user(uuid).thenApply(this::wrap);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected abstract C wrap(CarbonPlayerCommon common);
|
protected abstract C wrap(final CarbonPlayerCommon common);
|
||||||
|
|
||||||
@Override
|
|
||||||
public int saveDisplayName(final UUID id, final @Nullable Component component) {
|
|
||||||
return this.saveOnChange.saveDisplayName(id, component);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int saveMuted(final UUID id, final boolean muted) {
|
|
||||||
return this.saveOnChange.saveMuted(id, muted);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int saveDeafened(final UUID id, final boolean deafened) {
|
|
||||||
return this.saveOnChange.saveDeafened(id, deafened);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int saveSpying(final UUID id, final boolean spying) {
|
|
||||||
return this.saveOnChange.saveSpying(id, spying);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int saveSelectedChannel(final UUID id, final @Nullable Key selectedChannel) {
|
|
||||||
return this.saveOnChange.saveSelectedChannel(id, selectedChannel);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int saveLastWhisperTarget(final UUID id, final @Nullable UUID lastWhisperTarget) {
|
|
||||||
return this.saveOnChange.saveLastWhisperTarget(id, lastWhisperTarget);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int saveWhisperReplyTarget(final UUID id, final @Nullable UUID whisperReplyTarget) {
|
|
||||||
return this.saveOnChange.saveWhisperReplyTarget(id, whisperReplyTarget);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int addIgnore(final UUID id, final UUID ignoredPlayer) {
|
|
||||||
return this.saveOnChange.addIgnore(id, ignoredPlayer);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int removeIgnore(final UUID id, final UUID ignoredPlayer) {
|
|
||||||
return this.saveOnChange.removeIgnore(id, ignoredPlayer);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int addLeftChannel(final UUID id, final Key channel) {
|
|
||||||
return this.saveOnChange.addLeftChannel(id, channel);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int removeLeftChannel(final UUID id, final Key channel) {
|
|
||||||
return this.saveOnChange.removeLeftChannel(id, channel);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void shutdown() {
|
public void shutdown() {
|
||||||
|
|||||||
@@ -1,54 +0,0 @@
|
|||||||
/*
|
|
||||||
* CarbonChat
|
|
||||||
*
|
|
||||||
* Copyright (c) 2023 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 displayName);
|
|
||||||
|
|
||||||
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);
|
|
||||||
|
|
||||||
int addLeftChannel(final UUID id, final Key channel);
|
|
||||||
|
|
||||||
int removeLeftChannel(final UUID id, final Key channel);
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -109,4 +109,5 @@ public abstract class DatabaseUserManager implements UserManagerInternal<CarbonP
|
|||||||
}
|
}
|
||||||
ConcurrentUtil.shutdownExecutor(this.executor, TimeUnit.MILLISECONDS, 500);
|
ConcurrentUtil.shutdownExecutor(this.executor, TimeUnit.MILLISECONDS, 500);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -1,66 +0,0 @@
|
|||||||
/*
|
|
||||||
* CarbonChat
|
|
||||||
*
|
|
||||||
* Copyright (c) 2023 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.mysql;
|
|
||||||
|
|
||||||
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 MySQLSaveOnChange extends SaveOnChange {
|
|
||||||
|
|
||||||
@SqlUpdate("UPDATE carbon_users SET displayname = :displayName WHERE id = UNHEX(REPLACE(:id, '-', ''))")
|
|
||||||
int saveDisplayName(final UUID id, final @Nullable Component displayName);
|
|
||||||
|
|
||||||
@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 = UNHEX(REPLACE(:lastWhisperTarget, '-', '')) WHERE id = UNHEX(REPLACE(:id, '-', ''))")
|
|
||||||
int saveLastWhisperTarget(final UUID id, final @Nullable UUID lastWhisperTarget);
|
|
||||||
|
|
||||||
@SqlUpdate("UPDATE carbon_users SET whisperreplytarget = UNHEX(REPLACE(:whisperReplyTarget, '-', '')) WHERE id = UNHEX(REPLACE(:id, '-', ''))")
|
|
||||||
int saveWhisperReplyTarget(final UUID id, final @Nullable UUID whisperReplyTarget);
|
|
||||||
|
|
||||||
@SqlUpdate("INSERT IGNORE INTO carbon_ignores (id, ignoredplayer) VALUES (UNHEX(REPLACE(:id, '-', '')), UNHEX(REPLACE(:ignoredPlayer, '-', '')))")
|
|
||||||
int addIgnore(final UUID id, final UUID ignoredPlayer);
|
|
||||||
|
|
||||||
@SqlUpdate("DELETE FROM carbon_ignores WHERE id = UNHEX(REPLACE(:id, '-', '')) AND ignoredplayer = UNHEX(REPLACE(:ignoredPlayer, '-', ''))")
|
|
||||||
int removeIgnore(final UUID id, final UUID ignoredPlayer);
|
|
||||||
|
|
||||||
@SqlUpdate("INSERT IGNORE INTO carbon_leftchannels (id, channel) VALUES (UNHEX(REPLACE(:id, '-', '')), :channel)")
|
|
||||||
int addLeftChannel(final UUID id, final Key channel);
|
|
||||||
|
|
||||||
@SqlUpdate("DELETE FROM carbon_leftchannels WHERE id = UNHEX(REPLACE(:id, '-', '')) AND channel = :channel")
|
|
||||||
int removeLeftChannel(final UUID id, final Key channel);
|
|
||||||
}
|
|
||||||
+2
-59
@@ -34,7 +34,6 @@ import net.draycia.carbon.api.channels.ChatChannel;
|
|||||||
import net.draycia.carbon.common.config.DatabaseSettings;
|
import net.draycia.carbon.common.config.DatabaseSettings;
|
||||||
import net.draycia.carbon.common.users.CarbonPlayerCommon;
|
import net.draycia.carbon.common.users.CarbonPlayerCommon;
|
||||||
import net.draycia.carbon.common.users.ProfileResolver;
|
import net.draycia.carbon.common.users.ProfileResolver;
|
||||||
import net.draycia.carbon.common.users.SaveOnChange;
|
|
||||||
import net.draycia.carbon.common.users.db.ComponentArgumentFactory;
|
import net.draycia.carbon.common.users.db.ComponentArgumentFactory;
|
||||||
import net.draycia.carbon.common.users.db.DBType;
|
import net.draycia.carbon.common.users.db.DBType;
|
||||||
import net.draycia.carbon.common.users.db.DatabaseUserManager;
|
import net.draycia.carbon.common.users.db.DatabaseUserManager;
|
||||||
@@ -42,7 +41,6 @@ import net.draycia.carbon.common.users.db.KeyArgumentFactory;
|
|||||||
import net.draycia.carbon.common.users.db.QueriesLocator;
|
import net.draycia.carbon.common.users.db.QueriesLocator;
|
||||||
import net.draycia.carbon.common.util.ConcurrentUtil;
|
import net.draycia.carbon.common.util.ConcurrentUtil;
|
||||||
import net.kyori.adventure.key.Key;
|
import net.kyori.adventure.key.Key;
|
||||||
import net.kyori.adventure.text.Component;
|
|
||||||
import org.apache.logging.log4j.Logger;
|
import org.apache.logging.log4j.Logger;
|
||||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||||
@@ -54,7 +52,7 @@ import org.jdbi.v3.sqlobject.SqlObjectPlugin;
|
|||||||
|
|
||||||
// TODO: Dispatch updates using messaging system when users are modified
|
// TODO: Dispatch updates using messaging system when users are modified
|
||||||
@DefaultQualifier(NonNull.class)
|
@DefaultQualifier(NonNull.class)
|
||||||
public final class MySQLUserManager extends DatabaseUserManager implements SaveOnChange {
|
public final class MySQLUserManager extends DatabaseUserManager {
|
||||||
|
|
||||||
private final ProfileResolver profileResolver;
|
private final ProfileResolver profileResolver;
|
||||||
private final Map<UUID, CompletableFuture<CarbonPlayerCommon>> cache = new HashMap<>();
|
private final Map<UUID, CompletableFuture<CarbonPlayerCommon>> cache = new HashMap<>();
|
||||||
@@ -179,62 +177,7 @@ public final class MySQLUserManager extends DatabaseUserManager implements SaveO
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int saveDisplayName(final UUID id, final @Nullable Component displayName) {
|
public CompletableFuture<Void> loggedOut(final UUID uuid) {
|
||||||
return this.jdbi.withExtension(MySQLSaveOnChange.class, changeSaver -> changeSaver.saveDisplayName(id, displayName));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int saveMuted(final UUID id, final boolean muted) {
|
|
||||||
return this.jdbi.withExtension(MySQLSaveOnChange.class, changeSaver -> changeSaver.saveMuted(id, muted));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int saveDeafened(final UUID id, final boolean deafened) {
|
|
||||||
return this.jdbi.withExtension(MySQLSaveOnChange.class, changeSaver -> changeSaver.saveDeafened(id, deafened));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int saveSpying(final UUID id, final boolean spying) {
|
|
||||||
return this.jdbi.withExtension(MySQLSaveOnChange.class, changeSaver -> changeSaver.saveSpying(id, spying));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int saveSelectedChannel(final UUID id, final @Nullable Key selectedChannel) {
|
|
||||||
return this.jdbi.withExtension(MySQLSaveOnChange.class, changeSaver -> changeSaver.saveSelectedChannel(id, selectedChannel));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int saveLastWhisperTarget(final UUID id, final @Nullable UUID lastWhisperTarget) {
|
|
||||||
return this.jdbi.withExtension(MySQLSaveOnChange.class, changeSaver -> changeSaver.saveLastWhisperTarget(id, lastWhisperTarget));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int saveWhisperReplyTarget(final UUID id, final @Nullable UUID whisperReplyTarget) {
|
|
||||||
return this.jdbi.withExtension(MySQLSaveOnChange.class, changeSaver -> changeSaver.saveWhisperReplyTarget(id, whisperReplyTarget));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int addIgnore(final UUID id, final UUID ignoredPlayer) {
|
|
||||||
return this.jdbi.withExtension(MySQLSaveOnChange.class, changeSaver -> changeSaver.addIgnore(id, ignoredPlayer));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int removeIgnore(final UUID id, final UUID ignoredPlayer) {
|
|
||||||
return this.jdbi.withExtension(MySQLSaveOnChange.class, changeSaver -> changeSaver.removeIgnore(id, ignoredPlayer));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int addLeftChannel(final UUID id, final Key channel) {
|
|
||||||
return this.jdbi.withExtension(MySQLSaveOnChange.class, changeSaver -> changeSaver.addLeftChannel(id, channel));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int removeLeftChannel(final UUID id, final Key channel) {
|
|
||||||
return this.jdbi.withExtension(MySQLSaveOnChange.class, changeSaver -> changeSaver.removeLeftChannel(id, channel));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public CompletableFuture<Void> loggedOut(UUID uuid) {
|
|
||||||
final CompletableFuture<@Nullable CarbonPlayerCommon> remove = this.cache.remove(uuid);
|
final CompletableFuture<@Nullable CarbonPlayerCommon> remove = this.cache.remove(uuid);
|
||||||
final @Nullable CarbonPlayerCommon join = remove.join();
|
final @Nullable CarbonPlayerCommon join = remove.join();
|
||||||
if (remove.isDone() && join != null) { // don't need to save if it never finished loading
|
if (remove.isDone() && join != null) { // don't need to save if it never finished loading
|
||||||
|
|||||||
-66
@@ -1,66 +0,0 @@
|
|||||||
/*
|
|
||||||
* CarbonChat
|
|
||||||
*
|
|
||||||
* Copyright (c) 2023 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.postgresql;
|
|
||||||
|
|
||||||
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 PostgreSQLSaveOnChange extends SaveOnChange {
|
|
||||||
|
|
||||||
@SqlUpdate("UPDATE carbon_users SET displayname = :displayName WHERE id = :id")
|
|
||||||
int saveDisplayName(final UUID id, final @Nullable Component displayName);
|
|
||||||
|
|
||||||
@SqlUpdate("UPDATE carbon_users SET muted = :muted WHERE id = :id")
|
|
||||||
int saveMuted(final UUID id, final boolean muted);
|
|
||||||
|
|
||||||
@SqlUpdate("UPDATE carbon_users SET deafened = :deafened WHERE id = :id")
|
|
||||||
int saveDeafened(final UUID id, final boolean deafened);
|
|
||||||
|
|
||||||
@SqlUpdate("UPDATE carbon_users SET spying = :spying WHERE id = :id")
|
|
||||||
int saveSpying(final UUID id, final boolean spying);
|
|
||||||
|
|
||||||
@SqlUpdate("UPDATE carbon_users SET selectedchannel = :selectedChannel WHERE id = :id")
|
|
||||||
int saveSelectedChannel(final UUID id, final @Nullable Key selectedChannel);
|
|
||||||
|
|
||||||
@SqlUpdate("UPDATE carbon_users SET lastwhispertarget = :lastWhisperTarget WHERE id = :id")
|
|
||||||
int saveLastWhisperTarget(final UUID id, final @Nullable UUID lastWhisperTarget);
|
|
||||||
|
|
||||||
@SqlUpdate("UPDATE carbon_users SET whisperreplytarget = :whisperReplyTarget WHERE id = :id")
|
|
||||||
int saveWhisperReplyTarget(final UUID id, final @Nullable UUID whisperReplyTarget);
|
|
||||||
|
|
||||||
@SqlUpdate("INSERT INTO carbon_ignores VALUES id = :id, ignoredplayer = :ignoredPlayer")
|
|
||||||
int addIgnore(final UUID id, final UUID ignoredPlayer);
|
|
||||||
|
|
||||||
@SqlUpdate("DELETE FROM carbon_ignores WHERE id = :id, ignoredplayer = :ignoredPlayer")
|
|
||||||
int removeIgnore(final UUID id, final UUID ignoredPlayer);
|
|
||||||
|
|
||||||
@SqlUpdate("INSERT INTO carbon_leftchannels VALUES id = :id, channel = :channel")
|
|
||||||
int addLeftChannel(final UUID id, final Key channel);
|
|
||||||
|
|
||||||
@SqlUpdate("DELETE FROM carbon_leftchannels WHERE id = :id, channel = :channel")
|
|
||||||
int removeLeftChannel(final UUID id, final Key channel);
|
|
||||||
}
|
|
||||||
+3
-59
@@ -33,7 +33,6 @@ import net.draycia.carbon.api.channels.ChatChannel;
|
|||||||
import net.draycia.carbon.common.config.DatabaseSettings;
|
import net.draycia.carbon.common.config.DatabaseSettings;
|
||||||
import net.draycia.carbon.common.users.CarbonPlayerCommon;
|
import net.draycia.carbon.common.users.CarbonPlayerCommon;
|
||||||
import net.draycia.carbon.common.users.ProfileResolver;
|
import net.draycia.carbon.common.users.ProfileResolver;
|
||||||
import net.draycia.carbon.common.users.SaveOnChange;
|
|
||||||
import net.draycia.carbon.common.users.db.ComponentArgumentFactory;
|
import net.draycia.carbon.common.users.db.ComponentArgumentFactory;
|
||||||
import net.draycia.carbon.common.users.db.DBType;
|
import net.draycia.carbon.common.users.db.DBType;
|
||||||
import net.draycia.carbon.common.users.db.DatabaseUserManager;
|
import net.draycia.carbon.common.users.db.DatabaseUserManager;
|
||||||
@@ -41,7 +40,6 @@ import net.draycia.carbon.common.users.db.KeyArgumentFactory;
|
|||||||
import net.draycia.carbon.common.users.db.QueriesLocator;
|
import net.draycia.carbon.common.users.db.QueriesLocator;
|
||||||
import net.draycia.carbon.common.util.ConcurrentUtil;
|
import net.draycia.carbon.common.util.ConcurrentUtil;
|
||||||
import net.kyori.adventure.key.Key;
|
import net.kyori.adventure.key.Key;
|
||||||
import net.kyori.adventure.text.Component;
|
|
||||||
import org.apache.logging.log4j.Logger;
|
import org.apache.logging.log4j.Logger;
|
||||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||||
@@ -55,7 +53,7 @@ import org.jdbi.v3.sqlobject.SqlObjectPlugin;
|
|||||||
|
|
||||||
// TODO: Dispatch updates using messaging system when users are modified
|
// TODO: Dispatch updates using messaging system when users are modified
|
||||||
@DefaultQualifier(NonNull.class)
|
@DefaultQualifier(NonNull.class)
|
||||||
public final class PostgreSQLUserManager extends DatabaseUserManager implements SaveOnChange {
|
public final class PostgreSQLUserManager extends DatabaseUserManager {
|
||||||
|
|
||||||
private final ProfileResolver profileResolver;
|
private final ProfileResolver profileResolver;
|
||||||
private final Map<UUID, CompletableFuture<CarbonPlayerCommon>> cache = new HashMap<>();
|
private final Map<UUID, CompletableFuture<CarbonPlayerCommon>> cache = new HashMap<>();
|
||||||
@@ -184,62 +182,7 @@ public final class PostgreSQLUserManager extends DatabaseUserManager implements
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int saveDisplayName(final UUID id, final @Nullable Component displayName) {
|
public CompletableFuture<Void> loggedOut(final UUID uuid) {
|
||||||
return this.jdbi.withExtension(PostgreSQLSaveOnChange.class, changeSaver -> changeSaver.saveDisplayName(id, displayName));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int saveMuted(final UUID id, final boolean muted) {
|
|
||||||
return this.jdbi.withExtension(PostgreSQLSaveOnChange.class, changeSaver -> changeSaver.saveMuted(id, muted));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int saveDeafened(final UUID id, final boolean deafened) {
|
|
||||||
return this.jdbi.withExtension(PostgreSQLSaveOnChange.class, changeSaver -> changeSaver.saveDeafened(id, deafened));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int saveSpying(final UUID id, final boolean spying) {
|
|
||||||
return this.jdbi.withExtension(PostgreSQLSaveOnChange.class, changeSaver -> changeSaver.saveSpying(id, spying));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int saveSelectedChannel(final UUID id, final @Nullable Key selectedChannel) {
|
|
||||||
return this.jdbi.withExtension(PostgreSQLSaveOnChange.class, changeSaver -> changeSaver.saveSelectedChannel(id, selectedChannel));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int saveLastWhisperTarget(final UUID id, final @Nullable UUID lastWhisperTarget) {
|
|
||||||
return this.jdbi.withExtension(PostgreSQLSaveOnChange.class, changeSaver -> changeSaver.saveLastWhisperTarget(id, lastWhisperTarget));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int saveWhisperReplyTarget(final UUID id, final @Nullable UUID whisperReplyTarget) {
|
|
||||||
return this.jdbi.withExtension(PostgreSQLSaveOnChange.class, changeSaver -> changeSaver.saveWhisperReplyTarget(id, whisperReplyTarget));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int addIgnore(final UUID id, final UUID ignoredPlayer) {
|
|
||||||
return this.jdbi.withExtension(PostgreSQLSaveOnChange.class, changeSaver -> changeSaver.addIgnore(id, ignoredPlayer));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int removeIgnore(final UUID id, final UUID ignoredPlayer) {
|
|
||||||
return this.jdbi.withExtension(PostgreSQLSaveOnChange.class, changeSaver -> changeSaver.removeIgnore(id, ignoredPlayer));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int addLeftChannel(final UUID id, final Key channel) {
|
|
||||||
return this.jdbi.withExtension(PostgreSQLSaveOnChange.class, changeSaver -> changeSaver.addLeftChannel(id, channel));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int removeLeftChannel(final UUID id, final Key channel) {
|
|
||||||
return this.jdbi.withExtension(PostgreSQLSaveOnChange.class, changeSaver -> changeSaver.removeLeftChannel(id, channel));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public CompletableFuture<Void> loggedOut(UUID uuid) {
|
|
||||||
final CompletableFuture<@Nullable CarbonPlayerCommon> remove = this.cache.remove(uuid);
|
final CompletableFuture<@Nullable CarbonPlayerCommon> remove = this.cache.remove(uuid);
|
||||||
final @Nullable CarbonPlayerCommon join = remove.join();
|
final @Nullable CarbonPlayerCommon join = remove.join();
|
||||||
if (remove.isDone() && join != null) { // don't need to save if it never finished loading
|
if (remove.isDone() && join != null) { // don't need to save if it never finished loading
|
||||||
@@ -247,4 +190,5 @@ public final class PostgreSQLUserManager extends DatabaseUserManager implements
|
|||||||
}
|
}
|
||||||
return CompletableFuture.completedFuture(null);
|
return CompletableFuture.completedFuture(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -185,4 +185,5 @@ public class JSONUserManager implements UserManagerInternal<CarbonPlayerCommon>
|
|||||||
}
|
}
|
||||||
return CompletableFuture.completedFuture(null);
|
return CompletableFuture.completedFuture(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -31,7 +31,7 @@ import org.checkerframework.framework.qual.DefaultQualifier;
|
|||||||
|
|
||||||
@DefaultQualifier(NonNull.class)
|
@DefaultQualifier(NonNull.class)
|
||||||
@Singleton
|
@Singleton
|
||||||
public class FabricUserManager extends PlatformUserManager<CarbonPlayerFabric> {
|
public final class FabricUserManager extends PlatformUserManager<CarbonPlayerFabric> {
|
||||||
|
|
||||||
private final CarbonChatFabric carbonChatFabric;
|
private final CarbonChatFabric carbonChatFabric;
|
||||||
|
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ import org.checkerframework.framework.qual.DefaultQualifier;
|
|||||||
|
|
||||||
@DefaultQualifier(NonNull.class)
|
@DefaultQualifier(NonNull.class)
|
||||||
@Singleton
|
@Singleton
|
||||||
public class PaperUserManager extends PlatformUserManager<CarbonPlayerPaper> {
|
public final class PaperUserManager extends PlatformUserManager<CarbonPlayerPaper> {
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
private PaperUserManager(final @Backing UserManagerInternal<CarbonPlayerCommon> proxiedUserManager) {
|
private PaperUserManager(final @Backing UserManagerInternal<CarbonPlayerCommon> proxiedUserManager) {
|
||||||
|
|||||||
Reference in new issue
Block a user