3
0
Mirror von https://github.com/PaperMC/Velocity.git synchronisiert 2024-11-16 21:10:30 +01:00

Further API tweaks

Dieser Commit ist enthalten in:
Andrew Steinborn 2021-06-18 16:18:15 -04:00
Ursprung 5579f76316
Commit cbee52aa61
22 geänderte Dateien mit 95 neuen und 106 gelöschten Zeilen

Datei anzeigen

@ -8,8 +8,18 @@
package com.velocitypowered.api.network.registry;
import com.velocitypowered.api.network.PlatformVersion;
import java.util.Collection;
import org.checkerframework.checker.nullness.qual.Nullable;
public interface ProtocolVersionRegistry {
/**
* Returns a collection of supported protocol versions for the given {@code platform}. The
* collection is expected to be ordered and immutable.
*
* @param platform the platform to look up the versions for
* @return an ordered, immutable collection of supported protocol versions
*/
Collection<PlatformVersion> supported(Platform platform);
@Nullable PlatformVersion lookup(Platform platform, int version);
}

Datei anzeigen

@ -16,6 +16,7 @@ import com.velocitypowered.api.plugin.PluginManager;
import com.velocitypowered.api.proxy.config.ProxyConfig;
import com.velocitypowered.api.proxy.connection.Player;
import com.velocitypowered.api.proxy.messages.ChannelRegistrar;
import com.velocitypowered.api.proxy.player.PlayerIdentity;
import com.velocitypowered.api.proxy.server.RegisteredServer;
import com.velocitypowered.api.proxy.server.ServerInfo;
import com.velocitypowered.api.scheduler.Scheduler;
@ -60,6 +61,16 @@ public interface ProxyServer extends Audience {
*/
@Nullable Player player(UUID uuid);
/**
* Retrieves the player currently connected to this proxy by their identity.
*
* @param identity the identity
* @return the player instance, if connected, else {@code null}
*/
@Nullable default Player player(PlayerIdentity identity) {
return player(identity.uuid());
}
/**
* Retrieves all players currently connected to this proxy. This call may or may not be a snapshot
* of all players online.

Datei anzeigen

@ -15,7 +15,7 @@ import com.velocitypowered.api.proxy.messages.PluginChannelId;
import com.velocitypowered.api.proxy.player.ConnectionRequestBuilder;
import com.velocitypowered.api.proxy.player.PlatformActions;
import com.velocitypowered.api.proxy.player.PlayerIdentity;
import com.velocitypowered.api.proxy.player.TabList;
import com.velocitypowered.api.proxy.player.java.TabList;
import com.velocitypowered.api.proxy.player.java.JavaClientSettings;
import com.velocitypowered.api.proxy.player.java.JavaPlayerIdentity;
import com.velocitypowered.api.proxy.server.RegisteredServer;
@ -55,13 +55,6 @@ public interface Player extends CommandSource, Identified, InboundConnection,
*/
@Nullable ServerConnection connectedServer();
/**
* Returns the player's client settings.
*
* @return the settings
*/
JavaClientSettings clientSettings();
/**
* Returns the player's mod info if they have a modded client.
*
@ -91,13 +84,6 @@ public interface Player extends CommandSource, Identified, InboundConnection,
*/
ConnectionRequestBuilder createConnectionRequest(RegisteredServer server);
/**
* Sets the player's profile properties.
*
* @param properties the properties
*/
void setGameProfileProperties(List<JavaPlayerIdentity.Property> properties);
/**
* Returns the player's identity, which depends on what version of Minecraft they are currently
* playing.
@ -105,13 +91,6 @@ public interface Player extends CommandSource, Identified, InboundConnection,
@Override
@NonNull PlayerIdentity identity();
/**
* Returns the player's tab list.
*
* @return this player's tab list
*/
TabList tabList();
/**
* Disconnects the player with the specified reason. Once this method is called, further calls to
* other {@link Player} methods will become undefined.
@ -127,25 +106,6 @@ public interface Player extends CommandSource, Identified, InboundConnection,
*/
void spoofChatInput(String input);
/**
* Sends the specified resource pack from {@code url} to the user. If at all possible, send the
* resource pack using {@link #sendResourcePack(String, byte[])}. To monitor the status of the
* sent resource pack, subscribe to {@link PlayerResourcePackStatusEvent}.
*
* @param url the URL for the resource pack
*/
void sendResourcePack(String url);
/**
* Sends the specified resource pack from {@code url} to the user, using the specified 20-byte
* SHA-1 hash. To monitor the status of the sent resource pack, subscribe to
* {@link PlayerResourcePackStatusEvent}.
*
* @param url the URL for the resource pack
* @param hash the SHA-1 hash value for the resource pack
*/
void sendResourcePack(String url, byte[] hash);
/**
* <strong>Note that this method does not send a plugin message to the server the player
* is connected to.</strong> You should only use this method if you are trying to communicate

Datei anzeigen

@ -7,11 +7,58 @@
package com.velocitypowered.api.proxy.player;
import com.velocitypowered.api.event.player.PlayerResourcePackStatusEvent;
import com.velocitypowered.api.proxy.player.java.JavaClientSettings;
import com.velocitypowered.api.proxy.player.java.JavaPlayerIdentity.Property;
import com.velocitypowered.api.proxy.player.java.TabList;
import java.util.List;
import org.checkerframework.checker.nullness.qual.Nullable;
/**
* Provides certain actions that may be implemented across platforms (or not at all). Similar to
* Adventure's {@link net.kyori.adventure.audience.Audience}, methods that are not implemented for
* a platform will silently fail.
* a platform will silently fail or return no-op instances as appropriate.
*/
public interface PlatformActions {
/**
* Sets the player's profile properties. This operation is not applicable to Bedrock Edition.
*
* @param properties the properties
*/
void setGameProfileProperties(List<Property> properties);
/**
* Returns the player's client settings as sent by the client, for Java Edition clients only.
*
* @return the settings
*/
@Nullable JavaClientSettings clientSettings();
/**
* Returns the player's tab list, if supported.
*
* @return this player's tab list
*/
TabList tabList();
/**
* Sends the specified resource pack from {@code url} to the user, if supported. If possible,
* send the resource pack using {@link #sendResourcePack(String, byte[])}. To monitor the status
* of the sent resource pack, subscribe to {@link PlayerResourcePackStatusEvent}.
*
* @param url the URL for the resource pack
*/
void sendResourcePack(String url);
/**
* Sends the specified resource pack from {@code url} to the user, if supported, and use the
* 20-byte SHA-1 hash as an unique identifier for this resource oack. To monitor the status of
* the sent resource pack, subscribe to {@link PlayerResourcePackStatusEvent}.
*
* @param url the URL for the resource pack
* @param hash the SHA-1 hash value for the resource pack
*/
void sendResourcePack(String url, byte[] hash);
}

Datei anzeigen

@ -5,17 +5,16 @@
* reference the LICENSE file in the api top-level directory.
*/
package com.velocitypowered.api.proxy.player;
package com.velocitypowered.api.proxy.player.java;
import com.velocitypowered.api.proxy.connection.Player;
import com.velocitypowered.api.proxy.player.java.JavaPlayerIdentity;
import java.util.Collection;
import java.util.UUID;
import net.kyori.adventure.text.Component;
import org.checkerframework.checker.nullness.qual.Nullable;
/**
* Represents the tab list of a {@link Player}.
* Represents the tab list of a {@link Player}, specifically for Java players only.
*/
public interface TabList {

Datei anzeigen

@ -5,14 +5,13 @@
* reference the LICENSE file in the api top-level directory.
*/
package com.velocitypowered.api.proxy.player;
package com.velocitypowered.api.proxy.player.java;
import com.velocitypowered.api.proxy.player.java.JavaPlayerIdentity;
import net.kyori.adventure.text.Component;
import org.checkerframework.checker.nullness.qual.Nullable;
/**
* Represents a single entry in a {@link TabList}.
* Represents a single entry in a {@link TabList}, specifically for Java players only.
*/
public interface TabListEntry {

Datei anzeigen

@ -137,7 +137,15 @@ shadowJar {
exclude 'it/unimi/dsi/fastutil/objects/*Object2Reference*'
exclude 'it/unimi/dsi/fastutil/objects/*Object2Short*'
exclude 'it/unimi/dsi/fastutil/objects/*ObjectRB*'
exclude 'it/unimi/dsi/fastutil/objects/*Reference*'
exclude 'it/unimi/dsi/fastutil/objects/*Reference2Byte*'
exclude 'it/unimi/dsi/fastutil/objects/*Reference2Char*'
exclude 'it/unimi/dsi/fastutil/objects/*Reference2Double*'
exclude 'it/unimi/dsi/fastutil/objects/*Reference2Float*'
exclude 'it/unimi/dsi/fastutil/objects/*Reference2Short*'
exclude 'it/unimi/dsi/fastutil/objects/*Reference2Long*'
exclude 'it/unimi/dsi/fastutil/objects/*Reference2Object*'
exclude 'it/unimi/dsi/fastutil/objects/*Reference2Reference*'
exclude 'it/unimi/dsi/fastutil/objects/*Reference2Boolean*'
exclude 'it/unimi/dsi/fastutil/shorts/**'
exclude 'org/checkerframework/checker/**'

Datei anzeigen

@ -35,7 +35,6 @@ import com.velocitypowered.api.proxy.ProxyServer;
import com.velocitypowered.api.proxy.server.RegisteredServer;
import com.velocitypowered.api.util.ProxyVersion;
import com.velocitypowered.proxy.VelocityServer;
import com.velocitypowered.proxy.util.InformationUtils;
import java.net.ConnectException;
import java.net.UnknownHostException;
import java.nio.charset.StandardCharsets;

Datei anzeigen

@ -27,7 +27,6 @@ import com.google.common.collect.ImmutableMap;
import com.google.gson.annotations.Expose;
import com.velocitypowered.api.proxy.config.ProxyConfig;
import com.velocitypowered.api.util.Favicon;
import com.velocitypowered.proxy.util.AddressUtil;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import java.io.File;
import java.io.IOException;

Datei anzeigen

@ -41,10 +41,9 @@ import com.velocitypowered.proxy.network.java.serialization.brigadier.ArgumentPr
import com.velocitypowered.proxy.network.packet.Packet;
import com.velocitypowered.proxy.network.packet.PacketReader;
import com.velocitypowered.proxy.network.packet.PacketWriter;
import com.velocitypowered.proxy.util.collect.IdentityHashStrategy;
import io.netty.buffer.ByteBuf;
import it.unimi.dsi.fastutil.objects.Object2IntLinkedOpenCustomHashMap;
import it.unimi.dsi.fastutil.objects.Object2IntMap;
import it.unimi.dsi.fastutil.objects.Reference2IntLinkedOpenHashMap;
import it.unimi.dsi.fastutil.objects.Reference2IntMap;
import java.util.ArrayDeque;
import java.util.Arrays;
import java.util.Deque;
@ -118,8 +117,8 @@ public class ClientboundAvailableCommandsPacket implements Packet {
public void encode(ByteBuf buf, ProtocolVersion protocolVersion) {
// Assign all the children an index.
Deque<CommandNode<CommandSource>> childrenQueue = new ArrayDeque<>(ImmutableList.of(rootNode));
Object2IntMap<CommandNode<CommandSource>> idMappings = new Object2IntLinkedOpenCustomHashMap<>(
IdentityHashStrategy.instance());
Reference2IntMap<CommandNode<CommandSource>> idMappings =
new Reference2IntLinkedOpenHashMap<>();
while (!childrenQueue.isEmpty()) {
CommandNode<CommandSource> child = childrenQueue.poll();
if (!idMappings.containsKey(child)) {
@ -137,7 +136,7 @@ public class ClientboundAvailableCommandsPacket implements Packet {
}
private static void serializeNode(CommandNode<CommandSource> node, ByteBuf buf,
Object2IntMap<CommandNode<CommandSource>> idMappings) {
Reference2IntMap<CommandNode<CommandSource>> idMappings) {
byte flags = 0;
if (node.getRedirect() != null) {
flags |= FLAG_IS_REDIRECT;

Datei anzeigen

@ -21,7 +21,7 @@ import com.google.common.base.MoreObjects;
import com.google.common.base.VerifyException;
import com.google.common.collect.ImmutableList;
import com.velocitypowered.api.network.ProtocolVersion;
import com.velocitypowered.api.proxy.player.TabListEntry;
import com.velocitypowered.api.proxy.player.java.TabListEntry;
import com.velocitypowered.api.proxy.player.java.JavaPlayerIdentity;
import com.velocitypowered.proxy.network.ProtocolUtils;
import com.velocitypowered.proxy.network.java.packet.JavaPacketHandler;

Datei anzeigen

@ -25,7 +25,6 @@ import com.velocitypowered.proxy.network.java.packet.JavaPacketHandler;
import com.velocitypowered.proxy.network.packet.Packet;
import com.velocitypowered.proxy.network.packet.PacketReader;
import com.velocitypowered.proxy.network.packet.PacketWriter;
import com.velocitypowered.proxy.util.DurationUtils;
import io.netty.buffer.ByteBuf;
import java.util.Arrays;
import net.kyori.adventure.title.Title;

Datei anzeigen

@ -18,8 +18,8 @@
package com.velocitypowered.proxy.tablist;
import com.google.common.base.Preconditions;
import com.velocitypowered.api.proxy.player.TabList;
import com.velocitypowered.api.proxy.player.TabListEntry;
import com.velocitypowered.api.proxy.player.java.TabList;
import com.velocitypowered.api.proxy.player.java.TabListEntry;
import com.velocitypowered.api.proxy.player.java.JavaPlayerIdentity;
import com.velocitypowered.proxy.connection.MinecraftConnection;
import com.velocitypowered.proxy.connection.client.ConnectedPlayer;

Datei anzeigen

@ -17,8 +17,8 @@
package com.velocitypowered.proxy.tablist;
import com.velocitypowered.api.proxy.player.TabList;
import com.velocitypowered.api.proxy.player.TabListEntry;
import com.velocitypowered.api.proxy.player.java.TabList;
import com.velocitypowered.api.proxy.player.java.TabListEntry;
import com.velocitypowered.api.proxy.player.java.JavaPlayerIdentity;
import com.velocitypowered.proxy.network.java.packet.clientbound.ClientboundPlayerListItemPacket;
import net.kyori.adventure.text.Component;

Datei anzeigen

@ -17,7 +17,7 @@
package com.velocitypowered.proxy.tablist;
import com.velocitypowered.api.proxy.player.TabListEntry;
import com.velocitypowered.api.proxy.player.java.TabListEntry;
import com.velocitypowered.api.proxy.player.java.JavaPlayerIdentity;
import net.kyori.adventure.text.Component;
import org.checkerframework.checker.nullness.qual.Nullable;

Datei anzeigen

@ -18,7 +18,7 @@
package com.velocitypowered.proxy.tablist;
import com.google.common.collect.ImmutableList;
import com.velocitypowered.api.proxy.player.TabListEntry;
import com.velocitypowered.api.proxy.player.java.TabListEntry;
import com.velocitypowered.api.proxy.player.java.JavaPlayerIdentity;
import com.velocitypowered.proxy.connection.client.ConnectedPlayer;
import com.velocitypowered.proxy.network.java.packet.clientbound.ClientboundPlayerListItemPacket;

Datei anzeigen

@ -1,41 +0,0 @@
/*
* Copyright (C) 2018 Velocity 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 com.velocitypowered.proxy.util.collect;
import it.unimi.dsi.fastutil.Hash.Strategy;
public final class IdentityHashStrategy<T> implements Strategy<T> {
@SuppressWarnings("rawtypes")
private static final IdentityHashStrategy INSTANCE = new IdentityHashStrategy();
public static <T> Strategy<T> instance() {
//noinspection unchecked
return INSTANCE;
}
@Override
public int hashCode(T o) {
return System.identityHashCode(o);
}
@Override
public boolean equals(T a, T b) {
return a == b;
}
}