Skip to content

Commit

Permalink
Update to latest Velocity and Waterfall
Browse files Browse the repository at this point in the history
Also use Java 17 now seeing as Velocity requires it now too!
  • Loading branch information
Phoenix616 committed Mar 27, 2024
1 parent b3d9102 commit c2f3201
Show file tree
Hide file tree
Showing 5 changed files with 98 additions and 30 deletions.
16 changes: 8 additions & 8 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@

<groupId>de.themoep</groupId>
<artifactId>snap</artifactId>
<version>1.1-SNAPSHOT</version>
<version>1.2-SNAPSHOT</version>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.target>1.8</maven.compiler.target>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
<maven.compiler.source>17</maven.compiler.source>
<build.number>${buildNumber}</build.number>
<minecraft.plugin.version>${project.version} ${buildDescription}</minecraft.plugin.version>
</properties>
Expand All @@ -28,13 +28,13 @@
<dependency>
<groupId>com.velocitypowered</groupId>
<artifactId>velocity-api</artifactId>
<version>3.1.1</version>
<version>3.3.0-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>io.github.waterfallmc</groupId>
<artifactId>waterfall-api</artifactId>
<version>1.19-R0.1-SNAPSHOT</version>
<version>1.20-R0.3-SNAPSHOT</version>
<scope>compile</scope>
</dependency>
<!-- API requirements, not actually part of API -->
Expand Down Expand Up @@ -80,7 +80,7 @@
<dependency>
<groupId>com.mysql</groupId>
<artifactId>mysql-connector-j</artifactId>
<version>8.0.33</version>
<version>8.2.0</version>
<scope>runtime</scope>
</dependency>
</dependencies>
Expand Down Expand Up @@ -131,15 +131,15 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<version>3.11.0</version>
<configuration>
<proc>none</proc>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.2.3</version>
<version>3.5.1</version>
<executions>
<execution>
<phase>package</phase>
Expand Down
48 changes: 26 additions & 22 deletions src/main/java/de/themoep/snap/PluginConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,10 @@
* You should have received a copy of the GNU Lesser General Public
* License along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
import com.typesafe.config.ConfigParseOptions;
import com.typesafe.config.ConfigRenderOptions;
import ninja.leaping.configurate.ConfigurationNode;
import ninja.leaping.configurate.hocon.HoconConfigurationLoader;
import ninja.leaping.configurate.yaml.YAMLConfigurationLoader;

import org.spongepowered.configurate.ConfigurationNode;
import org.spongepowered.configurate.hocon.HoconConfigurationLoader;
import org.spongepowered.configurate.serialize.SerializationException;

import java.io.BufferedReader;
import java.io.IOException;
Expand Down Expand Up @@ -51,9 +50,7 @@ public PluginConfig(Snap plugin, Path configFile, String defaultFile) {
this.configFile = configFile;
this.defaultFile = defaultFile;
configLoader = HoconConfigurationLoader.builder()
.setPath(configFile)
.setParseOptions(ConfigParseOptions.defaults())
.setRenderOptions(ConfigRenderOptions.defaults())
.path(configFile)
.build();
}

Expand All @@ -62,13 +59,11 @@ public boolean load() {
config = configLoader.load();
if (defaultFile != null && plugin.getClass().getClassLoader().getResource(defaultFile) != null) {
defaultConfig = HoconConfigurationLoader.builder()
.setPath(configFile)
.setParseOptions(ConfigParseOptions.defaults())
.setRenderOptions(ConfigRenderOptions.defaults())
.setSource(() -> new BufferedReader(new InputStreamReader(plugin.getClass().getClassLoader().getResourceAsStream(defaultFile))))
.path(configFile)
.source(() -> new BufferedReader(new InputStreamReader(plugin.getClass().getClassLoader().getResourceAsStream(defaultFile))))
.build()
.load();
if (config.isEmpty()) {
if (config.empty()) {
config = defaultConfig.copy();
}
}
Expand Down Expand Up @@ -113,31 +108,40 @@ public void save() {
}

public Object set(String path, Object value) {
ConfigurationNode node = config.getNode(splitPath(path));
Object prev = node.getValue();
node.setValue(value);
ConfigurationNode node = config.node(splitPath(path));
Object prev = node.raw();
try {
node.set(value);
} catch (SerializationException e) {
plugin.getLogger().error("Could not set node at " + path, e);
}
return prev;
}

public ConfigurationNode remove(String path) {
ConfigurationNode node = config.getNode(splitPath(path));
return node.isVirtual() ? node : node.setValue(null);
ConfigurationNode node = config.node(splitPath(path));
try {
return node.virtual() ? node : node.set(null);
} catch (SerializationException e) {
plugin.getLogger().error("Could not remove node at " + path, e);
return null;
}
}

public ConfigurationNode getRawConfig() {
return config;
}

public ConfigurationNode getRawConfig(String path) {
return getRawConfig().getNode(splitPath(path));
return getRawConfig().node(splitPath(path));
}

public boolean has(String path) {
return !getRawConfig(path).isVirtual();
return !getRawConfig(path).virtual();
}

public boolean isSection(String path) {
return getRawConfig(path).hasMapChildren();
return getRawConfig(path).isMap();
}

public int getInt(String path) {
Expand All @@ -157,7 +161,7 @@ public double getDouble(String path, double def) {
}

public String getString(String path) {
return getString(path, null);
return getRawConfig(path).getString();
}

public String getString(String path, String def) {
Expand Down
34 changes: 34 additions & 0 deletions src/main/java/de/themoep/snap/forwarding/SnapPlayer.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
import java.util.Map;
import java.util.Optional;
import java.util.UUID;
import java.util.concurrent.CompletableFuture;
import java.util.stream.Collectors;

public class SnapPlayer extends SnapCommandSender implements ProxiedPlayer {
Expand Down Expand Up @@ -108,6 +109,20 @@ public boolean isLegacy() {
return player.getProtocolVersion().isLegacy();
}

@Override
public boolean isTransferred() {
// TODO: Support 1.20.5 features
snap.unsupported("Transferred connections are not supported in Velocity's API yet!");
return false;
}

@Override
public CompletableFuture<byte[]> retrieveCookie(String s) {
// TODO: Support 1.20.5 features
snap.unsupported("Transferred connections and cookies are not supported in Velocity's API yet!");
return null;
}

@Override
public InetSocketAddress getAddress() {
return player.getRemoteAddress();
Expand Down Expand Up @@ -423,6 +438,25 @@ public Scoreboard getScoreboard() {
return (Scoreboard) snap.unsupported("Scoreboards are not supported by Snap");
}

@Override
public CompletableFuture<byte[]> retrieveCookie(String s) {
// TODO: Support 1.20.5 features
snap.unsupported("Transferred connections and cookies are not supported in Velocity's API yet!");
return CompletableFuture.completedFuture(null);
}

@Override
public void storeCookie(String s, byte[] bytes) {
// TODO: Support 1.20.5 features
snap.unsupported("Transferred connections and cookies are not supported in Velocity's API yet!");
}

@Override
public void transfer(String s, int i) {
// TODO: Support 1.20.5 features
snap.unsupported("Transferred connections and cookies are not supported in Velocity's API yet!");
}

@Override
public String getName() {
return player.getUsername();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import java.net.InetSocketAddress;
import java.net.SocketAddress;
import java.util.UUID;
import java.util.concurrent.CompletableFuture;

public abstract class ForwardingListener {
protected final Snap snap;
Expand Down Expand Up @@ -94,6 +95,20 @@ public boolean isLegacy() {
return connection.getProtocolVersion().isLegacy();
}

@Override
public boolean isTransferred() {
// TODO: Support 1.20.5 features
snap.unsupported("Transferred connections are not supported in Velocity's API yet!");
return false;
}

@Override
public CompletableFuture<byte[]> retrieveCookie(String s) {
// TODO: Support 1.20.5 features
snap.unsupported("Transferred connections and cookies are not supported in Velocity's API yet!");
return null;
}

@Override
public InetSocketAddress getAddress() {
return connection.getRemoteAddress();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import java.net.InetSocketAddress;
import java.net.SocketAddress;
import java.util.UUID;
import java.util.concurrent.CompletableFuture;

public class PreLoginListener extends ForwardingListener {

Expand Down Expand Up @@ -107,6 +108,20 @@ public boolean isLegacy() {
return event.getConnection().getProtocolVersion().isLegacy();
}

@Override
public boolean isTransferred() {
// TODO: Support 1.20.5 features
snap.unsupported("Transferred connections are not supported in Velocity's API yet!");
return false;
}

@Override
public CompletableFuture<byte[]> retrieveCookie(String s) {
// TODO: Support 1.20.5 features
snap.unsupported("Transferred connections and cookies are not supported in Velocity's API yet!");
return null;
}

@Override
public InetSocketAddress getAddress() {
return event.getConnection().getRemoteAddress();
Expand Down

0 comments on commit c2f3201

Please sign in to comment.