Skip to content

Commit 11b80dd

Browse files
committed
Added code
1 parent 5152644 commit 11b80dd

File tree

9 files changed

+128
-183
lines changed

9 files changed

+128
-183
lines changed

README.MD

+19-22
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,24 @@
1-
# Gradle Template
2-
A template project for my gradle based repos.
1+
# ViaProxyWhitelist
2+
Only allow specified players to join the ViaProxy server.
33

4-
## Maven Server Setup
5-
To use the maven servers in this template you need to enter your credentials into your `gradle.properties` files.\
6-
The file can be found in the `.gradle` folder in your home directory (create it if it doesn't exist).
7-
```properties
8-
reposiliteUsername=user
9-
reposilitePassword=123456
4+
## Usage
5+
### Installation
6+
Download the latest release from the [releases page](https://github.com/ViaVersionAddons/ViaProxyWhitelist/releases) and place it in the `plugins` folder of the ViaProxy server.\
7+
The minimum required version of ViaProxy is `3.3.4`.
108

11-
ossrhUsername=user
12-
ossrhPassword=123456
13-
```
9+
### Configuration
10+
You must enable the `proxy-online-mode` option in the config!\
11+
The plugin does not work without this option enabled.
1412

15-
## Signing Setup
16-
To sign your artifacts you need to enter your signing credentials into your `gradle.properties` files.\
17-
The file can be found in the `.gradle` folder in your home directory (create it if it doesn't exist).
18-
```properties
19-
signing.keyId=ABC12345
20-
signing.password=123456
21-
signing.secretKeyRingFile=secretkey.gpg
22-
```
13+
After starting the server with the plugin, a `whitelist.yml` file will be created in the server folder.\
14+
It contains the kick message and the list of players that are allowed to join the server.
15+
16+
```yaml
17+
#The message that will be displayed when a player is not whitelisted
18+
KickMessage: You are not whitelisted on this server!
2319

24-
The secretkey can be exported using the `gpg` command:
25-
```bash
26-
gpg --export-secret-key > secretkey.gpg
20+
#The list of players that are allowed to join the server
21+
Whitelist:
22+
- Player1
23+
- Player2
2724
```

build.gradle

+5-155
Original file line numberDiff line numberDiff line change
@@ -1,81 +1,30 @@
11
plugins {
22
id "java"
3-
id "maven-publish"
4-
id "signing"
53
id "checkstyle"
6-
id "net.raphimc.class-token-replacer" version "1.1.3"
74
}
85

96
base {
10-
java.toolchain.languageVersion = JavaLanguageVersion.of(8)
7+
java.toolchain.languageVersion = JavaLanguageVersion.of(17)
118
compileJava.options.encoding = compileTestJava.options.encoding = javadoc.options.encoding = "UTF-8"
129

1310
archivesName = project.maven_name ?: rootProject.maven_name
1411
group = project.maven_group ?: rootProject.maven_group
1512
version = project.maven_version ?: rootProject.maven_version
1613
}
1714

18-
configurations {
19-
include
20-
21-
implementation.extendsFrom include
22-
api.extendsFrom include
23-
}
24-
2515
repositories {
2616
mavenCentral()
2717
maven {
28-
name = "lenni0451"
29-
url = "https://maven.lenni0451.net/everything"
30-
}
31-
maven {
32-
name = "jitpack"
33-
url = "https://jitpack.io"
18+
name = "viaversion"
19+
url = "https://repo.viaversion.com/everything"
3420
}
35-
maven {
36-
name = "sonatype snapshots"
37-
url "https://oss.sonatype.org/content/repositories/snapshots/"
38-
}
39-
40-
//ivy { //include "waterfall:1.19:504@jar"
41-
// url "https://papermc.io/api/v2/projects"
42-
// patternLayout {
43-
// artifact "/[organisation]/versions/[module]/builds/[revision]/downloads/[organisation]-[module]-[revision].[ext]"
44-
// }
45-
// metadataSources {
46-
// artifact()
47-
// }
48-
//}
4921
}
5022

5123
dependencies {
52-
if (new File(projectDir, "libs").exists()) { //Include all jars in the libs folder
53-
include fileTree(include: ["*.jar"], dir: "libs")
54-
}
55-
5624
compileOnly "com.google.code.findbugs:jsr305:3.0.2"
5725
compileOnly "org.jetbrains:annotations:25.0.0"
5826
compileOnly(annotationProcessor("org.projectlombok:lombok:1.18.34"))
59-
//include "net.lenni0451:Reflect:1.0.0"
60-
61-
testImplementation(platform("org.junit:junit-bom:5.11.1"))
62-
testImplementation "org.junit.jupiter:junit-jupiter"
63-
testRuntimeOnly "org.junit.platform:junit-platform-launcher"
64-
testCompileOnly(testAnnotationProcessor("org.projectlombok:lombok:1.18.34"))
65-
}
66-
67-
sourceSets {
68-
main {
69-
classTokenReplacer {
70-
//Replace all instances of '${version}' with the project version
71-
property("\${version}", project.version)
72-
}
73-
}
74-
}
75-
76-
java {
77-
withSourcesJar()
78-
withJavadocJar()
27+
compileOnly "net.raphimc:ViaProxy:3.3.4-SNAPSHOT"
7928
}
8029

8130
processResources {
@@ -84,115 +33,16 @@ processResources {
8433
"version": project.maven_version
8534
)
8635

87-
filesMatching("config.yml") {
36+
filesMatching("viaproxy.yml") {
8837
expand(
8938
"version": project.maven_version
9039
)
9140
}
9241
}
9342

94-
artifacts {
95-
archives javadocJar, sourcesJar
96-
}
97-
98-
jar {
99-
dependsOn configurations.include
100-
from {
101-
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
102-
configurations.include.collect {
103-
zipTree(it)
104-
}
105-
} {
106-
exclude "META-INF/*.RSA", "META-INF/*.SF", "META-INF/*.DSA"
107-
}
108-
109-
manifest {
110-
attributes(
111-
"Main-Class": "net.lenni0451.gradletemplate.Main",
112-
"Multi-Release": "true"
113-
)
114-
}
115-
}
116-
117-
test {
118-
useJUnitPlatform()
119-
testLogging {
120-
events "passed", "skipped", "failed"
121-
}
122-
maxParallelForks Runtime.runtime.availableProcessors()
123-
}
124-
125-
publishing {
126-
repositories {
127-
maven {
128-
name = "reposilite"
129-
def releasesUrl = "https://maven.lenni0451.net/releases"
130-
def snapshotsUrl = "https://maven.lenni0451.net/snapshots"
131-
url = project.maven_version.endsWith("SNAPSHOT") ? snapshotsUrl : releasesUrl
132-
133-
credentials(PasswordCredentials)
134-
authentication {
135-
basic(BasicAuthentication)
136-
}
137-
}
138-
maven {
139-
name = "ossrh"
140-
def releasesUrl = "https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/"
141-
def snapshotsUrl = "https://s01.oss.sonatype.org/content/repositories/snapshots/"
142-
url = project.maven_version.endsWith("SNAPSHOT") ? snapshotsUrl : releasesUrl
143-
144-
credentials(PasswordCredentials)
145-
authentication {
146-
basic(BasicAuthentication)
147-
}
148-
}
149-
}
150-
publications {
151-
maven(MavenPublication) {
152-
artifactId = project.maven_name ?: rootProject.maven_name
153-
groupId = rootProject.maven_group
154-
version = rootProject.maven_version
155-
156-
from components.java
157-
158-
pom {
159-
name = rootProject.name
160-
description = rootProject.maven_description
161-
url = "https://github.com/" + rootProject.github_repo
162-
licenses {
163-
license {
164-
name = "MIT License"
165-
url = "https://github.com/" + rootProject.github_repo + "/blob/main/LICENSE"
166-
}
167-
}
168-
developers {
169-
developer {
170-
id = "Lenni0451"
171-
}
172-
}
173-
scm {
174-
connection = "scm:git:git://github.com/" + rootProject.github_repo + ".git"
175-
developerConnection = "scm:git:ssh://github.com/" + rootProject.github_repo + ".git"
176-
url = "github.com/" + rootProject.github_repo
177-
}
178-
}
179-
}
180-
}
181-
}
182-
18343
checkstyle {
18444
toolVersion = "10.16.0" //Latest version for Java 8: 9.3
18545
configFile = rootProject.file("config/checkstyle/checkstyle.xml")
18646
}
18747

188-
signing {
189-
setRequired false
190-
sign configurations.archives
191-
sign publishing.publications.maven
192-
}
193-
194-
project.tasks.withType(PublishToMavenRepository).forEach {
195-
it.dependsOn(project.tasks.withType(Sign))
196-
}
197-
build.dependsOn(test)
19848
build.dependsOn(check)

gradle.properties

+3-3
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ org.gradle.parallel=true
44
org.gradle.configureondemand=true
55

66
#Maven settings
7-
maven_name=GradleTemplate
7+
maven_name=ViaProxyWhitelist
88
maven_group=net.lenni0451
99
maven_version=1.0.0
1010

11-
maven_description=A template for gradle projects
12-
github_repo=Lenni0451/GradleTemplate
11+
maven_description=Only allow specified players to join the ViaProxy server
12+
github_repo=ViaVersionAddons/ViaProxyWhitelist

settings.gradle

+1-3
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,4 @@ plugins {
99
id "org.gradle.toolchains.foojay-resolver-convention" version "0.8.0"
1010
}
1111

12-
rootProject.name = "GradleTemplate"
13-
14-
//include(":subproject")
12+
rootProject.name = "ViaProxyWhitelist"

src/.gitkeep

Whitespace-only changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package net.lenni0451.whitelist;
2+
3+
import io.netty.channel.ChannelFutureListener;
4+
import net.raphimc.netminecraft.packet.Packet;
5+
import net.raphimc.netminecraft.packet.impl.login.C2SLoginHelloPacket;
6+
import net.raphimc.viaproxy.proxy.packethandler.PacketHandler;
7+
import net.raphimc.viaproxy.proxy.session.ProxyConnection;
8+
9+
import java.util.List;
10+
11+
public class LoginListener extends PacketHandler {
12+
13+
public LoginListener(final ProxyConnection proxyConnection) {
14+
super(proxyConnection);
15+
}
16+
17+
@Override
18+
public boolean handleC2P(Packet packet, List<ChannelFutureListener> listeners) {
19+
if (packet instanceof C2SLoginHelloPacket loginHello) {
20+
if (!WhitelistConfig.whitelist.contains(loginHello.name)) {
21+
this.proxyConnection.kickClient(WhitelistConfig.kickMessage);
22+
}
23+
}
24+
return true;
25+
}
26+
27+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package net.lenni0451.whitelist;
2+
3+
import net.lenni0451.lambdaevents.EventHandler;
4+
import net.raphimc.viaproxy.ViaProxy;
5+
import net.raphimc.viaproxy.plugins.ViaProxyPlugin;
6+
import net.raphimc.viaproxy.plugins.events.ConnectEvent;
7+
import net.raphimc.viaproxy.plugins.events.ViaProxyLoadedEvent;
8+
import net.raphimc.viaproxy.util.logging.Logger;
9+
10+
public class Main extends ViaProxyPlugin {
11+
12+
@Override
13+
public void onEnable() {
14+
WhitelistConfig.load();
15+
ViaProxy.EVENT_MANAGER.register(this);
16+
}
17+
18+
@EventHandler
19+
public void onViaProxyLoaded(final ViaProxyLoadedEvent event) {
20+
if (!ViaProxy.getConfig().isProxyOnlineMode()) {
21+
Logger.LOGGER.error("Proxy online mode is disabled, please enable it to use the whitelist plugin!");
22+
Logger.LOGGER.error("Without online mode the whitelist plugin would be effectively useless");
23+
Logger.LOGGER.error("Shutting down...");
24+
System.exit(0);
25+
}
26+
}
27+
28+
@EventHandler(priority = Integer.MIN_VALUE)
29+
public void onConnect(final ConnectEvent event) {
30+
event.getProxyConnection().getPacketHandlers().add(0, new LoginListener(event.getProxyConnection()));
31+
}
32+
33+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package net.lenni0451.whitelist;
2+
3+
import net.lenni0451.optconfig.ConfigLoader;
4+
import net.lenni0451.optconfig.annotations.Description;
5+
import net.lenni0451.optconfig.annotations.OptConfig;
6+
import net.lenni0451.optconfig.annotations.Option;
7+
import net.lenni0451.optconfig.provider.ConfigProvider;
8+
import net.raphimc.viaproxy.util.logging.Logger;
9+
10+
import java.io.File;
11+
import java.util.List;
12+
13+
@OptConfig
14+
public class WhitelistConfig {
15+
16+
@Option("KickMessage")
17+
@Description("The message that will be displayed when a player is not whitelisted")
18+
public static String kickMessage = "You are not whitelisted on this server!";
19+
20+
@Option("Whitelist")
21+
@Description("The list of players that are allowed to join the server")
22+
public static List<String> whitelist = List.of("Player1", "Player2");
23+
24+
public static void load() {
25+
try {
26+
ConfigLoader<WhitelistConfig> configLoader = new ConfigLoader<>(WhitelistConfig.class);
27+
configLoader.getConfigOptions().setResetInvalidOptions(true);
28+
configLoader.loadStatic(ConfigProvider.file(new File("whitelist.yml")));
29+
} catch (Throwable t) {
30+
Logger.LOGGER.error("Failed to load the whitelist configuration!", t);
31+
System.exit(-1);
32+
}
33+
}
34+
35+
}

src/main/resources/viaproxy.yml

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
name: "Whitelist"
2+
version: "${version}"
3+
author: "Lenni0451"
4+
main: "net.lenni0451.whitelist.Main"
5+
min-version: "3.3.4"

0 commit comments

Comments
 (0)