functioning postgres, checkstyle fixes, etc

This commit is contained in:
Draycia committed 2022-06-08 15:17:21 -07:00
1 parent 629c34db04
commit de834ac32b
37 files changed
+641 -242

No files matched your search

@@ -22,7 +22,6 @@ package net.draycia.carbon.velocity;
import com.google.gson.Gson;
import com.google.gson.JsonObject;
import com.google.inject.Inject;
import com.velocitypowered.api.proxy.Player;
import com.velocitypowered.api.proxy.ProxyServer;
import com.velocitypowered.api.util.UuidUtils;
import java.io.IOException;
@@ -36,7 +35,6 @@ import java.util.List;
import java.util.UUID;
import java.util.concurrent.CompletableFuture;
import net.draycia.carbon.api.CarbonServer;
import net.draycia.carbon.api.users.CarbonPlayer;
import net.draycia.carbon.api.users.ComponentPlayerResult;
import net.draycia.carbon.api.users.UserManager;
import net.draycia.carbon.common.users.CarbonPlayerCommon;
@@ -44,19 +42,16 @@ import net.draycia.carbon.common.util.FastUuidSansHyphens;
import net.draycia.carbon.velocity.users.CarbonPlayerVelocity;
import net.kyori.adventure.audience.Audience;
import net.kyori.adventure.audience.ForwardingAudience;
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.jetbrains.annotations.NotNull;
import static net.kyori.adventure.text.Component.text;
@DefaultQualifier(NonNull.class)
public final class CarbonServerVelocity implements CarbonServer, ForwardingAudience.Single {
private final ProxyServer server;
private final UserManager<CarbonPlayerCommon> userManager;
private final UserManager<CarbonPlayerVelocity> userManager;
private final HttpClient client = HttpClient.newHttpClient();
private final Gson gson = new Gson();
@@ -64,7 +59,7 @@ public final class CarbonServerVelocity implements CarbonServer, ForwardingAudie
@Inject
private CarbonServerVelocity(final ProxyServer server, final UserManager<CarbonPlayerCommon> userManager) {
this.server = server;
this.userManager = userManager;
this.userManager = new VelocityUserManager(userManager, server);
}
@Override
@@ -82,56 +77,19 @@ public final class CarbonServerVelocity implements CarbonServer, ForwardingAudie
final var players = new ArrayList<CarbonPlayerVelocity>();
for (final var player : this.server.getAllPlayers()) {
final @Nullable ComponentPlayerResult<CarbonPlayer> carbonPlayer = this.player(player).join();
final ComponentPlayerResult<CarbonPlayerVelocity> carbonPlayer = this.userManager.carbonPlayer(player.getUniqueId()).join();
if (carbonPlayer.player() != null) {
players.add((CarbonPlayerVelocity) carbonPlayer.player());
players.add(carbonPlayer.player());
}
}
return players;
}
private CompletableFuture<ComponentPlayerResult<CarbonPlayer>> wrapPlayer(final UUID uuid) {
return this.userManager.carbonPlayer(uuid).thenCompose(result -> {
return CompletableFuture.supplyAsync(() -> {
if (result.player() != null) {
return new ComponentPlayerResult<>(new CarbonPlayerVelocity(this.server, result.player()), Component.empty());
}
final @Nullable String name = this.resolveName(uuid).join();
if (name != null) {
final CarbonPlayerCommon player = new CarbonPlayerCommon(name, uuid);
return new ComponentPlayerResult<>(new CarbonPlayerVelocity(this.server, player), Component.empty());
}
return new ComponentPlayerResult<>(null, text("Name not found for uuid!"));
});
});
}
@Override
public CompletableFuture<ComponentPlayerResult<CarbonPlayer>> player(final UUID uuid) {
return this.wrapPlayer(uuid);
}
@Override
public CompletableFuture<ComponentPlayerResult<CarbonPlayer>> player(final String username) {
return CompletableFuture.supplyAsync(() -> {
final @Nullable UUID uuid = this.resolveUUID(username).join();
if (uuid != null) {
return this.player(uuid).join();
}
return new ComponentPlayerResult<>(null, text("No UUID found for name."));
});
}
public CompletableFuture<ComponentPlayerResult<CarbonPlayer>> player(final Player player) {
return this.player(player.getUniqueId());
public UserManager<CarbonPlayerVelocity> userManager() {
return this.userManager;
}
@Override
@@ -0,0 +1,161 @@
/*
* 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.velocity;
import com.velocitypowered.api.proxy.ProxyServer;
import java.util.UUID;
import java.util.concurrent.CompletableFuture;
import net.draycia.carbon.api.users.ComponentPlayerResult;
import net.draycia.carbon.api.users.UserManager;
import net.draycia.carbon.common.users.CarbonPlayerCommon;
import net.draycia.carbon.common.users.SaveOnChange;
import net.draycia.carbon.velocity.users.CarbonPlayerVelocity;
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 class VelocityUserManager implements UserManager<CarbonPlayerVelocity>, SaveOnChange {
protected final UserManager<CarbonPlayerCommon> proxiedUserManager;
private final ProxyServer proxyServer;
public VelocityUserManager(final UserManager<CarbonPlayerCommon> proxiedUserManager, final ProxyServer proxyServer) {
this.proxiedUserManager = proxiedUserManager;
this.proxyServer = proxyServer;
}
@Override
public CompletableFuture<ComponentPlayerResult<CarbonPlayerVelocity>> carbonPlayer(final UUID uuid) {
return this.proxiedUserManager.carbonPlayer(uuid).thenApply(result -> {
if (result.player() == null) {
return new ComponentPlayerResult<>(null, result.reason());
}
return new ComponentPlayerResult<>(new CarbonPlayerVelocity(this.proxyServer, result.player()), result.reason());
});
}
@Override
public CompletableFuture<ComponentPlayerResult<CarbonPlayerVelocity>> savePlayer(final CarbonPlayerVelocity player) {
return this.proxiedUserManager.savePlayer(player.carbonPlayerCommon()).thenApply(result -> {
if (result.player() == null) {
return new ComponentPlayerResult<>(null, result.reason());
}
return new ComponentPlayerResult<>(new CarbonPlayerVelocity(this.proxyServer, result.player()), result.reason());
});
}
@Override
public CompletableFuture<ComponentPlayerResult<CarbonPlayerVelocity>> saveAndInvalidatePlayer(final CarbonPlayerVelocity player) {
return this.proxiedUserManager.saveAndInvalidatePlayer(player.carbonPlayerCommon()).thenApply(result -> {
if (result.player() == null) {
return new ComponentPlayerResult<>(null, result.reason());
}
return new ComponentPlayerResult<>(new CarbonPlayerVelocity(this.proxyServer, result.player()), result.reason());
});
}
@Override
public int saveDisplayName(final UUID id, final @Nullable Component component) {
if (this.proxiedUserManager instanceof SaveOnChange saveOnChange) {
return saveOnChange.saveDisplayName(id, component);
}
return -1;
}
@Override
public int saveMuted(final UUID id, final boolean muted) {
if (this.proxiedUserManager instanceof SaveOnChange saveOnChange) {
return saveOnChange.saveMuted(id, muted);
}
return -1;
}
@Override
public int saveDeafened(final UUID id, final boolean deafened) {
if (this.proxiedUserManager instanceof SaveOnChange saveOnChange) {
return saveOnChange.saveDeafened(id, deafened);
}
return -1;
}
@Override
public int saveSpying(final UUID id, final boolean spying) {
if (this.proxiedUserManager instanceof SaveOnChange saveOnChange) {
return saveOnChange.saveSpying(id, spying);
}
return -1;
}
@Override
public int saveSelectedChannel(final UUID id, final @Nullable Key selectedChannel) {
if (this.proxiedUserManager instanceof SaveOnChange saveOnChange) {
return saveOnChange.saveSelectedChannel(id, selectedChannel);
}
return -1;
}
@Override
public int saveLastWhisperTarget(final UUID id, final @Nullable UUID lastWhisperTarget) {
if (this.proxiedUserManager instanceof SaveOnChange saveOnChange) {
return saveOnChange.saveLastWhisperTarget(id, lastWhisperTarget);
}
return -1;
}
@Override
public int saveWhisperReplyTarget(final UUID id, final @Nullable UUID whisperReplyTarget) {
if (this.proxiedUserManager instanceof SaveOnChange saveOnChange) {
return saveOnChange.saveWhisperReplyTarget(id, whisperReplyTarget);
}
return -1;
}
@Override
public int addIgnore(final UUID id, final UUID ignoredPlayer) {
if (this.proxiedUserManager instanceof SaveOnChange saveOnChange) {
return saveOnChange.addIgnore(id, ignoredPlayer);
}
return -1;
}
@Override
public int removeIgnore(final UUID id, final UUID ignoredPlayer) {
if (this.proxiedUserManager instanceof SaveOnChange saveOnChange) {
return saveOnChange.removeIgnore(id, ignoredPlayer);
}
return -1;
}
}
@@ -49,7 +49,7 @@ public record VelocityPlayerCommander(
@Override
public CarbonPlayer carbonPlayer() {
return requireNonNull(this.carbon.server().player(this.player.getUniqueId()).join().player(), "No CarbonPlayer for logged in Player!");
return requireNonNull(this.carbon.server().userManager().carbonPlayer(this.player.getUniqueId()).join().player(), "No CarbonPlayer for logged in Player!");
}
}
@@ -28,6 +28,7 @@ import net.draycia.carbon.api.CarbonChat;
import net.draycia.carbon.api.channels.ChannelRegistry;
import net.draycia.carbon.api.events.CarbonChatEvent;
import net.draycia.carbon.api.users.CarbonPlayer;
import net.draycia.carbon.api.users.ComponentPlayerResult;
import net.draycia.carbon.api.util.KeyedRenderer;
import net.draycia.carbon.api.util.RenderedMessage;
import net.draycia.carbon.velocity.CarbonChatVelocity;
@@ -68,7 +69,7 @@ public final class VelocityChatListener {
event.setResult(PlayerChatEvent.ChatResult.denied());
final var playerResult = this.carbonChat.server().player(event.getPlayer().getUniqueId()).join();
final ComponentPlayerResult<? extends CarbonPlayer> playerResult = this.carbonChat.server().userManager().carbonPlayer(event.getPlayer().getUniqueId()).join();
final @Nullable CarbonPlayer sender = playerResult.player();
if (sender == null) {
@@ -47,7 +47,7 @@ public class VelocityPlayerJoinListener {
@Subscribe
public void onPlayerLeave(final DisconnectEvent event) {
this.carbonChat.server().player(event.getPlayer().getUniqueId()).thenAccept(result -> {
this.carbonChat.server().userManager().carbonPlayer(event.getPlayer().getUniqueId()).thenAccept(result -> {
if (result.player() == null) {
return;
}