From 3a51bee0522f77442326ea9ca2867d520bed00f0 Mon Sep 17 00:00:00 2001 From: Andrew Steinborn Date: Mon, 1 Mar 2021 19:41:35 -0500 Subject: [PATCH 01/99] Fix Checkstyle errors and update geriatric Checkstyle version --- .../event/player/PlayerChannelRegisterEvent.java | 1 - .../api/proxy/connection/InboundConnection.java | 1 - .../api/proxy/server/ServerPing.java | 1 - .../api/proxy/server/QueryResponseTest.java | 2 +- config/checkstyle/checkstyle.xml | 14 ++++++-------- gradle/checkstyle.gradle | 2 +- .../java/com/velocitypowered/proxy/Metrics.java | 2 -- .../proxy/command/builtin/VelocityCommand.java | 3 --- .../proxy/config/VelocityConfiguration.java | 2 -- .../connection/registry/DimensionRegistry.java | 2 -- .../proxy/network/ProtocolUtils.java | 2 -- .../network/packet/AbstractStatusPingPacket.java | 1 + .../ClientboundStatusResponsePacket.java | 2 +- .../packet/serverbound/ServerboundChatPacket.java | 2 +- .../serverbound/ServerboundServerLoginPacket.java | 5 ++--- .../proxy/plugin/VelocityPluginManager.java | 2 +- .../proxy/util/InformationUtils.java | 1 - 17 files changed, 14 insertions(+), 31 deletions(-) diff --git a/api/src/main/java/com/velocitypowered/api/event/player/PlayerChannelRegisterEvent.java b/api/src/main/java/com/velocitypowered/api/event/player/PlayerChannelRegisterEvent.java index 2672f3632..a65a9c282 100644 --- a/api/src/main/java/com/velocitypowered/api/event/player/PlayerChannelRegisterEvent.java +++ b/api/src/main/java/com/velocitypowered/api/event/player/PlayerChannelRegisterEvent.java @@ -3,7 +3,6 @@ package com.velocitypowered.api.event.player; import com.google.common.base.Preconditions; import com.velocitypowered.api.proxy.connection.Player; import com.velocitypowered.api.proxy.messages.ChannelIdentifier; - import java.util.List; /** diff --git a/api/src/main/java/com/velocitypowered/api/proxy/connection/InboundConnection.java b/api/src/main/java/com/velocitypowered/api/proxy/connection/InboundConnection.java index ec0bda8fe..519e609a4 100644 --- a/api/src/main/java/com/velocitypowered/api/proxy/connection/InboundConnection.java +++ b/api/src/main/java/com/velocitypowered/api/proxy/connection/InboundConnection.java @@ -1,7 +1,6 @@ package com.velocitypowered.api.proxy.connection; import com.velocitypowered.api.network.ProtocolVersion; - import java.net.InetSocketAddress; import java.net.SocketAddress; import java.util.Optional; diff --git a/api/src/main/java/com/velocitypowered/api/proxy/server/ServerPing.java b/api/src/main/java/com/velocitypowered/api/proxy/server/ServerPing.java index 8b2f0b0dd..45cc733df 100644 --- a/api/src/main/java/com/velocitypowered/api/proxy/server/ServerPing.java +++ b/api/src/main/java/com/velocitypowered/api/proxy/server/ServerPing.java @@ -11,7 +11,6 @@ import java.util.List; import java.util.Objects; import java.util.Optional; import java.util.UUID; - import net.kyori.adventure.text.Component; import org.checkerframework.checker.nullness.qual.Nullable; diff --git a/api/src/test/java/com/velocitypowered/api/proxy/server/QueryResponseTest.java b/api/src/test/java/com/velocitypowered/api/proxy/server/QueryResponseTest.java index c7222a06f..64416d1d7 100644 --- a/api/src/test/java/com/velocitypowered/api/proxy/server/QueryResponseTest.java +++ b/api/src/test/java/com/velocitypowered/api/proxy/server/QueryResponseTest.java @@ -13,7 +13,7 @@ class QueryResponseTest { QueryResponse response = new QueryResponse("test", "test", "test", 1, 2, "test", 1234, ImmutableList.of("tuxed"), "0.0.1", ImmutableList.of(new PluginInformation("test", "1.0.0"), - new PluginInformation("test2", null))); + new PluginInformation("test2", null))); assertEquals(response, response.toBuilder().build()); } } \ No newline at end of file diff --git a/config/checkstyle/checkstyle.xml b/config/checkstyle/checkstyle.xml index 31cc2ea7c..f419cca1f 100644 --- a/config/checkstyle/checkstyle.xml +++ b/config/checkstyle/checkstyle.xml @@ -31,6 +31,12 @@ + + + + + + diff --git a/proxy/src/test/java/com/velocitypowered/proxy/command/CommandManagerTests.java b/proxy/src/test/java/com/velocitypowered/proxy/command/CommandManagerTests.java index ae8fa8343..b9b40cc35 100644 --- a/proxy/src/test/java/com/velocitypowered/proxy/command/CommandManagerTests.java +++ b/proxy/src/test/java/com/velocitypowered/proxy/command/CommandManagerTests.java @@ -1,3 +1,20 @@ +/* + * 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 . + */ + package com.velocitypowered.proxy.command; import static org.junit.jupiter.api.Assertions.assertArrayEquals; diff --git a/proxy/src/test/java/com/velocitypowered/proxy/command/MockCommandSource.java b/proxy/src/test/java/com/velocitypowered/proxy/command/MockCommandSource.java index c6dad95f5..bd2cbd359 100644 --- a/proxy/src/test/java/com/velocitypowered/proxy/command/MockCommandSource.java +++ b/proxy/src/test/java/com/velocitypowered/proxy/command/MockCommandSource.java @@ -1,3 +1,20 @@ +/* + * 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 . + */ + package com.velocitypowered.proxy.command; import com.velocitypowered.api.command.CommandSource; diff --git a/proxy/src/test/java/com/velocitypowered/proxy/connection/client/HandshakeSessionHandlerTest.java b/proxy/src/test/java/com/velocitypowered/proxy/connection/client/HandshakeSessionHandlerTest.java index c89fc9b87..4a8af8228 100644 --- a/proxy/src/test/java/com/velocitypowered/proxy/connection/client/HandshakeSessionHandlerTest.java +++ b/proxy/src/test/java/com/velocitypowered/proxy/connection/client/HandshakeSessionHandlerTest.java @@ -1,3 +1,20 @@ +/* + * 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 . + */ + package com.velocitypowered.proxy.connection.client; import static com.velocitypowered.proxy.connection.client.HandshakeSessionHandler.cleanVhost; diff --git a/proxy/src/test/java/com/velocitypowered/proxy/plugin/MockEventManager.java b/proxy/src/test/java/com/velocitypowered/proxy/plugin/MockEventManager.java index 20be3a079..e882e7d20 100644 --- a/proxy/src/test/java/com/velocitypowered/proxy/plugin/MockEventManager.java +++ b/proxy/src/test/java/com/velocitypowered/proxy/plugin/MockEventManager.java @@ -1,3 +1,20 @@ +/* + * 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 . + */ + package com.velocitypowered.proxy.plugin; /** diff --git a/proxy/src/test/java/com/velocitypowered/proxy/plugin/MockPluginManager.java b/proxy/src/test/java/com/velocitypowered/proxy/plugin/MockPluginManager.java index 170c0cdb6..33864a168 100644 --- a/proxy/src/test/java/com/velocitypowered/proxy/plugin/MockPluginManager.java +++ b/proxy/src/test/java/com/velocitypowered/proxy/plugin/MockPluginManager.java @@ -1,3 +1,20 @@ +/* + * 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 . + */ + package com.velocitypowered.proxy.plugin; import com.google.common.collect.ImmutableList; diff --git a/proxy/src/test/java/com/velocitypowered/proxy/plugin/util/PluginDependencyUtilsTest.java b/proxy/src/test/java/com/velocitypowered/proxy/plugin/util/PluginDependencyUtilsTest.java index 0a2901360..aff2ae73f 100644 --- a/proxy/src/test/java/com/velocitypowered/proxy/plugin/util/PluginDependencyUtilsTest.java +++ b/proxy/src/test/java/com/velocitypowered/proxy/plugin/util/PluginDependencyUtilsTest.java @@ -1,3 +1,20 @@ +/* + * 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 . + */ + package com.velocitypowered.proxy.plugin.util; import static org.junit.jupiter.api.Assertions.assertEquals; diff --git a/proxy/src/test/java/com/velocitypowered/proxy/protocol/PacketRegistryTest.java b/proxy/src/test/java/com/velocitypowered/proxy/protocol/PacketRegistryTest.java index e1c40091a..1780d14ac 100644 --- a/proxy/src/test/java/com/velocitypowered/proxy/protocol/PacketRegistryTest.java +++ b/proxy/src/test/java/com/velocitypowered/proxy/protocol/PacketRegistryTest.java @@ -1,3 +1,20 @@ +/* + * 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 . + */ + package com.velocitypowered.proxy.protocol; import static com.google.common.collect.Iterables.getLast; diff --git a/proxy/src/test/java/com/velocitypowered/proxy/protocol/util/PluginMessageUtilTest.java b/proxy/src/test/java/com/velocitypowered/proxy/protocol/util/PluginMessageUtilTest.java index 2c4b162d9..ef40511dc 100644 --- a/proxy/src/test/java/com/velocitypowered/proxy/protocol/util/PluginMessageUtilTest.java +++ b/proxy/src/test/java/com/velocitypowered/proxy/protocol/util/PluginMessageUtilTest.java @@ -1,3 +1,20 @@ +/* + * 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 . + */ + package com.velocitypowered.proxy.protocol.util; import static org.junit.jupiter.api.Assertions.assertEquals; diff --git a/proxy/src/test/java/com/velocitypowered/proxy/scheduler/VelocitySchedulerTest.java b/proxy/src/test/java/com/velocitypowered/proxy/scheduler/VelocitySchedulerTest.java index 2afc90830..a7e565cd8 100644 --- a/proxy/src/test/java/com/velocitypowered/proxy/scheduler/VelocitySchedulerTest.java +++ b/proxy/src/test/java/com/velocitypowered/proxy/scheduler/VelocitySchedulerTest.java @@ -1,3 +1,20 @@ +/* + * 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 . + */ + package com.velocitypowered.proxy.scheduler; import static org.junit.jupiter.api.Assertions.assertEquals; diff --git a/proxy/src/test/java/com/velocitypowered/proxy/testutil/FakePluginManager.java b/proxy/src/test/java/com/velocitypowered/proxy/testutil/FakePluginManager.java index 1aedeeaab..64a64f4c4 100644 --- a/proxy/src/test/java/com/velocitypowered/proxy/testutil/FakePluginManager.java +++ b/proxy/src/test/java/com/velocitypowered/proxy/testutil/FakePluginManager.java @@ -1,3 +1,20 @@ +/* + * 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 . + */ + package com.velocitypowered.proxy.testutil; import com.google.common.collect.ImmutableList; diff --git a/proxy/src/test/java/com/velocitypowered/proxy/util/EncryptionUtilsTest.java b/proxy/src/test/java/com/velocitypowered/proxy/util/EncryptionUtilsTest.java index f6229a018..7aa347796 100644 --- a/proxy/src/test/java/com/velocitypowered/proxy/util/EncryptionUtilsTest.java +++ b/proxy/src/test/java/com/velocitypowered/proxy/util/EncryptionUtilsTest.java @@ -1,3 +1,20 @@ +/* + * 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 . + */ + package com.velocitypowered.proxy.util; import static org.junit.jupiter.api.Assertions.assertEquals; diff --git a/proxy/src/test/java/com/velocitypowered/proxy/util/ServerMapTest.java b/proxy/src/test/java/com/velocitypowered/proxy/util/ServerMapTest.java index 7c67b48bf..ad1206702 100644 --- a/proxy/src/test/java/com/velocitypowered/proxy/util/ServerMapTest.java +++ b/proxy/src/test/java/com/velocitypowered/proxy/util/ServerMapTest.java @@ -1,3 +1,20 @@ +/* + * 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 . + */ + package com.velocitypowered.proxy.util; import static org.junit.jupiter.api.Assertions.assertEquals; diff --git a/proxy/src/test/java/com/velocitypowered/proxy/util/VelocityChannelRegistrarTest.java b/proxy/src/test/java/com/velocitypowered/proxy/util/VelocityChannelRegistrarTest.java index 40af50794..2e92217c6 100644 --- a/proxy/src/test/java/com/velocitypowered/proxy/util/VelocityChannelRegistrarTest.java +++ b/proxy/src/test/java/com/velocitypowered/proxy/util/VelocityChannelRegistrarTest.java @@ -1,3 +1,20 @@ +/* + * 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 . + */ + package com.velocitypowered.proxy.util; import static org.junit.jupiter.api.Assertions.assertEquals; diff --git a/proxy/src/test/java/com/velocitypowered/proxy/util/collect/CappedSetTest.java b/proxy/src/test/java/com/velocitypowered/proxy/util/collect/CappedSetTest.java index 11df2237d..73943be90 100644 --- a/proxy/src/test/java/com/velocitypowered/proxy/util/collect/CappedSetTest.java +++ b/proxy/src/test/java/com/velocitypowered/proxy/util/collect/CappedSetTest.java @@ -1,3 +1,20 @@ +/* + * 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 . + */ + package com.velocitypowered.proxy.util.collect; import static org.junit.jupiter.api.Assertions.assertEquals; diff --git a/proxy/src/test/java/com/velocitypowered/proxy/util/concurrent/OnceTest.java b/proxy/src/test/java/com/velocitypowered/proxy/util/concurrent/OnceTest.java index f84b81159..aeb7ffb50 100644 --- a/proxy/src/test/java/com/velocitypowered/proxy/util/concurrent/OnceTest.java +++ b/proxy/src/test/java/com/velocitypowered/proxy/util/concurrent/OnceTest.java @@ -1,3 +1,20 @@ +/* + * 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 . + */ + package com.velocitypowered.proxy.util.concurrent; import static org.junit.jupiter.api.Assertions.assertEquals; diff --git a/proxy/src/test/java/com/velocitypowered/proxy/util/ratelimit/GuavaCacheRatelimiterTest.java b/proxy/src/test/java/com/velocitypowered/proxy/util/ratelimit/GuavaCacheRatelimiterTest.java index 3ebb8db0f..39f50e7f2 100644 --- a/proxy/src/test/java/com/velocitypowered/proxy/util/ratelimit/GuavaCacheRatelimiterTest.java +++ b/proxy/src/test/java/com/velocitypowered/proxy/util/ratelimit/GuavaCacheRatelimiterTest.java @@ -1,3 +1,20 @@ +/* + * 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 . + */ + package com.velocitypowered.proxy.util.ratelimit; import static org.junit.jupiter.api.Assertions.assertFalse; From be21ac5a30491d2e28655301fac9b199cdd3f912 Mon Sep 17 00:00:00 2001 From: Andrew Steinborn Date: Wed, 31 Mar 2021 20:36:08 -0400 Subject: [PATCH 16/99] [ci-skip] Update license in README --- README.md | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 4b35a9a02..f665aaa5f 100644 --- a/README.md +++ b/README.md @@ -6,8 +6,7 @@ A Minecraft server proxy with unparalleled server support, scalability, and flexibility. -Velocity is licensed under the MIT license for ultimate permissiveness -and expanding the pool of potential contributors and users. +Velocity is licensed under the GPLv3 license. ## Goals @@ -34,4 +33,4 @@ Once you've built Velocity, you can copy and run the `-all` JAR from and you can configure it from there. Alternatively, you can get the proxy JAR from the [downloads](https://www.velocitypowered.com/downloads) -page. \ No newline at end of file +page. From 7ba231850692a5492dce5f5537543a400f1e330c Mon Sep 17 00:00:00 2001 From: A248 Date: Fri, 2 Apr 2021 01:45:58 -0400 Subject: [PATCH 17/99] Fix one more case of a possibly swallowed exception (#455) Maybe spotbugs will add a rule for this in the future --- .../connection/client/LoginSessionHandler.java | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/proxy/src/main/java/com/velocitypowered/proxy/connection/client/LoginSessionHandler.java b/proxy/src/main/java/com/velocitypowered/proxy/connection/client/LoginSessionHandler.java index 230d50d56..c1967e858 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/connection/client/LoginSessionHandler.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/connection/client/LoginSessionHandler.java @@ -309,7 +309,11 @@ public class LoginSessionHandler implements MinecraftSessionHandler { mcConnection.setSessionHandler(new InitialConnectSessionHandler(player)); server.getEventManager().fire(new PostLoginEvent(player)) - .thenRun(() -> connectToInitialServer(player)); + .thenCompose((ignored) -> connectToInitialServer(player)) + .exceptionally((ex) -> { + logger.error("Exception while connecting {} to initial server", player, ex); + return null; + }); } }, mcConnection.eventLoop()) .exceptionally((ex) -> { @@ -318,12 +322,12 @@ public class LoginSessionHandler implements MinecraftSessionHandler { }); } - private void connectToInitialServer(ConnectedPlayer player) { + private CompletableFuture connectToInitialServer(ConnectedPlayer player) { Optional initialFromConfig = player.getNextServerToTry(); PlayerChooseInitialServerEvent event = new PlayerChooseInitialServerEvent(player, initialFromConfig.orElse(null)); - server.getEventManager().fire(event) + return server.getEventManager().fire(event) .thenRunAsync(() -> { Optional toTry = event.getInitialServer(); if (!toTry.isPresent()) { @@ -332,11 +336,7 @@ public class LoginSessionHandler implements MinecraftSessionHandler { return; } player.createConnectionRequest(toTry.get()).fireAndForget(); - }, mcConnection.eventLoop()) - .exceptionally((ex) -> { - logger.error("Exception while connecting {} to initial server", player, ex); - return null; - }); + }, mcConnection.eventLoop()); } @Override From 54474d710099fa9352e288a579b84f733a75cd93 Mon Sep 17 00:00:00 2001 From: A248 Date: Fri, 2 Apr 2021 01:51:54 -0400 Subject: [PATCH 18/99] Add Duration methods to TaskBuilder (#445) --- .../api/scheduler/Scheduler.java | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/api/src/main/java/com/velocitypowered/api/scheduler/Scheduler.java b/api/src/main/java/com/velocitypowered/api/scheduler/Scheduler.java index 1ff2b8afa..f59324d65 100644 --- a/api/src/main/java/com/velocitypowered/api/scheduler/Scheduler.java +++ b/api/src/main/java/com/velocitypowered/api/scheduler/Scheduler.java @@ -7,6 +7,7 @@ package com.velocitypowered.api.scheduler; +import java.time.Duration; import java.util.concurrent.TimeUnit; import org.checkerframework.common.value.qual.IntRange; @@ -38,6 +39,16 @@ public interface Scheduler { */ TaskBuilder delay(@IntRange(from = 0) long time, TimeUnit unit); + /** + * Specifies that the task should delay its execution by the specified amount of time. + * + * @param duration the duration of the delay + * @return this builder, for chaining + */ + default TaskBuilder delay(Duration duration) { + return delay(duration.toMillis(), TimeUnit.MILLISECONDS); + } + /** * Specifies that the task should continue running after waiting for the specified amount, until * it is cancelled. @@ -48,6 +59,17 @@ public interface Scheduler { */ TaskBuilder repeat(@IntRange(from = 0) long time, TimeUnit unit); + /** + * Specifies that the task should continue running after waiting for the specified amount, until + * it is cancelled. + * + * @param duration the duration of the delay + * @return this builder, for chaining + */ + default TaskBuilder repeat(Duration duration) { + return repeat(duration.toMillis(), TimeUnit.MILLISECONDS); + } + /** * Clears the delay on this task. * From c34aee76aec2f70be546aee0181f69cc6ea9dc01 Mon Sep 17 00:00:00 2001 From: Rocco Date: Fri, 2 Apr 2021 18:36:32 +0200 Subject: [PATCH 19/99] Fix Forge/Client Proxy Connections mismatch in config (#456) --- .../com/velocitypowered/proxy/config/VelocityConfiguration.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/proxy/src/main/java/com/velocitypowered/proxy/config/VelocityConfiguration.java b/proxy/src/main/java/com/velocitypowered/proxy/config/VelocityConfiguration.java index 95792ded4..12d1e9511 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/config/VelocityConfiguration.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/config/VelocityConfiguration.java @@ -482,8 +482,8 @@ public class VelocityConfiguration implements ProxyConfig { motd, maxPlayers, onlineMode, - announceForge, preventClientProxyConnections, + announceForge, forwardingMode, forwardingSecret, kickExisting, From 5ea6728d1a780186a98841d59b88867debf864fa Mon Sep 17 00:00:00 2001 From: Cubxity Date: Fri, 2 Apr 2021 17:24:45 +0000 Subject: [PATCH 20/99] Added ListenerBoundEvent and ListenerCloseEvent. (#454) --- .../api/event/proxy/ListenerBoundEvent.java | 42 ++++++++++++++++++ .../api/event/proxy/ListenerCloseEvent.java | 42 ++++++++++++++++++ .../api/network/ListenerType.java | 27 ++++++++++++ .../proxy/network/ConnectionManager.java | 39 ++++++++++++++--- .../proxy/network/Endpoint.java | 43 +++++++++++++++++++ 5 files changed, 186 insertions(+), 7 deletions(-) create mode 100644 api/src/main/java/com/velocitypowered/api/event/proxy/ListenerBoundEvent.java create mode 100644 api/src/main/java/com/velocitypowered/api/event/proxy/ListenerCloseEvent.java create mode 100644 api/src/main/java/com/velocitypowered/api/network/ListenerType.java create mode 100644 proxy/src/main/java/com/velocitypowered/proxy/network/Endpoint.java diff --git a/api/src/main/java/com/velocitypowered/api/event/proxy/ListenerBoundEvent.java b/api/src/main/java/com/velocitypowered/api/event/proxy/ListenerBoundEvent.java new file mode 100644 index 000000000..464b85f12 --- /dev/null +++ b/api/src/main/java/com/velocitypowered/api/event/proxy/ListenerBoundEvent.java @@ -0,0 +1,42 @@ +/* + * Copyright (C) 2018 Velocity Contributors + * + * The Velocity API is licensed under the terms of the MIT License. For more details, + * reference the LICENSE file in the api top-level directory. + */ + +package com.velocitypowered.api.event.proxy; + +import com.google.common.base.Preconditions; +import com.velocitypowered.api.network.ListenerType; +import java.net.InetSocketAddress; + +/** + * This event is fired by the proxy after a listener starts accepting connections. + */ +public final class ListenerBoundEvent { + + private final InetSocketAddress address; + private final ListenerType listenerType; + + public ListenerBoundEvent(InetSocketAddress address, ListenerType listenerType) { + this.address = Preconditions.checkNotNull(address, "address"); + this.listenerType = Preconditions.checkNotNull(listenerType, "listenerType"); + } + + public InetSocketAddress getAddress() { + return address; + } + + public ListenerType getListenerType() { + return listenerType; + } + + @Override + public String toString() { + return "ListenerBoundEvent{" + + "address=" + address + + ", listenerType=" + listenerType + + '}'; + } +} diff --git a/api/src/main/java/com/velocitypowered/api/event/proxy/ListenerCloseEvent.java b/api/src/main/java/com/velocitypowered/api/event/proxy/ListenerCloseEvent.java new file mode 100644 index 000000000..9cfe28d77 --- /dev/null +++ b/api/src/main/java/com/velocitypowered/api/event/proxy/ListenerCloseEvent.java @@ -0,0 +1,42 @@ +/* + * Copyright (C) 2018 Velocity Contributors + * + * The Velocity API is licensed under the terms of the MIT License. For more details, + * reference the LICENSE file in the api top-level directory. + */ + +package com.velocitypowered.api.event.proxy; + +import com.google.common.base.Preconditions; +import com.velocitypowered.api.network.ListenerType; +import java.net.InetSocketAddress; + +/** + * This event is fired by the proxy before the proxy stops accepting connections. + */ +public final class ListenerCloseEvent { + + private final InetSocketAddress address; + private final ListenerType listenerType; + + public ListenerCloseEvent(InetSocketAddress address, ListenerType listenerType) { + this.address = Preconditions.checkNotNull(address, "address"); + this.listenerType = Preconditions.checkNotNull(listenerType, "listenerType"); + } + + public InetSocketAddress getAddress() { + return address; + } + + public ListenerType getListenerType() { + return listenerType; + } + + @Override + public String toString() { + return "ListenerCloseEvent{" + + "address=" + address + + ", listenerType=" + listenerType + + '}'; + } +} diff --git a/api/src/main/java/com/velocitypowered/api/network/ListenerType.java b/api/src/main/java/com/velocitypowered/api/network/ListenerType.java new file mode 100644 index 000000000..e0c901307 --- /dev/null +++ b/api/src/main/java/com/velocitypowered/api/network/ListenerType.java @@ -0,0 +1,27 @@ +/* + * Copyright (C) 2018 Velocity Contributors + * + * The Velocity API is licensed under the terms of the MIT License. For more details, + * reference the LICENSE file in the api top-level directory. + */ + +package com.velocitypowered.api.network; + +/** + * Represents each listener type. + */ +public enum ListenerType { + MINECRAFT("Minecraft"), + QUERY("Query"); + + final String name; + + ListenerType(final String name) { + this.name = name; + } + + @Override + public String toString() { + return this.name; + } +} diff --git a/proxy/src/main/java/com/velocitypowered/proxy/network/ConnectionManager.java b/proxy/src/main/java/com/velocitypowered/proxy/network/ConnectionManager.java index 9a402162a..9bf9e78b0 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/network/ConnectionManager.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/network/ConnectionManager.java @@ -21,6 +21,9 @@ import static org.asynchttpclient.Dsl.asyncHttpClient; import static org.asynchttpclient.Dsl.config; import com.google.common.base.Preconditions; +import com.velocitypowered.api.event.proxy.ListenerBoundEvent; +import com.velocitypowered.api.event.proxy.ListenerCloseEvent; +import com.velocitypowered.api.network.ListenerType; import com.velocitypowered.natives.util.Natives; import com.velocitypowered.proxy.VelocityServer; import com.velocitypowered.proxy.network.netty.SeparatePoolInetNameResolver; @@ -51,7 +54,7 @@ public final class ConnectionManager { private static final WriteBufferWaterMark SERVER_WRITE_MARK = new WriteBufferWaterMark(1 << 20, 1 << 21); private static final Logger LOGGER = LogManager.getLogger(ConnectionManager.class); - private final Map endpoints = new HashMap<>(); + private final Map endpoints = new HashMap<>(); private final TransportType transportType; private final EventLoopGroup bossGroup; private final EventLoopGroup workerGroup; @@ -125,8 +128,12 @@ public final class ConnectionManager { .addListener((ChannelFutureListener) future -> { final Channel channel = future.channel(); if (future.isSuccess()) { - this.endpoints.put(address, channel); + this.endpoints.put(address, new Endpoint(channel, ListenerType.MINECRAFT)); LOGGER.info("Listening on {}", channel.localAddress()); + + // Fire the proxy bound event after the socket is bound + server.getEventManager().fireAndForget( + new ListenerBoundEvent(address, ListenerType.MINECRAFT)); } else { LOGGER.error("Can't bind to {}", address, future.cause()); } @@ -150,8 +157,12 @@ public final class ConnectionManager { .addListener((ChannelFutureListener) future -> { final Channel channel = future.channel(); if (future.isSuccess()) { - this.endpoints.put(address, channel); + this.endpoints.put(address, new Endpoint(channel, ListenerType.QUERY)); LOGGER.info("Listening for GS4 query on {}", channel.localAddress()); + + // Fire the proxy bound event after the socket is bound + server.getEventManager().fireAndForget( + new ListenerBoundEvent(address, ListenerType.QUERY)); } else { LOGGER.error("Can't bind to {}", bootstrap.config().localAddress(), future.cause()); } @@ -185,7 +196,14 @@ public final class ConnectionManager { * @param oldBind the endpoint to close */ public void close(InetSocketAddress oldBind) { - Channel serverChannel = endpoints.remove(oldBind); + Endpoint endpoint = endpoints.remove(oldBind); + + // Fire proxy close event to notify plugins of socket close. We block since plugins + // should have a chance to be notified before the server stops accepting connections. + server.getEventManager().fire(new ListenerCloseEvent(oldBind, endpoint.getType())).join(); + + Channel serverChannel = endpoint.getChannel(); + Preconditions.checkState(serverChannel != null, "Endpoint %s not registered", oldBind); LOGGER.info("Closing endpoint {}", serverChannel.localAddress()); serverChannel.close().syncUninterruptibly(); @@ -195,10 +213,17 @@ public final class ConnectionManager { * Closes all endpoints. */ public void shutdown() { - for (final Channel endpoint : this.endpoints.values()) { + for (final Map.Entry entry : this.endpoints.entrySet()) { + final InetSocketAddress address = entry.getKey(); + final Endpoint endpoint = entry.getValue(); + + // Fire proxy close event to notify plugins of socket close. We block since plugins + // should have a chance to be notified before the server stops accepting connections. + server.getEventManager().fire(new ListenerCloseEvent(address, endpoint.getType())).join(); + try { - LOGGER.info("Closing endpoint {}", endpoint.localAddress()); - endpoint.close().sync(); + LOGGER.info("Closing endpoint {}", address); + endpoint.getChannel().close().sync(); } catch (final InterruptedException e) { LOGGER.info("Interrupted whilst closing endpoint", e); Thread.currentThread().interrupt(); diff --git a/proxy/src/main/java/com/velocitypowered/proxy/network/Endpoint.java b/proxy/src/main/java/com/velocitypowered/proxy/network/Endpoint.java new file mode 100644 index 000000000..af453e636 --- /dev/null +++ b/proxy/src/main/java/com/velocitypowered/proxy/network/Endpoint.java @@ -0,0 +1,43 @@ +/* + * 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 . + */ + +package com.velocitypowered.proxy.network; + +import com.google.common.base.Preconditions; +import com.velocitypowered.api.network.ListenerType; +import io.netty.channel.Channel; + +/** + * Represents a listener endpoint. + */ +public final class Endpoint { + private final Channel channel; + private final ListenerType type; + + public Endpoint(Channel channel, ListenerType type) { + this.channel = Preconditions.checkNotNull(channel, "channel"); + this.type = Preconditions.checkNotNull(type, "type"); + } + + public Channel getChannel() { + return channel; + } + + public ListenerType getType() { + return type; + } +} From 4de71fe9426038ca7d0570c5968157c3a7a9cbad Mon Sep 17 00:00:00 2001 From: Andrew Steinborn Date: Thu, 15 Apr 2021 04:22:44 -0400 Subject: [PATCH 21/99] Fix color and overlay packets for Adventure boss bar Someone discovered this bug but decided not to tell anyone. For the record, I'm the one who was brain-damaged... well, I made that particular copy-paste error. --- .../proxy/util/bossbar/AdventureBossBarManager.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/proxy/src/main/java/com/velocitypowered/proxy/util/bossbar/AdventureBossBarManager.java b/proxy/src/main/java/com/velocitypowered/proxy/util/bossbar/AdventureBossBarManager.java index 3ff17998d..3136169dd 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/util/bossbar/AdventureBossBarManager.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/util/bossbar/AdventureBossBarManager.java @@ -234,8 +234,9 @@ public class AdventureBossBarManager implements BossBar.Listener { com.velocitypowered.proxy.protocol.packet.BossBar packet = new com.velocitypowered .proxy.protocol.packet.BossBar(); packet.setUuid(this.id); - packet.setAction(com.velocitypowered.proxy.protocol.packet.BossBar.UPDATE_NAME); + packet.setAction(com.velocitypowered.proxy.protocol.packet.BossBar.UPDATE_STYLE); packet.setColor(COLORS_TO_PROTOCOL.get(color)); + packet.setOverlay(OVERLAY_TO_PROTOCOL.get(bar.overlay())); packet.setFlags(serializeFlags(bar.flags())); return packet; } @@ -268,7 +269,8 @@ public class AdventureBossBarManager implements BossBar.Listener { com.velocitypowered.proxy.protocol.packet.BossBar packet = new com.velocitypowered .proxy.protocol.packet.BossBar(); packet.setUuid(this.id); - packet.setAction(com.velocitypowered.proxy.protocol.packet.BossBar.UPDATE_PROPERTIES); + packet.setAction(com.velocitypowered.proxy.protocol.packet.BossBar.UPDATE_STYLE); + packet.setColor(COLORS_TO_PROTOCOL.get(bar.color())); packet.setOverlay(OVERLAY_TO_PROTOCOL.get(overlay)); return packet; } From c51359e8930f049aa80c4ca9ed530fde3eac2213 Mon Sep 17 00:00:00 2001 From: Andrew Steinborn Date: Thu, 15 Apr 2021 04:23:59 -0400 Subject: [PATCH 22/99] Move away from deprecated percent() method. Also fixed another small nit. --- .../proxy/util/bossbar/AdventureBossBarManager.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/proxy/src/main/java/com/velocitypowered/proxy/util/bossbar/AdventureBossBarManager.java b/proxy/src/main/java/com/velocitypowered/proxy/util/bossbar/AdventureBossBarManager.java index 3136169dd..cf5e285f0 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/util/bossbar/AdventureBossBarManager.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/util/bossbar/AdventureBossBarManager.java @@ -215,8 +215,8 @@ public class AdventureBossBarManager implements BossBar.Listener { packet.setAction(com.velocitypowered.proxy.protocol.packet.BossBar.ADD); packet.setName(ProtocolUtils.getJsonChatSerializer(version).serialize(bar.name())); packet.setColor(COLORS_TO_PROTOCOL.get(bar.color())); - packet.setOverlay(bar.overlay().ordinal()); - packet.setPercent(bar.percent()); + packet.setOverlay(OVERLAY_TO_PROTOCOL.get(bar.overlay())); + packet.setPercent(bar.progress()); packet.setFlags(serializeFlags(bar.flags())); return packet; } From f1cb3eb1a28bc5003d8dd844b5cdf990970ab89d Mon Sep 17 00:00:00 2001 From: Andrew Steinborn Date: Thu, 15 Apr 2021 22:56:37 -0400 Subject: [PATCH 23/99] Move timeout handler to after frame decoder Mitigates attacks like the one described in SpigotMC/BungeeCord#3066. This cannot be considered a full protection, only a mitigation that expects full packets. The attack described is essentially the infamous Slowloris attack. --- .../proxy/network/BackendChannelInitializer.java | 2 +- .../proxy/network/ServerChannelInitializer.java | 4 ++-- .../proxy/server/VelocityRegisteredServer.java | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/proxy/src/main/java/com/velocitypowered/proxy/network/BackendChannelInitializer.java b/proxy/src/main/java/com/velocitypowered/proxy/network/BackendChannelInitializer.java index a862ddf74..0e41fd68a 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/network/BackendChannelInitializer.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/network/BackendChannelInitializer.java @@ -48,10 +48,10 @@ public class BackendChannelInitializer extends ChannelInitializer { @Override protected void initChannel(Channel ch) throws Exception { ch.pipeline() + .addLast(FRAME_DECODER, new MinecraftVarintFrameDecoder()) .addLast(READ_TIMEOUT, new ReadTimeoutHandler(server.getConfiguration().getReadTimeout(), TimeUnit.MILLISECONDS)) - .addLast(FRAME_DECODER, new MinecraftVarintFrameDecoder()) .addLast(FRAME_ENCODER, MinecraftVarintLengthEncoder.INSTANCE) .addLast(MINECRAFT_DECODER, new MinecraftDecoder(ProtocolUtils.Direction.CLIENTBOUND)) diff --git a/proxy/src/main/java/com/velocitypowered/proxy/network/ServerChannelInitializer.java b/proxy/src/main/java/com/velocitypowered/proxy/network/ServerChannelInitializer.java index 2c27b3fb1..55f7d6f88 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/network/ServerChannelInitializer.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/network/ServerChannelInitializer.java @@ -53,11 +53,11 @@ public class ServerChannelInitializer extends ChannelInitializer { @Override protected void initChannel(final Channel ch) { ch.pipeline() + .addLast(LEGACY_PING_DECODER, new LegacyPingDecoder()) + .addLast(FRAME_DECODER, new MinecraftVarintFrameDecoder()) .addLast(READ_TIMEOUT, new ReadTimeoutHandler(this.server.getConfiguration().getReadTimeout(), TimeUnit.MILLISECONDS)) - .addLast(LEGACY_PING_DECODER, new LegacyPingDecoder()) - .addLast(FRAME_DECODER, new MinecraftVarintFrameDecoder()) .addLast(LEGACY_PING_ENCODER, LegacyPingEncoder.INSTANCE) .addLast(FRAME_ENCODER, MinecraftVarintLengthEncoder.INSTANCE) .addLast(MINECRAFT_DECODER, new MinecraftDecoder(ProtocolUtils.Direction.SERVERBOUND)) diff --git a/proxy/src/main/java/com/velocitypowered/proxy/server/VelocityRegisteredServer.java b/proxy/src/main/java/com/velocitypowered/proxy/server/VelocityRegisteredServer.java index fd1c6176a..af49cf1e2 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/server/VelocityRegisteredServer.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/server/VelocityRegisteredServer.java @@ -102,10 +102,10 @@ public class VelocityRegisteredServer implements RegisteredServer, ForwardingAud @Override protected void initChannel(Channel ch) throws Exception { ch.pipeline() + .addLast(FRAME_DECODER, new MinecraftVarintFrameDecoder()) .addLast(READ_TIMEOUT, new ReadTimeoutHandler(server.getConfiguration().getReadTimeout(), TimeUnit.MILLISECONDS)) - .addLast(FRAME_DECODER, new MinecraftVarintFrameDecoder()) .addLast(FRAME_ENCODER, MinecraftVarintLengthEncoder.INSTANCE) .addLast(MINECRAFT_DECODER, new MinecraftDecoder(ProtocolUtils.Direction.CLIENTBOUND)) From f879858e7d869ca834b219f37ccca0f930b74ee3 Mon Sep 17 00:00:00 2001 From: Andrew Steinborn Date: Fri, 16 Apr 2021 04:11:55 -0400 Subject: [PATCH 24/99] Bring 2.0.0 fully up to date on GPLv3 relicense --- .../api/command/ConsoleCommandSource.java | 7 +++ .../api/event/Continuation.java | 7 +++ .../velocitypowered/api/event/EventTask.java | 7 +++ .../api/event/connection/ProxyPingEvent.java | 7 +++ .../api/event/connection/ProxyQueryEvent.java | 7 +++ .../event/lifecycle/ProxyInitializeEvent.java | 2 +- .../api/event/lifecycle/ProxyReloadEvent.java | 7 +++ .../event/lifecycle/ProxyShutdownEvent.java | 7 +++ .../lifecycle/network/ListenerBoundEvent.java | 43 +++++++++++++++++++ .../network/ListenerClosedEvent.java | 43 +++++++++++++++++++ .../api/event/player/DisconnectEvent.java | 7 +++ .../api/event/player/LoginEvent.java | 7 +++ .../api/event/player/PostLoginEvent.java | 7 +++ .../api/event/player/PreLoginEvent.java | 7 +++ .../proxy/connection/InboundConnection.java | 7 +++ .../api/proxy/connection/Player.java | 7 +++ .../proxy/connection/ServerConnection.java | 7 +++ .../api/util/FaviconChecker.java | 7 +++ .../api/util/FaviconCheckerTest.java | 7 +++ .../client/LoginSessionHandler.java | 1 + .../proxy/event/UntargetedEventHandler.java | 17 ++++++++ .../proxy/event/VelocityEventManager.java | 17 ++++++++ .../proxy/network/ConnectionManager.java | 14 +++--- .../proxy/network/NettyPreconditions.java | 17 ++++++++ .../proxy/network/PluginMessageUtil.java | 17 ++++++++ .../proxy/network/StateRegistry.java | 17 ++++++++ .../buffer/TypedDefaultByteBufHolder.java | 17 ++++++++ .../packet/AbstractKeepAlivePacket.java | 17 ++++++++ .../packet/AbstractPluginMessagePacket.java | 17 ++++++++ .../packet/AbstractStatusPingPacket.java | 17 ++++++++ .../proxy/network/packet/Packet.java | 17 ++++++++ .../proxy/network/packet/PacketDirection.java | 17 ++++++++ .../proxy/network/packet/PacketHandler.java | 17 ++++++++ .../proxy/network/packet/PacketReader.java | 17 ++++++++ .../proxy/network/packet/PacketWriter.java | 17 ++++++++ .../ClientboundAvailableCommandsPacket.java | 17 ++++++++ .../clientbound/ClientboundBossBarPacket.java | 17 ++++++++ .../clientbound/ClientboundChatPacket.java | 17 ++++++++ .../ClientboundDisconnectPacket.java | 17 ++++++++ .../ClientboundEncryptionRequestPacket.java | 17 ++++++++ .../ClientboundHeaderAndFooterPacket.java | 17 ++++++++ .../ClientboundJoinGamePacket.java | 17 ++++++++ .../ClientboundKeepAlivePacket.java | 17 ++++++++ .../ClientboundLoginPluginMessagePacket.java | 17 ++++++++ .../ClientboundPlayerListItemPacket.java | 17 ++++++++ .../ClientboundPluginMessagePacket.java | 17 ++++++++ .../ClientboundResourcePackRequestPacket.java | 17 ++++++++ .../clientbound/ClientboundRespawnPacket.java | 17 ++++++++ .../ClientboundServerLoginSuccessPacket.java | 17 ++++++++ .../ClientboundSetCompressionPacket.java | 17 ++++++++ .../ClientboundStatusPingPacket.java | 17 ++++++++ .../ClientboundStatusResponsePacket.java | 17 ++++++++ .../ClientboundTabCompleteResponsePacket.java | 17 ++++++++ .../clientbound/ClientboundTitlePacket.java | 17 ++++++++ .../packet/legacy/LegacyDisconnectPacket.java | 17 ++++++++ .../packet/legacy/LegacyHandshakePacket.java | 17 ++++++++ .../legacy/LegacyMinecraftPingVersion.java | 17 ++++++++ .../network/packet/legacy/LegacyPacket.java | 17 ++++++++ .../packet/legacy/LegacyPingPacket.java | 17 ++++++++ .../serverbound/ServerboundChatPacket.java | 17 ++++++++ .../ServerboundClientSettingsPacket.java | 17 ++++++++ .../ServerboundEncryptionResponsePacket.java | 17 ++++++++ .../ServerboundHandshakePacket.java | 17 ++++++++ .../ServerboundKeepAlivePacket.java | 17 ++++++++ .../ServerboundLoginPluginResponsePacket.java | 17 ++++++++ .../ServerboundPluginMessagePacket.java | 17 ++++++++ ...ServerboundResourcePackResponsePacket.java | 17 ++++++++ .../ServerboundServerLoginPacket.java | 17 ++++++++ .../ServerboundStatusPingPacket.java | 17 ++++++++ .../ServerboundStatusRequestPacket.java | 17 ++++++++ .../ServerboundTabCompleteRequestPacket.java | 17 ++++++++ .../network/pipeline/GS4QueryHandler.java | 17 ++++++++ .../network/pipeline/LegacyPingDecoder.java | 17 ++++++++ .../network/pipeline/LegacyPingEncoder.java | 17 ++++++++ .../pipeline/MinecraftCipherDecoder.java | 17 ++++++++ .../pipeline/MinecraftCipherEncoder.java | 17 ++++++++ .../pipeline/MinecraftCompressDecoder.java | 17 ++++++++ .../pipeline/MinecraftCompressEncoder.java | 17 ++++++++ .../network/pipeline/MinecraftDecoder.java | 17 ++++++++ .../network/pipeline/MinecraftEncoder.java | 17 ++++++++ .../pipeline/MinecraftVarintFrameDecoder.java | 17 ++++++++ .../MinecraftVarintLengthEncoder.java | 17 ++++++++ .../network/pipeline/VarintByteDecoder.java | 1 + .../SeparatePoolInetNameResolver.java | 17 ++++++++ .../serialization/FaviconSerializer.java | 17 ++++++++ .../serialization/GameProfileSerializer.java | 2 +- .../ByteArgumentPropertySerializer.java | 17 ++++++++ .../DoubleArgumentPropertySerializer.java | 17 ++++++++ .../EmptyArgumentPropertySerializer.java | 17 ++++++++ .../FloatArgumentPropertySerializer.java | 17 ++++++++ .../GenericArgumentPropertySerializer.java | 17 ++++++++ .../IntegerArgumentPropertySerializer.java | 17 ++++++++ .../LongArgumentPropertySerializer.java | 17 ++++++++ .../brigadier/ModArgumentProperty.java | 2 +- .../ModArgumentPropertySerializer.java | 17 ++++++++ .../brigadier/PassthroughProperty.java | 17 ++++++++ .../StringArgumentPropertySerializer.java | 17 ++++++++ .../proxy/event/EventTest.java | 17 ++++++++ .../proxy/event/MockEventManager.java | 17 ++++++++ .../proxy/network/PluginMessageUtilTest.java | 17 ++++++++ 100 files changed, 1502 insertions(+), 10 deletions(-) create mode 100644 api/src/main/java/com/velocitypowered/api/event/lifecycle/network/ListenerBoundEvent.java create mode 100644 api/src/main/java/com/velocitypowered/api/event/lifecycle/network/ListenerClosedEvent.java diff --git a/api/src/main/java/com/velocitypowered/api/command/ConsoleCommandSource.java b/api/src/main/java/com/velocitypowered/api/command/ConsoleCommandSource.java index a1d671cc4..3a369ca45 100644 --- a/api/src/main/java/com/velocitypowered/api/command/ConsoleCommandSource.java +++ b/api/src/main/java/com/velocitypowered/api/command/ConsoleCommandSource.java @@ -1,3 +1,10 @@ +/* + * Copyright (C) 2018 Velocity Contributors + * + * The Velocity API is licensed under the terms of the MIT License. For more details, + * reference the LICENSE file in the api top-level directory. + */ + package com.velocitypowered.api.command; import com.velocitypowered.api.command.CommandSource; diff --git a/api/src/main/java/com/velocitypowered/api/event/Continuation.java b/api/src/main/java/com/velocitypowered/api/event/Continuation.java index 412bf04ca..e4d7048ab 100644 --- a/api/src/main/java/com/velocitypowered/api/event/Continuation.java +++ b/api/src/main/java/com/velocitypowered/api/event/Continuation.java @@ -1,3 +1,10 @@ +/* + * Copyright (C) 2018 Velocity Contributors + * + * The Velocity API is licensed under the terms of the MIT License. For more details, + * reference the LICENSE file in the api top-level directory. + */ + package com.velocitypowered.api.event; /** diff --git a/api/src/main/java/com/velocitypowered/api/event/EventTask.java b/api/src/main/java/com/velocitypowered/api/event/EventTask.java index 1c4000e97..6dad00e58 100644 --- a/api/src/main/java/com/velocitypowered/api/event/EventTask.java +++ b/api/src/main/java/com/velocitypowered/api/event/EventTask.java @@ -1,3 +1,10 @@ +/* + * Copyright (C) 2018 Velocity Contributors + * + * The Velocity API is licensed under the terms of the MIT License. For more details, + * reference the LICENSE file in the api top-level directory. + */ + package com.velocitypowered.api.event; import static java.util.Objects.requireNonNull; diff --git a/api/src/main/java/com/velocitypowered/api/event/connection/ProxyPingEvent.java b/api/src/main/java/com/velocitypowered/api/event/connection/ProxyPingEvent.java index f6ee8c5db..edf76f260 100644 --- a/api/src/main/java/com/velocitypowered/api/event/connection/ProxyPingEvent.java +++ b/api/src/main/java/com/velocitypowered/api/event/connection/ProxyPingEvent.java @@ -1,3 +1,10 @@ +/* + * Copyright (C) 2018 Velocity Contributors + * + * The Velocity API is licensed under the terms of the MIT License. For more details, + * reference the LICENSE file in the api top-level directory. + */ + package com.velocitypowered.api.event.connection; import com.google.common.base.Preconditions; diff --git a/api/src/main/java/com/velocitypowered/api/event/connection/ProxyQueryEvent.java b/api/src/main/java/com/velocitypowered/api/event/connection/ProxyQueryEvent.java index f9cf5bf2b..daba17517 100644 --- a/api/src/main/java/com/velocitypowered/api/event/connection/ProxyQueryEvent.java +++ b/api/src/main/java/com/velocitypowered/api/event/connection/ProxyQueryEvent.java @@ -1,3 +1,10 @@ +/* + * Copyright (C) 2018 Velocity Contributors + * + * The Velocity API is licensed under the terms of the MIT License. For more details, + * reference the LICENSE file in the api top-level directory. + */ + package com.velocitypowered.api.event.connection; import com.google.common.base.Preconditions; diff --git a/api/src/main/java/com/velocitypowered/api/event/lifecycle/ProxyInitializeEvent.java b/api/src/main/java/com/velocitypowered/api/event/lifecycle/ProxyInitializeEvent.java index 80c5b8405..bb4ee1aa1 100644 --- a/api/src/main/java/com/velocitypowered/api/event/lifecycle/ProxyInitializeEvent.java +++ b/api/src/main/java/com/velocitypowered/api/event/lifecycle/ProxyInitializeEvent.java @@ -5,7 +5,7 @@ * reference the LICENSE file in the api top-level directory. */ -package com.velocitypowered.api.event.proxy; +package com.velocitypowered.api.event.lifecycle; /** * This event is fired by the proxy after plugins have been loaded but before the proxy starts diff --git a/api/src/main/java/com/velocitypowered/api/event/lifecycle/ProxyReloadEvent.java b/api/src/main/java/com/velocitypowered/api/event/lifecycle/ProxyReloadEvent.java index d29684142..063aede14 100644 --- a/api/src/main/java/com/velocitypowered/api/event/lifecycle/ProxyReloadEvent.java +++ b/api/src/main/java/com/velocitypowered/api/event/lifecycle/ProxyReloadEvent.java @@ -1,3 +1,10 @@ +/* + * Copyright (C) 2018 Velocity Contributors + * + * The Velocity API is licensed under the terms of the MIT License. For more details, + * reference the LICENSE file in the api top-level directory. + */ + package com.velocitypowered.api.event.lifecycle; /** diff --git a/api/src/main/java/com/velocitypowered/api/event/lifecycle/ProxyShutdownEvent.java b/api/src/main/java/com/velocitypowered/api/event/lifecycle/ProxyShutdownEvent.java index 010b61821..3a540b989 100644 --- a/api/src/main/java/com/velocitypowered/api/event/lifecycle/ProxyShutdownEvent.java +++ b/api/src/main/java/com/velocitypowered/api/event/lifecycle/ProxyShutdownEvent.java @@ -1,3 +1,10 @@ +/* + * Copyright (C) 2018 Velocity Contributors + * + * The Velocity API is licensed under the terms of the MIT License. For more details, + * reference the LICENSE file in the api top-level directory. + */ + package com.velocitypowered.api.event.lifecycle; /** diff --git a/api/src/main/java/com/velocitypowered/api/event/lifecycle/network/ListenerBoundEvent.java b/api/src/main/java/com/velocitypowered/api/event/lifecycle/network/ListenerBoundEvent.java new file mode 100644 index 000000000..2c226820f --- /dev/null +++ b/api/src/main/java/com/velocitypowered/api/event/lifecycle/network/ListenerBoundEvent.java @@ -0,0 +1,43 @@ +/* + * Copyright (C) 2018 Velocity Contributors + * + * The Velocity API is licensed under the terms of the MIT License. For more details, + * reference the LICENSE file in the api top-level directory. + */ + +package com.velocitypowered.api.event.lifecycle.network; + +import com.google.common.base.Preconditions; +import com.velocitypowered.api.network.ListenerType; +import java.net.InetSocketAddress; +import java.net.SocketAddress; + +/** + * This event is fired by the proxy after a listener starts accepting connections. + */ +public final class ListenerBoundEvent { + + private final SocketAddress address; + private final ListenerType listenerType; + + public ListenerBoundEvent(SocketAddress address, ListenerType listenerType) { + this.address = Preconditions.checkNotNull(address, "address"); + this.listenerType = Preconditions.checkNotNull(listenerType, "listenerType"); + } + + public SocketAddress getAddress() { + return address; + } + + public ListenerType getListenerType() { + return listenerType; + } + + @Override + public String toString() { + return "ListenerBoundEvent{" + + "address=" + address + + ", listenerType=" + listenerType + + '}'; + } +} \ No newline at end of file diff --git a/api/src/main/java/com/velocitypowered/api/event/lifecycle/network/ListenerClosedEvent.java b/api/src/main/java/com/velocitypowered/api/event/lifecycle/network/ListenerClosedEvent.java new file mode 100644 index 000000000..96eeffaa4 --- /dev/null +++ b/api/src/main/java/com/velocitypowered/api/event/lifecycle/network/ListenerClosedEvent.java @@ -0,0 +1,43 @@ +/* + * Copyright (C) 2018 Velocity Contributors + * + * The Velocity API is licensed under the terms of the MIT License. For more details, + * reference the LICENSE file in the api top-level directory. + */ + +package com.velocitypowered.api.event.lifecycle.network; + +import com.google.common.base.Preconditions; +import com.velocitypowered.api.network.ListenerType; +import java.net.InetSocketAddress; +import java.net.SocketAddress; + +/** + * This event is fired by the proxy before the proxy stops accepting connections. + */ +public final class ListenerClosedEvent { + + private final SocketAddress address; + private final ListenerType listenerType; + + public ListenerClosedEvent(SocketAddress address, ListenerType listenerType) { + this.address = Preconditions.checkNotNull(address, "address"); + this.listenerType = Preconditions.checkNotNull(listenerType, "listenerType"); + } + + public SocketAddress getAddress() { + return address; + } + + public ListenerType getListenerType() { + return listenerType; + } + + @Override + public String toString() { + return "ListenerCloseEvent{" + + "address=" + address + + ", listenerType=" + listenerType + + '}'; + } +} \ No newline at end of file diff --git a/api/src/main/java/com/velocitypowered/api/event/player/DisconnectEvent.java b/api/src/main/java/com/velocitypowered/api/event/player/DisconnectEvent.java index 12c238370..5aa6e4820 100644 --- a/api/src/main/java/com/velocitypowered/api/event/player/DisconnectEvent.java +++ b/api/src/main/java/com/velocitypowered/api/event/player/DisconnectEvent.java @@ -1,3 +1,10 @@ +/* + * Copyright (C) 2018 Velocity Contributors + * + * The Velocity API is licensed under the terms of the MIT License. For more details, + * reference the LICENSE file in the api top-level directory. + */ + package com.velocitypowered.api.event.player; import com.google.common.base.Preconditions; diff --git a/api/src/main/java/com/velocitypowered/api/event/player/LoginEvent.java b/api/src/main/java/com/velocitypowered/api/event/player/LoginEvent.java index e90137bcc..77b243111 100644 --- a/api/src/main/java/com/velocitypowered/api/event/player/LoginEvent.java +++ b/api/src/main/java/com/velocitypowered/api/event/player/LoginEvent.java @@ -1,3 +1,10 @@ +/* + * Copyright (C) 2018 Velocity Contributors + * + * The Velocity API is licensed under the terms of the MIT License. For more details, + * reference the LICENSE file in the api top-level directory. + */ + package com.velocitypowered.api.event.player; import com.google.common.base.Preconditions; diff --git a/api/src/main/java/com/velocitypowered/api/event/player/PostLoginEvent.java b/api/src/main/java/com/velocitypowered/api/event/player/PostLoginEvent.java index 29b5d6460..509c5bb51 100644 --- a/api/src/main/java/com/velocitypowered/api/event/player/PostLoginEvent.java +++ b/api/src/main/java/com/velocitypowered/api/event/player/PostLoginEvent.java @@ -1,3 +1,10 @@ +/* + * Copyright (C) 2018 Velocity Contributors + * + * The Velocity API is licensed under the terms of the MIT License. For more details, + * reference the LICENSE file in the api top-level directory. + */ + package com.velocitypowered.api.event.player; import com.google.common.base.Preconditions; diff --git a/api/src/main/java/com/velocitypowered/api/event/player/PreLoginEvent.java b/api/src/main/java/com/velocitypowered/api/event/player/PreLoginEvent.java index 40c98cb28..bff5951d0 100644 --- a/api/src/main/java/com/velocitypowered/api/event/player/PreLoginEvent.java +++ b/api/src/main/java/com/velocitypowered/api/event/player/PreLoginEvent.java @@ -1,3 +1,10 @@ +/* + * Copyright (C) 2018 Velocity Contributors + * + * The Velocity API is licensed under the terms of the MIT License. For more details, + * reference the LICENSE file in the api top-level directory. + */ + package com.velocitypowered.api.event.player; import com.google.common.base.Preconditions; diff --git a/api/src/main/java/com/velocitypowered/api/proxy/connection/InboundConnection.java b/api/src/main/java/com/velocitypowered/api/proxy/connection/InboundConnection.java index 519e609a4..682aaa2e6 100644 --- a/api/src/main/java/com/velocitypowered/api/proxy/connection/InboundConnection.java +++ b/api/src/main/java/com/velocitypowered/api/proxy/connection/InboundConnection.java @@ -1,3 +1,10 @@ +/* + * Copyright (C) 2018 Velocity Contributors + * + * The Velocity API is licensed under the terms of the MIT License. For more details, + * reference the LICENSE file in the api top-level directory. + */ + package com.velocitypowered.api.proxy.connection; import com.velocitypowered.api.network.ProtocolVersion; diff --git a/api/src/main/java/com/velocitypowered/api/proxy/connection/Player.java b/api/src/main/java/com/velocitypowered/api/proxy/connection/Player.java index d493f145c..95a1203e9 100644 --- a/api/src/main/java/com/velocitypowered/api/proxy/connection/Player.java +++ b/api/src/main/java/com/velocitypowered/api/proxy/connection/Player.java @@ -1,3 +1,10 @@ +/* + * Copyright (C) 2018 Velocity Contributors + * + * The Velocity API is licensed under the terms of the MIT License. For more details, + * reference the LICENSE file in the api top-level directory. + */ + package com.velocitypowered.api.proxy.connection; import com.velocitypowered.api.command.CommandSource; diff --git a/api/src/main/java/com/velocitypowered/api/proxy/connection/ServerConnection.java b/api/src/main/java/com/velocitypowered/api/proxy/connection/ServerConnection.java index a5c179b1c..3c24f9c32 100644 --- a/api/src/main/java/com/velocitypowered/api/proxy/connection/ServerConnection.java +++ b/api/src/main/java/com/velocitypowered/api/proxy/connection/ServerConnection.java @@ -1,3 +1,10 @@ +/* + * Copyright (C) 2018 Velocity Contributors + * + * The Velocity API is licensed under the terms of the MIT License. For more details, + * reference the LICENSE file in the api top-level directory. + */ + package com.velocitypowered.api.proxy.connection; import com.velocitypowered.api.proxy.messages.ChannelMessageSink; diff --git a/api/src/main/java/com/velocitypowered/api/util/FaviconChecker.java b/api/src/main/java/com/velocitypowered/api/util/FaviconChecker.java index 4dcd5a374..2cac6cb3b 100644 --- a/api/src/main/java/com/velocitypowered/api/util/FaviconChecker.java +++ b/api/src/main/java/com/velocitypowered/api/util/FaviconChecker.java @@ -1,3 +1,10 @@ +/* + * Copyright (C) 2018 Velocity Contributors + * + * The Velocity API is licensed under the terms of the MIT License. For more details, + * reference the LICENSE file in the api top-level directory. + */ + package com.velocitypowered.api.util; import java.nio.ByteBuffer; diff --git a/api/src/test/java/com/velocitypowered/api/util/FaviconCheckerTest.java b/api/src/test/java/com/velocitypowered/api/util/FaviconCheckerTest.java index b61b19323..41073300a 100644 --- a/api/src/test/java/com/velocitypowered/api/util/FaviconCheckerTest.java +++ b/api/src/test/java/com/velocitypowered/api/util/FaviconCheckerTest.java @@ -1,3 +1,10 @@ +/* + * Copyright (C) 2018 Velocity Contributors + * + * The Velocity API is licensed under the terms of the MIT License. For more details, + * reference the LICENSE file in the api top-level directory. + */ + package com.velocitypowered.api.util; import static org.junit.jupiter.api.Assertions.assertFalse; diff --git a/proxy/src/main/java/com/velocitypowered/proxy/connection/client/LoginSessionHandler.java b/proxy/src/main/java/com/velocitypowered/proxy/connection/client/LoginSessionHandler.java index 144ba57c9..635d8135e 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/connection/client/LoginSessionHandler.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/connection/client/LoginSessionHandler.java @@ -34,6 +34,7 @@ import com.velocitypowered.api.event.player.PlayerChooseInitialServerEvent; import com.velocitypowered.api.event.player.PostLoginEvent; import com.velocitypowered.api.event.player.PreLoginEvent; import com.velocitypowered.api.event.player.PreLoginEvent.PreLoginComponentResult; +import com.velocitypowered.api.permission.PermissionFunction; import com.velocitypowered.api.proxy.server.RegisteredServer; import com.velocitypowered.api.util.GameProfile; import com.velocitypowered.api.util.UuidUtils; diff --git a/proxy/src/main/java/com/velocitypowered/proxy/event/UntargetedEventHandler.java b/proxy/src/main/java/com/velocitypowered/proxy/event/UntargetedEventHandler.java index f4ae56fb1..a0fb6376a 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/event/UntargetedEventHandler.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/event/UntargetedEventHandler.java @@ -1,3 +1,20 @@ +/* + * 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 . + */ + package com.velocitypowered.proxy.event; import com.velocitypowered.api.event.EventTask; diff --git a/proxy/src/main/java/com/velocitypowered/proxy/event/VelocityEventManager.java b/proxy/src/main/java/com/velocitypowered/proxy/event/VelocityEventManager.java index f5f7ca518..b6252cef9 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/event/VelocityEventManager.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/event/VelocityEventManager.java @@ -1,3 +1,20 @@ +/* + * 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 . + */ + package com.velocitypowered.proxy.event; import static java.util.Objects.requireNonNull; diff --git a/proxy/src/main/java/com/velocitypowered/proxy/network/ConnectionManager.java b/proxy/src/main/java/com/velocitypowered/proxy/network/ConnectionManager.java index 1360f6ce3..8c56b7c6d 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/network/ConnectionManager.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/network/ConnectionManager.java @@ -21,8 +21,8 @@ import static org.asynchttpclient.Dsl.asyncHttpClient; import static org.asynchttpclient.Dsl.config; import com.google.common.base.Preconditions; -import com.velocitypowered.api.event.proxy.ListenerBoundEvent; -import com.velocitypowered.api.event.proxy.ListenerCloseEvent; +import com.velocitypowered.api.event.lifecycle.network.ListenerBoundEvent; +import com.velocitypowered.api.event.lifecycle.network.ListenerClosedEvent; import com.velocitypowered.api.network.ListenerType; import com.velocitypowered.natives.util.Natives; import com.velocitypowered.proxy.VelocityServer; @@ -198,12 +198,12 @@ public final class ConnectionManager { * * @param oldBind the endpoint to close */ - public void close(InetSocketAddress oldBind) { + public void close(SocketAddress oldBind) { Endpoint endpoint = endpoints.remove(oldBind); // Fire proxy close event to notify plugins of socket close. We block since plugins // should have a chance to be notified before the server stops accepting connections. - server.getEventManager().fire(new ListenerCloseEvent(oldBind, endpoint.getType())).join(); + server.getEventManager().fire(new ListenerClosedEvent(oldBind, endpoint.getType())).join(); Channel serverChannel = endpoint.getChannel(); @@ -216,13 +216,13 @@ public final class ConnectionManager { * Closes all endpoints. */ public void shutdown() { - for (final Map.Entry entry : this.endpoints.entrySet()) { - final InetSocketAddress address = entry.getKey(); + for (final Map.Entry entry : this.endpoints.entrySet()) { + final SocketAddress address = entry.getKey(); final Endpoint endpoint = entry.getValue(); // Fire proxy close event to notify plugins of socket close. We block since plugins // should have a chance to be notified before the server stops accepting connections. - server.getEventManager().fire(new ListenerCloseEvent(address, endpoint.getType())).join(); + server.getEventManager().fire(new ListenerClosedEvent(address, endpoint.getType())).join(); try { LOGGER.info("Closing endpoint {}", address); diff --git a/proxy/src/main/java/com/velocitypowered/proxy/network/NettyPreconditions.java b/proxy/src/main/java/com/velocitypowered/proxy/network/NettyPreconditions.java index 351b268cb..f696158ab 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/network/NettyPreconditions.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/network/NettyPreconditions.java @@ -1,3 +1,20 @@ +/* + * 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 . + */ + package com.velocitypowered.proxy.network; import com.google.common.base.Strings; diff --git a/proxy/src/main/java/com/velocitypowered/proxy/network/PluginMessageUtil.java b/proxy/src/main/java/com/velocitypowered/proxy/network/PluginMessageUtil.java index 6143d1e22..22771c5ae 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/network/PluginMessageUtil.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/network/PluginMessageUtil.java @@ -1,3 +1,20 @@ +/* + * 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 . + */ + package com.velocitypowered.proxy.network; import static com.google.common.base.Preconditions.checkArgument; diff --git a/proxy/src/main/java/com/velocitypowered/proxy/network/StateRegistry.java b/proxy/src/main/java/com/velocitypowered/proxy/network/StateRegistry.java index 3d828ad1b..2ba906f23 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/network/StateRegistry.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/network/StateRegistry.java @@ -1,3 +1,20 @@ +/* + * 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 . + */ + package com.velocitypowered.proxy.network; import static com.google.common.collect.Iterables.getLast; diff --git a/proxy/src/main/java/com/velocitypowered/proxy/network/buffer/TypedDefaultByteBufHolder.java b/proxy/src/main/java/com/velocitypowered/proxy/network/buffer/TypedDefaultByteBufHolder.java index 7320e24a6..7b62afd4b 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/network/buffer/TypedDefaultByteBufHolder.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/network/buffer/TypedDefaultByteBufHolder.java @@ -1,3 +1,20 @@ +/* + * 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 . + */ + package com.velocitypowered.proxy.network.buffer; import io.netty.buffer.ByteBuf; diff --git a/proxy/src/main/java/com/velocitypowered/proxy/network/packet/AbstractKeepAlivePacket.java b/proxy/src/main/java/com/velocitypowered/proxy/network/packet/AbstractKeepAlivePacket.java index 2c411975c..b629379df 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/network/packet/AbstractKeepAlivePacket.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/network/packet/AbstractKeepAlivePacket.java @@ -1,3 +1,20 @@ +/* + * 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 . + */ + package com.velocitypowered.proxy.network.packet; import com.google.common.base.MoreObjects; diff --git a/proxy/src/main/java/com/velocitypowered/proxy/network/packet/AbstractPluginMessagePacket.java b/proxy/src/main/java/com/velocitypowered/proxy/network/packet/AbstractPluginMessagePacket.java index 86819742d..b2b8b0944 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/network/packet/AbstractPluginMessagePacket.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/network/packet/AbstractPluginMessagePacket.java @@ -1,3 +1,20 @@ +/* + * 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 . + */ + package com.velocitypowered.proxy.network.packet; import static com.velocitypowered.proxy.network.PluginMessageUtil.transformLegacyToModernChannel; diff --git a/proxy/src/main/java/com/velocitypowered/proxy/network/packet/AbstractStatusPingPacket.java b/proxy/src/main/java/com/velocitypowered/proxy/network/packet/AbstractStatusPingPacket.java index 92f237a92..5dfcf9e41 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/network/packet/AbstractStatusPingPacket.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/network/packet/AbstractStatusPingPacket.java @@ -1,3 +1,20 @@ +/* + * 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 . + */ + package com.velocitypowered.proxy.network.packet; import com.google.common.base.MoreObjects; diff --git a/proxy/src/main/java/com/velocitypowered/proxy/network/packet/Packet.java b/proxy/src/main/java/com/velocitypowered/proxy/network/packet/Packet.java index 30bf4e1cf..7e0be981d 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/network/packet/Packet.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/network/packet/Packet.java @@ -1,3 +1,20 @@ +/* + * 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 . + */ + package com.velocitypowered.proxy.network.packet; import com.velocitypowered.api.network.ProtocolVersion; diff --git a/proxy/src/main/java/com/velocitypowered/proxy/network/packet/PacketDirection.java b/proxy/src/main/java/com/velocitypowered/proxy/network/packet/PacketDirection.java index aecb2d511..172caa302 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/network/packet/PacketDirection.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/network/packet/PacketDirection.java @@ -1,3 +1,20 @@ +/* + * 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 . + */ + package com.velocitypowered.proxy.network.packet; public enum PacketDirection { diff --git a/proxy/src/main/java/com/velocitypowered/proxy/network/packet/PacketHandler.java b/proxy/src/main/java/com/velocitypowered/proxy/network/packet/PacketHandler.java index 25dc49923..40b06ac13 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/network/packet/PacketHandler.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/network/packet/PacketHandler.java @@ -1,3 +1,20 @@ +/* + * 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 . + */ + package com.velocitypowered.proxy.network.packet; import com.velocitypowered.proxy.network.packet.clientbound.ClientboundAvailableCommandsPacket; diff --git a/proxy/src/main/java/com/velocitypowered/proxy/network/packet/PacketReader.java b/proxy/src/main/java/com/velocitypowered/proxy/network/packet/PacketReader.java index d536b0603..becaf65dd 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/network/packet/PacketReader.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/network/packet/PacketReader.java @@ -1,3 +1,20 @@ +/* + * 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 . + */ + package com.velocitypowered.proxy.network.packet; import com.velocitypowered.api.network.ProtocolVersion; diff --git a/proxy/src/main/java/com/velocitypowered/proxy/network/packet/PacketWriter.java b/proxy/src/main/java/com/velocitypowered/proxy/network/packet/PacketWriter.java index 585d8d9b5..f6b4534cb 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/network/packet/PacketWriter.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/network/packet/PacketWriter.java @@ -1,3 +1,20 @@ +/* + * 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 . + */ + package com.velocitypowered.proxy.network.packet; import com.velocitypowered.api.network.ProtocolVersion; diff --git a/proxy/src/main/java/com/velocitypowered/proxy/network/packet/clientbound/ClientboundAvailableCommandsPacket.java b/proxy/src/main/java/com/velocitypowered/proxy/network/packet/clientbound/ClientboundAvailableCommandsPacket.java index 0ab515dcb..259dfd4d4 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/network/packet/clientbound/ClientboundAvailableCommandsPacket.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/network/packet/clientbound/ClientboundAvailableCommandsPacket.java @@ -1,3 +1,20 @@ +/* + * 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 . + */ + package com.velocitypowered.proxy.network.packet.clientbound; import com.google.common.base.MoreObjects; diff --git a/proxy/src/main/java/com/velocitypowered/proxy/network/packet/clientbound/ClientboundBossBarPacket.java b/proxy/src/main/java/com/velocitypowered/proxy/network/packet/clientbound/ClientboundBossBarPacket.java index 763734308..d31faf043 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/network/packet/clientbound/ClientboundBossBarPacket.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/network/packet/clientbound/ClientboundBossBarPacket.java @@ -1,3 +1,20 @@ +/* + * 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 . + */ + package com.velocitypowered.proxy.network.packet.clientbound; import com.google.common.base.MoreObjects; diff --git a/proxy/src/main/java/com/velocitypowered/proxy/network/packet/clientbound/ClientboundChatPacket.java b/proxy/src/main/java/com/velocitypowered/proxy/network/packet/clientbound/ClientboundChatPacket.java index df6281f13..0208e7049 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/network/packet/clientbound/ClientboundChatPacket.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/network/packet/clientbound/ClientboundChatPacket.java @@ -1,3 +1,20 @@ +/* + * 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 . + */ + package com.velocitypowered.proxy.network.packet.clientbound; import com.google.common.base.MoreObjects; diff --git a/proxy/src/main/java/com/velocitypowered/proxy/network/packet/clientbound/ClientboundDisconnectPacket.java b/proxy/src/main/java/com/velocitypowered/proxy/network/packet/clientbound/ClientboundDisconnectPacket.java index 6c85eee50..12472db77 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/network/packet/clientbound/ClientboundDisconnectPacket.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/network/packet/clientbound/ClientboundDisconnectPacket.java @@ -1,3 +1,20 @@ +/* + * 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 . + */ + package com.velocitypowered.proxy.network.packet.clientbound; import com.google.common.base.MoreObjects; diff --git a/proxy/src/main/java/com/velocitypowered/proxy/network/packet/clientbound/ClientboundEncryptionRequestPacket.java b/proxy/src/main/java/com/velocitypowered/proxy/network/packet/clientbound/ClientboundEncryptionRequestPacket.java index ee12530df..95054d742 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/network/packet/clientbound/ClientboundEncryptionRequestPacket.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/network/packet/clientbound/ClientboundEncryptionRequestPacket.java @@ -1,3 +1,20 @@ +/* + * 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 . + */ + package com.velocitypowered.proxy.network.packet.clientbound; import static com.velocitypowered.proxy.connection.VelocityConstants.EMPTY_BYTE_ARRAY; diff --git a/proxy/src/main/java/com/velocitypowered/proxy/network/packet/clientbound/ClientboundHeaderAndFooterPacket.java b/proxy/src/main/java/com/velocitypowered/proxy/network/packet/clientbound/ClientboundHeaderAndFooterPacket.java index a64849ccd..1bfa98756 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/network/packet/clientbound/ClientboundHeaderAndFooterPacket.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/network/packet/clientbound/ClientboundHeaderAndFooterPacket.java @@ -1,3 +1,20 @@ +/* + * 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 . + */ + package com.velocitypowered.proxy.network.packet.clientbound; import static com.velocitypowered.proxy.network.ProtocolUtils.writeString; diff --git a/proxy/src/main/java/com/velocitypowered/proxy/network/packet/clientbound/ClientboundJoinGamePacket.java b/proxy/src/main/java/com/velocitypowered/proxy/network/packet/clientbound/ClientboundJoinGamePacket.java index 1afb05d89..bce9a5806 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/network/packet/clientbound/ClientboundJoinGamePacket.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/network/packet/clientbound/ClientboundJoinGamePacket.java @@ -1,3 +1,20 @@ +/* + * 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 . + */ + package com.velocitypowered.proxy.network.packet.clientbound; import com.google.common.collect.ImmutableSet; diff --git a/proxy/src/main/java/com/velocitypowered/proxy/network/packet/clientbound/ClientboundKeepAlivePacket.java b/proxy/src/main/java/com/velocitypowered/proxy/network/packet/clientbound/ClientboundKeepAlivePacket.java index c9115110e..1b69d86bd 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/network/packet/clientbound/ClientboundKeepAlivePacket.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/network/packet/clientbound/ClientboundKeepAlivePacket.java @@ -1,3 +1,20 @@ +/* + * 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 . + */ + package com.velocitypowered.proxy.network.packet.clientbound; import com.velocitypowered.proxy.network.packet.AbstractKeepAlivePacket; diff --git a/proxy/src/main/java/com/velocitypowered/proxy/network/packet/clientbound/ClientboundLoginPluginMessagePacket.java b/proxy/src/main/java/com/velocitypowered/proxy/network/packet/clientbound/ClientboundLoginPluginMessagePacket.java index 44e5effbe..c2b6c343d 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/network/packet/clientbound/ClientboundLoginPluginMessagePacket.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/network/packet/clientbound/ClientboundLoginPluginMessagePacket.java @@ -1,3 +1,20 @@ +/* + * 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 . + */ + package com.velocitypowered.proxy.network.packet.clientbound; import com.google.common.base.MoreObjects; diff --git a/proxy/src/main/java/com/velocitypowered/proxy/network/packet/clientbound/ClientboundPlayerListItemPacket.java b/proxy/src/main/java/com/velocitypowered/proxy/network/packet/clientbound/ClientboundPlayerListItemPacket.java index 5d51f9c68..ddfbb56d9 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/network/packet/clientbound/ClientboundPlayerListItemPacket.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/network/packet/clientbound/ClientboundPlayerListItemPacket.java @@ -1,3 +1,20 @@ +/* + * 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 . + */ + package com.velocitypowered.proxy.network.packet.clientbound; import com.google.common.base.MoreObjects; diff --git a/proxy/src/main/java/com/velocitypowered/proxy/network/packet/clientbound/ClientboundPluginMessagePacket.java b/proxy/src/main/java/com/velocitypowered/proxy/network/packet/clientbound/ClientboundPluginMessagePacket.java index a9a55e963..4d0fb27a0 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/network/packet/clientbound/ClientboundPluginMessagePacket.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/network/packet/clientbound/ClientboundPluginMessagePacket.java @@ -1,3 +1,20 @@ +/* + * 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 . + */ + package com.velocitypowered.proxy.network.packet.clientbound; import com.velocitypowered.proxy.network.packet.AbstractPluginMessagePacket; diff --git a/proxy/src/main/java/com/velocitypowered/proxy/network/packet/clientbound/ClientboundResourcePackRequestPacket.java b/proxy/src/main/java/com/velocitypowered/proxy/network/packet/clientbound/ClientboundResourcePackRequestPacket.java index 991bff257..599bfa1ae 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/network/packet/clientbound/ClientboundResourcePackRequestPacket.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/network/packet/clientbound/ClientboundResourcePackRequestPacket.java @@ -1,3 +1,20 @@ +/* + * 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 . + */ + package com.velocitypowered.proxy.network.packet.clientbound; import com.google.common.base.MoreObjects; diff --git a/proxy/src/main/java/com/velocitypowered/proxy/network/packet/clientbound/ClientboundRespawnPacket.java b/proxy/src/main/java/com/velocitypowered/proxy/network/packet/clientbound/ClientboundRespawnPacket.java index ee90e50ee..d48a4c5ed 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/network/packet/clientbound/ClientboundRespawnPacket.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/network/packet/clientbound/ClientboundRespawnPacket.java @@ -1,3 +1,20 @@ +/* + * 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 . + */ + package com.velocitypowered.proxy.network.packet.clientbound; import com.google.common.base.MoreObjects; diff --git a/proxy/src/main/java/com/velocitypowered/proxy/network/packet/clientbound/ClientboundServerLoginSuccessPacket.java b/proxy/src/main/java/com/velocitypowered/proxy/network/packet/clientbound/ClientboundServerLoginSuccessPacket.java index 1160e75ab..54ca5d114 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/network/packet/clientbound/ClientboundServerLoginSuccessPacket.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/network/packet/clientbound/ClientboundServerLoginSuccessPacket.java @@ -1,3 +1,20 @@ +/* + * 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 . + */ + package com.velocitypowered.proxy.network.packet.clientbound; import com.google.common.base.MoreObjects; diff --git a/proxy/src/main/java/com/velocitypowered/proxy/network/packet/clientbound/ClientboundSetCompressionPacket.java b/proxy/src/main/java/com/velocitypowered/proxy/network/packet/clientbound/ClientboundSetCompressionPacket.java index 6744d8421..012220a3b 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/network/packet/clientbound/ClientboundSetCompressionPacket.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/network/packet/clientbound/ClientboundSetCompressionPacket.java @@ -1,3 +1,20 @@ +/* + * 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 . + */ + package com.velocitypowered.proxy.network.packet.clientbound; import com.google.common.base.MoreObjects; diff --git a/proxy/src/main/java/com/velocitypowered/proxy/network/packet/clientbound/ClientboundStatusPingPacket.java b/proxy/src/main/java/com/velocitypowered/proxy/network/packet/clientbound/ClientboundStatusPingPacket.java index 297edfdbe..8380da70d 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/network/packet/clientbound/ClientboundStatusPingPacket.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/network/packet/clientbound/ClientboundStatusPingPacket.java @@ -1,3 +1,20 @@ +/* + * 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 . + */ + package com.velocitypowered.proxy.network.packet.clientbound; import com.velocitypowered.proxy.network.packet.AbstractStatusPingPacket; diff --git a/proxy/src/main/java/com/velocitypowered/proxy/network/packet/clientbound/ClientboundStatusResponsePacket.java b/proxy/src/main/java/com/velocitypowered/proxy/network/packet/clientbound/ClientboundStatusResponsePacket.java index 80af53f83..40b785c71 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/network/packet/clientbound/ClientboundStatusResponsePacket.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/network/packet/clientbound/ClientboundStatusResponsePacket.java @@ -1,3 +1,20 @@ +/* + * 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 . + */ + package com.velocitypowered.proxy.network.packet.clientbound; import com.google.common.base.MoreObjects; diff --git a/proxy/src/main/java/com/velocitypowered/proxy/network/packet/clientbound/ClientboundTabCompleteResponsePacket.java b/proxy/src/main/java/com/velocitypowered/proxy/network/packet/clientbound/ClientboundTabCompleteResponsePacket.java index de2f9126e..0f9ab6e63 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/network/packet/clientbound/ClientboundTabCompleteResponsePacket.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/network/packet/clientbound/ClientboundTabCompleteResponsePacket.java @@ -1,3 +1,20 @@ +/* + * 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 . + */ + package com.velocitypowered.proxy.network.packet.clientbound; import com.google.common.base.MoreObjects; diff --git a/proxy/src/main/java/com/velocitypowered/proxy/network/packet/clientbound/ClientboundTitlePacket.java b/proxy/src/main/java/com/velocitypowered/proxy/network/packet/clientbound/ClientboundTitlePacket.java index 305dcdf7e..b0e14515c 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/network/packet/clientbound/ClientboundTitlePacket.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/network/packet/clientbound/ClientboundTitlePacket.java @@ -1,3 +1,20 @@ +/* + * 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 . + */ + package com.velocitypowered.proxy.network.packet.clientbound; import com.google.common.base.MoreObjects; diff --git a/proxy/src/main/java/com/velocitypowered/proxy/network/packet/legacy/LegacyDisconnectPacket.java b/proxy/src/main/java/com/velocitypowered/proxy/network/packet/legacy/LegacyDisconnectPacket.java index 4f8099476..3c570a1b2 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/network/packet/legacy/LegacyDisconnectPacket.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/network/packet/legacy/LegacyDisconnectPacket.java @@ -1,3 +1,20 @@ +/* + * 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 . + */ + package com.velocitypowered.proxy.network.packet.legacy; import com.google.common.collect.ImmutableList; diff --git a/proxy/src/main/java/com/velocitypowered/proxy/network/packet/legacy/LegacyHandshakePacket.java b/proxy/src/main/java/com/velocitypowered/proxy/network/packet/legacy/LegacyHandshakePacket.java index 2106098fb..4e46b51cc 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/network/packet/legacy/LegacyHandshakePacket.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/network/packet/legacy/LegacyHandshakePacket.java @@ -1,3 +1,20 @@ +/* + * 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 . + */ + package com.velocitypowered.proxy.network.packet.legacy; import com.velocitypowered.api.network.ProtocolVersion; diff --git a/proxy/src/main/java/com/velocitypowered/proxy/network/packet/legacy/LegacyMinecraftPingVersion.java b/proxy/src/main/java/com/velocitypowered/proxy/network/packet/legacy/LegacyMinecraftPingVersion.java index 5b63c44c2..3622e30c0 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/network/packet/legacy/LegacyMinecraftPingVersion.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/network/packet/legacy/LegacyMinecraftPingVersion.java @@ -1,3 +1,20 @@ +/* + * 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 . + */ + package com.velocitypowered.proxy.network.packet.legacy; public enum LegacyMinecraftPingVersion { diff --git a/proxy/src/main/java/com/velocitypowered/proxy/network/packet/legacy/LegacyPacket.java b/proxy/src/main/java/com/velocitypowered/proxy/network/packet/legacy/LegacyPacket.java index 67ff76360..024a3695e 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/network/packet/legacy/LegacyPacket.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/network/packet/legacy/LegacyPacket.java @@ -1,3 +1,20 @@ +/* + * 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 . + */ + package com.velocitypowered.proxy.network.packet.legacy; public interface LegacyPacket { diff --git a/proxy/src/main/java/com/velocitypowered/proxy/network/packet/legacy/LegacyPingPacket.java b/proxy/src/main/java/com/velocitypowered/proxy/network/packet/legacy/LegacyPingPacket.java index 520d310fc..0c1cdc3f8 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/network/packet/legacy/LegacyPingPacket.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/network/packet/legacy/LegacyPingPacket.java @@ -1,3 +1,20 @@ +/* + * 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 . + */ + package com.velocitypowered.proxy.network.packet.legacy; import com.velocitypowered.api.network.ProtocolVersion; diff --git a/proxy/src/main/java/com/velocitypowered/proxy/network/packet/serverbound/ServerboundChatPacket.java b/proxy/src/main/java/com/velocitypowered/proxy/network/packet/serverbound/ServerboundChatPacket.java index a45c2bd66..eb4c06954 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/network/packet/serverbound/ServerboundChatPacket.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/network/packet/serverbound/ServerboundChatPacket.java @@ -1,3 +1,20 @@ +/* + * 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 . + */ + package com.velocitypowered.proxy.network.packet.serverbound; import com.google.common.base.MoreObjects; diff --git a/proxy/src/main/java/com/velocitypowered/proxy/network/packet/serverbound/ServerboundClientSettingsPacket.java b/proxy/src/main/java/com/velocitypowered/proxy/network/packet/serverbound/ServerboundClientSettingsPacket.java index 70ccf8040..7cdba5d85 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/network/packet/serverbound/ServerboundClientSettingsPacket.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/network/packet/serverbound/ServerboundClientSettingsPacket.java @@ -1,3 +1,20 @@ +/* + * 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 . + */ + package com.velocitypowered.proxy.network.packet.serverbound; import com.google.common.base.MoreObjects; diff --git a/proxy/src/main/java/com/velocitypowered/proxy/network/packet/serverbound/ServerboundEncryptionResponsePacket.java b/proxy/src/main/java/com/velocitypowered/proxy/network/packet/serverbound/ServerboundEncryptionResponsePacket.java index 4ee125419..31990f984 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/network/packet/serverbound/ServerboundEncryptionResponsePacket.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/network/packet/serverbound/ServerboundEncryptionResponsePacket.java @@ -1,3 +1,20 @@ +/* + * 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 . + */ + package com.velocitypowered.proxy.network.packet.serverbound; import com.google.common.base.MoreObjects; diff --git a/proxy/src/main/java/com/velocitypowered/proxy/network/packet/serverbound/ServerboundHandshakePacket.java b/proxy/src/main/java/com/velocitypowered/proxy/network/packet/serverbound/ServerboundHandshakePacket.java index f49710749..8d355f4e0 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/network/packet/serverbound/ServerboundHandshakePacket.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/network/packet/serverbound/ServerboundHandshakePacket.java @@ -1,3 +1,20 @@ +/* + * 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 . + */ + package com.velocitypowered.proxy.network.packet.serverbound; import com.google.common.base.MoreObjects; diff --git a/proxy/src/main/java/com/velocitypowered/proxy/network/packet/serverbound/ServerboundKeepAlivePacket.java b/proxy/src/main/java/com/velocitypowered/proxy/network/packet/serverbound/ServerboundKeepAlivePacket.java index 17bf0c2d0..64adbf36d 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/network/packet/serverbound/ServerboundKeepAlivePacket.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/network/packet/serverbound/ServerboundKeepAlivePacket.java @@ -1,3 +1,20 @@ +/* + * 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 . + */ + package com.velocitypowered.proxy.network.packet.serverbound; import com.velocitypowered.proxy.network.packet.AbstractKeepAlivePacket; diff --git a/proxy/src/main/java/com/velocitypowered/proxy/network/packet/serverbound/ServerboundLoginPluginResponsePacket.java b/proxy/src/main/java/com/velocitypowered/proxy/network/packet/serverbound/ServerboundLoginPluginResponsePacket.java index 206b4dc19..029c9f2fe 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/network/packet/serverbound/ServerboundLoginPluginResponsePacket.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/network/packet/serverbound/ServerboundLoginPluginResponsePacket.java @@ -1,3 +1,20 @@ +/* + * 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 . + */ + package com.velocitypowered.proxy.network.packet.serverbound; import com.google.common.base.MoreObjects; diff --git a/proxy/src/main/java/com/velocitypowered/proxy/network/packet/serverbound/ServerboundPluginMessagePacket.java b/proxy/src/main/java/com/velocitypowered/proxy/network/packet/serverbound/ServerboundPluginMessagePacket.java index 4707ced29..b544323a0 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/network/packet/serverbound/ServerboundPluginMessagePacket.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/network/packet/serverbound/ServerboundPluginMessagePacket.java @@ -1,3 +1,20 @@ +/* + * 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 . + */ + package com.velocitypowered.proxy.network.packet.serverbound; import com.velocitypowered.proxy.network.packet.AbstractPluginMessagePacket; diff --git a/proxy/src/main/java/com/velocitypowered/proxy/network/packet/serverbound/ServerboundResourcePackResponsePacket.java b/proxy/src/main/java/com/velocitypowered/proxy/network/packet/serverbound/ServerboundResourcePackResponsePacket.java index 00047e3d2..97b8bbfc7 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/network/packet/serverbound/ServerboundResourcePackResponsePacket.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/network/packet/serverbound/ServerboundResourcePackResponsePacket.java @@ -1,3 +1,20 @@ +/* + * 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 . + */ + package com.velocitypowered.proxy.network.packet.serverbound; import com.google.common.base.MoreObjects; diff --git a/proxy/src/main/java/com/velocitypowered/proxy/network/packet/serverbound/ServerboundServerLoginPacket.java b/proxy/src/main/java/com/velocitypowered/proxy/network/packet/serverbound/ServerboundServerLoginPacket.java index 8f1f5bbf8..f4572de72 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/network/packet/serverbound/ServerboundServerLoginPacket.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/network/packet/serverbound/ServerboundServerLoginPacket.java @@ -1,3 +1,20 @@ +/* + * 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 . + */ + package com.velocitypowered.proxy.network.packet.serverbound; import com.google.common.base.MoreObjects; diff --git a/proxy/src/main/java/com/velocitypowered/proxy/network/packet/serverbound/ServerboundStatusPingPacket.java b/proxy/src/main/java/com/velocitypowered/proxy/network/packet/serverbound/ServerboundStatusPingPacket.java index 3f73147bd..d71454527 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/network/packet/serverbound/ServerboundStatusPingPacket.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/network/packet/serverbound/ServerboundStatusPingPacket.java @@ -1,3 +1,20 @@ +/* + * 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 . + */ + package com.velocitypowered.proxy.network.packet.serverbound; import com.velocitypowered.proxy.network.packet.AbstractStatusPingPacket; diff --git a/proxy/src/main/java/com/velocitypowered/proxy/network/packet/serverbound/ServerboundStatusRequestPacket.java b/proxy/src/main/java/com/velocitypowered/proxy/network/packet/serverbound/ServerboundStatusRequestPacket.java index 36d3c6745..34562d9ab 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/network/packet/serverbound/ServerboundStatusRequestPacket.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/network/packet/serverbound/ServerboundStatusRequestPacket.java @@ -1,3 +1,20 @@ +/* + * 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 . + */ + package com.velocitypowered.proxy.network.packet.serverbound; import com.velocitypowered.api.network.ProtocolVersion; diff --git a/proxy/src/main/java/com/velocitypowered/proxy/network/packet/serverbound/ServerboundTabCompleteRequestPacket.java b/proxy/src/main/java/com/velocitypowered/proxy/network/packet/serverbound/ServerboundTabCompleteRequestPacket.java index 8f0c275df..973ca4d48 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/network/packet/serverbound/ServerboundTabCompleteRequestPacket.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/network/packet/serverbound/ServerboundTabCompleteRequestPacket.java @@ -1,3 +1,20 @@ +/* + * 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 . + */ + package com.velocitypowered.proxy.network.packet.serverbound; import static com.velocitypowered.api.network.ProtocolVersion.MINECRAFT_1_13; diff --git a/proxy/src/main/java/com/velocitypowered/proxy/network/pipeline/GS4QueryHandler.java b/proxy/src/main/java/com/velocitypowered/proxy/network/pipeline/GS4QueryHandler.java index 37c8897bc..026789e1d 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/network/pipeline/GS4QueryHandler.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/network/pipeline/GS4QueryHandler.java @@ -1,3 +1,20 @@ +/* + * 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 . + */ + package com.velocitypowered.proxy.network.pipeline; import static com.velocitypowered.api.event.connection.ProxyQueryEvent.QueryType.BASIC; diff --git a/proxy/src/main/java/com/velocitypowered/proxy/network/pipeline/LegacyPingDecoder.java b/proxy/src/main/java/com/velocitypowered/proxy/network/pipeline/LegacyPingDecoder.java index 95277af02..63f328ea3 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/network/pipeline/LegacyPingDecoder.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/network/pipeline/LegacyPingDecoder.java @@ -1,3 +1,20 @@ +/* + * 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 . + */ + package com.velocitypowered.proxy.network.pipeline; import static com.velocitypowered.proxy.network.NettyPreconditions.checkFrame; diff --git a/proxy/src/main/java/com/velocitypowered/proxy/network/pipeline/LegacyPingEncoder.java b/proxy/src/main/java/com/velocitypowered/proxy/network/pipeline/LegacyPingEncoder.java index dc00506b5..0932c4d92 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/network/pipeline/LegacyPingEncoder.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/network/pipeline/LegacyPingEncoder.java @@ -1,3 +1,20 @@ +/* + * 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 . + */ + package com.velocitypowered.proxy.network.pipeline; import com.velocitypowered.proxy.network.packet.legacy.LegacyDisconnectPacket; diff --git a/proxy/src/main/java/com/velocitypowered/proxy/network/pipeline/MinecraftCipherDecoder.java b/proxy/src/main/java/com/velocitypowered/proxy/network/pipeline/MinecraftCipherDecoder.java index 0219e4604..4f17a1538 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/network/pipeline/MinecraftCipherDecoder.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/network/pipeline/MinecraftCipherDecoder.java @@ -1,3 +1,20 @@ +/* + * 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 . + */ + package com.velocitypowered.proxy.network.pipeline; import com.google.common.base.Preconditions; diff --git a/proxy/src/main/java/com/velocitypowered/proxy/network/pipeline/MinecraftCipherEncoder.java b/proxy/src/main/java/com/velocitypowered/proxy/network/pipeline/MinecraftCipherEncoder.java index 30dac4673..03b58b24e 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/network/pipeline/MinecraftCipherEncoder.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/network/pipeline/MinecraftCipherEncoder.java @@ -1,3 +1,20 @@ +/* + * 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 . + */ + package com.velocitypowered.proxy.network.pipeline; import com.google.common.base.Preconditions; diff --git a/proxy/src/main/java/com/velocitypowered/proxy/network/pipeline/MinecraftCompressDecoder.java b/proxy/src/main/java/com/velocitypowered/proxy/network/pipeline/MinecraftCompressDecoder.java index 1bc29da54..138403ff5 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/network/pipeline/MinecraftCompressDecoder.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/network/pipeline/MinecraftCompressDecoder.java @@ -1,3 +1,20 @@ +/* + * 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 . + */ + package com.velocitypowered.proxy.network.pipeline; import static com.velocitypowered.natives.util.MoreByteBufUtils.ensureCompatible; diff --git a/proxy/src/main/java/com/velocitypowered/proxy/network/pipeline/MinecraftCompressEncoder.java b/proxy/src/main/java/com/velocitypowered/proxy/network/pipeline/MinecraftCompressEncoder.java index 430bae6f7..b482b7320 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/network/pipeline/MinecraftCompressEncoder.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/network/pipeline/MinecraftCompressEncoder.java @@ -1,3 +1,20 @@ +/* + * 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 . + */ + package com.velocitypowered.proxy.network.pipeline; import com.velocitypowered.natives.compression.VelocityCompressor; diff --git a/proxy/src/main/java/com/velocitypowered/proxy/network/pipeline/MinecraftDecoder.java b/proxy/src/main/java/com/velocitypowered/proxy/network/pipeline/MinecraftDecoder.java index 91c335111..fc568602b 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/network/pipeline/MinecraftDecoder.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/network/pipeline/MinecraftDecoder.java @@ -1,3 +1,20 @@ +/* + * 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 . + */ + package com.velocitypowered.proxy.network.pipeline; import com.google.common.base.Preconditions; diff --git a/proxy/src/main/java/com/velocitypowered/proxy/network/pipeline/MinecraftEncoder.java b/proxy/src/main/java/com/velocitypowered/proxy/network/pipeline/MinecraftEncoder.java index 92ec80780..5931ef27f 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/network/pipeline/MinecraftEncoder.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/network/pipeline/MinecraftEncoder.java @@ -1,3 +1,20 @@ +/* + * 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 . + */ + package com.velocitypowered.proxy.network.pipeline; import com.google.common.base.Preconditions; diff --git a/proxy/src/main/java/com/velocitypowered/proxy/network/pipeline/MinecraftVarintFrameDecoder.java b/proxy/src/main/java/com/velocitypowered/proxy/network/pipeline/MinecraftVarintFrameDecoder.java index 7c45c28fa..ebe7faad9 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/network/pipeline/MinecraftVarintFrameDecoder.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/network/pipeline/MinecraftVarintFrameDecoder.java @@ -1,3 +1,20 @@ +/* + * 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 . + */ + package com.velocitypowered.proxy.network.pipeline; import com.velocitypowered.proxy.network.pipeline.VarintByteDecoder.DecodeResult; diff --git a/proxy/src/main/java/com/velocitypowered/proxy/network/pipeline/MinecraftVarintLengthEncoder.java b/proxy/src/main/java/com/velocitypowered/proxy/network/pipeline/MinecraftVarintLengthEncoder.java index 673bf065b..cfd66f505 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/network/pipeline/MinecraftVarintLengthEncoder.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/network/pipeline/MinecraftVarintLengthEncoder.java @@ -1,3 +1,20 @@ +/* + * 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 . + */ + package com.velocitypowered.proxy.network.pipeline; import com.velocitypowered.natives.encryption.JavaVelocityCipher; diff --git a/proxy/src/main/java/com/velocitypowered/proxy/network/pipeline/VarintByteDecoder.java b/proxy/src/main/java/com/velocitypowered/proxy/network/pipeline/VarintByteDecoder.java index 25f3b810f..e2cdb8345 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/network/pipeline/VarintByteDecoder.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/network/pipeline/VarintByteDecoder.java @@ -14,6 +14,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ + package com.velocitypowered.proxy.network.pipeline; import io.netty.util.ByteProcessor; diff --git a/proxy/src/main/java/com/velocitypowered/proxy/network/resolver/SeparatePoolInetNameResolver.java b/proxy/src/main/java/com/velocitypowered/proxy/network/resolver/SeparatePoolInetNameResolver.java index b1d695e19..0346eb27c 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/network/resolver/SeparatePoolInetNameResolver.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/network/resolver/SeparatePoolInetNameResolver.java @@ -1,3 +1,20 @@ +/* + * 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 . + */ + package com.velocitypowered.proxy.network.resolver; import com.google.common.cache.Cache; diff --git a/proxy/src/main/java/com/velocitypowered/proxy/network/serialization/FaviconSerializer.java b/proxy/src/main/java/com/velocitypowered/proxy/network/serialization/FaviconSerializer.java index 818c76103..93a26ec9c 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/network/serialization/FaviconSerializer.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/network/serialization/FaviconSerializer.java @@ -1,3 +1,20 @@ +/* + * 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 . + */ + package com.velocitypowered.proxy.network.serialization; import com.google.gson.JsonDeserializationContext; diff --git a/proxy/src/main/java/com/velocitypowered/proxy/network/serialization/GameProfileSerializer.java b/proxy/src/main/java/com/velocitypowered/proxy/network/serialization/GameProfileSerializer.java index 96de26103..a0314be12 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/network/serialization/GameProfileSerializer.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/network/serialization/GameProfileSerializer.java @@ -15,7 +15,7 @@ * along with this program. If not, see . */ -package com.velocitypowered.proxy.protocol.util; +package com.velocitypowered.proxy.network.serialization; import com.google.gson.JsonDeserializationContext; import com.google.gson.JsonDeserializer; diff --git a/proxy/src/main/java/com/velocitypowered/proxy/network/serialization/brigadier/ByteArgumentPropertySerializer.java b/proxy/src/main/java/com/velocitypowered/proxy/network/serialization/brigadier/ByteArgumentPropertySerializer.java index 6f037fc0f..79e9ebd58 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/network/serialization/brigadier/ByteArgumentPropertySerializer.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/network/serialization/brigadier/ByteArgumentPropertySerializer.java @@ -1,3 +1,20 @@ +/* + * 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 . + */ + package com.velocitypowered.proxy.network.serialization.brigadier; import io.netty.buffer.ByteBuf; diff --git a/proxy/src/main/java/com/velocitypowered/proxy/network/serialization/brigadier/DoubleArgumentPropertySerializer.java b/proxy/src/main/java/com/velocitypowered/proxy/network/serialization/brigadier/DoubleArgumentPropertySerializer.java index 3ce325766..922d6567c 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/network/serialization/brigadier/DoubleArgumentPropertySerializer.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/network/serialization/brigadier/DoubleArgumentPropertySerializer.java @@ -1,3 +1,20 @@ +/* + * 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 . + */ + package com.velocitypowered.proxy.network.serialization.brigadier; import static com.velocitypowered.proxy.network.serialization.brigadier.IntegerArgumentPropertySerializer.HAS_MAXIMUM; diff --git a/proxy/src/main/java/com/velocitypowered/proxy/network/serialization/brigadier/EmptyArgumentPropertySerializer.java b/proxy/src/main/java/com/velocitypowered/proxy/network/serialization/brigadier/EmptyArgumentPropertySerializer.java index e8cdba120..d7d681a10 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/network/serialization/brigadier/EmptyArgumentPropertySerializer.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/network/serialization/brigadier/EmptyArgumentPropertySerializer.java @@ -1,3 +1,20 @@ +/* + * 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 . + */ + package com.velocitypowered.proxy.network.serialization.brigadier; import io.netty.buffer.ByteBuf; diff --git a/proxy/src/main/java/com/velocitypowered/proxy/network/serialization/brigadier/FloatArgumentPropertySerializer.java b/proxy/src/main/java/com/velocitypowered/proxy/network/serialization/brigadier/FloatArgumentPropertySerializer.java index f5c079697..9c5d75bbf 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/network/serialization/brigadier/FloatArgumentPropertySerializer.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/network/serialization/brigadier/FloatArgumentPropertySerializer.java @@ -1,3 +1,20 @@ +/* + * 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 . + */ + package com.velocitypowered.proxy.network.serialization.brigadier; import static com.velocitypowered.proxy.network.serialization.brigadier.IntegerArgumentPropertySerializer.HAS_MAXIMUM; diff --git a/proxy/src/main/java/com/velocitypowered/proxy/network/serialization/brigadier/GenericArgumentPropertySerializer.java b/proxy/src/main/java/com/velocitypowered/proxy/network/serialization/brigadier/GenericArgumentPropertySerializer.java index f25854eb5..9c838412a 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/network/serialization/brigadier/GenericArgumentPropertySerializer.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/network/serialization/brigadier/GenericArgumentPropertySerializer.java @@ -1,3 +1,20 @@ +/* + * 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 . + */ + package com.velocitypowered.proxy.network.serialization.brigadier; import com.mojang.brigadier.arguments.ArgumentType; diff --git a/proxy/src/main/java/com/velocitypowered/proxy/network/serialization/brigadier/IntegerArgumentPropertySerializer.java b/proxy/src/main/java/com/velocitypowered/proxy/network/serialization/brigadier/IntegerArgumentPropertySerializer.java index a4c09a390..5d2b90652 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/network/serialization/brigadier/IntegerArgumentPropertySerializer.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/network/serialization/brigadier/IntegerArgumentPropertySerializer.java @@ -1,3 +1,20 @@ +/* + * 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 . + */ + package com.velocitypowered.proxy.network.serialization.brigadier; import com.mojang.brigadier.arguments.IntegerArgumentType; diff --git a/proxy/src/main/java/com/velocitypowered/proxy/network/serialization/brigadier/LongArgumentPropertySerializer.java b/proxy/src/main/java/com/velocitypowered/proxy/network/serialization/brigadier/LongArgumentPropertySerializer.java index e63823836..e99d8feba 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/network/serialization/brigadier/LongArgumentPropertySerializer.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/network/serialization/brigadier/LongArgumentPropertySerializer.java @@ -1,3 +1,20 @@ +/* + * 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 . + */ + package com.velocitypowered.proxy.network.serialization.brigadier; import static com.velocitypowered.proxy.network.serialization.brigadier.IntegerArgumentPropertySerializer.HAS_MAXIMUM; diff --git a/proxy/src/main/java/com/velocitypowered/proxy/network/serialization/brigadier/ModArgumentProperty.java b/proxy/src/main/java/com/velocitypowered/proxy/network/serialization/brigadier/ModArgumentProperty.java index cf6283b26..a918b819f 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/network/serialization/brigadier/ModArgumentProperty.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/network/serialization/brigadier/ModArgumentProperty.java @@ -15,7 +15,7 @@ * along with this program. If not, see . */ -package com.velocitypowered.proxy.protocol.packet.brigadier; +package com.velocitypowered.proxy.network.serialization.brigadier; import com.mojang.brigadier.StringReader; import com.mojang.brigadier.arguments.ArgumentType; diff --git a/proxy/src/main/java/com/velocitypowered/proxy/network/serialization/brigadier/ModArgumentPropertySerializer.java b/proxy/src/main/java/com/velocitypowered/proxy/network/serialization/brigadier/ModArgumentPropertySerializer.java index e9b0c6dc4..d5027af7b 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/network/serialization/brigadier/ModArgumentPropertySerializer.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/network/serialization/brigadier/ModArgumentPropertySerializer.java @@ -1,3 +1,20 @@ +/* + * 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 . + */ + package com.velocitypowered.proxy.network.serialization.brigadier; import com.velocitypowered.proxy.network.ProtocolUtils; diff --git a/proxy/src/main/java/com/velocitypowered/proxy/network/serialization/brigadier/PassthroughProperty.java b/proxy/src/main/java/com/velocitypowered/proxy/network/serialization/brigadier/PassthroughProperty.java index 2a43df76a..55f6d73b4 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/network/serialization/brigadier/PassthroughProperty.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/network/serialization/brigadier/PassthroughProperty.java @@ -1,3 +1,20 @@ +/* + * 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 . + */ + package com.velocitypowered.proxy.network.serialization.brigadier; import com.mojang.brigadier.StringReader; diff --git a/proxy/src/main/java/com/velocitypowered/proxy/network/serialization/brigadier/StringArgumentPropertySerializer.java b/proxy/src/main/java/com/velocitypowered/proxy/network/serialization/brigadier/StringArgumentPropertySerializer.java index 3ec2e3911..7c6782c43 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/network/serialization/brigadier/StringArgumentPropertySerializer.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/network/serialization/brigadier/StringArgumentPropertySerializer.java @@ -1,3 +1,20 @@ +/* + * 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 . + */ + package com.velocitypowered.proxy.network.serialization.brigadier; import com.mojang.brigadier.arguments.StringArgumentType; diff --git a/proxy/src/test/java/com/velocitypowered/proxy/event/EventTest.java b/proxy/src/test/java/com/velocitypowered/proxy/event/EventTest.java index ae7590701..bd6941d45 100644 --- a/proxy/src/test/java/com/velocitypowered/proxy/event/EventTest.java +++ b/proxy/src/test/java/com/velocitypowered/proxy/event/EventTest.java @@ -1,3 +1,20 @@ +/* + * 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 . + */ + package com.velocitypowered.proxy.event; import static org.junit.jupiter.api.Assertions.assertEquals; diff --git a/proxy/src/test/java/com/velocitypowered/proxy/event/MockEventManager.java b/proxy/src/test/java/com/velocitypowered/proxy/event/MockEventManager.java index 6b937cda5..f71098d7e 100644 --- a/proxy/src/test/java/com/velocitypowered/proxy/event/MockEventManager.java +++ b/proxy/src/test/java/com/velocitypowered/proxy/event/MockEventManager.java @@ -1,3 +1,20 @@ +/* + * 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 . + */ + package com.velocitypowered.proxy.event; import com.velocitypowered.proxy.plugin.MockPluginManager; diff --git a/proxy/src/test/java/com/velocitypowered/proxy/network/PluginMessageUtilTest.java b/proxy/src/test/java/com/velocitypowered/proxy/network/PluginMessageUtilTest.java index 77cde9a7b..bc9031ffc 100644 --- a/proxy/src/test/java/com/velocitypowered/proxy/network/PluginMessageUtilTest.java +++ b/proxy/src/test/java/com/velocitypowered/proxy/network/PluginMessageUtilTest.java @@ -1,3 +1,20 @@ +/* + * 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 . + */ + package com.velocitypowered.proxy.network; import static org.junit.jupiter.api.Assertions.assertEquals; From c8519949bca1c8adc4f0d647d7f56120362dddba Mon Sep 17 00:00:00 2001 From: Andrew Steinborn Date: Fri, 16 Apr 2021 04:12:45 -0400 Subject: [PATCH 25/99] Configuate 4.0.0 is stable --- build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index 3506f0aa2..9f7823941 100644 --- a/build.gradle +++ b/build.gradle @@ -28,7 +28,7 @@ allprojects { nettyVersion = '4.1.59.Final' guavaVersion = '30.0-jre' checkerFrameworkVersion = '3.6.1' - configurateVersion = '4.0.0-SNAPSHOT' + configurateVersion = '4.0.0' getCurrentShortRevision = { new ByteArrayOutputStream().withStream { os -> From 730d385f02a86f4d34734c54ce46074eecd8272f Mon Sep 17 00:00:00 2001 From: Andrew Steinborn Date: Sat, 17 Apr 2021 03:50:10 -0400 Subject: [PATCH 26/99] Extract interfaces for all events. This is in preparation for moving to event-impl-gen. --- api/build.gradle | 4 - .../api/command/CommandManager.java | 4 +- .../event/command/CommandExecuteEvent.java | 63 +++---------- .../command/CommandExecuteEventImpl.java | 66 ++++++++++++++ .../command/PlayerAvailableCommandsEvent.java | 28 +----- .../PlayerAvailableCommandsEventImpl.java | 46 ++++++++++ .../connection/ConnectionHandshakeEvent.java | 21 +---- .../ConnectionHandshakeEventImpl.java | 34 +++++++ .../api/event/connection/ProxyPingEvent.java | 31 +------ .../event/connection/ProxyPingEventImpl.java | 49 ++++++++++ .../api/event/connection/ProxyQueryEvent.java | 47 ++-------- .../event/connection/ProxyQueryEventImpl.java | 85 ++++++++++++++++++ .../event/lifecycle/ProxyInitializeEvent.java | 6 +- .../lifecycle/ProxyInitializeEventImpl.java | 20 +++++ .../api/event/lifecycle/ProxyReloadEvent.java | 6 +- .../event/lifecycle/ProxyReloadEventImpl.java | 19 ++++ .../event/lifecycle/ProxyShutdownEvent.java | 6 +- .../lifecycle/ProxyShutdownEventImpl.java | 16 ++++ .../lifecycle/network/ListenerBoundEvent.java | 30 +------ .../network/ListenerBoundEventImpl.java | 44 +++++++++ .../network/ListenerClosedEvent.java | 30 +------ .../network/ListenerClosedEventImpl.java | 44 +++++++++ .../permission/PermissionsSetupEvent.java | 37 ++------ .../permission/PermissionsSetupEventImpl.java | 74 +++++++++++++++ .../api/event/player/DisconnectEvent.java | 31 +------ .../api/event/player/DisconnectEventImpl.java | 45 ++++++++++ .../event/player/GameProfileRequestEvent.java | 2 +- .../event/player/KickedFromServerEvent.java | 64 +++---------- .../player/KickedFromServerEventImpl.java | 89 +++++++++++++++++++ .../api/event/player/LoginEvent.java | 31 +------ .../api/event/player/LoginEventImpl.java | 49 ++++++++++ .../player/PlayerChannelRegisterEvent.java | 27 +----- .../PlayerChannelRegisterEventImpl.java | 46 ++++++++++ .../api/event/player/PlayerChatEvent.java | 50 ++--------- .../api/event/player/PlayerChatEventImpl.java | 62 +++++++++++++ .../PlayerChooseInitialServerEvent.java | 38 ++------ .../PlayerChooseInitialServerEventImpl.java | 61 +++++++++++++ .../api/event/player/PlayerModInfoEvent.java | 31 ++----- .../event/player/PlayerModInfoEventImpl.java | 42 +++++++++ .../player/PlayerResourcePackStatusEvent.java | 29 +----- .../PlayerResourcePackStatusEventImpl.java | 55 ++++++++++++ .../player/PlayerSettingsChangedEvent.java | 28 +----- .../PlayerSettingsChangedEventImpl.java | 42 +++++++++ .../api/event/player/PostLoginEvent.java | 20 +---- .../api/event/player/PostLoginEventImpl.java | 36 ++++++++ .../api/event/player/PreLoginEvent.java | 44 ++------- .../api/event/player/PreLoginEventImpl.java | 65 ++++++++++++++ .../event/player/ServerConnectedEvent.java | 42 +-------- .../player/ServerConnectedEventImpl.java | 62 +++++++++++++ .../event/player/ServerPostConnectEvent.java | 29 +----- .../player/ServerPostConnectEventImpl.java | 47 ++++++++++ .../event/player/ServerPreConnectEvent.java | 59 ++++-------- .../player/ServerPreConnectEventImpl.java | 73 +++++++++++++++ .../api/event/player/TabCompleteEvent.java | 44 ++------- .../event/player/TabCompleteEventImpl.java | 72 +++++++++++++++ .../api/proxy/connection/Player.java | 6 +- .../velocitypowered/proxy/VelocityServer.java | 12 +-- .../proxy/command/VelocityCommandManager.java | 5 +- .../backend/BackendPlaySessionHandler.java | 4 +- .../backend/TransitionSessionHandler.java | 8 +- .../client/ClientPlaySessionHandler.java | 17 ++-- .../connection/client/ConnectedPlayer.java | 20 +++-- .../client/HandshakeSessionHandler.java | 4 +- .../client/LoginSessionHandler.java | 22 ++--- .../client/StatusSessionHandler.java | 6 +- .../proxy/console/VelocityConsole.java | 3 +- .../proxy/network/ConnectionManager.java | 12 +-- .../network/pipeline/GS4QueryHandler.java | 4 +- 68 files changed, 1539 insertions(+), 809 deletions(-) create mode 100644 api/src/main/java/com/velocitypowered/api/event/command/CommandExecuteEventImpl.java create mode 100644 api/src/main/java/com/velocitypowered/api/event/command/PlayerAvailableCommandsEventImpl.java create mode 100644 api/src/main/java/com/velocitypowered/api/event/connection/ConnectionHandshakeEventImpl.java create mode 100644 api/src/main/java/com/velocitypowered/api/event/connection/ProxyPingEventImpl.java create mode 100644 api/src/main/java/com/velocitypowered/api/event/connection/ProxyQueryEventImpl.java create mode 100644 api/src/main/java/com/velocitypowered/api/event/lifecycle/ProxyInitializeEventImpl.java create mode 100644 api/src/main/java/com/velocitypowered/api/event/lifecycle/ProxyReloadEventImpl.java create mode 100644 api/src/main/java/com/velocitypowered/api/event/lifecycle/ProxyShutdownEventImpl.java create mode 100644 api/src/main/java/com/velocitypowered/api/event/lifecycle/network/ListenerBoundEventImpl.java create mode 100644 api/src/main/java/com/velocitypowered/api/event/lifecycle/network/ListenerClosedEventImpl.java create mode 100644 api/src/main/java/com/velocitypowered/api/event/permission/PermissionsSetupEventImpl.java create mode 100644 api/src/main/java/com/velocitypowered/api/event/player/DisconnectEventImpl.java create mode 100644 api/src/main/java/com/velocitypowered/api/event/player/KickedFromServerEventImpl.java create mode 100644 api/src/main/java/com/velocitypowered/api/event/player/LoginEventImpl.java create mode 100644 api/src/main/java/com/velocitypowered/api/event/player/PlayerChannelRegisterEventImpl.java create mode 100644 api/src/main/java/com/velocitypowered/api/event/player/PlayerChatEventImpl.java create mode 100644 api/src/main/java/com/velocitypowered/api/event/player/PlayerChooseInitialServerEventImpl.java create mode 100644 api/src/main/java/com/velocitypowered/api/event/player/PlayerModInfoEventImpl.java create mode 100644 api/src/main/java/com/velocitypowered/api/event/player/PlayerResourcePackStatusEventImpl.java create mode 100644 api/src/main/java/com/velocitypowered/api/event/player/PlayerSettingsChangedEventImpl.java create mode 100644 api/src/main/java/com/velocitypowered/api/event/player/PostLoginEventImpl.java create mode 100644 api/src/main/java/com/velocitypowered/api/event/player/PreLoginEventImpl.java create mode 100644 api/src/main/java/com/velocitypowered/api/event/player/ServerConnectedEventImpl.java create mode 100644 api/src/main/java/com/velocitypowered/api/event/player/ServerPostConnectEventImpl.java create mode 100644 api/src/main/java/com/velocitypowered/api/event/player/ServerPreConnectEventImpl.java create mode 100644 api/src/main/java/com/velocitypowered/api/event/player/TabCompleteEventImpl.java diff --git a/api/build.gradle b/api/build.gradle index 3a518caef..a7e2c2298 100644 --- a/api/build.gradle +++ b/api/build.gradle @@ -100,10 +100,6 @@ test { useJUnitPlatform() } -test { - useJUnitPlatform() -} - publishing { publications { mavenJava(MavenPublication) { diff --git a/api/src/main/java/com/velocitypowered/api/command/CommandManager.java b/api/src/main/java/com/velocitypowered/api/command/CommandManager.java index b8f14fe8e..1ee80e97b 100644 --- a/api/src/main/java/com/velocitypowered/api/command/CommandManager.java +++ b/api/src/main/java/com/velocitypowered/api/command/CommandManager.java @@ -7,7 +7,7 @@ package com.velocitypowered.api.command; -import com.velocitypowered.api.event.command.CommandExecuteEvent; +import com.velocitypowered.api.event.command.CommandExecuteEventImpl; import java.util.concurrent.CompletableFuture; /** @@ -81,7 +81,7 @@ public interface CommandManager { /** * Attempts to asynchronously execute a command from the given {@code cmdLine} - * without firing a {@link CommandExecuteEvent}. + * without firing a {@link CommandExecuteEventImpl}. * * @param source the source to execute the command for * @param cmdLine the command to run diff --git a/api/src/main/java/com/velocitypowered/api/event/command/CommandExecuteEvent.java b/api/src/main/java/com/velocitypowered/api/event/command/CommandExecuteEvent.java index 72ee2f8cd..94dc9c1d3 100644 --- a/api/src/main/java/com/velocitypowered/api/event/command/CommandExecuteEvent.java +++ b/api/src/main/java/com/velocitypowered/api/event/command/CommandExecuteEvent.java @@ -16,63 +16,22 @@ import org.checkerframework.checker.nullness.qual.NonNull; import org.checkerframework.checker.nullness.qual.Nullable; /** - * This event is fired when someone executing command. + * This event is fired when someone executes a command. */ -public final class CommandExecuteEvent implements ResultedEvent { +public interface CommandExecuteEvent extends ResultedEvent { - private final CommandSource commandSource; - private final String command; - private CommandResult result; + CommandSource getCommandSource(); /** - * Constructs a CommandExecuteEvent. - * @param commandSource the source executing the command - * @param command the command being executed without first slash - */ - public CommandExecuteEvent(CommandSource commandSource, String command) { - this.commandSource = Preconditions.checkNotNull(commandSource, "commandSource"); - this.command = Preconditions.checkNotNull(command, "command"); - this.result = CommandResult.allowed(); - } - - public CommandSource getCommandSource() { - return commandSource; - } - - /** - * Gets the original command being executed without first slash. + * Gets the original command being executed without the first slash. * @return the original command being executed */ - public String getCommand() { - return command; - } + String getCommand(); - @Override - public CommandResult getResult() { - return result; - } + final class CommandResult implements ResultedEvent.Result { - @Override - public void setResult(CommandResult result) { - this.result = Preconditions.checkNotNull(result, "result"); - } - - @Override - public String toString() { - return "CommandExecuteEvent{" - + "commandSource=" + commandSource - + ", command=" + command - + ", result=" + result - + '}'; - } - - /** - * Represents the result of the {@link CommandExecuteEvent}. - */ - public static final class CommandResult implements ResultedEvent.Result { - - private static final CommandResult ALLOWED = new CommandResult(true, false,null); - private static final CommandResult DENIED = new CommandResult(false, false,null); + private static final CommandResult ALLOWED = new CommandResult(true, false, null); + private static final CommandResult DENIED = new CommandResult(false, false, null); private static final CommandResult FORWARD_TO_SERVER = new CommandResult(false, true, null); private @Nullable String command; @@ -105,6 +64,7 @@ public final class CommandExecuteEvent implements ResultedEvent { /** * Allows the command to be sent, without modification. + * * @return the allowed result */ public static CommandResult allowed() { @@ -113,6 +73,7 @@ public final class CommandExecuteEvent implements ResultedEvent { /** * Prevents the command from being executed. + * * @return the denied result */ public static CommandResult denied() { @@ -121,6 +82,7 @@ public final class CommandExecuteEvent implements ResultedEvent { /** * Prevents the command from being executed, but forward command to server. + * * @return the forward result */ public static CommandResult forwardToServer() { @@ -129,6 +91,7 @@ public final class CommandExecuteEvent implements ResultedEvent { /** * Prevents the command from being executed on proxy, but forward command to server. + * * @param newCommand the command without first slash to use instead * @return a result with a new command being forwarded to server */ @@ -139,6 +102,7 @@ public final class CommandExecuteEvent implements ResultedEvent { /** * Allows the command to be executed, but silently replaced old command with another. + * * @param newCommand the command to use instead without first slash * @return a result with a new command */ @@ -147,4 +111,5 @@ public final class CommandExecuteEvent implements ResultedEvent { return new CommandResult(true, false, newCommand); } } + } diff --git a/api/src/main/java/com/velocitypowered/api/event/command/CommandExecuteEventImpl.java b/api/src/main/java/com/velocitypowered/api/event/command/CommandExecuteEventImpl.java new file mode 100644 index 000000000..672b93522 --- /dev/null +++ b/api/src/main/java/com/velocitypowered/api/event/command/CommandExecuteEventImpl.java @@ -0,0 +1,66 @@ +/* + * Copyright (C) 2018 Velocity Contributors + * + * The Velocity API is licensed under the terms of the MIT License. For more details, + * reference the LICENSE file in the api top-level directory. + */ + +package com.velocitypowered.api.event.command; + +import com.google.common.base.Preconditions; +import com.velocitypowered.api.command.CommandSource; + +/** + * This event is fired when someone executing command. + */ +public final class CommandExecuteEventImpl implements CommandExecuteEvent { + + private final CommandSource commandSource; + private final String command; + private CommandResult result; + + /** + * Constructs a CommandExecuteEvent. + * @param commandSource the source executing the command + * @param command the command being executed without first slash + */ + public CommandExecuteEventImpl(CommandSource commandSource, String command) { + this.commandSource = Preconditions.checkNotNull(commandSource, "commandSource"); + this.command = Preconditions.checkNotNull(command, "command"); + this.result = CommandResult.allowed(); + } + + @Override + public CommandSource getCommandSource() { + return commandSource; + } + + /** + * Gets the original command being executed without first slash. + * @return the original command being executed + */ + @Override + public String getCommand() { + return command; + } + + @Override + public CommandResult getResult() { + return result; + } + + @Override + public void setResult(CommandResult result) { + this.result = Preconditions.checkNotNull(result, "result"); + } + + @Override + public String toString() { + return "CommandExecuteEvent{" + + "commandSource=" + commandSource + + ", command=" + command + + ", result=" + result + + '}'; + } + +} diff --git a/api/src/main/java/com/velocitypowered/api/event/command/PlayerAvailableCommandsEvent.java b/api/src/main/java/com/velocitypowered/api/event/command/PlayerAvailableCommandsEvent.java index e0aa0eeb5..1948beec2 100644 --- a/api/src/main/java/com/velocitypowered/api/event/command/PlayerAvailableCommandsEvent.java +++ b/api/src/main/java/com/velocitypowered/api/event/command/PlayerAvailableCommandsEvent.java @@ -7,9 +7,6 @@ package com.velocitypowered.api.event.command; -import static com.google.common.base.Preconditions.checkNotNull; - -import com.google.common.annotations.Beta; import com.mojang.brigadier.tree.RootCommandNode; import com.velocitypowered.api.proxy.connection.Player; @@ -17,28 +14,9 @@ import com.velocitypowered.api.proxy.connection.Player; * Allows plugins to modify the packet indicating commands available on the server to a * Minecraft 1.13+ client. */ -@Beta -public class PlayerAvailableCommandsEvent { +public interface PlayerAvailableCommandsEvent { - private final Player player; - private final RootCommandNode rootNode; + Player getPlayer(); - /** - * Constructs an available commands event. - * @param player the targeted player - * @param rootNode the Brigadier root node - */ - public PlayerAvailableCommandsEvent(Player player, - RootCommandNode rootNode) { - this.player = checkNotNull(player, "player"); - this.rootNode = checkNotNull(rootNode, "rootNode"); - } - - public Player getPlayer() { - return player; - } - - public RootCommandNode getRootNode() { - return rootNode; - } + RootCommandNode getRootNode(); } diff --git a/api/src/main/java/com/velocitypowered/api/event/command/PlayerAvailableCommandsEventImpl.java b/api/src/main/java/com/velocitypowered/api/event/command/PlayerAvailableCommandsEventImpl.java new file mode 100644 index 000000000..926d94c17 --- /dev/null +++ b/api/src/main/java/com/velocitypowered/api/event/command/PlayerAvailableCommandsEventImpl.java @@ -0,0 +1,46 @@ +/* + * Copyright (C) 2018 Velocity Contributors + * + * The Velocity API is licensed under the terms of the MIT License. For more details, + * reference the LICENSE file in the api top-level directory. + */ + +package com.velocitypowered.api.event.command; + +import static com.google.common.base.Preconditions.checkNotNull; + +import com.google.common.annotations.Beta; +import com.mojang.brigadier.tree.RootCommandNode; +import com.velocitypowered.api.proxy.connection.Player; + +/** + * Allows plugins to modify the packet indicating commands available on the server to a + * Minecraft 1.13+ client. + */ +@Beta +public class PlayerAvailableCommandsEventImpl implements PlayerAvailableCommandsEvent { + + private final Player player; + private final RootCommandNode rootNode; + + /** + * Constructs an available commands event. + * @param player the targeted player + * @param rootNode the Brigadier root node + */ + public PlayerAvailableCommandsEventImpl(Player player, + RootCommandNode rootNode) { + this.player = checkNotNull(player, "player"); + this.rootNode = checkNotNull(rootNode, "rootNode"); + } + + @Override + public Player getPlayer() { + return player; + } + + @Override + public RootCommandNode getRootNode() { + return rootNode; + } +} diff --git a/api/src/main/java/com/velocitypowered/api/event/connection/ConnectionHandshakeEvent.java b/api/src/main/java/com/velocitypowered/api/event/connection/ConnectionHandshakeEvent.java index baa008286..166981316 100644 --- a/api/src/main/java/com/velocitypowered/api/event/connection/ConnectionHandshakeEvent.java +++ b/api/src/main/java/com/velocitypowered/api/event/connection/ConnectionHandshakeEvent.java @@ -7,28 +7,9 @@ package com.velocitypowered.api.event.connection; -import com.google.common.base.Preconditions; -import com.velocitypowered.api.proxy.connection.InboundConnection; - /** * This event is fired when a handshake is established between a client and the proxy. */ -public final class ConnectionHandshakeEvent { +public interface ConnectionHandshakeEvent { - private final InboundConnection connection; - - public ConnectionHandshakeEvent(InboundConnection connection) { - this.connection = Preconditions.checkNotNull(connection, "connection"); - } - - public InboundConnection getConnection() { - return connection; - } - - @Override - public String toString() { - return "ConnectionHandshakeEvent{" - + "connection=" + connection - + '}'; - } } diff --git a/api/src/main/java/com/velocitypowered/api/event/connection/ConnectionHandshakeEventImpl.java b/api/src/main/java/com/velocitypowered/api/event/connection/ConnectionHandshakeEventImpl.java new file mode 100644 index 000000000..a87dbb926 --- /dev/null +++ b/api/src/main/java/com/velocitypowered/api/event/connection/ConnectionHandshakeEventImpl.java @@ -0,0 +1,34 @@ +/* + * Copyright (C) 2018 Velocity Contributors + * + * The Velocity API is licensed under the terms of the MIT License. For more details, + * reference the LICENSE file in the api top-level directory. + */ + +package com.velocitypowered.api.event.connection; + +import com.google.common.base.Preconditions; +import com.velocitypowered.api.proxy.connection.InboundConnection; + +/** + * This event is fired when a handshake is established between a client and the proxy. + */ +public final class ConnectionHandshakeEventImpl implements ConnectionHandshakeEvent { + + private final InboundConnection connection; + + public ConnectionHandshakeEventImpl(InboundConnection connection) { + this.connection = Preconditions.checkNotNull(connection, "connection"); + } + + public InboundConnection getConnection() { + return connection; + } + + @Override + public String toString() { + return "ConnectionHandshakeEvent{" + + "connection=" + connection + + '}'; + } +} diff --git a/api/src/main/java/com/velocitypowered/api/event/connection/ProxyPingEvent.java b/api/src/main/java/com/velocitypowered/api/event/connection/ProxyPingEvent.java index edf76f260..be31a0098 100644 --- a/api/src/main/java/com/velocitypowered/api/event/connection/ProxyPingEvent.java +++ b/api/src/main/java/com/velocitypowered/api/event/connection/ProxyPingEvent.java @@ -7,40 +7,17 @@ package com.velocitypowered.api.event.connection; -import com.google.common.base.Preconditions; import com.velocitypowered.api.proxy.connection.InboundConnection; import com.velocitypowered.api.proxy.server.ServerPing; /** * This event is fired when a server list ping request is sent by a remote client. */ -public final class ProxyPingEvent { +public interface ProxyPingEvent { - private final InboundConnection connection; - private ServerPing ping; + InboundConnection getConnection(); - public ProxyPingEvent(InboundConnection connection, ServerPing ping) { - this.connection = Preconditions.checkNotNull(connection, "connection"); - this.ping = Preconditions.checkNotNull(ping, "ping"); - } + ServerPing getPing(); - public InboundConnection getConnection() { - return connection; - } - - public ServerPing getPing() { - return ping; - } - - public void setPing(ServerPing ping) { - this.ping = Preconditions.checkNotNull(ping, "ping"); - } - - @Override - public String toString() { - return "ProxyPingEvent{" - + "connection=" + connection - + ", ping=" + ping - + '}'; - } + void setPing(ServerPing ping); } diff --git a/api/src/main/java/com/velocitypowered/api/event/connection/ProxyPingEventImpl.java b/api/src/main/java/com/velocitypowered/api/event/connection/ProxyPingEventImpl.java new file mode 100644 index 000000000..49284e165 --- /dev/null +++ b/api/src/main/java/com/velocitypowered/api/event/connection/ProxyPingEventImpl.java @@ -0,0 +1,49 @@ +/* + * Copyright (C) 2018 Velocity Contributors + * + * The Velocity API is licensed under the terms of the MIT License. For more details, + * reference the LICENSE file in the api top-level directory. + */ + +package com.velocitypowered.api.event.connection; + +import com.google.common.base.Preconditions; +import com.velocitypowered.api.proxy.connection.InboundConnection; +import com.velocitypowered.api.proxy.server.ServerPing; + +/** + * This event is fired when a server list ping request is sent by a remote client. + */ +public final class ProxyPingEventImpl implements ProxyPingEvent { + + private final InboundConnection connection; + private ServerPing ping; + + public ProxyPingEventImpl(InboundConnection connection, ServerPing ping) { + this.connection = Preconditions.checkNotNull(connection, "connection"); + this.ping = Preconditions.checkNotNull(ping, "ping"); + } + + @Override + public InboundConnection getConnection() { + return connection; + } + + @Override + public ServerPing getPing() { + return ping; + } + + @Override + public void setPing(ServerPing ping) { + this.ping = Preconditions.checkNotNull(ping, "ping"); + } + + @Override + public String toString() { + return "ProxyPingEvent{" + + "connection=" + connection + + ", ping=" + ping + + '}'; + } +} diff --git a/api/src/main/java/com/velocitypowered/api/event/connection/ProxyQueryEvent.java b/api/src/main/java/com/velocitypowered/api/event/connection/ProxyQueryEvent.java index daba17517..4f2b1b2c2 100644 --- a/api/src/main/java/com/velocitypowered/api/event/connection/ProxyQueryEvent.java +++ b/api/src/main/java/com/velocitypowered/api/event/connection/ProxyQueryEvent.java @@ -7,81 +7,46 @@ package com.velocitypowered.api.event.connection; -import com.google.common.base.Preconditions; import com.velocitypowered.api.proxy.server.QueryResponse; import java.net.InetAddress; /** * This event is fired if proxy is getting queried over GS4 Query protocol. */ -public final class ProxyQueryEvent { - - private final QueryType queryType; - private final InetAddress querierAddress; - private QueryResponse response; - - /** - * Creates a new event. - * - * @param queryType the type of query - * @param querierAddress the remote address for the query - * @param response the current query response - */ - public ProxyQueryEvent(QueryType queryType, InetAddress querierAddress, QueryResponse response) { - this.queryType = Preconditions.checkNotNull(queryType, "queryType"); - this.querierAddress = Preconditions.checkNotNull(querierAddress, "querierAddress"); - this.response = Preconditions.checkNotNull(response, "response"); - } +public interface ProxyQueryEvent { /** * Returns the kind of query the remote client is performing. * * @return query type */ - public QueryType getQueryType() { - return queryType; - } + QueryType getQueryType(); /** * Get the address of the client that sent this query. * * @return querier address */ - public InetAddress getQuerierAddress() { - return querierAddress; - } + InetAddress getQuerierAddress(); /** * Returns the current query response. * * @return the current query response */ - public QueryResponse getResponse() { - return response; - } + QueryResponse getResponse(); /** * Sets a new query response. * * @param response the new non-null query response */ - public void setResponse(QueryResponse response) { - this.response = Preconditions.checkNotNull(response, "response"); - } - - @Override - public String toString() { - return "ProxyQueryEvent{" - + "queryType=" + queryType - + ", querierAddress=" + querierAddress - + ", response=" + response - + '}'; - } + void setResponse(QueryResponse response); /** * Represents the type of query the client is asking for. */ - public enum QueryType { + enum QueryType { /** * Basic query asks only a subset of information, such as hostname, game type (hardcoded to *
MINECRAFT
), map, current players, max players, proxy port and proxy hostname. diff --git a/api/src/main/java/com/velocitypowered/api/event/connection/ProxyQueryEventImpl.java b/api/src/main/java/com/velocitypowered/api/event/connection/ProxyQueryEventImpl.java new file mode 100644 index 000000000..7d7b23ea2 --- /dev/null +++ b/api/src/main/java/com/velocitypowered/api/event/connection/ProxyQueryEventImpl.java @@ -0,0 +1,85 @@ +/* + * Copyright (C) 2018 Velocity Contributors + * + * The Velocity API is licensed under the terms of the MIT License. For more details, + * reference the LICENSE file in the api top-level directory. + */ + +package com.velocitypowered.api.event.connection; + +import com.google.common.base.Preconditions; +import com.velocitypowered.api.proxy.server.QueryResponse; +import java.net.InetAddress; + +/** + * This event is fired if proxy is getting queried over GS4 Query protocol. + */ +public final class ProxyQueryEventImpl implements ProxyQueryEvent { + + private final QueryType queryType; + private final InetAddress querierAddress; + private QueryResponse response; + + /** + * Creates a new event. + * + * @param queryType the type of query + * @param querierAddress the remote address for the query + * @param response the current query response + */ + public ProxyQueryEventImpl(QueryType queryType, InetAddress querierAddress, QueryResponse response) { + this.queryType = Preconditions.checkNotNull(queryType, "queryType"); + this.querierAddress = Preconditions.checkNotNull(querierAddress, "querierAddress"); + this.response = Preconditions.checkNotNull(response, "response"); + } + + /** + * Returns the kind of query the remote client is performing. + * + * @return query type + */ + @Override + public QueryType getQueryType() { + return queryType; + } + + /** + * Get the address of the client that sent this query. + * + * @return querier address + */ + @Override + public InetAddress getQuerierAddress() { + return querierAddress; + } + + /** + * Returns the current query response. + * + * @return the current query response + */ + @Override + public QueryResponse getResponse() { + return response; + } + + /** + * Sets a new query response. + * + * @param response the new non-null query response + */ + @Override + public void setResponse(QueryResponse response) { + this.response = Preconditions.checkNotNull(response, "response"); + } + + @Override + public String toString() { + return "ProxyQueryEvent{" + + "queryType=" + queryType + + ", querierAddress=" + querierAddress + + ", response=" + response + + '}'; + } + +} diff --git a/api/src/main/java/com/velocitypowered/api/event/lifecycle/ProxyInitializeEvent.java b/api/src/main/java/com/velocitypowered/api/event/lifecycle/ProxyInitializeEvent.java index bb4ee1aa1..046ff239a 100644 --- a/api/src/main/java/com/velocitypowered/api/event/lifecycle/ProxyInitializeEvent.java +++ b/api/src/main/java/com/velocitypowered/api/event/lifecycle/ProxyInitializeEvent.java @@ -11,10 +11,6 @@ package com.velocitypowered.api.event.lifecycle; * This event is fired by the proxy after plugins have been loaded but before the proxy starts * accepting connections. */ -public final class ProxyInitializeEvent { +public interface ProxyInitializeEvent { - @Override - public String toString() { - return "ProxyInitializeEvent"; - } } diff --git a/api/src/main/java/com/velocitypowered/api/event/lifecycle/ProxyInitializeEventImpl.java b/api/src/main/java/com/velocitypowered/api/event/lifecycle/ProxyInitializeEventImpl.java new file mode 100644 index 000000000..a03c85167 --- /dev/null +++ b/api/src/main/java/com/velocitypowered/api/event/lifecycle/ProxyInitializeEventImpl.java @@ -0,0 +1,20 @@ +/* + * Copyright (C) 2018 Velocity Contributors + * + * The Velocity API is licensed under the terms of the MIT License. For more details, + * reference the LICENSE file in the api top-level directory. + */ + +package com.velocitypowered.api.event.lifecycle; + +/** + * This event is fired by the proxy after plugins have been loaded but before the proxy starts + * accepting connections. + */ +public final class ProxyInitializeEventImpl implements ProxyInitializeEvent { + + @Override + public String toString() { + return "ProxyInitializeEvent"; + } +} diff --git a/api/src/main/java/com/velocitypowered/api/event/lifecycle/ProxyReloadEvent.java b/api/src/main/java/com/velocitypowered/api/event/lifecycle/ProxyReloadEvent.java index 063aede14..763cee952 100644 --- a/api/src/main/java/com/velocitypowered/api/event/lifecycle/ProxyReloadEvent.java +++ b/api/src/main/java/com/velocitypowered/api/event/lifecycle/ProxyReloadEvent.java @@ -10,10 +10,6 @@ package com.velocitypowered.api.event.lifecycle; /** * This event is fired when the proxy is reloaded by the user using {@code /velocity reload}. */ -public class ProxyReloadEvent { +public interface ProxyReloadEvent { - @Override - public String toString() { - return "ProxyReloadEvent"; - } } diff --git a/api/src/main/java/com/velocitypowered/api/event/lifecycle/ProxyReloadEventImpl.java b/api/src/main/java/com/velocitypowered/api/event/lifecycle/ProxyReloadEventImpl.java new file mode 100644 index 000000000..4e79a7be4 --- /dev/null +++ b/api/src/main/java/com/velocitypowered/api/event/lifecycle/ProxyReloadEventImpl.java @@ -0,0 +1,19 @@ +/* + * Copyright (C) 2018 Velocity Contributors + * + * The Velocity API is licensed under the terms of the MIT License. For more details, + * reference the LICENSE file in the api top-level directory. + */ + +package com.velocitypowered.api.event.lifecycle; + +/** + * This event is fired when the proxy is reloaded by the user using {@code /velocity reload}. + */ +public class ProxyReloadEventImpl implements ProxyReloadEvent { + + @Override + public String toString() { + return "ProxyReloadEvent"; + } +} diff --git a/api/src/main/java/com/velocitypowered/api/event/lifecycle/ProxyShutdownEvent.java b/api/src/main/java/com/velocitypowered/api/event/lifecycle/ProxyShutdownEvent.java index 3a540b989..cb0118907 100644 --- a/api/src/main/java/com/velocitypowered/api/event/lifecycle/ProxyShutdownEvent.java +++ b/api/src/main/java/com/velocitypowered/api/event/lifecycle/ProxyShutdownEvent.java @@ -11,10 +11,6 @@ package com.velocitypowered.api.event.lifecycle; * This event is fired by the proxy after the proxy has stopped accepting connections but before the * proxy process exits. */ -public final class ProxyShutdownEvent { +public interface ProxyShutdownEvent { - @Override - public String toString() { - return "ProxyShutdownEvent"; - } } diff --git a/api/src/main/java/com/velocitypowered/api/event/lifecycle/ProxyShutdownEventImpl.java b/api/src/main/java/com/velocitypowered/api/event/lifecycle/ProxyShutdownEventImpl.java new file mode 100644 index 000000000..15b35ce39 --- /dev/null +++ b/api/src/main/java/com/velocitypowered/api/event/lifecycle/ProxyShutdownEventImpl.java @@ -0,0 +1,16 @@ +/* + * Copyright (C) 2018 Velocity Contributors + * + * The Velocity API is licensed under the terms of the MIT License. For more details, + * reference the LICENSE file in the api top-level directory. + */ + +package com.velocitypowered.api.event.lifecycle; + +public final class ProxyShutdownEventImpl implements ProxyShutdownEvent { + + @Override + public String toString() { + return "ProxyShutdownEvent"; + } +} diff --git a/api/src/main/java/com/velocitypowered/api/event/lifecycle/network/ListenerBoundEvent.java b/api/src/main/java/com/velocitypowered/api/event/lifecycle/network/ListenerBoundEvent.java index 2c226820f..e43fd51ed 100644 --- a/api/src/main/java/com/velocitypowered/api/event/lifecycle/network/ListenerBoundEvent.java +++ b/api/src/main/java/com/velocitypowered/api/event/lifecycle/network/ListenerBoundEvent.java @@ -7,37 +7,15 @@ package com.velocitypowered.api.event.lifecycle.network; -import com.google.common.base.Preconditions; import com.velocitypowered.api.network.ListenerType; -import java.net.InetSocketAddress; import java.net.SocketAddress; /** * This event is fired by the proxy after a listener starts accepting connections. */ -public final class ListenerBoundEvent { +public interface ListenerBoundEvent { - private final SocketAddress address; - private final ListenerType listenerType; + SocketAddress getAddress(); - public ListenerBoundEvent(SocketAddress address, ListenerType listenerType) { - this.address = Preconditions.checkNotNull(address, "address"); - this.listenerType = Preconditions.checkNotNull(listenerType, "listenerType"); - } - - public SocketAddress getAddress() { - return address; - } - - public ListenerType getListenerType() { - return listenerType; - } - - @Override - public String toString() { - return "ListenerBoundEvent{" - + "address=" + address - + ", listenerType=" + listenerType - + '}'; - } -} \ No newline at end of file + ListenerType getListenerType(); +} diff --git a/api/src/main/java/com/velocitypowered/api/event/lifecycle/network/ListenerBoundEventImpl.java b/api/src/main/java/com/velocitypowered/api/event/lifecycle/network/ListenerBoundEventImpl.java new file mode 100644 index 000000000..c4a498a67 --- /dev/null +++ b/api/src/main/java/com/velocitypowered/api/event/lifecycle/network/ListenerBoundEventImpl.java @@ -0,0 +1,44 @@ +/* + * Copyright (C) 2018 Velocity Contributors + * + * The Velocity API is licensed under the terms of the MIT License. For more details, + * reference the LICENSE file in the api top-level directory. + */ + +package com.velocitypowered.api.event.lifecycle.network; + +import com.google.common.base.Preconditions; +import com.velocitypowered.api.network.ListenerType; +import java.net.SocketAddress; + +/** + * This event is fired by the proxy after a listener starts accepting connections. + */ +public final class ListenerBoundEventImpl implements ListenerBoundEvent { + + private final SocketAddress address; + private final ListenerType listenerType; + + public ListenerBoundEventImpl(SocketAddress address, ListenerType listenerType) { + this.address = Preconditions.checkNotNull(address, "address"); + this.listenerType = Preconditions.checkNotNull(listenerType, "listenerType"); + } + + @Override + public SocketAddress getAddress() { + return address; + } + + @Override + public ListenerType getListenerType() { + return listenerType; + } + + @Override + public String toString() { + return "ListenerBoundEvent{" + + "address=" + address + + ", listenerType=" + listenerType + + '}'; + } +} \ No newline at end of file diff --git a/api/src/main/java/com/velocitypowered/api/event/lifecycle/network/ListenerClosedEvent.java b/api/src/main/java/com/velocitypowered/api/event/lifecycle/network/ListenerClosedEvent.java index 96eeffaa4..3a607a0af 100644 --- a/api/src/main/java/com/velocitypowered/api/event/lifecycle/network/ListenerClosedEvent.java +++ b/api/src/main/java/com/velocitypowered/api/event/lifecycle/network/ListenerClosedEvent.java @@ -7,37 +7,15 @@ package com.velocitypowered.api.event.lifecycle.network; -import com.google.common.base.Preconditions; import com.velocitypowered.api.network.ListenerType; -import java.net.InetSocketAddress; import java.net.SocketAddress; /** * This event is fired by the proxy before the proxy stops accepting connections. */ -public final class ListenerClosedEvent { +public interface ListenerClosedEvent { - private final SocketAddress address; - private final ListenerType listenerType; + SocketAddress getAddress(); - public ListenerClosedEvent(SocketAddress address, ListenerType listenerType) { - this.address = Preconditions.checkNotNull(address, "address"); - this.listenerType = Preconditions.checkNotNull(listenerType, "listenerType"); - } - - public SocketAddress getAddress() { - return address; - } - - public ListenerType getListenerType() { - return listenerType; - } - - @Override - public String toString() { - return "ListenerCloseEvent{" - + "address=" + address - + ", listenerType=" + listenerType - + '}'; - } -} \ No newline at end of file + ListenerType getListenerType(); +} diff --git a/api/src/main/java/com/velocitypowered/api/event/lifecycle/network/ListenerClosedEventImpl.java b/api/src/main/java/com/velocitypowered/api/event/lifecycle/network/ListenerClosedEventImpl.java new file mode 100644 index 000000000..eec5f56e7 --- /dev/null +++ b/api/src/main/java/com/velocitypowered/api/event/lifecycle/network/ListenerClosedEventImpl.java @@ -0,0 +1,44 @@ +/* + * Copyright (C) 2018 Velocity Contributors + * + * The Velocity API is licensed under the terms of the MIT License. For more details, + * reference the LICENSE file in the api top-level directory. + */ + +package com.velocitypowered.api.event.lifecycle.network; + +import com.google.common.base.Preconditions; +import com.velocitypowered.api.network.ListenerType; +import java.net.SocketAddress; + +/** + * This event is fired by the proxy before the proxy stops accepting connections. + */ +public final class ListenerClosedEventImpl implements ListenerClosedEvent { + + private final SocketAddress address; + private final ListenerType listenerType; + + public ListenerClosedEventImpl(SocketAddress address, ListenerType listenerType) { + this.address = Preconditions.checkNotNull(address, "address"); + this.listenerType = Preconditions.checkNotNull(listenerType, "listenerType"); + } + + @Override + public SocketAddress getAddress() { + return address; + } + + @Override + public ListenerType getListenerType() { + return listenerType; + } + + @Override + public String toString() { + return "ListenerCloseEvent{" + + "address=" + address + + ", listenerType=" + listenerType + + '}'; + } +} \ No newline at end of file diff --git a/api/src/main/java/com/velocitypowered/api/event/permission/PermissionsSetupEvent.java b/api/src/main/java/com/velocitypowered/api/event/permission/PermissionsSetupEvent.java index 99ba8c841..915e65944 100644 --- a/api/src/main/java/com/velocitypowered/api/event/permission/PermissionsSetupEvent.java +++ b/api/src/main/java/com/velocitypowered/api/event/permission/PermissionsSetupEvent.java @@ -7,7 +7,6 @@ package com.velocitypowered.api.event.permission; -import com.google.common.base.Preconditions; import com.velocitypowered.api.permission.PermissionFunction; import com.velocitypowered.api.permission.PermissionProvider; import com.velocitypowered.api.permission.PermissionSubject; @@ -18,20 +17,9 @@ import org.checkerframework.checker.nullness.qual.Nullable; * *

This event is only called once per subject, on initialisation.

*/ -public final class PermissionsSetupEvent { +public interface PermissionsSetupEvent { - private final PermissionSubject subject; - private final PermissionProvider defaultProvider; - private PermissionProvider provider; - - public PermissionsSetupEvent(PermissionSubject subject, PermissionProvider provider) { - this.subject = Preconditions.checkNotNull(subject, "subject"); - this.provider = this.defaultProvider = Preconditions.checkNotNull(provider, "provider"); - } - - public PermissionSubject getSubject() { - return this.subject; - } + PermissionSubject getSubject(); /** * Uses the provider function to obtain a {@link PermissionFunction} for the subject. @@ -39,13 +27,9 @@ public final class PermissionsSetupEvent { * @param subject the subject * @return the obtained permission function */ - public PermissionFunction createFunction(PermissionSubject subject) { - return this.provider.createFunction(subject); - } + PermissionFunction createFunction(PermissionSubject subject); - public PermissionProvider getProvider() { - return this.provider; - } + PermissionProvider getProvider(); /** * Sets the {@link PermissionFunction} that should be used for the subject. @@ -55,16 +39,5 @@ public final class PermissionsSetupEvent { * * @param provider the provider */ - public void setProvider(@Nullable PermissionProvider provider) { - this.provider = provider == null ? this.defaultProvider : provider; - } - - @Override - public String toString() { - return "PermissionsSetupEvent{" - + "subject=" + subject - + ", defaultProvider=" + defaultProvider - + ", provider=" + provider - + '}'; - } + void setProvider(@Nullable PermissionProvider provider); } diff --git a/api/src/main/java/com/velocitypowered/api/event/permission/PermissionsSetupEventImpl.java b/api/src/main/java/com/velocitypowered/api/event/permission/PermissionsSetupEventImpl.java new file mode 100644 index 000000000..4921470db --- /dev/null +++ b/api/src/main/java/com/velocitypowered/api/event/permission/PermissionsSetupEventImpl.java @@ -0,0 +1,74 @@ +/* + * Copyright (C) 2018 Velocity Contributors + * + * The Velocity API is licensed under the terms of the MIT License. For more details, + * reference the LICENSE file in the api top-level directory. + */ + +package com.velocitypowered.api.event.permission; + +import com.google.common.base.Preconditions; +import com.velocitypowered.api.permission.PermissionFunction; +import com.velocitypowered.api.permission.PermissionProvider; +import com.velocitypowered.api.permission.PermissionSubject; +import org.checkerframework.checker.nullness.qual.Nullable; + +/** + * Called when a {@link PermissionSubject}'s permissions are being setup. + * + *

This event is only called once per subject, on initialisation.

+ */ +public final class PermissionsSetupEventImpl implements PermissionsSetupEvent { + + private final PermissionSubject subject; + private final PermissionProvider defaultProvider; + private PermissionProvider provider; + + public PermissionsSetupEventImpl(PermissionSubject subject, PermissionProvider provider) { + this.subject = Preconditions.checkNotNull(subject, "subject"); + this.provider = this.defaultProvider = Preconditions.checkNotNull(provider, "provider"); + } + + @Override + public PermissionSubject getSubject() { + return this.subject; + } + + /** + * Uses the provider function to obtain a {@link PermissionFunction} for the subject. + * + * @param subject the subject + * @return the obtained permission function + */ + @Override + public PermissionFunction createFunction(PermissionSubject subject) { + return this.provider.createFunction(subject); + } + + @Override + public PermissionProvider getProvider() { + return this.provider; + } + + /** + * Sets the {@link PermissionFunction} that should be used for the subject. + * + *

Specifying null will reset the provider to the default + * instance given when the event was posted.

+ * + * @param provider the provider + */ + @Override + public void setProvider(@Nullable PermissionProvider provider) { + this.provider = provider == null ? this.defaultProvider : provider; + } + + @Override + public String toString() { + return "PermissionsSetupEvent{" + + "subject=" + subject + + ", defaultProvider=" + defaultProvider + + ", provider=" + provider + + '}'; + } +} diff --git a/api/src/main/java/com/velocitypowered/api/event/player/DisconnectEvent.java b/api/src/main/java/com/velocitypowered/api/event/player/DisconnectEvent.java index 5aa6e4820..ffb49ee02 100644 --- a/api/src/main/java/com/velocitypowered/api/event/player/DisconnectEvent.java +++ b/api/src/main/java/com/velocitypowered/api/event/player/DisconnectEvent.java @@ -7,38 +7,13 @@ package com.velocitypowered.api.event.player; -import com.google.common.base.Preconditions; import com.velocitypowered.api.proxy.connection.Player; -/** - * This event is fired when a player disconnects from the proxy. Operations on the provided player, - * aside from basic data retrieval operations, may behave in undefined ways. - */ -public final class DisconnectEvent { +public interface DisconnectEvent { - private final Player player; - private final LoginStatus loginStatus; + Player getPlayer(); - public DisconnectEvent(Player player, LoginStatus loginStatus) { - this.player = Preconditions.checkNotNull(player, "player"); - this.loginStatus = Preconditions.checkNotNull(loginStatus, "loginStatus"); - } - - public Player getPlayer() { - return player; - } - - public LoginStatus getLoginStatus() { - return loginStatus; - } - - @Override - public String toString() { - return "DisconnectEvent{" - + "player=" + player + ", " - + "loginStatus=" + loginStatus - + '}'; - } + LoginStatus getLoginStatus(); public enum LoginStatus { diff --git a/api/src/main/java/com/velocitypowered/api/event/player/DisconnectEventImpl.java b/api/src/main/java/com/velocitypowered/api/event/player/DisconnectEventImpl.java new file mode 100644 index 000000000..abfaa4d53 --- /dev/null +++ b/api/src/main/java/com/velocitypowered/api/event/player/DisconnectEventImpl.java @@ -0,0 +1,45 @@ +/* + * Copyright (C) 2018 Velocity Contributors + * + * The Velocity API is licensed under the terms of the MIT License. For more details, + * reference the LICENSE file in the api top-level directory. + */ + +package com.velocitypowered.api.event.player; + +import com.google.common.base.Preconditions; +import com.velocitypowered.api.proxy.connection.Player; + +/** + * This event is fired when a player disconnects from the proxy. Operations on the provided player, + * aside from basic data retrieval operations, may behave in undefined ways. + */ +public final class DisconnectEventImpl implements DisconnectEvent { + + private final Player player; + private final LoginStatus loginStatus; + + public DisconnectEventImpl(Player player, LoginStatus loginStatus) { + this.player = Preconditions.checkNotNull(player, "player"); + this.loginStatus = Preconditions.checkNotNull(loginStatus, "loginStatus"); + } + + @Override + public Player getPlayer() { + return player; + } + + @Override + public LoginStatus getLoginStatus() { + return loginStatus; + } + + @Override + public String toString() { + return "DisconnectEvent{" + + "player=" + player + ", " + + "loginStatus=" + loginStatus + + '}'; + } + +} diff --git a/api/src/main/java/com/velocitypowered/api/event/player/GameProfileRequestEvent.java b/api/src/main/java/com/velocitypowered/api/event/player/GameProfileRequestEvent.java index 065442a23..8609d91bb 100644 --- a/api/src/main/java/com/velocitypowered/api/event/player/GameProfileRequestEvent.java +++ b/api/src/main/java/com/velocitypowered/api/event/player/GameProfileRequestEvent.java @@ -13,7 +13,7 @@ import com.velocitypowered.api.util.GameProfile; import org.checkerframework.checker.nullness.qual.Nullable; /** - * This event is fired after the {@link PreLoginEvent} in + * This event is fired after the {@link PreLoginEventImpl} in * order to set up the game profile for the user. This can be used to configure a custom profile for * a user, i.e. skin replacement. */ diff --git a/api/src/main/java/com/velocitypowered/api/event/player/KickedFromServerEvent.java b/api/src/main/java/com/velocitypowered/api/event/player/KickedFromServerEvent.java index 938a17ef7..2990dea11 100644 --- a/api/src/main/java/com/velocitypowered/api/event/player/KickedFromServerEvent.java +++ b/api/src/main/java/com/velocitypowered/api/event/player/KickedFromServerEvent.java @@ -13,7 +13,6 @@ import com.velocitypowered.api.proxy.connection.Player; import com.velocitypowered.api.proxy.server.RegisteredServer; import java.util.Optional; import net.kyori.adventure.text.Component; -import org.checkerframework.checker.nullness.qual.NonNull; import org.checkerframework.checker.nullness.qual.Nullable; /** @@ -22,79 +21,38 @@ import org.checkerframework.checker.nullness.qual.Nullable; * Velocity will notify the user (if they are already connected to a server) or disconnect them * (if they are not on a server and no other servers are available). */ -public final class KickedFromServerEvent implements +public interface KickedFromServerEvent extends ResultedEvent { - private final Player player; - private final RegisteredServer server; - private final @Nullable Component originalReason; - private final boolean duringServerConnect; - private ServerKickResult result; + Player getPlayer(); - /** - * Creates a {@code KickedFromServerEvent} instance. - * @param player the player affected - * @param server the server the player disconnected from - * @param originalReason the reason for being kicked, optional - * @param duringServerConnect whether or not the player was kicked during the connection process - * @param result the initial result - */ - public KickedFromServerEvent(Player player, RegisteredServer server, - net.kyori.adventure.text.@Nullable Component originalReason, - boolean duringServerConnect, ServerKickResult result) { - this.player = Preconditions.checkNotNull(player, "player"); - this.server = Preconditions.checkNotNull(server, "server"); - this.originalReason = originalReason; - this.duringServerConnect = duringServerConnect; - this.result = Preconditions.checkNotNull(result, "result"); - } - - @Override - public ServerKickResult getResult() { - return result; - } - - @Override - public void setResult(@NonNull ServerKickResult result) { - this.result = Preconditions.checkNotNull(result, "result"); - } - - public Player getPlayer() { - return player; - } - - public RegisteredServer getServer() { - return server; - } + RegisteredServer getServer(); /** * Gets the reason the server kicked the player from the server. + * * @return the server kicked the player from the server */ - public Optional getServerKickReason() { - return Optional.ofNullable(originalReason); - } + Optional getServerKickReason(); /** * Returns whether or not the player got kicked while connecting to another server. * * @return whether or not the player got kicked */ - public boolean kickedDuringServerConnect() { - return duringServerConnect; - } + boolean kickedDuringServerConnect(); /** * Represents the base interface for {@link KickedFromServerEvent} results. */ - public interface ServerKickResult extends ResultedEvent.Result { + public interface ServerKickResult extends Result { } /** * Tells the proxy to disconnect the player with the specified reason. */ - public static final class DisconnectPlayer implements ServerKickResult { + final class DisconnectPlayer implements ServerKickResult { private final Component component; @@ -126,13 +84,13 @@ public final class KickedFromServerEvent implements * Tells the proxy to redirect the player to another server. No messages will be sent from the * proxy when this result is used. */ - public static final class RedirectPlayer implements ServerKickResult { + final class RedirectPlayer implements ServerKickResult { private final Component message; private final RegisteredServer server; private RedirectPlayer(RegisteredServer server, - net.kyori.adventure.text.@Nullable Component message) { + @Nullable Component message) { this.server = Preconditions.checkNotNull(server, "server"); this.message = message; } @@ -171,7 +129,7 @@ public final class KickedFromServerEvent implements * result to use if the player was trying to connect to a different server, otherwise it is * treated like a {@link DisconnectPlayer} result. */ - public static final class Notify implements ServerKickResult { + final class Notify implements ServerKickResult { private final Component message; diff --git a/api/src/main/java/com/velocitypowered/api/event/player/KickedFromServerEventImpl.java b/api/src/main/java/com/velocitypowered/api/event/player/KickedFromServerEventImpl.java new file mode 100644 index 000000000..49271db4b --- /dev/null +++ b/api/src/main/java/com/velocitypowered/api/event/player/KickedFromServerEventImpl.java @@ -0,0 +1,89 @@ +/* + * Copyright (C) 2018 Velocity Contributors + * + * The Velocity API is licensed under the terms of the MIT License. For more details, + * reference the LICENSE file in the api top-level directory. + */ + +package com.velocitypowered.api.event.player; + +import com.google.common.base.Preconditions; +import com.velocitypowered.api.proxy.connection.Player; +import com.velocitypowered.api.proxy.server.RegisteredServer; +import java.util.Optional; +import net.kyori.adventure.text.Component; +import org.checkerframework.checker.nullness.qual.NonNull; +import org.checkerframework.checker.nullness.qual.Nullable; + +/** + * Fired when a player is kicked from a server. You may either allow Velocity to kick the player + * (with an optional reason override) or redirect the player to a separate server. By default, + * Velocity will notify the user (if they are already connected to a server) or disconnect them + * (if they are not on a server and no other servers are available). + */ +public final class KickedFromServerEventImpl implements KickedFromServerEvent { + + private final Player player; + private final RegisteredServer server; + private final @Nullable Component originalReason; + private final boolean duringServerConnect; + private ServerKickResult result; + + /** + * Creates a {@code KickedFromServerEvent} instance. + * @param player the player affected + * @param server the server the player disconnected from + * @param originalReason the reason for being kicked, optional + * @param duringServerConnect whether or not the player was kicked during the connection process + * @param result the initial result + */ + public KickedFromServerEventImpl(Player player, RegisteredServer server, + net.kyori.adventure.text.@Nullable Component originalReason, + boolean duringServerConnect, ServerKickResult result) { + this.player = Preconditions.checkNotNull(player, "player"); + this.server = Preconditions.checkNotNull(server, "server"); + this.originalReason = originalReason; + this.duringServerConnect = duringServerConnect; + this.result = Preconditions.checkNotNull(result, "result"); + } + + @Override + public ServerKickResult getResult() { + return result; + } + + @Override + public void setResult(@NonNull ServerKickResult result) { + this.result = Preconditions.checkNotNull(result, "result"); + } + + @Override + public Player getPlayer() { + return player; + } + + @Override + public RegisteredServer getServer() { + return server; + } + + /** + * Gets the reason the server kicked the player from the server. + * @return the server kicked the player from the server + */ + @Override + public Optional getServerKickReason() { + return Optional.ofNullable(originalReason); + } + + /** + * Returns whether or not the player got kicked while connecting to another server. + * + * @return whether or not the player got kicked + */ + @Override + public boolean kickedDuringServerConnect() { + return duringServerConnect; + } + +} diff --git a/api/src/main/java/com/velocitypowered/api/event/player/LoginEvent.java b/api/src/main/java/com/velocitypowered/api/event/player/LoginEvent.java index 77b243111..6eea91911 100644 --- a/api/src/main/java/com/velocitypowered/api/event/player/LoginEvent.java +++ b/api/src/main/java/com/velocitypowered/api/event/player/LoginEvent.java @@ -7,7 +7,6 @@ package com.velocitypowered.api.event.player; -import com.google.common.base.Preconditions; import com.velocitypowered.api.event.ResultedEvent; import com.velocitypowered.api.proxy.connection.Player; @@ -15,35 +14,13 @@ import com.velocitypowered.api.proxy.connection.Player; * This event is fired once the player has been authenticated but before they connect to a server on * the proxy. */ -public final class LoginEvent implements ResultedEvent { +public interface LoginEvent extends ResultedEvent { - private final Player player; - private ComponentResult result; - - public LoginEvent(Player player) { - this.player = Preconditions.checkNotNull(player, "player"); - this.result = ComponentResult.allowed(); - } - - public Player getPlayer() { - return player; - } + Player getPlayer(); @Override - public ComponentResult getResult() { - return result; - } + ComponentResult getResult(); @Override - public void setResult(ComponentResult result) { - this.result = Preconditions.checkNotNull(result, "result"); - } - - @Override - public String toString() { - return "LoginEvent{" - + "player=" + player - + ", result=" + result - + '}'; - } + void setResult(ComponentResult result); } diff --git a/api/src/main/java/com/velocitypowered/api/event/player/LoginEventImpl.java b/api/src/main/java/com/velocitypowered/api/event/player/LoginEventImpl.java new file mode 100644 index 000000000..9daf5cef2 --- /dev/null +++ b/api/src/main/java/com/velocitypowered/api/event/player/LoginEventImpl.java @@ -0,0 +1,49 @@ +/* + * Copyright (C) 2018 Velocity Contributors + * + * The Velocity API is licensed under the terms of the MIT License. For more details, + * reference the LICENSE file in the api top-level directory. + */ + +package com.velocitypowered.api.event.player; + +import com.google.common.base.Preconditions; +import com.velocitypowered.api.proxy.connection.Player; + +/** + * This event is fired once the player has been authenticated but before they connect to a server on + * the proxy. + */ +public final class LoginEventImpl implements LoginEvent { + + private final Player player; + private ComponentResult result; + + public LoginEventImpl(Player player) { + this.player = Preconditions.checkNotNull(player, "player"); + this.result = ComponentResult.allowed(); + } + + @Override + public Player getPlayer() { + return player; + } + + @Override + public ComponentResult getResult() { + return result; + } + + @Override + public void setResult(ComponentResult result) { + this.result = Preconditions.checkNotNull(result, "result"); + } + + @Override + public String toString() { + return "LoginEvent{" + + "player=" + player + + ", result=" + result + + '}'; + } +} diff --git a/api/src/main/java/com/velocitypowered/api/event/player/PlayerChannelRegisterEvent.java b/api/src/main/java/com/velocitypowered/api/event/player/PlayerChannelRegisterEvent.java index 3f979f4c6..401bba506 100644 --- a/api/src/main/java/com/velocitypowered/api/event/player/PlayerChannelRegisterEvent.java +++ b/api/src/main/java/com/velocitypowered/api/event/player/PlayerChannelRegisterEvent.java @@ -7,7 +7,6 @@ package com.velocitypowered.api.event.player; -import com.google.common.base.Preconditions; import com.velocitypowered.api.proxy.connection.Player; import com.velocitypowered.api.proxy.messages.ChannelIdentifier; import java.util.List; @@ -16,29 +15,9 @@ import java.util.List; * This event is fired when a client ({@link Player}) sends a plugin message through the * register channel. */ -public final class PlayerChannelRegisterEvent { +public interface PlayerChannelRegisterEvent { - private final Player player; - private final List channels; + Player getPlayer(); - public PlayerChannelRegisterEvent(Player player, List channels) { - this.player = Preconditions.checkNotNull(player, "player"); - this.channels = Preconditions.checkNotNull(channels, "channels"); - } - - public Player getPlayer() { - return player; - } - - public List getChannels() { - return channels; - } - - @Override - public String toString() { - return "PlayerChannelRegisterEvent{" - + "player=" + player - + ", channels=" + channels - + '}'; - } + List getChannels(); } diff --git a/api/src/main/java/com/velocitypowered/api/event/player/PlayerChannelRegisterEventImpl.java b/api/src/main/java/com/velocitypowered/api/event/player/PlayerChannelRegisterEventImpl.java new file mode 100644 index 000000000..3782d13e3 --- /dev/null +++ b/api/src/main/java/com/velocitypowered/api/event/player/PlayerChannelRegisterEventImpl.java @@ -0,0 +1,46 @@ +/* + * Copyright (C) 2018 Velocity Contributors + * + * The Velocity API is licensed under the terms of the MIT License. For more details, + * reference the LICENSE file in the api top-level directory. + */ + +package com.velocitypowered.api.event.player; + +import com.google.common.base.Preconditions; +import com.velocitypowered.api.proxy.connection.Player; +import com.velocitypowered.api.proxy.messages.ChannelIdentifier; +import java.util.List; + +/** + * This event is fired when a client ({@link Player}) sends a plugin message through the + * register channel. + */ +public final class PlayerChannelRegisterEventImpl implements PlayerChannelRegisterEvent { + + private final Player player; + private final List channels; + + public PlayerChannelRegisterEventImpl(Player player, List channels) { + this.player = Preconditions.checkNotNull(player, "player"); + this.channels = Preconditions.checkNotNull(channels, "channels"); + } + + @Override + public Player getPlayer() { + return player; + } + + @Override + public List getChannels() { + return channels; + } + + @Override + public String toString() { + return "PlayerChannelRegisterEvent{" + + "player=" + player + + ", channels=" + channels + + '}'; + } +} diff --git a/api/src/main/java/com/velocitypowered/api/event/player/PlayerChatEvent.java b/api/src/main/java/com/velocitypowered/api/event/player/PlayerChatEvent.java index 90f796adc..7fec00e40 100644 --- a/api/src/main/java/com/velocitypowered/api/event/player/PlayerChatEvent.java +++ b/api/src/main/java/com/velocitypowered/api/event/player/PlayerChatEvent.java @@ -14,57 +14,22 @@ import java.util.Optional; import org.checkerframework.checker.nullness.qual.NonNull; import org.checkerframework.checker.nullness.qual.Nullable; -/** - * This event is fired when a player types in a chat message. - */ -public final class PlayerChatEvent implements ResultedEvent { +public interface PlayerChatEvent extends ResultedEvent { - private final Player player; - private final String message; - private ChatResult result; + Player getPlayer(); - /** - * Constructs a PlayerChatEvent. - * @param player the player sending the message - * @param message the message being sent - */ - public PlayerChatEvent(Player player, String message) { - this.player = Preconditions.checkNotNull(player, "player"); - this.message = Preconditions.checkNotNull(message, "message"); - this.result = ChatResult.allowed(); - } - - public Player getPlayer() { - return player; - } - - public String getMessage() { - return message; - } + String getMessage(); @Override - public ChatResult getResult() { - return result; - } + ChatResult getResult(); @Override - public void setResult(ChatResult result) { - this.result = Preconditions.checkNotNull(result, "result"); - } - - @Override - public String toString() { - return "PlayerChatEvent{" - + "player=" + player - + ", message=" + message - + ", result=" + result - + '}'; - } + void setResult(ChatResult result); /** * Represents the result of the {@link PlayerChatEvent}. */ - public static final class ChatResult implements ResultedEvent.Result { + final class ChatResult implements Result { private static final ChatResult ALLOWED = new ChatResult(true, null); private static final ChatResult DENIED = new ChatResult(false, null); @@ -93,6 +58,7 @@ public final class PlayerChatEvent implements ResultedEvent getInitialServer() { - return Optional.ofNullable(initialServer); - } + Optional getInitialServer(); /** * Sets the new initial server. + * * @param server the initial server the player should connect to */ - public void setInitialServer(RegisteredServer server) { - this.initialServer = server; - } - - @Override - public String toString() { - return "PlayerChooseInitialServerEvent{" - + "player=" + player - + ", initialServer=" + initialServer - + '}'; - } + void setInitialServer(RegisteredServer server); } diff --git a/api/src/main/java/com/velocitypowered/api/event/player/PlayerChooseInitialServerEventImpl.java b/api/src/main/java/com/velocitypowered/api/event/player/PlayerChooseInitialServerEventImpl.java new file mode 100644 index 000000000..c89e9be75 --- /dev/null +++ b/api/src/main/java/com/velocitypowered/api/event/player/PlayerChooseInitialServerEventImpl.java @@ -0,0 +1,61 @@ +/* + * Copyright (C) 2018 Velocity Contributors + * + * The Velocity API is licensed under the terms of the MIT License. For more details, + * reference the LICENSE file in the api top-level directory. + */ + +package com.velocitypowered.api.event.player; + +import com.google.common.base.Preconditions; +import com.velocitypowered.api.proxy.connection.Player; +import com.velocitypowered.api.proxy.server.RegisteredServer; +import java.util.Optional; +import org.checkerframework.checker.nullness.qual.Nullable; + +/** + * Fired when a player has finished connecting to the proxy and we need to choose the first server + * to connect to. + */ +public class PlayerChooseInitialServerEventImpl implements PlayerChooseInitialServerEvent { + + private final Player player; + private @Nullable RegisteredServer initialServer; + + /** + * Constructs a PlayerChooseInitialServerEvent. + * @param player the player that was connected + * @param initialServer the initial server selected, may be {@code null} + */ + public PlayerChooseInitialServerEventImpl(Player player, @Nullable RegisteredServer initialServer) { + this.player = Preconditions.checkNotNull(player, "player"); + this.initialServer = initialServer; + } + + @Override + public Player getPlayer() { + return player; + } + + @Override + public Optional getInitialServer() { + return Optional.ofNullable(initialServer); + } + + /** + * Sets the new initial server. + * @param server the initial server the player should connect to + */ + @Override + public void setInitialServer(RegisteredServer server) { + this.initialServer = server; + } + + @Override + public String toString() { + return "PlayerChooseInitialServerEvent{" + + "player=" + player + + ", initialServer=" + initialServer + + '}'; + } +} diff --git a/api/src/main/java/com/velocitypowered/api/event/player/PlayerModInfoEvent.java b/api/src/main/java/com/velocitypowered/api/event/player/PlayerModInfoEvent.java index 75afb7093..245de58f0 100644 --- a/api/src/main/java/com/velocitypowered/api/event/player/PlayerModInfoEvent.java +++ b/api/src/main/java/com/velocitypowered/api/event/player/PlayerModInfoEvent.java @@ -7,37 +7,16 @@ package com.velocitypowered.api.event.player; -import com.google.common.base.MoreObjects; -import com.google.common.base.Preconditions; import com.velocitypowered.api.proxy.connection.Player; import com.velocitypowered.api.util.ModInfo; /** - * This event is fired when a Forge client sends its mods to the proxy while connecting to a server. + * This event is fired when a modded client sends its mods to the proxy while connecting to a + * server. */ -public final class PlayerModInfoEvent { +public interface PlayerModInfoEvent { - private final Player player; - private final ModInfo modInfo; + Player getPlayer(); - public PlayerModInfoEvent(Player player, ModInfo modInfo) { - this.player = Preconditions.checkNotNull(player, "player"); - this.modInfo = Preconditions.checkNotNull(modInfo, "modInfo"); - } - - public Player getPlayer() { - return player; - } - - public ModInfo getModInfo() { - return modInfo; - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(this) - .add("player", player) - .add("modInfo", modInfo) - .toString(); - } + ModInfo getModInfo(); } diff --git a/api/src/main/java/com/velocitypowered/api/event/player/PlayerModInfoEventImpl.java b/api/src/main/java/com/velocitypowered/api/event/player/PlayerModInfoEventImpl.java new file mode 100644 index 000000000..9b3db009a --- /dev/null +++ b/api/src/main/java/com/velocitypowered/api/event/player/PlayerModInfoEventImpl.java @@ -0,0 +1,42 @@ +/* + * Copyright (C) 2018 Velocity Contributors + * + * The Velocity API is licensed under the terms of the MIT License. For more details, + * reference the LICENSE file in the api top-level directory. + */ + +package com.velocitypowered.api.event.player; + +import com.google.common.base.MoreObjects; +import com.google.common.base.Preconditions; +import com.velocitypowered.api.proxy.connection.Player; +import com.velocitypowered.api.util.ModInfo; + +public final class PlayerModInfoEventImpl implements PlayerModInfoEvent { + + private final Player player; + private final ModInfo modInfo; + + public PlayerModInfoEventImpl(Player player, ModInfo modInfo) { + this.player = Preconditions.checkNotNull(player, "player"); + this.modInfo = Preconditions.checkNotNull(modInfo, "modInfo"); + } + + @Override + public Player getPlayer() { + return player; + } + + @Override + public ModInfo getModInfo() { + return modInfo; + } + + @Override + public String toString() { + return MoreObjects.toStringHelper(this) + .add("player", player) + .add("modInfo", modInfo) + .toString(); + } +} diff --git a/api/src/main/java/com/velocitypowered/api/event/player/PlayerResourcePackStatusEvent.java b/api/src/main/java/com/velocitypowered/api/event/player/PlayerResourcePackStatusEvent.java index 2b4c5f797..e088a5786 100644 --- a/api/src/main/java/com/velocitypowered/api/event/player/PlayerResourcePackStatusEvent.java +++ b/api/src/main/java/com/velocitypowered/api/event/player/PlayerResourcePackStatusEvent.java @@ -7,53 +7,32 @@ package com.velocitypowered.api.event.player; -import com.google.common.base.Preconditions; import com.velocitypowered.api.proxy.connection.Player; /** * This event is fired when the status of a resource pack sent to the player by the server is * changed. */ -public class PlayerResourcePackStatusEvent { - - private final Player player; - private final Status status; - - public PlayerResourcePackStatusEvent(Player player, Status status) { - this.player = Preconditions.checkNotNull(player, "player"); - this.status = Preconditions.checkNotNull(status, "status"); - } +public interface PlayerResourcePackStatusEvent { /** * Returns the player affected by the change in resource pack status. * * @return the player */ - public Player getPlayer() { - return player; - } + Player getPlayer(); /** * Returns the new status for the resource pack. * * @return the new status */ - public Status getStatus() { - return status; - } - - @Override - public String toString() { - return "PlayerResourcePackStatusEvent{" - + "player=" + player - + ", status=" + status - + '}'; - } + Status getStatus(); /** * Represents the possible statuses for the resource pack. */ - public enum Status { + enum Status { /** * The resource pack was applied successfully. */ diff --git a/api/src/main/java/com/velocitypowered/api/event/player/PlayerResourcePackStatusEventImpl.java b/api/src/main/java/com/velocitypowered/api/event/player/PlayerResourcePackStatusEventImpl.java new file mode 100644 index 000000000..ea4bee51f --- /dev/null +++ b/api/src/main/java/com/velocitypowered/api/event/player/PlayerResourcePackStatusEventImpl.java @@ -0,0 +1,55 @@ +/* + * Copyright (C) 2018 Velocity Contributors + * + * The Velocity API is licensed under the terms of the MIT License. For more details, + * reference the LICENSE file in the api top-level directory. + */ + +package com.velocitypowered.api.event.player; + +import com.google.common.base.Preconditions; +import com.velocitypowered.api.proxy.connection.Player; + +/** + * This event is fired when the status of a resource pack sent to the player by the server is + * changed. + */ +public class PlayerResourcePackStatusEventImpl implements PlayerResourcePackStatusEvent { + + private final Player player; + private final Status status; + + public PlayerResourcePackStatusEventImpl(Player player, Status status) { + this.player = Preconditions.checkNotNull(player, "player"); + this.status = Preconditions.checkNotNull(status, "status"); + } + + /** + * Returns the player affected by the change in resource pack status. + * + * @return the player + */ + @Override + public Player getPlayer() { + return player; + } + + /** + * Returns the new status for the resource pack. + * + * @return the new status + */ + @Override + public Status getStatus() { + return status; + } + + @Override + public String toString() { + return "PlayerResourcePackStatusEvent{" + + "player=" + player + + ", status=" + status + + '}'; + } + +} diff --git a/api/src/main/java/com/velocitypowered/api/event/player/PlayerSettingsChangedEvent.java b/api/src/main/java/com/velocitypowered/api/event/player/PlayerSettingsChangedEvent.java index 5175c3773..8277952c3 100644 --- a/api/src/main/java/com/velocitypowered/api/event/player/PlayerSettingsChangedEvent.java +++ b/api/src/main/java/com/velocitypowered/api/event/player/PlayerSettingsChangedEvent.java @@ -7,34 +7,12 @@ package com.velocitypowered.api.event.player; -import com.google.common.base.MoreObjects; -import com.google.common.base.Preconditions; import com.velocitypowered.api.proxy.connection.Player; import com.velocitypowered.api.proxy.player.PlayerSettings; -public final class PlayerSettingsChangedEvent { +public interface PlayerSettingsChangedEvent { - private final Player player; - private final PlayerSettings playerSettings; + Player getPlayer(); - public PlayerSettingsChangedEvent(Player player, PlayerSettings playerSettings) { - this.player = Preconditions.checkNotNull(player, "player"); - this.playerSettings = Preconditions.checkNotNull(playerSettings, "playerSettings"); - } - - public Player getPlayer() { - return player; - } - - public PlayerSettings getPlayerSettings() { - return playerSettings; - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(this) - .add("player", player) - .add("playerSettings", playerSettings) - .toString(); - } + PlayerSettings getPlayerSettings(); } diff --git a/api/src/main/java/com/velocitypowered/api/event/player/PlayerSettingsChangedEventImpl.java b/api/src/main/java/com/velocitypowered/api/event/player/PlayerSettingsChangedEventImpl.java new file mode 100644 index 000000000..207f3c9a1 --- /dev/null +++ b/api/src/main/java/com/velocitypowered/api/event/player/PlayerSettingsChangedEventImpl.java @@ -0,0 +1,42 @@ +/* + * Copyright (C) 2018 Velocity Contributors + * + * The Velocity API is licensed under the terms of the MIT License. For more details, + * reference the LICENSE file in the api top-level directory. + */ + +package com.velocitypowered.api.event.player; + +import com.google.common.base.MoreObjects; +import com.google.common.base.Preconditions; +import com.velocitypowered.api.proxy.connection.Player; +import com.velocitypowered.api.proxy.player.PlayerSettings; + +public final class PlayerSettingsChangedEventImpl implements PlayerSettingsChangedEvent { + + private final Player player; + private final PlayerSettings playerSettings; + + public PlayerSettingsChangedEventImpl(Player player, PlayerSettings playerSettings) { + this.player = Preconditions.checkNotNull(player, "player"); + this.playerSettings = Preconditions.checkNotNull(playerSettings, "playerSettings"); + } + + @Override + public Player getPlayer() { + return player; + } + + @Override + public PlayerSettings getPlayerSettings() { + return playerSettings; + } + + @Override + public String toString() { + return MoreObjects.toStringHelper(this) + .add("player", player) + .add("playerSettings", playerSettings) + .toString(); + } +} diff --git a/api/src/main/java/com/velocitypowered/api/event/player/PostLoginEvent.java b/api/src/main/java/com/velocitypowered/api/event/player/PostLoginEvent.java index 509c5bb51..3c12c5480 100644 --- a/api/src/main/java/com/velocitypowered/api/event/player/PostLoginEvent.java +++ b/api/src/main/java/com/velocitypowered/api/event/player/PostLoginEvent.java @@ -7,29 +7,13 @@ package com.velocitypowered.api.event.player; -import com.google.common.base.Preconditions; import com.velocitypowered.api.proxy.connection.Player; /** * This event is fired once the player has been fully initialized and is about to connect to their * first server. */ -public final class PostLoginEvent { +public interface PostLoginEvent { - private final Player player; - - public PostLoginEvent(Player player) { - this.player = Preconditions.checkNotNull(player, "player"); - } - - public Player getPlayer() { - return player; - } - - @Override - public String toString() { - return "PostLoginEvent{" - + "player=" + player - + '}'; - } + Player getPlayer(); } diff --git a/api/src/main/java/com/velocitypowered/api/event/player/PostLoginEventImpl.java b/api/src/main/java/com/velocitypowered/api/event/player/PostLoginEventImpl.java new file mode 100644 index 000000000..c627442a8 --- /dev/null +++ b/api/src/main/java/com/velocitypowered/api/event/player/PostLoginEventImpl.java @@ -0,0 +1,36 @@ +/* + * Copyright (C) 2018 Velocity Contributors + * + * The Velocity API is licensed under the terms of the MIT License. For more details, + * reference the LICENSE file in the api top-level directory. + */ + +package com.velocitypowered.api.event.player; + +import com.google.common.base.Preconditions; +import com.velocitypowered.api.proxy.connection.Player; + +/** + * This event is fired once the player has been fully initialized and is about to connect to their + * first server. + */ +public final class PostLoginEventImpl implements PostLoginEvent { + + private final Player player; + + public PostLoginEventImpl(Player player) { + this.player = Preconditions.checkNotNull(player, "player"); + } + + @Override + public Player getPlayer() { + return player; + } + + @Override + public String toString() { + return "PostLoginEvent{" + + "player=" + player + + '}'; + } +} diff --git a/api/src/main/java/com/velocitypowered/api/event/player/PreLoginEvent.java b/api/src/main/java/com/velocitypowered/api/event/player/PreLoginEvent.java index bff5951d0..d0715bfb1 100644 --- a/api/src/main/java/com/velocitypowered/api/event/player/PreLoginEvent.java +++ b/api/src/main/java/com/velocitypowered/api/event/player/PreLoginEvent.java @@ -20,55 +20,23 @@ import org.checkerframework.checker.nullness.qual.Nullable; * authenticates the player with Mojang or before the player's proxy connection is fully established * (for offline mode). */ -public final class PreLoginEvent implements ResultedEvent { +public interface PreLoginEvent extends ResultedEvent { - private final InboundConnection connection; - private final String username; - private PreLoginComponentResult result; + InboundConnection getConnection(); - /** - * Creates a new instance. - * @param connection the connection logging into the proxy - * @param username the player's username - */ - public PreLoginEvent(InboundConnection connection, String username) { - this.connection = Preconditions.checkNotNull(connection, "connection"); - this.username = Preconditions.checkNotNull(username, "username"); - this.result = PreLoginComponentResult.allowed(); - } - - public InboundConnection getConnection() { - return connection; - } - - public String getUsername() { - return username; - } + String getUsername(); @Override - public PreLoginComponentResult getResult() { - return result; - } + PreLoginComponentResult getResult(); @Override - public void setResult(@NonNull PreLoginComponentResult result) { - this.result = Preconditions.checkNotNull(result, "result"); - } - - @Override - public String toString() { - return "PreLoginEvent{" - + "connection=" + connection - + ", username='" + username + '\'' - + ", result=" + result - + '}'; - } + void setResult(@NonNull PreLoginComponentResult result); /** * Represents an "allowed/allowed with forced online\offline mode/denied" result with a reason * allowed for denial. */ - public static final class PreLoginComponentResult implements ResultedEvent.Result { + final class PreLoginComponentResult implements Result { private static final PreLoginComponentResult ALLOWED = new PreLoginComponentResult( Result.ALLOWED, null); diff --git a/api/src/main/java/com/velocitypowered/api/event/player/PreLoginEventImpl.java b/api/src/main/java/com/velocitypowered/api/event/player/PreLoginEventImpl.java new file mode 100644 index 000000000..7888c5941 --- /dev/null +++ b/api/src/main/java/com/velocitypowered/api/event/player/PreLoginEventImpl.java @@ -0,0 +1,65 @@ +/* + * Copyright (C) 2018 Velocity Contributors + * + * The Velocity API is licensed under the terms of the MIT License. For more details, + * reference the LICENSE file in the api top-level directory. + */ + +package com.velocitypowered.api.event.player; + +import com.google.common.base.Preconditions; +import com.velocitypowered.api.proxy.connection.InboundConnection; +import org.checkerframework.checker.nullness.qual.NonNull; + +/** + * This event is fired when a player has initiated a connection with the proxy but before the proxy + * authenticates the player with Mojang or before the player's proxy connection is fully established + * (for offline mode). + */ +public final class PreLoginEventImpl implements PreLoginEvent { + + private final InboundConnection connection; + private final String username; + private PreLoginComponentResult result; + + /** + * Creates a new instance. + * @param connection the connection logging into the proxy + * @param username the player's username + */ + public PreLoginEventImpl(InboundConnection connection, String username) { + this.connection = Preconditions.checkNotNull(connection, "connection"); + this.username = Preconditions.checkNotNull(username, "username"); + this.result = PreLoginComponentResult.allowed(); + } + + @Override + public InboundConnection getConnection() { + return connection; + } + + @Override + public String getUsername() { + return username; + } + + @Override + public PreLoginComponentResult getResult() { + return result; + } + + @Override + public void setResult(@NonNull PreLoginComponentResult result) { + this.result = Preconditions.checkNotNull(result, "result"); + } + + @Override + public String toString() { + return "PreLoginEvent{" + + "connection=" + connection + + ", username='" + username + '\'' + + ", result=" + result + + '}'; + } + +} diff --git a/api/src/main/java/com/velocitypowered/api/event/player/ServerConnectedEvent.java b/api/src/main/java/com/velocitypowered/api/event/player/ServerConnectedEvent.java index caa8adb48..141bd13b4 100644 --- a/api/src/main/java/com/velocitypowered/api/event/player/ServerConnectedEvent.java +++ b/api/src/main/java/com/velocitypowered/api/event/player/ServerConnectedEvent.java @@ -7,53 +7,19 @@ package com.velocitypowered.api.event.player; -import com.google.common.base.Preconditions; import com.velocitypowered.api.proxy.connection.Player; import com.velocitypowered.api.proxy.server.RegisteredServer; import java.util.Optional; -import org.checkerframework.checker.nullness.qual.Nullable; /** * This event is fired once the player has successfully connected to the target server and the * connection to the previous server has been de-established. */ -public final class ServerConnectedEvent { +public interface ServerConnectedEvent { - private final Player player; - private final RegisteredServer server; - private final @Nullable RegisteredServer previousServer; + Player getPlayer(); - /** - * Constructs a ServerConnectedEvent. - * @param player the player that was connected - * @param server the server the player was connected to - * @param previousServer the server the player was previously connected to, null if none - */ - public ServerConnectedEvent(Player player, RegisteredServer server, - @Nullable RegisteredServer previousServer) { - this.player = Preconditions.checkNotNull(player, "player"); - this.server = Preconditions.checkNotNull(server, "server"); - this.previousServer = previousServer; - } + RegisteredServer getServer(); - public Player getPlayer() { - return player; - } - - public RegisteredServer getServer() { - return server; - } - - public Optional getPreviousServer() { - return Optional.ofNullable(previousServer); - } - - @Override - public String toString() { - return "ServerConnectedEvent{" - + "player=" + player - + ", server=" + server - + ", previousServer=" + previousServer - + '}'; - } + Optional getPreviousServer(); } diff --git a/api/src/main/java/com/velocitypowered/api/event/player/ServerConnectedEventImpl.java b/api/src/main/java/com/velocitypowered/api/event/player/ServerConnectedEventImpl.java new file mode 100644 index 000000000..0c7a3cc2a --- /dev/null +++ b/api/src/main/java/com/velocitypowered/api/event/player/ServerConnectedEventImpl.java @@ -0,0 +1,62 @@ +/* + * Copyright (C) 2018 Velocity Contributors + * + * The Velocity API is licensed under the terms of the MIT License. For more details, + * reference the LICENSE file in the api top-level directory. + */ + +package com.velocitypowered.api.event.player; + +import com.google.common.base.Preconditions; +import com.velocitypowered.api.proxy.connection.Player; +import com.velocitypowered.api.proxy.server.RegisteredServer; +import java.util.Optional; +import org.checkerframework.checker.nullness.qual.Nullable; + +/** + * This event is fired once the player has successfully connected to the target server and the + * connection to the previous server has been de-established. + */ +public final class ServerConnectedEventImpl implements ServerConnectedEvent { + + private final Player player; + private final RegisteredServer server; + private final @Nullable RegisteredServer previousServer; + + /** + * Constructs a ServerConnectedEvent. + * @param player the player that was connected + * @param server the server the player was connected to + * @param previousServer the server the player was previously connected to, null if none + */ + public ServerConnectedEventImpl(Player player, RegisteredServer server, + @Nullable RegisteredServer previousServer) { + this.player = Preconditions.checkNotNull(player, "player"); + this.server = Preconditions.checkNotNull(server, "server"); + this.previousServer = previousServer; + } + + @Override + public Player getPlayer() { + return player; + } + + @Override + public RegisteredServer getServer() { + return server; + } + + @Override + public Optional getPreviousServer() { + return Optional.ofNullable(previousServer); + } + + @Override + public String toString() { + return "ServerConnectedEvent{" + + "player=" + player + + ", server=" + server + + ", previousServer=" + previousServer + + '}'; + } +} diff --git a/api/src/main/java/com/velocitypowered/api/event/player/ServerPostConnectEvent.java b/api/src/main/java/com/velocitypowered/api/event/player/ServerPostConnectEvent.java index a831ac86c..105e28bcb 100644 --- a/api/src/main/java/com/velocitypowered/api/event/player/ServerPostConnectEvent.java +++ b/api/src/main/java/com/velocitypowered/api/event/player/ServerPostConnectEvent.java @@ -7,8 +7,6 @@ package com.velocitypowered.api.event.player; -import com.google.common.annotations.Beta; -import com.google.common.base.Preconditions; import com.velocitypowered.api.proxy.connection.Player; import com.velocitypowered.api.proxy.server.RegisteredServer; import org.checkerframework.checker.nullness.qual.Nullable; @@ -17,30 +15,9 @@ import org.checkerframework.checker.nullness.qual.Nullable; * Fired after the player has connected to a server. The server the player is now connected to is * available in {@link Player#getCurrentServer()}. */ -@Beta -public class ServerPostConnectEvent { - private final Player player; - private final RegisteredServer previousServer; +public interface ServerPostConnectEvent { - public ServerPostConnectEvent(Player player, - @Nullable RegisteredServer previousServer) { - this.player = Preconditions.checkNotNull(player, "player"); - this.previousServer = previousServer; - } + Player getPlayer(); - public Player getPlayer() { - return player; - } - - public @Nullable RegisteredServer getPreviousServer() { - return previousServer; - } - - @Override - public String toString() { - return "ServerPostConnectEvent{" - + "player=" + player - + ", previousServer=" + previousServer - + '}'; - } + @Nullable RegisteredServer getPreviousServer(); } diff --git a/api/src/main/java/com/velocitypowered/api/event/player/ServerPostConnectEventImpl.java b/api/src/main/java/com/velocitypowered/api/event/player/ServerPostConnectEventImpl.java new file mode 100644 index 000000000..c97f07e93 --- /dev/null +++ b/api/src/main/java/com/velocitypowered/api/event/player/ServerPostConnectEventImpl.java @@ -0,0 +1,47 @@ +/* + * Copyright (C) 2018 Velocity Contributors + * + * The Velocity API is licensed under the terms of the MIT License. For more details, + * reference the LICENSE file in the api top-level directory. + */ + +package com.velocitypowered.api.event.player; + +import com.google.common.base.Preconditions; +import com.velocitypowered.api.proxy.connection.Player; +import com.velocitypowered.api.proxy.server.RegisteredServer; +import org.checkerframework.checker.nullness.qual.Nullable; + +/** + * Fired after the player has connected to a server. The server the player is now connected to is + * available in {@link Player#getCurrentServer()}. + */ +public class ServerPostConnectEventImpl implements ServerPostConnectEvent { + + private final Player player; + private final RegisteredServer previousServer; + + public ServerPostConnectEventImpl(Player player, + @Nullable RegisteredServer previousServer) { + this.player = Preconditions.checkNotNull(player, "player"); + this.previousServer = previousServer; + } + + @Override + public Player getPlayer() { + return player; + } + + @Override + public @Nullable RegisteredServer getPreviousServer() { + return previousServer; + } + + @Override + public String toString() { + return "ServerPostConnectEvent{" + + "player=" + player + + ", previousServer=" + previousServer + + '}'; + } +} diff --git a/api/src/main/java/com/velocitypowered/api/event/player/ServerPreConnectEvent.java b/api/src/main/java/com/velocitypowered/api/event/player/ServerPreConnectEvent.java index d38100b6b..0e5d0f129 100644 --- a/api/src/main/java/com/velocitypowered/api/event/player/ServerPreConnectEvent.java +++ b/api/src/main/java/com/velocitypowered/api/event/player/ServerPreConnectEvent.java @@ -19,65 +19,34 @@ import org.checkerframework.checker.nullness.qual.Nullable; /** * This event is fired before the player connects to a server. */ -public final class ServerPreConnectEvent implements - ResultedEvent { - - private final Player player; - private final RegisteredServer originalServer; - private ServerResult result; - - /** - * Creates the ServerPreConnectEvent. - * @param player the player who is connecting to a server - * @param originalServer the server the player was trying to connect to - */ - public ServerPreConnectEvent(Player player, RegisteredServer originalServer) { - this.player = Preconditions.checkNotNull(player, "player"); - this.originalServer = Preconditions.checkNotNull(originalServer, "originalServer"); - this.result = ServerResult.allowed(originalServer); - } +public interface ServerPreConnectEvent extends ResultedEvent { /** * Returns the player connecting to the server. + * * @return the player connecting to the server */ - public Player getPlayer() { - return player; - } + Player getPlayer(); @Override - public ServerResult getResult() { - return result; - } + ServerResult getResult(); @Override - public void setResult(ServerResult result) { - this.result = Preconditions.checkNotNull(result, "result"); - } + void setResult(ServerResult result); /** - * Returns the server that the player originally tried to connect to. To get the server the - * player will connect to, see the {@link ServerResult} of this event. To get the server the - * player is currently on when this event is fired, use {@link Player#getCurrentServer()}. + * Returns the server that the player originally tried to connect to. To get the server the player + * will connect to, see the {@link ServerResult} of this event. To get the server the player is + * currently on when this event is fired, use {@link Player#getCurrentServer()}. + * * @return the server that the player originally tried to connect to */ - public RegisteredServer getOriginalServer() { - return originalServer; - } - - @Override - public String toString() { - return "ServerPreConnectEvent{" - + "player=" + player - + ", originalServer=" + originalServer - + ", result=" + result - + '}'; - } + RegisteredServer getOriginalServer(); /** * Represents the result of the {@link ServerPreConnectEvent}. */ - public static class ServerResult implements ResultedEvent.Result { + class ServerResult implements Result { private static final ServerResult DENIED = new ServerResult(null); @@ -106,8 +75,9 @@ public final class ServerPreConnectEvent implements /** * Returns a result that will prevent players from connecting to another server. If this result - * is used, then {@link ConnectionRequestBuilder#connect()}'s result will have the status - * {@link Status#CONNECTION_CANCELLED}. + * is used, then {@link ConnectionRequestBuilder#connect()}'s result will have the status {@link + * Status#CONNECTION_CANCELLED}. + * * @return a result to deny conneections */ public static ServerResult denied() { @@ -116,6 +86,7 @@ public final class ServerPreConnectEvent implements /** * Allows the player to connect to the specified server. + * * @param server the new server to connect to * @return a result to allow the player to connect to the specified server */ diff --git a/api/src/main/java/com/velocitypowered/api/event/player/ServerPreConnectEventImpl.java b/api/src/main/java/com/velocitypowered/api/event/player/ServerPreConnectEventImpl.java new file mode 100644 index 000000000..a1ea14512 --- /dev/null +++ b/api/src/main/java/com/velocitypowered/api/event/player/ServerPreConnectEventImpl.java @@ -0,0 +1,73 @@ +/* + * Copyright (C) 2018 Velocity Contributors + * + * The Velocity API is licensed under the terms of the MIT License. For more details, + * reference the LICENSE file in the api top-level directory. + */ + +package com.velocitypowered.api.event.player; + +import com.google.common.base.Preconditions; +import com.velocitypowered.api.proxy.connection.Player; +import com.velocitypowered.api.proxy.server.RegisteredServer; + +/** + * This event is fired before the player connects to a server. + */ +public final class ServerPreConnectEventImpl implements ServerPreConnectEvent { + + private final Player player; + private final RegisteredServer originalServer; + private ServerResult result; + + /** + * Creates the ServerPreConnectEvent. + * @param player the player who is connecting to a server + * @param originalServer the server the player was trying to connect to + */ + public ServerPreConnectEventImpl(Player player, RegisteredServer originalServer) { + this.player = Preconditions.checkNotNull(player, "player"); + this.originalServer = Preconditions.checkNotNull(originalServer, "originalServer"); + this.result = ServerResult.allowed(originalServer); + } + + /** + * Returns the player connecting to the server. + * @return the player connecting to the server + */ + @Override + public Player getPlayer() { + return player; + } + + @Override + public ServerResult getResult() { + return result; + } + + @Override + public void setResult(ServerResult result) { + this.result = Preconditions.checkNotNull(result, "result"); + } + + /** + * Returns the server that the player originally tried to connect to. To get the server the + * player will connect to, see the {@link ServerResult} of this event. To get the server the + * player is currently on when this event is fired, use {@link Player#getCurrentServer()}. + * @return the server that the player originally tried to connect to + */ + @Override + public RegisteredServer getOriginalServer() { + return originalServer; + } + + @Override + public String toString() { + return "ServerPreConnectEvent{" + + "player=" + player + + ", originalServer=" + originalServer + + ", result=" + result + + '}'; + } + +} diff --git a/api/src/main/java/com/velocitypowered/api/event/player/TabCompleteEvent.java b/api/src/main/java/com/velocitypowered/api/event/player/TabCompleteEvent.java index 96efd694c..0871322cb 100644 --- a/api/src/main/java/com/velocitypowered/api/event/player/TabCompleteEvent.java +++ b/api/src/main/java/com/velocitypowered/api/event/player/TabCompleteEvent.java @@ -7,63 +7,33 @@ package com.velocitypowered.api.event.player; -import static com.google.common.base.Preconditions.checkNotNull; - import com.velocitypowered.api.proxy.connection.Player; -import java.util.ArrayList; import java.util.List; /** * This event is fired after a tab complete response is sent by the remote server, for clients on * 1.12.2 and below. You have the opportunity to modify the response sent to the remote player. */ -public class TabCompleteEvent { - private final Player player; - private final String partialMessage; - private final List suggestions; - - /** - * Constructs a new TabCompleteEvent instance. - * @param player the player - * @param partialMessage the partial message - * @param suggestions the initial list of suggestions - */ - public TabCompleteEvent(Player player, String partialMessage, List suggestions) { - this.player = checkNotNull(player, "player"); - this.partialMessage = checkNotNull(partialMessage, "partialMessage"); - this.suggestions = new ArrayList<>(checkNotNull(suggestions, "suggestions")); - } +public interface TabCompleteEvent { /** * Returns the player requesting the tab completion. + * * @return the requesting player */ - public Player getPlayer() { - return player; - } + Player getPlayer(); /** * Returns the message being partially completed. + * * @return the partial message */ - public String getPartialMessage() { - return partialMessage; - } + String getPartialMessage(); /** * Returns all the suggestions provided to the user, as a mutable list. + * * @return the suggestions */ - public List getSuggestions() { - return suggestions; - } - - @Override - public String toString() { - return "TabCompleteEvent{" - + "player=" + player - + ", partialMessage='" + partialMessage + '\'' - + ", suggestions=" + suggestions - + '}'; - } + List getSuggestions(); } diff --git a/api/src/main/java/com/velocitypowered/api/event/player/TabCompleteEventImpl.java b/api/src/main/java/com/velocitypowered/api/event/player/TabCompleteEventImpl.java new file mode 100644 index 000000000..5f51ca1ac --- /dev/null +++ b/api/src/main/java/com/velocitypowered/api/event/player/TabCompleteEventImpl.java @@ -0,0 +1,72 @@ +/* + * Copyright (C) 2018 Velocity Contributors + * + * The Velocity API is licensed under the terms of the MIT License. For more details, + * reference the LICENSE file in the api top-level directory. + */ + +package com.velocitypowered.api.event.player; + +import static com.google.common.base.Preconditions.checkNotNull; + +import com.velocitypowered.api.proxy.connection.Player; +import java.util.ArrayList; +import java.util.List; + +/** + * This event is fired after a tab complete response is sent by the remote server, for clients on + * 1.12.2 and below. You have the opportunity to modify the response sent to the remote player. + */ +public class TabCompleteEventImpl implements TabCompleteEvent { + private final Player player; + private final String partialMessage; + private final List suggestions; + + /** + * Constructs a new TabCompleteEvent instance. + * @param player the player + * @param partialMessage the partial message + * @param suggestions the initial list of suggestions + */ + public TabCompleteEventImpl(Player player, String partialMessage, List suggestions) { + this.player = checkNotNull(player, "player"); + this.partialMessage = checkNotNull(partialMessage, "partialMessage"); + this.suggestions = new ArrayList<>(checkNotNull(suggestions, "suggestions")); + } + + /** + * Returns the player requesting the tab completion. + * @return the requesting player + */ + @Override + public Player getPlayer() { + return player; + } + + /** + * Returns the message being partially completed. + * @return the partial message + */ + @Override + public String getPartialMessage() { + return partialMessage; + } + + /** + * Returns all the suggestions provided to the user, as a mutable list. + * @return the suggestions + */ + @Override + public List getSuggestions() { + return suggestions; + } + + @Override + public String toString() { + return "TabCompleteEvent{" + + "player=" + player + + ", partialMessage='" + partialMessage + '\'' + + ", suggestions=" + suggestions + + '}'; + } +} diff --git a/api/src/main/java/com/velocitypowered/api/proxy/connection/Player.java b/api/src/main/java/com/velocitypowered/api/proxy/connection/Player.java index 95a1203e9..a1a489ed0 100644 --- a/api/src/main/java/com/velocitypowered/api/proxy/connection/Player.java +++ b/api/src/main/java/com/velocitypowered/api/proxy/connection/Player.java @@ -8,7 +8,7 @@ package com.velocitypowered.api.proxy.connection; import com.velocitypowered.api.command.CommandSource; -import com.velocitypowered.api.event.player.PlayerResourcePackStatusEvent; +import com.velocitypowered.api.event.player.PlayerResourcePackStatusEventImpl; import com.velocitypowered.api.proxy.messages.ChannelMessageSink; import com.velocitypowered.api.proxy.messages.ChannelMessageSource; import com.velocitypowered.api.proxy.player.ConnectionRequestBuilder; @@ -123,7 +123,7 @@ public interface Player extends CommandSource, Identified, InboundConnection, /** * 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}. + * sent resource pack, subscribe to {@link PlayerResourcePackStatusEventImpl}. * * @param url the URL for the resource pack */ @@ -132,7 +132,7 @@ public interface Player extends CommandSource, Identified, InboundConnection, /** * 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}. + * {@link PlayerResourcePackStatusEventImpl}. * * @param url the URL for the resource pack * @param hash the SHA-1 hash value for the resource pack diff --git a/proxy/src/main/java/com/velocitypowered/proxy/VelocityServer.java b/proxy/src/main/java/com/velocitypowered/proxy/VelocityServer.java index f2c541428..b5866eb99 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/VelocityServer.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/VelocityServer.java @@ -23,9 +23,9 @@ import com.google.common.collect.ImmutableList; import com.google.gson.Gson; import com.google.gson.GsonBuilder; import com.velocitypowered.api.event.EventManager; -import com.velocitypowered.api.event.lifecycle.ProxyInitializeEvent; -import com.velocitypowered.api.event.lifecycle.ProxyReloadEvent; -import com.velocitypowered.api.event.lifecycle.ProxyShutdownEvent; +import com.velocitypowered.api.event.lifecycle.ProxyInitializeEventImpl; +import com.velocitypowered.api.event.lifecycle.ProxyReloadEventImpl; +import com.velocitypowered.api.event.lifecycle.ProxyShutdownEventImpl; import com.velocitypowered.api.network.ProtocolVersion; import com.velocitypowered.api.plugin.PluginContainer; import com.velocitypowered.api.plugin.PluginManager; @@ -214,7 +214,7 @@ public class VelocityServer implements ProxyServer, ForwardingAudience { // Go ahead and fire the proxy initialization event. We block since plugins should have a chance // to fully initialize before we accept any connections to the server. - eventManager.fire(new ProxyInitializeEvent()).join(); + eventManager.fire(new ProxyInitializeEventImpl()).join(); // init console permissions after plugins are loaded console.setupPermissions(); @@ -390,7 +390,7 @@ public class VelocityServer implements ProxyServer, ForwardingAudience { ipAttemptLimiter = Ratelimiters.createWithMilliseconds(newConfiguration.getLoginRatelimit()); this.configuration = newConfiguration; - eventManager.fireAndForget(new ProxyReloadEvent()); + eventManager.fireAndForget(new ProxyReloadEventImpl()); return true; } @@ -441,7 +441,7 @@ public class VelocityServer implements ProxyServer, ForwardingAudience { } try { - eventManager.fire(new ProxyShutdownEvent()).get(10, TimeUnit.SECONDS); + eventManager.fire(new ProxyShutdownEventImpl()).get(10, TimeUnit.SECONDS); } catch (TimeoutException e) { timedOut = true; } catch (ExecutionException e) { diff --git a/proxy/src/main/java/com/velocitypowered/proxy/command/VelocityCommandManager.java b/proxy/src/main/java/com/velocitypowered/proxy/command/VelocityCommandManager.java index 75325a29f..5895acfb4 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/command/VelocityCommandManager.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/command/VelocityCommandManager.java @@ -34,6 +34,7 @@ import com.velocitypowered.api.command.RawCommand; import com.velocitypowered.api.command.SimpleCommand; import com.velocitypowered.api.event.command.CommandExecuteEvent; import com.velocitypowered.api.event.command.CommandExecuteEvent.CommandResult; +import com.velocitypowered.api.event.command.CommandExecuteEventImpl; import com.velocitypowered.proxy.event.VelocityEventManager; import com.velocitypowered.proxy.util.BrigadierUtils; import java.util.Iterator; @@ -117,7 +118,7 @@ public class VelocityCommandManager implements CommandManager { } /** - * Fires a {@link CommandExecuteEvent}. + * Fires a {@link CommandExecuteEventImpl}. * * @param source the source to execute the command for * @param cmdLine the command to execute @@ -127,7 +128,7 @@ public class VelocityCommandManager implements CommandManager { final String cmdLine) { Preconditions.checkNotNull(source, "source"); Preconditions.checkNotNull(cmdLine, "cmdLine"); - return eventManager.fire(new CommandExecuteEvent(source, cmdLine)); + return eventManager.fire(new CommandExecuteEventImpl(source, cmdLine)); } private boolean executeImmediately0(final CommandSource source, final String cmdLine) { diff --git a/proxy/src/main/java/com/velocitypowered/proxy/connection/backend/BackendPlaySessionHandler.java b/proxy/src/main/java/com/velocitypowered/proxy/connection/backend/BackendPlaySessionHandler.java index b3dd0e715..877ca182c 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/connection/backend/BackendPlaySessionHandler.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/connection/backend/BackendPlaySessionHandler.java @@ -24,7 +24,7 @@ import com.mojang.brigadier.builder.ArgumentBuilder; import com.mojang.brigadier.tree.CommandNode; import com.mojang.brigadier.tree.RootCommandNode; import com.velocitypowered.api.command.CommandSource; -import com.velocitypowered.api.event.command.PlayerAvailableCommandsEvent; +import com.velocitypowered.api.event.command.PlayerAvailableCommandsEventImpl; import com.velocitypowered.api.event.connection.PluginMessageEvent; import com.velocitypowered.api.network.ProtocolVersion; import com.velocitypowered.api.proxy.messages.ChannelIdentifier; @@ -214,7 +214,7 @@ public class BackendPlaySessionHandler implements MinecraftSessionHandler { } server.getEventManager().fire( - new PlayerAvailableCommandsEvent(serverConn.getPlayer(), rootNode)) + new PlayerAvailableCommandsEventImpl(serverConn.getPlayer(), rootNode)) .thenAcceptAsync(event -> playerConnection.write(commands), playerConnection.eventLoop()) .exceptionally((ex) -> { logger.error("Exception while handling available commands for {}", playerConnection, ex); diff --git a/proxy/src/main/java/com/velocitypowered/proxy/connection/backend/TransitionSessionHandler.java b/proxy/src/main/java/com/velocitypowered/proxy/connection/backend/TransitionSessionHandler.java index 1b29e36ec..0aad3103b 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/connection/backend/TransitionSessionHandler.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/connection/backend/TransitionSessionHandler.java @@ -20,8 +20,8 @@ package com.velocitypowered.proxy.connection.backend; import static com.velocitypowered.proxy.connection.backend.BackendConnectionPhases.IN_TRANSITION; import static com.velocitypowered.proxy.connection.forge.legacy.LegacyForgeHandshakeBackendPhase.HELLO; -import com.velocitypowered.api.event.player.ServerConnectedEvent; -import com.velocitypowered.api.event.player.ServerPostConnectEvent; +import com.velocitypowered.api.event.player.ServerConnectedEventImpl; +import com.velocitypowered.api.event.player.ServerPostConnectEventImpl; import com.velocitypowered.proxy.VelocityServer; import com.velocitypowered.proxy.connection.ConnectionTypes; import com.velocitypowered.proxy.connection.MinecraftConnection; @@ -101,7 +101,7 @@ public class TransitionSessionHandler implements MinecraftSessionHandler { // The goods are in hand! We got JoinGame. Let's transition completely to the new state. smc.setAutoReading(false); server.getEventManager() - .fire(new ServerConnectedEvent(player, serverConn.getServer(), + .fire(new ServerConnectedEventImpl(player, serverConn.getServer(), existingConnection != null ? existingConnection.getServer() : null)) .thenRunAsync(() -> { // Make sure we can still transition (player might have disconnected here). @@ -132,7 +132,7 @@ public class TransitionSessionHandler implements MinecraftSessionHandler { serverConn.getPlayer().setConnectedServer(serverConn); // We're done! :) - server.getEventManager().fireAndForget(new ServerPostConnectEvent(player, + server.getEventManager().fireAndForget(new ServerPostConnectEventImpl(player, existingConnection == null ? null : existingConnection.getServer())); resultFuture.complete(ConnectionRequestResults.successful(serverConn.getServer())); }, smc.eventLoop()) diff --git a/proxy/src/main/java/com/velocitypowered/proxy/connection/client/ClientPlaySessionHandler.java b/proxy/src/main/java/com/velocitypowered/proxy/connection/client/ClientPlaySessionHandler.java index 36bfb5cbd..3f5112c4b 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/connection/client/ClientPlaySessionHandler.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/connection/client/ClientPlaySessionHandler.java @@ -25,10 +25,11 @@ import static com.velocitypowered.proxy.network.PluginMessageUtil.constructChann import com.google.common.collect.ImmutableList; import com.velocitypowered.api.event.command.CommandExecuteEvent.CommandResult; import com.velocitypowered.api.event.connection.PluginMessageEvent; -import com.velocitypowered.api.event.player.PlayerChannelRegisterEvent; +import com.velocitypowered.api.event.player.PlayerChannelRegisterEventImpl; import com.velocitypowered.api.event.player.PlayerChatEvent; -import com.velocitypowered.api.event.player.PlayerResourcePackStatusEvent; -import com.velocitypowered.api.event.player.TabCompleteEvent; +import com.velocitypowered.api.event.player.PlayerChatEventImpl; +import com.velocitypowered.api.event.player.PlayerResourcePackStatusEventImpl; +import com.velocitypowered.api.event.player.TabCompleteEventImpl; import com.velocitypowered.api.network.ProtocolVersion; import com.velocitypowered.api.proxy.messages.ChannelIdentifier; import com.velocitypowered.api.proxy.messages.LegacyChannelIdentifier; @@ -173,10 +174,10 @@ public class ClientPlaySessionHandler implements MinecraftSessionHandler { return null; }); } else { - PlayerChatEvent event = new PlayerChatEvent(player, msg); + PlayerChatEvent event = new PlayerChatEventImpl(player, msg); server.getEventManager().fire(event) .thenAcceptAsync(pme -> { - PlayerChatEvent.ChatResult chatResult = pme.getResult(); + PlayerChatEventImpl.ChatResult chatResult = pme.getResult(); if (chatResult.isAllowed()) { Optional eventMsg = pme.getResult().getMessage(); if (eventMsg.isPresent()) { @@ -224,7 +225,7 @@ public class ClientPlaySessionHandler implements MinecraftSessionHandler { channelIdentifiers.add(new LegacyChannelIdentifier(channel)); } } - server.getEventManager().fireAndForget(new PlayerChannelRegisterEvent(player, + server.getEventManager().fireAndForget(new PlayerChannelRegisterEventImpl(player, ImmutableList.copyOf(channelIdentifiers))); backendConn.write(packet.retain()); } else if (PluginMessageUtil.isUnregister(packet)) { @@ -286,7 +287,7 @@ public class ClientPlaySessionHandler implements MinecraftSessionHandler { @Override public boolean handle(ServerboundResourcePackResponsePacket packet) { - server.getEventManager().fireAndForget(new PlayerResourcePackStatusEvent(player, + server.getEventManager().fireAndForget(new PlayerResourcePackStatusEventImpl(player, packet.getStatus())); return false; } @@ -576,7 +577,7 @@ public class ClientPlaySessionHandler implements MinecraftSessionHandler { for (Offer offer : response.getOffers()) { offers.add(offer.getText()); } - server.getEventManager().fire(new TabCompleteEvent(player, request.getCommand(), offers)) + server.getEventManager().fire(new TabCompleteEventImpl(player, request.getCommand(), offers)) .thenAcceptAsync(e -> { response.getOffers().clear(); for (String s : e.getSuggestions()) { diff --git a/proxy/src/main/java/com/velocitypowered/proxy/connection/client/ConnectedPlayer.java b/proxy/src/main/java/com/velocitypowered/proxy/connection/client/ConnectedPlayer.java index 8039ec4eb..9bcd6a6de 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/connection/client/ConnectedPlayer.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/connection/client/ConnectedPlayer.java @@ -25,14 +25,17 @@ import com.google.common.base.Preconditions; import com.google.gson.JsonObject; import com.velocitypowered.api.event.player.DisconnectEvent; import com.velocitypowered.api.event.player.DisconnectEvent.LoginStatus; +import com.velocitypowered.api.event.player.DisconnectEventImpl; import com.velocitypowered.api.event.player.KickedFromServerEvent; import com.velocitypowered.api.event.player.KickedFromServerEvent.DisconnectPlayer; import com.velocitypowered.api.event.player.KickedFromServerEvent.Notify; import com.velocitypowered.api.event.player.KickedFromServerEvent.RedirectPlayer; import com.velocitypowered.api.event.player.KickedFromServerEvent.ServerKickResult; -import com.velocitypowered.api.event.player.PlayerModInfoEvent; -import com.velocitypowered.api.event.player.PlayerSettingsChangedEvent; +import com.velocitypowered.api.event.player.KickedFromServerEventImpl; +import com.velocitypowered.api.event.player.PlayerModInfoEventImpl; +import com.velocitypowered.api.event.player.PlayerSettingsChangedEventImpl; import com.velocitypowered.api.event.player.ServerPreConnectEvent; +import com.velocitypowered.api.event.player.ServerPreConnectEventImpl; import com.velocitypowered.api.network.ProtocolVersion; import com.velocitypowered.api.permission.PermissionFunction; import com.velocitypowered.api.permission.PermissionProvider; @@ -59,7 +62,6 @@ import com.velocitypowered.proxy.network.StateRegistry; import com.velocitypowered.proxy.network.packet.AbstractPluginMessagePacket; import com.velocitypowered.proxy.network.packet.clientbound.ClientboundChatPacket; import com.velocitypowered.proxy.network.packet.clientbound.ClientboundDisconnectPacket; -import com.velocitypowered.proxy.network.packet.clientbound.ClientboundHeaderAndFooterPacket; import com.velocitypowered.proxy.network.packet.clientbound.ClientboundKeepAlivePacket; import com.velocitypowered.proxy.network.packet.clientbound.ClientboundPluginMessagePacket; import com.velocitypowered.proxy.network.packet.clientbound.ClientboundResourcePackRequestPacket; @@ -212,7 +214,7 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player { void setPlayerSettings(ServerboundClientSettingsPacket settings) { ClientSettingsWrapper cs = new ClientSettingsWrapper(settings); this.settings = cs; - server.getEventManager().fireAndForget(new PlayerSettingsChangedEvent(this, cs)); + server.getEventManager().fireAndForget(new PlayerSettingsChangedEventImpl(this, cs)); } @Override @@ -222,7 +224,7 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player { public void setModInfo(ModInfo modInfo) { this.modInfo = modInfo; - server.getEventManager().fireAndForget(new PlayerModInfoEvent(this, modInfo)); + server.getEventManager().fireAndForget(new PlayerModInfoEventImpl(this, modInfo)); } @Override @@ -505,7 +507,7 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player { } result = Notify.create(friendlyReason); } - KickedFromServerEvent originalEvent = new KickedFromServerEvent(this, rs, kickReason, + KickedFromServerEvent originalEvent = new KickedFromServerEventImpl(this, rs, kickReason, !kickedFromCurrent, result); handleKickEvent(originalEvent, friendlyReason, kickedFromCurrent); } @@ -669,7 +671,7 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player { Optional connectedPlayer = server.getPlayer(this.getUniqueId()); server.unregisterConnection(this); - DisconnectEvent.LoginStatus status; + DisconnectEventImpl.LoginStatus status; if (connectedPlayer.isPresent()) { if (!connectedPlayer.get().getCurrentServer().isPresent()) { status = LoginStatus.PRE_SERVER_JOIN; @@ -682,7 +684,7 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player { LoginStatus.CANCELLED_BY_USER; } - DisconnectEvent event = new DisconnectEvent(this, status); + DisconnectEvent event = new DisconnectEventImpl(this, status); server.getEventManager().fire(event).whenComplete((val, ex) -> { if (ex == null) { this.teardownFuture.complete(null); @@ -852,7 +854,7 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player { return completedFuture(plainResult(initialCheck.get(), toConnect)); } - ServerPreConnectEvent event = new ServerPreConnectEvent(ConnectedPlayer.this, + ServerPreConnectEvent event = new ServerPreConnectEventImpl(ConnectedPlayer.this, toConnect); return server.getEventManager().fire(event) .thenComposeAsync(newEvent -> { diff --git a/proxy/src/main/java/com/velocitypowered/proxy/connection/client/HandshakeSessionHandler.java b/proxy/src/main/java/com/velocitypowered/proxy/connection/client/HandshakeSessionHandler.java index 07b15b3bf..bed65af85 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/connection/client/HandshakeSessionHandler.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/connection/client/HandshakeSessionHandler.java @@ -19,7 +19,7 @@ package com.velocitypowered.proxy.connection.client; import com.google.common.annotations.VisibleForTesting; import com.google.common.base.Preconditions; -import com.velocitypowered.api.event.connection.ConnectionHandshakeEvent; +import com.velocitypowered.api.event.connection.ConnectionHandshakeEventImpl; import com.velocitypowered.api.network.ProtocolVersion; import com.velocitypowered.api.proxy.connection.InboundConnection; import com.velocitypowered.proxy.VelocityServer; @@ -136,7 +136,7 @@ public class HandshakeSessionHandler implements MinecraftSessionHandler { return; } - server.getEventManager().fireAndForget(new ConnectionHandshakeEvent(ic)); + server.getEventManager().fireAndForget(new ConnectionHandshakeEventImpl(ic)); connection.setSessionHandler(new LoginSessionHandler(server, connection, ic)); } diff --git a/proxy/src/main/java/com/velocitypowered/proxy/connection/client/LoginSessionHandler.java b/proxy/src/main/java/com/velocitypowered/proxy/connection/client/LoginSessionHandler.java index 635d8135e..31b1919e7 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/connection/client/LoginSessionHandler.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/connection/client/LoginSessionHandler.java @@ -25,15 +25,17 @@ import static com.velocitypowered.proxy.util.EncryptionUtils.decryptRsa; import static com.velocitypowered.proxy.util.EncryptionUtils.generateServerId; import com.google.common.base.Preconditions; -import com.velocitypowered.api.event.permission.PermissionsSetupEvent; -import com.velocitypowered.api.event.player.DisconnectEvent; +import com.velocitypowered.api.event.permission.PermissionsSetupEventImpl; import com.velocitypowered.api.event.player.DisconnectEvent.LoginStatus; +import com.velocitypowered.api.event.player.DisconnectEventImpl; import com.velocitypowered.api.event.player.GameProfileRequestEvent; -import com.velocitypowered.api.event.player.LoginEvent; +import com.velocitypowered.api.event.player.LoginEventImpl; import com.velocitypowered.api.event.player.PlayerChooseInitialServerEvent; -import com.velocitypowered.api.event.player.PostLoginEvent; +import com.velocitypowered.api.event.player.PlayerChooseInitialServerEventImpl; +import com.velocitypowered.api.event.player.PostLoginEventImpl; import com.velocitypowered.api.event.player.PreLoginEvent; import com.velocitypowered.api.event.player.PreLoginEvent.PreLoginComponentResult; +import com.velocitypowered.api.event.player.PreLoginEventImpl; import com.velocitypowered.api.permission.PermissionFunction; import com.velocitypowered.api.proxy.server.RegisteredServer; import com.velocitypowered.api.util.GameProfile; @@ -176,7 +178,7 @@ public class LoginSessionHandler implements MinecraftSessionHandler { if (login == null) { throw new IllegalStateException("No ServerLogin packet received yet."); } - PreLoginEvent event = new PreLoginEvent(inbound, login.getUsername()); + PreLoginEvent event = new PreLoginEventImpl(inbound, login.getUsername()); server.getEventManager().fire(event) .thenRunAsync(() -> { if (mcConnection.isClosed()) { @@ -245,7 +247,7 @@ public class LoginSessionHandler implements MinecraftSessionHandler { logger.info("{} has connected", player); return server.getEventManager() - .fire(new PermissionsSetupEvent(player, ConnectedPlayer.DEFAULT_PERMISSIONS)) + .fire(new PermissionsSetupEventImpl(player, ConnectedPlayer.DEFAULT_PERMISSIONS)) .thenAcceptAsync(event -> { if (!mcConnection.isClosed()) { // wait for permissions to load, then set the players permission function @@ -285,11 +287,11 @@ public class LoginSessionHandler implements MinecraftSessionHandler { mcConnection.setAssociation(player); mcConnection.setState(StateRegistry.PLAY); - server.getEventManager().fire(new LoginEvent(player)) + server.getEventManager().fire(new LoginEventImpl(player)) .thenAcceptAsync(event -> { if (mcConnection.isClosed()) { // The player was disconnected - server.getEventManager().fireAndForget(new DisconnectEvent(player, + server.getEventManager().fireAndForget(new DisconnectEventImpl(player, LoginStatus.CANCELLED_BY_USER_BEFORE_COMPLETE)); return; } @@ -305,7 +307,7 @@ public class LoginSessionHandler implements MinecraftSessionHandler { } mcConnection.setSessionHandler(new InitialConnectSessionHandler(player)); - server.getEventManager().fire(new PostLoginEvent(player)) + server.getEventManager().fire(new PostLoginEventImpl(player)) .thenCompose((ignored) -> connectToInitialServer(player)) .exceptionally((ex) -> { logger.error("Exception while connecting {} to initial server", player, ex); @@ -321,7 +323,7 @@ public class LoginSessionHandler implements MinecraftSessionHandler { private CompletableFuture connectToInitialServer(ConnectedPlayer player) { Optional initialFromConfig = player.getNextServerToTry(); - PlayerChooseInitialServerEvent event = new PlayerChooseInitialServerEvent(player, + PlayerChooseInitialServerEvent event = new PlayerChooseInitialServerEventImpl(player, initialFromConfig.orElse(null)); return server.getEventManager().fire(event) diff --git a/proxy/src/main/java/com/velocitypowered/proxy/connection/client/StatusSessionHandler.java b/proxy/src/main/java/com/velocitypowered/proxy/connection/client/StatusSessionHandler.java index 9b963b4bd..58331c84d 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/connection/client/StatusSessionHandler.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/connection/client/StatusSessionHandler.java @@ -19,7 +19,7 @@ package com.velocitypowered.proxy.connection.client; import com.google.common.collect.ImmutableList; import com.spotify.futures.CompletableFutures; -import com.velocitypowered.api.event.connection.ProxyPingEvent; +import com.velocitypowered.api.event.connection.ProxyPingEventImpl; import com.velocitypowered.api.network.ProtocolVersion; import com.velocitypowered.api.proxy.connection.InboundConnection; import com.velocitypowered.api.proxy.server.RegisteredServer; @@ -182,7 +182,7 @@ public class StatusSessionHandler implements MinecraftSessionHandler { } this.pingReceived = true; getInitialPing() - .thenCompose(ping -> server.getEventManager().fire(new ProxyPingEvent(inbound, ping))) + .thenCompose(ping -> server.getEventManager().fire(new ProxyPingEventImpl(inbound, ping))) .thenAcceptAsync(event -> connection.closeWith( LegacyDisconnectPacket.fromServerPing(event.getPing(), packet.getVersion())), connection.eventLoop()) @@ -207,7 +207,7 @@ public class StatusSessionHandler implements MinecraftSessionHandler { this.pingReceived = true; getInitialPing() - .thenCompose(ping -> server.getEventManager().fire(new ProxyPingEvent(inbound, ping))) + .thenCompose(ping -> server.getEventManager().fire(new ProxyPingEventImpl(inbound, ping))) .thenAcceptAsync( (event) -> { StringBuilder json = new StringBuilder(); diff --git a/proxy/src/main/java/com/velocitypowered/proxy/console/VelocityConsole.java b/proxy/src/main/java/com/velocitypowered/proxy/console/VelocityConsole.java index 0f57b6ef4..cd8df4f36 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/console/VelocityConsole.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/console/VelocityConsole.java @@ -21,6 +21,7 @@ import static com.velocitypowered.api.permission.PermissionFunction.ALWAYS_TRUE; import com.velocitypowered.api.command.ConsoleCommandSource; import com.velocitypowered.api.event.permission.PermissionsSetupEvent; +import com.velocitypowered.api.event.permission.PermissionsSetupEventImpl; import com.velocitypowered.api.permission.PermissionFunction; import com.velocitypowered.api.permission.Tristate; import com.velocitypowered.proxy.VelocityServer; @@ -72,7 +73,7 @@ public final class VelocityConsole extends SimpleTerminalConsole implements Cons * Sets up permissions for the console. */ public void setupPermissions() { - PermissionsSetupEvent event = new PermissionsSetupEvent(this, s -> ALWAYS_TRUE); + PermissionsSetupEvent event = new PermissionsSetupEventImpl(this, s -> ALWAYS_TRUE); // we can safely block here, this is before any listeners fire this.permissionFunction = this.server.getEventManager().fire(event).join().createFunction(this); if (this.permissionFunction == null) { diff --git a/proxy/src/main/java/com/velocitypowered/proxy/network/ConnectionManager.java b/proxy/src/main/java/com/velocitypowered/proxy/network/ConnectionManager.java index 8c56b7c6d..62fa5e84e 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/network/ConnectionManager.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/network/ConnectionManager.java @@ -21,8 +21,8 @@ import static org.asynchttpclient.Dsl.asyncHttpClient; import static org.asynchttpclient.Dsl.config; import com.google.common.base.Preconditions; -import com.velocitypowered.api.event.lifecycle.network.ListenerBoundEvent; -import com.velocitypowered.api.event.lifecycle.network.ListenerClosedEvent; +import com.velocitypowered.api.event.lifecycle.network.ListenerBoundEventImpl; +import com.velocitypowered.api.event.lifecycle.network.ListenerClosedEventImpl; import com.velocitypowered.api.network.ListenerType; import com.velocitypowered.natives.util.Natives; import com.velocitypowered.proxy.VelocityServer; @@ -136,7 +136,7 @@ public final class ConnectionManager { // Fire the proxy bound event after the socket is bound server.getEventManager().fireAndForget( - new ListenerBoundEvent(address, ListenerType.MINECRAFT)); + new ListenerBoundEventImpl(address, ListenerType.MINECRAFT)); } else { LOGGER.error("Can't bind to {}", address, future.cause()); } @@ -165,7 +165,7 @@ public final class ConnectionManager { // Fire the proxy bound event after the socket is bound server.getEventManager().fireAndForget( - new ListenerBoundEvent(address, ListenerType.QUERY)); + new ListenerBoundEventImpl(address, ListenerType.QUERY)); } else { LOGGER.error("Can't bind to {}", bootstrap.config().localAddress(), future.cause()); } @@ -203,7 +203,7 @@ public final class ConnectionManager { // Fire proxy close event to notify plugins of socket close. We block since plugins // should have a chance to be notified before the server stops accepting connections. - server.getEventManager().fire(new ListenerClosedEvent(oldBind, endpoint.getType())).join(); + server.getEventManager().fire(new ListenerClosedEventImpl(oldBind, endpoint.getType())).join(); Channel serverChannel = endpoint.getChannel(); @@ -222,7 +222,7 @@ public final class ConnectionManager { // Fire proxy close event to notify plugins of socket close. We block since plugins // should have a chance to be notified before the server stops accepting connections. - server.getEventManager().fire(new ListenerClosedEvent(address, endpoint.getType())).join(); + server.getEventManager().fire(new ListenerClosedEventImpl(address, endpoint.getType())).join(); try { LOGGER.info("Closing endpoint {}", address); diff --git a/proxy/src/main/java/com/velocitypowered/proxy/network/pipeline/GS4QueryHandler.java b/proxy/src/main/java/com/velocitypowered/proxy/network/pipeline/GS4QueryHandler.java index 026789e1d..fc33e0b11 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/network/pipeline/GS4QueryHandler.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/network/pipeline/GS4QueryHandler.java @@ -23,7 +23,7 @@ import static com.velocitypowered.api.event.connection.ProxyQueryEvent.QueryType import com.google.common.cache.Cache; import com.google.common.cache.CacheBuilder; import com.google.common.collect.ImmutableSet; -import com.velocitypowered.api.event.connection.ProxyQueryEvent; +import com.velocitypowered.api.event.connection.ProxyQueryEventImpl; import com.velocitypowered.api.network.ProtocolVersion; import com.velocitypowered.api.plugin.PluginContainer; import com.velocitypowered.api.plugin.PluginDescription; @@ -151,7 +151,7 @@ public class GS4QueryHandler extends SimpleChannelInboundHandler // Call event and write response server.getEventManager() - .fire(new ProxyQueryEvent(isBasic ? BASIC : FULL, senderAddress, response)) + .fire(new ProxyQueryEventImpl(isBasic ? BASIC : FULL, senderAddress, response)) .whenCompleteAsync((event, exc) -> { // Packet header ByteBuf queryResponse = ctx.alloc().buffer(); From a6728476db23157f7d070277f416ef858c44671c Mon Sep 17 00:00:00 2001 From: Andrew Steinborn Date: Sat, 17 Apr 2021 03:52:01 -0400 Subject: [PATCH 27/99] I missed a spot --- .../event/player/GameProfileRequestEvent.java | 62 ++----------- .../player/GameProfileRequestEventImpl.java | 92 +++++++++++++++++++ .../client/LoginSessionHandler.java | 3 +- 3 files changed, 103 insertions(+), 54 deletions(-) create mode 100644 api/src/main/java/com/velocitypowered/api/event/player/GameProfileRequestEventImpl.java diff --git a/api/src/main/java/com/velocitypowered/api/event/player/GameProfileRequestEvent.java b/api/src/main/java/com/velocitypowered/api/event/player/GameProfileRequestEvent.java index 8609d91bb..3a5b38d9e 100644 --- a/api/src/main/java/com/velocitypowered/api/event/player/GameProfileRequestEvent.java +++ b/api/src/main/java/com/velocitypowered/api/event/player/GameProfileRequestEvent.java @@ -7,53 +7,23 @@ package com.velocitypowered.api.event.player; -import com.google.common.base.Preconditions; import com.velocitypowered.api.proxy.connection.InboundConnection; import com.velocitypowered.api.util.GameProfile; import org.checkerframework.checker.nullness.qual.Nullable; /** - * This event is fired after the {@link PreLoginEventImpl} in - * order to set up the game profile for the user. This can be used to configure a custom profile for - * a user, i.e. skin replacement. + * This event is fired after the {@link PreLoginEventImpl} in order to set up the game profile for + * the user. This can be used to configure a custom profile for a user, i.e. skin replacement. */ -public final class GameProfileRequestEvent { +public interface GameProfileRequestEvent { - private final String username; - private final InboundConnection connection; - private final GameProfile originalProfile; - private final boolean onlineMode; - private @Nullable GameProfile gameProfile; + InboundConnection getConnection(); - /** - * Creates a new instance. - * @param connection the connection connecting to the proxy - * @param originalProfile the original {@link GameProfile} for the user - * @param onlineMode whether or not the user connected in online or offline mode - */ - public GameProfileRequestEvent(InboundConnection connection, GameProfile originalProfile, - boolean onlineMode) { - this.connection = Preconditions.checkNotNull(connection, "connection"); - this.originalProfile = Preconditions.checkNotNull(originalProfile, "originalProfile"); - this.username = originalProfile.getName(); - this.onlineMode = onlineMode; - } + String getUsername(); - public InboundConnection getConnection() { - return connection; - } + GameProfile getOriginalProfile(); - public String getUsername() { - return username; - } - - public GameProfile getOriginalProfile() { - return originalProfile; - } - - public boolean isOnlineMode() { - return onlineMode; - } + boolean isOnlineMode(); /** * Returns the game profile that will be used to initialize the connection with. Should no profile @@ -62,26 +32,12 @@ public final class GameProfileRequestEvent { * * @return the user's {@link GameProfile} */ - public GameProfile getGameProfile() { - return gameProfile == null ? originalProfile : gameProfile; - } + GameProfile getGameProfile(); /** * Sets the game profile to use for this connection. * * @param gameProfile the profile for this connection, {@code null} uses the original profile */ - public void setGameProfile(@Nullable GameProfile gameProfile) { - this.gameProfile = gameProfile; - } - - @Override - public String toString() { - return "GameProfileRequestEvent{" - + "username=" + username - + ", gameProfile=" + gameProfile - + "}"; - } - - + void setGameProfile(@Nullable GameProfile gameProfile); } diff --git a/api/src/main/java/com/velocitypowered/api/event/player/GameProfileRequestEventImpl.java b/api/src/main/java/com/velocitypowered/api/event/player/GameProfileRequestEventImpl.java new file mode 100644 index 000000000..b57066874 --- /dev/null +++ b/api/src/main/java/com/velocitypowered/api/event/player/GameProfileRequestEventImpl.java @@ -0,0 +1,92 @@ +/* + * Copyright (C) 2018 Velocity Contributors + * + * The Velocity API is licensed under the terms of the MIT License. For more details, + * reference the LICENSE file in the api top-level directory. + */ + +package com.velocitypowered.api.event.player; + +import com.google.common.base.Preconditions; +import com.velocitypowered.api.proxy.connection.InboundConnection; +import com.velocitypowered.api.util.GameProfile; +import org.checkerframework.checker.nullness.qual.Nullable; + +/** + * This event is fired after the {@link PreLoginEventImpl} in order to set up the game profile for + * the user. This can be used to configure a custom profile for a user, i.e. skin replacement. + */ +public final class GameProfileRequestEventImpl implements GameProfileRequestEvent { + + private final String username; + private final InboundConnection connection; + private final GameProfile originalProfile; + private final boolean onlineMode; + private @Nullable GameProfile gameProfile; + + /** + * Creates a new instance. + * @param connection the connection connecting to the proxy + * @param originalProfile the original {@link GameProfile} for the user + * @param onlineMode whether or not the user connected in online or offline mode + */ + public GameProfileRequestEventImpl(InboundConnection connection, GameProfile originalProfile, + boolean onlineMode) { + this.connection = Preconditions.checkNotNull(connection, "connection"); + this.originalProfile = Preconditions.checkNotNull(originalProfile, "originalProfile"); + this.username = originalProfile.getName(); + this.onlineMode = onlineMode; + } + + @Override + public InboundConnection getConnection() { + return connection; + } + + @Override + public String getUsername() { + return username; + } + + @Override + public GameProfile getOriginalProfile() { + return originalProfile; + } + + @Override + public boolean isOnlineMode() { + return onlineMode; + } + + /** + * Returns the game profile that will be used to initialize the connection with. Should no profile + * be currently specified, the one generated by the proxy (for offline mode) or retrieved from the + * Mojang session servers (for online mode) will be returned instead. + * + * @return the user's {@link GameProfile} + */ + @Override + public GameProfile getGameProfile() { + return gameProfile == null ? originalProfile : gameProfile; + } + + /** + * Sets the game profile to use for this connection. + * + * @param gameProfile the profile for this connection, {@code null} uses the original profile + */ + @Override + public void setGameProfile(@Nullable GameProfile gameProfile) { + this.gameProfile = gameProfile; + } + + @Override + public String toString() { + return "GameProfileRequestEvent{" + + "username=" + username + + ", gameProfile=" + gameProfile + + "}"; + } + + +} diff --git a/proxy/src/main/java/com/velocitypowered/proxy/connection/client/LoginSessionHandler.java b/proxy/src/main/java/com/velocitypowered/proxy/connection/client/LoginSessionHandler.java index 31b1919e7..1edfb613d 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/connection/client/LoginSessionHandler.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/connection/client/LoginSessionHandler.java @@ -29,6 +29,7 @@ import com.velocitypowered.api.event.permission.PermissionsSetupEventImpl; import com.velocitypowered.api.event.player.DisconnectEvent.LoginStatus; import com.velocitypowered.api.event.player.DisconnectEventImpl; import com.velocitypowered.api.event.player.GameProfileRequestEvent; +import com.velocitypowered.api.event.player.GameProfileRequestEventImpl; import com.velocitypowered.api.event.player.LoginEventImpl; import com.velocitypowered.api.event.player.PlayerChooseInitialServerEvent; import com.velocitypowered.api.event.player.PlayerChooseInitialServerEventImpl; @@ -225,7 +226,7 @@ public class LoginSessionHandler implements MinecraftSessionHandler { // Some connection types may need to alter the game profile. profile = mcConnection.getType().addGameProfileTokensIfRequired(profile, server.getConfiguration().getPlayerInfoForwardingMode()); - GameProfileRequestEvent profileRequestEvent = new GameProfileRequestEvent(inbound, profile, + GameProfileRequestEvent profileRequestEvent = new GameProfileRequestEventImpl(inbound, profile, onlineMode); final GameProfile finalProfile = profile; From cf7c2b004a324c868615d0c5fa4e71c0bfa4dc38 Mon Sep 17 00:00:00 2001 From: Andrew Steinborn Date: Sat, 17 Apr 2021 04:10:27 -0400 Subject: [PATCH 28/99] Better documentation for EventHandler --- .../java/com/velocitypowered/api/event/EventHandler.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/api/src/main/java/com/velocitypowered/api/event/EventHandler.java b/api/src/main/java/com/velocitypowered/api/event/EventHandler.java index f15e5fb9a..fdf25862e 100644 --- a/api/src/main/java/com/velocitypowered/api/event/EventHandler.java +++ b/api/src/main/java/com/velocitypowered/api/event/EventHandler.java @@ -8,8 +8,9 @@ package com.velocitypowered.api.event; /** - * Represents an interface to perform direct dispatch of an event. This makes integration easier to - * achieve with platforms such as RxJava. + * Allows a listener to receive direct dispatches of events. This interface can be used directly + * by a listener (using {@link EventManager#register(Object, Class, short, EventHandler)} or + * similar), or pass events through to an external system to be handled. */ @FunctionalInterface public interface EventHandler { From 2254e3b617b5530843e19cd78bdf086958303be5 Mon Sep 17 00:00:00 2001 From: Andrew Steinborn Date: Sat, 17 Apr 2021 04:23:58 -0400 Subject: [PATCH 29/99] Rename CommandManager#metaBuilder -> CommandManager#createMetaBuilder --- .../com/velocitypowered/api/command/Command.java | 15 ++++++--------- .../api/command/CommandInvocation.java | 2 +- .../api/command/CommandManager.java | 6 +++--- .../proxy/command/VelocityCommandManager.java | 6 +++--- .../proxy/command/CommandManagerTests.java | 5 ++--- 5 files changed, 15 insertions(+), 19 deletions(-) diff --git a/api/src/main/java/com/velocitypowered/api/command/Command.java b/api/src/main/java/com/velocitypowered/api/command/Command.java index 774c70fdd..68f4594e4 100644 --- a/api/src/main/java/com/velocitypowered/api/command/Command.java +++ b/api/src/main/java/com/velocitypowered/api/command/Command.java @@ -13,19 +13,16 @@ import com.velocitypowered.api.proxy.connection.Player; * Represents a command that can be executed by a {@link CommandSource} * such as a {@link Player} or the console. * - *

Velocity 1.1.0 introduces specialized command subinterfaces to separate - * command parsing concerns. These include, in order of preference: + *

You should not subclass Command. Use one of the following + * subinterfaces:

* *
    - *
  • {@link BrigadierCommand}, which supports parameterized arguments and - * specialized execution, tab complete suggestions and permission-checking logic. + *
  • {@link BrigadierCommand} wraps a Brigadier literal command node. It supports parameterized + * arguments and specialized execution, tab complete suggestions and permission-checking logic. * - *
  • {@link SimpleCommand}, modelled after the convention popularized by - * Bukkit and BungeeCord. Older classes directly implementing {@link Command} - * are suggested to migrate to this interface. + *
  • {@link SimpleCommand} is modelled after the convention popularized by Bukkit and BungeeCord. * - *
  • {@link RawCommand}, useful for bolting on external command frameworks - * to Velocity. + *
  • {@link RawCommand} is useful for bolting on external command frameworks onto Velocity. * *
*/ diff --git a/api/src/main/java/com/velocitypowered/api/command/CommandInvocation.java b/api/src/main/java/com/velocitypowered/api/command/CommandInvocation.java index 4ac13e8ed..bc9be26ea 100644 --- a/api/src/main/java/com/velocitypowered/api/command/CommandInvocation.java +++ b/api/src/main/java/com/velocitypowered/api/command/CommandInvocation.java @@ -8,7 +8,7 @@ package com.velocitypowered.api.command; /** - * Provides information related to the possible execution of a {@link Command}. + * Provides information related to the (possible) execution of a {@link Command}. * * @param the type of the arguments */ diff --git a/api/src/main/java/com/velocitypowered/api/command/CommandManager.java b/api/src/main/java/com/velocitypowered/api/command/CommandManager.java index 1ee80e97b..144d3e579 100644 --- a/api/src/main/java/com/velocitypowered/api/command/CommandManager.java +++ b/api/src/main/java/com/velocitypowered/api/command/CommandManager.java @@ -22,7 +22,7 @@ public interface CommandManager { * @param alias the first command alias * @return a {@link CommandMeta} builder */ - CommandMeta.Builder metaBuilder(String alias); + CommandMeta.Builder createMetaBuilder(String alias); /** * Returns a builder to create a {@link CommandMeta} for @@ -31,7 +31,7 @@ public interface CommandManager { * @param command the command * @return a {@link CommandMeta} builder */ - CommandMeta.Builder metaBuilder(BrigadierCommand command); + CommandMeta.Builder createMetaBuilder(BrigadierCommand command); /** * Registers the specified command with the specified aliases. @@ -42,7 +42,7 @@ public interface CommandManager { * @throws IllegalArgumentException if one of the given aliases is already registered */ default void register(String alias, Command command, String... otherAliases) { - register(metaBuilder(alias).aliases(otherAliases).build(), command); + register(createMetaBuilder(alias).aliases(otherAliases).build(), command); } /** diff --git a/proxy/src/main/java/com/velocitypowered/proxy/command/VelocityCommandManager.java b/proxy/src/main/java/com/velocitypowered/proxy/command/VelocityCommandManager.java index 5895acfb4..a624a2106 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/command/VelocityCommandManager.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/command/VelocityCommandManager.java @@ -56,13 +56,13 @@ public class VelocityCommandManager implements CommandManager { } @Override - public CommandMeta.Builder metaBuilder(final String alias) { + public CommandMeta.Builder createMetaBuilder(final String alias) { Preconditions.checkNotNull(alias, "alias"); return new VelocityCommandMeta.Builder(alias); } @Override - public CommandMeta.Builder metaBuilder(final BrigadierCommand command) { + public CommandMeta.Builder createMetaBuilder(final BrigadierCommand command) { Preconditions.checkNotNull(command, "command"); return new VelocityCommandMeta.Builder(command.getNode().getName()); } @@ -70,7 +70,7 @@ public class VelocityCommandManager implements CommandManager { @Override public void register(final BrigadierCommand command) { Preconditions.checkNotNull(command, "command"); - register(metaBuilder(command).build(), command); + register(createMetaBuilder(command).build(), command); } @Override diff --git a/proxy/src/test/java/com/velocitypowered/proxy/command/CommandManagerTests.java b/proxy/src/test/java/com/velocitypowered/proxy/command/CommandManagerTests.java index a1d6e4e9f..bdf300fd3 100644 --- a/proxy/src/test/java/com/velocitypowered/proxy/command/CommandManagerTests.java +++ b/proxy/src/test/java/com/velocitypowered/proxy/command/CommandManagerTests.java @@ -44,7 +44,6 @@ import java.util.List; import java.util.concurrent.ExecutionException; import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicReference; -import org.checkerframework.checker.nullness.qual.NonNull; import org.junit.jupiter.api.Test; public class CommandManagerTests { @@ -91,7 +90,7 @@ public class CommandManagerTests { .literal("bar") .build(); BrigadierCommand aliasesCommand = new BrigadierCommand(barNode); - CommandMeta meta = manager.metaBuilder(aliasesCommand) + CommandMeta meta = manager.createMetaBuilder(aliasesCommand) .aliases("baZ") .build(); @@ -412,7 +411,7 @@ public class CommandManagerTests { CommandNode bazHint = LiteralArgumentBuilder .literal("baz") .build(); - CommandMeta meta = manager.metaBuilder("foo") + CommandMeta meta = manager.createMetaBuilder("foo") .aliases("foo2") .hint(barHint) .hint(bazHint) From 47c354e6eea71789299a2829a9dd1617d2ad3ea1 Mon Sep 17 00:00:00 2001 From: Andrew Steinborn Date: Sat, 17 Apr 2021 04:58:16 -0400 Subject: [PATCH 30/99] [Breaking] Many renamings in the API The get prefix has been dropped from getters where it is unambiguous what is being referred to. Other getters have also received renames to clarify their purpose. The main exception is the ProxyConfig API, but it's one of my personal sore spots in the API, so it'll be replaced instead. --- .../api/command/CommandMeta.java | 4 +- .../api/command/RawCommand.java | 7 - .../api/command/SimpleCommand.java | 7 - .../api/event/ResultedEvent.java | 4 +- .../velocitypowered/api/event/Subscribe.java | 7 +- .../event/command/CommandExecuteEvent.java | 6 +- .../command/CommandExecuteEventImpl.java | 6 +- .../command/PlayerAvailableCommandsEvent.java | 4 +- .../PlayerAvailableCommandsEventImpl.java | 4 +- .../connection/ConnectionHandshakeEvent.java | 3 + .../ConnectionHandshakeEventImpl.java | 3 +- .../event/connection/PluginMessageEvent.java | 75 +------- .../connection/PluginMessageEventImpl.java | 101 +++++++++++ .../api/event/connection/ProxyPingEvent.java | 4 +- .../event/connection/ProxyPingEventImpl.java | 4 +- .../api/event/connection/ProxyQueryEvent.java | 6 +- .../event/connection/ProxyQueryEventImpl.java | 6 +- .../lifecycle/network/ListenerBoundEvent.java | 4 +- .../network/ListenerBoundEventImpl.java | 4 +- .../network/ListenerClosedEvent.java | 4 +- .../network/ListenerClosedEventImpl.java | 4 +- .../permission/PermissionsSetupEvent.java | 4 +- .../permission/PermissionsSetupEventImpl.java | 4 +- .../api/event/player/DisconnectEvent.java | 8 +- .../api/event/player/DisconnectEventImpl.java | 4 +- .../event/player/GameProfileRequestEvent.java | 8 +- .../player/GameProfileRequestEventImpl.java | 8 +- .../event/player/KickedFromServerEvent.java | 20 +-- .../player/KickedFromServerEventImpl.java | 8 +- .../api/event/player/LoginEvent.java | 7 +- .../api/event/player/LoginEventImpl.java | 4 +- .../player/PlayerChannelRegisterEvent.java | 4 +- .../PlayerChannelRegisterEventImpl.java | 4 +- .../api/event/player/PlayerChatEvent.java | 14 +- .../api/event/player/PlayerChatEventImpl.java | 6 +- .../PlayerChooseInitialServerEvent.java | 4 +- .../PlayerChooseInitialServerEventImpl.java | 4 +- ... => PlayerClientSettingsChangedEvent.java} | 8 +- ...PlayerClientSettingsChangedEventImpl.java} | 19 +- .../api/event/player/PlayerModInfoEvent.java | 4 +- .../event/player/PlayerModInfoEventImpl.java | 4 +- .../player/PlayerResourcePackStatusEvent.java | 4 +- .../PlayerResourcePackStatusEventImpl.java | 4 +- .../api/event/player/PostLoginEvent.java | 2 +- .../api/event/player/PostLoginEventImpl.java | 2 +- .../api/event/player/PreLoginEvent.java | 12 +- .../api/event/player/PreLoginEventImpl.java | 6 +- .../event/player/ServerConnectedEvent.java | 6 +- .../player/ServerConnectedEventImpl.java | 6 +- .../event/player/ServerPostConnectEvent.java | 6 +- .../player/ServerPostConnectEventImpl.java | 6 +- .../event/player/ServerPreConnectEvent.java | 36 ++-- .../player/ServerPreConnectEventImpl.java | 8 +- .../api/event/player/TabCompleteEvent.java | 6 +- .../event/player/TabCompleteEventImpl.java | 6 +- .../api/network/ProtocolVersion.java | 28 +-- .../api/permission/PermissionFunction.java | 4 +- .../api/permission/PermissionSubject.java | 4 +- .../api/plugin/PluginContainer.java | 4 +- .../api/plugin/PluginDescription.java | 20 +-- .../api/proxy/ProxyServer.java | 35 ++-- .../api/proxy/config/ProxyConfig.java | 2 +- .../proxy/connection/InboundConnection.java | 6 +- .../api/proxy/connection/Player.java | 20 +-- .../proxy/connection/ServerConnection.java | 6 +- .../api/proxy/messages/ChannelIdentifier.java | 2 +- .../api/proxy/messages/ChannelRegistrar.java | 4 +- .../messages/LegacyChannelIdentifier.java | 2 +- .../messages/MinecraftChannelIdentifier.java | 2 +- ...layerSettings.java => ClientSettings.java} | 2 +- .../player/ConnectionRequestBuilder.java | 10 +- .../api/proxy/player/TabList.java | 2 +- .../api/proxy/player/TabListEntry.java | 24 +-- .../api/proxy/server/QueryResponse.java | 72 ++++---- .../api/proxy/server/RegisteredServer.java | 4 +- .../api/proxy/server/ServerInfo.java | 7 +- .../api/proxy/server/ServerPing.java | 26 +-- .../com/velocitypowered/proxy/Metrics.java | 8 +- .../com/velocitypowered/proxy/Velocity.java | 2 +- .../velocitypowered/proxy/VelocityServer.java | 71 ++++---- .../proxy/command/VelocityCommandManager.java | 8 +- .../proxy/command/VelocityCommandMeta.java | 4 +- .../command/builtin/BuiltinCommandUtil.java | 4 +- .../proxy/command/builtin/GlistCommand.java | 18 +- .../proxy/command/builtin/ServerCommand.java | 22 +-- .../command/builtin/ShutdownCommand.java | 2 +- .../command/builtin/VelocityCommand.java | 48 ++--- .../proxy/connection/MinecraftConnection.java | 2 +- .../backend/BackendPlaySessionHandler.java | 51 +++--- .../backend/BungeeCordMessageResponder.java | 60 +++---- .../backend/LoginSessionHandler.java | 14 +- .../backend/TransitionSessionHandler.java | 40 ++--- .../backend/VelocityServerConnection.java | 34 ++-- .../client/ClientPlaySessionHandler.java | 67 +++---- .../client/ClientSettingsWrapper.java | 6 +- .../connection/client/ConnectedPlayer.java | 166 +++++++++--------- .../client/HandshakeSessionHandler.java | 10 +- .../client/InitialInboundConnection.java | 10 +- .../client/LoginSessionHandler.java | 56 +++--- .../client/StatusSessionHandler.java | 40 ++--- .../LegacyForgeHandshakeBackendPhase.java | 2 +- .../LegacyForgeHandshakeClientPhase.java | 2 +- .../util/ConnectionRequestResults.java | 6 +- .../proxy/console/VelocityConsole.java | 12 +- .../proxy/event/VelocityEventManager.java | 2 +- .../network/BackendChannelInitializer.java | 2 +- .../proxy/network/ConnectionManager.java | 16 +- .../network/ServerChannelInitializer.java | 4 +- .../ClientboundPlayerListItemPacket.java | 12 +- .../packet/legacy/LegacyDisconnectPacket.java | 18 +- .../ServerboundHandshakePacket.java | 4 +- .../network/pipeline/GS4QueryHandler.java | 46 ++--- .../proxy/plugin/VelocityPluginManager.java | 31 ++-- .../loader/VelocityPluginContainer.java | 4 +- .../loader/VelocityPluginDescription.java | 16 +- .../plugin/loader/java/JavaPluginLoader.java | 26 +-- .../loader/java/VelocityPluginModule.java | 4 +- .../plugin/util/PluginDependencyUtils.java | 8 +- .../proxy/scheduler/VelocityScheduler.java | 5 +- .../proxy/server/PingSessionHandler.java | 2 +- .../proxy/server/ServerMap.java | 16 +- .../server/VelocityRegisteredServer.java | 18 +- .../proxy/tablist/VelocityTabList.java | 10 +- .../proxy/tablist/VelocityTabListEntry.java | 12 +- .../tablist/VelocityTabListEntryLegacy.java | 2 +- .../proxy/tablist/VelocityTabListLegacy.java | 6 +- .../proxy/util/InformationUtils.java | 34 ++-- .../proxy/util/VelocityChannelRegistrar.java | 18 +- .../util/bossbar/AdventureBossBarManager.java | 4 +- .../proxy/command/CommandManagerTests.java | 4 +- .../proxy/command/MockCommandSource.java | 2 +- .../proxy/testutil/FakePluginManager.java | 4 +- .../util/VelocityChannelRegistrarTest.java | 12 +- 133 files changed, 951 insertions(+), 965 deletions(-) create mode 100644 api/src/main/java/com/velocitypowered/api/event/connection/PluginMessageEventImpl.java rename api/src/main/java/com/velocitypowered/api/event/player/{PlayerSettingsChangedEvent.java => PlayerClientSettingsChangedEvent.java} (65%) rename api/src/main/java/com/velocitypowered/api/event/player/{PlayerSettingsChangedEventImpl.java => PlayerClientSettingsChangedEventImpl.java} (58%) rename api/src/main/java/com/velocitypowered/api/proxy/player/{PlayerSettings.java => ClientSettings.java} (97%) diff --git a/api/src/main/java/com/velocitypowered/api/command/CommandMeta.java b/api/src/main/java/com/velocitypowered/api/command/CommandMeta.java index d731e6ec4..60f933c0b 100644 --- a/api/src/main/java/com/velocitypowered/api/command/CommandMeta.java +++ b/api/src/main/java/com/velocitypowered/api/command/CommandMeta.java @@ -21,7 +21,7 @@ public interface CommandMeta { * * @return the command aliases */ - Collection getAliases(); + Collection aliases(); /** * Returns a collection containing command nodes that provide additional @@ -30,7 +30,7 @@ public interface CommandMeta { * * @return the hinting command nodes */ - Collection> getHints(); + Collection> hints(); /** * Provides a fluent interface to create {@link CommandMeta}s. diff --git a/api/src/main/java/com/velocitypowered/api/command/RawCommand.java b/api/src/main/java/com/velocitypowered/api/command/RawCommand.java index 9cd78d220..62e3f5f70 100644 --- a/api/src/main/java/com/velocitypowered/api/command/RawCommand.java +++ b/api/src/main/java/com/velocitypowered/api/command/RawCommand.java @@ -18,12 +18,5 @@ public interface RawCommand extends InvocableCommand { * Contains the invocation data for a raw command. */ interface Invocation extends CommandInvocation { - - /** - * Returns the used alias to execute the command. - * - * @return the used command alias - */ - String alias(); } } diff --git a/api/src/main/java/com/velocitypowered/api/command/SimpleCommand.java b/api/src/main/java/com/velocitypowered/api/command/SimpleCommand.java index c51e33963..1286d80ee 100644 --- a/api/src/main/java/com/velocitypowered/api/command/SimpleCommand.java +++ b/api/src/main/java/com/velocitypowered/api/command/SimpleCommand.java @@ -22,12 +22,5 @@ public interface SimpleCommand extends InvocableCommand { - - /** - * Returns the used alias to execute the command. - * - * @return the used command alias - */ - String alias(); } } diff --git a/api/src/main/java/com/velocitypowered/api/event/ResultedEvent.java b/api/src/main/java/com/velocitypowered/api/event/ResultedEvent.java index 7e10b2e1a..fd889a19b 100644 --- a/api/src/main/java/com/velocitypowered/api/event/ResultedEvent.java +++ b/api/src/main/java/com/velocitypowered/api/event/ResultedEvent.java @@ -23,7 +23,7 @@ public interface ResultedEvent { * * @return the result of this event */ - R getResult(); + R result(); /** * Sets the result of this event. The result must be non-null. @@ -99,7 +99,7 @@ public interface ResultedEvent { return status; } - public Optional getReason() { + public Optional reason() { return Optional.ofNullable(reason); } diff --git a/api/src/main/java/com/velocitypowered/api/event/Subscribe.java b/api/src/main/java/com/velocitypowered/api/event/Subscribe.java index f762ee7c1..6d6acea77 100644 --- a/api/src/main/java/com/velocitypowered/api/event/Subscribe.java +++ b/api/src/main/java/com/velocitypowered/api/event/Subscribe.java @@ -27,11 +27,12 @@ public @interface Subscribe { short order() default PostOrder.NORMAL; /** - * Whether the handler is required to be called asynchronously. + * Whether the handler must be called asynchronously. * *

If this method returns {@code true}, the method is guaranteed to be executed - * asynchronously from the current thread. Otherwise, the handler may be executed on the - * current thread or asynchronously.

+ * asynchronously. Otherwise, the handler may be executed on the current thread or + * asynchronously. This still means you must consider thread-safety in your + * event listeners as the "current thread" can and will be different each time.

* *

If any method handler targeting an event type is marked with {@code true}, then every * handler targeting that event type will be executed asynchronously.

diff --git a/api/src/main/java/com/velocitypowered/api/event/command/CommandExecuteEvent.java b/api/src/main/java/com/velocitypowered/api/event/command/CommandExecuteEvent.java index 94dc9c1d3..a799986fe 100644 --- a/api/src/main/java/com/velocitypowered/api/event/command/CommandExecuteEvent.java +++ b/api/src/main/java/com/velocitypowered/api/event/command/CommandExecuteEvent.java @@ -20,13 +20,13 @@ import org.checkerframework.checker.nullness.qual.Nullable; */ public interface CommandExecuteEvent extends ResultedEvent { - CommandSource getCommandSource(); + CommandSource source(); /** * Gets the original command being executed without the first slash. * @return the original command being executed */ - String getCommand(); + String rawCommand(); final class CommandResult implements ResultedEvent.Result { @@ -44,7 +44,7 @@ public interface CommandExecuteEvent extends ResultedEvent { this.command = command; } - public Optional getCommand() { + public Optional modifiedCommand() { return Optional.ofNullable(command); } diff --git a/api/src/main/java/com/velocitypowered/api/event/command/CommandExecuteEventImpl.java b/api/src/main/java/com/velocitypowered/api/event/command/CommandExecuteEventImpl.java index 672b93522..c4cae21df 100644 --- a/api/src/main/java/com/velocitypowered/api/event/command/CommandExecuteEventImpl.java +++ b/api/src/main/java/com/velocitypowered/api/event/command/CommandExecuteEventImpl.java @@ -31,7 +31,7 @@ public final class CommandExecuteEventImpl implements CommandExecuteEvent { } @Override - public CommandSource getCommandSource() { + public CommandSource source() { return commandSource; } @@ -40,12 +40,12 @@ public final class CommandExecuteEventImpl implements CommandExecuteEvent { * @return the original command being executed */ @Override - public String getCommand() { + public String rawCommand() { return command; } @Override - public CommandResult getResult() { + public CommandResult result() { return result; } diff --git a/api/src/main/java/com/velocitypowered/api/event/command/PlayerAvailableCommandsEvent.java b/api/src/main/java/com/velocitypowered/api/event/command/PlayerAvailableCommandsEvent.java index 1948beec2..9cc5b560d 100644 --- a/api/src/main/java/com/velocitypowered/api/event/command/PlayerAvailableCommandsEvent.java +++ b/api/src/main/java/com/velocitypowered/api/event/command/PlayerAvailableCommandsEvent.java @@ -16,7 +16,7 @@ import com.velocitypowered.api.proxy.connection.Player; */ public interface PlayerAvailableCommandsEvent { - Player getPlayer(); + Player player(); - RootCommandNode getRootNode(); + RootCommandNode rootNode(); } diff --git a/api/src/main/java/com/velocitypowered/api/event/command/PlayerAvailableCommandsEventImpl.java b/api/src/main/java/com/velocitypowered/api/event/command/PlayerAvailableCommandsEventImpl.java index 926d94c17..313ea751d 100644 --- a/api/src/main/java/com/velocitypowered/api/event/command/PlayerAvailableCommandsEventImpl.java +++ b/api/src/main/java/com/velocitypowered/api/event/command/PlayerAvailableCommandsEventImpl.java @@ -35,12 +35,12 @@ public class PlayerAvailableCommandsEventImpl implements PlayerAvailableCommands } @Override - public Player getPlayer() { + public Player player() { return player; } @Override - public RootCommandNode getRootNode() { + public RootCommandNode rootNode() { return rootNode; } } diff --git a/api/src/main/java/com/velocitypowered/api/event/connection/ConnectionHandshakeEvent.java b/api/src/main/java/com/velocitypowered/api/event/connection/ConnectionHandshakeEvent.java index 166981316..a744dbe8a 100644 --- a/api/src/main/java/com/velocitypowered/api/event/connection/ConnectionHandshakeEvent.java +++ b/api/src/main/java/com/velocitypowered/api/event/connection/ConnectionHandshakeEvent.java @@ -7,9 +7,12 @@ package com.velocitypowered.api.event.connection; +import com.velocitypowered.api.proxy.connection.InboundConnection; + /** * This event is fired when a handshake is established between a client and the proxy. */ public interface ConnectionHandshakeEvent { + InboundConnection connection(); } diff --git a/api/src/main/java/com/velocitypowered/api/event/connection/ConnectionHandshakeEventImpl.java b/api/src/main/java/com/velocitypowered/api/event/connection/ConnectionHandshakeEventImpl.java index a87dbb926..4df985717 100644 --- a/api/src/main/java/com/velocitypowered/api/event/connection/ConnectionHandshakeEventImpl.java +++ b/api/src/main/java/com/velocitypowered/api/event/connection/ConnectionHandshakeEventImpl.java @@ -21,7 +21,8 @@ public final class ConnectionHandshakeEventImpl implements ConnectionHandshakeEv this.connection = Preconditions.checkNotNull(connection, "connection"); } - public InboundConnection getConnection() { + @Override + public InboundConnection connection() { return connection; } diff --git a/api/src/main/java/com/velocitypowered/api/event/connection/PluginMessageEvent.java b/api/src/main/java/com/velocitypowered/api/event/connection/PluginMessageEvent.java index 50c988764..51ee66fb0 100644 --- a/api/src/main/java/com/velocitypowered/api/event/connection/PluginMessageEvent.java +++ b/api/src/main/java/com/velocitypowered/api/event/connection/PluginMessageEvent.java @@ -7,9 +7,7 @@ package com.velocitypowered.api.event.connection; -import com.google.common.base.Preconditions; import com.google.common.io.ByteArrayDataInput; -import com.google.common.io.ByteStreams; import com.velocitypowered.api.event.ResultedEvent; import com.velocitypowered.api.proxy.connection.Player; import com.velocitypowered.api.proxy.connection.ServerConnection; @@ -17,86 +15,29 @@ import com.velocitypowered.api.proxy.messages.ChannelIdentifier; import com.velocitypowered.api.proxy.messages.ChannelMessageSink; import com.velocitypowered.api.proxy.messages.ChannelMessageSource; import java.io.ByteArrayInputStream; -import java.util.Arrays; /** * This event is fired when a plugin message is sent to the proxy, either from a client ({@link * Player}) or a server ({@link ServerConnection}). */ -public final class PluginMessageEvent implements ResultedEvent { +public interface PluginMessageEvent extends ResultedEvent { - private final ChannelMessageSource source; - private final ChannelMessageSink target; - private final ChannelIdentifier identifier; - private final byte[] data; - private ForwardResult result; + ChannelMessageSource getSource(); - /** - * Creates a new instance. - * - * @param source the source of the plugin message - * @param target the destination of the plugin message - * @param identifier the channel for this plugin message - * @param data the payload of the plugin message - */ - public PluginMessageEvent(ChannelMessageSource source, ChannelMessageSink target, - ChannelIdentifier identifier, byte[] data) { - this.source = Preconditions.checkNotNull(source, "source"); - this.target = Preconditions.checkNotNull(target, "target"); - this.identifier = Preconditions.checkNotNull(identifier, "identifier"); - this.data = Preconditions.checkNotNull(data, "data"); - this.result = ForwardResult.forward(); - } + ChannelMessageSink getTarget(); - @Override - public ForwardResult getResult() { - return result; - } + ChannelIdentifier getIdentifier(); - @Override - public void setResult(ForwardResult result) { - this.result = Preconditions.checkNotNull(result, "result"); - } + byte[] getData(); - public ChannelMessageSource getSource() { - return source; - } + ByteArrayInputStream dataAsInputStream(); - public ChannelMessageSink getTarget() { - return target; - } - - public ChannelIdentifier getIdentifier() { - return identifier; - } - - public byte[] getData() { - return Arrays.copyOf(data, data.length); - } - - public ByteArrayInputStream dataAsInputStream() { - return new ByteArrayInputStream(data); - } - - public ByteArrayDataInput dataAsDataStream() { - return ByteStreams.newDataInput(data); - } - - @Override - public String toString() { - return "PluginMessageEvent{" - + "source=" + source - + ", target=" + target - + ", identifier=" + identifier - + ", data=" + Arrays.toString(data) - + ", result=" + result - + '}'; - } + ByteArrayDataInput dataAsDataStream(); /** * A result determining whether or not to forward this message on. */ - public static final class ForwardResult implements ResultedEvent.Result { + public static final class ForwardResult implements Result { private static final ForwardResult ALLOWED = new ForwardResult(true); private static final ForwardResult DENIED = new ForwardResult(false); diff --git a/api/src/main/java/com/velocitypowered/api/event/connection/PluginMessageEventImpl.java b/api/src/main/java/com/velocitypowered/api/event/connection/PluginMessageEventImpl.java new file mode 100644 index 000000000..d8f8e7460 --- /dev/null +++ b/api/src/main/java/com/velocitypowered/api/event/connection/PluginMessageEventImpl.java @@ -0,0 +1,101 @@ +/* + * Copyright (C) 2018 Velocity Contributors + * + * The Velocity API is licensed under the terms of the MIT License. For more details, + * reference the LICENSE file in the api top-level directory. + */ + +package com.velocitypowered.api.event.connection; + +import com.google.common.base.Preconditions; +import com.google.common.io.ByteArrayDataInput; +import com.google.common.io.ByteStreams; +import com.velocitypowered.api.proxy.connection.Player; +import com.velocitypowered.api.proxy.connection.ServerConnection; +import com.velocitypowered.api.proxy.messages.ChannelIdentifier; +import com.velocitypowered.api.proxy.messages.ChannelMessageSink; +import com.velocitypowered.api.proxy.messages.ChannelMessageSource; +import java.io.ByteArrayInputStream; +import java.util.Arrays; + +/** + * This event is fired when a plugin message is sent to the proxy, either from a client ({@link + * Player}) or a server ({@link ServerConnection}). + */ +public final class PluginMessageEventImpl implements PluginMessageEvent { + + private final ChannelMessageSource source; + private final ChannelMessageSink target; + private final ChannelIdentifier identifier; + private final byte[] data; + private ForwardResult result; + + /** + * Creates a new instance. + * + * @param source the source of the plugin message + * @param target the destination of the plugin message + * @param identifier the channel for this plugin message + * @param data the payload of the plugin message + */ + public PluginMessageEventImpl(ChannelMessageSource source, ChannelMessageSink target, + ChannelIdentifier identifier, byte[] data) { + this.source = Preconditions.checkNotNull(source, "source"); + this.target = Preconditions.checkNotNull(target, "target"); + this.identifier = Preconditions.checkNotNull(identifier, "identifier"); + this.data = Preconditions.checkNotNull(data, "data"); + this.result = ForwardResult.forward(); + } + + @Override + public ForwardResult result() { + return result; + } + + @Override + public void setResult(ForwardResult result) { + this.result = Preconditions.checkNotNull(result, "result"); + } + + @Override + public ChannelMessageSource getSource() { + return source; + } + + @Override + public ChannelMessageSink getTarget() { + return target; + } + + @Override + public ChannelIdentifier getIdentifier() { + return identifier; + } + + @Override + public byte[] getData() { + return Arrays.copyOf(data, data.length); + } + + @Override + public ByteArrayInputStream dataAsInputStream() { + return new ByteArrayInputStream(data); + } + + @Override + public ByteArrayDataInput dataAsDataStream() { + return ByteStreams.newDataInput(data); + } + + @Override + public String toString() { + return "PluginMessageEvent{" + + "source=" + source + + ", target=" + target + + ", identifier=" + identifier + + ", data=" + Arrays.toString(data) + + ", result=" + result + + '}'; + } + +} diff --git a/api/src/main/java/com/velocitypowered/api/event/connection/ProxyPingEvent.java b/api/src/main/java/com/velocitypowered/api/event/connection/ProxyPingEvent.java index be31a0098..fb16908bb 100644 --- a/api/src/main/java/com/velocitypowered/api/event/connection/ProxyPingEvent.java +++ b/api/src/main/java/com/velocitypowered/api/event/connection/ProxyPingEvent.java @@ -15,9 +15,9 @@ import com.velocitypowered.api.proxy.server.ServerPing; */ public interface ProxyPingEvent { - InboundConnection getConnection(); + InboundConnection connection(); - ServerPing getPing(); + ServerPing ping(); void setPing(ServerPing ping); } diff --git a/api/src/main/java/com/velocitypowered/api/event/connection/ProxyPingEventImpl.java b/api/src/main/java/com/velocitypowered/api/event/connection/ProxyPingEventImpl.java index 49284e165..3a308a4ad 100644 --- a/api/src/main/java/com/velocitypowered/api/event/connection/ProxyPingEventImpl.java +++ b/api/src/main/java/com/velocitypowered/api/event/connection/ProxyPingEventImpl.java @@ -25,12 +25,12 @@ public final class ProxyPingEventImpl implements ProxyPingEvent { } @Override - public InboundConnection getConnection() { + public InboundConnection connection() { return connection; } @Override - public ServerPing getPing() { + public ServerPing ping() { return ping; } diff --git a/api/src/main/java/com/velocitypowered/api/event/connection/ProxyQueryEvent.java b/api/src/main/java/com/velocitypowered/api/event/connection/ProxyQueryEvent.java index 4f2b1b2c2..058d357f7 100644 --- a/api/src/main/java/com/velocitypowered/api/event/connection/ProxyQueryEvent.java +++ b/api/src/main/java/com/velocitypowered/api/event/connection/ProxyQueryEvent.java @@ -20,21 +20,21 @@ public interface ProxyQueryEvent { * * @return query type */ - QueryType getQueryType(); + QueryType type(); /** * Get the address of the client that sent this query. * * @return querier address */ - InetAddress getQuerierAddress(); + InetAddress queryingAddress(); /** * Returns the current query response. * * @return the current query response */ - QueryResponse getResponse(); + QueryResponse response(); /** * Sets a new query response. diff --git a/api/src/main/java/com/velocitypowered/api/event/connection/ProxyQueryEventImpl.java b/api/src/main/java/com/velocitypowered/api/event/connection/ProxyQueryEventImpl.java index 7d7b23ea2..e45bd26eb 100644 --- a/api/src/main/java/com/velocitypowered/api/event/connection/ProxyQueryEventImpl.java +++ b/api/src/main/java/com/velocitypowered/api/event/connection/ProxyQueryEventImpl.java @@ -39,7 +39,7 @@ public final class ProxyQueryEventImpl implements ProxyQueryEvent { * @return query type */ @Override - public QueryType getQueryType() { + public QueryType type() { return queryType; } @@ -49,7 +49,7 @@ public final class ProxyQueryEventImpl implements ProxyQueryEvent { * @return querier address */ @Override - public InetAddress getQuerierAddress() { + public InetAddress queryingAddress() { return querierAddress; } @@ -59,7 +59,7 @@ public final class ProxyQueryEventImpl implements ProxyQueryEvent { * @return the current query response */ @Override - public QueryResponse getResponse() { + public QueryResponse response() { return response; } diff --git a/api/src/main/java/com/velocitypowered/api/event/lifecycle/network/ListenerBoundEvent.java b/api/src/main/java/com/velocitypowered/api/event/lifecycle/network/ListenerBoundEvent.java index e43fd51ed..e53ed6277 100644 --- a/api/src/main/java/com/velocitypowered/api/event/lifecycle/network/ListenerBoundEvent.java +++ b/api/src/main/java/com/velocitypowered/api/event/lifecycle/network/ListenerBoundEvent.java @@ -15,7 +15,7 @@ import java.net.SocketAddress; */ public interface ListenerBoundEvent { - SocketAddress getAddress(); + SocketAddress address(); - ListenerType getListenerType(); + ListenerType type(); } diff --git a/api/src/main/java/com/velocitypowered/api/event/lifecycle/network/ListenerBoundEventImpl.java b/api/src/main/java/com/velocitypowered/api/event/lifecycle/network/ListenerBoundEventImpl.java index c4a498a67..a004e4956 100644 --- a/api/src/main/java/com/velocitypowered/api/event/lifecycle/network/ListenerBoundEventImpl.java +++ b/api/src/main/java/com/velocitypowered/api/event/lifecycle/network/ListenerBoundEventImpl.java @@ -25,12 +25,12 @@ public final class ListenerBoundEventImpl implements ListenerBoundEvent { } @Override - public SocketAddress getAddress() { + public SocketAddress address() { return address; } @Override - public ListenerType getListenerType() { + public ListenerType type() { return listenerType; } diff --git a/api/src/main/java/com/velocitypowered/api/event/lifecycle/network/ListenerClosedEvent.java b/api/src/main/java/com/velocitypowered/api/event/lifecycle/network/ListenerClosedEvent.java index 3a607a0af..78595935c 100644 --- a/api/src/main/java/com/velocitypowered/api/event/lifecycle/network/ListenerClosedEvent.java +++ b/api/src/main/java/com/velocitypowered/api/event/lifecycle/network/ListenerClosedEvent.java @@ -15,7 +15,7 @@ import java.net.SocketAddress; */ public interface ListenerClosedEvent { - SocketAddress getAddress(); + SocketAddress address(); - ListenerType getListenerType(); + ListenerType type(); } diff --git a/api/src/main/java/com/velocitypowered/api/event/lifecycle/network/ListenerClosedEventImpl.java b/api/src/main/java/com/velocitypowered/api/event/lifecycle/network/ListenerClosedEventImpl.java index eec5f56e7..fbfa9abf0 100644 --- a/api/src/main/java/com/velocitypowered/api/event/lifecycle/network/ListenerClosedEventImpl.java +++ b/api/src/main/java/com/velocitypowered/api/event/lifecycle/network/ListenerClosedEventImpl.java @@ -25,12 +25,12 @@ public final class ListenerClosedEventImpl implements ListenerClosedEvent { } @Override - public SocketAddress getAddress() { + public SocketAddress address() { return address; } @Override - public ListenerType getListenerType() { + public ListenerType type() { return listenerType; } diff --git a/api/src/main/java/com/velocitypowered/api/event/permission/PermissionsSetupEvent.java b/api/src/main/java/com/velocitypowered/api/event/permission/PermissionsSetupEvent.java index 915e65944..99241271a 100644 --- a/api/src/main/java/com/velocitypowered/api/event/permission/PermissionsSetupEvent.java +++ b/api/src/main/java/com/velocitypowered/api/event/permission/PermissionsSetupEvent.java @@ -19,7 +19,7 @@ import org.checkerframework.checker.nullness.qual.Nullable; */ public interface PermissionsSetupEvent { - PermissionSubject getSubject(); + PermissionSubject subject(); /** * Uses the provider function to obtain a {@link PermissionFunction} for the subject. @@ -29,7 +29,7 @@ public interface PermissionsSetupEvent { */ PermissionFunction createFunction(PermissionSubject subject); - PermissionProvider getProvider(); + PermissionProvider provider(); /** * Sets the {@link PermissionFunction} that should be used for the subject. diff --git a/api/src/main/java/com/velocitypowered/api/event/permission/PermissionsSetupEventImpl.java b/api/src/main/java/com/velocitypowered/api/event/permission/PermissionsSetupEventImpl.java index 4921470db..36f9488e4 100644 --- a/api/src/main/java/com/velocitypowered/api/event/permission/PermissionsSetupEventImpl.java +++ b/api/src/main/java/com/velocitypowered/api/event/permission/PermissionsSetupEventImpl.java @@ -30,7 +30,7 @@ public final class PermissionsSetupEventImpl implements PermissionsSetupEvent { } @Override - public PermissionSubject getSubject() { + public PermissionSubject subject() { return this.subject; } @@ -46,7 +46,7 @@ public final class PermissionsSetupEventImpl implements PermissionsSetupEvent { } @Override - public PermissionProvider getProvider() { + public PermissionProvider provider() { return this.provider; } diff --git a/api/src/main/java/com/velocitypowered/api/event/player/DisconnectEvent.java b/api/src/main/java/com/velocitypowered/api/event/player/DisconnectEvent.java index ffb49ee02..85f0744e8 100644 --- a/api/src/main/java/com/velocitypowered/api/event/player/DisconnectEvent.java +++ b/api/src/main/java/com/velocitypowered/api/event/player/DisconnectEvent.java @@ -9,11 +9,15 @@ package com.velocitypowered.api.event.player; import com.velocitypowered.api.proxy.connection.Player; +/** + * This event is fired when a player disconnects from the proxy. Operations on the provided player, + * aside from basic data retrieval operations, may behave in undefined ways. + */ public interface DisconnectEvent { - Player getPlayer(); + Player player(); - LoginStatus getLoginStatus(); + LoginStatus loginStatus(); public enum LoginStatus { diff --git a/api/src/main/java/com/velocitypowered/api/event/player/DisconnectEventImpl.java b/api/src/main/java/com/velocitypowered/api/event/player/DisconnectEventImpl.java index abfaa4d53..a6a55b81c 100644 --- a/api/src/main/java/com/velocitypowered/api/event/player/DisconnectEventImpl.java +++ b/api/src/main/java/com/velocitypowered/api/event/player/DisconnectEventImpl.java @@ -25,12 +25,12 @@ public final class DisconnectEventImpl implements DisconnectEvent { } @Override - public Player getPlayer() { + public Player player() { return player; } @Override - public LoginStatus getLoginStatus() { + public LoginStatus loginStatus() { return loginStatus; } diff --git a/api/src/main/java/com/velocitypowered/api/event/player/GameProfileRequestEvent.java b/api/src/main/java/com/velocitypowered/api/event/player/GameProfileRequestEvent.java index 3a5b38d9e..cb6efa4c4 100644 --- a/api/src/main/java/com/velocitypowered/api/event/player/GameProfileRequestEvent.java +++ b/api/src/main/java/com/velocitypowered/api/event/player/GameProfileRequestEvent.java @@ -17,11 +17,11 @@ import org.checkerframework.checker.nullness.qual.Nullable; */ public interface GameProfileRequestEvent { - InboundConnection getConnection(); + InboundConnection connection(); - String getUsername(); + String username(); - GameProfile getOriginalProfile(); + GameProfile initialProfile(); boolean isOnlineMode(); @@ -32,7 +32,7 @@ public interface GameProfileRequestEvent { * * @return the user's {@link GameProfile} */ - GameProfile getGameProfile(); + GameProfile gameProfile(); /** * Sets the game profile to use for this connection. diff --git a/api/src/main/java/com/velocitypowered/api/event/player/GameProfileRequestEventImpl.java b/api/src/main/java/com/velocitypowered/api/event/player/GameProfileRequestEventImpl.java index b57066874..aa3a25535 100644 --- a/api/src/main/java/com/velocitypowered/api/event/player/GameProfileRequestEventImpl.java +++ b/api/src/main/java/com/velocitypowered/api/event/player/GameProfileRequestEventImpl.java @@ -39,17 +39,17 @@ public final class GameProfileRequestEventImpl implements GameProfileRequestEven } @Override - public InboundConnection getConnection() { + public InboundConnection connection() { return connection; } @Override - public String getUsername() { + public String username() { return username; } @Override - public GameProfile getOriginalProfile() { + public GameProfile initialProfile() { return originalProfile; } @@ -66,7 +66,7 @@ public final class GameProfileRequestEventImpl implements GameProfileRequestEven * @return the user's {@link GameProfile} */ @Override - public GameProfile getGameProfile() { + public GameProfile gameProfile() { return gameProfile == null ? originalProfile : gameProfile; } diff --git a/api/src/main/java/com/velocitypowered/api/event/player/KickedFromServerEvent.java b/api/src/main/java/com/velocitypowered/api/event/player/KickedFromServerEvent.java index 2990dea11..07044d907 100644 --- a/api/src/main/java/com/velocitypowered/api/event/player/KickedFromServerEvent.java +++ b/api/src/main/java/com/velocitypowered/api/event/player/KickedFromServerEvent.java @@ -24,16 +24,16 @@ import org.checkerframework.checker.nullness.qual.Nullable; public interface KickedFromServerEvent extends ResultedEvent { - Player getPlayer(); + Player player(); - RegisteredServer getServer(); + RegisteredServer server(); /** * Gets the reason the server kicked the player from the server. * * @return the server kicked the player from the server */ - Optional getServerKickReason(); + Optional serverKickReason(); /** * Returns whether or not the player got kicked while connecting to another server. @@ -54,10 +54,10 @@ public interface KickedFromServerEvent extends */ final class DisconnectPlayer implements ServerKickResult { - private final Component component; + private final Component message; - private DisconnectPlayer(Component component) { - this.component = Preconditions.checkNotNull(component, "component"); + private DisconnectPlayer(Component message) { + this.message = Preconditions.checkNotNull(message, "message"); } @Override @@ -65,8 +65,8 @@ public interface KickedFromServerEvent extends return true; } - public Component getReason() { - return component; + public Component message() { + return message; } /** @@ -104,7 +104,7 @@ public interface KickedFromServerEvent extends return server; } - public Component getMessage() { + public Component message() { return message; } @@ -142,7 +142,7 @@ public interface KickedFromServerEvent extends return false; } - public Component getMessage() { + public Component message() { return message; } diff --git a/api/src/main/java/com/velocitypowered/api/event/player/KickedFromServerEventImpl.java b/api/src/main/java/com/velocitypowered/api/event/player/KickedFromServerEventImpl.java index 49271db4b..8591bd7f8 100644 --- a/api/src/main/java/com/velocitypowered/api/event/player/KickedFromServerEventImpl.java +++ b/api/src/main/java/com/velocitypowered/api/event/player/KickedFromServerEventImpl.java @@ -48,7 +48,7 @@ public final class KickedFromServerEventImpl implements KickedFromServerEvent { } @Override - public ServerKickResult getResult() { + public ServerKickResult result() { return result; } @@ -58,12 +58,12 @@ public final class KickedFromServerEventImpl implements KickedFromServerEvent { } @Override - public Player getPlayer() { + public Player player() { return player; } @Override - public RegisteredServer getServer() { + public RegisteredServer server() { return server; } @@ -72,7 +72,7 @@ public final class KickedFromServerEventImpl implements KickedFromServerEvent { * @return the server kicked the player from the server */ @Override - public Optional getServerKickReason() { + public Optional serverKickReason() { return Optional.ofNullable(originalReason); } diff --git a/api/src/main/java/com/velocitypowered/api/event/player/LoginEvent.java b/api/src/main/java/com/velocitypowered/api/event/player/LoginEvent.java index 6eea91911..fd909dfff 100644 --- a/api/src/main/java/com/velocitypowered/api/event/player/LoginEvent.java +++ b/api/src/main/java/com/velocitypowered/api/event/player/LoginEvent.java @@ -16,11 +16,6 @@ import com.velocitypowered.api.proxy.connection.Player; */ public interface LoginEvent extends ResultedEvent { - Player getPlayer(); + Player player(); - @Override - ComponentResult getResult(); - - @Override - void setResult(ComponentResult result); } diff --git a/api/src/main/java/com/velocitypowered/api/event/player/LoginEventImpl.java b/api/src/main/java/com/velocitypowered/api/event/player/LoginEventImpl.java index 9daf5cef2..4735361e2 100644 --- a/api/src/main/java/com/velocitypowered/api/event/player/LoginEventImpl.java +++ b/api/src/main/java/com/velocitypowered/api/event/player/LoginEventImpl.java @@ -25,12 +25,12 @@ public final class LoginEventImpl implements LoginEvent { } @Override - public Player getPlayer() { + public Player player() { return player; } @Override - public ComponentResult getResult() { + public ComponentResult result() { return result; } diff --git a/api/src/main/java/com/velocitypowered/api/event/player/PlayerChannelRegisterEvent.java b/api/src/main/java/com/velocitypowered/api/event/player/PlayerChannelRegisterEvent.java index 401bba506..72c33c806 100644 --- a/api/src/main/java/com/velocitypowered/api/event/player/PlayerChannelRegisterEvent.java +++ b/api/src/main/java/com/velocitypowered/api/event/player/PlayerChannelRegisterEvent.java @@ -17,7 +17,7 @@ import java.util.List; */ public interface PlayerChannelRegisterEvent { - Player getPlayer(); + Player player(); - List getChannels(); + List channels(); } diff --git a/api/src/main/java/com/velocitypowered/api/event/player/PlayerChannelRegisterEventImpl.java b/api/src/main/java/com/velocitypowered/api/event/player/PlayerChannelRegisterEventImpl.java index 3782d13e3..6a7bae4fe 100644 --- a/api/src/main/java/com/velocitypowered/api/event/player/PlayerChannelRegisterEventImpl.java +++ b/api/src/main/java/com/velocitypowered/api/event/player/PlayerChannelRegisterEventImpl.java @@ -27,12 +27,12 @@ public final class PlayerChannelRegisterEventImpl implements PlayerChannelRegist } @Override - public Player getPlayer() { + public Player player() { return player; } @Override - public List getChannels() { + public List channels() { return channels; } diff --git a/api/src/main/java/com/velocitypowered/api/event/player/PlayerChatEvent.java b/api/src/main/java/com/velocitypowered/api/event/player/PlayerChatEvent.java index 7fec00e40..a8b390bd9 100644 --- a/api/src/main/java/com/velocitypowered/api/event/player/PlayerChatEvent.java +++ b/api/src/main/java/com/velocitypowered/api/event/player/PlayerChatEvent.java @@ -16,15 +16,9 @@ import org.checkerframework.checker.nullness.qual.Nullable; public interface PlayerChatEvent extends ResultedEvent { - Player getPlayer(); + Player player(); - String getMessage(); - - @Override - ChatResult getResult(); - - @Override - void setResult(ChatResult result); + String sentMessage(); /** * Represents the result of the {@link PlayerChatEvent}. @@ -42,7 +36,7 @@ public interface PlayerChatEvent extends ResultedEvent getMessage() { + public Optional modifiedMessage() { return Optional.ofNullable(message); } @@ -80,7 +74,7 @@ public interface PlayerChatEvent extends ResultedEvent getInitialServer(); + Optional initialServer(); /** * Sets the new initial server. diff --git a/api/src/main/java/com/velocitypowered/api/event/player/PlayerChooseInitialServerEventImpl.java b/api/src/main/java/com/velocitypowered/api/event/player/PlayerChooseInitialServerEventImpl.java index c89e9be75..19bbb95c5 100644 --- a/api/src/main/java/com/velocitypowered/api/event/player/PlayerChooseInitialServerEventImpl.java +++ b/api/src/main/java/com/velocitypowered/api/event/player/PlayerChooseInitialServerEventImpl.java @@ -33,12 +33,12 @@ public class PlayerChooseInitialServerEventImpl implements PlayerChooseInitialSe } @Override - public Player getPlayer() { + public Player player() { return player; } @Override - public Optional getInitialServer() { + public Optional initialServer() { return Optional.ofNullable(initialServer); } diff --git a/api/src/main/java/com/velocitypowered/api/event/player/PlayerSettingsChangedEvent.java b/api/src/main/java/com/velocitypowered/api/event/player/PlayerClientSettingsChangedEvent.java similarity index 65% rename from api/src/main/java/com/velocitypowered/api/event/player/PlayerSettingsChangedEvent.java rename to api/src/main/java/com/velocitypowered/api/event/player/PlayerClientSettingsChangedEvent.java index 8277952c3..8b12d268a 100644 --- a/api/src/main/java/com/velocitypowered/api/event/player/PlayerSettingsChangedEvent.java +++ b/api/src/main/java/com/velocitypowered/api/event/player/PlayerClientSettingsChangedEvent.java @@ -8,11 +8,11 @@ package com.velocitypowered.api.event.player; import com.velocitypowered.api.proxy.connection.Player; -import com.velocitypowered.api.proxy.player.PlayerSettings; +import com.velocitypowered.api.proxy.player.ClientSettings; -public interface PlayerSettingsChangedEvent { +public interface PlayerClientSettingsChangedEvent { - Player getPlayer(); + Player player(); - PlayerSettings getPlayerSettings(); + ClientSettings settings(); } diff --git a/api/src/main/java/com/velocitypowered/api/event/player/PlayerSettingsChangedEventImpl.java b/api/src/main/java/com/velocitypowered/api/event/player/PlayerClientSettingsChangedEventImpl.java similarity index 58% rename from api/src/main/java/com/velocitypowered/api/event/player/PlayerSettingsChangedEventImpl.java rename to api/src/main/java/com/velocitypowered/api/event/player/PlayerClientSettingsChangedEventImpl.java index 207f3c9a1..d16df9fc4 100644 --- a/api/src/main/java/com/velocitypowered/api/event/player/PlayerSettingsChangedEventImpl.java +++ b/api/src/main/java/com/velocitypowered/api/event/player/PlayerClientSettingsChangedEventImpl.java @@ -10,33 +10,34 @@ package com.velocitypowered.api.event.player; import com.google.common.base.MoreObjects; import com.google.common.base.Preconditions; import com.velocitypowered.api.proxy.connection.Player; -import com.velocitypowered.api.proxy.player.PlayerSettings; +import com.velocitypowered.api.proxy.player.ClientSettings; -public final class PlayerSettingsChangedEventImpl implements PlayerSettingsChangedEvent { +public final class PlayerClientSettingsChangedEventImpl implements + PlayerClientSettingsChangedEvent { private final Player player; - private final PlayerSettings playerSettings; + private final ClientSettings clientSettings; - public PlayerSettingsChangedEventImpl(Player player, PlayerSettings playerSettings) { + public PlayerClientSettingsChangedEventImpl(Player player, ClientSettings clientSettings) { this.player = Preconditions.checkNotNull(player, "player"); - this.playerSettings = Preconditions.checkNotNull(playerSettings, "playerSettings"); + this.clientSettings = Preconditions.checkNotNull(clientSettings, "playerSettings"); } @Override - public Player getPlayer() { + public Player player() { return player; } @Override - public PlayerSettings getPlayerSettings() { - return playerSettings; + public ClientSettings settings() { + return clientSettings; } @Override public String toString() { return MoreObjects.toStringHelper(this) .add("player", player) - .add("playerSettings", playerSettings) + .add("playerSettings", clientSettings) .toString(); } } diff --git a/api/src/main/java/com/velocitypowered/api/event/player/PlayerModInfoEvent.java b/api/src/main/java/com/velocitypowered/api/event/player/PlayerModInfoEvent.java index 245de58f0..020fd4c9e 100644 --- a/api/src/main/java/com/velocitypowered/api/event/player/PlayerModInfoEvent.java +++ b/api/src/main/java/com/velocitypowered/api/event/player/PlayerModInfoEvent.java @@ -16,7 +16,7 @@ import com.velocitypowered.api.util.ModInfo; */ public interface PlayerModInfoEvent { - Player getPlayer(); + Player player(); - ModInfo getModInfo(); + ModInfo modInfo(); } diff --git a/api/src/main/java/com/velocitypowered/api/event/player/PlayerModInfoEventImpl.java b/api/src/main/java/com/velocitypowered/api/event/player/PlayerModInfoEventImpl.java index 9b3db009a..6b0c1d1d6 100644 --- a/api/src/main/java/com/velocitypowered/api/event/player/PlayerModInfoEventImpl.java +++ b/api/src/main/java/com/velocitypowered/api/event/player/PlayerModInfoEventImpl.java @@ -23,12 +23,12 @@ public final class PlayerModInfoEventImpl implements PlayerModInfoEvent { } @Override - public Player getPlayer() { + public Player player() { return player; } @Override - public ModInfo getModInfo() { + public ModInfo modInfo() { return modInfo; } diff --git a/api/src/main/java/com/velocitypowered/api/event/player/PlayerResourcePackStatusEvent.java b/api/src/main/java/com/velocitypowered/api/event/player/PlayerResourcePackStatusEvent.java index e088a5786..1e3a75a39 100644 --- a/api/src/main/java/com/velocitypowered/api/event/player/PlayerResourcePackStatusEvent.java +++ b/api/src/main/java/com/velocitypowered/api/event/player/PlayerResourcePackStatusEvent.java @@ -20,14 +20,14 @@ public interface PlayerResourcePackStatusEvent { * * @return the player */ - Player getPlayer(); + Player player(); /** * Returns the new status for the resource pack. * * @return the new status */ - Status getStatus(); + Status status(); /** * Represents the possible statuses for the resource pack. diff --git a/api/src/main/java/com/velocitypowered/api/event/player/PlayerResourcePackStatusEventImpl.java b/api/src/main/java/com/velocitypowered/api/event/player/PlayerResourcePackStatusEventImpl.java index ea4bee51f..55dadc7e9 100644 --- a/api/src/main/java/com/velocitypowered/api/event/player/PlayerResourcePackStatusEventImpl.java +++ b/api/src/main/java/com/velocitypowered/api/event/player/PlayerResourcePackStatusEventImpl.java @@ -30,7 +30,7 @@ public class PlayerResourcePackStatusEventImpl implements PlayerResourcePackStat * @return the player */ @Override - public Player getPlayer() { + public Player player() { return player; } @@ -40,7 +40,7 @@ public class PlayerResourcePackStatusEventImpl implements PlayerResourcePackStat * @return the new status */ @Override - public Status getStatus() { + public Status status() { return status; } diff --git a/api/src/main/java/com/velocitypowered/api/event/player/PostLoginEvent.java b/api/src/main/java/com/velocitypowered/api/event/player/PostLoginEvent.java index 3c12c5480..47348ae29 100644 --- a/api/src/main/java/com/velocitypowered/api/event/player/PostLoginEvent.java +++ b/api/src/main/java/com/velocitypowered/api/event/player/PostLoginEvent.java @@ -15,5 +15,5 @@ import com.velocitypowered.api.proxy.connection.Player; */ public interface PostLoginEvent { - Player getPlayer(); + Player player(); } diff --git a/api/src/main/java/com/velocitypowered/api/event/player/PostLoginEventImpl.java b/api/src/main/java/com/velocitypowered/api/event/player/PostLoginEventImpl.java index c627442a8..84af1e219 100644 --- a/api/src/main/java/com/velocitypowered/api/event/player/PostLoginEventImpl.java +++ b/api/src/main/java/com/velocitypowered/api/event/player/PostLoginEventImpl.java @@ -23,7 +23,7 @@ public final class PostLoginEventImpl implements PostLoginEvent { } @Override - public Player getPlayer() { + public Player player() { return player; } diff --git a/api/src/main/java/com/velocitypowered/api/event/player/PreLoginEvent.java b/api/src/main/java/com/velocitypowered/api/event/player/PreLoginEvent.java index d0715bfb1..b48e32c26 100644 --- a/api/src/main/java/com/velocitypowered/api/event/player/PreLoginEvent.java +++ b/api/src/main/java/com/velocitypowered/api/event/player/PreLoginEvent.java @@ -22,15 +22,9 @@ import org.checkerframework.checker.nullness.qual.Nullable; */ public interface PreLoginEvent extends ResultedEvent { - InboundConnection getConnection(); + InboundConnection connection(); - String getUsername(); - - @Override - PreLoginComponentResult getResult(); - - @Override - void setResult(@NonNull PreLoginComponentResult result); + String username(); /** * Represents an "allowed/allowed with forced online\offline mode/denied" result with a reason @@ -59,7 +53,7 @@ public interface PreLoginEvent extends ResultedEvent getReason() { + public Optional denialReason() { return Optional.ofNullable(reason); } diff --git a/api/src/main/java/com/velocitypowered/api/event/player/PreLoginEventImpl.java b/api/src/main/java/com/velocitypowered/api/event/player/PreLoginEventImpl.java index 7888c5941..37e2e0fae 100644 --- a/api/src/main/java/com/velocitypowered/api/event/player/PreLoginEventImpl.java +++ b/api/src/main/java/com/velocitypowered/api/event/player/PreLoginEventImpl.java @@ -34,17 +34,17 @@ public final class PreLoginEventImpl implements PreLoginEvent { } @Override - public InboundConnection getConnection() { + public InboundConnection connection() { return connection; } @Override - public String getUsername() { + public String username() { return username; } @Override - public PreLoginComponentResult getResult() { + public PreLoginComponentResult result() { return result; } diff --git a/api/src/main/java/com/velocitypowered/api/event/player/ServerConnectedEvent.java b/api/src/main/java/com/velocitypowered/api/event/player/ServerConnectedEvent.java index 141bd13b4..98de16158 100644 --- a/api/src/main/java/com/velocitypowered/api/event/player/ServerConnectedEvent.java +++ b/api/src/main/java/com/velocitypowered/api/event/player/ServerConnectedEvent.java @@ -17,9 +17,9 @@ import java.util.Optional; */ public interface ServerConnectedEvent { - Player getPlayer(); + Player player(); - RegisteredServer getServer(); + RegisteredServer target(); - Optional getPreviousServer(); + Optional previousServer(); } diff --git a/api/src/main/java/com/velocitypowered/api/event/player/ServerConnectedEventImpl.java b/api/src/main/java/com/velocitypowered/api/event/player/ServerConnectedEventImpl.java index 0c7a3cc2a..d9725a79e 100644 --- a/api/src/main/java/com/velocitypowered/api/event/player/ServerConnectedEventImpl.java +++ b/api/src/main/java/com/velocitypowered/api/event/player/ServerConnectedEventImpl.java @@ -37,17 +37,17 @@ public final class ServerConnectedEventImpl implements ServerConnectedEvent { } @Override - public Player getPlayer() { + public Player player() { return player; } @Override - public RegisteredServer getServer() { + public RegisteredServer target() { return server; } @Override - public Optional getPreviousServer() { + public Optional previousServer() { return Optional.ofNullable(previousServer); } diff --git a/api/src/main/java/com/velocitypowered/api/event/player/ServerPostConnectEvent.java b/api/src/main/java/com/velocitypowered/api/event/player/ServerPostConnectEvent.java index 105e28bcb..3eaf6a068 100644 --- a/api/src/main/java/com/velocitypowered/api/event/player/ServerPostConnectEvent.java +++ b/api/src/main/java/com/velocitypowered/api/event/player/ServerPostConnectEvent.java @@ -13,11 +13,11 @@ import org.checkerframework.checker.nullness.qual.Nullable; /** * Fired after the player has connected to a server. The server the player is now connected to is - * available in {@link Player#getCurrentServer()}. + * available in {@link Player#connectedServer()}. */ public interface ServerPostConnectEvent { - Player getPlayer(); + Player player(); - @Nullable RegisteredServer getPreviousServer(); + @Nullable RegisteredServer previousServer(); } diff --git a/api/src/main/java/com/velocitypowered/api/event/player/ServerPostConnectEventImpl.java b/api/src/main/java/com/velocitypowered/api/event/player/ServerPostConnectEventImpl.java index c97f07e93..fad2ff268 100644 --- a/api/src/main/java/com/velocitypowered/api/event/player/ServerPostConnectEventImpl.java +++ b/api/src/main/java/com/velocitypowered/api/event/player/ServerPostConnectEventImpl.java @@ -14,7 +14,7 @@ import org.checkerframework.checker.nullness.qual.Nullable; /** * Fired after the player has connected to a server. The server the player is now connected to is - * available in {@link Player#getCurrentServer()}. + * available in {@link Player#connectedServer()}. */ public class ServerPostConnectEventImpl implements ServerPostConnectEvent { @@ -28,12 +28,12 @@ public class ServerPostConnectEventImpl implements ServerPostConnectEvent { } @Override - public Player getPlayer() { + public Player player() { return player; } @Override - public @Nullable RegisteredServer getPreviousServer() { + public @Nullable RegisteredServer previousServer() { return previousServer; } diff --git a/api/src/main/java/com/velocitypowered/api/event/player/ServerPreConnectEvent.java b/api/src/main/java/com/velocitypowered/api/event/player/ServerPreConnectEvent.java index 0e5d0f129..89840bf6b 100644 --- a/api/src/main/java/com/velocitypowered/api/event/player/ServerPreConnectEvent.java +++ b/api/src/main/java/com/velocitypowered/api/event/player/ServerPreConnectEvent.java @@ -26,22 +26,16 @@ public interface ServerPreConnectEvent extends ResultedEvent getServer() { - return Optional.ofNullable(server); + public Optional target() { + return Optional.ofNullable(target); } @Override public String toString() { - if (server != null) { - return "allowed: connect to " + server.getServerInfo().getName(); + if (target != null) { + return "allowed: connect to " + target.serverInfo().name(); } return "denied"; } @@ -87,12 +81,12 @@ public interface ServerPreConnectEvent extends ResultedEvent getSuggestions(); + List suggestions(); } diff --git a/api/src/main/java/com/velocitypowered/api/event/player/TabCompleteEventImpl.java b/api/src/main/java/com/velocitypowered/api/event/player/TabCompleteEventImpl.java index 5f51ca1ac..c2128c53c 100644 --- a/api/src/main/java/com/velocitypowered/api/event/player/TabCompleteEventImpl.java +++ b/api/src/main/java/com/velocitypowered/api/event/player/TabCompleteEventImpl.java @@ -39,7 +39,7 @@ public class TabCompleteEventImpl implements TabCompleteEvent { * @return the requesting player */ @Override - public Player getPlayer() { + public Player player() { return player; } @@ -48,7 +48,7 @@ public class TabCompleteEventImpl implements TabCompleteEvent { * @return the partial message */ @Override - public String getPartialMessage() { + public String partialMessage() { return partialMessage; } @@ -57,7 +57,7 @@ public class TabCompleteEventImpl implements TabCompleteEvent { * @return the suggestions */ @Override - public List getSuggestions() { + public List suggestions() { return suggestions; } diff --git a/api/src/main/java/com/velocitypowered/api/network/ProtocolVersion.java b/api/src/main/java/com/velocitypowered/api/network/ProtocolVersion.java index e0e7c8dfd..55ee5b751 100644 --- a/api/src/main/java/com/velocitypowered/api/network/ProtocolVersion.java +++ b/api/src/main/java/com/velocitypowered/api/network/ProtocolVersion.java @@ -75,8 +75,8 @@ public enum ProtocolVersion implements Ordered { * The user-friendly representation of the lowest and highest supported versions. */ public static final String SUPPORTED_VERSION_STRING = String - .format("%s-%s", MINIMUM_VERSION.getVersionIntroducedIn(), - MAXIMUM_VERSION.getMostRecentSupportedVersion()); + .format("%s-%s", MINIMUM_VERSION.versionIntroducedIn(), + MAXIMUM_VERSION.mostRecentSupportedVersion()); /** * A map linking the protocol version number to its {@link ProtocolVersion} representation. @@ -135,29 +135,17 @@ public enum ProtocolVersion implements Ordered { * * @return the protocol version */ - public int getProtocol() { + public int protocol() { return protocol == -1 ? snapshotProtocol : protocol; } - /** - * Returns the user-friendly name for this protocol. - * - * @return the protocol name - * @deprecated A protocol may be shared by multiple versions. Use @link{#getVersionIntroducedIn()} - * or @link{#getVersionsSupportedBy()} to get more accurate version names. - */ - @Deprecated - public String getName() { - return getVersionIntroducedIn(); - } - /** * Returns the user-friendly name of the version * this protocol was introduced in. * * @return the version name */ - public String getVersionIntroducedIn() { + public String versionIntroducedIn() { return names[0]; } @@ -167,7 +155,7 @@ public enum ProtocolVersion implements Ordered { * * @return the version name */ - public String getMostRecentSupportedVersion() { + public String mostRecentSupportedVersion() { return names[names.length - 1]; } @@ -176,7 +164,7 @@ public enum ProtocolVersion implements Ordered { * * @return the version names */ - public List getVersionsSupportedBy() { + public List supportedVersions() { return ImmutableList.copyOf(names); } @@ -186,7 +174,7 @@ public enum ProtocolVersion implements Ordered { * @param protocol the protocol as an int * @return the protocol version */ - public static ProtocolVersion getProtocolVersion(int protocol) { + public static ProtocolVersion byMinecraftProtocolVersion(int protocol) { return ID_TO_PROTOCOL_CONSTANT.getOrDefault(protocol, UNKNOWN); } @@ -232,6 +220,6 @@ public enum ProtocolVersion implements Ordered { @Override public String toString() { - return getVersionIntroducedIn(); + return versionIntroducedIn(); } } diff --git a/api/src/main/java/com/velocitypowered/api/permission/PermissionFunction.java b/api/src/main/java/com/velocitypowered/api/permission/PermissionFunction.java index 7e9f2c857..2fecf03b8 100644 --- a/api/src/main/java/com/velocitypowered/api/permission/PermissionFunction.java +++ b/api/src/main/java/com/velocitypowered/api/permission/PermissionFunction.java @@ -29,10 +29,10 @@ public interface PermissionFunction { PermissionFunction ALWAYS_UNDEFINED = p -> Tristate.UNDEFINED; /** - * Gets the subjects setting for a particular permission. + * Evaluates whether or not the player has a permission. * * @param permission the permission * @return the value the permission is set to */ - Tristate getPermissionValue(String permission); + Tristate evaluatePermission(String permission); } diff --git a/api/src/main/java/com/velocitypowered/api/permission/PermissionSubject.java b/api/src/main/java/com/velocitypowered/api/permission/PermissionSubject.java index ec7171e9f..8a8d6c91b 100644 --- a/api/src/main/java/com/velocitypowered/api/permission/PermissionSubject.java +++ b/api/src/main/java/com/velocitypowered/api/permission/PermissionSubject.java @@ -19,7 +19,7 @@ public interface PermissionSubject { * @return whether or not the subject has the permission */ default boolean hasPermission(String permission) { - return getPermissionValue(permission).asBoolean(); + return evaluatePermission(permission).asBoolean(); } /** @@ -28,5 +28,5 @@ public interface PermissionSubject { * @param permission the permission * @return the value the permission is set to */ - Tristate getPermissionValue(String permission); + Tristate evaluatePermission(String permission); } diff --git a/api/src/main/java/com/velocitypowered/api/plugin/PluginContainer.java b/api/src/main/java/com/velocitypowered/api/plugin/PluginContainer.java index 1f6a61b33..b5fe9ab44 100644 --- a/api/src/main/java/com/velocitypowered/api/plugin/PluginContainer.java +++ b/api/src/main/java/com/velocitypowered/api/plugin/PluginContainer.java @@ -19,14 +19,14 @@ public interface PluginContainer { * * @return the plugin's description */ - PluginDescription getDescription(); + PluginDescription description(); /** * Returns the created plugin if it is available. * * @return the instance if available */ - default Optional getInstance() { + default Optional instance() { return Optional.empty(); } } diff --git a/api/src/main/java/com/velocitypowered/api/plugin/PluginDescription.java b/api/src/main/java/com/velocitypowered/api/plugin/PluginDescription.java index 5d8af646f..101272b32 100644 --- a/api/src/main/java/com/velocitypowered/api/plugin/PluginDescription.java +++ b/api/src/main/java/com/velocitypowered/api/plugin/PluginDescription.java @@ -34,7 +34,7 @@ public interface PluginDescription { * @return the plugin ID * @see Plugin#id() */ - String getId(); + String id(); /** * Gets the name of the {@link Plugin} within this container. @@ -42,7 +42,7 @@ public interface PluginDescription { * @return an {@link Optional} with the plugin name, may be empty * @see Plugin#name() */ - default Optional getName() { + default Optional name() { return Optional.empty(); } @@ -52,7 +52,7 @@ public interface PluginDescription { * @return an {@link Optional} with the plugin version, may be empty * @see Plugin#version() */ - default Optional getVersion() { + default Optional version() { return Optional.empty(); } @@ -62,7 +62,7 @@ public interface PluginDescription { * @return an {@link Optional} with the plugin description, may be empty * @see Plugin#description() */ - default Optional getDescription() { + default Optional description() { return Optional.empty(); } @@ -72,7 +72,7 @@ public interface PluginDescription { * @return an {@link Optional} with the plugin url, may be empty * @see Plugin#url() */ - default Optional getUrl() { + default Optional url() { return Optional.empty(); } @@ -82,7 +82,7 @@ public interface PluginDescription { * @return the plugin authors, may be empty * @see Plugin#authors() */ - default List getAuthors() { + default List authors() { return ImmutableList.of(); } @@ -92,7 +92,7 @@ public interface PluginDescription { * @return the plugin dependencies, can be empty * @see Plugin#dependencies() */ - default Collection getDependencies() { + default Collection dependencies() { return ImmutableSet.of(); } @@ -101,11 +101,11 @@ public interface PluginDescription { } /** - * Returns the source the plugin was loaded from. + * Returns the file path the plugin was loaded from. * - * @return the source the plugin was loaded from or {@link Optional#empty()} if unknown + * @return the path the plugin was loaded from or {@link Optional#empty()} if unknown */ - default Optional getSource() { + default Optional file() { return Optional.empty(); } } diff --git a/api/src/main/java/com/velocitypowered/api/proxy/ProxyServer.java b/api/src/main/java/com/velocitypowered/api/proxy/ProxyServer.java index dc4fb8c62..a82ffbe98 100644 --- a/api/src/main/java/com/velocitypowered/api/proxy/ProxyServer.java +++ b/api/src/main/java/com/velocitypowered/api/proxy/ProxyServer.java @@ -24,6 +24,7 @@ import java.util.Collection; import java.util.Optional; import java.util.UUID; import net.kyori.adventure.audience.Audience; +import net.kyori.adventure.text.Component; /** * Provides an interface to a Minecraft server proxy. @@ -35,7 +36,7 @@ public interface ProxyServer extends Audience { * * @param reason message to kick online players with */ - void shutdown(net.kyori.adventure.text.Component reason); + void shutdown(Component reason); /** * Shuts down the proxy, kicking players with the default reason. @@ -65,14 +66,14 @@ public interface ProxyServer extends Audience { * * @return the players online on this proxy */ - Collection getAllPlayers(); + Collection connectedPlayers(); /** * Returns the number of players currently connected to this proxy. * * @return the players on this proxy */ - int getPlayerCount(); + int countConnectedPlayers(); /** * Retrieves a registered {@link RegisteredServer} instance by its name. The search is @@ -81,14 +82,14 @@ public interface ProxyServer extends Audience { * @param name the name of the server * @return the registered server, which may be empty */ - Optional getServer(String name); + Optional server(String name); /** * Retrieves all {@link RegisteredServer}s registered with this proxy. * * @return the servers registered with this proxy */ - Collection getAllServers(); + Collection registeredServers(); /** * Matches all {@link Player}s whose names start with the provided partial name. @@ -129,62 +130,54 @@ public interface ProxyServer extends Audience { * * @return the console command invoker */ - ConsoleCommandSource getConsoleCommandSource(); + ConsoleCommandSource consoleCommandSource(); /** * Gets the {@link PluginManager} instance. * * @return the plugin manager instance */ - PluginManager getPluginManager(); + PluginManager pluginManager(); /** * Gets the {@link EventManager} instance. * * @return the event manager instance */ - EventManager getEventManager(); + EventManager eventManager(); /** * Gets the {@link CommandManager} instance. * * @return the command manager */ - CommandManager getCommandManager(); + CommandManager commandManager(); /** * Gets the {@link Scheduler} instance. * * @return the scheduler instance */ - Scheduler getScheduler(); + Scheduler scheduler(); /** * Gets the {@link ChannelRegistrar} instance. * * @return the channel registrar */ - ChannelRegistrar getChannelRegistrar(); - - /** - * Gets the address that this proxy is bound to. This does not necessarily indicate the external - * IP address of the proxy. - * - * @return the address the proxy is bound to - */ - SocketAddress getBoundAddress(); + ChannelRegistrar channelRegistrar(); /** * Gets the {@link ProxyConfig} instance. * * @return the proxy config */ - ProxyConfig getConfiguration(); + ProxyConfig configuration(); /** * Returns the version of the proxy. * * @return the proxy version */ - ProxyVersion getVersion(); + ProxyVersion version(); } diff --git a/api/src/main/java/com/velocitypowered/api/proxy/config/ProxyConfig.java b/api/src/main/java/com/velocitypowered/api/proxy/config/ProxyConfig.java index 360d2ba54..e5e4440e4 100644 --- a/api/src/main/java/com/velocitypowered/api/proxy/config/ProxyConfig.java +++ b/api/src/main/java/com/velocitypowered/api/proxy/config/ProxyConfig.java @@ -80,7 +80,7 @@ public interface ProxyConfig { /** * Get a Map of all servers registered in velocity.toml. This method does * not return all the servers currently in memory, although in most cases it - * does. For a view of all registered servers, see {@link ProxyServer#getAllServers()}. + * does. For a view of all registered servers, see {@link ProxyServer#registeredServers()}. * * @return registered servers map */ diff --git a/api/src/main/java/com/velocitypowered/api/proxy/connection/InboundConnection.java b/api/src/main/java/com/velocitypowered/api/proxy/connection/InboundConnection.java index 682aaa2e6..4652899f1 100644 --- a/api/src/main/java/com/velocitypowered/api/proxy/connection/InboundConnection.java +++ b/api/src/main/java/com/velocitypowered/api/proxy/connection/InboundConnection.java @@ -22,14 +22,14 @@ public interface InboundConnection { * * @return the player's remote address */ - SocketAddress getRemoteAddress(); + SocketAddress remoteAddress(); /** * Returns the hostname that the user entered into the client, if applicable. * * @return the hostname from the client */ - Optional getVirtualHost(); + Optional connectedHost(); /** * Determine whether or not the player remains online. @@ -43,5 +43,5 @@ public interface InboundConnection { * * @return the protocol version the connection uses */ - ProtocolVersion getProtocolVersion(); + ProtocolVersion protocolVersion(); } diff --git a/api/src/main/java/com/velocitypowered/api/proxy/connection/Player.java b/api/src/main/java/com/velocitypowered/api/proxy/connection/Player.java index a1a489ed0..b7586c781 100644 --- a/api/src/main/java/com/velocitypowered/api/proxy/connection/Player.java +++ b/api/src/main/java/com/velocitypowered/api/proxy/connection/Player.java @@ -11,8 +11,8 @@ import com.velocitypowered.api.command.CommandSource; import com.velocitypowered.api.event.player.PlayerResourcePackStatusEventImpl; import com.velocitypowered.api.proxy.messages.ChannelMessageSink; import com.velocitypowered.api.proxy.messages.ChannelMessageSource; +import com.velocitypowered.api.proxy.player.ClientSettings; import com.velocitypowered.api.proxy.player.ConnectionRequestBuilder; -import com.velocitypowered.api.proxy.player.PlayerSettings; import com.velocitypowered.api.proxy.player.TabList; import com.velocitypowered.api.proxy.server.RegisteredServer; import com.velocitypowered.api.util.GameProfile; @@ -34,49 +34,49 @@ public interface Player extends CommandSource, Identified, InboundConnection, * * @return the username */ - String getUsername(); + String username(); /** * Returns the player's UUID. * * @return the UUID */ - UUID getUniqueId(); + UUID id(); /** * Returns the server that the player is currently connected to. * * @return an {@link Optional} the server that the player is connected to, which may be empty */ - Optional getCurrentServer(); + Optional connectedServer(); /** * Returns the player's client settings. * * @return the settings */ - PlayerSettings getPlayerSettings(); + ClientSettings clientSettings(); /** * Returns the player's mod info if they have a modded client. * * @return an {@link Optional} the mod info. which may be empty */ - Optional getModInfo(); + Optional modInfo(); /** * Returns the current player's ping. * * @return the player's ping or -1 if ping information is currently unknown */ - long getPing(); + long ping(); /** * Returns the player's connection status. * * @return true if the player is authenticated with Mojang servers */ - boolean isOnlineMode(); + boolean onlineMode(); /** * Creates a new connection request so that the player can connect to another server. @@ -96,14 +96,14 @@ public interface Player extends CommandSource, Identified, InboundConnection, /** * Returns the player's game profile. */ - GameProfile getGameProfile(); + GameProfile gameProfile(); /** * Returns the player's tab list. * * @return this player's tab list */ - TabList getTabList(); + TabList tabList(); /** * Disconnects the player with the specified reason. Once this method is called, further calls to diff --git a/api/src/main/java/com/velocitypowered/api/proxy/connection/ServerConnection.java b/api/src/main/java/com/velocitypowered/api/proxy/connection/ServerConnection.java index 3c24f9c32..63f1fee32 100644 --- a/api/src/main/java/com/velocitypowered/api/proxy/connection/ServerConnection.java +++ b/api/src/main/java/com/velocitypowered/api/proxy/connection/ServerConnection.java @@ -22,19 +22,19 @@ public interface ServerConnection extends ChannelMessageSource, ChannelMessageSi * * @return the server this connection is connected to */ - RegisteredServer getServer(); + RegisteredServer target(); /** * Returns the server info for this connection. * * @return the server info for this connection */ - ServerInfo getServerInfo(); + ServerInfo serverInfo(); /** * Returns the player that this connection is associated with. * * @return the player for this connection */ - Player getPlayer(); + Player player(); } diff --git a/api/src/main/java/com/velocitypowered/api/proxy/messages/ChannelIdentifier.java b/api/src/main/java/com/velocitypowered/api/proxy/messages/ChannelIdentifier.java index f8d329db7..1fd1bf025 100644 --- a/api/src/main/java/com/velocitypowered/api/proxy/messages/ChannelIdentifier.java +++ b/api/src/main/java/com/velocitypowered/api/proxy/messages/ChannelIdentifier.java @@ -17,5 +17,5 @@ public interface ChannelIdentifier { * * @return the textual representation of the identifier */ - String getId(); + String id(); } diff --git a/api/src/main/java/com/velocitypowered/api/proxy/messages/ChannelRegistrar.java b/api/src/main/java/com/velocitypowered/api/proxy/messages/ChannelRegistrar.java index 197628a23..0b9768b00 100644 --- a/api/src/main/java/com/velocitypowered/api/proxy/messages/ChannelRegistrar.java +++ b/api/src/main/java/com/velocitypowered/api/proxy/messages/ChannelRegistrar.java @@ -7,6 +7,8 @@ package com.velocitypowered.api.proxy.messages; +import com.velocitypowered.api.event.connection.PluginMessageEventImpl; + /** * Represents an interface to register and unregister {@link ChannelIdentifier}s for the proxy to * listen on. @@ -15,7 +17,7 @@ public interface ChannelRegistrar { /** * Registers the specified message identifiers to listen on so you can intercept plugin messages - * on the channel using {@link com.velocitypowered.api.event.connection.PluginMessageEvent}. + * on the channel using {@link PluginMessageEventImpl}. * * @param identifiers the channel identifiers to register */ diff --git a/api/src/main/java/com/velocitypowered/api/proxy/messages/LegacyChannelIdentifier.java b/api/src/main/java/com/velocitypowered/api/proxy/messages/LegacyChannelIdentifier.java index f57181648..6eacb6924 100644 --- a/api/src/main/java/com/velocitypowered/api/proxy/messages/LegacyChannelIdentifier.java +++ b/api/src/main/java/com/velocitypowered/api/proxy/messages/LegacyChannelIdentifier.java @@ -58,7 +58,7 @@ public final class LegacyChannelIdentifier implements ChannelIdentifier { } @Override - public String getId() { + public String id() { return this.getName(); } } diff --git a/api/src/main/java/com/velocitypowered/api/proxy/messages/MinecraftChannelIdentifier.java b/api/src/main/java/com/velocitypowered/api/proxy/messages/MinecraftChannelIdentifier.java index b782132d4..f9314c3ef 100644 --- a/api/src/main/java/com/velocitypowered/api/proxy/messages/MinecraftChannelIdentifier.java +++ b/api/src/main/java/com/velocitypowered/api/proxy/messages/MinecraftChannelIdentifier.java @@ -108,7 +108,7 @@ public final class MinecraftChannelIdentifier implements ChannelIdentifier { } @Override - public String getId() { + public String id() { return namespace + ":" + name; } } diff --git a/api/src/main/java/com/velocitypowered/api/proxy/player/PlayerSettings.java b/api/src/main/java/com/velocitypowered/api/proxy/player/ClientSettings.java similarity index 97% rename from api/src/main/java/com/velocitypowered/api/proxy/player/PlayerSettings.java rename to api/src/main/java/com/velocitypowered/api/proxy/player/ClientSettings.java index 61faae34b..723bf6df3 100644 --- a/api/src/main/java/com/velocitypowered/api/proxy/player/PlayerSettings.java +++ b/api/src/main/java/com/velocitypowered/api/proxy/player/ClientSettings.java @@ -12,7 +12,7 @@ import java.util.Locale; /** * Represents the client settings for the player. */ -public interface PlayerSettings { +public interface ClientSettings { /** * Returns the locale of the Minecraft client. diff --git a/api/src/main/java/com/velocitypowered/api/proxy/player/ConnectionRequestBuilder.java b/api/src/main/java/com/velocitypowered/api/proxy/player/ConnectionRequestBuilder.java index 15d07bc6d..94bdce1e4 100644 --- a/api/src/main/java/com/velocitypowered/api/proxy/player/ConnectionRequestBuilder.java +++ b/api/src/main/java/com/velocitypowered/api/proxy/player/ConnectionRequestBuilder.java @@ -24,7 +24,7 @@ public interface ConnectionRequestBuilder { * * @return the server this request will connect to */ - RegisteredServer getServer(); + RegisteredServer target(); /** * Initiates the connection to the remote server and emits a result on the {@link @@ -61,7 +61,7 @@ public interface ConnectionRequestBuilder { * @return whether or not the request succeeded */ default boolean isSuccessful() { - return getStatus() == Status.SUCCESS; + return status() == Status.SUCCESS; } /** @@ -69,21 +69,21 @@ public interface ConnectionRequestBuilder { * * @return the status for this result */ - Status getStatus(); + Status status(); /** * Returns an (optional) textual reason for the failure to connect to the server. * * @return the reason why the user could not connect to the server */ - Optional getReason(); + Optional failureReason(); /** * Returns the server we actually tried to connect to. * * @return the server we actually tried to connect to */ - RegisteredServer getAttemptedConnection(); + RegisteredServer finalTarget(); } /** diff --git a/api/src/main/java/com/velocitypowered/api/proxy/player/TabList.java b/api/src/main/java/com/velocitypowered/api/proxy/player/TabList.java index d0010e640..bcee9d204 100644 --- a/api/src/main/java/com/velocitypowered/api/proxy/player/TabList.java +++ b/api/src/main/java/com/velocitypowered/api/proxy/player/TabList.java @@ -63,7 +63,7 @@ public interface TabList { * * @return immutable {@link Collection} of tab list entries */ - Collection getEntries(); + Collection entries(); /** * Builds a tab list entry. diff --git a/api/src/main/java/com/velocitypowered/api/proxy/player/TabListEntry.java b/api/src/main/java/com/velocitypowered/api/proxy/player/TabListEntry.java index 757271c94..eedeee88b 100644 --- a/api/src/main/java/com/velocitypowered/api/proxy/player/TabListEntry.java +++ b/api/src/main/java/com/velocitypowered/api/proxy/player/TabListEntry.java @@ -22,7 +22,7 @@ public interface TabListEntry { * * @return parent {@link TabList} */ - TabList getTabList(); + TabList parent(); /** * Returns the {@link GameProfile} of the entry, which uniquely identifies the entry with the @@ -31,7 +31,7 @@ public interface TabListEntry { * * @return {@link GameProfile} of the entry */ - GameProfile getProfile(); + GameProfile gameProfile(); /** * Returns {@link Optional} text {@link Component}, which if present is the text @@ -41,7 +41,7 @@ public interface TabListEntry { * @return {@link Optional} text {@link Component} of name displayed in the tab * list */ - Optional getDisplayName(); + Optional displayName(); /** * Sets the text {@link Component} to be displayed for {@code this} {@link TabListEntry}. If @@ -68,16 +68,16 @@ public interface TabListEntry { * * @return latency set for {@code this} entry */ - int getLatency(); + int ping(); /** * Sets the latency for {@code this} entry to the specified value. * * @param latency to changed to * @return {@code this}, for chaining - * @see #getLatency() + * @see #ping() */ - TabListEntry setLatency(int latency); + TabListEntry setPing(int latency); /** * Gets the game mode {@code this} entry has been set to. @@ -92,14 +92,14 @@ public interface TabListEntry { * * @return the game mode */ - int getGameMode(); + int gameMode(); /** * Sets the game mode for {@code this} entry to the specified value. * * @param gameMode to change to * @return {@code this}, for chaining - * @see #getGameMode() + * @see #gameMode() */ TabListEntry setGameMode(int gameMode); @@ -145,7 +145,7 @@ public interface TabListEntry { * * @param profile to set * @return {@code this}, for chaining - * @see TabListEntry#getProfile() + * @see TabListEntry#gameProfile() */ public Builder profile(GameProfile profile) { this.profile = profile; @@ -157,7 +157,7 @@ public interface TabListEntry { * * @param displayName to set * @return {@code this}, for chaining - * @see TabListEntry#getDisplayName() + * @see TabListEntry#displayName() */ public Builder displayName(@Nullable Component displayName) { this.displayName = displayName; @@ -169,7 +169,7 @@ public interface TabListEntry { * * @param latency to set * @return {@code this}, for chaining - * @see TabListEntry#getLatency() + * @see TabListEntry#ping() */ public Builder latency(int latency) { this.latency = latency; @@ -181,7 +181,7 @@ public interface TabListEntry { * * @param gameMode to set * @return {@code this}, for chaining - * @see TabListEntry#getGameMode() + * @see TabListEntry#gameMode() */ public Builder gameMode(int gameMode) { this.gameMode = gameMode; diff --git a/api/src/main/java/com/velocitypowered/api/proxy/server/QueryResponse.java b/api/src/main/java/com/velocitypowered/api/proxy/server/QueryResponse.java index 617356c46..bf46d37d4 100644 --- a/api/src/main/java/com/velocitypowered/api/proxy/server/QueryResponse.java +++ b/api/src/main/java/com/velocitypowered/api/proxy/server/QueryResponse.java @@ -30,7 +30,7 @@ public final class QueryResponse { private final String hostname; private final String gameVersion; private final String map; - private final int currentPlayers; + private final int onlinePlayers; private final int maxPlayers; private final String proxyHost; private final int proxyPort; @@ -39,13 +39,13 @@ public final class QueryResponse { private final ImmutableCollection plugins; @VisibleForTesting - QueryResponse(String hostname, String gameVersion, String map, int currentPlayers, + QueryResponse(String hostname, String gameVersion, String map, int onlinePlayers, int maxPlayers, String proxyHost, int proxyPort, ImmutableCollection players, String proxyVersion, ImmutableCollection plugins) { this.hostname = hostname; this.gameVersion = gameVersion; this.map = map; - this.currentPlayers = currentPlayers; + this.onlinePlayers = onlinePlayers; this.maxPlayers = maxPlayers; this.proxyHost = proxyHost; this.proxyPort = proxyPort; @@ -60,7 +60,7 @@ public final class QueryResponse { * * @return hostname */ - public String getHostname() { + public String hostname() { return hostname; } @@ -70,7 +70,7 @@ public final class QueryResponse { * * @return game version */ - public String getGameVersion() { + public String gameVersion() { return gameVersion; } @@ -80,7 +80,7 @@ public final class QueryResponse { * * @return map name */ - public String getMap() { + public String mapName() { return map; } @@ -89,8 +89,8 @@ public final class QueryResponse { * * @return online player count */ - public int getCurrentPlayers() { - return currentPlayers; + public int onlinePlayers() { + return onlinePlayers; } /** @@ -98,7 +98,7 @@ public final class QueryResponse { * * @return max player count */ - public int getMaxPlayers() { + public int maxPlayers() { return maxPlayers; } @@ -107,7 +107,7 @@ public final class QueryResponse { * * @return proxy hostname */ - public String getProxyHost() { + public String proxyHost() { return proxyHost; } @@ -116,7 +116,7 @@ public final class QueryResponse { * * @return proxy port */ - public int getProxyPort() { + public int proxyPort() { return proxyPort; } @@ -125,7 +125,7 @@ public final class QueryResponse { * * @return collection of players */ - public Collection getPlayers() { + public Collection players() { return players; } @@ -134,7 +134,7 @@ public final class QueryResponse { * * @return server software */ - public String getProxyVersion() { + public String proxyVersion() { return proxyVersion; } @@ -143,11 +143,10 @@ public final class QueryResponse { * * @return collection of plugins */ - public Collection getPlugins() { + public Collection plugins() { return plugins; } - /** * Creates a new {@link Builder} instance from data represented by this response, so that you * may create a new {@link QueryResponse} with new data. It is guaranteed that @@ -158,16 +157,16 @@ public final class QueryResponse { */ public Builder toBuilder() { return QueryResponse.builder() - .hostname(getHostname()) - .gameVersion(getGameVersion()) - .map(getMap()) - .currentPlayers(getCurrentPlayers()) - .maxPlayers(getMaxPlayers()) - .proxyHost(getProxyHost()) - .proxyPort(getProxyPort()) - .players(getPlayers()) - .proxyVersion(getProxyVersion()) - .plugins(getPlugins()); + .hostname(hostname()) + .gameVersion(gameVersion()) + .map(mapName()) + .onlinePlayers(onlinePlayers()) + .maxPlayers(maxPlayers()) + .proxyHost(proxyHost()) + .proxyPort(proxyPort()) + .players(players()) + .proxyVersion(proxyVersion()) + .plugins(plugins()); } /** @@ -188,7 +187,7 @@ public final class QueryResponse { return false; } QueryResponse response = (QueryResponse) o; - return currentPlayers == response.currentPlayers + return onlinePlayers == response.onlinePlayers && maxPlayers == response.maxPlayers && proxyPort == response.proxyPort && hostname.equals(response.hostname) @@ -202,9 +201,8 @@ public final class QueryResponse { @Override public int hashCode() { - return Objects - .hash(hostname, gameVersion, map, currentPlayers, maxPlayers, proxyHost, proxyPort, players, - proxyVersion, plugins); + return Objects.hash(hostname, gameVersion, map, onlinePlayers, maxPlayers, proxyHost, + proxyPort, players, proxyVersion, plugins); } @Override @@ -213,7 +211,7 @@ public final class QueryResponse { + "hostname='" + hostname + '\'' + ", gameVersion='" + gameVersion + '\'' + ", map='" + map + '\'' - + ", currentPlayers=" + currentPlayers + + ", onlinePlayers=" + onlinePlayers + ", maxPlayers=" + maxPlayers + ", proxyHost='" + proxyHost + '\'' + ", proxyPort=" + proxyPort @@ -233,7 +231,7 @@ public final class QueryResponse { private @MonotonicNonNull String proxyHost; private @MonotonicNonNull String proxyVersion; - private int currentPlayers; + private int onlinePlayers; private int maxPlayers; private int proxyPort; @@ -275,12 +273,12 @@ public final class QueryResponse { /** * Sets the players that are currently claimed to be online. - * @param currentPlayers a non-negative number representing all players online + * @param players a non-negative number representing all players online * @return this builder, for chaining */ - public Builder currentPlayers(int currentPlayers) { - Preconditions.checkArgument(currentPlayers >= 0, "currentPlayers cannot be negative"); - this.currentPlayers = currentPlayers; + public Builder onlinePlayers(int players) { + Preconditions.checkArgument(players >= 0, "currentPlayers cannot be negative"); + this.onlinePlayers = players; return this; } @@ -338,7 +336,7 @@ public final class QueryResponse { } /** - * Removes all players from the builder. This does not affect {@link #getCurrentPlayers()}. + * Removes all players from the builder. This does not affect {@link #onlinePlayers()}. * @return this builder, for chaining */ public Builder clearPlayers() { @@ -397,7 +395,7 @@ public final class QueryResponse { Preconditions.checkNotNull(hostname, "hostname"), Preconditions.checkNotNull(gameVersion, "gameVersion"), Preconditions.checkNotNull(map, "map"), - currentPlayers, + onlinePlayers, maxPlayers, Preconditions.checkNotNull(proxyHost, "proxyHost"), proxyPort, diff --git a/api/src/main/java/com/velocitypowered/api/proxy/server/RegisteredServer.java b/api/src/main/java/com/velocitypowered/api/proxy/server/RegisteredServer.java index 6c3ebf452..db7fbd3af 100644 --- a/api/src/main/java/com/velocitypowered/api/proxy/server/RegisteredServer.java +++ b/api/src/main/java/com/velocitypowered/api/proxy/server/RegisteredServer.java @@ -25,14 +25,14 @@ public interface RegisteredServer extends ChannelMessageSink, Audience { * * @return the server info */ - ServerInfo getServerInfo(); + ServerInfo serverInfo(); /** * Returns a list of all the players currently connected to this server on this proxy. * * @return the players on this proxy */ - Collection getPlayersConnected(); + Collection connectedPlayers(); /** * Attempts to ping the remote server and return the server list ping result. diff --git a/api/src/main/java/com/velocitypowered/api/proxy/server/ServerInfo.java b/api/src/main/java/com/velocitypowered/api/proxy/server/ServerInfo.java index 85e69aa34..b1f9b8427 100644 --- a/api/src/main/java/com/velocitypowered/api/proxy/server/ServerInfo.java +++ b/api/src/main/java/com/velocitypowered/api/proxy/server/ServerInfo.java @@ -8,7 +8,6 @@ package com.velocitypowered.api.proxy.server; import com.google.common.base.Preconditions; -import java.net.InetSocketAddress; import java.net.SocketAddress; import java.util.Objects; import org.checkerframework.checker.nullness.qual.Nullable; @@ -33,11 +32,11 @@ public final class ServerInfo implements Comparable { this.address = Preconditions.checkNotNull(address, "address"); } - public final String getName() { + public final String name() { return name; } - public final SocketAddress getAddress() { + public final SocketAddress address() { return address; } @@ -69,6 +68,6 @@ public final class ServerInfo implements Comparable { @Override public int compareTo(ServerInfo o) { - return this.name.compareTo(o.getName()); + return this.name.compareTo(o.name()); } } diff --git a/api/src/main/java/com/velocitypowered/api/proxy/server/ServerPing.java b/api/src/main/java/com/velocitypowered/api/proxy/server/ServerPing.java index 5f679ed78..e27e3b08e 100644 --- a/api/src/main/java/com/velocitypowered/api/proxy/server/ServerPing.java +++ b/api/src/main/java/com/velocitypowered/api/proxy/server/ServerPing.java @@ -56,23 +56,23 @@ public final class ServerPing { this.modinfo = modinfo; } - public Version getVersion() { + public Version version() { return version; } - public Optional getPlayers() { + public Optional players() { return Optional.ofNullable(players); } - public Component getDescription() { + public Component description() { return description; } - public Optional getFavicon() { + public Optional favicon() { return Optional.ofNullable(favicon); } - public Optional getModinfo() { + public Optional modInfo() { return Optional.ofNullable(modinfo); } @@ -122,7 +122,7 @@ public final class ServerPing { if (players != null) { builder.onlinePlayers = players.online; builder.maximumPlayers = players.max; - builder.samplePlayers.addAll(players.getSample()); + builder.samplePlayers.addAll(players.sample()); } else { builder.nullOutPlayers = true; } @@ -319,11 +319,11 @@ public final class ServerPing { this.name = Preconditions.checkNotNull(name, "name"); } - public int getProtocol() { + public int protocol() { return protocol; } - public String getName() { + public String name() { return name; } @@ -371,15 +371,15 @@ public final class ServerPing { this.sample = ImmutableList.copyOf(sample); } - public int getOnline() { + public int online() { return online; } - public int getMax() { + public int maximum() { return max; } - public List getSample() { + public List sample() { return sample == null ? ImmutableList.of() : sample; } @@ -421,11 +421,11 @@ public final class ServerPing { this.id = id; } - public String getName() { + public String name() { return name; } - public UUID getId() { + public UUID id() { return id; } diff --git a/proxy/src/main/java/com/velocitypowered/proxy/Metrics.java b/proxy/src/main/java/com/velocitypowered/proxy/Metrics.java index 4b8f07d1f..e927ef559 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/Metrics.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/Metrics.java @@ -103,17 +103,17 @@ public class Metrics { Metrics metrics = new Metrics(logger, 4752, metricsConfig.isEnabled()); metrics.addCustomChart( - new SingleLineChart("players", server::getPlayerCount) + new SingleLineChart("players", server::countConnectedPlayers) ); metrics.addCustomChart( - new SingleLineChart("managed_servers", () -> server.getAllServers().size()) + new SingleLineChart("managed_servers", () -> server.registeredServers().size()) ); metrics.addCustomChart( new SimplePie("online_mode", - () -> server.getConfiguration().isOnlineMode() ? "online" : "offline") + () -> server.configuration().isOnlineMode() ? "online" : "offline") ); metrics.addCustomChart(new SimplePie("velocity_version", - () -> server.getVersion().getVersion())); + () -> server.version().getVersion())); metrics.addCustomChart(new DrilldownPie("java_version", () -> { Map> map = new HashMap<>(); diff --git a/proxy/src/main/java/com/velocitypowered/proxy/Velocity.java b/proxy/src/main/java/com/velocitypowered/proxy/Velocity.java index f12378a5d..2206ed6a6 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/Velocity.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/Velocity.java @@ -84,7 +84,7 @@ public class Velocity { double bootTime = (System.currentTimeMillis() - startTime) / 1000d; logger.info("Done ({}s)!", new DecimalFormat("#.##").format(bootTime)); - server.getConsoleCommandSource().start(); + server.consoleCommandSource().start(); // If we don't have a console available (because SimpleTerminalConsole returned), then we still // need to wait, otherwise the JVM will reap us as no non-daemon threads will be active once the diff --git a/proxy/src/main/java/com/velocitypowered/proxy/VelocityServer.java b/proxy/src/main/java/com/velocitypowered/proxy/VelocityServer.java index b5866eb99..28cbb07d0 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/VelocityServer.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/VelocityServer.java @@ -155,12 +155,12 @@ public class VelocityServer implements ProxyServer, ForwardingAudience { } @Override - public VelocityConfiguration getConfiguration() { + public VelocityConfiguration configuration() { return this.configuration; } @Override - public ProxyVersion getVersion() { + public ProxyVersion version() { Package pkg = VelocityServer.class.getPackage(); String implName; String implVersion; @@ -179,7 +179,7 @@ public class VelocityServer implements ProxyServer, ForwardingAudience { } @Override - public VelocityCommandManager getCommandManager() { + public VelocityCommandManager commandManager() { return commandManager; } @@ -190,7 +190,7 @@ public class VelocityServer implements ProxyServer, ForwardingAudience { @EnsuresNonNull({"serverKeyPair", "servers", "pluginManager", "eventManager", "scheduler", "console", "cm", "configuration"}) void start() { - logger.info("Booting up {} {}...", getVersion().getName(), getVersion().getVersion()); + logger.info("Booting up {} {}...", version().getName(), version().getVersion()); console.setupStreams(); serverKeyPair = EncryptionUtils.createRsaKeyPair(1024); @@ -278,13 +278,13 @@ public class VelocityServer implements ProxyServer, ForwardingAudience { // Register the plugin main classes so that we can fire the proxy initialize event for (PluginContainer plugin : pluginManager.getPlugins()) { - Optional instance = plugin.getInstance(); + Optional instance = plugin.instance(); if (instance.isPresent()) { try { eventManager.register(instance.get(), instance.get()); } catch (Exception e) { logger.error("Unable to register plugin listener for {}", - plugin.getDescription().getName().orElse(plugin.getDescription().getId()), e); + plugin.description().name().orElse(plugin.description().id()), e); } } } @@ -327,15 +327,15 @@ public class VelocityServer implements ProxyServer, ForwardingAudience { Optional rs = servers.getServer(entry.getKey()); if (!rs.isPresent()) { servers.register(newInfo); - } else if (!rs.get().getServerInfo().equals(newInfo)) { - for (Player player : rs.get().getPlayersConnected()) { + } else if (!rs.get().serverInfo().equals(newInfo)) { + for (Player player : rs.get().connectedPlayers()) { if (!(player instanceof ConnectedPlayer)) { throw new IllegalStateException("ConnectedPlayer not found for player " + player - + " in server " + rs.get().getServerInfo().getName()); + + " in server " + rs.get().serverInfo().name()); } evacuate.add((ConnectedPlayer) player); } - servers.unregister(rs.get().getServerInfo()); + servers.unregister(rs.get().serverInfo()); servers.register(newInfo); } } @@ -518,9 +518,9 @@ public class VelocityServer implements ProxyServer, ForwardingAudience { if (configuration.isOnlineMode() && configuration.isOnlineModeKickExistingPlayers()) { return true; } - String lowerName = connection.getUsername().toLowerCase(Locale.US); + String lowerName = connection.username().toLowerCase(Locale.US); return !(connectionsByName.containsKey(lowerName) - || connectionsByUuid.containsKey(connection.getUniqueId())); + || connectionsByUuid.containsKey(connection.id())); } /** @@ -529,25 +529,25 @@ public class VelocityServer implements ProxyServer, ForwardingAudience { * @return {@code true} if we registered the connection, {@code false} if not */ public boolean registerConnection(ConnectedPlayer connection) { - String lowerName = connection.getUsername().toLowerCase(Locale.US); + String lowerName = connection.username().toLowerCase(Locale.US); if (!this.configuration.isOnlineModeKickExistingPlayers()) { if (connectionsByName.putIfAbsent(lowerName, connection) != null) { return false; } - if (connectionsByUuid.putIfAbsent(connection.getUniqueId(), connection) != null) { + if (connectionsByUuid.putIfAbsent(connection.id(), connection) != null) { connectionsByName.remove(lowerName, connection); return false; } } else { - ConnectedPlayer existing = connectionsByUuid.get(connection.getUniqueId()); + ConnectedPlayer existing = connectionsByUuid.get(connection.id()); if (existing != null) { existing.disconnect(Component.translatable("multiplayer.disconnect.duplicate_login")); } // We can now replace the entries as needed. connectionsByName.put(lowerName, connection); - connectionsByUuid.put(connection.getUniqueId(), connection); + connectionsByUuid.put(connection.id(), connection); } return true; } @@ -558,8 +558,8 @@ public class VelocityServer implements ProxyServer, ForwardingAudience { * @param connection the connection to unregister */ public void unregisterConnection(ConnectedPlayer connection) { - connectionsByName.remove(connection.getUsername().toLowerCase(Locale.US), connection); - connectionsByUuid.remove(connection.getUniqueId(), connection); + connectionsByName.remove(connection.username().toLowerCase(Locale.US), connection); + connectionsByUuid.remove(connection.id(), connection); bossBarManager.onDisconnect(connection); } @@ -579,7 +579,7 @@ public class VelocityServer implements ProxyServer, ForwardingAudience { public Collection matchPlayer(String partialName) { Objects.requireNonNull(partialName); - return getAllPlayers().stream().filter(p -> p.getUsername() + return connectedPlayers().stream().filter(p -> p.username() .regionMatches(true, 0, partialName, 0, partialName.length())) .collect(Collectors.toList()); } @@ -588,28 +588,28 @@ public class VelocityServer implements ProxyServer, ForwardingAudience { public Collection matchServer(String partialName) { Objects.requireNonNull(partialName); - return getAllServers().stream().filter(s -> s.getServerInfo().getName() + return registeredServers().stream().filter(s -> s.serverInfo().name() .regionMatches(true, 0, partialName, 0, partialName.length())) .collect(Collectors.toList()); } @Override - public Collection getAllPlayers() { + public Collection connectedPlayers() { return ImmutableList.copyOf(connectionsByUuid.values()); } @Override - public int getPlayerCount() { + public int countConnectedPlayers() { return connectionsByUuid.size(); } @Override - public Optional getServer(String name) { + public Optional server(String name) { return servers.getServer(name); } @Override - public Collection getAllServers() { + public Collection registeredServers() { return servers.getAllServers(); } @@ -624,44 +624,35 @@ public class VelocityServer implements ProxyServer, ForwardingAudience { } @Override - public VelocityConsole getConsoleCommandSource() { + public VelocityConsole consoleCommandSource() { return console; } @Override - public PluginManager getPluginManager() { + public PluginManager pluginManager() { return pluginManager; } @Override - public EventManager getEventManager() { + public EventManager eventManager() { return eventManager; } @Override - public VelocityScheduler getScheduler() { + public VelocityScheduler scheduler() { return scheduler; } @Override - public VelocityChannelRegistrar getChannelRegistrar() { + public VelocityChannelRegistrar channelRegistrar() { return channelRegistrar; } - @Override - public SocketAddress getBoundAddress() { - if (configuration == null) { - throw new IllegalStateException( - "No configuration"); // even though you'll never get the chance... heh, heh - } - return configuration.getBind(); - } - @Override public @NonNull Iterable audiences() { - Collection audiences = new ArrayList<>(this.getPlayerCount() + 1); + Collection audiences = new ArrayList<>(this.countConnectedPlayers() + 1); audiences.add(this.console); - audiences.addAll(this.getAllPlayers()); + audiences.addAll(this.connectedPlayers()); return audiences; } diff --git a/proxy/src/main/java/com/velocitypowered/proxy/command/VelocityCommandManager.java b/proxy/src/main/java/com/velocitypowered/proxy/command/VelocityCommandManager.java index a624a2106..05fb6aa06 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/command/VelocityCommandManager.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/command/VelocityCommandManager.java @@ -78,7 +78,7 @@ public class VelocityCommandManager implements CommandManager { Preconditions.checkNotNull(meta, "meta"); Preconditions.checkNotNull(command, "command"); - Iterator aliasIterator = meta.getAliases().iterator(); + Iterator aliasIterator = meta.aliases().iterator(); String primaryAlias = aliasIterator.next(); LiteralCommandNode node = null; @@ -94,7 +94,7 @@ public class VelocityCommandManager implements CommandManager { } if (!(command instanceof BrigadierCommand)) { - for (CommandNode hint : meta.getHints()) { + for (CommandNode hint : meta.hints()) { node.addChild(BrigadierUtils.wrapForHinting(hint, node.getCommand())); } } @@ -160,11 +160,11 @@ public class VelocityCommandManager implements CommandManager { Preconditions.checkNotNull(cmdLine, "cmdLine"); return callCommandEvent(source, cmdLine).thenApplyAsync(event -> { - CommandResult commandResult = event.getResult(); + CommandResult commandResult = event.result(); if (commandResult.isForwardToServer() || !commandResult.isAllowed()) { return false; } - return executeImmediately0(source, commandResult.getCommand().orElse(event.getCommand())); + return executeImmediately0(source, commandResult.modifiedCommand().orElse(event.rawCommand())); }, eventManager.getAsyncExecutor()); } diff --git a/proxy/src/main/java/com/velocitypowered/proxy/command/VelocityCommandMeta.java b/proxy/src/main/java/com/velocitypowered/proxy/command/VelocityCommandMeta.java index c45b51080..78b1f5073 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/command/VelocityCommandMeta.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/command/VelocityCommandMeta.java @@ -76,12 +76,12 @@ final class VelocityCommandMeta implements CommandMeta { } @Override - public Collection getAliases() { + public Collection aliases() { return aliases; } @Override - public Collection> getHints() { + public Collection> hints() { return hints; } } diff --git a/proxy/src/main/java/com/velocitypowered/proxy/command/builtin/BuiltinCommandUtil.java b/proxy/src/main/java/com/velocitypowered/proxy/command/builtin/BuiltinCommandUtil.java index 60edb8806..d535de6cb 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/command/builtin/BuiltinCommandUtil.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/command/builtin/BuiltinCommandUtil.java @@ -31,8 +31,8 @@ class BuiltinCommandUtil { } static List sortedServerList(ProxyServer proxy) { - List servers = new ArrayList<>(proxy.getAllServers()); - servers.sort(Comparator.comparing(RegisteredServer::getServerInfo)); + List servers = new ArrayList<>(proxy.registeredServers()); + servers.sort(Comparator.comparing(RegisteredServer::serverInfo)); return Collections.unmodifiableList(servers); } } diff --git a/proxy/src/main/java/com/velocitypowered/proxy/command/builtin/GlistCommand.java b/proxy/src/main/java/com/velocitypowered/proxy/command/builtin/GlistCommand.java index 523ebcd2b..d12f33cf2 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/command/builtin/GlistCommand.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/command/builtin/GlistCommand.java @@ -56,14 +56,14 @@ public class GlistCommand { LiteralCommandNode totalNode = LiteralArgumentBuilder .literal("glist") .requires(source -> - source.getPermissionValue("velocity.command.glist") == Tristate.TRUE) + source.evaluatePermission("velocity.command.glist") == Tristate.TRUE) .executes(this::totalCount) .build(); ArgumentCommandNode serverNode = RequiredArgumentBuilder .argument(SERVER_ARG, StringArgumentType.string()) .suggests((context, builder) -> { - for (RegisteredServer server : server.getAllServers()) { - builder.suggest(server.getServerInfo().getName()); + for (RegisteredServer server : server.registeredServers()) { + builder.suggest(server.serverInfo().name()); } builder.suggest("all"); return builder.buildFuture(); @@ -71,7 +71,7 @@ public class GlistCommand { .executes(this::serverCount) .build(); totalNode.addChild(serverNode); - server.getCommandManager().register(new BrigadierCommand(totalNode)); + server.commandManager().register(new BrigadierCommand(totalNode)); } private int totalCount(final CommandContext context) { @@ -95,7 +95,7 @@ public class GlistCommand { } sendTotalProxyCount(source); } else { - Optional registeredServer = server.getServer(serverName); + Optional registeredServer = server.server(serverName); if (!registeredServer.isPresent()) { source.sendMessage(Identity.nil(), Component.text("Server " + serverName + " doesn't exist.", NamedTextColor.RED)); @@ -109,19 +109,19 @@ public class GlistCommand { private void sendTotalProxyCount(CommandSource target) { target.sendMessage(Identity.nil(), Component.text() .content("There are ").color(NamedTextColor.YELLOW) - .append(Component.text(server.getAllPlayers().size(), NamedTextColor.GREEN)) + .append(Component.text(server.connectedPlayers().size(), NamedTextColor.GREEN)) .append(Component.text(" player(s) online.", NamedTextColor.YELLOW)) .build()); } private void sendServerPlayers(CommandSource target, RegisteredServer server, boolean fromAll) { - List onServer = ImmutableList.copyOf(server.getPlayersConnected()); + List onServer = ImmutableList.copyOf(server.connectedPlayers()); if (onServer.isEmpty() && fromAll) { return; } TextComponent.Builder builder = Component.text() - .append(Component.text("[" + server.getServerInfo().getName() + "] ", + .append(Component.text("[" + server.serverInfo().name() + "] ", NamedTextColor.DARK_AQUA)) .append(Component.text("(" + onServer.size() + ")", NamedTextColor.GRAY)) .append(Component.text(": ")) @@ -129,7 +129,7 @@ public class GlistCommand { for (int i = 0; i < onServer.size(); i++) { Player player = onServer.get(i); - builder.append(Component.text(player.getUsername())); + builder.append(Component.text(player.username())); if (i + 1 < onServer.size()) { builder.append(Component.text(", ")); diff --git a/proxy/src/main/java/com/velocitypowered/proxy/command/builtin/ServerCommand.java b/proxy/src/main/java/com/velocitypowered/proxy/command/builtin/ServerCommand.java index 52bf14d17..760c6b6e0 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/command/builtin/ServerCommand.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/command/builtin/ServerCommand.java @@ -62,7 +62,7 @@ public class ServerCommand implements SimpleCommand { if (args.length == 1) { // Trying to connect to a server. String serverName = args[0]; - Optional toConnect = server.getServer(serverName); + Optional toConnect = server.server(serverName); if (!toConnect.isPresent()) { player.sendMessage(Identity.nil(), Component.text("Server " + serverName + " doesn't exist.", NamedTextColor.RED)); @@ -76,8 +76,8 @@ public class ServerCommand implements SimpleCommand { } private void outputServerInformation(Player executor) { - String currentServer = executor.getCurrentServer().map(ServerConnection::getServerInfo) - .map(ServerInfo::getName).orElse(""); + String currentServer = executor.connectedServer().map(ServerConnection::serverInfo) + .map(ServerInfo::name).orElse(""); executor.sendMessage(Identity.nil(), Component.text( "You are currently connected to " + currentServer + ".", NamedTextColor.YELLOW)); @@ -103,18 +103,18 @@ public class ServerCommand implements SimpleCommand { } private TextComponent formatServerComponent(String currentPlayerServer, RegisteredServer server) { - ServerInfo serverInfo = server.getServerInfo(); - TextComponent serverTextComponent = Component.text(serverInfo.getName()); + ServerInfo serverInfo = server.serverInfo(); + TextComponent serverTextComponent = Component.text(serverInfo.name()); - String playersText = server.getPlayersConnected().size() + " player(s) online"; - if (serverInfo.getName().equals(currentPlayerServer)) { + String playersText = server.connectedPlayers().size() + " player(s) online"; + if (serverInfo.name().equals(currentPlayerServer)) { serverTextComponent = serverTextComponent.color(NamedTextColor.GREEN) .hoverEvent( showText(Component.text("Currently connected to this server\n" + playersText)) ); } else { serverTextComponent = serverTextComponent.color(NamedTextColor.GRAY) - .clickEvent(ClickEvent.runCommand("/server " + serverInfo.getName())) + .clickEvent(ClickEvent.runCommand("/server " + serverInfo.name())) .hoverEvent( showText(Component.text("Click to connect to this server\n" + playersText)) ); @@ -125,8 +125,8 @@ public class ServerCommand implements SimpleCommand { @Override public List suggest(final SimpleCommand.Invocation invocation) { final String[] currentArgs = invocation.arguments(); - Stream possibilities = server.getAllServers().stream() - .map(rs -> rs.getServerInfo().getName()); + Stream possibilities = server.registeredServers().stream() + .map(rs -> rs.serverInfo().name()); if (currentArgs.length == 0) { return possibilities.collect(Collectors.toList()); @@ -141,6 +141,6 @@ public class ServerCommand implements SimpleCommand { @Override public boolean hasPermission(final SimpleCommand.Invocation invocation) { - return invocation.source().getPermissionValue("velocity.command.server") != Tristate.FALSE; + return invocation.source().evaluatePermission("velocity.command.server") != Tristate.FALSE; } } diff --git a/proxy/src/main/java/com/velocitypowered/proxy/command/builtin/ShutdownCommand.java b/proxy/src/main/java/com/velocitypowered/proxy/command/builtin/ShutdownCommand.java index 47394384a..f8a8b346d 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/command/builtin/ShutdownCommand.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/command/builtin/ShutdownCommand.java @@ -41,6 +41,6 @@ public class ShutdownCommand implements RawCommand { @Override public boolean hasPermission(final Invocation invocation) { - return invocation.source() == server.getConsoleCommandSource(); + return invocation.source() == server.consoleCommandSource(); } } diff --git a/proxy/src/main/java/com/velocitypowered/proxy/command/builtin/VelocityCommand.java b/proxy/src/main/java/com/velocitypowered/proxy/command/builtin/VelocityCommand.java index 2b0b88782..cb9bc4bcd 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/command/builtin/VelocityCommand.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/command/builtin/VelocityCommand.java @@ -197,7 +197,7 @@ public class VelocityCommand implements SimpleCommand { @Override public boolean hasPermission(final CommandSource source, final String @NonNull [] args) { - return source.getPermissionValue("velocity.command.reload") == Tristate.TRUE; + return source.evaluatePermission("velocity.command.reload") == Tristate.TRUE; } } @@ -217,7 +217,7 @@ public class VelocityCommand implements SimpleCommand { return; } - ProxyVersion version = server.getVersion(); + ProxyVersion version = server.version(); TextComponent velocity = Component.text().content(version.getName() + " ") .decoration(TextDecoration.BOLD, true) @@ -251,7 +251,7 @@ public class VelocityCommand implements SimpleCommand { @Override public boolean hasPermission(final CommandSource source, final String @NonNull [] args) { - return source.getPermissionValue("velocity.command.info") != Tristate.FALSE; + return source.evaluatePermission("velocity.command.info") != Tristate.FALSE; } } @@ -270,7 +270,7 @@ public class VelocityCommand implements SimpleCommand { return; } - List plugins = ImmutableList.copyOf(server.getPluginManager().getPlugins()); + List plugins = ImmutableList.copyOf(server.pluginManager().getPlugins()); int pluginCount = plugins.size(); if (pluginCount == 0) { @@ -283,7 +283,7 @@ public class VelocityCommand implements SimpleCommand { .color(NamedTextColor.YELLOW); for (int i = 0; i < pluginCount; i++) { PluginContainer plugin = plugins.get(i); - output.append(componentForPlugin(plugin.getDescription())); + output.append(componentForPlugin(plugin.description())); if (i + 1 < pluginCount) { output.append(Component.text(", ")); } @@ -293,37 +293,37 @@ public class VelocityCommand implements SimpleCommand { } private TextComponent componentForPlugin(PluginDescription description) { - String pluginInfo = description.getName().orElse(description.getId()) - + description.getVersion().map(v -> " " + v).orElse(""); + String pluginInfo = description.name().orElse(description.id()) + + description.version().map(v -> " " + v).orElse(""); TextComponent.Builder hoverText = Component.text().content(pluginInfo); - description.getUrl().ifPresent(url -> { + description.url().ifPresent(url -> { hoverText.append(Component.newline()); hoverText.append(Component.text("Website: " + url)); }); - if (!description.getAuthors().isEmpty()) { + if (!description.authors().isEmpty()) { hoverText.append(Component.newline()); - if (description.getAuthors().size() == 1) { - hoverText.append(Component.text("Author: " + description.getAuthors().get(0))); + if (description.authors().size() == 1) { + hoverText.append(Component.text("Author: " + description.authors().get(0))); } else { hoverText.append(Component.text("Authors: " + Joiner.on(", ") - .join(description.getAuthors()))); + .join(description.authors()))); } } - description.getDescription().ifPresent(pdesc -> { + description.description().ifPresent(pdesc -> { hoverText.append(Component.newline()); hoverText.append(Component.newline()); hoverText.append(Component.text(pdesc)); }); - return Component.text(description.getId(), NamedTextColor.GRAY) + return Component.text(description.id(), NamedTextColor.GRAY) .hoverEvent(HoverEvent.showText(hoverText.build())); } @Override public boolean hasPermission(final CommandSource source, final String @NonNull [] args) { - return source.getPermissionValue("velocity.command.plugins") == Tristate.TRUE; + return source.evaluatePermission("velocity.command.plugins") == Tristate.TRUE; } } @@ -343,27 +343,27 @@ public class VelocityCommand implements SimpleCommand { return; } - Collection allServers = ImmutableSet.copyOf(server.getAllServers()); + Collection allServers = ImmutableSet.copyOf(server.registeredServers()); JsonObject servers = new JsonObject(); for (RegisteredServer iter : allServers) { - servers.add(iter.getServerInfo().getName(), + servers.add(iter.serverInfo().name(), InformationUtils.collectServerInfo(iter)); } JsonArray connectOrder = new JsonArray(); List attemptedConnectionOrder = ImmutableList.copyOf( - server.getConfiguration().getAttemptConnectionOrder()); + server.configuration().getAttemptConnectionOrder()); for (int i = 0; i < attemptedConnectionOrder.size(); i++) { connectOrder.add(attemptedConnectionOrder.get(i)); } - JsonObject proxyConfig = InformationUtils.collectProxyConfig(server.getConfiguration()); + JsonObject proxyConfig = InformationUtils.collectProxyConfig(server.configuration()); proxyConfig.add("servers", servers); proxyConfig.add("connectOrder", connectOrder); proxyConfig.add("forcedHosts", - InformationUtils.collectForcedHosts(server.getConfiguration())); + InformationUtils.collectForcedHosts(server.configuration())); JsonObject dump = new JsonObject(); - dump.add("versionInfo", InformationUtils.collectProxyInfo(server.getVersion())); + dump.add("versionInfo", InformationUtils.collectProxyInfo(server.version())); dump.add("platform", InformationUtils.collectEnvironmentInfo()); dump.add("config", proxyConfig); dump.add("plugins", InformationUtils.collectPluginInfo(server)); @@ -374,8 +374,8 @@ public class VelocityCommand implements SimpleCommand { BoundRequestBuilder request = httpClient.preparePost("https://dump.velocitypowered.com/documents"); request.setHeader("Content-Type", "text/plain"); - request.addHeader("User-Agent", server.getVersion().getName() + "/" - + server.getVersion().getVersion()); + request.addHeader("User-Agent", server.version().getName() + "/" + + server.version().getVersion()); request.setBody( InformationUtils.toHumanReadableString(dump).getBytes(StandardCharsets.UTF_8)); @@ -459,7 +459,7 @@ public class VelocityCommand implements SimpleCommand { @Override public boolean hasPermission(final CommandSource source, final String @NonNull [] args) { - return source.getPermissionValue("velocity.command.plugins") == Tristate.TRUE; + return source.evaluatePermission("velocity.command.plugins") == Tristate.TRUE; } } } diff --git a/proxy/src/main/java/com/velocitypowered/proxy/connection/MinecraftConnection.java b/proxy/src/main/java/com/velocitypowered/proxy/connection/MinecraftConnection.java index fb164ff97..787992fe0 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/connection/MinecraftConnection.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/connection/MinecraftConnection.java @@ -414,7 +414,7 @@ public class MinecraftConnection extends ChannelInboundHandlerAdapter { decoder.setThreshold(threshold); encoder.setThreshold(threshold); } else { - int level = server.getConfiguration().getCompressionLevel(); + int level = server.configuration().getCompressionLevel(); VelocityCompressor compressor = Natives.compress.get().create(level); encoder = new MinecraftCompressEncoder(threshold, compressor); diff --git a/proxy/src/main/java/com/velocitypowered/proxy/connection/backend/BackendPlaySessionHandler.java b/proxy/src/main/java/com/velocitypowered/proxy/connection/backend/BackendPlaySessionHandler.java index 877ca182c..296f0e53c 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/connection/backend/BackendPlaySessionHandler.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/connection/backend/BackendPlaySessionHandler.java @@ -26,6 +26,7 @@ import com.mojang.brigadier.tree.RootCommandNode; import com.velocitypowered.api.command.CommandSource; import com.velocitypowered.api.event.command.PlayerAvailableCommandsEventImpl; import com.velocitypowered.api.event.connection.PluginMessageEvent; +import com.velocitypowered.api.event.connection.PluginMessageEventImpl; import com.velocitypowered.api.network.ProtocolVersion; import com.velocitypowered.api.proxy.messages.ChannelIdentifier; import com.velocitypowered.proxy.VelocityServer; @@ -68,7 +69,7 @@ public class BackendPlaySessionHandler implements MinecraftSessionHandler { BackendPlaySessionHandler(VelocityServer server, VelocityServerConnection serverConn) { this.server = server; this.serverConn = serverConn; - this.playerConnection = serverConn.getPlayer().getConnection(); + this.playerConnection = serverConn.player().getConnection(); MinecraftSessionHandler psh = playerConnection.getSessionHandler(); if (!(psh instanceof ClientPlaySessionHandler)) { @@ -78,14 +79,14 @@ public class BackendPlaySessionHandler implements MinecraftSessionHandler { this.playerSessionHandler = (ClientPlaySessionHandler) psh; this.bungeecordMessageResponder = new BungeeCordMessageResponder(server, - serverConn.getPlayer()); + serverConn.player()); } @Override public void activated() { - serverConn.getServer().addPlayer(serverConn.getPlayer()); + serverConn.target().addPlayer(serverConn.player()); - if (server.getConfiguration().isBungeePluginChannelEnabled()) { + if (server.configuration().isBungeePluginChannelEnabled()) { MinecraftConnection serverMc = serverConn.ensureConnected(); serverMc.write(PluginMessageUtil.constructChannelsPacket(serverMc.getProtocolVersion(), ImmutableList.of(getBungeeCordChannel(serverMc.getProtocolVersion())), @@ -112,7 +113,7 @@ public class BackendPlaySessionHandler implements MinecraftSessionHandler { @Override public boolean handle(ClientboundDisconnectPacket packet) { serverConn.disconnect(); - serverConn.getPlayer().handleConnectionException(serverConn.getServer(), packet, true); + serverConn.player().handleConnectionException(serverConn.target(), packet, true); return true; } @@ -132,7 +133,7 @@ public class BackendPlaySessionHandler implements MinecraftSessionHandler { return true; } - if (!serverConn.getPlayer().canForwardPluginMessage(serverConn.ensureConnected() + if (!serverConn.player().canForwardPluginMessage(serverConn.ensureConnected() .getProtocolVersion(), packet)) { return true; } @@ -140,36 +141,36 @@ public class BackendPlaySessionHandler implements MinecraftSessionHandler { // 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)); + serverConn.player().getKnownChannels().addAll(PluginMessageUtil.getChannels(packet)); return false; } else if (PluginMessageUtil.isUnregister(packet)) { - serverConn.getPlayer().getKnownChannels().removeAll(PluginMessageUtil.getChannels(packet)); + serverConn.player().getKnownChannels().removeAll(PluginMessageUtil.getChannels(packet)); return false; } if (PluginMessageUtil.isMcBrand(packet)) { AbstractPluginMessagePacket rewritten = PluginMessageUtil.rewriteMinecraftBrand(packet, - server.getVersion(), playerConnection.getProtocolVersion(), ClientboundPluginMessagePacket.FACTORY); + server.version(), playerConnection.getProtocolVersion(), ClientboundPluginMessagePacket.FACTORY); playerConnection.write(rewritten); return true; } - if (serverConn.getPhase().handle(serverConn, serverConn.getPlayer(), packet)) { + if (serverConn.getPhase().handle(serverConn, serverConn.player(), packet)) { // Handled. return true; } - ChannelIdentifier id = server.getChannelRegistrar().getFromId(packet.getChannel()); + ChannelIdentifier id = server.channelRegistrar().getFromId(packet.getChannel()); if (id == null) { return false; } byte[] copy = ByteBufUtil.getBytes(packet.content()); - PluginMessageEvent event = new PluginMessageEvent(serverConn, serverConn.getPlayer(), id, + PluginMessageEvent event = new PluginMessageEventImpl(serverConn, serverConn.player(), id, copy); - server.getEventManager().fire(event) + server.eventManager().fire(event) .thenAcceptAsync(pme -> { - if (pme.getResult().isAllowed() && !playerConnection.isClosed()) { + if (pme.result().isAllowed() && !playerConnection.isClosed()) { ClientboundPluginMessagePacket copied = new ClientboundPluginMessagePacket(packet.getChannel(), Unpooled.wrappedBuffer(copy)); playerConnection.write(copied); @@ -190,18 +191,18 @@ public class BackendPlaySessionHandler implements MinecraftSessionHandler { @Override public boolean handle(ClientboundPlayerListItemPacket packet) { - serverConn.getPlayer().getTabList().processBackendPacket(packet); + serverConn.player().tabList().processBackendPacket(packet); return false; //Forward packet to player } @Override public boolean handle(ClientboundAvailableCommandsPacket commands) { RootCommandNode rootNode = commands.getRootNode(); - if (server.getConfiguration().isAnnounceProxyCommands()) { + if (server.configuration().isAnnounceProxyCommands()) { // Inject commands from the proxy. RootCommandNode dispatcherRootNode = (RootCommandNode) - filterNode(server.getCommandManager().getDispatcher().getRoot()); + filterNode(server.commandManager().getDispatcher().getRoot()); assert dispatcherRootNode != null : "Filtering root node returned null."; Collection> proxyNodes = dispatcherRootNode.getChildren(); for (CommandNode node : proxyNodes) { @@ -213,8 +214,8 @@ public class BackendPlaySessionHandler implements MinecraftSessionHandler { } } - server.getEventManager().fire( - new PlayerAvailableCommandsEventImpl(serverConn.getPlayer(), rootNode)) + server.eventManager().fire( + new PlayerAvailableCommandsEventImpl(serverConn.player(), rootNode)) .thenAcceptAsync(event -> playerConnection.write(commands), playerConnection.eventLoop()) .exceptionally((ex) -> { logger.error("Exception while handling available commands for {}", playerConnection, ex); @@ -237,7 +238,7 @@ public class BackendPlaySessionHandler implements MinecraftSessionHandler { } else { if (source.getRequirement() != null) { try { - if (!source.getRequirement().test(serverConn.getPlayer())) { + if (!source.getRequirement().test(serverConn.player())) { return null; } } catch (Throwable e) { @@ -288,7 +289,7 @@ public class BackendPlaySessionHandler implements MinecraftSessionHandler { @Override public void exception(Throwable throwable) { exceptionTriggered = true; - serverConn.getPlayer().handleConnectionException(serverConn.getServer(), throwable, + serverConn.player().handleConnectionException(serverConn.target(), throwable, !(throwable instanceof ReadTimeoutException)); } @@ -298,14 +299,14 @@ public class BackendPlaySessionHandler implements MinecraftSessionHandler { @Override public void disconnected() { - serverConn.getServer().removePlayer(serverConn.getPlayer()); + serverConn.target().removePlayer(serverConn.player()); if (!serverConn.isGracefulDisconnect() && !exceptionTriggered) { - if (server.getConfiguration().isFailoverOnUnexpectedServerDisconnect()) { - serverConn.getPlayer().handleConnectionException(serverConn.getServer(), + if (server.configuration().isFailoverOnUnexpectedServerDisconnect()) { + serverConn.player().handleConnectionException(serverConn.target(), ClientboundDisconnectPacket.create(ConnectionMessages.INTERNAL_SERVER_CONNECTION_ERROR, ProtocolVersion.MINECRAFT_1_16), true); } else { - serverConn.getPlayer().disconnect(ConnectionMessages.INTERNAL_SERVER_CONNECTION_ERROR); + serverConn.player().disconnect(ConnectionMessages.INTERNAL_SERVER_CONNECTION_ERROR); } } } diff --git a/proxy/src/main/java/com/velocitypowered/proxy/connection/backend/BungeeCordMessageResponder.java b/proxy/src/main/java/com/velocitypowered/proxy/connection/backend/BungeeCordMessageResponder.java index 0e050fb86..2862e6182 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/connection/backend/BungeeCordMessageResponder.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/connection/backend/BungeeCordMessageResponder.java @@ -64,13 +64,13 @@ public class BungeeCordMessageResponder { } public static boolean isBungeeCordMessage(AbstractPluginMessagePacket message) { - return MODERN_CHANNEL.getId().equals(message.getChannel()) || LEGACY_CHANNEL.getId() + return MODERN_CHANNEL.id().equals(message.getChannel()) || LEGACY_CHANNEL.id() .equals(message.getChannel()); } private void processConnect(ByteBufDataInput in) { String serverName = in.readUTF(); - proxy.getServer(serverName).ifPresent(server -> player.createConnectionRequest(server) + proxy.server(serverName).ifPresent(server -> player.createConnectionRequest(server) .fireAndForget()); } @@ -79,7 +79,7 @@ public class BungeeCordMessageResponder { String serverName = in.readUTF(); Optional referencedPlayer = proxy.getPlayer(playerName); - Optional referencedServer = proxy.getServer(serverName); + Optional referencedServer = proxy.server(serverName); if (referencedPlayer.isPresent() && referencedServer.isPresent()) { referencedPlayer.get().createConnectionRequest(referencedServer.get()).fireAndForget(); } @@ -90,7 +90,7 @@ public class BungeeCordMessageResponder { ByteBufDataOutput out = new ByteBufDataOutput(buf); out.writeUTF("IP"); - SocketAddress address = player.getRemoteAddress(); + SocketAddress address = player.remoteAddress(); if (address instanceof InetSocketAddress) { InetSocketAddress serverInetAddr = (InetSocketAddress) address; out.writeUTF(serverInetAddr.getHostString()); @@ -110,12 +110,12 @@ public class BungeeCordMessageResponder { if (target.equals("ALL")) { out.writeUTF("PlayerCount"); out.writeUTF("ALL"); - out.writeInt(proxy.getPlayerCount()); + out.writeInt(proxy.countConnectedPlayers()); } else { - proxy.getServer(target).ifPresent(rs -> { - int playersOnServer = rs.getPlayersConnected().size(); + proxy.server(target).ifPresent(rs -> { + int playersOnServer = rs.connectedPlayers().size(); out.writeUTF("PlayerCount"); - out.writeUTF(rs.getServerInfo().getName()); + out.writeUTF(rs.serverInfo().name()); out.writeInt(playersOnServer); }); } @@ -137,18 +137,18 @@ public class BungeeCordMessageResponder { out.writeUTF("ALL"); StringJoiner joiner = new StringJoiner(", "); - for (Player online : proxy.getAllPlayers()) { - joiner.add(online.getUsername()); + for (Player online : proxy.connectedPlayers()) { + joiner.add(online.username()); } out.writeUTF(joiner.toString()); } else { - proxy.getServer(target).ifPresent(info -> { + proxy.server(target).ifPresent(info -> { out.writeUTF("PlayerList"); - out.writeUTF(info.getServerInfo().getName()); + out.writeUTF(info.serverInfo().name()); StringJoiner joiner = new StringJoiner(", "); - for (Player online : info.getPlayersConnected()) { - joiner.add(online.getUsername()); + for (Player online : info.connectedPlayers()) { + joiner.add(online.username()); } out.writeUTF(joiner.toString()); }); @@ -163,8 +163,8 @@ public class BungeeCordMessageResponder { private void processGetServers() { StringJoiner joiner = new StringJoiner(", "); - for (RegisteredServer server : proxy.getAllServers()) { - joiner.add(server.getServerInfo().getName()); + for (RegisteredServer server : proxy.registeredServers()) { + joiner.add(server.serverInfo().name()); } ByteBuf buf = Unpooled.buffer(); @@ -202,7 +202,7 @@ public class BungeeCordMessageResponder { ByteBufDataOutput out = new ByteBufDataOutput(buf); out.writeUTF("GetServer"); - out.writeUTF(player.ensureAndGetCurrentServer().getServerInfo().getName()); + out.writeUTF(player.ensureAndGetCurrentServer().serverInfo().name()); sendResponseOnConnection(buf); } @@ -212,7 +212,7 @@ public class BungeeCordMessageResponder { ByteBufDataOutput out = new ByteBufDataOutput(buf); out.writeUTF("UUID"); - out.writeUTF(UuidUtils.toUndashed(player.getUniqueId())); + out.writeUTF(UuidUtils.toUndashed(player.id())); sendResponseOnConnection(buf); } @@ -223,8 +223,8 @@ public class BungeeCordMessageResponder { ByteBufDataOutput out = new ByteBufDataOutput(buf); out.writeUTF("UUIDOther"); - out.writeUTF(player.getUsername()); - out.writeUTF(UuidUtils.toUndashed(player.getUniqueId())); + out.writeUTF(player.username()); + out.writeUTF(UuidUtils.toUndashed(player.id())); sendResponseOnConnection(buf); }); @@ -236,8 +236,8 @@ public class BungeeCordMessageResponder { ByteBufDataOutput out = new ByteBufDataOutput(buf); out.writeUTF("IPOther"); - out.writeUTF(player.getUsername()); - SocketAddress address = player.getRemoteAddress(); + out.writeUTF(player.username()); + SocketAddress address = player.remoteAddress(); if (address instanceof InetSocketAddress) { InetSocketAddress serverInetAddr = (InetSocketAddress) address; out.writeUTF(serverInetAddr.getHostString()); @@ -252,13 +252,13 @@ public class BungeeCordMessageResponder { } private void processServerIp(ByteBufDataInput in) { - proxy.getServer(in.readUTF()).ifPresent(info -> { + proxy.server(in.readUTF()).ifPresent(info -> { ByteBuf buf = Unpooled.buffer(); ByteBufDataOutput out = new ByteBufDataOutput(buf); out.writeUTF("ServerIP"); - out.writeUTF(info.getServerInfo().getName()); - SocketAddress address = info.getServerInfo().getAddress(); + out.writeUTF(info.serverInfo().name()); + SocketAddress address = info.serverInfo().address(); if (address instanceof InetSocketAddress) { InetSocketAddress serverInetAddr = (InetSocketAddress) address; out.writeUTF(serverInetAddr.getHostString()); @@ -292,7 +292,7 @@ public class BungeeCordMessageResponder { ByteBuf toForward = in.unwrap().copy(); if (target.equals("ALL")) { try { - for (RegisteredServer rs : proxy.getAllServers()) { + for (RegisteredServer rs : proxy.registeredServers()) { ((VelocityRegisteredServer) rs).sendPluginMessage(LEGACY_CHANNEL, toForward.retainedSlice()); } @@ -300,7 +300,7 @@ public class BungeeCordMessageResponder { toForward.release(); } } else { - Optional server = proxy.getServer(target); + Optional server = proxy.server(target); if (server.isPresent()) { ((VelocityRegisteredServer) server.get()).sendPluginMessage(LEGACY_CHANNEL, toForward); } else { @@ -310,8 +310,8 @@ public class BungeeCordMessageResponder { } static String getBungeeCordChannel(ProtocolVersion version) { - return version.gte(ProtocolVersion.MINECRAFT_1_13) ? MODERN_CHANNEL.getId() - : LEGACY_CHANNEL.getId(); + return version.gte(ProtocolVersion.MINECRAFT_1_13) ? MODERN_CHANNEL.id() + : LEGACY_CHANNEL.id(); } // Note: this method will always release the buffer! @@ -328,7 +328,7 @@ public class BungeeCordMessageResponder { } boolean process(AbstractPluginMessagePacket message) { - if (!proxy.getConfiguration().isBungeePluginChannelEnabled()) { + if (!proxy.configuration().isBungeePluginChannelEnabled()) { return false; } diff --git a/proxy/src/main/java/com/velocitypowered/proxy/connection/backend/LoginSessionHandler.java b/proxy/src/main/java/com/velocitypowered/proxy/connection/backend/LoginSessionHandler.java index dbb4f75c6..6cdac9475 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/connection/backend/LoginSessionHandler.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/connection/backend/LoginSessionHandler.java @@ -73,12 +73,12 @@ public class LoginSessionHandler implements MinecraftSessionHandler { @Override public boolean handle(ClientboundLoginPluginMessagePacket packet) { MinecraftConnection mc = serverConn.ensureConnected(); - VelocityConfiguration configuration = server.getConfiguration(); + VelocityConfiguration configuration = server.configuration(); if (configuration.getPlayerInfoForwardingMode() == PlayerInfoForwarding.MODERN && packet .getChannel().equals(VelocityConstants.VELOCITY_IP_FORWARDING_CHANNEL)) { ByteBuf forwardingData = createForwardingData(configuration.getForwardingSecret(), - cleanRemoteAddress(serverConn.getPlayer().getRemoteAddress()), - serverConn.getPlayer().getGameProfile()); + cleanRemoteAddress(serverConn.player().remoteAddress()), + serverConn.player().gameProfile()); ServerboundLoginPluginResponsePacket response = new ServerboundLoginPluginResponsePacket( packet.getId(), true, forwardingData); mc.write(response); @@ -93,7 +93,7 @@ public class LoginSessionHandler implements MinecraftSessionHandler { @Override public boolean handle(ClientboundDisconnectPacket packet) { - resultFuture.complete(ConnectionRequestResults.forDisconnect(packet, serverConn.getServer())); + resultFuture.complete(ConnectionRequestResults.forDisconnect(packet, serverConn.target())); serverConn.disconnect(); return true; } @@ -106,10 +106,10 @@ public class LoginSessionHandler implements MinecraftSessionHandler { @Override public boolean handle(ClientboundServerLoginSuccessPacket packet) { - if (server.getConfiguration().getPlayerInfoForwardingMode() == PlayerInfoForwarding.MODERN + if (server.configuration().getPlayerInfoForwardingMode() == PlayerInfoForwarding.MODERN && !informationForwarded) { resultFuture.complete(ConnectionRequestResults.forDisconnect(MODERN_IP_FORWARDING_FAILURE, - serverConn.getServer())); + serverConn.target())); serverConn.disconnect(); return true; } @@ -133,7 +133,7 @@ public class LoginSessionHandler implements MinecraftSessionHandler { @Override public void disconnected() { - if (server.getConfiguration().getPlayerInfoForwardingMode() == PlayerInfoForwarding.LEGACY) { + if (server.configuration().getPlayerInfoForwardingMode() == PlayerInfoForwarding.LEGACY) { resultFuture.completeExceptionally( new QuietRuntimeException("The connection to the remote server was unexpectedly closed.\n" + "This is usually because the remote server does not have BungeeCord IP forwarding " diff --git a/proxy/src/main/java/com/velocitypowered/proxy/connection/backend/TransitionSessionHandler.java b/proxy/src/main/java/com/velocitypowered/proxy/connection/backend/TransitionSessionHandler.java index 0aad3103b..b217d106c 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/connection/backend/TransitionSessionHandler.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/connection/backend/TransitionSessionHandler.java @@ -85,9 +85,9 @@ public class TransitionSessionHandler implements MinecraftSessionHandler { @Override public boolean handle(ClientboundJoinGamePacket packet) { MinecraftConnection smc = serverConn.ensureConnected(); - VelocityServerConnection existingConnection = serverConn.getPlayer().getConnectedServer(); + VelocityServerConnection existingConnection = serverConn.player().getConnectedServer(); - final ConnectedPlayer player = serverConn.getPlayer(); + final ConnectedPlayer player = serverConn.player(); if (existingConnection != null) { // Shut down the existing server connection. @@ -100,9 +100,9 @@ public class TransitionSessionHandler implements MinecraftSessionHandler { // The goods are in hand! We got JoinGame. Let's transition completely to the new state. smc.setAutoReading(false); - server.getEventManager() - .fire(new ServerConnectedEventImpl(player, serverConn.getServer(), - existingConnection != null ? existingConnection.getServer() : null)) + server.eventManager() + .fire(new ServerConnectedEventImpl(player, serverConn.target(), + existingConnection != null ? existingConnection.target() : null)) .thenRunAsync(() -> { // Make sure we can still transition (player might have disconnected here). if (!serverConn.isActive()) { @@ -129,17 +129,17 @@ public class TransitionSessionHandler implements MinecraftSessionHandler { smc.setAutoReading(true); // Now set the connected server. - serverConn.getPlayer().setConnectedServer(serverConn); + serverConn.player().setConnectedServer(serverConn); // We're done! :) - server.getEventManager().fireAndForget(new ServerPostConnectEventImpl(player, - existingConnection == null ? null : existingConnection.getServer())); - resultFuture.complete(ConnectionRequestResults.successful(serverConn.getServer())); + server.eventManager().fireAndForget(new ServerPostConnectEventImpl(player, + existingConnection == null ? null : existingConnection.target())); + resultFuture.complete(ConnectionRequestResults.successful(serverConn.target())); }, smc.eventLoop()) .exceptionally(exc -> { logger.error("Unable to switch to new server {} for {}", - serverConn.getServerInfo().getName(), - player.getUsername(), exc); + serverConn.serverInfo().name(), + player.username(), exc); player.disconnect(ConnectionMessages.INTERNAL_SERVER_CONNECTION_ERROR); resultFuture.completeExceptionally(exc); return null; @@ -158,9 +158,9 @@ public class TransitionSessionHandler implements MinecraftSessionHandler { if (connection.getType() == ConnectionTypes.LEGACY_FORGE && !serverConn.getPhase().consideredComplete()) { resultFuture.complete(ConnectionRequestResults.forUnsafeDisconnect(packet, - serverConn.getServer())); + serverConn.target())); } else { - resultFuture.complete(ConnectionRequestResults.forDisconnect(packet, serverConn.getServer())); + resultFuture.complete(ConnectionRequestResults.forDisconnect(packet, serverConn.target())); } return true; @@ -168,35 +168,35 @@ public class TransitionSessionHandler implements MinecraftSessionHandler { @Override public boolean handle(ClientboundPluginMessagePacket packet) { - if (!serverConn.getPlayer().canForwardPluginMessage(serverConn.ensureConnected() + if (!serverConn.player().canForwardPluginMessage(serverConn.ensureConnected() .getProtocolVersion(), packet)) { return true; } if (PluginMessageUtil.isRegister(packet)) { - serverConn.getPlayer().getKnownChannels().addAll(PluginMessageUtil.getChannels(packet)); + serverConn.player().getKnownChannels().addAll(PluginMessageUtil.getChannels(packet)); } else if (PluginMessageUtil.isUnregister(packet)) { - serverConn.getPlayer().getKnownChannels().removeAll(PluginMessageUtil.getChannels(packet)); + serverConn.player().getKnownChannels().removeAll(PluginMessageUtil.getChannels(packet)); } // We always need to handle plugin messages, for Forge compatibility. - if (serverConn.getPhase().handle(serverConn, serverConn.getPlayer(), packet)) { + if (serverConn.getPhase().handle(serverConn, serverConn.player(), packet)) { // Handled, but check the server connection phase. if (serverConn.getPhase() == HELLO) { - VelocityServerConnection existingConnection = serverConn.getPlayer().getConnectedServer(); + VelocityServerConnection existingConnection = serverConn.player().getConnectedServer(); if (existingConnection != null && existingConnection.getPhase() != IN_TRANSITION) { // Indicate that this connection is "in transition" existingConnection.setConnectionPhase(IN_TRANSITION); // Tell the player that we're leaving and we just aren't coming back. existingConnection.getPhase().onDepartForNewServer(existingConnection, - serverConn.getPlayer()); + serverConn.player()); } } return true; } - serverConn.getPlayer().getConnection().write(packet.retain()); + serverConn.player().getConnection().write(packet.retain()); return true; } diff --git a/proxy/src/main/java/com/velocitypowered/proxy/connection/backend/VelocityServerConnection.java b/proxy/src/main/java/com/velocitypowered/proxy/connection/backend/VelocityServerConnection.java index bf83cb2d3..f09356100 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/connection/backend/VelocityServerConnection.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/connection/backend/VelocityServerConnection.java @@ -91,7 +91,7 @@ public class VelocityServerConnection implements MinecraftConnectionAssociation, CompletableFuture result = new CompletableFuture<>(); // Note: we use the event loop for the connection the player is on. This reduces context // switches. - SocketAddress destinationAddress = registeredServer.getServerInfo().getAddress(); + SocketAddress destinationAddress = registeredServer.serverInfo().address(); server.createBootstrap(proxyPlayer.getConnection().eventLoop(), destinationAddress) .handler(server.getBackendChannelInitializer()) .connect(destinationAddress) @@ -118,26 +118,26 @@ public class VelocityServerConnection implements MinecraftConnectionAssociation, } private String getHandshakeRemoteAddress() { - return proxyPlayer.getVirtualHost().map(InetSocketAddress::getHostString).orElse(""); + return proxyPlayer.connectedHost().map(InetSocketAddress::getHostString).orElse(""); } private String createLegacyForwardingAddress(UnaryOperator> propertiesTransform) { // BungeeCord IP forwarding is simply a special injection after the "address" in the handshake, // separated by \0 (the null byte). In order, you send the original host, the player's IP, their // UUID (undashed), and if you are in online-mode, their login properties (from Mojang). - SocketAddress playerRemoteAddress = proxyPlayer.getRemoteAddress(); + SocketAddress playerRemoteAddress = proxyPlayer.remoteAddress(); if (!(playerRemoteAddress instanceof InetSocketAddress)) { return getHandshakeRemoteAddress(); } StringBuilder data = new StringBuilder() .append(getHandshakeRemoteAddress()) .append('\0') - .append(((InetSocketAddress) proxyPlayer.getRemoteAddress()).getHostString()) + .append(((InetSocketAddress) proxyPlayer.remoteAddress()).getHostString()) .append('\0') - .append(proxyPlayer.getGameProfile().getUndashedId()) + .append(proxyPlayer.gameProfile().getUndashedId()) .append('\0'); GENERAL_GSON - .toJson(propertiesTransform.apply(proxyPlayer.getGameProfile().getProperties()), data); + .toJson(propertiesTransform.apply(proxyPlayer.gameProfile().getProperties()), data); return data.toString(); } @@ -157,7 +157,7 @@ public class VelocityServerConnection implements MinecraftConnectionAssociation, private void startHandshake() { final MinecraftConnection mc = ensureConnected(); - PlayerInfoForwarding forwardingMode = server.getConfiguration().getPlayerInfoForwardingMode(); + PlayerInfoForwarding forwardingMode = server.configuration().getPlayerInfoForwardingMode(); // Initiate the handshake. ProtocolVersion protocolVersion = proxyPlayer.getConnection().getProtocolVersion(); @@ -167,7 +167,7 @@ public class VelocityServerConnection implements MinecraftConnectionAssociation, if (forwardingMode == PlayerInfoForwarding.LEGACY) { handshake.setServerAddress(createLegacyForwardingAddress()); } else if (forwardingMode == PlayerInfoForwarding.BUNGEEGUARD) { - byte[] secret = server.getConfiguration().getForwardingSecret(); + byte[] secret = server.configuration().getForwardingSecret(); handshake.setServerAddress(createBungeeGuardForwardingAddress(secret)); } else if (proxyPlayer.getConnection().getType() == ConnectionTypes.LEGACY_FORGE) { handshake.setServerAddress(getHandshakeRemoteAddress() + HANDSHAKE_HOSTNAME_TOKEN); @@ -175,7 +175,7 @@ public class VelocityServerConnection implements MinecraftConnectionAssociation, handshake.setServerAddress(getHandshakeRemoteAddress()); } - SocketAddress destinationAddr = registeredServer.getServerInfo().getAddress(); + SocketAddress destinationAddr = registeredServer.serverInfo().address(); if (destinationAddr instanceof InetSocketAddress) { handshake.setPort(((InetSocketAddress) destinationAddr).getPort()); } @@ -183,7 +183,7 @@ public class VelocityServerConnection implements MinecraftConnectionAssociation, mc.setProtocolVersion(protocolVersion); mc.setState(StateRegistry.LOGIN); - mc.delayedWrite(new ServerboundServerLoginPacket(proxyPlayer.getUsername())); + mc.delayedWrite(new ServerboundServerLoginPacket(proxyPlayer.username())); mc.flush(); } @@ -204,17 +204,17 @@ public class VelocityServerConnection implements MinecraftConnectionAssociation, } @Override - public VelocityRegisteredServer getServer() { + public VelocityRegisteredServer target() { return registeredServer; } @Override - public ServerInfo getServerInfo() { - return registeredServer.getServerInfo(); + public ServerInfo serverInfo() { + return registeredServer.serverInfo(); } @Override - public ConnectedPlayer getPlayer() { + public ConnectedPlayer player() { return proxyPlayer; } @@ -231,8 +231,8 @@ public class VelocityServerConnection implements MinecraftConnectionAssociation, @Override public String toString() { - return "[server connection] " + proxyPlayer.getGameProfile().getName() + " -> " - + registeredServer.getServerInfo().getName(); + return "[server connection] " + proxyPlayer.gameProfile().getName() + " -> " + + registeredServer.serverInfo().name(); } @Override @@ -252,7 +252,7 @@ public class VelocityServerConnection implements MinecraftConnectionAssociation, MinecraftConnection mc = ensureConnected(); - ServerboundPluginMessagePacket message = new ServerboundPluginMessagePacket(identifier.getId(), data); + ServerboundPluginMessagePacket message = new ServerboundPluginMessagePacket(identifier.id(), data); mc.write(message); return true; } diff --git a/proxy/src/main/java/com/velocitypowered/proxy/connection/client/ClientPlaySessionHandler.java b/proxy/src/main/java/com/velocitypowered/proxy/connection/client/ClientPlaySessionHandler.java index 3f5112c4b..983cb0b56 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/connection/client/ClientPlaySessionHandler.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/connection/client/ClientPlaySessionHandler.java @@ -25,6 +25,7 @@ import static com.velocitypowered.proxy.network.PluginMessageUtil.constructChann import com.google.common.collect.ImmutableList; import com.velocitypowered.api.event.command.CommandExecuteEvent.CommandResult; import com.velocitypowered.api.event.connection.PluginMessageEvent; +import com.velocitypowered.api.event.connection.PluginMessageEventImpl; import com.velocitypowered.api.event.player.PlayerChannelRegisterEventImpl; import com.velocitypowered.api.event.player.PlayerChatEvent; import com.velocitypowered.api.event.player.PlayerChatEventImpl; @@ -104,10 +105,10 @@ public class ClientPlaySessionHandler implements MinecraftSessionHandler { @Override public void activated() { - Collection channels = server.getChannelRegistrar().getChannelsForProtocol(player - .getProtocolVersion()); + Collection channels = server.channelRegistrar().getChannelsForProtocol(player + .protocolVersion()); if (!channels.isEmpty()) { - AbstractPluginMessagePacket register = constructChannelsPacket(player.getProtocolVersion(), + AbstractPluginMessagePacket register = constructChannelsPacket(player.protocolVersion(), channels, ClientboundPluginMessagePacket.FACTORY); player.getConnection().write(register); player.getKnownChannels().addAll(channels); @@ -157,17 +158,17 @@ public class ClientPlaySessionHandler implements MinecraftSessionHandler { String msg = packet.getMessage(); if (msg.startsWith("/")) { String originalCommand = msg.substring(1); - server.getCommandManager().callCommandEvent(player, msg.substring(1)) + server.commandManager().callCommandEvent(player, msg.substring(1)) .thenComposeAsync(event -> processCommandExecuteResult(originalCommand, - event.getResult())) + event.result())) .whenComplete((ignored, throwable) -> { - if (server.getConfiguration().isLogCommandExecutions()) { + if (server.configuration().isLogCommandExecutions()) { logger.info("{} -> executed command /{}", player, originalCommand); } }) .exceptionally(e -> { logger.info("Exception occurred while running command for {}", - player.getUsername(), e); + player.username(), e); player.sendMessage(Identity.nil(), Component.text("An error occurred while running this command.", NamedTextColor.RED)); @@ -175,11 +176,11 @@ public class ClientPlaySessionHandler implements MinecraftSessionHandler { }); } else { PlayerChatEvent event = new PlayerChatEventImpl(player, msg); - server.getEventManager().fire(event) + server.eventManager().fire(event) .thenAcceptAsync(pme -> { - PlayerChatEventImpl.ChatResult chatResult = pme.getResult(); + PlayerChatEventImpl.ChatResult chatResult = pme.result(); if (chatResult.isAllowed()) { - Optional eventMsg = pme.getResult().getMessage(); + Optional eventMsg = pme.result().modifiedMessage(); if (eventMsg.isPresent()) { smc.write(new ServerboundChatPacket(eventMsg.get())); } else { @@ -225,7 +226,7 @@ public class ClientPlaySessionHandler implements MinecraftSessionHandler { channelIdentifiers.add(new LegacyChannelIdentifier(channel)); } } - server.getEventManager().fireAndForget(new PlayerChannelRegisterEventImpl(player, + server.eventManager().fireAndForget(new PlayerChannelRegisterEventImpl(player, ImmutableList.copyOf(channelIdentifiers))); backendConn.write(packet.retain()); } else if (PluginMessageUtil.isUnregister(packet)) { @@ -233,7 +234,7 @@ public class ClientPlaySessionHandler implements MinecraftSessionHandler { backendConn.write(packet.retain()); } else if (PluginMessageUtil.isMcBrand(packet)) { backendConn.write(PluginMessageUtil - .rewriteMinecraftBrand(packet, server.getVersion(), player.getProtocolVersion(), ServerboundPluginMessagePacket.FACTORY)); + .rewriteMinecraftBrand(packet, server.version(), player.protocolVersion(), ServerboundPluginMessagePacket.FACTORY)); } else if (BungeeCordMessageResponder.isBungeeCordMessage(packet)) { return true; } else { @@ -258,14 +259,14 @@ public class ClientPlaySessionHandler implements MinecraftSessionHandler { // appropriately. loginPluginMessages.add(packet.retain()); } else { - ChannelIdentifier id = server.getChannelRegistrar().getFromId(packet.getChannel()); + ChannelIdentifier id = server.channelRegistrar().getFromId(packet.getChannel()); if (id == null) { backendConn.write(packet.retain()); } else { byte[] copy = ByteBufUtil.getBytes(packet.content()); - PluginMessageEvent event = new PluginMessageEvent(player, serverConn, id, copy); - server.getEventManager().fire(event).thenAcceptAsync(pme -> { - if (pme.getResult().isAllowed()) { + PluginMessageEvent event = new PluginMessageEventImpl(player, serverConn, id, copy); + server.eventManager().fire(event).thenAcceptAsync(pme -> { + if (pme.result().isAllowed()) { ServerboundPluginMessagePacket message = new ServerboundPluginMessagePacket(packet.getChannel(), Unpooled.wrappedBuffer(copy)); backendConn.write(message); @@ -287,7 +288,7 @@ public class ClientPlaySessionHandler implements MinecraftSessionHandler { @Override public boolean handle(ServerboundResourcePackResponsePacket packet) { - server.getEventManager().fireAndForget(new PlayerResourcePackStatusEventImpl(player, + server.eventManager().fireAndForget(new PlayerResourcePackStatusEventImpl(player, packet.getStatus())); return false; } @@ -330,7 +331,7 @@ public class ClientPlaySessionHandler implements MinecraftSessionHandler { @Override public void exception(Throwable throwable) { - player.disconnect(server.getConfiguration().getMessages().getGenericConnectionError()); + player.disconnect(server.configuration().getMessages().getGenericConnectionError()); } @Override @@ -371,7 +372,7 @@ public class ClientPlaySessionHandler implements MinecraftSessionHandler { player.getPhase().onFirstJoin(player); } else { // Clear tab list to avoid duplicate entries - player.getTabList().clearAll(); + player.tabList().clearAll(); if (player.getConnection().getType() == ConnectionTypes.LEGACY_FORGE) { this.doSafeClientServerSwitch(joinGame); } else { @@ -403,9 +404,9 @@ public class ClientPlaySessionHandler implements MinecraftSessionHandler { } // Clear any title from the previous server. - if (player.getProtocolVersion().gte(MINECRAFT_1_8)) { + if (player.protocolVersion().gte(MINECRAFT_1_8)) { player.getConnection() - .delayedWrite(ClientboundTitlePacket.reset(player.getProtocolVersion())); + .delayedWrite(ClientboundTitlePacket.reset(player.protocolVersion())); } // Flush everything @@ -424,7 +425,7 @@ public class ClientPlaySessionHandler implements MinecraftSessionHandler { // to perform entity ID rewrites, eliminating potential issues from rewriting packets and // improving compatibility with mods. int sentOldDim = joinGame.getDimension(); - if (player.getProtocolVersion().lt(MINECRAFT_1_16)) { + if (player.protocolVersion().lt(MINECRAFT_1_16)) { // Before Minecraft 1.16, we could not switch to the same dimension without sending an // additional respawn. On older versions of Minecraft this forces the client to perform // garbage collection which adds additional latency. @@ -476,8 +477,8 @@ public class ClientPlaySessionHandler implements MinecraftSessionHandler { } String commandLabel = command.substring(0, commandEndPosition); - if (!server.getCommandManager().hasCommand(commandLabel)) { - if (player.getProtocolVersion().lt(MINECRAFT_1_13)) { + if (!server.commandManager().hasCommand(commandLabel)) { + if (player.protocolVersion().lt(MINECRAFT_1_13)) { // Outstanding tab completes are recorded for use with 1.12 clients and below to provide // additional tab completion support. outstandingTabComplete = packet; @@ -485,7 +486,7 @@ public class ClientPlaySessionHandler implements MinecraftSessionHandler { return false; } - server.getCommandManager().offerSuggestions(player, command) + server.commandManager().offerSuggestions(player, command) .thenAcceptAsync(suggestions -> { if (suggestions.isEmpty()) { return; @@ -514,7 +515,7 @@ public class ClientPlaySessionHandler implements MinecraftSessionHandler { } private boolean handleRegularTabComplete(ServerboundTabCompleteRequestPacket packet) { - if (player.getProtocolVersion().lt(MINECRAFT_1_13)) { + if (player.protocolVersion().lt(MINECRAFT_1_13)) { // Outstanding tab completes are recorded for use with 1.12 clients and below to provide // additional tab completion support. outstandingTabComplete = packet; @@ -544,9 +545,9 @@ public class ClientPlaySessionHandler implements MinecraftSessionHandler { private void finishCommandTabComplete(ServerboundTabCompleteRequestPacket request, ClientboundTabCompleteResponsePacket response) { String command = request.getCommand().substring(1); - server.getCommandManager().offerSuggestions(player, command) + server.commandManager().offerSuggestions(player, command) .thenAcceptAsync(offers -> { - boolean legacy = player.getProtocolVersion().lt(MINECRAFT_1_13); + boolean legacy = player.protocolVersion().lt(MINECRAFT_1_13); try { for (String offer : offers) { offer = legacy && !offer.startsWith("/") ? "/" + offer : offer; @@ -559,7 +560,7 @@ public class ClientPlaySessionHandler implements MinecraftSessionHandler { player.getConnection().write(response); } catch (Exception e) { logger.error("Unable to provide tab list completions for {} for command '{}'", - player.getUsername(), + player.username(), command, e); } }, player.getConnection().eventLoop()) @@ -577,10 +578,10 @@ public class ClientPlaySessionHandler implements MinecraftSessionHandler { for (Offer offer : response.getOffers()) { offers.add(offer.getText()); } - server.getEventManager().fire(new TabCompleteEventImpl(player, request.getCommand(), offers)) + server.eventManager().fire(new TabCompleteEventImpl(player, request.getCommand(), offers)) .thenAcceptAsync(e -> { response.getOffers().clear(); - for (String s : e.getSuggestions()) { + for (String s : e.suggestions()) { response.getOffers().add(new Offer(s)); } player.getConnection().write(response); @@ -600,12 +601,12 @@ public class ClientPlaySessionHandler implements MinecraftSessionHandler { } MinecraftConnection smc = player.ensureAndGetCurrentServer().ensureConnected(); - String commandToRun = result.getCommand().orElse(originalCommand); + String commandToRun = result.modifiedCommand().orElse(originalCommand); if (result.isForwardToServer()) { return CompletableFuture.runAsync(() -> smc.write(new ServerboundChatPacket("/" + commandToRun)), smc.eventLoop()); } else { - return server.getCommandManager().executeImmediately(player, commandToRun) + return server.commandManager().executeImmediately(player, commandToRun) .thenAcceptAsync(hasRun -> { if (!hasRun) { smc.write(new ServerboundChatPacket("/" + commandToRun)); diff --git a/proxy/src/main/java/com/velocitypowered/proxy/connection/client/ClientSettingsWrapper.java b/proxy/src/main/java/com/velocitypowered/proxy/connection/client/ClientSettingsWrapper.java index 64b9988ef..773ad2b70 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/connection/client/ClientSettingsWrapper.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/connection/client/ClientSettingsWrapper.java @@ -17,15 +17,15 @@ package com.velocitypowered.proxy.connection.client; -import com.velocitypowered.api.proxy.player.PlayerSettings; +import com.velocitypowered.api.proxy.player.ClientSettings; import com.velocitypowered.api.proxy.player.SkinParts; import com.velocitypowered.proxy.network.packet.serverbound.ServerboundClientSettingsPacket; import java.util.Locale; import org.checkerframework.checker.nullness.qual.Nullable; -public class ClientSettingsWrapper implements PlayerSettings { +public class ClientSettingsWrapper implements ClientSettings { - static final PlayerSettings DEFAULT = new ClientSettingsWrapper( + static final ClientSettings DEFAULT = new ClientSettingsWrapper( new ServerboundClientSettingsPacket("en_US", (byte) 10, 0, true, (short) 127, 1)); private final ServerboundClientSettingsPacket settings; diff --git a/proxy/src/main/java/com/velocitypowered/proxy/connection/client/ConnectedPlayer.java b/proxy/src/main/java/com/velocitypowered/proxy/connection/client/ConnectedPlayer.java index 9bcd6a6de..4098f75e9 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/connection/client/ConnectedPlayer.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/connection/client/ConnectedPlayer.java @@ -32,8 +32,8 @@ import com.velocitypowered.api.event.player.KickedFromServerEvent.Notify; import com.velocitypowered.api.event.player.KickedFromServerEvent.RedirectPlayer; import com.velocitypowered.api.event.player.KickedFromServerEvent.ServerKickResult; import com.velocitypowered.api.event.player.KickedFromServerEventImpl; +import com.velocitypowered.api.event.player.PlayerClientSettingsChangedEventImpl; import com.velocitypowered.api.event.player.PlayerModInfoEventImpl; -import com.velocitypowered.api.event.player.PlayerSettingsChangedEventImpl; import com.velocitypowered.api.event.player.ServerPreConnectEvent; import com.velocitypowered.api.event.player.ServerPreConnectEventImpl; import com.velocitypowered.api.network.ProtocolVersion; @@ -43,8 +43,8 @@ import com.velocitypowered.api.permission.Tristate; import com.velocitypowered.api.proxy.connection.Player; import com.velocitypowered.api.proxy.connection.ServerConnection; import com.velocitypowered.api.proxy.messages.ChannelIdentifier; +import com.velocitypowered.api.proxy.player.ClientSettings; import com.velocitypowered.api.proxy.player.ConnectionRequestBuilder; -import com.velocitypowered.api.proxy.player.PlayerSettings; import com.velocitypowered.api.proxy.server.RegisteredServer; import com.velocitypowered.api.util.GameProfile; import com.velocitypowered.api.util.ModInfo; @@ -122,7 +122,7 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player { private final boolean onlineMode; private @Nullable VelocityServerConnection connectedServer; private @Nullable VelocityServerConnection connectionInFlight; - private @Nullable PlayerSettings settings; + private @Nullable ClientSettings settings; private @Nullable ModInfo modInfo; private Component playerListHeader = Component.empty(); private Component playerListFooter = Component.empty(); @@ -157,17 +157,17 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player { } @Override - public String getUsername() { + public String username() { return profile.getName(); } @Override - public UUID getUniqueId() { + public UUID id() { return profile.getId(); } @Override - public Optional getCurrentServer() { + public Optional connectedServer() { return Optional.ofNullable(connectedServer); } @@ -184,7 +184,7 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player { } @Override - public GameProfile getGameProfile() { + public GameProfile gameProfile() { return profile; } @@ -193,7 +193,7 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player { } @Override - public long getPing() { + public long ping() { return this.ping; } @@ -202,38 +202,38 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player { } @Override - public boolean isOnlineMode() { + public boolean onlineMode() { return onlineMode; } @Override - public PlayerSettings getPlayerSettings() { + public ClientSettings clientSettings() { return settings == null ? ClientSettingsWrapper.DEFAULT : this.settings; } void setPlayerSettings(ServerboundClientSettingsPacket settings) { ClientSettingsWrapper cs = new ClientSettingsWrapper(settings); this.settings = cs; - server.getEventManager().fireAndForget(new PlayerSettingsChangedEventImpl(this, cs)); + server.eventManager().fireAndForget(new PlayerClientSettingsChangedEventImpl(this, cs)); } @Override - public Optional getModInfo() { + public Optional modInfo() { return Optional.ofNullable(modInfo); } public void setModInfo(ModInfo modInfo) { this.modInfo = modInfo; - server.getEventManager().fireAndForget(new PlayerModInfoEventImpl(this, modInfo)); + server.eventManager().fireAndForget(new PlayerModInfoEventImpl(this, modInfo)); } @Override - public SocketAddress getRemoteAddress() { + public SocketAddress remoteAddress() { return connection.getRemoteAddress(); } @Override - public Optional getVirtualHost() { + public Optional connectedHost() { return Optional.ofNullable(virtualHost); } @@ -247,7 +247,7 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player { } @Override - public ProtocolVersion getProtocolVersion() { + public ProtocolVersion protocolVersion() { return connection.getProtocolVersion(); } @@ -258,7 +258,7 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player { Preconditions.checkNotNull(type, "type"); connection.write(new ClientboundChatPacket( - ProtocolUtils.getJsonChatSerializer(this.getProtocolVersion()).serialize(message), + ProtocolUtils.getJsonChatSerializer(this.protocolVersion()).serialize(message), type == MessageType.CHAT ? ClientboundChatPacket.CHAT_TYPE : ClientboundChatPacket.SYSTEM_TYPE, @@ -268,7 +268,7 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player { @Override public void sendActionBar(net.kyori.adventure.text.@NonNull Component message) { - ProtocolVersion playerVersion = getProtocolVersion(); + ProtocolVersion playerVersion = protocolVersion(); if (playerVersion.gte(ProtocolVersion.MINECRAFT_1_11)) { // Use the title packet instead. connection.write(new ClientboundTitlePacket( @@ -307,9 +307,9 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player { @Override public void showTitle(net.kyori.adventure.title.@NonNull Title title) { - if (this.getProtocolVersion().compareTo(ProtocolVersion.MINECRAFT_1_8) >= 0) { + if (this.protocolVersion().compareTo(ProtocolVersion.MINECRAFT_1_8) >= 0) { GsonComponentSerializer serializer = ProtocolUtils.getJsonChatSerializer(this - .getProtocolVersion()); + .protocolVersion()); connection.delayedWrite(new ClientboundTitlePacket( ClientboundTitlePacket.SET_TITLE, @@ -323,7 +323,7 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player { net.kyori.adventure.title.Title.Times times = title.times(); if (times != null) { - connection.delayedWrite(ClientboundTitlePacket.times(this.getProtocolVersion(), times)); + connection.delayedWrite(ClientboundTitlePacket.times(this.protocolVersion(), times)); } connection.flush(); @@ -332,28 +332,28 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player { @Override public void clearTitle() { - if (this.getProtocolVersion().compareTo(ProtocolVersion.MINECRAFT_1_8) >= 0) { - connection.write(ClientboundTitlePacket.hide(this.getProtocolVersion())); + if (this.protocolVersion().compareTo(ProtocolVersion.MINECRAFT_1_8) >= 0) { + connection.write(ClientboundTitlePacket.hide(this.protocolVersion())); } } @Override public void resetTitle() { - if (this.getProtocolVersion().compareTo(ProtocolVersion.MINECRAFT_1_8) >= 0) { - connection.write(ClientboundTitlePacket.reset(this.getProtocolVersion())); + if (this.protocolVersion().compareTo(ProtocolVersion.MINECRAFT_1_8) >= 0) { + connection.write(ClientboundTitlePacket.reset(this.protocolVersion())); } } @Override public void hideBossBar(@NonNull BossBar bar) { - if (this.getProtocolVersion().compareTo(ProtocolVersion.MINECRAFT_1_9) >= 0) { + if (this.protocolVersion().compareTo(ProtocolVersion.MINECRAFT_1_9) >= 0) { this.server.getBossBarManager().removeBossBar(this, bar); } } @Override public void showBossBar(@NonNull BossBar bar) { - if (this.getProtocolVersion().compareTo(ProtocolVersion.MINECRAFT_1_9) >= 0) { + if (this.protocolVersion().compareTo(ProtocolVersion.MINECRAFT_1_9) >= 0) { this.server.getBossBarManager().addBossBar(this, bar); } } @@ -369,7 +369,7 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player { } @Override - public VelocityTabList getTabList() { + public VelocityTabList tabList() { return tabList; } @@ -390,7 +390,7 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player { public void disconnect0(Component reason, boolean duringLogin) { logger.info("{} has disconnected: {}", this, LegacyComponentSerializer.legacySection().serialize(reason)); - connection.closeWith(ClientboundDisconnectPacket.create(reason, this.getProtocolVersion())); + connection.closeWith(ClientboundDisconnectPacket.create(reason, this.protocolVersion())); } public @Nullable VelocityServerConnection getConnectedServer() { @@ -430,13 +430,13 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player { } } String userMessage; - if (connectedServer != null && connectedServer.getServerInfo().equals(server.getServerInfo())) { - userMessage = "Your connection to " + server.getServerInfo().getName() + " encountered an " + if (connectedServer != null && connectedServer.serverInfo().equals(server.serverInfo())) { + userMessage = "Your connection to " + server.serverInfo().name() + " encountered an " + "error."; } else { - logger.error("{}: unable to connect to server {}", this, server.getServerInfo().getName(), + logger.error("{}: unable to connect to server {}", this, server.serverInfo().name(), wrapped); - userMessage = "Unable to connect to " + server.getServerInfo().getName() + ". Try again " + userMessage = "Unable to connect to " + server.serverInfo().name() + ". Try again " + "later."; } handleConnectionException(server, null, Component.text(userMessage, @@ -456,23 +456,23 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player { return; } - VelocityConfiguration.Messages messages = this.server.getConfiguration().getMessages(); + VelocityConfiguration.Messages messages = this.server.configuration().getMessages(); Component disconnectReason = GsonComponentSerializer.gson().deserialize(disconnect.getReason()); String plainTextReason = PASS_THRU_TRANSLATE.serialize(disconnectReason); - if (connectedServer != null && connectedServer.getServerInfo().equals(server.getServerInfo())) { - logger.error("{}: kicked from server {}: {}", this, server.getServerInfo().getName(), + if (connectedServer != null && connectedServer.serverInfo().equals(server.serverInfo())) { + logger.error("{}: kicked from server {}: {}", this, server.serverInfo().name(), plainTextReason); handleConnectionException(server, disconnectReason, Component.text() - .append(messages.getKickPrefix(server.getServerInfo().getName()) + .append(messages.getKickPrefix(server.serverInfo().name()) .colorIfAbsent(NamedTextColor.RED)) .color(NamedTextColor.RED) .append(disconnectReason) .build(), safe); } else { logger.error("{}: disconnected while connecting to {}: {}", this, - server.getServerInfo().getName(), plainTextReason); + server.serverInfo().name(), plainTextReason); handleConnectionException(server, disconnectReason, Component.text() - .append(messages.getDisconnectPrefix(server.getServerInfo().getName()) + .append(messages.getDisconnectPrefix(server.serverInfo().name()) .colorIfAbsent(NamedTextColor.RED)) .append(disconnectReason) .build(), safe); @@ -494,7 +494,7 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player { return; } - boolean kickedFromCurrent = connectedServer == null || connectedServer.getServer().equals(rs); + boolean kickedFromCurrent = connectedServer == null || connectedServer.target().equals(rs); ServerKickResult result; if (kickedFromCurrent) { Optional next = getNextServerToTry(rs); @@ -502,7 +502,7 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player { .orElseGet(() -> DisconnectPlayer.create(friendlyReason)); } else { // If we were kicked by going to another server, the connection should not be in flight - if (connectionInFlight != null && connectionInFlight.getServer().equals(rs)) { + if (connectionInFlight != null && connectionInFlight.target().equals(rs)) { resetInFlightConnection(); } result = Notify.create(friendlyReason); @@ -514,7 +514,7 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player { private void handleKickEvent(KickedFromServerEvent originalEvent, Component friendlyReason, boolean kickedFromCurrent) { - server.getEventManager().fire(originalEvent) + server.eventManager().fire(originalEvent) .thenAcceptAsync(event -> { // There can't be any connection in flight now. connectionInFlight = null; @@ -530,36 +530,36 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player { return; } - if (event.getResult() instanceof DisconnectPlayer) { - DisconnectPlayer res = (DisconnectPlayer) event.getResult(); - disconnect(res.getReason()); - } else if (event.getResult() instanceof RedirectPlayer) { - RedirectPlayer res = (RedirectPlayer) event.getResult(); + if (event.result() instanceof DisconnectPlayer) { + DisconnectPlayer res = (DisconnectPlayer) event.result(); + disconnect(res.message()); + } else if (event.result() instanceof RedirectPlayer) { + RedirectPlayer res = (RedirectPlayer) event.result(); createConnectionRequest(res.getServer()) .connect() .whenCompleteAsync((status, throwable) -> { if (throwable != null) { - handleConnectionException(status != null ? status.getAttemptedConnection() + handleConnectionException(status != null ? status.finalTarget() : res.getServer(), throwable, true); return; } - switch (status.getStatus()) { + switch (status.status()) { // Impossible/nonsensical cases case ALREADY_CONNECTED: case CONNECTION_IN_PROGRESS: // Fatal case case CONNECTION_CANCELLED: - disconnect(status.getReason().orElse(res.getMessage())); + disconnect(status.failureReason().orElse(res.message())); break; case SERVER_DISCONNECTED: - Component reason = status.getReason() + Component reason = status.failureReason() .orElse(ConnectionMessages.INTERNAL_SERVER_CONNECTION_ERROR); handleConnectionException(res.getServer(), ClientboundDisconnectPacket.create(reason, - getProtocolVersion()), ((Impl) status).isSafe()); + protocolVersion()), ((Impl) status).isSafe()); break; case SUCCESS: - sendMessage(Identity.nil(), server.getConfiguration().getMessages() + sendMessage(Identity.nil(), server.configuration().getMessages() .getMovedToNewServerPrefix().append(friendlyReason)); break; default: @@ -567,12 +567,12 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player { break; } }, connection.eventLoop()); - } else if (event.getResult() instanceof Notify) { - Notify res = (Notify) event.getResult(); + } else if (event.result() instanceof Notify) { + Notify res = (Notify) event.result(); if (event.kickedDuringServerConnect() && previouslyConnected) { - sendMessage(Identity.nil(), res.getMessage()); + sendMessage(Identity.nil(), res.message()); } else { - disconnect(res.getMessage()); + disconnect(res.message()); } } else { // In case someone gets creative, assume we want to disconnect the player. @@ -601,31 +601,31 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player { */ private Optional getNextServerToTry(@Nullable RegisteredServer current) { if (serversToTry == null) { - String virtualHostStr = getVirtualHost().map(InetSocketAddress::getHostString).orElse(""); - serversToTry = server.getConfiguration().getForcedHosts().getOrDefault(virtualHostStr, + String virtualHostStr = connectedHost().map(InetSocketAddress::getHostString).orElse(""); + serversToTry = server.configuration().getForcedHosts().getOrDefault(virtualHostStr, Collections.emptyList()); } if (serversToTry.isEmpty()) { - serversToTry = server.getConfiguration().getAttemptConnectionOrder(); + serversToTry = server.configuration().getAttemptConnectionOrder(); } for (int i = tryIndex; i < serversToTry.size(); i++) { String toTryName = serversToTry.get(i); - if ((connectedServer != null && hasSameName(connectedServer.getServer(), toTryName)) - || (connectionInFlight != null && hasSameName(connectionInFlight.getServer(), toTryName)) + if ((connectedServer != null && hasSameName(connectedServer.target(), toTryName)) + || (connectionInFlight != null && hasSameName(connectionInFlight.target(), toTryName)) || (current != null && hasSameName(current, toTryName))) { continue; } tryIndex = i; - return server.getServer(toTryName); + return server.server(toTryName); } return Optional.empty(); } private static boolean hasSameName(RegisteredServer server, String name) { - return server.getServerInfo().getName().equalsIgnoreCase(name); + return server.serverInfo().name().equalsIgnoreCase(name); } /** @@ -668,12 +668,12 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player { connectedServer.disconnect(); } - Optional connectedPlayer = server.getPlayer(this.getUniqueId()); + Optional connectedPlayer = server.getPlayer(this.id()); server.unregisterConnection(this); DisconnectEventImpl.LoginStatus status; if (connectedPlayer.isPresent()) { - if (!connectedPlayer.get().getCurrentServer().isPresent()) { + if (!connectedPlayer.get().connectedServer().isPresent()) { status = LoginStatus.PRE_SERVER_JOIN; } else { status = connectedPlayer.get() == this ? LoginStatus.SUCCESSFUL_LOGIN @@ -685,7 +685,7 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player { } DisconnectEvent event = new DisconnectEventImpl(this, status); - server.getEventManager().fire(event).whenComplete((val, ex) -> { + server.eventManager().fire(event).whenComplete((val, ex) -> { if (ex == null) { this.teardownFuture.complete(null); } else { @@ -700,19 +700,19 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player { @Override public String toString() { - return "[connected player] " + profile.getName() + " (" + getRemoteAddress() + ")"; + return "[connected player] " + profile.getName() + " (" + remoteAddress() + ")"; } @Override - public Tristate getPermissionValue(String permission) { - return permissionFunction.getPermissionValue(permission); + public Tristate evaluatePermission(String permission) { + return permissionFunction.evaluatePermission(permission); } @Override public boolean sendPluginMessage(ChannelIdentifier identifier, byte[] data) { Preconditions.checkNotNull(identifier, "identifier"); Preconditions.checkNotNull(data, "data"); - ClientboundPluginMessagePacket message = new ClientboundPluginMessagePacket(identifier.getId(), + ClientboundPluginMessagePacket message = new ClientboundPluginMessagePacket(identifier.id(), Unpooled.wrappedBuffer(data)); connection.write(message); return true; @@ -730,7 +730,7 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player { public void sendResourcePack(String url) { Preconditions.checkNotNull(url, "url"); - if (this.getProtocolVersion().compareTo(ProtocolVersion.MINECRAFT_1_8) >= 0) { + if (this.protocolVersion().compareTo(ProtocolVersion.MINECRAFT_1_8) >= 0) { connection.write(new ClientboundResourcePackRequestPacket(url, "")); } } @@ -741,7 +741,7 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player { Preconditions.checkNotNull(hash, "hash"); Preconditions.checkArgument(hash.length == 20, "Hash length is not 20"); - if (this.getProtocolVersion().compareTo(ProtocolVersion.MINECRAFT_1_8) >= 0) { + if (this.protocolVersion().compareTo(ProtocolVersion.MINECRAFT_1_8) >= 0) { connection.write(new ClientboundResourcePackRequestPacket(url, ByteBufUtil.hexDump(hash))); } } @@ -813,7 +813,7 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player { private class IdentityImpl implements Identity { @Override public @NonNull UUID uuid() { - return ConnectedPlayer.this.getUniqueId(); + return ConnectedPlayer.this.id(); } } @@ -826,7 +826,7 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player { } @Override - public RegisteredServer getServer() { + public RegisteredServer target() { return toConnect; } @@ -837,7 +837,7 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player { && !connectedServer.hasCompletedJoin())) { return Optional.of(ConnectionRequestBuilder.Status.CONNECTION_IN_PROGRESS); } - if (connectedServer != null && connectedServer.getServer().equals(server)) { + if (connectedServer != null && connectedServer.target().equals(server)) { return Optional.of(ALREADY_CONNECTED); } return Optional.empty(); @@ -856,9 +856,9 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player { ServerPreConnectEvent event = new ServerPreConnectEventImpl(ConnectedPlayer.this, toConnect); - return server.getEventManager().fire(event) + return server.eventManager().fire(event) .thenComposeAsync(newEvent -> { - Optional newDest = newEvent.getResult().getServer(); + Optional newDest = newEvent.result().target(); if (!newDest.isPresent()) { return completedFuture( plainResult(ConnectionRequestBuilder.Status.CONNECTION_CANCELLED, toConnect) @@ -895,7 +895,7 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player { .whenCompleteAsync((status, throwable) -> { if (status != null && !status.isSuccessful()) { if (!status.isSafe()) { - handleConnectionException(status.getAttemptedConnection(), throwable, false); + handleConnectionException(status.finalTarget(), throwable, false); return; } } @@ -912,12 +912,12 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player { .whenCompleteAsync((status, throwable) -> { if (throwable != null) { // TODO: The exception handling from this is not very good. Find a better way. - handleConnectionException(status != null ? status.getAttemptedConnection() + handleConnectionException(status != null ? status.finalTarget() : toConnect, throwable, true); return; } - switch (status.getStatus()) { + switch (status.status()) { case ALREADY_CONNECTED: sendMessage(Identity.nil(), ConnectionMessages.ALREADY_CONNECTED); break; @@ -928,10 +928,10 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player { // Ignored; the plugin probably already handled this. break; case SERVER_DISCONNECTED: - Component reason = status.getReason() + Component reason = status.failureReason() .orElse(ConnectionMessages.INTERNAL_SERVER_CONNECTION_ERROR); handleConnectionException(toConnect, ClientboundDisconnectPacket.create(reason, - getProtocolVersion()), status.isSafe()); + protocolVersion()), status.isSafe()); break; default: // The only remaining value is successful (no need to do anything!) diff --git a/proxy/src/main/java/com/velocitypowered/proxy/connection/client/HandshakeSessionHandler.java b/proxy/src/main/java/com/velocitypowered/proxy/connection/client/HandshakeSessionHandler.java index bed65af85..bfe109eaf 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/connection/client/HandshakeSessionHandler.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/connection/client/HandshakeSessionHandler.java @@ -130,13 +130,13 @@ public class HandshakeSessionHandler implements MinecraftSessionHandler { // If the proxy is configured for modern forwarding, we must deny connections from 1.12.2 // and lower, otherwise IP information will never get forwarded. - if (server.getConfiguration().getPlayerInfoForwardingMode() == PlayerInfoForwarding.MODERN + if (server.configuration().getPlayerInfoForwardingMode() == PlayerInfoForwarding.MODERN && handshake.getProtocolVersion().lt(ProtocolVersion.MINECRAFT_1_13)) { ic.disconnectQuietly(Component.text("This server is only compatible with 1.13 and above.")); return; } - server.getEventManager().fireAndForget(new ConnectionHandshakeEventImpl(ic)); + server.eventManager().fireAndForget(new ConnectionHandshakeEventImpl(ic)); connection.setSessionHandler(new LoginSessionHandler(server, connection, ic)); } @@ -204,12 +204,12 @@ public class HandshakeSessionHandler implements MinecraftSessionHandler { } @Override - public InetSocketAddress getRemoteAddress() { + public InetSocketAddress remoteAddress() { return (InetSocketAddress) connection.getRemoteAddress(); } @Override - public Optional getVirtualHost() { + public Optional connectedHost() { return Optional.ofNullable(ping.getVhost()); } @@ -219,7 +219,7 @@ public class HandshakeSessionHandler implements MinecraftSessionHandler { } @Override - public ProtocolVersion getProtocolVersion() { + public ProtocolVersion protocolVersion() { return ProtocolVersion.LEGACY; } } diff --git a/proxy/src/main/java/com/velocitypowered/proxy/connection/client/InitialInboundConnection.java b/proxy/src/main/java/com/velocitypowered/proxy/connection/client/InitialInboundConnection.java index c178ab4aa..cb6384d7a 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/connection/client/InitialInboundConnection.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/connection/client/InitialInboundConnection.java @@ -47,12 +47,12 @@ public final class InitialInboundConnection implements InboundConnection, } @Override - public InetSocketAddress getRemoteAddress() { + public InetSocketAddress remoteAddress() { return (InetSocketAddress) connection.getRemoteAddress(); } @Override - public Optional getVirtualHost() { + public Optional connectedHost() { return Optional.of(InetSocketAddress.createUnresolved(cleanedAddress, handshake.getPort())); } @@ -62,7 +62,7 @@ public final class InitialInboundConnection implements InboundConnection, } @Override - public ProtocolVersion getProtocolVersion() { + public ProtocolVersion protocolVersion() { return connection.getProtocolVersion(); } @@ -78,7 +78,7 @@ public final class InitialInboundConnection implements InboundConnection, public void disconnect(Component reason) { logger.info("{} has disconnected: {}", this, LegacyComponentSerializer.legacySection().serialize(reason)); - connection.closeWith(ClientboundDisconnectPacket.create(reason, getProtocolVersion())); + connection.closeWith(ClientboundDisconnectPacket.create(reason, protocolVersion())); } /** @@ -86,6 +86,6 @@ public final class InitialInboundConnection implements InboundConnection, * @param reason the reason for disconnecting */ public void disconnectQuietly(Component reason) { - connection.closeWith(ClientboundDisconnectPacket.create(reason, getProtocolVersion())); + connection.closeWith(ClientboundDisconnectPacket.create(reason, protocolVersion())); } } diff --git a/proxy/src/main/java/com/velocitypowered/proxy/connection/client/LoginSessionHandler.java b/proxy/src/main/java/com/velocitypowered/proxy/connection/client/LoginSessionHandler.java index 1edfb613d..36ec63cf8 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/connection/client/LoginSessionHandler.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/connection/client/LoginSessionHandler.java @@ -123,7 +123,7 @@ public class LoginSessionHandler implements MinecraftSessionHandler { String url = String.format(MOJANG_HASJOINED_URL, urlFormParameterEscaper().escape(login.getUsername()), serverId); - if (server.getConfiguration().shouldPreventClientProxyConnections()) { + if (server.configuration().shouldPreventClientProxyConnections()) { url += "&ip=" + urlFormParameterEscaper().escape(playerIp); } @@ -151,7 +151,7 @@ public class LoginSessionHandler implements MinecraftSessionHandler { GameProfile.class), true); } else if (profileResponse.getStatusCode() == 204) { // Apparently an offline-mode user logged onto this online-mode proxy. - inbound.disconnect(server.getConfiguration().getMessages().getOnlineModeOnly()); + inbound.disconnect(server.configuration().getMessages().getOnlineModeOnly()); } else { // Something else went wrong logger.error( @@ -180,23 +180,23 @@ public class LoginSessionHandler implements MinecraftSessionHandler { throw new IllegalStateException("No ServerLogin packet received yet."); } PreLoginEvent event = new PreLoginEventImpl(inbound, login.getUsername()); - server.getEventManager().fire(event) + server.eventManager().fire(event) .thenRunAsync(() -> { if (mcConnection.isClosed()) { // The player was disconnected return; } - PreLoginComponentResult result = event.getResult(); - Optional disconnectReason = result.getReason(); + PreLoginComponentResult result = event.result(); + Optional disconnectReason = result.denialReason(); if (disconnectReason.isPresent()) { // The component is guaranteed to be provided if the connection was denied. mcConnection.closeWith(ClientboundDisconnectPacket.create(disconnectReason.get(), - inbound.getProtocolVersion())); + inbound.protocolVersion())); return; } - if (!result.isForceOfflineMode() && (server.getConfiguration().isOnlineMode() || result + if (!result.isForceOfflineMode() && (server.configuration().isOnlineMode() || result .isOnlineModeAllowed())) { // Request encryption. ClientboundEncryptionRequestPacket request = generateEncryptionRequest(); @@ -225,29 +225,29 @@ public class LoginSessionHandler implements MinecraftSessionHandler { private void initializePlayer(GameProfile profile, boolean onlineMode) { // Some connection types may need to alter the game profile. profile = mcConnection.getType().addGameProfileTokensIfRequired(profile, - server.getConfiguration().getPlayerInfoForwardingMode()); + server.configuration().getPlayerInfoForwardingMode()); GameProfileRequestEvent profileRequestEvent = new GameProfileRequestEventImpl(inbound, profile, onlineMode); final GameProfile finalProfile = profile; - server.getEventManager().fire(profileRequestEvent).thenComposeAsync(profileEvent -> { + server.eventManager().fire(profileRequestEvent).thenComposeAsync(profileEvent -> { if (mcConnection.isClosed()) { // The player disconnected after we authenticated them. return CompletableFuture.completedFuture(null); } // Initiate a regular connection and move over to it. - ConnectedPlayer player = new ConnectedPlayer(server, profileEvent.getGameProfile(), - mcConnection, inbound.getVirtualHost().orElse(null), onlineMode); + ConnectedPlayer player = new ConnectedPlayer(server, profileEvent.gameProfile(), + mcConnection, inbound.connectedHost().orElse(null), onlineMode); this.connectedPlayer = player; if (!server.canRegisterConnection(player)) { - player.disconnect0(server.getConfiguration().getMessages().getAlreadyConnected(), true); + player.disconnect0(server.configuration().getMessages().getAlreadyConnected(), true); return CompletableFuture.completedFuture(null); } logger.info("{} has connected", player); - return server.getEventManager() + return server.eventManager() .fire(new PermissionsSetupEventImpl(player, ConnectedPlayer.DEFAULT_PERMISSIONS)) .thenAcceptAsync(event -> { if (!mcConnection.isClosed()) { @@ -258,8 +258,8 @@ public class LoginSessionHandler implements MinecraftSessionHandler { "A plugin permission provider {} provided an invalid permission function" + " for player {}. This is a bug in the plugin, not in Velocity. Falling" + " back to the default permission function.", - event.getProvider().getClass().getName(), - player.getUsername()); + event.provider().getClass().getName(), + player.username()); } else { player.setPermissionFunction(function); } @@ -273,42 +273,42 @@ public class LoginSessionHandler implements MinecraftSessionHandler { } private void completeLoginProtocolPhaseAndInitialize(ConnectedPlayer player) { - int threshold = server.getConfiguration().getCompressionThreshold(); + int threshold = server.configuration().getCompressionThreshold(); if (threshold >= 0 && mcConnection.getProtocolVersion().gte(MINECRAFT_1_8)) { mcConnection.write(new ClientboundSetCompressionPacket(threshold)); mcConnection.setCompressionThreshold(threshold); } - VelocityConfiguration configuration = server.getConfiguration(); - UUID playerUniqueId = player.getUniqueId(); + VelocityConfiguration configuration = server.configuration(); + UUID playerUniqueId = player.id(); if (configuration.getPlayerInfoForwardingMode() == PlayerInfoForwarding.NONE) { - playerUniqueId = UuidUtils.generateOfflinePlayerUuid(player.getUsername()); + playerUniqueId = UuidUtils.generateOfflinePlayerUuid(player.username()); } - mcConnection.write(new ClientboundServerLoginSuccessPacket(playerUniqueId, player.getUsername())); + mcConnection.write(new ClientboundServerLoginSuccessPacket(playerUniqueId, player.username())); mcConnection.setAssociation(player); mcConnection.setState(StateRegistry.PLAY); - server.getEventManager().fire(new LoginEventImpl(player)) + server.eventManager().fire(new LoginEventImpl(player)) .thenAcceptAsync(event -> { if (mcConnection.isClosed()) { // The player was disconnected - server.getEventManager().fireAndForget(new DisconnectEventImpl(player, + server.eventManager().fireAndForget(new DisconnectEventImpl(player, LoginStatus.CANCELLED_BY_USER_BEFORE_COMPLETE)); return; } - Optional reason = event.getResult().getReason(); + Optional reason = event.result().reason(); if (reason.isPresent()) { player.disconnect0(reason.get(), true); } else { if (!server.registerConnection(player)) { - player.disconnect0(server.getConfiguration().getMessages() + player.disconnect0(server.configuration().getMessages() .getAlreadyConnected(), true); return; } mcConnection.setSessionHandler(new InitialConnectSessionHandler(player)); - server.getEventManager().fire(new PostLoginEventImpl(player)) + server.eventManager().fire(new PostLoginEventImpl(player)) .thenCompose((ignored) -> connectToInitialServer(player)) .exceptionally((ex) -> { logger.error("Exception while connecting {} to initial server", player, ex); @@ -327,11 +327,11 @@ public class LoginSessionHandler implements MinecraftSessionHandler { PlayerChooseInitialServerEvent event = new PlayerChooseInitialServerEventImpl(player, initialFromConfig.orElse(null)); - return server.getEventManager().fire(event) + return server.eventManager().fire(event) .thenRunAsync(() -> { - Optional toTry = event.getInitialServer(); + Optional toTry = event.initialServer(); if (!toTry.isPresent()) { - player.disconnect0(server.getConfiguration().getMessages() + player.disconnect0(server.configuration().getMessages() .getNoAvailableServers(), true); return; } diff --git a/proxy/src/main/java/com/velocitypowered/proxy/connection/client/StatusSessionHandler.java b/proxy/src/main/java/com/velocitypowered/proxy/connection/client/StatusSessionHandler.java index 58331c84d..5a9f7cd29 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/connection/client/StatusSessionHandler.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/connection/client/StatusSessionHandler.java @@ -67,18 +67,18 @@ public class StatusSessionHandler implements MinecraftSessionHandler { @Override public void activated() { - if (server.getConfiguration().isShowPingRequests()) { + if (server.configuration().isShowPingRequests()) { logger.info("{} is pinging the server with version {}", this.inbound, this.connection.getProtocolVersion()); } } private ServerPing constructLocalPing(ProtocolVersion version) { - VelocityConfiguration configuration = server.getConfiguration(); + VelocityConfiguration configuration = server.configuration(); return new ServerPing( - new ServerPing.Version(version.getProtocol(), + new ServerPing.Version(version.protocol(), "Velocity " + ProtocolVersion.SUPPORTED_VERSION_STRING), - new ServerPing.Players(server.getPlayerCount(), configuration.getShowMaxPlayers(), + new ServerPing.Players(server.countConnectedPlayers(), configuration.getShowMaxPlayers(), ImmutableList.of()), configuration.getMotd(), configuration.getFavicon().orElse(null), @@ -91,7 +91,7 @@ public class StatusSessionHandler implements MinecraftSessionHandler { ServerPing fallback = constructLocalPing(pingingVersion); List> pings = new ArrayList<>(); for (String s : servers) { - Optional rs = server.getServer(s); + Optional rs = server.server(s); if (!rs.isPresent()) { continue; } @@ -123,7 +123,7 @@ public class StatusSessionHandler implements MinecraftSessionHandler { if (response == fallback) { continue; } - Optional modInfo = response.getModinfo(); + Optional modInfo = response.modInfo(); if (modInfo.isPresent()) { return fallback.asBuilder().mods(modInfo.get()).build(); } @@ -138,16 +138,16 @@ public class StatusSessionHandler implements MinecraftSessionHandler { continue; } - if (response.getDescription() == null) { + if (response.description() == null) { continue; } return new ServerPing( - fallback.getVersion(), - fallback.getPlayers().orElse(null), - response.getDescription(), - fallback.getFavicon().orElse(null), - response.getModinfo().orElse(null) + fallback.version(), + fallback.players().orElse(null), + response.description(), + fallback.favicon().orElse(null), + response.modInfo().orElse(null) ); } return fallback; @@ -159,7 +159,7 @@ public class StatusSessionHandler implements MinecraftSessionHandler { } private CompletableFuture getInitialPing() { - VelocityConfiguration configuration = server.getConfiguration(); + VelocityConfiguration configuration = server.configuration(); ProtocolVersion shownVersion = ProtocolVersion.isSupported(connection.getProtocolVersion()) ? connection.getProtocolVersion() : ProtocolVersion.MAXIMUM_VERSION; PingPassthroughMode passthrough = configuration.getPingPassthrough(); @@ -167,10 +167,10 @@ public class StatusSessionHandler implements MinecraftSessionHandler { if (passthrough == PingPassthroughMode.DISABLED) { return CompletableFuture.completedFuture(constructLocalPing(shownVersion)); } else { - String virtualHostStr = inbound.getVirtualHost().map(InetSocketAddress::getHostString) + String virtualHostStr = inbound.connectedHost().map(InetSocketAddress::getHostString) .orElse(""); - List serversToTry = server.getConfiguration().getForcedHosts().getOrDefault( - virtualHostStr, server.getConfiguration().getAttemptConnectionOrder()); + List serversToTry = server.configuration().getForcedHosts().getOrDefault( + virtualHostStr, server.configuration().getAttemptConnectionOrder()); return attemptPingPassthrough(configuration.getPingPassthrough(), serversToTry, shownVersion); } } @@ -182,9 +182,9 @@ public class StatusSessionHandler implements MinecraftSessionHandler { } this.pingReceived = true; getInitialPing() - .thenCompose(ping -> server.getEventManager().fire(new ProxyPingEventImpl(inbound, ping))) + .thenCompose(ping -> server.eventManager().fire(new ProxyPingEventImpl(inbound, ping))) .thenAcceptAsync(event -> connection.closeWith( - LegacyDisconnectPacket.fromServerPing(event.getPing(), packet.getVersion())), + LegacyDisconnectPacket.fromServerPing(event.ping(), packet.getVersion())), connection.eventLoop()) .exceptionally((ex) -> { logger.error("Exception while handling legacy ping {}", packet, ex); @@ -207,12 +207,12 @@ public class StatusSessionHandler implements MinecraftSessionHandler { this.pingReceived = true; getInitialPing() - .thenCompose(ping -> server.getEventManager().fire(new ProxyPingEventImpl(inbound, ping))) + .thenCompose(ping -> server.eventManager().fire(new ProxyPingEventImpl(inbound, ping))) .thenAcceptAsync( (event) -> { StringBuilder json = new StringBuilder(); VelocityServer.getPingGsonInstance(connection.getProtocolVersion()) - .toJson(event.getPing(), json); + .toJson(event.ping(), json); connection.write(new ClientboundStatusResponsePacket(json)); }, connection.eventLoop()) diff --git a/proxy/src/main/java/com/velocitypowered/proxy/connection/forge/legacy/LegacyForgeHandshakeBackendPhase.java b/proxy/src/main/java/com/velocitypowered/proxy/connection/forge/legacy/LegacyForgeHandshakeBackendPhase.java index 5ec3895fe..690427cb1 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/connection/forge/legacy/LegacyForgeHandshakeBackendPhase.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/connection/forge/legacy/LegacyForgeHandshakeBackendPhase.java @@ -60,7 +60,7 @@ public enum LegacyForgeHandshakeBackendPhase implements BackendConnectionPhase { if (mc != null) { mc.setType(ConnectionTypes.LEGACY_FORGE); } - connection.getPlayer().sendLegacyForgeHandshakeResetPacket(); + connection.player().sendLegacyForgeHandshakeResetPacket(); } }, diff --git a/proxy/src/main/java/com/velocitypowered/proxy/connection/forge/legacy/LegacyForgeHandshakeClientPhase.java b/proxy/src/main/java/com/velocitypowered/proxy/connection/forge/legacy/LegacyForgeHandshakeClientPhase.java index e1ea9cdf4..11109404a 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/connection/forge/legacy/LegacyForgeHandshakeClientPhase.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/connection/forge/legacy/LegacyForgeHandshakeClientPhase.java @@ -93,7 +93,7 @@ public enum LegacyForgeHandshakeClientPhase implements ClientConnectionPhase { AbstractPluginMessagePacket message, MinecraftConnection backendConn) { // Read the mod list if we haven't already. - if (!player.getModInfo().isPresent()) { + if (!player.modInfo().isPresent()) { List mods = LegacyForgeUtil.readModList(message); if (!mods.isEmpty()) { player.setModInfo(new ModInfo("FML", mods)); diff --git a/proxy/src/main/java/com/velocitypowered/proxy/connection/util/ConnectionRequestResults.java b/proxy/src/main/java/com/velocitypowered/proxy/connection/util/ConnectionRequestResults.java index 9f5b8aab0..51380d6d0 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/connection/util/ConnectionRequestResults.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/connection/util/ConnectionRequestResults.java @@ -84,17 +84,17 @@ public class ConnectionRequestResults { } @Override - public Status getStatus() { + public Status status() { return status; } @Override - public Optional getReason() { + public Optional failureReason() { return Optional.ofNullable(component); } @Override - public RegisteredServer getAttemptedConnection() { + public RegisteredServer finalTarget() { return attemptedConnection; } diff --git a/proxy/src/main/java/com/velocitypowered/proxy/console/VelocityConsole.java b/proxy/src/main/java/com/velocitypowered/proxy/console/VelocityConsole.java index cd8df4f36..80e4e3ea6 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/console/VelocityConsole.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/console/VelocityConsole.java @@ -57,8 +57,8 @@ public final class VelocityConsole extends SimpleTerminalConsole implements Cons } @Override - public @NonNull Tristate getPermissionValue(@NonNull String permission) { - return this.permissionFunction.getPermissionValue(permission); + public @NonNull Tristate evaluatePermission(@NonNull String permission) { + return this.permissionFunction.evaluatePermission(permission); } /** @@ -75,13 +75,13 @@ public final class VelocityConsole extends SimpleTerminalConsole implements Cons public void setupPermissions() { PermissionsSetupEvent event = new PermissionsSetupEventImpl(this, s -> ALWAYS_TRUE); // we can safely block here, this is before any listeners fire - this.permissionFunction = this.server.getEventManager().fire(event).join().createFunction(this); + this.permissionFunction = this.server.eventManager().fire(event).join().createFunction(this); if (this.permissionFunction == null) { logger.error( "A plugin permission provider {} provided an invalid permission function" + " for the console. This is a bug in the plugin, not in Velocity. Falling" + " back to the default permission function.", - event.getProvider().getClass().getName()); + event.provider().getClass().getName()); this.permissionFunction = ALWAYS_TRUE; } } @@ -92,7 +92,7 @@ public final class VelocityConsole extends SimpleTerminalConsole implements Cons .appName("Velocity") .completer((reader, parsedLine, list) -> { try { - List offers = this.server.getCommandManager() + List offers = this.server.commandManager() .offerSuggestions(this, parsedLine.line()) .join(); // Console doesn't get harmed much by this... for (String offer : offers) { @@ -113,7 +113,7 @@ public final class VelocityConsole extends SimpleTerminalConsole implements Cons @Override protected void runCommand(String command) { try { - if (!this.server.getCommandManager().execute(this, command).join()) { + if (!this.server.commandManager().execute(this, command).join()) { sendMessage(Component.text("Command not found.", NamedTextColor.RED)); } } catch (Exception e) { diff --git a/proxy/src/main/java/com/velocitypowered/proxy/event/VelocityEventManager.java b/proxy/src/main/java/com/velocitypowered/proxy/event/VelocityEventManager.java index b6252cef9..1b44e074c 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/event/VelocityEventManager.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/event/VelocityEventManager.java @@ -595,7 +595,7 @@ public class VelocityEventManager implements EventManager { private static void logHandlerException( final HandlerRegistration registration, final Throwable t) { logger.error("Couldn't pass {} to {}", registration.eventType.getSimpleName(), - registration.plugin.getDescription().getId(), t); + registration.plugin.description().id(), t); } public boolean shutdown() throws InterruptedException { diff --git a/proxy/src/main/java/com/velocitypowered/proxy/network/BackendChannelInitializer.java b/proxy/src/main/java/com/velocitypowered/proxy/network/BackendChannelInitializer.java index c64274087..c3f711535 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/network/BackendChannelInitializer.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/network/BackendChannelInitializer.java @@ -50,7 +50,7 @@ public class BackendChannelInitializer extends ChannelInitializer { ch.pipeline() .addLast(FRAME_DECODER, new MinecraftVarintFrameDecoder()) .addLast(READ_TIMEOUT, - new ReadTimeoutHandler(server.getConfiguration().getReadTimeout(), + new ReadTimeoutHandler(server.configuration().getReadTimeout(), TimeUnit.MILLISECONDS)) .addLast(FRAME_ENCODER, MinecraftVarintLengthEncoder.INSTANCE) .addLast(MINECRAFT_DECODER, diff --git a/proxy/src/main/java/com/velocitypowered/proxy/network/ConnectionManager.java b/proxy/src/main/java/com/velocitypowered/proxy/network/ConnectionManager.java index 62fa5e84e..2b7bcddf6 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/network/ConnectionManager.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/network/ConnectionManager.java @@ -87,7 +87,7 @@ public final class ConnectionManager { this.resolver = new SeparatePoolInetNameResolver(GlobalEventExecutor.INSTANCE); this.httpClient = asyncHttpClient(config() .setEventLoopGroup(this.workerGroup) - .setUserAgent(server.getVersion().getName() + "/" + server.getVersion().getVersion()) + .setUserAgent(server.version().getName() + "/" + server.version().getVersion()) .addRequestFilter(new RequestFilter() { @Override public FilterContext filter(FilterContext ctx) { @@ -122,7 +122,7 @@ public final class ConnectionManager { if (address instanceof InetSocketAddress) { bootstrap.childOption(ChannelOption.TCP_NODELAY, true) .childOption(ChannelOption.IP_TOS, 0x18); - if (transportType == TransportType.EPOLL && server.getConfiguration().useTcpFastOpen()) { + if (transportType == TransportType.EPOLL && server.configuration().useTcpFastOpen()) { bootstrap.option(EpollChannelOption.TCP_FASTOPEN, 3); } } @@ -135,7 +135,7 @@ public final class ConnectionManager { LOGGER.info("Listening on {}", channel.localAddress()); // Fire the proxy bound event after the socket is bound - server.getEventManager().fireAndForget( + server.eventManager().fireAndForget( new ListenerBoundEventImpl(address, ListenerType.MINECRAFT)); } else { LOGGER.error("Can't bind to {}", address, future.cause()); @@ -164,7 +164,7 @@ public final class ConnectionManager { LOGGER.info("Listening for GS4 query on {}", channel.localAddress()); // Fire the proxy bound event after the socket is bound - server.getEventManager().fireAndForget( + server.eventManager().fireAndForget( new ListenerBoundEventImpl(address, ListenerType.QUERY)); } else { LOGGER.error("Can't bind to {}", bootstrap.config().localAddress(), future.cause()); @@ -184,10 +184,10 @@ public final class ConnectionManager { .channelFactory(this.transportType.getClientChannelFactory(target)) .option(ChannelOption.TCP_NODELAY, true) .option(ChannelOption.CONNECT_TIMEOUT_MILLIS, - this.server.getConfiguration().getConnectTimeout()) + this.server.configuration().getConnectTimeout()) .group(group == null ? this.workerGroup : group) .resolver(this.resolver.asGroup()); - if (transportType == TransportType.EPOLL && server.getConfiguration().useTcpFastOpen()) { + if (transportType == TransportType.EPOLL && server.configuration().useTcpFastOpen()) { bootstrap.option(EpollChannelOption.TCP_FASTOPEN_CONNECT, true); } return bootstrap; @@ -203,7 +203,7 @@ public final class ConnectionManager { // Fire proxy close event to notify plugins of socket close. We block since plugins // should have a chance to be notified before the server stops accepting connections. - server.getEventManager().fire(new ListenerClosedEventImpl(oldBind, endpoint.getType())).join(); + server.eventManager().fire(new ListenerClosedEventImpl(oldBind, endpoint.getType())).join(); Channel serverChannel = endpoint.getChannel(); @@ -222,7 +222,7 @@ public final class ConnectionManager { // Fire proxy close event to notify plugins of socket close. We block since plugins // should have a chance to be notified before the server stops accepting connections. - server.getEventManager().fire(new ListenerClosedEventImpl(address, endpoint.getType())).join(); + server.eventManager().fire(new ListenerClosedEventImpl(address, endpoint.getType())).join(); try { LOGGER.info("Closing endpoint {}", address); diff --git a/proxy/src/main/java/com/velocitypowered/proxy/network/ServerChannelInitializer.java b/proxy/src/main/java/com/velocitypowered/proxy/network/ServerChannelInitializer.java index 9282240a4..fd795223e 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/network/ServerChannelInitializer.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/network/ServerChannelInitializer.java @@ -56,7 +56,7 @@ public class ServerChannelInitializer extends ChannelInitializer { .addLast(LEGACY_PING_DECODER, new LegacyPingDecoder()) .addLast(FRAME_DECODER, new MinecraftVarintFrameDecoder()) .addLast(READ_TIMEOUT, - new ReadTimeoutHandler(this.server.getConfiguration().getReadTimeout(), + new ReadTimeoutHandler(this.server.configuration().getReadTimeout(), TimeUnit.MILLISECONDS)) .addLast(LEGACY_PING_ENCODER, LegacyPingEncoder.INSTANCE) .addLast(FRAME_ENCODER, MinecraftVarintLengthEncoder.INSTANCE) @@ -67,7 +67,7 @@ public class ServerChannelInitializer extends ChannelInitializer { connection.setSessionHandler(new HandshakeSessionHandler(connection, this.server)); ch.pipeline().addLast(HandlerNames.HANDLER, connection); - if (this.server.getConfiguration().isProxyProtocol()) { + if (this.server.configuration().isProxyProtocol()) { ch.pipeline().addFirst(new HAProxyMessageDecoder()); } } diff --git a/proxy/src/main/java/com/velocitypowered/proxy/network/packet/clientbound/ClientboundPlayerListItemPacket.java b/proxy/src/main/java/com/velocitypowered/proxy/network/packet/clientbound/ClientboundPlayerListItemPacket.java index ddfbb56d9..49ce0c1c3 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/network/packet/clientbound/ClientboundPlayerListItemPacket.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/network/packet/clientbound/ClientboundPlayerListItemPacket.java @@ -205,12 +205,12 @@ public class ClientboundPlayerListItemPacket implements Packet { } public static Item from(TabListEntry entry) { - return new Item(entry.getProfile().getId()) - .setName(entry.getProfile().getName()) - .setProperties(entry.getProfile().getProperties()) - .setLatency(entry.getLatency()) - .setGameMode(entry.getGameMode()) - .setDisplayName(entry.getDisplayName().orElse(null)); + return new Item(entry.gameProfile().getId()) + .setName(entry.gameProfile().getName()) + .setProperties(entry.gameProfile().getProperties()) + .setLatency(entry.ping()) + .setGameMode(entry.gameMode()) + .setDisplayName(entry.displayName().orElse(null)); } public @Nullable UUID getUuid() { diff --git a/proxy/src/main/java/com/velocitypowered/proxy/network/packet/legacy/LegacyDisconnectPacket.java b/proxy/src/main/java/com/velocitypowered/proxy/network/packet/legacy/LegacyDisconnectPacket.java index 3c570a1b2..af3f1a47c 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/network/packet/legacy/LegacyDisconnectPacket.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/network/packet/legacy/LegacyDisconnectPacket.java @@ -45,7 +45,7 @@ public class LegacyDisconnectPacket implements LegacyPacket { */ public static LegacyDisconnectPacket fromServerPing(ServerPing response, LegacyMinecraftPingVersion version) { - Players players = response.getPlayers().orElse(FAKE_PLAYERS); + Players players = response.players().orElse(FAKE_PLAYERS); switch (version) { case MINECRAFT_1_3: @@ -54,20 +54,20 @@ public class LegacyDisconnectPacket implements LegacyPacket { // MOTD. return new LegacyDisconnectPacket(String.join(LEGACY_COLOR_CODE, cleanSectionSymbol(getFirstLine(PlainComponentSerializer.plain().serialize( - response.getDescription()))), - Integer.toString(players.getOnline()), - Integer.toString(players.getMax()))); + response.description()))), + Integer.toString(players.online()), + Integer.toString(players.maximum()))); case MINECRAFT_1_4: case MINECRAFT_1_6: // Minecraft 1.4-1.6 provide support for more fields, and additionally support color codes. return new LegacyDisconnectPacket(String.join("\0", LEGACY_COLOR_CODE + "1", - Integer.toString(response.getVersion().getProtocol()), - response.getVersion().getName(), + Integer.toString(response.version().protocol()), + response.version().name(), getFirstLine(LegacyComponentSerializer.legacySection().serialize(response - .getDescription())), - Integer.toString(players.getOnline()), - Integer.toString(players.getMax()) + .description())), + Integer.toString(players.online()), + Integer.toString(players.maximum()) )); default: throw new IllegalArgumentException("Unknown version " + version); diff --git a/proxy/src/main/java/com/velocitypowered/proxy/network/packet/serverbound/ServerboundHandshakePacket.java b/proxy/src/main/java/com/velocitypowered/proxy/network/packet/serverbound/ServerboundHandshakePacket.java index 8d355f4e0..3fc140266 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/network/packet/serverbound/ServerboundHandshakePacket.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/network/packet/serverbound/ServerboundHandshakePacket.java @@ -29,7 +29,7 @@ import io.netty.buffer.ByteBuf; public class ServerboundHandshakePacket implements Packet { public static final PacketReader DECODER = (buf, version) -> { int realProtocolVersion = ProtocolUtils.readVarInt(buf); - final ProtocolVersion protocolVersion = ProtocolVersion.getProtocolVersion(realProtocolVersion); + final ProtocolVersion protocolVersion = ProtocolVersion.byMinecraftProtocolVersion(realProtocolVersion); final String hostname = ProtocolUtils.readString(buf); final int port = buf.readUnsignedShort(); final int nextStatus = ProtocolUtils.readVarInt(buf); @@ -54,7 +54,7 @@ public class ServerboundHandshakePacket implements Packet { @Override public void encode(ByteBuf buf, ProtocolVersion ignored) { - ProtocolUtils.writeVarInt(buf, this.protocolVersion.getProtocol()); + ProtocolUtils.writeVarInt(buf, this.protocolVersion.protocol()); ProtocolUtils.writeString(buf, this.serverAddress); buf.writeShort(this.port); ProtocolUtils.writeVarInt(buf, this.nextStatus); diff --git a/proxy/src/main/java/com/velocitypowered/proxy/network/pipeline/GS4QueryHandler.java b/proxy/src/main/java/com/velocitypowered/proxy/network/pipeline/GS4QueryHandler.java index fc33e0b11..dfc21ac4d 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/network/pipeline/GS4QueryHandler.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/network/pipeline/GS4QueryHandler.java @@ -84,18 +84,18 @@ public class GS4QueryHandler extends SimpleChannelInboundHandler private QueryResponse createInitialResponse() { return QueryResponse.builder() - .hostname(PlainComponentSerializer.plain().serialize(server.getConfiguration().getMotd())) + .hostname(PlainComponentSerializer.plain().serialize(server.configuration().getMotd())) .gameVersion(ProtocolVersion.SUPPORTED_VERSION_STRING) - .map(server.getConfiguration().getQueryMap()) - .currentPlayers(server.getPlayerCount()) - .maxPlayers(server.getConfiguration().getShowMaxPlayers()) - .proxyPort(((InetSocketAddress) server.getConfiguration().getBind()).getPort()) - .proxyHost(((InetSocketAddress) server.getConfiguration().getBind()).getHostString()) - .players(server.getAllPlayers().stream().map(Player::getUsername) + .map(server.configuration().getQueryMap()) + .onlinePlayers(server.countConnectedPlayers()) + .maxPlayers(server.configuration().getShowMaxPlayers()) + .proxyPort(((InetSocketAddress) server.configuration().getBind()).getPort()) + .proxyHost(((InetSocketAddress) server.configuration().getBind()).getHostString()) + .players(server.connectedPlayers().stream().map(Player::username) .collect(Collectors.toList())) .proxyVersion("Velocity") .plugins( - server.getConfiguration().shouldQueryShowPlugins() ? getRealPluginInformation() + server.configuration().shouldQueryShowPlugins() ? getRealPluginInformation() : Collections.emptyList()) .build(); } @@ -150,7 +150,7 @@ public class GS4QueryHandler extends SimpleChannelInboundHandler boolean isBasic = !queryMessage.isReadable(); // Call event and write response - server.getEventManager() + server.eventManager() .fire(new ProxyQueryEventImpl(isBasic ? BASIC : FULL, senderAddress, response)) .whenCompleteAsync((event, exc) -> { // Packet header @@ -160,22 +160,22 @@ public class GS4QueryHandler extends SimpleChannelInboundHandler // Start writing the response ResponseWriter responseWriter = new ResponseWriter(queryResponse, isBasic); - responseWriter.write("hostname", event.getResponse().getHostname()); + responseWriter.write("hostname", event.response().hostname()); responseWriter.write("gametype", "SMP"); responseWriter.write("game_id", "MINECRAFT"); - responseWriter.write("version", event.getResponse().getGameVersion()); - responseWriter.writePlugins(event.getResponse().getProxyVersion(), - event.getResponse().getPlugins()); + responseWriter.write("version", event.response().gameVersion()); + responseWriter.writePlugins(event.response().proxyVersion(), + event.response().plugins()); - responseWriter.write("map", event.getResponse().getMap()); - responseWriter.write("numplayers", event.getResponse().getCurrentPlayers()); - responseWriter.write("maxplayers", event.getResponse().getMaxPlayers()); - responseWriter.write("hostport", event.getResponse().getProxyPort()); - responseWriter.write("hostip", event.getResponse().getProxyHost()); + responseWriter.write("map", event.response().mapName()); + responseWriter.write("numplayers", event.response().onlinePlayers()); + responseWriter.write("maxplayers", event.response().maxPlayers()); + responseWriter.write("hostport", event.response().proxyPort()); + responseWriter.write("hostip", event.response().proxyHost()); if (!responseWriter.isBasic) { - responseWriter.writePlayers(event.getResponse().getPlayers()); + responseWriter.writePlayers(event.response().players()); } // Send the response @@ -201,10 +201,10 @@ public class GS4QueryHandler extends SimpleChannelInboundHandler private List getRealPluginInformation() { List result = new ArrayList<>(); - for (PluginContainer plugin : server.getPluginManager().getPlugins()) { - PluginDescription description = plugin.getDescription(); - result.add(QueryResponse.PluginInformation.of(description.getName() - .orElse(description.getId()), description.getVersion().orElse(null))); + for (PluginContainer plugin : server.pluginManager().getPlugins()) { + PluginDescription description = plugin.description(); + result.add(QueryResponse.PluginInformation.of(description.name() + .orElse(description.id()), description.version().orElse(null))); } return result; } diff --git a/proxy/src/main/java/com/velocitypowered/proxy/plugin/VelocityPluginManager.java b/proxy/src/main/java/com/velocitypowered/proxy/plugin/VelocityPluginManager.java index cddee9d68..eb74e72a7 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/plugin/VelocityPluginManager.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/plugin/VelocityPluginManager.java @@ -43,7 +43,6 @@ import java.nio.file.Path; import java.util.ArrayList; import java.util.Collection; import java.util.Collections; -import java.util.HashMap; import java.util.HashSet; import java.util.IdentityHashMap; import java.util.LinkedHashMap; @@ -67,8 +66,8 @@ public class VelocityPluginManager implements PluginManager { } private void registerPlugin(PluginContainer plugin) { - plugins.put(plugin.getDescription().getId(), plugin); - Optional instance = plugin.getInstance(); + plugins.put(plugin.description().id(), plugin); + Optional instance = plugin.instance(); instance.ifPresent(o -> pluginInstances.put(o, plugin)); } @@ -110,9 +109,9 @@ public class VelocityPluginManager implements PluginManager { pluginLoad: for (PluginDescription candidate : sortedPlugins) { // Verify dependencies - for (PluginDependency dependency : candidate.getDependencies()) { + for (PluginDependency dependency : candidate.dependencies()) { if (!dependency.isOptional() && !loadedPluginsById.contains(dependency.getId())) { - logger.error("Can't load plugin {} due to missing dependency {}", candidate.getId(), + logger.error("Can't load plugin {} due to missing dependency {}", candidate.id(), dependency.getId()); continue pluginLoad; } @@ -122,9 +121,9 @@ public class VelocityPluginManager implements PluginManager { PluginDescription realPlugin = loader.loadPlugin(candidate); VelocityPluginContainer container = new VelocityPluginContainer(realPlugin); pluginContainers.put(container, loader.createModule(container)); - loadedPluginsById.add(realPlugin.getId()); + loadedPluginsById.add(realPlugin.id()); } catch (Exception e) { - logger.error("Can't create module for plugin {}", candidate.getId(), e); + logger.error("Can't create module for plugin {}", candidate.id(), e); } } @@ -133,12 +132,12 @@ public class VelocityPluginManager implements PluginManager { @Override protected void configure() { bind(ProxyServer.class).toInstance(server); - bind(PluginManager.class).toInstance(server.getPluginManager()); - bind(EventManager.class).toInstance(server.getEventManager()); - bind(CommandManager.class).toInstance(server.getCommandManager()); + bind(PluginManager.class).toInstance(server.pluginManager()); + bind(EventManager.class).toInstance(server.eventManager()); + bind(CommandManager.class).toInstance(server.commandManager()); for (PluginContainer container : pluginContainers.keySet()) { bind(PluginContainer.class) - .annotatedWith(Names.named(container.getDescription().getId())) + .annotatedWith(Names.named(container.description().id())) .toInstance(container); } } @@ -146,17 +145,17 @@ public class VelocityPluginManager implements PluginManager { for (Map.Entry plugin : pluginContainers.entrySet()) { PluginContainer container = plugin.getKey(); - PluginDescription description = container.getDescription(); + PluginDescription description = container.description(); try { loader.createPlugin(container, plugin.getValue(), commonModule); } catch (Exception e) { - logger.error("Can't create plugin {}", description.getId(), e); + logger.error("Can't create plugin {}", description.id(), e); continue; } - logger.info("Loaded plugin {} {} by {}", description.getId(), description.getVersion() - .orElse(""), Joiner.on(", ").join(description.getAuthors())); + logger.info("Loaded plugin {} {} by {}", description.id(), description.version() + .orElse(""), Joiner.on(", ").join(description.authors())); registerPlugin(container); } } @@ -194,7 +193,7 @@ public class VelocityPluginManager implements PluginManager { checkNotNull(path, "path"); Optional optContainer = fromInstance(plugin); checkArgument(optContainer.isPresent(), "plugin is not loaded"); - Optional optInstance = optContainer.get().getInstance(); + Optional optInstance = optContainer.get().instance(); checkArgument(optInstance.isPresent(), "plugin has no instance"); ClassLoader pluginClassloader = optInstance.get().getClass().getClassLoader(); diff --git a/proxy/src/main/java/com/velocitypowered/proxy/plugin/loader/VelocityPluginContainer.java b/proxy/src/main/java/com/velocitypowered/proxy/plugin/loader/VelocityPluginContainer.java index 6c07ac3fb..68c7bcd38 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/plugin/loader/VelocityPluginContainer.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/plugin/loader/VelocityPluginContainer.java @@ -31,12 +31,12 @@ public class VelocityPluginContainer implements PluginContainer { } @Override - public PluginDescription getDescription() { + public PluginDescription description() { return this.description; } @Override - public Optional getInstance() { + public Optional instance() { return Optional.ofNullable(instance); } diff --git a/proxy/src/main/java/com/velocitypowered/proxy/plugin/loader/VelocityPluginDescription.java b/proxy/src/main/java/com/velocitypowered/proxy/plugin/loader/VelocityPluginDescription.java index b799dbbf3..8ceb5fdba 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/plugin/loader/VelocityPluginDescription.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/plugin/loader/VelocityPluginDescription.java @@ -67,37 +67,37 @@ public class VelocityPluginDescription implements PluginDescription { } @Override - public String getId() { + public String id() { return id; } @Override - public Optional getName() { + public Optional name() { return Optional.ofNullable(name); } @Override - public Optional getVersion() { + public Optional version() { return Optional.ofNullable(version); } @Override - public Optional getDescription() { + public Optional description() { return Optional.ofNullable(description); } @Override - public Optional getUrl() { + public Optional url() { return Optional.ofNullable(url); } @Override - public List getAuthors() { + public List authors() { return authors; } @Override - public Collection getDependencies() { + public Collection dependencies() { return dependencies.values(); } @@ -107,7 +107,7 @@ public class VelocityPluginDescription implements PluginDescription { } @Override - public Optional getSource() { + public Optional file() { return Optional.ofNullable(source); } diff --git a/proxy/src/main/java/com/velocitypowered/proxy/plugin/loader/java/JavaPluginLoader.java b/proxy/src/main/java/com/velocitypowered/proxy/plugin/loader/java/JavaPluginLoader.java index a3043a93b..b451674b9 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/plugin/loader/java/JavaPluginLoader.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/plugin/loader/java/JavaPluginLoader.java @@ -78,7 +78,7 @@ public class JavaPluginLoader implements PluginLoader { throw new IllegalArgumentException("Description provided isn't of the Java plugin loader"); } - URL pluginJarUrl = source.getSource().get().toUri().toURL(); + URL pluginJarUrl = source.file().get().toUri().toURL(); PluginClassLoader loader = AccessController.doPrivileged( (PrivilegedAction) () -> new PluginClassLoader(new URL[]{pluginJarUrl})); loader.addToClassloaders(); @@ -91,13 +91,13 @@ public class JavaPluginLoader implements PluginLoader { @Override public Module createModule(PluginContainer container) throws Exception { - PluginDescription description = container.getDescription(); + PluginDescription description = container.description(); if (!(description instanceof JavaVelocityPluginDescription)) { throw new IllegalArgumentException("Description provided isn't of the Java plugin loader"); } JavaVelocityPluginDescription javaDescription = (JavaVelocityPluginDescription) description; - Optional source = javaDescription.getSource(); + Optional source = javaDescription.file(); if (!source.isPresent()) { throw new IllegalArgumentException("No path in plugin description"); @@ -111,7 +111,7 @@ public class JavaPluginLoader implements PluginLoader { if (!(container instanceof VelocityPluginContainer)) { throw new IllegalArgumentException("Container provided isn't of the Java plugin loader"); } - PluginDescription description = container.getDescription(); + PluginDescription description = container.description(); if (!(description instanceof JavaVelocityPluginDescription)) { throw new IllegalArgumentException("Description provided isn't of the Java plugin loader"); } @@ -122,7 +122,7 @@ public class JavaPluginLoader implements PluginLoader { if (instance == null) { throw new IllegalStateException( - "Got nothing from injector for plugin " + description.getId()); + "Got nothing from injector for plugin " + description.id()); } ((VelocityPluginContainer) container).setInstance(instance); @@ -183,14 +183,14 @@ public class JavaPluginLoader implements PluginLoader { JavaVelocityPluginDescriptionCandidate description, Class mainClass) { return new JavaVelocityPluginDescription( - description.getId(), - description.getName().orElse(null), - description.getVersion().orElse(null), - description.getDescription().orElse(null), - description.getUrl().orElse(null), - description.getAuthors(), - description.getDependencies(), - description.getSource().orElse(null), + description.id(), + description.name().orElse(null), + description.version().orElse(null), + description.description().orElse(null), + description.url().orElse(null), + description.authors(), + description.dependencies(), + description.file().orElse(null), mainClass ); } diff --git a/proxy/src/main/java/com/velocitypowered/proxy/plugin/loader/java/VelocityPluginModule.java b/proxy/src/main/java/com/velocitypowered/proxy/plugin/loader/java/VelocityPluginModule.java index 2e8bd6ebc..587bd523d 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/plugin/loader/java/VelocityPluginModule.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/plugin/loader/java/VelocityPluginModule.java @@ -47,9 +47,9 @@ class VelocityPluginModule implements Module { public void configure(Binder binder) { binder.bind(description.getMainClass()).in(Scopes.SINGLETON); - binder.bind(Logger.class).toInstance(LoggerFactory.getLogger(description.getId())); + binder.bind(Logger.class).toInstance(LoggerFactory.getLogger(description.id())); binder.bind(Path.class).annotatedWith(DataDirectory.class) - .toInstance(basePluginPath.resolve(description.getId())); + .toInstance(basePluginPath.resolve(description.id())); binder.bind(PluginDescription.class).toInstance(description); binder.bind(PluginContainer.class).toInstance(pluginContainer); } diff --git a/proxy/src/main/java/com/velocitypowered/proxy/plugin/util/PluginDependencyUtils.java b/proxy/src/main/java/com/velocitypowered/proxy/plugin/util/PluginDependencyUtils.java index a4c45b155..faf4a52f1 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/plugin/util/PluginDependencyUtils.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/plugin/util/PluginDependencyUtils.java @@ -47,7 +47,7 @@ public class PluginDependencyUtils { */ public static List sortCandidates(List candidates) { List sortedCandidates = new ArrayList<>(candidates); - sortedCandidates.sort(Comparator.comparing(PluginDescription::getId)); + sortedCandidates.sort(Comparator.comparing(PluginDescription::id)); // Create a graph and populate it with plugin dependencies. Specifically, each graph has plugin // nodes, and edges that represent the dependencies that plugin relies on. Non-existent plugins @@ -57,12 +57,12 @@ public class PluginDependencyUtils { .expectedNodeCount(sortedCandidates.size()) .build(); Map candidateMap = Maps.uniqueIndex(sortedCandidates, - PluginDescription::getId); + PluginDescription::id); for (PluginDescription description : sortedCandidates) { graph.addNode(description); - for (PluginDependency dependency : description.getDependencies()) { + for (PluginDependency dependency : description.dependencies()) { PluginDescription in = candidateMap.get(dependency.getId()); if (in != null) { @@ -93,7 +93,7 @@ public class PluginDependencyUtils { currentIteration.addLast(node); StringBuilder loopGraph = new StringBuilder(); for (PluginDescription description : currentIteration) { - loopGraph.append(description.getId()); + loopGraph.append(description.id()); loopGraph.append(" -> "); } loopGraph.setLength(loopGraph.length() - 4); diff --git a/proxy/src/main/java/com/velocitypowered/proxy/scheduler/VelocityScheduler.java b/proxy/src/main/java/com/velocitypowered/proxy/scheduler/VelocityScheduler.java index 8f33b355f..ec8f3776e 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/scheduler/VelocityScheduler.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/scheduler/VelocityScheduler.java @@ -24,7 +24,6 @@ import com.google.common.collect.ImmutableList; import com.google.common.collect.Multimap; import com.google.common.collect.Multimaps; import com.google.common.util.concurrent.ThreadFactoryBuilder; -import com.velocitypowered.api.plugin.PluginContainer; import com.velocitypowered.api.plugin.PluginManager; import com.velocitypowered.api.scheduler.ScheduledTask; import com.velocitypowered.api.scheduler.Scheduler; @@ -207,8 +206,8 @@ public class VelocityScheduler implements Scheduler { Thread.currentThread().interrupt(); } else { String friendlyPluginName = pluginManager.fromInstance(plugin) - .map(container -> container.getDescription().getName() - .orElse(container.getDescription().getId())) + .map(container -> container.description().name() + .orElse(container.description().id())) .orElse("UNKNOWN"); Log.logger.error("Exception in task {} by plugin {}", runnable, friendlyPluginName, e); diff --git a/proxy/src/main/java/com/velocitypowered/proxy/server/PingSessionHandler.java b/proxy/src/main/java/com/velocitypowered/proxy/server/PingSessionHandler.java index 5f303cb14..c290fc587 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/server/PingSessionHandler.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/server/PingSessionHandler.java @@ -53,7 +53,7 @@ public class PingSessionHandler implements MinecraftSessionHandler { ServerboundHandshakePacket handshake = new ServerboundHandshakePacket(); handshake.setNextStatus(StateRegistry.STATUS_ID); - SocketAddress address = server.getServerInfo().getAddress(); + SocketAddress address = server.serverInfo().address(); if (address instanceof InetSocketAddress) { InetSocketAddress socketAddr = (InetSocketAddress) address; handshake.setServerAddress(socketAddr.getHostString()); diff --git a/proxy/src/main/java/com/velocitypowered/proxy/server/ServerMap.java b/proxy/src/main/java/com/velocitypowered/proxy/server/ServerMap.java index 41d337be0..2d982f6a1 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/server/ServerMap.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/server/ServerMap.java @@ -62,13 +62,13 @@ public class ServerMap { */ public RegisteredServer register(ServerInfo serverInfo) { Preconditions.checkNotNull(serverInfo, "serverInfo"); - String lowerName = serverInfo.getName().toLowerCase(Locale.US); + String lowerName = serverInfo.name().toLowerCase(Locale.US); VelocityRegisteredServer rs = new VelocityRegisteredServer(server, serverInfo); RegisteredServer existing = servers.putIfAbsent(lowerName, rs); - if (existing != null && !existing.getServerInfo().equals(serverInfo)) { + if (existing != null && !existing.serverInfo().equals(serverInfo)) { throw new IllegalArgumentException( - "Server with name " + serverInfo.getName() + " already registered"); + "Server with name " + serverInfo.name() + " already registered"); } else if (existing == null) { return rs; } else { @@ -83,15 +83,15 @@ public class ServerMap { */ public void unregister(ServerInfo serverInfo) { Preconditions.checkNotNull(serverInfo, "serverInfo"); - String lowerName = serverInfo.getName().toLowerCase(Locale.US); + String lowerName = serverInfo.name().toLowerCase(Locale.US); RegisteredServer rs = servers.get(lowerName); if (rs == null) { throw new IllegalArgumentException( - "Server with name " + serverInfo.getName() + " is not registered!"); + "Server with name " + serverInfo.name() + " is not registered!"); } - Preconditions.checkArgument(rs.getServerInfo().equals(serverInfo), - "Trying to remove server %s with differing information", serverInfo.getName()); + Preconditions.checkArgument(rs.serverInfo().equals(serverInfo), + "Trying to remove server %s with differing information", serverInfo.name()); Preconditions.checkState(servers.remove(lowerName, rs), - "Server with name %s replaced whilst unregistering", serverInfo.getName()); + "Server with name %s replaced whilst unregistering", serverInfo.name()); } } diff --git a/proxy/src/main/java/com/velocitypowered/proxy/server/VelocityRegisteredServer.java b/proxy/src/main/java/com/velocitypowered/proxy/server/VelocityRegisteredServer.java index 611a12fcb..0b98d7078 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/server/VelocityRegisteredServer.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/server/VelocityRegisteredServer.java @@ -71,12 +71,12 @@ public class VelocityRegisteredServer implements RegisteredServer, ForwardingAud } @Override - public ServerInfo getServerInfo() { + public ServerInfo serverInfo() { return serverInfo; } @Override - public Collection getPlayersConnected() { + public Collection connectedPlayers() { return ImmutableList.copyOf(players.values()); } @@ -97,14 +97,14 @@ public class VelocityRegisteredServer implements RegisteredServer, ForwardingAud throw new IllegalStateException("No Velocity proxy instance available"); } CompletableFuture pingFuture = new CompletableFuture<>(); - server.createBootstrap(loop, serverInfo.getAddress()) + server.createBootstrap(loop, serverInfo.address()) .handler(new ChannelInitializer() { @Override protected void initChannel(Channel ch) throws Exception { ch.pipeline() .addLast(FRAME_DECODER, new MinecraftVarintFrameDecoder()) .addLast(READ_TIMEOUT, - new ReadTimeoutHandler(server.getConfiguration().getReadTimeout(), + new ReadTimeoutHandler(server.configuration().getReadTimeout(), TimeUnit.MILLISECONDS)) .addLast(FRAME_ENCODER, MinecraftVarintLengthEncoder.INSTANCE) .addLast(MINECRAFT_DECODER, @@ -115,7 +115,7 @@ public class VelocityRegisteredServer implements RegisteredServer, ForwardingAud ch.pipeline().addLast(HANDLER, new MinecraftConnection(ch, server)); } }) - .connect(serverInfo.getAddress()) + .connect(serverInfo.address()) .addListener((ChannelFutureListener) future -> { if (future.isSuccess()) { MinecraftConnection conn = future.channel().pipeline().get(MinecraftConnection.class); @@ -129,11 +129,11 @@ public class VelocityRegisteredServer implements RegisteredServer, ForwardingAud } public void addPlayer(ConnectedPlayer player) { - players.put(player.getUniqueId(), player); + players.put(player.id(), player); } public void removePlayer(ConnectedPlayer player) { - players.remove(player.getUniqueId(), player); + players.remove(player.id(), player); } @Override @@ -152,7 +152,7 @@ public class VelocityRegisteredServer implements RegisteredServer, ForwardingAud public boolean sendPluginMessage(ChannelIdentifier identifier, ByteBuf data) { for (ConnectedPlayer player : players.values()) { VelocityServerConnection connection = player.getConnectedServer(); - if (connection != null && connection.getServer() == this) { + if (connection != null && connection.target() == this) { return connection.sendPluginMessage(identifier, data); } } @@ -168,6 +168,6 @@ public class VelocityRegisteredServer implements RegisteredServer, ForwardingAud @Override public @NonNull Iterable audiences() { - return this.getPlayersConnected(); + return this.connectedPlayers(); } } diff --git a/proxy/src/main/java/com/velocitypowered/proxy/tablist/VelocityTabList.java b/proxy/src/main/java/com/velocitypowered/proxy/tablist/VelocityTabList.java index e583139c1..da074f1ce 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/tablist/VelocityTabList.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/tablist/VelocityTabList.java @@ -69,16 +69,16 @@ public class VelocityTabList implements TabList { @Override public void addEntry(TabListEntry entry) { Preconditions.checkNotNull(entry, "entry"); - Preconditions.checkArgument(entry.getTabList().equals(this), + Preconditions.checkArgument(entry.parent().equals(this), "The provided entry was not created by this tab list"); - Preconditions.checkArgument(!entries.containsKey(entry.getProfile().getId()), + Preconditions.checkArgument(!entries.containsKey(entry.gameProfile().getId()), "this TabList already contains an entry with the same uuid"); Preconditions.checkArgument(entry instanceof VelocityTabListEntry, "Not a Velocity tab list entry"); connection.write(new ClientboundPlayerListItemPacket(ClientboundPlayerListItemPacket.ADD_PLAYER, Collections.singletonList(ClientboundPlayerListItemPacket.Item.from(entry)))); - entries.put(entry.getProfile().getId(), (VelocityTabListEntry) entry); + entries.put(entry.gameProfile().getId(), (VelocityTabListEntry) entry); } @Override @@ -122,7 +122,7 @@ public class VelocityTabList implements TabList { } @Override - public Collection getEntries() { + public Collection entries() { return Collections.unmodifiableCollection(this.entries.values()); } @@ -198,7 +198,7 @@ public class VelocityTabList implements TabList { } void updateEntry(int action, TabListEntry entry) { - if (entries.containsKey(entry.getProfile().getId())) { + if (entries.containsKey(entry.gameProfile().getId())) { connection.write(new ClientboundPlayerListItemPacket(action, Collections.singletonList(ClientboundPlayerListItemPacket.Item.from(entry)))); } diff --git a/proxy/src/main/java/com/velocitypowered/proxy/tablist/VelocityTabListEntry.java b/proxy/src/main/java/com/velocitypowered/proxy/tablist/VelocityTabListEntry.java index 0eb3fc477..1ba3113c3 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/tablist/VelocityTabListEntry.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/tablist/VelocityTabListEntry.java @@ -43,17 +43,17 @@ public class VelocityTabListEntry implements TabListEntry { } @Override - public TabList getTabList() { + public TabList parent() { return tabList; } @Override - public GameProfile getProfile() { + public GameProfile gameProfile() { return profile; } @Override - public Optional getDisplayName() { + public Optional displayName() { return Optional.ofNullable(displayName); } @@ -69,12 +69,12 @@ public class VelocityTabListEntry implements TabListEntry { } @Override - public int getLatency() { + public int ping() { return latency; } @Override - public TabListEntry setLatency(int latency) { + public TabListEntry setPing(int latency) { this.latency = latency; tabList.updateEntry(ClientboundPlayerListItemPacket.UPDATE_LATENCY, this); return this; @@ -85,7 +85,7 @@ public class VelocityTabListEntry implements TabListEntry { } @Override - public int getGameMode() { + public int gameMode() { return gameMode; } diff --git a/proxy/src/main/java/com/velocitypowered/proxy/tablist/VelocityTabListEntryLegacy.java b/proxy/src/main/java/com/velocitypowered/proxy/tablist/VelocityTabListEntryLegacy.java index 8aa00c9f7..8e9261213 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/tablist/VelocityTabListEntryLegacy.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/tablist/VelocityTabListEntryLegacy.java @@ -31,7 +31,7 @@ public class VelocityTabListEntryLegacy extends VelocityTabListEntry { @Override public TabListEntry setDisplayName(@Nullable Component displayName) { - getTabList().removeEntry(getProfile().getId()); // We have to remove first if updating + parent().removeEntry(gameProfile().getId()); // We have to remove first if updating return super.setDisplayName(displayName); } } diff --git a/proxy/src/main/java/com/velocitypowered/proxy/tablist/VelocityTabListLegacy.java b/proxy/src/main/java/com/velocitypowered/proxy/tablist/VelocityTabListLegacy.java index 154bd8f99..3d207e950 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/tablist/VelocityTabListLegacy.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/tablist/VelocityTabListLegacy.java @@ -50,13 +50,13 @@ public class VelocityTabListLegacy extends VelocityTabList { @Override public void addEntry(TabListEntry entry) { super.addEntry(entry); - nameMapping.put(entry.getProfile().getName(), entry.getProfile().getId()); + nameMapping.put(entry.gameProfile().getName(), entry.gameProfile().getId()); } @Override public Optional removeEntry(UUID uuid) { Optional entry = super.removeEntry(uuid); - entry.map(TabListEntry::getProfile).map(GameProfile::getName).ifPresent(nameMapping::remove); + entry.map(TabListEntry::gameProfile).map(GameProfile::getName).ifPresent(nameMapping::remove); return entry; } @@ -108,7 +108,7 @@ public class VelocityTabListLegacy extends VelocityTabList { @Override void updateEntry(int action, TabListEntry entry) { - if (entries.containsKey(entry.getProfile().getId())) { + if (entries.containsKey(entry.gameProfile().getId())) { switch (action) { case ClientboundPlayerListItemPacket.UPDATE_LATENCY: case ClientboundPlayerListItemPacket.UPDATE_DISPLAY_NAME: // Add here because we diff --git a/proxy/src/main/java/com/velocitypowered/proxy/util/InformationUtils.java b/proxy/src/main/java/com/velocitypowered/proxy/util/InformationUtils.java index 5d5f03683..265158f32 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/util/InformationUtils.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/util/InformationUtils.java @@ -53,35 +53,35 @@ public enum InformationUtils { */ public static JsonArray collectPluginInfo(ProxyServer proxy) { List allPlugins = ImmutableList.copyOf( - proxy.getPluginManager().getPlugins()); + proxy.pluginManager().getPlugins()); JsonArray plugins = new JsonArray(); for (PluginContainer plugin : allPlugins) { - PluginDescription desc = plugin.getDescription(); + PluginDescription desc = plugin.description(); JsonObject current = new JsonObject(); - current.addProperty("id", desc.getId()); - if (desc.getName().isPresent()) { - current.addProperty("name", desc.getName().get()); + current.addProperty("id", desc.id()); + if (desc.name().isPresent()) { + current.addProperty("name", desc.name().get()); } - if (desc.getVersion().isPresent()) { - current.addProperty("version", desc.getVersion().get()); + if (desc.version().isPresent()) { + current.addProperty("version", desc.version().get()); } - if (!desc.getAuthors().isEmpty()) { + if (!desc.authors().isEmpty()) { JsonArray authorsArray = new JsonArray(); - for (String author : desc.getAuthors()) { + for (String author : desc.authors()) { authorsArray.add(author); } current.add("authors", authorsArray); } - if (desc.getDescription().isPresent()) { - current.addProperty("description", desc.getDescription().get()); + if (desc.description().isPresent()) { + current.addProperty("description", desc.description().get()); } - if (desc.getUrl().isPresent()) { - current.addProperty("url", desc.getUrl().get()); + if (desc.url().isPresent()) { + current.addProperty("url", desc.url().get()); } - if (!desc.getDependencies().isEmpty()) { + if (!desc.dependencies().isEmpty()) { JsonArray dependencies = new JsonArray(); - for (PluginDependency dependency : desc.getDependencies()) { + for (PluginDependency dependency : desc.dependencies()) { dependencies.add(dependency.getId()); } current.add("dependencies", dependencies); @@ -185,8 +185,8 @@ public enum InformationUtils { */ public static JsonObject collectServerInfo(RegisteredServer server) { JsonObject info = new JsonObject(); - info.addProperty("currentPlayers", server.getPlayersConnected().size()); - SocketAddress address = server.getServerInfo().getAddress(); + info.addProperty("currentPlayers", server.connectedPlayers().size()); + SocketAddress address = server.serverInfo().address(); if (address instanceof InetSocketAddress) { InetSocketAddress iaddr = (InetSocketAddress) address; if (iaddr.isUnresolved()) { diff --git a/proxy/src/main/java/com/velocitypowered/proxy/util/VelocityChannelRegistrar.java b/proxy/src/main/java/com/velocitypowered/proxy/util/VelocityChannelRegistrar.java index 5262d8450..58cbe97e1 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/util/VelocityChannelRegistrar.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/util/VelocityChannelRegistrar.java @@ -43,10 +43,10 @@ public class VelocityChannelRegistrar implements ChannelRegistrar { for (ChannelIdentifier identifier : identifiers) { if (identifier instanceof MinecraftChannelIdentifier) { - identifierMap.put(identifier.getId(), identifier); + identifierMap.put(identifier.id(), identifier); } else { - String rewritten = PluginMessageUtil.transformLegacyToModernChannel(identifier.getId()); - identifierMap.put(identifier.getId(), identifier); + String rewritten = PluginMessageUtil.transformLegacyToModernChannel(identifier.id()); + identifierMap.put(identifier.id(), identifier); identifierMap.put(rewritten, identifier); } } @@ -62,10 +62,10 @@ public class VelocityChannelRegistrar implements ChannelRegistrar { for (ChannelIdentifier identifier : identifiers) { if (identifier instanceof MinecraftChannelIdentifier) { - identifierMap.remove(identifier.getId()); + identifierMap.remove(identifier.id()); } else { - String rewritten = PluginMessageUtil.transformLegacyToModernChannel(identifier.getId()); - identifierMap.remove(identifier.getId()); + String rewritten = PluginMessageUtil.transformLegacyToModernChannel(identifier.id()); + identifierMap.remove(identifier.id()); identifierMap.remove(rewritten); } } @@ -79,7 +79,7 @@ public class VelocityChannelRegistrar implements ChannelRegistrar { public Collection getLegacyChannelIds() { Collection ids = new HashSet<>(); for (ChannelIdentifier value : identifierMap.values()) { - ids.add(value.getId()); + ids.add(value.id()); } return ids; } @@ -93,9 +93,9 @@ public class VelocityChannelRegistrar implements ChannelRegistrar { Collection ids = new HashSet<>(); for (ChannelIdentifier value : identifierMap.values()) { if (value instanceof MinecraftChannelIdentifier) { - ids.add(value.getId()); + ids.add(value.id()); } else { - ids.add(PluginMessageUtil.transformLegacyToModernChannel(value.getId())); + ids.add(PluginMessageUtil.transformLegacyToModernChannel(value.id())); } } return ids; diff --git a/proxy/src/main/java/com/velocitypowered/proxy/util/bossbar/AdventureBossBarManager.java b/proxy/src/main/java/com/velocitypowered/proxy/util/bossbar/AdventureBossBarManager.java index a9381709f..9408d4886 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/util/bossbar/AdventureBossBarManager.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/util/bossbar/AdventureBossBarManager.java @@ -101,7 +101,7 @@ public class AdventureBossBarManager implements BossBar.Listener { public void addBossBar(ConnectedPlayer player, BossBar bar) { BossBarHolder holder = this.getOrCreateHandler(bar); if (holder.subscribers.add(player)) { - player.getConnection().write(holder.createAddPacket(player.getProtocolVersion())); + player.getConnection().write(holder.createAddPacket(player.protocolVersion())); } } @@ -129,7 +129,7 @@ public class AdventureBossBarManager implements BossBar.Listener { ClientboundBossBarPacket rgbPacket = holder.createTitleUpdate( newName, ProtocolVersion.MINECRAFT_1_16); for (ConnectedPlayer player : holder.subscribers) { - if (player.getProtocolVersion().gte(ProtocolVersion.MINECRAFT_1_16)) { + if (player.protocolVersion().gte(ProtocolVersion.MINECRAFT_1_16)) { player.getConnection().write(rgbPacket); } else { player.getConnection().write(pre116Packet); diff --git a/proxy/src/test/java/com/velocitypowered/proxy/command/CommandManagerTests.java b/proxy/src/test/java/com/velocitypowered/proxy/command/CommandManagerTests.java index bdf300fd3..ee9021645 100644 --- a/proxy/src/test/java/com/velocitypowered/proxy/command/CommandManagerTests.java +++ b/proxy/src/test/java/com/velocitypowered/proxy/command/CommandManagerTests.java @@ -94,8 +94,8 @@ public class CommandManagerTests { .aliases("baZ") .build(); - assertEquals(ImmutableSet.of("bar", "baz"), meta.getAliases()); - assertTrue(meta.getHints().isEmpty()); + assertEquals(ImmutableSet.of("bar", "baz"), meta.aliases()); + assertTrue(meta.hints().isEmpty()); manager.register(meta, aliasesCommand); assertTrue(manager.hasCommand("bAr")); assertTrue(manager.hasCommand("Baz")); diff --git a/proxy/src/test/java/com/velocitypowered/proxy/command/MockCommandSource.java b/proxy/src/test/java/com/velocitypowered/proxy/command/MockCommandSource.java index d3c6c5d1d..6d056a995 100644 --- a/proxy/src/test/java/com/velocitypowered/proxy/command/MockCommandSource.java +++ b/proxy/src/test/java/com/velocitypowered/proxy/command/MockCommandSource.java @@ -25,7 +25,7 @@ public class MockCommandSource implements CommandSource { public static final CommandSource INSTANCE = new MockCommandSource(); @Override - public Tristate getPermissionValue(final String permission) { + public Tristate evaluatePermission(final String permission) { return Tristate.UNDEFINED; } } diff --git a/proxy/src/test/java/com/velocitypowered/proxy/testutil/FakePluginManager.java b/proxy/src/test/java/com/velocitypowered/proxy/testutil/FakePluginManager.java index 64a64f4c4..a2fed39ea 100644 --- a/proxy/src/test/java/com/velocitypowered/proxy/testutil/FakePluginManager.java +++ b/proxy/src/test/java/com/velocitypowered/proxy/testutil/FakePluginManager.java @@ -83,12 +83,12 @@ public class FakePluginManager implements PluginManager { } @Override - public @NonNull PluginDescription getDescription() { + public @NonNull PluginDescription description() { return () -> id; } @Override - public Optional getInstance() { + public Optional instance() { return Optional.of(instance); } } diff --git a/proxy/src/test/java/com/velocitypowered/proxy/util/VelocityChannelRegistrarTest.java b/proxy/src/test/java/com/velocitypowered/proxy/util/VelocityChannelRegistrarTest.java index 2e92217c6..d63c5b163 100644 --- a/proxy/src/test/java/com/velocitypowered/proxy/util/VelocityChannelRegistrarTest.java +++ b/proxy/src/test/java/com/velocitypowered/proxy/util/VelocityChannelRegistrarTest.java @@ -45,9 +45,9 @@ class VelocityChannelRegistrarTest { // Two channels cover the modern channel (velocity:test) and the legacy-mapped channel // (legacy:velocitytest). Make sure they're what we expect. - assertEquals(ImmutableSet.of(MODERN.getId(), SIMPLE_LEGACY_REMAPPED), registrar + assertEquals(ImmutableSet.of(MODERN.id(), SIMPLE_LEGACY_REMAPPED), registrar .getModernChannelIds()); - assertEquals(ImmutableSet.of(SIMPLE_LEGACY.getId(), MODERN.getId()), registrar + assertEquals(ImmutableSet.of(SIMPLE_LEGACY.id(), MODERN.id()), registrar .getLegacyChannelIds()); } @@ -57,8 +57,8 @@ class VelocityChannelRegistrarTest { registrar.register(SPECIAL_REMAP_LEGACY, MODERN_SPECIAL_REMAP); // This one, just one channel for the modern case. - assertEquals(ImmutableSet.of(MODERN_SPECIAL_REMAP.getId()), registrar.getModernChannelIds()); - assertEquals(ImmutableSet.of(MODERN_SPECIAL_REMAP.getId(), SPECIAL_REMAP_LEGACY.getId()), + assertEquals(ImmutableSet.of(MODERN_SPECIAL_REMAP.id()), registrar.getModernChannelIds()); + assertEquals(ImmutableSet.of(MODERN_SPECIAL_REMAP.id(), SPECIAL_REMAP_LEGACY.id()), registrar.getLegacyChannelIds()); } @@ -68,7 +68,7 @@ class VelocityChannelRegistrarTest { registrar.register(MODERN, SIMPLE_LEGACY); registrar.unregister(SIMPLE_LEGACY); - assertEquals(ImmutableSet.of(MODERN.getId()), registrar.getModernChannelIds()); - assertEquals(ImmutableSet.of(MODERN.getId()), registrar.getLegacyChannelIds()); + assertEquals(ImmutableSet.of(MODERN.id()), registrar.getModernChannelIds()); + assertEquals(ImmutableSet.of(MODERN.id()), registrar.getLegacyChannelIds()); } } \ No newline at end of file From 0ed83520129837168afdcfdd77767c55f0f67a1c Mon Sep 17 00:00:00 2001 From: Andrew Steinborn Date: Sat, 17 Apr 2021 05:00:16 -0400 Subject: [PATCH 31/99] Do it to the message event too --- .../api/event/connection/PluginMessageEvent.java | 12 ++++++------ .../api/event/connection/PluginMessageEventImpl.java | 12 ++++++------ 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/api/src/main/java/com/velocitypowered/api/event/connection/PluginMessageEvent.java b/api/src/main/java/com/velocitypowered/api/event/connection/PluginMessageEvent.java index 51ee66fb0..79a8d952f 100644 --- a/api/src/main/java/com/velocitypowered/api/event/connection/PluginMessageEvent.java +++ b/api/src/main/java/com/velocitypowered/api/event/connection/PluginMessageEvent.java @@ -22,17 +22,17 @@ import java.io.ByteArrayInputStream; */ public interface PluginMessageEvent extends ResultedEvent { - ChannelMessageSource getSource(); + ChannelMessageSource source(); - ChannelMessageSink getTarget(); + ChannelMessageSink sink(); - ChannelIdentifier getIdentifier(); + ChannelIdentifier channel(); - byte[] getData(); + byte[] rawMessage(); - ByteArrayInputStream dataAsInputStream(); + ByteArrayInputStream messageAsInputStream(); - ByteArrayDataInput dataAsDataStream(); + ByteArrayDataInput messageAsDataInput(); /** * A result determining whether or not to forward this message on. diff --git a/api/src/main/java/com/velocitypowered/api/event/connection/PluginMessageEventImpl.java b/api/src/main/java/com/velocitypowered/api/event/connection/PluginMessageEventImpl.java index d8f8e7460..e8d173a8e 100644 --- a/api/src/main/java/com/velocitypowered/api/event/connection/PluginMessageEventImpl.java +++ b/api/src/main/java/com/velocitypowered/api/event/connection/PluginMessageEventImpl.java @@ -58,32 +58,32 @@ public final class PluginMessageEventImpl implements PluginMessageEvent { } @Override - public ChannelMessageSource getSource() { + public ChannelMessageSource source() { return source; } @Override - public ChannelMessageSink getTarget() { + public ChannelMessageSink sink() { return target; } @Override - public ChannelIdentifier getIdentifier() { + public ChannelIdentifier channel() { return identifier; } @Override - public byte[] getData() { + public byte[] rawMessage() { return Arrays.copyOf(data, data.length); } @Override - public ByteArrayInputStream dataAsInputStream() { + public ByteArrayInputStream messageAsInputStream() { return new ByteArrayInputStream(data); } @Override - public ByteArrayDataInput dataAsDataStream() { + public ByteArrayDataInput messageAsDataInput() { return ByteStreams.newDataInput(data); } From 9645fb59dad426565009bd51aa7853234228e39e Mon Sep 17 00:00:00 2001 From: Andrew Steinborn Date: Sat, 17 Apr 2021 06:04:12 -0400 Subject: [PATCH 32/99] Further improvements. The main component here is the total revamp of the plugin channel identifier system - instead of Legacy/Modern channel IDs, you can have a modern channel or a modern channel paired with a legacy channel, which is much less confusing to work with. --- .../event/connection/PluginMessageEvent.java | 4 +- .../connection/PluginMessageEventImpl.java | 8 +- .../player/PlayerChannelRegisterEvent.java | 4 +- .../PlayerChannelRegisterEventImpl.java | 8 +- .../api/plugin/PluginManager.java | 2 +- .../api/proxy/messages/ChannelIdentifier.java | 21 ---- .../proxy/messages/ChannelMessageSink.java | 2 +- .../api/proxy/messages/ChannelRegistrar.java | 6 +- .../messages/LegacyChannelIdentifier.java | 64 ---------- .../messages/MinecraftChannelIdentifier.java | 114 ------------------ .../messages/MinecraftPluginChannelId.java | 55 +++++++++ .../proxy/messages/PairedPluginChannelId.java | 72 +++++++++++ .../api/proxy/messages/PluginChannelId.java | 41 +++++++ .../MinecraftChannelIdentifierTest.java | 63 ---------- .../velocitypowered/proxy/VelocityServer.java | 4 +- .../command/builtin/VelocityCommand.java | 2 +- .../backend/BackendPlaySessionHandler.java | 4 +- .../backend/BungeeCordMessageResponder.java | 23 ++-- .../backend/VelocityServerConnection.java | 10 +- .../client/ClientPlaySessionHandler.java | 26 ++-- .../connection/client/ConnectedPlayer.java | 8 +- .../proxy/network/PluginMessageUtil.java | 16 +++ .../packet/AbstractPluginMessagePacket.java | 3 - .../network/pipeline/GS4QueryHandler.java | 2 +- .../proxy/plugin/VelocityPluginManager.java | 2 +- .../server/VelocityRegisteredServer.java | 6 +- .../proxy/util/InformationUtils.java | 5 +- .../proxy/util/VelocityChannelRegistrar.java | 78 ++++++------ .../util/bossbar/AdventureBossBarManager.java | 8 +- .../proxy/plugin/MockPluginManager.java | 2 +- .../proxy/testutil/FakePluginManager.java | 2 +- .../util/VelocityChannelRegistrarTest.java | 46 +++---- 32 files changed, 307 insertions(+), 404 deletions(-) delete mode 100644 api/src/main/java/com/velocitypowered/api/proxy/messages/ChannelIdentifier.java delete mode 100644 api/src/main/java/com/velocitypowered/api/proxy/messages/LegacyChannelIdentifier.java delete mode 100644 api/src/main/java/com/velocitypowered/api/proxy/messages/MinecraftChannelIdentifier.java create mode 100644 api/src/main/java/com/velocitypowered/api/proxy/messages/MinecraftPluginChannelId.java create mode 100644 api/src/main/java/com/velocitypowered/api/proxy/messages/PairedPluginChannelId.java create mode 100644 api/src/main/java/com/velocitypowered/api/proxy/messages/PluginChannelId.java delete mode 100644 api/src/test/java/com/velocitypowered/api/proxy/messages/MinecraftChannelIdentifierTest.java diff --git a/api/src/main/java/com/velocitypowered/api/event/connection/PluginMessageEvent.java b/api/src/main/java/com/velocitypowered/api/event/connection/PluginMessageEvent.java index 79a8d952f..74b8155f0 100644 --- a/api/src/main/java/com/velocitypowered/api/event/connection/PluginMessageEvent.java +++ b/api/src/main/java/com/velocitypowered/api/event/connection/PluginMessageEvent.java @@ -11,9 +11,9 @@ import com.google.common.io.ByteArrayDataInput; import com.velocitypowered.api.event.ResultedEvent; import com.velocitypowered.api.proxy.connection.Player; import com.velocitypowered.api.proxy.connection.ServerConnection; -import com.velocitypowered.api.proxy.messages.ChannelIdentifier; import com.velocitypowered.api.proxy.messages.ChannelMessageSink; import com.velocitypowered.api.proxy.messages.ChannelMessageSource; +import com.velocitypowered.api.proxy.messages.PluginChannelId; import java.io.ByteArrayInputStream; /** @@ -26,7 +26,7 @@ public interface PluginMessageEvent extends ResultedEvent channels(); + List channels(); } diff --git a/api/src/main/java/com/velocitypowered/api/event/player/PlayerChannelRegisterEventImpl.java b/api/src/main/java/com/velocitypowered/api/event/player/PlayerChannelRegisterEventImpl.java index 6a7bae4fe..8f30d69ba 100644 --- a/api/src/main/java/com/velocitypowered/api/event/player/PlayerChannelRegisterEventImpl.java +++ b/api/src/main/java/com/velocitypowered/api/event/player/PlayerChannelRegisterEventImpl.java @@ -9,7 +9,7 @@ package com.velocitypowered.api.event.player; import com.google.common.base.Preconditions; import com.velocitypowered.api.proxy.connection.Player; -import com.velocitypowered.api.proxy.messages.ChannelIdentifier; +import com.velocitypowered.api.proxy.messages.PluginChannelId; import java.util.List; /** @@ -19,9 +19,9 @@ import java.util.List; public final class PlayerChannelRegisterEventImpl implements PlayerChannelRegisterEvent { private final Player player; - private final List channels; + private final List channels; - public PlayerChannelRegisterEventImpl(Player player, List channels) { + public PlayerChannelRegisterEventImpl(Player player, List channels) { this.player = Preconditions.checkNotNull(player, "player"); this.channels = Preconditions.checkNotNull(channels, "channels"); } @@ -32,7 +32,7 @@ public final class PlayerChannelRegisterEventImpl implements PlayerChannelRegist } @Override - public List channels() { + public List channels() { return channels; } diff --git a/api/src/main/java/com/velocitypowered/api/plugin/PluginManager.java b/api/src/main/java/com/velocitypowered/api/plugin/PluginManager.java index 7af16566d..4688f9bf1 100644 --- a/api/src/main/java/com/velocitypowered/api/plugin/PluginManager.java +++ b/api/src/main/java/com/velocitypowered/api/plugin/PluginManager.java @@ -39,7 +39,7 @@ public interface PluginManager { * * @return the plugins */ - Collection getPlugins(); + Collection plugins(); /** * Checks if a plugin is loaded based on its ID. diff --git a/api/src/main/java/com/velocitypowered/api/proxy/messages/ChannelIdentifier.java b/api/src/main/java/com/velocitypowered/api/proxy/messages/ChannelIdentifier.java deleted file mode 100644 index 1fd1bf025..000000000 --- a/api/src/main/java/com/velocitypowered/api/proxy/messages/ChannelIdentifier.java +++ /dev/null @@ -1,21 +0,0 @@ -/* - * Copyright (C) 2018 Velocity Contributors - * - * The Velocity API is licensed under the terms of the MIT License. For more details, - * reference the LICENSE file in the api top-level directory. - */ - -package com.velocitypowered.api.proxy.messages; - -/** - * Represents a channel identifier for use with plugin messaging. - */ -public interface ChannelIdentifier { - - /** - * Returns the textual representation of this identifier. - * - * @return the textual representation of the identifier - */ - String id(); -} diff --git a/api/src/main/java/com/velocitypowered/api/proxy/messages/ChannelMessageSink.java b/api/src/main/java/com/velocitypowered/api/proxy/messages/ChannelMessageSink.java index 2f8264220..e84ccb7ec 100644 --- a/api/src/main/java/com/velocitypowered/api/proxy/messages/ChannelMessageSink.java +++ b/api/src/main/java/com/velocitypowered/api/proxy/messages/ChannelMessageSink.java @@ -19,5 +19,5 @@ public interface ChannelMessageSink { * @param data the data to send * @return whether or not the message could be sent */ - boolean sendPluginMessage(ChannelIdentifier identifier, byte[] data); + boolean sendPluginMessage(PluginChannelId identifier, byte[] data); } diff --git a/api/src/main/java/com/velocitypowered/api/proxy/messages/ChannelRegistrar.java b/api/src/main/java/com/velocitypowered/api/proxy/messages/ChannelRegistrar.java index 0b9768b00..b01037dd6 100644 --- a/api/src/main/java/com/velocitypowered/api/proxy/messages/ChannelRegistrar.java +++ b/api/src/main/java/com/velocitypowered/api/proxy/messages/ChannelRegistrar.java @@ -10,7 +10,7 @@ package com.velocitypowered.api.proxy.messages; import com.velocitypowered.api.event.connection.PluginMessageEventImpl; /** - * Represents an interface to register and unregister {@link ChannelIdentifier}s for the proxy to + * Represents an interface to register and unregister {@link PluginChannelId}s for the proxy to * listen on. */ public interface ChannelRegistrar { @@ -21,12 +21,12 @@ public interface ChannelRegistrar { * * @param identifiers the channel identifiers to register */ - void register(ChannelIdentifier... identifiers); + void register(PluginChannelId... identifiers); /** * Removes the intent to listen for the specified channel. * * @param identifiers the identifiers to unregister */ - void unregister(ChannelIdentifier... identifiers); + void unregister(PluginChannelId... identifiers); } diff --git a/api/src/main/java/com/velocitypowered/api/proxy/messages/LegacyChannelIdentifier.java b/api/src/main/java/com/velocitypowered/api/proxy/messages/LegacyChannelIdentifier.java deleted file mode 100644 index 6eacb6924..000000000 --- a/api/src/main/java/com/velocitypowered/api/proxy/messages/LegacyChannelIdentifier.java +++ /dev/null @@ -1,64 +0,0 @@ -/* - * Copyright (C) 2018 Velocity Contributors - * - * The Velocity API is licensed under the terms of the MIT License. For more details, - * reference the LICENSE file in the api top-level directory. - */ - -package com.velocitypowered.api.proxy.messages; - -import com.google.common.base.Preconditions; -import com.google.common.base.Strings; -import java.util.Objects; -import org.checkerframework.checker.nullness.qual.Nullable; - -/** - * Reperesents a legacy channel identifier (for Minecraft 1.12 and below). For modern 1.13 plugin - * messages, please see {@link MinecraftChannelIdentifier}. This class is immutable and safe for - * multi-threaded use. - */ -public final class LegacyChannelIdentifier implements ChannelIdentifier { - - private final String name; - - /** - * Creates a new legacy channel identifier. - * - * @param name the name for the channel - */ - public LegacyChannelIdentifier(String name) { - Preconditions.checkArgument(!Strings.isNullOrEmpty(name), "provided name is empty"); - this.name = name; - } - - public String getName() { - return name; - } - - @Override - public String toString() { - return name + " (legacy)"; - } - - @Override - public boolean equals(@Nullable Object o) { - if (this == o) { - return true; - } - if (o == null || getClass() != o.getClass()) { - return false; - } - LegacyChannelIdentifier that = (LegacyChannelIdentifier) o; - return Objects.equals(name, that.name); - } - - @Override - public int hashCode() { - return Objects.hash(name); - } - - @Override - public String id() { - return this.getName(); - } -} diff --git a/api/src/main/java/com/velocitypowered/api/proxy/messages/MinecraftChannelIdentifier.java b/api/src/main/java/com/velocitypowered/api/proxy/messages/MinecraftChannelIdentifier.java deleted file mode 100644 index f9314c3ef..000000000 --- a/api/src/main/java/com/velocitypowered/api/proxy/messages/MinecraftChannelIdentifier.java +++ /dev/null @@ -1,114 +0,0 @@ -/* - * Copyright (C) 2018 Velocity Contributors - * - * The Velocity API is licensed under the terms of the MIT License. For more details, - * reference the LICENSE file in the api top-level directory. - */ - -package com.velocitypowered.api.proxy.messages; - -import com.google.common.base.Preconditions; -import com.google.common.base.Strings; -import java.util.Objects; -import java.util.regex.Pattern; -import org.checkerframework.checker.nullness.qual.Nullable; - -/** - * Represents a Minecraft 1.13+ channel identifier. This class is immutable and safe for - * multi-threaded use. - */ -public final class MinecraftChannelIdentifier implements ChannelIdentifier { - - private static final Pattern VALID_IDENTIFIER_REGEX = Pattern.compile("[a-z0-9/\\-_]*"); - - private final String namespace; - private final String name; - - private MinecraftChannelIdentifier(String namespace, String name) { - this.namespace = namespace; - this.name = name; - } - - /** - * Creates an identifier in the default namespace ({@code minecraft}). Plugins are strongly - * encouraged to provide their own namespace. - * - * @param name the name in the default namespace to use - * @return a new channel identifier - */ - public static MinecraftChannelIdentifier forDefaultNamespace(String name) { - return new MinecraftChannelIdentifier("minecraft", name); - } - - /** - * Creates an identifier in the specified namespace. - * - * @param namespace the namespace to use - * @param name the channel name inside the specified namespace - * @return a new channel identifier - */ - public static MinecraftChannelIdentifier create(String namespace, String name) { - Preconditions.checkArgument(!Strings.isNullOrEmpty(namespace), "namespace is null or empty"); - Preconditions.checkArgument(name != null, "namespace is null or empty"); - Preconditions.checkArgument(VALID_IDENTIFIER_REGEX.matcher(namespace).matches(), - "namespace is not valid"); - Preconditions - .checkArgument(VALID_IDENTIFIER_REGEX.matcher(name).matches(), "name is not valid"); - return new MinecraftChannelIdentifier(namespace, name); - } - - /** - * Creates an channel identifier from the specified Minecraft identifier. - * - * @param identifier the Minecraft identifier - * @return a new channel identifier - */ - public static MinecraftChannelIdentifier from(String identifier) { - int colonPos = identifier.indexOf(':'); - if (colonPos == -1) { - throw new IllegalArgumentException("Identifier does not contain a colon."); - } - if (colonPos + 1 == identifier.length()) { - throw new IllegalArgumentException("Identifier is empty."); - } - String namespace = identifier.substring(0, colonPos); - String name = identifier.substring(colonPos + 1); - return create(namespace, name); - } - - public String getNamespace() { - return namespace; - } - - public String getName() { - return name; - } - - @Override - public String toString() { - return namespace + ":" + name + " (modern)"; - } - - @Override - public boolean equals(@Nullable Object o) { - if (this == o) { - return true; - } - if (o == null || getClass() != o.getClass()) { - return false; - } - MinecraftChannelIdentifier that = (MinecraftChannelIdentifier) o; - return Objects.equals(namespace, that.namespace) - && Objects.equals(name, that.name); - } - - @Override - public int hashCode() { - return Objects.hash(namespace, name); - } - - @Override - public String id() { - return namespace + ":" + name; - } -} diff --git a/api/src/main/java/com/velocitypowered/api/proxy/messages/MinecraftPluginChannelId.java b/api/src/main/java/com/velocitypowered/api/proxy/messages/MinecraftPluginChannelId.java new file mode 100644 index 000000000..b5b6b583d --- /dev/null +++ b/api/src/main/java/com/velocitypowered/api/proxy/messages/MinecraftPluginChannelId.java @@ -0,0 +1,55 @@ +/* + * Copyright (C) 2018 Velocity Contributors + * + * The Velocity API is licensed under the terms of the MIT License. For more details, + * reference the LICENSE file in the api top-level directory. + */ + +package com.velocitypowered.api.proxy.messages; + +import com.google.common.base.Preconditions; +import com.google.common.base.Strings; +import java.util.Objects; +import java.util.regex.Pattern; +import net.kyori.adventure.key.Key; +import org.checkerframework.checker.nullness.qual.Nullable; + +/** + * Represents a Minecraft 1.13+ channel identifier. + */ +public final class MinecraftPluginChannelId implements PluginChannelId { + + private final Key key; + + MinecraftPluginChannelId(Key key) { + this.key = Preconditions.checkNotNull(key, "key"); + } + + public Key key() { + return key; + } + + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + + MinecraftPluginChannelId that = (MinecraftPluginChannelId) o; + + return key.equals(that.key); + } + + @Override + public int hashCode() { + return key.hashCode(); + } + + @Override + public String toString() { + return key.asString(); + } +} diff --git a/api/src/main/java/com/velocitypowered/api/proxy/messages/PairedPluginChannelId.java b/api/src/main/java/com/velocitypowered/api/proxy/messages/PairedPluginChannelId.java new file mode 100644 index 000000000..b31cbc0b6 --- /dev/null +++ b/api/src/main/java/com/velocitypowered/api/proxy/messages/PairedPluginChannelId.java @@ -0,0 +1,72 @@ +/* + * Copyright (C) 2018 Velocity Contributors + * + * The Velocity API is licensed under the terms of the MIT License. For more details, + * reference the LICENSE file in the api top-level directory. + */ + +package com.velocitypowered.api.proxy.messages; + +import com.google.common.base.Preconditions; +import com.google.common.base.Strings; +import net.kyori.adventure.key.Key; + +/** + * Reperesents a legacy channel identifier (for Minecraft 1.12 and below). For modern 1.13 plugin + * messages, please see {@link MinecraftPluginChannelId}. This class is immutable and safe for + * multi-threaded use. + */ +public final class PairedPluginChannelId implements PluginChannelId { + + private final String legacyChannel; + private final Key modernChannelKey; + + /** + * Creates a new legacy channel identifier. + * + * @param legacyChannel the name for the legacy channel name + * @param modernChannelKey the modern channel key to use + */ + PairedPluginChannelId(String legacyChannel, Key modernChannelKey) { + Preconditions.checkArgument(!Strings.isNullOrEmpty(legacyChannel), "provided name is empty"); + this.legacyChannel = legacyChannel; + this.modernChannelKey = Preconditions.checkNotNull(modernChannelKey, "modernChannelKey"); + } + + public String legacyChannel() { + return legacyChannel; + } + + public Key modernChannelKey() { + return modernChannelKey; + } + + @Override + public String toString() { + return legacyChannel + "/" + modernChannelKey.asString(); + } + + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + + PairedPluginChannelId that = (PairedPluginChannelId) o; + + if (!legacyChannel.equals(that.legacyChannel)) { + return false; + } + return modernChannelKey.equals(that.modernChannelKey); + } + + @Override + public int hashCode() { + int result = legacyChannel.hashCode(); + result = 31 * result + modernChannelKey.hashCode(); + return result; + } +} diff --git a/api/src/main/java/com/velocitypowered/api/proxy/messages/PluginChannelId.java b/api/src/main/java/com/velocitypowered/api/proxy/messages/PluginChannelId.java new file mode 100644 index 000000000..119a0f350 --- /dev/null +++ b/api/src/main/java/com/velocitypowered/api/proxy/messages/PluginChannelId.java @@ -0,0 +1,41 @@ +/* + * Copyright (C) 2018 Velocity Contributors + * + * The Velocity API is licensed under the terms of the MIT License. For more details, + * reference the LICENSE file in the api top-level directory. + */ + +package com.velocitypowered.api.proxy.messages; + +import net.kyori.adventure.key.Key; + +/** + * Represents a channel identifier for use with plugin messaging. + */ +public interface PluginChannelId { + + /** + * Wraps the specified Minecraft key so it can be used as a {@link PluginChannelId}. + * If the client is connected using Minecraft 1.12.2 or earlier, use the key as the + * channel name. + * + * @param key the key instance to wrap + * @return a wrapped plugin channel ID + */ + static MinecraftPluginChannelId wrap(Key key) { + return new MinecraftPluginChannelId(key); + } + + /** + * Wraps the specified Minecraft key so it can be used as a {@link PluginChannelId}, + * with the specified {@code legacyChannel} for clients onnected using Minecraft 1.12.2 + * or earlier. + * + * @param legacyChannel the legacy channel name + * @param modernChannelKey the key instance to wrap + * @return a wrapped plugin channel ID + */ + static PairedPluginChannelId withLegacy(String legacyChannel, Key modernChannelKey) { + return new PairedPluginChannelId(legacyChannel, modernChannelKey); + } +} diff --git a/api/src/test/java/com/velocitypowered/api/proxy/messages/MinecraftChannelIdentifierTest.java b/api/src/test/java/com/velocitypowered/api/proxy/messages/MinecraftChannelIdentifierTest.java deleted file mode 100644 index 17e6e499c..000000000 --- a/api/src/test/java/com/velocitypowered/api/proxy/messages/MinecraftChannelIdentifierTest.java +++ /dev/null @@ -1,63 +0,0 @@ -/* - * Copyright (C) 2018 Velocity Contributors - * - * The Velocity API is licensed under the terms of the MIT License. For more details, - * reference the LICENSE file in the api top-level directory. - */ - -package com.velocitypowered.api.proxy.messages; - -import static com.velocitypowered.api.proxy.messages.MinecraftChannelIdentifier.create; -import static com.velocitypowered.api.proxy.messages.MinecraftChannelIdentifier.from; -import static org.junit.jupiter.api.Assertions.assertAll; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertThrows; - -import org.junit.jupiter.api.Test; - -class MinecraftChannelIdentifierTest { - - @Test - void createAllowsValidNamespaces() { - create("minecraft", "brand"); - } - - @Test - void createAllowsEmptyName() { - create("minecraft", ""); - } - - @Test - void createDisallowsNull() { - assertAll( - () -> assertThrows(IllegalArgumentException.class, () -> create(null, "")), - () -> assertThrows(IllegalArgumentException.class, () -> create("", "")), - () -> assertThrows(IllegalArgumentException.class, () -> create("minecraft", null)) - ); - } - - @Test - void fromIdentifierIsCorrect() { - MinecraftChannelIdentifier expected = MinecraftChannelIdentifier.create("velocity", "test"); - assertEquals(expected, MinecraftChannelIdentifier.from("velocity:test")); - } - - @Test - void createAllowsSlashes() { - create("velocity", "test/test2"); - } - - @Test - void fromIdentifierThrowsOnBadValues() { - assertAll( - () -> assertThrows(IllegalArgumentException.class, () -> from("")), - () -> assertThrows(IllegalArgumentException.class, () -> from(":")), - () -> assertThrows(IllegalArgumentException.class, () -> from(":a")), - () -> assertThrows(IllegalArgumentException.class, () -> from("a:")), - () -> assertThrows(IllegalArgumentException.class, () -> from("hello:$$$$$$")), - () -> assertThrows(IllegalArgumentException.class, () -> from("hello::")) - ); - } - - -} \ No newline at end of file diff --git a/proxy/src/main/java/com/velocitypowered/proxy/VelocityServer.java b/proxy/src/main/java/com/velocitypowered/proxy/VelocityServer.java index 28cbb07d0..5855fdf8e 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/VelocityServer.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/VelocityServer.java @@ -277,7 +277,7 @@ public class VelocityServer implements ProxyServer, ForwardingAudience { } // Register the plugin main classes so that we can fire the proxy initialize event - for (PluginContainer plugin : pluginManager.getPlugins()) { + for (PluginContainer plugin : pluginManager.plugins()) { Optional instance = plugin.instance(); if (instance.isPresent()) { try { @@ -289,7 +289,7 @@ public class VelocityServer implements ProxyServer, ForwardingAudience { } } - logger.info("Loaded {} plugins", pluginManager.getPlugins().size()); + logger.info("Loaded {} plugins", pluginManager.plugins().size()); } public Bootstrap createBootstrap(@Nullable EventLoopGroup group, SocketAddress target) { diff --git a/proxy/src/main/java/com/velocitypowered/proxy/command/builtin/VelocityCommand.java b/proxy/src/main/java/com/velocitypowered/proxy/command/builtin/VelocityCommand.java index cb9bc4bcd..e7a579727 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/command/builtin/VelocityCommand.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/command/builtin/VelocityCommand.java @@ -270,7 +270,7 @@ public class VelocityCommand implements SimpleCommand { return; } - List plugins = ImmutableList.copyOf(server.pluginManager().getPlugins()); + List plugins = ImmutableList.copyOf(server.pluginManager().plugins()); int pluginCount = plugins.size(); if (pluginCount == 0) { diff --git a/proxy/src/main/java/com/velocitypowered/proxy/connection/backend/BackendPlaySessionHandler.java b/proxy/src/main/java/com/velocitypowered/proxy/connection/backend/BackendPlaySessionHandler.java index 296f0e53c..dc3184832 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/connection/backend/BackendPlaySessionHandler.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/connection/backend/BackendPlaySessionHandler.java @@ -28,7 +28,7 @@ import com.velocitypowered.api.event.command.PlayerAvailableCommandsEventImpl; import com.velocitypowered.api.event.connection.PluginMessageEvent; import com.velocitypowered.api.event.connection.PluginMessageEventImpl; import com.velocitypowered.api.network.ProtocolVersion; -import com.velocitypowered.api.proxy.messages.ChannelIdentifier; +import com.velocitypowered.api.proxy.messages.PluginChannelId; import com.velocitypowered.proxy.VelocityServer; import com.velocitypowered.proxy.connection.MinecraftConnection; import com.velocitypowered.proxy.connection.MinecraftSessionHandler; @@ -160,7 +160,7 @@ public class BackendPlaySessionHandler implements MinecraftSessionHandler { return true; } - ChannelIdentifier id = server.channelRegistrar().getFromId(packet.getChannel()); + PluginChannelId id = server.channelRegistrar().getFromId(packet.getChannel()); if (id == null) { return false; } diff --git a/proxy/src/main/java/com/velocitypowered/proxy/connection/backend/BungeeCordMessageResponder.java b/proxy/src/main/java/com/velocitypowered/proxy/connection/backend/BungeeCordMessageResponder.java index 2862e6182..32f9011fb 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/connection/backend/BungeeCordMessageResponder.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/connection/backend/BungeeCordMessageResponder.java @@ -19,8 +19,8 @@ package com.velocitypowered.proxy.connection.backend; import com.velocitypowered.api.network.ProtocolVersion; import com.velocitypowered.api.proxy.connection.Player; -import com.velocitypowered.api.proxy.messages.LegacyChannelIdentifier; -import com.velocitypowered.api.proxy.messages.MinecraftChannelIdentifier; +import com.velocitypowered.api.proxy.messages.PairedPluginChannelId; +import com.velocitypowered.api.proxy.messages.PluginChannelId; import com.velocitypowered.api.proxy.server.RegisteredServer; import com.velocitypowered.api.util.UuidUtils; import com.velocitypowered.proxy.VelocityServer; @@ -40,6 +40,7 @@ import java.net.SocketAddress; import java.util.Optional; import java.util.StringJoiner; import net.kyori.adventure.identity.Identity; +import net.kyori.adventure.key.Key; import net.kyori.adventure.text.Component; import net.kyori.adventure.text.serializer.ComponentSerializer; import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer; @@ -50,10 +51,8 @@ import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer; + "nothing.") public class BungeeCordMessageResponder { - private static final MinecraftChannelIdentifier MODERN_CHANNEL = MinecraftChannelIdentifier - .create("bungeecord", "main"); - private static final LegacyChannelIdentifier LEGACY_CHANNEL = - new LegacyChannelIdentifier("BungeeCord"); + private static final PairedPluginChannelId CHANNEL = PluginChannelId + .withLegacy("BungeeCord", Key.key("bungeecord", "main")); private final VelocityServer proxy; private final ConnectedPlayer player; @@ -64,8 +63,8 @@ public class BungeeCordMessageResponder { } public static boolean isBungeeCordMessage(AbstractPluginMessagePacket message) { - return MODERN_CHANNEL.id().equals(message.getChannel()) || LEGACY_CHANNEL.id() - .equals(message.getChannel()); + return CHANNEL.modernChannelKey().asString().equals(message.getChannel()) + || CHANNEL.legacyChannel().equals(message.getChannel()); } private void processConnect(ByteBufDataInput in) { @@ -293,7 +292,7 @@ public class BungeeCordMessageResponder { if (target.equals("ALL")) { try { for (RegisteredServer rs : proxy.registeredServers()) { - ((VelocityRegisteredServer) rs).sendPluginMessage(LEGACY_CHANNEL, + ((VelocityRegisteredServer) rs).sendPluginMessage(CHANNEL, toForward.retainedSlice()); } } finally { @@ -302,7 +301,7 @@ public class BungeeCordMessageResponder { } else { Optional server = proxy.server(target); if (server.isPresent()) { - ((VelocityRegisteredServer) server.get()).sendPluginMessage(LEGACY_CHANNEL, toForward); + ((VelocityRegisteredServer) server.get()).sendPluginMessage(CHANNEL, toForward); } else { toForward.release(); } @@ -310,8 +309,8 @@ public class BungeeCordMessageResponder { } static String getBungeeCordChannel(ProtocolVersion version) { - return version.gte(ProtocolVersion.MINECRAFT_1_13) ? MODERN_CHANNEL.id() - : LEGACY_CHANNEL.id(); + return version.gte(ProtocolVersion.MINECRAFT_1_13) ? CHANNEL.modernChannelKey().asString() + : CHANNEL.legacyChannel(); } // Note: this method will always release the buffer! diff --git a/proxy/src/main/java/com/velocitypowered/proxy/connection/backend/VelocityServerConnection.java b/proxy/src/main/java/com/velocitypowered/proxy/connection/backend/VelocityServerConnection.java index f09356100..197272884 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/connection/backend/VelocityServerConnection.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/connection/backend/VelocityServerConnection.java @@ -20,12 +20,13 @@ package com.velocitypowered.proxy.connection.backend; import static com.velocitypowered.proxy.VelocityServer.GENERAL_GSON; import static com.velocitypowered.proxy.connection.forge.legacy.LegacyForgeConstants.HANDSHAKE_HOSTNAME_TOKEN; import static com.velocitypowered.proxy.network.HandlerNames.HANDLER; +import static com.velocitypowered.proxy.network.PluginMessageUtil.channelIdForVersion; import com.google.common.base.Preconditions; import com.google.common.collect.ImmutableList; import com.velocitypowered.api.network.ProtocolVersion; import com.velocitypowered.api.proxy.connection.ServerConnection; -import com.velocitypowered.api.proxy.messages.ChannelIdentifier; +import com.velocitypowered.api.proxy.messages.PluginChannelId; import com.velocitypowered.api.proxy.player.ConnectionRequestBuilder; import com.velocitypowered.api.proxy.server.ServerInfo; import com.velocitypowered.api.util.GameProfile.Property; @@ -236,7 +237,7 @@ public class VelocityServerConnection implements MinecraftConnectionAssociation, } @Override - public boolean sendPluginMessage(ChannelIdentifier identifier, byte[] data) { + public boolean sendPluginMessage(PluginChannelId identifier, byte[] data) { return sendPluginMessage(identifier, Unpooled.wrappedBuffer(data)); } @@ -246,13 +247,14 @@ public class VelocityServerConnection implements MinecraftConnectionAssociation, * @param data the data * @return whether or not the message was sent */ - public boolean sendPluginMessage(ChannelIdentifier identifier, ByteBuf data) { + public boolean sendPluginMessage(PluginChannelId identifier, ByteBuf data) { Preconditions.checkNotNull(identifier, "identifier"); Preconditions.checkNotNull(data, "data"); MinecraftConnection mc = ensureConnected(); - ServerboundPluginMessagePacket message = new ServerboundPluginMessagePacket(identifier.id(), data); + ServerboundPluginMessagePacket message = new ServerboundPluginMessagePacket( + channelIdForVersion(identifier, mc.getProtocolVersion()), data); mc.write(message); return true; } diff --git a/proxy/src/main/java/com/velocitypowered/proxy/connection/client/ClientPlaySessionHandler.java b/proxy/src/main/java/com/velocitypowered/proxy/connection/client/ClientPlaySessionHandler.java index 983cb0b56..ae6e48d1a 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/connection/client/ClientPlaySessionHandler.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/connection/client/ClientPlaySessionHandler.java @@ -32,9 +32,7 @@ import com.velocitypowered.api.event.player.PlayerChatEventImpl; import com.velocitypowered.api.event.player.PlayerResourcePackStatusEventImpl; import com.velocitypowered.api.event.player.TabCompleteEventImpl; import com.velocitypowered.api.network.ProtocolVersion; -import com.velocitypowered.api.proxy.messages.ChannelIdentifier; -import com.velocitypowered.api.proxy.messages.LegacyChannelIdentifier; -import com.velocitypowered.api.proxy.messages.MinecraftChannelIdentifier; +import com.velocitypowered.api.proxy.messages.PluginChannelId; import com.velocitypowered.proxy.VelocityServer; import com.velocitypowered.proxy.connection.ConnectionTypes; import com.velocitypowered.proxy.connection.MinecraftConnection; @@ -72,6 +70,7 @@ import java.util.Queue; import java.util.UUID; import java.util.concurrent.CompletableFuture; import net.kyori.adventure.identity.Identity; +import net.kyori.adventure.key.Key; import net.kyori.adventure.text.Component; import net.kyori.adventure.text.format.NamedTextColor; import org.apache.logging.log4j.LogManager; @@ -218,16 +217,21 @@ public class ClientPlaySessionHandler implements MinecraftSessionHandler { } else if (PluginMessageUtil.isRegister(packet)) { List channels = PluginMessageUtil.getChannels(packet); player.getKnownChannels().addAll(channels); - List channelIdentifiers = new ArrayList<>(); - for (String channel : channels) { - try { - channelIdentifiers.add(MinecraftChannelIdentifier.from(channel)); - } catch (IllegalArgumentException e) { - channelIdentifiers.add(new LegacyChannelIdentifier(channel)); + + List pluginChannelIds = new ArrayList<>(); + if (player.protocolVersion().gte(MINECRAFT_1_13)) { + for (String channel : channels) { + pluginChannelIds.add(PluginChannelId.wrap(Key.key(channel))); + } + } else { + for (String channel : channels) { + pluginChannelIds.add(PluginChannelId.withLegacy(channel, + Key.key(PluginMessageUtil.transformLegacyToModernChannel(channel)))); } } + server.eventManager().fireAndForget(new PlayerChannelRegisterEventImpl(player, - ImmutableList.copyOf(channelIdentifiers))); + ImmutableList.copyOf(pluginChannelIds))); backendConn.write(packet.retain()); } else if (PluginMessageUtil.isUnregister(packet)) { player.getKnownChannels().removeAll(PluginMessageUtil.getChannels(packet)); @@ -259,7 +263,7 @@ public class ClientPlaySessionHandler implements MinecraftSessionHandler { // appropriately. loginPluginMessages.add(packet.retain()); } else { - ChannelIdentifier id = server.channelRegistrar().getFromId(packet.getChannel()); + PluginChannelId id = server.channelRegistrar().getFromId(packet.getChannel()); if (id == null) { backendConn.write(packet.retain()); } else { diff --git a/proxy/src/main/java/com/velocitypowered/proxy/connection/client/ConnectedPlayer.java b/proxy/src/main/java/com/velocitypowered/proxy/connection/client/ConnectedPlayer.java index 4098f75e9..e14c935ce 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/connection/client/ConnectedPlayer.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/connection/client/ConnectedPlayer.java @@ -19,6 +19,7 @@ package com.velocitypowered.proxy.connection.client; import static com.velocitypowered.api.proxy.player.ConnectionRequestBuilder.Status.ALREADY_CONNECTED; import static com.velocitypowered.proxy.connection.util.ConnectionRequestResults.plainResult; +import static com.velocitypowered.proxy.network.PluginMessageUtil.channelIdForVersion; import static java.util.concurrent.CompletableFuture.completedFuture; import com.google.common.base.Preconditions; @@ -42,7 +43,7 @@ import com.velocitypowered.api.permission.PermissionProvider; import com.velocitypowered.api.permission.Tristate; import com.velocitypowered.api.proxy.connection.Player; import com.velocitypowered.api.proxy.connection.ServerConnection; -import com.velocitypowered.api.proxy.messages.ChannelIdentifier; +import com.velocitypowered.api.proxy.messages.PluginChannelId; import com.velocitypowered.api.proxy.player.ClientSettings; import com.velocitypowered.api.proxy.player.ConnectionRequestBuilder; import com.velocitypowered.api.proxy.server.RegisteredServer; @@ -709,10 +710,11 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player { } @Override - public boolean sendPluginMessage(ChannelIdentifier identifier, byte[] data) { + public boolean sendPluginMessage(PluginChannelId identifier, byte[] data) { Preconditions.checkNotNull(identifier, "identifier"); Preconditions.checkNotNull(data, "data"); - ClientboundPluginMessagePacket message = new ClientboundPluginMessagePacket(identifier.id(), + ClientboundPluginMessagePacket message = new ClientboundPluginMessagePacket( + channelIdForVersion(identifier, connection.getProtocolVersion()), Unpooled.wrappedBuffer(data)); connection.write(message); return true; diff --git a/proxy/src/main/java/com/velocitypowered/proxy/network/PluginMessageUtil.java b/proxy/src/main/java/com/velocitypowered/proxy/network/PluginMessageUtil.java index 22771c5ae..04036e472 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/network/PluginMessageUtil.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/network/PluginMessageUtil.java @@ -22,6 +22,9 @@ import static com.google.common.base.Preconditions.checkNotNull; import com.google.common.collect.ImmutableList; import com.velocitypowered.api.network.ProtocolVersion; +import com.velocitypowered.api.proxy.messages.MinecraftPluginChannelId; +import com.velocitypowered.api.proxy.messages.PairedPluginChannelId; +import com.velocitypowered.api.proxy.messages.PluginChannelId; import com.velocitypowered.api.util.ProxyVersion; import com.velocitypowered.proxy.network.packet.AbstractPluginMessagePacket; import io.netty.buffer.ByteBuf; @@ -174,6 +177,19 @@ public final class PluginMessageUtil { } } + public static String channelIdForVersion(PluginChannelId id, ProtocolVersion version) { + if (id instanceof MinecraftPluginChannelId) { + return ((MinecraftPluginChannelId) id).key().asString(); + } else if (id instanceof PairedPluginChannelId) { + if (version.gte(ProtocolVersion.MINECRAFT_1_13)) { + return ((PairedPluginChannelId) id).modernChannelKey().asString(); + } else { + return ((PairedPluginChannelId) id).legacyChannel(); + } + } + throw new IllegalArgumentException("Unknown channel ID " + id.getClass().getName()); + } + private static final Pattern INVALID_IDENTIFIER_REGEX = Pattern.compile("[^a-z0-9\\-_]*"); /** diff --git a/proxy/src/main/java/com/velocitypowered/proxy/network/packet/AbstractPluginMessagePacket.java b/proxy/src/main/java/com/velocitypowered/proxy/network/packet/AbstractPluginMessagePacket.java index b2b8b0944..154a8f3f5 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/network/packet/AbstractPluginMessagePacket.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/network/packet/AbstractPluginMessagePacket.java @@ -32,9 +32,6 @@ public abstract class AbstractPluginMessagePacket> PacketReader

decoder(final Factory

factory) { return (buf, version) -> { String channel = ProtocolUtils.readString(buf); - if (version.gte(ProtocolVersion.MINECRAFT_1_13)) { - channel = transformLegacyToModernChannel(channel); - } final ByteBuf data; if (version.gte(ProtocolVersion.MINECRAFT_1_8)) { data = buf.readRetainedSlice(buf.readableBytes()); diff --git a/proxy/src/main/java/com/velocitypowered/proxy/network/pipeline/GS4QueryHandler.java b/proxy/src/main/java/com/velocitypowered/proxy/network/pipeline/GS4QueryHandler.java index dfc21ac4d..6b348b213 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/network/pipeline/GS4QueryHandler.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/network/pipeline/GS4QueryHandler.java @@ -201,7 +201,7 @@ public class GS4QueryHandler extends SimpleChannelInboundHandler private List getRealPluginInformation() { List result = new ArrayList<>(); - for (PluginContainer plugin : server.pluginManager().getPlugins()) { + for (PluginContainer plugin : server.pluginManager().plugins()) { PluginDescription description = plugin.description(); result.add(QueryResponse.PluginInformation.of(description.name() .orElse(description.id()), description.version().orElse(null))); diff --git a/proxy/src/main/java/com/velocitypowered/proxy/plugin/VelocityPluginManager.java b/proxy/src/main/java/com/velocitypowered/proxy/plugin/VelocityPluginManager.java index eb74e72a7..edbd59a09 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/plugin/VelocityPluginManager.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/plugin/VelocityPluginManager.java @@ -178,7 +178,7 @@ public class VelocityPluginManager implements PluginManager { } @Override - public Collection getPlugins() { + public Collection plugins() { return Collections.unmodifiableCollection(plugins.values()); } diff --git a/proxy/src/main/java/com/velocitypowered/proxy/server/VelocityRegisteredServer.java b/proxy/src/main/java/com/velocitypowered/proxy/server/VelocityRegisteredServer.java index 0b98d7078..558829cbb 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/server/VelocityRegisteredServer.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/server/VelocityRegisteredServer.java @@ -28,7 +28,7 @@ import com.google.common.base.Preconditions; import com.google.common.collect.ImmutableList; import com.velocitypowered.api.network.ProtocolVersion; import com.velocitypowered.api.proxy.connection.Player; -import com.velocitypowered.api.proxy.messages.ChannelIdentifier; +import com.velocitypowered.api.proxy.messages.PluginChannelId; import com.velocitypowered.api.proxy.server.RegisteredServer; import com.velocitypowered.api.proxy.server.ServerInfo; import com.velocitypowered.api.proxy.server.ServerPing; @@ -137,7 +137,7 @@ public class VelocityRegisteredServer implements RegisteredServer, ForwardingAud } @Override - public boolean sendPluginMessage(ChannelIdentifier identifier, byte[] data) { + public boolean sendPluginMessage(PluginChannelId identifier, byte[] data) { return sendPluginMessage(identifier, Unpooled.wrappedBuffer(data)); } @@ -149,7 +149,7 @@ public class VelocityRegisteredServer implements RegisteredServer, ForwardingAud * @param data the data * @return whether or not the message was sent */ - public boolean sendPluginMessage(ChannelIdentifier identifier, ByteBuf data) { + public boolean sendPluginMessage(PluginChannelId identifier, ByteBuf data) { for (ConnectedPlayer player : players.values()) { VelocityServerConnection connection = player.getConnectedServer(); if (connection != null && connection.target() == this) { diff --git a/proxy/src/main/java/com/velocitypowered/proxy/util/InformationUtils.java b/proxy/src/main/java/com/velocitypowered/proxy/util/InformationUtils.java index 265158f32..17a75fb3e 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/util/InformationUtils.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/util/InformationUtils.java @@ -52,8 +52,7 @@ public enum InformationUtils { * @return {@link JsonArray} containing zero or more {@link JsonObject} */ public static JsonArray collectPluginInfo(ProxyServer proxy) { - List allPlugins = ImmutableList.copyOf( - proxy.pluginManager().getPlugins()); + List allPlugins = ImmutableList.copyOf(proxy.pluginManager().plugins()); JsonArray plugins = new JsonArray(); for (PluginContainer plugin : allPlugins) { @@ -190,7 +189,7 @@ public enum InformationUtils { if (address instanceof InetSocketAddress) { InetSocketAddress iaddr = (InetSocketAddress) address; if (iaddr.isUnresolved()) { - // Greetings form Netty 4aa10db9 + // Greetings from Netty 4aa10db9 info.addProperty("host", iaddr.getHostString()); } else { info.addProperty("host", anonymizeInetAddress(iaddr.getAddress())); diff --git a/proxy/src/main/java/com/velocitypowered/proxy/util/VelocityChannelRegistrar.java b/proxy/src/main/java/com/velocitypowered/proxy/util/VelocityChannelRegistrar.java index 58cbe97e1..e87795a3f 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/util/VelocityChannelRegistrar.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/util/VelocityChannelRegistrar.java @@ -18,55 +18,58 @@ package com.velocitypowered.proxy.util; import com.google.common.base.Preconditions; +import com.google.common.collect.ImmutableSet; import com.velocitypowered.api.network.ProtocolVersion; -import com.velocitypowered.api.proxy.messages.ChannelIdentifier; import com.velocitypowered.api.proxy.messages.ChannelRegistrar; -import com.velocitypowered.api.proxy.messages.LegacyChannelIdentifier; -import com.velocitypowered.api.proxy.messages.MinecraftChannelIdentifier; -import com.velocitypowered.proxy.network.PluginMessageUtil; +import com.velocitypowered.api.proxy.messages.MinecraftPluginChannelId; +import com.velocitypowered.api.proxy.messages.PairedPluginChannelId; +import com.velocitypowered.api.proxy.messages.PluginChannelId; import java.util.Collection; -import java.util.HashSet; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; import org.checkerframework.checker.nullness.qual.Nullable; public class VelocityChannelRegistrar implements ChannelRegistrar { - private final Map identifierMap = new ConcurrentHashMap<>(); + private final Map byLegacyId = new ConcurrentHashMap<>(); + private final Map byKey = new ConcurrentHashMap<>(); @Override - public void register(ChannelIdentifier... identifiers) { - for (ChannelIdentifier identifier : identifiers) { - Preconditions.checkArgument(identifier instanceof LegacyChannelIdentifier - || identifier instanceof MinecraftChannelIdentifier, "identifier is unknown"); + public void register(PluginChannelId... identifiers) { + for (PluginChannelId identifier : identifiers) { + Preconditions.checkArgument(identifier instanceof PairedPluginChannelId + || identifier instanceof MinecraftPluginChannelId, "identifier is unknown"); } - for (ChannelIdentifier identifier : identifiers) { - if (identifier instanceof MinecraftChannelIdentifier) { - identifierMap.put(identifier.id(), identifier); + for (PluginChannelId identifier : identifiers) { + if (identifier instanceof MinecraftPluginChannelId) { + MinecraftPluginChannelId modern = (MinecraftPluginChannelId) identifier; + byLegacyId.put(modern.key().asString(), identifier); + byKey.put(modern.key().asString(), identifier); } else { - String rewritten = PluginMessageUtil.transformLegacyToModernChannel(identifier.id()); - identifierMap.put(identifier.id(), identifier); - identifierMap.put(rewritten, identifier); + PairedPluginChannelId paired = (PairedPluginChannelId) identifier; + byLegacyId.put(paired.legacyChannel(), identifier); + byKey.put(paired.modernChannelKey().asString(), identifier); } } } @Override - public void unregister(ChannelIdentifier... identifiers) { - for (ChannelIdentifier identifier : identifiers) { - Preconditions.checkArgument(identifier instanceof LegacyChannelIdentifier - || identifier instanceof MinecraftChannelIdentifier, + public void unregister(PluginChannelId... identifiers) { + for (PluginChannelId identifier : identifiers) { + Preconditions.checkArgument(identifier instanceof PairedPluginChannelId + || identifier instanceof MinecraftPluginChannelId, "identifier is unknown"); } - for (ChannelIdentifier identifier : identifiers) { - if (identifier instanceof MinecraftChannelIdentifier) { - identifierMap.remove(identifier.id()); + for (PluginChannelId identifier : identifiers) { + if (identifier instanceof MinecraftPluginChannelId) { + MinecraftPluginChannelId modern = (MinecraftPluginChannelId) identifier; + byKey.remove(modern.key().asString(), identifier); } else { - String rewritten = PluginMessageUtil.transformLegacyToModernChannel(identifier.id()); - identifierMap.remove(identifier.id()); - identifierMap.remove(rewritten); + PairedPluginChannelId paired = (PairedPluginChannelId) identifier; + byLegacyId.remove(paired.legacyChannel(), identifier); + byKey.remove(paired.modernChannelKey().asString(), identifier); } } } @@ -77,11 +80,7 @@ public class VelocityChannelRegistrar implements ChannelRegistrar { * @return all legacy channel IDs */ public Collection getLegacyChannelIds() { - Collection ids = new HashSet<>(); - for (ChannelIdentifier value : identifierMap.values()) { - ids.add(value.id()); - } - return ids; + return ImmutableSet.copyOf(this.byLegacyId.keySet()); } /** @@ -90,19 +89,14 @@ public class VelocityChannelRegistrar implements ChannelRegistrar { * @return the channel IDs for Minecraft 1.13 and above */ public Collection getModernChannelIds() { - Collection ids = new HashSet<>(); - for (ChannelIdentifier value : identifierMap.values()) { - if (value instanceof MinecraftChannelIdentifier) { - ids.add(value.id()); - } else { - ids.add(PluginMessageUtil.transformLegacyToModernChannel(value.id())); - } - } - return ids; + return ImmutableSet.copyOf(this.byKey.keySet()); } - public @Nullable ChannelIdentifier getFromId(String id) { - return identifierMap.get(id); + public @Nullable PluginChannelId getFromId(String id) { + if (id.indexOf(':') >= 0) { + return byKey.get(id); + } + return byLegacyId.get(id); } /** diff --git a/proxy/src/main/java/com/velocitypowered/proxy/util/bossbar/AdventureBossBarManager.java b/proxy/src/main/java/com/velocitypowered/proxy/util/bossbar/AdventureBossBarManager.java index 9408d4886..29e2fdee9 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/util/bossbar/AdventureBossBarManager.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/util/bossbar/AdventureBossBarManager.java @@ -138,13 +138,12 @@ public class AdventureBossBarManager implements BossBar.Listener { } @Override - public void bossBarPercentChanged(@NonNull BossBar bar, float oldPercent, float newPercent) { + public void bossBarProgressChanged(@NonNull BossBar bar, float oldProgress, float newProgress) { BossBarHolder holder = this.getHandler(bar); if (holder == null) { return; } - ClientboundBossBarPacket packet = holder - .createPercentUpdate(newPercent); + ClientboundBossBarPacket packet = holder.createPercentUpdate(newProgress); for (ConnectedPlayer player : holder.subscribers) { player.getConnection().write(packet); } @@ -170,8 +169,7 @@ public class AdventureBossBarManager implements BossBar.Listener { if (holder == null) { return; } - ClientboundBossBarPacket packet = holder - .createOverlayUpdate(newOverlay); + ClientboundBossBarPacket packet = holder.createOverlayUpdate(newOverlay); for (ConnectedPlayer player : holder.subscribers) { player.getConnection().write(packet); } diff --git a/proxy/src/test/java/com/velocitypowered/proxy/plugin/MockPluginManager.java b/proxy/src/test/java/com/velocitypowered/proxy/plugin/MockPluginManager.java index 33864a168..8fb1247a1 100644 --- a/proxy/src/test/java/com/velocitypowered/proxy/plugin/MockPluginManager.java +++ b/proxy/src/test/java/com/velocitypowered/proxy/plugin/MockPluginManager.java @@ -39,7 +39,7 @@ public class MockPluginManager implements PluginManager { } @Override - public Collection getPlugins() { + public Collection plugins() { return ImmutableList.of(); } diff --git a/proxy/src/test/java/com/velocitypowered/proxy/testutil/FakePluginManager.java b/proxy/src/test/java/com/velocitypowered/proxy/testutil/FakePluginManager.java index a2fed39ea..b72ea461b 100644 --- a/proxy/src/test/java/com/velocitypowered/proxy/testutil/FakePluginManager.java +++ b/proxy/src/test/java/com/velocitypowered/proxy/testutil/FakePluginManager.java @@ -58,7 +58,7 @@ public class FakePluginManager implements PluginManager { } @Override - public @NonNull Collection getPlugins() { + public @NonNull Collection plugins() { return ImmutableList.of(PC_A, PC_B); } diff --git a/proxy/src/test/java/com/velocitypowered/proxy/util/VelocityChannelRegistrarTest.java b/proxy/src/test/java/com/velocitypowered/proxy/util/VelocityChannelRegistrarTest.java index d63c5b163..a59d295ce 100644 --- a/proxy/src/test/java/com/velocitypowered/proxy/util/VelocityChannelRegistrarTest.java +++ b/proxy/src/test/java/com/velocitypowered/proxy/util/VelocityChannelRegistrarTest.java @@ -20,23 +20,18 @@ package com.velocitypowered.proxy.util; import static org.junit.jupiter.api.Assertions.assertEquals; import com.google.common.collect.ImmutableSet; -import com.velocitypowered.api.proxy.messages.LegacyChannelIdentifier; -import com.velocitypowered.api.proxy.messages.MinecraftChannelIdentifier; +import com.velocitypowered.api.proxy.messages.MinecraftPluginChannelId; +import com.velocitypowered.api.proxy.messages.PairedPluginChannelId; +import com.velocitypowered.api.proxy.messages.PluginChannelId; +import net.kyori.adventure.key.Key; import org.junit.jupiter.api.Test; class VelocityChannelRegistrarTest { - private static final MinecraftChannelIdentifier MODERN = MinecraftChannelIdentifier - .create("velocity", "test"); - private static final LegacyChannelIdentifier SIMPLE_LEGACY = - new LegacyChannelIdentifier("VelocityTest"); - - private static final MinecraftChannelIdentifier MODERN_SPECIAL_REMAP = MinecraftChannelIdentifier - .create("bungeecord", "main"); - private static final LegacyChannelIdentifier SPECIAL_REMAP_LEGACY = - new LegacyChannelIdentifier("BungeeCord"); - - private static final String SIMPLE_LEGACY_REMAPPED = "legacy:velocitytest"; + private static final MinecraftPluginChannelId MODERN = PluginChannelId.wrap( + Key.key("velocity", "moderntest")); + private static final PairedPluginChannelId SIMPLE_LEGACY = + PluginChannelId.withLegacy("VelocityTest", Key.key("velocity", "test")); @Test void register() { @@ -45,30 +40,21 @@ class VelocityChannelRegistrarTest { // Two channels cover the modern channel (velocity:test) and the legacy-mapped channel // (legacy:velocitytest). Make sure they're what we expect. - assertEquals(ImmutableSet.of(MODERN.id(), SIMPLE_LEGACY_REMAPPED), registrar - .getModernChannelIds()); - assertEquals(ImmutableSet.of(SIMPLE_LEGACY.id(), MODERN.id()), registrar + assertEquals( + ImmutableSet.of(MODERN.key().asString(), SIMPLE_LEGACY.modernChannelKey().asString()), + registrar.getModernChannelIds()); + assertEquals( + ImmutableSet.of(SIMPLE_LEGACY.legacyChannel(), MODERN.key().asString()), registrar .getLegacyChannelIds()); } - @Test - void registerSpecialRewrite() { - VelocityChannelRegistrar registrar = new VelocityChannelRegistrar(); - registrar.register(SPECIAL_REMAP_LEGACY, MODERN_SPECIAL_REMAP); - - // This one, just one channel for the modern case. - assertEquals(ImmutableSet.of(MODERN_SPECIAL_REMAP.id()), registrar.getModernChannelIds()); - assertEquals(ImmutableSet.of(MODERN_SPECIAL_REMAP.id(), SPECIAL_REMAP_LEGACY.id()), - registrar.getLegacyChannelIds()); - } - @Test void unregister() { VelocityChannelRegistrar registrar = new VelocityChannelRegistrar(); - registrar.register(MODERN, SIMPLE_LEGACY); + registrar.register(MODERN); registrar.unregister(SIMPLE_LEGACY); - assertEquals(ImmutableSet.of(MODERN.id()), registrar.getModernChannelIds()); - assertEquals(ImmutableSet.of(MODERN.id()), registrar.getLegacyChannelIds()); + assertEquals(ImmutableSet.of(MODERN.key().asString()), registrar.getModernChannelIds()); + assertEquals(ImmutableSet.of(MODERN.key().asString()), registrar.getLegacyChannelIds()); } } \ No newline at end of file From ec6fb80d6c4f083c0ff3c75338e13c3f6f3699e6 Mon Sep 17 00:00:00 2001 From: Andrew Steinborn Date: Sat, 17 Apr 2021 06:17:45 -0400 Subject: [PATCH 33/99] Fix typo --- .../com/velocitypowered/api/proxy/messages/PluginChannelId.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/api/src/main/java/com/velocitypowered/api/proxy/messages/PluginChannelId.java b/api/src/main/java/com/velocitypowered/api/proxy/messages/PluginChannelId.java index 119a0f350..037caf1f0 100644 --- a/api/src/main/java/com/velocitypowered/api/proxy/messages/PluginChannelId.java +++ b/api/src/main/java/com/velocitypowered/api/proxy/messages/PluginChannelId.java @@ -28,7 +28,7 @@ public interface PluginChannelId { /** * Wraps the specified Minecraft key so it can be used as a {@link PluginChannelId}, - * with the specified {@code legacyChannel} for clients onnected using Minecraft 1.12.2 + * with the specified {@code legacyChannel} for clients connected using Minecraft 1.12.2 * or earlier. * * @param legacyChannel the legacy channel name From 4318c179a45488d4716216ce5743c79b4152ed35 Mon Sep 17 00:00:00 2001 From: Andrew Steinborn Date: Sat, 17 Apr 2021 06:19:29 -0400 Subject: [PATCH 34/99] Fix Javadocs for PairedPluginChannelId and KeyedPluginChannelId --- ...ginChannelId.java => KeyedPluginChannelId.java} | 12 ++++-------- .../api/proxy/messages/PairedPluginChannelId.java | 5 ++--- .../api/proxy/messages/PluginChannelId.java | 4 ++-- .../proxy/network/PluginMessageUtil.java | 6 +++--- .../proxy/util/VelocityChannelRegistrar.java | 14 +++++++------- .../proxy/util/VelocityChannelRegistrarTest.java | 4 ++-- 6 files changed, 20 insertions(+), 25 deletions(-) rename api/src/main/java/com/velocitypowered/api/proxy/messages/{MinecraftPluginChannelId.java => KeyedPluginChannelId.java} (68%) diff --git a/api/src/main/java/com/velocitypowered/api/proxy/messages/MinecraftPluginChannelId.java b/api/src/main/java/com/velocitypowered/api/proxy/messages/KeyedPluginChannelId.java similarity index 68% rename from api/src/main/java/com/velocitypowered/api/proxy/messages/MinecraftPluginChannelId.java rename to api/src/main/java/com/velocitypowered/api/proxy/messages/KeyedPluginChannelId.java index b5b6b583d..14b66c836 100644 --- a/api/src/main/java/com/velocitypowered/api/proxy/messages/MinecraftPluginChannelId.java +++ b/api/src/main/java/com/velocitypowered/api/proxy/messages/KeyedPluginChannelId.java @@ -8,20 +8,16 @@ package com.velocitypowered.api.proxy.messages; import com.google.common.base.Preconditions; -import com.google.common.base.Strings; -import java.util.Objects; -import java.util.regex.Pattern; import net.kyori.adventure.key.Key; -import org.checkerframework.checker.nullness.qual.Nullable; /** - * Represents a Minecraft 1.13+ channel identifier. + * Represents a modern namespaced channel identifier. */ -public final class MinecraftPluginChannelId implements PluginChannelId { +public final class KeyedPluginChannelId implements PluginChannelId { private final Key key; - MinecraftPluginChannelId(Key key) { + KeyedPluginChannelId(Key key) { this.key = Preconditions.checkNotNull(key, "key"); } @@ -38,7 +34,7 @@ public final class MinecraftPluginChannelId implements PluginChannelId { return false; } - MinecraftPluginChannelId that = (MinecraftPluginChannelId) o; + KeyedPluginChannelId that = (KeyedPluginChannelId) o; return key.equals(that.key); } diff --git a/api/src/main/java/com/velocitypowered/api/proxy/messages/PairedPluginChannelId.java b/api/src/main/java/com/velocitypowered/api/proxy/messages/PairedPluginChannelId.java index b31cbc0b6..2bce1abc0 100644 --- a/api/src/main/java/com/velocitypowered/api/proxy/messages/PairedPluginChannelId.java +++ b/api/src/main/java/com/velocitypowered/api/proxy/messages/PairedPluginChannelId.java @@ -12,9 +12,8 @@ import com.google.common.base.Strings; import net.kyori.adventure.key.Key; /** - * Reperesents a legacy channel identifier (for Minecraft 1.12 and below). For modern 1.13 plugin - * messages, please see {@link MinecraftPluginChannelId}. This class is immutable and safe for - * multi-threaded use. + * Reperesents a legacy channel identifier (for Minecraft 1.12 and below) paired with a namespaced + * key for 1.13 and above. This class is immutable and safe for multi-threaded use. */ public final class PairedPluginChannelId implements PluginChannelId { diff --git a/api/src/main/java/com/velocitypowered/api/proxy/messages/PluginChannelId.java b/api/src/main/java/com/velocitypowered/api/proxy/messages/PluginChannelId.java index 037caf1f0..49c4dd767 100644 --- a/api/src/main/java/com/velocitypowered/api/proxy/messages/PluginChannelId.java +++ b/api/src/main/java/com/velocitypowered/api/proxy/messages/PluginChannelId.java @@ -22,8 +22,8 @@ public interface PluginChannelId { * @param key the key instance to wrap * @return a wrapped plugin channel ID */ - static MinecraftPluginChannelId wrap(Key key) { - return new MinecraftPluginChannelId(key); + static KeyedPluginChannelId wrap(Key key) { + return new KeyedPluginChannelId(key); } /** diff --git a/proxy/src/main/java/com/velocitypowered/proxy/network/PluginMessageUtil.java b/proxy/src/main/java/com/velocitypowered/proxy/network/PluginMessageUtil.java index 04036e472..8db301011 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/network/PluginMessageUtil.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/network/PluginMessageUtil.java @@ -22,7 +22,7 @@ import static com.google.common.base.Preconditions.checkNotNull; import com.google.common.collect.ImmutableList; import com.velocitypowered.api.network.ProtocolVersion; -import com.velocitypowered.api.proxy.messages.MinecraftPluginChannelId; +import com.velocitypowered.api.proxy.messages.KeyedPluginChannelId; import com.velocitypowered.api.proxy.messages.PairedPluginChannelId; import com.velocitypowered.api.proxy.messages.PluginChannelId; import com.velocitypowered.api.util.ProxyVersion; @@ -178,8 +178,8 @@ public final class PluginMessageUtil { } public static String channelIdForVersion(PluginChannelId id, ProtocolVersion version) { - if (id instanceof MinecraftPluginChannelId) { - return ((MinecraftPluginChannelId) id).key().asString(); + if (id instanceof KeyedPluginChannelId) { + return ((KeyedPluginChannelId) id).key().asString(); } else if (id instanceof PairedPluginChannelId) { if (version.gte(ProtocolVersion.MINECRAFT_1_13)) { return ((PairedPluginChannelId) id).modernChannelKey().asString(); diff --git a/proxy/src/main/java/com/velocitypowered/proxy/util/VelocityChannelRegistrar.java b/proxy/src/main/java/com/velocitypowered/proxy/util/VelocityChannelRegistrar.java index e87795a3f..9eafa4852 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/util/VelocityChannelRegistrar.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/util/VelocityChannelRegistrar.java @@ -21,7 +21,7 @@ import com.google.common.base.Preconditions; import com.google.common.collect.ImmutableSet; import com.velocitypowered.api.network.ProtocolVersion; import com.velocitypowered.api.proxy.messages.ChannelRegistrar; -import com.velocitypowered.api.proxy.messages.MinecraftPluginChannelId; +import com.velocitypowered.api.proxy.messages.KeyedPluginChannelId; import com.velocitypowered.api.proxy.messages.PairedPluginChannelId; import com.velocitypowered.api.proxy.messages.PluginChannelId; import java.util.Collection; @@ -38,12 +38,12 @@ public class VelocityChannelRegistrar implements ChannelRegistrar { public void register(PluginChannelId... identifiers) { for (PluginChannelId identifier : identifiers) { Preconditions.checkArgument(identifier instanceof PairedPluginChannelId - || identifier instanceof MinecraftPluginChannelId, "identifier is unknown"); + || identifier instanceof KeyedPluginChannelId, "identifier is unknown"); } for (PluginChannelId identifier : identifiers) { - if (identifier instanceof MinecraftPluginChannelId) { - MinecraftPluginChannelId modern = (MinecraftPluginChannelId) identifier; + if (identifier instanceof KeyedPluginChannelId) { + KeyedPluginChannelId modern = (KeyedPluginChannelId) identifier; byLegacyId.put(modern.key().asString(), identifier); byKey.put(modern.key().asString(), identifier); } else { @@ -58,13 +58,13 @@ public class VelocityChannelRegistrar implements ChannelRegistrar { public void unregister(PluginChannelId... identifiers) { for (PluginChannelId identifier : identifiers) { Preconditions.checkArgument(identifier instanceof PairedPluginChannelId - || identifier instanceof MinecraftPluginChannelId, + || identifier instanceof KeyedPluginChannelId, "identifier is unknown"); } for (PluginChannelId identifier : identifiers) { - if (identifier instanceof MinecraftPluginChannelId) { - MinecraftPluginChannelId modern = (MinecraftPluginChannelId) identifier; + if (identifier instanceof KeyedPluginChannelId) { + KeyedPluginChannelId modern = (KeyedPluginChannelId) identifier; byKey.remove(modern.key().asString(), identifier); } else { PairedPluginChannelId paired = (PairedPluginChannelId) identifier; diff --git a/proxy/src/test/java/com/velocitypowered/proxy/util/VelocityChannelRegistrarTest.java b/proxy/src/test/java/com/velocitypowered/proxy/util/VelocityChannelRegistrarTest.java index a59d295ce..ed10149f9 100644 --- a/proxy/src/test/java/com/velocitypowered/proxy/util/VelocityChannelRegistrarTest.java +++ b/proxy/src/test/java/com/velocitypowered/proxy/util/VelocityChannelRegistrarTest.java @@ -20,7 +20,7 @@ package com.velocitypowered.proxy.util; import static org.junit.jupiter.api.Assertions.assertEquals; import com.google.common.collect.ImmutableSet; -import com.velocitypowered.api.proxy.messages.MinecraftPluginChannelId; +import com.velocitypowered.api.proxy.messages.KeyedPluginChannelId; import com.velocitypowered.api.proxy.messages.PairedPluginChannelId; import com.velocitypowered.api.proxy.messages.PluginChannelId; import net.kyori.adventure.key.Key; @@ -28,7 +28,7 @@ import org.junit.jupiter.api.Test; class VelocityChannelRegistrarTest { - private static final MinecraftPluginChannelId MODERN = PluginChannelId.wrap( + private static final KeyedPluginChannelId MODERN = PluginChannelId.wrap( Key.key("velocity", "moderntest")); private static final PairedPluginChannelId SIMPLE_LEGACY = PluginChannelId.withLegacy("VelocityTest", Key.key("velocity", "test")); From 3d0ca2732efe2846102cdd49974b199db0c64430 Mon Sep 17 00:00:00 2001 From: Andrew Steinborn Date: Sat, 17 Apr 2021 07:02:39 -0400 Subject: [PATCH 35/99] Run all components in cases where the locale is known through the translation registry. --- .../connection/client/ConnectedPlayer.java | 34 ++++++++++++++----- .../proxy/tablist/VelocityTabList.java | 4 +++ .../util/bossbar/AdventureBossBarManager.java | 18 ++++++---- 3 files changed, 40 insertions(+), 16 deletions(-) diff --git a/proxy/src/main/java/com/velocitypowered/proxy/connection/client/ConnectedPlayer.java b/proxy/src/main/java/com/velocitypowered/proxy/connection/client/ConnectedPlayer.java index e14c935ce..8de648b6a 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/connection/client/ConnectedPlayer.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/connection/client/ConnectedPlayer.java @@ -80,6 +80,7 @@ import java.net.SocketAddress; import java.util.Collection; import java.util.Collections; import java.util.List; +import java.util.Locale; import java.util.Objects; import java.util.Optional; import java.util.UUID; @@ -95,6 +96,9 @@ import net.kyori.adventure.text.format.NamedTextColor; import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer; import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer; import net.kyori.adventure.text.serializer.plain.PlainComponentSerializer; +import net.kyori.adventure.title.Title; +import net.kyori.adventure.title.Title.Times; +import net.kyori.adventure.translation.GlobalTranslator; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.checkerframework.checker.nullness.qual.MonotonicNonNull; @@ -252,14 +256,21 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player { return connection.getProtocolVersion(); } + public Component translateMessage(Component message) { + Locale locale = this.settings == null ? Locale.getDefault() : this.settings.getLocale(); + return GlobalTranslator.render(message, locale); + } + @Override public void sendMessage(@NonNull Identity identity, @NonNull Component message, @NonNull MessageType type) { Preconditions.checkNotNull(message, "message"); Preconditions.checkNotNull(type, "type"); + Component translated = translateMessage(message); + connection.write(new ClientboundChatPacket( - ProtocolUtils.getJsonChatSerializer(this.protocolVersion()).serialize(message), + ProtocolUtils.getJsonChatSerializer(this.protocolVersion()).serialize(translated), type == MessageType.CHAT ? ClientboundChatPacket.CHAT_TYPE : ClientboundChatPacket.SYSTEM_TYPE, @@ -269,18 +280,21 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player { @Override public void sendActionBar(net.kyori.adventure.text.@NonNull Component message) { + Component translated = translateMessage(message); + ProtocolVersion playerVersion = protocolVersion(); if (playerVersion.gte(ProtocolVersion.MINECRAFT_1_11)) { // Use the title packet instead. connection.write(new ClientboundTitlePacket( ClientboundTitlePacket.SET_ACTION_BAR, - ProtocolUtils.getJsonChatSerializer(playerVersion).serialize(message) + ProtocolUtils.getJsonChatSerializer(playerVersion).serialize(translated) )); } else { // Due to issues with action bar packets, we'll need to convert the text message into a // legacy message and then inject the legacy text into a component... yuck! JsonObject object = new JsonObject(); - object.addProperty("text", LegacyComponentSerializer.legacySection().serialize(message)); + object.addProperty("text", LegacyComponentSerializer.legacySection() + .serialize(translated)); connection.write(new ClientboundChatPacket( object.toString(), ClientboundChatPacket.GAME_INFO_TYPE, @@ -307,22 +321,22 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player { } @Override - public void showTitle(net.kyori.adventure.title.@NonNull Title title) { + public void showTitle(@NonNull Title title) { if (this.protocolVersion().compareTo(ProtocolVersion.MINECRAFT_1_8) >= 0) { GsonComponentSerializer serializer = ProtocolUtils.getJsonChatSerializer(this .protocolVersion()); connection.delayedWrite(new ClientboundTitlePacket( ClientboundTitlePacket.SET_TITLE, - serializer.serialize(title.title()) + serializer.serialize(translateMessage(title.title())) )); connection.delayedWrite(new ClientboundTitlePacket( ClientboundTitlePacket.SET_SUBTITLE, - serializer.serialize(title.subtitle()) + serializer.serialize(translateMessage(title.subtitle())) )); - net.kyori.adventure.title.Title.Times times = title.times(); + Times times = title.times(); if (times != null) { connection.delayedWrite(ClientboundTitlePacket.times(this.protocolVersion(), times)); } @@ -389,9 +403,11 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player { * @param duringLogin whether the disconnect happened during login */ public void disconnect0(Component reason, boolean duringLogin) { + Component translated = this.translateMessage(reason); + logger.info("{} has disconnected: {}", this, - LegacyComponentSerializer.legacySection().serialize(reason)); - connection.closeWith(ClientboundDisconnectPacket.create(reason, this.protocolVersion())); + LegacyComponentSerializer.legacySection().serialize(translated)); + connection.closeWith(ClientboundDisconnectPacket.create(translated, this.protocolVersion())); } public @Nullable VelocityServerConnection getConnectedServer() { diff --git a/proxy/src/main/java/com/velocitypowered/proxy/tablist/VelocityTabList.java b/proxy/src/main/java/com/velocitypowered/proxy/tablist/VelocityTabList.java index da074f1ce..4367cffb1 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/tablist/VelocityTabList.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/tablist/VelocityTabList.java @@ -55,6 +55,10 @@ public class VelocityTabList implements TabList { Preconditions.checkNotNull(footer, "footer"); GsonComponentSerializer serializer = ProtocolUtils.getJsonChatSerializer( connection.getProtocolVersion()); + + Component translatedHeader = player.translateMessage(header); + Component translatedFooter = player.translateMessage(footer); + connection.write(new ClientboundHeaderAndFooterPacket( serializer.serialize(header), serializer.serialize(footer) diff --git a/proxy/src/main/java/com/velocitypowered/proxy/util/bossbar/AdventureBossBarManager.java b/proxy/src/main/java/com/velocitypowered/proxy/util/bossbar/AdventureBossBarManager.java index 29e2fdee9..6c45cea36 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/util/bossbar/AdventureBossBarManager.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/util/bossbar/AdventureBossBarManager.java @@ -19,6 +19,7 @@ package com.velocitypowered.proxy.util.bossbar; import com.google.common.collect.MapMaker; import com.velocitypowered.api.network.ProtocolVersion; +import com.velocitypowered.api.proxy.connection.Player; import com.velocitypowered.proxy.connection.client.ConnectedPlayer; import com.velocitypowered.proxy.network.ProtocolUtils; import com.velocitypowered.proxy.network.packet.clientbound.ClientboundBossBarPacket; @@ -101,7 +102,7 @@ public class AdventureBossBarManager implements BossBar.Listener { public void addBossBar(ConnectedPlayer player, BossBar bar) { BossBarHolder holder = this.getOrCreateHandler(bar); if (holder.subscribers.add(player)) { - player.getConnection().write(holder.createAddPacket(player.protocolVersion())); + player.getConnection().write(holder.createAddPacket(player)); } } @@ -124,14 +125,16 @@ public class AdventureBossBarManager implements BossBar.Listener { if (holder == null) { return; } - ClientboundBossBarPacket pre116Packet = holder.createTitleUpdate( - newName, ProtocolVersion.MINECRAFT_1_15_2); - ClientboundBossBarPacket rgbPacket = holder.createTitleUpdate( - newName, ProtocolVersion.MINECRAFT_1_16); for (ConnectedPlayer player : holder.subscribers) { + Component translated = player.translateMessage(newName); + if (player.protocolVersion().gte(ProtocolVersion.MINECRAFT_1_16)) { + ClientboundBossBarPacket rgbPacket = holder.createTitleUpdate( + translated, ProtocolVersion.MINECRAFT_1_16); player.getConnection().write(rgbPacket); } else { + ClientboundBossBarPacket pre116Packet = holder.createTitleUpdate( + translated, ProtocolVersion.MINECRAFT_1_15_2); player.getConnection().write(pre116Packet); } } @@ -207,11 +210,12 @@ public class AdventureBossBarManager implements BossBar.Listener { return ClientboundBossBarPacket.createRemovePacket(this.id); } - ClientboundBossBarPacket createAddPacket(ProtocolVersion version) { + ClientboundBossBarPacket createAddPacket(ConnectedPlayer player) { ClientboundBossBarPacket packet = new ClientboundBossBarPacket(); packet.setUuid(this.id); packet.setAction(ClientboundBossBarPacket.ADD); - packet.setName(ProtocolUtils.getJsonChatSerializer(version).serialize(bar.name())); + packet.setName(ProtocolUtils.getJsonChatSerializer(player.protocolVersion()) + .serialize(player.translateMessage(bar.name()))); packet.setColor(COLORS_TO_PROTOCOL.get(bar.color())); packet.setOverlay(OVERLAY_TO_PROTOCOL.get(bar.overlay())); packet.setPercent(bar.progress()); From 50f47422403a73934bdc84d53070fa556dd9d778 Mon Sep 17 00:00:00 2001 From: Andrew Steinborn Date: Sat, 17 Apr 2021 07:06:23 -0400 Subject: [PATCH 36/99] Add some cases where the locale should fallback to the default --- .../connection/client/InitialInboundConnection.java | 11 ++++++++--- .../proxy/connection/client/LoginSessionHandler.java | 8 +++++--- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/proxy/src/main/java/com/velocitypowered/proxy/connection/client/InitialInboundConnection.java b/proxy/src/main/java/com/velocitypowered/proxy/connection/client/InitialInboundConnection.java index cb6384d7a..49571ec9f 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/connection/client/InitialInboundConnection.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/connection/client/InitialInboundConnection.java @@ -24,9 +24,11 @@ import com.velocitypowered.proxy.connection.MinecraftConnectionAssociation; import com.velocitypowered.proxy.network.packet.clientbound.ClientboundDisconnectPacket; import com.velocitypowered.proxy.network.packet.serverbound.ServerboundHandshakePacket; import java.net.InetSocketAddress; +import java.util.Locale; import java.util.Optional; import net.kyori.adventure.text.Component; import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer; +import net.kyori.adventure.translation.GlobalTranslator; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; @@ -76,9 +78,11 @@ public final class InitialInboundConnection implements InboundConnection, * @param reason the reason for disconnecting */ public void disconnect(Component reason) { + Component translated = GlobalTranslator.render(reason, Locale.getDefault()); + logger.info("{} has disconnected: {}", this, - LegacyComponentSerializer.legacySection().serialize(reason)); - connection.closeWith(ClientboundDisconnectPacket.create(reason, protocolVersion())); + LegacyComponentSerializer.legacySection().serialize(translated)); + connection.closeWith(ClientboundDisconnectPacket.create(translated, protocolVersion())); } /** @@ -86,6 +90,7 @@ public final class InitialInboundConnection implements InboundConnection, * @param reason the reason for disconnecting */ public void disconnectQuietly(Component reason) { - connection.closeWith(ClientboundDisconnectPacket.create(reason, protocolVersion())); + Component translated = GlobalTranslator.render(reason, Locale.getDefault()); + connection.closeWith(ClientboundDisconnectPacket.create(translated, protocolVersion())); } } diff --git a/proxy/src/main/java/com/velocitypowered/proxy/connection/client/LoginSessionHandler.java b/proxy/src/main/java/com/velocitypowered/proxy/connection/client/LoginSessionHandler.java index 36ec63cf8..008644ff3 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/connection/client/LoginSessionHandler.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/connection/client/LoginSessionHandler.java @@ -47,7 +47,6 @@ import com.velocitypowered.proxy.config.VelocityConfiguration; import com.velocitypowered.proxy.connection.MinecraftConnection; import com.velocitypowered.proxy.connection.MinecraftSessionHandler; import com.velocitypowered.proxy.network.StateRegistry; -import com.velocitypowered.proxy.network.packet.clientbound.ClientboundDisconnectPacket; import com.velocitypowered.proxy.network.packet.clientbound.ClientboundEncryptionRequestPacket; import com.velocitypowered.proxy.network.packet.clientbound.ClientboundServerLoginSuccessPacket; import com.velocitypowered.proxy.network.packet.clientbound.ClientboundSetCompressionPacket; @@ -59,12 +58,14 @@ import java.security.GeneralSecurityException; import java.security.KeyPair; import java.security.MessageDigest; import java.util.Arrays; +import java.util.Locale; import java.util.Optional; import java.util.UUID; import java.util.concurrent.CompletableFuture; import java.util.concurrent.ExecutionException; import java.util.concurrent.ThreadLocalRandom; import net.kyori.adventure.text.Component; +import net.kyori.adventure.translation.GlobalTranslator; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.asynchttpclient.ListenableFuture; @@ -191,8 +192,9 @@ public class LoginSessionHandler implements MinecraftSessionHandler { Optional disconnectReason = result.denialReason(); if (disconnectReason.isPresent()) { // The component is guaranteed to be provided if the connection was denied. - mcConnection.closeWith(ClientboundDisconnectPacket.create(disconnectReason.get(), - inbound.protocolVersion())); + Component disconnectReasonTranslated = GlobalTranslator.render(disconnectReason.get(), + Locale.getDefault()); + inbound.disconnect(disconnectReasonTranslated); return; } From 5d07c29cf6ab543dab9862991f5059cfbcdfa056 Mon Sep 17 00:00:00 2001 From: Andrew Steinborn Date: Sat, 17 Apr 2021 07:08:35 -0400 Subject: [PATCH 37/99] Fix SpotBugs issue --- .../com/velocitypowered/proxy/tablist/VelocityTabList.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/proxy/src/main/java/com/velocitypowered/proxy/tablist/VelocityTabList.java b/proxy/src/main/java/com/velocitypowered/proxy/tablist/VelocityTabList.java index 4367cffb1..a60500881 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/tablist/VelocityTabList.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/tablist/VelocityTabList.java @@ -60,8 +60,8 @@ public class VelocityTabList implements TabList { Component translatedFooter = player.translateMessage(footer); connection.write(new ClientboundHeaderAndFooterPacket( - serializer.serialize(header), - serializer.serialize(footer) + serializer.serialize(translatedHeader), + serializer.serialize(translatedFooter) )); } From c0b6f461cbc0472f675ffabdfe0804dfae9d0a1e Mon Sep 17 00:00:00 2001 From: Andrew Steinborn Date: Sat, 17 Apr 2021 08:30:31 -0400 Subject: [PATCH 38/99] Add localization support. Fixes #230 This is less flexible, but it is an Adventure-native solution and doesn't require an onerous amount of work to maintain. --- .../velocitypowered/proxy/VelocityServer.java | 16 ++++ .../command/builtin/CommandMessages.java | 30 +++++++ .../proxy/command/builtin/GlistCommand.java | 23 +++-- .../proxy/command/builtin/ServerCommand.java | 44 +++++++--- .../command/builtin/VelocityCommand.java | 61 +++++++------ .../proxy/config/VelocityConfiguration.java | 85 +------------------ .../backend/LoginSessionHandler.java | 4 +- .../client/ClientPlaySessionHandler.java | 8 +- .../connection/client/ConnectedPlayer.java | 40 +++++---- .../client/HandshakeSessionHandler.java | 10 ++- .../client/LoginSessionHandler.java | 19 +++-- .../connection/util/ConnectionMessages.java | 13 +-- .../proxy/console/VelocityConsole.java | 10 ++- .../velocitypowered/proxy/messages.properties | 62 ++++++++++++++ .../src/main/resources/default-velocity.toml | 18 +--- 15 files changed, 247 insertions(+), 196 deletions(-) create mode 100644 proxy/src/main/java/com/velocitypowered/proxy/command/builtin/CommandMessages.java create mode 100644 proxy/src/main/resources/com/velocitypowered/proxy/messages.properties diff --git a/proxy/src/main/java/com/velocitypowered/proxy/VelocityServer.java b/proxy/src/main/java/com/velocitypowered/proxy/VelocityServer.java index 5855fdf8e..bbe8a23aa 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/VelocityServer.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/VelocityServer.java @@ -78,6 +78,7 @@ import java.util.Locale; import java.util.Map; import java.util.Objects; import java.util.Optional; +import java.util.ResourceBundle; import java.util.UUID; import java.util.concurrent.CompletableFuture; import java.util.concurrent.ConcurrentHashMap; @@ -90,7 +91,11 @@ import java.util.function.IntFunction; import java.util.stream.Collectors; import net.kyori.adventure.audience.Audience; import net.kyori.adventure.audience.ForwardingAudience; +import net.kyori.adventure.key.Key; import net.kyori.adventure.text.Component; +import net.kyori.adventure.translation.GlobalTranslator; +import net.kyori.adventure.translation.TranslationRegistry; +import net.kyori.adventure.util.UTF8ResourceBundleControl; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.asynchttpclient.AsyncHttpClient; @@ -193,6 +198,8 @@ public class VelocityServer implements ProxyServer, ForwardingAudience { logger.info("Booting up {} {}...", version().getName(), version().getVersion()); console.setupStreams(); + registerTranslations(); + serverKeyPair = EncryptionUtils.createRsaKeyPair(1024); cm.logChannelInformation(); @@ -236,6 +243,15 @@ public class VelocityServer implements ProxyServer, ForwardingAudience { Metrics.VelocityMetrics.startMetrics(this, configuration.getMetrics()); } + private void registerTranslations() { + final TranslationRegistry translationRegistry = TranslationRegistry + .create(Key.key("velocity", "translations")); + translationRegistry.registerAll(Locale.US, + ResourceBundle.getBundle("com/velocitypowered/proxy/messages", Locale.US, + UTF8ResourceBundleControl.get()), false); + GlobalTranslator.get().addSource(translationRegistry); + } + @SuppressFBWarnings("DM_EXIT") private void doStartupConfigLoad() { try { diff --git a/proxy/src/main/java/com/velocitypowered/proxy/command/builtin/CommandMessages.java b/proxy/src/main/java/com/velocitypowered/proxy/command/builtin/CommandMessages.java new file mode 100644 index 000000000..b4a5a2130 --- /dev/null +++ b/proxy/src/main/java/com/velocitypowered/proxy/command/builtin/CommandMessages.java @@ -0,0 +1,30 @@ +/* + * 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 . + */ + +package com.velocitypowered.proxy.command.builtin; + +import net.kyori.adventure.text.Component; +import net.kyori.adventure.text.TranslatableComponent; +import net.kyori.adventure.text.format.NamedTextColor; + +public class CommandMessages { + + public static final TranslatableComponent PLAYERS_ONLY = Component.translatable( + "velocity.command.players-only", NamedTextColor.RED); + public static final TranslatableComponent SERVER_DOES_NOT_EXIST = Component.translatable( + "velocity.command.server-does-not-exist", NamedTextColor.RED); +} diff --git a/proxy/src/main/java/com/velocitypowered/proxy/command/builtin/GlistCommand.java b/proxy/src/main/java/com/velocitypowered/proxy/command/builtin/GlistCommand.java index d12f33cf2..6d0f8f947 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/command/builtin/GlistCommand.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/command/builtin/GlistCommand.java @@ -78,11 +78,7 @@ public class GlistCommand { final CommandSource source = context.getSource(); sendTotalProxyCount(source); source.sendMessage(Identity.nil(), - Component.text().content("To view all players on servers, use ") - .color(NamedTextColor.YELLOW) - .append(Component.text("/glist all", NamedTextColor.DARK_AQUA)) - .append(Component.text(".", NamedTextColor.YELLOW)) - .build()); + Component.translatable("velocity.command.glist-view-all", NamedTextColor.YELLOW)); return 1; } @@ -98,7 +94,7 @@ public class GlistCommand { Optional registeredServer = server.server(serverName); if (!registeredServer.isPresent()) { source.sendMessage(Identity.nil(), - Component.text("Server " + serverName + " doesn't exist.", NamedTextColor.RED)); + CommandMessages.SERVER_DOES_NOT_EXIST.args(Component.text(serverName))); return -1; } sendServerPlayers(source, registeredServer.get(), false); @@ -107,10 +103,19 @@ public class GlistCommand { } private void sendTotalProxyCount(CommandSource target) { + int online = server.countConnectedPlayers(); target.sendMessage(Identity.nil(), Component.text() - .content("There are ").color(NamedTextColor.YELLOW) - .append(Component.text(server.connectedPlayers().size(), NamedTextColor.GREEN)) - .append(Component.text(" player(s) online.", NamedTextColor.YELLOW)) + .append(Component.text(Integer.toString(online), NamedTextColor.GREEN)) + .append(Component.space()) + .append(Component.translatable( + online == 1 + ? "velocity.command.glist-player-singular" + : "velocity.command.glist-player-plural", + NamedTextColor.YELLOW + )) + .append(Component.space()) + .append(Component.translatable("velocity.command.glist-total-suffix", + NamedTextColor.YELLOW)) .build()); } diff --git a/proxy/src/main/java/com/velocitypowered/proxy/command/builtin/ServerCommand.java b/proxy/src/main/java/com/velocitypowered/proxy/command/builtin/ServerCommand.java index 760c6b6e0..87ec2d6a6 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/command/builtin/ServerCommand.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/command/builtin/ServerCommand.java @@ -35,6 +35,7 @@ import java.util.stream.Stream; import net.kyori.adventure.identity.Identity; import net.kyori.adventure.text.Component; import net.kyori.adventure.text.TextComponent; +import net.kyori.adventure.text.TranslatableComponent; import net.kyori.adventure.text.event.ClickEvent; import net.kyori.adventure.text.format.NamedTextColor; @@ -53,8 +54,7 @@ public class ServerCommand implements SimpleCommand { final String[] args = invocation.arguments(); if (!(source instanceof Player)) { - source.sendMessage(Identity.nil(), Component.text("Only players may run this command.", - NamedTextColor.RED)); + source.sendMessage(Identity.nil(), CommandMessages.PLAYERS_ONLY); return; } @@ -64,8 +64,8 @@ public class ServerCommand implements SimpleCommand { String serverName = args[0]; Optional toConnect = server.server(serverName); if (!toConnect.isPresent()) { - player.sendMessage(Identity.nil(), - Component.text("Server " + serverName + " doesn't exist.", NamedTextColor.RED)); + player.sendMessage(Identity.nil(), CommandMessages.SERVER_DOES_NOT_EXIST + .args(Component.text(serverName))); return; } @@ -78,19 +78,23 @@ public class ServerCommand implements SimpleCommand { private void outputServerInformation(Player executor) { String currentServer = executor.connectedServer().map(ServerConnection::serverInfo) .map(ServerInfo::name).orElse(""); - executor.sendMessage(Identity.nil(), Component.text( - "You are currently connected to " + currentServer + ".", NamedTextColor.YELLOW)); + executor.sendMessage(Identity.nil(), Component.translatable( + "velocity.command.server-current-server", + NamedTextColor.YELLOW, + Component.text(currentServer))); List servers = BuiltinCommandUtil.sortedServerList(server); if (servers.size() > MAX_SERVERS_TO_LIST) { - executor.sendMessage(Identity.nil(), Component.text( - "Too many servers to list. Tab-complete to show all servers.", NamedTextColor.RED)); + executor.sendMessage(Identity.nil(), Component.translatable( + "velocity.command.server-too-many", NamedTextColor.RED)); return; } // Assemble the list of servers as components - TextComponent.Builder serverListBuilder = Component.text().content("Available servers: ") - .color(NamedTextColor.YELLOW); + TextComponent.Builder serverListBuilder = Component.text() + .append(Component.translatable("velocity.command.server-available", + NamedTextColor.YELLOW)) + .append(Component.space()); for (int i = 0; i < servers.size(); i++) { RegisteredServer rs = servers.get(i); serverListBuilder.append(formatServerComponent(currentServer, rs)); @@ -106,17 +110,31 @@ public class ServerCommand implements SimpleCommand { ServerInfo serverInfo = server.serverInfo(); TextComponent serverTextComponent = Component.text(serverInfo.name()); - String playersText = server.connectedPlayers().size() + " player(s) online"; + int connectedPlayers = server.connectedPlayers().size(); + TranslatableComponent playersTextComponent; + if (connectedPlayers == 1) { + playersTextComponent = Component.translatable("velocity.command.server-tooltip-player-online"); + } else { + playersTextComponent = Component.translatable("velocity.command.server-tooltip-players-online"); + } + playersTextComponent = playersTextComponent.args(Component.text(connectedPlayers)); + if (serverInfo.name().equals(currentPlayerServer)) { serverTextComponent = serverTextComponent.color(NamedTextColor.GREEN) .hoverEvent( - showText(Component.text("Currently connected to this server\n" + playersText)) + showText( + Component.translatable("velocity.command.server-tooltip-current-server") + .append(Component.newline()) + .append(playersTextComponent)) ); } else { serverTextComponent = serverTextComponent.color(NamedTextColor.GRAY) .clickEvent(ClickEvent.runCommand("/server " + serverInfo.name())) .hoverEvent( - showText(Component.text("Click to connect to this server\n" + playersText)) + showText( + Component.translatable("velocity.command.server-tooltip-offer-connect-server") + .append(Component.newline()) + .append(playersTextComponent)) ); } return serverTextComponent; diff --git a/proxy/src/main/java/com/velocitypowered/proxy/command/builtin/VelocityCommand.java b/proxy/src/main/java/com/velocitypowered/proxy/command/builtin/VelocityCommand.java index e7a579727..c2fee2570 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/command/builtin/VelocityCommand.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/command/builtin/VelocityCommand.java @@ -17,7 +17,6 @@ package com.velocitypowered.proxy.command.builtin; -import com.google.common.base.Joiner; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableSet; @@ -49,6 +48,7 @@ import java.util.stream.Collectors; import net.kyori.adventure.identity.Identity; import net.kyori.adventure.text.Component; import net.kyori.adventure.text.TextComponent; +import net.kyori.adventure.text.TranslatableComponent; import net.kyori.adventure.text.event.ClickEvent; import net.kyori.adventure.text.event.HoverEvent; import net.kyori.adventure.text.format.NamedTextColor; @@ -180,17 +180,15 @@ public class VelocityCommand implements SimpleCommand { public void execute(CommandSource source, String @NonNull [] args) { try { if (server.reloadConfiguration()) { - source.sendMessage(Identity.nil(), Component.text( - "Configuration reloaded.", NamedTextColor.GREEN)); + source.sendMessage(Component.translatable("velocity.command.reload-success", + NamedTextColor.GREEN)); } else { - source.sendMessage(Identity.nil(), Component.text( - "Unable to reload your configuration. Check the console for more details.", + source.sendMessage(Component.translatable("velocity.command.reload-failure", NamedTextColor.RED)); } } catch (Exception e) { logger.error("Unable to reload configuration", e); - source.sendMessage(Identity.nil(), Component.text( - "Unable to reload your configuration. Check the console for more details.", + source.sendMessage(Component.translatable("velocity.command.reload-failure", NamedTextColor.RED)); } } @@ -219,33 +217,35 @@ public class VelocityCommand implements SimpleCommand { ProxyVersion version = server.version(); - TextComponent velocity = Component.text().content(version.getName() + " ") + Component velocity = Component.text().content(version.getName() + " ") .decoration(TextDecoration.BOLD, true) .color(VELOCITY_COLOR) .append(Component.text(version.getVersion()).decoration(TextDecoration.BOLD, false)) .build(); - TextComponent copyright = Component - .text("Copyright 2018-2020 " + version.getVendor() + ". " + version.getName() - + " is licensed under the terms of the GNU General Public License v3."); + Component copyright = Component + .translatable("velocity.command.version-copyright", + Component.text(version.getVendor()), + Component.text(version.getName())); source.sendMessage(Identity.nil(), velocity); source.sendMessage(Identity.nil(), copyright); if (version.getName().equals("Velocity")) { - TextComponent velocityWebsite = Component.text() - .content("Visit the ") - .append(Component.text().content("Velocity website") + TextComponent embellishment = Component.text() + .append(Component.text().content("velocitypowered.com") .color(NamedTextColor.GREEN) + .decoration(TextDecoration.UNDERLINED, true) .clickEvent( ClickEvent.openUrl("https://www.velocitypowered.com")) .build()) - .append(Component.text(" or the ")) - .append(Component.text().content("Velocity GitHub") + .append(Component.text(" - ")) + .append(Component.text().content("GitHub") .color(NamedTextColor.GREEN) + .decoration(TextDecoration.UNDERLINED, true) .clickEvent(ClickEvent.openUrl( "https://github.com/VelocityPowered/Velocity")) .build()) .build(); - source.sendMessage(Identity.nil(), velocityWebsite); + source.sendMessage(Identity.nil(), embellishment); } } @@ -274,12 +274,13 @@ public class VelocityCommand implements SimpleCommand { int pluginCount = plugins.size(); if (pluginCount == 0) { - source.sendMessage(Identity.nil(), Component.text( - "No plugins installed.", NamedTextColor.YELLOW)); + source.sendMessage(Component.translatable("velocity.command.no-plugins", + NamedTextColor.YELLOW)); return; } - TextComponent.Builder output = Component.text().content("Plugins: ") + TranslatableComponent.Builder output = Component.translatable() + .key("velocity.command.plugins-list") .color(NamedTextColor.YELLOW); for (int i = 0; i < pluginCount; i++) { PluginContainer plugin = plugins.get(i); @@ -300,15 +301,21 @@ public class VelocityCommand implements SimpleCommand { description.url().ifPresent(url -> { hoverText.append(Component.newline()); - hoverText.append(Component.text("Website: " + url)); + hoverText.append(Component.translatable( + "velocity.command.plugin-tooltip-website", + Component.text(url))); }); if (!description.authors().isEmpty()) { hoverText.append(Component.newline()); if (description.authors().size() == 1) { - hoverText.append(Component.text("Author: " + description.authors().get(0))); + hoverText.append(Component.translatable("velocity.command.plugin-tooltip-author", + Component.text(description.authors().get(0)))); } else { - hoverText.append(Component.text("Authors: " + Joiner.on(", ") - .join(description.authors()))); + hoverText.append( + Component.translatable("velocity.command.plugin-tooltip-author", + Component.text(String.join(", ", description.authors())) + ) + ); } } description.description().ifPresent(pdesc -> { @@ -352,8 +359,8 @@ public class VelocityCommand implements SimpleCommand { JsonArray connectOrder = new JsonArray(); List attemptedConnectionOrder = ImmutableList.copyOf( server.configuration().getAttemptConnectionOrder()); - for (int i = 0; i < attemptedConnectionOrder.size(); i++) { - connectOrder.add(attemptedConnectionOrder.get(i)); + for (String s : attemptedConnectionOrder) { + connectOrder.add(s); } JsonObject proxyConfig = InformationUtils.collectProxyConfig(server.configuration()); @@ -446,7 +453,7 @@ public class VelocityCommand implements SimpleCommand { e.getCause().printStackTrace(); } catch (JsonParseException e) { source.sendMessage(Component.text() - .content("An error occurred on the Velocity-servers and the dump could not " + .content("An error occurred on the Velocity servers and the dump could not " + "be completed. Please contact the Velocity staff about this problem. " + "If you do, provide the details about this error from the Velocity " + "console or server log.") diff --git a/proxy/src/main/java/com/velocitypowered/proxy/config/VelocityConfiguration.java b/proxy/src/main/java/com/velocitypowered/proxy/config/VelocityConfiguration.java index 033dd188f..deefcd99b 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/config/VelocityConfiguration.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/config/VelocityConfiguration.java @@ -45,7 +45,6 @@ import java.util.List; import java.util.Map; import java.util.Optional; import java.util.Random; -import net.kyori.adventure.text.Component; import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer; import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer; import org.apache.logging.log4j.LogManager; @@ -72,25 +71,23 @@ public class VelocityConfiguration implements ProxyConfig { @Expose private final Advanced advanced; @Expose private final Query query; private final Metrics metrics; - private final Messages messages; private net.kyori.adventure.text.@MonotonicNonNull Component motdAsComponent; private @Nullable Favicon favicon; private VelocityConfiguration(Servers servers, ForcedHosts forcedHosts, Advanced advanced, - Query query, Metrics metrics, Messages messages) { + Query query, Metrics metrics) { this.servers = servers; this.forcedHosts = forcedHosts; this.advanced = advanced; this.query = query; this.metrics = metrics; - this.messages = messages; } private VelocityConfiguration(String bind, String motd, int showMaxPlayers, boolean onlineMode, boolean preventClientProxyConnections, boolean announceForge, PlayerInfoForwarding playerInfoForwardingMode, byte[] forwardingSecret, boolean onlineModeKickExistingPlayers, PingPassthroughMode pingPassthrough, Servers servers, - ForcedHosts forcedHosts, Advanced advanced, Query query, Metrics metrics, Messages messages) { + ForcedHosts forcedHosts, Advanced advanced, Query query, Metrics metrics) { this.bind = bind; this.motd = motd; this.showMaxPlayers = showMaxPlayers; @@ -106,7 +103,6 @@ public class VelocityConfiguration implements ProxyConfig { this.advanced = advanced; this.query = query; this.metrics = metrics; - this.messages = messages; } /** @@ -373,10 +369,6 @@ public class VelocityConfiguration implements ProxyConfig { return advanced.isLogCommandExecutions(); } - public Messages getMessages() { - return messages; - } - @Override public String toString() { return MoreObjects.toStringHelper(this) @@ -450,7 +442,6 @@ public class VelocityConfiguration implements ProxyConfig { CommentedConfig advancedConfig = config.get("advanced"); CommentedConfig queryConfig = config.get("query"); CommentedConfig metricsConfig = config.get("metrics"); - CommentedConfig messagesConfig = config.get("messages"); PlayerInfoForwarding forwardingMode = config.getEnumOrElse("player-info-forwarding-mode", PlayerInfoForwarding.NONE); PingPassthroughMode pingPassthroughMode = config.getEnumOrElse("ping-passthrough", @@ -480,8 +471,7 @@ public class VelocityConfiguration implements ProxyConfig { new ForcedHosts(forcedHostsConfig), new Advanced(advancedConfig), new Query(queryConfig), - new Metrics(metricsConfig), - new Messages(messagesConfig, defaultConfig.get("messages")) + new Metrics(metricsConfig) ); } @@ -793,73 +783,4 @@ public class VelocityConfiguration implements ProxyConfig { return enabled; } } - - public static class Messages { - - private final CommentedConfig toml; - private final CommentedConfig defaultToml; - - private final String kickPrefix; - private final String disconnectPrefix; - private final String onlineModeOnly; - private final String noAvailableServers; - private final String alreadyConnected; - private final String movedToNewServerPrefix; - private final String genericConnectionError; - - private Messages(CommentedConfig toml, CommentedConfig defaultToml) { - this.toml = toml; - this.defaultToml = defaultToml; - this.kickPrefix = getString("kick-prefix"); - this.disconnectPrefix = getString("disconnect-prefix"); - this.onlineModeOnly = getString("online-mode-only"); - this.noAvailableServers = getString("no-available-servers"); - this.alreadyConnected = getString("already-connected"); - this.movedToNewServerPrefix = getString("moved-to-new-server-prefix"); - this.genericConnectionError = getString("generic-connection-error"); - } - - private String getString(String path) { - String def = defaultToml.getOrElse(path, ""); - if (toml == null) { - return def; - } - return toml.getOrElse(path, def); - } - - public Component getKickPrefix(String server) { - return deserialize(String.format(kickPrefix, server)); - } - - public Component getDisconnectPrefix(String server) { - return deserialize(String.format(disconnectPrefix, server)); - } - - public Component getOnlineModeOnly() { - return deserialize(onlineModeOnly); - } - - public Component getNoAvailableServers() { - return deserialize(noAvailableServers); - } - - public Component getAlreadyConnected() { - return deserialize(alreadyConnected); - } - - public Component getMovedToNewServerPrefix() { - return deserialize(movedToNewServerPrefix); - } - - public Component getGenericConnectionError() { - return deserialize(genericConnectionError); - } - - private Component deserialize(String str) { - if (str.startsWith("{")) { - return GsonComponentSerializer.gson().deserialize(str); - } - return LegacyComponentSerializer.legacyAmpersand().deserialize(str); - } - } } diff --git a/proxy/src/main/java/com/velocitypowered/proxy/connection/backend/LoginSessionHandler.java b/proxy/src/main/java/com/velocitypowered/proxy/connection/backend/LoginSessionHandler.java index 6cdac9475..a06fa6600 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/connection/backend/LoginSessionHandler.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/connection/backend/LoginSessionHandler.java @@ -50,8 +50,8 @@ import net.kyori.adventure.text.TextComponent; public class LoginSessionHandler implements MinecraftSessionHandler { - private static final TextComponent MODERN_IP_FORWARDING_FAILURE = Component - .text("Your server did not send a forwarding request to the proxy. Is it set up correctly?"); + private static final Component MODERN_IP_FORWARDING_FAILURE = Component + .translatable("velocity.error.modern-forwarding-failed"); private final VelocityServer server; private final VelocityServerConnection serverConn; diff --git a/proxy/src/main/java/com/velocitypowered/proxy/connection/client/ClientPlaySessionHandler.java b/proxy/src/main/java/com/velocitypowered/proxy/connection/client/ClientPlaySessionHandler.java index ae6e48d1a..3840f0b3c 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/connection/client/ClientPlaySessionHandler.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/connection/client/ClientPlaySessionHandler.java @@ -168,9 +168,8 @@ public class ClientPlaySessionHandler implements MinecraftSessionHandler { .exceptionally(e -> { logger.info("Exception occurred while running command for {}", player.username(), e); - player.sendMessage(Identity.nil(), - Component.text("An error occurred while running this command.", - NamedTextColor.RED)); + player.sendMessage(Component.translatable("velocity.command.generic-error", + NamedTextColor.RED)); return null; }); } else { @@ -335,7 +334,8 @@ public class ClientPlaySessionHandler implements MinecraftSessionHandler { @Override public void exception(Throwable throwable) { - player.disconnect(server.configuration().getMessages().getGenericConnectionError()); + player.disconnect(Component.translatable("velocity.error.player-connection-error", + NamedTextColor.RED)); } @Override diff --git a/proxy/src/main/java/com/velocitypowered/proxy/connection/client/ConnectedPlayer.java b/proxy/src/main/java/com/velocitypowered/proxy/connection/client/ConnectedPlayer.java index 8de648b6a..5e432c164 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/connection/client/ConnectedPlayer.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/connection/client/ConnectedPlayer.java @@ -446,18 +446,18 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player { wrapped = cause; } } - String userMessage; + + Component friendlyError; if (connectedServer != null && connectedServer.serverInfo().equals(server.serverInfo())) { - userMessage = "Your connection to " + server.serverInfo().name() + " encountered an " - + "error."; + friendlyError = Component.translatable("velocity.error.connected-server-error", + Component.text(server.serverInfo().name())); } else { logger.error("{}: unable to connect to server {}", this, server.serverInfo().name(), wrapped); - userMessage = "Unable to connect to " + server.serverInfo().name() + ". Try again " - + "later."; + friendlyError = Component.translatable("velocity.error.connecting-server-error", + Component.text(server.serverInfo().name())); } - handleConnectionException(server, null, Component.text(userMessage, - NamedTextColor.RED), safe); + handleConnectionException(server, null, friendlyError.color(NamedTextColor.RED), safe); } /** @@ -473,26 +473,22 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player { return; } - VelocityConfiguration.Messages messages = this.server.configuration().getMessages(); Component disconnectReason = GsonComponentSerializer.gson().deserialize(disconnect.getReason()); String plainTextReason = PASS_THRU_TRANSLATE.serialize(disconnectReason); if (connectedServer != null && connectedServer.serverInfo().equals(server.serverInfo())) { logger.error("{}: kicked from server {}: {}", this, server.serverInfo().name(), plainTextReason); - handleConnectionException(server, disconnectReason, Component.text() - .append(messages.getKickPrefix(server.serverInfo().name()) - .colorIfAbsent(NamedTextColor.RED)) - .color(NamedTextColor.RED) - .append(disconnectReason) - .build(), safe); + handleConnectionException(server, disconnectReason, + Component.translatable("velocity.error.moved-to-new-server", NamedTextColor.RED, + Component.text(server.serverInfo().name()), + disconnectReason), safe); } else { logger.error("{}: disconnected while connecting to {}: {}", this, server.serverInfo().name(), plainTextReason); - handleConnectionException(server, disconnectReason, Component.text() - .append(messages.getDisconnectPrefix(server.serverInfo().name()) - .colorIfAbsent(NamedTextColor.RED)) - .append(disconnectReason) - .build(), safe); + handleConnectionException(server, disconnectReason, + Component.translatable("velocity.error.cant-connect", NamedTextColor.RED, + Component.text(server.serverInfo().name()), + disconnectReason), safe); } } @@ -576,8 +572,10 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player { protocolVersion()), ((Impl) status).isSafe()); break; case SUCCESS: - sendMessage(Identity.nil(), server.configuration().getMessages() - .getMovedToNewServerPrefix().append(friendlyReason)); + sendMessage(Component.translatable("velocity.error.moved-to-new-server", + NamedTextColor.RED, + Component.text(originalEvent.server().serverInfo().name()), + friendlyReason)); break; default: // The only remaining value is successful (no need to do anything!) diff --git a/proxy/src/main/java/com/velocitypowered/proxy/connection/client/HandshakeSessionHandler.java b/proxy/src/main/java/com/velocitypowered/proxy/connection/client/HandshakeSessionHandler.java index bfe109eaf..8d9fbf669 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/connection/client/HandshakeSessionHandler.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/connection/client/HandshakeSessionHandler.java @@ -70,7 +70,10 @@ public class HandshakeSessionHandler implements MinecraftSessionHandler { @Override public boolean handle(LegacyHandshakePacket packet) { connection.closeWith(LegacyDisconnectPacket - .from(Component.text("Your client is old, please upgrade!", NamedTextColor.RED))); + .from(Component.text( + "Your client is extremely old. Please update to a newer version of Minecraft.", + NamedTextColor.RED) + )); return true; } @@ -122,7 +125,7 @@ public class HandshakeSessionHandler implements MinecraftSessionHandler { InetAddress address = ((InetSocketAddress) connection.getRemoteAddress()).getAddress(); if (!server.getIpAttemptLimiter().attempt(address)) { - ic.disconnectQuietly(Component.text("You are logging in too fast, try again later.")); + ic.disconnectQuietly(Component.translatable("velocity.error.logging-in-too-fast")); return; } @@ -132,7 +135,8 @@ public class HandshakeSessionHandler implements MinecraftSessionHandler { // and lower, otherwise IP information will never get forwarded. if (server.configuration().getPlayerInfoForwardingMode() == PlayerInfoForwarding.MODERN && handshake.getProtocolVersion().lt(ProtocolVersion.MINECRAFT_1_13)) { - ic.disconnectQuietly(Component.text("This server is only compatible with 1.13 and above.")); + ic.disconnectQuietly(Component.translatable( + "velocity.error.modern-forwarding-needs-new-client")); return; } diff --git a/proxy/src/main/java/com/velocitypowered/proxy/connection/client/LoginSessionHandler.java b/proxy/src/main/java/com/velocitypowered/proxy/connection/client/LoginSessionHandler.java index 008644ff3..4acde610d 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/connection/client/LoginSessionHandler.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/connection/client/LoginSessionHandler.java @@ -65,6 +65,7 @@ import java.util.concurrent.CompletableFuture; import java.util.concurrent.ExecutionException; import java.util.concurrent.ThreadLocalRandom; import net.kyori.adventure.text.Component; +import net.kyori.adventure.text.format.NamedTextColor; import net.kyori.adventure.translation.GlobalTranslator; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; @@ -152,7 +153,8 @@ public class LoginSessionHandler implements MinecraftSessionHandler { GameProfile.class), true); } else if (profileResponse.getStatusCode() == 204) { // Apparently an offline-mode user logged onto this online-mode proxy. - inbound.disconnect(server.configuration().getMessages().getOnlineModeOnly()); + inbound.disconnect(Component.translatable("velocity.error.online-mode-only", + NamedTextColor.RED)); } else { // Something else went wrong logger.error( @@ -192,9 +194,7 @@ public class LoginSessionHandler implements MinecraftSessionHandler { Optional disconnectReason = result.denialReason(); if (disconnectReason.isPresent()) { // The component is guaranteed to be provided if the connection was denied. - Component disconnectReasonTranslated = GlobalTranslator.render(disconnectReason.get(), - Locale.getDefault()); - inbound.disconnect(disconnectReasonTranslated); + inbound.disconnect(disconnectReason.get()); return; } @@ -243,7 +243,8 @@ public class LoginSessionHandler implements MinecraftSessionHandler { mcConnection, inbound.connectedHost().orElse(null), onlineMode); this.connectedPlayer = player; if (!server.canRegisterConnection(player)) { - player.disconnect0(server.configuration().getMessages().getAlreadyConnected(), true); + player.disconnect0(Component.translatable("velocity.error.already-connected-proxy", + NamedTextColor.RED), true); return CompletableFuture.completedFuture(null); } @@ -304,8 +305,8 @@ public class LoginSessionHandler implements MinecraftSessionHandler { player.disconnect0(reason.get(), true); } else { if (!server.registerConnection(player)) { - player.disconnect0(server.configuration().getMessages() - .getAlreadyConnected(), true); + player.disconnect0(Component.translatable("velocity.error.already-connected-proxy"), + true); return; } @@ -333,8 +334,8 @@ public class LoginSessionHandler implements MinecraftSessionHandler { .thenRunAsync(() -> { Optional toTry = event.initialServer(); if (!toTry.isPresent()) { - player.disconnect0(server.configuration().getMessages() - .getNoAvailableServers(), true); + player.disconnect0(Component.translatable("velocity.error.no-available-servers", + NamedTextColor.RED), true); return; } player.createConnectionRequest(toTry.get()).fireAndForget(); diff --git a/proxy/src/main/java/com/velocitypowered/proxy/connection/util/ConnectionMessages.java b/proxy/src/main/java/com/velocitypowered/proxy/connection/util/ConnectionMessages.java index bbb6c2daf..5e29672ce 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/connection/util/ConnectionMessages.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/connection/util/ConnectionMessages.java @@ -19,16 +19,17 @@ package com.velocitypowered.proxy.connection.util; import net.kyori.adventure.text.Component; import net.kyori.adventure.text.TextComponent; +import net.kyori.adventure.text.TranslatableComponent; import net.kyori.adventure.text.format.NamedTextColor; public class ConnectionMessages { - public static final TextComponent ALREADY_CONNECTED = Component - .text("You are already connected to this server!", NamedTextColor.RED); - public static final TextComponent IN_PROGRESS = Component - .text("You are already connecting to a server!", NamedTextColor.RED); - public static final TextComponent INTERNAL_SERVER_CONNECTION_ERROR = Component - .text("An internal server connection error occurred.", NamedTextColor.RED); + public static final TranslatableComponent ALREADY_CONNECTED = Component + .translatable("velocity.error.already-connected", NamedTextColor.RED); + public static final TranslatableComponent IN_PROGRESS = Component + .translatable("velocity.error.already-connecting", NamedTextColor.RED); + public static final TranslatableComponent INTERNAL_SERVER_CONNECTION_ERROR = Component + .translatable("velocity.error.internal-server-connection-error", NamedTextColor.RED); private ConnectionMessages() { throw new AssertionError(); diff --git a/proxy/src/main/java/com/velocitypowered/proxy/console/VelocityConsole.java b/proxy/src/main/java/com/velocitypowered/proxy/console/VelocityConsole.java index 80e4e3ea6..d3138a60e 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/console/VelocityConsole.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/console/VelocityConsole.java @@ -26,9 +26,12 @@ import com.velocitypowered.api.permission.PermissionFunction; import com.velocitypowered.api.permission.Tristate; import com.velocitypowered.proxy.VelocityServer; import java.util.List; +import java.util.Locale; import net.kyori.adventure.identity.Identity; import net.kyori.adventure.text.Component; import net.kyori.adventure.text.format.NamedTextColor; +import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer; +import net.kyori.adventure.translation.GlobalTranslator; import net.minecrell.terminalconsole.SimpleTerminalConsole; import org.apache.logging.log4j.Level; import org.apache.logging.log4j.LogManager; @@ -52,8 +55,8 @@ public final class VelocityConsole extends SimpleTerminalConsole implements Cons @Override public void sendMessage(@NonNull Identity identity, @NonNull Component message) { - logger.info(net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer.legacySection() - .serialize(message)); + Component translated = GlobalTranslator.render(message, Locale.getDefault()); + logger.info(LegacyComponentSerializer.legacySection().serialize(translated)); } @Override @@ -114,7 +117,8 @@ public final class VelocityConsole extends SimpleTerminalConsole implements Cons protected void runCommand(String command) { try { if (!this.server.commandManager().execute(this, command).join()) { - sendMessage(Component.text("Command not found.", NamedTextColor.RED)); + sendMessage(Component.translatable("velocity.command.command-does-not-exist", + NamedTextColor.RED)); } } catch (Exception e) { logger.error("An error occurred while running this command.", e); diff --git a/proxy/src/main/resources/com/velocitypowered/proxy/messages.properties b/proxy/src/main/resources/com/velocitypowered/proxy/messages.properties new file mode 100644 index 000000000..df291dc77 --- /dev/null +++ b/proxy/src/main/resources/com/velocitypowered/proxy/messages.properties @@ -0,0 +1,62 @@ +# +# 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 . +# + +velocity.error.already-connected=You are already connected to this server! +velocity.error.already-connected-proxy=You are already connected to this proxy! +velocity.error.already-connecting=You are already trying to connect to a server! +velocity.error.cant-connect=Unable to connect to {0}: {1} +velocity.error.connecting-server-error=Unable to connect you to {0}. Please try again later. +velocity.error.connected-server-error=Your connection to {0} encountered a problem. +velocity.error.internal-server-connection-error=An internal server connection error occurred. +velocity.error.logging-in-too-fast=You are logging in too fast, try again later. +velocity.error.online-mode-only=You are not logged into your Minecraft account. If you are logged into your Minecraft account, try restarting your Minecraft client. +velocity.error.player-connection-error=An internal error occurred in your connection. +velocity.error.modern-forwarding-needs-new-client=This server is only compatible with Minecraft 1.13 and above. +velocity.error.modern-forwarding-failed=Your server did not send a forwarding request to the proxy. Make sure the server is configured for Velocity forwarding. +velocity.error.moved-to-new-server=YOu were kicked from {0}: {1} +velocity.error.no-available-servers=There are no available servers to connect you to. Try again later or contact an admin. + +# Commands +velocity.command.generic-error=An error occurred while running this command. +velocity.command.command-does-not-exist=This command does not exist. + +velocity.command.players-only=Only players can run this command. +velocity.command.server-does-not-exist=The specified server {0} does not exist. + +velocity.command.server-current-server=You are currently connected to {0}. +velocity.command.server-too-many=There are too many servers set up. Use tab completion to get individual server counts. +velocity.command.server-available=Available servers: +velocity.command.server-tooltip-player-online={0} player online +velocity.command.server-tooltip-players-online={0} players online +velocity.command.server-tooltip-current-server=Currently connected to this server +velocity.command.server-tooltip-offer-connect-server=Click to connect to this server + +velocity.command.glist-player-singular=player +velocity.command.glist-player-plural=players +velocity.command.glist-total-suffix= are currently connected to the proxy. +velocity.command.glist-view-all=To view all players on servers, use /glist all. + +velocity.command.reload-success=Velocity configuration successfully reloaded. +velocity.command.reload-failure=Unable to reload your Velocity configuration. Check the console for more details. + +velocity.command.version-copyright=Copyright 2018-2021 {0}. {1} is licensed under the terms of the GNU General Public License v3. + +velocity.command.no-plugins=There are no plugins currently installed. +velocity.command.plugins-list=Plugins: {0} +velocity.command.plugin-tooltip-website=Website: {0} +velocity.command.plugin-tooltip-author=Author: {0} +velocity.command.plugin-tooltip-authors=Authors: {0} \ No newline at end of file diff --git a/proxy/src/main/resources/default-velocity.toml b/proxy/src/main/resources/default-velocity.toml index fbad6626c..4a8447336 100644 --- a/proxy/src/main/resources/default-velocity.toml +++ b/proxy/src/main/resources/default-velocity.toml @@ -141,20 +141,4 @@ port = 25577 map = "Velocity" # Whether plugins should be shown in query response by default or not -show-plugins = false - -# Legacy color codes and JSON are accepted in all messages. -[messages] -# Prefix when the player gets kicked from a server. -# First argument '%s': the server name -kick-prefix = "&cKicked from %s: " - -# Prefix when the player is disconnected from a server. -# First argument '%s': the server name -disconnect-prefix = "&cCan't connect to %s: " - -online-mode-only = "&cThis server only accepts connections from online-mode clients.\n\n&7Did you change your username? Sign out of Minecraft, sign back in, and try again." -no-available-servers = "&cThere are no available servers." -already-connected = "&cYou are already connected to this proxy!" -moved-to-new-server-prefix = "&cThe server you were on kicked you: " -generic-connection-error = "&cAn internal error occurred in your connection." +show-plugins = false \ No newline at end of file From 69cba59630c4db0445060199e46b983d1ebd72da Mon Sep 17 00:00:00 2001 From: Andrew Steinborn Date: Sat, 17 Apr 2021 09:00:48 -0400 Subject: [PATCH 39/99] Load localizations automatically. Also included a sample "backwards" localization to demonstrate that it does in fact work. --- .../velocitypowered/proxy/VelocityServer.java | 41 +++++++++++- .../command/builtin/VelocityCommand.java | 4 +- .../proxy/util/FileSystemUtils.java | 56 +++++++++++++++++ .../proxy/{ => l10n}/messages.properties | 2 +- .../proxy/l10n/messages_en_UD.properties | 62 +++++++++++++++++++ 5 files changed, 159 insertions(+), 6 deletions(-) create mode 100644 proxy/src/main/java/com/velocitypowered/proxy/util/FileSystemUtils.java rename proxy/src/main/resources/com/velocitypowered/proxy/{ => l10n}/messages.properties (96%) create mode 100644 proxy/src/main/resources/com/velocitypowered/proxy/l10n/messages_en_UD.properties diff --git a/proxy/src/main/java/com/velocitypowered/proxy/VelocityServer.java b/proxy/src/main/java/com/velocitypowered/proxy/VelocityServer.java index bbe8a23aa..0051f0707 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/VelocityServer.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/VelocityServer.java @@ -54,6 +54,7 @@ import com.velocitypowered.proxy.scheduler.VelocityScheduler; import com.velocitypowered.proxy.server.ServerMap; import com.velocitypowered.proxy.util.AddressUtil; import com.velocitypowered.proxy.util.EncryptionUtils; +import com.velocitypowered.proxy.util.FileSystemUtils; import com.velocitypowered.proxy.util.VelocityChannelRegistrar; import com.velocitypowered.proxy.util.bossbar.AdventureBossBarManager; import com.velocitypowered.proxy.util.ratelimit.Ratelimiter; @@ -246,9 +247,43 @@ public class VelocityServer implements ProxyServer, ForwardingAudience { private void registerTranslations() { final TranslationRegistry translationRegistry = TranslationRegistry .create(Key.key("velocity", "translations")); - translationRegistry.registerAll(Locale.US, - ResourceBundle.getBundle("com/velocitypowered/proxy/messages", Locale.US, - UTF8ResourceBundleControl.get()), false); + try { + FileSystemUtils.visitResources(VelocityServer.class, + Paths.get("com", "velocitypowered", "proxy", "l10n"), path -> { + logger.info("Loading localizations..."); + + try { + Files.walk(path).forEach(file -> { + if (!Files.isRegularFile(file)) { + return; + } + + String filename = com.google.common.io.Files + .getNameWithoutExtension(file.getFileName().toString()); + String localeName = filename.replace("messages_", "") + .replace("messages", "") + .replace('_', '-'); + Locale locale; + if (localeName.isEmpty()) { + locale = Locale.US; + } else { + locale = Locale.forLanguageTag(localeName); + } + + translationRegistry.registerAll(locale, + ResourceBundle.getBundle("com/velocitypowered/proxy/l10n/messages", + locale, UTF8ResourceBundleControl.get()), false); + }); + } catch (IOException e) { + logger.error("Encountered an I/O error whilst loading translations", e); + System.exit(1); + } + }); + } catch (IOException e) { + logger.error("Encountered an I/O error whilst loading translations", e); + System.exit(1); + return; + } GlobalTranslator.get().addSource(translationRegistry); } diff --git a/proxy/src/main/java/com/velocitypowered/proxy/command/builtin/VelocityCommand.java b/proxy/src/main/java/com/velocitypowered/proxy/command/builtin/VelocityCommand.java index c2fee2570..eb9394b23 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/command/builtin/VelocityCommand.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/command/builtin/VelocityCommand.java @@ -226,8 +226,8 @@ public class VelocityCommand implements SimpleCommand { .translatable("velocity.command.version-copyright", Component.text(version.getVendor()), Component.text(version.getName())); - source.sendMessage(Identity.nil(), velocity); - source.sendMessage(Identity.nil(), copyright); + source.sendMessage(velocity); + source.sendMessage(copyright); if (version.getName().equals("Velocity")) { TextComponent embellishment = Component.text() diff --git a/proxy/src/main/java/com/velocitypowered/proxy/util/FileSystemUtils.java b/proxy/src/main/java/com/velocitypowered/proxy/util/FileSystemUtils.java new file mode 100644 index 000000000..27fb7f75a --- /dev/null +++ b/proxy/src/main/java/com/velocitypowered/proxy/util/FileSystemUtils.java @@ -0,0 +1,56 @@ +package com.velocitypowered.proxy.util; + +import java.io.File; +import java.io.IOException; +import java.net.URI; +import java.net.URISyntaxException; +import java.net.URL; +import java.nio.file.FileSystem; +import java.nio.file.FileSystems; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.Collections; +import java.util.function.Consumer; + +public class FileSystemUtils { + + /** + * Visits the resources at the given {@link Path} within the resource + * path of the given {@link Class}. + * + * @param target The target class of the resource path to scan + * @param path The path to scan within the resource path + * @param consumer The consumer to visit the resolved path + */ + public static boolean visitResources(Class target, Path path, Consumer consumer) + throws IOException { + final File file = new File(target + .getProtectionDomain().getCodeSource().getLocation().getPath()); + + if (file.isFile()) { // jar + URI uri = file.toURI(); + try (FileSystem fileSystem = FileSystems.newFileSystem(uri, Collections.emptyMap())) { + Path toVisit = fileSystem.getPath(path.toString()); + if (Files.exists(toVisit)) { + consumer.accept(toVisit); + return true; + } + return false; + } + } else { + URI uri; + try { + URL url = target.getClassLoader().getResource(path.toString()); + if (url == null) { + return false; + } + uri = url.toURI(); + } catch (URISyntaxException e) { + throw new IllegalStateException(e); + } + consumer.accept(Paths.get(uri)); + return true; + } + } +} diff --git a/proxy/src/main/resources/com/velocitypowered/proxy/messages.properties b/proxy/src/main/resources/com/velocitypowered/proxy/l10n/messages.properties similarity index 96% rename from proxy/src/main/resources/com/velocitypowered/proxy/messages.properties rename to proxy/src/main/resources/com/velocitypowered/proxy/l10n/messages.properties index df291dc77..fedbb6359 100644 --- a/proxy/src/main/resources/com/velocitypowered/proxy/messages.properties +++ b/proxy/src/main/resources/com/velocitypowered/proxy/l10n/messages.properties @@ -27,7 +27,7 @@ velocity.error.online-mode-only=You are not logged into your Minecraft account. velocity.error.player-connection-error=An internal error occurred in your connection. velocity.error.modern-forwarding-needs-new-client=This server is only compatible with Minecraft 1.13 and above. velocity.error.modern-forwarding-failed=Your server did not send a forwarding request to the proxy. Make sure the server is configured for Velocity forwarding. -velocity.error.moved-to-new-server=YOu were kicked from {0}: {1} +velocity.error.moved-to-new-server=You were kicked from {0}: {1} velocity.error.no-available-servers=There are no available servers to connect you to. Try again later or contact an admin. # Commands diff --git a/proxy/src/main/resources/com/velocitypowered/proxy/l10n/messages_en_UD.properties b/proxy/src/main/resources/com/velocitypowered/proxy/l10n/messages_en_UD.properties new file mode 100644 index 000000000..47fb0ba3e --- /dev/null +++ b/proxy/src/main/resources/com/velocitypowered/proxy/l10n/messages_en_UD.properties @@ -0,0 +1,62 @@ +# +# 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 . +# + +velocity.error.already-connected=¡ɹǝʌɹǝs sᴉɥʇ oʇ pǝʇɔǝuuoɔ ʎpɐǝɹlɐ ǝɹɐ no⅄ +velocity.error.already-connected-proxy=¡ʎxoɹd sᴉɥʇ oʇ pǝʇɔǝuuoɔ ʎpɐǝɹlɐ ǝɹɐ no⅄ +velocity.error.already-connecting=¡ɹǝʌɹǝs ɐ oʇ ʇɔǝuuoɔ oʇ ƃuᴉʎɹʇ ʎpɐǝɹlɐ ǝɹɐ no⅄ +velocity.error.cant-connect={1} :{0} oʇ ʇɔǝuuoɔ oʇ ǝlqɐu∩ +velocity.error.connecting-server-error=˙ɹǝʇɐl uᴉɐƃɐ ʎɹʇ ǝsɐǝlԀ ˙{0} oʇ noʎ ʇɔǝuuoɔ oʇ ǝlqɐu∩ +velocity.error.connected-server-error=˙ɯǝlqoɹd ɐ pǝɹǝʇunoɔuǝ {0} oʇ uoᴉʇɔǝuuoɔ ɹno⅄ +velocity.error.internal-server-connection-error=˙pǝɹɹnɔɔo ɹoɹɹǝ uoᴉʇɔǝuuoɔ ɹǝʌɹǝs lɐuɹǝʇuᴉ u∀ +velocity.error.logging-in-too-fast=˙ɹǝʇɐl uᴉɐƃɐ ʎɹʇ 'ʇsɐɟ ooʇ uᴉ ƃuᴉƃƃol ǝɹɐ no⅄ +velocity.error.online-mode-only=˙ʇuǝᴉlɔ ʇɟɐɹɔǝuᴉW ɹnoʎ ƃuᴉʇɹɐʇsǝɹ ʎɹʇ 'ʇunoɔɔɐ ʇɟɐɹɔǝuᴉW ɹnoʎ oʇuᴉ pǝƃƃol ǝɹɐ noʎ ɟI ˙ʇunoɔɔɐ ʇɟɐɹɔǝuᴉW ɹnoʎ oʇuᴉ pǝƃƃol ʇou ǝɹɐ no⅄ +velocity.error.player-connection-error=˙uoᴉʇɔǝuuoɔ ɹnoʎ uᴉ pǝɹɹnɔɔo ɹoɹɹǝ lɐuɹǝʇuᴉ u∀ +velocity.error.modern-forwarding-needs-new-client=˙ǝʌoqɐ puɐ ƐƖ˙Ɩ ʇɟɐɹɔǝuᴉW ɥʇᴉʍ ǝlqᴉʇɐdɯoɔ ʎluo sᴉ ɹǝʌɹǝs sᴉɥ┴ +velocity.error.modern-forwarding-failed=˙ƃuᴉpɹɐʍɹoɟ ʎʇᴉɔolǝΛ ɹoɟ pǝɹnƃᴉɟuoɔ sᴉ ɹǝʌɹǝs ǝɥʇ ǝɹns ǝʞɐW ˙ʎxoɹd ǝɥʇ oʇ ʇsǝnbǝɹ ƃuᴉpɹɐʍɹoɟ ɐ puǝs ʇou pᴉp ɹǝʌɹǝs ɹno⅄ +velocity.error.moved-to-new-server={1} :{0} ɯoɹɟ pǝʞɔᴉʞ ǝɹǝʍ no⅄ +velocity.error.no-available-servers=˙uᴉɯpɐ uɐ ʇɔɐʇuoɔ ɹo ɹǝʇɐl uᴉɐƃɐ ʎɹ┴ ˙oʇ noʎ ʇɔǝuuoɔ oʇ sɹǝʌɹǝs ǝlqɐlᴉɐʌɐ ou ǝɹɐ ǝɹǝɥ┴ + +# Commands +velocity.command.generic-error=˙puɐɯɯoɔ sᴉɥʇ ƃuᴉuunɹ ǝlᴉɥʍ pǝɹɹnɔɔo ɹoɹɹǝ u∀ +velocity.command.command-does-not-exist=˙ʇsᴉxǝ ʇou sǝop puɐɯɯoɔ sᴉɥ┴ + +velocity.command.players-only=Only players can run this command. +velocity.command.server-does-not-exist=˙puɐɯɯoɔ sᴉɥʇ unɹ uɐɔ sɹǝʎɐld ʎluO + +velocity.command.server-current-server=˙{0} oʇ pǝʇɔǝuuoɔ ʎlʇuǝɹɹnɔ ǝɹɐ no⅄ +velocity.command.server-too-many=˙sʇunoɔ ɹǝʌɹǝs lɐnpᴉʌᴉpuᴉ ʇǝƃ oʇ uoᴉʇǝldɯoɔ qɐʇ ǝs∩ ˙dn ʇǝs sɹǝʌɹǝs ʎuɐɯ ooʇ ǝɹɐ ǝɹǝɥ┴ +velocity.command.server-available=:sɹǝʌɹǝs ǝlqɐlᴉɐʌ∀ +velocity.command.server-tooltip-player-online=ǝuᴉluo ɹǝʎɐld {0} +velocity.command.server-tooltip-players-online=ǝuᴉluo sɹǝʎɐld {0} +velocity.command.server-tooltip-current-server=ɹǝʌɹǝs sᴉɥʇ oʇ pǝʇɔǝuuoɔ ʎlʇuǝɹɹnƆ +velocity.command.server-tooltip-offer-connect-server=ɹǝʌɹǝs sᴉɥʇ oʇ ʇɔǝuuoɔ oʇ ʞɔᴉlƆ + +velocity.command.glist-player-singular=ɹǝʎɐld +velocity.command.glist-player-plural=sɹǝʎɐld +velocity.command.glist-total-suffix=˙ʎxoɹd ǝɥʇ oʇ pǝʇɔǝuuoɔ ʎlʇuǝɹɹnɔ ǝɹɐ +velocity.command.glist-view-all=˙/glist all ǝsn 'sɹǝʌɹǝs uo sɹǝʎɐld llɐ ʍǝᴉʌ o┴ + +velocity.command.reload-success=˙pǝpɐolǝɹ ʎllnɟssǝɔɔns uoᴉʇɐɹnƃᴉɟuoɔ ʎʇᴉɔolǝΛ +velocity.command.reload-failure=˙slᴉɐʇǝp ǝɹoɯ ɹoɟ ǝlosuoɔ ǝɥʇ ʞɔǝɥƆ ˙uoᴉʇɐɹnƃᴉɟuoɔ ʎʇᴉɔolǝΛ ɹnoʎ pɐolǝɹ oʇ ǝlqɐu∩ + +velocity.command.version-copyright=˙Ɛʌ ǝsuǝɔᴉ˥ ɔᴉlqnԀ lɐɹǝuǝפ ∩Nפ ǝɥʇ ɟo sɯɹǝʇ ǝɥʇ ɹǝpun pǝsuǝɔᴉl sᴉ {1} ˙{0} Ɩᄅ0ᄅ-8Ɩ0ᄅ ʇɥƃᴉɹʎdoƆ + +velocity.command.no-plugins=˙pǝllɐʇsuᴉ ʎlʇuǝɹɹnɔ suᴉƃnld ou ǝɹɐ ǝɹǝɥ┴ +velocity.command.plugins-list={0}: suᴉƃnlԀ +velocity.command.plugin-tooltip-website={0}: ǝʇᴉsqǝM +velocity.command.plugin-tooltip-author={0}: ɹoɥʇn∀ +velocity.command.plugin-tooltip-authors={0}: sɹoɥʇn∀ \ No newline at end of file From 3209103317ba5821bb4f05a1f28f113294c75077 Mon Sep 17 00:00:00 2001 From: Andrew Steinborn Date: Sat, 17 Apr 2021 09:01:21 -0400 Subject: [PATCH 40/99] Licensing fun --- .../proxy/util/FileSystemUtils.java | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/proxy/src/main/java/com/velocitypowered/proxy/util/FileSystemUtils.java b/proxy/src/main/java/com/velocitypowered/proxy/util/FileSystemUtils.java index 27fb7f75a..f103457ba 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/util/FileSystemUtils.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/util/FileSystemUtils.java @@ -1,3 +1,20 @@ +/* + * 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 . + */ + package com.velocitypowered.proxy.util; import java.io.File; From 6c369c7d09bda5189bad5f874c4ba4fa99118af0 Mon Sep 17 00:00:00 2001 From: Andrew Steinborn Date: Sat, 17 Apr 2021 09:05:23 -0400 Subject: [PATCH 41/99] Fix SpotBugs stuff --- .../src/main/java/com/velocitypowered/proxy/VelocityServer.java | 2 -- .../java/com/velocitypowered/proxy/util/FileSystemUtils.java | 2 ++ 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/proxy/src/main/java/com/velocitypowered/proxy/VelocityServer.java b/proxy/src/main/java/com/velocitypowered/proxy/VelocityServer.java index 0051f0707..108988372 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/VelocityServer.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/VelocityServer.java @@ -276,12 +276,10 @@ public class VelocityServer implements ProxyServer, ForwardingAudience { }); } catch (IOException e) { logger.error("Encountered an I/O error whilst loading translations", e); - System.exit(1); } }); } catch (IOException e) { logger.error("Encountered an I/O error whilst loading translations", e); - System.exit(1); return; } GlobalTranslator.get().addSource(translationRegistry); diff --git a/proxy/src/main/java/com/velocitypowered/proxy/util/FileSystemUtils.java b/proxy/src/main/java/com/velocitypowered/proxy/util/FileSystemUtils.java index f103457ba..b623481c5 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/util/FileSystemUtils.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/util/FileSystemUtils.java @@ -17,6 +17,7 @@ package com.velocitypowered.proxy.util; +import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; import java.io.File; import java.io.IOException; import java.net.URI; @@ -40,6 +41,7 @@ public class FileSystemUtils { * @param path The path to scan within the resource path * @param consumer The consumer to visit the resolved path */ + @SuppressFBWarnings({"RCN_REDUNDANT_NULLCHECK_WOULD_HAVE_BEEN_A_NPE"}) public static boolean visitResources(Class target, Path path, Consumer consumer) throws IOException { final File file = new File(target From f2ddd391a5eff865b800c7bc4685fe92dc771327 Mon Sep 17 00:00:00 2001 From: Andrew Steinborn Date: Sat, 17 Apr 2021 09:15:34 -0400 Subject: [PATCH 42/99] Fix localization loading from JAR --- .../java/com/velocitypowered/proxy/util/FileSystemUtils.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/proxy/src/main/java/com/velocitypowered/proxy/util/FileSystemUtils.java b/proxy/src/main/java/com/velocitypowered/proxy/util/FileSystemUtils.java index b623481c5..167ee47b0 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/util/FileSystemUtils.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/util/FileSystemUtils.java @@ -48,8 +48,7 @@ public class FileSystemUtils { .getProtectionDomain().getCodeSource().getLocation().getPath()); if (file.isFile()) { // jar - URI uri = file.toURI(); - try (FileSystem fileSystem = FileSystems.newFileSystem(uri, Collections.emptyMap())) { + try (FileSystem fileSystem = FileSystems.newFileSystem(file.toPath(), null)) { Path toVisit = fileSystem.getPath(path.toString()); if (Files.exists(toVisit)) { consumer.accept(toVisit); From c069a0730fbf4434649842b43841fb5ad953fe26 Mon Sep 17 00:00:00 2001 From: Andrew Steinborn Date: Sat, 17 Apr 2021 22:23:04 -0400 Subject: [PATCH 43/99] Fix "too many servers" message --- .../com/velocitypowered/proxy/l10n/messages.properties | 2 +- .../com/velocitypowered/proxy/l10n/messages_en_UD.properties | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/proxy/src/main/resources/com/velocitypowered/proxy/l10n/messages.properties b/proxy/src/main/resources/com/velocitypowered/proxy/l10n/messages.properties index fedbb6359..28314dd44 100644 --- a/proxy/src/main/resources/com/velocitypowered/proxy/l10n/messages.properties +++ b/proxy/src/main/resources/com/velocitypowered/proxy/l10n/messages.properties @@ -38,7 +38,7 @@ velocity.command.players-only=Only players can run this command. velocity.command.server-does-not-exist=The specified server {0} does not exist. velocity.command.server-current-server=You are currently connected to {0}. -velocity.command.server-too-many=There are too many servers set up. Use tab completion to get individual server counts. +velocity.command.server-too-many=There are too many servers set up. Use tab completion to view all servers available. velocity.command.server-available=Available servers: velocity.command.server-tooltip-player-online={0} player online velocity.command.server-tooltip-players-online={0} players online diff --git a/proxy/src/main/resources/com/velocitypowered/proxy/l10n/messages_en_UD.properties b/proxy/src/main/resources/com/velocitypowered/proxy/l10n/messages_en_UD.properties index 47fb0ba3e..1e174330d 100644 --- a/proxy/src/main/resources/com/velocitypowered/proxy/l10n/messages_en_UD.properties +++ b/proxy/src/main/resources/com/velocitypowered/proxy/l10n/messages_en_UD.properties @@ -38,7 +38,7 @@ velocity.command.players-only=Only players can run this command. velocity.command.server-does-not-exist=˙puɐɯɯoɔ sᴉɥʇ unɹ uɐɔ sɹǝʎɐld ʎluO velocity.command.server-current-server=˙{0} oʇ pǝʇɔǝuuoɔ ʎlʇuǝɹɹnɔ ǝɹɐ no⅄ -velocity.command.server-too-many=˙sʇunoɔ ɹǝʌɹǝs lɐnpᴉʌᴉpuᴉ ʇǝƃ oʇ uoᴉʇǝldɯoɔ qɐʇ ǝs∩ ˙dn ʇǝs sɹǝʌɹǝs ʎuɐɯ ooʇ ǝɹɐ ǝɹǝɥ┴ +velocity.command.server-too-many=˙ǝlqɐlᴉɐʌɐ sɹǝʌɹǝs llɐ ʍǝᴉʌ oʇ uoᴉʇǝldɯoɔ qɐʇ ǝs∩ ˙dn ʇǝs sɹǝʌɹǝs ʎuɐɯ ooʇ ǝɹɐ ǝɹǝɥ┴ velocity.command.server-available=:sɹǝʌɹǝs ǝlqɐlᴉɐʌ∀ velocity.command.server-tooltip-player-online=ǝuᴉluo ɹǝʎɐld {0} velocity.command.server-tooltip-players-online=ǝuᴉluo sɹǝʎɐld {0} From ff546226638ddaec57cfc33c14f5e83ce0cee30d Mon Sep 17 00:00:00 2001 From: Andrew Steinborn Date: Sun, 18 Apr 2021 08:20:04 -0400 Subject: [PATCH 44/99] Forced hosts should be case-insensitive. Fixes #464 --- .../proxy/connection/client/ConnectedPlayer.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/proxy/src/main/java/com/velocitypowered/proxy/connection/client/ConnectedPlayer.java b/proxy/src/main/java/com/velocitypowered/proxy/connection/client/ConnectedPlayer.java index 2c7aa7e86..fe49f71ee 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/connection/client/ConnectedPlayer.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/connection/client/ConnectedPlayer.java @@ -79,6 +79,7 @@ import java.net.InetSocketAddress; import java.util.Collection; import java.util.Collections; import java.util.List; +import java.util.Locale; import java.util.Objects; import java.util.Optional; import java.util.UUID; @@ -736,7 +737,9 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player { */ private Optional getNextServerToTry(@Nullable RegisteredServer current) { if (serversToTry == null) { - String virtualHostStr = getVirtualHost().map(InetSocketAddress::getHostString).orElse(""); + String virtualHostStr = getVirtualHost().map(InetSocketAddress::getHostString) + .orElse("") + .toLowerCase(Locale.ROOT); serversToTry = server.getConfiguration().getForcedHosts().getOrDefault(virtualHostStr, Collections.emptyList()); } From ca52f8989e325109ce075900e7caf66fb867ce8f Mon Sep 17 00:00:00 2001 From: Andrew Steinborn Date: Sun, 18 Apr 2021 08:22:36 -0400 Subject: [PATCH 45/99] Load forced hosts as lowercase too, see #464 --- .../proxy/config/VelocityConfiguration.java | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/proxy/src/main/java/com/velocitypowered/proxy/config/VelocityConfiguration.java b/proxy/src/main/java/com/velocitypowered/proxy/config/VelocityConfiguration.java index 12d1e9511..570504636 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/config/VelocityConfiguration.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/config/VelocityConfiguration.java @@ -43,6 +43,7 @@ import java.nio.file.StandardCopyOption; import java.security.SecureRandom; import java.util.HashMap; import java.util.List; +import java.util.Locale; import java.util.Map; import java.util.Optional; import java.util.Random; @@ -600,9 +601,11 @@ public class VelocityConfiguration implements ProxyConfig { Map> forcedHosts = new HashMap<>(); for (UnmodifiableConfig.Entry entry : config.entrySet()) { if (entry.getValue() instanceof String) { - forcedHosts.put(entry.getKey(), ImmutableList.of(entry.getValue())); + forcedHosts.put(entry.getKey().toLowerCase(Locale.ROOT), + ImmutableList.of(entry.getValue())); } else if (entry.getValue() instanceof List) { - forcedHosts.put(entry.getKey(), ImmutableList.copyOf((List) entry.getValue())); + forcedHosts.put(entry.getKey().toLowerCase(Locale.ROOT), + ImmutableList.copyOf((List) entry.getValue())); } else { throw new IllegalStateException( "Invalid value of type " + entry.getValue().getClass() + " in forced hosts!"); From 699314d7ae0367013d8184cf4fbf717a51a94708 Mon Sep 17 00:00:00 2001 From: EasyClifton <63668444+EasyClifton@users.noreply.github.com> Date: Sun, 18 Apr 2021 16:58:09 +0300 Subject: [PATCH 46/99] Create messages_ru.properties Did the translation to Russian. Tho I still have some concerns about the plural forms because Russian has multiple forms for "players". --- .../proxy/l10n/messages_ru.properties | 61 +++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 proxy/src/main/resources/com/velocitypowered/proxy/l10n/messages_ru.properties diff --git a/proxy/src/main/resources/com/velocitypowered/proxy/l10n/messages_ru.properties b/proxy/src/main/resources/com/velocitypowered/proxy/l10n/messages_ru.properties new file mode 100644 index 000000000..0859f70f1 --- /dev/null +++ b/proxy/src/main/resources/com/velocitypowered/proxy/l10n/messages_ru.properties @@ -0,0 +1,61 @@ +# +# 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 . +# + +velocity.error.already-connected=Вы уже подключены к этому серверу! +velocity.error.already-connected-proxy=Вы уже подключены к этому прокси! +velocity.error.already-connecting=Вы уже подключаетесь к серверу! +velocity.error.cant-connect=Не удалось подключиться к {0}: {1} +velocity.error.connecting-server-error=Не удалось подключить вас к {0}. Пожалуйста, попробуйте снова через некоторое время. +velocity.error.connected-server-error=С вашим подключением к {0} возникла проблема. +velocity.error.internal-server-connection-error=На сервере произошла внутренняя ошибка подключения. +velocity.error.logging-in-too-fast=Вы входите слишком быстро, попробуйте снова через некоторое время. +velocity.error.online-mode-only=Вы не вошли в свой аккаунт Minecraft. Если вы уверены, что вошли в аккаунт, попробуйте перезапустить свой клиент Minecraft. +velocity.error.player-connection-error=В вашем подключении произошла внутренняя ошибка. +velocity.error.modern-forwarding-needs-new-client=Этот сервер совместим только с Minecraft 1.13 и выше. +velocity.error.modern-forwarding-failed=Ваш сервер не посылал запрос на переадресацию на прокси-сервер. Убедитесь, что сервер настроен на переадресацию Velocity. +velocity.error.moved-to-new-server=Вы были кикнуты с {0}: {1} +velocity.error.no-available-servers=Нет серверов, доступных для подключения. Попробуйте позже или свяжитесь с администратором. + +# Commands +velocity.command.generic-error=Во время выполнения этой команды произошла ошибка. +velocity.command.command-does-not-exist=Этой команды не существует. + +velocity.command.players-only=Только игроки могут использовать эту команду. +velocity.command.server-does-not-exist=Указанный сервер {0} не существует. + +velocity.command.server-current-server=На данный момент вы подключены к {0}. +velocity.command.server-too-many=Настроено слишком много серверов. Для просмотра всех доступных серверов используйте автозаполнение с помощью клавиши Tab. +velocity.command.server-available=Доступные серверы: +velocity.command.server-tooltip-player-online={0} игрок онлайн +velocity.command.server-tooltip-players-online={0} игрока онлайн +velocity.command.server-tooltip-current-server=Подключен к этому серверу +velocity.command.server-tooltip-offer-connect-server=Кликните, чтобы присоединиться к этому серверу +velocity.command.glist-player-singular=игрок +velocity.command.glist-player-plural=игроки +velocity.command.glist-total-suffix= сейчас подключены к этому прокси. +velocity.command.glist-view-all=Чтобы просмотреть всех игроков на серверах, используйте /glist all. + +velocity.command.reload-success=Конфигурация Velocity успешно перезагружена. +velocity.command.reload-failure=Не удалось перезагрузить вашу конфигурацию Velocity. Проверьте консоль для подробностей. + +velocity.command.version-copyright=Copyright 2018-2021 {0}. {1} лицензирована на условиях GNU General Public License v3. + +velocity.command.no-plugins=Ни одного плагина не установлено. +velocity.command.plugins-list=Плагины: {0} +velocity.command.plugin-tooltip-website=Вебсайт: {0} +velocity.command.plugin-tooltip-author=Автор: {0} +velocity.command.plugin-tooltip-authors=Авторы: {0} From d26d61f0389e922317a76e749f85ebb8edc8045f Mon Sep 17 00:00:00 2001 From: Andrew Steinborn Date: Sun, 18 Apr 2021 11:16:11 -0400 Subject: [PATCH 47/99] Fix pluralization of /glist player summary --- .../proxy/command/builtin/GlistCommand.java | 19 ++++++------------- .../proxy/l10n/messages.properties | 5 ++--- .../proxy/l10n/messages_en_UD.properties | 5 ++--- 3 files changed, 10 insertions(+), 19 deletions(-) diff --git a/proxy/src/main/java/com/velocitypowered/proxy/command/builtin/GlistCommand.java b/proxy/src/main/java/com/velocitypowered/proxy/command/builtin/GlistCommand.java index 6d0f8f947..976a3644a 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/command/builtin/GlistCommand.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/command/builtin/GlistCommand.java @@ -37,6 +37,7 @@ import java.util.Optional; import net.kyori.adventure.identity.Identity; import net.kyori.adventure.text.Component; import net.kyori.adventure.text.TextComponent; +import net.kyori.adventure.text.TranslatableComponent; import net.kyori.adventure.text.format.NamedTextColor; public class GlistCommand { @@ -104,19 +105,11 @@ public class GlistCommand { private void sendTotalProxyCount(CommandSource target) { int online = server.countConnectedPlayers(); - target.sendMessage(Identity.nil(), Component.text() - .append(Component.text(Integer.toString(online), NamedTextColor.GREEN)) - .append(Component.space()) - .append(Component.translatable( - online == 1 - ? "velocity.command.glist-player-singular" - : "velocity.command.glist-player-plural", - NamedTextColor.YELLOW - )) - .append(Component.space()) - .append(Component.translatable("velocity.command.glist-total-suffix", - NamedTextColor.YELLOW)) - .build()); + TranslatableComponent msg = online == 1 + ? Component.translatable("velocity.command.glist-player-singular") + : Component.translatable("velocity.command.glist-player-plural"); + target.sendMessage(msg.color(NamedTextColor.YELLOW) + .args(Component.text(Integer.toString(online), NamedTextColor.GREEN))); } private void sendServerPlayers(CommandSource target, RegisteredServer server, boolean fromAll) { diff --git a/proxy/src/main/resources/com/velocitypowered/proxy/l10n/messages.properties b/proxy/src/main/resources/com/velocitypowered/proxy/l10n/messages.properties index 28314dd44..abde8db10 100644 --- a/proxy/src/main/resources/com/velocitypowered/proxy/l10n/messages.properties +++ b/proxy/src/main/resources/com/velocitypowered/proxy/l10n/messages.properties @@ -45,9 +45,8 @@ velocity.command.server-tooltip-players-online={0} players online velocity.command.server-tooltip-current-server=Currently connected to this server velocity.command.server-tooltip-offer-connect-server=Click to connect to this server -velocity.command.glist-player-singular=player -velocity.command.glist-player-plural=players -velocity.command.glist-total-suffix= are currently connected to the proxy. +velocity.command.glist-player-singular={0} player is currently connected to the proxy. +velocity.command.glist-player-plural={0} players are currently connected to the proxy. velocity.command.glist-view-all=To view all players on servers, use /glist all. velocity.command.reload-success=Velocity configuration successfully reloaded. diff --git a/proxy/src/main/resources/com/velocitypowered/proxy/l10n/messages_en_UD.properties b/proxy/src/main/resources/com/velocitypowered/proxy/l10n/messages_en_UD.properties index 1e174330d..5f3b9abcf 100644 --- a/proxy/src/main/resources/com/velocitypowered/proxy/l10n/messages_en_UD.properties +++ b/proxy/src/main/resources/com/velocitypowered/proxy/l10n/messages_en_UD.properties @@ -45,9 +45,8 @@ velocity.command.server-tooltip-players-online=ǝuᴉluo sɹǝʎɐld {0} velocity.command.server-tooltip-current-server=ɹǝʌɹǝs sᴉɥʇ oʇ pǝʇɔǝuuoɔ ʎlʇuǝɹɹnƆ velocity.command.server-tooltip-offer-connect-server=ɹǝʌɹǝs sᴉɥʇ oʇ ʇɔǝuuoɔ oʇ ʞɔᴉlƆ -velocity.command.glist-player-singular=ɹǝʎɐld -velocity.command.glist-player-plural=sɹǝʎɐld -velocity.command.glist-total-suffix=˙ʎxoɹd ǝɥʇ oʇ pǝʇɔǝuuoɔ ʎlʇuǝɹɹnɔ ǝɹɐ +velocity.command.glist-player-singular=˙ʎxoɹd ǝɥʇ oʇ pǝʇɔǝuuoɔ ʎlʇuǝɹɹnɔ sᴉ ɹǝʎɐld {0} +velocity.command.glist-player-plural=˙ʎxoɹd ǝɥʇ oʇ pǝʇɔǝuuoɔ ʎlʇuǝɹɹnɔ ǝɹɐ sɹǝʎɐld {0} velocity.command.glist-view-all=˙/glist all ǝsn 'sɹǝʌɹǝs uo sɹǝʎɐld llɐ ʍǝᴉʌ o┴ velocity.command.reload-success=˙pǝpɐolǝɹ ʎllnɟssǝɔɔns uoᴉʇɐɹnƃᴉɟuoɔ ʎʇᴉɔolǝΛ From 6ac5643212bd76db6120c62079a2b47a4da8d5cd Mon Sep 17 00:00:00 2001 From: Seppe Volkaerts Date: Sun, 18 Apr 2021 22:54:18 +0200 Subject: [PATCH 48/99] Fix ambiguous newFileSystem method when using Java 13. --- .../java/com/velocitypowered/proxy/util/FileSystemUtils.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/proxy/src/main/java/com/velocitypowered/proxy/util/FileSystemUtils.java b/proxy/src/main/java/com/velocitypowered/proxy/util/FileSystemUtils.java index 167ee47b0..353e638fd 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/util/FileSystemUtils.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/util/FileSystemUtils.java @@ -48,7 +48,7 @@ public class FileSystemUtils { .getProtectionDomain().getCodeSource().getLocation().getPath()); if (file.isFile()) { // jar - try (FileSystem fileSystem = FileSystems.newFileSystem(file.toPath(), null)) { + try (FileSystem fileSystem = FileSystems.newFileSystem(file.toPath(), (ClassLoader) null)) { Path toVisit = fileSystem.getPath(path.toString()); if (Files.exists(toVisit)) { consumer.accept(toVisit); From 5024e432f87880d72c92e5a7c8201f43d4a48591 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fabian=20M=C3=A4kil=C3=A4?= <44451855+FaberoM@users.noreply.github.com> Date: Mon, 19 Apr 2021 00:38:48 +0300 Subject: [PATCH 49/99] Add fi_FI translations. --- .../proxy/l10n/messages_fi_FI.properties | 61 +++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 proxy/src/main/resources/com/velocitypowered/proxy/l10n/messages_fi_FI.properties diff --git a/proxy/src/main/resources/com/velocitypowered/proxy/l10n/messages_fi_FI.properties b/proxy/src/main/resources/com/velocitypowered/proxy/l10n/messages_fi_FI.properties new file mode 100644 index 000000000..ea5a308bb --- /dev/null +++ b/proxy/src/main/resources/com/velocitypowered/proxy/l10n/messages_fi_FI.properties @@ -0,0 +1,61 @@ +# +# 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 . +# + +velocity.error.already-connected=Olet jo yhdistänyt tälle palvelimelle! +velocity.error.already-connected-proxy=Olet jo yhdistänyt tälle välityspalvelimelle! +velocity.error.already-connecting=Yrität jo tällä hetkellä yhdistää palvelimeen! +velocity.error.cant-connect={0} ei saatu yhteyttä: {1} +velocity.error.connecting-server-error=Yhteyttä palvelimeen {0} ei voitu muodostaa. Yritä myöhemmin uudelleen. +velocity.error.connected-server-error=Yhteydessäsi palvelimeen {0} tapahtui virhe. +velocity.error.internal-server-connection-error=Virhe tapahtui sisäisessä palvelinyhteydessä. +velocity.error.logging-in-too-fast=Kirjaudut sisään liian nopeasti, yritä uudelleen hetken kuluttua. +velocity.error.online-mode-only=Et ole kirjautuneena Minecraft tilillesi. Jos olet kirjautuneena sisään, yritä pelin uudelleenkäynnistämistä. +velocity.error.player-connection-error=Yhteydessäsi tapahtui sisäinen virhe. +velocity.error.modern-forwarding-needs-new-client=Tämä palvelin on yhteensopiva vain version 1.13 ja ylemmän kanssa. +velocity.error.modern-forwarding-failed=Valitsemasi palvelin ei lähettänyt välityspyyntöä välityspalvelimelle. Tarkista että palvelin on määritetty oikein Velocityä varten. +velocity.error.moved-to-new-server=Sinut potkittiin pois palvelimelta {0}: {1} +velocity.error.no-available-servers=Yhtään palvelinta ei ole tällä hetkellä saatavilla. Yritä myöhemmin uudelleen tai ota yhteyttä palvelimen ylläpitäjään. + +# Commands +velocity.command.generic-error=Virhe tapahtui komentoa suorittaessa. +velocity.command.command-does-not-exist=Tuota komentoa ei ole olemassa. + +velocity.command.players-only=Vain pelaajat voivat käyttää tuota komentoa. +velocity.command.server-does-not-exist=Palvelinta {0} ei ole olemassa. + +velocity.command.server-current-server=Olet tällä hetkellä yhdistettynä palvelimeen {0}. +velocity.command.server-too-many=Liian monta palvelinta on määritetty. Paina Tab -näppäintä nähdäksesi kaikki saatavilla olevat palvelimet. +velocity.command.server-available=Saatavilla olevat palvelimet: +velocity.command.server-tooltip-player-online={0} pelaaja palvelimella +velocity.command.server-tooltip-players-online={0} pelaajaa palvelimella +velocity.command.server-tooltip-current-server=Yhdistetty tällä hetkellä +velocity.command.server-tooltip-offer-connect-server=Paina yhdistääksesi palvelimelle + +velocity.command.glist-player-singular={0} pelaaja on tällä hetkellä yhdistänyt välityspalvelimelle. +velocity.command.glist-player-plural={0} pelaajaa on tällä hetkellä yhdistänyt välityspalvelimelle. +velocity.command.glist-view-all=Nähdäksesi pelaajat kaikilta palvelimilla, käytä komentoa /glist all. + +velocity.command.reload-success=Velocityn asetukset uudelleenladattiin onnistuneesti. +velocity.command.reload-failure=Velocityn asetusten uudelleenlataus epäonnistui. Tarkista tarkemmat tiedot konsolista. + +velocity.command.version-copyright=Tekijänoikeudet 2018-2021 {0}. {1} on lisensoitu GNU General Public License v3 ehtojen mukaisesti. + +velocity.command.no-plugins=Yhtään lisäosaa(plugin) ei ole asennettu. +velocity.command.plugins-list=Lisäosat: {0} +velocity.command.plugin-tooltip-website=Verkkosivu: {0} +velocity.command.plugin-tooltip-author=Tekijä: {0} +velocity.command.plugin-tooltip-authors=Tekijät: {0} \ No newline at end of file From 71db78e172ddb9ce66ffa34aa7b0ae3f962b71f2 Mon Sep 17 00:00:00 2001 From: Seppe Volkaerts Date: Mon, 19 Apr 2021 01:18:01 +0200 Subject: [PATCH 50/99] Fix the automatic registration of main plugin event listeners. (#471) --- .../velocitypowered/proxy/VelocityServer.java | 2 +- .../proxy/event/VelocityEventManager.java | 29 ++++++++++--------- 2 files changed, 17 insertions(+), 14 deletions(-) diff --git a/proxy/src/main/java/com/velocitypowered/proxy/VelocityServer.java b/proxy/src/main/java/com/velocitypowered/proxy/VelocityServer.java index 108988372..4795f941f 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/VelocityServer.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/VelocityServer.java @@ -330,7 +330,7 @@ public class VelocityServer implements ProxyServer, ForwardingAudience { Optional instance = plugin.instance(); if (instance.isPresent()) { try { - eventManager.register(instance.get(), instance.get()); + eventManager.registerInternally(plugin, instance.get()); } catch (Exception e) { logger.error("Unable to register plugin listener for {}", plugin.description().name().orElse(plugin.description().id()), e); diff --git a/proxy/src/main/java/com/velocitypowered/proxy/event/VelocityEventManager.java b/proxy/src/main/java/com/velocitypowered/proxy/event/VelocityEventManager.java index 1b44e074c..ff25e0fce 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/event/VelocityEventManager.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/event/VelocityEventManager.java @@ -319,7 +319,23 @@ public class VelocityEventManager implements EventManager { if (plugin == listener) { throw new IllegalArgumentException("The plugin main instance is automatically registered."); } + registerInternally(pluginContainer, listener); + } + @Override + @SuppressWarnings("unchecked") + public void register(final Object plugin, final Class eventClass, + final short order, final EventHandler handler) { + final PluginContainer pluginContainer = ensurePlugin(plugin); + requireNonNull(eventClass, "eventClass"); + requireNonNull(handler, "handler"); + + final HandlerRegistration registration = new HandlerRegistration(pluginContainer, order, + eventClass, handler, (EventHandler) handler, AsyncType.SOMETIMES); + register(Collections.singletonList(registration)); + } + + public void registerInternally(final PluginContainer pluginContainer, final Object listener) { final Class targetClass = listener.getClass(); final Map collected = new HashMap<>(); collectMethods(targetClass, collected); @@ -342,19 +358,6 @@ public class VelocityEventManager implements EventManager { register(registrations); } - @Override - @SuppressWarnings("unchecked") - public void register(final Object plugin, final Class eventClass, - final short order, final EventHandler handler) { - final PluginContainer pluginContainer = ensurePlugin(plugin); - requireNonNull(eventClass, "eventClass"); - requireNonNull(handler, "handler"); - - final HandlerRegistration registration = new HandlerRegistration(pluginContainer, order, - eventClass, handler, (EventHandler) handler, AsyncType.SOMETIMES); - register(Collections.singletonList(registration)); - } - @Override public void unregisterListeners(final Object plugin) { final PluginContainer pluginContainer = ensurePlugin(plugin); From efa9f6f303b47317ff2ebb767ff749a4b7109d2f Mon Sep 17 00:00:00 2001 From: Andrew Steinborn Date: Mon, 19 Apr 2021 07:42:11 -0400 Subject: [PATCH 51/99] Make sure we fallback to en_US. Fixes #474 --- .../src/main/java/com/velocitypowered/proxy/VelocityServer.java | 1 + 1 file changed, 1 insertion(+) diff --git a/proxy/src/main/java/com/velocitypowered/proxy/VelocityServer.java b/proxy/src/main/java/com/velocitypowered/proxy/VelocityServer.java index 4795f941f..bd5141ed0 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/VelocityServer.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/VelocityServer.java @@ -247,6 +247,7 @@ public class VelocityServer implements ProxyServer, ForwardingAudience { private void registerTranslations() { final TranslationRegistry translationRegistry = TranslationRegistry .create(Key.key("velocity", "translations")); + translationRegistry.defaultLocale(Locale.US); try { FileSystemUtils.visitResources(VelocityServer.class, Paths.get("com", "velocitypowered", "proxy", "l10n"), path -> { From 6a349d24ac1a31904c6be69540389e165e38029d Mon Sep 17 00:00:00 2001 From: Andrew Steinborn Date: Mon, 19 Apr 2021 07:54:48 -0400 Subject: [PATCH 52/99] Specify an explicit path instead of using Paths.get() to construct it --- .../main/java/com/velocitypowered/proxy/VelocityServer.java | 2 +- .../com/velocitypowered/proxy/util/FileSystemUtils.java | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/proxy/src/main/java/com/velocitypowered/proxy/VelocityServer.java b/proxy/src/main/java/com/velocitypowered/proxy/VelocityServer.java index bd5141ed0..6f915a953 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/VelocityServer.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/VelocityServer.java @@ -250,7 +250,7 @@ public class VelocityServer implements ProxyServer, ForwardingAudience { translationRegistry.defaultLocale(Locale.US); try { FileSystemUtils.visitResources(VelocityServer.class, - Paths.get("com", "velocitypowered", "proxy", "l10n"), path -> { + "com/velocitypowered/proxy/l10n", path -> { logger.info("Loading localizations..."); try { diff --git a/proxy/src/main/java/com/velocitypowered/proxy/util/FileSystemUtils.java b/proxy/src/main/java/com/velocitypowered/proxy/util/FileSystemUtils.java index 353e638fd..0b634b7cf 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/util/FileSystemUtils.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/util/FileSystemUtils.java @@ -42,14 +42,14 @@ public class FileSystemUtils { * @param consumer The consumer to visit the resolved path */ @SuppressFBWarnings({"RCN_REDUNDANT_NULLCHECK_WOULD_HAVE_BEEN_A_NPE"}) - public static boolean visitResources(Class target, Path path, Consumer consumer) + public static boolean visitResources(Class target, String path, Consumer consumer) throws IOException { final File file = new File(target .getProtectionDomain().getCodeSource().getLocation().getPath()); if (file.isFile()) { // jar try (FileSystem fileSystem = FileSystems.newFileSystem(file.toPath(), (ClassLoader) null)) { - Path toVisit = fileSystem.getPath(path.toString()); + Path toVisit = fileSystem.getPath(path); if (Files.exists(toVisit)) { consumer.accept(toVisit); return true; @@ -59,7 +59,7 @@ public class FileSystemUtils { } else { URI uri; try { - URL url = target.getClassLoader().getResource(path.toString()); + URL url = target.getClassLoader().getResource(path); if (url == null) { return false; } From 7c0b62274291f4a0687f29ce9410652ea3fbb1d8 Mon Sep 17 00:00:00 2001 From: Andrew Steinborn Date: Mon, 19 Apr 2021 08:01:58 -0400 Subject: [PATCH 53/99] Try #2 at explicit path --- .../proxy/util/FileSystemUtils.java | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/proxy/src/main/java/com/velocitypowered/proxy/util/FileSystemUtils.java b/proxy/src/main/java/com/velocitypowered/proxy/util/FileSystemUtils.java index 0b634b7cf..1139f004f 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/util/FileSystemUtils.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/util/FileSystemUtils.java @@ -28,7 +28,9 @@ import java.nio.file.FileSystems; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; -import java.util.Collections; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; import java.util.function.Consumer; public class FileSystemUtils { @@ -38,18 +40,20 @@ public class FileSystemUtils { * path of the given {@link Class}. * * @param target The target class of the resource path to scan - * @param path The path to scan within the resource path * @param consumer The consumer to visit the resolved path + * @param firstPathComponent First path component + * @param remainingPathComponents Remaining path components */ @SuppressFBWarnings({"RCN_REDUNDANT_NULLCHECK_WOULD_HAVE_BEEN_A_NPE"}) - public static boolean visitResources(Class target, String path, Consumer consumer) + public static boolean visitResources(Class target, Consumer consumer, + String firstPathComponent, String... remainingPathComponents) throws IOException { final File file = new File(target .getProtectionDomain().getCodeSource().getLocation().getPath()); if (file.isFile()) { // jar try (FileSystem fileSystem = FileSystems.newFileSystem(file.toPath(), (ClassLoader) null)) { - Path toVisit = fileSystem.getPath(path); + Path toVisit = fileSystem.getPath(firstPathComponent, remainingPathComponents); if (Files.exists(toVisit)) { consumer.accept(toVisit); return true; @@ -58,8 +62,12 @@ public class FileSystemUtils { } } else { URI uri; + List componentList = new ArrayList<>(); + componentList.add(firstPathComponent); + componentList.addAll(Arrays.asList(remainingPathComponents)); + try { - URL url = target.getClassLoader().getResource(path); + URL url = target.getClassLoader().getResource(String.join("/", componentList)); if (url == null) { return false; } From 1bd691f91bd23d00f508740330c1286879414186 Mon Sep 17 00:00:00 2001 From: Andrew Steinborn Date: Mon, 19 Apr 2021 08:03:55 -0400 Subject: [PATCH 54/99] Checkstyle strikes again! --- .../velocitypowered/proxy/VelocityServer.java | 53 +++++++++---------- 1 file changed, 26 insertions(+), 27 deletions(-) diff --git a/proxy/src/main/java/com/velocitypowered/proxy/VelocityServer.java b/proxy/src/main/java/com/velocitypowered/proxy/VelocityServer.java index 6f915a953..0b9d49f1d 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/VelocityServer.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/VelocityServer.java @@ -249,36 +249,35 @@ public class VelocityServer implements ProxyServer, ForwardingAudience { .create(Key.key("velocity", "translations")); translationRegistry.defaultLocale(Locale.US); try { - FileSystemUtils.visitResources(VelocityServer.class, - "com/velocitypowered/proxy/l10n", path -> { - logger.info("Loading localizations..."); + FileSystemUtils.visitResources(VelocityServer.class, path -> { + logger.info("Loading localizations..."); - try { - Files.walk(path).forEach(file -> { - if (!Files.isRegularFile(file)) { - return; - } - - String filename = com.google.common.io.Files - .getNameWithoutExtension(file.getFileName().toString()); - String localeName = filename.replace("messages_", "") - .replace("messages", "") - .replace('_', '-'); - Locale locale; - if (localeName.isEmpty()) { - locale = Locale.US; - } else { - locale = Locale.forLanguageTag(localeName); - } - - translationRegistry.registerAll(locale, - ResourceBundle.getBundle("com/velocitypowered/proxy/l10n/messages", - locale, UTF8ResourceBundleControl.get()), false); - }); - } catch (IOException e) { - logger.error("Encountered an I/O error whilst loading translations", e); + try { + Files.walk(path).forEach(file -> { + if (!Files.isRegularFile(file)) { + return; } + + String filename = com.google.common.io.Files + .getNameWithoutExtension(file.getFileName().toString()); + String localeName = filename.replace("messages_", "") + .replace("messages", "") + .replace('_', '-'); + Locale locale; + if (localeName.isEmpty()) { + locale = Locale.US; + } else { + locale = Locale.forLanguageTag(localeName); + } + + translationRegistry.registerAll(locale, + ResourceBundle.getBundle("com/velocitypowered/proxy/l10n/messages", + locale, UTF8ResourceBundleControl.get()), false); }); + } catch (IOException e) { + logger.error("Encountered an I/O error whilst loading translations", e); + } + }, "com", "velocitypowered", "proxy", "l10n"); } catch (IOException e) { logger.error("Encountered an I/O error whilst loading translations", e); return; From 688babb4da94bcca95faf45521f927e928f2cf01 Mon Sep 17 00:00:00 2001 From: Andrew Steinborn Date: Mon, 19 Apr 2021 08:48:42 -0400 Subject: [PATCH 55/99] Actually fix loading locales from paths with spaces in them --- .../proxy/util/FileSystemUtils.java | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/proxy/src/main/java/com/velocitypowered/proxy/util/FileSystemUtils.java b/proxy/src/main/java/com/velocitypowered/proxy/util/FileSystemUtils.java index 1139f004f..591308bcb 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/util/FileSystemUtils.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/util/FileSystemUtils.java @@ -18,7 +18,6 @@ package com.velocitypowered.proxy.util; import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; -import java.io.File; import java.io.IOException; import java.net.URI; import java.net.URISyntaxException; @@ -31,6 +30,7 @@ import java.nio.file.Paths; import java.util.ArrayList; import java.util.Arrays; import java.util.List; +import java.util.Map; import java.util.function.Consumer; public class FileSystemUtils { @@ -48,11 +48,18 @@ public class FileSystemUtils { public static boolean visitResources(Class target, Consumer consumer, String firstPathComponent, String... remainingPathComponents) throws IOException { - final File file = new File(target - .getProtectionDomain().getCodeSource().getLocation().getPath()); + final URL knownResource = FileSystemUtils.class.getClassLoader() + .getResource("default-velocity.toml"); + if (knownResource == null) { + throw new IllegalStateException( + "default-velocity.toml does not exist, don't know where we are"); + } + if (knownResource.getProtocol().equals("jar")) { + // Running from a JAR + String jarPathRaw = knownResource.toString().split("!")[0]; + URI path = URI.create(jarPathRaw + "!/"); - if (file.isFile()) { // jar - try (FileSystem fileSystem = FileSystems.newFileSystem(file.toPath(), (ClassLoader) null)) { + try (FileSystem fileSystem = FileSystems.newFileSystem(path, Map.of("create", "true"))) { Path toVisit = fileSystem.getPath(firstPathComponent, remainingPathComponents); if (Files.exists(toVisit)) { consumer.accept(toVisit); @@ -61,6 +68,7 @@ public class FileSystemUtils { return false; } } else { + // Running from the file system URI uri; List componentList = new ArrayList<>(); componentList.add(firstPathComponent); From 8b38fba08e4cec46ead5539ad6259faeeaee7a1d Mon Sep 17 00:00:00 2001 From: Mariell Hoversholm Date: Wed, 21 Apr 2021 22:21:51 +0200 Subject: [PATCH 56/99] feat: nb_NO and nn_NO localisation (#467) --- .../proxy/l10n/messages_nb_NO.properties | 63 +++++++++++++++++++ .../proxy/l10n/messages_nn_NO.properties | 63 +++++++++++++++++++ 2 files changed, 126 insertions(+) create mode 100644 proxy/src/main/resources/com/velocitypowered/proxy/l10n/messages_nb_NO.properties create mode 100644 proxy/src/main/resources/com/velocitypowered/proxy/l10n/messages_nn_NO.properties diff --git a/proxy/src/main/resources/com/velocitypowered/proxy/l10n/messages_nb_NO.properties b/proxy/src/main/resources/com/velocitypowered/proxy/l10n/messages_nb_NO.properties new file mode 100644 index 000000000..487c856d2 --- /dev/null +++ b/proxy/src/main/resources/com/velocitypowered/proxy/l10n/messages_nb_NO.properties @@ -0,0 +1,63 @@ +# +# 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 . +# + +velocity.error.already-connected=Du er allerede tilkoblet denne serveren! +velocity.error.already-connected-proxy=Du er allerede tilkoblet denne proxyen! +velocity.error.already-connecting=Du tilkobles allerede en server! +velocity.error.cant-connect=Kan ikke koble til {0}: {1} +velocity.error.connecting-server-error=Kan ikke koble deg til {0}. Vennligst prøv igjen senere. +velocity.error.connected-server-error=Din oppkobling mot {0} traff et uventet problem. +velocity.error.internal-server-connection-error=Et internt problem oppstod. +velocity.error.logging-in-too-fast=Du logger inn for raskt, prøv igjen senere. +velocity.error.online-mode-only=Du er ikke innlogget på din Minecraft konto. Om du er innlogget, prøv å restarte din Minecraft klient. +velocity.error.player-connection-error=Et internt problem oppstod. +velocity.error.modern-forwarding-needs-new-client=Denne serveren er bare kompatibel med Minecraft 1.13 og nyere. +velocity.error.modern-forwarding-failed=Din server sendte ikke en viderekoblingsforespørsel til proxyen. Pass på at serveren er konfigurert for Velocity viderekobling. +velocity.error.moved-to-new-server=Du ble sparket ut fra {0}: {1} +velocity.error.no-available-servers=Det finnes ingen tilgjengelige servere å koble deg til. Prøv igjen senere eller kontakt en administrator. + +# Commands +velocity.command.generic-error=En feil oppstod under gjennomføringen av denne kommandoen. +velocity.command.command-does-not-exist=Denne kommandoen finnes ikke. + +velocity.command.players-only=Bare spillere kan utføre denne kommandoen. +velocity.command.server-does-not-exist=Den oppgivne serveren {0} finnes ikke. + +velocity.command.server-current-server=Du er for øyeblikket tilkoblet {0}. +velocity.command.server-too-many=Det er for mange servere satt opp. Bruk tabfullførelse for å se alle tilgjengelige servere. +velocity.command.server-available=Tilgjengelige servere: +velocity.command.server-tooltip-player-online={0} spiller tilkoblet +velocity.command.server-tooltip-players-online={0} spillere tilkoblet +velocity.command.server-tooltip-current-server=Du er for øyeblikket tilkoblet denne serveren +velocity.command.server-tooltip-offer-connect-server=Trykk for å koble til denne serveren + +velocity.command.glist-player-singular={0} spiller er for øyeblikket tilkoblet denne proxyen. +velocity.command.glist-player-plural={0} spillere er for øyeblikket tilkoblet denne proxyen. +velocity.command.glist-view-all=For å se alle tilkoblede spillere, utfør /glist all. + +velocity.command.reload-success=Velocity konfigurasjonen ble lastet inn på nytt. +velocity.command.reload-failure=Kan ikke laste inn Velocity konfigurasjonen din. Sjekk konsollen for mer detaljer. + +velocity.command.version-copyright=Opphavsrett 2018-2021 {0}. {1} er lisensiert under betingelsense av GNU General Public License v3. + +# "plugins" was kept English as that is what most will be familiar with. "tillegg" would be possible, but unnatural. +# Vi velger å beholde "plugins" i engelsk, ettersom det er hva de fleste kjenner til. "tillegg" er mulig, men unaturlig. +velocity.command.no-plugins=Det er ingen plugins installert. +velocity.command.plugins-list=Plugins: {0} +velocity.command.plugin-tooltip-website=Hjemmeside: {0} +velocity.command.plugin-tooltip-author=Skaper: {0} +velocity.command.plugin-tooltip-authors=Skapere: {0} diff --git a/proxy/src/main/resources/com/velocitypowered/proxy/l10n/messages_nn_NO.properties b/proxy/src/main/resources/com/velocitypowered/proxy/l10n/messages_nn_NO.properties new file mode 100644 index 000000000..c089b8c19 --- /dev/null +++ b/proxy/src/main/resources/com/velocitypowered/proxy/l10n/messages_nn_NO.properties @@ -0,0 +1,63 @@ +# +# 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 . +# + +velocity.error.already-connected=Du er allereie tilkopla denne sørvaren! +velocity.error.already-connected-proxy=Du er allereie tilkopla denne proxyen! +velocity.error.already-connecting=Du tilkoplas allereie ein sørvar! +velocity.error.cant-connect=Kan ikkje kopla til {0}: {1} +velocity.error.connecting-server-error=Kan ikkje kopla deg til {0}. Prøv gjerne igjen seinare. +velocity.error.connected-server-error=Din oppkopling mot {0} trefte eit uventa problem. +velocity.error.internal-server-connection-error=Eit internt problem oppstod. +velocity.error.logging-in-too-fast=Du loggar inn for raskt, prøv igjen seinare. +velocity.error.online-mode-only=Du er ikkje innlogga på din Minecraft konto. Dersom du er innlogga, prøv å restarta din Minecraft klient. +velocity.error.player-connection-error=Eit internt problem oppstod. +velocity.error.modern-forwarding-needs-new-client=Denne sørvaren er bare kompatibel med Minecraft 1.13 og nyare. +velocity.error.modern-forwarding-failed=Din server sende ikkje ein vidarekoplingsførespurnad til proxyen. Pass på at sørvaren er konfigurert for Velocity vidarekopling. +velocity.error.moved-to-new-server=Du blei sparka ut frå {0}: {1} +velocity.error.no-available-servers=Det finst ingen tilgjengelege sørvarar å kopla deg til. Prøv igjen seinare eller kontakt ein administrator. + +# Commands +velocity.command.generic-error=Ein feil oppstod under utføringa av denne kommandoen. +velocity.command.command-does-not-exist=Denne kommandoen finst ikkje. + +velocity.command.players-only=Bare spelarar kan utføra denne kommandoen. +velocity.command.server-does-not-exist=Den oppgjevne sørvaren {0} finst ikkje. + +velocity.command.server-current-server=Du er for augneblinken tilkopla {0}. +velocity.command.server-too-many=Det er for mange sørvarar sette opp. Bruk tabfullføring for å sjå alle tilgjengelege sørvarar. +velocity.command.server-available=Tilgjengelege sørvarar: +velocity.command.server-tooltip-player-online={0} spelar tilkopla +velocity.command.server-tooltip-players-online={0} spelarar tilkopla +velocity.command.server-tooltip-current-server=Du er for augneblinken tilkopla denne sørvaren +velocity.command.server-tooltip-offer-connect-server=Trykk for å kopla til denne sørvaren + +velocity.command.glist-player-singular={0} spelar er for augneblinken tilkopla denne proxyen. +velocity.command.glist-player-plural={0} spelare er for augneblinken tilkopla denne proxyen. +velocity.command.glist-view-all=For å sjå alle tilkopla spelarar, gjer /glist all. + +velocity.command.reload-success=Velocity konfigurasjonen blei lasta inn på nytt. +velocity.command.reload-failure=Kan ikkje lasta inn Velocity konfigurasjonen din. Sjekk konsollen for meir detaljar. + +velocity.command.version-copyright=Opphavsrett 2018-2021 {0}. {1} er lisensiert under vilkåra av GNU General Public License v3. + +# "plugins" was kept English as that is what most will be familiar with. "tillegg" would be possible, but unnatural. +# Me veljer å beholda "plugins" i engelsk, då det er kva dei fleiste kjenner til. "tillegg" er mogleg, men unaturleg. +velocity.command.no-plugins=Det er ingen plugins installert. +velocity.command.plugins-list=Plugins: {0} +velocity.command.plugin-tooltip-website=Heimeside: {0} +velocity.command.plugin-tooltip-author=Skapar: {0} +velocity.command.plugin-tooltip-authors=Skaparar: {0} From e416b9fc45aee8cdf08c2869e634f59476acc06c Mon Sep 17 00:00:00 2001 From: Andrew Steinborn Date: Thu, 22 Apr 2021 11:22:55 -0400 Subject: [PATCH 57/99] Reapply f1cb3eb and add the same fix to ping passthrough --- .../proxy/connection/client/ConnectedPlayer.java | 4 +++- .../proxy/connection/client/StatusSessionHandler.java | 2 ++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/proxy/src/main/java/com/velocitypowered/proxy/connection/client/ConnectedPlayer.java b/proxy/src/main/java/com/velocitypowered/proxy/connection/client/ConnectedPlayer.java index 5e432c164..d05f20954 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/connection/client/ConnectedPlayer.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/connection/client/ConnectedPlayer.java @@ -616,7 +616,9 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player { */ private Optional getNextServerToTry(@Nullable RegisteredServer current) { if (serversToTry == null) { - String virtualHostStr = connectedHost().map(InetSocketAddress::getHostString).orElse(""); + String virtualHostStr = connectedHost().map(InetSocketAddress::getHostString) + .orElse("") + .toLowerCase(Locale.ROOT); serversToTry = server.configuration().getForcedHosts().getOrDefault(virtualHostStr, Collections.emptyList()); } diff --git a/proxy/src/main/java/com/velocitypowered/proxy/connection/client/StatusSessionHandler.java b/proxy/src/main/java/com/velocitypowered/proxy/connection/client/StatusSessionHandler.java index 5a9f7cd29..70fac7f61 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/connection/client/StatusSessionHandler.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/connection/client/StatusSessionHandler.java @@ -42,6 +42,7 @@ import io.netty.buffer.ByteBuf; import java.net.InetSocketAddress; import java.util.ArrayList; import java.util.List; +import java.util.Locale; import java.util.Optional; import java.util.concurrent.CompletableFuture; import org.apache.logging.log4j.LogManager; @@ -168,6 +169,7 @@ public class StatusSessionHandler implements MinecraftSessionHandler { return CompletableFuture.completedFuture(constructLocalPing(shownVersion)); } else { String virtualHostStr = inbound.connectedHost().map(InetSocketAddress::getHostString) + .map(str -> str.toLowerCase(Locale.ROOT)) .orElse(""); List serversToTry = server.configuration().getForcedHosts().getOrDefault( virtualHostStr, server.configuration().getAttemptConnectionOrder()); From ce26ae76c2cf93cb25be5356fdfb26f32820436b Mon Sep 17 00:00:00 2001 From: Andrew Steinborn Date: Thu, 22 Apr 2021 11:23:42 -0400 Subject: [PATCH 58/99] Fix case-sensitivity for ping passthrough --- .../proxy/connection/client/StatusSessionHandler.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/proxy/src/main/java/com/velocitypowered/proxy/connection/client/StatusSessionHandler.java b/proxy/src/main/java/com/velocitypowered/proxy/connection/client/StatusSessionHandler.java index d17a419dc..792c5b458 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/connection/client/StatusSessionHandler.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/connection/client/StatusSessionHandler.java @@ -41,6 +41,7 @@ import io.netty.buffer.ByteBuf; import java.net.InetSocketAddress; import java.util.ArrayList; import java.util.List; +import java.util.Locale; import java.util.Optional; import java.util.concurrent.CompletableFuture; import org.apache.logging.log4j.LogManager; @@ -167,6 +168,7 @@ public class StatusSessionHandler implements MinecraftSessionHandler { return CompletableFuture.completedFuture(constructLocalPing(shownVersion)); } else { String virtualHostStr = inbound.getVirtualHost().map(InetSocketAddress::getHostString) + .map(str -> str.toLowerCase(Locale.ROOT)) .orElse(""); List serversToTry = server.getConfiguration().getForcedHosts().getOrDefault( virtualHostStr, server.getConfiguration().getAttemptConnectionOrder()); From 92865b0307e052dcc19a2e958a37a768424cf875 Mon Sep 17 00:00:00 2001 From: Andrew Steinborn Date: Thu, 22 Apr 2021 11:23:57 -0400 Subject: [PATCH 59/99] Velocity 1.1.5 --- build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index a1395e472..3b10333c4 100644 --- a/build.gradle +++ b/build.gradle @@ -17,7 +17,7 @@ allprojects { apply plugin: "com.github.spotbugs" group 'com.velocitypowered' - version '1.1.5-SNAPSHOT' + version '1.1.5' ext { // dependency versions From d7435fcbb67d299296bd98c3d99f6d19dc509fa1 Mon Sep 17 00:00:00 2001 From: Andrew Steinborn Date: Thu, 22 Apr 2021 11:28:49 -0400 Subject: [PATCH 60/99] Velocity 1.1.6-SNAPSHOT --- build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index 3b10333c4..ac9db4ce6 100644 --- a/build.gradle +++ b/build.gradle @@ -17,7 +17,7 @@ allprojects { apply plugin: "com.github.spotbugs" group 'com.velocitypowered' - version '1.1.5' + version '1.1.6-SNAPSHOT' ext { // dependency versions From c729acc829eb2cf473713be73cf7e06fff20f83f Mon Sep 17 00:00:00 2001 From: FabianAdrian Date: Fri, 23 Apr 2021 17:13:33 +0300 Subject: [PATCH 61/99] Change some wording based on suggestions Co-authored-by: Antti --- .../proxy/l10n/messages_fi_FI.properties | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/proxy/src/main/resources/com/velocitypowered/proxy/l10n/messages_fi_FI.properties b/proxy/src/main/resources/com/velocitypowered/proxy/l10n/messages_fi_FI.properties index ea5a308bb..85bffef1f 100644 --- a/proxy/src/main/resources/com/velocitypowered/proxy/l10n/messages_fi_FI.properties +++ b/proxy/src/main/resources/com/velocitypowered/proxy/l10n/messages_fi_FI.properties @@ -15,23 +15,23 @@ # along with this program. If not, see . # -velocity.error.already-connected=Olet jo yhdistänyt tälle palvelimelle! -velocity.error.already-connected-proxy=Olet jo yhdistänyt tälle välityspalvelimelle! +velocity.error.already-connected=Olet jo yhteydessä tälle palvelimelle! +velocity.error.already-connected-proxy=Olet jo yhteydessä tälle välityspalvelimelle! velocity.error.already-connecting=Yrität jo tällä hetkellä yhdistää palvelimeen! velocity.error.cant-connect={0} ei saatu yhteyttä: {1} velocity.error.connecting-server-error=Yhteyttä palvelimeen {0} ei voitu muodostaa. Yritä myöhemmin uudelleen. velocity.error.connected-server-error=Yhteydessäsi palvelimeen {0} tapahtui virhe. -velocity.error.internal-server-connection-error=Virhe tapahtui sisäisessä palvelinyhteydessä. +velocity.error.internal-server-connection-error=Tapahtui palvelimen sisäinen yhteysvirhe. velocity.error.logging-in-too-fast=Kirjaudut sisään liian nopeasti, yritä uudelleen hetken kuluttua. velocity.error.online-mode-only=Et ole kirjautuneena Minecraft tilillesi. Jos olet kirjautuneena sisään, yritä pelin uudelleenkäynnistämistä. velocity.error.player-connection-error=Yhteydessäsi tapahtui sisäinen virhe. -velocity.error.modern-forwarding-needs-new-client=Tämä palvelin on yhteensopiva vain version 1.13 ja ylemmän kanssa. +velocity.error.modern-forwarding-needs-new-client=Tämä palvelin on yhteensopiva vain version 1.13 tai uudemman kanssa. velocity.error.modern-forwarding-failed=Valitsemasi palvelin ei lähettänyt välityspyyntöä välityspalvelimelle. Tarkista että palvelin on määritetty oikein Velocityä varten. velocity.error.moved-to-new-server=Sinut potkittiin pois palvelimelta {0}: {1} velocity.error.no-available-servers=Yhtään palvelinta ei ole tällä hetkellä saatavilla. Yritä myöhemmin uudelleen tai ota yhteyttä palvelimen ylläpitäjään. # Commands -velocity.command.generic-error=Virhe tapahtui komentoa suorittaessa. +velocity.command.generic-error=Komentoa suorittaessa tapahtui virhe. velocity.command.command-does-not-exist=Tuota komentoa ei ole olemassa. velocity.command.players-only=Vain pelaajat voivat käyttää tuota komentoa. @@ -58,4 +58,4 @@ velocity.command.no-plugins=Yhtään lisäosaa(plugin) ei ole asennettu. velocity.command.plugins-list=Lisäosat: {0} velocity.command.plugin-tooltip-website=Verkkosivu: {0} velocity.command.plugin-tooltip-author=Tekijä: {0} -velocity.command.plugin-tooltip-authors=Tekijät: {0} \ No newline at end of file +velocity.command.plugin-tooltip-authors=Tekijät: {0} From 48a69c7cc595ce500803fafa4d3d3c53747e82b0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fabian=20M=C3=A4kil=C3=A4?= <44451855+FaberoM@users.noreply.github.com> Date: Fri, 23 Apr 2021 17:20:26 +0300 Subject: [PATCH 62/99] Add missing hyphen --- .../com/velocitypowered/proxy/l10n/messages_fi_FI.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/proxy/src/main/resources/com/velocitypowered/proxy/l10n/messages_fi_FI.properties b/proxy/src/main/resources/com/velocitypowered/proxy/l10n/messages_fi_FI.properties index 85bffef1f..4e126dea7 100644 --- a/proxy/src/main/resources/com/velocitypowered/proxy/l10n/messages_fi_FI.properties +++ b/proxy/src/main/resources/com/velocitypowered/proxy/l10n/messages_fi_FI.properties @@ -23,7 +23,7 @@ velocity.error.connecting-server-error=Yhteyttä palvelimeen {0} ei voitu muodos velocity.error.connected-server-error=Yhteydessäsi palvelimeen {0} tapahtui virhe. velocity.error.internal-server-connection-error=Tapahtui palvelimen sisäinen yhteysvirhe. velocity.error.logging-in-too-fast=Kirjaudut sisään liian nopeasti, yritä uudelleen hetken kuluttua. -velocity.error.online-mode-only=Et ole kirjautuneena Minecraft tilillesi. Jos olet kirjautuneena sisään, yritä pelin uudelleenkäynnistämistä. +velocity.error.online-mode-only=Et ole kirjautuneena Minecraft-tilillesi. Jos olet kirjautuneena sisään, yritä pelin uudelleenkäynnistämistä. velocity.error.player-connection-error=Yhteydessäsi tapahtui sisäinen virhe. velocity.error.modern-forwarding-needs-new-client=Tämä palvelin on yhteensopiva vain version 1.13 tai uudemman kanssa. velocity.error.modern-forwarding-failed=Valitsemasi palvelin ei lähettänyt välityspyyntöä välityspalvelimelle. Tarkista että palvelin on määritetty oikein Velocityä varten. From 3dc3c40c336113c00d9c9e2010cf848f2176d8e7 Mon Sep 17 00:00:00 2001 From: Andrew Steinborn Date: Fri, 23 Apr 2021 19:01:40 -0400 Subject: [PATCH 63/99] Convert some more packets to use PacketReader/PacketWriter --- .../ClientboundDisconnectPacket.java | 29 ++++--------------- .../ClientboundHeaderAndFooterPacket.java | 14 ++++----- .../ClientboundResourcePackRequestPacket.java | 11 +++---- .../ClientboundServerLoginSuccessPacket.java | 23 +++++++-------- .../ServerboundStatusRequestPacket.java | 2 -- 5 files changed, 26 insertions(+), 53 deletions(-) diff --git a/proxy/src/main/java/com/velocitypowered/proxy/network/packet/clientbound/ClientboundDisconnectPacket.java b/proxy/src/main/java/com/velocitypowered/proxy/network/packet/clientbound/ClientboundDisconnectPacket.java index 12472db77..a4a518dab 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/network/packet/clientbound/ClientboundDisconnectPacket.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/network/packet/clientbound/ClientboundDisconnectPacket.java @@ -31,13 +31,13 @@ import net.kyori.adventure.text.Component; import org.checkerframework.checker.nullness.qual.Nullable; public class ClientboundDisconnectPacket implements Packet { - public static final PacketReader DECODER = PacketReader.method(ClientboundDisconnectPacket::new); - public static final PacketWriter ENCODER = PacketWriter.deprecatedEncode(); + public static final PacketReader DECODER = (buf, version) -> + new ClientboundDisconnectPacket(ProtocolUtils.readString(buf)); + public static final PacketWriter ENCODER = (out, packet, version) -> { + ProtocolUtils.writeString(out, packet.reason); + }; - private @Nullable String reason; - - public ClientboundDisconnectPacket() { - } + private final String reason; public ClientboundDisconnectPacket(String reason) { this.reason = Preconditions.checkNotNull(reason, "reason"); @@ -50,23 +50,6 @@ public class ClientboundDisconnectPacket implements Packet { return reason; } - public void setReason(@Nullable String reason) { - this.reason = reason; - } - - @Override - public void decode(ByteBuf buf, PacketDirection direction, ProtocolVersion version) { - reason = ProtocolUtils.readString(buf); - } - - @Override - public void encode(ByteBuf buf, ProtocolVersion version) { - if (reason == null) { - throw new IllegalStateException("No reason specified."); - } - ProtocolUtils.writeString(buf, reason); - } - @Override public boolean handle(PacketHandler handler) { return handler.handle(this); diff --git a/proxy/src/main/java/com/velocitypowered/proxy/network/packet/clientbound/ClientboundHeaderAndFooterPacket.java b/proxy/src/main/java/com/velocitypowered/proxy/network/packet/clientbound/ClientboundHeaderAndFooterPacket.java index 1bfa98756..2f53d8d62 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/network/packet/clientbound/ClientboundHeaderAndFooterPacket.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/network/packet/clientbound/ClientboundHeaderAndFooterPacket.java @@ -22,6 +22,7 @@ import static com.velocitypowered.proxy.network.ProtocolUtils.writeString; import com.google.common.base.MoreObjects; import com.google.common.base.Preconditions; import com.velocitypowered.api.network.ProtocolVersion; +import com.velocitypowered.proxy.network.ProtocolUtils; import com.velocitypowered.proxy.network.packet.Packet; import com.velocitypowered.proxy.network.packet.PacketHandler; import com.velocitypowered.proxy.network.packet.PacketReader; @@ -29,8 +30,11 @@ import com.velocitypowered.proxy.network.packet.PacketWriter; import io.netty.buffer.ByteBuf; public class ClientboundHeaderAndFooterPacket implements Packet { - public static final PacketReader DECODER = PacketReader.method(ClientboundHeaderAndFooterPacket::new); - public static final PacketWriter ENCODER = PacketWriter.deprecatedEncode(); + public static final PacketReader DECODER = PacketReader.unsupported(); + public static final PacketWriter ENCODER = (out, packet, version) -> { + writeString(out, packet.header); + writeString(out, packet.footer); + }; private static final String EMPTY_COMPONENT = "{\"translate\":\"\"}"; private static final ClientboundHeaderAndFooterPacket RESET @@ -48,12 +52,6 @@ public class ClientboundHeaderAndFooterPacket implements Packet { this.footer = Preconditions.checkNotNull(footer, "footer"); } - @Override - public void encode(ByteBuf buf, ProtocolVersion version) { - writeString(buf, header); - writeString(buf, footer); - } - @Override public boolean handle(PacketHandler handler) { return handler.handle(this); diff --git a/proxy/src/main/java/com/velocitypowered/proxy/network/packet/clientbound/ClientboundResourcePackRequestPacket.java b/proxy/src/main/java/com/velocitypowered/proxy/network/packet/clientbound/ClientboundResourcePackRequestPacket.java index 599bfa1ae..6d2e055b5 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/network/packet/clientbound/ClientboundResourcePackRequestPacket.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/network/packet/clientbound/ClientboundResourcePackRequestPacket.java @@ -33,7 +33,10 @@ public class ClientboundResourcePackRequestPacket implements Packet { final String hash = ProtocolUtils.readString(buf); return new ClientboundResourcePackRequestPacket(url, hash); }; - public static final PacketWriter ENCODER = PacketWriter.deprecatedEncode(); + public static final PacketWriter ENCODER = (out, packet, version) -> { + ProtocolUtils.writeString(out, packet.url); + ProtocolUtils.writeString(out, packet.hash); + }; private final String url; private final String hash; @@ -43,12 +46,6 @@ public class ClientboundResourcePackRequestPacket implements Packet { this.hash = Objects.requireNonNull(hash, "hash"); } - @Override - public void encode(ByteBuf buf, ProtocolVersion protocolVersion) { - ProtocolUtils.writeString(buf, url); - ProtocolUtils.writeString(buf, hash); - } - @Override public boolean handle(PacketHandler handler) { return handler.handle(this); diff --git a/proxy/src/main/java/com/velocitypowered/proxy/network/packet/clientbound/ClientboundServerLoginSuccessPacket.java b/proxy/src/main/java/com/velocitypowered/proxy/network/packet/clientbound/ClientboundServerLoginSuccessPacket.java index 54ca5d114..40055510a 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/network/packet/clientbound/ClientboundServerLoginSuccessPacket.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/network/packet/clientbound/ClientboundServerLoginSuccessPacket.java @@ -42,7 +42,16 @@ public class ClientboundServerLoginSuccessPacket implements Packet { final String username = ProtocolUtils.readString(buf, 16); return new ClientboundServerLoginSuccessPacket(uuid, username); }; - public static final PacketWriter ENCODER = PacketWriter.deprecatedEncode(); + public static final PacketWriter ENCODER = (out, packet, version) -> { + if (version.gte(ProtocolVersion.MINECRAFT_1_16)) { + ProtocolUtils.writeUuidIntArray(out, packet.uuid); + } else if (version.gte(ProtocolVersion.MINECRAFT_1_7_6)) { + ProtocolUtils.writeString(out, packet.uuid.toString()); + } else { + ProtocolUtils.writeString(out, UuidUtils.toUndashed(packet.uuid)); + } + ProtocolUtils.writeString(out, packet.username); + }; private final UUID uuid; private final String username; @@ -52,18 +61,6 @@ public class ClientboundServerLoginSuccessPacket implements Packet { this.username = Objects.requireNonNull(username, "username"); } - @Override - public void encode(ByteBuf buf, ProtocolVersion version) { - if (version.gte(ProtocolVersion.MINECRAFT_1_16)) { - ProtocolUtils.writeUuidIntArray(buf, uuid); - } else if (version.gte(ProtocolVersion.MINECRAFT_1_7_6)) { - ProtocolUtils.writeString(buf, uuid.toString()); - } else { - ProtocolUtils.writeString(buf, UuidUtils.toUndashed(uuid)); - } - ProtocolUtils.writeString(buf, username); - } - @Override public boolean handle(PacketHandler handler) { return handler.handle(this); diff --git a/proxy/src/main/java/com/velocitypowered/proxy/network/packet/serverbound/ServerboundStatusRequestPacket.java b/proxy/src/main/java/com/velocitypowered/proxy/network/packet/serverbound/ServerboundStatusRequestPacket.java index 34562d9ab..8db8ab693 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/network/packet/serverbound/ServerboundStatusRequestPacket.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/network/packet/serverbound/ServerboundStatusRequestPacket.java @@ -17,12 +17,10 @@ package com.velocitypowered.proxy.network.packet.serverbound; -import com.velocitypowered.api.network.ProtocolVersion; import com.velocitypowered.proxy.network.packet.Packet; import com.velocitypowered.proxy.network.packet.PacketHandler; import com.velocitypowered.proxy.network.packet.PacketReader; import com.velocitypowered.proxy.network.packet.PacketWriter; -import io.netty.buffer.ByteBuf; public class ServerboundStatusRequestPacket implements Packet { public static final ServerboundStatusRequestPacket INSTANCE = new ServerboundStatusRequestPacket(); From f00b9b73ead178340c3b023b131da2a179683876 Mon Sep 17 00:00:00 2001 From: Andrew Steinborn Date: Fri, 23 Apr 2021 19:16:47 -0400 Subject: [PATCH 64/99] Make ServerboundHandshakePacket immutable --- .../proxy/connection/InboundConnection.java | 2 +- .../backend/VelocityServerConnection.java | 43 ++++++++--------- .../connection/client/ConnectedPlayer.java | 5 +- .../client/HandshakeSessionHandler.java | 2 +- .../client/InitialInboundConnection.java | 2 +- .../client/LoginSessionHandler.java | 4 +- .../client/StatusSessionHandler.java | 2 +- .../ServerboundHandshakePacket.java | 46 ++++--------------- .../proxy/server/PingSessionHandler.java | 21 +++++---- 9 files changed, 52 insertions(+), 75 deletions(-) diff --git a/api/src/main/java/com/velocitypowered/api/proxy/connection/InboundConnection.java b/api/src/main/java/com/velocitypowered/api/proxy/connection/InboundConnection.java index 4652899f1..c03adb9a8 100644 --- a/api/src/main/java/com/velocitypowered/api/proxy/connection/InboundConnection.java +++ b/api/src/main/java/com/velocitypowered/api/proxy/connection/InboundConnection.java @@ -29,7 +29,7 @@ public interface InboundConnection { * * @return the hostname from the client */ - Optional connectedHost(); + Optional connectedHostname(); /** * Determine whether or not the player remains online. diff --git a/proxy/src/main/java/com/velocitypowered/proxy/connection/backend/VelocityServerConnection.java b/proxy/src/main/java/com/velocitypowered/proxy/connection/backend/VelocityServerConnection.java index 197272884..23b3a4411 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/connection/backend/VelocityServerConnection.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/connection/backend/VelocityServerConnection.java @@ -118,8 +118,8 @@ public class VelocityServerConnection implements MinecraftConnectionAssociation, return result; } - private String getHandshakeRemoteAddress() { - return proxyPlayer.connectedHost().map(InetSocketAddress::getHostString).orElse(""); + private String playerConnectedHostname() { + return proxyPlayer.connectedHostname().map(InetSocketAddress::getHostString).orElse(""); } private String createLegacyForwardingAddress(UnaryOperator> propertiesTransform) { @@ -128,10 +128,10 @@ public class VelocityServerConnection implements MinecraftConnectionAssociation, // UUID (undashed), and if you are in online-mode, their login properties (from Mojang). SocketAddress playerRemoteAddress = proxyPlayer.remoteAddress(); if (!(playerRemoteAddress instanceof InetSocketAddress)) { - return getHandshakeRemoteAddress(); + return playerConnectedHostname(); } StringBuilder data = new StringBuilder() - .append(getHandshakeRemoteAddress()) + .append(playerConnectedHostname()) .append('\0') .append(((InetSocketAddress) proxyPlayer.remoteAddress()).getHostString()) .append('\0') @@ -162,24 +162,12 @@ public class VelocityServerConnection implements MinecraftConnectionAssociation, // Initiate the handshake. ProtocolVersion protocolVersion = proxyPlayer.getConnection().getProtocolVersion(); - ServerboundHandshakePacket handshake = new ServerboundHandshakePacket(); - handshake.setNextStatus(StateRegistry.LOGIN_ID); - handshake.setProtocolVersion(protocolVersion); - if (forwardingMode == PlayerInfoForwarding.LEGACY) { - handshake.setServerAddress(createLegacyForwardingAddress()); - } else if (forwardingMode == PlayerInfoForwarding.BUNGEEGUARD) { - byte[] secret = server.configuration().getForwardingSecret(); - handshake.setServerAddress(createBungeeGuardForwardingAddress(secret)); - } else if (proxyPlayer.getConnection().getType() == ConnectionTypes.LEGACY_FORGE) { - handshake.setServerAddress(getHandshakeRemoteAddress() + HANDSHAKE_HOSTNAME_TOKEN); - } else { - handshake.setServerAddress(getHandshakeRemoteAddress()); - } - + String address = getHandshakeAddressField(forwardingMode); SocketAddress destinationAddr = registeredServer.serverInfo().address(); - if (destinationAddr instanceof InetSocketAddress) { - handshake.setPort(((InetSocketAddress) destinationAddr).getPort()); - } + int port = destinationAddr instanceof InetSocketAddress + ? ((InetSocketAddress) destinationAddr).getPort() : 0; + ServerboundHandshakePacket handshake = new ServerboundHandshakePacket(protocolVersion, + address, port, StateRegistry.LOGIN_ID); mc.delayedWrite(handshake); mc.setProtocolVersion(protocolVersion); @@ -188,6 +176,19 @@ public class VelocityServerConnection implements MinecraftConnectionAssociation, mc.flush(); } + private String getHandshakeAddressField(PlayerInfoForwarding forwardingMode) { + if (forwardingMode == PlayerInfoForwarding.LEGACY) { + return createLegacyForwardingAddress(); + } else if (forwardingMode == PlayerInfoForwarding.BUNGEEGUARD) { + byte[] secret = server.configuration().getForwardingSecret(); + return createBungeeGuardForwardingAddress(secret); + } else if (proxyPlayer.getConnection().getType() == ConnectionTypes.LEGACY_FORGE) { + return playerConnectedHostname() + HANDSHAKE_HOSTNAME_TOKEN; + } else { + return playerConnectedHostname(); + } + } + public @Nullable MinecraftConnection getConnection() { return connection; } diff --git a/proxy/src/main/java/com/velocitypowered/proxy/connection/client/ConnectedPlayer.java b/proxy/src/main/java/com/velocitypowered/proxy/connection/client/ConnectedPlayer.java index d05f20954..9abe2e542 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/connection/client/ConnectedPlayer.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/connection/client/ConnectedPlayer.java @@ -50,7 +50,6 @@ import com.velocitypowered.api.proxy.server.RegisteredServer; import com.velocitypowered.api.util.GameProfile; import com.velocitypowered.api.util.ModInfo; import com.velocitypowered.proxy.VelocityServer; -import com.velocitypowered.proxy.config.VelocityConfiguration; import com.velocitypowered.proxy.connection.MinecraftConnection; import com.velocitypowered.proxy.connection.MinecraftConnectionAssociation; import com.velocitypowered.proxy.connection.backend.VelocityServerConnection; @@ -238,7 +237,7 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player { } @Override - public Optional connectedHost() { + public Optional connectedHostname() { return Optional.ofNullable(virtualHost); } @@ -616,7 +615,7 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player { */ private Optional getNextServerToTry(@Nullable RegisteredServer current) { if (serversToTry == null) { - String virtualHostStr = connectedHost().map(InetSocketAddress::getHostString) + String virtualHostStr = connectedHostname().map(InetSocketAddress::getHostString) .orElse("") .toLowerCase(Locale.ROOT); serversToTry = server.configuration().getForcedHosts().getOrDefault(virtualHostStr, diff --git a/proxy/src/main/java/com/velocitypowered/proxy/connection/client/HandshakeSessionHandler.java b/proxy/src/main/java/com/velocitypowered/proxy/connection/client/HandshakeSessionHandler.java index 8d9fbf669..c1f6b9b2b 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/connection/client/HandshakeSessionHandler.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/connection/client/HandshakeSessionHandler.java @@ -213,7 +213,7 @@ public class HandshakeSessionHandler implements MinecraftSessionHandler { } @Override - public Optional connectedHost() { + public Optional connectedHostname() { return Optional.ofNullable(ping.getVhost()); } diff --git a/proxy/src/main/java/com/velocitypowered/proxy/connection/client/InitialInboundConnection.java b/proxy/src/main/java/com/velocitypowered/proxy/connection/client/InitialInboundConnection.java index 49571ec9f..a2a383489 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/connection/client/InitialInboundConnection.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/connection/client/InitialInboundConnection.java @@ -54,7 +54,7 @@ public final class InitialInboundConnection implements InboundConnection, } @Override - public Optional connectedHost() { + public Optional connectedHostname() { return Optional.of(InetSocketAddress.createUnresolved(cleanedAddress, handshake.getPort())); } diff --git a/proxy/src/main/java/com/velocitypowered/proxy/connection/client/LoginSessionHandler.java b/proxy/src/main/java/com/velocitypowered/proxy/connection/client/LoginSessionHandler.java index 4acde610d..085dec7ee 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/connection/client/LoginSessionHandler.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/connection/client/LoginSessionHandler.java @@ -58,7 +58,6 @@ import java.security.GeneralSecurityException; import java.security.KeyPair; import java.security.MessageDigest; import java.util.Arrays; -import java.util.Locale; import java.util.Optional; import java.util.UUID; import java.util.concurrent.CompletableFuture; @@ -66,7 +65,6 @@ import java.util.concurrent.ExecutionException; import java.util.concurrent.ThreadLocalRandom; import net.kyori.adventure.text.Component; import net.kyori.adventure.text.format.NamedTextColor; -import net.kyori.adventure.translation.GlobalTranslator; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.asynchttpclient.ListenableFuture; @@ -240,7 +238,7 @@ public class LoginSessionHandler implements MinecraftSessionHandler { // Initiate a regular connection and move over to it. ConnectedPlayer player = new ConnectedPlayer(server, profileEvent.gameProfile(), - mcConnection, inbound.connectedHost().orElse(null), onlineMode); + mcConnection, inbound.connectedHostname().orElse(null), onlineMode); this.connectedPlayer = player; if (!server.canRegisterConnection(player)) { player.disconnect0(Component.translatable("velocity.error.already-connected-proxy", diff --git a/proxy/src/main/java/com/velocitypowered/proxy/connection/client/StatusSessionHandler.java b/proxy/src/main/java/com/velocitypowered/proxy/connection/client/StatusSessionHandler.java index 70fac7f61..36010d7a0 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/connection/client/StatusSessionHandler.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/connection/client/StatusSessionHandler.java @@ -168,7 +168,7 @@ public class StatusSessionHandler implements MinecraftSessionHandler { if (passthrough == PingPassthroughMode.DISABLED) { return CompletableFuture.completedFuture(constructLocalPing(shownVersion)); } else { - String virtualHostStr = inbound.connectedHost().map(InetSocketAddress::getHostString) + String virtualHostStr = inbound.connectedHostname().map(InetSocketAddress::getHostString) .map(str -> str.toLowerCase(Locale.ROOT)) .orElse(""); List serversToTry = server.configuration().getForcedHosts().getOrDefault( diff --git a/proxy/src/main/java/com/velocitypowered/proxy/network/packet/serverbound/ServerboundHandshakePacket.java b/proxy/src/main/java/com/velocitypowered/proxy/network/packet/serverbound/ServerboundHandshakePacket.java index 3fc140266..17beb7a88 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/network/packet/serverbound/ServerboundHandshakePacket.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/network/packet/serverbound/ServerboundHandshakePacket.java @@ -35,15 +35,17 @@ public class ServerboundHandshakePacket implements Packet { final int nextStatus = ProtocolUtils.readVarInt(buf); return new ServerboundHandshakePacket(protocolVersion, hostname, port, nextStatus); }; - public static final PacketWriter ENCODER = PacketWriter.deprecatedEncode(); + public static final PacketWriter ENCODER = (out, packet, version) -> { + ProtocolUtils.writeVarInt(out, packet.protocolVersion.protocol()); + ProtocolUtils.writeString(out, packet.serverAddress); + out.writeShort(packet.port); + ProtocolUtils.writeVarInt(out, packet.nextStatus); + }; - private ProtocolVersion protocolVersion; - private String serverAddress = ""; - private int port; - private int nextStatus; - - public ServerboundHandshakePacket() { - } + private final ProtocolVersion protocolVersion; + private final String serverAddress; + private final int port; + private final int nextStatus; public ServerboundHandshakePacket(final ProtocolVersion protocolVersion, final String hostname, final int port, final int nextStatus) { this.protocolVersion = protocolVersion; @@ -52,14 +54,6 @@ public class ServerboundHandshakePacket implements Packet { this.nextStatus = nextStatus; } - @Override - public void encode(ByteBuf buf, ProtocolVersion ignored) { - ProtocolUtils.writeVarInt(buf, this.protocolVersion.protocol()); - ProtocolUtils.writeString(buf, this.serverAddress); - buf.writeShort(this.port); - ProtocolUtils.writeVarInt(buf, this.nextStatus); - } - @Override public boolean handle(PacketHandler handler) { return handler.handle(this); @@ -69,38 +63,18 @@ public class ServerboundHandshakePacket implements Packet { return protocolVersion; } - @Deprecated - public void setProtocolVersion(ProtocolVersion protocolVersion) { - this.protocolVersion = protocolVersion; - } - public String getServerAddress() { return serverAddress; } - @Deprecated - public void setServerAddress(String serverAddress) { - this.serverAddress = serverAddress; - } - public int getPort() { return port; } - @Deprecated - public void setPort(int port) { - this.port = port; - } - public int getNextStatus() { return nextStatus; } - @Deprecated - public void setNextStatus(int nextStatus) { - this.nextStatus = nextStatus; - } - @Override public String toString() { return MoreObjects.toStringHelper(this) diff --git a/proxy/src/main/java/com/velocitypowered/proxy/server/PingSessionHandler.java b/proxy/src/main/java/com/velocitypowered/proxy/server/PingSessionHandler.java index c290fc587..63e2447d2 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/server/PingSessionHandler.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/server/PingSessionHandler.java @@ -50,20 +50,25 @@ public class PingSessionHandler implements MinecraftSessionHandler { @Override public void activated() { - ServerboundHandshakePacket handshake = new ServerboundHandshakePacket(); - handshake.setNextStatus(StateRegistry.STATUS_ID); - SocketAddress address = server.serverInfo().address(); + String hostname; + int port; if (address instanceof InetSocketAddress) { InetSocketAddress socketAddr = (InetSocketAddress) address; - handshake.setServerAddress(socketAddr.getHostString()); - handshake.setPort(socketAddr.getPort()); + hostname = socketAddr.getHostString(); + port = socketAddr.getPort(); } else { // Just fake it - handshake.setServerAddress("127.0.0.1"); + hostname = "127.0.0.1"; + port = 25565; } - handshake.setProtocolVersion(version); - connection.delayedWrite(handshake); + + connection.delayedWrite(new ServerboundHandshakePacket( + version, + hostname, + port, + StateRegistry.STATUS_ID + )); connection.setState(StateRegistry.STATUS); connection.delayedWrite(ServerboundStatusRequestPacket.INSTANCE); From 81311e7516b826b695f1ba221653c96c221ae10b Mon Sep 17 00:00:00 2001 From: Andrew Steinborn Date: Sun, 25 Apr 2021 10:14:13 -0400 Subject: [PATCH 65/99] Don't attempt to decode empty buffers (fixes #482) Stuff like this makes me want to drop support for <=1.13 versions of Minecraft. --- .../velocitypowered/proxy/protocol/netty/MinecraftDecoder.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/proxy/src/main/java/com/velocitypowered/proxy/protocol/netty/MinecraftDecoder.java b/proxy/src/main/java/com/velocitypowered/proxy/protocol/netty/MinecraftDecoder.java index c648d3e16..5243a6796 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/protocol/netty/MinecraftDecoder.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/protocol/netty/MinecraftDecoder.java @@ -62,7 +62,7 @@ public class MinecraftDecoder extends ChannelInboundHandlerAdapter { } private void tryDecode(ChannelHandlerContext ctx, ByteBuf buf) throws Exception { - if (!ctx.channel().isActive()) { + if (!ctx.channel().isActive() || !buf.isReadable()) { buf.release(); return; } From 347853b94502abf9a7763d2b3029ce087f9514f4 Mon Sep 17 00:00:00 2001 From: Andrew Steinborn Date: Sun, 25 Apr 2021 10:18:58 -0400 Subject: [PATCH 66/99] Disable hinting test for now --- .../com/velocitypowered/proxy/command/CommandManagerTests.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/proxy/src/test/java/com/velocitypowered/proxy/command/CommandManagerTests.java b/proxy/src/test/java/com/velocitypowered/proxy/command/CommandManagerTests.java index b9b40cc35..cdbee1759 100644 --- a/proxy/src/test/java/com/velocitypowered/proxy/command/CommandManagerTests.java +++ b/proxy/src/test/java/com/velocitypowered/proxy/command/CommandManagerTests.java @@ -46,6 +46,7 @@ import java.util.concurrent.ExecutionException; import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicReference; import org.checkerframework.checker.nullness.qual.NonNull; +import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; public class CommandManagerTests { @@ -441,6 +442,8 @@ public class CommandManagerTests { .join().isEmpty()); } + // TODO: Hug needs to fix this test! + @Disabled @Test void testHinting() { VelocityCommandManager manager = createManager(); From 3db2fe8d63162c716b8ac57ae0898027ecd3a7bb Mon Sep 17 00:00:00 2001 From: Andrew Steinborn Date: Mon, 3 May 2021 17:31:32 -0400 Subject: [PATCH 67/99] Optimize varint writing Inspired by the approach described at the bottom of https://richardstartin.github.io/posts/dont-use-protobuf-for-telemetry Given that we do a lot of varint writing as well, this should provide a small performance boost for larger/complex packets whilst not regressing hard on smaller packets. --- .../proxy/protocol/ProtocolUtils.java | 26 ++++++++++++++----- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/proxy/src/main/java/com/velocitypowered/proxy/protocol/ProtocolUtils.java b/proxy/src/main/java/com/velocitypowered/proxy/protocol/ProtocolUtils.java index 50f6c48d0..f7424b05b 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/protocol/ProtocolUtils.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/protocol/ProtocolUtils.java @@ -62,6 +62,17 @@ public enum ProtocolUtils { private static final int DEFAULT_MAX_STRING_SIZE = 65536; // 64KiB private static final QuietDecoderException BAD_VARINT_CACHED = new QuietDecoderException("Bad varint decoded"); + private static final int[] VAR_INT_LENGTHS = new int[33]; + + static { + // Inspired by https://richardstartin.github.io/posts/dont-use-protobuf-for-telemetry + // + // This has been slightly modified in that we reduce the length to 32-bit only, since Velocity + // doesn't look at any part of the Minecraft protocol that requires us to look at VarLongs. + for (int i = 0; i <= 32; ++i) { + VAR_INT_LENGTHS[i] = (31 - i) / 7; + } + } /** * Reads a Minecraft-style VarInt from the specified {@code buf}. @@ -97,21 +108,22 @@ public enum ProtocolUtils { return Integer.MIN_VALUE; } + public static int varintBytes(int value) { + return VAR_INT_LENGTHS[Integer.numberOfLeadingZeros(value)]; + } + /** * Writes a Minecraft-style VarInt to the specified {@code buf}. * @param buf the buffer to read from * @param value the integer to write */ public static void writeVarInt(ByteBuf buf, int value) { - while (true) { - if ((value & 0xFFFFFF80) == 0) { - buf.writeByte(value); - return; - } - - buf.writeByte(value & 0x7F | 0x80); + int length = varintBytes(value); + for (int i = 0; i < length; ++i) { + buf.writeByte(((byte) ((value & 0x7F) | 0x80))); value >>>= 7; } + buf.writeByte((byte) value); } public static String readString(ByteBuf buf) { From e531cdb373c654748f3c819b80a5286d9d431d21 Mon Sep 17 00:00:00 2001 From: Andrew Steinborn Date: Mon, 3 May 2021 18:07:25 -0400 Subject: [PATCH 68/99] Revert "Optimize varint writing" This reverts commit 3db2fe8d63162c716b8ac57ae0898027ecd3a7bb. --- .../proxy/protocol/ProtocolUtils.java | 26 +++++-------------- 1 file changed, 7 insertions(+), 19 deletions(-) diff --git a/proxy/src/main/java/com/velocitypowered/proxy/protocol/ProtocolUtils.java b/proxy/src/main/java/com/velocitypowered/proxy/protocol/ProtocolUtils.java index f7424b05b..50f6c48d0 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/protocol/ProtocolUtils.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/protocol/ProtocolUtils.java @@ -62,17 +62,6 @@ public enum ProtocolUtils { private static final int DEFAULT_MAX_STRING_SIZE = 65536; // 64KiB private static final QuietDecoderException BAD_VARINT_CACHED = new QuietDecoderException("Bad varint decoded"); - private static final int[] VAR_INT_LENGTHS = new int[33]; - - static { - // Inspired by https://richardstartin.github.io/posts/dont-use-protobuf-for-telemetry - // - // This has been slightly modified in that we reduce the length to 32-bit only, since Velocity - // doesn't look at any part of the Minecraft protocol that requires us to look at VarLongs. - for (int i = 0; i <= 32; ++i) { - VAR_INT_LENGTHS[i] = (31 - i) / 7; - } - } /** * Reads a Minecraft-style VarInt from the specified {@code buf}. @@ -108,22 +97,21 @@ public enum ProtocolUtils { return Integer.MIN_VALUE; } - public static int varintBytes(int value) { - return VAR_INT_LENGTHS[Integer.numberOfLeadingZeros(value)]; - } - /** * Writes a Minecraft-style VarInt to the specified {@code buf}. * @param buf the buffer to read from * @param value the integer to write */ public static void writeVarInt(ByteBuf buf, int value) { - int length = varintBytes(value); - for (int i = 0; i < length; ++i) { - buf.writeByte(((byte) ((value & 0x7F) | 0x80))); + while (true) { + if ((value & 0xFFFFFF80) == 0) { + buf.writeByte(value); + return; + } + + buf.writeByte(value & 0x7F | 0x80); value >>>= 7; } - buf.writeByte((byte) value); } public static String readString(ByteBuf buf) { From 4ca97a6df9833ff8b402095698fc9746ab86c1b9 Mon Sep 17 00:00:00 2001 From: Andrew Steinborn Date: Mon, 3 May 2021 19:14:48 -0400 Subject: [PATCH 69/99] Reapply "Optimize varint writing" Inspired by the approach described at the bottom of https://richardstartin.github.io/posts/dont-use-protobuf-for-telemetry Given that we do a lot of varint writing as well, this should provide a small performance boost for larger/complex packets whilst not regressing hard on smaller packets. This includes a test to ensure that the behavior is as expected and fixes the initialization loop so that the correct results will be given. Much thanks to @octylFractal for acting as my duck while trying to figure this out. --- .../proxy/protocol/ProtocolUtils.java | 26 ++++++++---- .../proxy/protocol/ProtocolUtilsTest.java | 42 +++++++++++++++++++ 2 files changed, 61 insertions(+), 7 deletions(-) create mode 100644 proxy/src/test/java/com/velocitypowered/proxy/protocol/ProtocolUtilsTest.java diff --git a/proxy/src/main/java/com/velocitypowered/proxy/protocol/ProtocolUtils.java b/proxy/src/main/java/com/velocitypowered/proxy/protocol/ProtocolUtils.java index 50f6c48d0..6fbecf2bc 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/protocol/ProtocolUtils.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/protocol/ProtocolUtils.java @@ -62,6 +62,17 @@ public enum ProtocolUtils { private static final int DEFAULT_MAX_STRING_SIZE = 65536; // 64KiB private static final QuietDecoderException BAD_VARINT_CACHED = new QuietDecoderException("Bad varint decoded"); + private static final int[] VAR_INT_BYTE_LENGTHS = new int[33]; + + static { + // Inspired by https://richardstartin.github.io/posts/dont-use-protobuf-for-telemetry + // This has been slightly modified in that we reduce the length to 32-bit only, since Velocity + // doesn't look at any part of the Minecraft protocol that requires us to look at VarLongs. + for (int i = 0; i <= 32; ++i) { + VAR_INT_BYTE_LENGTHS[i] = (int) Math.ceil((31d - (i - 1)) / 7d); + } + VAR_INT_BYTE_LENGTHS[32] = 1; // Special case for the number 0. + } /** * Reads a Minecraft-style VarInt from the specified {@code buf}. @@ -97,21 +108,22 @@ public enum ProtocolUtils { return Integer.MIN_VALUE; } + public static int varintBytes(int value) { + return VAR_INT_BYTE_LENGTHS[Integer.numberOfLeadingZeros(value)]; + } + /** * Writes a Minecraft-style VarInt to the specified {@code buf}. * @param buf the buffer to read from * @param value the integer to write */ public static void writeVarInt(ByteBuf buf, int value) { - while (true) { - if ((value & 0xFFFFFF80) == 0) { - buf.writeByte(value); - return; - } - - buf.writeByte(value & 0x7F | 0x80); + int length = varintBytes(value); + for (int i = 0; i < length; ++i) { + buf.writeByte(((byte) ((value & 0x7F) | 0x80))); value >>>= 7; } + buf.writeByte((byte) value); } public static String readString(ByteBuf buf) { diff --git a/proxy/src/test/java/com/velocitypowered/proxy/protocol/ProtocolUtilsTest.java b/proxy/src/test/java/com/velocitypowered/proxy/protocol/ProtocolUtilsTest.java new file mode 100644 index 000000000..35431d81a --- /dev/null +++ b/proxy/src/test/java/com/velocitypowered/proxy/protocol/ProtocolUtilsTest.java @@ -0,0 +1,42 @@ +package com.velocitypowered.proxy.protocol; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +import org.junit.jupiter.api.Test; + +public class ProtocolUtilsTest { + + @Test + void negativeVarIntBytes() { + assertEquals(5, ProtocolUtils.varintBytes(-1)); + assertEquals(5, ProtocolUtils.varintBytes(Integer.MIN_VALUE)); + } + + @Test + void zeroVarIntBytes() { + assertEquals(1, ProtocolUtils.varintBytes(0)); + assertEquals(1, ProtocolUtils.varintBytes(1)); + } + + @Test + void ensureConsistencyAcrossNumberBits() { + for (int i = 0; i <= 31; i++) { + int number = (1 << i) - 1; + assertEquals(conventionalWrittenBytes(number), ProtocolUtils.varintBytes(number), + "mismatch with " + i + "-bit number"); + } + } + + private int conventionalWrittenBytes(int value) { + int wouldBeWritten = 0; + while (true) { + if ((value & ~0x7FL) == 0) { + wouldBeWritten++; + return wouldBeWritten; + } else { + wouldBeWritten++; + value >>>= 7; + } + } + } +} From 0811ebb312267525fc5b6ff0c7e9ef0d3302df11 Mon Sep 17 00:00:00 2001 From: Andrew Steinborn Date: Mon, 3 May 2021 19:18:06 -0400 Subject: [PATCH 70/99] Gotta add the license header to the test file --- .../proxy/protocol/ProtocolUtilsTest.java | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/proxy/src/test/java/com/velocitypowered/proxy/protocol/ProtocolUtilsTest.java b/proxy/src/test/java/com/velocitypowered/proxy/protocol/ProtocolUtilsTest.java index 35431d81a..d48be3742 100644 --- a/proxy/src/test/java/com/velocitypowered/proxy/protocol/ProtocolUtilsTest.java +++ b/proxy/src/test/java/com/velocitypowered/proxy/protocol/ProtocolUtilsTest.java @@ -1,3 +1,20 @@ +/* + * 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 . + */ + package com.velocitypowered.proxy.protocol; import static org.junit.jupiter.api.Assertions.assertEquals; From 0debb81392a70f33781756198133414eed5ba7f1 Mon Sep 17 00:00:00 2001 From: Andrew Steinborn Date: Mon, 3 May 2021 20:08:16 -0400 Subject: [PATCH 71/99] I was nagged to make it more consistent --- .../proxy/protocol/ProtocolUtils.java | 16 ++++++++-------- .../proxy/protocol/ProtocolUtilsTest.java | 10 +++++----- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/proxy/src/main/java/com/velocitypowered/proxy/protocol/ProtocolUtils.java b/proxy/src/main/java/com/velocitypowered/proxy/protocol/ProtocolUtils.java index 6fbecf2bc..2591da8cc 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/protocol/ProtocolUtils.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/protocol/ProtocolUtils.java @@ -61,17 +61,17 @@ public enum ProtocolUtils { private static final int DEFAULT_MAX_STRING_SIZE = 65536; // 64KiB private static final QuietDecoderException BAD_VARINT_CACHED = - new QuietDecoderException("Bad varint decoded"); - private static final int[] VAR_INT_BYTE_LENGTHS = new int[33]; + new QuietDecoderException("Bad VarInt decoded"); + private static final int[] VARINT_BYTE_LENGTHS = new int[33]; static { // Inspired by https://richardstartin.github.io/posts/dont-use-protobuf-for-telemetry // This has been slightly modified in that we reduce the length to 32-bit only, since Velocity // doesn't look at any part of the Minecraft protocol that requires us to look at VarLongs. for (int i = 0; i <= 32; ++i) { - VAR_INT_BYTE_LENGTHS[i] = (int) Math.ceil((31d - (i - 1)) / 7d); + VARINT_BYTE_LENGTHS[i] = (int) Math.ceil((31d - (i - 1)) / 7d); } - VAR_INT_BYTE_LENGTHS[32] = 1; // Special case for the number 0. + VARINT_BYTE_LENGTHS[32] = 1; // Special case for the number 0. } /** @@ -82,7 +82,7 @@ public enum ProtocolUtils { public static int readVarInt(ByteBuf buf) { int read = readVarIntSafely(buf); if (read == Integer.MIN_VALUE) { - throw MinecraftDecoder.DEBUG ? new CorruptedFrameException("Bad varint decoded") + throw MinecraftDecoder.DEBUG ? new CorruptedFrameException("Bad VarInt decoded") : BAD_VARINT_CACHED; } return read; @@ -108,8 +108,8 @@ public enum ProtocolUtils { return Integer.MIN_VALUE; } - public static int varintBytes(int value) { - return VAR_INT_BYTE_LENGTHS[Integer.numberOfLeadingZeros(value)]; + public static int varIntBytes(int value) { + return VARINT_BYTE_LENGTHS[Integer.numberOfLeadingZeros(value)]; } /** @@ -118,7 +118,7 @@ public enum ProtocolUtils { * @param value the integer to write */ public static void writeVarInt(ByteBuf buf, int value) { - int length = varintBytes(value); + int length = varIntBytes(value); for (int i = 0; i < length; ++i) { buf.writeByte(((byte) ((value & 0x7F) | 0x80))); value >>>= 7; diff --git a/proxy/src/test/java/com/velocitypowered/proxy/protocol/ProtocolUtilsTest.java b/proxy/src/test/java/com/velocitypowered/proxy/protocol/ProtocolUtilsTest.java index d48be3742..40800935d 100644 --- a/proxy/src/test/java/com/velocitypowered/proxy/protocol/ProtocolUtilsTest.java +++ b/proxy/src/test/java/com/velocitypowered/proxy/protocol/ProtocolUtilsTest.java @@ -25,21 +25,21 @@ public class ProtocolUtilsTest { @Test void negativeVarIntBytes() { - assertEquals(5, ProtocolUtils.varintBytes(-1)); - assertEquals(5, ProtocolUtils.varintBytes(Integer.MIN_VALUE)); + assertEquals(5, ProtocolUtils.varIntBytes(-1)); + assertEquals(5, ProtocolUtils.varIntBytes(Integer.MIN_VALUE)); } @Test void zeroVarIntBytes() { - assertEquals(1, ProtocolUtils.varintBytes(0)); - assertEquals(1, ProtocolUtils.varintBytes(1)); + assertEquals(1, ProtocolUtils.varIntBytes(0)); + assertEquals(1, ProtocolUtils.varIntBytes(1)); } @Test void ensureConsistencyAcrossNumberBits() { for (int i = 0; i <= 31; i++) { int number = (1 << i) - 1; - assertEquals(conventionalWrittenBytes(number), ProtocolUtils.varintBytes(number), + assertEquals(conventionalWrittenBytes(number), ProtocolUtils.varIntBytes(number), "mismatch with " + i + "-bit number"); } } From c041bea1b6ff82469313094c312f84a9c39e5ffa Mon Sep 17 00:00:00 2001 From: Andrew Steinborn Date: Mon, 3 May 2021 20:17:51 -0400 Subject: [PATCH 72/99] Avoid calling writeVarInt in the (very) common uncompressed packet case --- .../proxy/protocol/netty/MinecraftCompressEncoder.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/proxy/src/main/java/com/velocitypowered/proxy/protocol/netty/MinecraftCompressEncoder.java b/proxy/src/main/java/com/velocitypowered/proxy/protocol/netty/MinecraftCompressEncoder.java index f6cb495ca..356c27231 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/protocol/netty/MinecraftCompressEncoder.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/protocol/netty/MinecraftCompressEncoder.java @@ -39,7 +39,7 @@ public class MinecraftCompressEncoder extends MessageToByteEncoder { int uncompressed = msg.readableBytes(); if (uncompressed < threshold) { // Under the threshold, there is nothing to do. - ProtocolUtils.writeVarInt(out, 0); + out.writeByte(0); out.writeBytes(msg); } else { ProtocolUtils.writeVarInt(out, uncompressed); From 2713831f77722eef4c34160515649ad3dc3cb9da Mon Sep 17 00:00:00 2001 From: Riley Park Date: Mon, 3 May 2021 19:38:39 -0700 Subject: [PATCH 73/99] Revert "Avoid calling writeVarInt in the (very) common uncompressed packet case" This reverts commit c041bea1b6ff82469313094c312f84a9c39e5ffa. --- .../proxy/protocol/netty/MinecraftCompressEncoder.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/proxy/src/main/java/com/velocitypowered/proxy/protocol/netty/MinecraftCompressEncoder.java b/proxy/src/main/java/com/velocitypowered/proxy/protocol/netty/MinecraftCompressEncoder.java index 356c27231..f6cb495ca 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/protocol/netty/MinecraftCompressEncoder.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/protocol/netty/MinecraftCompressEncoder.java @@ -39,7 +39,7 @@ public class MinecraftCompressEncoder extends MessageToByteEncoder { int uncompressed = msg.readableBytes(); if (uncompressed < threshold) { // Under the threshold, there is nothing to do. - out.writeByte(0); + ProtocolUtils.writeVarInt(out, 0); out.writeBytes(msg); } else { ProtocolUtils.writeVarInt(out, uncompressed); From 3dc8e25ec7e9c8f3dac71f0c825dc7cd20fc6ee0 Mon Sep 17 00:00:00 2001 From: Andrew Steinborn Date: Tue, 4 May 2021 16:30:32 -0400 Subject: [PATCH 74/99] Fix varint writing (for real!) Thanks to @Leymooo for reporting and providing test cases. (I also added one of my own tests which proved the most useful to debugging the issue.) --- .../proxy/protocol/ProtocolUtils.java | 23 +++-- .../proxy/protocol/ProtocolUtilsTest.java | 94 +++++++++++++++++++ 2 files changed, 108 insertions(+), 9 deletions(-) diff --git a/proxy/src/main/java/com/velocitypowered/proxy/protocol/ProtocolUtils.java b/proxy/src/main/java/com/velocitypowered/proxy/protocol/ProtocolUtils.java index 2591da8cc..9ac62ff69 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/protocol/ProtocolUtils.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/protocol/ProtocolUtils.java @@ -62,16 +62,13 @@ public enum ProtocolUtils { private static final int DEFAULT_MAX_STRING_SIZE = 65536; // 64KiB private static final QuietDecoderException BAD_VARINT_CACHED = new QuietDecoderException("Bad VarInt decoded"); - private static final int[] VARINT_BYTE_LENGTHS = new int[33]; + private static final int[] VARINT_EXACT_BYTE_LENGTHS = new int[33]; static { - // Inspired by https://richardstartin.github.io/posts/dont-use-protobuf-for-telemetry - // This has been slightly modified in that we reduce the length to 32-bit only, since Velocity - // doesn't look at any part of the Minecraft protocol that requires us to look at VarLongs. for (int i = 0; i <= 32; ++i) { - VARINT_BYTE_LENGTHS[i] = (int) Math.ceil((31d - (i - 1)) / 7d); + VARINT_EXACT_BYTE_LENGTHS[i] = (int) Math.ceil((31d - (i - 1)) / 7d); } - VARINT_BYTE_LENGTHS[32] = 1; // Special case for the number 0. + VARINT_EXACT_BYTE_LENGTHS[32] = 1; // Special case for the number 0. } /** @@ -108,8 +105,13 @@ public enum ProtocolUtils { return Integer.MIN_VALUE; } + /** + * Returns the exact byte size of {@code value} if it were encoded as a VarInt. + * @param value the value to encode + * @return the byte size of {@code value} if encoded as a VarInt + */ public static int varIntBytes(int value) { - return VARINT_BYTE_LENGTHS[Integer.numberOfLeadingZeros(value)]; + return VARINT_EXACT_BYTE_LENGTHS[Integer.numberOfLeadingZeros(value)]; } /** @@ -118,8 +120,11 @@ public enum ProtocolUtils { * @param value the integer to write */ public static void writeVarInt(ByteBuf buf, int value) { - int length = varIntBytes(value); - for (int i = 0; i < length; ++i) { + // Inspired by https://richardstartin.github.io/posts/dont-use-protobuf-for-telemetry + // This has been slightly modified in that we reduce the length to 32-bit only, since Velocity + // doesn't look at any part of the Minecraft protocol that requires us to look at VarLongs. + int continuationBytes = (31 - Integer.numberOfLeadingZeros(value)) / 7; + for (int i = 0; i < continuationBytes; ++i) { buf.writeByte(((byte) ((value & 0x7F) | 0x80))); value >>>= 7; } diff --git a/proxy/src/test/java/com/velocitypowered/proxy/protocol/ProtocolUtilsTest.java b/proxy/src/test/java/com/velocitypowered/proxy/protocol/ProtocolUtilsTest.java index 40800935d..43b940806 100644 --- a/proxy/src/test/java/com/velocitypowered/proxy/protocol/ProtocolUtilsTest.java +++ b/proxy/src/test/java/com/velocitypowered/proxy/protocol/ProtocolUtilsTest.java @@ -17,8 +17,13 @@ package com.velocitypowered.proxy.protocol; +import static org.junit.jupiter.api.Assertions.assertArrayEquals; import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; +import io.netty.buffer.ByteBuf; +import io.netty.buffer.ByteBufUtil; +import io.netty.buffer.Unpooled; import org.junit.jupiter.api.Test; public class ProtocolUtilsTest { @@ -44,6 +49,95 @@ public class ProtocolUtilsTest { } } + @Test + void testPositiveOld() { + ByteBuf buf = Unpooled.buffer(5); + for (int i = 0; i >= 0; i += 127) { + writeReadTestOld(buf, i); + } + } + + @Test + void testNegativeOld() { + ByteBuf buf = Unpooled.buffer(5); + for (int i = 0; i <= 0; i -= 127) { + writeReadTestOld(buf, i); + } + } + + private void writeReadTestOld(ByteBuf buf, int test) { + buf.clear(); + writeVarIntOld(buf, test); + assertEquals(test, ProtocolUtils.readVarIntSafely(buf)); + } + + @Test + void testBytesWrittenAtBitBoundaries() { + ByteBuf varintNew = Unpooled.buffer(5); + ByteBuf varintOld = Unpooled.buffer(5); + + long bytesNew = 0; + long bytesOld = 0; + for (int bit = 0; bit <= 31; bit++) { + int i = (1 << bit) - 1; + + writeVarIntOld(varintOld, i); + ProtocolUtils.writeVarInt(varintNew, i); + assertArrayEquals(varintOld.array(), varintNew.array(), + "Encoding of " + i + " was invalid"); + + assertEquals(i, oldReadVarIntSafely(varintNew)); + assertEquals(i, ProtocolUtils.readVarIntSafely(varintOld)); + + varintNew.clear(); + varintOld.clear(); + } + assertEquals(bytesNew, bytesOld, "byte sizes differ"); + } + + @Test + void testBytesWritten() { + ByteBuf varintNew = Unpooled.buffer(5); + ByteBuf varintOld = Unpooled.buffer(5); + + long bytesNew = 0; + long bytesOld = 0; + for (int i = 0; i <= 1_000_000; i++) { + ProtocolUtils.writeVarInt(varintNew, i); + writeVarIntOld(varintOld, i); + bytesNew += varintNew.readableBytes(); + bytesOld += varintOld.readableBytes(); + varintNew.clear(); + varintOld.clear(); + } + assertEquals(bytesNew, bytesOld, "byte sizes differ"); + } + + private static int oldReadVarIntSafely(ByteBuf buf) { + int i = 0; + int maxRead = Math.min(5, buf.readableBytes()); + for (int j = 0; j < maxRead; j++) { + int k = buf.readByte(); + i |= (k & 0x7F) << j * 7; + if ((k & 0x80) != 128) { + return i; + } + } + return Integer.MIN_VALUE; + } + + private void writeVarIntOld(ByteBuf buf, int value) { + while (true) { + if ((value & 0xFFFFFF80) == 0) { + buf.writeByte(value); + return; + } + + buf.writeByte(value & 0x7F | 0x80); + value >>>= 7; + } + } + private int conventionalWrittenBytes(int value) { int wouldBeWritten = 0; while (true) { From 7c76ae9a272cf90796429cf0141ccea042c7f6ac Mon Sep 17 00:00:00 2001 From: Andrew Steinborn Date: Tue, 4 May 2021 16:32:37 -0400 Subject: [PATCH 75/99] Make sure to check not only the entire array but also how much was written --- .../com/velocitypowered/proxy/protocol/ProtocolUtilsTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/proxy/src/test/java/com/velocitypowered/proxy/protocol/ProtocolUtilsTest.java b/proxy/src/test/java/com/velocitypowered/proxy/protocol/ProtocolUtilsTest.java index 43b940806..57cd8f7da 100644 --- a/proxy/src/test/java/com/velocitypowered/proxy/protocol/ProtocolUtilsTest.java +++ b/proxy/src/test/java/com/velocitypowered/proxy/protocol/ProtocolUtilsTest.java @@ -83,7 +83,7 @@ public class ProtocolUtilsTest { writeVarIntOld(varintOld, i); ProtocolUtils.writeVarInt(varintNew, i); - assertArrayEquals(varintOld.array(), varintNew.array(), + assertArrayEquals(ByteBufUtil.getBytes(varintOld), ByteBufUtil.getBytes(varintNew), "Encoding of " + i + " was invalid"); assertEquals(i, oldReadVarIntSafely(varintNew)); From e0153267db1174c35f6d20be7f6cf8eea27ec097 Mon Sep 17 00:00:00 2001 From: Nicolas RAYNAUD Date: Wed, 5 May 2021 00:22:50 +0200 Subject: [PATCH 76/99] Fixed copyright year (#490) --- .../velocitypowered/proxy/command/builtin/VelocityCommand.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/proxy/src/main/java/com/velocitypowered/proxy/command/builtin/VelocityCommand.java b/proxy/src/main/java/com/velocitypowered/proxy/command/builtin/VelocityCommand.java index f4b98881b..6eaf7d69e 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/command/builtin/VelocityCommand.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/command/builtin/VelocityCommand.java @@ -228,7 +228,7 @@ public class VelocityCommand implements SimpleCommand { .append(Component.text(version.getVersion()).decoration(TextDecoration.BOLD, false)) .build(); TextComponent copyright = Component - .text("Copyright 2018-2020 " + version.getVendor() + ". " + version.getName() + .text("Copyright 2018-2021 " + version.getVendor() + ". " + version.getName() + " is licensed under the terms of the GNU General Public License v3."); source.sendMessage(Identity.nil(), velocity); source.sendMessage(Identity.nil(), copyright); From d42cc4f984656e5ff394ed4c22bfebc5eeaf73eb Mon Sep 17 00:00:00 2001 From: Andrew Steinborn Date: Tue, 4 May 2021 18:51:01 -0400 Subject: [PATCH 77/99] Force a flush after a certain threshold of packets have been queued for sending Fixes #486. --- .../backend/BackendPlaySessionHandler.java | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/proxy/src/main/java/com/velocitypowered/proxy/connection/backend/BackendPlaySessionHandler.java b/proxy/src/main/java/com/velocitypowered/proxy/connection/backend/BackendPlaySessionHandler.java index d649b4c07..b3c7133cf 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/connection/backend/BackendPlaySessionHandler.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/connection/backend/BackendPlaySessionHandler.java @@ -56,12 +56,16 @@ public class BackendPlaySessionHandler implements MinecraftSessionHandler { private static final Logger logger = LogManager.getLogger(BackendPlaySessionHandler.class); private static final boolean BACKPRESSURE_LOG = Boolean .getBoolean("velocity.log-server-backpressure"); + private static final int MAXIMUM_PACKETS_TO_FLUSH = Integer + .getInteger("velocity.max-packets-per-flush", 8192); + private final VelocityServer server; private final VelocityServerConnection serverConn; private final ClientPlaySessionHandler playerSessionHandler; private final MinecraftConnection playerConnection; private final BungeeCordMessageResponder bungeecordMessageResponder; private boolean exceptionTriggered = false; + private int packetsFlushed; BackendPlaySessionHandler(VelocityServer server, VelocityServerConnection serverConn) { this.server = server; @@ -271,16 +275,25 @@ public class BackendPlaySessionHandler implements MinecraftSessionHandler { ((PluginMessage) packet).retain(); } playerConnection.delayedWrite(packet); + if (++packetsFlushed >= MAXIMUM_PACKETS_TO_FLUSH) { + playerConnection.flush(); + packetsFlushed = 0; + } } @Override public void handleUnknown(ByteBuf buf) { playerConnection.delayedWrite(buf.retain()); + if (++packetsFlushed >= MAXIMUM_PACKETS_TO_FLUSH) { + playerConnection.flush(); + packetsFlushed = 0; + } } @Override public void readCompleted() { playerConnection.flush(); + packetsFlushed = 0; } @Override From 1cef82d54dda8726dcb5708b69fa51b04c215439 Mon Sep 17 00:00:00 2001 From: Andrew Steinborn Date: Wed, 5 May 2021 22:13:54 -0400 Subject: [PATCH 78/99] Unroll the VarInt writing loop This is about as optimized as it can get. Thanks to @Leymooo for the idea, I simply expanded on it. We optimize for the common 1-3 byte cases, and punt more "complicated" cases to the original VarInt writing function we had before. --- .../proxy/protocol/ProtocolUtils.java | 31 ++++++++++++++----- .../netty/MinecraftVarintLengthEncoder.java | 3 +- 2 files changed, 26 insertions(+), 8 deletions(-) diff --git a/proxy/src/main/java/com/velocitypowered/proxy/protocol/ProtocolUtils.java b/proxy/src/main/java/com/velocitypowered/proxy/protocol/ProtocolUtils.java index 9ac62ff69..1f696bb7a 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/protocol/ProtocolUtils.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/protocol/ProtocolUtils.java @@ -120,15 +120,32 @@ public enum ProtocolUtils { * @param value the integer to write */ public static void writeVarInt(ByteBuf buf, int value) { - // Inspired by https://richardstartin.github.io/posts/dont-use-protobuf-for-telemetry - // This has been slightly modified in that we reduce the length to 32-bit only, since Velocity - // doesn't look at any part of the Minecraft protocol that requires us to look at VarLongs. - int continuationBytes = (31 - Integer.numberOfLeadingZeros(value)) / 7; - for (int i = 0; i < continuationBytes; ++i) { - buf.writeByte(((byte) ((value & 0x7F) | 0x80))); + int bytes = varIntBytes(value); + // Optimization: focus on 1-3 byte VarInts as they are the most common + if (bytes == 1) { + buf.writeByte(value & 0x7f); + } else if (bytes == 2) { + int w = (value & 0x7F | 0x80) << 8 | (value >>> 7); + buf.writeShort(w); + } else if (bytes == 3) { + int w = (value & 0x7F | 0x80) << 16 | ((value >>> 7) & 0x7F | 0x80) << 8 | (value >>> 14); + buf.writeMedium(w); + } else { + // 4 and 5 byte VarInts aren't common so split those cases off + writeVarIntUncommon(buf, value); + } + } + + private static void writeVarIntUncommon(ByteBuf buf, int value) { + while (true) { + if ((value & 0xFFFFFF80) == 0) { + buf.writeByte(value); + return; + } + + buf.writeByte(value & 0x7F | 0x80); value >>>= 7; } - buf.writeByte((byte) value); } public static String readString(ByteBuf buf) { diff --git a/proxy/src/main/java/com/velocitypowered/proxy/protocol/netty/MinecraftVarintLengthEncoder.java b/proxy/src/main/java/com/velocitypowered/proxy/protocol/netty/MinecraftVarintLengthEncoder.java index 867ea9b7f..94bfa84d0 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/protocol/netty/MinecraftVarintLengthEncoder.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/protocol/netty/MinecraftVarintLengthEncoder.java @@ -43,7 +43,8 @@ public class MinecraftVarintLengthEncoder extends MessageToByteEncoder @Override protected ByteBuf allocateBuffer(ChannelHandlerContext ctx, ByteBuf msg, boolean preferDirect) throws Exception { - int anticipatedRequiredCapacity = 5 + msg.readableBytes(); + int anticipatedRequiredCapacity = ProtocolUtils.varIntBytes(msg.readableBytes()) + + msg.readableBytes(); return IS_JAVA_CIPHER ? ctx.alloc().heapBuffer(anticipatedRequiredCapacity) : ctx.alloc().directBuffer(anticipatedRequiredCapacity); From fb3f21abc6362bbed6e343ef559fb3d5d25342d1 Mon Sep 17 00:00:00 2001 From: Andrew Steinborn Date: Thu, 6 May 2021 00:48:19 -0400 Subject: [PATCH 79/99] More bitshifting magic --- .../velocitypowered/proxy/protocol/ProtocolUtils.java | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/proxy/src/main/java/com/velocitypowered/proxy/protocol/ProtocolUtils.java b/proxy/src/main/java/com/velocitypowered/proxy/protocol/ProtocolUtils.java index 1f696bb7a..c7e25f528 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/protocol/ProtocolUtils.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/protocol/ProtocolUtils.java @@ -120,14 +120,13 @@ public enum ProtocolUtils { * @param value the integer to write */ public static void writeVarInt(ByteBuf buf, int value) { - int bytes = varIntBytes(value); // Optimization: focus on 1-3 byte VarInts as they are the most common - if (bytes == 1) { - buf.writeByte(value & 0x7f); - } else if (bytes == 2) { + if ((value & (0xFFFFFFFF << 7)) == 0) { + buf.writeByte(value); + } else if ((value & (0xFFFFFFFF << 14)) == 0) { int w = (value & 0x7F | 0x80) << 8 | (value >>> 7); buf.writeShort(w); - } else if (bytes == 3) { + } else if ((value & (0xFFFFFFFF << 21)) == 0) { int w = (value & 0x7F | 0x80) << 16 | ((value >>> 7) & 0x7F | 0x80) << 8 | (value >>> 14); buf.writeMedium(w); } else { From bbc53da87ebe1f70d53170dc55c8d0d82bd21120 Mon Sep 17 00:00:00 2001 From: Andrew Steinborn Date: Thu, 6 May 2021 16:10:56 -0400 Subject: [PATCH 80/99] Create FUNDING.yml --- .github/FUNDING.yml | 1 + 1 file changed, 1 insertion(+) create mode 100644 .github/FUNDING.yml diff --git a/.github/FUNDING.yml b/.github/FUNDING.yml new file mode 100644 index 000000000..52d913562 --- /dev/null +++ b/.github/FUNDING.yml @@ -0,0 +1 @@ +github: astei From 3fdacd30d167dfbade07a33e7234c38aa99f2fbc Mon Sep 17 00:00:00 2001 From: Andrew Steinborn Date: Thu, 6 May 2021 16:43:40 -0400 Subject: [PATCH 81/99] Explain why Player#sendPluginMessage may not do what some people think it ought to do --- .../java/com/velocitypowered/api/proxy/Player.java | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/api/src/main/java/com/velocitypowered/api/proxy/Player.java b/api/src/main/java/com/velocitypowered/api/proxy/Player.java index d03e532b7..de31ae71d 100644 --- a/api/src/main/java/com/velocitypowered/api/proxy/Player.java +++ b/api/src/main/java/com/velocitypowered/api/proxy/Player.java @@ -9,6 +9,7 @@ package com.velocitypowered.api.proxy; import com.velocitypowered.api.command.CommandSource; import com.velocitypowered.api.event.player.PlayerResourcePackStatusEvent; +import com.velocitypowered.api.proxy.messages.ChannelIdentifier; import com.velocitypowered.api.proxy.messages.ChannelMessageSink; import com.velocitypowered.api.proxy.messages.ChannelMessageSource; import com.velocitypowered.api.proxy.player.PlayerSettings; @@ -226,4 +227,16 @@ public interface Player extends CommandSource, Identified, InboundConnection, * @param hash the SHA-1 hash value for the resource pack */ void sendResourcePack(String url, byte[] hash); + + /** + * @inheritDoc + * + * Note that this method does not send a plugin message to the server the player + * is connected to. You should only use this method if you are trying to communicate + * with a mod that is installed on the player's client. To send a plugin message to the server + * from the player, you should use the equivalent method on the instance returned by + * {@link #getCurrentServer()}. + */ + @Override + boolean sendPluginMessage(ChannelIdentifier identifier, byte[] data); } From 3d9a16689230152972dfd5c4a783bdac57ca4235 Mon Sep 17 00:00:00 2001 From: Andrew Steinborn Date: Thu, 6 May 2021 16:46:43 -0400 Subject: [PATCH 82/99] Fix Checkstyle --- api/src/main/java/com/velocitypowered/api/proxy/Player.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/api/src/main/java/com/velocitypowered/api/proxy/Player.java b/api/src/main/java/com/velocitypowered/api/proxy/Player.java index de31ae71d..540adc75e 100644 --- a/api/src/main/java/com/velocitypowered/api/proxy/Player.java +++ b/api/src/main/java/com/velocitypowered/api/proxy/Player.java @@ -229,13 +229,13 @@ public interface Player extends CommandSource, Identified, InboundConnection, void sendResourcePack(String url, byte[] hash); /** - * @inheritDoc - * * Note that this method does not send a plugin message to the server the player * is connected to. You should only use this method if you are trying to communicate * with a mod that is installed on the player's client. To send a plugin message to the server * from the player, you should use the equivalent method on the instance returned by * {@link #getCurrentServer()}. + * + * @inheritDoc */ @Override boolean sendPluginMessage(ChannelIdentifier identifier, byte[] data); From 37a4199d4338e859b23bec7aed0f54930d815dfe Mon Sep 17 00:00:00 2001 From: Andrew Steinborn Date: Thu, 6 May 2021 19:56:45 -0400 Subject: [PATCH 83/99] Combine VarInt prefix encoding with compression This saves us a memory copy in the common "there is no need to compress this packet" case. --- .../proxy/connection/MinecraftConnection.java | 10 ++++---- ... MinecraftCompressorAndLengthEncoder.java} | 24 +++++++++++++++---- 2 files changed, 26 insertions(+), 8 deletions(-) rename proxy/src/main/java/com/velocitypowered/proxy/protocol/netty/{MinecraftCompressEncoder.java => MinecraftCompressorAndLengthEncoder.java} (76%) diff --git a/proxy/src/main/java/com/velocitypowered/proxy/connection/MinecraftConnection.java b/proxy/src/main/java/com/velocitypowered/proxy/connection/MinecraftConnection.java index 4d6318968..ba172db42 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/connection/MinecraftConnection.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/connection/MinecraftConnection.java @@ -36,12 +36,13 @@ import com.velocitypowered.proxy.VelocityServer; import com.velocitypowered.proxy.connection.client.HandshakeSessionHandler; import com.velocitypowered.proxy.connection.client.LoginSessionHandler; import com.velocitypowered.proxy.connection.client.StatusSessionHandler; +import com.velocitypowered.proxy.network.Connections; import com.velocitypowered.proxy.protocol.MinecraftPacket; import com.velocitypowered.proxy.protocol.StateRegistry; import com.velocitypowered.proxy.protocol.netty.MinecraftCipherDecoder; import com.velocitypowered.proxy.protocol.netty.MinecraftCipherEncoder; import com.velocitypowered.proxy.protocol.netty.MinecraftCompressDecoder; -import com.velocitypowered.proxy.protocol.netty.MinecraftCompressEncoder; +import com.velocitypowered.proxy.protocol.netty.MinecraftCompressorAndLengthEncoder; import com.velocitypowered.proxy.protocol.netty.MinecraftDecoder; import com.velocitypowered.proxy.protocol.netty.MinecraftEncoder; import com.velocitypowered.proxy.util.except.QuietDecoderException; @@ -402,8 +403,8 @@ public class MinecraftConnection extends ChannelInboundHandlerAdapter { } else { MinecraftCompressDecoder decoder = (MinecraftCompressDecoder) channel.pipeline() .get(COMPRESSION_DECODER); - MinecraftCompressEncoder encoder = (MinecraftCompressEncoder) channel.pipeline() - .get(COMPRESSION_ENCODER); + MinecraftCompressorAndLengthEncoder encoder = + (MinecraftCompressorAndLengthEncoder) channel.pipeline().get(COMPRESSION_ENCODER); if (decoder != null && encoder != null) { decoder.setThreshold(threshold); encoder.setThreshold(threshold); @@ -411,9 +412,10 @@ public class MinecraftConnection extends ChannelInboundHandlerAdapter { int level = server.getConfiguration().getCompressionLevel(); VelocityCompressor compressor = Natives.compress.get().create(level); - encoder = new MinecraftCompressEncoder(threshold, compressor); + encoder = new MinecraftCompressorAndLengthEncoder(threshold, compressor); decoder = new MinecraftCompressDecoder(threshold, compressor); + channel.pipeline().remove(FRAME_ENCODER); channel.pipeline().addBefore(MINECRAFT_DECODER, COMPRESSION_DECODER, decoder); channel.pipeline().addBefore(MINECRAFT_ENCODER, COMPRESSION_ENCODER, encoder); } diff --git a/proxy/src/main/java/com/velocitypowered/proxy/protocol/netty/MinecraftCompressEncoder.java b/proxy/src/main/java/com/velocitypowered/proxy/protocol/netty/MinecraftCompressorAndLengthEncoder.java similarity index 76% rename from proxy/src/main/java/com/velocitypowered/proxy/protocol/netty/MinecraftCompressEncoder.java rename to proxy/src/main/java/com/velocitypowered/proxy/protocol/netty/MinecraftCompressorAndLengthEncoder.java index f6cb495ca..6684ee35d 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/protocol/netty/MinecraftCompressEncoder.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/protocol/netty/MinecraftCompressorAndLengthEncoder.java @@ -23,13 +23,14 @@ import com.velocitypowered.proxy.protocol.ProtocolUtils; import io.netty.buffer.ByteBuf; import io.netty.channel.ChannelHandlerContext; import io.netty.handler.codec.MessageToByteEncoder; +import java.util.zip.DataFormatException; -public class MinecraftCompressEncoder extends MessageToByteEncoder { +public class MinecraftCompressorAndLengthEncoder extends MessageToByteEncoder { private int threshold; private final VelocityCompressor compressor; - public MinecraftCompressEncoder(int threshold, VelocityCompressor compressor) { + public MinecraftCompressorAndLengthEncoder(int threshold, VelocityCompressor compressor) { this.threshold = threshold; this.compressor = compressor; } @@ -39,16 +40,31 @@ public class MinecraftCompressEncoder extends MessageToByteEncoder { int uncompressed = msg.readableBytes(); if (uncompressed < threshold) { // Under the threshold, there is nothing to do. + ProtocolUtils.writeVarInt(out, uncompressed + 1); ProtocolUtils.writeVarInt(out, 0); out.writeBytes(msg); } else { - ProtocolUtils.writeVarInt(out, uncompressed); + handleCompressed(ctx, msg, out); + } + } + + private void handleCompressed(ChannelHandlerContext ctx, ByteBuf msg, ByteBuf out) + throws DataFormatException { + int uncompressed = msg.readableBytes(); + ByteBuf tmpBuf = MoreByteBufUtils.preferredBuffer(ctx.alloc(), compressor, uncompressed - 1); + try { + ProtocolUtils.writeVarInt(tmpBuf, uncompressed); ByteBuf compatibleIn = MoreByteBufUtils.ensureCompatible(ctx.alloc(), compressor, msg); try { - compressor.deflate(compatibleIn, out); + compressor.deflate(compatibleIn, tmpBuf); } finally { compatibleIn.release(); } + + ProtocolUtils.writeVarInt(out, tmpBuf.readableBytes()); + out.writeBytes(tmpBuf); + } finally { + tmpBuf.release(); } } From 9318fe3dcab44ff9121a422eeeacd72f45efac7b Mon Sep 17 00:00:00 2001 From: Andrew Steinborn Date: Thu, 6 May 2021 21:08:57 -0400 Subject: [PATCH 84/99] Update link to Adventure documentation --- api/build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/api/build.gradle b/api/build.gradle index 273f61add..79f12e478 100644 --- a/api/build.gradle +++ b/api/build.gradle @@ -93,7 +93,7 @@ javadoc { 'https://google.github.io/guava/releases/25.1-jre/api/docs/', 'https://google.github.io/guice/api-docs/4.2/javadoc/', 'https://docs.oracle.com/javase/8/docs/api/', - 'https://jd.adventure.kyori.net/api/4.0.0/' + 'https://jd.adventure.kyori.net/api/4.7.0/' ) // Disable the crazy super-strict doclint tool in Java 8 From a8e0516d18b996b3a6aea80de97e017daa6e38a1 Mon Sep 17 00:00:00 2001 From: Leymooo Date: Fri, 7 May 2021 19:36:30 +0300 Subject: [PATCH 85/99] Also do not copy memory in case when packet needs to compress --- .../proxy/protocol/ProtocolUtils.java | 10 +++++ .../MinecraftCompressorAndLengthEncoder.java | 45 ++++++++++--------- .../netty/MinecraftVarintLengthEncoder.java | 2 +- .../proxy/protocol/ProtocolUtilsTest.java | 14 ++++++ 4 files changed, 49 insertions(+), 22 deletions(-) diff --git a/proxy/src/main/java/com/velocitypowered/proxy/protocol/ProtocolUtils.java b/proxy/src/main/java/com/velocitypowered/proxy/protocol/ProtocolUtils.java index c7e25f528..a40598e43 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/protocol/ProtocolUtils.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/protocol/ProtocolUtils.java @@ -147,6 +147,16 @@ public enum ProtocolUtils { } } + /** + * Writes all integers as 3 bytes Minecraft-style VarInt to the specified {@code buf}. + * @param buf the buffer to read from + * @param value the integer to write + */ + public static void writeVarIntAs3Bytes(ByteBuf buf, int value) { + int w = (value & 0x7F | 0x80) << 16 | ((value >>> 7) & 0x7F | 0x80) << 8 | (value >>> 14); + buf.writeMedium(w); + } + public static String readString(ByteBuf buf) { return readString(buf, DEFAULT_MAX_STRING_SIZE); } diff --git a/proxy/src/main/java/com/velocitypowered/proxy/protocol/netty/MinecraftCompressorAndLengthEncoder.java b/proxy/src/main/java/com/velocitypowered/proxy/protocol/netty/MinecraftCompressorAndLengthEncoder.java index 6684ee35d..73cea902b 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/protocol/netty/MinecraftCompressorAndLengthEncoder.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/protocol/netty/MinecraftCompressorAndLengthEncoder.java @@ -17,6 +17,8 @@ package com.velocitypowered.proxy.protocol.netty; +import static com.velocitypowered.proxy.protocol.netty.MinecraftVarintLengthEncoder.IS_JAVA_CIPHER; + import com.velocitypowered.natives.compression.VelocityCompressor; import com.velocitypowered.natives.util.MoreByteBufUtils; import com.velocitypowered.proxy.protocol.ProtocolUtils; @@ -50,36 +52,37 @@ public class MinecraftCompressorAndLengthEncoder extends MessageToByteEncoder { public static final MinecraftVarintLengthEncoder INSTANCE = new MinecraftVarintLengthEncoder(); - private static final boolean IS_JAVA_CIPHER = Natives.cipher.get() == JavaVelocityCipher.FACTORY; + public static final boolean IS_JAVA_CIPHER = Natives.cipher.get() == JavaVelocityCipher.FACTORY; private MinecraftVarintLengthEncoder() { } diff --git a/proxy/src/test/java/com/velocitypowered/proxy/protocol/ProtocolUtilsTest.java b/proxy/src/test/java/com/velocitypowered/proxy/protocol/ProtocolUtilsTest.java index 57cd8f7da..58530a4a3 100644 --- a/proxy/src/test/java/com/velocitypowered/proxy/protocol/ProtocolUtilsTest.java +++ b/proxy/src/test/java/com/velocitypowered/proxy/protocol/ProtocolUtilsTest.java @@ -71,6 +71,20 @@ public class ProtocolUtilsTest { assertEquals(test, ProtocolUtils.readVarIntSafely(buf)); } + @Test + void test3Bytes() { + ByteBuf buf = Unpooled.buffer(5); + for (int i = 0; i < 2097152; i += 31) { + writeReadTest3Bytes(buf, i); + } + } + + private void writeReadTest3Bytes(ByteBuf buf, int test) { + buf.clear(); + ProtocolUtils.writeVarIntAs3Bytes(buf, test); + assertEquals(test, ProtocolUtils.readVarInt(buf)); + } + @Test void testBytesWrittenAtBitBoundaries() { ByteBuf varintNew = Unpooled.buffer(5); From 6369a95ec99f4a1146ff3c38f1321770331dd4f5 Mon Sep 17 00:00:00 2001 From: Andrew Steinborn Date: Sat, 8 May 2021 18:40:23 -0400 Subject: [PATCH 86/99] Readd safe and slow compression handling and hide it behind a system property --- .../MinecraftCompressorAndLengthEncoder.java | 44 +++++++++++++++++-- 1 file changed, 40 insertions(+), 4 deletions(-) diff --git a/proxy/src/main/java/com/velocitypowered/proxy/protocol/netty/MinecraftCompressorAndLengthEncoder.java b/proxy/src/main/java/com/velocitypowered/proxy/protocol/netty/MinecraftCompressorAndLengthEncoder.java index 73cea902b..34d247bc7 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/protocol/netty/MinecraftCompressorAndLengthEncoder.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/protocol/netty/MinecraftCompressorAndLengthEncoder.java @@ -29,6 +29,9 @@ import java.util.zip.DataFormatException; public class MinecraftCompressorAndLengthEncoder extends MessageToByteEncoder { + private static final boolean MUST_USE_SAFE_AND_SLOW_COMPRESSION_HANDLING = + Boolean.getBoolean("velocity.increased-compression-cap"); + private int threshold; private final VelocityCompressor compressor; @@ -46,29 +49,62 @@ public class MinecraftCompressorAndLengthEncoder extends MessageToByteEncoder= 1 << 21) { + throw new DataFormatException("The server sent a very large (over 2MiB compressed) packet. " + + "Please restart Velocity with the JVM flag -Dvelocity.increased-compression-cap=true " + + "to fix this issue."); + } int writerIndex = out.writerIndex(); int packetLength = out.readableBytes() - 3; out.writerIndex(0); - ProtocolUtils.writeVarIntAs3Bytes(out, packetLength); //Rewrite packet length + ProtocolUtils.writeVarIntAs3Bytes(out, packetLength); // Rewrite packet length out.writerIndex(writerIndex); } + private void handleCompressedSafe(ChannelHandlerContext ctx, ByteBuf msg, ByteBuf out) + throws DataFormatException { + int uncompressed = msg.readableBytes(); + ByteBuf tmpBuf = MoreByteBufUtils.preferredBuffer(ctx.alloc(), compressor, uncompressed - 1); + try { + ProtocolUtils.writeVarInt(tmpBuf, uncompressed); + ByteBuf compatibleIn = MoreByteBufUtils.ensureCompatible(ctx.alloc(), compressor, msg); + try { + compressor.deflate(compatibleIn, tmpBuf); + } finally { + compatibleIn.release(); + } + + ProtocolUtils.writeVarInt(out, tmpBuf.readableBytes()); + out.writeBytes(tmpBuf); + } finally { + tmpBuf.release(); + } + } + @Override protected ByteBuf allocateBuffer(ChannelHandlerContext ctx, ByteBuf msg, boolean preferDirect) throws Exception { From 150fd9a9cf239b769fe46f607c95a85a6c197377 Mon Sep 17 00:00:00 2001 From: Andrew Steinborn Date: Sat, 8 May 2021 23:26:43 -0400 Subject: [PATCH 87/99] Add highly-optimized VarInt writing method --- .../proxy/protocol/ProtocolUtils.java | 30 ++++++++----------- .../MinecraftCompressorAndLengthEncoder.java | 4 +-- .../proxy/protocol/ProtocolUtilsTest.java | 2 +- 3 files changed, 16 insertions(+), 20 deletions(-) diff --git a/proxy/src/main/java/com/velocitypowered/proxy/protocol/ProtocolUtils.java b/proxy/src/main/java/com/velocitypowered/proxy/protocol/ProtocolUtils.java index a40598e43..ee3482c9d 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/protocol/ProtocolUtils.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/protocol/ProtocolUtils.java @@ -120,7 +120,7 @@ public enum ProtocolUtils { * @param value the integer to write */ public static void writeVarInt(ByteBuf buf, int value) { - // Optimization: focus on 1-3 byte VarInts as they are the most common + // See https://steinborn.me/posts/performance/how-fast-can-you-write-a-varint/ if ((value & (0xFFFFFFFF << 7)) == 0) { buf.writeByte(value); } else if ((value & (0xFFFFFFFF << 14)) == 0) { @@ -129,30 +129,26 @@ public enum ProtocolUtils { } else if ((value & (0xFFFFFFFF << 21)) == 0) { int w = (value & 0x7F | 0x80) << 16 | ((value >>> 7) & 0x7F | 0x80) << 8 | (value >>> 14); buf.writeMedium(w); + } else if ((value & (0xFFFFFFFF << 28)) == 0) { + int w = (value & 0x7F | 0x80) << 24 | (((value >>> 7) & 0x7F | 0x80) << 16) + | ((value >>> 14) & 0x7F | 0x80) << 8 | (value >>> 21); + buf.writeInt(w); } else { - // 4 and 5 byte VarInts aren't common so split those cases off - writeVarIntUncommon(buf, value); - } - } - - private static void writeVarIntUncommon(ByteBuf buf, int value) { - while (true) { - if ((value & 0xFFFFFF80) == 0) { - buf.writeByte(value); - return; - } - - buf.writeByte(value & 0x7F | 0x80); - value >>>= 7; + int w = (value & 0x7F | 0x80) << 24 | ((value >>> 7) & 0x7F | 0x80) << 16 + | ((value >>> 14) & 0x7F | 0x80) << 8 | ((value >>> 21) & 0x7F | 0x80); + buf.writeInt(w); + buf.writeByte(value >>> 28); } } /** - * Writes all integers as 3 bytes Minecraft-style VarInt to the specified {@code buf}. + * Writes the specified {@code value} as a 21-bit Minecraft VarInt to the specified {@code buf}. + * The upper 11 bits will be discarded. * @param buf the buffer to read from * @param value the integer to write */ - public static void writeVarIntAs3Bytes(ByteBuf buf, int value) { + public static void write21BitVarInt(ByteBuf buf, int value) { + // See https://steinborn.me/posts/performance/how-fast-can-you-write-a-varint/ int w = (value & 0x7F | 0x80) << 16 | ((value >>> 7) & 0x7F | 0x80) << 8 | (value >>> 14); buf.writeMedium(w); } diff --git a/proxy/src/main/java/com/velocitypowered/proxy/protocol/netty/MinecraftCompressorAndLengthEncoder.java b/proxy/src/main/java/com/velocitypowered/proxy/protocol/netty/MinecraftCompressorAndLengthEncoder.java index 34d247bc7..28d005161 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/protocol/netty/MinecraftCompressorAndLengthEncoder.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/protocol/netty/MinecraftCompressorAndLengthEncoder.java @@ -61,7 +61,7 @@ public class MinecraftCompressorAndLengthEncoder extends MessageToByteEncoder Date: Sun, 9 May 2021 02:57:01 -0400 Subject: [PATCH 88/99] Improve writeVarInt inlining by peeling the two most common cases --- .../proxy/protocol/ProtocolUtils.java | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/proxy/src/main/java/com/velocitypowered/proxy/protocol/ProtocolUtils.java b/proxy/src/main/java/com/velocitypowered/proxy/protocol/ProtocolUtils.java index ee3482c9d..7ae34b9db 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/protocol/ProtocolUtils.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/protocol/ProtocolUtils.java @@ -120,6 +120,19 @@ public enum ProtocolUtils { * @param value the integer to write */ public static void writeVarInt(ByteBuf buf, int value) { + // Peel the one and two byte count cases explicitly as they are the most common VarInt sizes + // that the proxy will write, to improve inlining. + if ((value & (0xFFFFFFFF << 7)) == 0) { + buf.writeByte(value); + } else if ((value & (0xFFFFFFFF << 14)) == 0) { + int w = (value & 0x7F | 0x80) << 8 | (value >>> 7); + buf.writeShort(w); + } else { + writeVarIntFull(buf, value); + } + } + + private static void writeVarIntFull(ByteBuf buf, int value) { // See https://steinborn.me/posts/performance/how-fast-can-you-write-a-varint/ if ((value & (0xFFFFFFFF << 7)) == 0) { buf.writeByte(value); @@ -135,7 +148,7 @@ public enum ProtocolUtils { buf.writeInt(w); } else { int w = (value & 0x7F | 0x80) << 24 | ((value >>> 7) & 0x7F | 0x80) << 16 - | ((value >>> 14) & 0x7F | 0x80) << 8 | ((value >>> 21) & 0x7F | 0x80); + | ((value >>> 14) & 0x7F | 0x80) | ((value >>> 21) & 0x7F | 0x80); buf.writeInt(w); buf.writeByte(value >>> 28); } From 11ed4b46e4b19a22a10063b03b41be0ae7d55a67 Mon Sep 17 00:00:00 2001 From: Andrew Steinborn Date: Sun, 9 May 2021 02:57:52 -0400 Subject: [PATCH 89/99] whoops --- .../java/com/velocitypowered/proxy/protocol/ProtocolUtils.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/proxy/src/main/java/com/velocitypowered/proxy/protocol/ProtocolUtils.java b/proxy/src/main/java/com/velocitypowered/proxy/protocol/ProtocolUtils.java index 7ae34b9db..53daae299 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/protocol/ProtocolUtils.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/protocol/ProtocolUtils.java @@ -148,7 +148,7 @@ public enum ProtocolUtils { buf.writeInt(w); } else { int w = (value & 0x7F | 0x80) << 24 | ((value >>> 7) & 0x7F | 0x80) << 16 - | ((value >>> 14) & 0x7F | 0x80) | ((value >>> 21) & 0x7F | 0x80); + | ((value >>> 14) & 0x7F | 0x80) << 8 | ((value >>> 21) & 0x7F | 0x80); buf.writeInt(w); buf.writeByte(value >>> 28); } From cdc9ebf72de8dc1bf77fde41c5ee34667ed145f3 Mon Sep 17 00:00:00 2001 From: Andrew Steinborn Date: Sun, 9 May 2021 03:56:26 -0400 Subject: [PATCH 90/99] Fix merge issues --- .../com/velocitypowered/api/proxy/connection/Player.java | 6 +++--- native/build.gradle | 4 ++-- .../pipeline/MinecraftCompressorAndLengthEncoder.java | 6 +++--- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/api/src/main/java/com/velocitypowered/api/proxy/connection/Player.java b/api/src/main/java/com/velocitypowered/api/proxy/connection/Player.java index 9aa7daf70..f08131743 100644 --- a/api/src/main/java/com/velocitypowered/api/proxy/connection/Player.java +++ b/api/src/main/java/com/velocitypowered/api/proxy/connection/Player.java @@ -9,9 +9,9 @@ package com.velocitypowered.api.proxy.connection; import com.velocitypowered.api.command.CommandSource; import com.velocitypowered.api.event.player.PlayerResourcePackStatusEvent; -import com.velocitypowered.api.proxy.messages.ChannelIdentifier; import com.velocitypowered.api.proxy.messages.ChannelMessageSink; import com.velocitypowered.api.proxy.messages.ChannelMessageSource; +import com.velocitypowered.api.proxy.messages.PluginChannelId; import com.velocitypowered.api.proxy.player.ClientSettings; import com.velocitypowered.api.proxy.player.ConnectionRequestBuilder; import com.velocitypowered.api.proxy.player.TabList; @@ -145,10 +145,10 @@ public interface Player extends CommandSource, Identified, InboundConnection, * is connected to. You should only use this method if you are trying to communicate * with a mod that is installed on the player's client. To send a plugin message to the server * from the player, you should use the equivalent method on the instance returned by - * {@link #getCurrentServer()}. + * {@link #connectedServer()}. * * @inheritDoc */ @Override - boolean sendPluginMessage(ChannelIdentifier identifier, byte[] data); + boolean sendPluginMessage(PluginChannelId identifier, byte[] data); } diff --git a/native/build.gradle b/native/build.gradle index 03f7f2423..b58547459 100644 --- a/native/build.gradle +++ b/native/build.gradle @@ -9,8 +9,8 @@ apply from: '../gradle/checkstyle.gradle' apply from: '../gradle/publish.gradle' java { - sourceCompatibility = JavaVersion.VERSION_1_8 - targetCompatibility = JavaVersion.VERSION_1_8 + sourceCompatibility = JavaVersion.VERSION_11 + targetCompatibility = JavaVersion.VERSION_11 } license { diff --git a/proxy/src/main/java/com/velocitypowered/proxy/network/pipeline/MinecraftCompressorAndLengthEncoder.java b/proxy/src/main/java/com/velocitypowered/proxy/network/pipeline/MinecraftCompressorAndLengthEncoder.java index 28d005161..e174250db 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/network/pipeline/MinecraftCompressorAndLengthEncoder.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/network/pipeline/MinecraftCompressorAndLengthEncoder.java @@ -15,13 +15,13 @@ * along with this program. If not, see . */ -package com.velocitypowered.proxy.protocol.netty; +package com.velocitypowered.proxy.network.pipeline; -import static com.velocitypowered.proxy.protocol.netty.MinecraftVarintLengthEncoder.IS_JAVA_CIPHER; +import static com.velocitypowered.proxy.network.pipeline.MinecraftVarintLengthEncoder.IS_JAVA_CIPHER; import com.velocitypowered.natives.compression.VelocityCompressor; import com.velocitypowered.natives.util.MoreByteBufUtils; -import com.velocitypowered.proxy.protocol.ProtocolUtils; +import com.velocitypowered.proxy.network.ProtocolUtils; import io.netty.buffer.ByteBuf; import io.netty.channel.ChannelHandlerContext; import io.netty.handler.codec.MessageToByteEncoder; From 1e8454c76a9127b07b65a0cd42e8be8279c1b7dc Mon Sep 17 00:00:00 2001 From: Andrew Steinborn Date: Sun, 9 May 2021 04:22:42 -0400 Subject: [PATCH 91/99] Localize the dump command --- .../command/builtin/VelocityCommand.java | 68 ++++++------------- .../proxy/l10n/messages.properties | 9 ++- .../proxy/l10n/messages_en_UD.properties | 9 ++- .../proxy/command/CommandManagerTests.java | 2 + .../proxy/protocol/ProtocolUtilsTest.java | 2 +- 5 files changed, 38 insertions(+), 52 deletions(-) diff --git a/proxy/src/main/java/com/velocitypowered/proxy/command/builtin/VelocityCommand.java b/proxy/src/main/java/com/velocitypowered/proxy/command/builtin/VelocityCommand.java index eb9394b23..cce794393 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/command/builtin/VelocityCommand.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/command/builtin/VelocityCommand.java @@ -17,6 +17,7 @@ package com.velocitypowered.proxy.command.builtin; +import com.google.common.base.Throwables; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableSet; @@ -312,7 +313,7 @@ public class VelocityCommand implements SimpleCommand { Component.text(description.authors().get(0)))); } else { hoverText.append( - Component.translatable("velocity.command.plugin-tooltip-author", + Component.translatable("velocity.command.plugin-tooltip-authors", Component.text(String.join(", ", description.authors())) ) ); @@ -375,7 +376,7 @@ public class VelocityCommand implements SimpleCommand { dump.add("config", proxyConfig); dump.add("plugins", InformationUtils.collectPluginInfo(server)); - source.sendMessage(Component.text().content("Uploading gathered information...").build()); + source.sendMessage(Component.translatable("velocity.command.dump-uploading")); AsyncHttpClient httpClient = ((VelocityServer) server).getAsyncHttpClient(); BoundRequestBuilder request = @@ -391,12 +392,8 @@ public class VelocityCommand implements SimpleCommand { try { Response response = future.get(); if (response.getStatusCode() != 200) { - source.sendMessage(Component.text() - .content("An error occurred while communicating with the Velocity servers. " - + "The servers may be temporarily unavailable or there is an issue " - + "with your network settings. You can find more information in the " - + "log or console of your Velocity server.") - .color(NamedTextColor.RED).build()); + source.sendMessage(Component.translatable("velocity.command.dump-send-error", + NamedTextColor.RED)); logger.error("Invalid status code while POST-ing Velocity dump: " + response.getStatusCode()); logger.error("Headers: \n--------------BEGIN HEADERS--------------\n" @@ -411,55 +408,28 @@ public class VelocityCommand implements SimpleCommand { } String url = "https://dump.velocitypowered.com/" + key.get("key").getAsString() + ".json"; - source.sendMessage(Component.text() - .content("Created an anonymised report containing useful information about " - + "this proxy. If a developer requested it, you may share the " - + "following link with them:") + source.sendMessage(Component.translatable("velocity.command.dump-success") .append(Component.newline()) .append(Component.text(">> " + url) .color(NamedTextColor.GREEN) .clickEvent(ClickEvent.openUrl(url))) .append(Component.newline()) - .append(Component.text("Note: This link is only valid for a few days") - .color(NamedTextColor.GRAY) - ).build()); - } catch (InterruptedException e) { - source.sendMessage(Component.text() - .content("Could not complete the request, the command was interrupted." - + "Please refer to the proxy-log or console for more information.") - .color(NamedTextColor.RED).build()); - logger.error("Failed to complete dump command, " - + "the executor was interrupted: " + e.getMessage()); - e.printStackTrace(); - } catch (ExecutionException e) { - TextComponent.Builder message = Component.text() - .content("An error occurred while attempting to upload the gathered " - + "information to the Velocity servers.") - .append(Component.newline()) - .color(NamedTextColor.RED); - if (e.getCause() instanceof UnknownHostException - || e.getCause() instanceof ConnectException) { - message.append(Component.text( - "Likely cause: Invalid system DNS settings or no internet connection")); - } - source.sendMessage(message - .append(Component.newline() - .append(Component.text( - "Error details can be found in the proxy log / console")) - ).build()); - - logger.error("Failed to complete dump command, " - + "the executor encountered an Exception: " + e.getCause().getMessage()); - e.getCause().printStackTrace(); + .append(Component.translatable("velocity.command.dump-will-expire", + NamedTextColor.GRAY))); } catch (JsonParseException e) { - source.sendMessage(Component.text() - .content("An error occurred on the Velocity servers and the dump could not " - + "be completed. Please contact the Velocity staff about this problem. " - + "If you do, provide the details about this error from the Velocity " - + "console or server log.") - .color(NamedTextColor.RED).build()); + source.sendMessage(Component.translatable("velocity.command.dump-server-error")); logger.error("Invalid response from the Velocity servers: " + e.getMessage()); e.printStackTrace(); + } catch (Exception e) { + Component message = Component.translatable("velocity.command.dump-send-error") + .append(Component.newline()) + .color(NamedTextColor.RED); + if (e.getCause() instanceof UnknownHostException + || e.getCause() instanceof ConnectException) { + message = message.append(Component.translatable("velocity.command.dump-offline")); + } + source.sendMessage(message); + logger.error("Failed to complete dump command", Throwables.getRootCause(e)); } }, MoreExecutors.directExecutor()); } diff --git a/proxy/src/main/resources/com/velocitypowered/proxy/l10n/messages.properties b/proxy/src/main/resources/com/velocitypowered/proxy/l10n/messages.properties index abde8db10..ee8e6cc2b 100644 --- a/proxy/src/main/resources/com/velocitypowered/proxy/l10n/messages.properties +++ b/proxy/src/main/resources/com/velocitypowered/proxy/l10n/messages.properties @@ -58,4 +58,11 @@ velocity.command.no-plugins=There are no plugins currently installed. velocity.command.plugins-list=Plugins: {0} velocity.command.plugin-tooltip-website=Website: {0} velocity.command.plugin-tooltip-author=Author: {0} -velocity.command.plugin-tooltip-authors=Authors: {0} \ No newline at end of file +velocity.command.plugin-tooltip-authors=Authors: {0} + +velocity.command.dump-uploading=Uploading gathered information... +velocity.command.dump-send-error=An error occurred while communicating with the Velocity servers. The servers may be temporarily unavailable or there is an issue with your network settings. You can find more information in the log or console of your Velocity server. +velocity.command.dump-success=Created an anonymised report containing useful information about this proxy. If a developer requested it, you may share the following link with them: +velocity.command.dump-will-expire=This link will expire in a few days. +velocity.command.dump-server-error=An error occurred on the Velocity servers and the dump could not be completed. Please contact the Velocity staff about this problem and provide the details about this error from the Velocity console or server log. +velocity.command.dump-offline=Likely cause: Invalid system DNS settings or no internet connection \ No newline at end of file diff --git a/proxy/src/main/resources/com/velocitypowered/proxy/l10n/messages_en_UD.properties b/proxy/src/main/resources/com/velocitypowered/proxy/l10n/messages_en_UD.properties index 5f3b9abcf..7a22f069b 100644 --- a/proxy/src/main/resources/com/velocitypowered/proxy/l10n/messages_en_UD.properties +++ b/proxy/src/main/resources/com/velocitypowered/proxy/l10n/messages_en_UD.properties @@ -58,4 +58,11 @@ velocity.command.no-plugins=˙pǝllɐʇsuᴉ ʎlʇuǝɹɹnɔ suᴉƃnld ou ǝɹ velocity.command.plugins-list={0}: suᴉƃnlԀ velocity.command.plugin-tooltip-website={0}: ǝʇᴉsqǝM velocity.command.plugin-tooltip-author={0}: ɹoɥʇn∀ -velocity.command.plugin-tooltip-authors={0}: sɹoɥʇn∀ \ No newline at end of file +velocity.command.plugin-tooltip-authors={0}: sɹoɥʇn∀ + +velocity.command.dump-uploading=˙˙˙uoᴉʇɐɯɹoɟuᴉ pǝɹǝɥʇɐƃ ƃuᴉpɐold∩ +velocity.command.dump-send-error=˙ɹǝʌɹǝs ʎʇᴉɔolǝΛ ɹnoʎ ɟo ǝlosuoɔ ɹo ƃol ǝɥʇ uᴉ uoᴉʇɐɯɹoɟuᴉ ǝɹoɯ puᴉɟ uɐɔ no⅄ ˙sƃuᴉʇʇǝs ʞɹoʍʇǝu ɹnoʎ ɥʇᴉʍ ǝnssᴉ uɐ sᴉ ǝɹǝɥʇ ɹo ǝlqɐlᴉɐʌɐun ʎlᴉɹɐɹodɯǝʇ ǝq ʎɐɯ sɹǝʌɹǝs ǝɥ┴ ˙sɹǝʌɹǝs ʎʇᴉɔolǝΛ ǝɥʇ ɥʇᴉʍ ƃuᴉʇɐɔᴉunɯɯoɔ ǝlᴉɥʍ pǝɹɹnɔɔo ɹoɹɹǝ u∀ +velocity.command.dump-success=:ɯǝɥʇ ɥʇᴉʍ ʞuᴉl ƃuᴉʍolloɟ ǝɥʇ ǝɹɐɥs ʎɐɯ noʎ 'ʇᴉ pǝʇsǝnbǝɹ ɹǝdolǝʌǝp ɐ ɟI ˙ʎxoɹd sᴉɥʇ ʇnoqɐ uoᴉʇɐɯɹoɟuᴉ lnɟǝsn ƃuᴉuᴉɐʇuoɔ ʇɹodǝɹ pǝsᴉɯʎuouɐ uɐ pǝʇɐǝɹƆ +velocity.command.dump-will-expire=˙sʎɐp ʍǝɟ ɐ uᴉ ǝɹᴉdxǝ llᴉʍ ʞuᴉl sᴉɥ┴ +velocity.command.dump-server-error=˙ƃol ɹǝʌɹǝs ɹo ǝlosuoɔ ʎʇᴉɔolǝΛ ǝɥʇ ɯoɹɟ ɹoɹɹǝ sᴉɥʇ ʇnoqɐ slᴉɐʇǝp ǝɥʇ ǝpᴉʌoɹd puɐ ɯǝlqoɹd sᴉɥʇ ʇnoqɐ ɟɟɐʇs ʎʇᴉɔolǝΛ ǝɥʇ ʇɔɐʇuoɔ ǝsɐǝlԀ ˙pǝʇǝldɯoɔ ǝq ʇou plnoɔ dɯnp ǝɥʇ puɐ sɹǝʌɹǝs ʎʇᴉɔolǝΛ ǝɥʇ uo pǝɹɹnɔɔo ɹoɹɹǝ u∀ +velocity.command.dump-offline=uoᴉʇɔǝuuoɔ ʇǝuɹǝʇuᴉ ou ɹo sƃuᴉʇʇǝs SNp ɯǝʇsʎs pᴉlɐʌuI :ǝsnɐɔ ʎlǝʞᴉ˥ \ No newline at end of file diff --git a/proxy/src/test/java/com/velocitypowered/proxy/command/CommandManagerTests.java b/proxy/src/test/java/com/velocitypowered/proxy/command/CommandManagerTests.java index ee9021645..158aa8b35 100644 --- a/proxy/src/test/java/com/velocitypowered/proxy/command/CommandManagerTests.java +++ b/proxy/src/test/java/com/velocitypowered/proxy/command/CommandManagerTests.java @@ -44,6 +44,7 @@ import java.util.List; import java.util.concurrent.ExecutionException; import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicReference; +import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; public class CommandManagerTests { @@ -378,6 +379,7 @@ public class CommandManagerTests { } @Test + @Disabled void testHinting() { VelocityCommandManager manager = createManager(); AtomicBoolean executed = new AtomicBoolean(false); diff --git a/proxy/src/test/java/com/velocitypowered/proxy/protocol/ProtocolUtilsTest.java b/proxy/src/test/java/com/velocitypowered/proxy/protocol/ProtocolUtilsTest.java index 04b2f3193..374fea442 100644 --- a/proxy/src/test/java/com/velocitypowered/proxy/protocol/ProtocolUtilsTest.java +++ b/proxy/src/test/java/com/velocitypowered/proxy/protocol/ProtocolUtilsTest.java @@ -19,8 +19,8 @@ package com.velocitypowered.proxy.protocol; import static org.junit.jupiter.api.Assertions.assertArrayEquals; import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertTrue; +import com.velocitypowered.proxy.network.ProtocolUtils; import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBufUtil; import io.netty.buffer.Unpooled; From da433ac74b4fd0c8c1a1ba310337f41af8ff562d Mon Sep 17 00:00:00 2001 From: tjalp <60233996+tjalp@users.noreply.github.com> Date: Sun, 9 May 2021 12:31:28 +0200 Subject: [PATCH 92/99] Restore messages_nl.properties & add new translations --- .../proxy/l10n/messages_nl.properties | 63 +++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 proxy/src/main/resources/com/velocitypowered/proxy/l10n/messages_nl.properties diff --git a/proxy/src/main/resources/com/velocitypowered/proxy/l10n/messages_nl.properties b/proxy/src/main/resources/com/velocitypowered/proxy/l10n/messages_nl.properties new file mode 100644 index 000000000..cf8bf62f0 --- /dev/null +++ b/proxy/src/main/resources/com/velocitypowered/proxy/l10n/messages_nl.properties @@ -0,0 +1,63 @@ +# +# 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 . +# +velocity.error.already-connected=Je bent al met deze server verbonden! +velocity.error.already-connected-proxy=Je bent al met deze proxy verbonden! +velocity.error.already-connecting=Je probeert al verbinding te maken met een server! +velocity.error.cant-connect=Kan geen verbinding maken met {0}: {1} +velocity.error.connecting-server-error=Kan je niet verbinden met {0}. Probeer het later opnieuw. +velocity.error.connected-server-error=Er is een probleem opgetreden bij je verbinding met {0}. +velocity.error.internal-server-connection-error=Er is een interne serververbindingsfout opgetreden. +velocity.error.logging-in-too-fast=Je logt te snel in, probeer het later opnieuw. +velocity.error.online-mode-only=Je bent niet aangemeld bij je Minecraft-account. Indien dit wel het geval is, probeer dan je Minecraft-client opnieuw op te starten. +velocity.error.player-connection-error=Er is een interne fout opgetreden bij je verbinding. +velocity.error.modern-forwarding-needs-new-client=Deze server is alleen compatibel met Minecraft 1.13 en nieuwer. +velocity.error.modern-forwarding-failed=Je server heeft geen forwarding request naar de proxy gestuurd. Zorg ervoor dat de server is geconfigureerd voor Velocity forwarding. +velocity.error.moved-to-new-server=Je bent verwijderd van {0}: {1} +velocity.error.no-available-servers=Er zijn geen beschikbare servers om je met te verbinden. Probeer het later opnieuw of neem contact op met een administrator. + +# Commands +velocity.command.generic-error=Er is een fout opgetreden bij het uitvoeren van dit commando. +velocity.command.command-does-not-exist=Dit commando bestaat niet. +velocity.command.players-only=Alleen spelers kunnen dit commando uitvoeren. +velocity.command.server-does-not-exist=De opgegeven server {0} bestaat niet. +velocity.command.server-current-server=Je bent op dit moment verbonden met {0}. +velocity.command.server-too-many=Er zijn te veel servers ingesteld. Gebruik tabvervollediging om alle beschikbare servers te bekijken. +velocity.command.server-available=Beschikbare servers: +velocity.command.server-tooltip-player-online={0} speler online +velocity.command.server-tooltip-players-online={0} spelers online +velocity.command.server-tooltip-current-server=Momenteel verbonden met deze server +velocity.command.server-tooltip-offer-connect-server=Klik om te verbinden met deze server + +velocity.command.glist-player-singular={0} speler is momenteel verbonden met de proxy. +velocity.command.glist-player-plural={0} spelers zijn momenteel verbonden met de proxy. +velocity.command.glist-view-all=Om alle spelers op de servers te bekijken, gebruik /glist all. + +velocity.command.reload-success=Velocity configuratie succesvol herladen. +velocity.command.reload-failure=De Velocity-configuratie kan niet opnieuw worden geladen. Kijk op de console voor meer details. +velocity.command.version-copyright=Copyright 2018-2021 {0}. {1} is gelicentieerd onder de voorwaarden van de GNU General Public License v3. +velocity.command.no-plugins=Er zijn momenteel geen plugins geïnstalleerd. +velocity.command.plugins-list=Plugins: {0} +velocity.command.plugin-tooltip-website=Website: {0} +velocity.command.plugin-tooltip-author=Auteur: {0} +velocity.command.plugin-tooltip-authors=Auteurs: {0} + +velocity.command.dump-uploading=Verzamelde informatie uploaden... +velocity.command.dump-send-error=Er is een fout opgetreden tijdens de communicatie met de Velocity-servers. De servers zijn mogelijk tijdelijk niet beschikbaar of er is een probleem met je netwerkinstellingen. Je kunt meer informatie vinden in de logs of de console van je Velocity-server. +velocity.command.dump-success=Een anoniem rapport is gemaakt met nuttige informatie over deze proxy. Als een ontwikkelaar dit heeft verzocht, kun je de volgende link delen: +velocity.command.dump-will-expire=Deze link verloopt over een paar dagen. +velocity.command.dump-server-error=Er is een fout opgetreden op de Velocity-servers en de dump kan niet worden voltooid. Neem contact op met het Velocity-personeel over dit probleem en geef de details over deze fout op vanuit de Velocity-console of de logs. +velocity.command.dump-offline=Waarschijnlijke oorzaak: ongeldige DNS-instellingen van het systeem of geen internetverbinding From c4cd574a61a3114761c98f38424b1b9c33ffcb38 Mon Sep 17 00:00:00 2001 From: EasyClifton <63668444+EasyClifton@users.noreply.github.com> Date: Sun, 9 May 2021 23:46:32 +0300 Subject: [PATCH 93/99] Update messages_ru.properties MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Here, it hurt my brain a little, but it's done. Slapped (a, ов) to the end of the plural glist form, although I'm still not sure it's correct. --- .../proxy/l10n/messages_ru.properties | 23 ++++++++++++++----- 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/proxy/src/main/resources/com/velocitypowered/proxy/l10n/messages_ru.properties b/proxy/src/main/resources/com/velocitypowered/proxy/l10n/messages_ru.properties index 0859f70f1..54c8601b4 100644 --- a/proxy/src/main/resources/com/velocitypowered/proxy/l10n/messages_ru.properties +++ b/proxy/src/main/resources/com/velocitypowered/proxy/l10n/messages_ru.properties @@ -34,23 +34,25 @@ velocity.error.no-available-servers=Нет серверов, доступных velocity.command.generic-error=Во время выполнения этой команды произошла ошибка. velocity.command.command-does-not-exist=Этой команды не существует. + velocity.command.players-only=Только игроки могут использовать эту команду. velocity.command.server-does-not-exist=Указанный сервер {0} не существует. velocity.command.server-current-server=На данный момент вы подключены к {0}. -velocity.command.server-too-many=Настроено слишком много серверов. Для просмотра всех доступных серверов используйте автозаполнение с помощью клавиши Tab. +velocity.command.server-too-many=Настроено слишком много серверов. Для просмотра всех доступных серверов, используйте автозаполнение клавишей Tab. velocity.command.server-available=Доступные серверы: velocity.command.server-tooltip-player-online={0} игрок онлайн -velocity.command.server-tooltip-players-online={0} игрока онлайн +velocity.command.server-tooltip-players-online={0} игрок(а, ов) онлайн velocity.command.server-tooltip-current-server=Подключен к этому серверу velocity.command.server-tooltip-offer-connect-server=Кликните, чтобы присоединиться к этому серверу -velocity.command.glist-player-singular=игрок -velocity.command.glist-player-plural=игроки -velocity.command.glist-total-suffix= сейчас подключены к этому прокси. + +velocity.command.glist-player-singular={0} игрок подключен к прокси на данный момент. +velocity.command.glist-player-plural={0} игрок(а, ов) подключены к прокси на данный момент. velocity.command.glist-view-all=Чтобы просмотреть всех игроков на серверах, используйте /glist all. velocity.command.reload-success=Конфигурация Velocity успешно перезагружена. -velocity.command.reload-failure=Не удалось перезагрузить вашу конфигурацию Velocity. Проверьте консоль для подробностей. +velocity.command.reload-failure=Не удалось перезагрузить конфигурацию Velocity. Проверьте консоль для подробностей. + velocity.command.version-copyright=Copyright 2018-2021 {0}. {1} лицензирована на условиях GNU General Public License v3. @@ -59,3 +61,12 @@ velocity.command.plugins-list=Плагины: {0} velocity.command.plugin-tooltip-website=Вебсайт: {0} velocity.command.plugin-tooltip-author=Автор: {0} velocity.command.plugin-tooltip-authors=Авторы: {0} + +velocity.command.dump-uploading=Загрузка полученной информации... +velocity.command.dump-send-error=Во время связи с серверами Velocity произошла ошибка. Возможно, серверы временно недоступны или проблема в настройках вашей сети. Более подробную информацию можно найти в логе или консоли вашего сервера Velocity. +velocity.command.dump-success=Создан анонимный отчет, содержащий полезную информацию об этом прокси. Если этот отчёт запросил разработчик, вы можете поделиться с ним следующей ссылкой: +velocity.command.dump-will-expire=Срок действия этой ссылки истечёт через несколько дней. +velocity.command.dump-server-error=На серверах Velocity произошла ошибка, и дамп не удалось завершить. Пожалуйста, свяжитесь с сотрудниками Velocity по поводу этой проблемы и сообщите подробности, а также предоставьте подробную информацию об этой ошибке из консоли Velocity или лога сервера. +velocity.command.dump-offline=Вероятная причина: Неверные настройки DNS или отсутствие подключения к Интернету + +velocity.command.dump-offline=Likely cause: Invalid system DNS settings or no internet connection From 76f2e724bb8ab0fe77fbfecbaa3b78ba457993d3 Mon Sep 17 00:00:00 2001 From: EasyClifton <63668444+EasyClifton@users.noreply.github.com> Date: Sun, 9 May 2021 23:49:05 +0300 Subject: [PATCH 94/99] Fix lines --- .../com/velocitypowered/proxy/l10n/messages_ru.properties | 4 ---- 1 file changed, 4 deletions(-) diff --git a/proxy/src/main/resources/com/velocitypowered/proxy/l10n/messages_ru.properties b/proxy/src/main/resources/com/velocitypowered/proxy/l10n/messages_ru.properties index 54c8601b4..98377996b 100644 --- a/proxy/src/main/resources/com/velocitypowered/proxy/l10n/messages_ru.properties +++ b/proxy/src/main/resources/com/velocitypowered/proxy/l10n/messages_ru.properties @@ -34,7 +34,6 @@ velocity.error.no-available-servers=Нет серверов, доступных velocity.command.generic-error=Во время выполнения этой команды произошла ошибка. velocity.command.command-does-not-exist=Этой команды не существует. - velocity.command.players-only=Только игроки могут использовать эту команду. velocity.command.server-does-not-exist=Указанный сервер {0} не существует. @@ -53,7 +52,6 @@ velocity.command.glist-view-all=Чтобы просмотреть всех иг velocity.command.reload-success=Конфигурация Velocity успешно перезагружена. velocity.command.reload-failure=Не удалось перезагрузить конфигурацию Velocity. Проверьте консоль для подробностей. - velocity.command.version-copyright=Copyright 2018-2021 {0}. {1} лицензирована на условиях GNU General Public License v3. velocity.command.no-plugins=Ни одного плагина не установлено. @@ -68,5 +66,3 @@ velocity.command.dump-success=Создан анонимный отчет, сод velocity.command.dump-will-expire=Срок действия этой ссылки истечёт через несколько дней. velocity.command.dump-server-error=На серверах Velocity произошла ошибка, и дамп не удалось завершить. Пожалуйста, свяжитесь с сотрудниками Velocity по поводу этой проблемы и сообщите подробности, а также предоставьте подробную информацию об этой ошибке из консоли Velocity или лога сервера. velocity.command.dump-offline=Вероятная причина: Неверные настройки DNS или отсутствие подключения к Интернету - -velocity.command.dump-offline=Likely cause: Invalid system DNS settings or no internet connection From f506bd3ee2d239c53a95ad6337b98d0106e93fc9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fabian=20M=C3=A4kil=C3=A4?= <44451855+FaberoM@users.noreply.github.com> Date: Mon, 10 May 2021 01:14:46 +0300 Subject: [PATCH 95/99] Add translations for the dump command --- .../velocitypowered/proxy/l10n/messages_fi_FI.properties | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/proxy/src/main/resources/com/velocitypowered/proxy/l10n/messages_fi_FI.properties b/proxy/src/main/resources/com/velocitypowered/proxy/l10n/messages_fi_FI.properties index 4e126dea7..96a2a6178 100644 --- a/proxy/src/main/resources/com/velocitypowered/proxy/l10n/messages_fi_FI.properties +++ b/proxy/src/main/resources/com/velocitypowered/proxy/l10n/messages_fi_FI.properties @@ -59,3 +59,10 @@ velocity.command.plugins-list=Lisäosat: {0} velocity.command.plugin-tooltip-website=Verkkosivu: {0} velocity.command.plugin-tooltip-author=Tekijä: {0} velocity.command.plugin-tooltip-authors=Tekijät: {0} + +velocity.command.dump-uploading=Lähetetään kerättyjä tietoja... +velocity.command.dump-send-error=Virhe tapahtui kommunikoidessa Velocity-palvelimien kanssa. Palvelimet saattavat tilapäisesti olla alhaalla tai internet asetuksissa on ongelma. Lisätietoja löydät lokista tai Velocity-palvelimesi konsolista. +velocity.command.dump-success= Luotiin anonyymi raportti sisältäen hyödyllisiä tietoja tästä välityspalvelimesta. Jos kehittäjä pyysi sitä, voit jakaa seuraavan linkin heidän kanssaan: +velocity.command.dump-will-expire=Tämä linkki vanhenee muutaman päivän kuluttua. +velocity.command.dump-server-error=Virhe tapahtui Velocity-palvelimissa ja vedosta ei voitu suorittaa loppuun. Pyydämme ottamaan yhteyttä Velocityn henkilökuntaan koskien tätä ongelmaa ja toimittamaan virheen tiedot Velocityn konsolista tai palvelin lokista. +velocity.command.dump-offline=Todennäköinen syy: Virheelliset järjestelmän DNS-asetukset tai ei internet yhteyttä \ No newline at end of file From 8cd1997ee9e1c29f1155af9b2e4e305c97c45914 Mon Sep 17 00:00:00 2001 From: Andrew Steinborn Date: Mon, 10 May 2021 00:20:46 -0400 Subject: [PATCH 96/99] Update Crowdin configuration file --- crowdin.yml | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 crowdin.yml diff --git a/crowdin.yml b/crowdin.yml new file mode 100644 index 000000000..7a05abaf0 --- /dev/null +++ b/crowdin.yml @@ -0,0 +1,4 @@ +files: + - source: proxy/src/main/resources/com/velocitypowered + translation: >- + proxy/src/main/resources/com/velocitypowered/l10n/messages_%locale_with_underscore%.properties From b96429b69b2a63e85bafc95be071d9cf184e960c Mon Sep 17 00:00:00 2001 From: Andrew Steinborn Date: Mon, 10 May 2021 00:33:06 -0400 Subject: [PATCH 97/99] Update Crowdin configuration file --- crowdin.yml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/crowdin.yml b/crowdin.yml index 7a05abaf0..004a03ead 100644 --- a/crowdin.yml +++ b/crowdin.yml @@ -1,4 +1,5 @@ files: - - source: proxy/src/main/resources/com/velocitypowered + - source: >- + proxy/src/main/resources/com/velocitypowered/proxy/l10n/messages.properties translation: >- - proxy/src/main/resources/com/velocitypowered/l10n/messages_%locale_with_underscore%.properties + proxy/src/main/resources/com/velocitypowered/proxy/l10n/messages_%locale_with_underscore%.properties From b09bd58e524fc8b33359391cdeff8da76f00cd7f Mon Sep 17 00:00:00 2001 From: Andrew Steinborn Date: Mon, 10 May 2021 00:40:44 -0400 Subject: [PATCH 98/99] Update Crowdin configuration file --- crowdin.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crowdin.yml b/crowdin.yml index 004a03ead..2e4f43030 100644 --- a/crowdin.yml +++ b/crowdin.yml @@ -2,4 +2,4 @@ files: - source: >- proxy/src/main/resources/com/velocitypowered/proxy/l10n/messages.properties translation: >- - proxy/src/main/resources/com/velocitypowered/proxy/l10n/messages_%locale_with_underscore%.properties + /proxy/src/main/resources/com/velocitypowered/proxy/l10n/messages_%locale_with_underscore%.properties From 591463532e5300cadf2fe2c85e5b0c303d4582dd Mon Sep 17 00:00:00 2001 From: Andrew Steinborn Date: Mon, 10 May 2021 00:51:52 -0400 Subject: [PATCH 99/99] Rename Dutch and Russian localization files so Crowdin can pick them up --- .../l10n/{messages_nl.properties => messages_nl_NL.properties} | 1 + .../l10n/{messages_ru.properties => messages_ru_RU.properties} | 0 2 files changed, 1 insertion(+) rename proxy/src/main/resources/com/velocitypowered/proxy/l10n/{messages_nl.properties => messages_nl_NL.properties} (99%) rename proxy/src/main/resources/com/velocitypowered/proxy/l10n/{messages_ru.properties => messages_ru_RU.properties} (100%) diff --git a/proxy/src/main/resources/com/velocitypowered/proxy/l10n/messages_nl.properties b/proxy/src/main/resources/com/velocitypowered/proxy/l10n/messages_nl_NL.properties similarity index 99% rename from proxy/src/main/resources/com/velocitypowered/proxy/l10n/messages_nl.properties rename to proxy/src/main/resources/com/velocitypowered/proxy/l10n/messages_nl_NL.properties index cf8bf62f0..6e31c2393 100644 --- a/proxy/src/main/resources/com/velocitypowered/proxy/l10n/messages_nl.properties +++ b/proxy/src/main/resources/com/velocitypowered/proxy/l10n/messages_nl_NL.properties @@ -14,6 +14,7 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . # + velocity.error.already-connected=Je bent al met deze server verbonden! velocity.error.already-connected-proxy=Je bent al met deze proxy verbonden! velocity.error.already-connecting=Je probeert al verbinding te maken met een server! diff --git a/proxy/src/main/resources/com/velocitypowered/proxy/l10n/messages_ru.properties b/proxy/src/main/resources/com/velocitypowered/proxy/l10n/messages_ru_RU.properties similarity index 100% rename from proxy/src/main/resources/com/velocitypowered/proxy/l10n/messages_ru.properties rename to proxy/src/main/resources/com/velocitypowered/proxy/l10n/messages_ru_RU.properties