Skip to content

Commit cc98eee

Browse files
committed
General cleanup
1 parent 7d44061 commit cc98eee

9 files changed

Lines changed: 81 additions & 142 deletions

File tree

README.MD

Lines changed: 22 additions & 96 deletions
Original file line numberDiff line numberDiff line change
@@ -4,112 +4,38 @@ This plugin is only needed if you want to host a public SRV mode proxy instance.
44

55
## SRV ViaProxy
66
### Running ViaProxy in SRV mode
7-
8-
To use the SRV mode in ViaProxy you have to start it through the config.\
9-
Here are The config options require to make a Public SRV mode.
10-
```
7+
To use the SRV mode in ViaProxy you have to change some config options.
8+
```yaml
119
bind-address: 0.0.0.0:25568 # will translate to viaproxy.0-0-0-0.nip.io:25568
12-
target-address: 127.0.0.1 # unused on srv mode.
13-
target-version: 1.8.x # unused on srv mode.
10+
target-address: 127.0.0.1 # unused in srv mode
11+
target-version: 1.8.x # unused in srv mode
1412
auth-method: OpenAuthMod
1513
wildcard-domain-handling: PUBLIC
1614
```
15+
You have to replace `0.0.0.0:25568` with the address and port you want ViaProxy to run on.\
16+
The `auth-method: openauthmod` is optional and enables [OpenAuthMod](https://github.com/RaphiMC/OpenAuthMod) authentication. Check the caution below.\
17+
The `target-address` and `target-version` are required for ViaProxy to start but don't do anything in SRV mode.
18+
19+
> <b>[CAUTION]</b>\
20+
> `auth-method: openauthmod` will not work for 1.7-1.7.10, 1.19.4+, Vanilla and Bedrock Edition.\
21+
> Reason:\
22+
> 1.7-1.7.10: OpenAuthMod is only available for 1.8+.\
23+
> Bedrock: Forge and Fabric don't support Bedrock Edition.\
24+
> 1.19.4+: OpenAuthMod was discontinued before release of 1.19.4.
1725

18-
You have to replace ``0.0.0.0:<bind port>`` with the port you want ViaProxy to run on.\
19-
The ``auth-method: openauthmod`` is optional and enables the [OpenAuthMod](https://github.com/RaphiMC/OpenAuthMod) authentication. for 1.19.4 users, see the caution below.\
20-
The ``target-address`` and ``target-version`` are required for ViaProxy to start but don't do anything in SRV mode.
21-
> [!CAUTION]
22-
> warning: auth-method: openauthmod will be not functional for 1.7-1.7.10, Vanilla 1.8-1.19.3, 1.19.4-1.21.1, and Bedrock Edition.\
23-
> Reason: 1.7-1.7.10: OpenAuthMod is only available for 1.8.
24-
> Bedrock: Forge or Fabric don't support Bedrock Edition.\
25-
> 1.19.4+: OpenAuthMod discontinued before release of 1.19.4. use this option if you want to.
2626
### Connecting to ViaProxy in SRV mode
2727
To connect to ViaProxy in SRV mode you need a domain pointing to the IP of the server running ViaProxy.\
28-
The subdomain ``viaproxy.`` is required for it to work.\
29-
For local connections you can use ``viaproxy.127-0-0-1.nip.io``.
28+
The subdomain `viaproxy.` is required for it to work.\
29+
For local connections you can use `viaproxy.127-0-0-1.nip.io`.
3030

31-
To connect to a server through ViaProxy you have to prepend the ``server ip``, ``server port`` and ``version`` to your domain:
32-
````
31+
To connect to a server through ViaProxy you have to prepend the `server ip`, `server port` and `version` to your domain:
32+
```
3333
address_port_version.viaproxy.hostname
34-
````
34+
```
3535

36-
For example to connect to ``lenni0451.net:39999`` with the version ``C0.30-CPE`` you can use:
37-
````
36+
For example to connect to `lenni0451.net:39999` with the version `C0.30-CPE` you can use:
37+
```
3838
lenni0451.net_39999_c0.30-cpe.viaproxy.127-0-0-1.nip.io
39-
````
39+
```
4040

4141
If the domain of a server contains an underscore you currently can't connect to it since ViaProxy uses the underscore as a separator.
42-
43-
## How to make a ViaProxy plugin
44-
### viaproxy.yml
45-
ViaProxy plugins require a ``viaproxy.yml`` file in the root of the plugin jar.\
46-
It defines the name, version, author, main class and minimum supported ViaProxy version of the plugin:
47-
````yaml
48-
name: "CoolPlugin"
49-
version: "1.0.0"
50-
author: "ExampleDude"
51-
main: "com.exampledude.coolplugin.Main"
52-
min-version: "3.0.0"
53-
````
54-
55-
### Plugin Main
56-
The plugin main must extend ``ViaProxyPlugin`` and implement the ``onEnable`` method:
57-
````java
58-
public class Main extends ViaProxyPlugin {
59-
@Override
60-
public void onEnable() {
61-
}
62-
}
63-
````
64-
65-
There is an optional ``registerTransformers`` method that can be implemented to register class transformers **for the own plugin classes**:
66-
````java
67-
@Override
68-
public void registerTransformers(final TransformerManager transformerManager) {
69-
transformerManager.addTransformer("com.exampledude.coolplugin.Transformer");
70-
}
71-
````
72-
73-
Check out the [ClassTransform](https://github.com/Lenni0451/ClassTransform/#usage) documentation for more information on how to use class transformers.
74-
75-
### Events
76-
The only real way to interact with ViaProxy is through events.\
77-
ViaProxy uses [LambdaEvents](https://github.com/Lenni0451/LambdaEvents) for event handling.\
78-
You can register a listener using the ``register()`` method in the ``PluginManager.EVENT_MANAGER``:
79-
````java
80-
PluginManager.EVENT_MANAGER.register(this);
81-
````
82-
83-
ViaProxy currently (at the time of writing) has the following events:
84-
- Client2ProxyChannelInitializeEvent
85-
- Client2ProxyHandlerCreationEvent
86-
- ClientLoggedInEvent
87-
- ConnectEvent
88-
- ConsoleCommandEvent
89-
- FillPlayerDataEvent
90-
- GetDefaultPortEvent
91-
- PostOptionsParseEvent
92-
- PreConnectEvent
93-
- PreOptionsParseEvent
94-
- ProtocolHackInitEvent
95-
- Proxy2ServerChannelInitializeEvent
96-
- Proxy2ServerHandlerCreationEvent
97-
- ProxyStartEvent
98-
- ProxyStopEvent
99-
- ResolveSrvEvent
100-
- ViaLoadingEvent
101-
102-
Some events have pre- and post-states and some events are cancellable.
103-
104-
To listen to an event you have to add the ``@EventHandler`` annotation to the handler method and put the event as the only parameter:
105-
````java
106-
@EventHandler
107-
public void onPreConnect(final PreConnectEvent event) {
108-
}
109-
````
110-
111-
### ViaVersion API
112-
Since ViaProxy uses ViaVersion for its protocol handling, the entire ViaVersion API is available.
113-
114-
### Loading the plugin
115-
To load plugins just put the plugin jars in the ``plugins`` folder and ViaProxy will load them on startup.

build.gradle

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
plugins {
2-
id "java"
2+
id "java-library"
33
}
44

5-
java.toolchain.languageVersion = JavaLanguageVersion.of(17)
6-
compileJava.options.encoding = "UTF-8"
5+
base {
6+
java.toolchain.languageVersion = JavaLanguageVersion.of(17)
7+
compileJava.options.encoding = "UTF-8"
78

8-
archivesBaseName = project.maven_name
9-
group = project.maven_group
10-
version = project.maven_version
9+
archivesName = project.maven_name
10+
group = project.maven_group
11+
version = project.maven_version
12+
}
1113

1214
repositories {
1315
maven {

gradle/wrapper/gradle-wrapper.jar

-16.9 KB
Binary file not shown.
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
distributionBase=GRADLE_USER_HOME
22
distributionPath=wrapper/dists
3-
distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-bin.zip
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-8.10.2-bin.zip
4+
networkTimeout=10000
5+
validateDistributionUrl=true
46
zipStoreBase=GRADLE_USER_HOME
57
zipStorePath=wrapper/dists

gradlew

Lines changed: 22 additions & 13 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

gradlew.bat

Lines changed: 11 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/main/java/net/lenni0451/nolocalconnections/Main.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package net.lenni0451.nolocalconnections;
22

3-
import net.lenni0451.nolocalconnections.KickMessageConfig;
43
import net.lenni0451.lambdaevents.EventHandler;
54
import net.raphimc.viaproxy.ViaProxy;
65
import net.raphimc.viaproxy.plugins.ViaProxyPlugin;
@@ -13,14 +12,14 @@ public class Main extends ViaProxyPlugin {
1312

1413
@Override
1514
public void onEnable() {
16-
KickMessageConfig.load();
15+
NoLocalConnectionsConfig.load(this.getDataFolder());
1716
ViaProxy.EVENT_MANAGER.register(this);
1817
}
1918

2019
@EventHandler
21-
public void onEvent(PreConnectEvent event) {
20+
public void onEvent(final PreConnectEvent event) {
2221
if (!(event.getServerAddress() instanceof InetSocketAddress socketAddress)) return;
23-
if (this.isLocal(socketAddress.getAddress())) event.setCancelMessage(KickMessageConfig.kick);
22+
if (this.isLocal(socketAddress.getAddress())) event.setCancelMessage(NoLocalConnectionsConfig.kickMessage);
2423
}
2524

2625
private boolean isLocal(final InetAddress address) {

src/main/java/net/lenni0451/nolocalconnections/KickMessageConfig.java renamed to src/main/java/net/lenni0451/nolocalconnections/NoLocalConnectionsConfig.java

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,30 +8,30 @@
88
import net.raphimc.viaproxy.util.logging.Logger;
99

1010
import java.io.File;
11-
import java.util.List;
1211

1312
@OptConfig(header = {
1413
"Configuration for the NoLocalConnections ViaProxy plugin.",
15-
"Used to block a Connection for Local Address Connections through ViaProxy(useful for address_port_version.viaproxy.hostname).",
14+
"Used to block connections to local addresses through ViaProxy (useful for public SRV proxies).",
1615
"",
1716
"Made by Lenni0451",
1817
"Source: https://github.com/ViaVersionAddons/NoLocalConnections"
1918
})
20-
public class KickMessageConfig {
19+
public class NoLocalConnectionsConfig {
2120

22-
@Option("kick")
21+
@Option("KickMessage")
2322
@Description({
24-
"kick message when the user tries to join using local address such as 192.168.35.1. you can use the Decoration Codes here using Section Symbol(§)."
23+
"Kick message when the user tries to connect local addresses such as 192.168.35.1",
24+
"You can use color codes here using section symbol (§)."
2525
})
26-
public static String kick = "§cYou can't connect to any local address.";
27-
28-
public static void load() {
26+
public static String kickMessage = "§cYou can't connect to any local address.";
27+
28+
public static void load(final File dataFolder) {
2929
try {
30-
ConfigLoader<KickMessageConfig> configLoader = new ConfigLoader<>(KickMessageConfig.class);
30+
ConfigLoader<NoLocalConnectionsConfig> configLoader = new ConfigLoader<>(NoLocalConnectionsConfig.class);
3131
configLoader.getConfigOptions().setResetInvalidOptions(true); //Reset invalid options to their default value
32-
configLoader.loadStatic(ConfigProvider.file(new File("kickmessage.yml")));
32+
configLoader.loadStatic(ConfigProvider.file(new File(dataFolder, "config.yml")));
3333
} catch (Throwable t) {
34-
Logger.LOGGER.error("Unable to load kick message! turning off viaproxy...", t);
34+
Logger.LOGGER.error("Unable to load config! Shutting down...", t);
3535
System.exit(-1);
3636
}
3737
}

src/main/resources/viaproxy.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@ name: "NoLocalConnections"
22
version: "1.2"
33
author: "Lenni0451"
44
main: "net.lenni0451.nolocalconnections.Main"
5-
min-version: "3.1.0"
5+
min-version: "3.3.4"

0 commit comments

Comments
 (0)