Update moonshine, add auto-nickname (#155)

This commit is contained in:
Josua Parks authored and GitHub committed 2021-09-01 12:41:10 -07:00
1 parent 74e83a08a0
commit 3b1987b5a2
71 files changed
+1022 -829

No files matched your search

@@ -8,7 +8,6 @@ import com.velocitypowered.api.plugin.Plugin;
import com.velocitypowered.api.plugin.PluginContainer;
import com.velocitypowered.api.plugin.annotation.DataDirectory;
import com.velocitypowered.api.proxy.ProxyServer;
import java.net.URISyntaxException;
import java.nio.file.Path;
import java.util.Set;
import net.draycia.carbon.api.CarbonChatProvider;
@@ -40,13 +39,13 @@ public class CarbonChatVelocity extends CarbonChatCommon {
private final Path dataDirectory;
private final ProxyServer proxyServer;
private final PluginContainer pluginContainer;
private final Logger logger;
private final Injector injector;
private final CarbonMessageService messageService;
private final ChannelRegistry channelRegistry;
private final CarbonServerVelocity carbonServer;
private final CarbonEventHandler eventHandler = new CarbonEventHandler();
@Inject
public CarbonChatVelocity(
@@ -59,17 +58,12 @@ public class CarbonChatVelocity extends CarbonChatCommon {
this.dataDirectory = dataDirectory;
this.proxyServer = proxyServer;
this.pluginContainer = pluginContainer;
this.logger = LogManager.getLogger(this.pluginContainer.getDescription().getId());
this.logger = LogManager.getLogger(pluginContainer.getDescription().getId());
final CarbonChatVelocityModule carbonVelocityModule;
try {
carbonVelocityModule = new CarbonChatVelocityModule(
this.logger, this.dataDirectory, this.pluginContainer, this.proxyServer, this);
} catch (final URISyntaxException ex) {
throw new RuntimeException(ex);
}
carbonVelocityModule = new CarbonChatVelocityModule(
this.logger, this.dataDirectory, pluginContainer, this.proxyServer, this);
this.injector = injector.createChildInjector(carbonVelocityModule);
@@ -113,8 +107,6 @@ public class CarbonChatVelocity extends CarbonChatCommon {
return this.messageService;
}
private final CarbonEventHandler eventHandler = new CarbonEventHandler();
@Override
public final @NonNull CarbonEventHandler eventHandler() {
return this.eventHandler;
@@ -9,7 +9,6 @@ import com.google.inject.Singleton;
import com.velocitypowered.api.plugin.PluginContainer;
import com.velocitypowered.api.proxy.Player;
import com.velocitypowered.api.proxy.ProxyServer;
import java.net.URISyntaxException;
import java.nio.file.Path;
import net.draycia.carbon.api.CarbonChat;
import net.draycia.carbon.api.CarbonServer;
@@ -37,7 +36,7 @@ public final class CarbonChatVelocityModule extends AbstractModule {
final PluginContainer pluginContainer,
final ProxyServer proxyServer,
final CarbonChatVelocity carbonChatVelocity
) throws URISyntaxException {
) {
this.logger = logger;
this.dataDirectory = dataDirectory;
this.pluginContainer = pluginContainer;
@@ -47,7 +46,7 @@ public final class CarbonChatVelocityModule extends AbstractModule {
@Provides
@Singleton
protected @NonNull CommandManager<Commander> createCommandManager() {
protected CommandManager<Commander> createCommandManager() {
final VelocityCommandManager<Commander> commandManager = new VelocityCommandManager<>(
this.pluginContainer,
this.proxyServer,
@@ -28,6 +28,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 org.jetbrains.annotations.NotNull;
import static net.kyori.adventure.text.Component.text;
@@ -47,7 +48,7 @@ public final class CarbonServerVelocity implements CarbonServer, ForwardingAudie
}
@Override
public Audience audience() {
public @NotNull Audience audience() {
return Audience.audience(this.console(), Audience.audience(this.players()));
}
@@ -123,12 +124,7 @@ public final class CarbonServerVelocity implements CarbonServer, ForwardingAudie
.GET()
.build();
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();
final JsonObject json = (JsonObject) jsonArray.get(1);
final JsonObject json = this.queryMojang(request);
return UuidUtils.fromUndashed(json.get("uuid").getAsString());
} catch (final URISyntaxException | IOException | InterruptedException e) {
@@ -148,12 +144,7 @@ public final class CarbonServerVelocity implements CarbonServer, ForwardingAudie
.GET()
.build();
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();
final JsonObject json = (JsonObject) jsonArray.get(1);
final JsonObject json = this.queryMojang(request);
return json.get("name").getAsString();
} catch (final URISyntaxException | IOException | InterruptedException e) {
@@ -164,4 +155,13 @@ public final class CarbonServerVelocity implements CarbonServer, ForwardingAudie
});
}
private JsonObject queryMojang(final HttpRequest request) throws IOException, InterruptedException {
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);
}
}
@@ -6,31 +6,21 @@ import net.kyori.adventure.audience.Audience;
import net.kyori.adventure.audience.ForwardingAudience;
import org.checkerframework.checker.nullness.qual.NonNull;
import org.checkerframework.framework.qual.DefaultQualifier;
import org.jetbrains.annotations.NotNull;
@DefaultQualifier(NonNull.class)
public interface VelocityCommander extends Commander, ForwardingAudience.Single {
CommandSource commandSource();
static VelocityCommander from(final CommandSource source) {
return new VelocityCommanderImpl(source);
}
final class VelocityCommanderImpl implements VelocityCommander {
CommandSource commandSource();
private final CommandSource commandSource;
private VelocityCommanderImpl(final CommandSource commandSource) {
this.commandSource = commandSource;
}
record VelocityCommanderImpl(CommandSource commandSource) implements VelocityCommander {
@Override
public CommandSource commandSource() {
return this.commandSource;
}
@Override
public Audience audience() {
public @NotNull Audience audience() {
return this.commandSource;
}
@@ -8,6 +8,7 @@ import net.draycia.carbon.common.command.PlayerCommander;
import net.kyori.adventure.audience.Audience;
import org.checkerframework.checker.nullness.qual.NonNull;
import org.checkerframework.framework.qual.DefaultQualifier;
import org.jetbrains.annotations.NotNull;
import static java.util.Objects.requireNonNull;
@@ -23,7 +24,7 @@ public record VelocityPlayerCommander(
}
@Override
public Audience audience() {
public @NotNull Audience audience() {
return this.player;
}
@@ -11,7 +11,9 @@ import net.draycia.carbon.api.events.CarbonChatEvent;
import net.draycia.carbon.api.users.ComponentPlayerResult;
import net.draycia.carbon.api.util.KeyedRenderer;
import net.draycia.carbon.velocity.CarbonChatVelocity;
import net.kyori.adventure.text.Component;
import org.checkerframework.checker.nullness.qual.NonNull;
import org.checkerframework.framework.qual.DefaultQualifier;
import static java.util.Objects.requireNonNullElse;
import static net.draycia.carbon.api.util.KeyedRenderer.keyedRenderer;
@@ -19,6 +21,7 @@ import static net.kyori.adventure.key.Key.key;
import static net.kyori.adventure.text.Component.empty;
import static net.kyori.adventure.text.Component.text;
@DefaultQualifier(NonNull.class)
public final class VelocityChatListener {
private final CarbonChatVelocity carbonChat;
@@ -31,7 +34,7 @@ public final class VelocityChatListener {
}
@Subscribe
public void onPlayerChat(final @NonNull PlayerChatEvent event) {
public void onPlayerChat(final PlayerChatEvent event) {
final var playerResult = this.carbonChat.server().player(event.getPlayer().getUniqueId()).join();
if (playerResult.player() == null) {
@@ -67,7 +70,7 @@ public final class VelocityChatListener {
}
}
if (component != null) {
if (component != Component.empty()) {
recipient.sendMessage(component);
}
}
@@ -14,6 +14,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 org.jetbrains.annotations.NotNull;
@DefaultQualifier(NonNull.class)
public final class CarbonPlayerVelocity extends CarbonPlayerCommon {
@@ -42,7 +43,7 @@ public final class CarbonPlayerVelocity extends CarbonPlayerCommon {
}
@Override
public Audience audience() {
public @NotNull Audience audience() {
final @Nullable Player player = this.player();
if (player == null) {
@@ -103,7 +104,7 @@ public final class CarbonPlayerVelocity extends CarbonPlayerCommon {
}
@Override
public @NonNull Identity identity() {
public @NotNull Identity identity() {
return this.carbonPlayer.identity();
}