Skip to content
This repository has been archived by the owner on Oct 31, 2024. It is now read-only.

Commit

Permalink
Merge pull request #1 from PaperMC/dev/3.0.0
Browse files Browse the repository at this point in the history
Update with upstream
  • Loading branch information
rexlManu authored Sep 5, 2023
2 parents cf1184c + 19abb90 commit e2f3ef7
Show file tree
Hide file tree
Showing 13 changed files with 53 additions and 193 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public ServerPreConnectEvent(Player player, RegisteredServer originalServer) {
*
* @param player the player who is connecting to a server
* @param originalServer the server the player was trying to connect to
* @param previousServer the server the player ís connected to
* @param previousServer the server the player is connected to
*/
public ServerPreConnectEvent(Player player, RegisteredServer originalServer,
@Nullable RegisteredServer previousServer) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public enum ProtocolVersion {
MINECRAFT_1_19_1(760, "1.19.1", "1.19.2"),
MINECRAFT_1_19_3(761, "1.19.3"),
MINECRAFT_1_19_4(762, "1.19.4"),
MINECRAFT_1_20(763, "1.20");
MINECRAFT_1_20(763, "1.20", "1.20.1");

private static final int SNAPSHOT_BIT = 30;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,28 @@ public interface TabList {
*/
void addEntry(TabListEntry entry);

/**
* Adds a {@link Iterable} of {@link TabListEntry}'s to the {@link Player}'s tab list.
*
* @param entries to add to the tab list
*/
default void addEntries(Iterable<TabListEntry> entries) {
for (TabListEntry entry : entries) {
addEntry(entry);
}
}

/**
* Adds an array of {@link TabListEntry}'s to the {@link Player}'s tab list.
*
* @param entries to add to the tab list
*/
default void addEntries(TabListEntry... entries) {
for (TabListEntry entry : entries) {
addEntry(entry);
}
}

/**
* Removes the {@link TabListEntry} from the tab list with the {@link GameProfile} identified with
* the specified {@link UUID}.
Expand Down
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ shadow = "com.github.johnrengelman.shadow:8.1.0"
spotless = "com.diffplug.spotless:6.12.0"

[libraries]
adventure-bom = "net.kyori:adventure-bom:4.13.1"
adventure-bom = "net.kyori:adventure-bom:4.14.0"
adventure-facet = "net.kyori:adventure-platform-facet:4.3.0"
asm = "org.ow2.asm:asm:9.5"
asynchttpclient = "org.asynchttpclient:async-http-client:2.12.3"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,13 +198,8 @@ public boolean handle(PluginMessage packet) {
return true;
}

// We need to specially handle REGISTER and UNREGISTER packets. Later on, we'll write them to
// the client.
if (PluginMessageUtil.isRegister(packet)) {
serverConn.getPlayer().getKnownChannels().addAll(PluginMessageUtil.getChannels(packet));
return false;
} else if (PluginMessageUtil.isUnregister(packet)) {
serverConn.getPlayer().getKnownChannels().removeAll(PluginMessageUtil.getChannels(packet));
// Register and unregister packets are simply forwarded to the server as-is.
if (PluginMessageUtil.isRegister(packet) || PluginMessageUtil.isUnregister(packet)) {
return false;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
import com.velocitypowered.proxy.protocol.packet.JoinGame;
import com.velocitypowered.proxy.protocol.packet.KeepAlive;
import com.velocitypowered.proxy.protocol.packet.PluginMessage;
import com.velocitypowered.proxy.protocol.util.PluginMessageUtil;
import java.io.IOException;
import java.util.concurrent.CompletableFuture;
import org.apache.logging.log4j.LogManager;
Expand Down Expand Up @@ -180,12 +179,6 @@ public boolean handle(PluginMessage packet) {
return true;
}

if (PluginMessageUtil.isRegister(packet)) {
serverConn.getPlayer().getKnownChannels().addAll(PluginMessageUtil.getChannels(packet));
} else if (PluginMessageUtil.isUnregister(packet)) {
serverConn.getPlayer().getKnownChannels().removeAll(PluginMessageUtil.getChannels(packet));
}

// We always need to handle plugin messages, for Forge compatibility.
if (serverConn.getPhase().handle(serverConn, serverConn.getPlayer(), packet)) {
// Handled, but check the server connection phase.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,6 @@ public void activated() {
if (!channels.isEmpty()) {
PluginMessage register = constructChannelsPacket(player.getProtocolVersion(), channels);
player.getConnection().write(register);
player.getKnownChannels().addAll(channels);
}
}

Expand Down Expand Up @@ -295,7 +294,6 @@ public boolean handle(PluginMessage packet) {
packet.getChannel());
} else if (PluginMessageUtil.isRegister(packet)) {
List<String> channels = PluginMessageUtil.getChannels(packet);
player.getKnownChannels().addAll(channels);
List<ChannelIdentifier> channelIdentifiers = new ArrayList<>();
for (String channel : channels) {
try {
Expand All @@ -309,7 +307,6 @@ public boolean handle(PluginMessage packet) {
new PlayerChannelRegisterEvent(player, ImmutableList.copyOf(channelIdentifiers)));
backendConn.write(packet.retain());
} else if (PluginMessageUtil.isUnregister(packet)) {
player.getKnownChannels().removeAll(PluginMessageUtil.getChannels(packet));
backendConn.write(packet.retain());
} else if (PluginMessageUtil.isMcBrand(packet)) {
String brand = PluginMessageUtil.readBrandMessage(packet.content());
Expand Down Expand Up @@ -485,10 +482,12 @@ public void handleBackendJoinGame(JoinGame joinGame, VelocityServerConnection de
}
serverBossBars.clear();

// Tell the server about this client's plugin message channels.
// Tell the server about the proxy's plugin message channels.
ProtocolVersion serverVersion = serverMc.getProtocolVersion();
if (!player.getKnownChannels().isEmpty()) {
serverMc.delayedWrite(constructChannelsPacket(serverVersion, player.getKnownChannels()));
final Collection<String> channels = server.getChannelRegistrar()
.getChannelsForProtocol(serverMc.getProtocolVersion());
if (!channels.isEmpty()) {
serverMc.delayedWrite(constructChannelsPacket(serverVersion, channels));
}

// If we had plugin messages queued during login/FML handshake, send them now.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,10 @@
import com.velocitypowered.proxy.tablist.VelocityTabListLegacy;
import com.velocitypowered.proxy.util.ClosestLocaleMatcher;
import com.velocitypowered.proxy.util.DurationUtils;
import com.velocitypowered.proxy.util.collect.CappedSet;
import io.netty.buffer.ByteBufUtil;
import io.netty.buffer.Unpooled;
import java.net.InetSocketAddress;
import java.util.ArrayDeque;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Locale;
Expand Down Expand Up @@ -155,7 +153,6 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player,
private final InternalTabList tabList;
private final VelocityServer server;
private ClientConnectionPhase connectionPhase;
private final Collection<String> knownChannels;
private final CompletableFuture<Void> teardownFuture = new CompletableFuture<>();
private @MonotonicNonNull List<String> serversToTry = null;
private @MonotonicNonNull Boolean previousResourceResponse;
Expand Down Expand Up @@ -185,7 +182,6 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player,
this.virtualHost = virtualHost;
this.permissionFunction = PermissionFunction.ALWAYS_UNDEFINED;
this.connectionPhase = connection.getType().getInitialClientPhase();
this.knownChannels = CappedSet.create(MAX_PLUGIN_CHANNELS);
this.onlineMode = onlineMode;

if (connection.getProtocolVersion().compareTo(ProtocolVersion.MINECRAFT_1_19_3) >= 0) {
Expand Down Expand Up @@ -1103,15 +1099,6 @@ public void setPhase(ClientConnectionPhase connectionPhase) {
this.connectionPhase = connectionPhase;
}

/**
* Return all the plugin message channels "known" to the client.
*
* @return the channels
*/
public Collection<String> getKnownChannels() {
return knownChannels;
}

@Override
public @Nullable IdentifiedKey getIdentifiedKey() {
return playerKey;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import com.velocitypowered.proxy.connection.backend.BungeeCordMessageResponder;
import com.velocitypowered.proxy.connection.backend.VelocityServerConnection;
import com.velocitypowered.proxy.protocol.packet.PluginMessage;
import com.velocitypowered.proxy.protocol.util.PluginMessageUtil;
import io.netty.buffer.ByteBufUtil;
import io.netty.buffer.Unpooled;
import org.apache.logging.log4j.LogManager;
Expand Down Expand Up @@ -55,15 +54,7 @@ public boolean handle(PluginMessage packet) {
return true;
}

if (PluginMessageUtil.isRegister(packet)) {
player.getKnownChannels().addAll(PluginMessageUtil.getChannels(packet));
serverConn.ensureConnected().write(packet.retain());
return true;
} else if (PluginMessageUtil.isUnregister(packet)) {
player.getKnownChannels().removeAll(PluginMessageUtil.getChannels(packet));
serverConn.ensureConnected().write(packet.retain());
return true;
} else if (BungeeCordMessageResponder.isBungeeCordMessage(packet)) {
if (BungeeCordMessageResponder.isBungeeCordMessage(packet)) {
return true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,4 +71,8 @@ public ExecutorService getExecutorService() {

return this.service;
}

public boolean hasExecutorService() {
return this.service != null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,12 @@
import com.velocitypowered.api.scheduler.Scheduler;
import com.velocitypowered.api.scheduler.TaskStatus;
import com.velocitypowered.proxy.plugin.loader.VelocityPluginContainer;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashSet;
import java.util.IdentityHashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Optional;
import java.util.Set;
import java.util.concurrent.ExecutionException;
Expand Down Expand Up @@ -116,17 +119,24 @@ public boolean shutdown() throws InterruptedException {
task.cancel();
}
timerExecutionService.shutdown();
for (final PluginContainer container : this.pluginManager.getPlugins()) {
final List<PluginContainer> plugins = new ArrayList<>(this.pluginManager.getPlugins());
final Iterator<PluginContainer> pluginIterator = plugins.iterator();
while (pluginIterator.hasNext()) {
final PluginContainer container = pluginIterator.next();
if (container instanceof VelocityPluginContainer) {
(container).getExecutorService().shutdown();
final VelocityPluginContainer pluginContainer = (VelocityPluginContainer) container;
if (pluginContainer.hasExecutorService()) {
container.getExecutorService().shutdown();
} else {
pluginIterator.remove();
}
} else {
pluginIterator.remove();
}
}

boolean allShutdown = true;
for (final PluginContainer container : this.pluginManager.getPlugins()) {
if (!(container instanceof VelocityPluginContainer)) {
continue;
}
for (final PluginContainer container : plugins) {
final String id = container.getDescription().getId();
final ExecutorService service = (container).getExecutorService();

Expand Down

This file was deleted.

This file was deleted.

0 comments on commit e2f3ef7

Please sign in to comment.