mirror of
https://github.com/darksaid98/Carbon.git
synced 2026-12-01 14:38:48 +00:00
functioning postgres, checkstyle fixes, etc
This commit is contained in:
1 parent
629c34db04
commit
de834ac32b
37 files changed
+641
-242
No files matched your search
@@ -34,6 +34,7 @@ import net.draycia.carbon.common.users.CarbonPlayerCommon;
|
||||
import net.kyori.adventure.audience.Audience;
|
||||
import net.kyori.adventure.audience.ForwardingAudience;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
import org.checkerframework.framework.qual.DefaultQualifier;
|
||||
@@ -66,7 +67,7 @@ public final class CarbonServerBukkit implements CarbonServer, ForwardingAudienc
|
||||
final var players = new ArrayList<CarbonPlayer>();
|
||||
|
||||
for (final var player : this.chatBukkitEntry.getServer().getOnlinePlayers()) {
|
||||
final @Nullable ComponentPlayerResult<CarbonPlayerBukkit> result = this.userManager.carbonPlayer(player.getUniqueId()).join();
|
||||
final ComponentPlayerResult<CarbonPlayerBukkit> result = this.userManager.carbonPlayer(player.getUniqueId()).join();
|
||||
|
||||
if (result.player() != null) {
|
||||
players.add(result.player());
|
||||
@@ -84,13 +85,29 @@ public final class CarbonServerBukkit implements CarbonServer, ForwardingAudienc
|
||||
@Override
|
||||
public CompletableFuture<@Nullable UUID> resolveUUID(final String username) {
|
||||
// TODO: user cache?
|
||||
return CompletableFuture.supplyAsync(() -> Bukkit.getOfflinePlayer(username).getUniqueId());
|
||||
return CompletableFuture.supplyAsync(() -> {
|
||||
final OfflinePlayer offlinePlayer = Bukkit.getOfflinePlayer(username);
|
||||
|
||||
if (!offlinePlayer.hasPlayedBefore()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return offlinePlayer.getUniqueId();
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompletableFuture<@Nullable String> resolveName(final UUID uuid) {
|
||||
// TODO: user cache?
|
||||
return CompletableFuture.supplyAsync(() -> Bukkit.getOfflinePlayer(uuid).getName());
|
||||
return CompletableFuture.supplyAsync(() -> {
|
||||
final OfflinePlayer offlinePlayer = Bukkit.getOfflinePlayer(uuid);
|
||||
|
||||
if (!offlinePlayer.hasPlayedBefore()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return offlinePlayer.getName();
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
+1
-1
@@ -56,7 +56,7 @@ public class DiscordMessageListener implements Listener {
|
||||
return;
|
||||
}
|
||||
|
||||
final var result = this.carbonChat.server().player(event.getUUID()).join();
|
||||
final var result = this.carbonChat.server().userManager().carbonPlayer(event.getUUID()).join();
|
||||
|
||||
if (result.player() != null) {
|
||||
var channel = result.player().selectedChannel();
|
||||
|
||||
@@ -42,9 +42,9 @@ import net.draycia.carbon.common.messages.placeholders.KeyPlaceholderResolver;
|
||||
import net.draycia.carbon.common.messages.placeholders.StringPlaceholderResolver;
|
||||
import net.draycia.carbon.common.messages.placeholders.UUIDPlaceholderResolver;
|
||||
import net.draycia.carbon.common.users.CarbonPlayerCommon;
|
||||
import net.draycia.carbon.common.users.db.mysql.MySQLUserManager;
|
||||
import net.draycia.carbon.common.users.db.postgresql.PostgreSQLUserManager;
|
||||
import net.draycia.carbon.common.users.json.JSONUserManager;
|
||||
import net.draycia.carbon.common.users.db.mysql.MySQLUserManager;
|
||||
import net.kyori.adventure.audience.Audience;
|
||||
import net.kyori.adventure.key.Key;
|
||||
import net.kyori.adventure.text.Component;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -30,6 +30,7 @@ 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)
|
||||
@@ -45,7 +46,7 @@ public class ProxiedCachingUserManager implements UserManager<CarbonPlayerCommon
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompletableFuture<ComponentPlayerResult<CarbonPlayerCommon>> carbonPlayer(UUID uuid) {
|
||||
public CompletableFuture<ComponentPlayerResult<CarbonPlayerCommon>> carbonPlayer(final UUID uuid) {
|
||||
return CompletableFuture.supplyAsync(() -> {
|
||||
final @Nullable CarbonPlayerCommon cachedPlayer = this.userCache.get(uuid);
|
||||
|
||||
|
||||
@@ -20,8 +20,6 @@
|
||||
package net.draycia.carbon.common.users.db;
|
||||
|
||||
import java.sql.Types;
|
||||
import java.util.UUID;
|
||||
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.argument.AbstractArgumentFactory;
|
||||
|
||||
@@ -20,7 +20,6 @@
|
||||
package net.draycia.carbon.common.users.db;
|
||||
|
||||
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;
|
||||
|
||||
@@ -22,7 +22,6 @@ package net.draycia.carbon.common.users.db;
|
||||
import com.google.common.base.Splitter;
|
||||
import java.util.List;
|
||||
import net.draycia.carbon.api.CarbonChat;
|
||||
import net.draycia.carbon.api.CarbonChatProvider;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
import org.jdbi.v3.core.locator.ClasspathSqlLocator;
|
||||
import org.jdbi.v3.core.locator.internal.ClasspathBuilder;
|
||||
@@ -46,7 +45,7 @@ public final class QueriesLocator {
|
||||
}
|
||||
|
||||
private String locate(final String name) {
|
||||
return locator.getResource(
|
||||
return this.locator.getResource(
|
||||
CarbonChat.class.getClassLoader(),
|
||||
new ClasspathBuilder()
|
||||
.appendDotPath(name)
|
||||
|
||||
-1
@@ -24,7 +24,6 @@ import java.sql.SQLException;
|
||||
import java.util.UUID;
|
||||
import net.draycia.carbon.common.users.CarbonPlayerCommon;
|
||||
import net.kyori.adventure.key.Key;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
import org.intellij.lang.annotations.Subst;
|
||||
|
||||
@@ -197,42 +197,42 @@ public final class MySQLUserManager implements UserManager<CarbonPlayerCommon>,
|
||||
}
|
||||
|
||||
@Override
|
||||
public int saveMuted(UUID id, boolean muted) {
|
||||
public int saveMuted(final UUID id, final boolean muted) {
|
||||
return this.jdbi.withExtension(MySQLSaveOnChange.class, changeSaver -> changeSaver.saveMuted(id, muted));
|
||||
}
|
||||
|
||||
@Override
|
||||
public int saveDeafened(UUID id, boolean deafened) {
|
||||
public int saveDeafened(final UUID id, final boolean deafened) {
|
||||
return this.jdbi.withExtension(MySQLSaveOnChange.class, changeSaver -> changeSaver.saveDeafened(id, deafened));
|
||||
}
|
||||
|
||||
@Override
|
||||
public int saveSpying(UUID id, boolean spying) {
|
||||
public int saveSpying(final UUID id, final boolean spying) {
|
||||
return this.jdbi.withExtension(MySQLSaveOnChange.class, changeSaver -> changeSaver.saveSpying(id, spying));
|
||||
}
|
||||
|
||||
@Override
|
||||
public int saveSelectedChannel(UUID id, @Nullable Key selectedChannel) {
|
||||
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(UUID id, @Nullable UUID lastWhisperTarget) {
|
||||
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(UUID id, @Nullable UUID whisperReplyTarget) {
|
||||
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(UUID id, UUID ignoredPlayer) {
|
||||
public int addIgnore(final UUID id, final UUID ignoredPlayer) {
|
||||
return this.jdbi.withExtension(MySQLSaveOnChange.class, changeSaver -> changeSaver.addIgnore(id, ignoredPlayer));
|
||||
}
|
||||
|
||||
@Override
|
||||
public int removeIgnore(UUID id, UUID ignoredPlayer) {
|
||||
public int removeIgnore(final UUID id, final UUID ignoredPlayer) {
|
||||
return this.jdbi.withExtension(MySQLSaveOnChange.class, changeSaver -> changeSaver.removeIgnore(id, ignoredPlayer));
|
||||
}
|
||||
|
||||
|
||||
+19
@@ -1,3 +1,22 @@
|
||||
/*
|
||||
* 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.postgresql;
|
||||
|
||||
import java.sql.ResultSet;
|
||||
|
||||
+19
@@ -1,3 +1,22 @@
|
||||
/*
|
||||
* 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.postgresql;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
+10
-10
@@ -36,10 +36,10 @@ 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.DBType;
|
||||
import net.draycia.carbon.common.users.db.QueriesLocator;
|
||||
import net.draycia.carbon.common.users.db.ComponentArgumentFactory;
|
||||
import net.draycia.carbon.common.users.db.DBType;
|
||||
import net.draycia.carbon.common.users.db.KeyArgumentFactory;
|
||||
import net.draycia.carbon.common.users.db.QueriesLocator;
|
||||
import net.kyori.adventure.key.Key;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
@@ -194,42 +194,42 @@ public final class PostgreSQLUserManager implements UserManager<CarbonPlayerComm
|
||||
}
|
||||
|
||||
@Override
|
||||
public int saveMuted(UUID id, boolean muted) {
|
||||
public int saveMuted(final UUID id, final boolean muted) {
|
||||
return this.jdbi.withExtension(PostgreSQLSaveOnChange.class, changeSaver -> changeSaver.saveMuted(id, muted));
|
||||
}
|
||||
|
||||
@Override
|
||||
public int saveDeafened(UUID id, boolean deafened) {
|
||||
public int saveDeafened(final UUID id, final boolean deafened) {
|
||||
return this.jdbi.withExtension(PostgreSQLSaveOnChange.class, changeSaver -> changeSaver.saveDeafened(id, deafened));
|
||||
}
|
||||
|
||||
@Override
|
||||
public int saveSpying(UUID id, boolean spying) {
|
||||
public int saveSpying(final UUID id, final boolean spying) {
|
||||
return this.jdbi.withExtension(PostgreSQLSaveOnChange.class, changeSaver -> changeSaver.saveSpying(id, spying));
|
||||
}
|
||||
|
||||
@Override
|
||||
public int saveSelectedChannel(UUID id, @Nullable Key selectedChannel) {
|
||||
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(UUID id, @Nullable UUID lastWhisperTarget) {
|
||||
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(UUID id, @Nullable UUID whisperReplyTarget) {
|
||||
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(UUID id, UUID ignoredPlayer) {
|
||||
public int addIgnore(final UUID id, final UUID ignoredPlayer) {
|
||||
return this.jdbi.withExtension(PostgreSQLSaveOnChange.class, changeSaver -> changeSaver.addIgnore(id, ignoredPlayer));
|
||||
}
|
||||
|
||||
@Override
|
||||
public int removeIgnore(UUID id, UUID ignoredPlayer) {
|
||||
public int removeIgnore(final UUID id, final UUID ignoredPlayer) {
|
||||
return this.jdbi.withExtension(PostgreSQLSaveOnChange.class, changeSaver -> changeSaver.removeIgnore(id, ignoredPlayer));
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
INSERT INTO carbon_users VALUES (
|
||||
:id,
|
||||
:muted,
|
||||
:deafened,
|
||||
:selectedchannel,
|
||||
:username,
|
||||
:displayname,
|
||||
:lastwhispertarget,
|
||||
:whisperreplytarget,
|
||||
:spying
|
||||
);
|
||||
@@ -0,0 +1 @@
|
||||
INSERT INTO carbon_ignores (id, ignoredplayer) VALUES(:id, :ignoredplayer)
|
||||
@@ -0,0 +1,12 @@
|
||||
UPDATE carbon_users
|
||||
SET
|
||||
id = :id,
|
||||
muted = :muted,
|
||||
deafened = :deafened,
|
||||
selectedchannel = :selectedchannel,
|
||||
username= :username,
|
||||
displayname = :displayname,
|
||||
lastwhispertarget = :lastwhispertarget,
|
||||
whisperreplytarget = :whisperreplytarget,
|
||||
spying = :spying
|
||||
WHERE id = :id;
|
||||
@@ -0,0 +1 @@
|
||||
SELECT ignoredplayer FROM carbon_ignores WHERE (id = :id);
|
||||
@@ -0,0 +1,11 @@
|
||||
SELECT
|
||||
id,
|
||||
muted,
|
||||
deafened,
|
||||
selectedchannel,
|
||||
username,
|
||||
displayname,
|
||||
lastwhispertarget,
|
||||
whisperreplytarget,
|
||||
spying
|
||||
FROM carbon_users WHERE (id = :id);
|
||||
@@ -19,22 +19,12 @@
|
||||
*/
|
||||
package net.draycia.carbon.fabric;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.JsonArray;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.Singleton;
|
||||
import java.io.IOException;
|
||||
import java.net.URI;
|
||||
import java.net.http.HttpClient;
|
||||
import java.net.http.HttpRequest;
|
||||
import java.net.http.HttpResponse;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import net.draycia.carbon.api.CarbonServer;
|
||||
import net.draycia.carbon.api.users.CarbonPlayer;
|
||||
import net.draycia.carbon.api.users.ComponentPlayerResult;
|
||||
@@ -44,32 +34,23 @@ import net.draycia.carbon.fabric.users.CarbonPlayerFabric;
|
||||
import net.kyori.adventure.audience.Audience;
|
||||
import net.kyori.adventure.audience.ForwardingAudience;
|
||||
import net.kyori.adventure.platform.fabric.FabricServerAudiences;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
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;
|
||||
|
||||
@Singleton
|
||||
@DefaultQualifier(NonNull.class)
|
||||
public final class CarbonServerFabric implements CarbonServer, ForwardingAudience.Single {
|
||||
|
||||
private final CarbonChatFabric carbonChatFabric;
|
||||
private final UserManager<CarbonPlayerCommon> userManager;
|
||||
|
||||
private final Map<UUID, CarbonPlayerFabric> userCache = new ConcurrentHashMap<>();
|
||||
|
||||
private final HttpClient client = HttpClient.newHttpClient();
|
||||
private final Gson gson = new Gson();
|
||||
private final UserManager<CarbonPlayerFabric> userManager;
|
||||
|
||||
@Inject
|
||||
private CarbonServerFabric(final CarbonChatFabric carbonChatFabric, final UserManager<CarbonPlayerCommon> userManager) {
|
||||
this.carbonChatFabric = carbonChatFabric;
|
||||
this.userManager = userManager;
|
||||
this.userManager = new FabricUserManager(userManager, carbonChatFabric);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -87,7 +68,7 @@ public final class CarbonServerFabric implements CarbonServer, ForwardingAudienc
|
||||
final var players = new ArrayList<CarbonPlayer>();
|
||||
|
||||
for (final var player : this.carbonChatFabric.minecraftServer().getPlayerList().getPlayers()) {
|
||||
final @Nullable ComponentPlayerResult<CarbonPlayer> result = this.player(player).join();
|
||||
final ComponentPlayerResult<CarbonPlayerFabric> result = this.userManager.carbonPlayer(player.getUUID()).join();
|
||||
|
||||
if (result.player() != null) {
|
||||
players.add(result.player());
|
||||
@@ -97,59 +78,9 @@ public final class CarbonServerFabric implements CarbonServer, ForwardingAudienc
|
||||
return players;
|
||||
}
|
||||
|
||||
private CompletableFuture<ComponentPlayerResult<CarbonPlayer>> wrapPlayer(final UUID uuid) {
|
||||
return CompletableFuture.supplyAsync(() -> {
|
||||
final @Nullable CarbonPlayerFabric cachedPlayer = this.userCache.get(uuid);
|
||||
|
||||
if (cachedPlayer != null) {
|
||||
return new ComponentPlayerResult<>(cachedPlayer, Component.empty());
|
||||
}
|
||||
|
||||
final ComponentPlayerResult<CarbonPlayerCommon> result = this.userManager.carbonPlayer(uuid).join();
|
||||
|
||||
if (result.player() != null) {
|
||||
final CarbonPlayerFabric carbonPlayerFabric = new CarbonPlayerFabric(result.player(), this.carbonChatFabric);
|
||||
|
||||
this.userCache.put(uuid, carbonPlayerFabric);
|
||||
|
||||
return new ComponentPlayerResult<>(carbonPlayerFabric, Component.empty());
|
||||
}
|
||||
|
||||
final @Nullable String name = this.resolveName(uuid).join();
|
||||
|
||||
if (name != null) {
|
||||
final CarbonPlayerCommon player = new CarbonPlayerCommon(name, uuid);
|
||||
final CarbonPlayerFabric carbonPlayerFabric = new CarbonPlayerFabric(player, this.carbonChatFabric);
|
||||
|
||||
this.userCache.put(uuid, carbonPlayerFabric);
|
||||
|
||||
return new ComponentPlayerResult<>(carbonPlayerFabric, 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.getUUID());
|
||||
public UserManager<CarbonPlayerFabric> userManager() {
|
||||
return this.userManager;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -170,23 +101,4 @@ public final class CarbonServerFabric implements CarbonServer, ForwardingAudienc
|
||||
return CompletableFuture.completedFuture(serverPlayer.getGameProfile().getName());
|
||||
}
|
||||
|
||||
private @Nullable JsonObject queryMojang(final URI uri) {
|
||||
final HttpRequest request = HttpRequest
|
||||
.newBuilder(uri)
|
||||
.GET()
|
||||
.build();
|
||||
|
||||
try {
|
||||
final HttpResponse<String> response =
|
||||
this.client.send(request, HttpResponse.BodyHandlers.ofString());
|
||||
final String mojangResponse = response.body();
|
||||
|
||||
final JsonArray jsonArray = this.gson.fromJson(mojangResponse, JsonObject.class).getAsJsonArray();
|
||||
return (JsonObject) jsonArray.get(1);
|
||||
} catch (IOException | InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,160 @@
|
||||
/*
|
||||
* 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.fabric;
|
||||
|
||||
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.fabric.users.CarbonPlayerFabric;
|
||||
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 FabricUserManager implements UserManager<CarbonPlayerFabric>, SaveOnChange {
|
||||
|
||||
protected final UserManager<CarbonPlayerCommon> proxiedUserManager;
|
||||
private final CarbonChatFabric carbonChatFabric;
|
||||
|
||||
public FabricUserManager(final UserManager<CarbonPlayerCommon> proxiedUserManager, final CarbonChatFabric carbonChatFabric) {
|
||||
this.proxiedUserManager = proxiedUserManager;
|
||||
this.carbonChatFabric = carbonChatFabric;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompletableFuture<ComponentPlayerResult<CarbonPlayerFabric>> 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 CarbonPlayerFabric(result.player(), this.carbonChatFabric), result.reason());
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompletableFuture<ComponentPlayerResult<CarbonPlayerFabric>> savePlayer(final CarbonPlayerFabric player) {
|
||||
return this.proxiedUserManager.savePlayer(player.carbonPlayerCommon()).thenApply(result -> {
|
||||
if (result.player() == null) {
|
||||
return new ComponentPlayerResult<>(null, result.reason());
|
||||
}
|
||||
|
||||
return new ComponentPlayerResult<>(new CarbonPlayerFabric(result.player(), this.carbonChatFabric), result.reason());
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompletableFuture<ComponentPlayerResult<CarbonPlayerFabric>> saveAndInvalidatePlayer(final CarbonPlayerFabric player) {
|
||||
return this.proxiedUserManager.saveAndInvalidatePlayer(player.carbonPlayerCommon()).thenApply(result -> {
|
||||
if (result.player() == null) {
|
||||
return new ComponentPlayerResult<>(null, result.reason());
|
||||
}
|
||||
|
||||
return new ComponentPlayerResult<>(new CarbonPlayerFabric(result.player(), this.carbonChatFabric), 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;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -47,7 +47,7 @@ public record FabricPlayerCommander(
|
||||
@Override
|
||||
public CarbonPlayer carbonPlayer() {
|
||||
return requireNonNull(
|
||||
this.carbon.server().player(this.player().getUUID()).join().player(),
|
||||
this.carbon.server().userManager().carbonPlayer(this.player().getUUID()).join().player(),
|
||||
"No CarbonPlayer for logged in Player!"
|
||||
);
|
||||
}
|
||||
|
||||
@@ -62,7 +62,7 @@ public class FabricChatListener implements Consumer<ChatCallback.Chat> {
|
||||
|
||||
@Override
|
||||
public void accept(final ChatCallback.Chat chat) {
|
||||
final var playerResult = this.carbonChatFabric.server().player(chat.sender().getUUID()).join();
|
||||
final var playerResult = this.carbonChatFabric.server().userManager().carbonPlayer(chat.sender().getUUID()).join();
|
||||
final @Nullable CarbonPlayer sender = playerResult.player();
|
||||
|
||||
if (sender == null) {
|
||||
@@ -125,7 +125,7 @@ public class FabricChatListener implements Consumer<ChatCallback.Chat> {
|
||||
try {
|
||||
final Optional<UUID> uuid = viewer.get(Identity.UUID);
|
||||
if (uuid.isPresent()) {
|
||||
final ComponentPlayerResult<CarbonPlayer> targetPlayer = this.carbonChatFabric.server().player(uuid.get()).join();
|
||||
final ComponentPlayerResult<? extends CarbonPlayer> targetPlayer = this.carbonChatFabric.server().userManager().carbonPlayer(uuid.get()).join();
|
||||
|
||||
renderedMessage = renderer.render(sender, targetPlayer.player(), renderedMessage.component(), chatEvent.message());
|
||||
} else {
|
||||
|
||||
+1
-1
@@ -46,7 +46,7 @@ public class FabricPlayerLeaveListener implements PlayerStatusMessageEvents.Mess
|
||||
|
||||
@Override
|
||||
public void onMessage(final PlayerStatusMessageEvents.MessageEvent event) {
|
||||
this.carbonChat.server().player(event.player().getUUID()).thenAccept(result -> {
|
||||
this.carbonChat.server().userManager().carbonPlayer(event.player().getUUID()).thenAccept(result -> {
|
||||
if (result.player() == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -26,35 +26,31 @@ 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;
|
||||
import net.draycia.carbon.sponge.users.CarbonPlayerSponge;
|
||||
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 org.spongepowered.api.Game;
|
||||
import org.spongepowered.api.Sponge;
|
||||
import org.spongepowered.api.entity.living.player.Player;
|
||||
|
||||
import static net.kyori.adventure.text.Component.text;
|
||||
import org.spongepowered.api.profile.ProfileNotFoundException;
|
||||
|
||||
@Singleton
|
||||
@DefaultQualifier(NonNull.class)
|
||||
public final class CarbonServerSponge implements CarbonServer, ForwardingAudience.Single {
|
||||
|
||||
private final Game game;
|
||||
private final UserManager<CarbonPlayerCommon> userManager;
|
||||
private final UserManager<CarbonPlayerSponge> userManager;
|
||||
|
||||
@Inject
|
||||
private CarbonServerSponge(final UserManager<CarbonPlayerCommon> userManager, final Game game) {
|
||||
this.game = game;
|
||||
this.userManager = userManager;
|
||||
this.userManager = new SpongeUserManager(userManager);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -72,70 +68,41 @@ public final class CarbonServerSponge implements CarbonServer, ForwardingAudienc
|
||||
final var players = new ArrayList<CarbonPlayerSponge>();
|
||||
|
||||
for (final var player : Sponge.server().onlinePlayers()) {
|
||||
final ComponentPlayerResult<CarbonPlayer> result = this.player(player).join();
|
||||
final ComponentPlayerResult<CarbonPlayerSponge> result = this.userManager.carbonPlayer(player.uniqueId()).join();
|
||||
|
||||
if (result.player() != null) {
|
||||
players.add((CarbonPlayerSponge) result.player());
|
||||
players.add(result.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 CarbonPlayerSponge(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 CarbonPlayerSponge(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.uniqueId());
|
||||
public UserManager<CarbonPlayerSponge> userManager() {
|
||||
return this.userManager;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompletableFuture<@Nullable UUID> resolveUUID(final String username) {
|
||||
return CompletableFuture.supplyAsync(() ->
|
||||
Sponge.server().gameProfileManager().basicProfile(username).join().uuid()
|
||||
);
|
||||
return CompletableFuture.supplyAsync(() -> {
|
||||
try {
|
||||
return Sponge.server().gameProfileManager().basicProfile(username).join().uuid();
|
||||
} catch (final ProfileNotFoundException exception) {
|
||||
return null;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompletableFuture<@Nullable String> resolveName(final UUID uuid) {
|
||||
return CompletableFuture.supplyAsync(() ->
|
||||
Sponge.server().gameProfileManager().basicProfile(uuid).join().name().orElse(null)
|
||||
);
|
||||
return CompletableFuture.supplyAsync(() -> {
|
||||
try {
|
||||
return Sponge.server().gameProfileManager().basicProfile(uuid).join().name().orElse(null);
|
||||
} catch (final ProfileNotFoundException exception) {
|
||||
return null;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,158 @@
|
||||
/*
|
||||
* 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.sponge;
|
||||
|
||||
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.sponge.users.CarbonPlayerSponge;
|
||||
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 SpongeUserManager implements UserManager<CarbonPlayerSponge>, SaveOnChange {
|
||||
|
||||
protected final UserManager<CarbonPlayerCommon> proxiedUserManager;
|
||||
|
||||
public SpongeUserManager(final UserManager<CarbonPlayerCommon> proxiedUserManager) {
|
||||
this.proxiedUserManager = proxiedUserManager;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompletableFuture<ComponentPlayerResult<CarbonPlayerSponge>> 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 CarbonPlayerSponge(result.player()), result.reason());
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompletableFuture<ComponentPlayerResult<CarbonPlayerSponge>> savePlayer(final CarbonPlayerSponge player) {
|
||||
return this.proxiedUserManager.savePlayer(player.carbonPlayerCommon()).thenApply(result -> {
|
||||
if (result.player() == null) {
|
||||
return new ComponentPlayerResult<>(null, result.reason());
|
||||
}
|
||||
|
||||
return new ComponentPlayerResult<>(new CarbonPlayerSponge(result.player()), result.reason());
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompletableFuture<ComponentPlayerResult<CarbonPlayerSponge>> saveAndInvalidatePlayer(final CarbonPlayerSponge player) {
|
||||
return this.proxiedUserManager.saveAndInvalidatePlayer(player.carbonPlayerCommon()).thenApply(result -> {
|
||||
if (result.player() == null) {
|
||||
return new ComponentPlayerResult<>(null, result.reason());
|
||||
}
|
||||
|
||||
return new ComponentPlayerResult<>(new CarbonPlayerSponge(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;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -40,7 +40,7 @@ public record SpongePlayerCommander(
|
||||
|
||||
@Override
|
||||
public CarbonPlayer carbonPlayer() {
|
||||
return requireNonNull(this.carbon.server().player(this.player.uniqueId()).join().player(), "No CarbonPlayer for logged in Player!");
|
||||
return requireNonNull(this.carbon.server().userManager().carbonPlayer(this.player.uniqueId()).join().player(), "No CarbonPlayer for logged in Player!");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -77,7 +77,7 @@ public final class SpongeChatListener {
|
||||
@Listener
|
||||
@IsCancelled(Tristate.FALSE)
|
||||
public void onPlayerChat(final PlayerChatEvent event, final @First Player source) {
|
||||
final var playerResult = this.carbonChat.server().player(source.uniqueId()).join();
|
||||
final var playerResult = this.carbonChat.server().userManager().carbonPlayer(source.uniqueId()).join();
|
||||
final @Nullable CarbonPlayer sender = playerResult.player();
|
||||
|
||||
if (sender == null) {
|
||||
@@ -158,7 +158,7 @@ public final class SpongeChatListener {
|
||||
for (final var renderer : chatEvent.renderers()) {
|
||||
try {
|
||||
if (recipient instanceof Player player) {
|
||||
final ComponentPlayerResult<CarbonPlayer> targetPlayer = this.carbonChat.server().player(player).join();
|
||||
final ComponentPlayerResult<? extends CarbonPlayer> targetPlayer = this.carbonChat.server().userManager().carbonPlayer(player.uniqueId()).join();
|
||||
|
||||
renderedMessage = renderer.render(sender, targetPlayer.player(), renderedMessage.component(), chatEvent.message());
|
||||
} else {
|
||||
@@ -177,7 +177,7 @@ public final class SpongeChatListener {
|
||||
|
||||
for (final var renderer : chatEvent.renderers()) {
|
||||
if (target instanceof ServerPlayer serverPlayer) {
|
||||
final ComponentPlayerResult<CarbonPlayer> targetPlayer = this.carbonChat.server().player(serverPlayer).join();
|
||||
final ComponentPlayerResult<? extends CarbonPlayer> targetPlayer = this.carbonChat.server().userManager().carbonPlayer(serverPlayer.uniqueId()).join();
|
||||
component = renderer.render(playerResult.player(), targetPlayer.player(), component, msg).component();
|
||||
} else {
|
||||
component = renderer.render(playerResult.player(), target, component, msg).component();
|
||||
|
||||
+1
-1
@@ -47,7 +47,7 @@ public class SpongePlayerJoinListener {
|
||||
|
||||
@Listener
|
||||
public void onPlayerQuit(final ServerSideConnectionEvent.Disconnect event) {
|
||||
this.carbonChat.server().player(event.player().uniqueId()).thenAccept(result -> {
|
||||
this.carbonChat.server().userManager().carbonPlayer(event.player().uniqueId()).thenAccept(result -> {
|
||||
if (result.player() == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
+1
-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!");
|
||||
}
|
||||
|
||||
}
|
||||
+2
-1
@@ -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) {
|
||||
|
||||
+1
-1
@@ -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;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user